| @@ -1,33 +1,23 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * Scribd Shortcode | |
| 4 | - * | |
| 5 | - * [scribd id=DOCUMENT_ID key=DOCUMENT_KEY mode=MODE] | |
| 6 | - * DOCUMENT_ID is an integer (also used as an object_id) | |
| 7 | - * DOCUMENT_KEY is an alphanumeric hash ('-' character as well) | |
| 8 | - * MODE can be 'list', 'book', 'slide', 'slideshow', or 'tile' | |
| 9 | - * | |
| 10 | - * [scribd id=39027960 key=key-3kaiwcjqhtipf25m8tw mode=list] | |
| 11 | - * | |
| 12 | - * @package automattic/jetpack | |
| 13 | - */ | |
| 14 | 2 | |
| 15 | -/** | |
| 16 | - * Register Scribd shortcode. | |
| 17 | - * | |
| 18 | - * @param array $atts Shortcode attributes. | |
| 19 | - */ | |
| 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 | + | |
| 20 | 14 | function scribd_shortcode_handler( $atts ) { |
| 21 | - $atts = shortcode_atts( | |
| 22 | - array( | |
| 23 | - 'id' => 0, | |
| 24 | - 'key' => 0, | |
| 25 | - 'mode' => '', | |
| 26 | - ), | |
| 27 | - $atts, | |
| 28 | - 'scribd' | |
| 29 | - ); | |
| 15 | + $atts = shortcode_atts( array( | |
| 16 | + 'id' => 0, | |
| 17 | + 'key' => 0, | |
| 18 | + 'mode' => '', | |
| 19 | + ), $atts, 'scribd' ); | |
| 30 | 20 | |
| 31 | 21 | $modes = array( 'list', 'book', 'slide', 'slideshow', 'tile' ); |
| 32 | 22 | |
| 33 | 23 | $atts['id'] = (int) $atts['id']; |
| @@ -33,9 +23,9 @@ | ||
| 33 | 23 | $atts['id'] = (int) $atts['id']; |
| 34 | 24 | if ( preg_match( '/^[A-Za-z0-9-]+$/', $atts['key'], $m ) ) { |
| 35 | 25 | $atts['key'] = $m[0]; |
| 36 | 26 | |
| 37 | - if ( ! in_array( $atts['mode'], $modes, true ) ) { | |
| 27 | + if ( ! in_array( $atts['mode'], $modes ) ) { | |
| 38 | 28 | $atts['mode'] = ''; |
| 39 | 29 | } |
| 40 | 30 | |
| 41 | 31 | return scribd_shortcode_markup( $atts ); |
| @@ -43,49 +33,20 @@ | ||
| 43 | 33 | return ''; |
| 44 | 34 | } |
| 45 | 35 | } |
| 46 | 36 | |
| 47 | -/** | |
| 48 | - * Display the shortcode. | |
| 49 | - * | |
| 50 | - * @param array $atts Shortcode attributes. | |
| 51 | - * @return string The rendered shortcode. | |
| 52 | - */ | |
| 53 | 37 | function scribd_shortcode_markup( $atts ) { |
| 54 | - $sandbox = class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() | |
| 55 | - ? 'sandbox="allow-popups allow-scripts allow-same-origin"' | |
| 56 | - : ''; | |
| 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; | |
| 57 | 42 | |
| 58 | - $url = add_query_arg( | |
| 59 | - array( | |
| 60 | - 'start_page' => '1', | |
| 61 | - 'view_mode' => esc_attr( $atts['mode'] ), | |
| 62 | - 'access_key' => esc_attr( $atts['key'] ), | |
| 63 | - ), | |
| 64 | - esc_url( | |
| 65 | - sprintf( | |
| 66 | - 'https://www.scribd.com/embeds/%1$d/content', | |
| 67 | - absint( $atts['id'] ) | |
| 68 | - ) | |
| 69 | - ) | |
| 70 | - ); | |
| 43 | + return $markup; | |
| 44 | +} | |
| 71 | 45 | |
| 72 | - return sprintf( | |
| 73 | - '<iframe class="scribd_iframe_embed" src="%1$s" %2$s data-auto-height="true" scrolling="no" id="scribd_%3$d" width="100%%" height="500" frameborder="0"></iframe> | |
| 74 | - <div style="font-size:10px;text-align:center;width:100%%"><a href="https://www.scribd.com/doc/%3$d" rel="noopener noreferrer" target="_blank">%4$s</a></div>', | |
| 75 | - $url, | |
| 76 | - $sandbox, | |
| 77 | - absint( $atts['id'] ), | |
| 78 | - esc_html__( 'View this document on Scribd', 'jetpack' ) | |
| 79 | - ); | |
| 80 | -} | |
| 81 | 46 | add_shortcode( 'scribd', 'scribd_shortcode_handler' ); |
| 82 | 47 | |
| 83 | -/** | |
| 84 | - * Scribd supports HTTPS, so use that endpoint to get HTTPS-compatible embeds. | |
| 85 | - * | |
| 86 | - * @param array $providers Array of oEmbed providers. | |
| 87 | - */ | |
| 48 | +// Scribd supports HTTPS, so use that endpoint to get HTTPS-compatible embeds | |
| 88 | 49 | function scribd_https_oembed( $providers ) { |
| 89 | 50 | if ( isset( $providers['#https?://(www\.)?scribd\.com/doc/.*#i'] ) ) { |
| 90 | 51 | $providers['#https?://(www\.)?scribd\.com/doc/.*#i'][0] = 'https://www.scribd.com/services/oembed'; |
| 91 | 52 | } |
| @@ -91,5 +52,6 @@ | ||
| 91 | 52 | } |
| 92 | 53 | |
| 93 | 54 | return $providers; |
| 94 | 55 | } |
| 56 | + | |
| 95 | 57 | add_filter( 'oembed_providers', 'scribd_https_oembed' ); |