Initial commit

This commit is contained in:
Ben Goldsworthy 2017-01-12 23:10:07 +00:00
commit 28e6ddf404
1083 changed files with 191734 additions and 0 deletions

View file

@ -0,0 +1,73 @@
<?php
/*
* Archives shortcode
* @author bubel & nickmomrik
* [archives limit=10]
*/
add_shortcode( 'archives', 'archives_shortcode' );
function archives_shortcode( $atts ) {
if ( is_feed() ) {
return '[archives]';
}
global $allowedposttags;
$default_atts = array(
'type' => 'postbypost',
'limit' => '',
'format' => 'html',
'showcount' => false,
'before' => '',
'after' => '',
'order' => 'desc',
);
$attr = shortcode_atts( $default_atts, $atts, 'archives' );
if ( ! in_array( $attr['type'], array( 'yearly', 'monthly', 'daily', 'weekly', 'postbypost' ) ) ) {
$attr['type'] = 'postbypost';
}
if ( ! in_array( $attr['format'], array( 'html', 'option', 'custom' ) ) ) {
$attr['format'] = 'html';
}
$limit = intval( $attr['limit'] );
// A Limit of 0 makes no sense so revert back to the default.
if ( empty( $limit ) ) {
$limit = '';
}
$showcount = ( false !== $attr['showcount'] && 'false' !== $attr['showcount'] ) ? true : false;
$before = wp_kses( $attr['before'], $allowedposttags );
$after = wp_kses( $attr['after'], $allowedposttags );
// Get the archives
$archives = wp_get_archives( array(
'type' => $attr['type'],
'limit' => $limit,
'format' => $attr['format'],
'echo' => false,
'show_post_count' => $showcount,
'before' => $before,
'after' => $after,
) );
if ( 'asc' === $attr['order'] ) {
$archives = implode( "\n", array_reverse( explode( "\n", $archives ) ) );
}
// Check to see if there are any archives
if ( empty( $archives ) ) {
$archives = '<p>' . __( 'Your blog does not currently have any published posts.', 'jetpack' ) . '</p>';
} else if ( 'option' === $attr['format'] ) {
$archives = '<select name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;"><option value="' . get_permalink() . '">--</option>' . $archives . '</select>';
} else if ( 'html' === $attr['format'] ) {
$archives = '<ul>' . $archives . '</ul>';
}
return $archives;
}

View file

@ -0,0 +1,435 @@
<?php
/**
* Class wrapper for audio shortcode
*/
class AudioShortcode {
static $add_script = false;
/**
* Add all the actions & resgister the shortcode
*/
function __construct() {
add_shortcode( 'audio', array( $this, 'audio_shortcode' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'check_infinite' ) );
add_action( 'infinite_scroll_render', array( $this, 'audio_shortcode_infinite' ), 11 );
}
/**
* Return the $url of the audio
*/
static function get_audio_id( $atts ) {
if ( isset( $atts[0] ) )
return $atts[0];
else
return 0;
}
/**
* Shortcode for audio
* [audio http://wpcom.files.wordpress.com/2007/01/mattmullenweg-interview.mp3|width=180|titles=1|artists=2]
*
* The important question here is whether the shortcode applies to widget_text:
* add_filter('widget_text', 'do_shortcode');
* */
function audio_shortcode( $atts ) {
global $ap_playerID;
global $post;
if ( ! is_array( $atts ) ) {
return '<!-- Audio shortcode passed invalid attributes -->';
}
if ( ! isset( $atts[0] ) ) {
if ( isset( $atts['src'] ) ) {
$atts[0] = $atts['src'];
unset( $atts['src'] );
} else {
return '<!-- Audio shortcode source not set -->';
}
}
$post_id = 0;
if ( isset( $post ) ) {
$post_id = $post->ID;
}
// add the special .js
wp_enqueue_script(
'audio-shortcode',
plugins_url( 'js/audio-shortcode.js', __FILE__ ),
array( 'jquery' ),
'1.1',
true);
// alert the infinite scroll renderer that it should try to load the script
self::$add_script = true;
$atts[0] = strip_tags( join( ' ', $atts ) );
$src = ltrim( $atts[0], '=' );
/**
* Set the audio player default colors.
*
* @module shortcodes
*
* @since 1.4.0
*
* @param array $ap_options {
* The default colors for the audio player in hexidecimal format (e.g. 0x#F8F8F8).
*
* @type string $bg Background color.
* @type string $leftbg Left background color.
* @type string $lefticon Left icon color.
* @type string $rightbg Right background color.
* @type string $rightbghover Right background hover color.
* @type string $righticon Right icon color.
* @type string $righticonhover Right icon hover color.
* @type string $text Text color.
* @type string $slider Slider color.
* @type string $track Track color.
* @type string $border Border color.
* @type string $loader Loader color.
*/
$ap_options = apply_filters(
'audio_player_default_colors',
array(
"bg" => "0xF8F8F8",
"leftbg" => "0xEEEEEE",
"lefticon" => "0x666666",
"rightbg" => "0xCCCCCC",
"rightbghover" => "0x999999",
"righticon" => "0x666666",
"righticonhover" => "0xFFFFFF",
"text" => "0x666666",
"slider" => "0x666666",
"track" => "0xFFFFFF",
"border" => "0x666666",
"loader" => "0x9FFFB8"
) );
if ( ! isset( $ap_playerID ) ) {
$ap_playerID = 1;
} else {
$ap_playerID++;
}
if ( ! isset( $load_audio_script ) ) {
$load_audio_script = true;
}
// prep the audio files
$src = trim( $src, ' "' );
$options = array();
$data = preg_split( "/\|/", $src );
$sound_file = $data[0];
$sound_files = explode( ',', $sound_file );
if ( is_ssl() ) {
for ( $i = 0; $i < count( $sound_files ); $i++ ) {
$sound_files[ $i ] = preg_replace( '#^http://([^.]+).files.wordpress.com/#', 'https://$1.files.wordpress.com/', $sound_files[ $i ] );
}
}
$sound_files = array_map( 'trim', $sound_files );
$sound_files = array_map( array( $this, 'rawurlencode_spaces' ), $sound_files );
$sound_files = array_map( 'esc_url_raw', $sound_files ); // Ensure each is a valid URL
$num_files = count( $sound_files );
$sound_types = array(
'mp3' => 'mpeg',
'wav' => 'wav',
'ogg' => 'ogg',
'oga' => 'ogg',
'm4a' => 'mp4',
'aac' => 'mp4',
'webm' => 'webm'
);
for ( $i = 1; $i < count( $data ); $i++ ) {
$pair = explode( "=", $data[$i] );
if ( strtolower( $pair[0] ) != 'autostart' ) {
$options[$pair[0]] = $pair[1];
}
}
// Merge runtime options to default colour options
// (runtime options overwrite default options)
foreach ( $ap_options as $key => $default ) {
if ( isset( $options[$key] ) ) {
if ( preg_match( '/^(0x)?[a-f0-9]{6}$/i', $default ) && !preg_match( '/^(0x)?[a-f0-9]{6}$/i', $options[$key] ) ) {
// Default is a hex color, but input is not
$options[$key] = $default;
}
} else {
$options[$key] = $default;
}
}
$options['soundFile'] = join( ',', $sound_files ); // Rebuild the option with our now sanitized data
$flash_vars = array();
foreach ( $options as $key => $value ) {
$flash_vars[] = rawurlencode( $key ) . '=' . rawurlencode( $value );
}
$flash_vars = implode( '&amp;', $flash_vars );
$flash_vars = esc_attr( $flash_vars );
// extract some of the options to insert into the markup
if ( isset( $options['bgcolor'] ) && preg_match( '/^(0x)?[a-f0-9]{6}$/i', $options['bgcolor'] ) ) {
$bgcolor = preg_replace( '/^(0x)?/', '#', $options['bgcolor'] );
$bgcolor = esc_attr( $bgcolor );
} else {
$bgcolor = '#FFFFFF';
}
if ( isset( $options['width'] ) ) {
$width = intval( $options['width'] );
} else {
$width = 290;
}
$loop = '';
$script_loop = 'false';
if ( isset( $options['loop'] ) && 'yes' == $options['loop'] ) {
$script_loop = 'true';
if ( 1 == $num_files ) {
$loop = 'loop';
}
}
$volume = 0.6;
if ( isset( $options['initialvolume'] ) &&
0.0 < floatval( $options['initialvolume'] ) &&
100.0 >= floatval( $options['initialvolume'] ) ) {
$volume = floatval( $options['initialvolume'] )/100.0;
}
$file_artists = array_pad( array(), $num_files, '' );
if ( isset( $options['artists'] ) ) {
$artists = preg_split( '/,/', $options['artists'] );
foreach ( $artists as $i => $artist ) {
$file_artists[$i] = esc_html( $artist ) . ' - ';
}
}
// generate default titles
$file_titles = array();
for ( $i = 0; $i < $num_files; $i++ ) {
$file_titles[] = 'Track #' . ($i+1);
}
// replace with real titles if they exist
if ( isset( $options['titles'] ) ) {
$titles = preg_split( '/,/', $options['titles'] );
foreach ( $titles as $i => $title ) {
$file_titles[$i] = esc_html( $title );
}
}
// fallback for the fallback, just a download link
$not_supported = '';
foreach ( $sound_files as $sfile ) {
$not_supported .= sprintf(
__( 'Download: <a href="%s">%s</a><br />', 'jetpack' ),
esc_url( $sfile ),
esc_html( basename( $sfile ) ) );
}
// HTML5 audio tag
$html5_audio = '';
$all_mp3 = true;
$add_audio = true;
$num_good = 0;
$to_remove = array();
foreach ( $sound_files as $i => $sfile ) {
$file_extension = pathinfo( $sfile, PATHINFO_EXTENSION );
if ( ! preg_match( '/^(mp3|wav|ogg|oga|m4a|aac|webm)$/i', $file_extension ) ) {
$html5_audio .= '<!-- Audio shortcode unsupported audio format -->';
if ( 1 == $num_files ) {
$html5_audio .= $not_supported;
}
$to_remove[] = $i; // make a note of the bad files
$all_mp3 = false;
continue;
} elseif ( ! preg_match( '/^mp3$/i', $file_extension ) ) {
$all_mp3 = false;
}
if ( 0 == $i ) { // only need one player
$html5_audio .= <<<AUDIO
<span id="wp-as-{$post_id}_{$ap_playerID}-container">
<audio id='wp-as-{$post_id}_{$ap_playerID}' controls preload='none' $loop style='background-color:$bgcolor;width:{$width}px;'>
<span id="wp-as-{$post_id}_{$ap_playerID}-nope">$not_supported</span>
</audio>
</span>
<br />
AUDIO;
}
$num_good++;
}
// player controls, if needed
if ( 1 < $num_files ) {
$html5_audio .= <<<CONTROLS
<span id='wp-as-{$post_id}_{$ap_playerID}-controls' style='display:none;'>
<a id='wp-as-{$post_id}_{$ap_playerID}-prev'
href='javascript:audioshortcode.prev_track( "{$post_id}_{$ap_playerID}" );'
style='font-size:1.5em;'>&laquo;</a>
|
<a id='wp-as-{$post_id}_{$ap_playerID}-next'
href='javascript:audioshortcode.next_track( "{$post_id}_{$ap_playerID}", true, $script_loop );'
style='font-size:1.5em;'>&raquo;</a>
</span>
CONTROLS;
}
$html5_audio .= "<span id='wp-as-{$post_id}_{$ap_playerID}-playing'></span>";
/**
* Sets external resource URL.
*
* @module shortcodes
*
* @since 1.4.0
*
* @param string $args URL of external resource.
*
*/
$swfurl = apply_filters(
'jetpack_static_url',
set_url_scheme( "http://en.wordpress.com/wp-content/plugins/audio-player/player.swf" )
);
// all the fancy javascript is causing Google Reader to break, just include flash in GReader
// override html5 audio code w/ just not supported code
if ( is_feed() ) {
$html5_audio = $not_supported;
}
if ( $all_mp3 ) {
// process regular flash player, inserting HTML5 tags into object as fallback
$audio_tags = <<<FLASH
<object id='wp-as-{$post_id}_{$ap_playerID}-flash' type='application/x-shockwave-flash' data='$swfurl' width='$width' height='24'>
<param name='movie' value='$swfurl' />
<param name='FlashVars' value='{$flash_vars}' />
<param name='quality' value='high' />
<param name='menu' value='false' />
<param name='bgcolor' value='$bgcolor' />
<param name='wmode' value='opaque' />
$html5_audio
</object>
FLASH;
} else { // just HTML5 for non-mp3 versions
$audio_tags = $html5_audio;
}
// strip out all the bad files before it reaches .js
foreach ( $to_remove as $i ) {
array_splice( $sound_files, $i, 1 );
array_splice( $file_artists, $i, 1 );
array_splice( $file_titles, $i, 1 );
}
// mashup the artist/titles for the script
$script_titles = array();
for ( $i = 0; $i < $num_files; $i++ ) {
if ( isset( $file_artists[ $i ] ) && isset( $file_titles[ $i ] ) ) {
$script_titles[] = $file_artists[ $i ] . $file_titles[ $i ];
}
}
// javacript to control audio
$script_files = json_encode( $sound_files );
$script_titles = json_encode( $script_titles );
$script = <<<SCRIPT
<script type='text/javascript'>
//<![CDATA[
(function() {
var prep = function() {
if ( 'undefined' === typeof window.audioshortcode ) { return; }
audioshortcode.prep(
'{$post_id}_{$ap_playerID}',
$script_files,
$script_titles,
$volume,
$script_loop
);
};
if ( 'undefined' === typeof jQuery ) {
if ( document.addEventListener ) {
window.addEventListener( 'load', prep, false );
} else if ( document.attachEvent ) {
window.attachEvent( 'onload', prep );
}
} else {
jQuery(document).on( 'ready as-script-load', prep );
}
})();
//]]>
</script>
SCRIPT;
// add the special javascript, if needed
if ( 0 < $num_good && ! is_feed() ) {
$audio_tags .= $script;
}
return "<span style='text-align:left;display:block;'><p>$audio_tags</p></span>";
}
/**
* If the theme uses infinite scroll, include jquery at the start
*/
function check_infinite() {
if ( current_theme_supports( 'infinite-scroll' ) && class_exists( 'The_Neverending_Home_Page' ) && The_Neverending_Home_Page::archive_supports_infinity() )
wp_enqueue_script( 'jquery' );
}
/**
* Dynamically load the .js, if needed
*
* This hooks in late (priority 11) to infinite_scroll_render to determine
* a posteriori if a shortcode has been called.
*/
function audio_shortcode_infinite() {
// only try to load if a shortcode has been called
if( self::$add_script ) {
$script_url = json_encode( esc_url_raw( plugins_url( 'js/audio-shortcode.js', __FILE__ ) ) );
// if the script hasn't been loaded, load it
// if the script loads successfully, fire an 'as-script-load' event
echo <<<SCRIPT
<script type='text/javascript'>
//<![CDATA[
if ( typeof window.audioshortcode === 'undefined' ) {
var wp_as_js = document.createElement( 'script' );
wp_as_js.type = 'text/javascript';
wp_as_js.src = $script_url;
wp_as_js.async = true;
wp_as_js.onload = function() {
jQuery( document.body ).trigger( 'as-script-load' );
};
document.getElementsByTagName( 'head' )[0].appendChild( wp_as_js );
} else {
jQuery( document.body ).trigger( 'as-script-load' );
}
//]]>
</script>
SCRIPT;
}
}
/**
* Fixes URLs that have been pasted with spaces:
* [audio http://example.com/Some Cool Music.mp3]
*
* @param string $url
* @return string
*/
function rawurlencode_spaces( $url ) {
return str_replace( ' ', rawurlencode( ' ' ), $url );
}
}
// kick it all off
new AudioShortcode();

View file

@ -0,0 +1,189 @@
<?php
// shortcode handler for [bandcamp], which inserts a bandcamp.com
// music player (iframe, html5)
//
// [bandcamp album=119385304]
// [bandcamp album=3462839126 bgcol=FFFFFF linkcol=4285BB size=venti]
// [bandcamp track=2446959313]
//
function shortcode_handler_bandcamp( $atts ) {
// there are no default values, but specify here anyway
// to explicitly list supported atts
$attributes = shortcode_atts( array(
'album' => null, // integer album id
'track' => null, // integer track id
'video' => null, // integer track id for video player
'size' => 'venti', // one of the supported sizes
'bgcol' => 'FFFFFF', // hex, no '#' prefix
'linkcol' => null, // hex, no '#' prefix
'layout' => null, // encoded layout url
'width' => null, // integer with optional "%"
'height' => null, // integer with optional "%"
'notracklist' => null, // may be string "true" (defaults false)
'tracklist' => null, // may be string "false" (defaults true)
'artwork' => null, // may be string "false" (alternately: "none") or "small" (default is large)
'minimal' => null, // may be string "true" (defaults false)
'theme' => null, // may be theme identifier string ("light"|"dark" so far)
'package' => null, // integer package id
't' => null, // integer track number
'tracks' => null, // comma separated list of allowed tracks
'esig' => null // hex, no '#' prefix
), $atts, 'bandcamp' );
$sizes = array(
'venti' => array( 'width' => 400, 'height' => 100 ),
'grande' => array( 'width' => 300, 'height' => 100 ),
'grande2' => array( 'width' => 300, 'height' => 355 ),
'grande3' => array( 'width' => 300, 'height' => 415 ),
'tall_album' => array( 'width' => 150, 'height' => 295 ),
'tall_track' => array( 'width' => 150, 'height' => 270 ),
'tall2' => array( 'width' => 150, 'height' => 450 ),
'short' => array( 'width' => 46, 'height' => 23 ),
'large' => array( 'width' => 350, 'height' => 470 ),
'medium' => array( 'width' => 450, 'height' => 120 ),
'small' => array( 'width' => 350, 'height' => 42 )
);
$sizekey = $attributes['size'];
$height = null;
$width = null;
$isVideo = false;
// Build iframe url. For audio players, args are appended as
// extra path segments for historical reasons having to
// do with an IE-only flash bug which required this URL
// to contain no querystring. Delay the actual joining
// of args into a string until after we decide if it's
// a video player or an audio player
$argparts = array();
if ( ! isset( $attributes['album'] ) && ! isset( $attributes['track'] ) && ! isset( $attributes['video'] ) ) {
return "[bandcamp: shortcode must include 'track', 'album', or 'video' param]";
}
if ( isset( $attributes['track'] ) && is_numeric( $attributes['track'] ) ) {
$track = esc_attr( $attributes['track'] );
array_push( $argparts, "track={$track}" );
} elseif ( isset( $attributes['video'] ) && is_numeric( $attributes['video'] ) ) {
$track = esc_attr( $attributes['video'] ); // videos are referenced by track id
$urlbase = "//bandcamp.com/EmbeddedPlayer/v=2";
$isVideo = true;
array_push( $argparts, "track={$track}" );
}
if ( isset( $attributes['album'] ) && is_numeric( $attributes['album'] ) ) {
$album = esc_attr( $attributes['album'] );
array_push( $argparts, "album={$album}" );
}
if ( $sizekey == 'tall' ) {
if ( isset( $attributes['album'] ) ) {
$sizekey .= '_album';
} else {
$sizekey .= '_track';
}
}
// if size specified that we don't recognize, fall back on venti
if ( empty( $sizes[ $sizekey ] ) ) {
$sizekey = 'venti';
$attributes['size'] = 'venti';
}
// use strict regex for digits + optional % instead of absint for height/width
// 'width' and 'height' params in the iframe url get the exact string from the shortcode
// args, whereas the inline style attribute must have "px" added to it if it has no "%"
if ( isset( $attributes['width'] ) && preg_match( "|^([0-9]+)(%)?$|", $attributes['width'], $matches ) ) {
$width = $csswidth = $attributes['width'];
if ( sizeof( $matches ) < 3 ) {
$csswidth .= "px";
}
}
if ( isset( $attributes['height'] ) && preg_match( "|^([0-9]+)(%)?$|", $attributes['height'], $matches ) ) {
$height = $cssheight = $attributes['height'];
if ( sizeof( $matches ) < 3 ) {
$cssheight .= "px";
}
}
if ( ! $height ) {
$height = $sizes[ $sizekey ]['height'];
$cssheight = $height . "px";
}
if ( ! $width ) {
$width = $sizes[ $sizekey ]['width'];
$csswidth = $width . "px";
}
if ( isset( $attributes['layout'] ) ) {
array_push( $argparts, "layout={$attributes['layout']}" );
} elseif ( isset( $attributes['size'] ) && preg_match( "|^[a-zA-Z0-9]+$|", $attributes['size'] ) ) {
array_push( $argparts, "size={$attributes['size']}" );
}
if ( isset( $attributes['bgcol'] ) && preg_match( "|^[0-9A-Fa-f]+$|", $attributes['bgcol'] ) ) {
array_push( $argparts, "bgcol={$attributes['bgcol']}" );
}
if ( isset( $attributes['linkcol'] ) && preg_match( "|^[0-9A-Fa-f]+$|", $attributes['linkcol'] ) ) {
array_push( $argparts, "linkcol={$attributes['linkcol']}" );
}
if ( isset( $attributes['package'] ) && preg_match( "|^[0-9]+$|", $attributes['package'] ) ) {
array_push( $argparts, "package={$attributes['package']}" );
}
if ( isset( $attributes['t'] ) && preg_match( "|^[0-9]+$|", $attributes['t'] ) ) {
array_push( $argparts, "t={$attributes['t']}" );
}
if ( $attributes['notracklist'] == "true" ) {
array_push( $argparts, "notracklist=true" );
}
// 'tracklist' arg deprecates 'notracklist=true' to be less weird. note, behavior
// if both are specified is undefined
switch ( $attributes['tracklist'] ) {
case "false":
case "none":
array_push( $argparts, "tracklist=false" );
break;
}
switch ( $attributes['artwork'] ) {
case "false":
case "none":
case "small":
array_push( $argparts, "artwork=" . $attributes['artwork'] );
break;
}
if ( $attributes['minimal'] == "true" ) {
array_push( $argparts, "minimal=true" );
}
if ( isset( $attributes['theme'] ) && preg_match( "|^[a-zA-Z_]+$|", $attributes['theme'] ) ) {
array_push( $argparts, "theme={$attributes['theme']}" );
}
// param 'tracks' is signed digest param 'esig'
if ( isset( $attributes['tracks'] ) && preg_match( "|^[0-9\,]+$|", $attributes['tracks'] ) ) {
if ( isset( $attributes['esig'] ) && preg_match( "|^[0-9A-Fa-f]+$|", $attributes['esig'] ) ) {
array_push( $argparts, "tracks={$attributes['tracks']}" );
array_push( $argparts, "esig={$attributes['esig']}" );
}
}
if ( $isVideo ) {
$url = "//bandcamp.com/VideoEmbed?" . join( '&', $argparts );
$extraAttrs = " mozallowfullscreen='1' webkitallowfullscreen='1' allowfullscreen='1'";
} else {
$url = "//bandcamp.com/EmbeddedPlayer/v=2/" . join( '/', $argparts ) . '/';
$extraAttrs = '';
}
return "<iframe width='" . esc_attr( $width ) . "' height='" . esc_attr( $height ) . "' style='position: relative; display: block; width: " . esc_attr( $csswidth ) . "; height: " . esc_attr( $cssheight ) . ";' src='" . esc_url( $url ) . "' allowtransparency='true' frameborder='0'" . $extraAttrs . "></iframe>";
}
add_shortcode( 'bandcamp', 'shortcode_handler_bandcamp' );

View file

@ -0,0 +1,55 @@
<?php
/**
* Blip.tv embed code:
* <embed src="http://blip.tv/play/g8sVgpfaCgI%2Em4v" type="application/x-shockwave-flash" width="480" height="255" allowscriptaccess="always" allowfullscreen="true"></embed>
* Blip.tv shortcode is: [blip.tv url-or-something-else]
* */
function blip_embed_to_shortcode( $content ) {
if ( false === stripos( $content, '/blip.tv/play/' ) )
return $content;
$regexp = '!<embed((?:\s+\w+="[^"]*")*)\s+src="http(?:\:|&#0*58;)//(blip\.tv/play/[^"]*)"((?:\s+\w+="[^"]*")*)\s*(?:/>|>\s*</embed>)!';
$regexp_ent = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $regexp, ENT_NOQUOTES ) );
foreach ( array( 'regexp', 'regexp_ent' ) as $reg ) {
if ( !preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) )
continue;
foreach ( $matches as $match ) {
$src = 'http://' . html_entity_decode( $match[2] );
$params = $match[1] . $match[3];
if ( 'regexp_ent' == $reg ) {
$src = html_entity_decode( $src );
$params = html_entity_decode( $params );
}
$params = wp_kses_hair( $params, array( 'http' ) );
if ( ! isset( $params['type'] ) || 'application/x-shockwave-flash' != $params['type']['value'] )
continue;
$content = str_replace( $match[0], "[blip.tv $src]", $content );
}
}
return $content;
}
add_filter( 'pre_kses', 'blip_embed_to_shortcode' );
// [blip.tv ?posts_id=4060324&dest=-1]
// [blip.tv http://blip.tv/play/hpZTgffqCAI%2Em4v] // WLS
function blip_shortcode( $atts ) {
if ( ! isset( $atts[0] ) )
return '';
$src = $atts[0];
if ( preg_match( '/^\?posts_id=(\d+)&[^d]*dest=(-?\d+)$/', $src, $matches ) )
return "<script type='text/javascript' src='http://blip.tv/syndication/write_player?skin=js&posts_id={$matches[1]}&cross_post_destination={$matches[2]}&view=full_js'></script>";
elseif ( preg_match( '|^http://blip.tv/play/[.\w]+$|', urldecode( $src ) ) ) // WLS
return "<embed src='$src' type='application/x-shockwave-flash' width='480' height='300' allowscriptaccess='never' allowfullscreen='true'></embed>";
return "<!--blip.tv pattern not matched -->";
}
add_shortcode( 'blip.tv', 'blip_shortcode' );

View file

@ -0,0 +1,18 @@
<?php
/*
* CartoDB
*
* example URL: http://osm2.cartodb.com/viz/08aef918-94da-11e4-ad83-0e0c41326911/public_map
*
* possible patterns:
* [username].cartodb.com/viz/[map-id]/public_map
* [username].cartodb.com/viz/[map-id]/embed_map
* [username].cartodb.com/viz/[map-id]/map
* [organization].cartodb.com/u/[username]/viz/[map-id]/public_map
* [organization].cartodb.com/u/[username]/viz/[map-id]/embed_map
* [organization].cartodb.com/u/[username]/viz/[map-id]/map
*/
wp_oembed_add_provider( '#https?://(?:www\.)?[^/^\.]+\.cartodb\.com/\S+#i', 'https://services.cartodb.com/oembed', true );

View file

@ -0,0 +1,10 @@
<?php
/*
* CodePen embed
*
* example URL: http://codepen.io/css-tricks/pen/wFeaG
*/
// Register oEmbed provider
wp_oembed_add_provider( '#https?://codepen.io/([^/]+)/pen/([^/]+)/?#', 'https://codepen.io/api/oembed', true );

View file

@ -0,0 +1,3 @@
.jetpack-recipe-meta li.jetpack-recipe-print {
display: none;
}

View file

@ -0,0 +1,33 @@
.jetpack-recipe {
border: 1px solid #f2f2f2;
border-radius: 1px;
clear: both;
margin: 1.5em 1%;
padding: 1% 2%;
}
.jetpack-recipe-title {
border-bottom: 1px solid #ccc;
margin: .25em 0;
padding: .25em 0;
}
.jetpack-recipe .jetpack-recipe-meta {
display: block;
font-size: .9em;
list-style-type: none;
margin-right: 0;
margin-left: 0;
padding: 0;
overflow: hidden;
width: 100%;
}
.jetpack-recipe .jetpack-recipe-meta li {
float: left;
list-style-type: none;
margin: 0;
padding: 0 5% 0 0;
}
.jetpack-recipe-meta li.jetpack-recipe-print {
float: right;
padding-right: 0;
text-align: right;
}

View file

@ -0,0 +1,35 @@
/* This file was automatically generated on Feb 24 2014 16:44:25 */
.jetpack-recipe {
border: 1px solid #f2f2f2;
border-radius: 1px;
clear: both;
margin: 1.5em 1%;
padding: 1% 2%;
}
.jetpack-recipe-title {
border-bottom: 1px solid #ccc;
margin: .25em 0;
padding: .25em 0;
}
.jetpack-recipe .jetpack-recipe-meta {
display: block;
font-size: .9em;
list-style-type: none;
margin-left: 0;
margin-right: 0;
padding: 0;
overflow: hidden;
width: 100%;
}
.jetpack-recipe .jetpack-recipe-meta li {
float: right;
list-style-type: none;
margin: 0;
padding: 0 0 0 5%;
}
.jetpack-recipe-meta li.jetpack-recipe-print {
float: left;
padding-left: 0;
text-align: left;
}

View file

@ -0,0 +1,159 @@
/* This file was automatically generated on May 26 2015 21:25:53 */
.slideshow-window {
background-color: #222;
border: 20px solid #222;
border-radius: 10px;
height: 0;
margin-bottom: 20px;
overflow: hidden;
padding-top: 30px !important;
padding-bottom: 56.25% !important;
position: relative;
z-index: 1;
}
.slideshow-window.slideshow-white {
background-color: #fff;
border-color: #fff;
}
.slideshow-window, .slideshow-window * {
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
}
.slideshow-loading {
height: 100%;
text-align: center;
margin: auto;
}
body div.slideshow-window * img {
/* Override any styles that might be present in the page stylesheet */
background-color: transparent !important;
background-image: none !important;
border-width: 0 !important;
display: block;
margin: 0 auto;
max-width: 100%;
max-height: 100%;
padding: 0 !important;
position: relative;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
top: 50%;
}
.slideshow-loading img {
vertical-align: middle;
}
.slideshow-slide {
display: none;
height: 100% !important;
right: 0;
margin: auto;
position: absolute;
text-align: center;
top: 0;
width: 100% !important;
}
.slideshow-slide img {
vertical-align: middle;
}
.slideshow-line-height-hack {
overflow: hidden;
width: 0px;
font-size: 0px;
}
.slideshow-slide-caption {
font-size: 13px;
font-family: "Helvetica Neue", sans-serif;
color: #f7f7f7;
text-shadow: #222 2px 1px 1px;
line-height: 25px;
height: 25px;
position: absolute;
bottom: 5px;
right: 0;
z-index: 100;
width: 100%;
text-align: center;
}
/* @noflip */
.slideshow-controls {
z-index: 1000;
position: absolute;
bottom: 30px;
margin: auto;
text-align: center;
width: 100%;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
opacity: 0.5;
direction:ltr;
-webkit-transition: 300ms opacity ease-out;
-moz-transition: 300ms opacity ease-out;
transition: 300ms opacity ease-out;
}
.slideshow-window:hover .slideshow-controls {
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
opacity: 1;
}
body div div.slideshow-controls a,
body div div.slideshow-controls a:hover {
border:2px solid rgba(255,255,255,0.1) !important;
background-color: #000 !important;
background-color: rgba(0,0,0,0.6) !important;
background-image: url('../../img/slideshow-controls.png') !important;
background-repeat: no-repeat;
background-size: 142px 16px !important;
background-position: -34px 8px !important;
color: #222 !important;
margin: 0 5px !important;
padding: 0 !important;
display: inline-block !important;
*display: inline;
zoom: 1;
height: 32px !important;
width: 32px !important;
line-height: 32px !important;
text-align: center !important;
-khtml-border-radius: 10em !important;
-webkit-border-radius: 10em !important;
-moz-border-radius: 10em !important;
border-radius: 10em !important;
-webkit-transition: 300ms border-color ease-out;
-moz-transition: 300ms border-color ease-out;
-o-transition: 300ms border-color ease-out;
transition: 300ms border-color ease-out;
}
@media only screen and (-webkit-min-device-pixel-ratio: 1.5) {
body div div.slideshow-controls a,
body div div.slideshow-controls a:hover {
background-image: url('../../img/slideshow-controls-2x.png') !important;
}
}
body div div.slideshow-controls a:hover {
border-color: rgba(255,255,255,1) !important;
}
body div div.slideshow-controls a:first-child { background-position: -76px 8px !important;}
body div div.slideshow-controls a:last-child { background-position: -117px 8px !important;}
body div div.slideshow-controls a:nth-child(2) { background-position: -34px 8px !important;}
body div div.slideshow-controls a.running { background-position: -34px 8px !important;}
body div div.slideshow-controls a.paused { background-position: 9px 8px !important;}
.slideshow-controls a img {
border: 50px dotted fuchsia;
}

View file

@ -0,0 +1,157 @@
.slideshow-window {
background-color: #222;
border: 20px solid #222;
border-radius: 10px;
height: 0;
margin-bottom: 20px;
overflow: hidden;
padding-top: 30px !important;
padding-bottom: 56.25% !important;
position: relative;
z-index: 1;
}
.slideshow-window.slideshow-white {
background-color: #fff;
border-color: #fff;
}
.slideshow-window, .slideshow-window * {
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
}
.slideshow-loading {
height: 100%;
text-align: center;
margin: auto;
}
body div.slideshow-window * img {
/* Override any styles that might be present in the page stylesheet */
background-color: transparent !important;
background-image: none !important;
border-width: 0 !important;
display: block;
margin: 0 auto;
max-width: 100%;
max-height: 100%;
padding: 0 !important;
position: relative;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
top: 50%;
}
.slideshow-loading img {
vertical-align: middle;
}
.slideshow-slide {
display: none;
height: 100% !important;
left: 0;
margin: auto;
position: absolute;
text-align: center;
top: 0;
width: 100% !important;
}
.slideshow-slide img {
vertical-align: middle;
}
.slideshow-line-height-hack {
overflow: hidden;
width: 0px;
font-size: 0px;
}
.slideshow-slide-caption {
font-size: 13px;
font-family: "Helvetica Neue", sans-serif;
color: #f7f7f7;
text-shadow: #222 1px 1px 2px;
line-height: 25px;
height: 25px;
position: absolute;
bottom: 5px;
left: 0;
z-index: 100;
width: 100%;
text-align: center;
}
/* @noflip */
.slideshow-controls {
z-index: 1000;
position: absolute;
bottom: 30px;
margin: auto;
text-align: center;
width: 100%;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
opacity: 0.5;
direction:ltr;
-webkit-transition: 300ms opacity ease-out;
-moz-transition: 300ms opacity ease-out;
transition: 300ms opacity ease-out;
}
.slideshow-window:hover .slideshow-controls {
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
opacity: 1;
}
body div div.slideshow-controls a,
body div div.slideshow-controls a:hover {
border:2px solid rgba(255,255,255,0.1) !important;
background-color: #000 !important;
background-color: rgba(0,0,0,0.6) !important;
background-image: url('../img/slideshow-controls.png') !important;
background-repeat: no-repeat;
background-size: 142px 16px !important;
background-position: -34px 8px !important;
color: #222 !important;
margin: 0 5px !important;
padding: 0 !important;
display: inline-block !important;
*display: inline;
zoom: 1;
height: 32px !important;
width: 32px !important;
line-height: 32px !important;
text-align: center !important;
-khtml-border-radius: 10em !important;
-webkit-border-radius: 10em !important;
-moz-border-radius: 10em !important;
border-radius: 10em !important;
-webkit-transition: 300ms border-color ease-out;
-moz-transition: 300ms border-color ease-out;
-o-transition: 300ms border-color ease-out;
transition: 300ms border-color ease-out;
}
@media only screen and (-webkit-min-device-pixel-ratio: 1.5) {
body div div.slideshow-controls a,
body div div.slideshow-controls a:hover {
background-image: url('../img/slideshow-controls-2x.png') !important;
}
}
body div div.slideshow-controls a:hover {
border-color: rgba(255,255,255,1) !important;
}
body div div.slideshow-controls a:first-child { background-position: -76px 8px !important;}
body div div.slideshow-controls a:last-child { background-position: -117px 8px !important;}
body div div.slideshow-controls a:nth-child(2) { background-position: -34px 8px !important;}
body div div.slideshow-controls a.running { background-position: -34px 8px !important;}
body div div.slideshow-controls a.paused { background-position: 9px 8px !important;}
.slideshow-controls a img {
border: 50px dotted fuchsia;
}

View file

@ -0,0 +1,188 @@
/**
* 1. Fullscreen styles
*/
html.presentation-wrapper-fullscreen-parent,
body.presentation-wrapper-fullscreen-parent {
overflow: hidden !important;
}
.presentation-wrapper-fullscreen-parent #wpadminbar {
display: none;
}
.presentation-wrapper-fullscreen,
.presentation-wrapper-fullscreen-parent {
min-width: 100% !important;
min-height: 100% !important;
position: absolute !important;
top: 0 !important;
right: 0 !important;
bottom: 0 !important;
left: 0 !important;
margin: 0 !important;
padding: 0 !important;
z-index: 10000 !important;
}
.presentation-wrapper-fullscreen {
background-color: #808080;
border: none !important;
}
.presentation-wrapper-fullscreen .nav-arrow-left,
.presentation-wrapper-fullscreen .nav-arrow-right {
z-index: 20001;
}
.presentation-wrapper-fullscreen .nav-fullscreen-button {
z-index: 20002;
}
/**
* 2. General presentation styles
*/
.presentation-wrapper {
margin: 20px auto;
border: 1px solid #e5e5e5;
overflow: hidden;
line-height: normal;
}
.presentation {
position: relative;
margin: 0;
overflow: hidden;
outline: none;
}
/**
* jmpress requires that step sizes are explicitly defined
* as it inserts sizeless divs before the steps. These
* dimensions are set by the js code on initialization
*/
.presentation,
.presentation .step {
background-repeat: no-repeat;
background-position: center;
background-size: 100% 100%;
}
/**
* Opacity transition durations are set by the js code
* so they match the presentation animation durations
*/
.presentation .step.fade:not(.active) {
opacity: 0;
}
.presentation .slide-content {
padding: 30px;
}
/**
* 3. Styles for the navigation arrows
*/
.presentation .nav-arrow-left,
.presentation .nav-arrow-right,
.presentation .nav-fullscreen-button {
position: absolute;
width: 34px;
background-repeat: no-repeat;
z-index: 2;
opacity: 0;
-webkit-transition : opacity .25s;
-moz-transition : opacity .25s;
-ms-transition : opacity .25s;
-o-transition : opacity .25s;
transition : opacity .25s;
}
.presentation .nav-arrow-left,
.presentation .nav-arrow-right {
height: 100%;
background-image: url(../images/slide-nav.png);
background-size: 450% 61px;
}
.presentation .nav-arrow-left {
left: 0;
background-position: 4px 50%;
}
.presentation .nav-arrow-right {
right: 0;
background-position: -120px 50%;
}
.presentation .nav-fullscreen-button {
width: 32px;
height: 32px;
margin: 4px;
bottom: 0;
right: 0;
z-index: 3;
background-image: url(../images/expand.png);
background-size: 100% 100%;
}
.presentation:hover .nav-arrow-left,
.presentation:hover .nav-arrow-right {
opacity: 1;
}
.presentation:hover .nav-fullscreen-button {
opacity: 0.8;
}
.presentation-wrapper-fullscreen .nav-fullscreen-button {
background-image: url(../images/collapse.png);
}
/**
* 4. Styles for the autoplay overlay
*/
.presentation .autoplay-overlay {
height: 15%;
width: 80%;
margin: 30% 10%;
position: relative;
z-index: 100;
display: table;
border-radius: 50px;
background-color: #e5e5e5;
background-color: rgba(0, 0, 0, 0.75);
-webkit-transition : opacity .5s;
-moz-transition : opacity .5s;
-ms-transition : opacity .5s;
-o-transition : opacity .5s;
transition : opacity .5s;
}
.presentation .autoplay-overlay .overlay-msg {
position: relative;
display: table-cell;
text-align: center;
vertical-align: middle;
color: #fff;
}
/**
* 5. Styles for fading steps
*/
.presentation .will-fade {
opacity: 0;
}
.presentation .do-fade {
opacity: 1;
-webkit-transition : opacity .5s;
-moz-transition : opacity .5s;
-ms-transition : opacity .5s;
-o-transition : opacity .5s;
transition : opacity .5s;
}

View file

