Example #1
0
 /**
  * Runs the query and returns the results via JSON.
  * Triggered by an AJAX request.
  *
  * @global $wp_query
  * @global $wp_the_query
  * @uses current_theme_supports, get_option, self::wp_query, self::set_last_post_time, current_user_can, apply_filters, self::get_settings, add_filter, WP_Query, remove_filter, have_posts, wp_head, do_action, add_action, this::render, this::has_wrapper, esc_attr, wp_footer, sharing_register_post_for_share_counts, get_the_id
  * @return string or null
  */
 function query()
 {
     if (!isset($_GET['page']) || !current_theme_supports('infinite-scroll')) {
         die;
     }
     $page = (int) $_GET['page'];
     $sticky = get_option('sticky_posts');
     $post__not_in = self::wp_query()->get('post__not_in');
     if (!empty($post__not_in)) {
         $sticky = array_unique(array_merge($sticky, $post__not_in));
     }
     if (!empty($_GET['date'])) {
         self::set_last_post_time($_GET['date']);
     }
     $post_status = array('publish');
     if (current_user_can('read_private_posts')) {
         array_push($post_status, 'private');
     }
     $order = in_array($_GET['order'], array('ASC', 'DESC')) ? $_GET['order'] : 'DESC';
     $query_args = array_merge(self::wp_query()->query_vars, array('paged' => $page, 'post_status' => $post_status, 'posts_per_page' => self::get_settings()->posts_per_page, 'post__not_in' => (array) $sticky, 'order' => $order));
     // By default, don't query for a specific page of a paged post object.
     // This argument can come from merging self::wp_query() into $query_args above.
     // Since IS is only used on archives, we should always display the first page of any paged content.
     unset($query_args['page']);
     $query_args = apply_filters('infinite_scroll_query_args', $query_args);
     // Add query filter that checks for posts below the date
     add_filter('posts_where', array($this, 'query_time_filter'), 10, 2);
     $GLOBALS['wp_the_query'] = $GLOBALS['wp_query'] = new WP_Query($query_args);
     remove_filter('posts_where', array($this, 'query_time_filter'), 10, 2);
     $results = array();
     if (have_posts()) {
         // 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();
         $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();
         do_action('infinite_scroll_render');
         $results['html'] = ob_get_clean();
         // Fall back if a theme doesn't specify a rendering function. Because themes may hook additional functions to the `infinite_scroll_render` action, `has_action()` is ineffective here.
         if (empty($results['html'])) {
             add_action('infinite_scroll_render', array($this, 'render'));
             rewind_posts();
             ob_start();
             do_action('infinite_scroll_render');
             $results['html'] = ob_get_clean();
         }
         // 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']);
             do_action('infinite_scroll_empty');
             $results['type'] = 'empty';
         } elseif ($this->has_wrapper()) {
             $wrapper_classes = is_string(self::get_settings()->wrapper) ? self::get_settings()->wrapper : 'infinite-wrap';
             $wrapper_classes .= ' infinite-view-' . $page;
             $wrapper_classes = trim($wrapper_classes);
             $results['html'] = '<div class="' . esc_attr($wrapper_classes) . '" id="infinite-view-' . $page . '" data-page-num="' . $page . '">' . $results['html'] . '</div>';
         }
         // 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();
         // Loop through posts to capture sharing data for new posts loaded via Infinite Scroll
         if ('success' == $results['type'] && function_exists('sharing_register_post_for_share_counts')) {
             global $jetpack_sharing_counts;
             while (have_posts()) {
                 the_post();
                 sharing_register_post_for_share_counts(get_the_ID());
             }
             $results['postflair'] = array_flip($jetpack_sharing_counts);
         }
     } else {
         do_action('infinite_scroll_empty');
         $results['type'] = 'empty';
     }
     echo json_encode(apply_filters('infinite_scroll_results', $results, $query_args, self::wp_query()));
     die;
 }
 public function get_display($post)
 {
     if ($this->smart) {
         $skype_share_html = sprintf('<div class="skype-share" data-href="%1$s" data-lang="%2$s" data-style="small" data-source="jetpack" ></div>', esc_attr($this->get_share_url($post->ID)), 'en-US');
         return $skype_share_html;
     }
     /** This filter is already documented in modules/sharedaddy/sharing-sources.php */
     if (apply_filters('jetpack_register_post_for_share_counts', true, $post->ID, 'skype')) {
         sharing_register_post_for_share_counts($post->ID);
     }
     return $this->get_link($this->get_process_request_url($post->ID), _x('Skype', 'share to', 'jetpack'), __('Share on Skype', 'jetpack'), 'share=skype', 'sharing-skype-' . $post->ID);
 }
 public function get_display($post)
 {
     $share_url = $this->get_share_url($post->ID);
     if ($this->smart) {
         $url = $this->http() . '://www.facebook.com/plugins/like.php?href=' . rawurlencode($share_url) . '&amp;layout=button_count&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;height=21';
         // Default widths to suit English
         $inner_w = 90;
         // Locale-specific widths/overrides
         $widths = array('bg_BG' => 120, 'bn_IN' => 100, 'cs_CZ' => 135, 'de_DE' => 120, 'da_DK' => 120, 'es_ES' => 122, 'es_LA' => 110, 'fi_FI' => 100, 'it_IT' => 100, 'ja_JP' => 100, 'pl_PL' => 100, 'nl_NL' => 130, 'ro_RO' => 100, 'ru_RU' => 128);
         $widths = apply_filters('sharing_facebook_like_widths', $widths);
         $locale = $this->guess_locale_from_lang(get_locale());
         if ($locale) {
             $url .= '&amp;locale=' . $locale;
             if (isset($widths[$locale])) {
                 $inner_w = $widths[$locale];
             }
         }
         $url .= '&amp;width=' . $inner_w;
         return '<div class="like_button"><iframe src="' . $url . '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:' . ($inner_w + 6) . 'px; height:21px;" allowTransparency="true"></iframe></div>';
     }
     if (apply_filters('jetpack_register_post_for_share_counts', true, $post->ID, 'facebook')) {
         sharing_register_post_for_share_counts($post->ID);
     }
     return $this->get_link(get_permalink($post->ID), _x('Facebook', 'share to', 'jetpack'), __('Share on Facebook', 'jetpack'), 'share=facebook', 'sharing-facebook-' . $post->ID);
 }
Example #4
0
 public function get_display($post)
 {
     $display = '';
     if ($this->smart) {
         $display = sprintf('<div class="pinterest_button"><a href="%s" data-pin-do="%s" data-pin-config="beside"><img src="//assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png" /></a></div>', esc_url($this->get_external_url($post)), esc_attr($this->get_widget_type()));
     } else {
         $display = $this->get_link($this->get_process_request_url($post->ID), _x('Pinterest', 'share to', 'jetpack'), __('Click to share on Pinterest', 'jetpack'), 'share=pinterest', 'sharing-pinterest-' . $post->ID);
     }
     /** This filter is already documented in modules/sharedaddy/sharing-sources.php */
     if (apply_filters('jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin')) {
         sharing_register_post_for_share_counts($post->ID);
     }
     return $display;
 }
Example #5
0
 /**
  * Runs the query and returns the results via JSON.
  * Triggered by an AJAX request.
  *
  * @global $wp_query
  * @global $wp_the_query
  * @uses current_theme_supports, get_option, self::wp_query, current_user_can, apply_filters, self::get_settings, add_filter, WP_Query, remove_filter, have_posts, wp_head, do_action, add_action, this::render, this::has_wrapper, esc_attr, wp_footer, sharing_register_post_for_share_counts, get_the_id
  * @return string or null
  */
 function query()
 {
     if (!isset($_REQUEST['page']) || !current_theme_supports('infinite-scroll')) {
         die;
     }
     $page = (int) $_REQUEST['page'];
     // Sanitize and set $previousday. Expected format: dd.mm.yy
     if (preg_match('/^\\d{2}\\.\\d{2}\\.\\d{2}$/', $_REQUEST['currentday'])) {
         global $previousday;
         $previousday = $_REQUEST['currentday'];
     }
     $sticky = get_option('sticky_posts');
     $post__not_in = self::wp_query()->get('post__not_in');
     //we have to take post__not_in args into consideration here not only sticky posts
     if (true === isset($_REQUEST['query_args']['post__not_in'])) {
         $post__not_in = array_merge($post__not_in, array_map('intval', (array) $_REQUEST['query_args']['post__not_in']));
     }
     if (!empty($post__not_in)) {
         $sticky = array_unique(array_merge($sticky, $post__not_in));
     }
     $post_status = array('publish');
     if (current_user_can('read_private_posts')) {
         array_push($post_status, 'private');
     }
     $order = in_array($_REQUEST['order'], array('ASC', 'DESC')) ? $_REQUEST['order'] : 'DESC';
     $query_args = array_merge(self::wp_query()->query_vars, array('paged' => $page, 'post_status' => $post_status, 'posts_per_page' => self::get_settings()->posts_per_page, 'post__not_in' => (array) $sticky, 'order' => $order));
     // 4.0 ?s= compatibility, see https://core.trac.wordpress.org/ticket/11330#comment:50
     if (empty($query_args['s']) && !isset(self::wp_query()->query['s'])) {
         unset($query_args['s']);
     }
     // By default, don't query for a specific page of a paged post object.
     // This argument can come from merging self::wp_query() into $query_args above.
     // 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
     add_filter('posts_where', array($this, 'query_time_filter'), 10, 2);
     $GLOBALS['wp_the_query'] = $GLOBALS['wp_query'] = new WP_Query($query_args);
     remove_filter('posts_where', array($this, 'query_time_filter'), 10, 2);
     $results = array();
     if (have_posts()) {
         // 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();
         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();
         // Fall back if a theme doesn't specify a rendering function. Because themes may hook additional functions to the `infinite_scroll_render` action, `has_action()` is ineffective here.
         if (empty($results['html'])) {
             add_action('infinite_scroll_render', array($this, 'render'));
             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();
         }
         // 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()) {
             $wrapper_classes = is_string(self::get_settings()->wrapper) ? self::get_settings()->wrapper : 'infinite-wrap';
             $wrapper_classes .= ' infinite-view-' . $page;
             $wrapper_classes = trim($wrapper_classes);
             $results['html'] = '<div class="' . esc_attr($wrapper_classes) . '" id="infinite-view-' . $page . '" data-page-num="' . $page . '">' . $results['html'] . '</div>';
         }
         // 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();
         while (ob_get_length()) {
             ob_end_clean();
         }
         if ('success' == $results['type']) {
             global $currentday;
             $results['lastbatch'] = self::is_last_batch();
             $results['currentday'] = $currentday;
         }
         // Loop through posts to capture sharing data for new posts loaded via Infinite Scroll
         if ('success' == $results['type'] && function_exists('sharing_register_post_for_share_counts')) {
             global $jetpack_sharing_counts;
             while (have_posts()) {
                 the_post();
                 sharing_register_post_for_share_counts(get_the_ID());
             }
             $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()));
     die;
 }
 public function get_display($post)
 {
     $display = '';
     if ($this->smart) {
         $share_url = 'http://pinterest.com/pin/create/button/?url=' . rawurlencode($this->get_share_url($post->ID)) . '&description=' . rawurlencode($post->post_title);
         $display .= sprintf('<div class="pinterest_button"><a href="%s" data-pin-do="buttonBookmark" data-pin-config="beside"><img src="//assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png" /></a></div>', esc_url($share_url));
     } else {
         $display = $this->get_link(get_permalink($post->ID), _x('Pinterest', 'share to', 'jetpack'), __('Click to share on Pinterest', 'jetpack'), 'share=pinterest', 'sharing-pinterest-' . $post->ID);
     }
     if (apply_filters('jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin')) {
         sharing_register_post_for_share_counts($post->ID);
     }
     return $display;
 }