function td_get_video_thumb($post_id) { //verify post is not a revision if (!wp_is_post_revision($post_id)) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } $td_post_video = get_post_meta($post_id, 'td_post_video', true); //load video support $td_video_support = new td_video_support(); //check to see if the url is valid if (empty($td_post_video['td_video']) or $td_video_support->validateVideoUrl($td_post_video['td_video']) === false) { return; } if (!empty($td_post_video['td_last_video']) and $td_post_video['td_last_video'] == $td_post_video['td_video']) { //we did not update the url return; } //$myFile = "D:/td_video.txt"; //$fh = fopen($myFile, 'a') or die("can't open file"); $stringData = $post_id . ' - ' . print_r($td_post_video, true) . "\n"; //return; $videoThumbUrl = $td_video_support->getThumbUrl($td_post_video['td_video']); /* $stringData .= $post_id . ' - ' . $videoThumbUrl . "\n"; fwrite($fh, $stringData); fclose($fh); */ if (!empty($videoThumbUrl)) { // add the function above to catch the attachments creation add_action('add_attachment', 'td_add_featured_image'); // load the attachment from the URL media_sideload_image($videoThumbUrl, $post_id, $post_id); // we have the Image now, and the function above will have fired too setting the thumbnail ID in the process, so lets remove the hook so we don't cause any more trouble remove_action('add_attachment', 'td_add_featured_image'); } } }
/** * v3 23 ian 2015 * @param $thumbType * @return string */ function get_image($thumbType) { global $page; // if ( //check to see if the current single template is configured to show the featured image on the second page // !isset( td_global::$single_templates_list[td_global::$cur_single_template]['show_featured_image_on_all_pages'] ) // or td_global::$single_templates_list[td_global::$cur_single_template]['show_featured_image_on_all_pages'] === false // ){ if (td_api_single_template::_check_show_featured_image_on_all_pages(td_global::$cur_single_template) === false) { //the post is configured to show the featured image only on the first page if (!empty($page) and $page > 1) { return ''; } } //do not show the featured image if the global setting is set to hide - show the video preview regardless of the setting if (td_util::get_option('tds_show_featured_image') == 'hide' and get_post_format($this->post->ID) != 'video') { return ''; } //handle video post format if (get_post_format($this->post->ID) == 'video') { //if it's a video post... $td_post_video = get_post_meta($this->post->ID, 'td_post_video', true); $td_video_support = new td_video_support(); //render the video if the post has a video in the featured video section of the post if (!empty($td_post_video['td_video'])) { return $td_video_support->renderVideo($td_post_video['td_video']); } } else { //if it's a normal post, show the default thumb if ($this->post_has_thumb) { //get the featured image id + full info about the 640px wide one $featured_image_id = get_post_thumbnail_id($this->post->ID); $featured_image_info = td_util::attachment_get_full_info($featured_image_id, $thumbType); //get the full size for the popup $featured_image_full_size_src = td_util::attachment_get_src($featured_image_id, 'full'); $buffy = ''; $show_td_modal_image = td_util::get_option('tds_featured_image_view_setting'); if (is_single()) { if ($show_td_modal_image != 'no_modal') { //wrap the image_html with a link + add td-modal-image class $image_html = '<a href="' . $featured_image_full_size_src['src'] . '" data-caption="' . esc_attr($featured_image_info['caption'], ENT_QUOTES) . '">'; $image_html .= '<img width="' . $featured_image_info['width'] . '" height="' . $featured_image_info['height'] . '" itemprop="image" class="entry-thumb td-modal-image" src="' . $featured_image_info['src'] . '" alt="' . $featured_image_info['alt'] . '" title="' . $featured_image_info['title'] . '"/>'; $image_html .= '</a>'; } else { //no_modal $image_html = '<img width="' . $featured_image_info['width'] . '" height="' . $featured_image_info['height'] . '" itemprop="image" class="entry-thumb" src="' . $featured_image_info['src'] . '" alt="' . $featured_image_info['alt'] . '" title="' . $featured_image_info['title'] . '"/>'; } } else { //on blog index page $image_html = '<a href="' . $this->href . '"><img width="' . $featured_image_info['width'] . '" height="' . $featured_image_info['height'] . '" itemprop="image" class="entry-thumb" src="' . $featured_image_info['src'] . '" alt="' . $featured_image_info['alt'] . '" title="' . $featured_image_info['title'] . '"/></a>'; } $buffy .= '<div class="td-post-featured-image">'; // caption - put html5 wrapper on when we have a caption if (!empty($featured_image_info['caption'])) { $buffy .= '<figure>'; $buffy .= $image_html; $buffy .= '<figcaption class="wp-caption-text">' . $featured_image_info['caption'] . '</figcaption>'; $buffy .= '</figure>'; } else { $buffy .= $image_html; } $buffy .= '</div>'; return $buffy; } else { return ''; //the post has no thumb } } }
/** * Downloads the video thumb on the save_post hook * @param $post_id */ static function on_save_post_get_video_thumb($post_id) { //verify post is not a revision if (!wp_is_post_revision($post_id)) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } $td_post_video = get_post_meta($post_id, 'td_post_video', true); //check to see if the url is valid if (empty($td_post_video['td_video']) or self::validate_video_url($td_post_video['td_video']) === false) { return; } if (!empty($td_post_video['td_last_video']) and $td_post_video['td_last_video'] == $td_post_video['td_video']) { //we did not update the url return; } $videoThumbUrl = self::get_thumb_url($td_post_video['td_video']); if (!empty($videoThumbUrl)) { self::$on_save_post_post_id = $post_id; // add the function above to catch the attachments creation add_action('add_attachment', array(__CLASS__, 'on_add_attachment_set_featured_image')); // load the attachment from the URL media_sideload_image($videoThumbUrl, $post_id, $post_id); // we have the Image now, and the function above will have fired too setting the thumbnail ID in the process, so lets remove the hook so we don't cause any more trouble remove_action('add_attachment', array(__CLASS__, 'on_add_attachment_set_featured_image')); } } }