$descr = has_excerpt() ? strip_tags(get_the_excerpt()) : ts_trim_text(apply_filters('the_content', get_the_content()), $descr_limit); $url = get_permalink(); $read_more = __('Read More', 'ThemeStockyard'); $meta = ts_get_the_category('portfolio-category'); } $link_begin = trim($url) ? '<a href="' . esc_url($url) . '" class="ts-item-link" target="' . esc_attr($target) . '">' : ''; $link_begin2 = trim($url) ? '<a href="' . esc_url($url) . '" class="ts-item-link ts-item-link-2" target="' . esc_attr($target) . '">' : ''; $link_end = trim($url) ? '</a>' : ''; } if ($slider_allow_vids && in_array($content_type, array('video', 'youtube', 'vimeo', 'self_hosted', 'self_hosted_video')) && !$slider_preview_exists) { $vimeo = get_post_meta($slider->post->ID, '_' . $prefix . '_vimeo_id', true); $youtube = get_post_meta($slider->post->ID, '_' . $prefix . '_youtube_id', true); $content_type .= $vimeo ? $vimeo : $youtube; if ($vimeo || $youtube) { $video_service = $vimeo ? 'vimeo' : ($youtube ? 'youtube' : ''); $video_id = $vimeo ? ts_get_video_id($vimeo) : ($youtube ? ts_get_video_id($youtube) : ''); $vdata = ts_get_and_save_video_data($video_id, $video_service); //$info = maybe_serialize(ts_get_saved_video_data($video_id, $video_service)); // for testing if ($ts_slider_type == 'carousel') { $style = 'width:' . absint($w) . 'px;height:' . absint($h) . 'px;'; } } if ($video_id) { $img = ''; } else { $youtube = $vimeo = ''; } } if (!$img && !$vimeo && !$youtube) { continue; }
function ts_youtube_shortcode($atts = null) { $atts = shortcode_atts(array('id' => '', 'url' => '', 'width' => 600, 'height' => 337, 'autoplay' => '', 'controls' => 1, 'showinfo' => 1, 'start' => '', 'end' => ''), $atts); $_id = trim($atts['id']) ? $atts['id'] : (trim($atts['url']) ? $atts['url'] : ''); $id = function_exists('ts_get_video_id') ? ts_get_video_id($_id) : ''; $autoplay = in_array($atts['autoplay'], array('true', '1', 'yes')) ? '&autoplay=1' : ''; $start = $atts['start'] ? '&start=' . $atts['start'] : ''; $end = $atts['end'] ? '&end=' . $atts['end'] : ''; $qs_addons = function_exists('ts_get_video_qs_addons') ? ts_get_video_qs_addons($atts['url'], '&') : ''; $controls = ''; $showinfo = ''; if ($id) { return '<div class="video-shortcode-wrap ts-shortcode-block"><div class="video-shortcode fluid-width-video-wrapper"><iframe title="YouTube video player" width="' . esc_attr($atts['width']) . '" height="' . esc_attr($atts['height']) . '" src="' . esc_url('https://www.youtube.com/embed/' . $id . '?hd=1' . $autoplay . $controls . $showinfo . $qs_addons . $start . $end) . '" frameborder="0" id="' . esc_attr('youtube_' . $id) . '" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div></div>'; } }
function ts_get_featured_media($arg = array()) { global $post, $smof_data, $ts_show_sidebar, $ts_page_id, $ts_within_blog_loop; $defaults = array('allow_audio' => false, 'allow_videos' => true, 'allow_galleries' => true); $arg = wp_parse_args($arg, $defaults); $html = ''; $ready = false; $within_slider = isset($arg['within_slider']) && ts_attr_is_true($arg['within_slider']) ? true : false; $is_single_featured_media = isset($arg['is_single']) && $arg['is_single'] === true && $post->ID == $ts_page_id ? true : false; $posttype = get_post_type($post->ID); $post_meta_prefix = $posttype == 'portfolio' ? '_portfolio_' : '_p_'; if ($posttype == 'portfolio') { $crop_images = ts_option_vs_default('crop_images_on_portfolio', 1) ? true : false; } else { $crop_images = ts_option_vs_default('crop_images_on_blog', 1) ? true : false; } $get_alt_text_in_loop = ts_option_vs_default('featured_image_alt_text_within_loop', 0) ? true : false; $get_alt_text = $is_single_featured_media || $get_alt_text_in_loop ? true : false; $video_id = $return_link = ''; if ($ts_show_sidebar == 'yes') { if ($crop_images) { $crop_width = 740; $crop_height = 480; } else { $crop_width = 740; $crop_height = 0; } } else { if ($crop_images) { $crop_width = 1100; $crop_height = 540; } else { $crop_width = 1100; $crop_height = 0; } } if (isset($arg['media_height']) && $arg['media_height'] !== false && isset($arg['media_width']) && $arg['media_width'] !== false) { $crop_width = $arg['media_width']; $crop_height = $arg['media_height']; } $seek_thumb_size_name = $crop_width > 1024 ? 'full' : 'large'; //ts_figure_thumb_name($crop_width, $crop_height); $allow_audio = isset($arg['allow_audio']) && ts_attr_is_true($arg['allow_audio']) ? true : false; $allow_videos = isset($arg['allow_videos']) && ts_attr_is_false($arg['allow_videos']) ? false : true; $allow_self_hosted_video = isset($arg['allow_self_hosted_video']) && ts_attr_is_true($arg['allow_self_hosted_video']) ? true : false; $allow_video_embed_code = isset($arg['allow_video_embed_code']) && ts_attr_is_false($arg['allow_video_embed_code']) ? false : true; $allow_galleries = isset($arg['allow_galleries']) && ts_attr_is_false($arg['allow_galleries']) ? false : true; if (isset($arg['video_height']) && isset($arg['video_width'])) { $video_width = 'width="' . esc_attr($arg['video_width']) . '"'; $video_height = 'height="' . esc_attr($arg['video_height']) . '"'; } else { $video_width = ''; $video_height = ''; } $audio_class = isset($arg['audio_class']) ? $arg['audio_class'] : ''; $media_class = isset($arg['media_class']) ? $arg['media_class'] : ''; $show_caption = isset($arg['show_caption']) && $arg['show_caption'] === true ? true : false; $post_format = $posttype == 'portfolio' ? get_post_meta($post->ID, $post_meta_prefix . 'project_type', true) : get_post_format(); if ($allow_videos && in_array($post_format, array('video', 'youtube', 'vimeo', 'self_hosted_video'))) { $vine = ''; // not used for now $vimeo = get_post_meta($post->ID, $post_meta_prefix . 'vimeo_id', true); $youtube = get_post_meta($post->ID, $post_meta_prefix . 'youtube_id', true); $self_hosted = get_post_meta($post->ID, $post_meta_prefix . 'self_hosted_video', true); $embed_code = get_post_meta($post->ID, $post_meta_prefix . 'video_embed_code', true); $post_format = $vimeo || $youtube || $self_hosted || $embed_code ? 'video' : 'standard'; if ($self_hosted && !$allow_self_hosted_video) { $post_format = 'standard'; } if ($embed_code && !$allow_video_embed_code) { $post_format = 'standard'; } } elseif ($allow_galleries && in_array($post_format, array('gallery', 'slider'))) { $post_format = 'gallery'; } elseif ($allow_audio && in_array($post_format, array('audio', 'soundcloud', 'spotify', 'self_hosted_audio'))) { $soundcloud = get_post_meta($post->ID, $post_meta_prefix . 'soundcloud_id', true); $spotify = get_post_meta($post->ID, $post_meta_prefix . 'spotify_id', true); $self_hosted_audio = get_post_meta($post->ID, $post_meta_prefix . 'self_hosted_audio', true); $post_format = $soundcloud || $spotify || $self_hosted_audio ? 'audio' : 'standard'; } else { $post_format = 'standard'; } $preview = get_post_meta($post->ID, $post_meta_prefix . 'preview_image', true); $preview_id = get_post_meta($post->ID, $post_meta_prefix . 'preview_image_id', true); $post_format = $preview && trim($preview) && $ts_page_id != $post->ID ? 'standard' : $post_format; $class = isset($arg['class']) ? $arg['class'] : ''; $color = str_replace('#', '', ts_option_vs_default('primary_color', '')); if ($post_format == 'video') { $html .= $class ? '<div class="' . esc_attr($class) . '">' : ''; if ($vimeo) { $qs_addons = ts_get_video_qs_addons($vimeo, '&'); $video_id = ts_get_video_id($vimeo); $return_link = 'https://vimeo.com/' . $video_id; $iframe_id = 'vimeo-' . $video_id . '-' . mt_rand(); $src_append = $within_slider ? '&api=1&player_id=' . $iframe_id : ''; $html .= '<div class="fluid-width-video-wrapper ' . esc_attr($media_class) . '"><div> <iframe id="' . esc_attr($iframe_id) . '" src="' . esc_url('https://player.vimeo.com/video/' . $video_id . '?title=0&byline=0&portrait=0&color=' . $color . $src_append . $qs_addons) . '" class="ts-vimeo-player" frameborder="0" webkitAllowFullScreen allowFullScreen ' . $video_width . ' ' . $video_height . '></iframe> </div></div>'; } elseif ($self_hosted) { $html .= '<div class="fluid-width-video-wrapperx ' . esc_attr($media_class) . '"> ' . do_shortcode('[video src="' . esc_url($self_hosted) . '"]') . ' </div>'; } elseif ($vine) { $video_id = ts_get_video_id($vine); $return_link = 'https://vine.com/v/' . $video_id; $html .= '<div class="featured-photo"><p class="fluid-width-video-wrapper ' . esc_attr($media_class) . '"> <iframe class="vine-embed" src="' . esc_url('https://vine.co/v/' . ts_get_video_id($vine) . '/embed/simple') . '" width="600" height="600" frameborder="0"></iframe><script async src="https://platform.vine.co/static/scripts/embed.js" charset="utf-8"></script> </p></div>'; } elseif ($embed_code) { $video_id = 'ts-embed-' . mt_rand(); $return_link = ''; $html = '<div class="fluid-width-video-wrapper ' . esc_attr($media_class) . '">' . $embed_code . '</div>'; } elseif ($youtube) { $qs_addons = ts_get_video_qs_addons($youtube, '&'); $video_id = ts_get_video_id($youtube); $return_link = 'https://www.youtube.com/watch?v=' . $video_id; $iframe_id = 'youtube-' . $video_id . '-' . mt_rand(); $src_append = $within_slider ? '&enablejsapi=1' : ''; $html .= '<div class="fluid-width-video-wrapper ' . esc_attr($media_class) . '"> <iframe id="' . esc_attr($iframe_id) . '" src="' . esc_url('https://www.youtube.com/embed/' . $video_id . '?rel=0' . $src_append . $qs_addons) . '" frameborder="0" class="ts-youtube-player" allowfullscreen ' . $video_width . ' ' . $video_height . '></iframe> </div>'; } $html .= $class ? '</div>' : ''; $ready = true; } if ($post_format == 'audio') { $html .= $class ? '<div class="featured-audio ' . esc_attr($class) . '">' : ''; if ($soundcloud) { $audio_url = ts_get_audio_embed_url($soundcloud); $return_link = $audio_url; $html .= '<div class="' . esc_attr($audio_class) . ' ' . esc_attr($media_class) . '">' . do_shortcode('[soundcloud url="' . esc_url($soundcloud) . '"]') . '</div>'; } elseif ($spotify) { $audio_url = ts_get_audio_embed_url($spotify); $return_link = $audio_url; $html .= '<div class="' . esc_attr($audio_class) . ' ' . esc_attr($media_class) . '">' . do_shortcode('[spotify url="' . esc_url($spotify) . '"]') . '</div>'; } elseif ($self_hosted_audio) { $return_link = $audio_url = $self_hosted_audio; $html .= '<div class="' . esc_attr($audio_class) . ' ' . esc_attr($media_class) . '">' . do_shortcode('[audio src="' . esc_url($self_hosted_audio) . '"]') . '</div>'; } $html .= $class ? '</div>' : ''; $post_format = $audio_url ? 'audio' : 'standard'; $ready = $audio_url ? true : false; } if ($post_format == 'gallery') { $crop_width = isset($arg['gallery_width']) ? $arg['gallery_width'] : $crop_width; $crop_height = isset($arg['gallery_height']) ? $arg['gallery_height'] : $crop_height; $gallery_type = isset($arg['gallery_type']) && $post->ID == $ts_page_id ? $arg['gallery_type'] : 'slider'; $photo1_id = get_post_meta($post->ID, $post_meta_prefix . 'image_1_id', true); $photo2_id = get_post_meta($post->ID, $post_meta_prefix . 'image_2_id', true); $photo3_id = get_post_meta($post->ID, $post_meta_prefix . 'image_3_id', true); $photo4_id = get_post_meta($post->ID, $post_meta_prefix . 'image_4_id', true); $photo5_id = get_post_meta($post->ID, $post_meta_prefix . 'image_5_id', true); $photo6_id = get_post_meta($post->ID, $post_meta_prefix . 'image_6_id', true); $photo7_id = get_post_meta($post->ID, $post_meta_prefix . 'image_7_id', true); $photo8_id = get_post_meta($post->ID, $post_meta_prefix . 'image_8_id', true); $photo9_id = get_post_meta($post->ID, $post_meta_prefix . 'image_9_id', true); $photo10_id = get_post_meta($post->ID, $post_meta_prefix . 'image_10_id', true); $photo1 = wp_get_attachment_image_src($photo1_id, $seek_thumb_size_name); $photo2 = wp_get_attachment_image_src($photo2_id, $seek_thumb_size_name); $photo3 = wp_get_attachment_image_src($photo3_id, $seek_thumb_size_name); $photo4 = wp_get_attachment_image_src($photo4_id, $seek_thumb_size_name); $photo5 = wp_get_attachment_image_src($photo5_id, $seek_thumb_size_name); $photo6 = wp_get_attachment_image_src($photo6_id, $seek_thumb_size_name); $photo7 = wp_get_attachment_image_src($photo7_id, $seek_thumb_size_name); $photo8 = wp_get_attachment_image_src($photo8_id, $seek_thumb_size_name); $photo9 = wp_get_attachment_image_src($photo9_id, $seek_thumb_size_name); $photo10 = wp_get_attachment_image_src($photo10_id, $seek_thumb_size_name); $photo1 = isset($photo1[0]) ? aq_resize($photo1[0], $crop_width, $crop_height, true, true, true, $photo1_id) : ''; $photo2 = isset($photo2[0]) ? aq_resize($photo2[0], $crop_width, $crop_height, true, true, true, $photo2_id) : ''; $photo3 = isset($photo3[0]) ? aq_resize($photo3[0], $crop_width, $crop_height, true, true, true, $photo3_id) : ''; $photo4 = isset($photo4[0]) ? aq_resize($photo4[0], $crop_width, $crop_height, true, true, true, $photo4_id) : ''; $photo5 = isset($photo5[0]) ? aq_resize($photo5[0], $crop_width, $crop_height, true, true, true, $photo5_id) : ''; $photo6 = isset($photo6[0]) ? aq_resize($photo6[0], $crop_width, $crop_height, true, true, true, $photo6_id) : ''; $photo7 = isset($photo7[0]) ? aq_resize($photo7[0], $crop_width, $crop_height, true, true, true, $photo7_id) : ''; $photo8 = isset($photo8[0]) ? aq_resize($photo8[0], $crop_width, $crop_height, true, true, true, $photo8_id) : ''; $photo9 = isset($photo9[0]) ? aq_resize($photo9[0], $crop_width, $crop_height, true, true, true, $photo9_id) : ''; $photo10 = isset($photo10[0]) ? aq_resize($photo10[0], $crop_width, $crop_height, true, true, true, $photo10_id) : ''; $all_photos = array('id_' . $photo1_id => $photo1, 'id_' . $photo2_id => $photo2, 'id_' . $photo3_id => $photo3, 'id_' . $photo4_id => $photo4, 'id_' . $photo5_id => $photo5, 'id_' . $photo6_id => $photo6, 'id_' . $photo7_id => $photo7, 'id_' . $photo8_id => $photo8, 'id_' . $photo9_id => $photo9, 'id_' . $photo10_id => $photo10); $all_photos = array_filter($all_photos); $return_link = current($all_photos); if (count($all_photos) > 0) { if ($gallery_type == 'masonry' || $gallery_type == 'grid') { $html .= '<div class="ts-portfolio-masonry-gallery">'; $link_begin = '<a href="' . esc_url(get_permalink()) . '" class="featured-photo-link">'; $link_end = '</a>'; if ($post->ID == $ts_page_id) { $link_begin = ''; $link_end = ''; } $i = 1; foreach ($all_photos as $img_id => $img) { $alt = $get_alt_text ? ts_get_attachment_alt_text($img_id) : ''; $html .= '<div class="item">' . $link_begin . '<img src="' . esc_url($img) . '" alt="' . esc_attr($alt) . '"/>' . $link_end . '</div>'; $i++; } $html .= $class ? '</div>' : ''; } elseif ($gallery_type == 'images') { $i = 1; foreach ($all_photos as $img_id => $img) { $alt = $get_alt_text ? ts_get_attachment_alt_text($img_id) : ''; $html .= '<div class="single-image"><img src="' . esc_url($img) . '" alt="' . esc_attr($alt) . '"/></div>'; $i++; } } else { $html .= $class ? '<div class="' . esc_attr($class) . ' ' . esc_attr($media_class) . '">' : ''; $html .= '<div class="flexslider gallery slider"><ul class="slides">'; $link_begin = '<a href="' . esc_url(get_permalink()) . '" class="featured-photo-link">'; $link_end = '</a>'; if ($post->ID == $ts_page_id) { $link_begin = ''; $link_end = ''; } $i = 1; foreach ($all_photos as $img_id => $img) { $alt = $get_alt_text ? ts_get_attachment_alt_text($img_id) : ''; $html .= '<li>' . $link_begin . '<img src="' . esc_url($img) . '" alt="' . esc_attr($alt) . '"/>' . $link_end . '</li>'; $i++; } $html .= '</ul></div>'; $html .= $class ? '</div>' : ''; } } else { $post_format = 'standard'; } } if (!in_array($post_format, array('video', 'gallery', 'slider', 'audio')) || in_array($post_format, array('video', 'gallery', 'slider', 'audio')) && !$html) { $post_format = 'standard'; $photo_id = ''; $thumb_photo_id = get_post_thumbnail_id($post->ID); $thumb_photo = wp_get_attachment_image_src($thumb_photo_id, $seek_thumb_size_name); $thumb_photo = isset($thumb_photo[0]) ? $thumb_photo[0] : ''; if (trim($preview) && !$is_single_featured_media || $preview && !$thumb_photo) { $photo_id = $preview_id; $photo = $return_link = $preview; } else { $photo_id = $thumb_photo_id; $photo = $return_link = $thumb_photo; } if ($photo) { $caption = ''; $link_class = $within_slider ? 'ts-item-link' : 'featured-photo-link'; $link_begin = '<a href="' . esc_url(get_permalink()) . '" class="' . esc_attr($link_class) . '">'; $link_end = '</a>'; if ($post->ID == $ts_page_id && $show_caption && $ts_within_blog_loop === false) { $link_begin = ''; $link_end = ''; $caption = ts_get_photo_caption($photo_id); } $photo = aq_resize($photo, $crop_width, $crop_height, true, true, true, $photo_id); $photo_class = $within_slider ? 'slider-photo' : 'featured-photo'; $alt = $get_alt_text ? ts_get_attachment_alt_text($photo_id) : ''; $media = '<div class="' . esc_attr($photo_class) . ' ' . esc_attr($media_class) . ' ' . esc_attr($ts_within_blog_loop) . '">' . $link_begin . '<img src="' . esc_url($photo) . '" alt="' . esc_attr($alt) . '" width="' . esc_attr($crop_width) . '"/>' . $link_end . $caption . '</div>'; $html .= $class ? '<div class="' . esc_attr($class) . '">' . $media . '</div>' . "\n" : $media . "\n"; } } $wrap_class = array(); $wrap_class[] = $within_slider ? '' : 'ts-fade-in'; $wrap_class[] = isset($arg['wrap_class']) ? $arg['wrap_class'] : ''; $wrap_class[] = 'ts-featured-media-' . $post_format; $wrap_class = implode(' ', $wrap_class); $final_html = '<div class="featured-media-wrap ' . esc_attr($wrap_class) . '">' . $html . '</div>'; if (isset($arg['return']) && $arg['return'] == 'link') { return $return_link; } elseif (isset($arg['return']) && $arg['return'] == 'array') { $mfp_class = $post_format == 'video' && $video_id ? 'mfp-iframe' : (isset($return_link) ? 'mfp-image' : ''); return array('link' => $return_link, 'mfp_class' => $mfp_class); } elseif (isset($arg['return']) && $arg['return'] == 'big_array') { $return_array = array('html' => $final_html, 'format' => $post_format); return $return_array; } else { return trim($html) ? $final_html : ''; } }