예제 #1
0
 /**
  * Show Post Flair on Infinite Scroll queries, only if it should show for regular queries as well.
  *
  * @param bool $show
  * @param bool $default
  * @uses The_Neverending_Home_Page::got_infinity
  * @filter post_flair_should_show
  * @return bool
  */
 function wpcom_infinite_scroll_show_postflair($show, $default)
 {
     if ($default && The_Neverending_Home_Page::got_infinity()) {
         $show = true;
     }
     return $show;
 }
 /**
  * Collects the necessary information to return for a get settings response.
  *
  * @return (array)
  */
 public function get_settings_response()
 {
     $response_format = self::$site_format;
     $blog_id = (int) $this->api->get_blog_id_for_output();
     foreach (array_keys($response_format) as $key) {
         switch ($key) {
             case 'ID':
                 $response[$key] = $blog_id;
                 break;
             case 'name':
                 $response[$key] = (string) htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
                 break;
             case 'description':
                 $response[$key] = (string) htmlspecialchars_decode(get_bloginfo('description'), ENT_QUOTES);
                 break;
             case 'URL':
                 $response[$key] = (string) home_url();
                 break;
             case 'lang':
                 $response[$key] = (string) get_bloginfo('language');
                 break;
             case 'settings':
                 if (class_exists('The_Neverending_Home_Page')) {
                     $infinity = new The_Neverending_Home_Page();
                     $infinity_settings = $infinity->get_settings();
                     $infinity_posts_per_page = $infinity_settings->posts_per_page;
                 }
                 $jetpack_relatedposts_options = Jetpack_Options::get_option('relatedposts');
                 if (method_exists('Jetpack', 'is_module_active')) {
                     $jetpack_relatedposts_options['enabled'] = Jetpack::is_module_active('related-posts');
                 }
                 // array_values() is necessary to ensure the array starts at index 0.
                 $post_categories = array_values(array_map(function ($category) {
                     return array('value' => $category->term_id, 'name' => $category->name);
                 }, get_categories(array('hide_empty' => false))));
                 $response[$key] = array('admin_url' => get_admin_url(), 'default_ping_status' => (bool) ('closed' != get_option('default_ping_status')), 'default_comment_status' => (bool) ('closed' != get_option('default_comment_status')), 'blog_public' => (int) (defined('WPCOM') && WPCOM ? get_option('blog_public') : 1), 'jetpack_relatedposts_allowed' => (bool) $this->jetpack_relatedposts_supported(), 'jetpack_relatedposts_enabled' => (bool) $jetpack_relatedposts_options['enabled'], 'jetpack_relatedposts_show_headline' => (bool) $jetpack_relatedposts_options['show_headline'], 'jetpack_relatedposts_show_thumbnails' => (bool) $jetpack_relatedposts_options['show_thumbnails'], 'infinite_scroll_supported' => (bool) current_theme_supports('infinite-scroll'), 'infinite_scroll' => (bool) get_option('infinite_scroll'), 'posts_per_page' => (int) $infinity_posts_per_page, 'default_category' => get_option('default_category'), 'post_categories' => (array) $post_categories, 'default_post_format' => get_option('default_post_format'), 'default_pingback_flag' => (bool) get_option('default_pingback_flag'), 'require_name_email' => (bool) get_option('require_name_email'), 'comment_registration' => (bool) get_option('comment_registration'), 'close_comments_for_old_posts' => (bool) get_option('close_comments_for_old_posts'), 'close_comments_days_old' => (int) get_option('close_comments_days_old'), 'thread_comments' => (bool) get_option('thread_comments'), 'thread_comments_depth' => (int) get_option('thread_comments_depth'), 'page_comments' => (bool) get_option('page_comments'), 'comments_per_page' => (int) get_option('comments_per_page'), 'default_comments_page' => get_option('default_comments_page'), 'comment_order' => get_option('comment_order'), 'comments_notify' => (bool) get_option('comments_notify'), 'moderation_notify' => (bool) get_option('moderation_notify'), 'social_notifications_like' => "on" == get_option('social_notifications_like'), 'social_notifications_reblog' => "on" == get_option('social_notifications_reblog'), 'social_notifications_subscribe' => "on" == get_option('social_notifications_subscribe'), 'comment_moderation' => (bool) get_option('comment_moderation'), 'comment_whitelist' => (bool) get_option('comment_whitelist'), 'comment_max_links' => (int) get_option('comment_max_links'), 'moderation_keys' => get_option('moderation_keys'), 'blacklist_keys' => get_option('blacklist_keys'), 'lang_id' => get_option('lang_id'));
                 if (!current_user_can('edit_posts')) {
                     unset($response[$key]);
                 }
                 break;
         }
     }
     return $response;
 }
