![]() |
|
Snippets |
|
Simple helper for embeding flash objects using Unobtrusive Flash Objects (UFO). Download and install ufo.js to js/ufo.js and place your movies (*.swf) to web/swf, FlashHelper.php in your lib/helper directory.
<div id="flashcontent"> This text is replaced by the Flash movie. </div> <?php use_helper('Flash'); ?> <?php echo flash_object('flashcontent', array( 'movie'=>'movie.swf', 'width'=>'200', 'height'=>'300', 'bgcolor'=> '#FFFFFF'); ?>
<?php /** * Flash object helper - embeds Flash objects (files with the .swf extension) * * Uses Unobtrusive Flash Objects (UFO) * * @param string $id - The ID od the div which will be replaced by flash movie * @param mixed $options - Flash object options * @see http://www.bobbyvandersluis.com/ufo/ */ function flash_object($id, $options = array()) { sfContext::getInstance()->getResponse()->addJavascript('ufo.js'); $options = _parse_attributes($options); $absolute = false; if (isset($options['absolute'])) { unset($options['absolute']); $absolute = true; } if(isset($options['size'])) { list($options['width'], $options['height']) = split('x', $options['size'], 2); unset($options['size']); } if(!isset($options['majorversion'])) { $options['majorversion'] = 7; } if(!isset($options['build'])) { $options['build'] = 0; } // check for all required params foreach(array('movie', 'width', 'height', 'majorversion', 'build') as $required) { if(!isset($options[$required])) { throw new sfException("{FlashHelper} Required parameter \"$required\" is missing."); } } $options['movie'] = flash_path($options['movie'], $absolute); $opts = array(); foreach ($options as $key => $value) { $opts[] = $key . ': "' . $value . '"'; } sort($opts); // javascript variable name $name = $id . '_var'; $js = 'var ' . $name . " = {".join(', ', $opts)."};\n"; $js .= 'UFO.create('.$name.', "'.$id.'");'."\n"; return content_tag('script', "\n//".cdata_section("\n$js\n//")."\n", array('type' => 'text/javascript')); } /** * Returns the path to a flash swf movie. * * <b>Example:</b> * <code> * echo flash_path('mymovie'); * => /swf/mymovie.swf * </code> * * <b>Note:</b> The asset name can be supplied as a... * - full path, like "/swf/movie.swf" * - file name, like "movie.swf", that gets expanded to "/swf/movie.swf" * - file name without extension, like "movie", that gets expanded to "/swf/movie.css" * * @param string asset name * @param bool return absolute path ? * @return string file path to the flash movie file */ function flash_path($source, $absolute = false) { return _compute_public_path($source, 'swf', 'swf', $absolute); }