/modules/shortcodes/scribd.php

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