private function __construct()
 {
     $this->jetpack = Jetpack::init();
     jetpack_require_lib('admin-pages/class.jetpack-react-page');
     $this->jetpack_react = new Jetpack_React_Page();
     // TODO: reactify
     require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-dashboard.php';
     $this->sync_dashboard = new Jetpack_Sync_Dashboard();
     $this->sync_dashboard->init();
     //		jetpack_require_lib( 'admin-pages/class.jetpack-landing-page' );
     //		$this->landing_page = new Jetpack_Landing_Page;
     //
     //		jetpack_require_lib( 'admin-pages/class.jetpack-settings-page' );
     //		$this->settings_page = new Jetpack_Settings_Page;
     //
     //		jetpack_require_lib( 'admin-pages/class.jetpack-my-jetpack-page' );
     //		$this->my_jetpack_page = new Jetpack_My_Jetpack_Page;
     //		if ( isset( $_POST['jetpack-set-master-user'] ) ) {
     //			add_action( 'init', array( $this->my_jetpack_page, 'jetpack_my_jetpack_change_user' ) );
     //		}
     // Add hooks for admin menus
     //		add_action( 'jetpack_admin_menu',            array( $this->jetpack_react, 'add_actions' ) );
     add_action('admin_menu', array($this->jetpack_react, 'add_actions'), 998);
     add_action('jetpack_admin_menu', array($this, 'admin_menu_debugger'));
     add_action('jetpack_admin_menu', array($this->sync_dashboard, 'add_actions'));
     // Add redirect to current page for activation/deactivation of modules
     add_action('jetpack_pre_activate_module', array($this, 'fix_redirect'), 10, 2);
     add_action('jetpack_pre_deactivate_module', array($this, 'fix_redirect'));
     // Add module bulk actions handler
     add_action('jetpack_unrecognized_action', array($this, 'handle_unrecognized_action'));
 }
Exemplo n.º 2
0
function jetpack_load_theme_tools()
{
    if (current_theme_supports('social-links')) {
        require_once JETPACK__PLUGIN_DIR . 'modules/theme-tools/social-links.php';
    }
    if (current_theme_supports('tonesque')) {
        jetpack_require_lib('tonesque');
    }
    require_once JETPACK__PLUGIN_DIR . 'modules/theme-tools/random-redirect.php';
}
Exemplo n.º 3
0
 function __construct($image_url)
 {
     if (!class_exists('Jetpack_Color')) {
         jetpack_require_lib('class.color');
     }
     $this->image_url = esc_url_raw($image_url);
     $this->image_url = trim($this->image_url);
     $this->image_url = apply_filters('tonesque_image_url', $this->image_url);
     $this->image_obj = self::imagecreatefromurl($this->image_url);
 }
Exemplo n.º 4
0
 public static function shortcode($atts = array())
 {
     jetpack_require_lib('icalendar-reader');
     $atts = shortcode_atts(array('url' => '', 'number' => 0), $atts, 'upcomingevents');
     $args = array('context' => 'shortcode', 'number' => absint($atts['number']));
     $events = icalendar_render_events($atts['url'], $args);
     if (!$events) {
         $events = sprintf('<p>%s</p>', __('No upcoming events', 'jetpack'));
     }
     return $events;
 }
 /**
  * Loads the JetPack Color class.
  * If Jetpack is not installed then use our copy of that file.
  */
 public function load_jetpack_color_lib()
 {
     if (function_exists('jetpack_require_lib')) {
         if (!class_exists('Jetpack_Color')) {
             jetpack_require_lib('class.color');
         }
     }
     if (!class_exists('Jetpack_Color')) {
         include_once dirname(__FILE__) . '/class.color.php';
     }
 }
 /**
  * Constructor for Jetpack_RelatedPosts.
  *
  * @param int $blog_id_local
  * @param int $blog_id_wpcom
  * @uses get_option, add_action, apply_filters
  * @return null
  */
 public function __construct($blog_id_local, $blog_id_wpcom)
 {
     $this->_blog_id_local = $blog_id_local;
     $this->_blog_id_wpcom = $blog_id_wpcom;
     $this->_blog_charset = get_option('blog_charset');
     $this->_convert_charset = function_exists('iconv') && !preg_match('/^utf\\-?8$/i', $this->_blog_charset);
     add_action('admin_init', array($this, 'action_admin_init'));
     add_action('wp', array($this, 'action_frontend_init'));
     if (!class_exists('Jetpack_Media_Summary')) {
         jetpack_require_lib('class.media-summary');
     }
 }
Exemplo n.º 7
0
 function require_libs_init()
 {
     /**
      * Load the color library from jetpack
      */
     if (function_exists('jetpack_require_lib')) {
         jetpack_require_lib('class.color');
     }
     /**
      * Load the Tonesque library from jetpack
      */
     if (function_exists('jetpack_require_lib')) {
         jetpack_require_lib('tonesque');
     }
 }
Exemplo n.º 8
0
 /**
  * Constructor for Jetpack_RelatedPosts.
  *
  * @param int $blog_id_local
  * @param int $blog_id_wpcom
  * @uses get_option, add_action, apply_filters
  * @return null
  */
 public function __construct($blog_id_local, $blog_id_wpcom)
 {
     $this->_blog_id_local = $blog_id_local;
     $this->_blog_id_wpcom = $blog_id_wpcom;
     $this->_blog_charset = get_option('blog_charset');
     $this->_convert_charset = function_exists('iconv') && !preg_match('/^utf\\-?8$/i', $this->_blog_charset);
     add_action('admin_init', array($this, 'action_admin_init'));
     add_action('wp', array($this, 'action_frontend_init'));
     if (!class_exists('Jetpack_Media_Summary')) {
         jetpack_require_lib('class.media-summary');
     }
     // Add Related Posts to the REST API Post response.
     if (function_exists('register_rest_field')) {
         add_action('rest_api_init', array($this, 'rest_register_related_posts'));
     }
 }
 private function __construct()
 {
     $this->jetpack = Jetpack::init();
     jetpack_require_lib('admin-pages/class.jetpack-landing-page');
     $this->landing_page = new Jetpack_Landing_Page();
     jetpack_require_lib('admin-pages/class.jetpack-settings-page');
     $this->settings_page = new Jetpack_Settings_Page();
     // Add hooks for admin menus
     add_action('admin_menu', array($this->landing_page, 'add_actions'), 998);
     add_action('jetpack_admin_menu', array($this, 'admin_menu_debugger'));
     add_action('jetpack_admin_menu', array($this->settings_page, 'add_actions'));
     // Add redirect to current page for activation/deactivation of modules
     add_action('jetpack_pre_activate_module', array($this, 'fix_redirect'), 10, 2);
     add_action('jetpack_pre_deactivate_module', array($this, 'fix_redirect'));
     // Add module bulk actions handler
     add_action('jetpack_unrecognized_action', array($this, 'handle_unrecognized_action'));
 }
Exemplo n.º 10
0
 function __construct($image_url)
 {
     if (!class_exists('Jetpack_Color')) {
         jetpack_require_lib('class.color');
     }
     $this->image_url = esc_url_raw($image_url);
     $this->image_url = trim($this->image_url);
     /**
      * Allows any image URL to be passed in for $this->image_url.
      *
      * @since 2.5.0
      *
      * @param string $image_url The URL to any image
      */
     $this->image_url = apply_filters('tonesque_image_url', $this->image_url);
     $this->image_obj = self::imagecreatefromurl($this->image_url);
 }
Exemplo n.º 11
0
 private function __construct()
 {
     $this->jetpack = Jetpack::init();
     jetpack_require_lib('admin-pages/class.jetpack-react-page');
     $this->jetpack_react = new Jetpack_React_Page();
     jetpack_require_lib('admin-pages/class.jetpack-settings-page');
     $this->fallback_page = new Jetpack_Settings_Page();
     add_action('admin_menu', array($this->jetpack_react, 'add_actions'), 998);
     add_action('jetpack_admin_menu', array($this->jetpack_react, 'jetpack_add_dashboard_sub_nav_item'));
     add_action('jetpack_admin_menu', array($this->jetpack_react, 'jetpack_add_settings_sub_nav_item'));
     add_action('jetpack_admin_menu', array($this, 'admin_menu_debugger'));
     add_action('jetpack_admin_menu', array($this->fallback_page, 'add_actions'));
     // Add redirect to current page for activation/deactivation of modules
     add_action('jetpack_pre_activate_module', array($this, 'fix_redirect'), 10, 2);
     add_action('jetpack_pre_deactivate_module', array($this, 'fix_redirect'));
     // Add module bulk actions handler
     add_action('jetpack_unrecognized_action', array($this, 'handle_unrecognized_action'));
 }
Exemplo n.º 12
0
<?php

if (!class_exists('MarkdownExtra_Parser')) {
    jetpack_require_lib('markdown/extra');
}
jetpack_require_lib('markdown/gfm');
Exemplo n.º 13
0
/**
 * Themes must declare that they support this module by adding
 * add_theme_support( 'tonesque' ); on 'after_setup_theme'.
 */
function jetpack_load_tonesque() {
	if ( current_theme_supports( 'tonesque' ) )
		jetpack_require_lib( 'tonesque' );
}
 static function twitter_cards_tags($og_tags)
 {
     global $post;
     if (post_password_required()) {
         return $og_tags;
     }
     /** This action is documented in class.jetpack.php */
     if (apply_filters('jetpack_disable_twitter_cards', false)) {
         return $og_tags;
     }
     /*
      * These tags apply to any page (home, archives, etc)
      */
     $site_tag = self::site_tag();
     /** This action is documented in modules/sharedaddy/sharing-sources.php */
     $site_tag = apply_filters('jetpack_sharing_twitter_via', $site_tag, is_singular() ? $post->ID : null);
     /** This action is documented in modules/sharedaddy/sharing-sources.php */
     $site_tag = apply_filters('jetpack_twitter_cards_site_tag', $site_tag, $og_tags);
     if (!empty($site_tag)) {
         $og_tags['twitter:site'] = self::sanitize_twitter_user($site_tag);
     }
     if (!is_singular() || !empty($og_tags['twitter:card'])) {
         return $og_tags;
     }
     /*
      * The following tags only apply to single pages.
      */
     $card_type = 'summary';
     // Try to give priority to featured images
     if (class_exists('Jetpack_PostImages')) {
         $featured = Jetpack_PostImages::from_thumbnail($post->ID, 240, 240);
         if (!empty($featured) && count($featured) > 0) {
             if ((int) $featured[0]['src_width'] >= 280 && (int) $featured[0]['src_height'] >= 150) {
                 $card_type = 'summary_large_image';
                 $og_tags['twitter:image'] = esc_url(add_query_arg('w', 640, $featured[0]['src']));
             } else {
                 $og_tags['twitter:image'] = esc_url(add_query_arg('w', 240, $featured[0]['src']));
             }
         }
     }
     // Only proceed with media analysis if a featured image has not superseded it already.
     if (empty($og_tags['twitter:image']) && empty($og_tags['twitter:image:src'])) {
         if (!class_exists('Jetpack_Media_Summary') && defined('IS_WPCOM') && IS_WPCOM) {
             include WP_CONTENT_DIR . '/lib/class.wpcom-media-summary.php';
         }
         if (!class_exists('Jetpack_Media_Summary')) {
             jetpack_require_lib('class.media-summary');
         }
         // Test again, class should already be auto-loaded in Jetpack.
         // If not, skip extra media analysis and stick with a summary card
         if (class_exists('Jetpack_Media_Summary')) {
             $extract = Jetpack_Media_Summary::get($post->ID);
             if ('gallery' == $extract['type']) {
                 list($og_tags, $card_type) = self::twitter_cards_define_type_based_on_image_count($og_tags, $extract);
             } elseif ('video' == $extract['type']) {
                 // Leave as summary, but with large pict of poster frame (we know those comply to Twitter's size requirements)
                 $card_type = 'summary_large_image';
                 $og_tags['twitter:image'] = esc_url(add_query_arg('w', 640, $extract['image']));
             } else {
                 list($og_tags, $card_type) = self::twitter_cards_define_type_based_on_image_count($og_tags, $extract);
             }
         }
     }
     $og_tags['twitter:card'] = $card_type;
     // If we have information on the author/creator, then include that as well
     if (!empty($post) && !empty($post->post_author)) {
         /** This action is documented in modules/sharedaddy/sharing-sources.php */
         $handle = apply_filters('jetpack_sharing_twitter_via', '', $post->ID);
         if (!empty($handle) && 'wordpressdotcom' != $handle && 'jetpack' != $handle) {
             $og_tags['twitter:creator'] = self::sanitize_twitter_user($handle);
         }
     }
     // Make sure we have a description for Twitter, their validator isn't happy without some content (single space not valid).
     if (!isset($og_tags['og:description']) || '' == trim($og_tags['og:description']) || __('Visit the post for more.', 'jetpack') == $og_tags['og:description']) {
         // empty( trim( $og_tags['og:description'] ) ) isn't valid php
         $has_creator = !empty($og_tags['twitter:creator']) && '@wordpressdotcom' != $og_tags['twitter:creator'] ? true : false;
         if (!empty($extract) && 'video' == $extract['type']) {
             // use $extract['type'] since $card_type is 'summary' for video posts
             $og_tags['twitter:description'] = $has_creator ? sprintf(__('Video post by %s.', 'jetpack'), $og_tags['twitter:creator']) : __('Video post.', 'jetpack');
         } else {
             $og_tags['twitter:description'] = $has_creator ? sprintf(__('Post by %s.', 'jetpack'), $og_tags['twitter:creator']) : __('Visit the post for more.', 'jetpack');
         }
     }
     return $og_tags;
 }
<?php

if (!class_exists('Jetpack_Media_Meta_Extractor')) {
    jetpack_require_lib('class.media-extractor');
}
class WP_Test_Jetpack_MediaExtractor extends WP_UnitTestCase
{
    /**
     * @author scotchfield
     * @covers Jetpack_Media_Meta_Extractor::extract
     * @since 3.2
     */
    public function test_mediaextractor_extract_empty_array()
    {
        $post_id = $this->factory->post->create(array('post_content' => ''));
        $extract = Jetpack_Media_Meta_Extractor::extract(Jetpack_Options::get_option('id'), $post_id);
        $this->assertInternalType('array', $extract);
        $this->assertEmpty($extract);
    }
    /**
     * @author scotchfield
     * @covers Jetpack_Media_Meta_Extractor::extract
     * @since 3.2
     */
    public function test_mediaextractor_extract_image()
    {
        $img_title = 'title.jpg';
        $post_id = $this->factory->post->create(array('post_content' => "<img src='{$img_title}'>"));
        $extract = Jetpack_Media_Meta_Extractor::extract(Jetpack_Options::get_option('id'), $post_id);
        $this->assertInternalType('array', $extract);
        $this->assertArrayHasKey('image', $extract);
<?php

if (!class_exists('Jetpack_Media_Summary')) {
    jetpack_require_lib('class.media-summary');
}
class WP_Test_Jetpack_MediaSummary extends WP_UnitTestCase
{
    /**
     * @author scotchfield
     * @covers Jetpack_Media_Summary::get
     * @since 3.2
     * @todo find a better way to test this large function
     */
    public function test_mediasummary_get()
    {
        $post_id = $this->factory->post->create(array());
        $get_obj = Jetpack_Media_Summary::get($post_id);
        $this->assertInternalType('array', $get_obj);
    }
    /**
     * @author scotchfield
     * @covers Jetpack_Media_Summary::https
     * @since 3.2
     */
    public function test_mediasummary_https()
    {
        $content = 'http://' . WP_TESTS_DOMAIN . '/';
        $expected = 'https://' . WP_TESTS_DOMAIN . '/';
        $this->assertEquals(Jetpack_Media_Summary::https($content), $expected);
    }
    /**
Exemplo n.º 17
0
 function widget($args, $instance)
 {
     jetpack_require_lib('icalendar-reader');
     $events = icalendar_render_events($instance['feed-url'], array('context' => 'widget', 'number' => $instance['count']));
     // nothing to display?
     if (!$events) {
         $events = sprintf('<p>%s</p>', __('No upcoming events', 'jetpack'));
     }
     echo $args['before_widget'];
     if (!empty($instance['title'])) {
         echo $args['before_title'];
         echo esc_html($instance['title']);
         echo $args['after_title'];
     }
     echo $events;
     echo $args['after_widget'];
     /** This action is documented in modules/widgets/gravatar-profile.php */
     do_action('jetpack_stats_extra', 'widget_view', 'grofile');
 }
Exemplo n.º 18
0
 static function get($post_id, $blog_id = 0, $args = array())
 {
     $defaults = array('max_words' => 16, 'max_chars' => 256);
     $args = wp_parse_args($args, $defaults);
     $switched = false;
     if (!empty($blog_id) && $blog_id != get_current_blog_id() && function_exists('switch_to_blog')) {
         switch_to_blog($blog_id);
         $switched = true;
     } else {
         $blog_id = get_current_blog_id();
     }
     if (!class_exists('Jetpack_Media_Meta_Extractor')) {
         jetpack_require_lib('class.media-extractor');
     }
     $post = get_post($post_id);
     $permalink = get_permalink($post_id);
     $return = array('type' => 'standard', 'permalink' => $permalink, 'image' => '', 'excerpt' => '', 'word_count' => 0, 'secure' => array('image' => ''), 'count' => array('image' => 0, 'video' => 0, 'word' => 0, 'link' => 0));
     if (empty($post->post_password)) {
         $return['excerpt'] = self::get_excerpt($post->post_content, $post->post_excerpt, $args['max_words'], $args['max_chars']);
         $return['count']['word'] = self::get_word_count($post->post_content);
         $return['count']['word_remaining'] = self::get_word_remaining_count($post->post_content, $return['excerpt']);
         $return['count']['link'] = self::get_link_count($post->post_content);
     }
     $extract = Jetpack_Media_Meta_Extractor::extract($blog_id, $post_id, Jetpack_Media_Meta_Extractor::ALL);
     if (empty($extract['has'])) {
         return $return;
     }
     // Prioritize [some] video embeds
     if (!empty($extract['has']['shortcode'])) {
         foreach ($extract['shortcode'] as $type => $data) {
             switch ($type) {
                 case 'videopress':
                 case 'wpvideo':
                     if (0 == $return['count']['video']) {
                         // If there is no id on the video, then let's just skip this
                         if (!isset($data['id'][0])) {
                             continue;
                         }
                         $guid = $data['id'][0];
                         $video_info = videopress_get_video_details($guid);
                         // Only add the video tags if the guid returns a valid videopress object.
                         if ($video_info instanceof stdClass) {
                             // Continue early if we can't find a Video slug.
                             if (empty($video_info->files->std->mp4)) {
                                 continue;
                             }
                             $url = sprintf('https://videos.files.wordpress.com/%1$s/%2$s', $guid, $video_info->files->std->mp4);
                             $thumbnail = $video_info->poster;
                             if (!empty($thumbnail)) {
                                 $return['image'] = $thumbnail;
                                 $return['secure']['image'] = $thumbnail;
                             }
                             $return['type'] = 'video';
                             $return['video'] = esc_url_raw($url);
                             $return['video_type'] = 'video/mp4';
                             $return['secure']['video'] = $return['video'];
                         }
                     }
                     $return['count']['video']++;
                     break;
                 case 'youtube':
                     if (0 == $return['count']['video']) {
                         $return['type'] = 'video';
                         $return['video'] = esc_url_raw('http://www.youtube.com/watch?feature=player_embedded&v=' . $extract['shortcode']['youtube']['id'][0]);
                         $return['image'] = self::get_video_poster('youtube', $extract['shortcode']['youtube']['id'][0]);
                         $return['secure']['video'] = self::https($return['video']);
                         $return['secure']['image'] = self::https($return['image']);
                     }
                     $return['count']['video']++;
                     break;
                 case 'vimeo':
                     if (0 == $return['count']['video']) {
                         $return['type'] = 'video';
                         $return['video'] = esc_url_raw('http://vimeo.com/' . $extract['shortcode']['vimeo']['id'][0]);
                         $return['secure']['video'] = self::https($return['video']);
                         $poster_image = get_post_meta($post_id, 'vimeo_poster_image', true);
                         if (!empty($poster_image)) {
                             $return['image'] = $poster_image;
                             $poster_url_parts = parse_url($poster_image);
                             $return['secure']['image'] = 'https://secure-a.vimeocdn.com' . $poster_url_parts['path'];
                         }
                     }
                     $return['count']['video']++;
                     break;
             }
         }
     }
     if (!empty($extract['has']['embed'])) {
         foreach ($extract['embed']['url'] as $embed) {
             if (preg_match('/((youtube|vimeo|dailymotion)\\.com|youtu.be)/', $embed)) {
                 if (0 == $return['count']['video']) {
                     $return['type'] = 'video';
                     $return['video'] = 'http://' . $embed;
                     $return['secure']['video'] = self::https($return['video']);
                     if (false !== strpos($embed, 'youtube')) {
                         $return['image'] = self::get_video_poster('youtube', jetpack_get_youtube_id($return['video']));
                         $return['secure']['image'] = self::https($return['image']);
                     } else {
                         if (false !== strpos($embed, 'youtu.be')) {
                             $youtube_id = jetpack_get_youtube_id($return['video']);
                             $return['video'] = 'http://youtube.com/watch?v=' . $youtube_id . '&feature=youtu.be';
                             $return['secure']['video'] = self::https($return['video']);
                             $return['image'] = self::get_video_poster('youtube', jetpack_get_youtube_id($return['video']));
                             $return['secure']['image'] = self::https($return['image']);
                         } else {
                             if (false !== strpos($embed, 'vimeo')) {
                                 $poster_image = get_post_meta($post_id, 'vimeo_poster_image', true);
                                 if (!empty($poster_image)) {
                                     $return['image'] = $poster_image;
                                     $poster_url_parts = parse_url($poster_image);
                                     $return['secure']['image'] = 'https://secure-a.vimeocdn.com' . $poster_url_parts['path'];
                                 }
                             } else {
                                 if (false !== strpos($embed, 'dailymotion')) {
                                     $return['image'] = str_replace('dailymotion.com/video/', 'dailymotion.com/thumbnail/video/', $embed);
                                     $return['image'] = parse_url($return['image'], PHP_URL_SCHEME) === null ? 'http://' . $return['image'] : $return['image'];
                                     $return['secure']['image'] = self::https($return['image']);
                                 }
                             }
                         }
                     }
                 }
                 $return['count']['video']++;
             }
         }
     }
     // Do we really want to make the video the primary focus of the post?
     if ('video' == $return['type']) {
         $content = wpautop(strip_tags($post->post_content));
         $paragraphs = explode('</p>', $content);
         $number_of_paragraphs = 0;
         foreach ($paragraphs as $i => $paragraph) {
             // Don't include blank lines as a paragraph
             if ('' == trim($paragraph)) {
                 unset($paragraphs[$i]);
                 continue;
             }
             $number_of_paragraphs++;
         }
         $number_of_paragraphs = $number_of_paragraphs - $return['count']['video'];
         // subtract amount for videos..
         // More than 2 paragraph? The video is not the primary focus so we can do some more analysis
         if ($number_of_paragraphs > 2) {
             $return['type'] = 'standard';
         }
     }
     // If we don't have any prioritized embed...
     if ('standard' == $return['type']) {
         if ((!empty($extract['has']['gallery']) || !empty($extract['shortcode']['gallery']['count'])) && !empty($extract['image'])) {
             //... Then we prioritize galleries first (multiple images returned)
             $return['type'] = 'gallery';
             $return['images'] = $extract['image'];
             foreach ($return['images'] as $image) {
                 $return['secure']['images'][] = array('url' => self::ssl_img($image['url']));
                 $return['count']['image']++;
             }
         } else {
             if (!empty($extract['has']['image'])) {
                 // ... Or we try and select a single image that would make sense
                 $content = wpautop(strip_tags($post->post_content));
                 $paragraphs = explode('</p>', $content);
                 $number_of_paragraphs = 0;
                 foreach ($paragraphs as $i => $paragraph) {
                     // Don't include 'actual' captions as a paragraph
                     if (false !== strpos($paragraph, '[caption')) {
                         unset($paragraphs[$i]);
                         continue;
                     }
                     // Don't include blank lines as a paragraph
                     if ('' == trim($paragraph)) {
                         unset($paragraphs[$i]);
                         continue;
                     }
                     $number_of_paragraphs++;
                 }
                 $return['image'] = $extract['image'][0]['url'];
                 $return['secure']['image'] = self::ssl_img($return['image']);
                 $return['count']['image']++;
                 if ($number_of_paragraphs <= 2 && 1 == count($extract['image'])) {
                     // If we have lots of text or images, let's not treat it as an image post, but return its first image
                     $return['type'] = 'image';
                 }
             }
         }
     }
     if ($switched) {
         restore_current_blog();
     }
     /**
      * Allow a theme or plugin to inspect and ultimately change the media summary.
      *
      * @since 4.4.0
      *
      * @param array $data The calculated media summary data.
      * @param int $post_id The id of the post this data applies to.
      */
     $return = apply_filters('jetpack_media_summary_output', $return, $post_id);
     return $return;
 }
Exemplo n.º 19
0
 function widget($args, $instance)
 {
     jetpack_require_lib('icalendar-reader');
     $events = icalendar_render_events($instance['feed-url'], array('context' => 'widget', 'number' => $instance['count']));
     // nothing to display?
     if (!$events) {
         $events = sprintf('<p>%s</p>', __('No upcoming events', 'jetpack'));
     }
     echo $args['before_widget'];
     if (!empty($instance['title'])) {
         echo $args['before_title'];
         echo esc_html($instance['title']);
         echo $args['after_title'];
     }
     echo $events;
     echo $args['after_widget'];
 }
Exemplo n.º 20
0
 /**
  * Get our Markdown parser object, optionally requiring all of our needed classes and
  * instantiating our parser.
  * @return object WPCom_GHF_Markdown_Parser instance.
  */
 protected function get_parser()
 {
     if (!self::$parser) {
         jetpack_require_lib('markdown');
         self::$parser = new WPCom_GHF_Markdown_Parser();
     }
     return self::$parser;
 }
Exemplo n.º 21
0
 static function get($post_id, $blog_id = 0, $args = array())
 {
     $defaults = array('max_words' => 16, 'max_chars' => 256);
     $args = wp_parse_args($args, $defaults);
     $switched = false;
     if (!empty($blog_id) && $blog_id != get_current_blog_id() && function_exists('switch_to_blog')) {
         switch_to_blog($blog_id);
         $switched = true;
     } else {
         $blog_id = get_current_blog_id();
     }
     if (!class_exists('Jetpack_Media_Meta_Extractor')) {
         jetpack_require_lib('class.media-extractor');
     }
     $post = get_post($post_id);
     $permalink = get_permalink($post_id);
     $return = array('type' => 'standard', 'permalink' => $permalink, 'image' => '', 'excerpt' => '', 'word_count' => 0, 'secure' => array('image' => ''), 'count' => array('image' => 0, 'video' => 0, 'word' => 0, 'link' => 0));
     if (empty($post->post_password)) {
         $return['excerpt'] = self::get_excerpt($post->post_content, $post->post_excerpt, $args['max_words'], $args['max_chars']);
         $return['count']['word'] = self::get_word_count($post->post_content);
         $return['count']['word_remaining'] = self::get_word_remaining_count($post->post_content, $return['excerpt']);
         $return['count']['link'] = self::get_link_count($post->post_content);
     }
     $extract = Jetpack_Media_Meta_Extractor::extract($blog_id, $post_id, Jetpack_Media_Meta_Extractor::ALL);
     if (empty($extract['has'])) {
         return $return;
     }
     // Prioritize [some] video embeds
     if (!empty($extract['has']['shortcode'])) {
         foreach ($extract['shortcode'] as $type => $data) {
             switch ($type) {
                 case 'wpvideo':
                     if (0 == $return['count']['video']) {
                         $return['type'] = 'video';
                         $return['video'] = esc_url_raw('http://s0.videopress.com/player.swf?guid=' . $extract['shortcode']['wpvideo']['id'][0] . '&isDynamicSeeking=true');
                         $return['image'] = self::get_video_poster('videopress', $extract['shortcode']['wpvideo']['id'][0]);
                         $return['secure']['video'] = preg_replace('@http://[^\\.]+.videopress.com/@', 'https://v0.wordpress.com/', $return['video']);
                         $return['secure']['image'] = str_replace('http://videos.videopress.com', 'https://videos.files.wordpress.com', $return['image']);
                     }
                     $return['count']['video']++;
                     break;
                 case 'youtube':
                     if (0 == $return['count']['video']) {
                         $return['type'] = 'video';
                         $return['video'] = esc_url_raw('http://www.youtube.com/watch?feature=player_embedded&v=' . $extract['shortcode']['youtube']['id'][0]);
                         $return['image'] = self::get_video_poster('youtube', $extract['shortcode']['youtube']['id'][0]);
                         $return['secure']['video'] = self::https($return['video']);
                         $return['secure']['image'] = self::https($return['image']);
                     }
                     $return['count']['video']++;
                     break;
                 case 'vimeo':
                     if (0 == $return['count']['video']) {
                         $return['type'] = 'video';
                         $return['video'] = esc_url_raw('http://vimeo.com/' . $extract['shortcode']['vimeo']['id'][0]);
                         $return['secure']['video'] = self::https($return['video']);
                         $poster_image = get_post_meta($post_id, 'vimeo_poster_image', true);
                         if (!empty($poster_image)) {
                             $return['image'] = $poster_image;
                             $poster_url_parts = parse_url($poster_image);
                             $return['secure']['image'] = 'https://secure-a.vimeocdn.com' . $poster_url_parts['path'];
                         }
                     }
                     $return['count']['video']++;
                     break;
             }
         }
     }
     if (!empty($extract['has']['embed'])) {
         foreach ($extract['embed']['url'] as $embed) {
             if (preg_match('/((youtube|vimeo|dailymotion)\\.com|youtu.be)/', $embed)) {
                 if (0 == $return['count']['video']) {
                     $return['type'] = 'video';
                     $return['video'] = 'http://' . $embed;
                     $return['secure']['video'] = self::https($return['video']);
                     if (false !== strpos($embed, 'youtube')) {
                         $return['image'] = self::get_video_poster('youtube', jetpack_get_youtube_id($return['video']));
                         $return['secure']['image'] = self::https($return['image']);
                     } else {
                         if (false !== strpos($embed, 'youtu.be')) {
                             $youtube_id = jetpack_get_youtube_id($return['video']);
                             $return['video'] = 'http://youtube.com/watch?v=' . $youtube_id . '&feature=youtu.be';
                             $return['secure']['video'] = self::https($return['video']);
                             $return['image'] = self::get_video_poster('youtube', jetpack_get_youtube_id($return['video']));
                             $return['secure']['image'] = self::https($return['image']);
                         } else {
                             if (false !== strpos($embed, 'vimeo')) {
                                 $poster_image = get_post_meta($post_id, 'vimeo_poster_image', true);
                                 if (!empty($poster_image)) {
                                     $return['image'] = $poster_image;
                                     $poster_url_parts = parse_url($poster_image);
                                     $return['secure']['image'] = 'https://secure-a.vimeocdn.com' . $poster_url_parts['path'];
                                 }
                             } else {
                                 if (false !== strpos($embed, 'dailymotion')) {
                                     $return['image'] = str_replace('dailymotion.com/video/', 'dailymotion.com/thumbnail/video/', $embed);
                                     $return['image'] = parse_url($return['image'], PHP_URL_SCHEME) === null ? 'http://' . $return['image'] : $return['image'];
                                     $return['secure']['image'] = self::https($return['image']);
                                 }
                             }
                         }
                     }
                 }
                 $return['count']['video']++;
             }
         }
     }
     // Do we really want to make the video the primary focus of the post?
     if ('video' == $return['type']) {
         $content = wpautop(strip_tags($post->post_content));
         $paragraphs = explode('</p>', $content);
         $number_of_paragraphs = 0;
         foreach ($paragraphs as $i => $paragraph) {
             // Don't include blank lines as a paragraph
             if ('' == trim($paragraph)) {
                 unset($paragraphs[$i]);
                 continue;
             }
             $number_of_paragraphs++;
         }
         $number_of_paragraphs = $number_of_paragraphs - $return['count']['video'];
         // subtract amount for videos..
         // More than 2 paragraph? The video is not the primary focus so we can do some more analysis
         if ($number_of_paragraphs > 2) {
             $return['type'] = 'standard';
         }
     }
     // If we don't have any prioritized embed...
     if ('standard' == $return['type']) {
         if ((!empty($extract['has']['gallery']) || !empty($extract['shortcode']['gallery']['count'])) && !empty($extract['image'])) {
             //... Then we prioritize galleries first (multiple images returned)
             $return['type'] = 'gallery';
             $return['images'] = $extract['image'];
             foreach ($return['images'] as $image) {
                 $return['secure']['images'][] = array('url' => self::ssl_img($image['url']));
                 $return['count']['image']++;
             }
         } else {
             if (!empty($extract['has']['image'])) {
                 // ... Or we try and select a single image that would make sense
                 $content = wpautop(strip_tags($post->post_content));
                 $paragraphs = explode('</p>', $content);
                 $number_of_paragraphs = 0;
                 foreach ($paragraphs as $i => $paragraph) {
                     // Don't include 'actual' captions as a paragraph
                     if (false !== strpos($paragraph, '[caption')) {
                         unset($paragraphs[$i]);
                         continue;
                     }
                     // Don't include blank lines as a paragraph
                     if ('' == trim($paragraph)) {
                         unset($paragraphs[$i]);
                         continue;
                     }
                     $number_of_paragraphs++;
                 }
                 $return['image'] = $extract['image'][0]['url'];
                 $return['secure']['image'] = self::ssl_img($return['image']);
                 $return['count']['image']++;
                 if ($number_of_paragraphs <= 2 && 1 == count($extract['image'])) {
                     // If we have lots of text or images, let's not treat it as an image post, but return its first image
                     $return['type'] = 'image';
                 }
             }
         }
     }
     if ($switched) {
         restore_current_blog();
     }
     return $return;
 }