summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/shortcodes/crowdsignal.php')
-rw-r--r--plugins/jetpack/modules/shortcodes/crowdsignal.php90
1 files changed, 50 insertions, 40 deletions
diff --git a/plugins/jetpack/modules/shortcodes/crowdsignal.php b/plugins/jetpack/modules/shortcodes/crowdsignal.php
index 04177919..145a7fba 100644
--- a/plugins/jetpack/modules/shortcodes/crowdsignal.php
+++ b/plugins/jetpack/modules/shortcodes/crowdsignal.php
@@ -15,7 +15,7 @@
* [crowdsignal poll=9541291 type=slider]
* [crowdsignal rating=8755352]
*
- * @package Jetpack
+ * @package automattic/jetpack
*/
use Automattic\Jetpack\Assets;
@@ -238,7 +238,7 @@ if (
/*
* Rating embed.
*/
- if ( intval( $attributes['rating'] ) > 0 && ! $no_script ) {
+ if ( (int) $attributes['rating'] > 0 && ! $no_script ) {
if ( empty( $attributes['unique_id'] ) ) {
$attributes['unique_id'] = is_page() ? 'wp-page-' . $post->ID : 'wp-post-' . $post->ID;
@@ -257,7 +257,7 @@ if (
$attributes['permalink'] = get_permalink( $post->ID );
}
- $rating = intval( $attributes['rating'] );
+ $rating = (int) $attributes['rating'];
$unique_id = preg_replace( '/[^\-_a-z0-9]/i', '', wp_strip_all_tags( $attributes['unique_id'] ) );
$item_id = wp_strip_all_tags( $attributes['item_id'] );
$item_id = preg_replace( '/[^_a-z0-9]/i', '', $item_id );
@@ -330,7 +330,7 @@ if (
);
}
}
- } elseif ( intval( $attributes['poll'] ) > 0 ) {
+ } elseif ( (int) $attributes['poll'] > 0 ) {
/*
* Poll embed.
*/
@@ -339,7 +339,7 @@ if (
$attributes['title'] = esc_html__( 'Take Our Poll', 'jetpack' );
}
- $poll = intval( $attributes['poll'] );
+ $poll = (int) $attributes['poll'];
if ( 'crowdsignal.com' === $attributes['site'] ) {
$poll_url = sprintf( 'https://poll.fm/%d', $poll );
@@ -379,16 +379,16 @@ if (
$settings = array(
'type' => 'slider',
'embed' => 'poll',
- 'delay' => intval( $attributes['delay'] ),
+ 'delay' => (int) $attributes['delay'],
'visit' => $attributes['visit'],
- 'id' => intval( $poll ),
+ 'id' => (int) $poll,
'site' => $attributes['site'],
);
return $this->get_async_code( $settings, $poll_link, $poll_url );
} else {
if ( 1 === $attributes['cb'] ) {
- $attributes['cb'] = '?cb=' . mktime();
+ $attributes['cb'] = '?cb=' . time();
} else {
$attributes['cb'] = false;
}
@@ -425,7 +425,7 @@ if (
$data = array( 'url' => $poll_js );
- self::$scripts['poll'][ intval( $poll ) ] = $data;
+ self::$scripts['poll'][ (int) $poll ] = $data;
add_action( 'wp_footer', array( $this, 'generate_scripts' ) );
@@ -443,8 +443,17 @@ if (
)
);
+ /**
+ * Hook into the Crowdsignal shortcode before rendering.
+ *
+ * @since 8.4.0
+ *
+ * @param int $poll Poll ID.
+ */
+ do_action( 'crowdsignal_shortcode_before', (int) $poll );
+
return sprintf(
- '<a name="pd_a_%1$d"></a><div class="CSS_Poll PDS_Poll" id="PDI_container%1$d" data-settings="%2$s" style="display:inline-block;%3$s%4$s"></div><div id="PD_superContainer"></div><noscript>%5$s</noscript>',
+ '<a name="pd_a_%1$d"></a><div class="CSS_Poll PDS_Poll" id="PDI_container%1$d" data-settings="%2$s" style="%3$s%4$s"></div><div id="PD_superContainer"></div><noscript>%5$s</noscript>',
absint( $poll ),
esc_attr( wp_json_encode( $data ) ),
$float,
@@ -464,8 +473,11 @@ if (
true
);
+ /** This action is already documented in modules/shortcodes/crowdsignal.php */
+ do_action( 'crowdsignal_shortcode_before', (int) $poll );
+
return sprintf(
- '<a id="pd_a_%1$s"></a><div class="CSS_Poll PDS_Poll" id="PDI_container%1$s" style="display:inline-block;%2$s%3$s"></div><div id="PD_superContainer"></div><noscript>%4$s</noscript>',
+ '<a id="pd_a_%1$s"></a><div class="CSS_Poll PDS_Poll" id="PDI_container%1$s" style="%2$s%3$s"></div><div id="PD_superContainer"></div><noscript>%4$s</noscript>',
absint( $poll ),
$float,
$margins,
@@ -499,12 +511,20 @@ if (
$inline = false;
}
- $survey = preg_replace( '/[^a-f0-9]/i', '', $attributes['survey'] );
+ $survey_url = '';
+
+ if ( 'true' !== $attributes['survey'] ) {
+ $survey = preg_replace( '/[^a-f0-9]/i', '', $attributes['survey'] );
- if ( 'crowdsignal.com' === $attributes['site'] ) {
- $survey_url = 'https://survey.fm/' . $survey;
+ if ( 'crowdsignal.com' === $attributes['site'] ) {
+ $survey_url = 'https://survey.fm/' . $survey;
+ } else {
+ $survey_url = 'https://polldaddy.com/s/' . $survey;
+ }
} else {
- $survey_url = 'https://polldaddy.com/s/' . $survey;
+ if ( isset( $attributes['domain'] ) && isset( $attributes['id'] ) ) {
+ $survey_url = 'https://' . $attributes['domain'] . '.survey.fm/' . $attributes['id'];
+ }
}
$survey_link = sprintf(
@@ -515,16 +535,6 @@ if (
$settings = array();
- // Do we want a full embed code or a link?
- if (
- $no_script
- || $inline
- || $infinite_scroll
- || ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() )
- ) {
- return $survey_link;
- }
-
if ( 'iframe' === $attributes['type'] ) {
if ( 'auto' !== $attributes['height'] ) {
if (
@@ -729,8 +739,8 @@ if (
if ( ! function_exists( 'crowdsignal_link' ) ) {
/**
- * Replace link by embed.
- * Example: http://polldaddy.com/poll/1562975/?view=results&msg=voted
+ * Replace link with shortcode.
+ * Examples: https://poll.fm/10499328 | https://7iger.survey.fm/test-embed
*
* @param string $content Post content.
*/
@@ -742,25 +752,25 @@ if (
return $content;
}
- return jetpack_preg_replace_outside_tags(
+ // Replace poll links.
+ $content = jetpack_preg_replace_outside_tags(
'!(?:\n|\A)https?://(polldaddy\.com/poll|poll\.fm)/([0-9]+?)(/.*)?(?:\n|\Z)!i',
- "\n<script type='text/javascript' charset='utf-8' src='//static.polldaddy.com/p/$2.js'></script><noscript> <a href='https://poll.fm/$2'>View Poll</a></noscript>\n", // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
- $content,
- 'polldaddy.com/poll'
+ '[crowdsignal poll=$2]',
+ $content
+ );
+
+ // Replace survey.fm links.
+ $content = preg_replace(
+ '!(?:\n|\A)https?://(.*).survey.fm/(.*)(/.*)?(?:\n|\Z)!i',
+ '[crowdsignal type="iframe" survey="true" height="auto" domain="$1" id="$2"]',
+ $content
);
+
+ return $content;
}
// higher priority because we need it before auto-link and autop get to it.
add_filter( 'the_content', 'crowdsignal_link', 1 );
add_filter( 'the_content_rss', 'crowdsignal_link', 1 );
}
-
- /**
- * Note that Core has the oembed of '#https?://survey\.fm/.*#i' as of 5.1.
- * This should be removed after Core has the current regex is in our minimum version.
- *
- * @see https://core.trac.wordpress.org/ticket/46467
- * @todo Remove once 5.2 is the minimum version.
- */
- wp_oembed_add_provider( '#https?://.+\.survey\.fm/.*#i', 'https://api.crowdsignal.com/oembed', true );
}