PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
← All changes | modules/shortcodes/crowdsignal.php +39 -32 13.3.316.3-a.1 View file →
@@ -22,8 +22,12 @@
22 22
23 23 use Automattic\Jetpack\Assets;
24 24 use Automattic\Jetpack\Constants;
25 25
26 +if ( ! defined( 'ABSPATH' ) ) {
27 + exit( 0 );
28 +}
29 +
26 30 // Keep compatibility with the PollDaddy plugin.
27 31 if (
28 32 ! class_exists( 'CrowdsignalShortcode' )
29 33 && ! class_exists( 'PolldaddyShortcode' )
@@ -29,8 +33,10 @@
29 33 && ! class_exists( 'PolldaddyShortcode' )
30 34 ) {
31 35 /**
32 36 * Class wrapper for Crowdsignal shortcodes
37 + *
38 + * @phan-constructor-used-for-side-effects
33 39 */
34 40 class CrowdsignalShortcode {
35 41
36 42 /**
@@ -55,9 +61,12 @@
55 61
56 62 add_shortcode( 'crowdsignal', array( $this, 'crowdsignal_shortcode' ) );
57 63 add_shortcode( 'polldaddy', array( $this, 'polldaddy_shortcode' ) );
58 64
59 - add_filter( 'pre_kses', array( $this, 'crowdsignal_embed_to_shortcode' ) );
65 + if ( jetpack_shortcodes_should_hook_pre_kses() ) {
66 + add_filter( 'pre_kses', array( $this, 'crowdsignal_embed_to_shortcode' ) );
67 + }
68 +
60 69 add_action( 'infinite_scroll_render', array( $this, 'crowdsignal_shortcode_infinite' ), 11 );
61 70 }
62 71
63 72 /**
@@ -100,15 +109,15 @@
100 109 if ( 'button' === $settings['type'] ) {
101 110 $placeholder = sprintf(
102 111 '<a class="cs-embed pd-embed" href="%1$s" data-settings="%2$s">%3$s</a>',
103 112 esc_url( $survey_url ),
104 - esc_attr( wp_json_encode( $settings ) ),
113 + esc_attr( wp_json_encode( $settings, JSON_HEX_AMP | JSON_UNESCAPED_SLASHES ) ),
105 114 esc_html( $settings['title'] )
106 115 );
107 116 } else {
108 117 $placeholder = sprintf(
109 118 '<div class="cs-embed pd-embed" data-settings="%1$s"></div><noscript>%2$s</noscript>',
110 - esc_attr( wp_json_encode( $settings ) ),
119 + esc_attr( wp_json_encode( $settings, JSON_HEX_AMP | JSON_UNESCAPED_SLASHES ) ),
111 120 $survey_link
112 121 );
113 122 }
114 123
@@ -218,9 +227,8 @@
218 227
219 228 $inline = ! in_the_loop()
220 229 && ! Constants::is_defined( 'TESTING_IN_JETPACK' );
221 230
222 - $no_script = false;
223 231 $infinite_scroll = false;
224 232
225 233 if ( is_home() && current_theme_supports( 'infinite-scroll' ) ) {
226 234 $infinite_scroll = true;
@@ -229,34 +237,37 @@
229 237 if ( function_exists( 'get_option' ) && get_option( 'polldaddy_load_poll_inline' ) ) {
230 238 $inline = true;
231 239 }
232 240
233 - if ( is_feed() || ( defined( 'DOING_AJAX' ) && ! $infinite_scroll ) ) {
234 - $no_script = false;
235 - }
236 -
237 241 self::$add_script = $infinite_scroll;
238 242
239 243 /*
240 244 * Rating embed.
241 245 */
242 - if ( (int) $attributes['rating'] > 0 && ! $no_script ) {
246 + if ( (int) $attributes['rating'] > 0 ) {
247 + $post_id = $post instanceof WP_Post ? $post->ID : get_the_ID();
248 + $post_id ??= '';
243 249
244 250 if ( empty( $attributes['unique_id'] ) ) {
245 - $attributes['unique_id'] = is_page() ? 'wp-page-' . $post->ID : 'wp-post-' . $post->ID;
251 + $attributes['unique_id'] = is_page() ? 'wp-page-' . $post_id : 'wp-post-' . $post_id;
246 252 }
247 253
248 254 if ( empty( $attributes['item_id'] ) ) {
249 - $attributes['item_id'] = is_page() ? '_page_' . $post->ID : '_post_' . $post->ID;
255 + $attributes['item_id'] = is_page() ? '_page_' . $post_id : '_post_' . $post_id;
250 256 }
251 257
252 258 if ( empty( $attributes['title'] ) ) {
259 + $title = $post instanceof WP_Post ? $post->post_title : get_the_title();
253 260 /** This filter is documented in core/src/wp-includes/general-template.php */
254 - $attributes['title'] = apply_filters( 'wp_title', $post->post_title, '', '' );
261 + $attributes['title'] = apply_filters( 'wp_title', $title, '', '' );
255 262 }
256 263
257 264 if ( empty( $attributes['permalink'] ) ) {
258 - $attributes['permalink'] = get_permalink( $post->ID );
265 + if ( $post_id ) {
266 + $attributes['permalink'] = get_permalink( $post_id );
267 + } else {
268 + $attributes['permalink'] = home_url( add_query_arg( array() ) );
269 + }
259 270 }
260 271
261 272 $rating = (int) $attributes['rating'];
262 273 $unique_id = sanitize_key( wp_strip_all_tags( $attributes['unique_id'] ) );
@@ -269,13 +280,12 @@
269 280 'unique_id' => $unique_id,
270 281 'title' => rawurlencode( trim( $attributes['title'] ) ),
271 282 'permalink' => esc_url( $attributes['permalink'] ),
272 283 'item_id' => $item_id,
273 - )
284 + ),
285 + JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP
274 286 );
275 287
276 - $item_id = esc_js( $item_id );
277 -
278 288 if (
279 289 class_exists( 'Jetpack_AMP_Support' )
280 290 && Jetpack_AMP_Support::is_amp_request()
281 291 ) {
@@ -320,9 +330,9 @@
320 330 return sprintf(
321 331 '<div class="cs-rating pd-rating" id="pd_rating_holder_%1$d%2$s" data-settings="%3$s"></div>',
322 332 absint( $rating ),
323 333 esc_attr( $item_id ),
324 - esc_attr( wp_json_encode( $data ) )
334 + esc_attr( wp_json_encode( $data, JSON_HEX_AMP | JSON_UNESCAPED_SLASHES ) )
325 335 );
326 336 } else {
327 337 return sprintf(
328 338 '<div class="cs-rating pd-rating" id="pd_rating_holder_%1$d%2$s"></div>',
@@ -354,12 +364,9 @@
354 364 esc_url( $poll_url ),
355 365 esc_html( $attributes['title'] )
356 366 );
357 367
358 - if (
359 - $no_script
360 - || ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() )
361 - ) {
368 + if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
362 369 return $poll_link;
363 370 } elseif ( 'slider' === $attributes['type'] && ! $inline ) { // Slider poll.
364 371 if ( ! in_array(
365 372 $attributes['visit'],
@@ -373,9 +380,9 @@
373 380 'type' => 'slider',
374 381 'embed' => 'poll',
375 382 'delay' => (int) $attributes['delay'],
376 383 'visit' => $attributes['visit'],
377 - 'id' => (int) $poll,
384 + 'id' => $poll,
378 385 'site' => $attributes['site'],
379 386 );
380 387
381 388 return $this->get_async_code( $settings, $poll_link, $poll_url );
@@ -395,11 +402,11 @@
395 402 ) ) {
396 403 $float = sprintf( 'float: %s;', $attributes['align'] );
397 404
398 405 if ( 'left' === $attributes['align'] ) {
399 - $margins = 'margin: 0px 10px 0px 0px;';
406 + $margins = 'margin: 0 10px 0 0;';
400 407 } elseif ( 'right' === $attributes['align'] ) {
401 - $margins = 'margin: 0px 0px 0px 10px';
408 + $margins = 'margin: 0 0 0 10px';
402 409 }
403 410 }
404 411
405 412 /*
@@ -417,9 +424,9 @@
417 424 }
418 425
419 426 $data = array( 'url' => $poll_js );
420 427
421 - self::$scripts['poll'][ (int) $poll ] = $data;
428 + self::$scripts['poll'][ $poll ] = $data;
422 429
423 430 add_action( 'wp_footer', array( $this, 'generate_scripts' ) );
424 431
425 432 wp_enqueue_script( 'crowdsignal-shortcode' );
@@ -442,14 +449,14 @@
442 449 * @since 8.4.0
443 450 *
444 451 * @param int $poll Poll ID.
445 452 */
446 - do_action( 'crowdsignal_shortcode_before', (int) $poll );
453 + do_action( 'crowdsignal_shortcode_before', $poll );
447 454
448 455 return sprintf(
449 456 '<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>',
450 457 absint( $poll ),
451 - esc_attr( wp_json_encode( $data ) ),
458 + esc_attr( wp_json_encode( $data, JSON_HEX_AMP | JSON_UNESCAPED_SLASHES ) ),
452 459 $float,
453 460 $margins,
454 461 $poll_link
455 462 );
@@ -466,9 +473,9 @@
466 473 true
467 474 );
468 475
469 476 /** This action is already documented in modules/shortcodes/crowdsignal.php */
470 - do_action( 'crowdsignal_shortcode_before', (int) $poll );
477 + do_action( 'crowdsignal_shortcode_before', $poll );
471 478
472 479 return sprintf(
473 480 '<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>',
474 481 absint( $poll ),
@@ -541,9 +548,9 @@
541 548 ) {
542 549 $attributes['width'] = $content_width;
543 550 }
544 551
545 - if ( ! $attributes['width'] ) {
552 + if ( empty( $attributes['width'] ) ) {
546 553 $attributes['width'] = '100%';
547 554 } else {
548 555 $attributes['width'] = (int) $attributes['width'];
549 556 }
@@ -638,9 +645,9 @@
638 645 'text_color' => $text_color,
639 646 'back_color' => $back_color,
640 647 'align' => $attributes['align'],
641 648 'style' => $attributes['style'],
642 - 'id' => $survey,
649 + 'id' => $survey ?? null,
643 650 'site' => $attributes['site'],
644 651 )
645 652 );
646 653 }
@@ -743,10 +750,10 @@
743 750 $content
744 751 );
745 752
746 753 // Replace survey.fm links.
747 - $content = preg_replace(
748 - '!(?:\n|\A)https?://(.*).survey.fm/(.*)(/.*)?(?:\n|\Z)!i',
754 + $content = jetpack_preg_replace_outside_tags(
755 + '!(?:\n|\A)https?:\/\/([^"\'.]+)\.survey\.fm\/([^"\'\/\s]+)(?:\/.*)?(?:\n|\Z)!i',
749 756 '[crowdsignal type="iframe" survey="true" height="auto" domain="$1" id="$2"]',
750 757 $content
751 758 );
752 759