@ -0,0 +1,249 @@
<?php
/**
* Dailymotion code
* */
/**
* Original codes:
*
* <embed height="270" type="application/x-shockwave-flash" width="480" src="http&#58;//www.dailymotion.com/swf/video/xekmrq?additionalInfos=0" wmode="opaque" pluginspage="http&#58;//www.macromedia.com/go/getflashplayer" allowscriptaccess="never" allownetworking="internal" />
*
* <object width="480" height="240"><param name="movie" value="http://www.dailymotion.com/swf/video/xen4ms_ghinzu-cold-love-mirror-mirror_music?additionalInfos=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param>
* <embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/xen4ms_ghinzu-cold-love-mirror-mirror_music?additionalInfos=0" width="480" height="240" allowfullscreen="true" allowscriptaccess="always"></embed>
* </object><br /><b><a href="http://www.dailymotion.com/video/xen4ms_ghinzu-cold-love-mirror-mirror_music">Ghinzu - Cold Love (Mirror Mirror)</a></b><br /><i>Uploaded by <a href="http://www.dailymotion.com/GhinzuTV">GhinzuTV</a>. - <a href="http://www.dailymotion.com/us/channel/music">Watch more music videos, in HD!</a></i>
*
* Code as of 01.01.11:
* <object width="560" height="421"><param name="movie" value="http://www.dailymotion.com/swf/video/xaose5?width=560&theme=denim&foreground=%2392ADE0&highlight=%23A2ACBF&background=%23202226&start=&animatedTitle=&iframe=0&additionalInfos=0&autoPlay=0&hideInfos=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/xaose5?width=560&theme=denim&foreground=%2392ADE0&highlight=%23A2ACBF&background=%23202226&start=&animatedTitle=&iframe=0&additionalInfos=0&autoPlay=0&hideInfos=0" width="560" height="421" allowfullscreen="true" allowscriptaccess="always"></embed></object><br /><b><a href="http://www.dailymotion.com/video/x29zm17_funny-videos-of-cats-and-babies-compilation-2015_fun">Funny cats and babies!</a></b><br /><i>Uploaded by <a href="http://www.dailymotion.com/GilLavie">GilLavie</a>. - <a target="_self" href="http://www.dailymotion.com/channel/funny/featured/1">Find more funny videos.</a></i>
* movie param enforces anti-xss protection
*
* Scroll down for the new <iframe> embed code handler.
*/
function dailymotion_embed_to_shortcode( $content ) {
if ( false === stripos( $content, 'www.dailymotion.com/swf/' ) ) {
return $content;
}
$regexp = '!<object.*>\s*(<param.*></param>\s*)*<embed((?:\s+\w+="[^"]*")*)\s+src="http(?:\:|&#0*58;)//(www\.dailymotion\.com/swf/[^"]*)"((?:\s+\w+="[^"]*")*)\s*(?:/>|>\s*</embed>)\s*</object><br /><b><a .*>.*</a></b><br /><i>.*</i>!';
$regexp_ent = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $regexp, ENT_NOQUOTES ) );
foreach ( array( 'regexp', 'regexp_ent' ) as $reg ) {
if ( ! preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) {
continue;
}
foreach ( $matches as $match ) {
$src = html_entity_decode( $match[3] );
$params = $match[2] . $match[4];
if ( 'regexp_ent' == $reg ) {
$src = html_entity_decode( $src );
$params = html_entity_decode( $params );
}
$params = wp_kses_hair( $params, array( 'http' ) );
if ( ! isset( $params['type'] ) || 'application/x-shockwave-flash' != $params['type']['value'] ) {
continue;
}
$id = basename( substr( $src, strlen( 'www.dailymotion.com/swf' ) ) );
$id = preg_replace( '/[^a-z0-9].*$/i', '', $id );
$content = str_replace( $match[0], "[dailymotion id=$id]", $content );
/** This action is documented in modules/shortcodes/youtube.php */
do_action( 'jetpack_embed_to_shortcode', 'dailymotion', $id );
}
}
return $content;
}
add_filter( 'pre_kses', 'dailymotion_embed_to_shortcode' );
/**
* DailyMotion shortcode
*
* The documented shortcode is:
* [dailymotion id=x8oma9]
*
* Possibilities, according to the old parsing regexp:
* [dailymotion x8oma9]
* [dailymotion=x8oma9]
*
* Hypothetical option, according to the old shortcode function is
* [dailymotion id=1&title=2&user=3&video=4]
*
* The new style is now:
* [dailymotion id=x8oma9 title=2 user=3 video=4]
* @todo: Update code to sniff for iframe embeds and convert those to shortcodes.
*
* @param array $atts
* @return string html
*
*/
function dailymotion_shortcode( $atts ) {
global $content_width;
if ( isset( $atts[0] ) ) {
$id = ltrim( $atts[0], '=' );
$atts['id'] = $id;
} else {
$params = shortcode_new_to_old_params( $atts );
parse_str( $params, $atts_new );
foreach( $atts_new as $k => $v ) {
$atts[ $k ] = $v;
}
}
if ( isset( $atts['id'] ) ) {
$id = $atts['id'];
} else {
return '<!--Dailymotion error: bad or missing ID-->';
}
if ( ! empty( $content_width ) ) {
$width = min( 425, intval( $content_width ) );
} else {
$width = 425;
}
$height = ( 425 == $width ) ? 334 : ( $width / 425 ) * 334;
$id = urlencode( $id );
if ( preg_match( '/^[A-Za-z0-9]+$/', $id ) ) {
$output = '<iframe width="' . $width . '" height="' . $height . '" src="' . esc_url( '//www.dailymotion.com/embed/video/' . $id ) . '" frameborder="0"></iframe>';
$after = '';
if ( array_key_exists( 'video', $atts ) && $video = preg_replace( '/[^-a-z0-9_]/i', '', $atts['video'] ) && array_key_exists( 'title', $atts ) && $title = wp_kses( $atts['title'], array() ) ) {
$after .= '<br /><strong><a href="' . esc_url( 'http://www.dailymotion.com/video/' . $video ) . '" target="_blank">' . esc_html( $title ) . '</a></strong>';
}
if ( array_key_exists( 'user', $atts ) && $user = preg_replace( '/[^-a-z0-9_]/i', '', $atts['user'] ) ) {
$after .= '<br /><em>Uploaded by <a href="' . esc_url( 'http://www.dailymotion.com/' . $user ) . '" target="_blank">' . esc_html( $user ) . '</a></em>';
}
}
return $output . $after;
}
add_shortcode( 'dailymotion', 'dailymotion_shortcode' );
/**
* DailyMotion Channel Shortcode
*
* Examples:
* [dailymotion-channel user=MatthewDominick]
* [dailymotion-channel user=MatthewDominick type=grid] (supports grid, carousel, badge/default)
*/
function dailymotion_channel_shortcode( $atts ) {
$username = $atts['user'];
switch( $atts['type'] ) {
case 'grid':
return '<iframe width="300px" height="264px" scrolling="no" frameborder="0" src="' . esc_url( '//www.dailymotion.com/badge/user/' . $username . '?type=grid' ) . '"></iframe>';
break;
case 'carousel':
return '<iframe width="300px" height="360px" scrolling="no" frameborder="0" src="' . esc_url( '//www.dailymotion.com/badge/user/' . $username . '?type=carousel' ) . '"></iframe>';
break;
default:
return '<iframe width="300px" height="78px" scrolling="no" frameborder="0" src="' . esc_url( '//www.dailymotion.com/badge/user/' . $username ) . '"></iframe>';
}
}
add_shortcode( 'dailymotion-channel', 'dailymotion_channel_shortcode' );
/**
* Embed Reversal for Badge/Channel
*/
function dailymotion_channel_reversal( $content ) {
if ( false === stripos( $content, 'dailymotion.com/badge/' ) ) {
return $content;
}
/* Sample embed code:
<iframe width="300px" height="360px" scrolling="no" frameborder="0" src="http://www.dailymotion.com/badge/user/Dailymotion?type=carousel"></iframe>
*/
$regexes = array();
$regexes[] = '#<iframe[^>]+?src=" (?:https?:)?//(?:www\.)?dailymotion\.com/badge/user/([^"\'/]++) "[^>]*+></iframe>#ix';
// Let's play nice with the visual editor too.
$regexes[] = '#&lt;iframe(?:[^&]|&(?!gt;))+?src=" (?:https?:)?//(?:www\.)?dailymotion\.com/badge/user/([^"\'/]++) "(?:[^&]|&(?!gt;))*+&gt;&lt;/iframe&gt;#ix';
foreach ( $regexes as $regex ) {
if ( ! preg_match_all( $regex, $content, $matches, PREG_SET_ORDER ) ) {
continue;
}
foreach ( $matches as $match ) {
$url_pieces = parse_url( $match[1] );
if ( 'type=carousel' === $url_pieces['query'] ) {
$type = 'carousel';
} else if ( 'type=grid' === $url_pieces['query'] ) {
$type = 'grid';
} else {
$type = 'badge';
}
$shortcode = '[dailymotion-channel user=' . esc_attr( $url_pieces['path'] ) . ' type=' . esc_attr( $type ) . ']';
$replace_regex = sprintf( '#\s*%s\s*#', preg_quote( $match[0], '#' ) );
$content = preg_replace( $replace_regex, sprintf( "\n\n%s\n\n", $shortcode ), $content );
}
}
return $content;
}
add_filter( 'pre_kses', 'dailymotion_channel_reversal' );
/**
* Dailymotion Embed Reversal (with new iframe code as of 17.09.2014)
*
* Converts a generic HTML embed code from Dailymotion into an
* oEmbeddable URL.
*/
function jetpack_dailymotion_embed_reversal( $content ) {
if ( false === stripos( $content, 'dailymotion.com/embed' ) ) {
return $content;
}
/* Sample embed code as of Sep 17th 2014:
<iframe frameborder="0" width="480" height="270" src="//www.dailymotion.com/embed/video/x25x71x" allowfullscreen></iframe><br /><a href="http://www.dailymotion.com/video/x25x71x_dog-with-legs-in-casts-learns-how-to-enter-the-front-door_animals" target="_blank">Dog with legs in casts learns how to enter the...</a> <i>by <a href="http://www.dailymotion.com/videobash" target="_blank">videobash</a></i>
*/
$regexes = array();
// I'm Konstantin and I love regex.
$regexes[] = '#<iframe[^>]+?src=" (?:https?:)?//(?:www\.)?dailymotion\.com/embed/video/([^"\'/]++) "[^>]*+>\s*+</iframe>\s*+(?:<br\s*+/>)?\s*+
(?: <a[^>]+?href=" (?:https?:)?//(?:www\.)?dailymotion\.com/[^"\']++ "[^>]*+>.+?</a>\s*+ )?
(?: <i>.*?<a[^>]+?href=" (?:https?:)?//(?:www\.)?dailymotion\.com/[^"\']++ "[^>]*+>.+?</a>\s*+</i> )?#ix';
$regexes[] = '#&lt;iframe(?:[^&]|&(?!gt;))+?src=" (?:https?:)?//(?:www\.)?dailymotion\.com/embed/video/([^"\'/]++) "(?:[^&]|&(?!gt;))*+&gt;\s*+&lt;/iframe&gt;\s*+(?:&lt;br\s*+/&gt;)?\s*+
(?: &lt;a(?:[^&]|&(?!gt;))+?href=" (?:https?:)?//(?:www\.)?dailymotion\.com/[^"\']++ "(?:[^&]|&(?!gt;))*+&gt;.+?&lt;/a&gt;\s*+ )?
(?: &lt;i&gt;.*?&lt;a(?:[^&]|&(?!gt;))+?href=" (?:https?:)?//(?:www\.)?dailymotion\.com/[^"\']++ "(?:[^&]|&(?!gt;))*+&gt;.+?&lt;/a&gt;\s*+&lt;/i&gt; )?#ix';
foreach ( $regexes as $regex ) {
if ( ! preg_match_all( $regex, $content, $matches, PREG_SET_ORDER ) ) {
continue;
}
foreach ( $matches as $match ) {
$url = esc_url( sprintf( 'https://dailymotion.com/video/%s', $match[1] ) );
$replace_regex = sprintf( '#\s*%s\s*#', preg_quote( $match[0], '#' ) );
$content = preg_replace( $replace_regex, sprintf( "\n\n%s\n\n", $url ), $content );
/** This action is documented in modules/shortcodes/youtube.php */
do_action( 'jetpack_embed_to_shortcode', 'dailymotion', $url );
}
}
return $content;
}
add_filter( 'pre_kses', 'jetpack_dailymotion_embed_reversal' );

View file

@ -0,0 +1,11 @@
<?php
/**
* Digg's API is no more and support has been removed
*/
function digg_shortcode( $atts ) {
return '';
}
add_shortcode( 'digg', 'digg_shortcode' );

View file

@ -0,0 +1,63 @@
<?php
/**
* Facebook embeds
*/
define( 'JETPACK_FACEBOOK_EMBED_REGEX', '#^https?://(www.)?facebook\.com/([^/]+)/(posts|photos)/([^/]+)?#' );
define( 'JETPACK_FACEBOOK_ALTERNATE_EMBED_REGEX', '#^https?://(www.)?facebook\.com/permalink.php\?([^\s]+)#' );
define( 'JETPACK_FACEBOOK_PHOTO_EMBED_REGEX', '#^https?://(www.)?facebook\.com/photo.php\?([^\s]+)#' );
define( 'JETPACK_FACEBOOK_PHOTO_ALTERNATE_EMBED_REGEX', '#^https?://(www.)?facebook\.com/([^/]+)/photos/([^/]+)?#' );
define( 'JETPACK_FACEBOOK_VIDEO_EMBED_REGEX', '#^https?://(www.)?facebook\.com/video.php\?([^\s]+)#' );
define( 'JETPACK_FACEBOOK_VIDEO_ALTERNATE_EMBED_REGEX', '#^https?://(www.)?facebook\.com/([^/]+)/videos/([^/]+)?#' );
// Example URL: https://www.facebook.com/VenusWilliams/posts/10151647007373076
wp_embed_register_handler( 'facebook', JETPACK_FACEBOOK_EMBED_REGEX, 'jetpack_facebook_embed_handler' );
// Example URL: https://www.facebook.com/permalink.php?id=222622504529111&story_fbid=559431180743788
wp_embed_register_handler( 'facebook-alternate', JETPACK_FACEBOOK_ALTERNATE_EMBED_REGEX, 'jetpack_facebook_embed_handler' );
// Photos are handled on a different endpoint; e.g. https://www.facebook.com/photo.php?fbid=10151609960150073&set=a.398410140072.163165.106666030072&type=1
wp_embed_register_handler( 'facebook-photo', JETPACK_FACEBOOK_PHOTO_EMBED_REGEX, 'jetpack_facebook_embed_handler' );
// Photos (from pages for example) can be at
wp_embed_register_handler( 'facebook-alternate-photo', JETPACK_FACEBOOK_PHOTO_ALTERNATE_EMBED_REGEX, 'jetpack_facebook_embed_handler' );
// Videos e.g. https://www.facebook.com/video.php?v=772471122790796
wp_embed_register_handler( 'facebook-video', JETPACK_FACEBOOK_VIDEO_EMBED_REGEX, 'jetpack_facebook_embed_handler' );
// Videos https://www.facebook.com/WhiteHouse/videos/10153398464269238/
wp_embed_register_handler( 'facebook-alternate-video', JETPACK_FACEBOOK_VIDEO_ALTERNATE_EMBED_REGEX, 'jetpack_facebook_embed_handler' );
function jetpack_facebook_embed_handler( $matches, $attr, $url ) {
if ( false !== strpos( $url, 'video.php' ) || false !== strpos( $url, '/videos/' ) ) {
$embed = sprintf( '<div class="fb-video" data-allowfullscreen="true" data-href="%s"></div>', esc_url( $url ) );
} else {
$embed = sprintf( '<fb:post href="%s"></fb:post>', esc_url( $url ) );
}
// since Facebook is a faux embed, we need to load the JS SDK in the wpview embed iframe
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && ! empty( $_POST['action'] ) && 'parse-embed' == $_POST['action'] ) {
return $embed . wp_scripts()->do_items( array( 'jetpack-facebook-embed' ) );
} else {
wp_enqueue_script( 'jetpack-facebook-embed' );
return $embed;
}
}
add_shortcode( 'facebook', 'jetpack_facebook_shortcode_handler' );
function jetpack_facebook_shortcode_handler( $atts ) {
global $wp_embed;
if ( empty( $atts['url'] ) )
return;
if ( ! preg_match( JETPACK_FACEBOOK_EMBED_REGEX, $atts['url'] )
&& ! preg_match( JETPACK_FACEBOOK_PHOTO_EMBED_REGEX, $atts['url'] )
&& ! preg_match( JETPACK_FACEBOOK_VIDEO_EMBED_REGEX, $atts['url'] )
&& ! preg_match( JETPACK_FACEBOOK_VIDEO_ALTERNATE_EMBED_REGEX, $atts['url'] ) ) {
return;
}
return $wp_embed->shortcode( $atts, $atts['url'] );
}

View file

@ -0,0 +1,199 @@
<?php
/*
Flickr Short Code
Author: kellan
License: BSD/GPL/public domain (take your pick)
[flickr video=http://www.flickr.com/photos/chaddles/2402990826]
[flickr video=2402990826]
[flickr video=2402990826 show_info=no]
[flickr video=2402990826 w=200 h=150]
[flickr video=2402990826 secret=846d9c1b39]
*/
/*
* <object type="application/x-shockwave-flash" width="400" height="300" data="http://www.flickr.com/apps/video/stewart.swf?v=71377" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"> <param name="flashvars" value="intl_lang=en-us&photo_secret=846d9c1be9&photo_id=2345938910"></param> <param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=71377"></param> <param name="bgcolor" value="#000000"></param> <param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=71377" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&photo_secret=846d9c1be9&photo_id=2345938910" height="300" width="400"></embed></object>
*/
function flickr_embed_to_shortcode( $content ) {
if ( false === stripos( $content, '/www.flickr.com/apps/video/stewart.swf' ) ) {
return $content;
}
$regexp = '%(<object.*?(?:<(?!/?(?:object|embed)\s+).*?)*?)?<embed((?:\s+\w+="[^"]*")*)\s+src="http(?:\:|&#0*58;)//www.flickr.com/apps/video/stewart.swf[^"]*"((?:\s+\w+="[^"]*")*)\s*(?:/>|>\s*</embed>)(?(1)\s*</object>)%';
$regexp_ent = str_replace(
array(
'&amp;#0*58;',
'[^&gt;]*',
'[^&lt;]*',
),
array(
'&amp;#0*58;|&#0*58;',
'[^&]*(?:&(?!gt;)[^&]*)*',
'[^&]*(?:&(?!lt;)[^&]*)*',
),
htmlspecialchars( $regexp, ENT_NOQUOTES )
);
foreach ( array( 'regexp', 'regexp_ent' ) as $reg ) {
if ( ! preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) {
continue;
}
foreach ( $matches as $match ) {
$params = $match[2] . $match[3];
if ( 'regexp_ent' == $reg ) {
$params = html_entity_decode( $params );
}
$params = wp_kses_hair( $params, array( 'http' ) );
if ( ! isset( $params['type'] ) || 'application/x-shockwave-flash' != $params['type']['value'] || ! isset( $params['flashvars'] ) ) {
continue;
}
wp_parse_str( html_entity_decode( $params['flashvars']['value'] ), $flashvars );
if ( ! isset( $flashvars['photo_id'] ) ) {
continue;
}
$code_atts = array( 'video' => $flashvars['photo_id'], );
if ( isset( $flashvars['flickr_show_info_box'] ) && 'true' == $flashvars['flickr_show_info_box'] ) {
$code_atts['show_info'] = 'true';
}
if ( ! empty( $flashvars['photo_secret'] ) ) {
$code_atts['secret'] = $flashvars['photo_secret'];
}
if ( ! empty( $params['width']['value'] ) ) {
$code_atts['w'] = (int) $params['width']['value'];
}
if ( ! empty( $params['height']['value'] ) ) {
$code_atts['h'] = (int) $params['height']['value'];
}
$code = '[flickr';
foreach ( $code_atts as $k => $v ) {
$code .= " $k=$v";
}
$code .= ']';
$content = str_replace( $match[0], $code, $content );
/** This action is documented in modules/shortcodes/youtube.php */
do_action( 'jetpack_embed_to_shortcode', 'flickr_video', $flashvars['photo_id'] );
}
}
return $content;
}
add_filter( 'pre_kses', 'flickr_embed_to_shortcode' );
function flickr_shortcode_handler( $atts ) {
$atts = shortcode_atts(
array(
'video' => 0,
'photo' => 0,
'show_info' => 0,
'w' => 400,
'h' => 300,
'secret' => 0,
'size' => 0,
), $atts, 'flickr'
);
if ( ! empty( $atts['video'] ) ) {
$showing = 'video';
$src = $atts['video'];
} elseif ( ! empty( $atts['photo'] ) ) {
$showing = 'photo';
$src = $atts['photo'];
} else {
return '';
}
if ( is_ssl() ) {
$src = str_replace( 'http://', 'https://', $src );
}
if ( 'video' === $showing ) {
if ( ! is_numeric( $src ) && ! preg_match( '~^(https?:)?//([\da-z\-]+\.)*?((static)?flickr\.com|flic\.kr)/.*~i', $src ) ) {
return '';
}
if ( preg_match( '!photos/(([0-9a-zA-Z-_]+)|([0-9]+@N[0-9]+))/([0-9]+)/?$!', $src, $m ) ) {
$atts['photo_id'] = $m[4];
} else {
$atts['photo_id'] = $atts['video'];
}
if ( ! isset( $atts['show_info'] ) || in_array( $atts['show_info'], array( 'yes', 'true' ) ) ) {
$atts['show_info'] = 'true';
} elseif ( in_array( $atts['show_info'], array( 'false', 'no' ) ) ) {
$atts['show_info'] = 'false';
}
if ( isset( $atts['secret'] ) ) {
$atts['secret'] = preg_replace( '![^\w]+!i', '', $atts['secret'] );
}
return flickr_shortcode_video_markup( $atts );
} elseif ( 'photo' == $showing ) {
if ( ! preg_match( '~^(https?:)?//([\da-z\-]+\.)*?((static)?flickr\.com|flic\.kr)/.*~i', $src ) ) {
return '';
}
$src = sprintf( '%s/player/', untrailingslashit( $src ) );
return sprintf( '<iframe src="%s" height="%s" width="%s" frameborder="0" allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen></iframe>', esc_url( $src ), esc_attr( $atts['h'] ), esc_attr( $atts['w'] ) );
}
return false;
}
function flickr_shortcode_video_markup( $atts ) {
$atts = array_map( 'esc_attr', $atts );
$http = ( is_ssl() ) ? 'https://' : 'http://';
$photo_vars = "photo_id=$atts[photo_id]";
if ( isset( $atts['secret'] ) ) {
$photo_vars .= "&amp;photo_secret=$atts[secret]";
}
return <<<EOD
<object type="application/x-shockwave-flash" width="$atts[w]" height="$atts[h]" data="{$http}www.flickr.com/apps/video/stewart.swf?v=1.161" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"> <param name="flashvars" value="$photo_vars&amp;flickr_show_info_box=$atts[show_info]"></param><param name="movie" value="{$http}www.flickr.com/apps/video/stewart.swf?v=1.161"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><param name="wmode" value="opaque"></param><embed type="application/x-shockwave-flash" src="{$http}www.flickr.com/apps/video/stewart.swf?v=1.161" bgcolor="#000000" allowfullscreen="true" flashvars="$photo_vars&amp;flickr_show_info_box=$atts[show_info]" wmode="opaque" height="$atts[h]" width="$atts[w]"></embed></object>
EOD;
}
add_shortcode( 'flickr', 'flickr_shortcode_handler' );
// Override core's Flickr support because Flickr oEmbed doesn't support web embeds
wp_embed_register_handler( 'flickr', '#https?://(www\.)?flickr\.com/.*#i', 'jetpack_flickr_oembed_handler' );
function jetpack_flickr_oembed_handler( $matches, $attr, $url ) {
// Legacy slideshow embeds end with /show/
// e.g. http://www.flickr.com/photos/yarnaholic/sets/72157615194738969/show/
if ( '/show/' !== substr( $url, -strlen( '/show/' ) ) ) {
// These lookups need cached, as they don't use WP_Embed (which caches)
$cache_key = md5( $url . serialize( $attr ) );
$cache_group = 'oembed_flickr';
$html = wp_cache_get( $cache_key, $cache_group );
if ( false === $html ) {
$html = _wp_oembed_get_object()->get_html( $url, $attr );
wp_cache_set( $cache_key, $html, $cache_group, 60 * MINUTE_IN_SECONDS );
}
return $html;
}
return flickr_shortcode_handler( array( 'photo' => $url ) );
}

View file

@ -0,0 +1,92 @@
<?php
/**
* GitHub's Gist site supports oEmbed but their oembed provider only
* returns raw HTML (no styling) and the first little bit of the code.
*
* Their JavaScript-based embed method is a lot better, so that's what we're using.
*/
wp_embed_register_handler( 'github-gist', '#https?://gist\.github\.com/([a-zA-Z0-9/]+)(\#file\-[a-zA-Z0-9\_\-]+)?#', 'github_gist_embed_handler' );
add_shortcode( 'gist', 'github_gist_shortcode' );
/**
* Handle gist embeds.
*
* @since 2.8.0
*
* @global WP_Embed $wp_embed
*
* @param array $matches Results after parsing the URL using the regex in wp_embed_register_handler().
* @param array $attr Embed attributes.
* @param string $url The original URL that was matched by the regex.
* @param array $rawattr The original unmodified attributes.
* @return string The embed HTML.
*/
function github_gist_embed_handler( $matches, $attr, $url, $rawattr ) {
// Let the shortcode callback do all the work
return github_gist_shortcode( $matches, $url );
}
/**
* Callback for gist shortcode.
*
* @since 2.8.0
*
* @param array $atts Attributes found in the shortcode.
* @param string $content Content enclosed by the shortcode.
*
* @return string The gist HTML.
*/
function github_gist_shortcode( $atts, $content = '' ) {
if ( empty( $atts[0] ) && empty( $content ) ) {
return '<!-- Missing Gist ID -->';
}
$id = ( ! empty( $content ) ) ? $content : $atts[0];
// Parse a URL
if ( ! is_numeric( $id ) ) {
$id = preg_replace( '#https?://gist.github.com/([a-zA-Z0-9]+)#', '$1', $id );
}
if ( ! $id ) {
return '<!-- Invalid Gist ID -->';
}
wp_enqueue_script( 'jetpack-gist-embed', plugins_url( 'js/gist.js', __FILE__ ), array( 'jquery' ), false, true );
if ( false !== strpos( $id, '#file-' ) ) {
// URL points to a specific file in the gist
$id = str_replace( '#file-', '.json?file=', $id );
$id = preg_replace( '/\-(?!.*\-)/', '.', $id );
} else {
$file = ( ! empty( $atts['file'] ) ) ? '?file=' . urlencode( $atts['file'] ) : '';
// URL points to the entire gist
$id .= ".json$file";
}
// inline style to prevent the bottom margin to the embed that themes like TwentyTen, et al., add to tables
$return = '<style>.gist table { margin-bottom: 0; }</style><div class="gist-oembed" data-gist="' . esc_attr( $id ) . '"></div>';
if ( isset( $_POST[ 'type' ] ) && 'embed' === $_POST[ 'type' ] &&
isset( $_POST[ 'action' ] ) && 'parse-embed' === $_POST['action'] ) {
return github_gist_simple_embed( $id );
}
return $return;
}
/**
* Use script tag to load shortcode in editor.
*
* @since 3.9.0
*
* @param string $id The ID of the gist.
*
* @return string
*/
function github_gist_simple_embed( $id ) {
$id = str_replace( 'json', 'js', $id );
return '<script type="text/javascript" src="https://gist.github.com/' . $id . '"></script>';
}

View file

@ -0,0 +1,111 @@
<?php
/*
* Google maps iframe - transforms code that looks like that:
* <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=bg&amp;geocode=&amp;q=%D0%9C%D0%BB%D0%B0%D0%B4%D0%BE%D1%81%D1%82+1,+%D0%A1%D0%BE%D1%84%D0%B8%D1%8F,+%D0%91%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D0%B8%D1%8F&amp;sll=37.0625,-95.677068&amp;sspn=40.545434,79.013672&amp;ie=UTF8&amp;hq=&amp;hnear=%D0%9C%D0%BB%D0%B0%D0%B4%D0%BE%D1%81%D1%82+1&amp;ll=42.654446,23.372061&amp;spn=0.036864,0.077162&amp;t=h&amp;z=14&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=bg&amp;geocode=&amp;q=%D0%9C%D0%BB%D0%B0%D0%B4%D0%BE%D1%81%D1%82+1,+%D0%A1%D0%BE%D1%84%D0%B8%D1%8F,+%D0%91%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D0%B8%D1%8F&amp;sll=37.0625,-95.677068&amp;sspn=40.545434,79.013672&amp;ie=UTF8&amp;hq=&amp;hnear=%D0%9C%D0%BB%D0%B0%D0%B4%D0%BE%D1%81%D1%82+1&amp;ll=42.654446,23.372061&amp;spn=0.036864,0.077162&amp;t=h&amp;z=14" style="color:#0000FF;text-align:left">Вижте по-голяма карта</a></small>
* into the [googlemaps http://...] shortcode format
*/
function jetpack_googlemaps_embed_to_short_code( $content ) {
if ( false === strpos( $content, 'maps.google.' ) && 1 !== preg_match( '@google\.[^/]+/maps?@', $content ) )
return $content;
// IE and TinyMCE format things differently
// &lt;iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="<a href="https://maps.google.co.uk/maps/ms?msa=0&amp;amp;msid=206216869547772496318.0004bf5f0ff25aea47bd9&amp;amp;hl=en&amp;amp;ie=UTF8&amp;amp;t=m&amp;amp;ll=50.91917,-1.398808&amp;amp;spn=0.013225,0.011794&amp;amp;output=embed&quot;&gt;&lt;/iframe&gt;&lt;br">https://maps.google.co.uk/maps/ms?msa=0&amp;amp;msid=206216869547772496318.0004bf5f0ff25aea47bd9&amp;amp;hl=en&amp;amp;ie=UTF8&amp;amp;t=m&amp;amp;ll=50.91917,-1.398808&amp;amp;spn=0.013225,0.011794&amp;amp;output=embed"&gt;&lt;/iframe&gt;&lt;br</a> /&gt;&lt;small&gt;View &lt;a href="<a href="https://maps.google.co.uk/maps/ms?msa=0&amp;amp;msid=206216869547772496318.0004bf5f0ff25aea47bd9&amp;amp;hl=en&amp;amp;ie=UTF8&amp;amp;t=m&amp;amp;ll=50.91917,-1.398808&amp;amp;spn=0.013225,0.011794&amp;amp;source=embed">https://maps.google.co.uk/maps/ms?msa=0&amp;amp;msid=206216869547772496318.0004bf5f0ff25aea47bd9&amp;amp;hl=en&amp;amp;ie=UTF8&amp;amp;t=m&amp;amp;ll=50.91917,-1.398808&amp;amp;spn=0.013225,0.011794&amp;amp;source=embed</a>" style="color:#0000FF;text-align:left"&gt;OARA Membership Discount Map&lt;/a&gt; in a larger map&lt;/small&gt;
if ( strpos( $content, 'src="<a href="' ) !== false ) {
$content = preg_replace_callback( '#&lt;iframe\s[^&]*?(?:&(?!gt;)[^&]*?)*?src="<a href="https?://(.*)?\.google\.(.*?)/(.*?)\?(.+?)&quot;[^&]*?(?:&(?!gt;)[^&]*?)*?&gt;\s*&lt;/iframe&gt;&lt;br">[^"]*?"&gt;\s*&lt;/iframe&gt;(?:&lt;br</a>\s*/&gt;\s*&lt;small&gt;.*?&lt;/small&gt;)?#i', 'jetpack_googlemaps_embed_to_short_code_callback', $content );
return $content;
}
$content = preg_replace_callback( '!\<iframe\s[^>]*?src="https?://(.*)?\.google\.(.*?)/(.*?)\?(.+?)"[^>]*?\>\s*\</iframe\>(?:\s*(?:\<br\s*/?\>)?\s*\<small\>.*?\</small\>)?!i', 'jetpack_googlemaps_embed_to_short_code_callback', $content );
$content = preg_replace_callback( '#&lt;iframe\s[^&]*?(?:&(?!gt;)[^&]*?)*?src="https?://(.*)?\.google\.(.*?)/(.*?)\?(.+?)"[^&]*?(?:&(?!gt;)[^&]*?)*?&gt;\s*&lt;/iframe&gt;(?:\s*(?:&lt;br\s*/?&gt;)?\s*&lt;small&gt;.*?&lt;/small&gt;)?#i', 'jetpack_googlemaps_embed_to_short_code_callback', $content );
return $content;
}
function jetpack_googlemaps_embed_to_short_code_callback( $match ) {
if ( preg_match( '/\bwidth=[\'"](\d+)(%)?/', $match[0], $width ) ) {
$percent = ! empty( $width[2] ) ? '%' : '';
$width = absint( $width[1] ) . $percent;
} else {
$width = 425;
}
if ( preg_match( '/\bheight=[\'"](\d+)(%)?/', $match[0], $height ) ) {
$percent = ! empty( $height[2] ) ? '%' : '';
$height = absint( $height[1] ) . $percent;
} else {
$height = 350;
}
$url = "https://{$match[1]}.google.{$match[2]}/{$match[3]}?{$match[4]}&amp;w={$width}&amp;h={$height}";
/** This action is documented in modules/shortcodes/youtube.php */
do_action( 'jetpack_embed_to_shortcode', 'googlemaps', $url );
return "[googlemaps $url]";
}
add_filter( 'pre_kses', 'jetpack_googlemaps_embed_to_short_code' );
/**
* [googlemaps] shortcode
*
* Example usage:
* [googlemaps http://maps.google.com/maps?f=q&hl=en&geocode=&q=San+Francisco,+CA&sll=43.469466,-83.998504&sspn=0.01115,0.025942&g=San+Francisco,+CA&ie=UTF8&z=12&iwloc=addr&ll=37.808156,-122.402458&output=embed&s=AARTsJp56EajYksz3JXgNCwT3LJnGsqqAQ&w=425&h=350]
* [googlemaps https://mapsengine.google.com/map/embed?mid=zbBhkou4wwtE.kUmp8K6QJ7SA&w=640&h=480]
*/
function jetpack_googlemaps_shortcode( $atts ) {
if ( !isset($atts[0]) )
return '';
$params = ltrim( $atts[0], '=' );
$width = 425;
$height = 350;
if ( preg_match( '!^https?://(www|maps|mapsengine)\.google(\.co|\.com)?(\.[a-z]+)?/.*?(\?.+)!i', $params, $match ) ) {
$params = str_replace( '&amp;amp;', '&amp;', $params );
$params = str_replace( '&amp;', '&', $params );
parse_str( $params, $arg );
if ( isset( $arg['hq'] ) )
unset( $arg['hq'] );
$url = '';
foreach ( (array) $arg as $key => $value ) {
if ( 'w' == $key ) {
$percent = ( '%' == substr( $value, -1 ) ) ? '%' : '';
$width = (int) $value . $percent;
} elseif ( 'h' == $key ) {
$height = (int) $value;
} else {
$key = str_replace( '_', '.', $key );
$url .= esc_attr( "$key=$value&amp;" );
}
}
$url = substr( $url, 0, -5 );
if( is_ssl() )
$url = str_replace( 'http://', 'https://', $url );
$css_class = 'googlemaps';
if ( ! empty( $atts['align'] ) && in_array( strtolower( $atts['align'] ), array( 'left', 'center', 'right' ), true ) ) {
$atts['align'] = strtolower( $atts['align'] );
if ( $atts['align'] === 'left' ) {
$css_class .= ' alignleft';
} elseif ( $atts['align'] === 'center' ) {
$css_class .= ' aligncenter';
} elseif ( $atts['align'] === 'right' ) {
$css_class .= ' alignright';
}
}
return '<div class="' . esc_attr( $css_class ) . '"><iframe width="' . $width . '" height="' . $height . '" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="' . $url . '"></iframe></div>';
}
}
add_shortcode( 'googlemaps', 'jetpack_googlemaps_shortcode' );

View file

@ -0,0 +1,42 @@
<?php
/**
* Google+ embeds
*/
define( 'JETPACK_GOOGLEPLUS_EMBED_REGEX', '#^https?://plus\.(sandbox\.)?google\.com/(u/\d+/)?([^/]+)/posts/([^/]+)$#' );
// Example URL: https://plus.google.com/114986219448604314131/posts/LgHkesWCmJo
// Alternate example: https://plus.google.com/u/0/100004581596612508203/posts/2UKwN67MBQs (note the /u/0/)
wp_embed_register_handler( 'googleplus', JETPACK_GOOGLEPLUS_EMBED_REGEX, 'jetpack_googleplus_embed_handler' );
function jetpack_googleplus_embed_handler( $matches, $attr, $url ) {
static $did_script;
if ( ! $did_script ) {
$did_script = true;
add_action( 'wp_footer', 'jetpack_googleplus_add_script' );
}
return sprintf( '<div class="g-post" data-href="%s"></div>', esc_url( $url ) );
}
function jetpack_googleplus_add_script() {
?>
<script src="https://apis.google.com/js/plusone.js"></script>
<?php
}
add_shortcode( 'googleplus', 'jetpack_googleplus_shortcode_handler' );
function jetpack_googleplus_shortcode_handler( $atts ) {
global $wp_embed;
if ( empty( $atts['url'] ) )
return;
if ( ! preg_match( JETPACK_GOOGLEPLUS_EMBED_REGEX, $atts['url'] ) )
return;
return $wp_embed->shortcode( $atts, $atts['url'] );
}

View file

@ -0,0 +1,29 @@
<?php
/**
* google video is replaced by youtube, but its embeds will probably continue working indefinitely.
* [googlevideo=http://video.google.com/googleplayer.swf?docId=-6006084025483872237]
*/
function googlevideo_shortcode( $atts ) {
if ( !isset( $atts[0] ) )
return '';
$src = ltrim( $atts[0], '=' );
if ( 0 !== strpos( $src, 'http://video.google.com/googleplayer.swf' ) ) {
if ( !preg_match( '|^http://(video\.google\.[a-z]{2,3}(?:.[a-z]{2})?)/|', $src ) || !preg_match( '|.*docid=([0-9-]+).*|i', $src, $match ) || !is_numeric( $match[1] ) )
return '<!--Google Video Error: bad URL entered-->';
$src = 'http://video.google.com/googleplayer.swf?docId=' . $match[1];
}
// default width should be 400 unless the theme's content width is smaller than that
global $content_width;
$default_width = intval( !empty( $content_width ) ? min( $content_width, 400 ) : 400 );
$height = intval( 0.825 * $default_width );
$src = esc_attr( $src );
return "<span style='text-align:center;display:block;'><object width='{$default_width}' height='{$height}' type='application/x-shockwave-flash' data='{$src}'><param name='allowScriptAccess' value='never' /><param name='movie' value='$src'/><param name='quality' value='best'/><param name='bgcolor' value='#ffffff' /><param name='scale' value='noScale' /><param name='wmode' value='opaque' /></object></span>";
}
add_shortcode( 'googlevideo', 'googlevideo_shortcode' );

View file

@ -0,0 +1,29 @@
<?php
/*
* Houzz Embed
*
* Examples:
* Post content:
* - [houzz=http://www.houzz.com/pro/james-crisp]
* - http://www.houzz.com/pro/james-crisp
* Blog sidebar: [houzz=http://www.houzz.com/profile/alon w=200 h=300]
*/
// Register oEmbed provider
wp_oembed_add_provider( '#https?://(.+?\.)?houzz\.(com|co\.uk|com\.au|de|fr|ru|jp|it|es|dk|se)/.*#i', 'https://www.houzz.com/oembed', true );
// Create Shortcode
function jetpack_houzz_shortcode( $atts, $content=null ) {
$url = substr( $atts[0], 1 );
$args = array();
if ( isset( $atts['w'] ) && is_numeric( $atts['w'] ) ) {
$args['width'] = $atts['w'];
}
if ( isset( $atts['h'] ) && is_numeric( $atts['h'] ) ) {
$args['height'] = $atts['h'];
}
$oembed = _wp_oembed_get_object();
return $oembed->get_html( $url, $args );
}
add_shortcode( 'houzz', 'jetpack_houzz_shortcode' );

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,009 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View file

@ -0,0 +1,178 @@
<?php
/**
* Embed Reversal for Instagram
*
* Hooked to pre_kses, converts an embed code from Instagram.com to an oEmbeddable URL.
* @return (string) the filtered or the original content
**/
function jetpack_instagram_embed_reversal( $content ) {
if ( false === stripos( $content, 'instagram.com' ) ) {
return $content;
}
/* Sample embed code:
<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-version="2" style=" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:658px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);"><div style="padding:8px;"><div style=" background:#F8F8F8; line-height:0; margin-top:40px; padding-bottom:55%; padding-top:45%; text-align:center; width:100%;"><div style="position:relative;"><div style=" -webkit-animation:dkaXkpbBxI 1s ease-out infinite; animation:dkaXkpbBxI 1s ease-out infinite; background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAsCAMAAAApWqozAAAAGFBMVEUiIiI9PT0eHh4gIB4hIBkcHBwcHBwcHBydr+JQAAAACHRSTlMABA4YHyQsM5jtaMwAAADfSURBVDjL7ZVBEgMhCAQBAf//42xcNbpAqakcM0ftUmFAAIBE81IqBJdS3lS6zs3bIpB9WED3YYXFPmHRfT8sgyrCP1x8uEUxLMzNWElFOYCV6mHWWwMzdPEKHlhLw7NWJqkHc4uIZphavDzA2JPzUDsBZziNae2S6owH8xPmX8G7zzgKEOPUoYHvGz1TBCxMkd3kwNVbU0gKHkx+iZILf77IofhrY1nYFnB/lQPb79drWOyJVa/DAvg9B/rLB4cC+Nqgdz/TvBbBnr6GBReqn/nRmDgaQEej7WhonozjF+Y2I/fZou/qAAAAAElFTkSuQmCC); display:block; height:44px; margin:0 auto -44px; position:relative; top:-44px; width:44px;"></div><span style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:12px; font-style:normal; font-weight:bold; position:relative; top:15px;">Loading</span></div></div><p style=" font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin:8px 0 0 0; padding:0 4px; word-wrap:break-word;"> Balloons</p><p style=" line-height:32px; margin-bottom:0; margin-top:8px; padding:0; text-align:center;"> <a href="https://instagram.com/p/r9vfPrmjeB/" style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; text-decoration:none;" target="_top"> View on Instagram</a></p></div><style>@-webkit-keyframes"dkaXkpbBxI"{ 0%{opacity:0.5;} 50%{opacity:1;} 100%{opacity:0.5;} } @keyframes"dkaXkpbBxI"{ 0%{opacity:0.5;} 50%{opacity:1;} 100%{opacity:0.5;} }</style></blockquote>
<script async defer src="https://platform.instagram.com/en_US/embeds.js"></script>
*/
$regexes = array();
// new style js
$regexes[] = '#<blockquote[^>]+?class="instagram-media"[^>](.+?)>(.+?)</blockquote><script[^>]+?src="(https?:)?//platform\.instagram\.com/(.+?)/embeds\.js"></script>#ix';
// Let's play nice with the visual editor too.
$regexes[] = '#&lt;blockquote(?:[^&]|&(?!gt;))+?class="instagram-media"(?:[^&]|&(?!gt;))(.+?)&gt;(.+?)&lt;/blockquote&gt;&lt;script(?:[^&]|&(?!gt;))+?src="(https?:)?//platform\.instagram\.com/(.+?)/embeds\.js"(?:[^&]|&(?!gt;))*+&gt;&lt;/script&gt;#ix';
// old style iframe
$regexes[] = '#<iframe[^>]+?src="(?:https?:)?//instagram\.com/p/([^"\'/]++)[^"\']*?"[^>]*+>\s*?</iframe>#i';
// Let's play nice with the visual editor too.
$regexes[] = '#&lt;iframe(?:[^&]|&(?!gt;))+?src="(?:https?:)?//instagram\.com/p/([^"\'/]++)[^"\']*?"(?:[^&]|&(?!gt;))*+&gt;\s*?&lt;/iframe&gt;#i';
foreach ( $regexes as $regex ) {
if ( ! preg_match_all( $regex, $content, $matches, PREG_SET_ORDER ) ) {
continue;
}
foreach ( $matches as $match ) {
if ( ! preg_match( '#(https?:)?//instagr(\.am|am\.com)/p/([^/]*)#i', $match[2], $url_matches ) ) {
continue;
}
// Since we support Instagram via oEmbed, we simply leave a link on a line by itself.
$replace_regex = sprintf( '#\s*%s\s*#', preg_quote( $match[0], '#' ) );
$url = esc_url( $url_matches[0] );
$content = preg_replace( $replace_regex, sprintf( "\n\n%s\n\n", $url ), $content );
/** This action is documented in modules/shortcodes/youtube.php */
do_action( 'jetpack_embed_to_shortcode', 'instagram', $url );
}
}
return $content;
}
add_filter( 'pre_kses', 'jetpack_instagram_embed_reversal' );
/**
* Instagram
*/
wp_oembed_remove_provider( '#https?://(www\.)?instagr(\.am|am\.com)/p/.*#i' ); // remove core's oEmbed support so we can override
wp_embed_register_handler( 'jetpack_instagram', '#http(s?)://(www\.)?instagr(\.am|am\.com)/p/([^/]*)#i', 'jetpack_instagram_handler' );
function jetpack_instagram_handler( $matches, $atts, $url ) {
global $content_width;
// keep a copy of the passed-in URL since it's modified below
$passed_url = $url;
$max_width = 698;
$min_width = 320;
if ( is_feed() ) {
$media_url = sprintf( 'http://instagr.am/p/%s/media/?size=l', $matches[4] );
return sprintf( '<a href="%s" title="%s" target="_blank"><img src="%s" alt="Instagram Photo" /></a>', esc_url( $url ), esc_attr__( 'View on Instagram', 'jetpack' ), esc_url( $media_url ) );
}
$atts = shortcode_atts( array(
'width' => isset( $content_width ) ? $content_width : $max_width,
'hidecaption' => false,
), $atts );
$atts['width'] = absint( $atts['width'] );
if ( $atts['width'] > $max_width || $min_width > $atts['width'] ) {
$atts['width'] = $max_width;
}
// remove the modal param from the URL
$url = remove_query_arg( 'modal', $url );
// force .com instead of .am for https support
$url = str_replace( 'instagr.am', 'instagram.com', $url );
// The oembed endpoint expects HTTP, but HTTP requests 301 to HTTPS
$instagram_http_url = str_replace( 'https://', 'http://', $url );
$instagram_https_url = str_replace( 'http://', 'https://', $url );
$url_args = array(
'url' => $instagram_http_url,
'maxwidth' => $atts['width'],
);
if ( $atts['hidecaption'] ) {
$url_args['hidecaption'] = 'true';
}
$url = esc_url_raw( add_query_arg( $url_args, 'https://api.instagram.com/oembed/' ) );
/**
* Filter Object Caching for response from Instagram.
*
* Allow enabling of object caching for the response sent by Instagram when querying for Instagram image HTML.
*
* @module shortcodes
*
* @since 3.3.0
*
* @param bool false Object caching is off by default.
* @param array $matches Array of Instagram URLs found in the post.
* @param array $atts Instagram Shortcode attributes.
* @param string $passed_url Instagram API URL.
*/
$response_body_use_cache = apply_filters( 'instagram_cache_oembed_api_response_body', false, $matches, $atts, $passed_url );
$response_body = false;
if ( $response_body_use_cache ) {
$cache_key = 'oembed_response_body_' . md5( $url );
$response_body = wp_cache_get( $cache_key, 'instagram_embeds' );
}
if ( ! $response_body ) {
// Not using cache (default case) or cache miss
$instagram_response = wp_remote_get( $url, array( 'redirection' => 0 ) );
if ( is_wp_error( $instagram_response ) || 200 != $instagram_response['response']['code'] || empty( $instagram_response['body'] ) ) {
return '<!-- instagram error: invalid instagram resource -->';
}
$response_body = json_decode( $instagram_response['body'] );
if ( $response_body_use_cache ) {
// if caching it is short-lived since this is a "Cache-Control: no-cache" resource
wp_cache_set( $cache_key, $response_body, 'instagram_embeds', HOUR_IN_SECONDS + mt_rand( 0, HOUR_IN_SECONDS ) );
}
}
if ( ! empty( $response_body->html ) ) {
wp_enqueue_script( 'jetpack-instagram-embed', plugins_url( 'js/instagram.js', __FILE__ ), array( 'jquery' ), false, true );
// there's a script in the response, which we strip on purpose since it's added by this ^ script
$ig_embed = preg_replace( '@<(script)[^>]*?>.*?</\\1>@si', '', $response_body->html );
return $ig_embed;
}
return '<!-- instagram error: no embed found -->';
}
// filters instagram's username format to the expected format that matches the embed handler
wp_embed_register_handler( 'jetpack_instagram_alternate_format', '#http(s?)://instagr(\.am|am\.com)/([^/]*)/p/([^/]*)#i', 'jetpack_instagram_alternate_format_handler' );
function jetpack_instagram_alternate_format_handler( $matches, $atts, $url ) {
$url = esc_url_raw( 'https://instagram.com/p/' . $matches[4] );
$matches[0] = $url;
$matches[3] = $matches[4];
unset( $matches[4] );
return jetpack_instagram_handler( $matches, $atts, $url );
}
// [instagram url="http://instagram.com/p/PSbF9sEIGP/"]
// [instagram url="http://instagram.com/p/PSbF9sEIGP/" width="300"]
add_shortcode( 'instagram', 'jetpack_shortcode_instagram' );
function jetpack_shortcode_instagram( $atts ) {
global $wp_embed;
if ( empty( $atts['url'] ) ) {
return '';
}
return $wp_embed->shortcode( $atts, $atts['url'] );
}

View file

@ -0,0 +1,159 @@
/* jshint onevar:false */
/* global audioshortcode */
// Note: This file no longer exists on wpcom.
(function($) {
window.audioshortcode = {
/**
* Prep the audio player once the page is ready, add listeners, etc
*/
prep: function( player_id, files, titles, volume, loop ) {
// check if the player has already been prepped, no-op if it has
var container = $( '#wp-as-' + player_id + '-container' );
if ( container.hasClass( 'wp-as-prepped' ) ) {
return;
}
container.addClass( 'wp-as-prepped' );
// browser doesn't support HTML5 audio, no-op
if ( ! document.createElement('audio').canPlayType ) {
return;
}
// if the browser removed the script, no-op
var player = $( '#wp-as-' + player_id ).get(0);
if ( typeof player === 'undefined' ) {
return;
}
this[player_id] = [];
this[player_id].i = 0;
this[player_id].files = files;
this[player_id].titles = titles;
player.volume = volume;
var type_map = {
'mp3': 'mpeg',
'wav': 'wav',
'ogg': 'ogg',
'oga': 'ogg',
'm4a': 'mp4',
'aac': 'mp4',
'webm': 'webm'
};
// strip out all the files that can't be played
for ( var i = this[player_id].files.length-1; i >= 0; i-- ) {
var extension = this[player_id].files[i].split( '.' ).pop();
var type = 'audio/' + type_map[extension];
if ( ! player.canPlayType( type ) ) {
this.remove_track( player_id, i );
}
}
// bail if there are no more good files
if ( 0 === this[player_id].files.length ) {
return;
}
player.src = this[player_id].files[0];
// show the controls if there are still 2+ files remaining
if ( 1 < this[player_id].files.length ) {
$( '#wp-as-' + player_id + '-controls' ).show();
}
player.addEventListener( 'error', function() {
audioshortcode.remove_track( player_id, audioshortcode[player_id].i );
if ( 0 < audioshortcode[player_id].files.length ) {
audioshortcode[player_id].i--;
audioshortcode.next_track( player_id, false, loop );
}
}, false );
player.addEventListener( 'ended', function() {
audioshortcode.next_track( player_id, false, loop );
}, false );
player.addEventListener( 'play', function() {
var i = audioshortcode[player_id].i;
var titles = audioshortcode[player_id].titles;
$( '#wp-as-' + player_id + '-playing' ).text( ' ' + titles[i] );
}, false );
player.addEventListener( 'pause', function() {
$( '#wp-as-' + player_id + '-playing' ).text( '' );
}, false );
},
/**
* Remove the track and update the player/controls if needed
*/
remove_track: function( player_id, index ) {
this[player_id].files.splice( index, 1 );
this[player_id].titles.splice( index, 1 );
// get rid of player/controls if they can't be played
if ( 0 === this[player_id].files.length ) {
$( '#wp-as-' + player_id + '-container' ).html( $( '#wp-as-' + player_id + '-nope' ).html() );
$( '#wp-as-' + player_id + '-controls' ).html( '' );
} else if ( 1 === this[player_id].files.length ) {
$( '#wp-as-' + player_id + '-controls' ).html( '' );
}
},
/**
* Change the src of the player, load the file, then play it
*/
start_track: function( player_id, file ) {
var player = $( '#wp-as-' + player_id ).get(0);
player.src = file;
player.load();
player.play();
},
/**
* Play the previous track
*/
prev_track: function( player_id ) {
var player = $( '#wp-as-' + player_id ).get(0);
var files = this[player_id].files;
if ( player.paused || 0 === this[player_id].i ) {
return;
}
player.pause();
if ( 0 < this[player_id].i ) {
this[player_id].i--;
this.start_track( player_id, files[this[player_id].i] );
}
},
/**
* Play the next track
*/
next_track: function( player_id, fromClick, loop ) {
var player = $( '#wp-as-' + player_id ).get(0);
var files = this[player_id].files;
if ( fromClick && ( player.paused || files.length-1 === this[player_id].i ) ) {
return;
}
player.pause();
if ( files.length-1 > this[player_id].i ) {
this[player_id].i++;
this.start_track( player_id, files[this[player_id].i] );
} else if ( loop ) {
this[player_id].i = 0;
this.start_track( player_id, 0 );
} else {
this[player_id].i = 0;
player.src = files[0];
$( '#wp-as-' + player_id + '-playing' ).text( '' );
}
}
};
})(jQuery);

View file

@ -0,0 +1,28 @@
;(function( $, undefined ) {
var gistStylesheetLoaded = false,
gistEmbed = function() {
$( '.gist-oembed' ).each( function( i, el ) {
var url = 'https://gist.github.com/' + $( el ).data( 'gist' );
$.ajax( {
url: url,
dataType: 'jsonp'
} ).done( function( response ) {
$( el ).replaceWith( response.div );
if ( ! gistStylesheetLoaded ) {
var stylesheet = '<link rel="stylesheet" href="' +
response.stylesheet +
'" type="text/css" />';
$( 'head' ).append( stylesheet );
gistStylesheetLoaded = true;
}
} );
} );
};
$( document ).ready( gistEmbed );
$( 'body' ).on( 'post-load', gistEmbed );
})( jQuery );

View file

@ -0,0 +1,19 @@
(function( instgrm ) {
var instagramEmbed = function() {
if ( 'undefined' !== typeof instgrm && instgrm.Embeds && instgrm.Embeds.process ) {
instgrm.Embeds.process();
} else {
var s = document.createElement( 'script' );
s.async = true;
s.defer = true;
s.src = '//platform.instagram.com/en_US/embeds.js';
document.getElementsByTagName( 'body' )[0].appendChild( s );
}
};
if ( 'undefined' !== typeof jQuery && 'undefined' !== typeof infiniteScroll ) {
jQuery( document.body ).on( 'post-load', instagramEmbed );
}
instagramEmbed();
})();

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,258 @@
(function($){
var jmpressOpts = {
fullscreen : false,
hash : { use : false },
mouse : { clickSelects : false },
keyboard : { use : true },
animation : { transitionDuration : '1s' },
presentationMode : false,
stepSelector : '.step',
duration : {
defaultValue: 0
}
};
/**
* Presentation constructor
*/
function Presentation (wrapper) {
var _self, duration, new_css, ie_regex, matches;
_self = this;
_self.wrapper = $(wrapper); // The wrapper for toggling fullscreen
_self.slideshow = $('.presentation', wrapper); // Holds the slides for jmpress
_self.navLeft = $('.nav-arrow-left', wrapper);
_self.navRight = $('.nav-arrow-right', wrapper);
_self.expandButton = $('.nav-fullscreen-button', wrapper);
_self.overlay = $('.autoplay-overlay', wrapper);
_self.fullscreen = false;
_self.autoPlaying = false;
_self.autoplayTime = parseFloat(_self.slideshow.attr('data-autoplay'), 10) || 0;
// The wrapper is scaled to the contents' size so that its border wraps tightly
_self.wrapper.css({
width: _self.slideshow.width(),
height: _self.slideshow.height()
});
duration = _self.slideshow.attr('duration') || '1s';
jmpressOpts.animation.transitionDuration = duration;
// Compensate for transition times
if( _self.autoplayTime ) {
_self.autoplayTime += parseFloat(duration, 10) * 1000;
}
// Set the opacity transition duration
// as it is delegated by css and not jmpress
duration = 'opacity ' + duration;
new_css = {
'width' : _self.slideshow.width(),
'height' : _self.slideshow.height(),
'-webkit-transition': duration,
'-moz-transition' : duration,
'-ms-transition' : duration,
'-o-transition' : duration,
'transition' : duration
};
$('.step', _self.slideshow).each(function(i, step) {
$(step).css(new_css);
});
// Apply attribute to allow fading individual bullets here,
// otherwise wp_kses will strip the attribute out
$('.step.fadebullets li', _self.slideshow).each(function(i, step) {
$(step).attr('data-jmpress', 'fade');
});
// Register resizing to window when fullscreen
$(window).resize(function() {
if ( _self.fullscreen ) {
_self.resizePresentation();
}
});
// Register the nav bars to move the slides
_self.navLeft.on('click', function(){
_self.slideshow.jmpress('prev');
_self.overlay.css('opacity', 0);
return false;
});
_self.navRight.on('click', function(){
_self.slideshow.jmpress('next');
_self.overlay.css('opacity', 0);
return false;
});
_self.slideshow.on('click', function() {
_self.setAutoplay(true);
return false;
});
_self.slideshow.on('focusout', function() {
_self.setAutoplay(false);
});
// Register toggling fullscreen except for IE 9 or lower
ie_regex = /MSIE\s(\d+)\.\d+/;
matches = ie_regex.exec(navigator.userAgent);
if ( matches && parseInt(matches[1], 10) < 10 ) {
_self.expandButton.remove();
_self.expandButton = null;
} else {
_self.expandButton.on('click', function() {
_self.setFullscreen( !_self.fullscreen );
return false;
});
}
// Register ESC key to exit fullscreen
$(window).on('keydown', function( event ) {
if ( event.which === 27 ) {
_self.setFullscreen( false );
}
});
// Start the presentation
_self.slideshow.jmpress(jmpressOpts);
// Make content visible and remove error message on jmpress success
if ( _self.slideshow.jmpress('initialized') ) {
_self.slideshow.css('display', '');
_self.overlay.css('display', '');
$('.not-supported-msg', _self.wrapper).remove();
}
// A bug in Firefox causes issues with the nav arrows appearing
// on hover in presentation mode. Explicitly disabling fullscreen
// on init seems to fix the issue
_self.setFullscreen( false );
}
$.extend( Presentation.prototype, {
resizePresentation: function () {
var scale, duration, settings, new_css, widthScale, heightScale;
// Set the animation duration to 0 during resizing
// so that there isn't an animation delay when scaling
// up the slide contents
settings = this.slideshow.jmpress('settings');
duration = settings.animation.transitionDuration;
settings.animation.transitionDuration = '0s';
this.slideshow.jmpress('reselect');
scale = 1;
new_css = {
top : 0,
left : 0,
zoom : 1
};
// Expand the presentation to fill the lesser of the max width or height
// This avoids content moving past the window for certain window sizes
if ( this.fullscreen ) {
widthScale = $(window).width() / this.slideshow.width();
heightScale = $(window).height() / this.slideshow.height();
scale = Math.min(widthScale, heightScale);
new_css.top = ( $(window).height() - (scale * this.slideshow.height()) ) / 2;
new_css.left = ( $(window).width() - (scale * this.slideshow.width() ) ) / 2;
}
// Firefox does not support the zoom property; IE does, but it does not work
// well like in webkit, so we manually transform and position the slideshow
if ( this.slideshow.css('-moz-transform') || this.slideshow.css('-ms-transform') ) {
// Firefox keeps the center of the element in place and expands outward
// so we must shift everything to compensate
new_css.top += (scale - 1) * this.slideshow.height() / 2;
new_css.left += (scale - 1) * this.slideshow.width() / 2;
scale = 'scale(' + scale + ')';
$.extend(new_css, {
'-moz-transform' : scale,
'-ms-transform' : scale,
'transform' : scale
});
} else {
// webkit scales everything with zoom so we need to offset the right amount
// so that the content is vertically centered after scaling effects
new_css.top /= scale;
new_css.left /= scale;
new_css.zoom = scale;
}
this.slideshow.css(new_css);
settings.animation.transitionDuration = duration;
this.slideshow.jmpress('reselect');
},
setFullscreen: function ( on ) {
this.fullscreen = on;
this.setAutoplay(false);
// Save the scroll positions before going into fullscreen mode
if ( on ) {
this.scrollVert = $(window).scrollTop();
this.scrollHoriz = $(window).scrollLeft();
// Chrome Bug: Force scroll to be at top
// otherwise the presentation can end up offscreen
$(window).scrollTop(0);
$(window).scrollLeft(0);
}
$('html').toggleClass('presentation-global-fullscreen', on);
$('body').toggleClass('presentation-global-fullscreen', on);
this.wrapper.toggleClass('presentation-wrapper-fullscreen', on);
this.wrapper.parents().each(function(i, e){
$(e).toggleClass('presentation-wrapper-fullscreen-parent', on);
});
this.resizePresentation();
// Reset the scroll positions after exiting fullscreen mode
if ( !on ) {
$(window).scrollTop(this.scrollVert);
$(window).scrollLeft(this.scrollHoriz);
}
},
setAutoplay: function ( on ) {
var _self = this, newAutoplayTime;
if ( _self.autoPlaying === on ) {
return;
}
newAutoplayTime = (on && _self.autoplayTime > 0) ? _self.autoplayTime : 0;
_self.slideshow.jmpress('settings').duration.defaultValue = newAutoplayTime;
// Move to the next slide when activating autoplay
if( newAutoplayTime ) {
_self.slideshow.jmpress('next');
_self.overlay.css('opacity', 0);
} else {
_self.slideshow.jmpress('reselect');
}
_self.autoPlaying = on;
}
});
$( document ).ready( function(){
$('.presentation-wrapper').map(function() {
new Presentation(this);
});
});
})(jQuery);

View file

@ -0,0 +1,170 @@
/*
* printThis v1.3
* @desc Printing plug-in for jQuery
* @author Jason Day
*
* Resources (based on) :
* jPrintArea: http://plugins.jquery.com/project/jPrintArea
* jqPrint: https://github.com/permanenttourist/jquery.jqprint
* Ben Nadal: http://www.bennadel.com/blog/1591-Ask-Ben-Print-Part-Of-A-Web-Page-With-jQuery.htm
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* (c) Jason Day 2013
*
* Usage:
*
* $("#mySelector").printThis({
* debug: false, * show the iframe for debugging
* importCSS: true, * import page CSS
* printContainer: true, * grab outer container as well as the contents of the selector
* loadCSS: "path/to/my.css", * path to additional css file
* pageTitle: "", * add title to print page
* removeInline: false, * remove all inline styles from print elements
* printDelay: 333, * variable print delay S. Vance
* header: null * prefix to html
* });
*
* Notes:
* - the loadCSS will load additional css (with or without @media print) into the iframe, adjusting layout
*/
/* jshint onevar: false, smarttabs: true, devel: true */
;(function ($) {
var opt;
$.fn.printThis = function (options) {
opt = $.extend({}, $.fn.printThis.defaults, options);
var $element = this instanceof jQuery ? this : $(this);
var strFrameName = 'printThis-' + (new Date()).getTime();
if(window.location.hostname !== document.domain && navigator.userAgent.match(/msie/i)){
// Ugly IE hacks due to IE not inheriting document.domain from parent
// checks if document.domain is set by comparing the host name against document.domain
var iframeContents = '<head><script>document.domain=\\\'' + document.domain + '\\\';</script></head><body></body>';
var iframeSrc = 'data:text/html;charset=utf-8,' + encodeURI(iframeContents);
var printI= document.createElement('iframe');
printI.name = 'printIframe';
printI.id = strFrameName;
printI.className = 'MSIE';
document.body.appendChild(printI);
printI.src = iframeSrc;
} else {
// other browsers inherit document.domain, and IE works if document.domain is not explicitly set
var $frame = $('<iframe id="' + strFrameName +'" name="printIframe" />');
$frame.appendTo('body');
}
var $iframe = $('#' + strFrameName);
// show frame if in debug mode
if (!opt.debug) {
$iframe.css({
position: 'absolute',
width: '0px',
height: '0px',
left: '-600px',
top: '-600px'
});
}
// $iframe.ready() and $iframe.load were inconsistent between browsers
setTimeout ( function () {
var $doc = $iframe.contents();
// import page stylesheets
if (opt.importCSS) {
$('link[rel=stylesheet]').each(function () {
var href = $(this).attr('href');
if (href) {
var media = $(this).attr('media') || 'all';
$doc.find('head').append('<link type="text/css" rel="stylesheet" href="' + href + '" media="' + media + '">');
}
});
}
//add title of the page
if (opt.pageTitle) {
$doc.find('head').append('<title>' + opt.pageTitle + '</title>');
}
// import additional stylesheet
if (opt.loadCSS) {
$doc.find('head').append('<link type="text/css" rel="stylesheet" href="' + opt.loadCSS + '">');
}
// print header
if (opt.header) {
$doc.find('body').append(opt.header);
}
// grab $.selector as container
if (opt.printContainer) {
$doc.find('body').append($element.outer());
}
// otherwise just print interior elements of container
else {
$element.each(function () {
$doc.find('body').append($(this).html());
});
}
// remove inline styles
if (opt.removeInline) {
// $.removeAttr available jQuery 1.7+
if ($.isFunction($.removeAttr)) {
$doc.find('body *').removeAttr('style');
} else {
$doc.find('body *').attr('style', '');
}
}
setTimeout(function () {
if($iframe.hasClass('MSIE')){
// check if the iframe was created with the ugly hack
// and perform another ugly hack out of neccessity
window.frames.printIframe.focus();
$doc.find('head').append('<script> window.print(); </script>');
} else {
// proper method
$iframe[0].contentWindow.focus();
$iframe[0].contentWindow.print();
}
$element.trigger( 'done');
//remove iframe after print
if (!opt.debug) {
setTimeout(function () {
$iframe.remove();
}, 1000);
}
}, opt.printDelay);
}, 333 );
};
// defaults
$.fn.printThis.defaults = {
debug: false, // show the iframe for debugging
importCSS: false, // import parent page css
printContainer: true, // print outer container/$.selector
loadCSS: '', // load an additional css file
pageTitle: '', // add title to print page
removeInline: false, // remove all inline styles
printDelay: 333, // variable print delay S. Vance
header: null // prefix to html
};
// $.selector container
jQuery.fn.outer = function () {
return $($('<div></div>').html(this.clone())).html();
};
})(jQuery);

View file

@ -0,0 +1,11 @@
/* global jetpack_recipes_vars */
( function( $ ) {
$( window ).load( function() {
$( '.jetpack-recipe-print a' ).click( function( event ) {
event.preventDefault();
// Print the DIV.
$( this ).closest( '.jetpack-recipe' ).printThis( { pageTitle: jetpack_recipes_vars.pageTitle, loadCSS: jetpack_recipes_vars.loadCSS } );
} );
} );
} )( jQuery );

View file

@ -0,0 +1,193 @@
/* jshint onevar:false, loopfunc:true */
/* global jetpackSlideshowSettings, escape */
function JetpackSlideshow( element, transition, autostart ) {
this.element = element;
this.images = [];
this.controls = {};
this.transition = transition || 'fade';
this.autostart = autostart;
}
JetpackSlideshow.prototype.showLoadingImage = function( toggle ) {
if ( toggle ) {
this.loadingImage_ = document.createElement( 'div' );
this.loadingImage_.className = 'slideshow-loading';
var img = document.createElement( 'img' );
img.src = jetpackSlideshowSettings.spinner;
this.loadingImage_.appendChild( img );
this.loadingImage_.appendChild( this.makeZeroWidthSpan() );
this.element.append( this.loadingImage_ );
} else if ( this.loadingImage_ ) {
this.loadingImage_.parentNode.removeChild( this.loadingImage_ );
this.loadingImage_ = null;
}
};
JetpackSlideshow.prototype.init = function() {
this.showLoadingImage(true);
var self = this;
// Set up DOM.
for ( var i = 0; i < this.images.length; i++ ) {
var imageInfo = this.images[i];
var img = document.createElement( 'img' );
img.src = imageInfo.src;
img.title = typeof( imageInfo.title ) !== 'undefined' ? imageInfo.title : '';
img.alt = typeof( imageInfo.alt ) !== 'undefined' ? imageInfo.alt : '';
img.align = 'middle';
img.setAttribute('itemprop','image');
img.nopin = 'nopin';
var caption = document.createElement( 'div' );
caption.className = 'slideshow-slide-caption';
caption.setAttribute('itemprop','caption description');
caption.innerHTML = imageInfo.caption;
var container = document.createElement('div');
container.className = 'slideshow-slide';
container.setAttribute('itemprop','associatedMedia');
container.setAttribute('itemscope','');
container.setAttribute('itemtype','http://schema.org/ImageObject');
// Hide loading image once first image has loaded.
if ( i === 0 ) {
if ( img.complete ) {
// IE, image in cache
setTimeout( function() {
self.finishInit_();
}, 1);
} else {
jQuery( img ).load(function() {
self.finishInit_();
});
}
}
container.appendChild( img );
// I'm not sure where these were coming from, but IE adds
// bad values for width/height for portrait-mode images
img.removeAttribute('width');
img.removeAttribute('height');
container.appendChild( this.makeZeroWidthSpan() );
container.appendChild( caption );
this.element.append( container );
}
};
JetpackSlideshow.prototype.makeZeroWidthSpan = function() {
var emptySpan = document.createElement( 'span' );
emptySpan.className = 'slideshow-line-height-hack';
// Having a NBSP makes IE act weird during transitions, but other
// browsers ignore a text node with a space in it as whitespace.
if ( -1 !== window.navigator.userAgent.indexOf( 'MSIE ' ) ) {
emptySpan.appendChild( document.createTextNode(' ') );
} else {
emptySpan.innerHTML = '&nbsp;';
}
return emptySpan;
};
JetpackSlideshow.prototype.finishInit_ = function() {
this.showLoadingImage( false );
this.renderControls_();
var self = this;
if ( this.images.length > 1 ) {
// Initialize Cycle instance.
this.element.cycle( {
fx: this.transition,
prev: this.controls.prev,
next: this.controls.next,
slideExpr: '.slideshow-slide',
onPrevNextEvent: function() {
return self.onCyclePrevNextClick_.apply( self, arguments );
}
} );
var slideshow = this.element;
if ( ! this.autostart ) {
slideshow.cycle( 'pause' );
jQuery(this.controls.stop).removeClass( 'running' );
jQuery(this.controls.stop).addClass( 'paused' );
}
jQuery( this.controls.stop ).click( function() {
var button = jQuery(this);
if ( ! button.hasClass( 'paused' ) ) {
slideshow.cycle( 'pause' );
button.removeClass( 'running' );
button.addClass( 'paused' );
} else {
button.addClass( 'running' );
button.removeClass( 'paused' );
slideshow.cycle( 'resume', true );
}
return false;
} );
} else {
this.element.children( ':first' ).show();
this.element.css( 'position', 'relative' );
}
this.initialized_ = true;
};
JetpackSlideshow.prototype.renderControls_ = function() {
if ( this.controlsDiv_ ) {
return;
}
var controlsDiv = document.createElement( 'div' );
controlsDiv.className = 'slideshow-controls';
var controls = [ 'prev', 'stop', 'next' ];
for ( var i = 0; i < controls.length; i++ ) {
var controlName = controls[i];
var a = document.createElement( 'a' );
a.href = '#';
controlsDiv.appendChild( a );
this.controls[controlName] = a;
}
this.element.append( controlsDiv );
this.controlsDiv_ = controlsDiv;
};
JetpackSlideshow.prototype.onCyclePrevNextClick_ = function( isNext, i/*, slideElement*/ ) {
// If blog_id not present don't track page views
if ( ! jetpackSlideshowSettings.blog_id ) {
return;
}
var postid = this.images[i].id;
var stats = new Image();
stats.src = document.location.protocol +
'//pixel.wp.com/g.gif?host=' +
escape( document.location.host ) +
'&rand=' + Math.random() +
'&blog=' + jetpackSlideshowSettings.blog_id +
'&subd=' + jetpackSlideshowSettings.blog_subdomain +
'&user_id=' + jetpackSlideshowSettings.user_id +
'&post=' + postid +
'&ref=' + escape( document.location );
};
( function ( $ ) {
function jetpack_slideshow_init() {
$( '.jetpack-slideshow-noscript' ).remove();
$( '.jetpack-slideshow' ).each( function () {
var container = $( this );
if ( container.data( 'processed' ) ) {
return;
}
var slideshow = new JetpackSlideshow( container, container.data( 'trans' ), container.data( 'autostart' ) );
slideshow.images = container.data( 'gallery' );
slideshow.init();
container.data( 'processed', true );
} );
}
$( document ).ready( jetpack_slideshow_init );
$( 'body' ).on( 'post-load', jetpack_slideshow_init );
} )( jQuery );

View file

@ -0,0 +1,67 @@
<?php
// Embed support for Medium https://medium.com/p/3eaed64aed8a
/**
* Faux-oembed support for Medium permalinks
*
* e.g.
* https://medium.com/help-center
* https://medium.com/@richroll
*/
wp_embed_register_handler( 'medium', '#^https?://medium.com/([a-zA-z0-9-_@]+)#', 'jetpack_embed_medium_oembed' );
function jetpack_embed_medium_oembed( $matches, $attr, $url ) {
$attr = jetpack_embed_medium_args( $attr );
$attr['url'] = $url;
return jetpack_embed_medium_embed_html( $attr );
}
function jetpack_embed_medium_embed_html( $args ) {
$args = jetpack_embed_medium_args( $args );
if ( empty( $args['url'] ) ) {
return;
}
$args['type'] = jetpack_embed_medium_get_embed_type( $args['url'] );
return sprintf( '<script async src="https://static.medium.com/embed.js"></script><a class="m-%1$s" href="%2$s" target="_blank" data-width="%3$s" data-border="%4$s" data-collapsed="%5$s">View %1$s at Medium.com</a>', esc_attr( $args['type'] ), esc_url( $args['url'] ), esc_attr( $args['width'] ), esc_attr( $args['border'] ), esc_attr( $args['collapsed'] ) );
}
/**
* Shortcode support that allows passing in URL
*
* [medium url="https://medium.com/help-center" width="100%" border="false" collapsed="true"]
*/
add_shortcode( 'medium', 'jetpack_embed_medium_shortcode' );
function jetpack_embed_medium_shortcode( $atts ) {
$atts = jetpack_embed_medium_args( $atts );
if ( ! empty( $atts['url'] ) ) {
global $wp_embed;
return $wp_embed->shortcode( $atts, $atts['url'] );
}
}
function jetpack_embed_medium_get_embed_type( $url ) {
$url_path = parse_url( $url, PHP_URL_PATH );
if ( preg_match( '/^\/@[\.\w]+$/', $url_path ) ) {
return 'profile';
} else if ( preg_match( '/^\/[\da-zA-Z-]+$/', $url_path ) ) {
return 'collection';
}
return 'story';
}
function jetpack_embed_medium_args( $atts ) {
return shortcode_atts( array(
'url' => '',
'width' => '400',
'border' => true,
'collapsed' => false,
), $atts, 'medium' );
}

View file

@ -0,0 +1,52 @@
<?php
/*
* Mixcloud embeds
*
* examples:
* [mixcloud MalibuRum/play-6-kissy-sellouts-winter-sun-house-party-mix/ /]
* [mixcloud MalibuRum/play-6-kissy-sellouts-winter-sun-house-party-mix/ width=640 height=480 /]
* [mixcloud http://www.mixcloud.com/MalibuRum/play-6-kissy-sellouts-winter-sun-house-party-mix/ /]
* [mixcloud http://www.mixcloud.com/MalibuRum/play-6-kissy-sellouts-winter-sun-house-party-mix/ width=640 height=480 /]
* [mixcloud]http://www.mixcloud.com/MalibuRum/play-6-kissy-sellouts-winter-sun-house-party-mix/[/mixcloud]
* [mixcloud]MalibuRum/play-6-kissy-sellouts-winter-sun-house-party-mix/[/mixcloud]
*/
// Register oEmbed provider
// Example URL: http://www.mixcloud.com/oembed/?url=http://www.mixcloud.com/MalibuRum/play-6-kissy-sellouts-winter-sun-house-party-mix/
wp_oembed_add_provider('#https?://(?:www\.)?mixcloud\.com/\S*#i', 'http://www.mixcloud.com/oembed', true);
// Register mixcloud shortcode
add_shortcode( 'mixcloud', 'mixcloud_shortcode' );
function mixcloud_shortcode( $atts, $content = null ) {
if ( empty( $atts[0] ) && empty( $content ) )
return "<!-- mixcloud error: invalid mixcloud resource -->";
$regular_expression = '#((?<=mixcloud.com/)([A-Za-z0-9%-]+/[A-Za-z0-9%-]+))|^([A-Za-z0-9%-]+/[A-Za-z0-9%-]+)#i';
preg_match( $regular_expression, $content, $match );
if ( ! empty( $match ) ) {
$resource_id = trim( $match[0] );
} else {
preg_match( $regular_expression, $atts[0], $match );
if ( ! empty( $match ) )
$resource_id = trim( $match[0] );
}
if ( empty( $resource_id ) )
return "<!-- mixcloud error: invalid mixcloud resource -->";
$atts = shortcode_atts( array(
'width' => 300,
'height' => 300,
), $atts, 'mixcloud' );
// Build URL
$url = add_query_arg( $atts, "http://api.mixcloud.com/$resource_id/embed-html/" );
$head = wp_remote_head( $url );
if ( is_wp_error( $head ) || 200 != $head['response']['code'] )
return "<!-- mixcloud error: invalid mixcloud resource -->";
return sprintf( '<iframe width="%d" height="%d" scrolling="no" frameborder="no" src="%s"></iframe>', $atts['width'], $atts['height'], esc_url( $url ) );
}

View file

@ -0,0 +1,578 @@
<?php
if ( !class_exists( 'PolldaddyShortcode' ) ) {
/**
* Class wrapper for polldaddy shortcodes
*/
class PolldaddyShortcode {
static $add_script = false;
static $scripts = false;
/**
* Add all the actions & resgister the shortcode
*/
function __construct() {
if ( defined( 'GLOBAL_TAGS' ) == false ) {
add_shortcode( 'polldaddy', array( $this, 'polldaddy_shortcode' ) );
add_filter( 'pre_kses', array( $this, 'polldaddy_embed_to_shortcode' ) );
}
add_action( 'wp_enqueue_scripts', array( $this, 'check_infinite' ) );
add_action( 'infinite_scroll_render', array( $this, 'polldaddy_shortcode_infinite' ), 11 );
}
private function get_async_code( array $settings, $survey_link ) {
$embed_src = 'http://i0.poll.fm/survey.js';
$embed_src_ssl = 'https://polldaddy.com/survey.js';
$include = <<<CONTAINER
( function( d, c, j ) {
if ( !d.getElementById( j ) ) {
var pd = d.createElement( c ), s;
pd.id = j;
pd.src = ( 'https:' == d.location.protocol ) ? '{$embed_src_ssl}' : '{$embed_src}';
s = d.getElementsByTagName( c )[0];
s.parentNode.insertBefore( pd, s );
}
}( document, 'script', 'pd-embed' ) );
CONTAINER;
// Compress it a bit
$include = $this->compress_it( $include );
$placeholder =
'<div class="pd-embed" data-settings="'
. esc_attr( json_encode( $settings ) )
. '"></div>';
if ( 'button' === $settings['type'] ) {
$placeholder =
'<a class="pd-embed" href="'
. esc_attr( $survey_link )
. '" data-settings="'
. esc_attr( json_encode( $settings ) )
. '">'
. esc_html( $settings['title'] )
. '</a>';
}
$js_include = $placeholder . "\n";
$js_include .= '<script type="text/javascript"><!--//--><![CDATA[//><!--' . "\n";
$js_include .= $include . "\n";
$js_include .= "//--><!]]></script>\n";
if ( 'button' !== $settings['type'] ) {
$js_include .= '<noscript>' . $survey_link . "</noscript>\n";
}
return $js_include;
}
private function compress_it( $js ) {
$js = str_replace( array( "\n", "\t", "\r" ), '', $js );
$js = preg_replace( '/\s*([,:\?\{;\-=\(\)])\s*/', '$1', $js );
return $js;
}
/*
* Polldaddy Poll Embed script - transforms code that looks like that:
* <script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/123456.js"></script>
* <noscript><a href="http://polldaddy.com/poll/123456/">What is your favourite color?</a></noscript>
* into the [polldaddy poll=...] shortcode format
*/
function polldaddy_embed_to_shortcode( $content ) {
if ( false === strpos( $content, 'polldaddy.com/p/' ) ) {
return $content;
}
$regexes = array();
$regexes[] = '#<script[^>]+?src="https?://(secure|static)\.polldaddy\.com/p/([0-9]+)\.js"[^>]*+>\s*?</script>\r?\n?(<noscript>.*?</noscript>)?#i';
$regexes[] = '#&lt;script(?:[^&]|&(?!gt;))+?src="https?://(secure|static)\.polldaddy\.com/p/([0-9]+)\.js"(?:[^&]|&(?!gt;))*+&gt;\s*?&lt;/script&gt;\r?\n?(&lt;noscript&gt;.*?&lt;/noscript&gt;)?#i';
foreach ( $regexes as $regex ) {
if ( ! preg_match_all( $regex, $content, $matches, PREG_SET_ORDER ) ) {
continue;
}
foreach ( $matches as $match ) {
if ( ! isset( $match[2] ) ) {
continue;
}
$id = (int) $match[2];
if ( $id > 0 ) {
$content = str_replace( $match[0], " [polldaddy poll=$id]", $content );
/** This action is documented in modules/shortcodes/youtube.php */
do_action( 'jetpack_embed_to_shortcode', 'polldaddy', $id );
}
}
}
return $content;
}
/**
* Shortcode for polldadddy
* [polldaddy poll|survey|rating="123456"]
*
* */
function polldaddy_shortcode( $atts ) {
global $post;
global $content_width;
extract( shortcode_atts( array(
'survey' => null,
'link_text' => 'Take Our Survey',
'poll' => 'empty',
'rating' => 'empty',
'unique_id' => null,
'item_id' => null,
'title' => null,
'permalink' => null,
'cb' => 0,
'type' => 'button',
'body' => '',
'button' => '',
'text_color' => '000000',
'back_color' => 'FFFFFF',
'align' => '',
'style' => '',
'width' => $content_width,
'height' => floor( $content_width * 3 / 4 ),
'delay' => 100,
'visit' => 'single',
'domain' => '',
'id' => '',
), $atts, 'polldaddy' ) );
if ( ! is_array( $atts ) ) {
return '<!-- Polldaddy shortcode passed invalid attributes -->';
}
$inline = ! in_the_loop();
$no_script = false;
$infinite_scroll = false;
if ( is_home() && current_theme_supports( 'infinite-scroll' ) ) {
$infinite_scroll = true;
}
if ( defined( 'PADPRESS_LOADED' ) ) {
$inline = true;
}
if ( function_exists( 'get_option' ) && get_option( 'polldaddy_load_poll_inline' ) ) {
$inline = true;
}
if ( is_feed() || ( defined( 'DOING_AJAX' ) && ! $infinite_scroll ) ) {
$no_script = false;
}
self::$add_script = $infinite_scroll;
if ( intval( $rating ) > 0 && ! $no_script ) { //rating embed
if ( empty( $unique_id ) ) {
$unique_id = is_page() ? 'wp-page-' . $post->ID : 'wp-post-' . $post->ID;
}
if ( empty( $item_id ) ) {
$item_id = is_page() ? '_page_' . $post->ID : '_post_' . $post->ID;
}
if ( empty( $title ) ) {
/** This filter is documented in core/src/wp-includes/general-template.php */
$title = apply_filters( 'wp_title', $post->post_title, '', '' );
}
if ( empty( $permalink ) ) {
$permalink = get_permalink( $post->ID );
}
$rating = intval( $rating );
$unique_id = preg_replace( '/[^\-_a-z0-9]/i', '', wp_strip_all_tags( $unique_id ) );
$item_id = wp_strip_all_tags( $item_id );
$item_id = preg_replace( '/[^_a-z0-9]/i', '', $item_id );
$settings = json_encode( array(
'id' => $rating,
'unique_id' => $unique_id,
'title' => rawurlencode( trim( $title ) ),
'permalink' => esc_url( $permalink ),
'item_id' => $item_id,
) );
$item_id = esc_js( $item_id );
if ( is_ssl() ) {
$rating_js_file = "https://polldaddy.com/js/rating/rating.js";
} else {
$rating_js_file = "http://i0.poll.fm/js/rating/rating.js";
}
if ( $inline ) {
return <<<SCRIPT
<div class="pd-rating" id="pd_rating_holder_{$rating}{$item_id}"></div>
<script type="text/javascript" charset="UTF-8"><!--//--><![CDATA[//><!--
PDRTJS_settings_{$rating}{$item_id}={$settings};
//--><!]]></script>
<script type="text/javascript" charset="UTF-8" src="{$rating_js_file}"></script>
SCRIPT;
} else {
if ( false === self::$scripts ) {
self::$scripts = array();
}
$data = array( 'id' => $rating, 'item_id' => $item_id, 'settings' => $settings );
self::$scripts['rating'][] = $data;
add_action( 'wp_footer', array( $this, 'generate_scripts' ) );
$data = esc_attr( json_encode( $data ) );
if ( $infinite_scroll ) {
return <<<CONTAINER
<div class="pd-rating" id="pd_rating_holder_{$rating}{$item_id}" data-settings="{$data}"></div>
CONTAINER;
} else {
return <<<CONTAINER
<div class="pd-rating" id="pd_rating_holder_{$rating}{$item_id}"></div>
CONTAINER;
}
}
} elseif ( intval( $poll ) > 0 ) { //poll embed
$poll = intval( $poll );
$poll_url = sprintf( 'http://polldaddy.com/poll/%d', $poll );
$poll_js = sprintf( '%s.polldaddy.com/p/%d.js', ( is_ssl() ? 'https://secure' : 'http://static' ), $poll );
$poll_link = sprintf( '<a href="%s" target="_blank">Take Our Poll</a>', $poll_url );
if ( $no_script ) {
return $poll_link;
} else {
if ( $type == 'slider' && !$inline ) {
if ( ! in_array( $visit, array( 'single', 'multiple' ) ) ) {
$visit = 'single';
}
$settings = array(
'type' => 'slider',
'embed' => 'poll',
'delay' => intval( $delay ),
'visit' => $visit,
'id' => intval( $poll )
);
return $this->get_async_code( $settings, $poll_link );
} else {
$cb = ( $cb == 1 ? '?cb='.mktime() : false );
$margins = '';
$float = '';
if ( in_array( $align, array( 'right', 'left' ) ) ) {
$float = sprintf( 'float: %s;', $align );
if ( $align == 'left')
$margins = 'margin: 0px 10px 0px 0px;';
elseif ( $align == 'right' )
$margins = 'margin: 0px 0px 0px 10px';
}
// Force the normal style embed on single posts/pages otherwise it's not rendered on infinite scroll themed blogs ('infinite_scroll_render' isn't fired)
if ( is_singular() ) {
$inline = true;
}
if ( false === $cb && ! $inline ) {
if ( false === self::$scripts ) {
self::$scripts = array();
}
$data = array( 'url' => $poll_js );
self::$scripts['poll'][intval( $poll )] = $data;
add_action( 'wp_footer', array( $this, 'generate_scripts' ) );
$data = esc_attr( json_encode( $data ) );
$script_url = esc_url_raw( plugins_url( 'js/polldaddy-shortcode.js', __FILE__ ) );
$str = <<<CONTAINER
<a name="pd_a_{$poll}"></a>
<div class="PDS_Poll" id="PDI_container{$poll}" data-settings="{$data}" style="display:inline-block;{$float}{$margins}"></div>
<div id="PD_superContainer"></div>
<noscript>{$poll_link}</noscript>
CONTAINER;
$loader = <<<SCRIPT
( function( d, c, j ) {
if ( ! d.getElementById( j ) ) {
var pd = d.createElement( c ), s;
pd.id = j;
pd.src = '{$script_url}';
s = d.getElementsByTagName( c )[0];
s.parentNode.insertBefore( pd, s );
} else if ( typeof jQuery !== 'undefined' ) {
jQuery( d.body ).trigger( 'pd-script-load' );
}
} ( document, 'script', 'pd-polldaddy-loader' ) );
SCRIPT;
$loader = $this->compress_it( $loader );
$loader = "<script type='text/javascript'>\n" . $loader . "\n</script>";
return $str . $loader;
} else {
if ( $inline ) {
$cb = '';
}
return <<<CONTAINER
<a id="pd_a_{$poll}"></a>
<div class="PDS_Poll" id="PDI_container{$poll}" style="display:inline-block;{$float}{$margins}"></div>
<div id="PD_superContainer"></div>
<script type="text/javascript" charset="UTF-8" src="{$poll_js}{$cb}"></script>
<noscript>{$poll_link}</noscript>
CONTAINER;
}
}
}
} elseif ( ! empty( $survey ) ) { //survey embed
if ( in_array( $type, array( 'iframe', 'button', 'banner', 'slider' ) ) ) {
if ( empty( $title ) ) {
$title = __( 'Take Our Survey', 'jetpack' );
if( ! empty( $link_text ) ) {
$title = $link_text;
}
}
if ( $type == 'banner' || $type == 'slider' )
$inline = false;
$survey = preg_replace( '/[^a-f0-9]/i', '', $survey );
$survey_url = esc_url( "http://polldaddy.com/s/{$survey}" );
$survey_link = sprintf( '<a href="%s" target="_blank">%s</a>', $survey_url, esc_html( $title ) );
$settings = array();
// Do we want a full embed code or a link?
if ( $no_script || $inline || $infinite_scroll ) {
return $survey_link;
}
if ( $type == 'iframe' ) {
if ( $height != 'auto' ) {
if ( isset( $content_width ) && is_numeric( $width ) && $width > $content_width ) {
$width = $content_width;
}
if ( ! $width ) {
$width = '100%';
} else {
$width = (int) $width;
}
if ( ! $height ) {
$height = '600';
} else {
$height = (int) $height;
}
return <<<CONTAINER
<iframe src="{$survey_url}?iframe=1" frameborder="0" width="{$width}" height="{$height}" scrolling="auto" allowtransparency="true" marginheight="0" marginwidth="0">{$survey_link}</iframe>
CONTAINER;
} elseif ( ! empty( $domain ) && ! empty( $id ) ) {
$domain = preg_replace( '/[^a-z0-9\-]/i', '', $domain );
$id = preg_replace( '/[\/\?&\{\}]/', '', $id );
$auto_src = esc_url( "http://{$domain}.polldaddy.com/s/{$id}" );
$auto_src = parse_url( $auto_src );
if ( ! is_array( $auto_src ) || count( $auto_src ) == 0 ) {
return '<!-- no polldaddy output -->';
}
if ( ! isset( $auto_src['host'] ) || ! isset( $auto_src['path'] ) ) {
return '<!-- no polldaddy output -->';
}
$domain = $auto_src['host'].'/s/';
$id = str_ireplace( '/s/', '', $auto_src['path'] );
$settings = array(
'type' => $type,
'auto' => true,
'domain' => $domain,
'id' => $id
);
}
} else {
$text_color = preg_replace( '/[^a-f0-9]/i', '', $text_color );
$back_color = preg_replace( '/[^a-f0-9]/i', '', $back_color );
if (
! in_array(
$align,
array(
'right',
'left',
'top-left',
'top-right',
'middle-left',
'middle-right',
'bottom-left',
'bottom-right'
)
)
) {
$align = '';
}
if (
! in_array(
$style,
array(
'inline',
'side',
'corner',
'rounded',
'square'
)
)
) {
$style = '';
}
$title = wp_strip_all_tags( $title );
$body = wp_strip_all_tags( $body );
$button = wp_strip_all_tags( $button );
$settings = array_filter( array(
'title' => $title,
'type' => $type,
'body' => $body,
'button' => $button,
'text_color' => $text_color,
'back_color' => $back_color,
'align' => $align,
'style' => $style,
'id' => $survey,
) );
}
if ( empty( $settings ) ) {
return '<!-- no polldaddy output -->';
}
return $this->get_async_code( $settings, $survey_link );
}
} else {
return '<!-- no polldaddy output -->';
}
}
function generate_scripts() {
$script = '';
if ( is_array( self::$scripts ) ) {
if ( is_ssl() ) {
$rating_js_file = "https://polldaddy.com/js/rating/rating.js";
} else {
$rating_js_file = "http://i0.poll.fm/js/rating/rating.js";
}
if ( isset( self::$scripts['rating'] ) ) {
$script = "<script type='text/javascript' charset='UTF-8' id='polldaddyRatings'><!--//--><![CDATA[//><!--\n";
foreach( self::$scripts['rating'] as $rating ) {
$script .= "PDRTJS_settings_{$rating['id']}{$rating['item_id']}={$rating['settings']}; if ( typeof PDRTJS_RATING !== 'undefined' ){if ( typeof PDRTJS_{$rating['id']}{$rating['item_id']} == 'undefined' ){PDRTJS_{$rating['id']}{$rating['item_id']} = new PDRTJS_RATING( PDRTJS_settings_{$rating['id']}{$rating['item_id']} );}}";
}
$script .= "\n//--><!]]></script><script type='text/javascript' charset='UTF-8' src='{$rating_js_file}'></script>";
}
if ( isset( self::$scripts['poll'] ) ) {
foreach( self::$scripts['poll'] as $poll ) {
$script .= "<script type='text/javascript' charset='UTF-8' src='{$poll['url']}'></script>";
}
}
}
self::$scripts = false;
echo $script;
}
/**
* If the theme uses infinite scroll, include jquery at the start
*/
function check_infinite() {
if (
current_theme_supports( 'infinite-scroll' )
&& class_exists( 'The_Neverending_Home_Page' )
&& The_Neverending_Home_Page::archive_supports_infinity()
) {
wp_enqueue_script( 'jquery' );
}
}
/**
* Dynamically load the .js, if needed
*
* This hooks in late (priority 11) to infinite_scroll_render to determine
* a posteriori if a shortcode has been called.
*/
function polldaddy_shortcode_infinite() {
// only try to load if a shortcode has been called and theme supports infinite scroll
if( self::$add_script ) {
$script_url = esc_url_raw( plugins_url( 'js/polldaddy-shortcode.js', __FILE__ ) );
// if the script hasn't been loaded, load it
// if the script loads successfully, fire an 'pd-script-load' event
echo <<<SCRIPT
<script type='text/javascript'>
//<![CDATA[
( function( d, c, j ) {
if ( !d.getElementById( j ) ) {
var pd = d.createElement( c ), s;
pd.id = j;
pd.src = '{$script_url}';
s = d.getElementsByTagName( c )[0];
s.parentNode.insertBefore( pd, s );
} else if ( typeof jQuery !== 'undefined' ) {
jQuery( d.body ).trigger( 'pd-script-load' );
}
} ( document, 'script', 'pd-polldaddy-loader' ) );
//]]>
</script>
SCRIPT;
}
}
}
// kick it all off
new PolldaddyShortcode();
if ( ! function_exists( 'polldaddy_link' ) ) {
// http://polldaddy.com/poll/1562975/?view=results&msg=voted
function polldaddy_link( $content ) {
return jetpack_preg_replace_outside_tags( '!(?:\n|\A)http://polldaddy.com/poll/([0-9]+?)/(.+)?(?:\n|\Z)!i', "\n<script type='text/javascript' charset='utf-8' src='//static.polldaddy.com/p/$1.js'></script><noscript> <a href='http://polldaddy.com/poll/$1/'>View Poll</a></noscript>\n", $content, 'polldaddy.com/poll' );
}
// higher priority because we need it before auto-link and autop get to it
add_filter( 'the_content', 'polldaddy_link', 1 );
add_filter( 'the_content_rss', 'polldaddy_link', 1 );
}
wp_oembed_add_provider( '#http://poll\.fm/.*#i', 'http://polldaddy.com/oembed/', true );
}

View file

@ -0,0 +1,454 @@
<?php
/*
Plugin Name: Presentations
Plugin URI: http://automattic.com/wordpress-plugins/
Description: Presentations plugin based on the work done by <a href="http://darylkoop.com/">Daryl Koopersmith</a>. Powered by jmpress.js
Version: 0.2
Author: Automattic
Author URI: http://automattic.com/wordpress-plugins/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Known issues:
*
* - IE 7/8 are not supported by jmpress and presentations will not work
* - IE 9 will not animate transitions at all, though it's possible to at least
* switch between slides.
* - Infinite Scroll themes will not load presentations properly unless the post
* happens to be on the first loaded page. The permalink page will function
* properly, however.
* - Exiting fullscreen mode will not properly reset the scroll locations in Safari
*/
/*
HOW TO: How the plugin settings are organized and which features are supported.
The entire presentation should be wrapped with a [presentation] shortcode, and every
individual slide should be wrapped with a [slide] shortcode. Any settings supported
by [slide] can be set into [presentation], which will apply that setting for the entire
presentation unless overridden by individual slides.
- [presentation] only settings:
- duration: transition durations, default is one second.
- height: content height, default is 400px
- width: content width, default is 550px
- autoplay: delay between transitions in seconds, default 3s
when set the presentation will automatically transition between slides
as long as the presentation remains in focus
- [slide] settings:
- transition: specifies where the next slide will be placed relative
to the last one before it. Supported values are "up", "down"
"left", "right", or "none". Default value is "down".
- scale: scales the content relative to other slides, default value is one
- rotate: rotates the content by the specified degrees, default is zero
- fade: slides will fade in and out during transition. Values of "on" or
"true" will enable fading, while values of "no" or "false" will
disable it. Default value is "on"
- bgcolor: specifies a background color for the slides. Any CSS valid value
is permitted. Default color is transparent.
- bgimg: specifies an image url which will fill the background. Image is
set to fill the background 100% width and height
- fadebullets: any html <li> tags will start out with an opacity of 0 and any
subsequent slide transitions will show the bullets one by one
*/
if ( ! class_exists( 'Presentations' ) ) :
class Presentations {
private $presentation_settings;
private $presentation_initialized;
private $scripts_and_style_included;
/**
* Constructor
*/
function __construct() {
// Bail without 3.0.
if ( ! function_exists( '__return_false' ) ) {
return;
}
$this->presentation_initialized = false;
$this->scripts_and_style_included = false;
// Registers shortcodes
add_action( 'wp_head', array( &$this, 'add_scripts' ), 1 );
add_shortcode( 'presentation', array( &$this, 'presentation_shortcode' ) );
add_shortcode( 'slide', array( &$this, 'slide_shortcode' ) );
}
function add_scripts() {
$this->scripts_and_style_included = false;
if ( empty( $GLOBALS['posts'] ) || ! is_array( $GLOBALS['posts'] ) ) {
return;
}
foreach ( $GLOBALS['posts'] as $p ) {
if ( has_shortcode( $p->post_content, 'presentation' ) ) {
$this->scripts_and_style_included = true;
break;
}
}
if ( ! $this->scripts_and_style_included ) {
return;
}
$plugin = plugin_dir_url( __FILE__ );
// Add CSS
wp_enqueue_style( 'presentations', $plugin . 'css/style.css' );
// Add JavaScript
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jmpress', $plugin . 'js/jmpress.min.js', array( 'jquery' ), '0.4.5', true );
wp_enqueue_script( 'presentations', $plugin . 'js/main.js', array( 'jquery', 'jmpress' ), false, true );
}
function presentation_shortcode( $atts, $content = '' ) {
// Mark that we've found a valid [presentation] shortcode
$this->presentation_initialized = true;
$atts = shortcode_atts(
array(
'duration' => '',
'height' => '',
'width' => '',
'bgcolor' => '',
'bgimg' => '',
'autoplay' => '',
// Settings
'transition' => '',
'scale' => '',
'rotate' => '',
'fade' => '',
'fadebullets' => '',
), $atts, 'presentation'
);
$this->presentation_settings = array(
'transition' => 'down',
'scale' => 1,
'rotate' => 0,
'fade' => 'on',
'fadebullets' => 0,
'last' => array(
'x' => 0,
'y' => 0,
'scale' => 1,
'rotate' => 0,
),
);
// Set the presentation-wide settings
if ( '' != trim( $atts['transition'] ) ) {
$this->presentation_settings['transition'] = $atts['transition'];
}
if ( '' != trim( $atts['scale'] ) ) {
$this->presentation_settings['scale'] = floatval( $atts['scale'] );
}
if ( '' != trim( $atts['rotate'] ) ) {
$this->presentation_settings['rotate'] = floatval( $atts['rotate'] );
}
if ( '' != trim( $atts['fade'] ) ) {
$this->presentation_settings['fade'] = $atts['fade'];
}
if ( '' != trim( $atts['fadebullets'] ) ) {
$this->presentation_settings['fadebullets'] = $atts['fadebullets'];
}
// Set any settings the slides don't care about
if ( '' != trim( $atts['duration'] ) ) {
$duration = floatval( $atts['duration'] ) . 's';
} else {
$duration = '1s';
}
// Autoplay durations are set in milliseconds
if ( '' != trim( $atts['autoplay'] ) ) {
$autoplay = floatval( $atts['autoplay'] ) * 1000;
} else {
$autoplay = 0;
} // No autoplay
// Set the presentation size as specified or with some nicely sized dimensions
if ( '' != trim( $atts['width'] ) ) {
$this->presentation_settings['width'] = intval( $atts['width'] );
} else {
$this->presentation_settings['width'] = 480;
}
if ( '' != trim( $atts['height'] ) ) {
$this->presentation_settings['height'] = intval( $atts['height'] );
} else {
$this->presentation_settings['height'] = 370;
}
// Hide the content by default in case the scripts fail
$style = 'display: none; width: ' . $this->presentation_settings['width'] . 'px; height: ' . $this->presentation_settings['height'] . 'px;';
// Check for background color XOR background image
// Use a white background if nothing specified
if ( preg_match( '/https?\:\/\/[^\'"\s]*/', $atts['bgimg'], $matches ) ) {
$style .= ' background-image: url("' . esc_url( $matches[0] ) . '");';
} else if ( '' != trim( $atts['bgcolor'] ) ) {
$style .= ' background-color: ' . esc_attr( $atts['bgcolor'] ) . ';';
} else {
$style .= ' background-color: #fff;';
}
// Not supported message style is inlined incase the style sheet doesn't get included
$out = "<section class='presentation-wrapper'>";
$out .= "<p class='not-supported-msg' style='display: inherit; padding: 25%; text-align: center;'>";
$out .= __( 'This slideshow could not be started. Try refreshing the page or viewing it in another browser.', 'jetpack' ) . '</p>';
// Bail out unless the scripts were added
if ( $this->scripts_and_style_included ) {
$out .= sprintf(
'<div class="presentation" duration="%s" data-autoplay="%s" style="%s">',
esc_attr( $duration ),
esc_attr( $autoplay ),
esc_attr( $style )
);
$out .= "<div class='nav-arrow-left'></div>";
$out .= "<div class='nav-arrow-right'></div>";
$out .= "<div class='nav-fullscreen-button'></div>";
if ( $autoplay ) {
$out .= '<div class="autoplay-overlay" style="display: none;"><p class="overlay-msg">';
$out .= __( 'Click to autoplay the presentation!', 'jetpack' );
$out .= '</p></div>';
}
$out .= do_shortcode( $content );
}
$out .= '</section>';
$this->presentation_initialized = false;
return $out;
}
function slide_shortcode( $atts, $content = '' ) {
// Bail out unless wrapped by a [presentation] shortcode
if ( ! $this->presentation_initialized ) {
return $content;
}
$atts = shortcode_atts(
array(
'transition' => '',
'scale' => '',
'rotate' => '',
'fade' => '',
'fadebullets' => '',
'bgcolor' => '',
'bgimg' => '',
), $atts, 'slide'
);
// Determine positioning based on transition
if ( '' == trim( $atts['transition'] ) ) {
$atts['transition'] = $this->presentation_settings['transition'];
}
// Setting the content scale
if ( '' == trim( $atts['scale'] ) ) {
$atts['scale'] = $this->presentation_settings['scale'];
}
if ( '' == trim( $atts['scale'] ) ) {
$scale = 1;
} else {
$scale = floatval( $atts['scale'] );
}
if ( $scale < 0 ) {
$scale *= -1;
}
// Setting the content rotation
if ( '' == trim( $atts['rotate'] ) ) {
$atts['rotate'] = $this->presentation_settings['rotate'];
}
if ( '' == trim( $atts['rotate'] ) ) {
$rotate = 0;
} else {
$rotate = floatval( $atts['rotate'] );
}
// Setting if the content should fade
if ( '' == trim( $atts['fade'] ) ) {
$atts['fade'] = $this->presentation_settings['fade'];
}
if ( 'on' == $atts['fade'] || 'true' == $atts['fade'] ) {
$fade = 'fade';
} else {
$fade = '';
}
// Setting if bullets should fade on step changes
if ( '' == trim( $atts['fadebullets'] ) ) {
$atts['fadebullets'] = $this->presentation_settings['fadebullets'];
}
if ( 'on' == $atts['fadebullets'] || 'true' == $atts['fadebullets'] ) {
$fadebullets = 'fadebullets';
} else {
$fadebullets = '';
}
$coords = $this->get_coords(
array(
'transition' => $atts['transition'],
'scale' => $scale,
'rotate' => $rotate,
)
);
$x = $coords['x'];
$y = $coords['y'];
// Check for background color XOR background image
// Use a white background if nothing specified
if ( preg_match( '/https?\:\/\/[^\'"\s]*/', $atts['bgimg'], $matches ) ) {
$style = 'background-image: url("' . esc_url( $matches[0] ) . '");';
} else if ( '' != trim( $atts['bgcolor'] ) ) {
$style = 'background-color: ' . esc_attr( $atts['bgcolor'] ) . ';';
} else {
$style = '';
}
// Put everything together and let jmpress do the magic!
$out = sprintf(
'<div class="step %s %s" data-x="%s" data-y="%s" data-scale="%s" data-rotate="%s" style="%s">',
esc_attr( $fade ),
esc_attr( $fadebullets ),
esc_attr( $x ),
esc_attr( $y ),
esc_attr( $scale ),
esc_attr( $rotate ),
esc_attr( $style )
);
$out .= '<div class="slide-content">';
$out .= do_shortcode( $content );
$out .= '</div></div>';
return $out;
}
/**
* Determines the position of the next slide based on the position and scaling of the previous slide.
*
* @param array $args : an array with the following key-value pairs
* string $transition: the transition name, "up", "down", "left", or "right"
* float $scale: the scale of the next slide (used to determine the position of the slide after that)
*
* @return array with the 'x' and 'y' coordinates of the slide
*/
function get_coords( $args ) {
if ( 0 == $args['scale'] ) {
$args['scale'] = 1;
}
$width = $this->presentation_settings['width'];
$height = $this->presentation_settings['height'];
$last = $this->presentation_settings['last'];
$scale = $last['scale'];
$next = array(
'x' => $last['x'],
'y' => $last['y'],
'scale' => $args['scale'],
'rotate' => $args['rotate'],
);
// All angles are measured from the vertical axis, so everything is backwards!
$diagAngle = atan2( $width, $height );
$diagonal = sqrt( pow( $width, 2 ) + pow( $height, 2 ) );
// We offset the angles by the angle formed by the diagonal so that
// we can multiply the sines directly against the diagonal length
$theta = deg2rad( $last['rotate'] ) - $diagAngle;
$phi = deg2rad( $next['rotate'] ) - $diagAngle;
// We start by displacing by the slide dimensions
$totalHorizDisp = $width * $scale;
$totalVertDisp = $height * $scale;
// If the previous slide was rotated, we add the incremental offset from the rotation
// Namely the difference between the regular dimension (no rotation) and the component
// of the diagonal for that angle
$totalHorizDisp += ( ( ( abs( sin( $theta ) ) * $diagonal ) - $width ) / 2 ) * $scale;
$totalVertDisp += ( ( ( abs( cos( $theta ) ) * $diagonal ) - $height ) / 2 ) * $scale;
// Similarly, we check if the current slide has been rotated and add whatever additional
// offset has been added. This is so that two rotated corners don't clash with each other.
// Note: we are checking the raw angle relative to the vertical axis, NOT the diagonal angle.
if ( 0 !== $next['rotate'] % 180 ) {
$totalHorizDisp += ( abs( ( sin( $phi ) * $diagonal ) - $width ) / 2 ) * $next['scale'];
$totalVertDisp += ( abs( ( cos( $phi ) * $diagonal ) - $height ) / 2 ) * $next['scale'];
}
switch ( trim( $args['transition'] ) ) {
case 'none':
break;
case 'left':
$next['x'] -= $totalHorizDisp;
break;
case 'right':
$next['x'] += $totalHorizDisp;
break;
case 'up':
$next['y'] -= $totalVertDisp;
break;
case 'down':
default:
$next['y'] += $totalVertDisp;
break;
}
$this->presentation_settings['last'] = $next;
return $next;
}
}
$GLOBALS['presentations'] = new Presentations();
endif;

View file

@ -0,0 +1,147 @@
<?php
/**
* Embed recipe 'cards' in post, with basic styling and print functionality
*
*/
class Jetpack_Recipes {
private $scripts_and_style_included = false;
function __construct() {
add_action( 'init', array( $this, 'action_init' ) );
}
function action_init() {
// Enqueue styles if [recipe] exists
add_action( 'wp_head', array( $this, 'add_scripts' ), 1 );
// Render [recipe]
add_shortcode( 'recipe', array( $this, 'recipe_shortcode' ) );
}
/**
* Enqueue scripts and styles
*/
function add_scripts() {
if ( empty( $GLOBALS['posts'] ) || ! is_array( $GLOBALS['posts'] ) ) {
return;
}
foreach ( $GLOBALS['posts'] as $p ) {
if ( has_shortcode( $p->post_content, 'recipe' ) ) {
$this->scripts_and_style_included = true;
break;
}
}
if ( ! $this->scripts_and_style_included ) {
return;
}
if( is_rtl() ) {
wp_enqueue_style( 'jetpack-recipes-style', plugins_url( '/css/rtl/recipes-rtl.css', __FILE__ ), array(), '20130919' );
} else {
wp_enqueue_style( 'jetpack-recipes-style', plugins_url( '/css/recipes.css', __FILE__ ), array(), '20130919' );
}
wp_enqueue_script( 'jetpack-recipes-printthis', plugins_url( '/js/recipes-printthis.js', __FILE__ ), array( 'jquery' ), '20131230' );
wp_enqueue_script( 'jetpack-recipes-js', plugins_url( '/js/recipes.js', __FILE__ ), array( 'jquery', 'jetpack-recipes-printthis' ), '20131230' );
$title_var = wp_title( '|', false, 'right' );
$print_css_var = plugins_url( '/css/recipes-print.css', __FILE__ );
wp_localize_script( 'jetpack-recipes-js', 'jetpack_recipes_vars', array(
'pageTitle' => $title_var,
'loadCSS' => $print_css_var
) );
}
/**
* Our [recipe] shortcode.
* Prints recipe data styled to look good on *any* theme.
*
* @return resume_shortcode_html
*/
static function recipe_shortcode( $atts, $content = '' ) {
$atts = shortcode_atts( array(
'title' => '', //string
'servings' => '', //intval
'time' => '', //string
'difficulty' => '', //string
'print' => '', //string
), $atts, 'recipe' );
return self::recipe_shortcode_html( $atts, $content );
}
/**
* The recipe output
*
* @return Html
*/
static function recipe_shortcode_html( $atts, $content = '' ) {
$html = false;
$html = '<div class="hrecipe jetpack-recipe" itemscope itemtype="http://schema.org/Recipe">';
// Print the recipe title if exists
if ( '' != $atts['title'] ) {
$html .= '<h3 class="jetpack-recipe-title" itemprop="name">' . esc_html( $atts['title'] ) . '</h3>';
}
// Print the recipe meta if exists
if ( '' != $atts['servings'] || '' != $atts['time'] || '' != $atts['difficulty'] || '' != $atts['print'] ) {
$html .= '<ul class="jetpack-recipe-meta">';
if ( '' != $atts['servings'] ) {
$html .= sprintf( '<li class="jetpack-recipe-servings" itemprop="recipeYield"><strong>%1$s: </strong>%2$s</li>',
__( 'Servings', 'jetpack' ),
esc_html( $atts['servings'] )
);
}
if ( '' != $atts['time'] ) {
$html .= sprintf( '<li class="jetpack-recipe-time" itemprop="totalTime"><strong>%1$s: </strong>%2$s</li>',
__( 'Time', 'jetpack' ),
esc_html( $atts['time'] )
);
}
if ( '' != $atts['difficulty'] ) {
$html .= sprintf( '<li class="jetpack-recipe-difficulty"><strong>%1$s: </strong>%2$s</li>',
__( 'Difficulty', 'jetpack' ),
esc_html( $atts['difficulty'] )
);
}
if ( 'false' != $atts['print'] ) {
$html .= sprintf( '<li class="jetpack-recipe-print"><a href="#">%s</a></li>',
__( 'Print', 'jetpack' )
);
}
$html .= '</ul>';
}
// Print content between codes
$html .= '<div class="jetpack-recipe-content">' . do_shortcode( $content ) . '</div>';
// Close it up
$html .= '</div>';
// If there is a recipe within a recipe, remove the shortcode
if ( has_shortcode( $html, 'recipe' ) ) {
remove_shortcode( 'recipe' );
}
// Sanitize html
$html = wp_kses_post( $html );
// Return the HTML block
return $html;
}
}
new Jetpack_Recipes();

View file

@ -0,0 +1,57 @@
<?php
/* Scribd Short Code
Author: Nick Momrik
[scribd id=DOCUMENT_ID key=DOCUMENT_KEY mode=MODE]
DOCUMENT_ID is an integer (also used as an object_id)
DOCUMENT_KEY is an alphanumeric hash ('-' character as well)
MODE can be 'list', 'book', 'slide', 'slideshow', or 'tile'
[scribd id=39027960 key=key-3kaiwcjqhtipf25m8tw mode=list]
*/
function scribd_shortcode_handler( $atts ) {
$atts = shortcode_atts( array(
'id' => 0,
'key' => 0,
'mode' => '',
), $atts, 'scribd' );
$modes = array( 'list', 'book', 'slide', 'slideshow', 'tile' );
$atts['id'] = (int) $atts['id'];
if ( preg_match( '/^[A-Za-z0-9-]+$/', $atts['key'], $m ) ) {
$atts['key'] = $m[0];
if ( ! in_array( $atts['mode'], $modes ) ) {
$atts['mode'] = '';
}
return scribd_shortcode_markup( $atts );
} else {
return '';
}
}
function scribd_shortcode_markup( $atts ) {
$markup = <<<EOD
<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>
<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>
EOD;
return $markup;
}
add_shortcode( 'scribd', 'scribd_shortcode_handler' );
// Scribd supports HTTPS, so use that endpoint to get HTTPS-compatible embeds
function scribd_https_oembed( $providers ) {
if ( isset( $providers['#https?://(www\.)?scribd\.com/doc/.*#i'] ) ) {
$providers['#https?://(www\.)?scribd\.com/doc/.*#i'][0] = 'https://www.scribd.com/services/oembed';
}
return $providers;
}
add_filter( 'oembed_providers', 'scribd_https_oembed' );

View file

@ -0,0 +1,115 @@
<?php
// guarantee use of https
wp_oembed_remove_provider( '#https?://(www\.)?slideshare\.net/.*#i' );
wp_oembed_add_provider( '#https?://(www\.)?slideshare\.net/.*#i', 'https://www.slideshare.net/api/oembed/2', true );
/*
* Slideshare shortcode format:
* Old style (still compatible): [slideshare id=5342235&doc=camprock-101002163655-phpapp01&w=300&h=200]
* New style: [slideshare id=5342235&w=300&h=200&fb=0&mw=0&mh=0&sc=no]
*
* Legend:
* id = Document ID provided by Slideshare
* w = Width of iFrame (int)
* h = Height of iFrame (int)
* fb = iFrame frameborder (int)
* mw = iFrame marginwidth (int)
* mh = iFrame marginheight (int)
* sc = iFrame Scrollbar (yes/no)
* pro = Slideshare Pro (yes/no)
* style = Inline CSS (string)
**/
add_shortcode( 'slideshare', 'slideshare_shortcode' );
function slideshare_shortcode( $atts ) {
global $content_width;
$params = shortcode_new_to_old_params( $atts );
parse_str( $params, $arguments );
if ( empty( $arguments ) ) {
return '<!-- SlideShare error: no arguments -->';
}
$attr = shortcode_atts(
array(
'id' => '',
'w' => '',
'h' => '',
'fb' => '',
'mw' => '',
'mh' => '',
'sc' => '',
'pro' => '',
'style' => '',
), $arguments
);
// check that the Slideshare ID contains letters, numbers and query strings
$pattern = '/[^-_a-zA-Z0-9?=&]/';
if ( empty( $attr['id'] ) || preg_match( $pattern, $attr['id'] ) ) {
return '<!-- SlideShare error: id is missing or has illegal characters -->';
}
// check the width/height
$w = $attr['w'];
if ( empty( $w ) && ! empty( $content_width ) ) {
$w = intval( $content_width );
} elseif ( ! ( $w = intval( $w ) ) || $w < 300 || $w > 1600 ) {
$w = 425;
} else {
$w = intval( $w );
}
$h = ceil( $w * 348 / 425 ); // Note: user-supplied height is ignored.
if ( isset( $attr['pro'] ) && $attr['pro'] ) {
$source = 'https://www.slideshare.net/slidesharepro/' . $attr['id'];
} else {
$source = 'https://www.slideshare.net/slideshow/embed_code/' . $attr['id'];
}
if ( isset( $rel ) ) {
$source = add_query_arg( 'rel', intval( $rel ), $source );
}
if ( isset( $startSlide ) ) {
$source = add_query_arg( 'startSlide', intval( $startSlide ), $source );
}
$player = sprintf( "<iframe src='%s' width='%d' height='%d'", esc_url( $source ), $w, $h );
// check the frameborder
if ( ! empty( $attr['fb'] ) || '0' === $attr['fb'] ) {
$player .= " frameborder='" . intval( $attr['fb'] ) . "'";
}
// check the margin width; if not empty, cast as int
if ( ! empty( $attr['mw'] ) || '0' === $attr['mw'] ) {
$player .= " marginwidth='" . intval( $attr['mw'] ) . "'";
}
// check the margin height, if not empty, cast as int
if ( ! empty( $attr['mh'] ) || '0' === $attr['mh'] ) {
$player .= " marginheight='" . intval( $attr['mh'] ) . "'";
}
if ( ! empty( $attr['style'] ) ) {
$player .= " style='" . esc_attr( $attr['style'] ) . "'";
}
// check the scrollbar; cast as a lowercase string for comparison
if ( ! empty( $attr['sc'] ) ) {
$sc = strtolower( $attr['sc'] );
if ( in_array( $sc, array( 'yes', 'no' ) ) ) {
$player .= " scrolling='" . $sc . "'";
}
}
$player .= ' allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>';
return $player;
}

View file

@ -0,0 +1,330 @@
<?php
/**
* Slideshow shortcode usage: [gallery type="slideshow"] or the older [slideshow]
*/
class Jetpack_Slideshow_Shortcode {
public $instance_count = 0;
function __construct() {
global $shortcode_tags;
$needs_scripts = false;
// Only if the slideshow shortcode has not already been defined.
if ( ! array_key_exists( 'slideshow', $shortcode_tags ) ) {
add_shortcode( 'slideshow', array( $this, 'shortcode_callback' ) );
$needs_scripts = true;
}
// Only if the gallery shortcode has not been redefined.
if ( isset( $shortcode_tags['gallery'] ) && 'gallery_shortcode' === $shortcode_tags['gallery'] ) {
add_filter( 'post_gallery', array( $this, 'post_gallery' ), 1002, 2 );
add_filter( 'jetpack_gallery_types', array( $this, 'add_gallery_type' ), 10 );
$needs_scripts = true;
}
if ( $needs_scripts ) {
add_action( 'wp_enqueue_scripts', array( $this, 'maybe_enqueue_scripts' ), 1 );
}
/**
* For the moment, comment out the setting for v2.8.
* The remainder should work as it always has.
* See: https://github.com/Automattic/jetpack/pull/85/files
*/
// add_action( 'admin_init', array( $this, 'register_settings' ), 5 );
}
/**
* Responds to the [gallery] shortcode, but not an actual shortcode callback.
*
* @param $value string An empty string if nothing has modified the gallery output, the output html otherwise
* @param $attr array The shortcode attributes array
*
* @return string The (un)modified $value
*/
function post_gallery( $value, $attr ) {
// Bail if somebody else has done something
if ( ! empty( $value ) ) {
return $value;
}
// If [gallery type="slideshow"] have it behave just like [slideshow]
if ( ! empty( $attr['type'] ) && 'slideshow' == $attr['type'] ) {
return $this->shortcode_callback( $attr );
}
return $value;
}
/**
* Add the Slideshow type to gallery settings
*
* @see Jetpack_Tiled_Gallery::media_ui_print_templates
*
* @param $types array An array of types where the key is the value, and the value is the caption.
*
* @return array
*/
function add_gallery_type( $types = array() ) {
$types['slideshow'] = esc_html__( 'Slideshow', 'jetpack' );
return $types;
}
function register_settings() {
add_settings_section( 'slideshow_section', __( 'Image Gallery Slideshow', 'jetpack' ), '__return_empty_string', 'media' );
add_settings_field( 'jetpack_slideshow_background_color', __( 'Background color', 'jetpack' ), array( $this, 'slideshow_background_color_callback' ), 'media', 'slideshow_section' );
register_setting( 'media', 'jetpack_slideshow_background_color', array( $this, 'slideshow_background_color_sanitize' ) );
}
function slideshow_background_color_callback() {
$options = array(
'black' => __( 'Black', 'jetpack' ),
'white' => __( 'White', 'jetpack' ),
);
$this->settings_select( 'jetpack_slideshow_background_color', $options );
}
function settings_select( $name, $values, $extra_text = '' ) {
if ( empty( $name ) || empty( $values ) || ! is_array( $values ) ) {
return;
}
$option = get_option( $name );
?>
<fieldset>
<select name="<?php echo esc_attr( $name ); ?>" id="<?php echo esc_attr( $name ); ?>">
<?php foreach ( $values as $key => $value ) : ?>
<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $option ); ?>>
<?php echo esc_html( $value ); ?>
</option>
<?php endforeach; ?>
</select>
<?php if ( ! empty( $extra_text ) ) : ?>
<p class="description"><?php echo esc_html( $extra_text ); ?></p>
<?php endif; ?>
</fieldset>
<?php
}
function slideshow_background_color_sanitize( $value ) {
return ( 'white' == $value ) ? 'white' : 'black';
}
function shortcode_callback( $attr ) {
global $post;
$attr = shortcode_atts(
array(
'trans' => 'fade',
'order' => 'ASC',
'orderby' => 'menu_order ID',
'id' => $post->ID,
'include' => '',
'exclude' => '',
'autostart' => true,
'size' => '',
), $attr, 'slideshow'
);
if ( 'rand' == strtolower( $attr['order'] ) ) {
$attr['orderby'] = 'none';
}
$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
if ( ! $attr['orderby'] ) {
$attr['orderby'] = 'menu_order ID';
}
if ( ! $attr['size'] ) {
$attr['size'] = 'full';
}
// Don't restrict to the current post if include
$post_parent = ( empty( $attr['include'] ) ) ? intval( $attr['id'] ) : null;
$attachments = get_posts(
array(
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'posts_per_page' => - 1,
'post_parent' => $post_parent,
'order' => $attr['order'],
'orderby' => $attr['orderby'],
'include' => $attr['include'],
'exclude' => $attr['exclude'],
)
);
if ( count( $attachments ) < 1 ) {
return false;
}
$gallery_instance = sprintf( 'gallery-%d-%d', $attr['id'], ++$this->instance_count );
$gallery = array();
foreach ( $attachments as $attachment ) {
$attachment_image_src = wp_get_attachment_image_src( $attachment->ID, $attr['size'] );
$attachment_image_src = $attachment_image_src[0]; // [url, width, height]
$attachment_image_title = get_the_title( $attachment->ID );
$attachment_image_alt = get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true );
/**
* Filters the Slideshow slide caption.
*
* @module shortcodes
*
* @since 2.3.0
*
* @param string wptexturize( strip_tags( $attachment->post_excerpt ) ) Post excerpt.
* @param string $attachment ->ID Attachment ID.
*/
$caption = apply_filters( 'jetpack_slideshow_slide_caption', wptexturize( strip_tags( $attachment->post_excerpt ) ), $attachment->ID );
$gallery[] = (object) array(
'src' => (string) esc_url_raw( $attachment_image_src ),
'id' => (string) $attachment->ID,
'title' => (string) esc_attr( $attachment_image_title ),
'alt' => (string) esc_attr( $attachment_image_alt ),
'caption' => (string) $caption,
'itemprop' => 'image',
);
}
$color = Jetpack_Options::get_option( 'slideshow_background_color', 'black' );
$js_attr = array(
'gallery' => $gallery,
'selector' => $gallery_instance,
'trans' => $attr['trans'] ? $attr['trans'] : 'fade',
'autostart' => $attr['autostart'] ? $attr['autostart'] : 'true',
'color' => $color,
);
// Show a link to the gallery in feeds.
if ( is_feed() ) {
return sprintf(
'<a href="%s">%s</a>',
esc_url( get_permalink( $post->ID ) . '#' . $gallery_instance . '-slideshow' ),
esc_html__( 'Click to view slideshow.', 'jetpack' )
);
}
return $this->slideshow_js( $js_attr );
}
/**
* Render the slideshow js
*
* Returns the necessary markup and js to fire a slideshow.
*
* @param $attr array Attributes for the slideshow.
*
* @uses $this->enqueue_scripts()
*
* @return string HTML output.
*/
function slideshow_js( $attr ) {
// Enqueue scripts
$this->enqueue_scripts();
$output = '';
if ( defined( 'JSON_HEX_AMP' ) ) {
// This is nice to have, but not strictly necessary since we use _wp_specialchars() below
$gallery = json_encode( $attr['gallery'], JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT );
} else {
$gallery = json_encode( $attr['gallery'] );
}
$output .= '<p class="jetpack-slideshow-noscript robots-nocontent">' . esc_html__( 'This slideshow requires JavaScript.', 'jetpack' ) . '</p>';
$output .= sprintf(
'<div id="%s" class="slideshow-window jetpack-slideshow slideshow-%s" data-trans="%s" data-autostart="%s" data-gallery="%s" itemscope itemtype="http://schema.org/ImageGallery"></div>',
esc_attr( $attr['selector'] . '-slideshow' ),
esc_attr( $attr['color'] ),
esc_attr( $attr['trans'] ),
esc_attr( $attr['autostart'] ),
/*
* The input to json_encode() above can contain '&quot;'.
*
* For calls to json_encode() lacking the JSON_HEX_AMP option,
* that '&quot;' is left unaltered. Running '&quot;' through esc_attr()
* also leaves it unaltered since esc_attr() does not double-encode.
*
* This means we end up with an attribute like
* `data-gallery="{&quot;foo&quot;:&quot;&quot;&quot;}"`,
* which is interpreted by the browser as `{"foo":"""}`,
* which cannot be JSON decoded.
*
* The preferred workaround is to include the JSON_HEX_AMP (and friends)
* options, but these are not available until 5.3.0.
* Alternatively, we can use _wp_specialchars( , , , true ) instead of
* esc_attr(), which will double-encode.
*
* Since we can't rely on JSON_HEX_AMP, we do both.
*/
_wp_specialchars( wp_check_invalid_utf8( $gallery ), ENT_QUOTES, false, true )
);
return $output;
}
/**
* Infinite Scroll needs the scripts to be present at all times
*/
function maybe_enqueue_scripts() {
if ( is_home() && current_theme_supports( 'infinite-scroll' ) ) {
$this->enqueue_scripts();
}
}
/**
* Actually enqueues the scripts and styles.
*/
function enqueue_scripts() {
static $enqueued = false;
if ( $enqueued ) {
return;
}
wp_enqueue_script( 'jquery-cycle', plugins_url( '/js/jquery.cycle.js', __FILE__ ), array( 'jquery' ), '2.9999.8', true );
wp_enqueue_script( 'jetpack-slideshow', plugins_url( '/js/slideshow-shortcode.js', __FILE__ ), array( 'jquery-cycle' ), '20121214.1', true );
if ( is_rtl() ) {
wp_enqueue_style( 'jetpack-slideshow', plugins_url( '/css/rtl/slideshow-shortcode-rtl.css', __FILE__ ) );
} else {
wp_enqueue_style( 'jetpack-slideshow', plugins_url( '/css/slideshow-shortcode.css', __FILE__ ) );
}
wp_localize_script(
'jetpack-slideshow',
'jetpackSlideshowSettings',
/**
* Filters the slideshow JavaScript spinner.
*
* @module shortcodes
*
* @since 2.1.0
*
* @param array $args
* - string - spinner - URL of the spinner image.
*/
apply_filters(
'jetpack_js_slideshow_settings', array(
'spinner' => plugins_url( '/img/slideshow-loader.gif', __FILE__ ),
)
)
);
$enqueued = true;
}
public static function init() {
$gallery = new Jetpack_Slideshow_Shortcode;
}
}
add_action( 'init', array( 'Jetpack_Slideshow_Shortcode', 'init' ) );

View file

@ -0,0 +1,310 @@
<?php
/*
Plugin Name: SoundCloud Shortcode
Plugin URI: http://wordpress.org/extend/plugins/soundcloud-shortcode/
Description: Converts SoundCloud WordPress shortcodes to a SoundCloud widget. Example: [soundcloud]http://soundcloud.com/forss/flickermood[/soundcloud]
Version: 2.3
Author: SoundCloud Inc., simplified for Jetpack by Automattic, Inc.
Author URI: http://soundcloud.com
License: GPLv2
Original version: Johannes Wagener <johannes@soundcloud.com>
Options support: Tiffany Conroy <tiffany@soundcloud.com>
HTML5 & oEmbed support: Tim Bormans <tim@soundcloud.com>
*/
/*
A8C: Taken from http://plugins.svn.wordpress.org/soundcloud-shortcode/trunk/
at revision 664386.
Commenting out (instead of removing) and replacing code with custom modifs
so it's eqsy to see what differs from the standard DOTORG version.
All custom modifs are annoted with "A8C" keyword in comment.
*/
/**
* Register oEmbed provider
*/
wp_oembed_add_provider( '#https?://(?:api\.)?soundcloud\.com/.*#i', 'http://soundcloud.com/oembed', true );
/**
* Register SoundCloud shortcode
*/
add_shortcode( 'soundcloud', 'soundcloud_shortcode' );
/**
* SoundCloud shortcode handler
*
* @param string|array $atts The attributes passed to the shortcode like [soundcloud attr1="value" /].
* Is an empty string when no arguments are given.
* @param string $content The content between non-self closing [soundcloud]...[/soundcloud] tags.
*
* @return string Widget embed code HTML
*/
function soundcloud_shortcode( $atts, $content = null ) {
// Custom shortcode options
$shortcode_options = array_merge( array( 'url' => trim( $content ) ), is_array( $atts ) ? $atts : array() );
// Turn shortcode option "param" (param=value&param2=value) into array
$shortcode_params = array();
if ( isset( $shortcode_options['params'] ) ) {
parse_str( html_entity_decode( $shortcode_options['params'] ), $shortcode_params );
}
$shortcode_options['params'] = $shortcode_params;
$player_type = soundcloud_get_option( 'player_type', 'visual' );
$isIframe = $player_type !== 'flash';
$isVisual = ! $player_type || $player_type === 'visual' || $shortcode_options['visual'];
// User preference options
$plugin_options = array_filter(
array(
'iframe' => $isIframe,
'width' => soundcloud_get_option( 'player_width' ),
'height' => soundcloud_url_has_tracklist( $shortcode_options['url'] ) ? soundcloud_get_option( 'player_height_multi' ) : soundcloud_get_option( 'player_height' ),
'params' => array_filter(
array(
'auto_play' => soundcloud_get_option( 'auto_play' ),
'show_comments' => soundcloud_get_option( 'show_comments' ),
'color' => soundcloud_get_option( 'color' ),
'visual' => ( $isVisual ? 'true' : 'false' ),
)
),
)
);
// Needs to be an array
if ( ! isset( $plugin_options['params'] ) ) {
$plugin_options['params'] = array();
}
// plugin options < shortcode options
$options = array_merge(
$plugin_options,
$shortcode_options
);
// plugin params < shortcode params
$options['params'] = array_merge(
$plugin_options['params'],
$shortcode_options['params']
);
// The "url" option is required
if ( ! isset( $options['url'] ) ) {
return '';
} else {
$options['url'] = trim( $options['url'] );
}
// Both "width" and "height" need to be integers
if ( isset( $options['width'] ) && ! preg_match( '/^\d+$/', $options['width'] ) ) {
// set to 0 so oEmbed will use the default 100% and WordPress themes will leave it alone
$options['width'] = 0;
}
if ( isset( $options['height'] ) && ! preg_match( '/^\d+$/', $options['height'] ) ) {
unset( $options['height'] );
}
// The "iframe" option must be true to load the iframe widget
$iframe = soundcloud_booleanize( $options['iframe'] );
// Remove visual parameter from Flash widget, when it's false because that's the default, or when displaying the smallest player
if ( $options['params']['visual'] && ( ! $iframe || ! soundcloud_booleanize( $options['params']['visual'] ) || ( isset( $options['height'] ) && '20' == $options['height'] ) ) ) {
unset( $options['params']['visual'] );
}
// Merge in "url" value
$options['params'] = array_merge(
array(
'url' => $options['url'],
), $options['params']
);
// Return html embed code
if ( $iframe ) {
return soundcloud_iframe_widget( $options );
} else {
return soundcloud_flash_widget( $options );
}
}
/**
* Plugin options getter
*
* @param string|array $option Option name
* @param mixed $default Default value
*
* @return mixed Option value
*/
function soundcloud_get_option( $option, $default = false ) {
$value = get_option( 'soundcloud_' . $option );
return $value === '' ? $default : $value;
}
/**
* Booleanize a value
*
* @param boolean|string $value
*
* @return boolean
*/
function soundcloud_booleanize( $value ) {
return is_bool( $value ) ? $value : $value === 'true' ? true : false;
}
/**
* Decide if a url has a tracklist
*
* @param string $url
*
* @return boolean
*/
function soundcloud_url_has_tracklist( $url ) {
return preg_match( '/^(.+?)\/(sets|groups|playlists)\/(.+?)$/', $url );
}
/**
* Parameterize url
*
* @param array $match Matched regex
*
* @return string Parameterized url
*/
function soundcloud_oembed_params_callback( $match ) {
global $soundcloud_oembed_params;
// Convert URL to array
$url = parse_url( urldecode( $match[1] ) );
// Convert URL query to array
parse_str( $url['query'], $query_array );
// Build new query string
$query = http_build_query( array_merge( $query_array, $soundcloud_oembed_params ) );
return 'src="' . $url['scheme'] . '://' . $url['host'] . $url['path'] . '?' . $query;
}
/**
* Iframe widget embed code
*
* @param array $options Parameters
*
* @return string Iframe embed code
*/
function soundcloud_iframe_widget( $options ) {
// Build URL
$url = set_url_scheme( 'https://w.soundcloud.com/player/?' . http_build_query( $options['params'] ) );
// Set default width if not defined
$width = isset( $options['width'] ) && $options['width'] !== 0 ? $options['width'] : '100%';
// Set default height if not defined
$height = isset( $options['height'] ) && $options['height'] !== 0
? $options['height']
: ( soundcloud_url_has_tracklist( $options['url'] ) || ( isset( $options['params']['visual'] ) && soundcloud_booleanize( $options['params']['visual'] ) ) ? '450' : '166' );
return sprintf( '<iframe width="%s" height="%s" scrolling="no" frameborder="no" src="%s"></iframe>', $width, $height, $url );
}
/**
* Legacy Flash widget embed code
*
* @param array $options Parameters
*
* @return string Flash embed code
*/
function soundcloud_flash_widget( $options ) {
// Build URL
$url = set_url_scheme( 'https://player.soundcloud.com/player.swf?' . http_build_query( $options['params'] ) );
// Set default width if not defined
$width = isset( $options['width'] ) && $options['width'] !== 0 ? $options['width'] : '100%';
// Set default height if not defined
$height = isset( $options['height'] ) && $options['height'] !== 0 ? $options['height'] : ( soundcloud_url_has_tracklist( $options['url'] ) ? '255' : '81' );
return preg_replace(
'/\s\s+/', '', sprintf(
'<object width="%s" height="%s">
<param name="movie" value="%s" />
<param name="allowscriptaccess" value="always" />
<embed width="%s" height="%s" src="%s" allowscriptaccess="always" type="application/x-shockwave-flash"></embed>
</object>', $width, $height, $url, $width, $height, $url
)
);
}
/**
* SoundCloud Embed Reversal
*
* Converts a generic HTML embed code from SoundClound into a
* WordPress.com-compatibly shortcode.
*
* @param string $content HTML content.
*
* @return string Parsed content.
*/
function jetpack_soundcloud_embed_reversal( $content ) {
if ( false === stripos( $content, 'w.soundcloud.com/player' ) ) {
return $content;
}
/* Sample embed code:
<iframe width="100%" height="450" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/150745932&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true"></iframe>
*/
$regexes = array();
$regexes[] = '#<iframe[^>]+?src="((?:https?:)?//w\.soundcloud\.com/player/[^"\']++)"[^>]*+>\s*?</iframe>#i';
$regexes[] = '#&lt;iframe(?:[^&]|&(?!gt;))+?src="((?:https?:)?//w\.soundcloud\.com/player/[^"\']++)"(?:[^&]|&(?!gt;))*+&gt;\s*?&lt;/iframe&gt;#i';
foreach ( $regexes as $regex ) {
if ( ! preg_match_all( $regex, $content, $matches, PREG_SET_ORDER ) ) {
continue;
}
foreach ( $matches as $match ) {
// if pasted from the visual editor - prevent double encoding
$match[1] = str_replace( '&amp;amp;', '&amp;', $match[1] );
$args = parse_url( html_entity_decode( $match[1] ), PHP_URL_QUERY );
$args = wp_parse_args( $args );
if ( ! preg_match( '#^(?:https?:)?//api\.soundcloud\.com/.+$#i', $args['url'], $url_matches ) ) {
continue;
}
if ( ! preg_match( '#height="(\d+)"#i', $match[0], $hmatch ) ) {
$height = '';
} else {
$height = ' height="' . intval( $hmatch[1] ) . '"';
}
unset( $args['url'] );
$params = 'params="';
if ( count( $args ) > 0 ) {
foreach ( $args as $key => $value ) {
$params .= esc_html( $key ) . '=' . esc_html( $value ) . '&amp;';
}
$params = substr( $params, 0, -5 );
}
$params .= '"';
$shortcode = '[soundcloud url="' . esc_url( $url_matches[0] ) . '" ' . $params . ' width="100%"' . $height . ' iframe="true" /]';
$replace_regex = sprintf( '#\s*%s\s*#', preg_quote( $match[0], '#' ) );
$content = preg_replace( $replace_regex, sprintf( "\n\n%s\n\n", $shortcode ), $content );
/** This action is documented in modules/shortcodes/youtube.php */
do_action( 'jetpack_embed_to_shortcode', 'soundcloud', $url_matches[0] );
}
}
return $content;
}
add_filter( 'pre_kses', 'jetpack_soundcloud_embed_reversal' );

View file

@ -0,0 +1,78 @@
<?php
/*
* TED Player embed code
* http://www.ted.com
*
* http://www.ted.com/talks/view/id/210
* http://www.ted.com/talks/marc_goodman_a_vision_of_crimes_in_the_future.html
* [ted id="210" lang="en"]
* [ted id="http://www.ted.com/talks/view/id/210" lang="en"]
* [ted id=1539 lang=fr width=560 height=315]
*/
wp_oembed_add_provider( '!https?://(www\.)?ted.com/talks/view/id/.+!i', 'http://www.ted.com/talks/oembed.json', true );
wp_oembed_add_provider( '!https?://(www\.)?ted.com/talks/[a-zA-Z\-\_]+\.html!i', 'http://www.ted.com/talks/oembed.json', true );
function jetpack_shortcode_get_ted_id( $atts ) {
return ( ! empty( $atts['id'] ) ? $atts['id'] : 0 );
}
add_shortcode( 'ted', 'shortcode_ted' );
function shortcode_ted( $atts ) {
global $wp_embed;
$defaults = array(
'id' => '',
'width' => '',
'height' => '',
'lang' => 'en',
);
$atts = shortcode_atts( $defaults, $atts, 'ted' );
if ( empty( $atts['id'] ) ) {
return '<!-- Missing TED ID -->';
}
$url = '';
if ( preg_match( '#^[\d]+$#', $atts['id'], $matches ) ) {
$url = 'http://ted.com/talks/view/id/' . $matches[0];
} elseif ( preg_match( '#^https?://(www\.)?ted\.com/talks/view/id/[0-9]+$#', $atts['id'], $matches ) ) {
$url = $matches[0];
}
unset( $atts['id'] );
$args = array();
if ( is_numeric( $atts['width'] ) ) {
$args['width'] = $atts['width'];
} else if ( $embed_size_w = get_option( 'embed_size_w' ) ) {
$args['width'] = $embed_size_w;
} else if ( ! empty( $GLOBALS['content_width'] ) ) {
$args['width'] = (int) $GLOBALS['content_width'];
} else {
$args['width'] = 500;
}
// Default to a 16x9 aspect ratio if there's no height set
if ( is_numeric( $atts['height'] ) ) {
$args['height'] = $atts['height'];
} else {
$args['height'] = $args['width'] * 0.5625;
}
if ( ! empty( $atts['lang'] ) ) {
$args['lang'] = sanitize_key( $atts['lang'] );
add_filter( 'oembed_fetch_url', 'ted_filter_oembed_fetch_url', 10, 3 );
}
$retval = $wp_embed->shortcode( $args, $url );
remove_filter( 'oembed_fetch_url', 'ted_filter_oembed_fetch_url', 10 );
return $retval;
}
/**
* Filter the request URL to also include the $lang parameter
*/
function ted_filter_oembed_fetch_url( $provider, $url, $args ) {
return add_query_arg( 'lang', $args['lang'], $provider );
}

View file

@ -0,0 +1,79 @@
<?php
/**
* twitch.tv shortcode
* [twitchtv url='http://www.twitch.tv/paperbat' height='378' width='620' autoplay='false']
* [twitchtv url='http://www.twitch.tv/paperbat/b/323486192' height='378' width='620' autoplay='false']
**/
/**
* Flash:
(Live URL) http://www.twitch.tv/paperbat
Video:
<object type="application/x-shockwave-flash" height="378" width="620" id="live_embed_player_flash" data="//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf?channel=paperbat" bgcolor="#000000">
<param name="allowFullScreen" value="true" />
<param name="allowScriptAccess" value="always" />
<param name="allowNetworking" value="all" />
<param name="movie" value="//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf" />
<param name="flashvars" value="hostname=www.twitch.tv&channel=paperbat&auto_play=true&start_volume=25" />
</object>
(Archive URL) http://www.twitch.tv/paperbat/v/323486192
<object bgcolor='#000000' data='//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf' height='378' id='clip_embed_player_flash' type='application/x-shockwave-flash' width='620'>
<param name='movie' value='//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf'>
<param name='allowScriptAccess' value='always'>
<param name='allowNetworking' value='all'>
<param name='allowFullScreen' value='true'>
<param name='flashvars' value='videoId=v323486192&hostname=www.twitch.tv&channel=paperbat&auto_play=false&title=PBat+Live+-+Playin%27+for+funnnnn+%287%2F1%2F2012%29&start_volume=25'>
</object>
*/
function wpcom_twitchtv_shortcode( $attr, $content = NULL ) {
$attr = extract( shortcode_atts( array(
'height' => 378,
'width' => 620,
'url' => '',
'autoplay' => false
), $attr ) );
if ( empty( $url ) )
return;
preg_match( '|^http://www.twitch.tv/([^/?]+)(/v/(\d+))?|i', $url, $match );
$width = (int) $width;
$height = (int) $height;
$autoplay = var_export( filter_var( $autoplay, FILTER_VALIDATE_BOOLEAN ), true );
$user_id = esc_attr( $match[1] );
$video_id = 0;
if ( !empty( $match[3] ) )
$video_id = (int) $match[3];
/** This action is documented in modules/widgets/social-media-icons.php */
do_action( 'jetpack_bump_stats_extras', 'twitchtv', 'shortcode' );
if ( $video_id > 0 ) {
// Archive video
return "<object bgcolor='#000000' data='//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf' height='$height' width='$width' id='clip_embed_player_flash' type='application/x-shockwave-flash'>
<param name='movie' value='//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf'>
<param name='allowScriptAccess' value='always'>
<param name='allowNetworking' value='all'>
<param name='allowFullScreen' value='true'>
<param name='flashvars' value='videoId=v$video_id&hostname=www.twitch.tv&channel=$user_id&auto_play=$autoplay'>
</object>";
}
$html = "<object type='application/x-shockwave-flash' height='$height' width='$width' id='live_embed_player_flash' data='//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf?channel=$user_id' bgcolor='#000000'>
<param name='allowFullScreen' value='true' />
<param name='allowScriptAccess' value='always' />
<param name='allowNetworking' value='all' />
<param name='movie' value='//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf' />
<param name='flashvars' value='hostname=www.twitch.tv&channel=$user_id&auto_play=$autoplay&start_volume=25' />
</object>";
return $html;
}
add_shortcode( 'twitch', 'wpcom_twitchtv_shortcode' );
add_shortcode( 'twitchtv', 'wpcom_twitchtv_shortcode' );

View file

@ -0,0 +1,38 @@
<?php
add_shortcode( 'twitter-timeline', 'twitter_timeline_shortcode' );
function twitter_timeline_shortcode( $attr ) {
$default_atts = array(
'username' => '',
'id' => '',
'height' => '282',
'width' => '450',
);
$attr = shortcode_atts( $default_atts, $attr, 'twitter-timeline' );
$attr['username'] = preg_replace( '/[^A-Za-z0-9_]+/', '', $attr['username'] );
if ( empty( $attr['username'] ) ) {
return '<!-- ' . __( 'Invalid Twitter Timeline username', 'jetpack' ) . ' -->';
}
if ( ! is_numeric( $attr['id'] ) ) {
return '<!-- ' . __( 'Invalid Twitter Timeline id', 'jetpack' ) . ' -->';
}
$tweets_by = sprintf( __( 'Tweets by @%s', 'jetpack' ), $attr['username'] );
$output = '<a class="twitter-timeline" width="' . esc_attr( $attr['width'] ) . '" height="' . esc_attr( $attr['height'] ) . '" href="' . esc_url( 'https://twitter.com/' . $attr['username'] ) . '/" data-widget-id="' . esc_attr( $attr['id'] ) . '">' . esc_html( $tweets_by ) . '</a>';
wp_enqueue_script( 'jetpack-twitter-timeline' );
return $output;
}
function twitter_timeline_js() {
if ( is_customize_preview() ) {
wp_enqueue_script( 'jetpack-twitter-timeline' );
}
}
add_action( 'wp_enqueue_scripts', 'twitter_timeline_js' );

View file

@ -0,0 +1,23 @@
<?php
/**
* Provides VideoPress videos support when module is disabled.
*
* @since 2.4
* @since 3.9.5 Added compatibility with refactored VideoPress module.
*/
if ( ! Jetpack::is_module_active( 'videopress' ) ) {
Jetpack::dns_prefetch( array(
'//v0.wordpress.com',
) );
/**
* We won't have any videos less than sixty pixels wide. That would be silly.
*/
define( 'VIDEOPRESS_MIN_WIDTH', 60 );
include_once JETPACK__PLUGIN_DIR . 'modules/videopress/utility-functions.php';
include_once JETPACK__PLUGIN_DIR . 'modules/videopress/shortcode.php';
}

View file

@ -0,0 +1,302 @@
<?php
/*
[vimeo 141358]
[vimeo http://vimeo.com/141358]
[vimeo 141358 h=500&w=350]
[vimeo id=141358 width=350 height=500]
<iframe src="http://player.vimeo.com/video/18427511" width="400" height="225" frameborder="0"></iframe><p><a href="http://vimeo.com/18427511">Eskmo 'We Got More' (Official Video)</a> from <a href="http://vimeo.com/ninjatune">Ninja Tune</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
*/
function jetpack_shortcode_get_vimeo_id( $atts ) {
if ( isset( $atts[0] ) ) {
$atts[0] = trim( $atts[0], '=' );
$id = false;
if ( is_numeric( $atts[0] ) ) {
$id = (int) $atts[0];
} elseif ( preg_match( '|vimeo\.com/(\d+)/?$|i', $atts[0], $match ) ) {
$id = (int) $match[1];
} elseif ( preg_match( '|player\.vimeo\.com/video/(\d+)/?$|i', $atts[0], $match ) ) {
$id = (int) $match[1];
}
return $id;
}
return 0;
}
/**
* Convert a Vimeo shortcode into an embed code.
*
* @param array $atts An array of shortcode attributes.
*
* @return string The embed code for the Vimeo video.
*/
function vimeo_shortcode( $atts ) {
global $content_width;
$attr = array_map(
'intval',
shortcode_atts(
array(
'id' => 0,
'width' => 0,
'height' => 0,
'autoplay' => 0,
'loop' => 0,
), $atts
)
);
if ( isset( $atts[0] ) ) {
$attr['id'] = jetpack_shortcode_get_vimeo_id( $atts );
}
if ( ! $attr['id'] ) {
return '<!-- vimeo error: not a vimeo video -->';
}
// [vimeo 141358 h=500&w=350]
$params = shortcode_new_to_old_params( $atts ); // h=500&w=350
$params = str_replace( array( '&amp;', '&#038;' ), '&', $params );
parse_str( $params, $args );
$width = intval( $attr['width'] );
$height = intval( $attr['height'] );
// Support w and h argument as fallback.
if ( empty( $width ) && isset( $args['w'] ) ) {
$width = intval( $args['w'] );
if ( empty( $height ) && ! isset( $args['h'] ) ) {
// The case where w=300 is specified without h=200, otherwise $height
// will always equal the default of 300, no matter what w was set to.
$height = round( ( $width / 640 ) * 360 );
}
}
if ( empty( $height ) && isset( $args['h'] ) ) {
$height = (int) $args['h'];
if ( ! isset( $args['w'] ) ) {
$width = round( ( $height / 360 ) * 640 );
}
}
if ( ! $width && ! empty( $content_width ) ) {
$width = absint( $content_width );
}
// If setting the width with content_width has failed, defaulting
if ( ! $width ) {
$width = 640;
}
if ( ! $height ) {
$height = round( ( $width / 640 ) * 360 );
}
/**
* Filter the Vimeo player width.
*
* @module shortcodes
*
* @since 3.4.0
*
* @param int $width Width of the Vimeo player in pixels.
*/
$width = (int) apply_filters( 'vimeo_width', $width );
/**
* Filter the Vimeo player height.
*
* @module shortcodes
*
* @since 3.4.0
*
* @param int $height Height of the Vimeo player in pixels.
*/
$height = (int) apply_filters( 'vimeo_height', $height );
$url = esc_url( 'https://player.vimeo.com/video/' . $attr['id'] );
// Handle autoplay and loop arguments.
if (
isset( $args['autoplay'] ) && '1' === $args['autoplay'] // Parsed from the embedded URL.
|| $attr['autoplay'] // Parsed from shortcode arguments.
|| in_array( 'autoplay', $atts ) // Catch the argument passed without a value.
) {
$url = add_query_arg( 'autoplay', 1, $url );
}
if (
isset( $args['loop'] ) && '1' === $args['loop'] // Parsed from the embedded URL.
|| $attr['loop'] // Parsed from shortcode arguments.
|| in_array( 'loop', $atts ) // Catch the argument passed without a value.
) {
$url = add_query_arg( 'loop', 1, $url );
}
$html = sprintf(
'<div class="embed-vimeo" style="text-align: center;"><iframe src="%1$s" width="%2$u" height="%3$u" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>',
esc_url( $url ),
esc_attr( $width ),
esc_attr( $height )
);
/**
* Filter the Vimeo player HTML.
*
* @module shortcodes
*
* @since 1.2.3
*
* @param string $html Embedded Vimeo player HTML.
*/
$html = apply_filters( 'video_embed_html', $html );
return $html;
}
add_shortcode( 'vimeo', 'vimeo_shortcode' );
/**
* Callback to modify output of embedded Vimeo video using Jetpack's shortcode.
*
* @since 3.9
*
* @param array $matches Regex partial matches against the URL passed.
* @param array $attr Attributes received in embed response
* @param array $url Requested URL to be embedded
*
* @return string Return output of Vimeo shortcode with the proper markup.
*/
function wpcom_vimeo_embed_url( $matches, $attr, $url ) {
return vimeo_shortcode( array( $url ) );
}
/**
* For bare URLs on their own line of the form
* http://vimeo.com/12345
*
* @since 3.9
*
* @uses wpcom_vimeo_embed_url
*/
function wpcom_vimeo_embed_url_init() {
wp_embed_register_handler( 'wpcom_vimeo_embed_url', '#https?://(.+\.)?vimeo\.com/#i', 'wpcom_vimeo_embed_url' );
}
// Register handler to modify Vimeo embeds using Jetpack's shortcode output.
add_action( 'init', 'wpcom_vimeo_embed_url_init' );
function vimeo_embed_to_shortcode( $content ) {
if ( false === stripos( $content, 'player.vimeo.com/video/' ) ) {
return $content;
}
$regexp = '!<iframe\s+src=[\'"](https?:)?//player\.vimeo\.com/video/(\d+)[\w=&;?]*[\'"]((?:\s+\w+=[\'"][^\'"]*[\'"])*)((?:[\s\w]*))></iframe>!i';
$regexp_ent = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $regexp, ENT_NOQUOTES ) );
foreach ( array( 'regexp', 'regexp_ent' ) as $reg ) {
if ( ! preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) {
continue;
}
foreach ( $matches as $match ) {
$id = (int) $match[2];
$params = $match[3];
if ( 'regexp_ent' == $reg ) {
$params = html_entity_decode( $params );
}
$params = wp_kses_hair( $params, array( 'http' ) );
$width = isset( $params['width'] ) ? (int) $params['width']['value'] : 0;
$height = isset( $params['height'] ) ? (int) $params['height']['value'] : 0;
$wh = '';
if ( $width && $height ) {
$wh = ' w=' . $width . ' h=' . $height;
}
$shortcode = '[vimeo ' . $id . $wh . ']';
$content = str_replace( $match[0], $shortcode, $content );
}
}
return $content;
}
add_filter( 'pre_kses', 'vimeo_embed_to_shortcode' );
/**
* Replaces shortcodes and plain-text URLs to Vimeo videos with Vimeo embeds.
* Covers shortcode usage [vimeo 1234] | [vimeo https://vimeo.com/1234] | [vimeo http://vimeo.com/1234]
* Or plain text URLs https://vimeo.com/1234 | vimeo.com/1234 | //vimeo.com/1234
* Links are left intact.
*
* @since 3.7.0
* @since 3.9.5 One regular expression matches shortcodes and plain URLs.
*
* @param string $content HTML content
* @return string The content with embeds instead of URLs
*/
function vimeo_link( $content ) {
/**
* [vimeo 12345]
* [vimeo http://vimeo.com/12345]
*/
$shortcode = "(?:\[vimeo\s+[^0-9]*)([0-9]+)(?:\])";
/**
* http://vimeo.com/12345
* https://vimeo.com/12345
* //vimeo.com/12345
* vimeo.com/some/descender/12345
*
* Should not capture inside HTML attributes
* [Not] <a href="vimeo.com/12345">Cool Video</a>
* [Not] <a href="https://vimeo.com/12345">vimeo.com/12345</a>
*
* Could erroneously capture:
* <a href="some.link/maybe/even/vimeo">This video (vimeo.com/12345) is teh cat's meow!</a>
*/
$plain_url = "(?:[^'\">]?\/?(?:https?:\/\/)?vimeo\.com[^0-9]+)([0-9]+)(?:[^'\"0-9<]|$)";
return jetpack_preg_replace_callback_outside_tags(
sprintf( '#%s|%s#i', $shortcode, $plain_url ),
'vimeo_link_callback',
$content,
'vimeo'
);
}
/**
* Callback function for the regex that replaces Vimeo URLs with Vimeo embeds.
*
* @since 3.7.0
*
* @param array $matches An array containing a Vimeo URL.
* @return string The Vimeo HTML embed code.
*/
function vimeo_link_callback( $matches ) {
$id = isset( $matches[ 2 ] ) ? $matches[ 2 ] : $matches[ 1 ];
if ( isset( $id ) && ctype_digit( $id ) ) {
return "\n" . vimeo_shortcode( array( 'id' => $id ) ) . "\n";
}
return $matches[ 0 ];
}
/** This filter is documented in modules/shortcodes/youtube.php */
if ( apply_filters( 'jetpack_comments_allow_oembed', get_option('embed_autourls') ) ) {
// We attach wp_kses_post to comment_text in default-filters.php with priority of 10 anyway, so the iframe gets filtered out.
if ( ! is_admin() ) {
// Higher priority because we need it before auto-link and autop get to it
add_filter( 'comment_text', 'vimeo_link', 1 );
}
}