예제 #3
0
파일: init.php 프로젝트: vicpril/rep_bidqa
 public static function outputStart()
 {
     if (class_exists('The_Neverending_Home_Page', false) && The_Neverending_Home_Page::got_infinity()) {
         add_filter('infinite_scroll_results', "N2Wordpress::infiniteScrollRenderEnd", 1, 3);
     } else {
         self::$nextend_wp_head = true;
         if (N2Settings::get('safemode') != 1) {
             ob_start("N2Wordpress::platformRenderEnd");
             ob_start();
         }
     }
 }
예제 #4
0
 /**
  * If the theme uses infinite scroll, include jquery at the start
  */
 function check_infinite()
 {
     if (current_theme_supports('infinite-scroll') && class_exists('The_Neverending_Home_Page') && The_Neverending_Home_Page::archive_supports_infinity()) {
         wp_enqueue_script('jquery');
     }
 }
예제 #5
0
 /**
  * Grab the timestamp for the last post.
  * @return string 'Y-m-d H:i:s' or null
  */
 function set_last_post_time($date = false)
 {
     $posts = self::wp_query()->posts;
     $count = count($posts);
     if (!empty($date) && preg_match('|\\d{4}\\-\\d{2}\\-\\d{2}|', $_GET['date'])) {
         self::$the_time = "{$date} 00:00:00";
         return self::$the_time;
     }
     // If we don't have enough posts for infinity, return early
     if (!$count || $count < self::get_settings()->posts_per_page) {
         return self::$the_time;
     }
     $last_post = end($posts);
     // If the function is called again but we already have a value, return it
     if (null != self::$the_time) {
         return self::$the_time;
     } elseif (isset($last_post->post_date_gmt)) {
         // Grab the latest post time in Y-m-d H:i:s gmt format
         self::$the_time = $last_post->post_date_gmt;
     }
     return self::$the_time;
 }
예제 #6
0
 /**
  * Parse IS settings provided by theme
  *
  * @uses get_theme_support, infinite_scroll_has_footer_widgets, sanitize_title, add_action, get_option, wp_parse_args, is_active_sidebar
  * @return object
  */
 static function get_settings()
 {
     if (is_null(self::$settings)) {
         $css_pattern = '#[^A-Z\\d\\-_]#i';
         $settings = $defaults = array('type' => 'scroll', 'requested_type' => 'scroll', 'footer_widgets' => false, 'container' => 'content', 'wrapper' => true, 'render' => false, 'footer' => true, 'footer_callback' => false, 'posts_per_page' => false, 'click_handle' => true);
         // Validate settings passed through add_theme_support()
         $_settings = get_theme_support('infinite-scroll');
         if (is_array($_settings)) {
             // Preferred implementation, where theme provides an array of options
             if (isset($_settings[0]) && is_array($_settings[0])) {
                 foreach ($_settings[0] as $key => $value) {
                     switch ($key) {
                         case 'type':
                             if (in_array($value, array('scroll', 'click'))) {
                                 $settings[$key] = $settings['requested_type'] = $value;
                             }
                             break;
                         case 'footer_widgets':
                             if (is_string($value)) {
                                 $settings[$key] = sanitize_title($value);
                             } elseif (is_array($value)) {
                                 $settings[$key] = array_map('sanitize_title', $value);
                             } elseif (is_bool($value)) {
                                 $settings[$key] = $value;
                             }
                             break;
                         case 'container':
                         case 'wrapper':
                             if ('wrapper' == $key && is_bool($value)) {
                                 $settings[$key] = $value;
                             } else {
                                 $value = preg_replace($css_pattern, '', $value);
                                 if (!empty($value)) {
                                     $settings[$key] = $value;
                                 }
                             }
                             break;
                         case 'render':
                             if (false !== $value && is_callable($value)) {
                                 $settings[$key] = $value;
                                 add_action('infinite_scroll_render', $value);
                             }
                             break;
                         case 'footer':
                             if (is_bool($value)) {
                                 $settings[$key] = $value;
                             } elseif (is_string($value)) {
                                 $value = preg_replace($css_pattern, '', $value);
                                 if (!empty($value)) {
                                     $settings[$key] = $value;
                                 }
                             }
                             break;
                         case 'footer_callback':
                             if (is_callable($value)) {
                                 $settings[$key] = $value;
                             } else {
                                 $settings[$key] = false;
                             }
                             break;
                         case 'posts_per_page':
                             if (is_numeric($value)) {
                                 $settings[$key] = (int) $value;
                             }
                             break;
                         case 'click_handle':
                             if (is_bool($value)) {
                                 $settings[$key] = $value;
                             }
                             break;
                         default:
                             continue;
                             break;
                     }
                 }
             } elseif (is_string($_settings[0])) {
                 // Checks below are for backwards compatibility
                 // Container to append new posts to
                 $settings['container'] = preg_replace($css_pattern, '', $_settings[0]);
                 // Wrap IS elements?
                 if (isset($_settings[1])) {
                     $settings['wrapper'] = (bool) $_settings[1];
                 }
             }
         }
         // Always ensure all values are present in the final array
         $settings = wp_parse_args($settings, $defaults);
         // Check if a legacy `infinite_scroll_has_footer_widgets()` function is defined and override the footer_widgets parameter's value.
         // Otherwise, if a widget area ID or array of IDs was provided in the footer_widgets parameter, check if any contains any widgets.
         // It is safe to use `is_active_sidebar()` before the sidebar is registered as this function doesn't check for a sidebar's existence when determining if it contains any widgets.
         if (function_exists('infinite_scroll_has_footer_widgets')) {
             $settings['footer_widgets'] = (bool) infinite_scroll_has_footer_widgets();
         } elseif (is_array($settings['footer_widgets'])) {
             $sidebar_ids = $settings['footer_widgets'];
             $settings['footer_widgets'] = false;
             foreach ($sidebar_ids as $sidebar_id) {
                 if (is_active_sidebar($sidebar_id)) {
                     $settings['footer_widgets'] = true;
                     break;
                 }
             }
             unset($sidebar_ids);
             unset($sidebar_id);
         } elseif (is_string($settings['footer_widgets'])) {
             $settings['footer_widgets'] = (bool) is_active_sidebar($settings['footer_widgets']);
         }
         // For complex logic, let themes filter the `footer_widgets` parameter.
         $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`.
         if (!is_bool($settings['footer_widgets'])) {
             $settings['footer_widgets'] = false;
         }
         // Ensure that IS is enabled and no footer widgets exist if the IS type isn't already "click".
         if ('click' != $settings['type']) {
             // Check the setting status
             $disabled = '' === get_option(self::$option_name_enabled) ? true : false;
             // Footer content or Reading option check
             if ($settings['footer_widgets'] || $disabled) {
                 $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');
         } elseif (false === $settings['posts_per_page']) {
             $settings['posts_per_page'] = 7;
         }
         // Force display of the click handler and attendant bits when the type isn't `click`
         if ('click' !== $settings['type']) {
             $settings['click_handle'] = true;
         }
         // Store final settings in a class static to avoid reparsing
         self::$settings = apply_filters('infinite_scroll_settings', $settings);
     }
     return (object) self::$settings;
 }
예제 #7
0
 /**
  * Always load certain scripts when IS is enabled, as they can't be loaded after `document.ready` fires, meaning they can't leverage IS's script loader.
  *
  * @global $videopress
  * @uses do_action()
  * @uses apply_filters()
  * @uses wp_enqueue_style()
  * @uses wp_enqueue_script()
  * @action wp_enqueue_scripts
  * @return null
  */
 public function action_wp_enqueue_scripts()
 {
     // VideoPress stand-alone plugin
     global $videopress;
     if (!empty($videopress) && The_Neverending_Home_Page::archive_supports_infinity() && is_a($videopress, 'VideoPress') && method_exists($videopress, 'enqueue_scripts')) {
         $videopress->enqueue_scripts();
     }
     // VideoPress Jetpack module
     if (Jetpack::is_module_active('videopress')) {
         Jetpack_VideoPress_Shortcode::enqueue_scripts();
     }
     // Fire the post_gallery action early so Carousel scripts are present.
     if (Jetpack::is_module_active('carousel')) {
         do_action('post_gallery', '', '');
     }
     // Always enqueue Tiled Gallery scripts when both IS and Tiled Galleries are enabled
     if (Jetpack::is_module_active('tiled-gallery')) {
         Jetpack_Tiled_Gallery::default_scripts_and_styles();
     }
     // Core's Audio and Video Shortcodes
     if ('mediaelement' === apply_filters('wp_audio_shortcode_library', 'mediaelement')) {
         wp_enqueue_style('wp-mediaelement');
         wp_enqueue_script('wp-mediaelement');
     }
     if ('mediaelement' === apply_filters('wp_video_shortcode_library', 'mediaelement')) {
         wp_enqueue_style('wp-mediaelement');
         wp_enqueue_script('wp-mediaelement');
     }
 }
예제 #8
0
 /**
  * Always load certain scripts when IS is enabled, as they can't be loaded after `document.ready` fires, meaning they can't leverage IS's script loader.
  *
  * @global $videopress
  * @uses do_action()
  * @uses apply_filters()
  * @uses wp_enqueue_style()
  * @uses wp_enqueue_script()
  * @action wp_enqueue_scripts
  * @return null
  */
 public function action_wp_enqueue_scripts()
 {
     // Do not load scripts and styles on singular pages and static pages
     $load_scripts_and_styles = !(is_singular() || is_page());
     if (!apply_filters('jetpack_infinite_scroll_load_scripts_and_styles', $load_scripts_and_styles)) {
         return;
     }
     // VideoPress stand-alone plugin
     global $videopress;
     if (!empty($videopress) && The_Neverending_Home_Page::archive_supports_infinity() && is_a($videopress, 'VideoPress') && method_exists($videopress, 'enqueue_scripts')) {
         $videopress->enqueue_scripts();
     }
     // VideoPress Jetpack module
     if (Jetpack::is_module_active('videopress')) {
         wp_enqueue_script('videopress');
     }
     // Fire the post_gallery action early so Carousel scripts are present.
     if (Jetpack::is_module_active('carousel')) {
         /** This filter is already documented in core/wp-includes/media.php */
         do_action('post_gallery', '', '');
     }
     // Always enqueue Tiled Gallery scripts when both IS and Tiled Galleries are enabled
     if (Jetpack::is_module_active('tiled-gallery')) {
         Jetpack_Tiled_Gallery::default_scripts_and_styles();
     }
     // Core's Audio and Video Shortcodes
     if ('mediaelement' === apply_filters('wp_audio_shortcode_library', 'mediaelement')) {
         wp_enqueue_style('wp-mediaelement');
         wp_enqueue_script('wp-mediaelement');
     }
     if ('mediaelement' === apply_filters('wp_video_shortcode_library', 'mediaelement')) {
         wp_enqueue_style('wp-mediaelement');
         wp_enqueue_script('wp-mediaelement');
     }
 }
예제 #9
0
 /**
  * Load VideoPress scripts if plugin is active.
  *
  * @global $videopress
  * @action wp_enqueue_scripts
  * @return null
  */
 public function action_wp_enqueue_scripts()
 {
     global $videopress;
     if (!empty($videopress) && The_Neverending_Home_Page::archive_supports_infinity() && is_a($videopress, 'VideoPress') && method_exists($videopress, 'enqueue_scripts')) {
         $videopress->enqueue_scripts();
     }
 }