Location: PHPKode > scripts > QSWFObject > qswfobject/QSWFObject.fluent.interface.php
class QSWFObject {

	const version = "0.2";

	protected $rootNode = 'div';
	protected $swfObjectDivId = 'flashContent';
	protected $swfObjectScriptBase = 'js/swfobject.js';
	protected $config;
	protected $object;
	protected $properties;
	protected $useSWFObject = false;
	protected $useSWFObjectScript = false;

	public function __construct($useSwfObject = true, $useSwfObjectScript = true, $classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000', $codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'){
		if(!is_object($this->object) && !$this->object instanceof SimpleXMLElement){
			$xml = '<?xml version="1.0" encoding="UTF-8"?><'.$this->rootNode.'></'.$this->rootNode.'>';
			$this->object = new SimpleXMLElement($xml);
				
			$this->properties['classid'] = $classid;
			$this->properties['codebase'] = $codebase;
			
			if($useSwfObject){
				$this->useSWFObject();
			}
			if($useSwfObjectScript){
				$this->useSWFObjectScript();
			}
			
		}
	}
	
	public function setFlashId($id){
		$this->swfObjectDivId = (string) $id;
		return $this;
	}
	public function setSWFObjectScript($file){
		$this->swfObjectScriptBase = (string) $file;
		return $this;
	}
	
	public function init(){
		if($this->useSWFObject){
			$this->initNoScript();
		} else {
			$this->initObject();			
		}
		return $this;
	}

	public function addConfig($config){
		$this->config = $config;
		$this->init();
		return $this;
	}
	
	protected function renderSWFObject(){
		$array = array();
		if($this->config){
			$array[] = 'var so=new SWFObject("'.($this->config["path"]?$this->config["path"].'/open-flash-chart.swf':"").'","'.(($this->config["id"]?$this->config["id"]:"")).'","'.(($this->config["width"]?$this->config["width"]:"")).'","'.(($this->config["height"]?$this->config["height"]:"")).'","'.(($this->config["version"]?$this->config["version"]:"9")).'","'.(($this->config["bgcolor"]?$this->config["bgcolor"]:"#fffff")).'");';
			$array[] = 'so.addVariable("data","'.(($this->config["url"]?$this->config["url"]:"")).'");';
			$array[] = 'so.addVariable("allowScriptAccess","sameDomain");';
			$array[] = 'so.write("'.$this->swfObjectDivId.'");';
			return "\n".implode("\n", $array)."\n";
		} else {
			echo "Config Data is missing.";
		}
		
	}
	
	protected function initSWFObject(){
		$swfobject = $this->get();
		$div = $swfobject->addChild("div");
		$div->addAttribute('id', $this->swfObjectDivId);
		
		if($this->useSWFObjectScript){
			$script = $swfobject->addChild("script");
			$script->addAttribute("type", "text/javascript");
			$script->addAttribute("src", $this->config["path"].'/js/swfobject.js');
		}
		
		$script2 = $swfobject->addChild("script", $this->renderSWFObject());
		$script2->addAttribute("type", "text/javascript");
	}
	
	protected function initNoScript(){
		$swfobject = $this->get();
		
		$this->initSWFObject();
		
		$noscript = $swfobject->addChild("noscript");
		$object = $noscript->addChild("object");
		foreach($this->properties as $name => $value){
			$object->addAttribute($name, $value);
		}
	}
	
	protected function initObject(){
		$swfobject = $this->get();
		$object = $swfobject->addChild("object");
		foreach($this->properties as $name => $value){
			$object->addAttribute($name, $value);
		}
	}

	public function useSWFObject(){
		$this->useSWFObject = true;
		return $this;
	}

	public function useSWFObjectScript(){
		$this->useSWFObjectScript = true;
		return $this;
	}

	public function get(){
		return $this->object;
	}

	public function addAttributes($array){
		foreach($array as $name => $value){
			$this->setAttribute($name, $value);
		}
		return $this;
	}

	public function setAttribute($name, $value){
		$this->object->addAttribute($name, $value);
		return $this;
	}

	public function setParam($array){
		$this->setNode("param", $array);
		return $this;
	}

	public function setEmbed($array){
		$this->setNode("embed", $array);
		return $this;
	}

	protected function setNode($type, $array){
		if($this->useSWFObject){
			$$type = $this->get()->noscript->object->addChild($type);			
		} else {
			$$type = $this->get()->object->addChild($type);
		}
		foreach($array as $name => $value){
			$$type->addAttribute($name, $value);
		}
	}

	protected function getRootNode(){
		return $this->rootNode;
	}

	public function render(){		
		$domnode = dom_import_simplexml($this->get());
		$dom = new DomDocument();
		$domnode = $dom->importNode($domnode, true);
		$dom->appendChild($domnode);
		echo $dom->saveHTML();
	}
}

?>
Return current item: QSWFObject