swfobject

Swfobject - PHP class for creating dynamic content of SWFObject V2.1.

Defined (1)

The class is defined in the following location(s).

/lib/swfobject.php  
  1. class swfobject { 
  2. /** 
  3. * id of the HTML element 
  4. * @var string 
  5. */ 
  6. var $id; 
  7. /** 
  8. * specifies the width of your SWF 
  9. * @var string 
  10. * @private 
  11. */ 
  12. var $width; 
  13. /** 
  14. * specifies the height of your SWF 
  15. * @var string 
  16. * @privat 
  17. */ 
  18. var $height; 
  19. /** 
  20. * the javascript output 
  21. * @var string 
  22. */ 
  23. var $js; 
  24. /** 
  25. * the replacemnt message 
  26. * @var string 
  27. */ 
  28. var $message = 'The <a href="http://www.macromedia.com/go/getflashplayer">Flash Player</a> and <a href="http://www.mozilla.com/firefox/">a browser with Javascript support</a> are needed..';  
  29. /** 
  30. * the classname for the div element 
  31. * @var string 
  32. */ 
  33. var $classname = 'swfobject';  
  34. /** 
  35. * array of flashvars 
  36. * @var array 
  37. */ 
  38. var $flashvars; 
  39. /** 
  40. * array of nested object element params 
  41. * @var array 
  42. */ 
  43. var $params; 
  44. /** 
  45. * array of object's attributest 
  46. * @var array 
  47. */ 
  48. var $attributes; 
  49.  
  50. /** 
  51. * swfobject::swfobject() 
  52. *  
  53. * @param string $swfUrl (required) specifies the URL of your SWF 
  54. * @param string $id (required) specifies the id of the HTML element (containing your alternative content) you would like to have replaced by your Flash content 
  55. * @param string $width (required) specifies the width of your SWF 
  56. * @param string $height (required) specifies the height of your SWF 
  57. * @param string $version (required) specifies the Flash player version your SWF is published for (format is: "major.minor.release") 
  58. * @param string $expressInstallSwfurl (optional) specifies the URL of your express install SWF and activates Adobe express install 
  59. * @param array $flashvars (optional) specifies your flashvars with name:value pairs 
  60. * @param array $params (optional) specifies your nested object element params with name:value pair 
  61. * @param array $attributes (optional) specifies your object's attributes with name:value pairs 
  62. * @return string the content 
  63. */ 
  64. function swfobject( $swfUrl, $id, $width, $height, $version, $expressInstallSwfurl = false, $flashvars = false, $params = false, $attributes = false ) { 
  65.  
  66. global $swfCounter; 
  67.  
  68. // look for a other swfobject instance 
  69. if ( !isset($swfCounter) ) 
  70. $swfCounter = 1; 
  71.  
  72. $this->id = $id . '_' . $swfCounter; 
  73. $this->width = $width; 
  74. $this->height = $height;  
  75.  
  76. $this->flashvars = ( is_array($flashvars) ) ? $flashvars : array(); 
  77. $this->params = ( is_array($params) ) ? $params : array(); 
  78. $this->attributes = ( is_array($attributes) ) ? $attributes : array(); 
  79.  
  80. $this->embedSWF = 'swfobject.embedSWF("'. $swfUrl .'", "'. $this->id .'", "'. $width .'", "'. $height .'", "'. $version .'", '. $expressInstallSwfurl .', this.flashvars, this.params , this.attr );' . "\n"; 
  81.  
  82. function output () { 
  83.  
  84. global $swfCounter; 
  85.  
  86. // count up if we have more than one swfobject 
  87. $swfCounter++; 
  88.  
  89. $out = "\n" . '<div class="'. $this->classname .'" id="'. $this->id .'" style="width:'.$this->width .'px; height:'. $this->height .'px;">'; 
  90. $out .= "\n" . $this->message; 
  91. $out .= "\n" . '</div>'; 
  92.  
  93. return $out; 
  94.  
  95. function javascript () { 
  96.  
  97. //Build javascript 
  98. $this->js = "\nvar " . $this->id . " = {\n"; 
  99. $this->js .= $this->add_js_parameters('params', $this->params) . ", \n"; 
  100. $this->js .= $this->add_js_parameters('flashvars', $this->flashvars) . ", \n"; 
  101. $this->js .= $this->add_js_parameters('attr', $this->attributes) . ", \n"; 
  102. $this->js .= "\tstart : function() {" . "\n\t\t"; 
  103. $this->js .= $this->embedSWF; 
  104. $this->js .= "\t}\n}\n"; 
  105. $this->js .= $this->id . '.start();'; 
  106.  
  107. return $this->js; 
  108.  
  109. function add_flashvars ( $key, $value, $default = '', $type = '', $prefix = '' ) { 
  110.  
  111. if ( is_bool( $value ) ) 
  112. $value = ( $value ) ? 'true' : 'false'; 
  113. elseif ( $type == 'bool' ) 
  114. $value = ( $value == '1' ) ? 'true' : 'false'; 
  115.  
  116. // do not add the variable if we hit the default setting  
  117. if ( $value == $default )  
  118. return; 
  119.  
  120. $this->flashvars[$key] = $prefix . $value; 
  121. return; 
  122.  
  123. function add_params ( $key, $value, $default = '', $type = '', $prefix = '' ) { 
  124.  
  125. if ( is_bool( $value ) ) 
  126. $value = ( $value ) ? 'true' : 'false'; 
  127. elseif ( $type == 'bool' ) 
  128. $value = ( $value == '1' ) ? 'true' : 'false'; 
  129.  
  130. // do not add the variable if we hit the default setting  
  131. if ( $value == $default )  
  132. return; 
  133.  
  134. $this->params[$key] = $prefix . $value; 
  135. return; 
  136.  
  137. function add_attributes ( $key, $value, $default = '', $type = '', $prefix = '' ) { 
  138.  
  139. if ( is_bool( $value ) ) 
  140. $value = ( $value ) ? 'true' : 'false'; 
  141. elseif ( $type == 'bool' ) 
  142. $value = ( $value == '1' ) ? 'true' : 'false'; 
  143.  
  144. // do not add the variable if we hit the default setting  
  145. if ( $value == $default )  
  146. return; 
  147.  
  148. $this->attributes[$key] = $prefix . $value; 
  149. return; 
  150.  
  151. function add_js_parameters( $name, $params ) { 
  152. $list = ''; 
  153. if ( is_array($params) ) { 
  154. foreach ($params as $key => $value) { 
  155. if ( !empty($list) ) 
  156. $list .= ", "; 
  157. if (false === strrpos($key, '.') )  
  158. $list .= "\n\t\t" . $key . ' : ' . '"' . $value .'"'; 
  159. else 
  160. $list .= "\n\t\t'" . $key . '\' : ' . '"' . $value .'"';  
  161. $js = "\t" . $name . ' : {' . $list . '}';  
  162. return $js;  
  163.