[EXTENSION] SwfUpload

Hi,

On this topic you can know all about the swfobject extension.

How to use:

Download and decompress all in ‘extensions’ dir.

Usage:




<?php $this->widget('ext.swfobject.ESwfObject', array(

          'width'         => '896',

          'height'        => '703',

          'swfFile'       => Yii::app()->baseUrl . '/swf/home.swf',

          'playerVersion' => '9.0.0',

          'params'        => array('menu' => 'false', 'quality' => 'high', 'wmode' => 'transparent'),

          'flashvars'     => array(),

          'attributes'    => array(),

      )); 

?>



So simple :)

Any admin can change the topic title please?

I type wrong, if SWFOBJECT not SWFUPLOAD .

Ty.

I make the support for EXTENSION DOWNLOAD command.

You can get with console command:

extension install swfobject

You can see how to use this command, here:

http://www.yiiframework.com/forum/index.php?/topic/7129-component-extension/

Nice extension.

Some proposals:

  • Use counter instead of date for id.

  • Use CJavaScript::encode to encode flashvars, params and attributes - it´s much easier and provides javascript parameter / method usage via "js:" (eg. "js:document.URL").




<?php


class ESwfObject extends CWidget

{

  public static $count = 0;


  public $params;

  public $flashvars;

  public $attributes;


  public $swfFile;

  public $width;

  public $height;

  public $playerVersion;


  private $expressInstallFile;

  private $newLineJS;

  private $baseUrl;

  private $clientScript;


  public $randomID;


  /**

   * Init the extension

   */

  public function init()

  {

    $this->randomID  = '_' . self::$count++;

    $this->newLineJS = "\n";


    parent::init();

  }


  /**

   * Publishes the assets

   */

  public function publishAssets()

  {

    $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';

    $this->baseUrl = Yii::app()->getAssetManager()->publish($dir);

  }


  /**

   * Registers the external javascript files

   */

  public function registerClientScripts()

  {

    // add the scripts

    if ($this->baseUrl === '')

    throw new CException(Yii::t('ESwfObject', 'baseUrl must be set. This is done automatically by calling publishAssets()'));


    $this->clientScript = Yii::app()->getClientScript();

    $this->clientScript->registerScriptFile($this->baseUrl.'/swfobject.js');


    // set install express url

    $this->expressInstallFile = $this->baseUrl.'/expressInstall.swf';

  }


  /**

   * The javascript needed

   */

  protected function createJsCode()

  {


    $js  = '';


    // add the flashvars array

    $js .= 'var flashvars' . $this->randomID . ' = ';

    $js .= CJavaScript::encode($this->flashvars);

    $js .= ';' . $this->newLineJS;


    // add the params array

    $js .= 'var params' . $this->randomID . ' = ';

    $js .= CJavaScript::encode($this->params);

    $js .= ';' . $this->newLineJS;


    // add the attributes array

    $js .= 'var attributes' . $this->randomID . ' = ';

    $js .= CJavaScript::encode($this->attributes);

    $js .= ';' . $this->newLineJS;


    // create the swfobject call

    $js .= $this->newLineJS;

    $js .= 'swfobject.embedSWF("' . $this->swfFile . '", "eswfobject_content' . $this->randomID . '", "' . $this->width . '", "' . $this->height . '", "' . $this->playerVersion . '","' . $this->expressInstallFile . '", flashvars' . $this->randomID . ', params' . $this->randomID . ', attributes' . $this->randomID . ');';


    return $js;

  }


  /**

   * The HTML object to receive the SWF OBJECT content

   */

  public function createHtml(){

    $html = '<div id="eswfobject_content' . $this->randomID . '"></div>';

    return $html;

  }


  /**

   * Run the widget

   */

  public function run()

  {

    $this->publishAssets();

    $this->registerClientScripts();


    $js = $this->createJsCode();

    $this->clientScript->registerScript('js_eswfobject' . $this->randomID, $js, CClientScript::POS_HEAD);


    echo( $this->createHtml() );


    parent::run();

  }

}



Happy coding

drx

I have problem when adding more than one flash file into different content id.

For example:




<?php $this->widget('ext.swfobject.ESwfObject', array(

          'width'         => '896',

          'height'        => '703',

          'swfFile'       => Yii::app()->baseUrl . '/swf/home.swf',

          'playerVersion' => '9.0.0',

          'params'        => array('menu' => 'false', 'quality' => 'high', 'wmode' => 'transparent'),

          'flashvars'     => array(),

          'attributes'    => array(),

      )); 

?>



then




<?php $this->widget('ext.swfobject.ESwfObject', array(

          'width'         => '896',

          'height'        => '703',

          'swfFile'       => Yii::app()->baseUrl . '/swf/footer.swf',

          'playerVersion' => '9.0.0',

          'params'        => array('menu' => 'false', 'quality' => 'high', 'wmode' => 'transparent'),

          'flashvars'     => array(),

          'attributes'    => array(),

      )); 

?>



This script override home.swf and just display footer.swf.

Any suggestion in this case? Thanks.

Nevermind, Problem solved when used count :)

how I can to set alternate content? why not use beginWidget/endWidget schema for alternate content?

i have created a $myId attribute and alter init metod to:





    /**

     * Init the extension

     */

    public function init() {

      $this->randomID = '_' . $this->myId . date('YdmHis');

      $this->newLineJS = "\n";


      parent::init();

    }