summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/shortcodes')
-rw-r--r--plugins/jetpack/modules/shortcodes/class.filter-embedded-html-objects.php2
-rw-r--r--plugins/jetpack/modules/shortcodes/css/blocks/vr-block.css16
-rw-r--r--plugins/jetpack/modules/shortcodes/facebook.php5
-rw-r--r--plugins/jetpack/modules/shortcodes/js/blocks/vr-block.js102
-rw-r--r--plugins/jetpack/modules/shortcodes/mixcloud.php56
-rw-r--r--plugins/jetpack/modules/shortcodes/polldaddy.php13
-rw-r--r--plugins/jetpack/modules/shortcodes/vr.php27
-rw-r--r--plugins/jetpack/modules/shortcodes/wordads.php67
8 files changed, 262 insertions, 26 deletions
diff --git a/plugins/jetpack/modules/shortcodes/class.filter-embedded-html-objects.php b/plugins/jetpack/modules/shortcodes/class.filter-embedded-html-objects.php
index 8555da37..8912c936 100644
--- a/plugins/jetpack/modules/shortcodes/class.filter-embedded-html-objects.php
+++ b/plugins/jetpack/modules/shortcodes/class.filter-embedded-html-objects.php
@@ -242,7 +242,7 @@ class Filter_Embedded_HTML_Objects {
}
static function get_attrs( $html ) {
- if ( ! ( function_exists( 'libxml_use_internal_errors' ) && function_exists( 'simplexml_load_string' ) ) ) {
+ 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();
}
diff --git a/plugins/jetpack/modules/shortcodes/css/blocks/vr-block.css b/plugins/jetpack/modules/shortcodes/css/blocks/vr-block.css
new file mode 100644
index 00000000..996d62fc
--- /dev/null
+++ b/plugins/jetpack/modules/shortcodes/css/blocks/vr-block.css
@@ -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%;
+} \ No newline at end of file
diff --git a/plugins/jetpack/modules/shortcodes/facebook.php b/plugins/jetpack/modules/shortcodes/facebook.php
index ab7a04f4..9f787539 100644
--- a/plugins/jetpack/modules/shortcodes/facebook.php
+++ b/plugins/jetpack/modules/shortcodes/facebook.php
@@ -44,7 +44,10 @@ function jetpack_facebook_embed_handler( $matches, $attr, $url ) {
// since Facebook is a faux embed, we need to load the JS SDK in the wpview embed iframe
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && ! empty( $_POST['action'] ) && 'parse-embed' == $_POST['action'] ) {
- return $embed . wp_scripts()->do_items( array( 'jetpack-facebook-embed' ) );
+ 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;
diff --git a/plugins/jetpack/modules/shortcodes/js/blocks/vr-block.js b/plugins/jetpack/modules/shortcodes/js/blocks/vr-block.js
new file mode 100644
index 00000000..9466a671
--- /dev/null
+++ b/plugins/jetpack/modules/shortcodes/js/blocks/vr-block.js
@@ -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); \ No newline at end of file
diff --git a/plugins/jetpack/modules/shortcodes/mixcloud.php b/plugins/jetpack/modules/shortcodes/mixcloud.php
index 8c244f17..ac5c3f01 100644
--- a/plugins/jetpack/modules/shortcodes/mixcloud.php
+++ b/plugins/jetpack/modules/shortcodes/mixcloud.php
@@ -9,44 +9,66 @@
* [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', 'http://www.mixcloud.com/oembed', true);
+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 -->";
+ if ( empty( $atts[0] ) && empty( $content ) ) {
+ return '<!-- mixcloud error: invalid mixcloud resource -->';
+ }
- $regular_expression = '#((?<=mixcloud.com/)([A-Za-z0-9%-]+/[A-Za-z0-9%-]+))|^([A-Za-z0-9%-]+/[A-Za-z0-9%-]+)#i';
+ $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 ) )
+ if ( ! empty( $match ) ) {
$resource_id = trim( $match[0] );
+ }
+ }
+
+ if ( empty( $resource_id ) ) {
+ return '<!-- mixcloud error: invalid mixcloud resource -->';
}
- if ( empty( $resource_id ) )
- return "<!-- mixcloud error: invalid mixcloud resource -->";
+ $mixcloud_url = 'https://mixcloud.com/' . $resource_id;
- $atts = shortcode_atts( array(
- 'width' => 300,
- 'height' => 300,
- ), $atts, 'mixcloud' );
+ $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 );
- // Build URL
- $url = add_query_arg( $atts, "http://api.mixcloud.com/$resource_id/embed-html/" );
- $head = wp_remote_head( $url );
- if ( is_wp_error( $head ) || 200 != $head['response']['code'] )
- return "<!-- mixcloud error: invalid mixcloud resource -->";
+ $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 -->';
+ }
- return sprintf( '<iframe width="%d" height="%d" scrolling="no" frameborder="no" src="%s"></iframe>', $atts['width'], $atts['height'], esc_url( $url ) );
+ $response_body = json_decode( $mixcloud_response['body'] );
+ return $response_body->html;
}
diff --git a/plugins/jetpack/modules/shortcodes/polldaddy.php b/plugins/jetpack/modules/shortcodes/polldaddy.php
index b72866ce..609794ff 100644
--- a/plugins/jetpack/modules/shortcodes/polldaddy.php
+++ b/plugins/jetpack/modules/shortcodes/polldaddy.php
@@ -76,7 +76,7 @@ CONTAINER;
/*
* Polldaddy Poll Embed script - transforms code that looks like that:
- * <script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/123456.js"></script>
+ * <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
*/
@@ -221,7 +221,7 @@ CONTAINER;
<script type="text/javascript" charset="UTF-8"><!--//--><![CDATA[//><!--
PDRTJS_settings_{$rating}{$item_id}={$settings};
//--><!]]></script>
-<script type="text/javascript" charset="UTF-8" src="{$rating_js_file}"></script>
+<script type="text/javascript" charset="UTF-8" async src="{$rating_js_file}"></script>
SCRIPT;
} else {
if ( false === self::$scripts ) {
@@ -338,7 +338,7 @@ SCRIPT;
<a id="pd_a_{$poll}"></a>
<div class="PDS_Poll" id="PDI_container{$poll}" style="display:inline-block;{$float}{$margins}"></div>
<div id="PD_superContainer"></div>
-<script type="text/javascript" charset="UTF-8" src="{$poll_js}{$cb}"></script>
+<script type="text/javascript" charset="UTF-8" async src="{$poll_js}{$cb}"></script>
<noscript>{$poll_link}</noscript>
CONTAINER;
}
@@ -496,13 +496,13 @@ CONTAINER;
foreach( self::$scripts['rating'] as $rating ) {
$script .= "PDRTJS_settings_{$rating['id']}{$rating['item_id']}={$rating['settings']}; if ( typeof PDRTJS_RATING !== 'undefined' ){if ( typeof PDRTJS_{$rating['id']}{$rating['item_id']} == 'undefined' ){PDRTJS_{$rating['id']}{$rating['item_id']} = new PDRTJS_RATING( PDRTJS_settings_{$rating['id']}{$rating['item_id']} );}}";
}
- $script .= "\n//--><!]]></script><script type='text/javascript' charset='UTF-8' src='{$rating_js_file}'></script>";
+ $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' src='{$poll['url']}'></script>";
+ $script .= "<script type='text/javascript' charset='UTF-8' async src='{$poll['url']}'></script>";
}
}
}
@@ -544,6 +544,7 @@ CONTAINER;
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 );
@@ -565,7 +566,7 @@ new PolldaddyShortcode();
if ( ! function_exists( 'polldaddy_link' ) ) {
// http://polldaddy.com/poll/1562975/?view=results&msg=voted
function polldaddy_link( $content ) {
- return jetpack_preg_replace_outside_tags( '!(?:\n|\A)http://polldaddy.com/poll/([0-9]+?)/(.+)?(?:\n|\Z)!i', "\n<script type='text/javascript' charset='utf-8' src='//static.polldaddy.com/p/$1.js'></script><noscript> <a href='http://polldaddy.com/poll/$1/'>View Poll</a></noscript>\n", $content, 'polldaddy.com/poll' );
+ 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
diff --git a/plugins/jetpack/modules/shortcodes/vr.php b/plugins/jetpack/modules/shortcodes/vr.php
index 15906c70..12835b8a 100644
--- a/plugins/jetpack/modules/shortcodes/vr.php
+++ b/plugins/jetpack/modules/shortcodes/vr.php
@@ -97,7 +97,6 @@ function jetpack_vr_viewer_get_html( $url_params ) {
* @return html - complete vr viewer html
*/
function jetpack_vr_viewer_shortcode( $atts ) {
-
$params = shortcode_atts( array(
0 => null,
'url' => null,
@@ -129,3 +128,29 @@ function jetpack_vr_viewer_shortcode( $atts ) {
}
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',
+ ) );
+} \ No newline at end of file
diff --git a/plugins/jetpack/modules/shortcodes/wordads.php b/plugins/jetpack/modules/shortcodes/wordads.php
new file mode 100644
index 00000000..7306eb77
--- /dev/null
+++ b/plugins/jetpack/modules/shortcodes/wordads.php
@@ -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();