Skip to content

Instantly share code, notes, and snippets.

@collegeman
Created November 12, 2011 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save collegeman/1361275 to your computer and use it in GitHub Desktop.
Save collegeman/1361275 to your computer and use it in GitHub Desktop.
Squidmags video player
<?php
$vids_config = array(
'http://youtube.com/?v=whatever This is my first title',
'http://youtube.com/?v=whatever This is my second title',
'http://youtube.com/?v=whatever This is my third title
);
foreach($vids_config as $vid) {
$parts = explode(' ', $vid);
$url = array_shift($parts);
$title = implode(' ', $parts);
parse_str(parse_url($url, PHP_URL_QUERY), $params);
$vids[] = (object) array(
'url' => $url,
'title' => $title,
'id' => $params['v']
);
}
if (!$vids) {
return false;
}
?>
<div id="sponsor_vids">
<div id="sponsor_featured_vid">
<?php $vid = array_shift($vids); ?>
<iframe width="445" height="280" src="http://www.youtube.com/embed/<?php echo $vid->id ?>?rel=0" frameborder="0" allowfullscreen></iframe>
</div><!-- #sponsor_featured_vid -->
<div id="sponsor_thumbs">
<ul>
<?php $rand = array_rand($vids, count($vids)); foreach(array_slice($rand, 0, 3) as $i) { $vid = $vids[$i]; ?>
<li class="button">
<a href="<?php echo esc_attr($vid->url) ?>">
<img src="http://i.ytimg.com/vi/<?php echo esc_attr($vid->id) ?>/2.jpg" alt="<?php echo esc_attr($vid->title) ?>" title="<?php echo esc_attr($vid->title) ?>" />
</a>
</li>
<?php } ?>
</ul>
</div><!-- #sponsor_thumbs -->
</div><!-- #sponsor_vids -->
<script>
(function($) {
var iframe = function(href) {
var query_string = href.split('?')[1];
var params = query_string.split('&');
for (var i=0; i<params.length; i++) {
var param = params[i];
if (param.substring(0, 2) == 'v=') {
var id = param.substring(2);
return '<iframe width="445" height="280" src="http://www.youtube.com/embed/'+id+'?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>';
}
}
};
$('.button').click(function() {
$('#sponsor_featured_vid').html(iframe($(this).find('a').attr('href')));
return false;
});
})(jQuery);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment