| 1 |
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 |
/** |
| 3 |
* Module: Comments |
| 4 |
* |
| 5 |
* @package automattic/jetpack |
| 6 |
*/ |
| 7 |
|
| 8 |
require __DIR__ . '/base.php'; |
| 9 |
use Automattic\Jetpack\Connection\Tokens; |
| 10 |
|
| 11 |
/** |
| 12 |
* Main Comments class |
| 13 |
* |
| 14 |
* @package automattic/jetpack |
| 15 |
* @version 1.4 |
| 16 |
* @since 1.4 |
| 17 |
*/ |
| 18 |
class Jetpack_Comments extends Highlander_Comments_Base { |
| 19 |
|
| 20 |
/** Variables *************************************************************/ |
| 21 |
|
| 22 |
/** |
| 23 |
* Possible comment form sources - empty array as default |
| 24 |
* |
| 25 |
* @var array |
| 26 |
*/ |
| 27 |
public $id_sources = array(); |
| 28 |
|
| 29 |
/** |
| 30 |
* Remote comment URL - empty string as default |
| 31 |
* |
| 32 |
* @var string |
| 33 |
*/ |
| 34 |
public $signed_url = ''; |
| 35 |
|
| 36 |
/** |
| 37 |
* The default comment form color scheme - default is light |
| 38 |
* |
| 39 |
* @var string |
| 40 |
* @see ::set_default_color_theme_based_on_theme_settings() |
| 41 |
*/ |
| 42 |
public $default_color_scheme = 'light'; |
| 43 |
|
| 44 |
/** Methods ***************************************************************/ |
| 45 |
|
| 46 |
/** |
| 47 |
* Initialize class |
| 48 |
*/ |
| 49 |
public static function init() { |
| 50 |
static $instance = false; |
| 51 |
|
| 52 |
if ( ! $instance ) { |
| 53 |
$instance = new Jetpack_Comments(); |
| 54 |
} |
| 55 |
|
| 56 |
return $instance; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Main constructor for Comments |
| 61 |
* |
| 62 |
* @since JetpackComments (1.4) |
| 63 |
*/ |
| 64 |
public function __construct() { |
| 65 |
parent::__construct(); |
| 66 |
|
| 67 |
// Comments is loaded. |
| 68 |
|
| 69 |
/** |
| 70 |
* Fires after the Jetpack_Comments object has been instantiated |
| 71 |
* |
| 72 |
* @module comments |
| 73 |
* |
| 74 |
* @since 1.4.0 |
| 75 |
* |
| 76 |
* @param array $jetpack_comments_loaded First element in array of type Jetpack_Comments |
| 77 |
*/ |
| 78 |
do_action_ref_array( 'jetpack_comments_loaded', array( $this ) ); |
| 79 |
add_action( 'after_setup_theme', array( $this, 'set_default_color_theme_based_on_theme_settings' ), 100 ); |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Set the default comments color theme based on theme settings |
| 84 |
*/ |
| 85 |
public function set_default_color_theme_based_on_theme_settings() { |
| 86 |
if ( function_exists( 'twentyeleven_get_theme_options' ) ) { |
| 87 |
$theme_options = twentyeleven_get_theme_options(); |
| 88 |
$theme_color_scheme = isset( $theme_options['color_scheme'] ) ? $theme_options['color_scheme'] : 'transparent'; |
| 89 |
} else { |
| 90 |
$theme_color_scheme = get_theme_mod( 'color_scheme', 'transparent' ); |
| 91 |
} |
| 92 |
// Default for $theme_color_scheme is 'transparent' just so it doesn't match 'light' or 'dark'. |
| 93 |
// The default for Jetpack's color scheme is still defined above as 'light'. |
| 94 |
|
| 95 |
if ( false !== stripos( $theme_color_scheme, 'light' ) ) { |
| 96 |
$this->default_color_scheme = 'light'; |
| 97 |
} elseif ( false !== stripos( $theme_color_scheme, 'dark' ) ) { |
| 98 |
$this->default_color_scheme = 'dark'; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
/** Private Methods *******************************************************/ |
| 103 |
|
| 104 |
/** |
| 105 |
* Set any global variables or class variables |
| 106 |
* |
| 107 |
* This is primarily defining the comment form sources. |
| 108 |
* |
| 109 |
* @since JetpackComments (1.4) |
| 110 |
*/ |
| 111 |
protected function setup_globals() { |
| 112 |
parent::setup_globals(); |
| 113 |
|
| 114 |
// Sources. |
| 115 |
$this->id_sources = array( |
| 116 |
'guest', |
| 117 |
'jetpack', |
| 118 |
'wordpress', |
| 119 |
'twitter', |
| 120 |
'facebook', |
| 121 |
); |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Setup actions for methods in this class |
| 126 |
* |
| 127 |
* @since JetpackComments (1.4) |
| 128 |
*/ |
| 129 |
protected function setup_actions() { |
| 130 |
parent::setup_actions(); |
| 131 |
|
| 132 |
// Selfishly remove everything from the existing comment form. |
| 133 |
remove_all_actions( 'comment_form_before' ); |
| 134 |
|
| 135 |
// Selfishly add only our actions back to the comment form. |
| 136 |
add_action( 'comment_form_before', array( $this, 'comment_form_before' ) ); |
| 137 |
add_action( 'comment_form_after', array( $this, 'comment_form_after' ), 1 ); // Set very early since we remove everything outputed before our action. |
| 138 |
|
| 139 |
// Before a comment is posted. |
| 140 |
add_action( 'pre_comment_on_post', array( $this, 'pre_comment_on_post' ), 1 ); |
| 141 |
|
| 142 |
// After a comment is posted. |
| 143 |
add_action( 'comment_post', array( $this, 'add_comment_meta' ) ); |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Setup filters for methods in this class |
| 148 |
* |
| 149 |
* @since 1.6.2 |
| 150 |
*/ |
| 151 |
protected function setup_filters() { |
| 152 |
parent::setup_filters(); |
| 153 |
|
| 154 |
add_filter( 'comment_post_redirect', array( $this, 'capture_comment_post_redirect_to_reload_parent_frame' ), 100 ); |
| 155 |
add_filter( 'get_avatar', array( $this, 'get_avatar' ), 10, 4 ); |
| 156 |
} |
| 157 |
|
| 158 |
/** |
| 159 |
* Get the comment avatar from Gravatar, Twitter, or Facebook |
| 160 |
* |
| 161 |
* @since JetpackComments (1.4) |
| 162 |
* |
| 163 |
* @param string $avatar Current avatar URL. |
| 164 |
* @param string $comment Comment for the avatar. |
| 165 |
* @param int $size Size of the avatar. |
| 166 |
* |
| 167 |
* @return string New avatar |
| 168 |
*/ |
| 169 |
public function get_avatar( $avatar, $comment, $size ) { |
| 170 |
if ( ! isset( $comment->comment_post_ID ) || ! isset( $comment->comment_ID ) ) { |
| 171 |
// it's not a comment - bail. |
| 172 |
return $avatar; |
| 173 |
} |
| 174 |
|
| 175 |
// Detect whether it's a Facebook or Twitter avatar. |
| 176 |
$foreign_avatar = get_comment_meta( $comment->comment_ID, 'hc_avatar', true ); |
| 177 |
$foreign_avatar_hostname = wp_parse_url( $foreign_avatar, PHP_URL_HOST ); |
| 178 |
if ( ! $foreign_avatar_hostname || |
| 179 |
! preg_match( '/\.?(graph\.facebook\.com|twimg\.com)$/', $foreign_avatar_hostname ) ) { |
| 180 |
return $avatar; |
| 181 |
} |
| 182 |
|
| 183 |
// Return the Facebook or Twitter avatar. |
| 184 |
return preg_replace( '#src=([\'"])[^\'"]+\\1#', 'src=\\1' . esc_url( set_url_scheme( $this->photon_avatar( $foreign_avatar, $size ), 'https' ) ) . '\\1', $avatar ); |
| 185 |
} |
| 186 |
|
| 187 |
/** Output Methods ********************************************************/ |
| 188 |
|
| 189 |
/** |
| 190 |
* Start capturing the core comment_form() output |
| 191 |
* |
| 192 |
* Comment form output will only be captured if comments are enabled - we return otherwise. |
| 193 |
* |
| 194 |
* @since JetpackComments (1.4) |
| 195 |
*/ |
| 196 |
public function comment_form_before() { |
| 197 |
/** |
| 198 |
* Filters the setting that determines if Jetpack comments should be enabled for |
| 199 |
* the current post type. |
| 200 |
* |
| 201 |
* @module comments |
| 202 |
* |
| 203 |
* @since 3.8.1 |
| 204 |
* |
| 205 |
* @param boolean $return Should comments be enabled? |
| 206 |
*/ |
| 207 |
if ( ! apply_filters( 'jetpack_comment_form_enabled_for_' . get_post_type(), true ) ) { |
| 208 |
return; |
| 209 |
} |
| 210 |
|
| 211 |
// Add some JS to the footer. |
| 212 |
add_action( 'wp_footer', array( $this, 'watch_comment_parent' ), 100 ); |
| 213 |
|
| 214 |
ob_start(); |
| 215 |
} |
| 216 |
|
| 217 |
/** |
| 218 |
* Noop the default comment form output, get some options, and output our |
| 219 |
* tricked out totally radical comment form. |
| 220 |
* |
| 221 |
* @since JetpackComments (1.4) |
| 222 |
*/ |
| 223 |
public function comment_form_after() { |
| 224 |
/** This filter is documented in modules/comments/comments.php */ |
| 225 |
if ( ! apply_filters( 'jetpack_comment_form_enabled_for_' . get_post_type(), true ) ) { |
| 226 |
return; |
| 227 |
} |
| 228 |
|
| 229 |
// Throw it all out and drop in our replacement. |
| 230 |
ob_end_clean(); |
| 231 |
|
| 232 |
// If users are required to be logged in, and they're not, then we don't need to do anything else. |
| 233 |
if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) { |
| 234 |
/** |
| 235 |
* Changes the log in to comment prompt. |
| 236 |
* |
| 237 |
* @module comments |
| 238 |
* |
| 239 |
* @since 1.4.0 |
| 240 |
* |
| 241 |
* @param string $var Default is "You must log in to post a comment." |
| 242 |
*/ |
| 243 |
echo '<p class="must-log-in">' . wp_kses_post( |
| 244 |
sprintf( |
| 245 |
apply_filters( |
| 246 |
'jetpack_must_log_in_to_comment', |
| 247 |
/* translators: %s is the wp-login URL for the site */ |
| 248 |
__( 'You must <a href="%s">log in</a> to post a comment.', 'jetpack' ) |
| 249 |
), |
| 250 |
wp_login_url( get_permalink() . '#respond' ) |
| 251 |
) |
| 252 |
) . '</p>'; |
| 253 |
return; |
| 254 |
} |
| 255 |
|
| 256 |
if ( in_array( 'subscriptions', Jetpack::get_active_modules(), true ) ) { |
| 257 |
$stb_enabled = get_option( 'stb_enabled', 1 ); |
| 258 |
$stb_enabled = empty( $stb_enabled ) ? 0 : 1; |
| 259 |
|
| 260 |
$stc_enabled = get_option( 'stc_enabled', 1 ); |
| 261 |
$stc_enabled = empty( $stc_enabled ) ? 0 : 1; |
| 262 |
} else { |
| 263 |
$stb_enabled = 0; |
| 264 |
$stc_enabled = 0; |
| 265 |
} |
| 266 |
|
| 267 |
$params = array( |
| 268 |
'blogid' => Jetpack_Options::get_option( 'id' ), |
| 269 |
'postid' => get_the_ID(), |
| 270 |
'comment_registration' => ( get_option( 'comment_registration' ) ? '1' : '0' ), // Need to explicitly send a '1' or a '0' for these. |
| 271 |
'require_name_email' => ( get_option( 'require_name_email' ) ? '1' : '0' ), |
| 272 |
'stc_enabled' => $stc_enabled, |
| 273 |
'stb_enabled' => $stb_enabled, |
| 274 |
'show_avatars' => ( get_option( 'show_avatars' ) ? '1' : '0' ), |
| 275 |
'avatar_default' => get_option( 'avatar_default' ), |
| 276 |
'greeting' => get_option( 'highlander_comment_form_prompt', __( 'Leave a Reply', 'jetpack' ) ), |
| 277 |
/** |
| 278 |
* Changes the comment form prompt. |
| 279 |
* |
| 280 |
* @module comments |
| 281 |
* |
| 282 |
* @since 2.3.0 |
| 283 |
* |
| 284 |
* @param string $var Default is "Leave a Reply to %s." |
| 285 |
*/ |
| 286 |
'greeting_reply' => apply_filters( |
| 287 |
'jetpack_comment_form_prompt_reply', |
| 288 |
/* translators: %s is the displayed username of the post (or comment) author */ |
| 289 |
__( 'Leave a Reply to %s', 'jetpack' ) |
| 290 |
), |
| 291 |
'color_scheme' => get_option( 'jetpack_comment_form_color_scheme', $this->default_color_scheme ), |
| 292 |
'lang' => get_locale(), |
| 293 |
'jetpack_version' => JETPACK__VERSION, |
| 294 |
); |
| 295 |
|
| 296 |
// Extra parameters for logged in user. |
| 297 |
if ( is_user_logged_in() ) { |
| 298 |
$current_user = wp_get_current_user(); |
| 299 |
$params['hc_post_as'] = 'jetpack'; |
| 300 |
$params['hc_userid'] = $current_user->ID; |
| 301 |
$params['hc_username'] = $current_user->display_name; |
| 302 |
$params['hc_userurl'] = $current_user->user_url; |
| 303 |
$params['hc_useremail'] = md5( strtolower( trim( $current_user->user_email ) ) ); |
| 304 |
if ( current_user_can( 'unfiltered_html' ) ) { |
| 305 |
$params['_wp_unfiltered_html_comment'] = wp_create_nonce( 'unfiltered-html-comment_' . get_the_ID() ); |
| 306 |
} |
| 307 |
} else { |
| 308 |
$commenter = wp_get_current_commenter(); |
| 309 |
$params['show_cookie_consent'] = (int) has_action( 'set_comment_cookies', 'wp_set_comment_cookies' ); |
| 310 |
$params['has_cookie_consent'] = (int) ! empty( $commenter['comment_author_email'] ); |
| 311 |
} |
| 312 |
|
| 313 |
$blog_token = ( new Tokens() )->get_access_token(); |
| 314 |
list( $token_key ) = explode( '.', $blog_token->secret, 2 ); |
| 315 |
// Prophylactic check: anything else should never happen. |
| 316 |
if ( $token_key && $token_key !== $blog_token->secret ) { |
| 317 |
// Is the token a Special Token (@see class.tokens.php)? |
| 318 |
if ( preg_match( '/^;.\d+;\d+;$/', $token_key, $matches ) ) { |
| 319 |
// The token key for a Special Token is public. |
| 320 |
$params['token_key'] = $token_key; |
| 321 |
} else { |
| 322 |
/* |
| 323 |
* The token key for a Normal Token is public but |
| 324 |
* looks like sensitive data. Since there can only be |
| 325 |
* one Normal Token per site, avoid concern by |
| 326 |
* sending the magic "use the Normal Token" token key. |
| 327 |
*/ |
| 328 |
$params['token_key'] = Tokens::MAGIC_NORMAL_TOKEN_KEY; |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
$signature = self::sign_remote_comment_parameters( $params, $blog_token->secret ); |
| 333 |
if ( is_wp_error( $signature ) ) { |
| 334 |
$signature = 'error'; |
| 335 |
} |
| 336 |
|
| 337 |
$params['sig'] = $signature; |
| 338 |
$url_origin = 'https://jetpack.wordpress.com'; |
| 339 |
$url = "{$url_origin}/jetpack-comment/?" . http_build_query( $params ); |
| 340 |
$url = "{$url}#parent=" . rawurlencode( set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) ); |
| 341 |
$this->signed_url = $url; |
| 342 |
$height = $params['comment_registration'] || is_user_logged_in() ? '315' : '430'; // Iframe can be shorter if we're not allowing guest commenting. |
| 343 |
$transparent = ( 'transparent' === $params['color_scheme'] ) ? 'true' : 'false'; |
| 344 |
|
| 345 |
if ( isset( $_GET['replytocom'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 346 |
$url .= '&replytocom=' . (int) $_GET['replytocom']; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 347 |
} |
| 348 |
|
| 349 |
/** |
| 350 |
* Filter whether the comment title can be displayed. |
| 351 |
* |
| 352 |
* @module comments |
| 353 |
* |
| 354 |
* @since 4.7.0 |
| 355 |
* |
| 356 |
* @param bool $show Can the comment be displayed? Default to true. |
| 357 |
*/ |
| 358 |
$show_greeting = apply_filters( 'jetpack_comment_form_display_greeting', true ); |
| 359 |
|
| 360 |
// The actual iframe (loads comment form from Jetpack server). |
| 361 |
|
| 362 |
$is_amp = Jetpack_AMP_Support::is_amp_request(); |
| 363 |
?> |
| 364 |
|
| 365 |
<div id="respond" class="comment-respond"> |
| 366 |
<?php if ( true === $show_greeting ) : ?> |
| 367 |
<h3 id="reply-title" class="comment-reply-title"><?php comment_form_title( esc_html( $params['greeting'] ), esc_html( $params['greeting_reply'] ) ); ?> |
| 368 |
<small><?php cancel_comment_reply_link( esc_html__( 'Cancel reply', 'jetpack' ) ); ?></small> |
| 369 |
</h3> |
| 370 |
<?php endif; ?> |
| 371 |
<form id="commentform" class="comment-form"> |
| 372 |
<iframe |
| 373 |
title="<?php esc_attr_e( 'Comment Form', 'jetpack' ); ?>" |
| 374 |
src="<?php echo esc_url( $url ); ?>" |
| 375 |
<?php if ( $is_amp ) : ?> |
| 376 |
resizable |
| 377 |
layout="fixed-height" |
| 378 |
height="<?php echo esc_attr( $height ); ?>" |
| 379 |
<?php else : ?> |
| 380 |
name="jetpack_remote_comment" |
| 381 |
style="width:100%; height: <?php echo esc_attr( $height ); ?>px; border:0;" |
| 382 |
<?php endif; ?> |
| 383 |
class="jetpack_remote_comment" |
| 384 |
id="jetpack_remote_comment" |
| 385 |
sandbox="allow-same-origin allow-top-navigation allow-scripts allow-forms allow-popups" |
| 386 |
> |
| 387 |
<?php if ( $is_amp ) : ?> |
| 388 |
<button overflow><?php esc_html_e( 'Show more', 'jetpack' ); ?></button> |
| 389 |
<?php endif; ?> |
| 390 |
</iframe> |
| 391 |
<?php if ( ! $is_amp ) : ?> |
| 392 |
<!--[if !IE]><!--> |
| 393 |
<script> |
| 394 |
document.addEventListener('DOMContentLoaded', function () { |
| 395 |
var commentForms = document.getElementsByClassName('jetpack_remote_comment'); |
| 396 |
for (var i = 0; i < commentForms.length; i++) { |
| 397 |
commentForms[i].allowTransparency = <?php echo esc_html( $transparent ); ?>; |
| 398 |
commentForms[i].scrolling = 'no'; |
| 399 |
} |
| 400 |
}); |
| 401 |
</script> |
| 402 |
<!--<![endif]--> |
| 403 |
<?php endif; ?> |
| 404 |
</form> |
| 405 |
</div> |
| 406 |
|
| 407 |
<?php // Below is required for comment reply JS to work. ?> |
| 408 |
|
| 409 |
<input type="hidden" name="comment_parent" id="comment_parent" value="" /> |
| 410 |
|
| 411 |
<?php |
| 412 |
} |
| 413 |
|
| 414 |
/** |
| 415 |
* Add some JS to wp_footer to watch for hierarchical reply parent change |
| 416 |
* |
| 417 |
* If AMP is enabled, we don't make any changes. |
| 418 |
* |
| 419 |
* @since JetpackComments (1.4) |
| 420 |
*/ |
| 421 |
public function watch_comment_parent() { |
| 422 |
if ( Jetpack_AMP_Support::is_amp_request() ) { |
| 423 |
// @todo Implement AMP support. |
| 424 |
return; |
| 425 |
} |
| 426 |
|
| 427 |
$url_origin = 'https://jetpack.wordpress.com'; |
| 428 |
?> |
| 429 |
|
| 430 |
<!--[if IE]> |
| 431 |
<script type="text/javascript"> |
| 432 |
if ( 0 === window.location.hash.indexOf( '#comment-' ) ) { |
| 433 |
// window.location.reload() doesn't respect the Hash in IE |
| 434 |
window.location.hash = window.location.hash; |
| 435 |
} |
| 436 |
</script> |
| 437 |
<![endif]--> |
| 438 |
<script type="text/javascript"> |
| 439 |
(function () { |
| 440 |
var comm_par_el = document.getElementById( 'comment_parent' ), |
| 441 |
comm_par = ( comm_par_el && comm_par_el.value ) ? comm_par_el.value : '', |
| 442 |
frame = document.getElementById( 'jetpack_remote_comment' ), |
| 443 |
tellFrameNewParent; |
| 444 |
|
| 445 |
tellFrameNewParent = function () { |
| 446 |
if ( comm_par ) { |
| 447 |
frame.src = "<?php echo esc_url_raw( $this->signed_url ); ?>" + '&replytocom=' + parseInt( comm_par, 10 ).toString(); |
| 448 |
} else { |
| 449 |
frame.src = "<?php echo esc_url_raw( $this->signed_url ); ?>"; |
| 450 |
} |
| 451 |
}; |
| 452 |
|
| 453 |
<?php if ( get_option( 'thread_comments' ) && get_option( 'thread_comments_depth' ) ) : ?> |
| 454 |
|
| 455 |
if ( 'undefined' !== typeof addComment ) { |
| 456 |
addComment._Jetpack_moveForm = addComment.moveForm; |
| 457 |
|
| 458 |
addComment.moveForm = function ( commId, parentId, respondId, postId ) { |
| 459 |
var returnValue = addComment._Jetpack_moveForm( commId, parentId, respondId, postId ), |
| 460 |
cancelClick, cancel; |
| 461 |
|
| 462 |
if ( false === returnValue ) { |
| 463 |
cancel = document.getElementById( 'cancel-comment-reply-link' ); |
| 464 |
cancelClick = cancel.onclick; |
| 465 |
cancel.onclick = function () { |
| 466 |
var cancelReturn = cancelClick.call( this ); |
| 467 |
if ( false !== cancelReturn ) { |
| 468 |
return cancelReturn; |
| 469 |
} |
| 470 |
|
| 471 |
if ( ! comm_par ) { |
| 472 |
return cancelReturn; |
| 473 |
} |
| 474 |
|
| 475 |
comm_par = 0; |
| 476 |
|
| 477 |
tellFrameNewParent(); |
| 478 |
|
| 479 |
return cancelReturn; |
| 480 |
}; |
| 481 |
} |
| 482 |
|
| 483 |
if ( comm_par == parentId ) { |
| 484 |
return returnValue; |
| 485 |
} |
| 486 |
|
| 487 |
comm_par = parentId; |
| 488 |
|
| 489 |
tellFrameNewParent(); |
| 490 |
|
| 491 |
return returnValue; |
| 492 |
}; |
| 493 |
} |
| 494 |
|
| 495 |
<?php endif; ?> |
| 496 |
|
| 497 |
// Do the post message bit after the dom has loaded. |
| 498 |
document.addEventListener( 'DOMContentLoaded', function () { |
| 499 |
var iframe_url = <?php echo wp_json_encode( esc_url_raw( $url_origin ) ); ?>; |
| 500 |
if ( window.postMessage ) { |
| 501 |
if ( document.addEventListener ) { |
| 502 |
window.addEventListener( 'message', function ( event ) { |
| 503 |
var origin = event.origin.replace( /^http:\/\//i, 'https://' ); |
| 504 |
if ( iframe_url.replace( /^http:\/\//i, 'https://' ) !== origin ) { |
| 505 |
return; |
| 506 |
} |
| 507 |
frame.style.height = event.data + 'px'; |
| 508 |
}); |
| 509 |
} else if ( document.attachEvent ) { |
| 510 |
window.attachEvent( 'message', function ( event ) { |
| 511 |
var origin = event.origin.replace( /^http:\/\//i, 'https://' ); |
| 512 |
if ( iframe_url.replace( /^http:\/\//i, 'https://' ) !== origin ) { |
| 513 |
return; |
| 514 |
} |
| 515 |
frame.style.height = event.data + 'px'; |
| 516 |
}); |
| 517 |
} |
| 518 |
} |
| 519 |
}) |
| 520 |
|
| 521 |
})(); |
| 522 |
</script> |
| 523 |
|
| 524 |
<?php |
| 525 |
} |
| 526 |
|
| 527 |
/** |
| 528 |
* Verify the hash included in remote comments. |
| 529 |
* |
| 530 |
* If the Jetpack toekn is missing we return nothing, |
| 531 |
* and if the token is unknown or invalid, or comments not allowed, an error is returned. |
| 532 |
* |
| 533 |
* @since JetpackComments (1.4) |
| 534 |
* |
| 535 |
* @todo We do need to add a nonce check here - internal ref for details: p1645643468937519/1645189749.180299-slack-C02HQGKMFJ8 |
| 536 |
*/ |
| 537 |
public function pre_comment_on_post() { |
| 538 |
$post_array = stripslashes_deep( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 539 |
|
| 540 |
// Bail if missing the Jetpack token. |
| 541 |
if ( ! isset( $post_array['sig'] ) || ! isset( $post_array['token_key'] ) ) { |
| 542 |
unset( $_POST['hc_post_as'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 543 |
|
| 544 |
return; |
| 545 |
} |
| 546 |
|
| 547 |
if ( false !== strpos( $post_array['hc_avatar'], '.gravatar.com' ) ) { |
| 548 |
$post_array['hc_avatar'] = htmlentities( $post_array['hc_avatar'] ); |
| 549 |
} |
| 550 |
|
| 551 |
$blog_token = ( new Tokens() )->get_access_token( false, $post_array['token_key'] ); |
| 552 |
if ( ! $blog_token ) { |
| 553 |
wp_die( esc_html__( 'Unknown security token.', 'jetpack' ), 400 ); |
| 554 |
} |
| 555 |
$check = self::sign_remote_comment_parameters( $post_array, $blog_token->secret ); |
| 556 |
if ( is_wp_error( $check ) ) { |
| 557 |
wp_die( esc_html( $check ) ); |
| 558 |
} |
| 559 |
|
| 560 |
// Bail if token is expired or not valid. |
| 561 |
if ( ! hash_equals( $check, $post_array['sig'] ) ) { |
| 562 |
wp_die( esc_html__( 'Invalid security token.', 'jetpack' ), 400 ); |
| 563 |
} |
| 564 |
|
| 565 |
/** This filter is documented in modules/comments/comments.php */ |
| 566 |
if ( ! apply_filters( 'jetpack_comment_form_enabled_for_' . get_post_type( $post_array['comment_post_ID'] ), true ) ) { |
| 567 |
// In case the comment POST is legit, but the comments are |
| 568 |
// now disabled, we don't allow the comment. |
| 569 |
|
| 570 |
wp_die( esc_html__( 'Comments are not allowed.', 'jetpack' ), 403 ); |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
/** Capabilities **********************************************************/ |
| 575 |
|
| 576 |
/** |
| 577 |
* Add some additional comment meta after comment is saved about what |
| 578 |
* service the comment is from, the avatar, user_id, etc... |
| 579 |
* |
| 580 |
* @since JetpackComments (1.4) |
| 581 |
* |
| 582 |
* @param int $comment_id The comment ID. |
| 583 |
*/ |
| 584 |
public function add_comment_meta( $comment_id ) { |
| 585 |
$comment_meta = array(); |
| 586 |
|
| 587 |
// phpcs:disable WordPress.Security.NonceVerification.Missing |
| 588 |
switch ( $this->is_highlander_comment_post() ) { |
| 589 |
case 'facebook': |
| 590 |
$comment_meta['hc_post_as'] = 'facebook'; |
| 591 |
$comment_meta['hc_avatar'] = stripslashes( $_POST['hc_avatar'] ); |
| 592 |
$comment_meta['hc_foreign_user_id'] = stripslashes( $_POST['hc_userid'] ); |
| 593 |
break; |
| 594 |
|
| 595 |
case 'twitter': |
| 596 |
$comment_meta['hc_post_as'] = 'twitter'; |
| 597 |
$comment_meta['hc_avatar'] = stripslashes( $_POST['hc_avatar'] ); |
| 598 |
$comment_meta['hc_foreign_user_id'] = stripslashes( $_POST['hc_userid'] ); |
| 599 |
break; |
| 600 |
|
| 601 |
// phpcs:ignore WordPress.WP.CapitalPDangit |
| 602 |
case 'wordpress': |
| 603 |
// phpcs:ignore WordPress.WP.CapitalPDangit |
| 604 |
$comment_meta['hc_post_as'] = 'wordpress'; |
| 605 |
$comment_meta['hc_avatar'] = stripslashes( $_POST['hc_avatar'] ); |
| 606 |
$comment_meta['hc_foreign_user_id'] = stripslashes( $_POST['hc_userid'] ); |
| 607 |
$comment_meta['hc_wpcom_id_sig'] = stripslashes( $_POST['hc_wpcom_id_sig'] ); // since 1.9. |
| 608 |
break; |
| 609 |
|
| 610 |
case 'jetpack': |
| 611 |
$comment_meta['hc_post_as'] = 'jetpack'; |
| 612 |
$comment_meta['hc_avatar'] = stripslashes( $_POST['hc_avatar'] ); |
| 613 |
$comment_meta['hc_foreign_user_id'] = stripslashes( $_POST['hc_userid'] ); |
| 614 |
break; |
| 615 |
|
| 616 |
} |
| 617 |
// phpcs:enable WordPress.Security.NonceVerification.Missing |
| 618 |
|
| 619 |
// Bail if no extra comment meta. |
| 620 |
if ( empty( $comment_meta ) ) { |
| 621 |
return; |
| 622 |
} |
| 623 |
|
| 624 |
// Loop through extra meta and add values. |
| 625 |
foreach ( $comment_meta as $key => $value ) { |
| 626 |
add_comment_meta( $comment_id, $key, $value, true ); |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
/** |
| 631 |
* POST the submitted comment to the iframe |
| 632 |
* |
| 633 |
* @param string $url The comment URL origin. |
| 634 |
*/ |
| 635 |
public function capture_comment_post_redirect_to_reload_parent_frame( $url ) { |
| 636 |
if ( ! isset( $_GET['for'] ) || 'jetpack' !== $_GET['for'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 637 |
return $url; |
| 638 |
} |
| 639 |
?> |
| 640 |
<!DOCTYPE html> |
| 641 |
<html <?php language_attributes(); ?>> |
| 642 |
<!--<![endif]--> |
| 643 |
<head> |
| 644 |
<meta charset="<?php bloginfo( 'charset' ); ?>" /> |
| 645 |
<title> |
| 646 |
<?php |
| 647 |
wp_kses_post( |
| 648 |
printf( |
| 649 |
/* translators: %s is replaced by an ellipsis */ |
| 650 |
__( 'Submitting Comment%s', 'jetpack' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 651 |
'…' |
| 652 |
) |
| 653 |
); |
| 654 |
?> |
| 655 |
</title> |
| 656 |
<style type="text/css"> |
| 657 |
body { |
| 658 |
display: table; |
| 659 |
width: 100%; |
| 660 |
height: 60%; |
| 661 |
position: absolute; |
| 662 |
top: 0; |
| 663 |
left: 0; |
| 664 |
overflow: hidden; |
| 665 |
color: #333; |
| 666 |
} |
| 667 |
|
| 668 |
h1 { |
| 669 |
text-align: center; |
| 670 |
margin: 0; |
| 671 |
padding: 0; |
| 672 |
display: table-cell; |
| 673 |
vertical-align: middle; |
| 674 |
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", sans-serif; |
| 675 |
font-weight: normal; |
| 676 |
} |
| 677 |
|
| 678 |
.hidden { |
| 679 |
opacity: 0; |
| 680 |
} |
| 681 |
|
| 682 |
h1 span { |
| 683 |
-moz-transition-property: opacity; |
| 684 |
-moz-transition-duration: 1s; |
| 685 |
-moz-transition-timing-function: ease-in-out; |
| 686 |
|
| 687 |
-webkit-transition-property: opacity; |
| 688 |
-webkit-transition-duration: 1s; |
| 689 |
-webbit-transition-timing-function: ease-in-out; |
| 690 |
|
| 691 |
-o-transition-property: opacity; |
| 692 |
-o-transition-duration: 1s; |
| 693 |
-o-transition-timing-function: ease-in-out; |
| 694 |
|
| 695 |
-ms-transition-property: opacity; |
| 696 |
-ms-transition-duration: 1s; |
| 697 |
-ms-transition-timing-function: ease-in-out; |
| 698 |
|
| 699 |
transition-property: opacity; |
| 700 |
transition-duration: 1s; |
| 701 |
transition-timing-function: ease-in-out; |
| 702 |
} |
| 703 |
</style> |
| 704 |
</head> |
| 705 |
<body> |
| 706 |
<h1> |
| 707 |
<?php |
| 708 |
wp_kses_post( |
| 709 |
printf( |
| 710 |
/* translators: %s is replaced by HTML markup to include an ellipsis */ |
| 711 |
__( 'Submitting Comment%s', 'jetpack' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 712 |
'<span id="ellipsis" class="hidden">…</span>' |
| 713 |
) |
| 714 |
); |
| 715 |
?> |
| 716 |
</h1> |
| 717 |
<script type="text/javascript"> |
| 718 |
try { |
| 719 |
window.parent.location = <?php echo wp_json_encode( $url ); ?>; |
| 720 |
window.parent.location.reload(true); |
| 721 |
} catch (e) { |
| 722 |
window.location = <?php echo wp_json_encode( $url ); ?>; |
| 723 |
window.location.reload(true); |
| 724 |
} |
| 725 |
ellipsis = document.getElementById('ellipsis'); |
| 726 |
|
| 727 |
function toggleEllipsis() { |
| 728 |
ellipsis.className = ellipsis.className ? '' : 'hidden'; |
| 729 |
} |
| 730 |
|
| 731 |
setInterval(toggleEllipsis, 1200); |
| 732 |
</script> |
| 733 |
</body> |
| 734 |
</html> |
| 735 |
<?php |
| 736 |
exit; |
| 737 |
} |
| 738 |
} |
| 739 |
|
| 740 |
Jetpack_Comments::init(); |
| 741 |
|