From 55c4ac1bfe565f1ca7f537fdd8b7a201be28e581 Mon Sep 17 00:00:00 2001 From: xue <> Date: Thu, 10 Nov 2005 12:47:19 +0000 Subject: Initial import of prado framework --- framework/Web/UI/TTheme.php | 64 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 framework/Web/UI/TTheme.php (limited to 'framework/Web/UI/TTheme.php') diff --git a/framework/Web/UI/TTheme.php b/framework/Web/UI/TTheme.php new file mode 100644 index 00000000..1e3d8fab --- /dev/null +++ b/framework/Web/UI/TTheme.php @@ -0,0 +1,64 @@ +_themePath=$name; + $this->initialize(); + } + + private function initialize() + { + if(($theme=opendir($this->_themePath))===false) + throw new Exception("Invalid theme ".$this->_themePath); + while(($file=readdir($theme))!==false) + { + if(basename($file,'.skin')!==$file) + $this->parseSkinFile($this->_themePath.'/'.$file); + } + closedir($theme); + } + + private function parseSkinFile($fileName) + { + if(($skin=simplexml_load_file($fileName))===false) + throw new Exception("Parsing $fileName failed."); + foreach($skin->children() as $type=>$control) + { + $attributes=array(); + foreach($control->attributes() as $name=>$value) + { + $attributes[strtolower($name)]=(string)$value; + } + $skinID=isset($attributes['skinid'])?(string)$attributes['skinid']:0; + unset($attributes['skinid']); + if(isset($this->_skins[$type][$skinID])) + throw new Exception("Duplicated skin $type.$skinID"); + else + $this->_skins[$type][$skinID]=$attributes; + } + } + + public function applySkin($control) + { + $type=get_class($control); + if(($id=$control->getSkinID())==='') + $id=0; + if(isset($this->_skins[$type][$id])) + { + foreach($this->_skins[$type][$id] as $name=>$value) + { + $control->setPropertyByPath($name,$value); + } + } + else + return; + } +} + + +?> \ No newline at end of file -- cgit v1.2.3