css
2 years ago
images
2 years ago
img
2 years ago
js
2 years ago
archiveorg-book.php
5 years ago
archiveorg.php
5 years ago
archives.php
5 years ago
bandcamp.php
3 years ago
brightcove.php
5 years ago
cartodb.php
5 years ago
class.filter-embedded-html-objects.php
2 years ago
codepen.php
5 years ago
crowdsignal.php
2 years ago
dailymotion.php
3 years ago
descript.php
4 years ago
facebook.php
2 years ago
flatio.php
5 years ago
flickr.php
2 years ago
getty.php
2 years ago
gist.php
3 years ago
googleapps.php
2 years ago
googlemaps.php
2 years ago
googleplus.php
5 years ago
gravatar.php
2 years ago
houzz.php
5 years ago
inline-pdfs.php
4 years ago
instagram.php
3 years ago
kickstarter.php
3 years ago
mailchimp.php
3 years ago
medium.php
3 years ago
mixcloud.php
2 years ago
others.php
2 years ago
pinterest.php
2 years ago
presentations.php
2 years ago
quiz.php
4 years ago
recipe.php
2 years ago
scribd.php
5 years ago
sitemap.php
5 years ago
slideshare.php
5 years ago
slideshow.php
2 years ago
smartframe.php
3 years ago
soundcloud.php
3 years ago
spotify.php
2 years ago
ted.php
5 years ago
tweet.php
2 years ago
twitchtv.php
5 years ago
twitter-timeline.php
5 years ago
unavailable.php
3 years ago
untappd-menu.php
3 years ago
upcoming-events.php
3 years ago
ustream.php
5 years ago
videopress.php
4 years ago
vimeo.php
2 years ago
vine.php
5 years ago
vr.php
2 years ago
wordads.php
5 years ago
wufoo.php
3 years ago
youtube.php
1 year ago
archiveorg.php
163 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Archive.org book shortcode. |
| 4 | * |
| 5 | * Usage: |
| 6 | * [archiveorg Experime1940] |
| 7 | * [archiveorg http://archive.org/details/Experime1940 poster=http://archive.org/images/map.png] |
| 8 | * [archiveorg id=Experime1940 width=640 height=480 autoplay=1] |
| 9 | |
| 10 | * <iframe src="http://archive.org/embed/Experime1940&autoplay=1&poster=http://archive.org/images/map.png" width="640" height="480" frameborder="0" webkitallowfullscreen="true" mozallowfullscreen="true" allowfullscreen></iframe> |
| 11 | * |
| 12 | * @package automattic/jetpack |
| 13 | */ |
| 14 | |
| 15 | /** |
| 16 | * Get ID of requested archive.org embed. |
| 17 | * |
| 18 | * @since 4.5.0 |
| 19 | * |
| 20 | * @param array $atts Shortcode attributes. |
| 21 | * |
| 22 | * @return int|string |
| 23 | */ |
| 24 | function jetpack_shortcode_get_archiveorg_id( $atts ) { |
| 25 | if ( isset( $atts[0] ) ) { |
| 26 | $atts[0] = trim( $atts[0], '=' ); |
| 27 | if ( preg_match( '#archive.org/(details|embed)/(.+)/?$#i', $atts[0], $match ) ) { |
| 28 | $id = $match[2]; |
| 29 | } else { |
| 30 | $id = $atts[0]; |
| 31 | } |
| 32 | return $id; |
| 33 | } |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Convert an archive.org shortcode into an embed code. |
| 39 | * |
| 40 | * @since 4.5.0 |
| 41 | * |
| 42 | * @param array $atts An array of shortcode attributes. |
| 43 | * @return string The embed code for the archive.org video. |
| 44 | */ |
| 45 | function jetpack_archiveorg_shortcode( $atts ) { |
| 46 | global $content_width; |
| 47 | |
| 48 | if ( isset( $atts[0] ) && empty( $atts['id'] ) ) { |
| 49 | $atts['id'] = jetpack_shortcode_get_archiveorg_id( $atts ); |
| 50 | } |
| 51 | |
| 52 | $atts = shortcode_atts( |
| 53 | array( |
| 54 | 'id' => '', |
| 55 | 'width' => 640, |
| 56 | 'height' => 480, |
| 57 | 'autoplay' => 0, |
| 58 | 'poster' => '', |
| 59 | ), |
| 60 | $atts |
| 61 | ); |
| 62 | |
| 63 | if ( ! $atts['id'] ) { |
| 64 | return '<!-- error: missing archive.org ID -->'; |
| 65 | } |
| 66 | |
| 67 | $id = $atts['id']; |
| 68 | |
| 69 | if ( ! $atts['width'] ) { |
| 70 | $width = absint( $content_width ); |
| 71 | } else { |
| 72 | $width = (int) $atts['width']; |
| 73 | } |
| 74 | |
| 75 | if ( ! $atts['height'] ) { |
| 76 | $height = round( ( $width / 640 ) * 360 ); |
| 77 | } else { |
| 78 | $height = (int) $atts['height']; |
| 79 | } |
| 80 | |
| 81 | if ( $atts['autoplay'] ) { |
| 82 | $autoplay = '&autoplay=1'; |
| 83 | } else { |
| 84 | $autoplay = ''; |
| 85 | } |
| 86 | |
| 87 | if ( $atts['poster'] ) { |
| 88 | $poster = '&poster=' . $atts['poster']; |
| 89 | } else { |
| 90 | $poster = ''; |
| 91 | } |
| 92 | |
| 93 | return sprintf( |
| 94 | '<div class="embed-archiveorg" style="text-align:center;"><iframe title="%s" src="%s" width="%s" height="%s" style="border:0;" webkitallowfullscreen="true" mozallowfullscreen="true" allowfullscreen></iframe></div>', |
| 95 | esc_attr__( 'Archive.org', 'jetpack' ), |
| 96 | esc_url( "https://archive.org/embed/{$id}{$autoplay}{$poster}" ), |
| 97 | esc_attr( $width ), |
| 98 | esc_attr( $height ) |
| 99 | ); |
| 100 | } |
| 101 | |
| 102 | add_shortcode( 'archiveorg', 'jetpack_archiveorg_shortcode' ); |
| 103 | |
| 104 | /** |
| 105 | * Compose shortcode from archive.org iframe. |
| 106 | * |
| 107 | * @since 4.5.0 |
| 108 | * |
| 109 | * @param string $content Post content. |
| 110 | * |
| 111 | * @return mixed |
| 112 | */ |
| 113 | function jetpack_archiveorg_embed_to_shortcode( $content ) { |
| 114 | if ( ! is_string( $content ) || false === stripos( $content, 'archive.org/embed/' ) ) { |
| 115 | return $content; |
| 116 | } |
| 117 | |
| 118 | $regexp = '!<iframe\s+src=[\'"]https?://archive\.org/embed/([^\'"]+)[\'"]((?:\s+\w+(=[\'"][^\'"]*[\'"])?)*)></iframe>!i'; |
| 119 | |
| 120 | if ( ! preg_match_all( $regexp, $content, $matches, PREG_SET_ORDER ) ) { |
| 121 | return $content; |
| 122 | } |
| 123 | |
| 124 | foreach ( $matches as $match ) { |
| 125 | $url = explode( '&', $match[1] ); |
| 126 | $id = 'id=' . $url[0]; |
| 127 | |
| 128 | $autoplay = ''; |
| 129 | $poster = ''; |
| 130 | $url_count = count( $url ); |
| 131 | |
| 132 | for ( $ii = 1; $ii < $url_count; $ii++ ) { |
| 133 | if ( 'autoplay=1' === $url[ $ii ] ) { |
| 134 | $autoplay = ' autoplay="1"'; |
| 135 | } |
| 136 | |
| 137 | $map_matches = array(); |
| 138 | if ( preg_match( '/^poster=(.+)$/', $url[ $ii ], $map_matches ) ) { |
| 139 | $poster = " poster=\"{$map_matches[1]}\""; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | $params = $match[2]; |
| 144 | |
| 145 | $params = wp_kses_hair( $params, array( 'http' ) ); |
| 146 | |
| 147 | $width = isset( $params['width'] ) ? (int) $params['width']['value'] : 0; |
| 148 | $height = isset( $params['height'] ) ? (int) $params['height']['value'] : 0; |
| 149 | |
| 150 | $wh = ''; |
| 151 | if ( $width && $height ) { |
| 152 | $wh = ' width=' . $width . ' height=' . $height; |
| 153 | } |
| 154 | |
| 155 | $shortcode = '[archiveorg ' . $id . $wh . $autoplay . $poster . ']'; |
| 156 | $content = str_replace( $match[0], $shortcode, $content ); |
| 157 | } |
| 158 | |
| 159 | return $content; |
| 160 | } |
| 161 | |
| 162 | add_filter( 'pre_kses', 'jetpack_archiveorg_embed_to_shortcode' ); |
| 163 |