Added login request

This commit is contained in:
Nedim Uka
2018-06-20 18:03:43 +02:00
parent 4e52521fae
commit 593b445a21
4716 changed files with 1218265 additions and 57 deletions

View File

@@ -0,0 +1,125 @@
<?php
/**
* Archive.org Shortcode
*
* Usage:
* [archiveorg-book goodytwoshoes00newyiala]
* [archiveorg-book http://www.archive.org/stream/goodytwoshoes00newyiala]
* [archiveorg id=goodytwoshoes00newyiala width=480 height=430]
*<iframe src='https://www.archive.org/stream/goodytwoshoes00newyiala?ui=embed#mode/1up' width='480px' height='430px' frameborder='0' ></iframe>
*/
/**
* Get ID of requested archive.org book embed.
*
* @since 4.5.0
*
* @param $atts
*
* @return int|string
*/
function jetpack_shortcode_get_archiveorg_book_id( $atts ) {
if ( isset( $atts[0] ) ) {
$atts[0] = trim( $atts[0] , '=' );
if ( preg_match( '#archive.org/stream/(.+)/?$#i', $atts[0], $match ) ) {
$id = $match[1];
} else {
$id = $atts[0];
}
return $id;
}
return 0;
}
/**
* Convert an archive.org book shortcode into an embed code.
*
* @since 4.5.0
*
* @param array $atts An array of shortcode attributes.
* @return string The embed code for the Archive.org book
*/
function jetpack_archiveorg_book_shortcode( $atts ) {
global $content_width;
if ( isset( $atts[0] ) && empty( $atts['id'] ) ) {
$atts['id'] = jetpack_shortcode_get_archiveorg_book_id( $atts );
}
$atts = shortcode_atts( array(
'id' => '',
'width' => 480,
'height' => 430,
), $atts );
if ( ! $atts['id'] ) {
return '<!-- error: missing archive.org book ID -->';
}
$id = $atts['id'];
if ( ! $atts['width'] ) {
$width = absint( $content_width );
} else {
$width = intval( $atts['width'] );
}
if ( ! $atts['height'] ) {
$height = round( ( $width / 640 ) * 360 );
} else {
$height = intval( $atts['height'] );
}
$url = esc_url( set_url_scheme( "http://archive.org/stream/{$id}?ui=embed#mode/1up" ) );
$html = "<div class='embed-archiveorg-book' style='text-align:center;'><iframe src='$url' width='$width' height='$height' style='border:0;' webkitallowfullscreen='true' mozallowfullscreen='true' allowfullscreen></iframe></div>";
return $html;
}
add_shortcode( 'archiveorg-book', 'jetpack_archiveorg_book_shortcode' );
/**
* Compose shortcode from archive.org book iframe.
*
* @since 4.5.0
*
* @param string $content
*
* @return mixed
*/
function jetpack_archiveorg_book_embed_to_shortcode( $content ) {
if ( ! is_string( $content ) || false === stripos( $content, 'archive.org/stream/' ) ) {
return $content;
}
$regexp = '!<iframe\s+src=[\'"](http|https)://(www.archive|archive)\.org/stream/([^\'"]+)[\'"]((?:\s+\w+(=[\'"][^\'"]*[\'"])?)*)\s></iframe>!i';
if ( ! preg_match_all( $regexp, $content, $matches, PREG_SET_ORDER ) ) {
return $content;
}
foreach ( $matches as $match ) {
$url = explode( '?', $match[3] );
$id = $url[0];
$params = $match[4];
$params = wp_kses_hair( $params, array( 'http' ) );
$width = isset( $params['width'] ) ? absint( $params['width']['value'] ) : 0;
$height = isset( $params['height'] ) ? absint( $params['height']['value'] ) : 0;
$wh = '';
if ( $width && $height ) {
$wh = ' width=' . $width . ' height=' . $height;
}
$shortcode = '[archiveorg-book ' . $id . $wh . ']';
$content = str_replace( $match[0], $shortcode, $content );
}
return $content;
}
add_filter( 'pre_kses', 'jetpack_archiveorg_book_embed_to_shortcode' );

View File

@@ -0,0 +1,153 @@
<?php
/**
* Archive.org book shortcode.
*
* Usage:
* [archiveorg Experime1940]
* [archiveorg http://archive.org/details/Experime1940 poster=http://archive.org/images/map.png]
* [archiveorg id=Experime1940 width=640 height=480 autoplay=1]
* <iframe src="http://archive.org/embed/Experime1940&autoplay=1&poster=http://archive.org/images/map.png" width="640" height="480" frameborder="0" webkitallowfullscreen="true" mozallowfullscreen="true" allowfullscreen></iframe>
*/
/**
* Get ID of requested archive.org embed.
*
* @since 4.5.0
*
* @param array $atts
*
* @return int|string
*/
function jetpack_shortcode_get_archiveorg_id( $atts ) {
if ( isset( $atts[0] ) ) {
$atts[0] = trim( $atts[0] , '=' );
if ( preg_match( '#archive.org/(details|embed)/(.+)/?$#i', $atts[0], $match ) ) {
$id = $match[2];
} else {
$id = $atts[0];
}
return $id;
}
return 0;
}
/**
* Convert an archive.org shortcode into an embed code.
*
* @since 4.5.0
*
* @param array $atts An array of shortcode attributes.
* @return string The embed code for the archive.org video.
*/
function jetpack_archiveorg_shortcode( $atts ) {
global $content_width;
if ( isset( $atts[0] ) && empty( $atts['id'] ) ) {
$atts['id'] = jetpack_shortcode_get_archiveorg_id( $atts );
}
$atts = shortcode_atts( array(
'id' => '',
'width' => 640,
'height' => 480,
'autoplay' => 0,
'poster' => ''
), $atts );
if ( ! $atts['id'] ) {
return '<!-- error: missing archive.org ID -->';
}
$id = $atts['id'];
if ( ! $atts['width'] ) {
$width = absint( $content_width );
} else {
$width = intval( $atts['width'] );
}
if ( ! $atts['height'] ) {
$height = round( ( $width / 640 ) * 360 );
} else {
$height = intval( $atts['height'] );
}
if ( $atts['autoplay'] ) {
$autoplay = '&autoplay=1';
} else {
$autoplay = '';
}
if ( $atts['poster'] ) {
$poster = '&poster=' . $atts['poster'];
} else {
$poster = '';
}
$url = esc_url( set_url_scheme( "https://archive.org/embed/{$id}{$autoplay}{$poster}" ) );
$html = "<div class='embed-archiveorg' style='text-align:center;'><iframe src='$url' width='$width' height='$height' style='border:0;' webkitallowfullscreen='true' mozallowfullscreen='true' allowfullscreen></iframe></div>";
return $html;
}
add_shortcode( 'archiveorg', 'jetpack_archiveorg_shortcode' );
/**
* Compose shortcode from archive.org iframe.
*
* @since 4.5.0
*
* @param string $content
*
* @return mixed
*/
function jetpack_archiveorg_embed_to_shortcode( $content ) {
if ( ! is_string( $content ) || false === stripos( $content, 'archive.org/embed/' ) ) {
return $content;
}
$regexp = '!<iframe\s+src=[\'"]https?://archive\.org/embed/([^\'"]+)[\'"]((?:\s+\w+(=[\'"][^\'"]*[\'"])?)*)></iframe>!i';
if ( ! preg_match_all( $regexp, $content, $matches, PREG_SET_ORDER ) ) {
return $content;
}
foreach ( $matches as $match ) {
$url = explode( '&amp;', $match[1] );
$id = 'id=' . $url[0];
$autoplay = '';
$poster = '';
for ( $ii = 1; $ii < count( $url ); $ii++ ) {
if ( 'autoplay=1' === $url[$ii] ) {
$autoplay = ' autoplay="1"';
}
$map_matches = array();
if ( preg_match( '/^poster=(.+)$/', $url[$ii], $map_matches ) ) {
$poster = " poster=\"{$map_matches[1]}\"";
}
}
$params = $match[2];
$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 = ' width=' . $width . ' height=' . $height;
}
$shortcode = '[archiveorg ' . $id . $wh . $autoplay . $poster . ']';
$content = str_replace( $match[0], $shortcode, $content );
}
return $content;
}
add_filter( 'pre_kses', 'jetpack_archiveorg_embed_to_shortcode' );

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,6 @@
<?php
/**
* Deprecated. No longer needed.
*
* @package Jetpack
*/

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,270 @@
<?php
/**
* Brightcove shortcode.
*
* Brighcove had renovated their video player embedding code since they introduced their "new studio".
* See https://support.brightcove.com/en/video-cloud/docs.
* The new code is not 100% backward compatible, as long as a customized player is used.
* By the time I wrote this, there were about 150000+ posts embedded legacy players, so it would be a bad
* idea either to introduce a new brightcove shortcode, or to break those posts completely.
*
* That's why we introduce a less aggressive way: leaving the old embedding code untouched, and
* introduce a new set of shortcode parameters which are translated to the latest Brightcove embedding code.
*
* e.g.
* [brightcove video_id="12345" account_id="99999"] will be translated to the latest embedding code.
* [brightcove exp=627045696&vid=1415670151] or [brightcove exp=1463233149&vref=1601200825] will be translated
* to the legacy code.
*
*/
class Jetpack_Brightcove_Shortcode {
static $shortcode = 'brightcove';
/**
* Parse shortcode arguments and render its output.
*
* @since 4.5.0
*
* @param array $atts Shortcode parameters.
*
* @return string
*/
static public function convert( $atts ) {
$normalized_atts = self::normalize_attributes( $atts );
if ( empty( $atts ) ) {
return '<!-- Missing Brightcove parameters -->';
}
return self::has_legacy_atts( $normalized_atts )
? self::convert_to_legacy_studio( $normalized_atts )
: self::convert_to_new_studio( $normalized_atts );
}
/**
* We need to take care of two kinds of shortcode format here.
* The latest: [shortcode a=1 b=2] and the legacy: [shortcode a=1&b=2]
* For an old shortcode: [shortcode a=1&b=2&c=3], it would be parsed into array( 'a' => 1&b=2&c=3' ), which is useless.
* However, since we want to determine whether to call convert_to_legacy_studio() or convert_to_new_studio() via passed parameters, we still need to parse the two properly.
* See http://jetpack.wp-a2z.org/oik_api/shortcode_new_to_old_params/
*
* @since 4.5.0
*
* @param array $atts Shortcode parameters.
*
* @return array
*/
static public function normalize_attributes( $atts ) {
if ( is_array( $atts ) && 1 == count( $atts ) ) { // this is the case we need to take care of.
$parsed_atts = array();
$params = shortcode_new_to_old_params( $atts );
$params = apply_filters( 'brightcove_dimensions', $params );
parse_str( $params, $parsed_atts );
return $parsed_atts;
} else {
return $atts;
}
}
/**
* Check that it has legacy attributes.
*
* @since 4.5.0
*
* @param array $atts Shortcode parameters.
*
* @return bool
*/
static public function has_legacy_atts( $atts ) {
return ( isset( $atts[ 'vid' ] ) || isset( $atts[ 'vref' ] ) )
&& ( isset( $atts[ 'exp' ] ) || isset( $atts[ 'exp3' ] ) );
}
/**
* Convert to latest player format.
*
* @since 4.5.0
*
* @param array $atts Shortcode parameters.
*
* @return string
*/
static public function convert_to_new_studio( $atts ) {
$defaults = array(
'account_id' => '',
'video_id' => '',
'player_id' => 'default',
'width' => '100%',
'height' => '100%',
);
$atts_applied = shortcode_atts( $defaults, $atts, self::$shortcode );
$player_url = sprintf(
'//players.brightcove.net/%s/%s_default/index.html?videoId=%s',
esc_attr( $atts_applied['account_id'] ),
esc_attr( $atts_applied['player_id'] ),
esc_attr( $atts_applied['video_id'] )
);
$output_html = sprintf(
'<iframe src="' . esc_url( $player_url ) . '" allowfullscreen webkitallowfullscreen mozallowfullscreen style="width: %spx; height: %spx;"></iframe>',
esc_attr( $atts_applied['width'] ),
esc_attr( $atts_applied['height'] )
);
return $output_html;
}
/**
* Convert to legacy player format.
*
* [brightcove exp=627045696&vid=1415670151] for the older player and backward compatibility
* [brightcove exp=1463233149&vref=1601200825] for the new player
*
* @since 4.5.0
*
* @param array $atts Shortcode parameters.
*
* @return string
*/
static public function convert_to_legacy_studio( $atts ) {
$attr = shortcode_atts( array(
'bg' => '',
'exp' => '',
'exp3' => '',
'h' => '',
'lbu' => '',
'pk' => '',
'pubid' => '',
's' => '',
'surl' => '',
'vid' => '',
'vref' => '',
'w' => '',
), $atts );
if ( isset( $attr['pk'] ) ) {
$attr['pk'] = rawurlencode( preg_replace( '/[^a-zA-Z0-9!*\'();:@&=+$,\/?#\[\]\-_.~ ]/', '', $attr['pk'] ) );
}
if ( isset( $attr['bg'] ) ) {
$attr['bg'] = preg_replace( '![^-a-zA-Z0-9#]!', '', $attr['bg'] );
}
$fv = array(
'viewerSecureGatewayURL' => 'https://services.brightcove.com/services/amfgateway',
'servicesURL' => 'http://services.brightcove.com/services',
'cdnURL' => 'http://admin.brightcove.com',
'autoStart' => 'false',
);
$js_tld = 'com';
$src = '';
$name = 'flashObj';
$html5 = false;
if ( isset( $attr['exp3'] ) ) {
if ( isset( $attr['surl'] ) && strpos( $attr['surl'], 'brightcove.co.jp' ) ) {
$js_tld = 'co.jp';
}
if ( ! isset( $attr['surl'] ) || ! preg_match( '#^https?://(?:[a-z\d-]+\.)*brightcove\.(?:com|co\.jp)/#', $attr['surl'] ) ) {
$attr['surl'] = 'http://c.brightcove.com/services';
}
$attr['exp3'] = intval( $attr['exp3'] );
$attr['pubid'] = intval( $attr['pubid'] );
$attr['vid'] = intval( $attr['vid'] );
$fv['servicesURL'] = $attr['surl'];
$fv['playerID'] = $attr['exp3'];
$fv['domain'] = 'embed';
$fv['videoID'] = intval( $attr['vid'] );
$src = sprintf( '%s/viewer/federated_f9/%s?isVid=1&amp;isUI=1&amp;publisherID=%s',
$attr['surl'],
$attr['exp3'],
$attr['pubid']
);
$html5 = true;
} elseif ( isset( $attr['exp'] ) ) {
$attr['exp'] = intval( $attr['exp'] );
$src = 'http://services.brightcove.com/services/viewer/federated_f8/' . $attr['exp'];
if ( $attr['vid'] ) {
$fv['videoId'] = $attr['vid'];
} else if ( $attr['vref'] ) {
$fv['videoRef'] = $attr['vref'];
}
$fv['playerId'] = $attr['exp'];
$fv['domain'] = 'embed';
} else {
return '<small>brightcove error: missing required parameter exp or exp3</small>';
}
if ( ! empty( $attr['lbu'] ) ) {
$fv['linkBaseURL'] = $attr['lbu'];
}
$flashvars = trim( add_query_arg( array_map( 'urlencode', $fv ), '' ), '?' );
$width = $height = null;
if ( ! empty( $attr['w'] ) && ! empty( $attr['h'] ) ) {
$w = abs( (int) $attr['w'] );
$h = abs( (int) $attr['h'] );
if ( $w && $h ) {
$width = $w;
$height = $h;
}
} elseif ( empty( $attr['s'] ) || 'l' === $attr['s'] ) {
$width = '480';
$height = '360';
}
if ( empty( $width ) || empty( $height ) ) {
$width = '280';
$height = '210';
}
if ( $html5 ) {
wp_enqueue_script(
'brightcove-loader',
Jetpack::get_file_url_for_environment( '_inc/build/shortcodes/js/brightcove.min.js', 'modules/shortcodes/js/brightcove.js' ),
array( 'jquery' ),
20121127,
false
);
wp_localize_script( 'brightcove-loader', 'brightcoveData', array(
'tld' => esc_js( $js_tld )
) );
return '
<object id="myExperience" class="BrightcoveExperience">
<param name="bgcolor" value="' . esc_attr( $attr['bg'] ) . '" />
<param name="width" value="' . esc_attr( $width ) . '" />
<param name="height" value="' . esc_attr( $height ) . '" />
<param name="playerID" value="' . esc_attr( $attr['exp3'] ) . '" />
<param name="@videoPlayer" value="' . esc_attr( $attr['vid'] ) . '" />
<param name="playerKey" value="' . esc_attr( $attr['pk'] ) . '" />
<param name="isVid" value="1" />
<param name="isUI" value="1" />
<param name="dynamicStreaming" value="true" />
<param name="autoStart" value="false" />
<param name="secureConnections" value="true" />
<param name="secureHTMLConnections" value="true" />
</object>';
}
return sprintf( '<embed src="%s" bgcolor="#FFFFFF" flashvars="%s" base="http://admin.brightcove.com" name="%s" width="%s" height="%s" allowFullScreen="true" seamlesstabbing="false" type="application/x-shockwave-flash" swLiveConnect="true" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" />',
esc_url( $src ),
$flashvars,
esc_attr( $name ),
esc_attr( $width ),
esc_attr( $height )
);
}
}
add_shortcode( Jetpack_Brightcove_Shortcode::$shortcode, array( 'Jetpack_Brightcove_Shortcode', 'convert' ) );

View File

@@ -0,0 +1,21 @@
<?php
/*
* Carto (formerly CartoDB)
*
* example URL: http://osm2.carto.com/viz/08aef918-94da-11e4-ad83-0e0c41326911/public_map
*
* possible patterns:
* [username].carto.com/viz/[map-id]/public_map
* [username].carto.com/viz/[map-id]/embed_map
* [username].carto.com/viz/[map-id]/map
* [organization].carto.com/u/[username]/viz/[map-id]/public_map
* [organization].carto.com/u/[username]/viz/[map-id]/embed_map
* [organization].carto.com/u/[username]/viz/[map-id]/map
*
* On July 8th, 2016 CartoDB changed its primary domain from cartodb.com to carto.com
* So this shortcode still supports the cartodb.com domain for oembeds.
*/
wp_oembed_add_provider( '#https?://(?:www\.)?[^/^\.]+\.carto(db)?\.com/\S+#i', 'https://services.carto.com/oembed', true );

View File

@@ -0,0 +1,293 @@
<?php
/**
* The companion file to shortcodes.php
*
* This file contains the code that converts HTML embeds into shortcodes
* for when the user copy/pastes in HTML.
*/
add_filter( 'pre_kses', array( 'Filter_Embedded_HTML_Objects', 'filter' ), 11 );
add_filter( 'pre_kses', array( 'Filter_Embedded_HTML_Objects', 'maybe_create_links' ), 100 ); // See WPCom_Embed_Stats::init()
/**
* Helper class for identifying and parsing known HTML blocks
*
* @since 4.5.0
*
* @author mdawaffe
*
* Not completely done, but seems to work okay
* Stolen from Mike's Seaside presentation:
* @link http://mdawaffepresents.wordpress.com/?p=36
*/
class Filter_Embedded_HTML_Objects {
static public $strpos_filters = array();
static public $regexp_filters = array();
static public $current_element = false;
static public $html_strpos_filters = array();
static public $html_regexp_filters = array();
static public $failed_embeds = array();
/**
* Store tokens found in Syntax Highlighter.
*
* @since 4.5.0
*
* @var array
*/
static private $sh_unfiltered_content_tokens;
/**
* Capture tokens found in Syntax Highlighter and collect them in self::$sh_unfiltered_content_tokens.
*
* @since 4.5.0
*
* @param array $match
*
* @return string
*/
static public function sh_regexp_callback( $match ) {
$token = '[prekses-filter-token-' . mt_rand() . '-' . md5( $match[0] ) . '-' . mt_rand() . ']';
self::$sh_unfiltered_content_tokens[$token] = $match[0];
return $token;
}
static public function filter( $html ) {
if ( ! $html || ! is_string( $html ) ) {
return $html;
}
$regexps = array(
'object' => '%<object[^>]*+>(?>[^<]*+(?><(?!/object>)[^<]*+)*)</object>%i',
'embed' => '%<embed[^>]*+>(?:\s*</embed>)?%i',
'iframe' => '%<iframe[^>]*+>(?>[^<]*+(?><(?!/iframe>)[^<]*+)*)</iframe>%i',
'div' => '%<div[^>]*+>(?>[^<]*+(?><(?!/div>)[^<]*+)*+)(?:</div>)+%i',
'script' => '%<script[^>]*+>(?>[^<]*+(?><(?!/script>)[^<]*+)*)</script>%i',
);
$unfiltered_content_tokens = array();
self::$sh_unfiltered_content_tokens = array();
// Check here to make sure that SyntaxHighlighter is still used. (Just a little future proofing)
if ( class_exists( 'SyntaxHighlighter' ) ) {
// Replace any "code" shortcode blocks with a token that we'll later replace with its original text.
// This will keep the contents of the shortcode from being filtered
global $SyntaxHighlighter;
// Check to see if the $SyntaxHighlighter object has been created and is ready for use
if ( isset( $SyntaxHighlighter ) && is_array( $SyntaxHighlighter->shortcodes ) ) {
$shortcode_regex = implode( '|', array_map( 'preg_quote', $SyntaxHighlighter->shortcodes ) );
$html = preg_replace_callback(
'/\[(' . $shortcode_regex . ')(\s[^\]]*)?\][\s\S]*?\[\/\1\]/m', array( __CLASS__, 'sh_regexp_callback' ), $html
);
$unfiltered_content_tokens = self::$sh_unfiltered_content_tokens;
}
}
foreach ( $regexps as $element => $regexp ) {
self::$current_element = $element;
if ( false !== stripos( $html, "<$element" ) ) {
if ( $new_html = preg_replace_callback( $regexp, array( __CLASS__, 'dispatch' ), $html ) ) {
$html = $new_html;
}
}
if ( false !== stripos( $html, "&lt;$element" ) ) {
$regexp_entities = self::regexp_entities( $regexp );
if ( $new_html = preg_replace_callback( $regexp_entities, array( __CLASS__, 'dispatch_entities' ), $html ) ) {
$html = $new_html;
}
}
}
if ( count( $unfiltered_content_tokens ) > 0 ) {
// Replace any tokens generated earlier with their original unfiltered text
$html = str_replace( array_keys( $unfiltered_content_tokens ), $unfiltered_content_tokens, $html );
}
return $html;
}
static public function regexp_entities( $regexp ) {
return preg_replace(
'/\[\^&([^\]]+)\]\*\+/',
'(?>[^&]*+(?>&(?!\1)[^&])*+)*+',
str_replace( '?&gt;', '?' . '>', htmlspecialchars( $regexp, ENT_NOQUOTES ) )
);
}
static public function register( $match, $callback, $is_regexp = false, $is_html_filter = false ) {
if ( $is_html_filter ) {
if ( $is_regexp ) {
self::$html_regexp_filters[$match] = $callback;
} else {
self::$html_strpos_filters[$match] = $callback;
}
} else {
if ( $is_regexp ) {
self::$regexp_filters[$match] = $callback;
} else {
self::$strpos_filters[$match] = $callback;
}
}
}
static public function unregister( $match ) {
// Allow themes/plugins to remove registered embeds
unset( self::$regexp_filters[$match] );
unset( self::$strpos_filters[$match] );
unset( self::$html_regexp_filters[$match] );
unset( self::$html_strpos_filters[$match] );
}
static function dispatch_entities( $matches ) {
$matches[0] = html_entity_decode( $matches[0] );
return self::dispatch( $matches );
}
static function dispatch( $matches ) {
$html = preg_replace( '%&#0*58;//%', '://', $matches[0] );
$attrs = self::get_attrs( $html );
if ( isset( $attrs['src'] ) ) {
$src = $attrs['src'];
} else if ( isset( $attrs['movie'] ) ) {
$src = $attrs['movie'];
} else {
// no src found, search html
foreach ( self::$html_strpos_filters as $match => $callback ) {
if ( false !== strpos( $html, $match ) ) {
return call_user_func( $callback, $attrs );
}
}
foreach ( self::$html_regexp_filters as $match => $callback ) {
if ( preg_match( $match, $html ) ) {
return call_user_func( $callback, $attrs );
}
}
return $matches[0];
}
$src = trim( $src );
// check source filter
foreach ( self::$strpos_filters as $match => $callback ) {
if ( false !== strpos( $src, $match ) ) {
return call_user_func( $callback, $attrs );
}
}
foreach ( self::$regexp_filters as $match => $callback ) {
if ( preg_match( $match, $src ) ) {
return call_user_func( $callback, $attrs );
}
}
// check html filters
foreach ( self::$html_strpos_filters as $match => $callback ) {
if ( false !== strpos( $html, $match ) ) {
return call_user_func( $callback, $attrs );
}
}
foreach ( self::$html_regexp_filters as $match => $callback ) {
if ( preg_match( $match, $html ) ) {
return call_user_func( $callback, $attrs );
}
}
// Log the strip
if ( function_exists( 'wp_kses_reject' ) ) {
wp_kses_reject( sprintf( __( '<code>%s</code> HTML tag removed as it is not allowed', 'jetpack' ), '&lt;' . self::$current_element . '&gt;' ), array( self::$current_element => $attrs ) );
}
// Keep the failed match so we can later replace it with a link,
// but return the original content to give others a chance too.
self::$failed_embeds[] = array(
'match' => $matches[0],
'src' => esc_url( $src ),
);
return $matches[0];
}
/**
* Failed embeds are stripped, so let's convert them to links at least.
*
* @param string $string Failed embed string.
*
* @return string $string Linkified string.
*/
public static function maybe_create_links( $string ) {
if ( empty( self::$failed_embeds ) ) {
return $string;
}
foreach ( self::$failed_embeds as $entry ) {
$html = sprintf( '<a href="%s">%s</a>', esc_url( $entry['src'] ), esc_url( $entry['src'] ) );
// Check if the string doesn't contain iframe, before replace.
if ( ! preg_match( '/<iframe /', $string ) ) {
$string = str_replace( $entry['match'], $html, $string );
}
}
self::$failed_embeds = array();
return $string;
}
static function get_attrs( $html ) {
if ( ! ( class_exists( 'DOMDocument' ) && function_exists( 'libxml_use_internal_errors' ) && function_exists( 'simplexml_load_string' ) ) ) {
trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
return array();
}
// We have to go through DOM, since it can load non-well-formed XML (i.e. HTML). SimpleXML cannot.
$dom = new DOMDocument;
// The @ is not enough to suppress errors when dealing with libxml,
// we have to tell it directly how we want to handle errors.
libxml_use_internal_errors( TRUE );
@$dom->loadHTML( $html ); // suppress parser warnings
libxml_use_internal_errors( FALSE );
$xml = false;
foreach ( $dom->childNodes as $node ) {
// find the root node (html)
if ( XML_ELEMENT_NODE == $node->nodeType ) {
// Use simplexml_load_string rather than simplexml_import_dom as the later doesn't cope well if the XML is malformmed in the DOM See #1688-wpcom
libxml_use_internal_errors( true );
$xml = simplexml_load_string( $dom->saveXML( $node->firstChild->firstChild ) ); // html->body->object
libxml_clear_errors();
break;
}
}
if ( ! $xml ) {
return array();
}
$attrs = array();
$attrs['_raw_html'] = $html;
// <param> elements
foreach ( $xml->param as $param ) {
$attrs[(string) $param['name']] = (string) $param['value'];
}
// <object> attributes
foreach ( $xml->attributes() as $name => $attr ) {
$attrs[$name] = (string) $attr;
}
// <embed> attributes
if ( $xml->embed ) {
foreach ( $xml->embed->attributes() as $name => $attr ) {
$attrs[$name] = (string) $attr;
}
}
return $attrs;
}
}

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,16 @@
.wp-block-jetpack-vr {
position: relative;
max-width: 525px;
margin-left: auto;
margin-right: auto;
overflow: hidden;
}
iframe.wp-block-jetpack-vr {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
height: 100%;
}

View File

@@ -0,0 +1,56 @@
div.jetpack-quiz {
border: 1px solid #deede3;
background-color: #f3f3f3;
padding: 1em;
line-height: 1.3em;
margin-bottom: 2em;
border-radius: .2em;
}
div.jetpack-quiz div.jetpack-quiz-question {
margin-bottom: .5em;
font-weight: bold;
}
div.jetpack-quiz div.jetpack-quiz-answer {
cursor: pointer;
margin-bottom: .5em;
padding: 1em 0 1em 1em;
border-bottom: 1px dotted #999;
}
div.jetpack-quiz div.jetpack-quiz-answer.last {
padding-bottom: 0;
margin-bottom: 0;
border-bottom: 0;
}
div.jetpack-quiz div.jetpack-quiz-answer.correct {
color: green;
}
div.jetpack-quiz div.jetpack-quiz-answer.wrong {
color: red;
}
div.jetpack-quiz div.jetpack-quiz-answer div.jetpack-quiz-explanation {
display: none;
}
div.jetpack-quiz div.jetpack-quiz-answer.correct div.jetpack-quiz-explanation, div.jetpack-quiz div.jetpack-quiz-answer.wrong div.jetpack-quiz-explanation {
display: block;
color: black;
font-size: 90%;
margin-top: 1em;
}
div.jetpack-quiz div.jetpack-quiz-answer.correct div.jetpack-quiz-explanation tt, div.jetpack-quiz div.jetpack-quiz-answer.wrong div.jetpack-quiz-explanation tt {
font-size: 85%;
}
div.jetpack-quiz pre {
font: 15px Monaco, Consolas, "Andale Mono", "DejaVu Sans Mono", monospace;
background: transparent;
margin: 0;
padding: 0;
}

View File

@@ -0,0 +1 @@
.jetpack-recipe-meta li.jetpack-recipe-print{display:none}.jetpack-recipe-title{font-size:16pt}.jetpack-recipe-content img{display:inline-block!important;max-width:100%}.jetpack-recipe-image{display:none!important}.jetpack-recipe-content .aligncenter{display:block!important;margin:0 auto 1em!important;text-align:center!important}.jetpack-recipe-content .alignright{float:left!important;margin:0 1em .5em 0!important}.jetpack-recipe-content .alignleft{float:right!important;margin:0 0 .5em 1em!important}.jetpack-recipe-content .alignnone{display:inline-block}

View File

@@ -0,0 +1 @@
.jetpack-recipe-meta li.jetpack-recipe-print{display:none}.jetpack-recipe-title{font-size:16pt}.jetpack-recipe-content img{display:inline-block!important;max-width:100%}.jetpack-recipe-image{display:none!important}.jetpack-recipe-content .aligncenter{display:block!important;margin:0 auto 1em!important;text-align:center!important}.jetpack-recipe-content .alignright{float:left!important;margin:0 1em .5em 0!important}.jetpack-recipe-content .alignleft{float:right!important;margin:0 0 .5em 1em!important}.jetpack-recipe-content .alignnone{display:inline-block}

View File

@@ -0,0 +1,36 @@
.jetpack-recipe-meta li.jetpack-recipe-print {
display: none;
}
.jetpack-recipe-title {
font-size: 16pt;
}
.jetpack-recipe-content img {
display: inline-block !important;
max-width: 100%;
}
.jetpack-recipe-image {
display: none !important;
}
.jetpack-recipe-content .aligncenter {
display: block !important;
margin: 0 auto 1em !important;
text-align: center !important;
}
.jetpack-recipe-content .alignright {
float: right !important;
margin: 0 0 .5em 1em !important;
}
.jetpack-recipe-content .alignleft {
float: left !important;
margin: 0 1em .5em 0 !important;
}
.jetpack-recipe-content .alignnone {
display: inline-block;
}

View File

@@ -0,0 +1,2 @@
/* Do not modify this file directly. It is concatenated from individual module CSS files. */
.jetpack-recipe-meta li.jetpack-recipe-print{display:none}.jetpack-recipe-title{font-size:16pt}.jetpack-recipe-content img{display:inline-block!important;max-width:100%}.jetpack-recipe-image{display:none!important}.jetpack-recipe-content .aligncenter{display:block!important;margin:0 auto 1em!important;text-align:center!important}.jetpack-recipe-content .alignright{float:right!important;margin:0 0 .5em 1em!important}.jetpack-recipe-content .alignleft{float:left!important;margin:0 1em .5em 0!important}.jetpack-recipe-content .alignnone{display:inline-block}

View File

@@ -0,0 +1 @@
.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}.jetpack-recipe-notes{font-style:italic}

View File

@@ -0,0 +1 @@
.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}.jetpack-recipe-notes{font-style:italic}

View File

@@ -0,0 +1,36 @@
.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;
}
.jetpack-recipe-notes {
font-style: italic;
}

View File

@@ -0,0 +1,2 @@
/* Do not modify this file directly. It is concatenated from individual module CSS files. */
.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}.jetpack-recipe-notes{font-style:italic}

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,329 @@
<?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 ( ! is_string( $content ) || 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]
*
* Supported parameters for player customization: width, height,
* autoplay, endscreen-enable, mute, sharing-enabled, start, subtitles-default,
* ui-highlight, ui-logo, ui-start-screen-info, ui-theme
* see https://developer.dailymotion.com/player#player-parameters
* @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;
}
}
$atts = shortcode_atts(
array(
'id' => '', // string
'width' => '', // int
'height' => '', // int
'title' => '', // string
'user' => '', // string
'video' => '', // string
'autoplay' => 0, // int
'endscreen-enable' => 1, // int
'mute' => 0, // int
'sharing-enable' => 1, // int
'start' => '', // int
'subtitles-default' => '', // string
'ui-highlight' => '', // string
'ui-logo' => 1, // int
'ui-start-screen-info' => 0, // int
'ui-theme' => '', // string
), $atts, 'dailymotion'
);
if ( isset( $atts['id'] ) && ! empty( $atts['id'] ) ) {
$id = urlencode( $atts['id'] );
} else {
return '<!--Dailymotion error: bad or missing ID-->';
}
/*set width and height using provided parameters if any */
$width = isset( $atts['width'] ) ? intval( $atts['width'] ) : 0 ;
$height = isset( $atts['height'] ) ? intval( $atts['height'] ) : 0 ;
if ( ! $width && ! $height ) {
if ( ! empty( $content_width ) ) {
$width = absint( $content_width );
} else {
$width = 425;
}
$height = $width / 425 * 334;
} elseif ( ! $height ) {
$height = $width / 425 * 334;
} elseif ( ! $width ) {
$width = $height / 334 * 425;
}
/**
* Let's add parameters if needed.
*
* @see https://developer.dailymotion.com/player
*/
$player_params = array();
if ( isset( $atts['autoplay'] ) && '1' === $atts['autoplay'] ) {
$player_params['autoplay'] = '1';
}
if ( isset( $atts['endscreen-enable'] ) && '0' === $atts['endscreen-enable'] ) {
$player_params['endscreen-enable'] = '0';
}
if ( isset( $atts['mute'] ) && '1' === $atts['mute'] ) {
$player_params['mute'] = '1';
}
if ( isset( $atts['sharing-enable'] ) && '0' === $atts['sharing-enable'] ) {
$player_params['sharing-enable'] = '0';
}
if ( isset( $atts['start'] ) && ! empty( $atts['start'] ) ) {
$player_params['start'] = abs( intval( $atts['start'] ) );
}
if ( isset( $atts['subtitles-default'] ) && ! empty( $atts['subtitles-default'] ) ) {
$player_params['subtitles-default'] = esc_attr( $atts['subtitles-default'] );
}
if ( isset( $atts['ui-highlight'] ) && ! empty( $atts['ui-highlight'] ) ) {
$player_params['ui-highlight'] = esc_attr( $atts['ui-highlight'] );
}
if ( isset( $atts['ui-logo'] ) && '0' === $atts['ui-logo'] ) {
$player_params['ui-logo'] = '0';
}
if ( isset( $atts['ui-start-screen-info'] ) && '0' === $atts['ui-start-screen-info'] ) {
$player_params['ui-start-screen-info'] = '0';
}
if ( isset( $atts['ui-theme'] ) && in_array( strtolower( $atts['ui-theme'] ), array( 'dark', 'light' ) ) ) {
$player_params['ui-theme'] = esc_attr( $atts['ui-theme'] );
}
// Add those parameters to the Video URL.
$video_url = add_query_arg(
$player_params,
'https://www.dailymotion.com/embed/video/' . $id
);
$output = '';
if ( preg_match( '/^[A-Za-z0-9]+$/', $id ) ) {
$output .= '<iframe width="' . esc_attr( $width ) . '" height="' . esc_attr( $height ) . '" src="' . esc_url( $video_url ) . '" style="border:0;" allowfullscreen></iframe>';
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() ) ) {
$output .= '<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'] ) ) {
/* translators: %s is a Dailymotion user name */
$output .= '<br /><em>' . wp_kses( sprintf( __( 'Uploaded by %s', 'jetpack' ), '<a href="' . esc_url( 'http://www.dailymotion.com/' . $user ) . '" target="_blank">' . esc_html( $user ) . '</a>' ), array( 'a' => array( 'href' => true, 'target' => true ) ) ) . '</em>';
}
}
return $output;
}
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" style="border:0;" src="' . esc_url( '//www.dailymotion.com/badge/user/' . $username . '?type=grid' ) . '"></iframe>';
break;
case 'carousel':
return '<iframe width="300px" height="360px" scrolling="no" style="border:0;" src="' . esc_url( '//www.dailymotion.com/badge/user/' . $username . '?type=carousel' ) . '"></iframe>';
break;
default:
return '<iframe width="300px" height="78px" scrolling="no" style="border: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 ( ! is_string( $content ) || 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 ( ! is_string( $content ) || 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,73 @@
<?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 {
$width = 552; // As of 01/2017, the default width of Facebook embeds when no width attribute provided
global $content_width;
if ( isset( $content_width ) ) {
$width = min( $width, $content_width );
}
$embed = sprintf( '<fb:post href="%s" data-width="%s"></fb:post>', esc_url( $url ), esc_attr( $width ) );
}
// 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'] ) {
ob_start();
wp_scripts()->do_items( array( 'jetpack-facebook-embed' ) );
$scripts = ob_get_clean();
return $embed . $scripts;
} 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,198 @@
<?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 ( ! is_string( $content ) || 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,
), $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,207 @@
<?php
/**
* Getty shortcode
*
* [getty src="82278805" width="$width" height="$height"]
* <div class="getty embed image" style="background-color:#fff;display:inline-block;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;color:#a7a7a7;font-size:11px;width:100%;max-width:462px;"><div style="padding:0;margin:0;text-align:left;"><a href="http://www.gettyimages.com/detail/82278805" target="_blank" style="color:#a7a7a7;text-decoration:none;font-weight:normal !important;border:none;display:inline-block;">Embed from Getty Images</a></div><div style="overflow:hidden;position:relative;height:0;padding:80.086580% 0 0 0;width:100%;"><iframe src="//embed.gettyimages.com/embed/82278805?et=jGiu6FXXSpJDGf1SnwLV2g&sig=TFVNFtqghwNw5iJQ1MFWnI8f4Y40_sfogfZLhai6SfA=" width="462" height="370" scrolling="no" frameborder="0" style="display:inline-block;position:absolute;top:0;left:0;width:100%;height:100%;"></iframe></div><p style="margin:0;"></p></div>
*/
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
add_action( 'init', 'jetpack_getty_enable_embeds' );
} else {
jetpack_getty_enable_embeds();
}
/**
* Register Getty as oembed provider. Add filter to reverse iframes to shortcode. Register [getty] shortcode.
*
* @since 4.5.0
* @since 5.8.0 removed string parameter.
*/
function jetpack_getty_enable_embeds() {
// Support their oEmbed Endpoint
wp_oembed_add_provider( '#https?://www\.gettyimages\.com/detail/.*#i', "https://embed.gettyimages.com/oembed/", true );
wp_oembed_add_provider( '#https?://(www\.)?gty\.im/.*#i', "https://embed.gettyimages.com/oembed/", true );
// Allow iframes to be filtered to short code (so direct copy+paste can be done)
add_filter( 'pre_kses', 'wpcom_shortcodereverse_getty' );
// Actually display the Getty Embed
add_shortcode( 'getty', 'jetpack_getty_shortcode' );
}
/**
* Filters the oEmbed provider URL for Getty URLs to include site URL host as
* caller if available, falling back to "wordpress.com". Must be applied at
* time of embed in case that `init` is too early (WP.com REST API).
*
* @module shortcodes
*
* @since 5.8.0
*
* @see WP_oEmbed::fetch
*
* @return string oEmbed provider URL
*/
add_filter( 'oembed_fetch_url', 'getty_add_oembed_endpoint_caller' );
function getty_add_oembed_endpoint_caller( $provider ) {
// By time filter is called, original provider URL has had url, maxwidth,
// maxheight query parameters added.
if ( 0 !== strpos( $provider, 'https://embed.gettyimages.com/oembed/' ) ) {
return $provider;
}
// Set the caller argument to pass to Getty's oembed provider.
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
// Only include caller for non-private sites
if ( ! function_exists( 'is_private_blog' ) || ! is_private_blog() ) {
$host = parse_url( get_bloginfo( 'url' ), PHP_URL_HOST );
}
// Fall back to WordPress.com
if ( empty( $host ) ) {
$host = 'wordpress.com';
}
} else {
$host = parse_url( get_home_url(), PHP_URL_HOST );
}
return add_query_arg( 'caller', $host, $provider );
}
/**
* Compose shortcode based on Getty iframes.
*
* @since 4.5.0
*
* @param string $content
*
* @return mixed
*/
function wpcom_shortcodereverse_getty( $content ) {
if ( ! is_string( $content ) || false === stripos( $content, '.gettyimages.com/' ) ) {
return $content;
}
$regexp = '!<iframe\s+src=[\'"](https?:)?//embed\.gettyimages\.com/embed(/|/?\?assets=)([a-z0-9_-]+(,[a-z0-9_-]+)*)[^\'"]*?[\'"]((?:\s+\w+=[\'"][^\'"]*[\'"])*)((?:[\s\w]*))></iframe>!i';
$regexp_ent = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $regexp, ENT_NOQUOTES ) );
// Markup pattern for 2017 embed syntax with significant differences from
// the prior pattern:
$regexp_2017 = '!<a.+?class=\'gie-(single|slideshow)\'.+?gie\.widgets\.load\({([^}]+)}\).+?embed-cdn\.gettyimages\.com/widgets\.js.+?</script>!';
$regexp_2017_ent = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $regexp_2017, ENT_NOQUOTES ) );
foreach ( array( 'regexp_2017', 'regexp_2017_ent', 'regexp', 'regexp_ent' ) as $reg ) {
if ( ! preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) {
continue;
}
foreach ( $matches as $match ) {
if ( 'regexp_2017' === $reg || 'regexp_2017_ent' === $reg ) {
// Extract individual keys from the matched JavaScript object
$params = $match[2];
if ( ! preg_match_all( '!(?P<key>\w+)\s*:\s*([\'"](?P<value>[^\'"]*?)(px)?[\'"])!', $params, $key_matches, PREG_SET_ORDER ) ) {
continue;
}
foreach ( $key_matches as $key_match ) {
switch ( $key_match['key'] ) {
case 'items': $ids = $key_match['value']; break;
case 'w': $width = (int) $key_match['value']; break;
case 'h': $height = (int) $key_match['value']; break;
case 'tld': $tld = $key_match['value']; break;
}
}
} else {
$params = $match[5];
if ( 'regexp_ent' === $reg ) {
$params = html_entity_decode( $params );
}
$params = wp_kses_hair( $params, array( 'http' ) );
$ids = esc_html( $match[3] );
$width = isset( $params['width'] ) ? (int) $params['width']['value'] : 0;
$height = isset( $params['height'] ) ? (int) $params['height']['value'] : 0;
}
if ( empty( $ids ) ) {
continue;
}
$shortcode = '[getty src="' . esc_attr( $ids ) . '"';
if ( ! empty( $width ) ) {
$shortcode .= ' width="' . esc_attr( $width ) . '"';
}
if ( ! empty( $height ) ) {
$shortcode .= ' height="' . esc_attr( $height ) . '"';
}
// While it does not appear to have any practical impact, Getty has
// requested that we include TLD in the embed request
if ( ! empty( $tld ) ) {
$shortcode .= ' tld="' . esc_attr( $tld ). '"';
}
$shortcode .= ']';
$content = str_replace( $match[0], $shortcode, $content );
}
}
// strip out enclosing div and any other markup
$regexp = '%<div class="getty\s[^>]*+>.*?<div[^>]*+>(\[getty[^\]]*+\])\s*</div>.*?</div>%is';
$regexp_ent = str_replace( array( '&amp;#0*58;', '[^&gt;]' ), array( '&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 ) {
$content = str_replace( $match[0], $match[1], $content );
}
}
/** This action is documented in modules/widgets/social-media-icons.php */
do_action( 'jetpack_bump_stats_extras', 'html_to_shortcode', 'getty' );
return $content;
}
/**
* Parse shortcode arguments and render its output.
*
* @since 4.5.0
*
* @param array $atts Shortcode parameters.
* @param string $content Content enclosed by shortcode tags.
*
* @return string
*/
function jetpack_getty_shortcode( $atts, $content = '' ) {
if ( ! empty( $content ) ) {
$src = $content;
} elseif ( ! empty( $atts['src'] ) ) {
$src = $atts['src'];
} elseif ( ! empty( $atts[0] ) ) {
$src = $atts[0];
} else {
return '<!-- Missing Getty Source ID -->';
}
$src = preg_replace( '/^([\da-z-]+(,[\da-z-]+)*).*$/', '$1', $src );
$params = array(
'width' => isset( $atts['width'] ) ? (int) $atts['width'] : null,
'height' => isset( $atts['height'] ) ? (int) $atts['height'] : null
);
if ( ! empty( $atts['tld'] ) ) {
$params['tld'] = $atts['tld'];
}
return wp_oembed_get( 'https://gty.im/' . $src, array_filter( $params ) );
}

View File

@@ -0,0 +1,98 @@
<?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',
Jetpack::get_file_url_for_environment( '_inc/build/shortcodes/js/gist.min.js', 'modules/shortcodes/js/gist.js' ),
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,242 @@
<?php
/**
* Google Docs and Google Calendar Shortcode
*
* Presentation:
* <iframe src="https://docs.google.com/present/embed?id=dhfhrphh_123drp8s65c&interval=15&autoStart=true&loop=true&size=l" frameborder="0" width="700" height="559"></iframe>
* <iframe src="https://docs.google.com/presentation/embed?id=13ItX4jV0SOSdr-ZjHarcpTh9Lr4omfsHAp87jpxv8-0&start=false&loop=false&delayms=3000" frameborder="0" width="960" height="749" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>
*
* Document:
* <iframe src="https://docs.google.com/document/pub?id=1kDatklacdZ_tZUOpWtt_ONzY97Ldj2zFcuO9LBY2Ln4&amp;embedded=true"></iframe>
* <iframe src="https://docs.google.com/document/d/1kDatklacdZ_tZUOpWtt_ONzY97Ldj2zFcuO9LBY2Ln4/pub?embedded=true"></iframe>
* <iframe src="https://docs.google.com/document/d/e/2PACX-1vRkpIdasKL-eKXDjJgpEONduUspZTz0YmKaajfie0eJYnzikuyusuG1_V8X8T9XflN9l8A1oCM2sgEA/pub?embedded=true"></iframe>
*
* External document:
* <iframe width=100% height=560px frameborder=0 src=https://docs.google.com/a/pranab.in/viewer?a=v&pid=explorer&chrome=false&embedded=true&srcid=1VTMwdgGiDMt8MCr75-YkQP-4u9WmEp1Qvf6C26KYBgFilxU2qndpd-VHhBIn&hl=en></iframe>
*
* Spreadsheet Form:
* <iframe src="https://spreadsheets.google.com/embeddedform?formkey=dEVOYnMzZG5jMUpGbjFMYjFYNVB3NkE6MQ" width="760" height="710" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe>
*
* Spreadsheet Widget:
* <iframe width='500' height='300' frameborder='0' src='https://spreadsheets1.google.com/a/petedavies.com/pub?hl=en&hl=en&key=0AjSij7nlnXvKdHNsNjRSWG12YmVfOEFwdlMxQ3J1S1E&single=true&gid=0&output=html&widget=true'></iframe>
* <iframe width='500' height='300' frameborder='0' src='https://spreadsheets.google.com/spreadsheet/pub?hl=en&hl=en&key=0AhInIwfvYrIUdGJiTXhtUEhBSFVPUzdRZU5OMDlqdnc&output=html&widget=true'></iframe>
*
* Calendar:
* <iframe src="https://www.google.com/calendar/embed?src=serjant%40gmail.com&ctz=Europe/Sofia" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>
* <iframe src="http://www.google.com/calendar/hosted/belcastro.com/embed?src=n8nr8sd6v9hnus3nmlk7ed1238%40group.calendar.google.com&ctz=Europe/Zurich" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>
*
* Customized calendar:
* <iframe src="https://www.google.com/calendar/embed?title=asdf&amp;showTitle=0&amp;showNav=0&amp;showDate=0&amp;showPrint=0&amp;showTabs=0&amp;showCalendars=0&amp;
* showTz=0&amp;mode=AGENDA&amp;height=300&amp;wkst=2&amp;hl=fi&amp;bgcolor=%23ffcccc&amp;src=m52gdmbgelo3itf00u1v44g0ns%40group.calendar.google.com&amp;color=%234E5D6C&amp;
* src=serjant%40gmail.com&amp;color=%235229A3&amp;ctz=Europe%2FRiga" style=" border:solid 1px #777 " width="500" height="300" frameborder="0" scrolling="no"></iframe>
*
* Generic
* <iframe src="https://docs.google.com/file/d/0B0SIdZW7iu-zX1RWREJpMXVHZVU/preview" width="640" height="480"></iframe>
*/
add_filter( 'pre_kses', 'googleapps_embed_to_shortcode' );
add_shortcode( 'googleapps', 'googleapps_shortcode' );
/**
* Reverse iframe embed to shortcode mapping HTML attributes to shortcode attributes.
*
* @since 4.5.0
*
* @param string $content
*
* @return mixed
*/
function googleapps_embed_to_shortcode( $content ) {
if ( ! is_string( $content ) || false === stripos( $content, '<iframe' ) && false === stripos( $content, '.google.com' ) ) {
return $content;
}
$regexp = '#<iframe((?:\s+\w+="[^"]*")*?)\s*src="https?://(docs|drive|spreadsheets\d*|calendar|www)*\.google\.com/(?!maps)([-\w\./]+)(?:\?)?([^"]+)?"\s*((?:\s+\w+="[^"]*")*?)>.*?</iframe>#i';
$regexp_ent = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $regexp, ENT_NOQUOTES ) );
$regexp_squot = str_replace( '"', "'", $regexp );
$regexp_ent_squot = str_replace( '"', "'", $regexp_ent );
$regexp_noquot = '!<iframe(.*?)src=https://(docs|drive)\.google\.com/[-\.\w/]*?(viewer)\?(.*?)>(.*?)</iframe>!';
$regexp_ent_noquot = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $regexp_noquot, ENT_NOQUOTES ) );
foreach ( array( 'regexp', 'regexp_ent', 'regexp_squot', 'regexp_ent_squot', 'regexp_noquot', 'regexp_ent_noquot' ) as $reg ) {
if ( ! preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) {
continue;
}
foreach ( $matches as $match ) {
$params = $match[1] . $match[5];
if ( in_array( $reg, array( 'regexp_ent', 'regexp_ent_squot' ) ) ) {
$params = html_entity_decode( $params );
}
$params = wp_kses_hair( $params, array( 'http' ) );
$width = $height = 0;
if ( isset( $params['width'] ) ) {
$width = (int) $params['width']['value'];
}
if ( isset( $params['height'] ) ) {
$height = (int) $params['height']['value'];
}
// allow the user to specify width greater than 200 inside text widgets
if ( $width > 400 && isset( $_POST['widget-text'] ) ) {
$width = 200;
$height = 200;
}
$attributes = '';
if ( isset( $params['width'] ) && '100%' == $params['width']['value'] ) {
$width = '100%';
}
if ( $width ) {
$attributes = ' width="' . $width . '"';
}
if ( $height ) {
$attributes .= ' height="' . $height . '"';
}
$domain = 'spreadsheets';
if ( in_array( $match[2], array( 'docs', 'drive', 'www', 'calendar' ) ) ) {
$domain = $match[2];
}
// Make sure this is actually something that the shortcode supports. If it's not, leave the HTML alone.
if ( ! googleapps_validate_domain_and_dir( $domain, $match[3] ) ) {
continue;
}
/** This action is documented in modules/widgets/social-media-icons.php */
do_action( 'jetpack_bump_stats_extras', 'html_to_shortcode', googleapps_service_name( $domain, $match[3] ) );
$content = str_replace( $match[0], '[googleapps domain="' . $domain . '" dir="' . $match[3] . '" query="' . esc_attr( $match[4] ) . '"' . $attributes . ' /]', $content );
}
}
return $content;
}
/**
* Parse shortcode attributes and output a Google Docs embed.
*
* @since 4.5.0
*
* @param array $atts
*
* @return string
*/
function googleapps_shortcode( $atts ) {
global $content_width;
$attr = shortcode_atts(
array(
'width' => '100%',
'height' => '560',
'domain' => 'docs',
'dir' => 'document',
'query' => '',
'src' => '',
), $atts
);
if ( isset( $content_width ) && is_numeric( $attr['width'] ) && $attr['width'] > $content_width ) {
$attr['width'] = $content_width;
}
if ( isset( $content_width ) && '560' === $attr['height'] ) {
$attr['height'] = $content_height = floor( $content_width * 3 / 4 );
}
if ( isset( $atts[0] ) && $atts[0] ) {
$attr['src'] = $atts[0];
}
if ( $attr['src'] && preg_match( '!https?://(docs|drive|spreadsheets\d*|calendar|www)*\.google\.com/([-\w\./]+)\?([^"]+)!', $attr['src'], $matches ) ) {
$attr['domain'] = $matches[1];
$attr['dir'] = $matches[2];
parse_str( htmlspecialchars_decode( $matches[3] ), $query_ar );
$query_ar['chrome'] = 'false';
$query_ar['embedded'] = 'true';
$attr['query'] = http_build_query( $query_ar );
}
if ( ! googleapps_validate_domain_and_dir( $attr['domain'], $attr['dir'] ) ) {
return '<!-- Unsupported URL -->';
}
$attr['query'] = $attr['dir'] . '?' . $attr['query'];
/** This action is documented in modules/widgets/social-media-icons.php */
do_action( 'jetpack_bump_stats_extras', 'embeds', googleapps_service_name( $attr['domain'], $attr['dir'] ) );
return sprintf(
'<iframe src="%s" frameborder="0" width="%s" height="%s" marginheight="0" marginwidth="0"></iframe>',
esc_url( 'https://' . $attr['domain'] . '.google.com/' . $attr['query'] ),
esc_attr( $attr['width'] ),
esc_attr( $attr['height'] )
);
}
/**
* Check that the domain blogs to a Google Apps domain.
*
* @since 4.5.0
*
* @param string $domain
* @param string $dir
*
* @return bool
*/
function googleapps_validate_domain_and_dir( $domain, $dir ) {
if ( ! in_array( $domain, array( 'docs', 'drive', 'www', 'spreadsheets', 'calendar' ) ) ) {
return false;
}
// Calendars
if ( ( 'www' === $domain || 'calendar' === $domain ) && 'calendar/' !== substr( $dir, 0, 9 ) ) {
return false;
}
// Docs
if ( in_array( $domain, array( 'docs', 'drive' ) ) && ! preg_match( '![-\.\w/]*(presentation/embed|presentation/d/(.*)|present/embed|document/pub|spreadsheets/d/(.*)|document/d/(e/)?[\w-]+/pub|file/d/[\w-]+/preview|viewer|forms/d/(.*)/viewform|spreadsheet/\w+)$!', $dir ) ) {
return false;
}
// Spreadsheets
if ( 'spreadsheets' == $domain && ! preg_match( '!^([-\.\w/]+/pub|[-\.\w/]*embeddedform)$!', $dir ) ) {
return false;
}
return true;
}
/**
* Get the name of the service we'll be embedding.
*
* @since 4.5.0
*
* @param string $domain
* @param string $dir
*
* @return string
*/
function googleapps_service_name( $domain, $dir ) {
switch ( $domain ) {
case 'drive':
case 'docs':
$service_name = ( 'present/embed' == $dir ) ? 'googledocs_presentation' : 'googledocs_document';
break;
case 'spreadsheets':
$service_name = ( 'embeddedform' == $dir ) ? 'googledocs_form' : 'googledocs_spreadsheet';
break;
case 'calendar':
default:
$service_name = 'google_calendar';
}
return $service_name;
}

View File

@@ -0,0 +1,112 @@
<?php
/*
* Google maps iframe - transforms code that looks like that:
* <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://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 ( ! is_string( $content ) || ( 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 https://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,30 @@
<?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 ) {
wp_enqueue_script( 'jetpack-gplus-api', 'https://apis.google.com/js/platform.js', array(), null, true );
return sprintf( '<div class="g-post" data-href="%s"></div>', esc_url( $url ) );
}
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,150 @@
<?php
/**
* Gravatar shortcode for avatar and profile.
*
* Usage:
*
* [gravatar email="user@example.org" size="48"]
* [gravatar_profile who="user@example.org"]
*/
add_shortcode( 'gravatar', 'jetpack_gravatar_shortcode' );
add_shortcode( 'gravatar_profile', 'jetpack_gravatar_profile_shortcode' );
/**
* Get gravatar using the email provided at the specified size.
*
* @since 4.5.0
*
* @param array $atts Shortcode attributes.
*
* @return bool|string
*/
function jetpack_gravatar_shortcode( $atts ) {
$atts = shortcode_atts( array(
'email' => '',
'size' => 96,
), $atts );
if ( empty( $atts['email'] ) || ! is_email( $atts['email'] ) ) {
return false;
}
$atts['size'] = intval( $atts['size'] );
if ( 0 > $atts['size'] ) {
$atts['size'] = 96;
}
return get_avatar( $atts['email'], $atts['size'] );
}
/**
* Display Gravatar profile
*
* @since 4.5.0
*
* @param array $atts Shortcode attributes.
*
* @uses shortcode_atts()
* @uses get_user_by()
* @uses is_email()
* @uses sanitize_email()
* @uses sanitize_user()
* @uses set_url_scheme()
* @uses wpcom_get_avatar_url()
* @uses get_user_attribute()
* @uses esc_url()
* @uses esc_html()
* @uses _e()
*
* @return string
*/
function jetpack_gravatar_profile_shortcode( $atts ) {
// Give each use of the shortcode a unique ID
static $instance = 0;
// Process passed attributes
$atts = shortcode_atts( array(
'who' => null,
), $atts, 'jetpack_gravatar_profile' );
// Can specify username, user ID, or email address
if ( is_numeric( $atts['who'] ) ) {
$user = get_user_by( 'id', (int) $atts['who'] );
} elseif ( is_email( $atts['who'] ) ) {
$user = get_user_by( 'email', sanitize_email( $atts['who'] ) );
} elseif ( is_string( $atts['who'] ) ) {
$user = get_user_by( 'login', sanitize_user( $atts['who'] ) );
} else {
$user = false;
}
// Bail if we don't have a user
if ( false === $user ) {
return false;
}
// Render the shortcode
$gravatar_url = set_url_scheme( 'http://gravatar.com/' . $user->user_login );
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
$avatar_url = wpcom_get_avatar_url( $user->ID, 96 );
$avatar_url = $avatar_url[0];
$user_location = get_user_attribute( $user->ID, 'location' );
} else {
$avatar_url = get_avatar_url( $user->user_email, array( 'size' => 96 ) );
$user_location = get_user_meta( $user->ID, 'location', true );
}
ob_start();
?>
<script type="text/javascript">
( function() {
if ( null === document.getElementById( 'gravatar-profile-embed-styles' ) ) {
var headID = document.getElementsByTagName( 'head' )[0];
var styleNode = document.createElement( 'style' );
styleNode.type = 'text/css';
styleNode.id = 'gravatar-profile-embed-styles';
var gCSS = '.grofile-wrap { border: solid 1px #eee; padding: 10px; } .grofile { padding: 0 0 5px 0; } .grofile-left { float: left; display: block; width: 96px; margin-right: 15px; } .grofile .gravatar { margin-bottom: 5px; } .grofile-clear { clear: left; font-size: 1px; height: 1px; } .grofile ul li a { text-indent: -99999px; } .grofile .grofile-left a:hover { text-decoration: none !important; border: none !important; } .grofile-name { margin-top: 0; }';
if ( document.all ) {
styleNode.innerText = gCSS;
} else {
styleNode.textContent = gCSS;
}
headID.appendChild( styleNode );
}
} )();
</script>
<div class="grofile vcard" id="grofile-embed-<?php echo esc_attr( $instance ); ?>">
<div class="grofile-inner">
<div class="grofile-left">
<div class="grofile-img">
<a href="<?php echo esc_url( $gravatar_url ); ?>">
<img src="<?php echo esc_url( $avatar_url ); ?>" width="96" height="96" class="no-grav gravatar photo" />
</a>
</div>
</div>
<div class="grofile-right">
<p class="grofile-name fn">
<strong><?php echo esc_html( $user->display_name ); ?></strong>
<?php if ( ! empty( $user_location ) ) : ?><br><span class="grofile-location adr"><?php echo esc_html( $user_location ); ?></span><?php endif; ?>
</p>
<p class="grofile-bio"><strong><?php esc_html_e( 'Bio:', 'jetpack' ); ?></strong> <?php echo wp_kses_post( $user->description ); ?></p>
<p class="grofile-view">
<a href="<?php echo esc_url( $gravatar_url ); ?>"><?php esc_html_e( 'View complete profile', 'jetpack' ); ?></a>
</p>
</div>
<span class="grofile-clear">&nbsp;</span>
</div>
</div><?php
// Increment and return the rendered profile
$instance++;
return ob_get_clean();
}

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' );

