| @@ -5,161 +5,16 @@ | ||
| 5 | 5 | * |
| 6 | 6 | * @package automattic/jetpack |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | + exit( 0 ); | |
| 11 | +} | |
| 12 | + | |
| 9 | 13 | // Set up Sharing in wp-admin. |
| 10 | 14 | require_once plugin_dir_path( __FILE__ ) . 'sharing.php'; |
| 11 | 15 | |
| 12 | 16 | /** |
| 13 | - * Send an email via the Email sharing button. | |
| 14 | - * | |
| 15 | - * @param array $data Array of information about the shared message. | |
| 16 | - * | |
| 17 | - * @return void | |
| 18 | - * | |
| 19 | - * @deprecated 11.0 | |
| 20 | - */ | |
| 21 | -function sharing_email_send_post( $data ) { | |
| 22 | - | |
| 23 | - $content = sharing_email_send_post_content( $data ); | |
| 24 | - // Borrowed from wp_mail(); | |
| 25 | - | |
| 26 | - if ( empty( $_SERVER['SERVER_NAME'] ) ) { | |
| 27 | - return; | |
| 28 | - } | |
| 29 | - | |
| 30 | - $sitename = strtolower( sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) ); | |
| 31 | - if ( str_starts_with( $sitename, 'www.' ) ) { | |
| 32 | - $sitename = substr( $sitename, 4 ); | |
| 33 | - } | |
| 34 | - | |
| 35 | - /** This filter is documented in core/src/wp-includes/pluggable.php */ | |
| 36 | - $from_email = apply_filters( 'wp_mail_from', 'wordpress@' . $sitename ); | |
| 37 | - | |
| 38 | - if ( ! empty( $data['name'] ) ) { | |
| 39 | - $s_name = (string) $data['name']; | |
| 40 | - $name_needs_encoding_regex = | |
| 41 | - '/[' . | |
| 42 | - // SpamAssasin's list of characters which "need MIME" encoding | |
| 43 | - '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff' . | |
| 44 | - // Our list of "unsafe" characters | |
| 45 | - '<\r\n' . | |
| 46 | - ']/'; | |
| 47 | - | |
| 48 | - $needs_encoding = | |
| 49 | - // If it contains any blocked chars. | |
| 50 | - preg_match( $name_needs_encoding_regex, $s_name ) || | |
| 51 | - // Or if we can't use `mb_convert_encoding` | |
| 52 | - ! function_exists( 'mb_convert_encoding' ) || | |
| 53 | - // Or if it's not already ASCII | |
| 54 | - mb_convert_encoding( $data['name'], 'ASCII' ) !== $s_name; | |
| 55 | - | |
| 56 | - if ( $needs_encoding ) { | |
| 57 | - $data['name'] = sprintf( '=?UTF-8?B?%s?=', base64_encode( $data['name'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode | |
| 58 | - } | |
| 59 | - } | |
| 60 | - | |
| 61 | - $headers = array(); | |
| 62 | - $headers[] = sprintf( 'From: %1$s <%2$s>', $data['name'], $from_email ); | |
| 63 | - $headers[] = sprintf( 'Reply-To: %1$s <%2$s>', $data['name'], $data['source'] ); | |
| 64 | - | |
| 65 | - // Make sure to pass the title through the normal sharing filters. | |
| 66 | - $title = $data['sharing_source']->get_share_title( $data['post']->ID ); | |
| 67 | - | |
| 68 | - /** | |
| 69 | - * Filter the Sharing Email Send Post Subject. | |
| 70 | - * | |
| 71 | - * @module sharedaddy | |
| 72 | - * | |
| 73 | - * @since 5.8.0 | |
| 74 | - * | |
| 75 | - * @param string $var Sharing Email Send Post Subject. Default is "Shared Post". | |
| 76 | - */ | |
| 77 | - $subject = apply_filters( 'wp_sharing_email_send_post_subject', '[' . __( 'Shared Post', 'jetpack' ) . '] ' . $title ); | |
| 78 | - | |
| 79 | - wp_mail( $data['target'], $subject, $content, $headers ); | |
| 80 | -} | |
| 81 | - | |
| 82 | -/** | |
| 83 | - * Checks for spam using Akismet if available. | |
| 84 | - * Return $data as it if email about to be send out is not spam. | |
| 85 | - * | |
| 86 | - * @param array $data Array of information about the shared message. | |
| 87 | - * | |
| 88 | - * @return array $data | |
| 89 | - * | |
| 90 | - * @deprecated 11.0 | |
| 91 | - */ | |
| 92 | -function sharing_email_check_for_spam_via_akismet( $data ) { | |
| 93 | - | |
| 94 | - if ( ! Jetpack::is_akismet_active() ) { | |
| 95 | - return $data; | |
| 96 | - } | |
| 97 | - | |
| 98 | - // Prepare the body_request for akismet | |
| 99 | - $body_request = array( | |
| 100 | - 'blog' => get_option( 'home' ), | |
| 101 | - 'permalink' => $data['sharing_source']->get_share_url( $data['post']->ID ), | |
| 102 | - 'comment_type' => 'share', | |
| 103 | - 'comment_author' => $data['name'], | |
| 104 | - 'comment_author_email' => $data['source'], | |
| 105 | - 'comment_content' => sharing_email_send_post_content( $data ), | |
| 106 | - 'user_agent' => ( isset( $_SERVER['HTTP_USER_AGENT'] ) | |
| 107 | - ? filter_var( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) | |
| 108 | - : null | |
| 109 | - ), | |
| 110 | - ); | |
| 111 | - | |
| 112 | - if ( method_exists( 'Akismet', 'http_post' ) ) { | |
| 113 | - $body_request['user_ip'] = Akismet::get_ip_address(); | |
| 114 | - $response = Akismet::http_post( build_query( $body_request ), 'comment-check' ); | |
| 115 | - } else { | |
| 116 | - global $akismet_api_host, $akismet_api_port; | |
| 117 | - $body_request['user_ip'] = ( isset( $_SERVER['REMOTE_ADDR'] ) | |
| 118 | - ? filter_var( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) | |
| 119 | - : null | |
| 120 | - ); | |
| 121 | - $response = akismet_http_post( build_query( $body_request ), $akismet_api_host, '/1.1/comment-check', $akismet_api_port ); | |
| 122 | - } | |
| 123 | - | |
| 124 | - /* | |
| 125 | - * The Response is spam lets not send the email. | |
| 126 | - * 'true' is spam | |
| 127 | - */ | |
| 128 | - if ( | |
| 129 | - ! empty( $response ) | |
| 130 | - && isset( $response[1] ) | |
| 131 | - && 'true' == trim( $response[1] ) // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual -- response comes from the Akismet API. | |
| 132 | - ) { | |
| 133 | - return false; // don't send the email | |
| 134 | - } | |
| 135 | - return $data; | |
| 136 | -} | |
| 137 | - | |
| 138 | -/** | |
| 139 | - * Content of the emails sent to the target email address. | |
| 140 | - * | |
| 141 | - * @param array $data Array of information about the shared message. | |
| 142 | - * | |
| 143 | - * @return string $content | |
| 144 | - * | |
| 145 | - * @deprecated 11.0 | |
| 146 | - */ | |
| 147 | -function sharing_email_send_post_content( $data ) { | |
| 148 | - $content = sprintf( | |
| 149 | - /* translators: included in email when post is shared via email. First item is sender's name. Second is sender's email address. */ | |
| 150 | - __( '%1$s (%2$s) thinks you may be interested in the following post:', 'jetpack' ), | |
| 151 | - $data['name'], | |
| 152 | - $data['source'] | |
| 153 | - ); | |
| 154 | - $content .= "\n\n"; | |
| 155 | - // Make sure to pass the title and URL through the normal sharing filters. | |
| 156 | - $content .= $data['sharing_source']->get_share_title( $data['post']->ID ) . "\n"; | |
| 157 | - $content .= $data['sharing_source']->get_share_url( $data['post']->ID ) . "\n"; | |
| 158 | - return $content; | |
| 159 | -} | |
| 160 | - | |
| 161 | -/** | |
| 162 | 17 | * Add a meta box to the post editing screen for sharing. |
| 163 | 18 | * |
| 164 | 19 | * @return void |
| 165 | 20 | */ |
| @@ -262,9 +117,10 @@ | ||
| 262 | 117 | $post_type_object = get_post_type_object( sanitize_key( $_POST['post_type'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Core takes care of the validation. |
| 263 | 118 | |
| 264 | 119 | // Record sharing disable. |
| 265 | 120 | if ( |
| 266 | - $post_type_object->public | |
| 121 | + $post_type_object instanceof \WP_Post_Type | |
| 122 | + && $post_type_object->public | |
| 267 | 123 | && current_user_can( 'edit_post', $post_id ) |
| 268 | 124 | && isset( $_POST['sharing_status_hidden'] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Core takes care of the validation. |
| 269 | 125 | ) { |
| 270 | 126 | if ( ! isset( $_POST['enable_post_sharing'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Core takes care of the validation. |
| @@ -365,92 +221,8 @@ | ||
| 365 | 221 | * @return void |
| 366 | 222 | */ |
| 367 | 223 | function sharing_global_resources_save() { |
| 368 | 224 | update_option( 'sharedaddy_disable_resources', isset( $_POST['disable_resources'] ) ? 1 : 0 ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce handling is handled for all elements at once. |
| 369 | -} | |
| 370 | - | |
| 371 | -/** | |
| 372 | - * Returns the Recaptcha site/public key. | |
| 373 | - * | |
| 374 | - * Supports legacy RECAPTCHA_PUBLIC_KEY or RECAPTCHA_SITE_KEY. | |
| 375 | - * | |
| 376 | - * @return string | |
| 377 | - * | |
| 378 | - * @deprecated 11.0 | |
| 379 | - */ | |
| 380 | -function sharing_recaptcha_site_key() { | |
| 381 | - if ( ! defined( 'RECAPTCHA_PUBLIC_KEY' ) && ! defined( 'RECAPTCHA_SITE_KEY' ) ) { | |
| 382 | - return ''; | |
| 383 | - } | |
| 384 | - | |
| 385 | - if ( defined( 'RECAPTCHA_PUBLIC_KEY' ) && ! defined( 'RECAPTCHA_SITE_KEY' ) ) { | |
| 386 | - define( 'RECAPTCHA_SITE_KEY', RECAPTCHA_PUBLIC_KEY ); | |
| 387 | - } | |
| 388 | - | |
| 389 | - return RECAPTCHA_SITE_KEY; | |
| 390 | -} | |
| 391 | - | |
| 392 | -/** | |
| 393 | - * Returns the Recaptcha private/secret key. | |
| 394 | - * | |
| 395 | - * Supports legacy RECAPTCHA_PRIVATE_KEY or RECAPTCHA_SECRET_KEY. | |
| 396 | - * | |
| 397 | - * @return string | |
| 398 | - * | |
| 399 | - * @deprecated 11.0 | |
| 400 | - */ | |
| 401 | -function sharing_recaptcha_secret_key() { | |
| 402 | - if ( ! defined( 'RECAPTCHA_PRIVATE_KEY' ) && ! defined( 'RECAPTCHA_SECRET_KEY' ) ) { | |
| 403 | - return ''; | |
| 404 | - } | |
| 405 | - | |
| 406 | - if ( defined( 'RECAPTCHA_PRIVATE_KEY' ) && ! defined( 'RECAPTCHA_SECRET_KEY' ) ) { | |
| 407 | - define( 'RECAPTCHA_SECRET_KEY', RECAPTCHA_PRIVATE_KEY ); | |
| 408 | - } | |
| 409 | - | |
| 410 | - return RECAPTCHA_SECRET_KEY; | |
| 411 | -} | |
| 412 | - | |
| 413 | -/** | |
| 414 | - * Contents of a reCAPTCHA box. | |
| 415 | - * | |
| 416 | - * @return void | |
| 417 | - * | |
| 418 | - * @deprecated 11.0 | |
| 419 | - */ | |
| 420 | -function sharing_email_dialog() { | |
| 421 | - require_once plugin_dir_path( __FILE__ ) . 'recaptcha.php'; | |
| 422 | - | |
| 423 | - $recaptcha = new Jetpack_ReCaptcha( | |
| 424 | - sharing_recaptcha_site_key(), | |
| 425 | - sharing_recaptcha_secret_key(), | |
| 426 | - array( 'script_lazy' => true ) | |
| 427 | - ); | |
| 428 | - echo $recaptcha->get_recaptcha_html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in method. | |
| 429 | -} | |
| 430 | - | |
| 431 | -/** | |
| 432 | - * Short-circuit the email sharing button based on the results of reCAPTCHA. | |
| 433 | - * | |
| 434 | - * @param bool $true Should we check if the message isn't spam. | |
| 435 | - * @param object $post Post information. | |
| 436 | - * @param array $data Information about the shared message. | |
| 437 | - * | |
| 438 | - * @deprecated 11.0 | |
| 439 | - */ | |
| 440 | -function sharing_email_check( $true, $post, $data ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 441 | - require_once plugin_dir_path( __FILE__ ) . 'recaptcha.php'; | |
| 442 | - | |
| 443 | - $recaptcha = new Jetpack_ReCaptcha( sharing_recaptcha_site_key(), sharing_recaptcha_secret_key(), array( 'script_lazy' => true ) ); | |
| 444 | - $response = ! empty( $_POST['g-recaptcha-response'] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing -- we do not change anything on the site based on that. | |
| 445 | - ? filter_var( wp_unslash( $_POST['g-recaptcha-response'] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Missing -- we do not change anything on the site based on that. | |
| 446 | - : ''; | |
| 447 | - $remote_addr = ! empty( $_SERVER['REMOTE_ADDR'] ) | |
| 448 | - ? filter_var( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) | |
| 449 | - : ''; | |
| 450 | - $result = $recaptcha->verify( $response, $remote_addr ); | |
| 451 | - | |
| 452 | - return ( true === $result ); | |
| 453 | 225 | } |
| 454 | 226 | |
| 455 | 227 | add_action( 'init', 'sharing_init' ); |
| 456 | 228 | add_action( 'add_meta_boxes', 'sharing_add_meta_box' ); |