From 657cafe0e955cf88033597f131aa50835140c617 Mon Sep 17 00:00:00 2001 From: Yury German Date: Fri, 12 Feb 2016 22:22:00 -0500 Subject: Updating plugins easy-table, jetpack, openid, public-post preview, talbe-of-contents-plus, wordress-mobile-pack - Bug 574468 --- .../jetpack/modules/infinite-scroll/infinity.php | 277 +++++++++++++++++++-- 1 file changed, 253 insertions(+), 24 deletions(-) (limited to 'plugins/jetpack/modules/infinite-scroll/infinity.php') diff --git a/plugins/jetpack/modules/infinite-scroll/infinity.php b/plugins/jetpack/modules/infinite-scroll/infinity.php index ee8aef0d..2c00f448 100644 --- a/plugins/jetpack/modules/infinite-scroll/infinity.php +++ b/plugins/jetpack/modules/infinite-scroll/infinity.php @@ -194,7 +194,15 @@ class The_Neverending_Home_Page { $settings['footer_widgets'] = (bool) is_active_sidebar( $settings['footer_widgets'] ); } - // For complex logic, let themes filter the `footer_widgets` parameter. + /** + * Filter Infinite Scroll's `footer_widgets` parameter. + * + * @module infinite-scroll + * + * @since 2.0.0 + * + * @param bool $settings['footer_widgets'] Does the current theme have Footer Widgets. + */ $settings['footer_widgets'] = apply_filters( 'infinite_scroll_has_footer_widgets', $settings['footer_widgets'] ); // Finally, after all of the sidebar checks and filtering, ensure that a boolean value is present, otherwise set to default of `false`. @@ -211,13 +219,15 @@ class The_Neverending_Home_Page { $settings['type'] = 'click'; } - // Ignore posts_per_page theme setting for [click] type - if ( 'click' == $settings['type'] ) - $settings['posts_per_page'] = (int) get_option( 'posts_per_page' ); - - // Backwards compatibility for posts_per_page setting - elseif ( false === $settings['posts_per_page'] ) - $settings['posts_per_page'] = 7; + // posts_per_page defaults to 7 for scroll, posts_per_page option for click + if ( false === $settings['posts_per_page'] ) { + if ( 'scroll' === $settings['type'] ) { + $settings['posts_per_page'] = 7; + } + else { + $settings['posts_per_page'] = (int) get_option( 'posts_per_page' ); + } + } // Force display of the click handler and attendant bits when the type isn't `click` if ( 'click' !== $settings['type'] ) { @@ -225,6 +235,15 @@ class The_Neverending_Home_Page { } // Store final settings in a class static to avoid reparsing + /** + * Filter the array of Infinite Scroll settings. + * + * @module infinite-scroll + * + * @since 2.0.0 + * + * @param array $settings Array of Infinite Scroll settings. + */ self::$settings = apply_filters( 'infinite_scroll_settings', $settings ); } @@ -240,6 +259,15 @@ class The_Neverending_Home_Page { */ static function wp_query() { global $wp_the_query; + /** + * Filter the Infinite Scroll query object. + * + * @module infinite-scroll + * + * @since 2.2.1 + * + * @param WP_Query $wp_the_query WP Query. + */ return apply_filters( 'infinite_scroll_query_object', $wp_the_query ); } @@ -247,7 +275,16 @@ class The_Neverending_Home_Page { * Has infinite scroll been triggered? */ static function got_infinity() { - return isset( $_GET[ 'infinity' ] ); + /** + * Filter the parameter used to check if Infinite Scroll has been triggered. + * + * @module infinite-scroll + * + * @since 3.9.0 + * + * @param bool isset( $_GET[ 'infinity' ] ) Return true if the "infinity" parameter is set. + */ + return apply_filters( 'infinite_scroll_got_infinity', isset( $_GET[ 'infinity' ] ) ); } /** @@ -359,7 +396,7 @@ class The_Neverending_Home_Page { $disabled = '' === get_option( self::$option_name_enabled ) ? true : false; if ( ! $disabled || 'click' == self::get_settings()->type ) { $classes[] = 'infinite-scroll'; - + if ( 'scroll' == self::get_settings()->type ) $classes[] = 'neverending'; } @@ -404,7 +441,7 @@ class The_Neverending_Home_Page { * @return array */ function get_query_vars() { - + $query_vars = self::wp_query()->query_vars; //applies to search page only if ( true === self::wp_query()->is_search() ) { @@ -428,7 +465,7 @@ class The_Neverending_Home_Page { * @return bool */ function has_only_title_matching_posts() { - + //apply following logic for search page results only if ( false === self::wp_query()->is_search() ) { return false; @@ -436,10 +473,10 @@ class The_Neverending_Home_Page { //grab the last posts in the stack as if the last one is title-matching the rest is title-matching as well $post = end( self::wp_query()->posts ); - + //code inspired by WP_Query class if ( preg_match_all( '/".*?("|$)|((?<=[\t ",+])|^)[^\t ",+]+/', self::wp_query()->get( 's' ), $matches ) ) { - $search_terms = self::wp_query()->parse_search_terms( $matches[0] ); + $search_terms = self::wp_query()->query_vars['search_terms']; // if the search string has only short terms or stopwords, or is 10+ terms long, match it as sentence if ( empty( $search_terms ) || count( $search_terms ) > 9 ) { $search_terms = array( self::wp_query()->get( 's' ) ); @@ -449,9 +486,11 @@ class The_Neverending_Home_Page { } //actual testing. As search query combines multiple keywords with AND, it's enough to check if any of the keywords is present in the title - if ( false !== strpos( $post->post_title, current( $search_terms ) ) ) { + $term = current( $search_terms ); + if ( ! empty( $term ) && false !== strpos( $post->post_title, $term ) ) { return true; } + return false; } @@ -549,6 +588,18 @@ class The_Neverending_Home_Page { // Construct the date query using our timestamp $clause = $wpdb->prepare( " AND {$wpdb->posts}.{$sort_field} {$operator} %s", $last_post_date ); + /** + * Filter Infinite Scroll's SQL date query making sure post queries + * will always return results prior to (descending sort) + * or before (ascending sort) the last post date. + * + * @module infinite-scroll + * + * @param string $clause SQL Date query. + * @param object $query Query. + * @param string $operator Query operator. + * @param string $last_post_date Last Post Date timestamp. + */ $where .= apply_filters( 'infinite_scroll_posts_where', $clause, $query, $operator, $last_post_date ); } @@ -590,6 +641,15 @@ class The_Neverending_Home_Page { $ajaxurl = add_query_arg( array( 'infinity' => 'scrolling' ), $base_url ); + /** + * Filter the Infinite Scroll Ajax URL. + * + * @module infinite-scroll + * + * @since 2.0.0 + * + * @param string $ajaxurl Infinite Scroll Ajax URL. + */ return apply_filters( 'infinite_scroll_ajax_url', $ajaxurl ); } @@ -609,6 +669,13 @@ class The_Neverending_Home_Page { @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); send_nosniff_header(); + /** + * Fires at the end of the Infinite Scroll Ajax response. + * + * @module infinite-scroll + * + * @since 2.0.0 + */ do_action( 'custom_ajax_infinite_scroll' ); die( '0' ); } @@ -695,8 +762,24 @@ class The_Neverending_Home_Page { $js_settings['order'] = $order; } + /** + * Filter the Infinite Scroll JS settings outputted in the head. + * + * @module infinite-scroll + * + * @since 2.0.0 + * + * @param array $js_settings Infinite Scroll JS settings. + */ $js_settings = apply_filters( 'infinite_scroll_js_settings', $js_settings ); + /** + * Fires before Infinite Scroll outputs inline JavaScript in the head. + * + * @module infinite-scroll + * + * @since 2.0.0 + */ do_action( 'infinite_scroll_wp_head' ); ?> @@ -776,9 +859,27 @@ class The_Neverending_Home_Page { global $wp_scripts, $wp_styles; $scripts = is_a( $wp_scripts, 'WP_Scripts' ) ? $wp_scripts->done : array(); + /** + * Filter the list of scripts already present on the page. + * + * @module infinite-scroll + * + * @since 2.1.2 + * + * @param array $scripts Array of scripts present on the page. + */ $scripts = apply_filters( 'infinite_scroll_existing_scripts', $scripts ); $styles = is_a( $wp_styles, 'WP_Styles' ) ? $wp_styles->done : array(); + /** + * Filter the list of styles already present on the page. + * + * @module infinite-scroll + * + * @since 2.1.2 + * + * @param array $styles Array of styles present on the page. + */ $styles = apply_filters( 'infinite_scroll_existing_stylesheets', $styles ); ?>