Пример #1
0
/**
 * 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'];
    $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;
}
Пример #2
0
function migrate_old_content()
{
    $content = array();
    $tmp = array();
    $files = array();
    $draft = array();
    $dtmp = array();
    $dfiles = array();
    $tmp = glob('content/*/blog/*.md', GLOB_NOSORT);
    if (is_array($tmp)) {
        foreach ($tmp as $file) {
            $content[] = $file;
        }
    }
    if (!empty($content)) {
        foreach ($content as $c => $v) {
            $arr = explode('/', $v);
            $string = file_get_contents($v);
            $image = get_content_tag('image', $string);
            $video = get_youtube_id(get_content_tag('video', $string));
            $audio = get_content_tag('audio', $string);
            $link = get_content_tag('link', $string);
            $quote = get_content_tag('quote', $string);
            if (!empty($image)) {
                $files[] = array($v, 'content/' . $arr[1] . '/blog/uncategorized/image/' . $arr[3]);
                $dir = 'content/' . $arr[1] . '/blog/uncategorized/image/';
                if (!is_dir($dir)) {
                    mkdir($dir, 0775, true);
                }
            }
            if (!empty($video)) {
                $files[] = array($v, 'content/' . $arr[1] . '/blog/uncategorized/video/' . $arr[3]);
                $dir = 'content/' . $arr[1] . '/blog/uncategorized/video/';
                if (!is_dir($dir)) {
                    mkdir($dir, 0775, true);
                }
            }
            if (!empty($audio)) {
                $files[] = array($v, 'content/' . $arr[1] . '/blog/uncategorized/audio/' . $arr[3]);
                $dir = 'content/' . $arr[1] . '/blog/uncategorized/audio/';
                if (!is_dir($dir)) {
                    mkdir($dir, 0775, true);
                }
            }
            if (!empty($link)) {
                $files[] = array($v, 'content/' . $arr[1] . '/blog/uncategorized/link/' . $arr[3]);
                $dir = 'content/' . $arr[1] . '/blog/uncategorized/link/';
                if (!is_dir($dir)) {
                    mkdir($dir, 0775, true);
                }
            }
            if (!empty($quote)) {
                $files[] = array($v, 'content/' . $arr[1] . '/blog/uncategorized/quote/' . $arr[3]);
                $dir = 'content/' . $arr[1] . '/blog/uncategorized/quote/';
                if (!is_dir($dir)) {
                    mkdir($dir, 0775, true);
                }
            }
            if (empty($image) && empty($video) && empty($audio) && empty($link) && empty($quote)) {
                $files[] = array($v, 'content/' . $arr[1] . '/blog/uncategorized/post/' . $arr[3]);
                $dir = 'content/' . $arr[1] . '/blog/uncategorized/post/';
                if (!is_dir($dir)) {
                    mkdir($dir, 0775, true);
                }
            }
        }
        foreach ($files as $f) {
            rename($f[0], $f[1]);
        }
    }
    $dir = 'content/data/';
    if (!is_dir($dir)) {
        mkdir($dir, 0775, true);
    }
    if (file_exists('content/tags.lang')) {
        rename('content/tags.lang', 'content/data/tags.lang');
        unlink('content/views.json');
    }
    $dtmp = glob('content/*/draft/*.md', GLOB_NOSORT);
    $old = array();
    if (is_array($dtmp)) {
        foreach ($dtmp as $dfile) {
            $draft[] = $dfile;
        }
    }
    if (!empty($draft)) {
        foreach ($draft as $d => $val) {
            $arr = explode('/', $val);
            $old[] = 'content/' . $arr[1] . '/draft/';
            $dir = 'content/' . $arr[1] . '/blog/uncategorized/draft/';
            $new = 'content/' . $arr[1] . '/blog/uncategorized/draft/' . $arr[3];
            if (!is_dir($dir)) {
                mkdir($dir, 0775, true);
            }
            $dfiles[] = array($val, $new);
        }
        foreach ($dfiles as $fd) {
            rename($fd[0], $fd[1]);
        }
        $tt = array();
        $tt = array_unique($old, SORT_REGULAR);
        foreach ($tt as $t) {
            rmdir($t);
        }
    }
    rebuilt_cache('all');
}
Пример #3
0
function youtube_id($url)
{
    if (!($id = get_youtube_id($url))) {
        return '<!--YouTube Error: bad URL entered-->';
    }
    $url = str_replace('&#038;', '&', $url);
    $url = trim($url, ' "');
    $url = trim($url);
    $url = str_replace(array('/v/', '#!v=', '&amp;'), array('/?v=', '?v=', '&'), $url);
    $url = parse_url($url);
    if (!isset($url['query'])) {
        return false;
    }
    $url['query'] = str_replace('?', '&', $url['query']);
    parse_str($url['query'], $qargs);
    $agent = $_SERVER['HTTP_USER_AGENT'];
    // Bloglines & Google Reader handle YouTube well now, instead of
    // big blank space of yester year, so they can skip this treatment
    if (is_feed() && !preg_match('#Bloglines|FeedFetcher-Google#i', $agent)) {
        return '<span style="text-align:center; display: block;"><a href="' . get_permalink() . '"><img src="http://img.youtube.com/vi/' . $id . '/2.jpg" alt="" /></a></span>';
    }
    // calculate the width and height, taken content_width into consideration
    global $content_width;
    $input_w = isset($qargs['w']) && intval($qargs['w']) ? intval($qargs['w']) : 0;
    $input_h = isset($qargs['h']) && intval($qargs['h']) ? intval($qargs['h']) : 0;
    $default_width = 640;
    if ($input_w > 0 && $input_h > 0) {
        $w = $input_w;
        $h = $input_h;
    } elseif (0 == $input_w && 0 == $input_h) {
        if (isset($qargs['fmt']) && intval($qargs['fmt'])) {
            $w = !empty($content_width) ? min($content_width, 480) : 480;
        } else {
            $w = !empty($content_width) ? min($content_width, $default_width) : $default_width;
        }
        $h = ceil($w / 16 * 9) + 30;
    } elseif ($input_w > 0) {
        $w = $input_w;
        $h = ceil($w / 16 * 9) + 30;
    } else {
        if (isset($qargs['fmt']) && intval($qargs['fmt'])) {
            $w = !empty($content_width) ? min($content_width, 480) : 480;
        } else {
            $w = !empty($content_width) ? min($content_width, $default_width) : $default_width;
        }
        $h = $input_h;
    }
    $w = (int) apply_filters('youtube_width', $w);
    $h = (int) apply_filters('youtube_height', $h);
    $fmt = '';
    if (isset($qargs['fmt']) && intval($qargs['fmt'])) {
        $fmt = '&fmt=' . (int) $qargs['fmt'];
    }
    if (isset($qargs['rel']) && 0 == $qargs['rel']) {
        $rel = 0;
    } else {
        $rel = 1;
    }
    if (isset($qargs['showsearch']) && 1 == $qargs['showsearch']) {
        $search = 1;
    } else {
        $search = 0;
    }
    if (isset($qargs['showinfo']) && 0 == $qargs['showinfo']) {
        $info = 0;
    } else {
        $info = 1;
    }
    if (isset($qargs['iv_load_policy']) && 3 == $qargs['iv_load_policy']) {
        $iv = 3;
    } else {
        $iv = 1;
    }
    $start = '';
    if (isset($qargs['start']) && intval($qargs['start'])) {
        $start = '&start=' . (int) $qargs['start'];
    }
    $hd = '';
    if (isset($qargs['hd']) && intval($qargs['hd'])) {
        $hd = '&hd=' . (int) $qargs['hd'];
    }
    return "<span style='text-align:center; display: block;'><object width='{$w}' height='{$h}'><param name='movie' value='http://www.youtube.com/v/{$id}?version=3&rel={$rel}&fs=1{$fmt}&showsearch={$search}&showinfo={$info}&iv_load_policy={$iv}{$start}{$hd}' /> <param name='allowfullscreen' value='true' /> <param name='wmode' value='opaque' /> <embed src='http://www.youtube.com/v/{$id}?version=3&rel={$rel}&fs=1{$fmt}&showsearch={$search}&showinfo={$info}&iv_load_policy={$iv}{$start}{$hd}' type='application/x-shockwave-flash' allowfullscreen='true' width='{$w}' height='{$h}' wmode='opaque'></embed> </object></span>";
}
Пример #4
0
     } elseif (is_picasa($rowcontent['vid_path'])) {
         $rowcontent['vid_type'] = 3;
         //is Picasa
     } elseif (is_facebook($rowcontent['vid_path'])) {
         $rowcontent['vid_type'] = 4;
         //is Facebook
     } else {
         $rowcontent['vid_type'] = 5;
         //hotlink from other site
     }
 } else {
     $rowcontent['vid_path'] = '';
 }
 // Auto-Thumb from Youtube - if empty Image
 if ($rowcontent['vid_type'] == 2 and empty($rowcontent['homeimgfile'])) {
     $rowcontent['homeimgfile'] = 'http://img.youtube.com/vi/' . get_youtube_id($rowcontent['vid_path']) . '/0.jpg';
     $rowcontent['homeimgthumb'] = 3;
 }
 // Auto-duration from Youtube - if empty
 if ($rowcontent['vid_type'] == 2 and empty($rowcontent['vid_duration'])) {
     $_vid_duration = youtubeVideoDuration($rowcontent['vid_path']);
     $rowcontent['vid_duration'] = sec2hms($_vid_duration);
 }
 if ($rowcontent['id'] == 0) {
     if (!defined('NV_IS_SPADMIN') and intval($rowcontent['publtime']) < NV_CURRENTTIME) {
         $rowcontent['publtime'] = NV_CURRENTTIME;
     }
     if ($rowcontent['status'] == 1 and $rowcontent['publtime'] > NV_CURRENTTIME) {
         $rowcontent['status'] = 2;
     }
     $sql = 'INSERT INTO ' . NV_PREFIXLANG . '_' . $module_data . '_rows
Пример #5
0
/**
 * Converts a YouTube URL into an embedded YouTube video.
 */
