Location: PHPKode > scripts > GOOX_SWFOBJECT > goox_swfobject/class/goox_swfobject_class.php
<?


/**
* GOOX_SWFOBJECT 
* @package SWF
* @author Otavio Theiss - hide@address.com
* @copyright 04/06/2008
*/
class GOOX_SWFOBJECT {

	/**
	 * monta o javascript e a div que será carregado o swf.
	 * @param array
	 * @access public	 
	 * @return mixed
	 */
	public function getSWFOBJECT($swf,$id,$w,$h,$flashvars='',$flashparams='',$flashattributes='') {
		
		global $path_url;
	
		$obj  = '<script type="text/javascript">'."\n\t";
		$obj .=	$this->setFlashVars($flashvars);
		$obj .=	$this->setFlashParam($flashparams);
		$obj .=	$this->setFlashAttributes($flashattributes);
		$obj .=	'swfobject.embedSWF("'.$path_url.$swf.'", "'.$id.'", "'.$w.'","'.$h.'", "9.0.0", false, flashvars, params, attributes);'."\n";
		$obj .= '</script>'."\n\t";
		$obj .= $this->getContainer($id);
	
		return $obj;	
	}
	
	/**
	 * monta o javascript com as variaveis do swfobject conhecidas como flashvars.
	 * @param array
	 * @access private	 
	 * @return mixed
	 */
	private function setFlashVars($flashvars=''){
		$vars  = 'var flashvars = {};'."\n\t";
		if(is_array($flashvars)){
			foreach($flashvars as $key => $value){
				$vars .= 'flashvars.'.$key.' = "'.$value.'";'."\n\t";
			}
		}
		return $vars;
	}

	/**
	 * monta o javascript com os parametros do swfobject conhecidas como params.
	 * @param array
	 * @access private	 
	 * @return mixed
	 */
	private function setFlashParam($flashparams=''){
		$params = 'var params = {};'."\n\t";
		if(is_array($flashparams)){
			foreach($flashparams as $key => $value){
				$params .= 'params.'.$key.' = "'.$value.'";'."\n\t";
			}
		}else{
			$params .= 'params.menu = "false";'."\n\t";
			$params .= 'params.quality = "high";'."\n\t";
      $params .= 'params.wmode = "transparent";'."\n\t";
      $params .= 'params.allowfullscreen = "true";'."\n\t";
		}
		
		return $params;
	}
	
	/**
	 * monta o javascript com os Attributos do swfobject caso exista algum.
	 * @param array
	 * @access private
	 * @return mixed
	 */
	private function setFlashAttributes($flashattributes=''){
		$attributes  = 'var attributes = {};'."\n\t";
		if(is_array($flashattributes)){
			foreach($flashattributes as $key => $value){
				$attributes .= 'attributes.'.$key.' = "'.$value.'";'."\n\t";
			}
		}
		return $attributes;
	}	
	
	/**
	 * monta a div que será carregado o swf.
	 * @param string
	 * @access private	 
	 * @return mixed
	 */
	private function getContainer($id) {
		global $path_url;
		$container  = '<div id="'.$id.'">'."\n\t";
		$container .= '<a href="http://www.adobe.com/go/getflashplayer">'."\n\t";
		$container .= '<img src="'.$path_url.'images/get_flash_player.gif" alt="Get Adobe Flash player" border="0"><br />'."\n\t";
		$container .= 'Você precisa do Flash Player.<br /> Clique na imagem para fazer o download.'."\n\t";
		$container .= '</a>'."\n\t";
		$container .= '</div>'."\n\t";

		return $container;	
	}
	
}

?>
Return current item: GOOX_SWFOBJECT