scribd.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /* Scribd Short Code
  3. Author: Nick Momrik
  4. [scribd id=DOCUMENT_ID key=DOCUMENT_KEY mode=MODE]
  5. DOCUMENT_ID is an integer (also used as an object_id)
  6. DOCUMENT_KEY is an alphanumeric hash ('-' character as well)
  7. MODE can be 'list', 'book', 'slide', 'slideshow', or 'tile'
  8. [scribd id=39027960 key=key-3kaiwcjqhtipf25m8tw mode=list]
  9. */
  10. function scribd_shortcode_handler( $atts ) {
  11. $atts = shortcode_atts( array(
  12. 'id' => 0,
  13. 'key' => 0,
  14. 'mode' => '',
  15. ), $atts, 'scribd' );
  16. $modes = array( 'list', 'book', 'slide', 'slideshow', 'tile' );
  17. $atts['id'] = (int) $atts['id'];
  18. if ( preg_match( '/^[A-Za-z0-9-]+$/', $atts['key'], $m ) ) {
  19. $atts['key'] = $m[0];
  20. if ( ! in_array( $atts['mode'], $modes ) ) {
  21. $atts['mode'] = '';
  22. }
  23. return scribd_shortcode_markup( $atts );
  24. } else {
  25. return '';
  26. }
  27. }
  28. function scribd_shortcode_markup( $atts ) {
  29. $markup = <<<EOD
  30. <iframe class="scribd_iframe_embed" src="//www.scribd.com/embeds/$atts[id]/content?start_page=1&view_mode=$atts[mode]&access_key=$atts[key]" data-auto-height="true" scrolling="no" id="scribd_$atts[id]" width="100%" height="500" frameborder="0"></iframe>
  31. <div style="font-size:10px;text-align:center;width:100%"><a href="http://www.scribd.com/doc/$atts[id]" target="_blank">View this document on Scribd</a></div>
  32. EOD;
  33. return $markup;
  34. }
  35. add_shortcode( 'scribd', 'scribd_shortcode_handler' );
  36. // Scribd supports HTTPS, so use that endpoint to get HTTPS-compatible embeds
  37. function scribd_https_oembed( $providers ) {
  38. if ( isset( $providers['#https?://(www\.)?scribd\.com/doc/.*#i'] ) ) {
  39. $providers['#https?://(www\.)?scribd\.com/doc/.*#i'][0] = 'https://www.scribd.com/services/oembed';
  40. }
  41. return $providers;
  42. }
  43. add_filter( 'oembed_providers', 'scribd_https_oembed' );