Last active
August 29, 2015 14:06
-
-
Save hugosolar/c94307ae225812492761 to your computer and use it in GitHub Desktop.
Class Videos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class videos { | |
/* function get_video | |
* Extract and return video id from youtbe & vimeo videos | |
* @param url : Video url | |
*/ | |
static function get_video($url,$width=560,$height=315) { | |
if (strstr($url,'youtube')){ | |
$parse_url=parse_url($url); | |
parse_str($parse_url['query']); | |
$id=$v; | |
$iframe='<iframe width="'.$width.'" height="'.$height.'" src="http://www.youtube.com/embed/'.$id.'" frameborder="0" allowfullscreen></iframe>'; | |
return $iframe; | |
} | |
if (strstr($url,'vimeo')) { | |
if (!empty($url)) { | |
$id=array_pop(explode('/',$url)); | |
$iframe='<iframe src="http://player.vimeo.com/video/'.$id.'?title=0&byline=0&portrait=0" width="'.$width.'" height="'.$height.'" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; | |
return $iframe; | |
} | |
} | |
return false; | |
} | |
static function render_video_button($video,$active=false) { | |
$active_class = ($active) ? ' active' : ''; | |
$url = get_post_meta($video->ID,'_video_url',true); | |
echo '<figure class="hentry entry-video clearfix'.$active_class.'">'; | |
echo '<a href="'.$url.'">'; | |
echo '<img src="'.self::get_video_thumb($url,'big').'" alt="'.$video->post_title.'">'; | |
echo '<div class="video-info">'; | |
echo '<h4 class="entry-title">'.$video->post_title.'</h4>'; | |
if (!empty($video->post_content)) { | |
echo '<div class="entry-description">'; | |
echo apply_filters( 'the_content', $video->post_content ); | |
echo '</div>'; | |
} | |
echo '</div>'; | |
echo '</a>'; | |
echo '</figure>'; | |
} | |
static function get_video_class($url) { | |
if (strstr($url,'youtube')){ | |
return 'youtube-lightbox'; | |
} | |
if (strstr($url,'vimeo')){ | |
return 'vimeo-lightbox'; | |
} | |
} | |
/** | |
* function get_video_thumb | |
* Extract and return video id from youtbe & vimeo videos | |
* @param url : Video url | |
* @param size: small, medium | |
*/ | |
static function get_video_thumb($url,$size) { | |
if (strstr($url,'youtube')){ | |
$parse_url=parse_url($url); | |
parse_str($parse_url['query']); | |
$id=$v; | |
$def_size = ($size=='small')?1:0; | |
$thumb='http://img.youtube.com/vi/'.$id.'/'.$def_size.'.jpg'; | |
return $thumb; | |
} | |
if (strstr($url,'vimeo')) { | |
$thumb = ''; | |
if (!empty($url)) { | |
if ( false === ( $thumb = get_transient( 'vimeo_'.$id ) ) ) { | |
$id=array_pop(explode('/',$url)); | |
$request = new WP_Http; | |
$result = $request->request( 'http://vimeo.com/api/v2/video/'.$id.'.php' , $args ); | |
//$iframe='<iframe src="http://player.vimeo.com/video/'.$id.'?title=0&byline=0&portrait=0" width="'.$width.'" height="'.$height.'" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; | |
if (!is_wp_error( $result )) { | |
$body = maybe_unserialize($result['body']); | |
$thumb = $body[0]['thumbnail_large']; | |
set_transient('vimeo_'.$id,$thumb,60*60*24); | |
} | |
} | |
return $thumb; | |
} | |
} | |
return false; | |
} | |
static function get_last_videos($size=3) { | |
$video = query_posts(array( | |
'post_type' => 'videos', | |
'posts_per_page' => $size, | |
'orderby' => 'date', | |
'order' => 'DESC' | |
)); | |
return $video; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment