Vimeo Helper

By Jonny Reeves (jreeves)
Short and Simple helper to assist with embedding Vimeo.com videos in your CakePHP Projects.
Not much to say, once you have included this helper in your controller, var $helpers = array('Vimeo');, simply call it in your view with:

Download code
<?php echo $vimeo->getEmbedHtml('http://www.vimeo.com/{vimeo_id}', array()); ?>

Please view the code below to get a complete list options which are passed via the second argument.

Download code
<?php
class VimeoHelper extends AppHelper
{
    
/**
     * Creates Vimeo Embed Code from a given Vimeo Video.
     *
     *    @param String $vimeo_id URL or ID of Video on Vimeo.com
     *    @param Array $usr_options VimeoHelper Options Array (see below)
     *    @return String HTML output.
    */
    
function getEmbedCode($vimeo_id$usr_options = array())
    {
        
// Default options.
        
$options = array
        (
            
'width' => 400,
            
'height' => 225,
            
'show_title' => 1,
            
'show_byline' => 1,
            
'show_portrait' => 0,
            
'color' => '00adef',
        );
        
$options array_merge($options$usr_options);
        
        
// Extract Vimeo.id from URL.
        
if (substr($vimeo_id021) == 'http://www.vimeo.com/') {
            
$vimeo_id substr($vimeo_id21);
        }
        
        
$output = array();
        
$output[] = sprintf('<object width="%s" height="%s">'$options['width'], $options['height']);
        
$output[] = ' <param name="allowfullscreen" value="true" />';
        
$output[] =    ' <param name="allowscriptaccess" value="always" />';
        
$output[] =    sprintf(' <param name="movie" value="http://www.vimeo.com/moogaloop.swf?clip_id=%s&server=www.vimeo.com&show_title=%s&show_byline=%s&show_portrait=%s&color=%s&fullscreen=1" />'$vimeo_id$options['show_title'], $options['show_byline'], $options['show_portrait'], $options['color']);
        
$output[] = sprintf(' <embed src="http://www.vimeo.com/moogaloop.swf?clip_id=%s&server=www.vimeo.com&show_title=%s&show_byline=%s&show_portrait=%s&color=%s&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="%s" height="%s"></embed>'$vimeo_id$options['show_title'], $options['show_byline'], $options['show_portrait'], $options['color'], $options['width'], $options['height']);
        
$output[] = '</object>';
        
        return 
$this->output(implode($output"\n"));
    }
}
?>

 

Comments 690

CakePHP Team Comments Author Comments
 

Comment

1 Just a small typo

Should be "var $helpers" in your intro, not "var $components" :)
Posted Jun 11, 2008 by Grant Cox.
 

Comment

2 Ooops

Should be "var $helpers" in your intro, not "var $components" :)
Thanks for noticing that Grant, change has been made to the intro text!
Posted Jun 15, 2008 by Jonny Reeves