diff options
author | Yury German <blueknight@gentoo.org> | 2016-02-12 22:22:00 -0500 |
---|---|---|
committer | Yury German <blueknight@gentoo.org> | 2016-02-12 22:22:00 -0500 |
commit | 657cafe0e955cf88033597f131aa50835140c617 (patch) | |
tree | cf21a30d319cb2a238a6cfb8b4eb3b20b1b5dcff /plugins/jetpack/modules/infinite-scroll/infinity.php | |
parent | Adding New Mantra version 2.4.1.1 - Bug 574468 (diff) | |
download | blogs-gentoo-657cafe0e955cf88033597f131aa50835140c617.tar.gz blogs-gentoo-657cafe0e955cf88033597f131aa50835140c617.tar.bz2 blogs-gentoo-657cafe0e955cf88033597f131aa50835140c617.zip |
Updating plugins easy-table, jetpack, openid, public-post preview, talbe-of-contents-plus, wordress-mobile-pack - Bug 574468
Diffstat (limited to 'plugins/jetpack/modules/infinite-scroll/infinity.php')
-rw-r--r-- | plugins/jetpack/modules/infinite-scroll/infinity.php | 277 |
1 files changed, 253 insertions, 24 deletions
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 ); ?><script type="text/javascript"> @@ -854,7 +955,27 @@ class The_Neverending_Home_Page { if ( ! isset( $results['scripts'] ) ) $results['scripts'] = array(); - $results['scripts'] = apply_filters( 'infinite_scroll_additional_scripts', $results['scripts'], $initial_scripts, $results, $query_args, $wp_query ); + /** + * Filter the additional scripts required by the latest set of IS posts. + * + * @module infinite-scroll + * + * @since 2.1.2 + * + * @param array $results['scripts'] Additional scripts required by the latest set of IS posts. + * @param array|bool $initial_scripts Set of scripts loaded on each page. + * @param array $results Array of Infinite Scroll results. + * @param array $query_args Array of Query arguments. + * @param WP_Query $wp_query WP Query. + */ + $results['scripts'] = apply_filters( + 'infinite_scroll_additional_scripts', + $results['scripts'], + $initial_scripts, + $results, + $query_args, + $wp_query + ); if ( empty( $results['scripts'] ) ) unset( $results['scripts' ] ); @@ -938,7 +1059,27 @@ class The_Neverending_Home_Page { if ( ! isset( $results['styles'] ) ) $results['styles'] = array(); - $results['styles'] = apply_filters( 'infinite_scroll_additional_stylesheets', $results['styles'], $initial_styles, $results, $query_args, $wp_query ); + /** + * Filter the additional styles required by the latest set of IS posts. + * + * @module infinite-scroll + * + * @since 2.1.2 + * + * @param array $results['styles'] Additional styles required by the latest set of IS posts. + * @param array|bool $initial_styles Set of styles loaded on each page. + * @param array $results Array of Infinite Scroll results. + * @param array $query_args Array of Query arguments. + * @param WP_Query $wp_query WP Query. + */ + $results['styles'] = apply_filters( + 'infinite_scroll_additional_stylesheets', + $results['styles'], + $initial_styles, + $results, + $query_args, + $wp_query + ); if ( empty( $results['styles'] ) ) unset( $results['styles' ] ); @@ -1003,6 +1144,15 @@ class The_Neverending_Home_Page { // Since IS is only used on archives, we should always display the first page of any paged content. unset( $query_args['page'] ); + /** + * Filter the array of main query arguments. + * + * @module infinite-scroll + * + * @since 2.0.1 + * + * @param array $query_args Array of Query arguments. + */ $query_args = apply_filters( 'infinite_scroll_query_args', $query_args ); // Add query filter that checks for posts below the date @@ -1018,12 +1168,21 @@ class The_Neverending_Home_Page { // Fire wp_head to ensure that all necessary scripts are enqueued. Output isn't used, but scripts are extracted in self::action_wp_footer. ob_start(); wp_head(); - ob_end_clean(); + while ( ob_get_length() ) { + ob_end_clean(); + } $results['type'] = 'success'; // First, try theme's specified rendering handler, either specified via `add_theme_support` or by hooking to this action directly. ob_start(); + /** + * Fires when rendering Infinite Scroll posts. + * + * @module infinite-scroll + * + * @since 2.0.0 + */ do_action( 'infinite_scroll_render' ); $results['html'] = ob_get_clean(); @@ -1033,6 +1192,7 @@ class The_Neverending_Home_Page { rewind_posts(); ob_start(); + /** This action is already documented in modules/infinite-scroll/infinity.php */ do_action( 'infinite_scroll_render' ); $results['html'] = ob_get_clean(); } @@ -1040,6 +1200,13 @@ class The_Neverending_Home_Page { // If primary and fallback rendering methods fail, prevent further IS rendering attempts. Otherwise, wrap the output if requested. if ( empty( $results['html'] ) ) { unset( $results['html'] ); + /** + * Fires when Infinite Scoll doesn't render any posts. + * + * @module infinite-scroll + * + * @since 2.0.0 + */ do_action( 'infinite_scroll_empty' ); $results['type'] = 'empty'; } elseif ( $this->has_wrapper() ) { @@ -1053,7 +1220,9 @@ class The_Neverending_Home_Page { // Fire wp_footer to ensure that all necessary scripts are enqueued. Output isn't used, but scripts are extracted in self::action_wp_footer. ob_start(); wp_footer(); - ob_end_clean(); + while ( ob_get_length() ) { + ob_end_clean(); + } if ( 'success' == $results['type'] ) { global $currentday; @@ -1074,11 +1243,25 @@ class The_Neverending_Home_Page { $results['postflair'] = array_flip( $jetpack_sharing_counts ); } } else { + /** This action is already documented in modules/infinite-scroll/infinity.php */ do_action( 'infinite_scroll_empty' ); $results['type'] = 'empty'; } - echo wp_json_encode( apply_filters( 'infinite_scroll_results', $results, $query_args, self::wp_query() ) ); + echo wp_json_encode( + /** + * Filter the Infinite Scroll results. + * + * @module infinite-scroll + * + * @since 2.0.0 + * + * @param array $results Array of Infinite Scroll results. + * @param array $query_args Array of main query arguments. + * @param WP_Query $wp_query WP Query. + */ + apply_filters( 'infinite_scroll_results', $results, $query_args, self::wp_query() ) + ); die; } @@ -1134,6 +1317,16 @@ class The_Neverending_Home_Page { * @return array */ function inject_query_args( $query_args ) { + /** + * Filter the array of allowed Infinite Scroll query arguments. + * + * @module infinite-scroll + * + * @since 2.6.0 + * + * @param array $args Array of allowed Infinite Scroll query arguments. + * @param array $query_args Array of query arguments. + */ $allowed_vars = apply_filters( 'infinite_scroll_allowed_vars', array(), $query_args ); $query_args = array_merge( $query_args, array( @@ -1173,11 +1366,22 @@ class The_Neverending_Home_Page { */ public static function archive_supports_infinity() { $supported = current_theme_supports( 'infinite-scroll' ) && ( is_home() || is_archive() || is_search() ); - // Disable infinite scroll in customizer previews - if ( isset( $_REQUEST[ 'wp_customize' ] ) && 'on' === $_REQUEST[ 'wp_customize' ] ) { + + // Disable when previewing a non-active theme in the customizer + if ( is_customize_preview() && ! $GLOBALS['wp_customize']->is_theme_active() ) { return false; } + /** + * Allow plugins to filter what archives Infinite Scroll supports. + * + * @module infinite-scroll + * + * @since 2.0.0 + * + * @param bool $supported Does the Archive page support Infinite Scroll. + * @param object self::get_settings() IS settings provided by theme. + */ return (bool) apply_filters( 'infinite_scroll_archive_supported', $supported, self::get_settings() ); } @@ -1210,8 +1414,23 @@ class The_Neverending_Home_Page { * @return string */ private function default_footer() { - $credits = '<a href="http://wordpress.org/" rel="generator">Proudly powered by WordPress</a> '; - $credits .= sprintf( __( 'Theme: %1$s.', 'jetpack' ), function_exists( 'wp_get_theme' ) ? wp_get_theme()->Name : get_current_theme() ); + $credits = sprintf( + '<a href="http://wordpress.org/" rel="generator">%1$s</a> ', + __( 'Proudly powered by WordPress', 'jetpack' ) + ); + $credits .= sprintf( + __( 'Theme: %1$s.', 'jetpack' ), + function_exists( 'wp_get_theme' ) ? wp_get_theme()->Name : get_current_theme() + ); + /** + * Filter Infinite Scroll's credit text. + * + * @module infinite-scroll + * + * @since 2.0.0 + * + * @param string $credits Infinite Scroll credits. + */ $credits = apply_filters( 'infinite_scroll_credit', $credits ); ?> @@ -1274,6 +1493,16 @@ add_action( 'init', 'the_neverending_home_page_init', 20 ); function the_neverending_home_page_theme_support() { $theme_name = get_stylesheet(); + /** + * Filter the path to the Infinite Scroll compatibility file. + * + * @module infinite-scroll + * + * @since 2.0.0 + * + * @param string $str IS compatibility file path. + * @param string $theme_name Theme name. + */ $customization_file = apply_filters( 'infinite_scroll_customization_file', dirname( __FILE__ ) . "/themes/{$theme_name}.php", $theme_name ); if ( is_readable( $customization_file ) ) |