diff options
Diffstat (limited to 'plugins/jetpack/_inc/lib')
10 files changed, 441 insertions, 278 deletions
diff --git a/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-admin-page.php b/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-admin-page.php index 9baa3edb..bca7521d 100644 --- a/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-admin-page.php +++ b/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-admin-page.php @@ -30,8 +30,21 @@ abstract class Jetpack_Admin_Page { */ function additional_styles() {} - function __construct() { - $this->jetpack = Jetpack::init(); + /** + * The constructor. + */ + public function __construct() { + add_action( 'jetpack_loaded', array( $this, 'on_jetpack_loaded' ) ); + } + + /** + * Runs on Jetpack being ready to load its packages. + * + * @param Jetpack $jetpack object. + */ + public function on_jetpack_loaded( $jetpack ) { + $this->jetpack = $jetpack; + self::$block_page_rendering_for_idc = ( Jetpack::validate_sync_error_idc_option() && ! Jetpack_Options::get_option( 'safe_mode_confirmed' ) ); @@ -262,6 +275,13 @@ abstract class Jetpack_Admin_Page { ); $args = wp_parse_args( $args, $defaults ); $jetpack_admin_url = admin_url( 'admin.php?page=jetpack' ); + $jetpack_about_url = ( Jetpack::is_active() || Jetpack::is_development_mode() ) + ? admin_url( 'admin.php?page=jetpack_about' ) + : 'https://jetpack.com'; + + $jetpack_privacy_url = ( Jetpack::is_active() || Jetpack::is_development_mode() ) + ? $jetpack_admin_url . '#/privacy' + : 'https://automattic.com/privacy/'; ?> <div id="jp-plugin-container" class=" @@ -285,6 +305,7 @@ abstract class Jetpack_Admin_Page { <?php if ( is_network_admin() ) { $current_screen = get_current_screen(); + $highlight_current_sites = ( 'toplevel_page_jetpack-network' === $current_screen->id ? 'is-primary' : '' ); $highlight_current_settings = ( 'jetpack_page_jetpack-settings-network' === $current_screen->id ? 'is-primary' : '' ); ?> @@ -327,135 +348,48 @@ abstract class Jetpack_Admin_Page { echo $callback_ui; ?> <!-- END OF CALLBACK --> - <?php self::render_footer(); ?> - </div> - <?php - return; - } - /** - * Output a list item with a link. - * - * @param string $url URL. - * @param string $title Link title attribute. - * @param string $text Link text. - * @param bool $is_internal Is the link linking to an internal or external domain. - */ - public static function the_footer_link( $url, $title, $text, $is_internal = true ) { - printf( - '<li class="jp-footer__link-item"><a class="jp-footer__link" href="%1$s" title="%2$s" %4$s>%3$s</a></li>', - esc_url( $url ), - esc_attr( $title ), - esc_html( $text ), - ( $is_internal ? '' : 'target="_blank" rel="noopener noreferrer"' ) - ); - } - - /** - * Render the footer of the jetpack dashboard. For admin pages. - * - * Note that the Jetpack Dashboard may append additional links to that list. - */ - public static function render_footer() { - $admin_url = admin_url( 'admin.php?page=jetpack' ); - - $is_dev_mode_or_connected = Jetpack::is_active() || ( new Status() )->is_development_mode(); - - $privacy_url = ( $is_dev_mode_or_connected ) - ? $admin_url . '#/privacy' - : 'https://automattic.com/privacy/'; - - $about_url = ( $is_dev_mode_or_connected ) - ? admin_url( 'admin.php?page=jetpack_about' ) - : 'https://jetpack.com'; - - ?> - <div class="jp-footer"> + <div class="jp-footer"> <div class="jp-footer__a8c-attr-container"> - <a href="<?php echo esc_url( $about_url ); ?>"> + <a href="<?php echo esc_url( $jetpack_about_url ); ?>"> <svg role="img" class="jp-footer__a8c-attr" x="0" y="0" viewBox="0 0 935 38.2" enable-background="new 0 0 935 38.2" aria-labelledby="a8c-svg-title"><title id="a8c-svg-title">An Automattic Airline</title><path d="M317.1 38.2c-12.6 0-20.7-9.1-20.7-18.5v-1.2c0-9.6 8.2-18.5 20.7-18.5 12.6 0 20.8 8.9 20.8 18.5v1.2C337.9 29.1 329.7 38.2 317.1 38.2zM331.2 18.6c0-6.9-5-13-14.1-13s-14 6.1-14 13v0.9c0 6.9 5 13.1 14 13.1s14.1-6.2 14.1-13.1V18.6zM175 36.8l-4.7-8.8h-20.9l-4.5 8.8h-7L157 1.3h5.5L182 36.8H175zM159.7 8.2L152 23.1h15.7L159.7 8.2zM212.4 38.2c-12.7 0-18.7-6.9-18.7-16.2V1.3h6.6v20.9c0 6.6 4.3 10.5 12.5 10.5 8.4 0 11.9-3.9 11.9-10.5V1.3h6.7V22C231.4 30.8 225.8 38.2 212.4 38.2zM268.6 6.8v30h-6.7v-30h-15.5V1.3h37.7v5.5H268.6zM397.3 36.8V8.7l-1.8 3.1 -14.9 25h-3.3l-14.7-25 -1.8-3.1v28.1h-6.5V1.3h9.2l14 24.4 1.7 3 1.7-3 13.9-24.4h9.1v35.5H397.3zM454.4 36.8l-4.7-8.8h-20.9l-4.5 8.8h-7l19.2-35.5h5.5l19.5 35.5H454.4zM439.1 8.2l-7.7 14.9h15.7L439.1 8.2zM488.4 6.8v30h-6.7v-30h-15.5V1.3h37.7v5.5H488.4zM537.3 6.8v30h-6.7v-30h-15.5V1.3h37.7v5.5H537.3zM569.3 36.8V4.6c2.7 0 3.7-1.4 3.7-3.4h2.8v35.5L569.3 36.8 569.3 36.8zM628 11.3c-3.2-2.9-7.9-5.7-14.2-5.7 -9.5 0-14.8 6.5-14.8 13.3v0.7c0 6.7 5.4 13 15.3 13 5.9 0 10.8-2.8 13.9-5.7l4 4.2c-3.9 3.8-10.5 7.1-18.3 7.1 -13.4 0-21.6-8.7-21.6-18.3v-1.2c0-9.6 8.9-18.7 21.9-18.7 7.5 0 14.3 3.1 18 7.1L628 11.3zM321.5 12.4c1.2 0.8 1.5 2.4 0.8 3.6l-6.1 9.4c-0.8 1.2-2.4 1.6-3.6 0.8l0 0c-1.2-0.8-1.5-2.4-0.8-3.6l6.1-9.4C318.7 11.9 320.3 11.6 321.5 12.4L321.5 12.4z"></path><path d="M37.5 36.7l-4.7-8.9H11.7l-4.6 8.9H0L19.4 0.8H25l19.7 35.9H37.5zM22 7.8l-7.8 15.1h15.9L22 7.8zM82.8 36.7l-23.3-24 -2.3-2.5v26.6h-6.7v-36H57l22.6 24 2.3 2.6V0.8h6.7v35.9H82.8z"></path><path d="M719.9 37l-4.8-8.9H694l-4.6 8.9h-7.1l19.5-36h5.6l19.8 36H719.9zM704.4 8l-7.8 15.1h15.9L704.4 8zM733 37V1h6.8v36H733zM781 37c-1.8 0-2.6-2.5-2.9-5.8l-0.2-3.7c-0.2-3.6-1.7-5.1-8.4-5.1h-12.8V37H750V1h19.6c10.8 0 15.7 4.3 15.7 9.9 0 3.9-2 7.7-9 9 7 0.5 8.5 3.7 8.6 7.9l0.1 3c0.1 2.5 0.5 4.3 2.2 6.1V37H781zM778.5 11.8c0-2.6-2.1-5.1-7.9-5.1h-13.8v10.8h14.4c5 0 7.3-2.4 7.3-5.2V11.8zM794.8 37V1h6.8v30.4h28.2V37H794.8zM836.7 37V1h6.8v36H836.7zM886.2 37l-23.4-24.1 -2.3-2.5V37h-6.8V1h6.5l22.7 24.1 2.3 2.6V1h6.8v36H886.2zM902.3 37V1H935v5.6h-26v9.2h20v5.5h-20v10.1h26V37H902.3z"></path></svg> </a> </div> - <ul class="jp-footer__links" id="jp-footer__links-id"> - <?php - // Version number. - self::the_footer_link( - 'https://jetpack.com', - __( 'Jetpack version', 'jetpack' ), - sprintf( - /* Translators: placeholder is a number. */ - __( 'Jetpack version %s', 'jetpack' ), - JETPACK__VERSION - ), - false - ); - - // About page. - self::the_footer_link( - $about_url, - __( 'About Jetpack', 'jetpack' ), - __( 'About', 'jetpack' ), - $is_dev_mode_or_connected - ); - - // TOS. - self::the_footer_link( - 'https://wordpress.com/tos/', - __( 'WordPress.com Terms of Service', 'jetpack' ), - _x( 'Terms', 'Navigation item', 'jetpack' ), - false - ); - - // Privacy policy. - self::the_footer_link( - $privacy_url, - __( "Automattic's Privacy Policy", 'jetpack' ), - _x( 'Privacy', 'Navigation item', 'jetpack' ), - $is_dev_mode_or_connected - ); - - // Network Admin Jetpack dashboard. - if ( is_multisite() && current_user_can( 'jetpack_network_sites_page' ) ) { - self::the_footer_link( - network_admin_url( 'admin.php?page=jetpack' ), - __( "Manage your network's Jetpack Sites", 'jetpack' ), - _x( 'Network Sites', 'Navigation item', 'jetpack' ), - true - ); - } - - // Network Admin Jetpack settings. - if ( is_multisite() && current_user_can( 'jetpack_network_settings_page' ) ) { - self::the_footer_link( - network_admin_url( 'admin.php?page=jetpack-settings' ), - __( "Manage your network's Jetpack settings", 'jetpack' ), - _x( 'Network Settings', 'Navigation item', 'jetpack' ), - true - ); - } - - // Legacy Modules page. - if ( current_user_can( 'manage_options' ) && $is_dev_mode_or_connected ) { - self::the_footer_link( - admin_url( 'admin.php?page=jetpack_modules' ), - __( 'Access the full list of Jetpack modules available on your site', 'jetpack' ), - _x( 'Modules', 'Navigation item', 'jetpack' ), - true - ); - } - - // Debugger. - if ( current_user_can( 'manage_options' ) ) { - self::the_footer_link( - admin_url( 'admin.php?page=jetpack-debugger' ), - __( "Test your site's compatibility with Jetpack", 'jetpack' ), - _x( 'Debug', 'Navigation item', 'jetpack' ), - true - ); - } - ?> + <ul class="jp-footer__links"> + <li class="jp-footer__link-item"> + <a href="https://jetpack.com" target="_blank" rel="noopener noreferrer" class="jp-footer__link" title="<?php esc_html_e( 'Jetpack version', 'jetpack' ); ?>">Jetpack <?php echo JETPACK__VERSION; ?></a> + </li> + <li class="jp-footer__link-item"> + <a href="<?php echo esc_url( $jetpack_about_url ); ?>" title="<?php esc_attr__( 'About Jetpack', 'jetpack' ); ?>" class="jp-footer__link"><?php echo esc_html__( 'About', 'jetpack' ); ?></a> + </li> + <li class="jp-footer__link-item"> + <a href="https://wordpress.com/tos/" target="_blank" rel="noopener noreferrer" title="<?php esc_html__( 'WordPress.com Terms of Service', 'jetpack' ); ?>" class="jp-footer__link"><?php echo esc_html_x( 'Terms', 'Navigation item', 'jetpack' ); ?></a> + </li> + <li class="jp-footer__link-item"> + <a href="<?php echo esc_url( $jetpack_privacy_url ); ?>" rel="noopener noreferrer" title="<?php esc_html_e( "Automattic's Privacy Policy", 'jetpack' ); ?>" class="jp-footer__link"><?php echo esc_html_x( 'Privacy', 'Navigation item', 'jetpack' ); ?></a> + </li> + <?php if ( is_multisite() && current_user_can( 'jetpack_network_sites_page' ) ) { ?> + <li class="jp-footer__link-item"> + <a href="<?php echo esc_url( network_admin_url( 'admin.php?page=jetpack' ) ); ?>" title="<?php esc_html_e( "Manage your network's Jetpack Sites.", 'jetpack' ); ?>" class="jp-footer__link"><?php echo esc_html_x( 'Network Sites', 'Navigation item', 'jetpack' ); ?></a> + </li> + <?php } ?> + <?php if ( is_multisite() && current_user_can( 'jetpack_network_settings_page' ) ) { ?> + <li class="jp-footer__link-item"> + <a href="<?php echo esc_url( network_admin_url( 'admin.php?page=jetpack-settings' ) ); ?>" title="<?php esc_html_e( "Manage your network's Jetpack Sites.", 'jetpack' ); ?>" class="jp-footer__link"><?php echo esc_html_x( 'Network Settings', 'Navigation item', 'jetpack' ); ?></a> + </li> + <?php } ?> + <?php if ( current_user_can( 'manage_options' ) ) { ?> + <li class="jp-footer__link-item"> + <a href="<?php echo esc_url( admin_url( 'admin.php?page=jetpack_modules' ) ); ?>" title="<?php esc_html_e( "Access the full list of Jetpack modules available on your site.", 'jetpack' ); ?>" class="jp-footer__link"><?php echo esc_html_x( 'Modules', 'Navigation item', 'jetpack' ); ?></a> + </li> + <li class="jp-footer__link-item"> + <a href="<?php echo esc_url( admin_url( 'admin.php?page=jetpack-debugger' ) ); ?>" title="<?php esc_html_e( "Test your site's compatibility with Jetpack.", 'jetpack' ); ?>" class="jp-footer__link"><?php echo esc_html_x( 'Debug', 'Navigation item', 'jetpack' ); ?></a> + </li> + <?php } ?> </ul> </div> + </div> <?php + return; } } diff --git a/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-react-page.php b/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-react-page.php index 9d3ce44c..2d20c4e0 100644 --- a/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-react-page.php +++ b/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-react-page.php @@ -1,5 +1,6 @@ <?php use Automattic\Jetpack\Status; +use Automattic\Jetpack\Partner; include_once( 'class.jetpack-admin-page.php' ); @@ -115,8 +116,6 @@ class Jetpack_React_Page extends Jetpack_Admin_Page { // We got the static.html so let's display it echo $static_html; - self::render_footer(); - } } @@ -148,6 +147,7 @@ class Jetpack_React_Page extends Jetpack_Admin_Page { return; // No need for scripts on a fallback page } + $is_development_mode = ( new Status() )->is_development_mode(); $script_deps_path = JETPACK__PLUGIN_DIR . '_inc/build/admin.asset.php'; $script_dependencies = array( 'wp-polyfill' ); @@ -156,16 +156,13 @@ class Jetpack_React_Page extends Jetpack_Admin_Page { $script_dependencies = $asset_manifest['dependencies']; } - if ( Jetpack::is_active() || $is_development_mode ) { - wp_enqueue_script( - 'react-plugin', - plugins_url( '_inc/build/admin.js', JETPACK__PLUGIN_FILE ), - $script_dependencies, - JETPACK__VERSION, - true - ); - } - + wp_enqueue_script( + 'react-plugin', + plugins_url( '_inc/build/admin.js', JETPACK__PLUGIN_FILE ), + $script_dependencies, + JETPACK__VERSION, + true + ); if ( ! $is_development_mode && Jetpack::is_active() ) { // Required for Analytics. @@ -223,40 +220,39 @@ class Jetpack_React_Page extends Jetpack_Admin_Page { ? get_permalink( $last_post[0]->ID ) : get_home_url(); - // Ensure that class to get the affiliate code is loaded - if ( ! class_exists( 'Jetpack_Affiliate' ) ) { - require_once JETPACK__PLUGIN_DIR . 'class.jetpack-affiliate.php'; - } - $current_user_data = jetpack_current_user_data(); + $status = new Status(); + return array( - 'WP_API_root' => esc_url_raw( rest_url() ), - 'WP_API_nonce' => wp_create_nonce( 'wp_rest' ), - 'pluginBaseUrl' => plugins_url( '', JETPACK__PLUGIN_FILE ), - 'connectionStatus' => array( - 'isActive' => Jetpack::is_active(), - 'isStaging' => Jetpack::is_staging_site(), - 'devMode' => array( - 'isActive' => ( new Status() )->is_development_mode(), + 'WP_API_root' => esc_url_raw( rest_url() ), + 'WP_API_nonce' => wp_create_nonce( 'wp_rest' ), + 'pluginBaseUrl' => plugins_url( '', JETPACK__PLUGIN_FILE ), + 'connectionStatus' => array( + 'isActive' => Jetpack::is_active(), + 'isStaging' => $status->is_staging_site(), + 'devMode' => array( + 'isActive' => $status->is_development_mode(), 'constant' => defined( 'JETPACK_DEV_DEBUG' ) && JETPACK_DEV_DEBUG, 'url' => site_url() && false === strpos( site_url(), '.' ), 'filter' => apply_filters( 'jetpack_development_mode', false ), ), - 'isPublic' => '1' == get_option( 'blog_public' ), + 'isPublic' => '1' == get_option( 'blog_public' ), // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison 'isInIdentityCrisis' => Jetpack::validate_sync_error_idc_option(), - 'sandboxDomain' => JETPACK__SANDBOX_DOMAIN, + 'sandboxDomain' => JETPACK__SANDBOX_DOMAIN, ), - 'connectUrl' => $current_user_data['isConnected'] == false ? Jetpack::init()->build_connect_url( true, false, false ) : '', - 'dismissedNotices' => $this->get_dismissed_jetpack_notices(), - 'isDevVersion' => Jetpack::is_development_version(), - 'currentVersion' => JETPACK__VERSION, - 'is_gutenberg_available' => true, - 'getModules' => $modules, - 'rawUrl' => Jetpack::build_raw_urls( get_home_url() ), - 'adminUrl' => esc_url( admin_url() ), - 'stats' => array( - // data is populated asynchronously on page load + 'connectUrl' => false == $current_user_data['isConnected'] // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison + ? Jetpack::init()->build_connect_url( true, false, false ) + : '', + 'dismissedNotices' => $this->get_dismissed_jetpack_notices(), + 'isDevVersion' => Jetpack::is_development_version(), + 'currentVersion' => JETPACK__VERSION, + 'is_gutenberg_available' => true, + 'getModules' => $modules, + 'rawUrl' => Jetpack::build_raw_urls( get_home_url() ), + 'adminUrl' => esc_url( admin_url() ), + 'stats' => array( + // data is populated asynchronously on page load. 'data' => array( 'general' => false, 'day' => false, @@ -265,13 +261,13 @@ class Jetpack_React_Page extends Jetpack_Admin_Page { ), 'roles' => $stats_roles, ), - 'aff' => Jetpack_Affiliate::init()->get_affiliate_code(), - 'settings' => $this->get_flattened_settings( $modules ), - 'userData' => array( -// 'othersLinked' => Jetpack::get_other_linked_admins(), - 'currentUser' => $current_user_data, + 'aff' => Partner::init()->get_partner_code( Partner::AFFILIATE_CODE ), + 'partnerSubsidiaryId' => Partner::init()->get_partner_code( Partner::SUBSIDIARY_CODE ), + 'settings' => $this->get_flattened_settings( $modules ), + 'userData' => array( + 'currentUser' => $current_user_data, ), - 'siteData' => array( + 'siteData' => array( 'icon' => has_site_icon() ? apply_filters( 'jetpack_photon_url', get_site_icon_url(), array( 'w' => 64 ) ) : '', @@ -289,25 +285,25 @@ class Jetpack_React_Page extends Jetpack_Admin_Page { 'showBackups' => Jetpack::show_backups_ui(), 'isMultisite' => is_multisite(), ), - 'themeData' => array( + 'themeData' => array( 'name' => $current_theme->get( 'Name' ), 'hasUpdate' => (bool) get_theme_update_available( $current_theme ), 'support' => array( - 'infinite-scroll' => current_theme_supports( 'infinite-scroll' ) || in_array( $current_theme->get_stylesheet(), $inf_scr_support_themes ), + 'infinite-scroll' => current_theme_supports( 'infinite-scroll' ) || in_array( $current_theme->get_stylesheet(), $inf_scr_support_themes, true ), ), ), - 'locale' => Jetpack::get_i18n_data_json(), - 'localeSlug' => join( '-', explode( '_', get_user_locale() ) ), - 'jetpackStateNotices' => array( - 'messageCode' => Jetpack::state( 'message' ), - 'errorCode' => Jetpack::state( 'error' ), + 'locale' => Jetpack::get_i18n_data_json(), + 'localeSlug' => join( '-', explode( '_', get_user_locale() ) ), + 'jetpackStateNotices' => array( + 'messageCode' => Jetpack::state( 'message' ), + 'errorCode' => Jetpack::state( 'error' ), 'errorDescription' => Jetpack::state( 'error_description' ), ), - 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(), - 'currentIp' => function_exists( 'jetpack_protect_get_ip' ) ? jetpack_protect_get_ip() : false, - 'lastPostUrl' => esc_url( $last_post ), + 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(), + 'currentIp' => function_exists( 'jetpack_protect_get_ip' ) ? jetpack_protect_get_ip() : false, + 'lastPostUrl' => esc_url( $last_post ), 'externalServicesConnectUrls' => $this->get_external_services_connect_urls(), - 'calypsoEnv' => Jetpack::get_calypso_env(), + 'calypsoEnv' => Jetpack::get_calypso_env(), ); } @@ -342,11 +338,20 @@ class Jetpack_React_Page extends Jetpack_Admin_Page { * @return array */ function jetpack_current_user_data() { - $current_user = wp_get_current_user(); + $current_user = wp_get_current_user(); $is_master_user = $current_user->ID == Jetpack_Options::get_option( 'master_user' ); $dotcom_data = Jetpack::get_connected_user_data(); + // Add connected user gravatar to the returned dotcom_data. - $dotcom_data['avatar'] = get_avatar_url( $dotcom_data['email'], array( 'size' => 64, 'default' => 'mysteryman' ) ); + $dotcom_data['avatar'] = ( ! empty( $dotcom_data['email'] ) ? + get_avatar_url( + $dotcom_data['email'], + array( + 'size' => 64, + 'default' => 'mysteryman', + ) + ) + : false ); $current_user_data = array( 'isConnected' => Jetpack::is_user_connected( $current_user->ID ), diff --git a/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php b/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php index 30a53865..742767b0 100644 --- a/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php +++ b/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php @@ -975,16 +975,17 @@ class Jetpack_Core_Json_Api_Endpoints { * @return bool True if site is connected */ public static function jetpack_connection_status() { + $status = new Status(); return rest_ensure_response( array( - 'isActive' => Jetpack::is_active(), - 'isStaging' => Jetpack::is_staging_site(), - 'isRegistered' => Jetpack::connection()->is_registered(), - 'devMode' => array( - 'isActive' => ( new Status() )->is_development_mode(), - 'constant' => defined( 'JETPACK_DEV_DEBUG' ) && JETPACK_DEV_DEBUG, - 'url' => site_url() && false === strpos( site_url(), '.' ), - 'filter' => apply_filters( 'jetpack_development_mode', false ), - ), + 'isActive' => Jetpack::is_active(), + 'isStaging' => $status->is_staging_site(), + 'isRegistered' => Jetpack::connection()->is_registered(), + 'devMode' => array( + 'isActive' => $status->is_development_mode(), + 'constant' => defined( 'JETPACK_DEV_DEBUG' ) && JETPACK_DEV_DEBUG, + 'url' => site_url() && false === strpos( site_url(), '.' ), + 'filter' => apply_filters( 'jetpack_development_mode', false ), + ), ) ); } @@ -2056,6 +2057,13 @@ class Jetpack_Core_Json_Api_Endpoints { 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'subscriptions', ), + 'social_notifications_subscribe' => array( + 'description' => esc_html__( 'Send email notification when someone follows my blog', 'jetpack' ), + 'type' => 'boolean', + 'default' => 0, + 'validate_callback' => __CLASS__ . '::validate_boolean', + 'jp_group' => 'subscriptions', + ), // Related Posts 'show_headline' => array( @@ -2907,9 +2915,9 @@ class Jetpack_Core_Json_Api_Endpoints { if ( isset( $definition['type'] ) ) { switch ( $definition['type'] ) { case 'boolean': - if ( 'true' === $value ) { + if ( 'true' === $value || 'on' === $value ) { return true; - } elseif ( 'false' === $value ) { + } elseif ( 'false' === $value || 'off' === $value ) { return false; } return (bool) $value; diff --git a/plugins/jetpack/_inc/lib/class.media.php b/plugins/jetpack/_inc/lib/class.media.php index 9e419580..9db73961 100644 --- a/plugins/jetpack/_inc/lib/class.media.php +++ b/plugins/jetpack/_inc/lib/class.media.php @@ -17,42 +17,45 @@ class Jetpack_Media { * The hash is built according to the filename trying to avoid name collisions * with other media files. * - * @param number $media_id - media post ID - * @param string $new_filename - the new filename + * @param number $media_id - media post ID. + * @param string $new_filename - the new filename. * @return string A random filename. */ public static function generate_new_filename( $media_id, $new_filename ) { - // get the right filename extension + // Get the right filename extension. $new_filename_paths = pathinfo( $new_filename ); - $new_file_ext = $new_filename_paths['extension']; + $new_file_ext = $new_filename_paths['extension']; + + // Get the file parts from the current attachment. + $current_file = get_attached_file( $media_id ); + $current_file_parts = pathinfo( $current_file ); + $current_file_ext = $current_file_parts['extension']; + $current_file_dirname = $current_file_parts['dirname']; - // take out filename from the original file or from the current attachment + // Take out filename from the original file or from the current attachment. $original_media = (array) self::get_original_media( $media_id ); if ( ! empty( $original_media ) ) { $original_file_parts = pathinfo( $original_media['file'] ); - $filename_base = $original_file_parts['filename']; + $filename_base = $original_file_parts['filename']; } else { - $current_file = get_attached_file( $media_id ); - $current_file_parts = pathinfo( $current_file ); - $current_file_ext = $current_file_parts['filename']; $filename_base = $current_file_parts['filename']; } - // add unique seed based on the filename - $filename_base .= '-' . crc32( $filename_base ) . '-'; + // Add unique seed based on the filename. + $filename_base .= '-' . crc32( $filename_base ) . '-'; $number_suffix = time() . rand( 100, 999 ); do { - $filename = $filename_base; + $filename = $filename_base; $filename .= $number_suffix; - $file_ext = $new_file_ext ? $new_file_ext : $current_file_ext; + $file_ext = $new_file_ext ? $new_file_ext : $current_file_ext; $new_filename = "{$filename}.{$file_ext}"; - $new_path = "{$current_file_parts['dirname']}/$new_filename"; + $new_path = "{$current_file_dirname}/$new_filename"; $number_suffix++; - } while( file_exists( $new_path ) ); + } while ( file_exists( $new_path ) ); return $new_filename; } @@ -70,7 +73,7 @@ class Jetpack_Media { * @param number $media_id * @return string */ - private function get_time_string_from_guid( $media_id ) { + private static function get_time_string_from_guid( $media_id ) { $time = date( "Y/m", strtotime( current_time( 'mysql' ) ) ); if ( $media = get_post( $media_id ) ) { @@ -397,22 +400,24 @@ class Jetpack_Media { * - preserve original media file * - trace revision history * - * @param number $media_id - media post ID - * @param array $file_array - temporal file + * @param number $media_id - media post ID. + * @param array $file_array - temporal file. * @return {Post|WP_Error} Updated media item or a WP_Error is something went wrong. */ public static function edit_media_file( $media_id, $file_array ) { - $media_item = get_post( $media_id ); + $media_item = get_post( $media_id ); $has_original_media = self::get_original_media( $media_id ); if ( ! $has_original_media ) { + // The first time that the media is updated - // the original media is stored into the revision_history + // the original media is stored into the revision_history. $snapshot = self::get_snapshot( $media_item ); + //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase add_post_meta( $media_id, self::$WP_ORIGINAL_MEDIA, $snapshot, true ); } - // save temporary file in the correct location + // Save temporary file in the correct location. $uploaded_file = self::save_temporary_file( $file_array, $media_id ); if ( is_wp_error( $uploaded_file ) ) { @@ -420,27 +425,30 @@ class Jetpack_Media { return $uploaded_file; } - // revision_history control + // Revision_history control. self::register_revision( $media_item, $uploaded_file, $has_original_media ); - $uploaded_path = $uploaded_file['file']; + $uploaded_path = $uploaded_file['file']; $udpated_mime_type = $uploaded_file['type']; - $was_updated = update_attached_file( $media_id, $uploaded_path ); + $was_updated = update_attached_file( $media_id, $uploaded_path ); if ( ! $was_updated ) { return WP_Error( 'update_error', 'Media update error' ); } + // Check maximum amount of revision_history before updating the attachment metadata. + self::limit_revision_history( $media_id ); + $new_metadata = wp_generate_attachment_metadata( $media_id, $uploaded_path ); wp_update_attachment_metadata( $media_id, $new_metadata ); - // check maximum amount of revision_history - self::limit_revision_history( $media_id ); - - $edited_action = wp_update_post( (object) array( - 'ID' => $media_id, - 'post_mime_type' => $udpated_mime_type - ), true ); + $edited_action = wp_update_post( + (object) array( + 'ID' => $media_id, + 'post_mime_type' => $udpated_mime_type, + ), + true + ); if ( is_wp_error( $edited_action ) ) { return $edited_action; @@ -456,4 +464,3 @@ function clean_revision_history( $media_id ) { }; add_action( 'delete_attachment', 'clean_revision_history' ); - diff --git a/plugins/jetpack/_inc/lib/core-api/load-wpcom-endpoints.php b/plugins/jetpack/_inc/lib/core-api/load-wpcom-endpoints.php index 2b26f78c..f9e1fb44 100644 --- a/plugins/jetpack/_inc/lib/core-api/load-wpcom-endpoints.php +++ b/plugins/jetpack/_inc/lib/core-api/load-wpcom-endpoints.php @@ -35,6 +35,11 @@ function wpcom_rest_api_v2_load_plugin( $class_name ) { require dirname( __FILE__ ) . '/class-wpcom-rest-field-controller.php'; -// Now load the endpoint files. -wpcom_rest_api_v2_load_plugin_files( 'wpcom-endpoints/*.php' ); -wpcom_rest_api_v2_load_plugin_files( 'wpcom-fields/*.php' ); +/** + * Load the REST API v2 plugin files during the plugins_loaded action. + */ +function load_wpcom_rest_api_v2_plugin_files() { + wpcom_rest_api_v2_load_plugin_files( 'wpcom-endpoints/*.php' ); + wpcom_rest_api_v2_load_plugin_files( 'wpcom-fields/*.php' ); +} +add_action( 'plugins_loaded', 'load_wpcom_rest_api_v2_plugin_files' ); diff --git a/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-resolve-redirect.php b/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-resolve-redirect.php index 442a2efa..c3777f6d 100644 --- a/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-resolve-redirect.php +++ b/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-resolve-redirect.php @@ -36,7 +36,9 @@ class WPCOM_REST_API_V2_Endpoint_Resolve_Redirect extends WP_REST_Controller { 'description' => __( 'The URL to check for redirects.', 'jetpack' ), 'type' => 'string', 'required' => 'true', - 'validate_callback' => 'wp_http_validate_url', + 'validate_callback' => function ( $param ) { + return wp_http_validate_url( $param ); + }, ), ), array( @@ -50,45 +52,83 @@ class WPCOM_REST_API_V2_Endpoint_Resolve_Redirect extends WP_REST_Controller { } /** - * Follows 301/302 redirect for the passed URL, and returns the final destination. + * Follows 301/302 redirect for the passed URL, and returns the final destination and status code. * * @param WP_REST_Request $request The REST API request data. * @return WP_REST_Response The REST API response. */ public function follow_redirect( $request ) { - $response = wp_safe_remote_get( $request['url'] ); - if ( is_wp_error( $response ) ) { - return rest_ensure_response( '' ); - } - - $history = $response['http_response']->get_response_object()->history; - if ( ! $history ) { - return response_ensure_response( $request['url'] ); - } + // Add a User-Agent header since the request is sometimes blocked without it. + $response = wp_safe_remote_get( + $request['url'], + array( + 'headers' => array( + 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:71.0) Gecko/20100101 Firefox/71.0', + ), + ) + ); - $location = $history[0]->headers->getValues( 'location' ); - if ( ! $location ) { - return response_ensure_response( $request['url'] ); + if ( is_wp_error( $response ) ) { + return rest_ensure_response( + array( + 'url' => '', + 'status' => $response->get_error_code(), + ) + ); } - return rest_ensure_response( $location[0] ); + return rest_ensure_response( + array( + 'url' => $this->get_response_url( $response['http_response']->get_response_object() ), + 'status' => wp_remote_retrieve_response_code( $response ), + ) + ); } /** - * Retrieves the comment's schema, conforming to JSON Schema. + * Retrieves the response schema, conforming to JSON Schema. * * @return array */ public function get_item_schema() { $schema = array( - '$schema' => 'http://json-schema.org/draft-04/schema#', - 'title' => 'resolve-redirect', - 'type' => 'string', - 'description' => __( 'The final destination of the URL being checked for redirects.', 'jetpack' ), + '$schema' => 'http://json-schema.org/draft-04/schema#', + 'title' => 'resolve-redirect', + 'type' => 'object', + 'properties' => array( + 'url' => array( + 'description' => __( 'The final destination of the URL being checked for redirects.', 'jetpack' ), + 'type' => 'string', + ), + 'status' => array( + 'description' => __( 'The status code of the URL\'s response.', 'jetpack' ), + 'type' => 'integer', + ), + ), ); return $schema; } + + /** + * Finds the destination url from an http response. + * + * @param Requests_Response $response Response object. + * @return string Final url of the response. + */ + protected function get_response_url( Requests_Response $response ) { + $history = $response->history; + if ( ! $history ) { + return $response->url; + } + + $location = $history[0]->headers->getValues( 'location' ); + if ( ! $location ) { + return $response->url; + } + + return $location[0]; + } } wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Endpoint_Resolve_Redirect' ); diff --git a/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/service-api-keys.php b/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/service-api-keys.php index 05d0ddd3..edf174cf 100644 --- a/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/service-api-keys.php +++ b/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/service-api-keys.php @@ -1,13 +1,14 @@ <?php -/* +/** * Service API Keys: Exposes 3rd party api keys that are used on a site. * * [ * { # Availabilty Object. See schema for more detail. - * code: (string) Displays success if the operation was successfully executed and an error code if it was not - * service: (string) The name of the service in question - * service_api_key: (string) The API key used by the service empty if one is not set yet - * message: (string) User friendly message + * code: (string) Displays success if the operation was successfully executed and an error code if it was not + * service: (string) The name of the service in question + * service_api_key: (string) The API key used by the service empty if one is not set yet + * service_api_key_source: (string) The source of the API key, defaults to "site" + * message: (string) User friendly message * }, * ... * ] @@ -77,19 +78,23 @@ class WPCOM_REST_API_V2_Endpoint_Service_API_Keys extends WP_REST_Controller { 'title' => 'service-api-keys', 'type' => 'object', 'properties' => array( - 'code' => array( + 'code' => array( 'description' => __( 'Displays success if the operation was successfully executed and an error code if it was not', 'jetpack' ), 'type' => 'string', ), - 'service' => array( + 'service' => array( 'description' => __( 'The name of the service in question', 'jetpack' ), 'type' => 'string', ), - 'service_api_key' => array( + 'service_api_key' => array( 'description' => __( 'The API key used by the service. Empty if none has been set yet', 'jetpack' ), 'type' => 'string', ), - 'message' => array( + 'service_api_key_source' => array( + 'description' => __( 'The source of the API key. Defaults to "site"', 'jetpack' ), + 'type' => 'string', + ), + 'message' => array( 'description' => __( 'User friendly message', 'jetpack' ), 'type' => 'string', ), @@ -109,18 +114,31 @@ class WPCOM_REST_API_V2_Endpoint_Service_API_Keys extends WP_REST_Controller { * } */ public static function get_service_api_key( $request ) { - $service = self::validate_service_api_service( $request['service'] ); if ( ! $service ) { return self::service_api_invalid_service_response(); } - $option = self::key_for_api_service( $service ); + + switch ( $service ) { + case 'mapbox': + $mapbox = self::get_service_api_key_mapbox(); + $service_api_key = $mapbox['key']; + $service_api_key_source = $mapbox['source']; + break; + default: + $option = self::key_for_api_service( $service ); + $service_api_key = Jetpack_Options::get_option( $option, '' ); + $service_api_key_source = 'site'; + }; + $message = esc_html__( 'API key retrieved successfully.', 'jetpack' ); + return array( - 'code' => 'success', - 'service' => $service, - 'service_api_key' => Jetpack_Options::get_option( $option, '' ), - 'message' => $message, + 'code' => 'success', + 'service' => $service, + 'service_api_key' => $service_api_key, + 'service_api_key_source' => $service_api_key_source, + 'message' => $message, ); } @@ -269,6 +287,82 @@ class WPCOM_REST_API_V2_Endpoint_Service_API_Keys extends WP_REST_Controller { } /** + * Get the site's own Mapbox API key if set, or the WordPress.com's one otherwise. + * + * @return array An array containing the key (if any) and its source ("site" or "wpcom"). + */ + public static function get_service_api_key_mapbox() { + // If the site provides its own Mapbox API key, return it. + $service_api_key = Jetpack_Options::get_option( self::key_for_api_service( 'mapbox' ) ); + if ( $service_api_key ) { + return self::format_api_key( $service_api_key ); + } + + // If the site is not WordPress.com, return an empty API key. + $site_id = self::get_wpcom_site_id(); + if ( ( ! self::is_wpcom() && ! jetpack_is_atomic_site() ) || ! $site_id ) { + return self::format_api_key(); + } + + // If there is a cached token, return it. + $transient_key = 'wpcom_mapbox_access_token'; + $cached_token = get_transient( $transient_key ); + if ( $cached_token ) { + return self::format_api_key( $cached_token, 'wpcom' ); + } + + // Otherwise retrieve a WordPress.com token. + $request_url = 'https://public-api.wordpress.com/wpcom/v2/sites/' . $site_id . '/mapbox'; + $response = wp_remote_get( esc_url_raw( $request_url ) ); + if ( 200 !== wp_remote_retrieve_response_code( $response ) ) { + return self::format_api_key(); + } + + $response_body = json_decode( wp_remote_retrieve_body( $response ) ); + $wpcom_mapbox_access_token = $response_body->wpcom_mapbox_access_token; + + set_transient( $transient_key, $wpcom_mapbox_access_token, HOUR_IN_SECONDS ); + return self::format_api_key( $wpcom_mapbox_access_token, 'wpcom' ); + } + + /** + * Format an API key and its source into an array. + * + * @param string $key The API key. + * @param string $source The key's source ("site" or "wpcom"). + * @return array + */ + private static function format_api_key( $key = '', $source = 'site' ) { + return array( + 'key' => $key, + 'source' => $source, + ); + } + + /** + * Check if we're in WordPress.com. + * + * @return bool + */ + private static function is_wpcom() { + return defined( 'IS_WPCOM' ) && IS_WPCOM; + } + + /** + * Get the current site's WordPress.com ID. + * + * @return mixed The site's WordPress.com ID or an empty string. + */ + private static function get_wpcom_site_id() { + if ( self::is_wpcom() ) { + return get_current_blog_id(); + } elseif ( method_exists( 'Jetpack', 'is_active' ) && Jetpack::is_active() ) { + return Jetpack_Options::get_option( 'id' ); + } + return false; + } + + /** * Create site option key for service * * @param string $service The service to create key for. diff --git a/plugins/jetpack/_inc/lib/debugger/class-jetpack-cxn-tests.php b/plugins/jetpack/_inc/lib/debugger/class-jetpack-cxn-tests.php index 6e3cccd6..87fbfc06 100644 --- a/plugins/jetpack/_inc/lib/debugger/class-jetpack-cxn-tests.php +++ b/plugins/jetpack/_inc/lib/debugger/class-jetpack-cxn-tests.php @@ -40,10 +40,11 @@ class Jetpack_Cxn_Tests extends Jetpack_Cxn_Test_Base { * Determines if the WP.com testing suite should be included. * * @since 7.1.0 + * @since 8.1.0 Default false. * - * @param bool $run_test To run the WP.com testing suite. Default true. + * @param bool $run_test To run the WP.com testing suite. Default false. */ - if ( apply_filters( 'jetpack_debugger_run_self_test', true ) ) { + if ( apply_filters( 'jetpack_debugger_run_self_test', false ) ) { /** * Intentionally added last as it checks for an existing failure state before attempting. * Generally, any failed location condition would result in the WP.com check to fail too, so @@ -157,7 +158,7 @@ class Jetpack_Cxn_Tests extends Jetpack_Cxn_Test_Base { if ( function_exists( 'xml_parser_create' ) ) { $result = self::passing_test( $name ); } else { - $result = self::failing_test( $name, __( 'PHP XML manipluation libraries are not available.', 'jetpack' ), __( "Please ask your hosting provider to refer to our server requirements at https://jetpack.com/support/server-requirements/ and enable PHP's XML module.", 'jetpack' ) ); + $result = self::failing_test( $name, __( 'PHP XML manipulation libraries are not available.', 'jetpack' ), __( "Please ask your hosting provider to refer to our server requirements at https://jetpack.com/support/server-requirements/ and enable PHP's XML module.", 'jetpack' ) ); } return $result; @@ -237,7 +238,8 @@ class Jetpack_Cxn_Tests extends Jetpack_Cxn_Test_Base { protected function test__wpcom_connection_test() { $name = __FUNCTION__; - if ( ! Jetpack::is_active() || ( new Status() )->is_development_mode() || Jetpack::is_staging_site() || ! $this->pass ) { + $status = new Status(); + if ( ! Jetpack::is_active() || $status->is_development_mode() || $status->is_staging_site() || ! $this->pass ) { return self::skipped_test( $name ); } @@ -343,7 +345,8 @@ class Jetpack_Cxn_Tests extends Jetpack_Cxn_Test_Base { protected function last__wpcom_self_test() { $name = 'test__wpcom_self_test'; - if ( ! Jetpack::is_active() || ( new Status() )->is_development_mode() || Jetpack::is_staging_site() || ! $this->pass ) { + $status = new Status(); + if ( ! Jetpack::is_active() || $status->is_development_mode() || $status->is_staging_site() || ! $this->pass ) { return self::skipped_test( $name ); } diff --git a/plugins/jetpack/_inc/lib/jetpack-wpes-query-builder/jetpack-wpes-query-builder.php b/plugins/jetpack/_inc/lib/jetpack-wpes-query-builder/jetpack-wpes-query-builder.php index d3481ce5..62b0ddda 100644 --- a/plugins/jetpack/_inc/lib/jetpack-wpes-query-builder/jetpack-wpes-query-builder.php +++ b/plugins/jetpack/_inc/lib/jetpack-wpes-query-builder/jetpack-wpes-query-builder.php @@ -1,6 +1,5 @@ <?php - /** * Provides an interface for easily building a complex search query that * combines multiple ranking signals. @@ -16,6 +15,8 @@ * All ES queries take a standard form with main query (with some filters), * wrapped in a function_score * + * Most functions are chainable, e.g. $bldr->add_filter( ... )->add_query( ... )->build_query(); + * * Bucketed queries use an aggregation to diversify results. eg a bunch * of separate filters where to get different sets of results. * @@ -27,10 +28,12 @@ class Jetpack_WPES_Query_Builder { // Custom boosting with function_score protected $functions = array(); + protected $weighting_functions = array(); protected $decays = array(); protected $scripts = array(); protected $functions_max_boost = 2.0; protected $functions_score_mode = 'multiply'; + protected $functions_boost_mode = 'multiply'; protected $query_bool_boost = null; // General aggregations for buckets and metrics @@ -46,11 +49,20 @@ class Jetpack_WPES_Query_Builder { protected $bucket_filters = array(); protected $bucket_sub_aggs = array(); + public function get_langs() { + if ( isset( $this->langs ) ) { + return $this->langs; + } + return false; + } + //////////////////////////////////// // Methods for building a query public function add_filter( $filter ) { $this->es_filters[] = $filter; + + return $this; } public function add_query( $query, $type = 'must' ) { @@ -68,6 +80,23 @@ class Jetpack_WPES_Query_Builder { $this->must_queries[] = $query; break; } + + return $this; + } + + /** + * Add any weighting function to the query + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html + * + * @param $function array A function structure to apply to the query + * + * @return void + */ + public function add_weighting_function( $function ) { + $this->weighting_functions[] = $function; + + return $this; } /** @@ -84,6 +113,8 @@ class Jetpack_WPES_Query_Builder { */ public function add_function( $function, $params ) { $this->functions[ $function ][] = $params; + + return $this; } /** @@ -101,6 +132,8 @@ class Jetpack_WPES_Query_Builder { */ public function add_decay( $function, $params ) { $this->decays[ $function ][] = $params; + + return $this; } /** @@ -114,19 +147,40 @@ class Jetpack_WPES_Query_Builder { */ public function add_score_mode_to_functions( $mode='multiply' ) { $this->functions_score_mode = $mode; + + return $this; + } + + public function add_boost_mode_to_functions( $mode='multiply' ) { + $this->functions_boost_mode = $mode; + + return $this; } public function add_max_boost_to_functions( $boost ) { $this->functions_max_boost = $boost; + + return $this; } public function add_boost_to_query_bool( $boost ) { $this->query_bool_boost = $boost; + + return $this; } public function add_aggs( $aggs_name, $aggs ) { $this->aggs_query = true; $this->aggs[$aggs_name] = $aggs; + + return $this; + } + + public function set_all_aggs( $aggs ) { + $this->aggs_query = true; + $this->aggs = $aggs; + + return $this; } public function add_aggs_sub_aggs( $aggs_name, $sub_aggs ) { @@ -134,12 +188,16 @@ class Jetpack_WPES_Query_Builder { $this->aggs[$aggs_name]['aggs'] = array(); } $this->aggs[$aggs_name]['aggs'] = $sub_aggs; + + return $this; } public function add_bucketed_query( $name, $query ) { $this->_add_bucket_filter( $name, $query ); $this->add_query( $query, 'dis_max' ); + + return $this; } public function add_bucketed_terms( $name, $field, $terms, $boost = 1 ) { @@ -163,10 +221,14 @@ class Jetpack_WPES_Query_Builder { 'boost' => $boost, ), ), 'dis_max' ); + + return $this; } public function add_bucket_sub_aggs( $agg ) { $this->bucket_sub_aggs = array_merge( $this->bucket_sub_aggs, $agg ); + + return $this; } protected function _add_bucket_filter( $name, $filter ) { @@ -203,15 +265,11 @@ class Jetpack_WPES_Query_Builder { } if ( empty( $this->should_queries ) ) { - if ( 1 == count( $this->must_queries ) ) { - $query = $this->must_queries[0]; - } else { - $query = array( - 'bool' => array( - 'must' => $this->must_queries, - ), - ); - } + $query = array( + 'bool' => array( + 'must' => $this->must_queries, + ), + ); } else { $query = array( 'bool' => array( @@ -226,7 +284,7 @@ class Jetpack_WPES_Query_Builder { } // If there are any function score adjustments, then combine those - if ( $this->functions || $this->decays || $this->scripts ) { + if ( $this->functions || $this->decays || $this->scripts || $this->weighting_functions ) { $weighting_functions = array(); if ( $this->functions ) { @@ -275,6 +333,7 @@ class Jetpack_WPES_Query_Builder { 'functions' => $weighting_functions, 'max_boost' => $this->functions_max_boost, 'score_mode' => $this->functions_score_mode, + 'boost_mode' => $this->functions_boost_mode, ), ); } // End if(). diff --git a/plugins/jetpack/_inc/lib/jetpack-wpes-query-builder/jetpack-wpes-query-parser.php b/plugins/jetpack/_inc/lib/jetpack-wpes-query-builder/jetpack-wpes-query-parser.php index 2b7710cb..42a82ede 100644 --- a/plugins/jetpack/_inc/lib/jetpack-wpes-query-builder/jetpack-wpes-query-parser.php +++ b/plugins/jetpack/_inc/lib/jetpack-wpes-query-builder/jetpack-wpes-query-parser.php @@ -31,7 +31,7 @@ * Example usage (from Search on Reader Manage): * * require_lib( 'jetpack-wpes-query-builder/jetpack-wpes-search-query-parser' ); - * $parser = new WPES_Search_Query_Parser( $args['q'], array( $lang ) ); + * $parser = new Jetpack_WPES_Search_Query_Parser( $args['q'], array( $lang ) ); * * //author * $parser->author_field_filter( array( @@ -124,6 +124,14 @@ class Jetpack_WPES_Search_Query_Parser extends Jetpack_WPES_Query_Builder { protected $extracted_phrases = array(); + public function get_current_query() { + return $this->current_query; + } + + public function set_current_query( $q ) { + $this->current_query = $q; + } + /////////////////////////////////////////////////////// // Methods for Building arrays of multilingual fields |