/** * Allows VideoPress, YouTube, and Vimeo videos to play inline on Facebook */ function enhanced_og_video($tags) { if (!is_singular() || post_password_required()) { return $tags; } global $post; // Always favor featured images. if (enhanced_og_has_featured_image($post->ID)) { return $tags; } $summary = Jetpack_Media_Summary::get($post->ID); if ('video' != $summary['type']) { if ($summary['count']['video'] > 0 && $summary['count']['image'] < 1) { $tags['og:image'] = $summary['image']; $tags['og:image:secure_url'] = $summary['secure']['image']; } return $tags; } $tags['og:image'] = $summary['image']; $tags['og:image:secure_url'] = $summary['secure']['image']; // This should be html by default for youtube/vimeo, since we're linking to HTML pages. $tags['og:video:type'] = isset($summary['video_type']) ? $summary['video_type'] : 'text/html'; $video_url = $summary['video']; $secure_video_url = $summary['secure']['video']; if (preg_match('/((youtube|vimeo)\\.com|youtu.be)/', $video_url)) { if (strstr($video_url, 'youtube')) { $id = jetpack_get_youtube_id($video_url); $video_url = 'http://www.youtube.com/v/' . $id . '?version=3&autohide=1'; $secure_video_url = 'https://www.youtube.com/v/' . $id . '?version=3&autohide=1'; } else { if (strstr($video_url, 'vimeo')) { preg_match('|vimeo\\.com/(\\d+)/?$|i', $video_url, $match); $id = (int) $match[1]; $video_url = 'http://vimeo.com/moogaloop.swf?clip_id=' . $id; $secure_video_url = 'https://vimeo.com/moogaloop.swf?clip_id=' . $id; } } } $tags['og:video'] = $video_url; $tags['og:video:secure_url'] = $secure_video_url; if (empty($post->post_title)) { $tags['og:title'] = sprintf(__('Video on %s', 'jetpack'), get_option('blogname')); } return $tags; }
/** * Allows VideoPress, YouTube, and Vimeo videos to play inline on Facebook */ function enhanced_og_video($tags) { if (!is_singular()) { return $tags; } global $post; // Always favor featured images. if (enhanced_og_has_featured_image($post->ID)) { return $tags; } $summary = Jetpack_Media_Summary::get($post->ID); if ('video' != $summary['type']) { if ($summary['count']['video'] > 0 && $summary['count']['image'] < 1) { $tags['og:image'] = $summary['image']; $tags['og:image:secure_url'] = $summary['secure']['image']; } return $tags; } $tags['og:image'] = $summary['image']; $tags['og:image:secure_url'] = $summary['secure']['image']; $tags['og:video:type'] = 'application/x-shockwave-flash'; $video_url = $summary['video']; $secure_video_url = $summary['secure']['video']; if (preg_match('/((youtube|vimeo)\\.com|youtu.be)/', $video_url)) { if (strstr($video_url, 'youtube')) { $id = get_youtube_id($video_url); $video_url = 'http://www.youtube.com/v/' . $id . '?version=3&autohide=1'; $secure_video_url = 'https://www.youtube.com/v/' . $id . '?version=3&autohide=1'; } else { if (strstr($video_url, 'vimeo')) { preg_match('|vimeo\\.com/(\\d+)/?$|i', $video_url, $match); $id = (int) $match[1]; $video_url = 'http://vimeo.com/moogaloop.swf?clip_id=' . $id; $secure_video_url = 'https://vimeo.com/moogaloop.swf?clip_id=' . $id; } } } $tags['og:video'] = $video_url; $tags['og:video:secure_url'] = $secure_video_url; if (empty($post->post_title)) { $tags['og:title'] = sprintf(__('Video on %s', 'jetpack'), get_option('blogname')); } return $tags; }
static function twitter_cards_tags($og_tags) { global $post; if (post_password_required()) { return $og_tags; } if (apply_filters('jetpack_disable_twitter_cards', false)) { return $og_tags; } /* * These tags apply to any page (home, archives, etc) */ $site_tag = apply_filters('jetpack_twitter_cards_site_tag', self::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:src'] = add_query_arg('w', 640, $featured[0]['src']); } else { $og_tags['twitter:image'] = 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'; } // 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); } else { if ('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:src'] = 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)) { $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 ('photo' == $card_type) { $og_tags['twitter:description'] = $has_creator ? sprintf(__('Photo post by %s.', 'jetpack'), $og_tags['twitter:creator']) : __('Photo post.', 'jetpack'); } else { 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 { if ('gallery' == $card_type) { $og_tags['twitter:description'] = $has_creator ? sprintf(__('Gallery post by %s.', 'jetpack'), $og_tags['twitter:creator']) : __('Gallery 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; }
function cleanyetibasic_attachment_gallery_data() { $post = get_post(); $id = $post->ID; $id = intval($id); $posturl = get_permalink(); $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')); $indexarray = array(); if (class_exists('Jetpack_Media_Summary')) { $summary = Jetpack_Media_Summary::get($post->ID); $images = $summary['images']; ?> <div class="small-12-cloumns"><ul class="small-block-grid-2 medium-block-grid-4"> <li><a href="<?php echo $posturl; ?> "><img src="<?php echo $images[0]['url']; ?> " alt="<?php the_title(); ?> " class="th" /></a></li> <li><a href="<?php echo $posturl; ?> "><img src="<?php echo $images[1]['url']; ?> " alt="<?php the_title(); ?> " class="th" /></a></li> <li><a href="<?php echo $posturl; ?> "><img src="<?php echo $images[2]['url']; ?> " alt="<?php the_title(); ?> " class="th" /></a></li> <li><a href="<?php echo $posturl; ?> "><img src="<?php echo $images[3]['url']; ?> " alt="<?php the_title(); ?> " class="th" /></a></li> </ul></div> <?php } else { foreach ($attachments as $id => $attachment) { array_push($indexarray, $id); } ?> <div class="small-12 columns"> <ul class="small-block-grid-2 medium-block-grid-4"> <?php $i = 0; while ($i <= 3) { $imageid = $indexarray[$i]; $imagepost = get_post($imageid); $imgurl = wp_get_attachment_url($imageid); $imgalt = trim(strip_tags(get_post_meta($imageid, '_wp_attachment_image_alt', true))); if (false !== $imgurl) { ?> <li><a href="<?php echo $posturl; ?> "><img src="<?php echo $imgurl; ?> " alt="<?php echo $imgalt; ?> "class="th" /></a></li> <?php } $i++; } ?> </ul> </div> <?php } }
/** * Generates the thumbnail image to be used for the post. Uses the * image as returned by Jetpack_PostImages::get_image() * * @param int $post_id * @uses self::get_options, apply_filters, Jetpack_PostImages::get_image, Jetpack_PostImages::fit_image_url * @return string */ protected function _generate_related_post_image_params($post_id) { $options = $this->get_options(); $image_params = array('src' => '', 'width' => 0, 'height' => 0); if (!$options['show_thumbnails']) { return $image_params; } $thumbnail_size = apply_filters('jetpack_relatedposts_filter_thumbnail_size', array('width' => 350, 'height' => 200)); if (!is_array($thumbnail_size)) { $thumbnail_size = array('width' => (int) $thumbnail_size, 'height' => (int) $thumbnail_size); } // Try to get post image if (class_exists('Jetpack_PostImages')) { $img_url = ''; $post_image = Jetpack_PostImages::get_image($post_id, $thumbnail_size); if (is_array($post_image)) { $img_url = $post_image['src']; } elseif (class_exists('Jetpack_Media_Summary')) { $media = Jetpack_Media_Summary::get($post_id); if (is_array($media) && !empty($media['image'])) { $img_url = $media['image']; } } if (!empty($img_url)) { $image_params['width'] = $thumbnail_size['width']; $image_params['height'] = $thumbnail_size['height']; $image_params['src'] = Jetpack_PostImages::fit_image_url($img_url, $thumbnail_size['width'], $thumbnail_size['height']); } } return $image_params; }
/** * @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); }