function youtube_id($url)
{
    if (apply_filters('jetpack_bail_on_shortcode', false, 'youtube')) {
        return '';
    }
    if (!($id = get_youtube_id($url))) {
        return '<!--YouTube Error: bad URL entered-->';
    }
    $url = youtube_sanitize_url($url);
    $url = parse_url($url);
    if (!isset($url['query'])) {
        return false;
    }
    parse_str($url['query'], $qargs);
    // calculate the width and height, taking content_width into consideration
    global $content_width;
    $input_w = isset($qargs['w']) && intval($qargs['w']) ? intval($qargs['w']) : 0;
    $input_h = isset($qargs['h']) && intval($qargs['h']) ? intval($qargs['h']) : 0;
    $default_width = get_option('embed_size_w');
    if (empty($default_width)) {
        if (!empty($content_width)) {
            $default_width = $content_width;
        } else {
            $default_width = 640;
        }
    }
    if ($input_w > 0 && $input_h > 0) {
        $w = $input_w;
        $h = $input_h;
    } elseif (0 == $input_w && 0 == $input_h) {
        if (isset($qargs['fmt']) && intval($qargs['fmt'])) {
            $w = !empty($content_width) ? min($content_width, 480) : 480;
        } else {
            $w = !empty($content_width) ? min($content_width, $default_width) : $default_width;
            $h = ceil($w / 16 * 9) + 30;
        }
    } elseif ($input_w > 0) {
        $w = $input_w;
        $h = ceil($w / 16 * 9) + 30;
    } else {
        if (isset($qargs['fmt']) && intval($qargs['fmt'])) {
            $w = !empty($content_width) ? min($content_width, 480) : 480;
        } else {
            $w = !empty($content_width) ? min($content_width, $default_width) : $default_width;
            $h = $input_h;
        }
    }
    $w = (int) apply_filters('youtube_width', $w);
    $h = (int) apply_filters('youtube_height', $h);
    $rel = isset($qargs['rel']) && 0 == $qargs['rel'] ? 0 : 1;
    $search = isset($qargs['showsearch']) && 1 == $qargs['showsearch'] ? 1 : 0;
    $info = isset($qargs['showinfo']) && 0 == $qargs['showinfo'] ? 0 : 1;
    $iv = isset($qargs['iv_load_policy']) && 3 == $qargs['iv_load_policy'] ? 3 : 1;
    $fmt = isset($qargs['fmt']) && intval($qargs['fmt']) ? '&fmt=' . (int) $qargs['fmt'] : '';
    $start = isset($qargs['start']) && intval($qargs['start']) ? '&start=' . (int) $qargs['start'] : '';
    $hd = isset($qargs['hd']) && intval($qargs['hd']) ? '&hd=' . (int) $qargs['hd'] : '';
    $wmode = isset($qargs['wmode']) && in_array(strtolower($qargs['wmode']), array('opaque', 'window', 'transparent')) ? $qargs['wmode'] : 'transparent';
    $alignmentcss = 'text-align:center;';
    if (isset($qargs['align'])) {
        switch ($qargs['align']) {
            case 'left':
                $alignmentcss = "float:left; width:{$w}px; height:{$h}px; margin-right:10px; margin-bottom: 10px;";
                break;
            case 'right':
                $alignmentcss = "float:right; width:{$w}px; height:{$h}px; margin-left:10px; margin-bottom: 10px;";
                break;
        }
    }
    if (isset($url['path']) && '/videoseries' == $url['path'] || isset($qargs['list'])) {
        $html = "<span class='embed-youtube' style='{$alignmentcss} display: block;'><iframe class='youtube-player' type='text/html' width='{$w}' height='{$h}' src='" . esc_url("http://www.youtube.com/embed/videoseries?list={$id}&hl=en_US") . "' frameborder='0'></iframe></span>";
    } else {
        $html = "<span class='embed-youtube' style='{$alignmentcss} display: block;'><iframe class='youtube-player' type='text/html' width='{$w}' height='{$h}' src='" . esc_url("http://www.youtube.com/embed/{$id}?version=3&rel={$rel}&fs=1{$fmt}&showsearch={$search}&showinfo={$info}&iv_load_policy={$iv}{$start}{$hd}&wmode={$wmode}") . "' frameborder='0'></iframe></span>";
    }
    $html = apply_filters('video_embed_html', $html);
    return $html;
}
 static function get($post_id, $blog_id = 0, $args = array())
 {
     $defaults = array('trigger_mshot' => false);
     $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();
     }
     $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));
     $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)\\.com|youtu.be)/', $embed)) {
                 if (0 == $return['count']['video']) {
                     $return['type'] = 'video';
                     $return['video'] = 'http://' . $embed;
                     $return['secure']['video'] = self::https($return['video']);
                     if (strstr($embed, 'youtube')) {
                         $return['image'] = self::get_video_poster('youtube', get_youtube_id($return['video']));
                         $return['secure']['image'] = self::https($return['image']);
                     } else {
                         if (strstr($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'];
                             }
                         }
                     }
                 }
                 $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'])) {
             //... 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) {
                     // If we have lots of text, let's not treat it as an image post, but return its first image
                     $return['type'] = 'image';
                 }
             }
         }
     }
     if (empty($post->post_password)) {
         $return['excerpt'] = self::get_excerpt($post->post_content, $post->post_excerpt);
         $return['count']['word'] = self::get_word_count($post->post_content);
         $return['count']['word_remaining'] = self::get_word_remaining_count($post->post_content, self::get_excerpt($post->post_content, $post->post_excerpt));
         $return['count']['link'] = self::get_link_count($post->post_content);
     }
     if ($switched) {
         restore_current_blog();
     }
     return $return;
 }
