12.07 php saved
gwoo
Tags add more
Helper, flash and swfobject  
Note
Latest swf object helper, check __baseOptions for the default usage.
  1. <?php
  2. /* SVN FILE: $Id: swfobject.php 16 2006-12-04 07:51:37Z gwoo $ */
  3.  
  4. /**
  5. * Short description for file.
  6. *
  7. * Long description here...
  8. *
  9. * PHP versions 4 and 5
  10. *
  11. * TBD
  12. * Copyright (c)    2006, Cake Software Foundation, Inc.
  13. *                1785 E. Sahara Avenue, Suite 490-204
  14. *                Las Vegas, Nevada 89104
  15. *
  16. * Licensed under The MIT License
  17. * Redistributions of files must retain the above copyright notice.
  18. *
  19. * @filesource
  20. * @copyright      Copyright (c) 2006, Cake Software Foundation, Inc.
  21. * @link                TBD
  22. * @package   TBD
  23. * @subpackage    TBD.views.helpers
  24. * @since         TBD
  25. * @version   $Revision: 16 $
  26. * @modifiedby    $LastChangedBy: gwoo $
  27. * @lastmodified    $Date: 2006-12-03 23:51:37 -0800 (Sun, 03 Dec 2006) $
  28. * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
  29. */
  30.  
  31. /**
  32. * Short description for class.
  33. *
  34. * Long description for class..
  35. *
  36. * @brief Class wrapper for the SWFObject.
  37. * @dependencies SWFObject v1.4.2: Flash Player detection and embed - http://blog.deconcept.com/swfobject/  put the js file in app/webroot/js/
  38. * @package  TBD
  39. * @subpackage  TBD.views.helpers
  40. * @brief Class wrapper for the SWFObject.
  41. * @dependencies SWFObject v1.4.2: Flash Player detection and embed - http://blog.deconcept.com/swfobject/  put the js file in app/webroot/js/
  42. *
  43. */
  44. class SwfobjectHelper extends Helper  {
  45. /**
  46. * The name of the message div
  47. *
  48. * @var string
  49. */
  50.     var $div = 'flashcontent';
  51.  
  52. /**
  53. * the message to display when the user needs to upgrade
  54. *
  55. * @var string
  56. */ 
  57.     var $message = '<strong>You need to upgrade your Flash Player</strong>
  58.                     This is replaced by the Flash content. Place your alternate content here
  59.                     and users without the Flash plugin or with Javascript turned off will see
  60.                     this. Content here allows you to leave out <code>noscript</code> tags.';
  61.    
  62.    
  63. /**
  64. * Flash vars. addVariable
  65. *
  66. * @var array
  67. */
  68.     var $__flashvars = array();
  69. /**
  70. * Swfobject params. addParam
  71. *
  72. * @var array
  73. */
  74.     var $__swfparams = array();
  75. /**
  76. * Attributes. addAttribute
  77. *
  78. * @var unknown_type
  79. */
  80.     var $__attributes = array();
  81.    
  82. /**
  83. * Enter description here...
  84. *
  85. * @var unknown_type
  86. */
  87.     var $__baseOptions = array('name' => 'movie', 'width' => '400', 'height' => '400',
  88.                                 'version' => '9', 'bgColor' => '#fff', 'express' => true)
  89.    
  90.    
  91. /**
  92. * Enter description here...
  93. *
  94. * @param string $path
  95. * @param array $options defaults to __baseConfig
  96. * @return formatted js code for
  97. */
  98.     function display($path, $options = array()) {
  99.        
  100.         $options = am($this->__baseOptions, $options);
  101.        
  102.         if($this->__debug) {
  103.            
  104.         }
  105.        
  106.         $out = '
  107.             <div id="'.$this->div.'">
  108.                 '.$this->message.'
  109.             </div>
  110.                 ';
  111.         $out .= '<script type="text/javascript">
  112.                     // <![CDATA[
  113.                     ';
  114.         $out .= 'var so = new SWFObject("'.str_replace('//', '/', $this->webroot.$path).'", "'.join('","', $options).'");';
  115.  
  116.         foreach ($this->__flashvars as $flashvar => $flashvarValue) {
  117.             $out .= 'so.addVariable("'.$flashvar.'", "'.$flashvarValue.'");';
  118.         }
  119.  
  120.         foreach ($this->__swfparams as $swfparam => $swfparamValue) {
  121.             $out .= 'so.addParam("'.$swfparam.'", "'.$swfparamValue.'");';
  122.         }
  123.  
  124.         foreach ($this->__attributes as $attr => $attrValue) {
  125.             $out .= 'so.setAttibute("'.$attr.'", "'.$attrValue.'");';
  126.         }
  127.  
  128.         $out .= 'so.write("'.$this->div.'");';
  129.         $out .='
  130.                 // ]]>
  131.                 </script>
  132.                 ';
  133.         return $out;
  134.     }
  135. /**
  136. * Enter description here...
  137. *
  138. * @param unknown_type $var
  139. * @param unknown_type $value
  140. */
  141.     function addFlashvar($var, $value = null) {
  142.         if(is_array($var)) {
  143.             $this->__flashvars = am($var, $this->__flashvars)
  144.         } else if($value !== null) {
  145.             $this->__flashvars[$var] = $value;
  146.         }
  147.     }
  148. /**
  149. * Enter description here...
  150. *
  151. * @param unknown_type $var
  152. * @param unknown_type $value
  153. */
  154.     function addParam($var, $value) {
  155.         if(is_array($var)) {
  156.             $this->__swfparams = am($var, $this->__swfparams)
  157.         } else if($value !== null) {
  158.             $this->__swfparams[$var] = $value;
  159.         }
  160.     }
  161. /**
  162. * Enter description here...
  163. *
  164. * @param unknown_type $var
  165. * @param unknown_type $value
  166. */
  167.     function addAttribute($var, $value) {
  168.         if(is_array($var)) {
  169.             $this->__attributes = am($var, $this->__attributes);   
  170.         } else if($value !== null) {
  171.             $this->__attributes[$var] = $value;
  172.         }
  173.     }
  174. /**
  175. * Enter description here...
  176. *
  177. * @param unknown_type $var
  178. * @param unknown_type $value
  179. */
  180.     function debug($value = null) {
  181.         if(!is_null($value)) {
  182.             return $this->__debug = $value;
  183.         } else {
  184.             $this->__debug = Configure::read();
  185.         }
  186.     }
  187.    
  188. }
  189. ?>
Parsed in 0.117 seconds, using GeSHi 1.0.7.14

Modify this Paste