| 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 |
|
| 31 |
return scribd_shortcode_markup( $atts ); |
| 32 |
} else { |
| 33 |
return ''; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
function scribd_shortcode_markup( $atts ) { |
| 38 |
$markup = <<<EOD |
| 39 |
<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> |
| 40 |
<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> |
| 41 |
EOD; |
| 42 |
|
| 43 |
return $markup; |
| 44 |
} |
| 45 |
|
| 46 |
add_shortcode( 'scribd', 'scribd_shortcode_handler' ); |
| 47 |
|
| 48 |
// Scribd supports HTTPS, so use that endpoint to get HTTPS-compatible embeds |
| 49 |
function scribd_https_oembed( $providers ) { |
| 50 |
if ( isset( $providers['#https?://(www\.)?scribd\.com/doc/.*#i'] ) ) { |
| 51 |
$providers['#https?://(www\.)?scribd\.com/doc/.*#i'][0] = 'https://www.scribd.com/services/oembed'; |
| 52 |
} |
| 53 |
|
| 54 |
return $providers; |
| 55 |
} |
| 56 |
|
| 57 |
add_filter( 'oembed_providers', 'scribd_https_oembed' ); |
| 58 |
|