Пример #7
0
/**
 * Converts a YouTube URL into an embedded YouTube video.
 */
function youtube_id($url)
{
    if (apply_filters('jetpack_bail_on_shortcode', false, 'youtube')) {
        return '';
    }
    if (!($id = get_youtube_id($url))) {
        return '<!--YouTube Error: bad URL entered-->';
    }
    $url = youtube_sanitize_url($url);
    $url = parse_url($url);
    if (!isset($url['query'])) {
        return false;
    }
    parse_str($url['query'], $qargs);
    $agent = $_SERVER['HTTP_USER_AGENT'];
    // Bloglines & Google Reader handle YouTube well now, instead of
    // big blank space of yester year, so they can skip this treatment
    if (is_feed() && !preg_match('#' . apply_filters('jetpack_shortcode_youtube_whitelist_user_agents', 'Bloglines|FeedFetcher-Google|feedburner') . '#i', $agent)) {
        return '<span style="text-align:center; display: block;"><a href="' . get_permalink() . '"><img src="http://img.youtube.com/vi/' . $id . '/2.jpg" alt="" /></a></span>';
    }
    // calculate the width and height, taken content_width into consideration
    global $content_width;
    $input_w = isset($qargs['w']) && intval($qargs['w']) ? intval($qargs['w']) : 0;
    $input_h = isset($qargs['h']) && intval($qargs['h']) ? intval($qargs['h']) : 0;
    $default_width = 640;
    if ($input_w > 0 && $input_h > 0) {
        $w = $input_w;
        $h = $input_h;
    } elseif (0 == $input_w && 0 == $input_h) {
        if (isset($qargs['fmt']) && intval($qargs['fmt'])) {
            $w = !empty($content_width) ? min($content_width, 480) : 480;
        } else {
            $w = !empty($content_width) ? min($content_width, $default_width) : $default_width;
        }
        $h = ceil($w / 16 * 9) + 30;
    } elseif ($input_w > 0) {
        $w = $input_w;
        $h = ceil($w / 16 * 9) + 30;
    } else {
        if (isset($qargs['fmt']) && intval($qargs['fmt'])) {
            $w = !empty($content_width) ? min($content_width, 480) : 480;
        } else {
            $w = !empty($content_width) ? min($content_width, $default_width) : $default_width;
        }
        $h = $input_h;
    }
    $w = (int) apply_filters('youtube_width', $w);
    $h = (int) apply_filters('youtube_height', $h);
    $fmt = '';
    if (isset($qargs['fmt']) && intval($qargs['fmt'])) {
        $fmt = '&fmt=' . (int) $qargs['fmt'];
    }
    if (isset($qargs['rel']) && 0 == $qargs['rel']) {
        $rel = 0;
    } else {
        $rel = 1;
    }
    if (isset($qargs['showsearch']) && 1 == $qargs['showsearch']) {
        $search = 1;
    } else {
        $search = 0;
    }
    if (isset($qargs['showinfo']) && 0 == $qargs['showinfo']) {
        $info = 0;
    } else {
        $info = 1;
    }
    if (isset($qargs['iv_load_policy']) && 3 == $qargs['iv_load_policy']) {
        $iv = 3;
    } else {
        $iv = 1;
    }
    $start = '';
    if (isset($qargs['start']) && intval($qargs['start'])) {
        $start = '&start=' . (int) $qargs['start'];
    }
    $hd = '';
    if (isset($qargs['hd']) && intval($qargs['hd'])) {
        $hd = '&hd=' . (int) $qargs['hd'];
    }
    $alignmentcss = 'text-align:center;';
    if (isset($qargs['align'])) {
        switch ($qargs['align']) {
            case 'left':
                $alignmentcss = "float:left; width:{$w}px; height:{$h}px; margin-right:10px; margin-bottom: 10px;";
                break;
            case 'right':
                $alignmentcss = "float:right; width:{$w}px; height:{$h}px; margin-left:10px; margin-bottom: 10px;";
                break;
        }
    }
    if (isset($qargs['wmode']) && in_array(strtolower($qargs['wmode']), array('opaque', 'window', 'transparent'))) {
        $wmode = $qargs['wmode'];
    } else {
        $wmode = 'transparent';
    }
    $html = "<span class='embed-youtube' style='{$alignmentcss} display: block;'><iframe class='youtube-player' type='text/html' width='{$w}' height='{$h}' src='" . esc_attr("http://www.youtube.com/embed/{$id}?version=3&rel={$rel}&fs=1{$fmt}&showsearch={$search}&showinfo={$info}&iv_load_policy={$iv}{$start}{$hd}&wmode={$wmode}") . "' frameborder='0'></iframe></span>";
    $html = apply_filters('video_embed_html', $html);
    return $html;
}
Пример #8
0
function the_videos($videoCategorySlug = '', $videoHtml = 'default_video')
{
    if (!$videoCategorySlug) {
        return;
    }
    $args = array('post_type' => 'video', 'youtube_video' => $videoCategorySlug, 'posts_per_page' => -1);
    $VIDEO_HTML = array('default_video' => 'default_video_html', 'about_video' => 'about_video_html', 'thumb_video' => 'thumb_video_html', 'main_video' => 'main_video_html', 'role_modeling_main_video' => 'role_modeling_main_video_html', 'founder_video' => 'founder_video_html');
    $posts = get_posts($args);
    if ($posts) {
        foreach ($posts as $post) {
            $youtubeId = get_youtube_id($post->ID);
            $videoData = array('thumbnail' => null, 'views' => null, 'text' => null, 'twitter-message' => null, 'permalink' => get_permalink($post->ID));
            $videoData = array_merge($videoData, get_video_data($post->ID, $youtubeId));
            if ($videoData['thumbnail']) {
                $VIDEO_HTML[$videoHtml]($videoData);
            }
            the_excerpt();
        }
    }
}
function is_youtube($url)
{
    if (strlen(get_youtube_id($url)) > 0) {
        return true;
    } else {
        return false;
    }
}
/**
* Return video duration in seconds.
* 
* @param $video_url
* @param $api_key
* @return integer|null
*/
function youtubeVideoDuration($video_url)
{
    global $module_config, $module_name;
    // video id from url
    $video_id = get_youtube_id($video_url);
    $api_key = $module_config[$module_name]['youtube_api'];
    if (empty($api_key)) {
        $seconds = '';
        return $seconds;
    } else {
        // video json data
        $json_result = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id={$video_id}&key={$api_key}");
        $result = json_decode($json_result, true);
        // video duration data
        if (!count($result['items'])) {
            return null;
        }
        $duration_encoded = $result['items'][0]['contentDetails']['duration'];
        // duration
        $interval = new DateInterval($duration_encoded);
        $seconds = $interval->days * 86400 + $interval->h * 3600 + $interval->i * 60 + $interval->s;
        return $seconds;
    }
}
Пример #11
0
	<div class="container">	
		<h2 class="title-slim">Vidéos</h2>
		<div id="player-video">
			<?php 
$videos = $cfs->get('musique_video_loop');
if ($videos) {
    $idVideo = get_youtube_id($videos[0]['musique_url_video']);
    echo '<iframe width="100%" height="500" src="https://www.youtube.com/embed/' . $idVideo . '" data-original-url="https://www.youtube.com/embed/" frameborder="0" allowfullscreen></iframe>';
}
?>
		</div><!--#player-video-->
		<div id="player-list">
			
			<?php 
foreach ($videos as $video) {
    $idVideo = get_youtube_id($video['musique_url_video']);
    ?>
					<div class="video wow fadeIn">					
						<a href='#'  data-id-video="<?php 
    echo $idVideo;
    ?>
">
							<div class="overlay">								<span class="glyphicon glyphicon-play"></span>								<div class="overlay-texte"><?php 
    echo $video['nom_chanson'];
    ?>
</div>							</div>							<img src="<?php 
    echo image_src($video['musique_image_video'], "video-thumbnail");
    ?>
" alt=""/>
						</a>
					</div>
Пример #12
0
<?php

$id = get_the_ID();
$youtubeId = get_youtube_id($id);
$videoData = get_video_data($id, $youtubeId);
?>
<div class="video-container" id="playerContainer" data-video-id="<?php 
echo $youtubeId;
?>
">
	<div id="player"></div>
	<section id="playerInfo" class="disabled">
		<h2 class="title"><?php 
get_the_title($id);
?>
</h2>
		<?php 
video_info_html($videoData);
?>
	</section>
	<?php 
get_template_part('social');
?>
</div>
<?php 
social_include();