View file

@ -0,0 +1,65 @@
<?php
/**
* Vine shortcode
*/
/**
* Vine embed code:
* <iframe class="vine-embed" src="https://vine.co/v/bjHh0zHdgZT" width="600" height="600" frameborder="0"></iframe>
* <script async src="//platform.vine.co/static/scripts/embed.js" charset="utf-8"></script>
*
* URL example:
* https://vine.co/v/bjHh0zHdgZT/
*
* Embed shortcode examples:
* [embed]https://vine.co/v/bjHh0zHdgZT[/embed]
* [embed width="300"]https://vine.co/v/bjHh0zHdgZT[/embed]
* [embed type="postcard" width="300"]https://vine.co/v/bjHh0zHdgZT[/embed]
**/
function vine_embed_video( $matches, $attr, $url, $rawattr ) {
static $vine_flag_embedded_script;
$max_height = 300;
$type = 'simple';
// Only allow 'postcard' or 'simple' types
if ( isset( $rawattr['type'] ) && $rawattr['type'] === 'postcard' )
$type = 'postcard';
$vine_size = Jetpack::get_content_width();
// If the user enters a value for width or height, we ignore the Jetpack::get_content_width()
if ( isset( $rawattr['width'] ) || isset( $rawattr['height'] ) ) {
// 300 is the minimum size that Vine provides for embeds. Lower than that, the postcard embeds looks weird.
$vine_size = max( $max_height, min( $attr['width'], $attr['height'] ) );
}
if ( empty( $vine_size ) ) {
$vine_size = $max_height;
}
$url = 'https://vine.co/v/' . $matches[1] . '/embed/' . $type;
$vine_html = sprintf( '<span class="embed-vine" style="display: block;"><iframe class="vine-embed" src="%s" width="%s" height="%s" frameborder="0"></iframe></span>', esc_url( $url ), (int) $vine_size, (int) $vine_size );
if ( $vine_flag_embedded_script !== true ) {
$vine_html .= '<script async src="//platform.vine.co/static/scripts/embed.js" charset="utf-8"></script>';
$vine_flag_embedded_script = true;
}
return $vine_html;
}
wp_embed_register_handler( 'jetpack_vine', '#https?://vine.co/v/([a-z0-9]+).*#i', 'vine_embed_video' );
function vine_shortcode( $atts ) {
global $wp_embed;
if ( empty( $atts['url'] ) )
return '';
if ( ! preg_match( '#https?://vine.co/v/([a-z0-9]+).*#i', $atts['url'] ) )
return '';
return $wp_embed->shortcode( $atts, $atts['url'] );
}
add_shortcode( 'vine', 'vine_shortcode' );

View file

@ -0,0 +1,82 @@
<?php
/*
Plugin Name: Wufoo Shortcode Plugin
Description: Enables shortcode to embed Wufoo forms. Usage: [wufoo username="chriscoyier" formhash="x7w3w3" autoresize="true" height="458" header="show" ssl="true"]
Author: Chris Coyier / Wufoo, evansolomon
Based on http://wordpress.org/extend/plugins/wufoo-shortcode/
http://wufoo.com/docs/code-manager/wordpress-shortcode-plugin/
*/
function wufoo_shortcode( $atts ) {
$attr = shortcode_atts(
array(
'username' => '',
'formhash' => '',
'autoresize' => true,
'height' => '500',
'header' => 'show',
'ssl' => '',
), $atts
);
// Check username and formhash to ensure they only have alphanumeric characters or underscores, and aren't empty.
if ( ! preg_match( '/^[a-zA-Z0-9_]+$/', $attr['username'] ) || ! preg_match( '/^[a-zA-Z0-9_]+$/', $attr['formhash'] ) ) {
/**
* Return an error to the users with instructions if one of these params is invalid
* They don't have default values because they are user/form-specific
*/
$return_error = sprintf( __( 'Something is wrong with your Wufoo shortcode. If you copy and paste it from the %sWufoo Code Manager%s, you should be golden.', 'jetpack' ), '<a href="http://wufoo.com/docs/code-manager/" target="_blank">', '</a>' );
return '
<div style="border: 20px solid red; border-radius: 40px; padding: 40px; margin: 50px 0 70px;">
<h3>Uh oh!</h3>
<p style="margin: 0;">' . $return_error . '</p>
</div>';
}
/**
* Required parameters are present.
* An error will be returned inside the form if they are invalid.
*/
$js_embed = '<script type="text/javascript">var host = (("https:" == document.location.protocol) ? "https://secure." : "http://");document.write(unescape("%3Cscript src=\'" + host + "wufoo.com/scripts/embed/form.js\' type=\'text/javascript\'%3E%3C/script%3E"));</script>';
$js_embed .= "<script type='text/javascript'>";
$js_embed .= 'var wufoo_' . $attr['formhash'] . ' = new WufooForm();';
$js_embed .= 'wufoo_' . $attr['formhash'] . ' .initialize({';
$js_embed .= "'userName':'" . $attr['username'] . "', ";
$js_embed .= "'formHash':'" . $attr['formhash'] . "', ";
$js_embed .= "'autoResize':" . (bool) ( $attr['autoresize'] ) . ',';
$js_embed .= "'height':'" . (int) $attr['height'] . "',";
$js_embed .= "'header':'" . esc_js( $attr['header'] ) . "' ";
/**
* Only output SSL value if passes as param.
* Lower tier plans don't show this param (don't offer SSL).
*/
$js_embed .= ( $attr['ssl'] ) ? ",'ssl':" . (bool) $attr['ssl'] : '';
$js_embed .= '});';
$js_embed .= 'wufoo_' . $attr['formhash'] . '.display();';
$js_embed .= '</script>';
/**
* iframe embed, loaded inside <noscript> tags.
*/
$iframe_embed = '<iframe ';
$iframe_embed .= 'height="' . (int) $attr['height'] . '" ';
$iframe_embed .= 'allowTransparency="true" frameborder="0" scrolling="no" style="width:100%;border:none;"';
$iframe_embed .= 'src="https://' . $attr['username'] . '.wufoo.com/embed/' . $attr['formhash'] . '/">';
$iframe_embed .= '<a href="https://' . $attr['username'] . '.wufoo.com/forms/' . $attr['formhash'] . '/" ';
$iframe_embed .= 'rel="nofollow" target="_blank">' . __( 'Fill out my Wufoo form!', 'jetpack' ) . '</a></iframe>';
/** This action is already documented in modules/widgets/gravatar-profile.php */
do_action( 'jetpack_stats_extra', 'embeds', 'wufoo' );
/**
* Return embed in JS and iframe.
*/
return "$js_embed <noscript> $iframe_embed </noscript>";
}
add_shortcode( 'wufoo', 'wufoo_shortcode' );

View file

@ -0,0 +1,389 @@
<?php
/**
* youtube shortcode
*
* Contains shortcode + some improvements over the Embeds syntax @
* http://codex.wordpress.org/Embeds
*
* @example [youtube=http://www.youtube.com/watch?v=wq0rXGLs0YM&amp;fs=1&amp;hl=bg_BG]
*/
/**
* Replaces YouTube embeds with YouTube shortcodes.
*
* @param string $content HTML content.
* @return string The content with YouTube embeds replaced with YouTube shortcodes.
*/
// 2008-07-15:
//<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/bZBHZT3a-FA&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/bZBHZT3a-FA&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>
// around 2008-06-06 youtube changed their old embed code to this:
//<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/M1D30gS7Z8U&hl=en"></param><embed src="http://www.youtube.com/v/M1D30gS7Z8U&hl=en" type="application/x-shockwave-flash" width="425" height="344"></embed></object>
// old style was:
// <object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/dGY28Qbj76A&rel=0"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/dGY28Qbj76A&rel=0" type="application/x-shockwave-flash" wmode="transparent" width="425" height="344"></embed></object>
// 12-2010:
// <object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/3H8bnKdf654?fs=1&amp;hl=en_GB"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/3H8bnKdf654?fs=1&amp;hl=en_GB" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>
// 01-2011:
// <iframe title="YouTube video player" class="youtube-player" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/Qq9El3ki0_g" frameborder="0" allowFullScreen></iframe>
// <iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/VIDEO_ID" frameborder="0"></iframe>
function youtube_embed_to_short_code( $content ) {
if ( false === strpos( $content, 'youtube.com' ) )
return $content;
//older codes
$regexp = '!<object width="\d+" height="\d+"><param name="movie" value="https?://www\.youtube\.com/v/([^"]+)"></param>(?:<param name="\w+" value="[^"]*"></param>)*<embed src="https?://www\.youtube\.com/v/(.+)" type="application/x-shockwave-flash"(?: \w+="[^"]*")* width="\d+" height="\d+"></embed></object>!i';
$regexp_ent = htmlspecialchars( $regexp, ENT_NOQUOTES );
$old_regexp = '!<embed(?:\s+\w+="[^"]*")*\s+src="https?(?:\:|&#0*58;)//www\.youtube\.com/v/([^"]+)"(?:\s+\w+="[^"]*")*\s*(?:/>|>\s*</embed>)!';
$old_regexp_ent = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $old_regexp, ENT_NOQUOTES ) );
//new code
$ifr_regexp = '!<iframe((?:\s+\w+="[^"]*")*?)\s+src="(https?:)?//(?:www\.)*youtube.com/embed/([^"]+)".*?</iframe>!i';
$ifr_regexp_ent = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $ifr_regexp, ENT_NOQUOTES ) );
foreach ( array( 'regexp', 'regexp_ent', 'old_regexp', 'old_regexp_ent', 'ifr_regexp', 'ifr_regexp_ent' ) as $reg ) {
if ( ! preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) )
continue;
foreach ( $matches as $match ) {
// Hack, but '?' should only ever appear once, and
// it should be for the 1st field-value pair in query string,
// if it is present
// YouTube changed their embed code.
// Example of how it is now:
// <object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/aP9AaD4tgBY?fs=1&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/aP9AaD4tgBY?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>
// As shown at the start of function, previous YouTube didn't '?'
// the 1st field-value pair.
if ( in_array ( $reg, array( 'ifr_regexp', 'ifr_regexp_ent' ) ) ) {
$params = $match[1];
if ( 'ifr_regexp_ent' == $reg )
$params = html_entity_decode( $params );
$params = wp_kses_hair( $params, array( 'http' ) );
$width = isset( $params['width'] ) ? (int) $params['width']['value'] : 0;
$height = isset( $params['height'] ) ? (int) $params['height']['value'] : 0;
$wh = '';
if ( $width && $height )
$wh = "&w=$width&h=$height";
$url = esc_url_raw( "https://www.youtube.com/watch?v={$match[3]}{$wh}" );
} else {
$match[1] = str_replace( '?', '&', $match[1] );
$url = esc_url_raw( "https://www.youtube.com/watch?v=" . html_entity_decode( $match[1] ) );
}
$content = str_replace( $match[0], "[youtube $url]", $content );
/**
* Fires before the YouTube embed is transformed into a shortcode.
*
* @module shortcodes
*
* @since 1.2.0
*
* @param string youtube Shortcode name.
* @param string $url YouTube video URL.
*/
do_action( 'jetpack_embed_to_shortcode', 'youtube', $url );
}
}
return $content;
}
add_filter( 'pre_kses', 'youtube_embed_to_short_code' );
/**
* Replaces plain-text links to YouTube videos with YouTube embeds.
*
* @param string $content HTML content
* @return string The content with embeds instead of URLs
*/
function youtube_link( $content ) {
return jetpack_preg_replace_callback_outside_tags( '!(?:\n|\A)https?://(?:www\.)?(?:youtube.com/(?:v/|playlist|watch[/\#?])|youtu\.be/)[^\s]+?(?:\n|\Z)!i', 'youtube_link_callback', $content, 'youtube.com/' );
}
/**
* Callback function for the regex that replaces YouTube URLs with
* YouTube embeds.
*/
function youtube_link_callback( $matches ) {
return "\n" . youtube_id( $matches[0] ) . "\n";
}
/**
* Normalizes a YouTube URL to include a v= parameter and a query string free of encoded ampersands.
*
* @param string $url
* @return string The normalized URL
*/
if ( ! function_exists( 'youtube_sanitize_url' ) ) :
function youtube_sanitize_url( $url ) {
$url = trim( $url, ' "' );
$url = trim( $url );
$url = str_replace( array( 'youtu.be/', '/v/', '#!v=', '&amp;', '&#038;', 'playlist' ), array( 'youtu.be/?v=', '/?v=', '?v=', '&', '&', 'videoseries' ), $url );
// Replace any extra question marks with ampersands - the result of a URL like "http://www.youtube.com/v/9FhMMmqzbD8?fs=1&hl=en_US" being passed in.
$query_string_start = strpos( $url, "?" );
if ( false !== $query_string_start ) {
$url = substr( $url, 0, $query_string_start + 1 ) . str_replace( "?", "&", substr( $url, $query_string_start + 1 ) );
}
return $url;
}
endif;
/*
* url can be:
* http://www.youtube.com/embed/videoseries?list=PL94269DA08231042B&amp;hl=en_US
* http://www.youtube.com/watch#!v=H2Ncxw1xfck
* http://www.youtube.com/watch?v=H2Ncxw1xfck
* http://www.youtube.com/watch?v=H2Ncxw1xfck&w=320&h=240&fmt=1&rel=0&showsearch=1&hd=0
* http://www.youtube.com/v/jF-kELmmvgA
* http://www.youtube.com/v/9FhMMmqzbD8?fs=1&hl=en_US
* http://youtu.be/Rrohlqeir5E
*/
/**
* Converts a YouTube URL into an embedded YouTube video.
*/
function youtube_id( $url ) {
if ( ! $id = jetpack_get_youtube_id( $url ) )
return '<!--YouTube Error: bad URL entered-->';
$url = youtube_sanitize_url( $url );
$url = parse_url( $url );
if ( ! isset( $url['query'] ) )
return false;
if ( isset( $url['fragment'] ) ) {
wp_parse_str( $url['fragment'], $fargs );
} else {
$fargs = array();
}
wp_parse_str( $url['query'], $qargs );
$qargs = array_merge( $fargs, $qargs );
// calculate the width and height, taking content_width into consideration
global $content_width;
$input_w = ( isset( $qargs['w'] ) && intval( $qargs['w'] ) ) ? intval( $qargs['w'] ) : 0;
$input_h = ( isset( $qargs['h'] ) && intval( $qargs['h'] ) ) ? intval( $qargs['h'] ) : 0;
$default_width = get_option('embed_size_w');
if ( empty( $default_width ) ) {
if ( ! empty( $content_width ) ) {
$default_width = $content_width;
} else {
$default_width = 640;
}
}
if ( $input_w > 0 && $input_h > 0 ) {
$w = $input_w;
$h = $input_h;
} elseif ( 0 == $input_w && 0 == $input_h ) {
if ( isset( $qargs['fmt'] ) && intval( $qargs['fmt'] ) ) {
$w = ( ! empty( $content_width ) ? min( $content_width, 480 ) : 480 );
} else {
$w = ( ! empty( $content_width ) ? min( $content_width, $default_width ) : $default_width );
$h = ceil( ( $w / 16 ) * 9 ) + 30;
}
} elseif ( $input_w > 0 ) {
$w = $input_w;
$h = ceil( ( $w / 16 ) * 9 ) + 30;
} else {
if ( isset( $qargs['fmt'] ) && intval( $qargs['fmt'] ) ) {
$w = ( ! empty( $content_width ) ? min( $content_width, 480 ) : 480 );
} else {
$w = ( ! empty( $content_width ) ? min( $content_width, $default_width ) : $default_width );
$h = $input_h;
}
}
/**
* Filter the YouTube player width.
*
* @module shortcodes
*
* @since 1.1.0
*
* @param int $w Width of the YouTube player in pixels.
*/
$w = (int) apply_filters( 'youtube_width', $w );
/**
* Filter the YouTube player height.
*
* @module shortcodes
*
* @since 1.1.0
*
* @param int $h Height of the YouTube player in pixels.
*/
$h = (int) apply_filters( 'youtube_height', $h );
$rel = ( isset( $qargs['rel'] ) && 0 == $qargs['rel'] ) ? 0 : 1;
$search = ( isset( $qargs['showsearch'] ) && 1 == $qargs['showsearch'] ) ? 1 : 0;
$info = ( isset( $qargs['showinfo'] ) && 0 == $qargs['showinfo'] ) ? 0 : 1;
$iv = ( isset( $qargs['iv_load_policy'] ) && 3 == $qargs['iv_load_policy'] ) ? 3 : 1;
$fmt = ( isset( $qargs['fmt'] ) && intval( $qargs['fmt'] ) ) ? '&fmt=' . (int) $qargs['fmt'] : '';
if ( ! isset( $qargs['autohide'] ) || ( $qargs['autohide'] < 0 || 2 < $qargs['autohide'] ) ) {
$autohide = '&autohide=2';
} else {
$autohide = '&autohide=' . absint( $qargs['autohide'] );
}
$start = 0;
if ( isset( $qargs['start'] ) ) {
$start = intval( $qargs['start'] );
} else if ( isset( $qargs['t'] ) ) {
$time_pieces = preg_split( '/(?<=\D)(?=\d+)/', $qargs['t'] );
foreach ( $time_pieces as $time_piece ) {
$int = (int) $time_piece;
switch ( substr( $time_piece, -1 ) ) {
case 'h' :
$start += $int * 3600;
break;
case 'm' :
$start += $int * 60;
break;
case 's' :
$start += $int;
break;
}
}
}
$start = $start ? '&start=' . $start : '';
$end = ( isset( $qargs['end'] ) && intval( $qargs['end'] ) ) ? '&end=' . (int) $qargs['end'] : '';
$hd = ( isset( $qargs['hd'] ) && intval( $qargs['hd'] ) ) ? '&hd=' . (int) $qargs['hd'] : '';
$vq = ( isset( $qargs['vq'] ) && in_array( $qargs['vq'], array('hd720','hd1080') ) ) ? '&vq=' . $qargs['vq'] : '';
$cc = ( isset( $qargs['cc_load_policy'] ) ) ? '&cc_load_policy=1' : '';
$cc_lang = ( isset( $qargs['cc_lang_pref'] ) ) ? '&cc_lang_pref=' . preg_replace( '/[^_a-z0-9-]/i', '', $qargs['cc_lang_pref'] ) : '';
$wmode = ( isset( $qargs['wmode'] ) && in_array( strtolower( $qargs['wmode'] ), array( 'opaque', 'window', 'transparent' ) ) ) ? $qargs['wmode'] : 'transparent';
$theme = ( isset( $qargs['theme'] ) && in_array( strtolower( $qargs['theme'] ), array( 'dark', 'light' ) ) ) ? '&theme=' . $qargs['theme'] : '';
$autoplay = '';
/**
* Allow YouTube videos to start playing automatically.
*
* @module shortcodes
*
* @since 2.2.2
*
* @param bool false Enable autoplay for YouTube videos.
*/
if ( apply_filters( 'jetpack_youtube_allow_autoplay', false ) && isset( $qargs['autoplay'] ) )
$autoplay = '&autoplay=' . (int)$qargs['autoplay'];
if ( ( isset( $url['path'] ) && '/videoseries' == $url['path'] ) || isset( $qargs['list'] ) ) {
$html = "<iframe class='youtube-player' type='text/html' width='$w' height='$h' src='" . esc_url( set_url_scheme( "http://www.youtube.com/embed/videoseries?list=$id&hl=en_US" ) ) . "' allowfullscreen='true' style='border:0;'></iframe>";
} else {
$html = "<iframe class='youtube-player' type='text/html' width='$w' height='$h' src='" . esc_url( set_url_scheme( "http://www.youtube.com/embed/$id?version=3&rel=$rel&fs=1$fmt$autohide&showsearch=$search&showinfo=$info&iv_load_policy=$iv$start$end$hd&wmode=$wmode$theme$autoplay{$cc}{$cc_lang}" ) ) . "' allowfullscreen='true' style='border:0;'></iframe>";
}
// Let's do some alignment wonder in a span, unless we're producing a feed
if ( ! is_feed() ) {
$alignmentcss = 'text-align:center;';
if ( isset( $qargs['align'] ) ) {
switch ( $qargs['align'] ) {
case 'left':
$alignmentcss = "float:left; width:{$w}px; height:{$h}px; margin-right:10px; margin-bottom: 10px;";
break;
case 'right':
$alignmentcss = "float:right; width:{$w}px; height:{$h}px; margin-left:10px; margin-bottom: 10px;";
break;
}
}
$html = sprintf(
'<span class="embed-youtube" style="%s display: block;">%s</span>',
esc_attr( $alignmentcss ),
$html
);
}
/**
* Filter the YouTube video HTML output.
*
* @module shortcodes
*
* @since 1.2.3
*
* @param string $html YouTube video HTML output.
*/
$html = apply_filters( 'video_embed_html', $html );
return $html;
}
function youtube_shortcode( $atts ) {
return youtube_id( ( isset ( $atts[0] ) ) ? ltrim( $atts[0] , '=' ) : shortcode_new_to_old_params( $atts ) );
}
add_shortcode( 'youtube', 'youtube_shortcode' );
/**
* For bare URLs on their own line of the form
* http://www.youtube.com/v/9FhMMmqzbD8?fs=1&hl=en_US
*/
function wpcom_youtube_embed_crazy_url( $matches, $attr, $url ) {
return youtube_id( $url );
}
function wpcom_youtube_embed_crazy_url_init() {
wp_embed_register_handler( 'wpcom_youtube_embed_crazy_url', '#https?://(?:www\.)?(?:youtube.com/(?:v/|playlist|watch[/\#?])|youtu\.be/).*#i', 'wpcom_youtube_embed_crazy_url' );
}
add_action( 'init', 'wpcom_youtube_embed_crazy_url_init' );
/**
* Allow oEmbeds in Jetpack's Comment form.
*
* @module shortcodes
*
* @since 2.8.0
*
* @param int get_option('embed_autourls') Option to automatically embed all plain text URLs.
*/
if ( apply_filters( 'jetpack_comments_allow_oembed', get_option('embed_autourls') ) ) {
// We attach wp_kses_post to comment_text in default-filters.php with priority of 10 anyway, so the iframe gets filtered out.
if ( ! is_admin() ) {
// Higher priority because we need it before auto-link and autop get to it
add_filter( 'comment_text', 'youtube_link', 1 );
}
}
/**
* Core changes to do_shortcode (https://core.trac.wordpress.org/changeset/34747) broke "improper" shortcodes
* with the format [shortcode=http://url.com].
*
* This removes the "=" from the shortcode so it can be parsed.
*
* @see https://github.com/Automattic/jetpack/issues/3121
*/
function jetpack_fix_youtube_shortcode_display_filter( $content ) {
if ( strpos( $content, '[youtube=' ) !== false ) {
$content = preg_replace( '@\[youtube=(.*?)\]@', '[youtube $1]', $content );
}
return $content;
}
add_filter( 'the_content', 'jetpack_fix_youtube_shortcode_display_filter', 7 );