View File

@@ -0,0 +1,272 @@
<?php
/**
* Hulu Shortcode
*
* [hulu 369061]
* [hulu id=369061]
* [hulu id=369061 width=512 height=288 start_time="10" end_time="20" thumbnail_frame="10"]
* [hulu http://www.hulu.com/watch/369061]
* [hulu id=gQ6Z0I990IWv_VFQI2J7Eg width=512 height=288]
*
* <object width="512" height="288">
* <param name="movie" value="http://www.hulu.com/embed/gQ6Z0I990IWv_VFQI2J7Eg"></param>
* <param name="allowFullScreen" value="true"></param>
* <embed src="http://www.hulu.com/embed/gQ6Z0I990IWv_VFQI2J7Eg" type="application/x-shockwave-flash" width="512" height="288" allowFullScreen="true"></embed>
* </object>
*/
if ( get_option( 'embed_autourls' ) ) {
// Convert hulu URLS to shortcodes for old comments, saved before comments for shortcodes were enabled
add_filter( 'comment_text', 'jetpack_hulu_link', 1 );
}
add_shortcode( 'hulu', 'jetpack_hulu_shortcode' );
/**
* Return a Hulu video ID from a given set to attributes.
*
* @since 4.5.0
*
* @param array $atts Shortcode parameters.
*
* @return string $id Hulu video ID.
*/
function jetpack_shortcode_get_hulu_id( $atts ) {
// This will catch an id explicitly defined as such, or assume any param without a label is the id. First found is used.
if ( isset( $atts['id'] ) ) {
// First we check to see if [hulu id=369061] or [hulu id=gQ6Z0I990IWv_VFQI2J7Eg] was used
$id = esc_attr( $atts['id'] );
} else if ( isset( $atts[0] ) && preg_match( '|www\.hulu\.com/watch/(\d+)|i', $atts[0], $match ) ) {
// this checks for [hulu http://www.hulu.com/watch/369061]
$id = (int) $match[1];
} else if ( isset( $atts[0] ) ) {
// This checks for [hulu 369061] or [hulu 65yppv6xqa45s5n7_m1wng]
$id = esc_attr( $atts[0] );
} else {
$id = 0;
}
return $id;
}
/**
* Convert a Hulu shortcode into an embed code.
*
* @since 4.5.0
*
* @param array $atts An array of shortcode attributes.
*
* @return string The embed code for the Hulu video.
*/
function jetpack_hulu_shortcode( $atts ) {
global $content_width;
// Set a default content width, if it's not specified.
$attr = shortcode_atts(
array(
'id' => '',
'width' => $content_width ? $content_width : 640,
'start_time' => '',
'end_time' => '',
'thumbnail_frame' => ''
), $atts
);
$id = jetpack_shortcode_get_hulu_id( $atts );
if ( ! $id ) {
return '<!-- Hulu Error: Hulu shortcode syntax invalid. -->';
}
$start_time = 0;
if ( is_numeric( $attr['start_time'] ) ) {
$start_time = intval( $attr['start_time'] );
}
if ( is_numeric( $attr['end_time'] ) && intval( $attr['end_time'] ) > $start_time ) {
$end_time = intval( $attr['end_time'] );
}
if ( is_numeric( $attr['thumbnail_frame'] ) ) {
$thumbnail_frame = intval( $attr['thumbnail_frame'] );
}
// check to see if $id is 76560 else we assume it's gQ6Z0I990IWv_VFQI2J7Eg
// If id is numeric, we'll send it off to the hulu oembed api to get the embed URL (and non-numeric id)
if ( is_numeric( $id ) ) {
$transient_key = "hulu-$id";
if ( false === ( $transient_value = get_transient( $transient_key ) ) ) {
// let's make a cross-site http request out to the hulu oembed api
$response = wp_remote_get( 'http://www.hulu.com/api/oembed.json?url=' . urlencode( 'http://www.hulu.com/watch/' . esc_attr( $id ) ) );
$response_code = wp_remote_retrieve_response_code( $response );
$response_message = wp_remote_retrieve_response_message( $response );
if ( 200 !== $response_code && ! empty( $response_message ) ) {
return "<!-- Hulu Error: Hulu shortcode http error $response_message -->";
} elseif ( 200 !== $response_code ) {
return "<!-- Hulu Error: Hulu shortcode unknown error occurred, $response_code -->";
} else {
$response_body = wp_remote_retrieve_body( $response );
$json = json_decode( $response_body );
// Pull out id from embed url (from oembed API)
$embed_url_params = array();
parse_str( parse_url( $json->embed_url, PHP_URL_QUERY ), $embed_url_params );
if ( isset( $embed_url_params['eid'] ) ) {
$id = $embed_url_params['eid'];
}
// let's cache this response indefinitely.
set_transient( $transient_key, $id );
}
} else {
$id = $transient_value;
}
}
if ( ! $id ) {
return '<!-- Hulu Error: Not a Hulu video. -->';
}
$width = intval( $attr['width'] );
$height = round( ( $width / 640 ) * 360 );
$iframe_url = 'http://www.hulu.com/embed.html';
if ( is_ssl() ) {
$iframe_url = 'https://secure.hulu.com/embed.html';
}
$query_args = array();
$query_args['eid'] = esc_attr( $id );
if ( isset( $start_time ) ) {
$query_args['st'] = intval( $start_time );
}
if ( isset( $end_time ) ) {
$query_args['et'] = intval( $end_time );
}
if ( isset( $thumbnail_frame ) ) {
$query_args['it'] = 'i' . intval( $thumbnail_frame );
}
$iframe_url = add_query_arg( $query_args, $iframe_url );
$html = sprintf(
'<div class="embed-hulu" style="text-align: center;"><iframe src="%s" width="%s" height="%s" style="border:0;" scrolling="no" webkitAllowFullScreen
mozallowfullscreen allowfullscreen></iframe></div>',
esc_url( $iframe_url ),
esc_attr( $width ),
esc_attr( $height )
);
$html = apply_filters( 'video_embed_html', $html );
return $html;
}
/**
* Callback to convert Hulu links in comments into a embed src.
*
* @since 4.5.0
*
* @param array $matches
*
* @return string
*/
function jetpack_hulu_link_callback( $matches ) {
$video_id = $matches[4];
$src = is_ssl()
? 'https://secure.hulu.com'
: 'http://www.hulu.com';
// Make up an embed src to pass to the shortcode reversal function
$attrs['src'] = $src . '/embed.html?eid=' . esc_attr( $video_id );
return wpcom_shortcodereverse_huluhelper( $attrs );
}
/**
* Convert Hulu links in comments into a Hulu shortcode.
*
* @since 4.5.0
*
* @param string $content
*
* @return string
*/
function jetpack_hulu_link( $content ) {
$content = preg_replace_callback( '!^(http(s)?://)?(www\.)?hulu\.com\/watch\/([0-9]+)$!im', 'jetpack_hulu_link_callback', $content );
return $content;
}
/**
* Makes a Hulu shortcode from $attrs and $pattern
*
* @since 4.5.0
*
* @param array $attrs
*
* @return string
*/
function wpcom_shortcodereverse_huluhelper( $attrs ) {
$attrs = wpcom_shortcodereverse_parseattr( $attrs );
$src_attributes = array();
parse_str( parse_url( $attrs['src'], PHP_URL_QUERY ), $src_attributes );
$attrs = array_merge( $attrs, $src_attributes );
// If we don't have an eid, we can't do anything. Just send back the src string.
if ( ! isset( $attrs['eid'] ) ) {
return $attrs['src'];
}
$shortcode = '[hulu id=' . esc_attr( $attrs['eid'] );
if ( $attrs['width'] ) {
$shortcode .= ' width=' . intval( $attrs['width'] );
}
if ( $attrs['height'] ) {
$shortcode .= ' height=' . intval( $attrs['height'] );
}
if ( $attrs['st'] ) {
$shortcode .= ' start_time=' . intval( $attrs['st'] );
}
if ( $attrs['et'] ) {
$shortcode .= ' end_time=' . intval( $attrs['et'] );
}
if ( $attrs['it'] ) {
// the thumbnail frame attribute comes with an i in front of the value, so we've got to remove that
$shortcode .= ' thumbnail_frame=' . intval( ltrim( $attrs['it'], 'i' ) );
}
$shortcode .= ']';
return $shortcode;
}
/**
* Initiates process to convert iframe HTML into a Hulu shortcode.
*
* Example:
* <iframe width="512" height="288" src="http://www.hulu.com/embed.html?eid=nlg_ios3tutcfrhatkiaow&et=20&st=10&it=i11" frameborder="0" scrolling="no" webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe>
*
* Converts to:
* [hulu id=nlg_ios3tutcfrhatkiaow width=512 height=288 start_time=10 end_time=20 thumbnail_frame=11]
*
* @since 4.5.0
*
* @param array $attrs
*
* @return string
*/
function wpcom_shortcodereverse_huluembed( $attrs ) {
$shortcode = wpcom_shortcodereverse_huluhelper( $attrs );
if ( substr( $shortcode, 0, 1 ) == '[' ) {
/** This action is documented in modules/widgets/social-media-icons.php */
do_action( 'jetpack_bump_stats_extras', 'html_to_shortcode', 'hulu-embed' );
}
return $shortcode;
}
Filter_Embedded_HTML_Objects::register( '#^http://www.hulu.com/embed.html#i', 'wpcom_shortcodereverse_huluembed', true );

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 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: 1009 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -0,0 +1,186 @@
<?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 ( ! is_string( $content ) || 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 ) {
$atts['width'] = $max_width;
} elseif ( $atts['width'] < $min_width ) {
$atts['width'] = $min_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',
Jetpack::get_file_url_for_environment( '_inc/build/shortcodes/js/instagram.min.js', 'modules/shortcodes/js/instagram.js' ),
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,102 @@
'use strict';
/* global wp */
/* eslint react/react-in-jsx-scope: 0 */
(function (blocks, components, i18n) {
var registerBlockType = blocks.registerBlockType,
UrlInput = blocks.UrlInput;
var Placeholder = components.Placeholder,
SelectControl = components.SelectControl;
var __ = i18n.__;
registerBlockType('jetpack/vr', {
title: __('VR Image', 'jetpack'),
icon: 'embed-photo',
category: 'embed',
support: {
html: false
},
attributes: {
url: {
type: 'string'
},
view: {
type: 'string'
}
},
edit: function edit(props) {
var attributes = props.attributes;
var onSetUrl = function onSetUrl(value) {
return props.setAttributes({ url: value });
};
var onSetView = function onSetView(value) {
return props.setAttributes({ view: value });
};
var renderEdit = function renderEdit() {
if (attributes.url && attributes.view) {
return wp.element.createElement(
'div',
{ className: props.className },
wp.element.createElement('iframe', {
title: __('VR Image', 'jetpack'),
allowFullScreen: 'true',
frameBorder: '0',
width: '100%',
height: '300',
src: 'https://vr.me.sh/view/?view=' + encodeURIComponent(attributes.view) + '&url=' + encodeURIComponent(attributes.url)
})
);
}
return wp.element.createElement(
'div',
null,
wp.element.createElement(
Placeholder,
{
key: 'placeholder',
instructions: __('Enter URL to VR image', 'jetpack'),
icon: 'format-image',
label: __('VR Image', 'jetpack'),
className: props.className
},
wp.element.createElement(UrlInput, {
value: attributes.url,
onChange: onSetUrl
}),
wp.element.createElement(
'div',
{ style: { marginTop: '10px' } },
wp.element.createElement(SelectControl, {
label: __('View Type', 'jetpack'),
value: attributes.view,
onChange: onSetView,
options: [{ label: '', value: '' }, { label: __('360', 'jetpack'), value: '360' }, { label: __('Cinema', 'jetpack'), value: 'cinema' }]
})
)
)
);
};
return renderEdit();
},
save: function save(props) {
return wp.element.createElement(
'div',
{ className: props.className },
wp.element.createElement('iframe', {
title: __('VR Image', 'jetpack'),
allowFullScreen: 'true',
frameBorder: '0',
width: '100%',
height: '300',
src: 'https://vr.me.sh/view/?view=' + encodeURIComponent(props.attributes.view) + '&url=' + encodeURIComponent(props.attributes.url)
})
);
}
});
})(wp.blocks, wp.components, wp.i18n);

View File

@@ -0,0 +1,29 @@
/* global brightcove, brightcoveData */
(function($){
var script = document.createElement('script'),
tld = 'co.jp' === brightcoveData.tld ? 'co.jp' : 'com',
timer = false;
// Load Brightcove script
script.src = 'https://sadmin.brightcove.' + tld + '/js/BrightcoveExperiences.js';
script.type = 'text/javascript';
script.language = 'JavaScript';
document.head.appendChild( script );
// Start detection for Brightcove script loading in its object
try_brightcove();
// Detect if Brightcove script has loaded and bind some events once loaded
function try_brightcove() {
clearTimeout( timer );
if ( 'object' === typeof brightcove ) {
$( document ).ready( brightcove.createExperiences );
$( 'body' ).on( 'post-load', brightcove.createExperiences );
brightcove.createExperiences();
} else {
timer = setTimeout( try_brightcove, 100 );
}
}
})(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,21 @@
/* global window */
(function() {
var instagramEmbed = function() {
if ( 'undefined' !== typeof window.instgrm && window.instgrm.Embeds && 'function' === typeof window.instgrm.Embeds.process ) {
window.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

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,55 @@
(function($){
$.fn.shuffleQuiz = function() {
var allElems = this.get(),
getRandom = function(max) {
return Math.floor(Math.random() * max);
},
shuffled = $.map(allElems, function(){
var random = getRandom(allElems.length),
randEl = $(allElems[random]).clone(true)[0];
allElems.splice(random, 1);
return randEl;
});
this.each(function(i){
$(this).replaceWith($(shuffled[i]));
});
return $(shuffled);
};
})(jQuery);
jQuery( function( $ ) {
$( '.jetpack-quiz' ).each( function() {
var quiz = $(this);
quiz.find( 'div.jetpack-quiz-answer' ).shuffleQuiz();
quiz.find( 'div[data-correct]' ).removeAttr( 'data-correct' ).data( 'correct', 1 );
quiz.find( 'div.jetpack-quiz-answer:last' ).addClass( 'last' );
});
$( 'div.jetpack-quiz' ).on( 'click', 'div.jetpack-quiz-answer', function() {
var trackid, answer = $( this ),
quiz = answer.closest( 'div.jetpack-quiz' );
if ( quiz.data( 'a8ctraining' ) ) {
new Image().src = '//pixel.wp.com/b.gif?v=wpcom-no-pv&x_trainingchaos-' + quiz.data( 'username' ) + '=' + quiz.data( 'a8ctraining' ) + '&rand=' + Math.random();
quiz.data( 'a8ctraining', false );
quiz.data( 'trackid', false );
}
trackid = quiz.data( 'trackid' );
if ( answer.data( 'correct' ) ) {
answer.addClass( 'correct' );
if ( trackid ) {
new Image().src = '//pixel.wp.com/b.gif?v=wpcom-no-pv&x_quiz-' + trackid + '=correct&rand=' + Math.random();
}
} else {
answer.addClass( 'wrong' );
if ( trackid ) {
new Image().src = '//pixel.wp.com/b.gif?v=wpcom-no-pv&x_quiz-' + trackid + '=wrong&rand=' + Math.random();
}
}
// only track the first answer
quiz.data( 'trackid', false );
});
} );

View File

@@ -0,0 +1,289 @@
// jshint ignore: start
/*
* printThis v1.9.0
* @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
*
* Licensed under the MIT licence:
* http://www.opensource.org/licenses/mit-license.php
*
* (c) Jason Day 2015
*
* Usage:
*
* $("#mySelector").printThis({
* debug: false, * show the iframe for debugging
* importCSS: true, * import page CSS
* importStyle: false, * import style tags
* printContainer: true, * grab outer container as well as the contents of the selector
* loadCSS: "path/to/my.css", * path to additional css file - us an array [] for multiple
* pageTitle: "", * add title to print page
* removeInline: false, * remove all inline styles from print elements
* printDelay: 333, * variable print delay
* header: null, * prefix to html
* footer: null, * postfix to html
* base: false, * preserve the BASE tag, or accept a string for the URL
* formValues: true * preserve input/form values
* canvas: false * copy canvas elements (experimental)
* doctypeString: '...' * enter a different doctype for older markup
* });
*
* 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 iframeSrc = "javascript:document.write(\"<head><script>document.domain=\\\"" + document.domain + "\\\";</s" + "cript></head><body></body>\")";
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() {
// Add doctype to fix the style difference between printing and render
function setDocType($iframe,doctype){
var win, doc;
win = $iframe.get(0);
win = win.contentWindow || win.contentDocument || win;
doc = win.document || win.contentDocument || win;
doc.open();
doc.write(doctype);
doc.close();
}
if(opt.doctypeString){
setDocType($iframe,opt.doctypeString);
}
var $doc = $iframe.contents(),
$head = $doc.find("head"),
$body = $doc.find("body"),
$base = $('base'),
baseURL;
// add base tag to ensure elements use the parent domain
if (opt.base === true && $base.length > 0) {
// take the base tag from the original page
baseURL = $base.attr('href');
} else if (typeof opt.base === 'string') {
// An exact base string is provided
baseURL = opt.base;
} else {
// Use the page URL as the base
baseURL = document.location.protocol + '//' + document.location.host;
}
$head.append('<base href="' + baseURL + '">');
// import page stylesheets
if (opt.importCSS) $("link[rel=stylesheet]").each(function() {
var href = $(this).attr("href");
if (href) {
var media = $(this).attr("media") || "all";
$head.append("<link type='text/css' rel='stylesheet' href='" + href + "' media='" + media + "'>");
}
});
// import style tags
if (opt.importStyle) $("style").each(function() {
$(this).clone().appendTo($head);
});
// add title of the page
if (opt.pageTitle) $head.append("<title>" + opt.pageTitle + "</title>");
// import additional stylesheet(s)
if (opt.loadCSS) {
if( $.isArray(opt.loadCSS)) {
jQuery.each(opt.loadCSS, function(index, value) {
$head.append("<link type='text/css' rel='stylesheet' href='" + this + "'>");
});
} else {
$head.append("<link type='text/css' rel='stylesheet' href='" + opt.loadCSS + "'>");
}
}
// print header
if (opt.header) $body.append(opt.header);
if (opt.canvas) {
// add canvas data-ids for easy access after the cloning.
var canvasId = 0;
$element.find('canvas').each(function(){
$(this).attr('data-printthis', canvasId++);
});
}
// grab $.selector as container
if (opt.printContainer) $body.append($element.outer());
// otherwise just print interior elements of container
else $element.each(function() {
$body.append($(this).html());
});
if (opt.canvas) {
// Re-draw new canvases by referencing the originals
$body.find('canvas').each(function(){
var cid = $(this).data('printthis'),
$src = $('[data-printthis="' + cid + '"]');
this.getContext('2d').drawImage($src[0], 0, 0);
// Remove the mark-up from the original
$src.removeData('printthis');
});
}
// capture form/field values
if (opt.formValues) {
// loop through inputs
var $input = $element.find('input');
if ($input.length) {
$input.each(function() {
var $this = $(this),
$name = $(this).attr('name'),
$checker = $this.is(':checkbox') || $this.is(':radio'),
$iframeInput = $doc.find('input[name="' + $name + '"]'),
$value = $this.val();
// order matters here
if (!$checker) {
$iframeInput.val($value);
} else if ($this.is(':checked')) {
if ($this.is(':checkbox')) {
$iframeInput.attr('checked', 'checked');
} else if ($this.is(':radio')) {
$doc.find('input[name="' + $name + '"][value="' + $value + '"]').attr('checked', 'checked');
}
}
});
}
// loop through selects
var $select = $element.find('select');
if ($select.length) {
$select.each(function() {
var $this = $(this),
$name = $(this).attr('name'),
$value = $this.val();
$doc.find('select[name="' + $name + '"]').val($value);
});
}
// loop through textareas
var $textarea = $element.find('textarea');
if ($textarea.length) {
$textarea.each(function() {
var $this = $(this),
$name = $(this).attr('name'),
$value = $this.val();
$doc.find('textarea[name="' + $name + '"]').val($value);
});
}
} // end capture form/field values
// 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", "");
}
}
// print "footer"
if (opt.footer) $body.append(opt.footer);
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();
$head.append("<script> window.print(); </s" + "cript>");
} else {
// proper method
if (document.queryCommandSupported("print")) {
$iframe[0].contentWindow.document.execCommand("print", false, null);
} else {
$iframe[0].contentWindow.focus();
$iframe[0].contentWindow.print();
}
}
// 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: true, // import parent page css
importStyle: false, // import style tags
printContainer: true, // print outer container/$.selector
loadCSS: "", // load an additional css file - load multiple stylesheets with an array []
pageTitle: "", // add title to print page
removeInline: false, // remove all inline styles
printDelay: 333, // variable print delay
header: null, // prefix to html
footer: null, // postfix to html
formValues: true, // preserve input/form values
canvas: false, // Copy canvas content (experimental)
base: false, // preserve the BASE tag, or accept a string for the URL
doctypeString: '<!DOCTYPE html>' // html doctype
};
// $.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,194 @@
/* 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','https://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,
timeout: jetpackSlideshowSettings.speed,
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,78 @@
<?php
/**
* Kickstarter shortcode
*
* Usage:
* [kickstarter url="https://www.kickstarter.com/projects/peaktoplateau/yak-wool-baselayers-from-tibet-to-the-world" width="480" height=""]
*/
add_shortcode( 'kickstarter', 'jetpack_kickstarter_shortcode' );
add_filter( 'pre_kses', 'jetpack_kickstarter_embed_to_shortcode' );
/**
* Parse shortcode arguments and render its output.
*
* @since 4.5.0
*
* @param array $atts Shortcode parameters.
*
* @return string
*/
function jetpack_kickstarter_shortcode( $atts ) {
if ( empty( $atts['url'] ) ) {
return '';
}
$url = esc_url_raw( $atts['url'] );
if ( ! preg_match( '#^(www\.)?kickstarter\.com$#i', parse_url( $url, PHP_URL_HOST ) ) ) {
return '<!-- Invalid Kickstarter URL -->';
}
global $wp_embed;
return $wp_embed->shortcode( $atts, $url );
}
/**
* Converts Kickstarter iframe embeds to a shortcode.
*
* EG: <iframe width="480" height="360" src="http://www.kickstarter.com/projects/deweymac/dewey-mac-kid-detective-book-make-diy-and-stem-spy/widget/video.html" frameborder="0" scrolling="no"> </iframe>
*
* @since 4.5.0
*
* @param string $content Entry content that possibly includes a Kickstarter embed.
*
* @return string
*/
function jetpack_kickstarter_embed_to_shortcode( $content ) {
if ( ! is_string( $content ) || false === stripos( $content, 'www.kickstarter.com/projects' ) ) {
return $content;
}
$regexp = '!<iframe((?:\s+\w+=[\'"][^\'"]*[\'"])*)\s+src=[\'"](http://www\.kickstarter\.com/projects/[^/]+/[^/]+)/[^\'"]+[\'"]((?:\s+\w+=[\'"][^\'"]*[\'"])*)>[\s]*</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 ) {
$url = esc_url( $match[2] );
$params = $match[1] . $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;
$shortcode = '[kickstarter url=' . $url . ( ( ! empty( $width ) ) ? " width=$width" : '' ) . ']';
$content = str_replace( $match[0], $shortcode, $content );
}
}
return $content;
}

View File

@@ -0,0 +1,296 @@
<?php
/**
* Lytro.com Short Code
*
* Format:
* [lytro photo='202' show_arrow='true' show_border='true' show_first_time_user='true' allow_full_view='true']
* [lytro username='lytroweb' photo='431119']
*
* Legend:
* username: the lytro.com username for newer embed format
* photo: the ID or the URL of the photo on lytro.com
* show_arrow: set to false to force-hide the menu in the lower right (not used in v2)
* show_border: set to true to force-show the border
* show_first_time_user: set to false to force-disable the first-time user experience (not used in v2)
* allow_full_view: set to true to allow an external site to have a full-zoom mode (not used in v2)
* enable_help: set to false to hide the question mark/help popup
*
* Output:
* <iframe width="400" height="415" src="https://www.lytro.com/living-pictures/202/embed?showArrow=true&showBorder=true&showFTU=true" frameborder="0" allowfullscreen></iframe>
* <iframe width="400" height="415" src="http://pictures.lytro.com/lytroweb/pictures/431119/embed" frameborder="0" allowfullscreen="" scrolling="no"></iframe>
*/
/**
* Lytro.com Short Code Attributes Definition
*
* This helper function returns an array all available
* shortcode attributes, their validation method, default
* value and more.
*
* Keys:
* validate: a callable function or regular expression used to validate the input
* default: default value for shortcode attribute
* query_arg: the related lytro query argument name
*
* @since 4.5.0
*/
function jetpack_lytro_shortcode_attributes() {
return array(
'username' => array(
'default' => '',
),
'photo' => array( // could be ID or URL, validated separately
'default' => 0,
),
'width' => array(
'validate' => '#^\d+$#',
'default' => 400,
),
'height' => array(
'validate' => '#^\d+$#',
'default' => 415,
),
'show_arrow' => array(
'query_arg' => 'showArrow',
'validate' => '#^(true|false)$#',
'default' => 'true',
),
'show_border' => array(
'query_arg' => 'showBorder',
'validate' => '#^(true|false)$#',
'default' => 'true',
),
'show_first_time_user' => array(
'query_arg' => 'showFTU',
'validate' => '#^(true|false)$#',
'default' => 'true',
),
'allow_full_view' => array(
'query_arg' => 'allowFullView',
'validate' => '#^(true|false)$#',
'default' => 'true',
),
'enable_help' => array(
'query_arg' => 'enableHelp',
'validate' => '#^(true|false)$#',
'default' => 'true',
),
'enable_attribution' => array(
'query_arg' => 'enableAttribution',
'validate' => '#^(true|false)$#',
'default' => 'true',
),
'enable_logo' => array(
'query_arg' => 'enableLogo',
'validate' => '#^(true|false)$#',
'default' => 'true',
),
'enable_fullscreen' => array(
'query_arg' => 'enableFullscreen',
'validate' => '#^(true|false)$#',
'default' => 'true',
),
'enable_play' => array(
'query_arg' => 'enablePlay',
'validate' => '#^(true|false)$#',
'default' => 'true',
),
'bg_color' => array(
'query_arg' => 'bgColor',
'validate' => '/^#(?:[0-9a-fA-F]{3}){1,2}$/',
'default' => '',
),
);
}
/**
* Lytro.com Shortcode
*
* Allows embedding Lytro "living pictures" using [lytro photo="200"] or
* [lytro photo="http://www.lytro.com/..."]. Additional attributes
* like show_border, show_arrow, etc have priority over the ones supplied
* in the URL.
*
* @since 4.5.0
*
* @param array $atts Shortcode attributes
*
* @uses jetpack_lytro_shortcode_attributes()
* @return string Embed HTML or a <!-- commented out error -->
*/
function jetpack_lytro_shortcode_handler( $atts ) {
$defaults = array();
$attributes = jetpack_lytro_shortcode_attributes();
foreach ( $attributes as $key => $attribute ) {
if ( isset( $attribute['default'] ) ) {
$defaults[$key] = $attribute['default'];
}
}
$atts = shortcode_atts( $defaults, $atts );
// There has to at least be a photo attribute.
if ( empty( $atts['photo'] ) ) {
return '<!-- Lytro Shortcode Error: No Photo ID/URL -->';
}
// The photo attribute might be a URL
if ( ! is_numeric( $atts['photo'] ) ) {
$atts = array_merge( $atts, jetpack_lytro_shortcode_url_to_atts( $atts['photo'] ) );
}
// Validate all attributes by callable function or regular expression.
foreach ( $atts as $key => $value ) {
$attribute = $attributes[$key];
if ( isset( $attribute['validate'] ) ) {
$validate = $attribute['validate'];
$valid = is_callable( $validate ) ? call_user_func( $validate, $value ) : preg_match( $validate, $value );
if ( ! $valid ) {
$atts[$key] = $defaults[$key];
}
}
}
// The photo attribute might have changed, make sure it's still valid.
if ( ! is_numeric( $atts['photo'] ) || ! $atts['photo'] ) {
return '<!-- Lytro Shortcode Error: Invalid Photo ID/URL -->';
}
// Build a query which is then appended to the iframe src.
$query_args = array();
foreach ( $atts as $key => $value ) {
$attribute = $attributes[$key];
if ( isset( $attribute['query_arg'] ) && ! empty( $attribute['query_arg'] ) && ! empty( $value ) ) {
$query_args[$attribute['query_arg']] = $value;
}
}
if ( ! empty( $atts['username'] ) ) {
$src = sprintf( 'https://pictures.lytro.com/%s/pictures/%d/embed', $atts['username'], $atts['photo'] );
} else {
$src = sprintf( 'https://pictures.lytro.com/pictures/%d/embed', $atts['photo'] );
}
// Add query args and build the iframe.
$src = add_query_arg( $query_args, $src );
return '<iframe width="' . esc_attr( $atts['width'] ) . '" height="' . esc_attr( $atts['height'] ) . '" src="' . esc_url( $src ) . '" frameborder="0" allowfullscreen scrolling="no"></iframe>';
}
add_shortcode( 'lytro', 'jetpack_lytro_shortcode_handler' );
/**
* Lytro Shortcode URL to Shortcode Attributes
*
* This helper function parses a Lytro.com URL
* and returns an attributes array.
*
* @since 4.5.0
*
* @uses jetpack_lytro_shortcode_attributes()
*/
function jetpack_lytro_shortcode_url_to_atts( $url ) {
$attributes = jetpack_lytro_shortcode_attributes();
$atts = array();
$url = str_replace( '&amp;', '&', $url );
if ( preg_match( '#^https?://(www\.)?lytro\.com/living-pictures/([0-9]+)/?#i', $url, $matches ) ) {
$atts['photo'] = $matches[2];
} elseif ( preg_match( '#^https?://(www\.)?pictures\.lytro\.com/([^/]+)/pictures/([0-9]+)/?#i', $url, $matches ) ) {
$atts['username'] = $matches[2];
$atts['photo'] = $matches[3];
}
$url = parse_url( $url );
if ( isset( $url['query'] ) ) {
parse_str( $url['query'], $qargs );
// Get the attributes with query_args and fill in the $atts array
foreach ( $attributes as $key => $attribute ) {
if ( isset( $attribute['query_arg'] ) && in_array( $attribute['query_arg'], array_keys( $qargs ) ) ) {
$atts[$key] = $qargs[$attribute['query_arg']];
}
}
}
return $atts;
}
/**
* Lytro Shortcode Reversal
*
* Example
* <iframe width="400" height="415" src="https://www.lytro.com/living-pictures/202/embed?showBorder=true" frameborder="0" allowfullscreen></iframe>
* <iframe width="400" height="415" src="http://pictures.lytro.com/lytroweb/pictures/431128/embed" frameborder="0" allowfullscreen="" scrolling="no"></iframe>
*
* Converts to:
* [lytro photo="202" show_border="true" width="400" height="415"]
*
* @since 4.5.0
*
* @uses jetpack_lytro_shortcode_url_to_atts()
* @uses wpcom_shortcodereverse_parseattr()
*/
function wpcom_shortcodereverse_lytro( $atts ) {
$atts = wpcom_shortcodereverse_parseattr( $atts );
$shortcode_atts = array();
// Grab the src URL and convert to shortcode attributes
if ( $atts['src'] ) {
$shortcode_atts = jetpack_lytro_shortcode_url_to_atts( $atts['src'] );
}
// Width and height too
if ( $atts['width'] ) {
$shortcode_atts['width'] = $atts['width'];
}
if ( $atts['height'] ) {
$shortcode_atts['height'] = $atts['height'];
}
// Generate the shortcode.
$shortcode = '';
foreach ( $shortcode_atts as $key => $value ) {
$shortcode .= " $key='" . esc_attr( $value ) . "'";
}
$shortcode = "[lytro {$shortcode}]";
return $shortcode;
}
Filter_Embedded_HTML_Objects::register( '#^https?://(www\.)?lytro\.com/living-pictures/#i', 'wpcom_shortcodereverse_lytro', true );
Filter_Embedded_HTML_Objects::register( '#^https?://(www\.)?pictures\.lytro\.com/([^/]+)/pictures/([0-9]+)/embed#i', 'wpcom_shortcodereverse_lytro', true );
/**
* Register Embed Handler
*
* Registers a WordPress Embed handler to allow embedding
* Lytro images by publishing the Lytro URL on a line by itself.
*
* @since 4.5.0
*
* @uses wp_embed_register_handler
*/
function jetpack_lytro_register_embed_handler() {
wp_embed_register_handler( 'lytro', '#^https?://(www\.)?lytro\.com/living-pictures/([0-9]+)/?#i', 'jetpack_lytro_embed_handler' );
wp_embed_register_handler( 'lytro-v2', '#^https?://(www\.)?pictures\.lytro\.com/([^/]+)/pictures/([0-9]+)/?#i', 'jetpack_lytro_embed_handler' );
}
add_action( 'init', 'jetpack_lytro_register_embed_handler' );
/**
* Lytro Embed Handler
*
* The embed handler function which converts a Lytro URL
* on a line by itself into an embedded Lytro image.
*
* @since 4.5.0
*
* @see jetpack_lytro_register_embed_handler
* @uses jetpack_lytro_shortcode_url_to_atts
* @uses jetpack_lytro_shortcode_handler
*/
function jetpack_lytro_embed_handler( $matches, $attr, $url, $rawattr ) {
return jetpack_lytro_shortcode_handler( jetpack_lytro_shortcode_url_to_atts( $url ) );
}

View File

@@ -0,0 +1,204 @@
<?php
/**
* MailChimp Subscriber Popup Form shortcode
*
* Example:
* [mailchimp_subscriber_popup baseUrl="mc.us11.list-manage.com" uuid="1ca7856462585a934b8674c71" lid="2d24f1898b"]
*
* Embed code example:
* <script type="text/javascript" src="//downloads.mailchimp.com/js/signup-forms/popup/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script><script type="text/javascript">require(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.us11.list-manage.com","uuid":"1ca7856462585a934b8674c71","lid":"2d24f1898b"}) })</script>
*
*/
/**
* Register [mailchimp_subscriber_popup] shortcode and add a filter to 'pre_kses' queue to reverse MailChimp embed to shortcode.
*
* @since 4.5.0
*/
function jetpack_mailchimp_subscriber_popup() {
add_shortcode( 'mailchimp_subscriber_popup', array(
'MailChimp_Subscriber_Popup',
'shortcode'
) );
add_filter( 'pre_kses', array(
'MailChimp_Subscriber_Popup',
'reversal'
) );
}
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
add_action( 'init', 'jetpack_mailchimp_subscriber_popup' );
} else {
jetpack_mailchimp_subscriber_popup();
}
/**
* Class MailChimp_Subscriber_Popup
*
* @since 4.5.0
*/
class MailChimp_Subscriber_Popup {
/**
* Regular expressions to reverse script tags to shortcodes.
*
* @var array
*/
static $reversal_regexes = array(
/* raw examplejs */
'/<script type="text\/javascript" src="(https?:)?\/\/downloads\.mailchimp\.com\/js\/signup-forms\/popup\/embed\.js" data-dojo-config="([^"]*?)"><\/script><script type="text\/javascript">require\(\["mojo\/signup-forms\/Loader"\]\, function\(L\) { L\.start\({([^}]*?)}\) }\)<\/script>/s',
/* visual editor */
'/&lt;script type="text\/javascript" src="(https?:)?\/\/downloads\.mailchimp\.com\/js\/signup-forms\/popup\/embed\.js" data-dojo-config="([^"]*?)"&gt;&lt;\/script&gt;&lt;script type="text\/javascript"&gt;require\(\["mojo\/signup-forms\/Loader"]\, function\(L\) { L\.start\({([^}]*?)}\) }\)&lt;\/script&gt;/s',
);
/**
* Allowed configuration attributes. Used in reversal when checking allowed attributes.
*
* @var array
*/
static $allowed_config = array(
'usePlainJson' => 'true',
'isDebug' => 'false',
);
/**
* Allowed JS variables. Used in reversal to whitelist variables.
*
* @var array
*/
static $allowed_js_vars = array(
'baseUrl',
'uuid',
'lid',
);
/**
* Runs the whole reversal.
*
* @since 4.5.0
*
* @param string $content Post Content
*
* @return string Content with embeds replaced
*/
static function reversal( $content ) {
// Bail without the js src
if ( ! is_string( $content ) || false === stripos( $content, 'downloads.mailchimp.com/js/signup-forms/popup/embed.js' ) ) {
return $content;
}
require_once( ABSPATH . WPINC . '/class-json.php' );
$wp_json = new Services_JSON();
// loop through our rules and find valid embeds
foreach ( self::$reversal_regexes as $regex ) {
if ( ! preg_match_all( $regex, $content, $matches ) ) {
continue;
}
foreach ( $matches[3] as $index => $js_vars ) {
// the regex rule for a specific embed
$replace_regex = sprintf( '#\s*%s\s*#', preg_quote( $matches[0][$index], '#' ) );
$attrs = $wp_json->decode( '{' . $js_vars . '}' );
if ( $matches[2][$index] ) {
$config_attrs = $wp_json->decode( '{' . $matches[2][$index] . '}' );
foreach ( $config_attrs as $key => $value ) {
$attrs->$key = ( 1 == $value ) ? 'true' : 'false';
}
}
$shortcode = self::build_shortcode_from_reversal_attrs( $attrs );
$content = preg_replace( $replace_regex, "\n\n$shortcode\n\n", $content );
/** This action is documented in modules/widgets/social-media-icons.php */
do_action( 'jetpack_bump_stats_extras', 'html_to_shortcode', 'mailchimp_subscriber_popup' );
}
}
return $content;
}
/**
* Builds the actual shortcode based on passed in attributes.
*
* @since 4.5.0
*
* @param array $attrs A valid list of attributes (gets matched against self::$allowed_config and self::$allowed_js_vars)
*
* @return string
*/
static function build_shortcode_from_reversal_attrs( $attrs ) {
$shortcode = '[mailchimp_subscriber_popup ';
foreach ( $attrs as $key => $value ) {
// skip unsupported keys
if ( ! in_array( $key, array_keys( self::$allowed_config ) ) && ! in_array( $key, self::$allowed_js_vars ) ) {
continue;
}
$value = esc_attr( $value );
$shortcode .= "$key='$value' ";
}
return trim( $shortcode ) . ']';
}
/**
* Parses the shortcode back out to embedded information.
*
* @since 4.5.0
*
* @param array $lcase_attrs
*
* @return string
*/
static function shortcode( $lcase_attrs ) {
static $displayed_once = false;
// Limit to one form per page load
if ( $displayed_once ) {
return '';
}
if ( empty( $lcase_attrs ) ) {
return '<!-- Missing MailChimp baseUrl, uuid or lid -->';
}
$defaults = array_fill_keys( self::$allowed_js_vars, '' );
$defaults = array_merge( $defaults, self::$allowed_config );
// Convert $attrs back to proper casing since they come through in all lowercase
$attrs = array();
foreach ( $defaults as $key => $value ) {
if ( array_key_exists( strtolower( $key ), $lcase_attrs ) ) {
$attrs[ $key ] = $lcase_attrs[ strtolower( $key ) ];
}
}
$attrs = array_map( 'esc_js', array_filter( shortcode_atts( $defaults, $attrs ) ) );
// Split config & js vars
$config_vars = $js_vars = array();
foreach ( $attrs as $key => $value ) {
if ( in_array( $key, self::$allowed_js_vars ) ) {
$js_vars[ $key ] = $value;
} else {
$config_vars[] = "$key: $value";
}
}
// If one of these parameters is missing we can't render the form so exist.
if ( empty( $js_vars['baseUrl'] ) || empty( $js_vars['uuid'] ) || empty( $js_vars['lid'] ) ) {
return '<!-- Missing MailChimp baseUrl, uuid or lid -->';
}
/** This action is already documented in modules/widgets/gravatar-profile.php */
do_action( 'jetpack_stats_extra', 'mailchimp_subscriber_popup', 'view' );
$displayed_once = true;
return "\n\n" . '<script type="text/javascript" data-dojo-config="' . esc_attr( implode( ', ', $config_vars ) ) . '">jQuery.getScript( "//downloads.mailchimp.com/js/signup-forms/popup/embed.js", function( data, textStatus, jqxhr ) { require(["mojo/signup-forms/Loader"], function(L) { L.start(' . wp_json_encode( $js_vars ) . ') }); window.define.amd = undefined; } );</script>' . "\n\n";
}
}

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,74 @@
<?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]
* [mixcloud http://www.mixcloud.com/mat/playlists/classics/ width=660 height=208 hide_cover=1 hide_tracklist=1]
*/
// 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', 'https://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\\/)[\\w-\\/]+$)|(^[\\w-\\/]+$)/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 -->';
}
$mixcloud_url = 'https://mixcloud.com/' . $resource_id;
$atts = shortcode_atts(
array(
'width' => false,
'height' => false,
'color' => false,
'light' => false,
'dark' => false,
'hide_tracklist' => false,
'hide_cover' => false,
'mini' => false,
'hide_followers' => false,
'hide_artwork' => false,
), $atts
);
// remove falsey values
$atts = array_filter( $atts );
$query_args = array( 'url' => $mixcloud_url );
$query_args = array_merge( $query_args, $atts );
$url = add_query_arg( urlencode_deep( $query_args ), 'https://www.mixcloud.com/oembed/' );
$mixcloud_response = wp_remote_get( $url, array( 'redirection' => 0 ) );
if ( is_wp_error( $mixcloud_response ) || 200 !== $mixcloud_response['response']['code'] || empty( $mixcloud_response['body'] ) ) {
return '<!-- mixcloud error: invalid mixcloud resource -->';
}
$response_body = json_decode( $mixcloud_response['body'] );
return $response_body->html;
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* Pinterest embeds
*
* Based on "Board Widget" example here: http://business.pinterest.com/widget-builder/#code
*/
// Example URL: http://pinterest.com/pinterest/pin-pets/
// Second Example URL: https://uk.pinterest.com/annsawesomepins/travel/
wp_embed_register_handler(
'pinterest',
'#'
. 'https?://'
. '(?:www\.)?'
. '(?:[a-z]{2}\.)?'
. 'pinterest\.[a-z.]+/'
. '([^/]+)'
. '(/[^/]+)?'
. '#',
'pinterest_embed_handler'
);
function pinterest_embed_handler( $matches, $attr, $url ) {
// Pinterest's JS handles making the embed
$script_src = '//assets.pinterest.com/js/pinit.js';
wp_enqueue_script( 'pinterest-embed', $script_src, array(), false, true );
$path = parse_url( $url, PHP_URL_PATH );
if ( 0 === strpos( $path, '/pin/' ) ) {
$embed_type = 'embedPin';
} elseif ( preg_match( '#^/([^/]+)/?$#', $path ) ) {
$embed_type = 'embedUser';
} elseif ( preg_match( '#^/([^/]+)/([^/]+)/?$#', $path ) ) {
$embed_type = 'embedBoard';
} else {
if ( current_user_can( 'edit_posts' ) ) {
return __( 'Sorry, that Pinterest URL was not recognized.', 'jetpack' );
}
return;
}
$return = sprintf( '<a data-pin-do="%s" href="%s"></a>', esc_attr( $embed_type ), esc_url( $url ) );
// If we're generating an embed view for the WordPress Admin via ajax...
if ( doing_action( 'wp_ajax_parse-embed' ) ) {
$return .= sprintf( '<script src="%s"></script>', esc_url( $script_src ) );
}
return $return;
}

View File

@@ -0,0 +1,579 @@
<?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" async 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 ( ! is_string( $content ) || 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" async 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" async 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' async src='{$rating_js_file}'></script>";
}
if ( isset( self::$scripts['poll'] ) ) {
foreach( self::$scripts['poll'] as $poll ) {
$script .= "<script type='text/javascript' charset='UTF-8' async 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.async = true;
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' async 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,461 @@
<?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() {
$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',
Jetpack::get_file_url_for_environment( '_inc/build/shortcodes/js/jmpress.min.js', 'modules/shortcodes/js/jmpress.js' ),
array( 'jquery' ),
'0.4.5',
true
);
wp_enqueue_script(
'presentations',
Jetpack::get_file_url_for_environment( '_inc/build/shortcodes/js/main.min.js', 'modules/shortcodes/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,298 @@
<?php
/**
* Quiz shortcode.
*
* Usage:
*
* [quiz]
* [question]What's the right answer?[/question]
* [wrong]This one?[explanation]Nope[/explanation][/wrong]
* [answer]Yes, this is the one![explanation]Yay![/explanation][/answer]
* [wrong]Maybe this one[explanation]Keep trying[/explanation][/wrong]
* [wrong]How about this one?[explanation]Try again[/explanation][/wrong]
* [/quiz]
*/
class Quiz_Shortcode {
/**
* Parameters admitted by [quiz] shortcode.
*
* @since 4.5.0
*
* @var array
*/
private static $quiz_params = array();
/**
* Whether the scripts were enqueued.
*
* @since 4.5.0
*
* @var bool
*/
private static $scripts_enqueued = false;
/**
* In a8c training, store user currently logged in.
*
* @since 4.5.0
*
* @var null
*/
private static $username = null;
/**
* Whether the noscript tag was already printed.
*
* @since 4.5.0
*
* @var bool
*/
private static $noscript_info_printed = false;
/**
* Whether JavaScript is available.
*
* @since 4.5.0
*
* @var null
*/
private static $javascript_unavailable = null;
/**
* Register all shortcodes.
*
* @since 4.5.0
*/
public static function init() {
add_shortcode( 'quiz', array( __CLASS__, 'shortcode' ) );
add_shortcode( 'question', array( __CLASS__, 'question_shortcode' ) );
add_shortcode( 'answer', array( __CLASS__, 'answer_shortcode' ) );
add_shortcode( 'wrong', array( __CLASS__, 'wrong_shortcode' ) );
add_shortcode( 'explanation', array( __CLASS__, 'explanation_shortcode' ) );
}
/**
* Enqueue assets needed by the quiz,
*
* @since 4.5.0
*/
private static function enqueue_scripts() {
wp_enqueue_style( 'quiz', plugins_url( 'css/quiz.css', __FILE__ ) );
wp_enqueue_script(
'quiz',
Jetpack::get_file_url_for_environment( '_inc/build/shortcodes/js/quiz.min.js', 'modules/shortcodes/js/quiz.js' ),
array( 'jquery' ),
null,
true
);
}
/**
* Check if this is a feed and thus JS is unavailable.
*
* @since 4.5.0
*
* @return bool|null
*/
private static function is_javascript_unavailable() {
if ( ! is_null( self::$javascript_unavailable ) ) {
return self::$javascript_unavailable;
}
if ( is_feed() ) {
return self::$javascript_unavailable = true;
}
return self::$javascript_unavailable = false;
}
/**
* Display message when JS is not available.
*
* @since 4.5.0
*
* @return string
*/
private static function noscript_info() {
if ( self::$noscript_info_printed ) {
return '';
}
self::$noscript_info_printed = true;
return '<noscript><div><i>' . esc_html__( 'Please view this post in your web browser to complete the quiz.', 'jetpack' ) . '</i></div></noscript>';
}
/**
* Check if we're in WordPress.com.
*
* @since 4.5.0
*
* @return bool
*/
public static function is_wpcom() {
return defined( 'IS_WPCOM' ) && IS_WPCOM;
}
/**
* Parse shortcode arguments and render its output.
*
* @since 4.5.0
*
* @param array $atts Shortcode parameters.
* @param string $content Content enclosed by shortcode tags.
*
* @return string
*/
public static function shortcode( $atts, $content = null ) {
// There's nothing to do if there's nothing enclosed.
if ( null == $content ) {
return '';
}
$id = '';
if ( self::is_javascript_unavailable() ) {
// in an e-mail print the question and the info sentence once per question, too
self::$noscript_info_printed = false;
} else {
if ( ! self::$scripts_enqueued ) {
// lazy enqueue cannot use the wp_enqueue_scripts action anymore
self::enqueue_scripts();
self::$scripts_enqueued = true;
}
$default_atts = self::is_wpcom()
? array(
'trackid' => '',
'a8ctraining' => '',
)
: array(
'trackid' => '',
);
self::$quiz_params = shortcode_atts( $default_atts, $atts );
if ( ! empty( self::$quiz_params[ 'trackid' ] ) ) {
$id .= ' data-trackid="' . esc_attr( self::$quiz_params[ 'trackid' ] ) . '"';
}
if ( self::is_wpcom() && ! empty( self::$quiz_params[ 'a8ctraining' ] ) ) {
if ( is_null( self::$username ) ) {
self::$username = wp_get_current_user()->user_login;
}
$id .= ' data-a8ctraining="'. esc_attr( self::$quiz_params[ 'a8ctraining' ] ) . '" data-username="' . esc_attr( self::$username ) . '"';
}
}
$quiz = self::do_shortcode( $content );
return '<div class="jetpack-quiz quiz"' . $id . '>' . $quiz . '</div>';
}
/**
* Strip line breaks, restrict allowed HTML to a few whitelisted tags and execute nested shortcodes.
*
* @since 4.5.0
*
* @param string $content
*
* @return mixed|string
*/
private static function do_shortcode( $content ) {
// strip autoinserted line breaks
$content = preg_replace( '#(<(?:br /|/?p)>\n?)*(\[/?[a-z]+\])(<(?:br /|/?p)>\n?)*#', '$2', $content );
// Add internal parameter so it's only rendered when it has it
$content = preg_replace( '/\[(question|answer|wrong|explanation)\]/i', '[$1 quiz_item="true"]', $content );
$content = do_shortcode( $content );
$content = wp_kses( $content, array(
'tt' => array(),
'pre' => array(),
'strong' => array(),
'i' => array(),
'br' => array(),
'img' => array( 'src' => true),
'div' => array( 'class' => true, 'data-correct' => 1, 'data-track-id' => 1, 'data-a8ctraining' => 1, 'data-username' => 1 ),
) );
return $content;
}
/**
* Render question.
*
* @since 4.5.0
*
* @param array $atts
* @param null $content
*
* @return string
*/
public static function question_shortcode( $atts, $content = null ) {
return isset( $atts['quiz_item'] )
? '<div class="jetpack-quiz-question question">' . self::do_shortcode( $content ) . '</div>'
: '';
}
/**
* Render correct answer.
*
* @since 4.5.0
*
* @param array $atts
* @param null $content
*
* @return string
*/
public static function answer_shortcode( $atts, $content = null ) {
if ( self::is_javascript_unavailable() ) {
return self::noscript_info();
}
return isset( $atts['quiz_item'] )
? '<div class="jetpack-quiz-answer answer" data-correct="1">' . self::do_shortcode( $content ) . '</div>'
: '';
}
/**
* Render wrong response.
*
* @since 4.5.0
*
* @param array $atts
* @param null $content
*
* @return string
*/
public static function wrong_shortcode( $atts, $content = null ) {
if ( self::is_javascript_unavailable() ) {
return self::noscript_info();
}
return isset( $atts['quiz_item'] )
? '<div class="jetpack-quiz-answer answer">' . self::do_shortcode( $content ) . '</div>'
: '';
}
/**
* Render explanation for wrong or right answer.
*
* @since 4.5.0
*
* @param array $atts
* @param null $content
*
* @return string
*/
public static function explanation_shortcode( $atts, $content = null ) {
if ( self::is_javascript_unavailable() ) {
return self::noscript_info();
}
return isset( $atts['quiz_item'] )
? '<div class="jetpack-quiz-explanation explanation">' . self::do_shortcode( $content ) . '</div>'
: '';
}
}
Quiz_Shortcode::init();

View File

@@ -0,0 +1,501 @@
<?php
/**
* Embed recipe 'cards' in post, with basic styling and print functionality
*
* To Do
* - defaults settings
* - basic styles/themecolor styles
* - validation/sanitization
* - print styles
*/
class Jetpack_Recipes {
private $scripts_and_style_included = false;
function __construct() {
add_action( 'init', array( $this, 'action_init' ) );
add_filter( 'wp_kses_allowed_html', array( $this, 'add_recipes_kses_rules' ), 10, 2 );
}
/**
* Add Schema-specific attributes to our allowed tags in wp_kses,
* so we can have better Schema.org compliance.
*
* @param array $allowedtags Array of allowed HTML tags in recipes.
* @param array $context Context to judge allowed tags by.
*/
function add_recipes_kses_rules( $allowedtags, $context ) {
if ( in_array( $context, array( '', 'post', 'data' ) ) ) :
// Create an array of all the tags we'd like to add the itemprop attribute to.
$tags = array( 'li', 'ol', 'ul', 'img', 'p', 'h3', 'time' );
foreach ( $tags as $tag ) {
$allowedtags = $this->add_kses_rule(
$allowedtags,
$tag,
array(
'class' => array(),
'itemprop' => array(),
'datetime' => array(),
)
);
}
// Allow itemscope and itemtype for divs.
$allowedtags = $this->add_kses_rule(
$allowedtags,
'div',
array(
'class' => array(),
'itemscope' => array(),
'itemtype' => array(),
)
);
endif;
return $allowedtags;
}
/**
* Function to add a new property rule to our kses array.
* Used by add_recipe_kses_rules() above.
*
* @param array $all_tags Array of allowed HTML tags in recipes.
* @param string $tag New HTML tag to add to the array of allowed HTML.
* @param array $rules Array of allowed attributes for that HTML tag.
*/
private function add_kses_rule( $all_tags, $tag, $rules ) {
// If the tag doesn't already exist, add it.
if ( ! isset( $all_tags[ $tag ] ) ) {
$all_tags[ $tag ] = array();
}
// Merge the new tags with existing tags.
$all_tags[ $tag ] = array_merge( $all_tags[ $tag ], $rules );
return $all_tags;
}
/**
* Register our shortcode and enqueue necessary files.
*/
function action_init() {
// Enqueue styles if [recipe] exists.
add_action( 'wp_head', array( $this, 'add_scripts' ), 1 );
// Render [recipe], along with other shortcodes that can be nested within.
add_shortcode( 'recipe', array( $this, 'recipe_shortcode' ) );
add_shortcode( 'recipe-notes', array( $this, 'recipe_notes_shortcode' ) );
add_shortcode( 'recipe-ingredients', array( $this, 'recipe_ingredients_shortcode' ) );
add_shortcode( 'recipe-directions', array( $this, 'recipe_directions_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;
}
wp_enqueue_style( 'jetpack-recipes-style', plugins_url( '/css/recipes.css', __FILE__ ), array(), '20130919' );
wp_style_add_data( 'jetpack-recipes-style', 'rtl', 'replace' );
// add $themecolors-defined styles.
wp_add_inline_style( 'jetpack-recipes-style', self::themecolor_styles() );
wp_enqueue_script(
'jetpack-recipes-printthis',
Jetpack::get_file_url_for_environment( '_inc/build/shortcodes/js/recipes-printthis.min.js', 'modules/shortcodes/js/recipes-printthis.js' ),
array( 'jquery' ),
'20170202'
);
wp_enqueue_script(
'jetpack-recipes-js',
Jetpack::get_file_url_for_environment( '_inc/build/shortcodes/js/recipes.min.js', 'modules/shortcodes/js/recipes.js' ),
array( 'jquery', 'jetpack-recipes-printthis' ),
'20131230'
);
$title_var = wp_title( '|', false, 'right' );
$rtl = is_rtl() ? '-rtl' : '';
$print_css_var = plugins_url( "/css/recipes-print{$rtl}.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.
*
* @param array $atts Array of shortcode attributes.
* @param string $content Post content.
*
* @return string HTML for recipe shortcode.
*/
static function recipe_shortcode( $atts, $content = '' ) {
$atts = shortcode_atts(
array(
'title' => '', // string.
'servings' => '', // intval.
'time' => '', // string.
'difficulty' => '', // string.
'print' => '', // string.
'source' => '', // string.
'sourceurl' => '', // string.
'image' => '', // string.
'description' => '', // string.
), $atts, 'recipe'
);
return self::recipe_shortcode_html( $atts, $content );
}
/**
* The recipe output
*
* @param array $atts Array of shortcode attributes.
* @param string $content Post content.
*
* @return string HTML output
*/
static function recipe_shortcode_html( $atts, $content = '' ) {
$html = '<div class="hrecipe jetpack-recipe" itemscope itemtype="https://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>',
esc_html_x( 'Servings', 'recipe', 'jetpack' ),
esc_html( $atts['servings'] )
);
}
if ( '' !== $atts['time'] ) {
// Get a time that's supported by Schema.org.
$duration = WPCOM_JSON_API_Date::format_duration( $atts['time'] );
// If no duration can be calculated, let's output what the user provided.
if ( empty( $duration ) ) {
$duration = $atts['time'];
}
$html .= sprintf(
'<li class="jetpack-recipe-time">
<time itemprop="totalTime" datetime="%3$s"><strong>%1$s: </strong>%2$s</time>
</li>',
esc_html_x( 'Time', 'recipe', 'jetpack' ),
esc_html( $atts['time'] ),
esc_attr( $duration )
);
}
if ( '' !== $atts['difficulty'] ) {
$html .= sprintf(
'<li class="jetpack-recipe-difficulty"><strong>%1$s: </strong>%2$s</li>',
esc_html_x( 'Difficulty', 'recipe', 'jetpack' ),
esc_html( $atts['difficulty'] )
);
}
if ( '' !== $atts['source'] ) {
$html .= sprintf(
'<li class="jetpack-recipe-source"><strong>%1$s: </strong>',
esc_html_x( 'Source', 'recipe', 'jetpack' )
);
if ( '' !== $atts['sourceurl'] ) :
// Show the link if we have one.
$html .= sprintf(
'<a href="%2$s">%1$s</a>',
esc_html( $atts['source'] ),
esc_url( $atts['sourceurl'] )
);
else :
// Skip the link.
$html .= sprintf(
'%1$s',
esc_html( $atts['source'] )
);
endif;
$html .= '</li>';
}
if ( 'false' !== $atts['print'] ) {
$html .= sprintf(
'<li class="jetpack-recipe-print"><a href="#">%1$s</a></li>',
esc_html_x( 'Print', 'recipe', 'jetpack' )
);
}
$html .= '</ul>';
} // End if().
// Output the image, if we have one.
if ( '' !== $atts['image'] ) {
$html .= sprintf(
'<img class="jetpack-recipe-image" itemprop="image" src="%1$s" />',
esc_url( $atts['image'] )
);
}
// Output the description, if we have one.
if ( '' !== $atts['description'] ) {
$html .= sprintf(
'<p class="jetpack-recipe-description" itemprop="description">%1$s</p>',
esc_html( $atts['description'] )
);
}
// 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;
}
/**
* Our [recipe-notes] shortcode.
* Outputs ingredients, styled in a div.
*
* @param array $atts Array of shortcode attributes.
* @param string $content Post content.
*
* @return string HTML for recipe notes shortcode.
*/
static function recipe_notes_shortcode( $atts, $content = '' ) {
$atts = shortcode_atts( array(
'title' => '', // string.
), $atts, 'recipe-notes' );
$html = '';
// Print a title if one exists.
if ( '' !== $atts['title'] ) {
$html .= '<h4 class="jetpack-recipe-notes-title">' . esc_html( $atts['title'] ) . '</h4>';
}
$html .= '<div class="jetpack-recipe-notes">';
// Format content using list functionality, if desired.
$html .= self::output_list_content( $content, 'notes' );
$html .= '</div>';
// Sanitize html.
$html = wp_kses_post( $html );
// Return the HTML block.
return $html;
}
/**
* Our [recipe-ingredients] shortcode.
* Outputs notes, styled in a div.
*
* @param array $atts Array of shortcode attributes.
* @param string $content Post content.
*
* @return string HTML for recipe ingredients shortcode.
*/
static function recipe_ingredients_shortcode( $atts, $content = '' ) {
$atts = shortcode_atts( array(
'title' => esc_html_x( 'Ingredients', 'recipe', 'jetpack' ), // string.
), $atts, 'recipe-ingredients' );
$html = '<div class="jetpack-recipe-ingredients">';
// Print a title unless the user has opted to exclude it.
if ( 'false' !== $atts['title'] ) {
$html .= '<h4 class="jetpack-recipe-ingredients-title">' . esc_html( $atts['title'] ) . '</h4>';
}
// Format content using list functionality.
$html .= self::output_list_content( $content, 'ingredients' );
$html .= '</div>';
// Sanitize html.
$html = wp_kses_post( $html );
// Return the HTML block.
return $html;
}
/**
* Reusable function to check for shortened formatting.
* Basically, users can create lists with the following shorthand:
* - item one
* - item two
* - item three
* And we'll magically convert it to a list. This has the added benefit
* of including itemprops for the recipe schema.
*
* @param string $content HTML content.
* @param string $type Type of list.
*
* @return string content formatted as a list item
*/
static function output_list_content( $content, $type ) {
$html = '';
switch ( $type ) {
case 'directions' :
$list_item_replacement = '<li class="jetpack-recipe-directions">${1}</li>';
$itemprop = ' itemprop="recipeInstructions"';
$listtype = 'ol';
break;
case 'ingredients' :
$list_item_replacement = '<li class="jetpack-recipe-ingredient" itemprop="recipeIngredient">${1}</li>';
$itemprop = '';
$listtype = 'ul';
break;
default:
$list_item_replacement = '<li class="jetpack-recipe-notes">${1}</li>';
$itemprop = '';
$listtype = 'ul';
}
// Check to see if the user is trying to use shortened formatting.
if (
strpos( $content, '&#8211;' ) !== false ||
strpos( $content, '&#8212;' ) !== false ||
strpos( $content, '-' ) !== false ||
strpos( $content, '*' ) !== false ||
strpos( $content, '#' ) !== false ||
strpos( $content, '' ) !== false || // ndash.
strpos( $content, '—' ) !== false || // mdash.
preg_match( '/\d+\.\s/', $content )
) {
// Remove breaks and extra whitespace.
$content = str_replace( "<br />\n", "\n", $content );
$content = trim( $content );
$ul_pattern = '/(?:^|\n|\<p\>)+(?:[\-–—]+|\&#8211;|\&#8212;|\*)+\h+(.*)/mi';
$ol_pattern = '/(?:^|\n|\<p\>)+(?:\d+\.|#+)+\h+(.*)/mi';
preg_match_all( $ul_pattern, $content, $ul_matches );
preg_match_all( $ol_pattern, $content, $ol_matches );
if ( 0 !== count( $ul_matches[0] ) || 0 !== count( $ol_matches[0] ) ) {
if ( 0 !== count( $ol_matches[0] ) ) {
$listtype = 'ol';
$list_item_pattern = $ol_pattern;
} else {
$listtype = 'ul';
$list_item_pattern = $ul_pattern;
}
$html .= '<' . $listtype . $itemprop . '>';
$html .= preg_replace( $list_item_pattern, $list_item_replacement, $content );
$html .= '</' . $listtype . '>';
// Strip out any empty <p> tags and stray </p> tags, because those are just silly.
$empty_p_pattern = '/(<p>)*\s*<\/p>/mi';
$html = preg_replace( $empty_p_pattern, '', $html );
} else {
$html .= do_shortcode( $content );
}
} else {
$html .= do_shortcode( $content );
}
// Return our formatted content.
return $html;
}
/**
* Our [recipe-directions] shortcode.
* Outputs directions, styled in a div.
*
* @param array $atts Array of shortcode attributes.
* @param string $content Post content.
*
* @return string HTML for recipe directions shortcode.
*/
static function recipe_directions_shortcode( $atts, $content = '' ) {
$atts = shortcode_atts( array(
'title' => esc_html_x( 'Directions', 'recipe', 'jetpack' ), // string.
), $atts, 'recipe-directions' );
$html = '<div class="jetpack-recipe-directions">';
// Print a title unless the user has specified to exclude it.
if ( 'false' !== $atts['title'] ) {
$html .= '<h4 class="jetpack-recipe-directions-title">' . esc_html( $atts['title'] ) . '</h4>';
}
// Format content using list functionality.
$html .= self::output_list_content( $content, 'directions' );
$html .= '</div>';
// Sanitize html.
$html = wp_kses_post( $html );
// Return the HTML block.
return $html;
}
/**
* Use $themecolors array to style the Recipes shortcode
*
* @print style block
* @return string $style
*/
function themecolor_styles() {
global $themecolors;
$style = '';
if ( isset( $themecolors ) ) {
$style .= '.jetpack-recipe { border-color: #' . esc_attr( $themecolors['border'] ) . '; }';
$style .= '.jetpack-recipe-title { border-bottom-color: #' . esc_attr( $themecolors['link'] ) . '; }';
}
return $style;
}
}
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,26 @@
<?php
/**
* Sitemap shortcode.
*
* Usage: [sitemap]
*/
add_shortcode( 'sitemap', 'jetpack_sitemap_shortcode' );
/**
* Renders a tree of pages.
*
* @since 4.5.0
*
* @return string
*/
function jetpack_sitemap_shortcode() {
$tree = wp_list_pages( array(
'title_li' => '<b><a href="/">' . esc_html( get_bloginfo( 'name' ) ) . '</a></b>',
'exclude' => get_option( 'page_on_front' ),
'echo' => false,
) );
return empty( $tree )
? ''
: '<ul class="jetpack-sitemap-shortcode">' . $tree . '</ul>';
}

View File

@@ -0,0 +1,125 @@
<?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>';
/**
* Filter the returned SlideShare shortcode.
*
* @module shortcodes
*
* @since 4.7.0
*
* @param string $player The iframe to return.
* @param array $atts The attributes specified in the shortcode.
*/
return apply_filters( 'jetpack_slideshare_shortcode', $player, $atts );
}

View File

@@ -0,0 +1,311 @@
<?php
/**
* Slideshow shortcode usage: [gallery type="slideshow"] or the older [slideshow]
*/
class Jetpack_Slideshow_Shortcode {
public $instance_count = 0;
function __construct() {
global $shortcode_tags;
// Only if the slideshow shortcode has not already been defined.
if ( ! array_key_exists( 'slideshow', $shortcode_tags ) ) {
add_shortcode( 'slideshow', array( $this, 'shortcode_callback' ) );
}
// 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 );
}
/**
* 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 ) {
$post_id = get_the_ID();
$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'],
'suppress_filters' => false,
)
);
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="https://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;
}
/**
* Actually enqueues the scripts and styles.
*/
function enqueue_scripts() {
wp_enqueue_script( 'jquery-cycle', plugins_url( '/js/jquery.cycle.min.js', __FILE__ ), array( 'jquery' ), '20161231', true );
wp_enqueue_script(
'jetpack-slideshow',
Jetpack::get_file_url_for_environment( '_inc/build/shortcodes/js/slideshow-shortcode.min.js', 'modules/shortcodes/js/slideshow-shortcode.js' ),
array( 'jquery-cycle' ),
'20160119.1',
true
);
wp_enqueue_style( 'jetpack-slideshow', plugins_url( '/css/slideshow-shortcode.css', __FILE__ ) );
wp_style_add_data( 'jetpack-slideshow', 'rtl', 'replace' );
wp_localize_script(
'jetpack-slideshow',
'jetpackSlideshowSettings',
/**
* Filters the slideshow JavaScript spinner.
*
* @module shortcodes
*
* @since 2.1.0
* @since 4.7.0 Added the `speed` option to the array of options.
*
* @param array $args
* - string - spinner - URL of the spinner image.
* - string - speed - Speed of the slideshow. Defaults to 4000.
*/
apply_filters( 'jetpack_js_slideshow_settings', array(
'spinner' => plugins_url( '/img/slideshow-loader.gif', __FILE__ ),
'speed' => '4000',
) )
);
}
public static function init() {
new Jetpack_Slideshow_Shortcode;
}
}
Jetpack_Slideshow_Shortcode::init();

View File

@@ -0,0 +1,315 @@
<?php
/*
Plugin Name: SoundCloud Shortcode
Plugin URI: https://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
*/
/* A8C: oEmbed is handled now in core; see wp-includes/class-oembed.php
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;
/* A8C: The original plugin exposes options we don't. SoundCloud omits "visual" shortcode
option when false, so if logic here remains, impossible to have non-visual shortcode.
$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' => true, // A8C: See above comment; flash is not a supported option
'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' => 'false', // A8C: Merged with params below at $options assignment
)
),
)
);
// 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 ( ! is_string( $content ) || 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,97 @@
<?php
/**
* Spotify shortcode.
*
* Usage:
* [spotify id="spotify:track:4bz7uB4edifWKJXSDxwHcs" width="400" height="100"]
*/
if ( ! shortcode_exists( 'spotify' ) ) {
add_shortcode( 'spotify', 'jetpack_spotify_shortcode' );
if ( get_option( 'embed_autourls' ) ) {
// If user enabled autourls, also convert syntax like spotify:track:4bz7uB4edifWKJXSDxwHcs
add_filter( 'the_content', 'jetpack_spotify_embed_ids', 7 );
}
}
/**
* Parse shortcode arguments and render its output.
*
* @since 4.5.0
*
* @param array $atts
* @param string $content
*
* @return string
*/
function jetpack_spotify_shortcode( $atts = array(), $content = '' ) {
if ( ! empty( $content ) ) {
$id = $content;
} elseif ( ! empty( $atts['id'] ) ) {
$id = $atts['id'];
} elseif ( ! empty( $atts[0] ) ) {
$id = $atts[0];
} else {
return '<!-- Missing Spotify ID -->';
}
if ( empty( $atts['width'] ) ) {
$atts['width'] = 300;
}
if ( empty( $atts['height'] ) ) {
$atts['height'] = 380;
}
$atts['width'] = (int) $atts['width'];
$atts['height'] = (int) $atts['height'];
// Spotify accepts both URLs and their Spotify ID format, so let them sort it out and validate
$embed_url = add_query_arg( 'uri', urlencode( $id ), 'https://embed.spotify.com/' );
return '<iframe src="' . esc_url( $embed_url ) . '" style="display:block; margin:0 auto; width:' . esc_attr( $atts['width'] ) . 'px; height:' . esc_attr( $atts['height'] ) . 'px;" frameborder="0" allowtransparency="true"></iframe>';
}
/**
* Turn text like this on it's own line into an embed: spotify:track:4bz7uB4edifWKJXSDxwHcs
* The core WordPress embed functionality only works with URLs
* Modified version of WP_Embed::autoembed()
*
* @since 4.5.0
*
* @param $content
*
* @return string
*/
function jetpack_spotify_embed_ids( $content ) {
$textarr = wp_html_split( $content );
foreach ( $textarr as &$element ) {
if ( '' == $element || '<' === $element[0] ) {
continue;
}
if ( substr( ltrim( $element ), 0, 8 ) !== 'spotify:' ) {
continue;
}
$element = preg_replace_callback( '|^\s*(spotify:[^\s"]+:[^\s"]+)\s*$|im', 'jetpack_spotify_embed_ids_callback', $element );
}
return implode( '', $textarr );
}
/**
* Call shortcode with ID provided by matching pattern.
*
* @since 4.5.0
*
* @param array $matches
*
* @return string
*/
function jetpack_spotify_embed_ids_callback( $matches ) {
return "\n" . jetpack_spotify_shortcode( array(), $matches[1] ) . "\n";
}

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,145 @@
<?php
/**
* Tweet shortcode.
* Params map to key value pairs, and all but tweet are optional:
* tweet = id or permalink url* (Required)
* align = none|left|right|center
* width = number in pixels example: width="300"
* lang = en|fr|de|ko|etc... language country code.
* hide_thread = true | false **
* hide_media = true | false **
*
* Basic:
* [tweet https://twitter.com/jack/statuses/20 width="350"]
*
* More parameters and another tweet syntax admitted:
* [tweet tweet="https://twitter.com/jack/statuses/20" align="left" width="350" align="center" lang="es"]
*/
add_shortcode( 'tweet', array( 'Jetpack_Tweet', 'jetpack_tweet_shortcode' ) );
class Jetpack_Tweet {
static $provider_args;
/**
* Parse shortcode arguments and render its output.
*
* @since 4.5.0
*
* @param array $atts Shortcode parameters.
*
* @return string
*/
static public function jetpack_tweet_shortcode( $atts ) {
$default_atts = array(
'tweet' => '',
'align' => 'none',
'width' => '',
'lang' => 'en',
'hide_thread' => 'false',
'hide_media' => 'false',
);
$attr = shortcode_atts( $default_atts, $atts );
self::$provider_args = $attr;
// figure out the tweet id for the requested tweet
// supporting both omitted attributes and tweet="tweet_id"
// and supporting both an id and a URL
if ( empty( $attr['tweet'] ) && ! empty( $atts[0] ) ) {
$attr['tweet'] = $atts[0];
}
if ( ctype_digit( $attr['tweet'] ) ) {
$id = 'https://twitter.com/jetpack/status/' . $attr['tweet'];
} else {
preg_match( '/^http(s|):\/\/twitter\.com(\/\#\!\/|\/)([a-zA-Z0-9_]{1,20})\/status(es)*\/(\d+)$/', $attr['tweet'], $urlbits );
if ( isset( $urlbits[5] ) && intval( $urlbits[5] ) ) {
$id = 'https://twitter.com/' . $urlbits[3] . '/status/' . intval( $urlbits[5] );
} else {
return '<!-- Invalid tweet id -->';
}
}
// Add shortcode arguments to provider URL
add_filter( 'oembed_fetch_url', array( 'Jetpack_Tweet', 'jetpack_tweet_url_extra_args' ), 10, 3 );
// Fetch tweet
$output = wp_oembed_get( $id, $atts );
// Clean up filter
remove_filter( 'oembed_fetch_url', array( 'Jetpack_Tweet', 'jetpack_tweet_url_extra_args' ), 10 );
// Add Twitter widgets.js script to the footer.
add_action( 'wp_footer', array( 'Jetpack_Tweet', 'jetpack_tweet_shortcode_script' ) );
/** This action is documented in modules/widgets/social-media-icons.php */
do_action( 'jetpack_bump_stats_extras', 'embeds', 'tweet' );
return $output;
}
/**
* Adds parameters to URL used to fetch the tweet.
*
* @since 4.5.0
*
* @param string $provider URL of provider that supplies the tweet we're requesting.
* @param string $url URL of tweet to embed.
* @param array $args Parameters supplied to shortcode and passed to wp_oembed_get
*
* @return string
*/
static public function jetpack_tweet_url_extra_args( $provider, $url, $args = array() ) {
foreach ( self::$provider_args as $key => $value ) {
switch ( $key ) {
case 'align':
case 'lang':
case 'hide_thread':
case 'hide_media':
$provider = add_query_arg( $key, $value, $provider );
break;
}
}
// Disable script since we're enqueing it in our own way in the footer
$provider = add_query_arg( 'omit_script', 'true', $provider );
// Twitter doesn't support maxheight so don't send it
$provider = remove_query_arg( 'maxheight', $provider );
/**
* Filter the Twitter Partner ID.
*
* @module shortcodes
*
* @since 4.6.0
*
* @param string $partner_id Twitter partner ID.
*/
$partner = apply_filters( 'jetpack_twitter_partner_id', 'jetpack' );
// Add Twitter partner ID to track embeds from Jetpack
if ( ! empty( $partner ) ) {
$provider = add_query_arg( 'partner', $partner, $provider );
}
return $provider;
}
/**
* Enqueue front end assets.
*
* @since 4.5.0
*/
static public function jetpack_tweet_shortcode_script() {
if ( ! wp_script_is( 'twitter-widgets', 'registered' ) ) {
wp_register_script( 'twitter-widgets', 'https://platform.twitter.com/widgets.js', array(), JETPACK__VERSION, true );
wp_print_scripts( 'twitter-widgets' );
}
}
} // class end

View File

@@ -0,0 +1,73 @@
<?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']
**/
/**
* (Live URL) http://www.twitch.tv/paperbat
*
* <iframe src="https://player.twitch.tv/?autoplay=false&#038;muted=false&#038;channel=paperbat" width="620" height="378" frameborder="0" scrolling="no" allowfullscreen></iframe>
*
* (Archive URL) http://www.twitch.tv/paperbat/v/323486192
*
* <iframe src="https://player.twitch.tv/?autoplay=false&#038;muted=false&#038;video=v323486192" width="620" height="378" frameborder="0" scrolling="no" allowfullscreen></iframe>
*
* @param $atts array User supplied shortcode arguments.
*
* @return string HTML output of the shortcode.
*/
function wpcom_twitchtv_shortcode( $atts ) {
$attr = shortcode_atts(
array(
'height' => 378,
'width' => 620,
'url' => '',
'autoplay' => 'false',
'muted' => 'false',
'time' => null
), $atts
);
if ( empty( $attr['url'] ) ) {
return '<!-- Invalid twitchtv URL -->';
}
preg_match( '|^http://www.twitch.tv/([^/?]+)(/v/(\d+))?|i', $attr['url'], $match );
$url_args = array(
'autoplay' => ( false !== $attr['autoplay'] && 'false' !== $attr['autoplay'] ) ? 'true' : 'false',
'muted' => ( false !== $attr['muted'] && 'false' !== $attr['muted'] ) ? 'true' : 'false',
'time' => $attr['time']
);
$width = intval( $attr['width'] );
$height = intval( $attr['height'] );
$user_id = $match[1];
$video_id = 0;
if ( ! empty( $match[3] ) ) {
$video_id = (int) $match[3];
}
do_action( 'jetpack_bump_stats_extras', 'twitchtv', 'shortcode' );
if ( $video_id > 0 ) {
$url_args['video'] = 'v' . $video_id;
} else {
$url_args['channel'] = $user_id;
}
$url = add_query_arg( $url_args, 'https://player.twitch.tv/' );
return sprintf(
'<iframe src="%s" width="%d" height="%d" frameborder="0" scrolling="no" allowfullscreen></iframe>',
esc_url( $url ),
esc_attr( $width ),
esc_attr( $height )
);
}
add_shortcode( 'twitch', 'wpcom_twitchtv_shortcode' );
add_shortcode( 'twitchtv', 'wpcom_twitchtv_shortcode' );

View File

@@ -0,0 +1,56 @@
<?php
add_shortcode( 'twitter-timeline', 'twitter_timeline_shortcode' );
function twitter_timeline_shortcode( $atts ) {
$default_atts = array(
'username' => '',
'id' => '',
'width' => '450',
'height' => '282',
);
$atts = shortcode_atts( $default_atts, $atts, 'twitter-timeline' );
$atts['username'] = preg_replace( '/[^A-Za-z0-9_]+/', '', $atts['username'] );
if ( empty( $atts['username'] ) && ! is_numeric( $atts['id'] ) ) {
return '<!-- ' . __( 'Must specify Twitter Timeline id or username.', 'jetpack' ) . ' -->';
}
$output = '<a class="twitter-timeline"';
/** This filter is documented in modules/shortcodes/tweet.php */
$partner = apply_filters( 'jetpack_twitter_partner_id', 'jetpack' );
if ( ! empty( $partner ) ) {
$output .= ' data-partner="' . esc_attr( $partner ) . '"';
}
if ( is_numeric( $atts['width'] ) ) {
$output .= ' data-width="' . esc_attr( $atts['width'] ) . '"';
}
if ( is_numeric( $atts['height'] ) ) {
$output .= ' data-height="' . esc_attr( $atts['height'] ) . '"';
}
if ( is_numeric( $atts['id'] ) ) {
$output .= ' data-widget-id="' . esc_attr( $atts['id'] ) . '"';
}
if ( ! empty( $atts['username'] ) ) {
$output .= ' href="' . esc_url( 'https://twitter.com/' . $atts['username'] ) . '"';
}
$output .= '>';
$output .= sprintf( __( 'Tweets by @%s', 'jetpack' ), $atts['username'] );
$output .= '</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,62 @@
<?php
/**
* Class Jetpack_Shortcode_Unavailable
*/
class Jetpack_Shortcode_Unavailable {
/**
* Set up the actions and filters for the class to listen to.
*
* @param array $shortcodes An associative array of keys being the shortcodes that are unavailable, and a string explaining why.
*/
public function __construct( $shortcodes ) {
$this->shortcodes = $shortcodes;
add_action( 'template_redirect', array( $this, 'add_shortcodes' ) );
}
/**
* For all of our defined unavailable shortcodes, if something else hasn't
* already claimed them, add a handler to nullify their output.
*/
public function add_shortcodes() {
foreach ( $this->shortcodes as $shortcode => $message ) {
if ( ! shortcode_exists( $shortcode ) ) {
add_shortcode( $shortcode, array( $this, 'stub_shortcode' ) );
}
}
}
/**
* Nullify the output of unavailable shortcodes. Includes a filter to make
* it easier to notify admins that a shortcode that they used is unavailable.
*
* @param $atts
* @param string $content
* @param string $shortcode
* @return mixed|void
*/
public function stub_shortcode( $atts, $content = '', $shortcode = '' ) {
$str = '';
if ( current_user_can( 'edit_posts' ) && ! empty( $this->shortcodes[ $shortcode ] ) ) {
$str = sprintf( '<div><strong>%s</strong></div>', $this->shortcodes[ $shortcode ] );
}
/**
* Filter the front-end output of unavailable shortcodes.
*
* @module shortcodes
*
* @since 4.5.0
*
* @param string $str The html displayed in lieu of the shortcode.
* @param array $atts The attributes (numeric or named) passed to the shortcode.
* @param string $content The content (if any) between the opening and closing tags.
* @param string $shortcode The shortcode tag used to invoke this.
*/
return apply_filters( 'jetpack_stub_shortcode', $str, $atts, $content, $shortcode );
}
}
new Jetpack_Shortcode_Unavailable( array(
'blip.tv' => __( 'The Blip.tv service has been shut down since August 20th, 2015.', 'jetpack' ),
) );

View File

@@ -0,0 +1,65 @@
<?php
/**
* Untappd Shortcodes
* @author kraftbj
*
* [untappd-menu location="123" theme="123"]
* @since 4.1.0
* @param location int Location ID for the Untappd venue. Required.
* @param theme int Theme ID for the Untappd menu. Required.
*/
class Jetpack_Untappd {
function __construct() {
add_action( 'init', array( $this, 'action_init' ) );
}
function action_init() {
add_shortcode( 'untappd-menu', array( $this, 'menu_shortcode' ) );
}
/**
* [untappd-menu] shortcode.
*
*/
static function menu_shortcode( $atts, $content = '' ) {
// Let's bail if we don't have location or theme.
if ( ! isset( $atts['location'] ) || ! isset( $atts['theme'] ) ) {
if ( current_user_can( 'edit_posts') ){
return __( 'No location or theme ID provided in the untappd-menu shortcode.', 'jetpack' );
}
return;
}
// Let's apply some defaults.
$atts = shortcode_atts( array(
'location' => '',
'theme' => '',
), $atts, 'untappd-menu' );
// We're going to clean the user input.
$atts = array_map( 'absint', $atts );
if ( $atts['location'] < 1 || $atts['theme'] < 1 ) {
return;
}
static $untappd_menu = 1;
$html = '<div id="menu-container-untappd-' . $untappd_menu . '" class="untappd-menu"></div>';
$html .= '<script type="text/javascript">' . PHP_EOL;
$html .= '!function(e,n){var t=document.createElement("script"),a=document.getElementsByTagName("script")[0];' . PHP_EOL;
$html .= 't.async=1,a.parentNode.insertBefore(t,a),t.onload=t.onreadystatechange=function(e,a){' . PHP_EOL;
$html .= '(a||!t.readyState||/loaded|complete/.test(t.readyState))&&(t.onload=t.onreadystatechange=null,t=void 0,a||n&&n())},' . PHP_EOL;
$html .= 't.src=e}("https://embed-menu-preloader.untappdapi.com/embed-menu-preloader.min.js",function(){' . PHP_EOL;
$html .= 'PreloadEmbedMenu( "menu-container-untappd-' . $untappd_menu . '",' . $atts["location"] . ',' . $atts["theme"] . ' )});' . PHP_EOL;
$html .= '</script>';
$untappd_menu++;
return $html;
}
}
new Jetpack_Untappd();

View File

@@ -0,0 +1,29 @@
<?php
/**
* Most of the heavy lifting done in iCalendarReader class
*/
class Upcoming_Events_Shortcode {
public static function init() {
add_shortcode( 'upcomingevents', array( __CLASS__, 'shortcode' ) );
}
public static function shortcode( $atts = array() ) {
jetpack_require_lib( 'icalendar-reader' );
$atts = shortcode_atts( array( 'url' => '', 'number' => 0 ), $atts, 'upcomingevents' );
$args = array(
'context' => 'shortcode',
'number' => absint( $atts['number'] ),
);
$events = icalendar_render_events( $atts['url'], $args );
if ( ! $events ) {
$events = sprintf( '<p>%s</p>', __( 'No upcoming events', 'jetpack' ) );
}
return $events;
}
}
add_action( 'plugins_loaded', array( 'Upcoming_Events_Shortcode', 'init' ), 101 );

View File

@@ -0,0 +1,127 @@
<?php
/**
* ustream.tv shortcode
*
* Example:
* [ustream id=1524 live=1]
* [ustreamsocial id=12980237 width="500"]
*
* Embed code example, from http://www.ustream.tv/leolaporte
* <iframe src="http://www.ustream.tv/embed/recorded/1524?v=3&#038;wmode=direct" width="480" height="296" scrolling="no" frameborder="0" style="border: 0 none transparent;"></iframe>
*/
add_shortcode( 'ustream', 'ustream_shortcode' );
add_shortcode( 'ustreamsocial', 'ustreamsocial_shortcode' );
/**
* Parse shortcode arguments and render output for ustream single video.
*
* @since 4.5.0
*
* @param $atts array of user-supplied arguments.
*
* @return string HTML output.
*/
function ustream_shortcode( $atts ) {
if ( isset( $atts[0] ) ) {
return '<!-- ustream error: bad parameters -->';
}
$defaults = array(
'width' => 480,
'height' => 296,
'id' => 0,
'live' => 0,
'highlight' => 0,
'version' => 3,
'hwaccel' => 1,
);
$atts = array_map( 'intval', shortcode_atts( $defaults, $atts ) );
$ustream_id = $atts['id'];
$width = $atts['width'];
$height = $atts['height'];
$live = $atts['live'];
$highlight = $atts['highlight'];
$version = $atts['version'];
$hwaccel = $atts['hwaccel'];
$version = 'v=' . esc_attr( $version );
if ( 0 >= $ustream_id ) {
return '<!-- ustream error: bad video ID -->';
}
if ( 0 >= $height ) {
return '<!-- ustream error: height invalid -->';
}
if ( 0 >= $width ) {
return '<!-- ustream error: width invalid -->';
}
if ( $live ) {
$recorded = '';
} else {
$recorded = 'recorded/';
}
if ( ! $live && ( 0 < $highlight ) ) {
$highlight = "/highlight/$highlight";
} else {
$highlight = '';
}
if ( 0 < $hwaccel ) {
$wmode = '&amp;wmode=direct';
} else {
$wmode = '';
}
$url = 'http://www.ustream.tv/embed/' . $recorded . esc_attr( $ustream_id ) . $highlight . '?' . $version . $wmode;
$url = set_url_scheme( $url );
$output = '<iframe src="' . esc_url( $url ) . '" width="' . esc_attr( $width ) . '" height="' . esc_attr( $height ) . '" scrolling="no" style="border: 0 none transparent;"></iframe>';
return $output;
}
/**
* Parse shortcode arguments and render output for ustream's Social Stream.
*
* @since 4.5.0
*
* @param $atts array of user-supplied arguments.
*
* @return string HTML output.
*/
function ustreamsocial_shortcode( $atts ) {
$defaults = array(
'id' => 0,
'height' => 420,
'width' => 320,
);
$atts = array_map( 'intval', shortcode_atts( $defaults, $atts ) );
$ustream_id = $atts['id'];
$width = $atts['width'];
$height = $atts['height'];
if ( 0 >= $ustream_id ) {
return '<!-- ustreamsocial error: bad social stream ID -->';
}
if ( 0 >= $height ) {
return '<!-- ustreamsocial error: height invalid -->';
}
if ( 0 >= $width ) {
return '<!-- ustreamsocial error: width invalid -->';
}
$url = set_url_scheme( "http://www.ustream.tv/socialstream/$ustream_id" );
return '<iframe id="SocialStream" class="" name="SocialStream" width="' . esc_attr( $width ) . '" height="' . esc_attr( $height ) . '" scrolling="no" allowtransparency="true" src="' . esc_url( $url ) . '" style="visibility: visible; margin-top: 0; margin-bottom: 0; border: 0;"></iframe>';
}

View File

@@ -0,0 +1,18 @@
<?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',
) );
include_once JETPACK__PLUGIN_DIR . 'modules/videopress/utility-functions.php';
include_once JETPACK__PLUGIN_DIR . 'modules/videopress/shortcode.php';
}

View File

@@ -0,0 +1,300 @@
<?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 ( ! is_string( $content ) || 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 ( ! is_admin() && apply_filters( 'jetpack_comments_allow_oembed', true ) ) {
// We attach wp_kses_post to comment_text in default-filters.php with priority of 10 anyway, so the iframe gets filtered out.
// 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,156 @@
<?php
// VR Viewer Shortcode
// converts [vr] shortcode to an iframe viewer hosted on vr.me.sh
/**
* Scrub URL paramaters for VR viewer
* @param url_params - parameter array which is passed to the jetpack_vr_viewer
* @param url_params['url'] - url of 360 media
* @param url_params['guid'] - guid for videopress
* @param url_params['view'] - cinema, 360 - controls if panaroma view, or 360
* @param url_params['rotation'] - number for rotating media
* @param url_params['preview'] - show preview image or not
* @return url_params array or false
*/
function jetpack_vr_viewer_get_viewer_url_params( $params ) {
$url_params = array();
if ( isset( $params['rotation'] ) ) {
$url_params['rotation'] = intval( $params['rotation'], 10 );
}
if ( isset( $params['view'] ) && in_array( $params['view'], array( 'cinema', '360' ), true ) ) {
$url_params['view'] = $params['view'];
}
if ( isset( $params['preview'] ) && $params['preview'] ) {
$url_params['preview'] = 1;
}
if ( isset( $params['url'] ) ) {
return array_merge( $url_params, array( 'url' => $params['url'] ) );
} else if ( isset( $params['guid'] ) ) {
return array_merge( $url_params, array( 'guid' => $params['guid'] ) );
}
return false;
}
/**
* Get padding for IFRAME depending on view type
* @param view - string cinema, 360 - default cinema
* @return css padding
*/
function jetpack_vr_viewer_iframe_padding( $view ) {
if ( $view === '360' ) {
return '100%'; // 1:1 square aspect for 360
}
return '50%'; // 2:1 panorama aspect
}
/**
* Create HTML for VR Viewer IFRAME and wrapper
* The viewer code is hosted on vr.me.sh site which is then displayed
* within posts via an IFRAME. This function returns the IFRAME html.
* @param url_params - parameter array which is passed to the jetpack_vr_viewer
* @param url_params['url'] - url of 360 media
* @param url_params['guid'] - guid for videopress
* @param url_params['view'] - cinema, 360 - controls if panaroma view, or 360
* @param url_params['rotation'] - number for rotating media
* @param url_params['preview'] - show preview image or not
* @return html - an iframe for viewer
*/
function jetpack_vr_viewer_get_html( $url_params ) {
global $content_width;
$iframe = add_query_arg( $url_params, 'https://vr.me.sh/view/' );
// set some defaults
$maxwidth = ( isset( $content_width ) ) ? $content_width : 720;
$view = ( isset( $url_params['view'] ) ) ? $url_params['view'] : 'cinema';
$rtn = '<div style="position: relative; max-width: ' . $maxwidth . 'px; margin-left: auto; margin-right: auto; overflow: hidden;">';
$rtn .= '<div style="padding-top: '. jetpack_vr_viewer_iframe_padding( $view ).';"></div>';
$rtn .= '<iframe style="position: absolute; top: 0; right: 0; bottom: 0; left: 0; height: 100%" allowfullscreen="true" frameborder="0" width="100%" height="300" src="'.esc_url( $iframe ).'">';
$rtn .= '</iframe>';
$rtn .= '</div>';
return $rtn;
}
/**
* Convert [vr] shortcode to viewer
*
* Shortcode example:
* [vr url="https://en-blog.files.wordpress.com/2016/12/regents_park.jpg" view="360"]
*
* VR Viewer embed code:
* <div style="position: relative; max-width: 720px; margin-left: auto; margin-right: auto; overflow: hidden;">
* <div style="padding-top: 100%;"></div>
* <iframe style="position: absolute; top: 0; right: 0; bottom: 0; left: 0; height: 100%" allowfullscreen="true" frameborder="0" width="100%" height="400" src="https://vr.me.sh/view/?view=360&amp;url=https://en-blog.files.wordpress.com/2016/12/regents_park.jpg">
* </iframe>
* </div>
*
* @return html - complete vr viewer html
*/
function jetpack_vr_viewer_shortcode( $atts ) {
$params = shortcode_atts( array(
0 => null,
'url' => null,
'src' => null,
'guid' => null,
'rotation' => null,
'view' => null,
'preview' => false,
), $atts );
// We offer a few ways to specify the URL
if ( $params[0] ) {
$params['url'] = $params[0];
} else if ( $params['src'] ) {
$params['url'] = $params['src'];
}
$url_params = jetpack_vr_viewer_get_viewer_url_params( $params );
if ( $url_params ) {
return jetpack_vr_viewer_get_html( $url_params );
}
// add check for user
if ( current_user_can( 'edit_posts' ) ) {
return '[vr] shortcode requires a data source to be given';
} else {
return '';
}
}
add_shortcode( 'vr', 'jetpack_vr_viewer_shortcode' );
// Gutenberg!
add_action( 'admin_init', 'jetpack_register_block_type_vr' );
function jetpack_register_block_type_vr() {
if ( ! function_exists( 'register_block_type' ) ) {
return;
}
wp_register_script(
'jetpack_vr_viewer_shortcode_editor_script',
Jetpack::get_file_url_for_environment( '_inc/build/shortcodes/js/blocks/vr-block.min.js', 'modules/shortcodes/js/blocks/vr-block.js' ),
array( 'wp-blocks', 'wp-element', 'wp-i18n' )
);
wp_register_style(
'jetpack_vr_viewer_shortcode_editor_style',
plugins_url( 'modules/shortcodes/css/blocks/vr-block.css', JETPACK__PLUGIN_FILE ),
array( 'wp-edit-blocks' )
);
register_block_type( 'jetpack/vr', array(
'editor_script' => 'jetpack_vr_viewer_shortcode_editor_script',
'editor_style' => 'jetpack_vr_viewer_shortcode_editor_style',
'render_callback' => 'jetpack_vr_viewer_shortcode',
) );
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* Embed WordAds 'ad' in post
*
*/
class Jetpack_WordAds_Shortcode {
private $scripts_and_style_included = false;
function __construct() {
add_action( 'init', array( $this, 'action_init' ) );
}
/**
* Register our shortcode and enqueue necessary files.
*/
function action_init() {
global $wordads;
if ( empty( $wordads ) ) {
return null;
}
add_shortcode( 'wordads', array( $this, 'wordads_shortcode' ) );
}
/**
* Our [wordads] shortcode.
* Prints a WordAds Ad.
*
* @param array $atts Array of shortcode attributes.
* @param string $content Post content.
*
* @return string HTML for WordAds shortcode.
*/
static function wordads_shortcode( $atts, $content = '' ) {
$atts = shortcode_atts( array(), $atts, 'wordads');
return self::wordads_shortcode_html( $atts, $content );
}
/**
* The shortcode output
*
* @param array $atts Array of shortcode attributes.
* @param string $content Post content.
*
* @return string HTML output
*/
static function wordads_shortcode_html( $atts, $content = '' ) {
global $wordads;
if ( empty( $wordads ) ) {
return '<div>' . __( 'The WordAds module is not active', 'jetpack' ) . '</div>';
}
$html = '<div class="jetpack-wordad" itemscope itemtype="https://schema.org/WPAdBlock">';
$html .= '</div>';
$html = $wordads->insert_inline_ad( $html );
return $html;
}
}
new Jetpack_WordAds_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 https://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,391 @@
<?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 ( ! is_string( $content ) || 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;
// If we have $content_width, use it.
if ( ! empty( $content_width ) ) {
$default_width = $content_width;
} else {
// Otherwise get default width from the old, now deprecated embed_size_w option.
$default_width = get_option('embed_size_w');
}
// If we don't know those 2 values use a hardcoded width.h
if ( empty( $default_width ) ) {
$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 ( ! is_admin() && apply_filters( 'jetpack_comments_allow_oembed', true ) ) {
// We attach wp_kses_post to comment_text in default-filters.php with priority of 10 anyway, so the iframe gets filtered out.
// 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 );