smarty modifier for FLASH Videos

a handgestrickt customer uses the "Free Video to Flash Converter" for converting his videos to FLV-format. this program also provides a FLASH-file with a very basic player, called player.swf.

this modifier is designed to take a link to an FLV-file and convert it to an HTML-snippet including a FLASH-plugin, with the player.swf, the link as the file-argument and the link-text as the player-title. this modifier is highly configurable.

basically this modifier can also be used for other FLASH-Video-players. only tiny modifications have to be made.

the code:

<?php
function identify_modifier_flvlink2flash () {
        return array (
                'name' => 'flvlink2flash',
                'type' => 'smarty_modifier',
                'nicename' => 'FLV-Link to FLASH',
                'description' => 'Converts a Link to an FLV-Video to a fully FLASH.',
                'authors' => 'Stefan Jelner <info@handgestrickt.biz>',
                'licence' => 'GPL',
                'help' => ''
        );
}

function smarty_modifier_flvlink2flash ($string,$params) {
        $temp = explode(',',trim($params));
        $params = array();
        foreach($temp as $value) {
                $temp2 = explode('=',trim($value));
                $params[trim($temp2[0])] = trim($temp2[1]);
        }
        //default values
        $defaults = array(
                'width' => '320',
                'height' => '200',
                'noembed_img' => 'http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif',
                'noembed_url' => 'http://www.adobe.com/go/getflashplayer',
                'allowScriptAccess' => 'sameDomain',
                'classid' => 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000',
                'codebase' => 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
                'type' => 'application/x-shockwave-flash',
                'pluginspage' => 'http://www.adobe.com/go/getflashplayer',
                'quality' => 'high',
                'wmode' => 'transparent',
                'menu' => 'false',
                'scale' => 'exactfit',
                'player_url' => 'player.swf',
                'player_size' => 'false',
                'player_aplay' => 'false',
                'player_autorev' => 'false'
        );
        //merge parameters with default values
        $params = array_merge($defaults,$params);
        //create FLASH-plugin-template
        $template = sprintf(
                '<!--[if !IE]>-->'.
                '<embed src="%14$s?file=%%1\\$s&size=%15$s&aplay=%16$s&autorev=%17$s&title=%%2\\$s" allowScriptAccess="%5$s" '.
                'type="%8$s" pluginspage="%9$s" quality="%10$s" width="%1$s" height="%2$s" wmode="%11$s" menu="%12$s" />'.
                '<noembed><a href="%4$s" target="_blank"><img src="%3$s" /></a></noembed>'.
                '<!--<![endif]-->'.
                '<!--[if IE]>'.
                '<object classid="%6$s" codebase="%7$s" width="%1$s" height="%2$s">'.
                '<param name="allowScriptAccess" value="%5$s" />'.
                '<param name="movie" value="%14$s?file=%%1\\$s&size=%15$s&aplay=%16$s&autorev=%17$s&title=%%2\\$s" />'.
                '<param name="wmode" value="%11$s" />'.
                '<param name="scale" value="%13$s" />'.
                '<param name="quality" value="%10$s" />'.
                '<param name="menu" value="%12$s" />'.
                '<a href="%4$s" target="_blank"><img src="%3$s" /></a>'.
                '</object>'.
                '<![endif]-->',
                $params['width'],
                $params['height'],
                $params['noembed_img'],
                $params['noembed_url'],
                $params['allowScriptAccess'],
                $params['classid'],
                $params['codebase'],
                $params['type'],
                $params['pluginspage'],
                $params['quality'],
                $params['wmode'],
                $params['menu'],
                $params['scale'],
                $params['player_url'],
                $params['player_size'],
                $params['player_aplay'],
                $params['player_autorev']
        );
        //find and replace link to FLV-files
        $string = preg_replace('/<a[^>]+href=([\\"\\\'])([^\\"\\\']+\\.flv)\\1[^>]*>([^<]*)<\\/a>/sie',"sprintf('$template','$2','$3')",$string);
        return $string;
}
?>

usage:

because smarty does not provide the ability to pass named arguments to modifiers, we have to do it with a string. the syntax is:

"key1=value1,key2=value2,....,keyn=valuen"

example:

{$foo|flvlink2flash:"width=450,height=338"}
{$foo|flvlink2flash:"width=450,height=338,menu=true"}

parameters:

  • width
  • height
  • noembed_img
  • noembed_url
  • allowScriptAccess
  • classid
  • codebase
  • type
  • pluginspage
  • quality
  • wmode
  • menu
  • scale
  • player_url
  • player_size
  • player_aplay
  • player_autorev

Friday, 24. August 2007 • trackback url

Add Comment

( to reply to a comment, click the reply link next to the comment )

Comment Title:
Your Name:
Email Address:
Make Public?
Website:
Make Public?

Comment:


Allowed XHTML tags : a, b, i, strong, code, acrynom, blockquote, abbr. Linebreaks will be converted automatically.


Captcha:

captcha image

please type the content of the above image into the following form-field: