<?phpdefine('DWOO_DIRECTORY',dirname(__FILE__).DIRECTORY_SEPARATOR);if(defined('DWOO_CACHE_DIRECTORY'))thrownewDwoo_Exception('DWOO_CACHE_DIRECTORY is deprecated, you should now set this in Dwoo\'s constructor using new Dwoo([ $compileDir [, $cacheDir ]])');if(defined('DWOO_COMPILE_DIRECTORY'))thrownewDwoo_Exception('DWOO_COMPILE_DIRECTORY is deprecated, you should now set this in Dwoo\'s constructor using new Dwoo([ $compileDir [, $cacheDir ]])');if(defined('DWOO_CHMOD')){thrownewDwoo_Exception('DWOO_CHMOD is deprecated, you should now set this on your template object using $tpl->setChmod('.DWOO_CHMOD.');');}classDwoo{constVERSION="1.0.0beta";constRELEASE_TAG=13;constCLASS_PLUGIN=1;constFUNC_PLUGIN=2;constNATIVE_PLUGIN=4;constBLOCK_PLUGIN=8;constCOMPILABLE_PLUGIN=16;constCUSTOM_PLUGIN=32;constSMARTY_MODIFIER=64;constSMARTY_BLOCK=128;constSMARTY_FUNCTION=256;constPROXY_PLUGIN=512;protected$charset='utf-8';protected$globals;protected$compileDir;protected$cacheDir;protected$cacheTime=0;protected$securityPolicy=null;protected$plugins=array();protected$filters=array();protected$resources=array('file'=>array('class'=>'Dwoo_Template_File','compiler'=>null),'string'=>array('class'=>'Dwoo_Template_String','compiler'=>null));protected$loader=null;protected$template=null;protected$runtimePlugins;protected$data;protected$scope;protected$scopeTree;protected$stack;protected$curBlock;protected$buffer;protected$pluginProxy;publicfunction__construct($compileDir=null,$cacheDir=null){if($compileDir!==null){$this->setCompileDir($compileDir);}if($cacheDir!==null){$this->setCacheDir($cacheDir);}}publicfunction__clone(){$this->template=null;}publicfunctionoutput($tpl,$data=array(),Dwoo_ICompiler$compiler=null){return$this->get($tpl,$data,$compiler,true);}publicfunctionget($_tpl,$data=array(),$_compiler=null,$_output=false){if($this->templateinstanceofDwoo_ITemplate){$proxy=clone$this;return$proxy->get($_tpl,$data,$_compiler,$_output);}if($_tplinstanceofDwoo_ITemplate){}elseif(is_string($_tpl)&&file_exists($_tpl)){$_tpl=newDwoo_Template_File($_tpl);}else{thrownewDwoo_Exception('Dwoo->get/Dwoo->output\'s first argument must be a Dwoo_ITemplate (i.e. Dwoo_Template_File) or a valid path to a template file',E_USER_NOTICE);}$this->template=$_tpl;if($datainstanceofDwoo_IDataProvider){$this->data=$data->getData();}elseif(is_array($data)){$this->data=$data;}else{thrownewDwoo_Exception('Dwoo->get/Dwoo->output\'s data argument must be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array',E_USER_NOTICE);}$this->initGlobals($_tpl);$this->initRuntimeVars($_tpl);$file=$_tpl->getCachedTemplate($this);$doCache=$file===true;$cacheLoaded=is_string($file);if($cacheLoaded===true){if($_output===true){include$file;$this->template=null;}else{ob_start();include$file;$this->template=null;returnob_get_clean();}}else{if($doCache===true){$dynamicId=uniqid();}$out=include$_tpl->getCompiledTemplate($this,$_compiler);if($out===false){$_tpl->forceCompilation();$out=include$_tpl->getCompiledTemplate($this,$_compiler);}if($doCache===true){$out=preg_replace('/(<%|%>|<\?php|<\?|\?>)/','<?php /*'.$dynamicId.'*/ echo \'$1\'; ?>',$out);if(!class_exists('Dwoo_plugin_dynamic',false)){$this->getLoader()->loadPlugin('dynamic');}$out=Dwoo_Plugin_dynamic::unescape($out,$dynamicId);}foreach($this->filtersas$filter){if(is_array($filter)&&$filter[0]instanceofDwoo_Filter){$out=call_user_func($filter,$out);}else{$out=call_user_func($filter,$this,$out);}}if($doCache===true){$file=$_tpl->cache($this,$out);if($_output===true){include$file;$this->template=null;}else{ob_start();include$file;$this->template=null;returnob_get_clean();}}else{$this->template=null;if($_output===true){echo$out;}else{return$out;}}}}protectedfunctioninitGlobals(Dwoo_ITemplate$tpl){$this->globals=array('version'=>self::VERSION,'ad'=>'<a href="http://dwoo.org/">Powered by Dwoo</a>','now'=>$_SERVER['REQUEST_TIME'],'template'=>$tpl->getName(),'charset'=>$this->charset,);}protectedfunctioninitRuntimeVars(Dwoo_ITemplate$tpl){$this->runtimePlugins=array();$this->scope=&$this->data;$this->scopeTree=array();$this->stack=array();$this->curBlock=null;$this->buffer='';}publicfunctionaddPlugin($name,$callback,$compilable=false){$compilable=$compilable?self::COMPILABLE_PLUGIN:0;if(is_array($callback)){if(is_subclass_of(is_object($callback[0])?get_class($callback[0]):$callback[0],'Dwoo_Block_Plugin')){$this->plugins[$name]=array('type'=>self::BLOCK_PLUGIN|$compilable,'callback'=>$callback,'class'=>(is_object($callback[0])?get_class($callback[0]):$callback[0]));}else{$this->plugins[$name]=array('type'=>self::CLASS_PLUGIN|$compilable,'callback'=>$callback,'class'=>(is_object($callback[0])?get_class($callback[0]):$callback[0]),'function'=>$callback[1]);}}elseif(class_exists($callback,false)){if(is_subclass_of($callback,'Dwoo_Block_Plugin')){$this->plugins[$name]=array('type'=>self::BLOCK_PLUGIN|$compilable,'callback'=>$callback,'class'=>$callback);}else{$this->plugins[$name]=array('type'=>self::CLASS_PLUGIN|$compilable,'callback'=>$callback,'class'=>$callback,'function'=>'process');}}elseif(function_exists($callback)){$this->plugins[$name]=array('type'=>self::FUNC_PLUGIN|$compilable,'callback'=>$callback);}else{thrownewDwoo_Exception('Callback could not be processed correctly, please check that the function/class you used exists');}}publicfunctionremovePlugin($name){if(isset($this->plugins[$name])){unset($this->plugins[$name]);}}publicfunctionaddFilter($callback,$autoload=false){if($autoload){$class='Dwoo_Filter_'.$callback;if(!class_exists($class,false)&&!function_exists($class)){try{$this->getLoader()->loadPlugin($callback);}catch(Dwoo_Exception$e){if(strstr($callback,'Dwoo_Filter_')){thrownewDwoo_Exception('Wrong filter name : '.$callback.', the "Dwoo_Filter_" prefix should not be used, please only use "'.str_replace('Dwoo_Filter_','',$callback).'"');}else{thrownewDwoo_Exception('Wrong filter name : '.$callback.', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"');}}}if(class_exists($class,false)){$callback=array(new$class($this),'process');}elseif(function_exists($class)){$callback=$class;}else{thrownewDwoo_Exception('Wrong filter name : '.$callback.', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"');}$this->filters[]=$callback;}else{$this->filters[]=$callback;}}publicfunctionremoveFilter($callback){if(($index=array_search('Dwoo_Filter_'.$callback,$this->filters,true))!==false){unset($this->filters[$index]);}elseif(($index=array_search($callback,$this->filters,true))!==false){unset($this->filters[$index]);}else{$class='Dwoo_Filter_'.$callback;foreach($this->filtersas$index=>$filter){if(is_array($filter)&&$filter[0]instanceof$class){unset($this->filters[$index]);break;}}}}publicfunctionaddResource($name,$class,$compilerFactory=null){if(strlen($name)<2){thrownewDwoo_Exception('Resource names must be at least two-character long to avoid conflicts with Windows paths');}if(!class_exists($class)){thrownewDwoo_Exception('Resource class does not exist');}$interfaces=class_implements($class);if(in_array('Dwoo_ITemplate',$interfaces)===false){thrownewDwoo_Exception('Resource class must implement Dwoo_ITemplate');}$this->resources[$name]=array('class'=>$class,'compiler'=>$compilerFactory);}publicfunctionremoveResource($name){unset($this->resources[$name]);if($name==='file'){$this->resources['file']=array('class'=>'Dwoo_Template_File','compiler'=>null);}}publicfunctionsetLoader(Dwoo_ILoader$loader){$this->loader=$loader;}publicfunctiongetLoader(){if($this->loader===null){$this->loader=newDwoo_Loader($this->getCompileDir());}return$this->loader;}publicfunctiongetCustomPlugins(){return$this->plugins;}publicfunctiongetCacheDir(){if($this->cacheDir===null){$this->setCacheDir(dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR);}return$this->cacheDir;}publicfunctionsetCacheDir($dir){$this->cacheDir=rtrim($dir,'/\\').DIRECTORY_SEPARATOR;if(is_writable($this->cacheDir)===false){thrownewDwoo_Exception('The cache directory must be writable, chmod "'.$this->cacheDir.'" to make it writable');}}publicfunctiongetCompileDir(){if($this->compileDir===null){$this->setCompileDir(dirname(__FILE__).DIRECTORY_SEPARATOR.'compiled'.DIRECTORY_SEPARATOR);}return$this->compileDir;}publicfunctionsetCompileDir($dir){$this->compileDir=rtrim($dir,'/\\').DIRECTORY_SEPARATOR;if(is_writable($this->compileDir)===false){thrownewDwoo_Exception('The compile directory must be writable, chmod "'.$this->compileDir.'" to make it writable');}}publicfunctiongetCacheTime(){return$this->cacheTime;}publicfunctionsetCacheTime($seconds){$this->cacheTime=(int)$seconds;}publicfunctiongetCharset(){return$this->charset;}publicfunctionsetCharset($charset){$this->charset=strtolower((string)$charset);}publicfunctiongetTemplate(){return$this->template;}publicfunctionsetDefaultCompilerFactory($resourceName,$compilerFactory){$this->resources[$resourceName]['compiler']=$compilerFactory;}publicfunctiongetDefaultCompilerFactory($resourceName){return$this->resources[$resourceName]['compiler'];}publicfunctionsetSecurityPolicy(Dwoo_Security_Policy$policy=null){$this->securityPolicy=$policy;}publicfunctiongetSecurityPolicy(){return$this->securityPolicy;}publicfunctionsetPluginProxy(Dwoo_IPluginProxy$pluginProxy){$this->pluginProxy=$pluginProxy;}publicfunctiongetPluginProxy(){return$this->pluginProxy;}publicfunctionisCached(Dwoo_ITemplate$tpl){returnis_string($tpl->getCachedTemplate($this));}publicfunctionclearCache($olderThan=-1){$cacheDirs=newRecursiveDirectoryIterator($this->getCacheDir());$cache=newRecursiveIteratorIterator($cacheDirs);$expired=time()-$olderThan;$count=0;foreach($cacheas$file){if($cache->isDot()||$cache->isDir()||substr($file,-5)!=='.html'){continue;}if($cache->getCTime()<$expired){$count+=unlink((string)$file)?1:0;}}return$count;}publicfunctiontemplateFactory($resourceName,$resourceId,$cacheTime=null,$cacheId=null,$compileId=null,Dwoo_ITemplate$parentTemplate=null){if(isset($this->resources[$resourceName])){returncall_user_func(array($this->resources[$resourceName]['class'],'templateFactory'),$this,$resourceId,$cacheTime,$cacheId,$compileId,$parentTemplate);}else{thrownewDwoo_Exception('Unknown resource type : '.$resourceName);}}publicfunctionisArray($value,$checkIsEmpty=false,$allowNonCountable=false){if(is_array($value)===true){if($checkIsEmpty===false){returntrue;}else{returncount($value)>0;}}elseif($valueinstanceofIterator||$valueinstanceofArrayAccess){if($checkIsEmpty===false){returntrue;}else{if($allowNonCountable===false){returncount($value)>0;}else{if($valueinstanceofCountable){returncount($value)>0;}else{$value->rewind();return$value->valid();}}}}returnfalse;}publicfunctiontriggerError($message,$level=E_USER_NOTICE){if(!($tplIdentifier=$this->template->getResourceIdentifier())){$tplIdentifier=$this->template->getResourceName();}trigger_error('Dwoo error (in '.$tplIdentifier.') : '.$message,$level);}publicfunctionaddStack($blockName,array$args=array()){if(isset($this->plugins[$blockName])){$class=$this->plugins[$blockName]['class'];}else{$class='Dwoo_Plugin_'.$blockName;}if($this->curBlock!==null){$this->curBlock->buffer(ob_get_contents());ob_clean();}else{$this->buffer.=ob_get_contents();ob_clean();}$block=new$class($this);$cnt=count($args);if($cnt===0){$block->init();}elseif($cnt===1){$block->init($args[0]);}elseif($cnt===2){$block->init($args[0],$args[1]);}elseif($cnt===3){$block->init($args[0],$args[1],$args[2]);}elseif($cnt===4){$block->init($args[0],$args[1],$args[2],$args[3]);}else{call_user_func_array(array($block,'init'),$args);}$this->stack[]=$this->curBlock=$block;return$block;}publicfunctiondelStack(){$args=func_get_args();$this->curBlock->buffer(ob_get_contents());ob_clean();$cnt=count($args);if($cnt===0){$this->curBlock->end();}elseif($cnt===1){$this->curBlock->end($args[0]);}elseif($cnt===2){$this->curBlock->end($args[0],$args[1]);}elseif($cnt===3){$this->curBlock->end($args[0],$args[1],$args[2]);}elseif($cnt===4){$this->curBlock->end($args[0],$args[1],$args[2],$args[3]);}else{call_user_func_array(array($this->curBlock,'end'),$args);}$tmp=array_pop($this->stack);if(count($this->stack)>0){$this->curBlock=end($this->stack);$this->curBlock->buffer($tmp->process());}else{$this->curBlock=null;echo$tmp->process();}unset($tmp);}publicfunctiongetParentBlock(Dwoo_Block_Plugin$block){$index=array_search($block,$this->stack,true);if($index!==false&&$index>0){return$this->stack[$index-1];}returnfalse;}publicfunctionfindBlock($type){if(isset($this->plugins[$type])){$type=$this->plugins[$type]['class'];}else{$type='Dwoo_Plugin_'.str_replace('Dwoo_Plugin_','',$type);}$keys=array_keys($this->stack);while(($key=array_pop($keys))!==false){if($this->stack[$key]instanceof$type){return$this->stack[$key];}}returnfalse;}protectedfunctiongetObjectPlugin($class){if(isset($this->runtimePlugins[$class])){return$this->runtimePlugins[$class];}return$this->runtimePlugins[$class]=new$class($this);}publicfunctionclassCall($plugName,array$params=array()){$class='Dwoo_Plugin_'.$plugName;$plugin=$this->getObjectPlugin($class);$cnt=count($params);if($cnt===0){return$plugin->process();}elseif($cnt===1){return$plugin->process($params[0]);}elseif($cnt===2){return$plugin->process($params[0],$params[1]);}elseif($cnt===3){return$plugin->process($params[0],$params[1],$params[2]);}elseif($cnt===4){return$plugin->process($params[0],$params[1],$params[2],$params[3]);}else{returncall_user_func_array(array($plugin,'process'),$params);}}publicfunctionarrayMap($callback,array$params){if($params[0]===$this){$addThis=true;array_shift($params);}if((is_array($params[0])||($params[0]instanceofIterator&&$params[0]instanceofArrayAccess))){if(empty($params[0])){return$params[0];}$out=array();$cnt=count($params);if(isset($addThis)){array_unshift($params,$this);$items=$params[1];$keys=array_keys($items);if(is_string($callback)===false){while(($i=array_shift($keys))!==null){$out[]=call_user_func_array($callback,array(1=>$items[$i])+$params);}}elseif($cnt===1){while(($i=array_shift($keys))!==null){$out[]=$callback($this,$items[$i]);}}elseif($cnt===2){while(($i=array_shift($keys))!==null){$out[]=$callback($this,$items[$i],$params[2]);}}elseif($cnt===3){while(($i=array_shift($keys))!==null){$out[]=$callback($this,$items[$i],$params[2],$params[3]);}}else{while(($i=array_shift($keys))!==null){$out[]=call_user_func_array($callback,array(1=>$items[$i])+$params);}}}else{$items=$params[0];$keys=array_keys($items);if(is_string($callback)===false){while(($i=array_shift($keys))!==null){$out[]=call_user_func_array($callback,array($items[$i])+$params);}}elseif($cnt===1){while(($i=array_shift($keys))!==null){$out[]=$callback($items[$i]);}}elseif($cnt===2){while(($i=array_shift($keys))!==null){$out[]=$callback($items[$i],$params[1]);}}elseif($cnt===3){while(($i=array_shift($keys))!==null){$out[]=$callback($items[$i],$params[1],$params[2]);}}elseif($cnt===4){while(($i=array_shift($keys))!==null){$out[]=$callback($items[$i],$params[1],$params[2],$params[3]);}}else{while(($i=array_shift($keys))!==null){$out[]=call_user_func_array($callback,array($items[$i])+$params);}}}return$out;}else{return$params[0];}}publicfunctionreadVarInto($varstr,$data){if($data===null){returnnull;}if(is_array($varstr)===false){preg_match_all('#(\[|->|\.)?([^.[\]-]+)\]?#i',$varstr,$m);}else{$m=$varstr;}unset($varstr);while(list($k,$sep)=each($m[1])){if($sep==='.'||$sep==='['||$sep===''){if((is_array($data)||$datainstanceofArrayAccess)&&isset($data[$m[2][$k]])){$data=$data[$m[2][$k]];}else{returnnull;}}else{if(is_object($data)){$data=$data->$m[2][$k];}else{returnnull;}}}return$data;}publicfunctionreadParentVar($parentLevels,$varstr=null){$tree=$this->scopeTree;$cur=$this->data;while($parentLevels--!==0){array_pop($tree);}while(($i=array_shift($tree))!==null){if(is_object($cur)){$cur=$cur->$i;}else{$cur=$cur[$i];}}if($varstr!==null){return$this->readVarInto($varstr,$cur);}else{return$cur;}}publicfunctionreadVar($varstr){if(is_array($varstr)===true){$m=$varstr;unset($varstr);}else{if(strstr($varstr,'.')===false&&strstr($varstr,'[')===false&&strstr($varstr,'->')===false){if($varstr==='dwoo'){return$this->globals;}elseif($varstr==='__'||$varstr==='_root'){return$this->data;$varstr=substr($varstr,6);}elseif($varstr==='_'||$varstr==='_parent'){$varstr='.'.$varstr;$tree=$this->scopeTree;$cur=$this->data;array_pop($tree);while(($i=array_shift($tree))!==null){if(is_object($cur)){$cur=$cur->$i;}else{$cur=$cur[$i];}}return$cur;}$cur=$this->scope;if(isset($cur[$varstr])){return$cur[$varstr];}else{returnnull;}}if(substr($varstr,0,1)==='.'){$varstr='dwoo'.$varstr;}preg_match_all('#(\[|->|\.)?([^.[\]-]+)\]?#i',$varstr,$m);}$i=$m[2][0];if($i==='dwoo'){$cur=$this->globals;array_shift($m[2]);array_shift($m[1]);switch($m[2][0]){case'get':$cur=$_GET;break;case'post':$cur=$_POST;break;case'session':$cur=$_SESSION;break;case'cookies':case'cookie':$cur=$_COOKIE;break;case'server':$cur=$_SERVER;break;case'env':$cur=$_ENV;break;case'request':$cur=$_REQUEST;break;case'const':array_shift($m[2]);if(defined($m[2][0])){returnconstant($m[2][0]);}else{returnnull;}}if($cur!==$this->globals){array_shift($m[2]);array_shift($m[1]);}}elseif($i==='__'||$i==='_root'){$cur=$this->data;array_shift($m[2]);array_shift($m[1]);}elseif($i==='_'||$i==='_parent'){$tree=$this->scopeTree;$cur=$this->data;while(true){array_pop($tree);array_shift($m[2]);array_shift($m[1]);if(current($m[2])==='_'||current($m[2])==='_parent'){continue;}while(($i=array_shift($tree))!==null){if(is_object($cur)){$cur=$cur->$i;}else{$cur=$cur[$i];}}break;}}else{$cur=$this->scope;}while(list($k,$sep)=each($m[1])){if($sep==='.'||$sep==='['||$sep===''){if((is_array($cur)||$curinstanceofArrayAccess)&&isset($cur[$m[2][$k]])){$cur=$cur[$m[2][$k]];}else{returnnull;}}elseif($sep==='->'){if(is_object($cur)){$cur=$cur->$m[2][$k];}else{returnnull;}}else{returnnull;}}return$cur;}publicfunctionassignInScope($value,$scope){$tree=&$this->scopeTree;$data=&$this->data;if(!is_string($scope)){return$this->triggerError('Assignments must be done into strings, ('.gettype($scope).') '.var_export($scope,true).' given',E_USER_ERROR);}if(strstr($scope,'.')===false&&strstr($scope,'->')===false){$this->scope[$scope]=$value;}else{preg_match_all('#(\[|->|\.)?([^.[\]-]+)\]?#i',$scope,$m);$cur=&$this->scope;$last=array(array_pop($m[1]),array_pop($m[2]));while(list($k,$sep)=each($m[1])){if($sep==='.'||$sep==='['||$sep===''){if(is_array($cur)===false){$cur=array();}$cur=&$cur[$m[2][$k]];}elseif($sep==='->'){if(is_object($cur)===false){$cur=newstdClass;}$cur=&$cur->$m[2][$k];}else{returnfalse;}}if($last[0]==='.'||$last[0]==='['||$last[0]===''){if(is_array($cur)===false){$cur=array();}$cur[$last[1]]=$value;}elseif($last[0]==='->'){if(is_object($cur)===false){$cur=newstdClass;}$cur->$last[1]=$value;}else{returnfalse;}}}publicfunctionsetScope($scope,$absolute=false){$old=$this->scopeTree;if(is_string($scope)===true){$scope=explode('.',$scope);}if($absolute===true){$this->scope=&$this->data;$this->scopeTree=array();}while(($bit=array_shift($scope))!==null){if($bit==='_'||$bit==='_parent'){array_pop($this->scopeTree);$this->scope=&$this->data;$cnt=count($this->scopeTree);for($i=0;$i<$cnt;$i++)$this->scope=&$this->scope[$this->scopeTree[$i]];}elseif($bit==='__'||$bit==='_root'){$this->scope=&$this->data;$this->scopeTree=array();}elseif(isset($this->scope[$bit])){$this->scope=&$this->scope[$bit];$this->scopeTree[]=$bit;}else{unset($this->scope);$this->scope=null;}}return$old;}publicfunctiongetData(){return$this->data;}publicfunction&getScope(){return$this->scope;}publicfunctionforceScope($scope){return$this->setScope($scope,true);}}interfaceDwoo_IPluginProxy{publicfunctionhandles($name);publicfunctiongetCode($name,$params);publicfunctiongetCallback($name);publicfunctiongetLoader($name);}interfaceDwoo_IElseable{}interfaceDwoo_ILoader{publicfunctionloadPlugin($class,$forceRehash=true);}classDwoo_LoaderimplementsDwoo_ILoader{protected$paths=array();protected$classPath=array();protected$cacheDir;protected$corePluginDir;publicfunction__construct($cacheDir){$this->corePluginDir=DWOO_DIRECTORY.'plugins';$this->cacheDir=$cacheDir.DIRECTORY_SEPARATOR;$foo=@file_get_contents($this->cacheDir.'classpath.cache.d'.Dwoo::RELEASE_TAG.'.php');if($foo){$this->classPath=unserialize($foo)+$this->classPath;}else{$this->rebuildClassPathCache($this->corePluginDir,$this->cacheDir.'classpath.cache.d'.Dwoo::RELEASE_TAG.'.php');}}protectedfunctionrebuildClassPathCache($path,$cacheFile){if($cacheFile!==false){$tmp=$this->classPath;$this->classPath=array();}$list=glob($path.DIRECTORY_SEPARATOR.'*');if(is_array($list)){foreach($listas$f){if(is_dir($f)){$this->rebuildClassPathCache($f,false);}else{$this->classPath[str_replace(array('function.','block.','modifier.','outputfilter.','filter.','prefilter.','postfilter.','pre.','post.','output.','shared.','helper.'),'',basename($f,'.php'))]=$f;}}}if($cacheFile!==false){if(!file_put_contents($cacheFile,serialize($this->classPath))){thrownewDwoo_Exception('Could not write into '.$cacheFile.', either because the folder is not there (create it) or because of the chmod configuration (please ensure this directory is writable by php), alternatively you can change the directory used with $dwoo->setCompileDir() or provide a custom loader object with $dwoo->setLoader()');}$this->classPath+=$tmp;}}publicfunctionloadPlugin($class,$forceRehash=true){if(!isset($this->classPath[$class])||!(include$this->classPath[$class])){if($forceRehash){$this->rebuildClassPathCache($this->corePluginDir,$this->cacheDir.'classpath.cache.d'.Dwoo::RELEASE_TAG.'.php');foreach($this->pathsas$path=>$file){$this->rebuildClassPathCache($path,$file);}if(isset($this->classPath[$class])){include$this->classPath[$class];}else{thrownewDwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?',E_USER_NOTICE);}}else{thrownewDwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?',E_USER_NOTICE);}}}publicfunctionaddDirectory($pluginDirectory){$pluginDir=realpath($pluginDirectory);if(!$pluginDir){thrownewDwoo_Exception('Plugin directory does not exist or can not be read : '.$pluginDirectory);}$cacheFile=$this->cacheDir.'classpath-'.substr(strtr($pluginDir,'/\\:'.PATH_SEPARATOR,'----'),strlen($pluginDir)>80?-80:0).'.d'.Dwoo::RELEASE_TAG.'.php';$this->paths[$pluginDir]=$cacheFile;$foo=@file_get_contents($cacheFile);if($foo){$this->classPath=unserialize($foo)+$this->classPath;}else{$this->rebuildClassPathCache($pluginDir,$cacheFile);}}}classDwoo_ExceptionextendsException{}classDwoo_Security_Policy{constPHP_ENCODE=1;constPHP_REMOVE=2;constPHP_ALLOW=3;constCONST_DISALLOW=false;constCONST_ALLOW=true;protected$allowedPhpFunctions=array('str_repeat','number_format','htmlentities','htmlspecialchars','long2ip','strlen','list','empty','count','sizeof','in_array','is_array',);protected$allowedDirectories=array();protected$phpHandling=self::PHP_REMOVE;protected$constHandling=self::CONST_DISALLOW;publicfunctionallowPhpFunction($func){if(is_array($func))foreach($funcas$fname)$this->allowedPhpFunctions[strtolower($fname)]=true;else$this->allowedPhpFunctions[strtolower($func)]=true;}publicfunctiondisallowPhpFunction($func){if(is_array($func))foreach($funcas$fname)unset($this->allowedPhpFunctions[strtolower($fname)]);elseunset($this->allowedPhpFunctions[strtolower($func)]);}publicfunctiongetAllowedPhpFunctions(){return$this->allowedPhpFunctions;}publicfunctionallowDirectory($path){if(is_array($path))foreach($pathas$dir)$this->allowedDirectories[realpath($dir)]=true;else$this->allowedDirectories[realpath($path)]=true;}publicfunctiondisallowDirectory($path){if(is_array($path))foreach($pathas$dir)unset($this->allowedDirectories[realpath($dir)]);elseunset($this->allowedDirectories[realpath($path)]);}publicfunctiongetAllowedDirectories(){return$this->allowedDirectories;}publicfunctionsetPhpHandling($level=self::PHP_REMOVE){$this->phpHandling=$level;}publicfunctiongetPhpHandling(){return$this->phpHandling;}publicfunctionsetConstantHandling($level=self::CONST_DISALLOW){$this->constHandling=$level;}publicfunctiongetConstantHandling(){return$this->constHandling;}}classDwoo_Security_ExceptionextendsDwoo_Exception{}interfaceDwoo_ICompilable{}interfaceDwoo_ICompiler{publicfunctioncompile(Dwoo$dwoo,Dwoo_ITemplate$template);publicfunctionsetCustomPlugins(array$customPlugins);publicfunctionsetSecurityPolicy(Dwoo_Security_Policy$policy=null);}interfaceDwoo_IDataProvider{publicfunctiongetData();}interfaceDwoo_ITemplate{publicfunctiongetCacheTime();publicfunctionsetCacheTime($seconds=null);publicfunctiongetCachedTemplate(Dwoo$dwoo);publicfunctioncache(Dwoo$dwoo,$output);publicfunctionclearCache(Dwoo$dwoo,$olderThan=-1);publicfunctiongetCompiledTemplate(Dwoo$dwoo,Dwoo_ICompiler$compiler=null);publicfunctiongetName();publicfunctiongetResourceName();publicfunctiongetResourceIdentifier();publicfunctiongetSource();publicfunctiongetUid();publicfunctiongetCompiler();publicstaticfunctiontemplateFactory(Dwoo$dwoo,$resourceId,$cacheTime=null,$cacheId=null,$compileId=null,Dwoo_ITemplate$parentTemplate=null);}interfaceDwoo_ICompilable_Block{}abstractclassDwoo_Plugin{protected$dwoo;publicfunction__construct(Dwoo$dwoo){$this->dwoo=$dwoo;}publicstaticfunctionparamsToAttributes(array$params,$delim='\''){if(isset($params['*'])){$params=array_merge($params,$params['*']);unset($params['*']);}$out='';foreach($paramsas$attr=>$val){$out.=' '.$attr.'=';if(trim($val,'"\'')==''||$val=='null'){$out.=str_replace($delim,'\\'.$delim,'""');}elseif(substr($val,0,1)===$delim&&substr($val,-1)===$delim){$out.=str_replace($delim,'\\'.$delim,'"'.substr($val,1,-1).'"');}else{$out.=str_replace($delim,'\\'.$delim,'"').$delim.'.'.$val.'.'.$delim.str_replace($delim,'\\'.$delim,'"');}}returnltrim($out);}}abstractclassDwoo_Block_PluginextendsDwoo_Plugin{protected$buffer='';publicfunctionbuffer($input){$this->buffer.=$input;}publicfunctionend(){}publicfunctionprocess(){return$this->buffer;}publicstaticfunctionpreProcessing(Dwoo_Compiler$compiler,array$params,$prepend,$append,$type){returnDwoo_Compiler::PHP_OPEN.$prepend.'$this->addStack("'.$type.'", array('.Dwoo_Compiler::implode_r($compiler->getCompiledParams($params)).'));'.$append.Dwoo_Compiler::PHP_CLOSE;}publicstaticfunctionpostProcessing(Dwoo_Compiler$compiler,array$params,$prepend,$append,$content){return$content.Dwoo_Compiler::PHP_OPEN.$prepend.'$this->delStack();'.$append.Dwoo_Compiler::PHP_CLOSE;}}abstractclassDwoo_Filter{protected$dwoo;publicfunction__construct(Dwoo$dwoo){$this->dwoo=$dwoo;}abstractpublicfunctionprocess($input);}abstractclassDwoo_Processor{protected$compiler;publicfunction__construct(Dwoo_Compiler$compiler){$this->compiler=$compiler;}abstractpublicfunctionprocess($input);}classDwoo_Template_StringimplementsDwoo_ITemplate{protected$name;protected$compileId;protected$cacheId;protected$cacheTime;protected$compilationEnforced;protectedstatic$cache=array('cached'=>array(),'compiled'=>array());protected$compiler;protected$chmod=0777;publicfunction__construct($templateString,$cacheTime=null,$cacheId=null,$compileId=null){$this->template=$templateString;if(function_exists('hash')){$this->name=hash('md4',$templateString);}else{$this->name=md5($templateString);}$this->cacheTime=$cacheTime;if($compileId!==null){$this->compileId=str_replace('../','__',strtr($compileId,'\\%?=!:;'.PATH_SEPARATOR,'/-------'));}if($cacheId!==null){$this->cacheId=str_replace('../','__',strtr($cacheId,'\\%?=!:;'.PATH_SEPARATOR,'/-------'));}}publicfunctiongetCacheTime(){return$this->cacheTime;}publicfunctionsetCacheTime($seconds=null){$this->cacheTime=$seconds;}publicfunctiongetChmod(){return$this->chmod;}publicfunctionsetChmod($mask=null){$this->chmod=$mask;}publicfunctiongetName(){return$this->name;}publicfunctiongetResourceName(){return'string';}publicfunctiongetResourceIdentifier(){returnfalse;}publicfunctiongetSource(){return$this->template;}publicfunctiongetUid(){return$this->name;}publicfunctiongetCompiler(){return$this->compiler;}publicfunctionforceCompilation(){$this->compilationEnforced=true;}publicfunctiongetCachedTemplate(Dwoo$dwoo){if($this->cacheTime!==null){$cacheLength=$this->cacheTime;}else{$cacheLength=$dwoo->getCacheTime();}if($cacheLength===0){returnfalse;}$cachedFile=$this->getCacheFilename($dwoo);if(isset(self::$cache['cached'][$this->cacheId])===true&&file_exists($cachedFile)){return$cachedFile;}elseif($this->compilationEnforced!==true&&file_exists($cachedFile)&&($cacheLength===-1||filemtime($cachedFile)>($_SERVER['REQUEST_TIME']-$cacheLength))){self::$cache['cached'][$this->cacheId]=true;return$cachedFile;}else{returntrue;}}publicfunctioncache(Dwoo$dwoo,$output){$cacheDir=$dwoo->getCacheDir();$cachedFile=$this->getCacheFilename($dwoo);$temp=tempnam($cacheDir,'temp');if(!($file=@fopen($temp,'wb'))){$temp=$cacheDir.DIRECTORY_SEPARATOR.uniqid('temp');if(!($file=@fopen($temp,'wb'))){trigger_error('Error writing temporary file \''.$temp.'\'',E_USER_WARNING);returnfalse;}}fwrite($file,$output);fclose($file);$this->makeDirectory(dirname($cachedFile));if(!@rename($temp,$cachedFile)){@unlink($cachedFile);@rename($temp,$cachedFile);}if($this->chmod!==null){chmod($cachedFile,$this->chmod);}self::$cache['cached'][$this->cacheId]=true;return$cachedFile;}publicfunctionclearCache(Dwoo$dwoo,$olderThan=-1){$cachedFile=$this->getCacheFilename($dwoo);return!file_exists($cachedFile)||(filectime($cachedFile)<(time()-$olderThan)&&unlink($cachedFile));}publicfunctiongetCompiledTemplate(Dwoo$dwoo,Dwoo_ICompiler$compiler=null){$compiledFile=$this->getCompiledFilename($dwoo);if($this->compilationEnforced!==true&&isset(self::$cache['compiled'][$this->compileId])===true){}elseif($this->compilationEnforced!==true&&$this->isValidCompiledFile($compiledFile)){self::$cache['compiled'][$this->compileId]=true;}else{$this->compilationEnforced=false;if($compiler===null){$compiler=$dwoo->getDefaultCompilerFactory($this->getResourceName());if($compiler===null||$compiler===array('Dwoo_Compiler','compilerFactory')){if(class_exists('Dwoo_Compiler',false)===false){includeDWOO_DIRECTORY.'Dwoo/Compiler.php';}$compiler=Dwoo_Compiler::compilerFactory();}else{$compiler=call_user_func($compiler);}}$this->compiler=$compiler;$compiler->setCustomPlugins($dwoo->getCustomPlugins());$compiler->setSecurityPolicy($dwoo->getSecurityPolicy());$this->makeDirectory(dirname($compiledFile));file_put_contents($compiledFile,$compiler->compile($dwoo,$this));if($this->chmod!==null){chmod($compiledFile,$this->chmod);}self::$cache['compiled'][$this->compileId]=true;}return$compiledFile;}protectedfunctionisValidCompiledFile($file){returnfile_exists($file);}publicstaticfunctiontemplateFactory(Dwoo$dwoo,$resourceId,$cacheTime=null,$cacheId=null,$compileId=null,Dwoo_ITemplate$parentTemplate=null){returnnewself($resourceId,$cacheTime,$cacheId,$compileId);}protectedfunctiongetCompiledFilename(Dwoo$dwoo){if($this->compileId===null){$this->compileId=$this->name;}return$dwoo->getCompileDir().$this->compileId.'.d'.Dwoo::RELEASE_TAG.'.php';}protectedfunctiongetCacheFilename(Dwoo$dwoo){if($this->cacheId===null){if(isset($_SERVER['REQUEST_URI'])===true){$cacheId=$_SERVER['REQUEST_URI'];}elseif(isset($_SERVER['SCRIPT_FILENAME'])&&isset($_SERVER['argv'])){$cacheId=$_SERVER['SCRIPT_FILENAME'].'-'.implode('-',$_SERVER['argv']);}else{$cacheId='';}$this->getCompiledFilename($dwoo);$this->cacheId=str_replace('../','__',$this->compileId.strtr($cacheId,'\\%?=!:;'.PATH_SEPARATOR,'/-------'));}return$dwoo->getCacheDir().$this->cacheId.'.html';}protectedfunctionmakeDirectory($path){if(is_dir($path)===true){return;}if($this->chmod!==null){mkdir($path,$this->chmod,true);}else{mkdir($path,0777,true);}}}classDwoo_Template_FileextendsDwoo_Template_String{protected$file;protected$includePath=null;protected$resolvedPath=null;publicfunction__construct($file,$cacheTime=null,$cacheId=null,$compileId=null,$includePath=null){$this->file=$file;$this->name=basename($file);$this->cacheTime=$cacheTime;if($compileId!==null){$this->compileId=str_replace('../','__',strtr($compileId,'\\%?=!:;'.PATH_SEPARATOR,'/-------'));}if($cacheId!==null){$this->cacheId=str_replace('../','__',strtr($cacheId,'\\%?=!:;'.PATH_SEPARATOR,'/-------'));}if(is_string($includePath)){$this->includePath=array($includePath);}elseif(is_array($includePath)){$this->includePath=$includePath;}}publicfunctionsetIncludePath($paths){if(is_array($paths)===false){$paths=array($paths);}$this->includePath=$paths;$this->resolvedPath=null;}publicfunctiongetIncludePath(){return$this->includePath;}protectedfunctionisValidCompiledFile($file){returnparent::isValidCompiledFile($file)&&(int)$this->getUid()<=filemtime($file);}publicfunctiongetSource(){returnfile_get_contents($this->getResourceIdentifier());}publicfunctiongetResourceName(){return'file';}publicfunctiongetResourceIdentifier(){if($this->resolvedPath!==null){return$this->resolvedPath;}elseif($this->includePath===null){return$this->file;}else{foreach($this->includePathas$path){if(file_exists($path.DIRECTORY_SEPARATOR.$this->file)===true){$this->resolvedPath=$path.DIRECTORY_SEPARATOR.$this->file;return$this->resolvedPath;}}thrownewDwoo_Exception('Template "'.$this->file.'" could not be found in any of your include path(s)');}}publicfunctiongetUid(){return(string)filemtime($this->getResourceIdentifier());}publicstaticfunctiontemplateFactory(Dwoo$dwoo,$resourceId,$cacheTime=null,$cacheId=null,$compileId=null,Dwoo_ITemplate$parentTemplate=null){if(DIRECTORY_SEPARATOR==='\\'){$resourceId=str_replace(array("\t","\n","\r","\f","\v"),array('\\t','\\n','\\r','\\f','\\v'),$resourceId);}$resourceId=strtr($resourceId,'\\','/');$includePath=null;if(file_exists($resourceId)===false){if($parentTemplate===null){$parentTemplate=$dwoo->getTemplate();}if($parentTemplateinstanceofDwoo_Template_File){if($includePath=$parentTemplate->getIncludePath()){if(strstr($resourceId,'../')){thrownewDwoo_Exception('When using an include path you can not reference a template into a parent directory (using ../)');}}else{$resourceId=dirname($parentTemplate->getResourceIdentifier()).DIRECTORY_SEPARATOR.$resourceId;if(file_exists($resourceId)===false){returnnull;}}}else{returnnull;}}if($policy=$dwoo->getSecurityPolicy()){while(true){if(preg_match('{^([a-z]+?)://}i',$resourceId)){thrownewDwoo_Security_Exception('The security policy prevents you to read files from external sources : <em>'.$resourceId.'</em>.');}if($includePath){break;}$resourceId=realpath($resourceId);$dirs=$policy->getAllowedDirectories();foreach($dirsas$dir=>$dummy){if(strpos($resourceId,$dir)===0){break2;}}thrownewDwoo_Security_Exception('The security policy prevents you to read <em>'.$resourceId.'</em>');}}returnnewDwoo_Template_File($resourceId,$cacheTime,$cacheId,$compileId,$includePath);}protectedfunctiongetCompiledFilename(Dwoo$dwoo){if($this->compileId===null){$this->compileId=str_replace('../','__',strtr($this->getResourceIdentifier(),'\\:','/-'));}return$dwoo->getCompileDir().$this->compileId.'.d'.Dwoo::RELEASE_TAG.'.php';}}classDwoo_DataimplementsDwoo_IDataProvider{protected$data=array();publicfunctiongetData(){return$this->data;}publicfunctionclear($name=null){if($name===null){$this->data=array();}elseif(is_array($name)){foreach($nameas$index)unset($this->data[$index]);}else{unset($this->data[$name]);}}publicfunctionsetData(array$data){$this->data=$data;}publicfunctionmergeData(array$data){$args=func_get_args();while(list(,$v)=each($args)){if(is_array($v)){$this->data=array_merge($this->data,$v);}}}publicfunctionassign($name,$val=null){if(is_array($name)){reset($name);while(list($k,$v)=each($name))$this->data[$k]=$v;}else{$this->data[$name]=$val;}}publicfunction__set($name,$value){$this->assign($name,$value);}publicfunctionassignByRef($name,&$val){$this->data[$name]=&$val;}publicfunctionappend($name,$val=null,$merge=false){if(is_array($name)){foreach($nameas$key=>$val){if(isset($this->data[$key])&&!is_array($this->data[$key])){settype($this->data[$key],'array');}if($merge===true&&is_array($val)){$this->data[$key]=$val+$this->data[$key];}else{$this->data[$key][]=$val;}}}elseif($val!==null){if(isset($this->data[$name])&&!is_array($this->data[$name])){settype($this->data[$name],'array');}if($merge===true&&is_array($val)){$this->data[$name]=$val+$this->data[$name];}else{$this->data[$name][]=$val;}}}publicfunctionappendByRef($name,&$val,$merge=false){if(isset($this->data[$name])&&!is_array($this->data[$name])){settype($this->data[$name],'array');}if($merge===true&&is_array($val)){foreach($valas$key=>&$val){$this->data[$name][$key]=&$val;}}else{$this->data[$name][]=&$val;}}publicfunctionisAssigned($name){returnisset($this->data[$name]);}publicfunction__isset($name){returnisset($this->data[$name]);}publicfunctionunassign($name){unset($this->data[$name]);}publicfunction__unset($name){unset($this->data[$name]);}publicfunctionget($name){return$this->__get($name);}publicfunction__get($name){if(isset($this->data[$name])){return$this->data[$name];}else{thrownewDwoo_Exception('Tried to read a value that was not assigned yet : "'.$name.'"');}}}
\ No newline at end of file
<?phpdefine('DWOO_DIRECTORY',dirname(__FILE__).DIRECTORY_SEPARATOR);classDwoo{constVERSION="1.0.0beta";constRELEASE_TAG=13;constCLASS_PLUGIN=1;constFUNC_PLUGIN=2;constNATIVE_PLUGIN=4;constBLOCK_PLUGIN=8;constCOMPILABLE_PLUGIN=16;constCUSTOM_PLUGIN=32;constSMARTY_MODIFIER=64;constSMARTY_BLOCK=128;constSMARTY_FUNCTION=256;constPROXY_PLUGIN=512;protected$charset='utf-8';protected$globals;protected$compileDir;protected$cacheDir;protected$cacheTime=0;protected$securityPolicy=null;protected$plugins=array();protected$filters=array();protected$resources=array('file'=>array('class'=>'Dwoo_Template_File','compiler'=>null),'string'=>array('class'=>'Dwoo_Template_String','compiler'=>null));protected$loader=null;protected$template=null;protected$runtimePlugins;protected$data;protected$scope;protected$scopeTree;protected$stack;protected$curBlock;protected$buffer;protected$pluginProxy;publicfunction__construct($compileDir=null,$cacheDir=null){if($compileDir!==null){$this->setCompileDir($compileDir);}if($cacheDir!==null){$this->setCacheDir($cacheDir);}}publicfunction__clone(){$this->template=null;}publicfunctionoutput($tpl,$data=array(),Dwoo_ICompiler$compiler=null){return$this->get($tpl,$data,$compiler,true);}publicfunctionget($_tpl,$data=array(),$_compiler=null,$_output=false){if($this->templateinstanceofDwoo_ITemplate){$proxy=clone$this;return$proxy->get($_tpl,$data,$_compiler,$_output);}if($_tplinstanceofDwoo_ITemplate){}elseif(is_string($_tpl)&&file_exists($_tpl)){$_tpl=newDwoo_Template_File($_tpl);}else{thrownewDwoo_Exception('Dwoo->get/Dwoo->output\'s first argument must be a Dwoo_ITemplate (i.e. Dwoo_Template_File) or a valid path to a template file',E_USER_NOTICE);}$this->template=$_tpl;if($datainstanceofDwoo_IDataProvider){$this->data=$data->getData();}elseif(is_array($data)){$this->data=$data;}else{thrownewDwoo_Exception('Dwoo->get/Dwoo->output\'s data argument must be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array',E_USER_NOTICE);}$this->initGlobals($_tpl);$this->initRuntimeVars($_tpl);$file=$_tpl->getCachedTemplate($this);$doCache=$file===true;$cacheLoaded=is_string($file);if($cacheLoaded===true){if($_output===true){include$file;$this->template=null;}else{ob_start();include$file;$this->template=null;returnob_get_clean();}}else{if($doCache===true){$dynamicId=uniqid();}$out=include$_tpl->getCompiledTemplate($this,$_compiler);if($out===false){$_tpl->forceCompilation();$out=include$_tpl->getCompiledTemplate($this,$_compiler);}if($doCache===true){$out=preg_replace('/(<%|%>|<\?php|<\?|\?>)/','<?php /*'.$dynamicId.'*/ echo \'$1\'; ?>',$out);if(!class_exists('Dwoo_plugin_dynamic',false)){$this->getLoader()->loadPlugin('dynamic');}$out=Dwoo_Plugin_dynamic::unescape($out,$dynamicId);}foreach($this->filtersas$filter){if(is_array($filter)&&$filter[0]instanceofDwoo_Filter){$out=call_user_func($filter,$out);}else{$out=call_user_func($filter,$this,$out);}}if($doCache===true){$file=$_tpl->cache($this,$out);if($_output===true){include$file;$this->template=null;}else{ob_start();include$file;$this->template=null;returnob_get_clean();}}else{$this->template=null;if($_output===true){echo$out;}else{return$out;}}}}protectedfunctioninitGlobals(Dwoo_ITemplate$tpl){$this->globals=array('version'=>self::VERSION,'ad'=>'<a href="http://dwoo.org/">Powered by Dwoo</a>','now'=>$_SERVER['REQUEST_TIME'],'template'=>$tpl->getName(),'charset'=>$this->charset,);}protectedfunctioninitRuntimeVars(Dwoo_ITemplate$tpl){$this->runtimePlugins=array();$this->scope=&$this->data;$this->scopeTree=array();$this->stack=array();$this->curBlock=null;$this->buffer='';}publicfunctionaddPlugin($name,$callback,$compilable=false){$compilable=$compilable?self::COMPILABLE_PLUGIN:0;if(is_array($callback)){if(is_subclass_of(is_object($callback[0])?get_class($callback[0]):$callback[0],'Dwoo_Block_Plugin')){$this->plugins[$name]=array('type'=>self::BLOCK_PLUGIN|$compilable,'callback'=>$callback,'class'=>(is_object($callback[0])?get_class($callback[0]):$callback[0]));}else{$this->plugins[$name]=array('type'=>self::CLASS_PLUGIN|$compilable,'callback'=>$callback,'class'=>(is_object($callback[0])?get_class($callback[0]):$callback[0]),'function'=>$callback[1]);}}elseif(class_exists($callback,false)){if(is_subclass_of($callback,'Dwoo_Block_Plugin')){$this->plugins[$name]=array('type'=>self::BLOCK_PLUGIN|$compilable,'callback'=>$callback,'class'=>$callback);}else{$this->plugins[$name]=array('type'=>self::CLASS_PLUGIN|$compilable,'callback'=>$callback,'class'=>$callback,'function'=>'process');}}elseif(function_exists($callback)){$this->plugins[$name]=array('type'=>self::FUNC_PLUGIN|$compilable,'callback'=>$callback);}else{thrownewDwoo_Exception('Callback could not be processed correctly, please check that the function/class you used exists');}}publicfunctionremovePlugin($name){if(isset($this->plugins[$name])){unset($this->plugins[$name]);}}publicfunctionaddFilter($callback,$autoload=false){if($autoload){$class='Dwoo_Filter_'.$callback;if(!class_exists($class,false)&&!function_exists($class)){try{$this->getLoader()->loadPlugin($callback);}catch(Dwoo_Exception$e){if(strstr($callback,'Dwoo_Filter_')){thrownewDwoo_Exception('Wrong filter name : '.$callback.', the "Dwoo_Filter_" prefix should not be used, please only use "'.str_replace('Dwoo_Filter_','',$callback).'"');}else{thrownewDwoo_Exception('Wrong filter name : '.$callback.', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"');}}}if(class_exists($class,false)){$callback=array(new$class($this),'process');}elseif(function_exists($class)){$callback=$class;}else{thrownewDwoo_Exception('Wrong filter name : '.$callback.', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"');}$this->filters[]=$callback;}else{$this->filters[]=$callback;}}publicfunctionremoveFilter($callback){if(($index=array_search('Dwoo_Filter_'.$callback,$this->filters,true))!==false){unset($this->filters[$index]);}elseif(($index=array_search($callback,$this->filters,true))!==false){unset($this->filters[$index]);}else{$class='Dwoo_Filter_'.$callback;foreach($this->filtersas$index=>$filter){if(is_array($filter)&&$filter[0]instanceof$class){unset($this->filters[$index]);break;}}}}publicfunctionaddResource($name,$class,$compilerFactory=null){if(strlen($name)<2){thrownewDwoo_Exception('Resource names must be at least two-character long to avoid conflicts with Windows paths');}if(!class_exists($class)){thrownewDwoo_Exception('Resource class does not exist');}$interfaces=class_implements($class);if(in_array('Dwoo_ITemplate',$interfaces)===false){thrownewDwoo_Exception('Resource class must implement Dwoo_ITemplate');}$this->resources[$name]=array('class'=>$class,'compiler'=>$compilerFactory);}publicfunctionremoveResource($name){unset($this->resources[$name]);if($name==='file'){$this->resources['file']=array('class'=>'Dwoo_Template_File','compiler'=>null);}}publicfunctionsetLoader(Dwoo_ILoader$loader){$this->loader=$loader;}publicfunctiongetLoader(){if($this->loader===null){$this->loader=newDwoo_Loader($this->getCompileDir());}return$this->loader;}publicfunctiongetCustomPlugins(){return$this->plugins;}publicfunctiongetCacheDir(){if($this->cacheDir===null){$this->setCacheDir(dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR);}return$this->cacheDir;}publicfunctionsetCacheDir($dir){$this->cacheDir=rtrim($dir,'/\\').DIRECTORY_SEPARATOR;if(is_writable($this->cacheDir)===false){thrownewDwoo_Exception('The cache directory must be writable, chmod "'.$this->cacheDir.'" to make it writable');}}publicfunctiongetCompileDir(){if($this->compileDir===null){$this->setCompileDir(dirname(__FILE__).DIRECTORY_SEPARATOR.'compiled'.DIRECTORY_SEPARATOR);}return$this->compileDir;}publicfunctionsetCompileDir($dir){$this->compileDir=rtrim($dir,'/\\').DIRECTORY_SEPARATOR;if(is_writable($this->compileDir)===false){thrownewDwoo_Exception('The compile directory must be writable, chmod "'.$this->compileDir.'" to make it writable');}}publicfunctiongetCacheTime(){return$this->cacheTime;}publicfunctionsetCacheTime($seconds){$this->cacheTime=(int)$seconds;}publicfunctiongetCharset(){return$this->charset;}publicfunctionsetCharset($charset){$this->charset=strtolower((string)$charset);}publicfunctiongetTemplate(){return$this->template;}publicfunctionsetDefaultCompilerFactory($resourceName,$compilerFactory){$this->resources[$resourceName]['compiler']=$compilerFactory;}publicfunctiongetDefaultCompilerFactory($resourceName){return$this->resources[$resourceName]['compiler'];}publicfunctionsetSecurityPolicy(Dwoo_Security_Policy$policy=null){$this->securityPolicy=$policy;}publicfunctiongetSecurityPolicy(){return$this->securityPolicy;}publicfunctionsetPluginProxy(Dwoo_IPluginProxy$pluginProxy){$this->pluginProxy=$pluginProxy;}publicfunctiongetPluginProxy(){return$this->pluginProxy;}publicfunctionisCached(Dwoo_ITemplate$tpl){returnis_string($tpl->getCachedTemplate($this));}publicfunctionclearCache($olderThan=-1){$cacheDirs=newRecursiveDirectoryIterator($this->getCacheDir());$cache=newRecursiveIteratorIterator($cacheDirs);$expired=time()-$olderThan;$count=0;foreach($cacheas$file){if($cache->isDot()||$cache->isDir()||substr($file,-5)!=='.html'){continue;}if($cache->getCTime()<$expired){$count+=unlink((string)$file)?1:0;}}return$count;}publicfunctiontemplateFactory($resourceName,$resourceId,$cacheTime=null,$cacheId=null,$compileId=null,Dwoo_ITemplate$parentTemplate=null){if(isset($this->resources[$resourceName])){returncall_user_func(array($this->resources[$resourceName]['class'],'templateFactory'),$this,$resourceId,$cacheTime,$cacheId,$compileId,$parentTemplate);}else{thrownewDwoo_Exception('Unknown resource type : '.$resourceName);}}publicfunctionisArray($value,$checkIsEmpty=false,$allowNonCountable=false){if(is_array($value)===true){if($checkIsEmpty===false){returntrue;}else{returncount($value)>0;}}elseif($valueinstanceofIterator||$valueinstanceofArrayAccess){if($checkIsEmpty===false){returntrue;}else{if($allowNonCountable===false){returncount($value)>0;}else{if($valueinstanceofCountable){returncount($value)>0;}else{$value->rewind();return$value->valid();}}}}returnfalse;}publicfunctiontriggerError($message,$level=E_USER_NOTICE){if(!($tplIdentifier=$this->template->getResourceIdentifier())){$tplIdentifier=$this->template->getResourceName();}trigger_error('Dwoo error (in '.$tplIdentifier.') : '.$message,$level);}publicfunctionaddStack($blockName,array$args=array()){if(isset($this->plugins[$blockName])){$class=$this->plugins[$blockName]['class'];}else{$class='Dwoo_Plugin_'.$blockName;}if($this->curBlock!==null){$this->curBlock->buffer(ob_get_contents());ob_clean();}else{$this->buffer.=ob_get_contents();ob_clean();}$block=new$class($this);$cnt=count($args);if($cnt===0){$block->init();}elseif($cnt===1){$block->init($args[0]);}elseif($cnt===2){$block->init($args[0],$args[1]);}elseif($cnt===3){$block->init($args[0],$args[1],$args[2]);}elseif($cnt===4){$block->init($args[0],$args[1],$args[2],$args[3]);}else{call_user_func_array(array($block,'init'),$args);}$this->stack[]=$this->curBlock=$block;return$block;}publicfunctiondelStack(){$args=func_get_args();$this->curBlock->buffer(ob_get_contents());ob_clean();$cnt=count($args);if($cnt===0){$this->curBlock->end();}elseif($cnt===1){$this->curBlock->end($args[0]);}elseif($cnt===2){$this->curBlock->end($args[0],$args[1]);}elseif($cnt===3){$this->curBlock->end($args[0],$args[1],$args[2]);}elseif($cnt===4){$this->curBlock->end($args[0],$args[1],$args[2],$args[3]);}else{call_user_func_array(array($this->curBlock,'end'),$args);}$tmp=array_pop($this->stack);if(count($this->stack)>0){$this->curBlock=end($this->stack);$this->curBlock->buffer($tmp->process());}else{$this->curBlock=null;echo$tmp->process();}unset($tmp);}publicfunctiongetParentBlock(Dwoo_Block_Plugin$block){$index=array_search($block,$this->stack,true);if($index!==false&&$index>0){return$this->stack[$index-1];}returnfalse;}publicfunctionfindBlock($type){if(isset($this->plugins[$type])){$type=$this->plugins[$type]['class'];}else{$type='Dwoo_Plugin_'.str_replace('Dwoo_Plugin_','',$type);}$keys=array_keys($this->stack);while(($key=array_pop($keys))!==false){if($this->stack[$key]instanceof$type){return$this->stack[$key];}}returnfalse;}protectedfunctiongetObjectPlugin($class){if(isset($this->runtimePlugins[$class])){return$this->runtimePlugins[$class];}return$this->runtimePlugins[$class]=new$class($this);}publicfunctionclassCall($plugName,array$params=array()){$class='Dwoo_Plugin_'.$plugName;$plugin=$this->getObjectPlugin($class);$cnt=count($params);if($cnt===0){return$plugin->process();}elseif($cnt===1){return$plugin->process($params[0]);}elseif($cnt===2){return$plugin->process($params[0],$params[1]);}elseif($cnt===3){return$plugin->process($params[0],$params[1],$params[2]);}elseif($cnt===4){return$plugin->process($params[0],$params[1],$params[2],$params[3]);}else{returncall_user_func_array(array($plugin,'process'),$params);}}publicfunctionarrayMap($callback,array$params){if($params[0]===$this){$addThis=true;array_shift($params);}if((is_array($params[0])||($params[0]instanceofIterator&&$params[0]instanceofArrayAccess))){if(empty($params[0])){return$params[0];}$out=array();$cnt=count($params);if(isset($addThis)){array_unshift($params,$this);$items=$params[1];$keys=array_keys($items);if(is_string($callback)===false){while(($i=array_shift($keys))!==null){$out[]=call_user_func_array($callback,array(1=>$items[$i])+$params);}}elseif($cnt===1){while(($i=array_shift($keys))!==null){$out[]=$callback($this,$items[$i]);}}elseif($cnt===2){while(($i=array_shift($keys))!==null){$out[]=$callback($this,$items[$i],$params[2]);}}elseif($cnt===3){while(($i=array_shift($keys))!==null){$out[]=$callback($this,$items[$i],$params[2],$params[3]);}}else{while(($i=array_shift($keys))!==null){$out[]=call_user_func_array($callback,array(1=>$items[$i])+$params);}}}else{$items=$params[0];$keys=array_keys($items);if(is_string($callback)===false){while(($i=array_shift($keys))!==null){$out[]=call_user_func_array($callback,array($items[$i])+$params);}}elseif($cnt===1){while(($i=array_shift($keys))!==null){$out[]=$callback($items[$i]);}}elseif($cnt===2){while(($i=array_shift($keys))!==null){$out[]=$callback($items[$i],$params[1]);}}elseif($cnt===3){while(($i=array_shift($keys))!==null){$out[]=$callback($items[$i],$params[1],$params[2]);}}elseif($cnt===4){while(($i=array_shift($keys))!==null){$out[]=$callback($items[$i],$params[1],$params[2],$params[3]);}}else{while(($i=array_shift($keys))!==null){$out[]=call_user_func_array($callback,array($items[$i])+$params);}}}return$out;}else{return$params[0];}}publicfunctionreadVarInto($varstr,$data){if($data===null){returnnull;}if(is_array($varstr)===false){preg_match_all('#(\[|->|\.)?([^.[\]-]+)\]?#i',$varstr,$m);}else{$m=$varstr;}unset($varstr);while(list($k,$sep)=each($m[1])){if($sep==='.'||$sep==='['||$sep===''){if((is_array($data)||$datainstanceofArrayAccess)&&isset($data[$m[2][$k]])){$data=$data[$m[2][$k]];}else{returnnull;}}else{if(is_object($data)){$data=$data->$m[2][$k];}else{returnnull;}}}return$data;}publicfunctionreadParentVar($parentLevels,$varstr=null){$tree=$this->scopeTree;$cur=$this->data;while($parentLevels--!==0){array_pop($tree);}while(($i=array_shift($tree))!==null){if(is_object($cur)){$cur=$cur->$i;}else{$cur=$cur[$i];}}if($varstr!==null){return$this->readVarInto($varstr,$cur);}else{return$cur;}}publicfunctionreadVar($varstr){if(is_array($varstr)===true){$m=$varstr;unset($varstr);}else{if(strstr($varstr,'.')===false&&strstr($varstr,'[')===false&&strstr($varstr,'->')===false){if($varstr==='dwoo'){return$this->globals;}elseif($varstr==='__'||$varstr==='_root'){return$this->data;$varstr=substr($varstr,6);}elseif($varstr==='_'||$varstr==='_parent'){$varstr='.'.$varstr;$tree=$this->scopeTree;$cur=$this->data;array_pop($tree);while(($i=array_shift($tree))!==null){if(is_object($cur)){$cur=$cur->$i;}else{$cur=$cur[$i];}}return$cur;}$cur=$this->scope;if(isset($cur[$varstr])){return$cur[$varstr];}else{returnnull;}}if(substr($varstr,0,1)==='.'){$varstr='dwoo'.$varstr;}preg_match_all('#(\[|->|\.)?([^.[\]-]+)\]?#i',$varstr,$m);}$i=$m[2][0];if($i==='dwoo'){$cur=$this->globals;array_shift($m[2]);array_shift($m[1]);switch($m[2][0]){case'get':$cur=$_GET;break;case'post':$cur=$_POST;break;case'session':$cur=$_SESSION;break;case'cookies':case'cookie':$cur=$_COOKIE;break;case'server':$cur=$_SERVER;break;case'env':$cur=$_ENV;break;case'request':$cur=$_REQUEST;break;case'const':array_shift($m[2]);if(defined($m[2][0])){returnconstant($m[2][0]);}else{returnnull;}}if($cur!==$this->globals){array_shift($m[2]);array_shift($m[1]);}}elseif($i==='__'||$i==='_root'){$cur=$this->data;array_shift($m[2]);array_shift($m[1]);}elseif($i==='_'||$i==='_parent'){$tree=$this->scopeTree;$cur=$this->data;while(true){array_pop($tree);array_shift($m[2]);array_shift($m[1]);if(current($m[2])==='_'||current($m[2])==='_parent'){continue;}while(($i=array_shift($tree))!==null){if(is_object($cur)){$cur=$cur->$i;}else{$cur=$cur[$i];}}break;}}else{$cur=$this->scope;}while(list($k,$sep)=each($m[1])){if($sep==='.'||$sep==='['||$sep===''){if((is_array($cur)||$curinstanceofArrayAccess)&&isset($cur[$m[2][$k]])){$cur=$cur[$m[2][$k]];}else{returnnull;}}elseif($sep==='->'){if(is_object($cur)){$cur=$cur->$m[2][$k];}else{returnnull;}}else{returnnull;}}return$cur;}publicfunctionassignInScope($value,$scope){$tree=&$this->scopeTree;$data=&$this->data;if(!is_string($scope)){return$this->triggerError('Assignments must be done into strings, ('.gettype($scope).') '.var_export($scope,true).' given',E_USER_ERROR);}if(strstr($scope,'.')===false&&strstr($scope,'->')===false){$this->scope[$scope]=$value;}else{preg_match_all('#(\[|->|\.)?([^.[\]-]+)\]?#i',$scope,$m);$cur=&$this->scope;$last=array(array_pop($m[1]),array_pop($m[2]));while(list($k,$sep)=each($m[1])){if($sep==='.'||$sep==='['||$sep===''){if(is_array($cur)===false){$cur=array();}$cur=&$cur[$m[2][$k]];}elseif($sep==='->'){if(is_object($cur)===false){$cur=newstdClass;}$cur=&$cur->$m[2][$k];}else{returnfalse;}}if($last[0]==='.'||$last[0]==='['||$last[0]===''){if(is_array($cur)===false){$cur=array();}$cur[$last[1]]=$value;}elseif($last[0]==='->'){if(is_object($cur)===false){$cur=newstdClass;}$cur->$last[1]=$value;}else{returnfalse;}}}publicfunctionsetScope($scope,$absolute=false){$old=$this->scopeTree;if(is_string($scope)===true){$scope=explode('.',$scope);}if($absolute===true){$this->scope=&$this->data;$this->scopeTree=array();}while(($bit=array_shift($scope))!==null){if($bit==='_'||$bit==='_parent'){array_pop($this->scopeTree);$this->scope=&$this->data;$cnt=count($this->scopeTree);for($i=0;$i<$cnt;$i++)$this->scope=&$this->scope[$this->scopeTree[$i]];}elseif($bit==='__'||$bit==='_root'){$this->scope=&$this->data;$this->scopeTree=array();}elseif(isset($this->scope[$bit])){$this->scope=&$this->scope[$bit];$this->scopeTree[]=$bit;}else{unset($this->scope);$this->scope=null;}}return$old;}publicfunctiongetData(){return$this->data;}publicfunction&getScope(){return$this->scope;}publicfunctionforceScope($scope){return$this->setScope($scope,true);}}interfaceDwoo_IPluginProxy{publicfunctionhandles($name);publicfunctiongetCode($name,$params);publicfunctiongetCallback($name);publicfunctiongetLoader($name);}interfaceDwoo_IElseable{}interfaceDwoo_ILoader{publicfunctionloadPlugin($class,$forceRehash=true);}classDwoo_LoaderimplementsDwoo_ILoader{protected$paths=array();protected$classPath=array();protected$cacheDir;protected$corePluginDir;publicfunction__construct($cacheDir){$this->corePluginDir=DWOO_DIRECTORY.'plugins';$this->cacheDir=$cacheDir.DIRECTORY_SEPARATOR;$foo=@file_get_contents($this->cacheDir.'classpath.cache.d'.Dwoo::RELEASE_TAG.'.php');if($foo){$this->classPath=unserialize($foo)+$this->classPath;}else{$this->rebuildClassPathCache($this->corePluginDir,$this->cacheDir.'classpath.cache.d'.Dwoo::RELEASE_TAG.'.php');}}protectedfunctionrebuildClassPathCache($path,$cacheFile){if($cacheFile!==false){$tmp=$this->classPath;$this->classPath=array();}$list=glob($path.DIRECTORY_SEPARATOR.'*');if(is_array($list)){foreach($listas$f){if(is_dir($f)){$this->rebuildClassPathCache($f,false);}else{$this->classPath[str_replace(array('function.','block.','modifier.','outputfilter.','filter.','prefilter.','postfilter.','pre.','post.','output.','shared.','helper.'),'',basename($f,'.php'))]=$f;}}}if($cacheFile!==false){if(!file_put_contents($cacheFile,serialize($this->classPath))){thrownewDwoo_Exception('Could not write into '.$cacheFile.', either because the folder is not there (create it) or because of the chmod configuration (please ensure this directory is writable by php), alternatively you can change the directory used with $dwoo->setCompileDir() or provide a custom loader object with $dwoo->setLoader()');}$this->classPath+=$tmp;}}publicfunctionloadPlugin($class,$forceRehash=true){if(!isset($this->classPath[$class])||!(include$this->classPath[$class])){if($forceRehash){$this->rebuildClassPathCache($this->corePluginDir,$this->cacheDir.'classpath.cache.d'.Dwoo::RELEASE_TAG.'.php');foreach($this->pathsas$path=>$file){$this->rebuildClassPathCache($path,$file);}if(isset($this->classPath[$class])){include$this->classPath[$class];}else{thrownewDwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?',E_USER_NOTICE);}}else{thrownewDwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?',E_USER_NOTICE);}}}publicfunctionaddDirectory($pluginDirectory){$pluginDir=realpath($pluginDirectory);if(!$pluginDir){thrownewDwoo_Exception('Plugin directory does not exist or can not be read : '.$pluginDirectory);}$cacheFile=$this->cacheDir.'classpath-'.substr(strtr($pluginDir,'/\\:'.PATH_SEPARATOR,'----'),strlen($pluginDir)>80?-80:0).'.d'.Dwoo::RELEASE_TAG.'.php';$this->paths[$pluginDir]=$cacheFile;$foo=@file_get_contents($cacheFile);if($foo){$this->classPath=unserialize($foo)+$this->classPath;}else{$this->rebuildClassPathCache($pluginDir,$cacheFile);}}}classDwoo_ExceptionextendsException{}classDwoo_Security_Policy{constPHP_ENCODE=1;constPHP_REMOVE=2;constPHP_ALLOW=3;constCONST_DISALLOW=false;constCONST_ALLOW=true;protected$allowedPhpFunctions=array('str_repeat','number_format','htmlentities','htmlspecialchars','long2ip','strlen','list','empty','count','sizeof','in_array','is_array',);protected$allowedDirectories=array();protected$phpHandling=self::PHP_REMOVE;protected$constHandling=self::CONST_DISALLOW;publicfunctionallowPhpFunction($func){if(is_array($func))foreach($funcas$fname)$this->allowedPhpFunctions[strtolower($fname)]=true;else$this->allowedPhpFunctions[strtolower($func)]=true;}publicfunctiondisallowPhpFunction($func){if(is_array($func))foreach($funcas$fname)unset($this->allowedPhpFunctions[strtolower($fname)]);elseunset($this->allowedPhpFunctions[strtolower($func)]);}publicfunctiongetAllowedPhpFunctions(){return$this->allowedPhpFunctions;}publicfunctionallowDirectory($path){if(is_array($path))foreach($pathas$dir)$this->allowedDirectories[realpath($dir)]=true;else$this->allowedDirectories[realpath($path)]=true;}publicfunctiondisallowDirectory($path){if(is_array($path))foreach($pathas$dir)unset($this->allowedDirectories[realpath($dir)]);elseunset($this->allowedDirectories[realpath($path)]);}publicfunctiongetAllowedDirectories(){return$this->allowedDirectories;}publicfunctionsetPhpHandling($level=self::PHP_REMOVE){$this->phpHandling=$level;}publicfunctiongetPhpHandling(){return$this->phpHandling;}publicfunctionsetConstantHandling($level=self::CONST_DISALLOW){$this->constHandling=$level;}publicfunctiongetConstantHandling(){return$this->constHandling;}}classDwoo_Security_ExceptionextendsDwoo_Exception{}interfaceDwoo_ICompilable{}interfaceDwoo_ICompiler{publicfunctioncompile(Dwoo$dwoo,Dwoo_ITemplate$template);publicfunctionsetCustomPlugins(array$customPlugins);publicfunctionsetSecurityPolicy(Dwoo_Security_Policy$policy=null);}interfaceDwoo_IDataProvider{publicfunctiongetData();}interfaceDwoo_ITemplate{publicfunctiongetCacheTime();publicfunctionsetCacheTime($seconds=null);publicfunctiongetCachedTemplate(Dwoo$dwoo);publicfunctioncache(Dwoo$dwoo,$output);publicfunctionclearCache(Dwoo$dwoo,$olderThan=-1);publicfunctiongetCompiledTemplate(Dwoo$dwoo,Dwoo_ICompiler$compiler=null);publicfunctiongetName();publicfunctiongetResourceName();publicfunctiongetResourceIdentifier();publicfunctiongetSource();publicfunctiongetUid();publicfunctiongetCompiler();publicstaticfunctiontemplateFactory(Dwoo$dwoo,$resourceId,$cacheTime=null,$cacheId=null,$compileId=null,Dwoo_ITemplate$parentTemplate=null);}interfaceDwoo_ICompilable_Block{}abstractclassDwoo_Plugin{protected$dwoo;publicfunction__construct(Dwoo$dwoo){$this->dwoo=$dwoo;}publicstaticfunctionparamsToAttributes(array$params,$delim='\''){if(isset($params['*'])){$params=array_merge($params,$params['*']);unset($params['*']);}$out='';foreach($paramsas$attr=>$val){$out.=' '.$attr.'=';if(trim($val,'"\'')==''||$val=='null'){$out.=str_replace($delim,'\\'.$delim,'""');}elseif(substr($val,0,1)===$delim&&substr($val,-1)===$delim){$out.=str_replace($delim,'\\'.$delim,'"'.substr($val,1,-1).'"');}else{$out.=str_replace($delim,'\\'.$delim,'"').$delim.'.'.$val.'.'.$delim.str_replace($delim,'\\'.$delim,'"');}}returnltrim($out);}}abstractclassDwoo_Block_PluginextendsDwoo_Plugin{protected$buffer='';publicfunctionbuffer($input){$this->buffer.=$input;}publicfunctionend(){}publicfunctionprocess(){return$this->buffer;}publicstaticfunctionpreProcessing(Dwoo_Compiler$compiler,array$params,$prepend,$append,$type){returnDwoo_Compiler::PHP_OPEN.$prepend.'$this->addStack("'.$type.'", array('.Dwoo_Compiler::implode_r($compiler->getCompiledParams($params)).'));'.$append.Dwoo_Compiler::PHP_CLOSE;}publicstaticfunctionpostProcessing(Dwoo_Compiler$compiler,array$params,$prepend,$append,$content){return$content.Dwoo_Compiler::PHP_OPEN.$prepend.'$this->delStack();'.$append.Dwoo_Compiler::PHP_CLOSE;}}abstractclassDwoo_Filter{protected$dwoo;publicfunction__construct(Dwoo$dwoo){$this->dwoo=$dwoo;}abstractpublicfunctionprocess($input);}abstractclassDwoo_Processor{protected$compiler;publicfunction__construct(Dwoo_Compiler$compiler){$this->compiler=$compiler;}abstractpublicfunctionprocess($input);}classDwoo_Template_StringimplementsDwoo_ITemplate{protected$name;protected$compileId;protected$cacheId;protected$cacheTime;protected$compilationEnforced;protectedstatic$cache=array('cached'=>array(),'compiled'=>array());protected$compiler;protected$chmod=0777;publicfunction__construct($templateString,$cacheTime=null,$cacheId=null,$compileId=null){$this->template=$templateString;if(function_exists('hash')){$this->name=hash('md4',$templateString);}else{$this->name=md5($templateString);}$this->cacheTime=$cacheTime;if($compileId!==null){$this->compileId=str_replace('../','__',strtr($compileId,'\\%?=!:;'.PATH_SEPARATOR,'/-------'));}if($cacheId!==null){$this->cacheId=str_replace('../','__',strtr($cacheId,'\\%?=!:;'.PATH_SEPARATOR,'/-------'));}}publicfunctiongetCacheTime(){return$this->cacheTime;}publicfunctionsetCacheTime($seconds=null){$this->cacheTime=$seconds;}publicfunctiongetChmod(){return$this->chmod;}publicfunctionsetChmod($mask=null){$this->chmod=$mask;}publicfunctiongetName(){return$this->name;}publicfunctiongetResourceName(){return'string';}publicfunctiongetResourceIdentifier(){returnfalse;}publicfunctiongetSource(){return$this->template;}publicfunctiongetUid(){return$this->name;}publicfunctiongetCompiler(){return$this->compiler;}publicfunctionforceCompilation(){$this->compilationEnforced=true;}publicfunctiongetCachedTemplate(Dwoo$dwoo){if($this->cacheTime!==null){$cacheLength=$this->cacheTime;}else{$cacheLength=$dwoo->getCacheTime();}if($cacheLength===0){returnfalse;}$cachedFile=$this->getCacheFilename($dwoo);if(isset(self::$cache['cached'][$this->cacheId])===true&&file_exists($cachedFile)){return$cachedFile;}elseif($this->compilationEnforced!==true&&file_exists($cachedFile)&&($cacheLength===-1||filemtime($cachedFile)>($_SERVER['REQUEST_TIME']-$cacheLength))){self::$cache['cached'][$this->cacheId]=true;return$cachedFile;}else{returntrue;}}publicfunctioncache(Dwoo$dwoo,$output){$cacheDir=$dwoo->getCacheDir();$cachedFile=$this->getCacheFilename($dwoo);$temp=tempnam($cacheDir,'temp');if(!($file=@fopen($temp,'wb'))){$temp=$cacheDir.DIRECTORY_SEPARATOR.uniqid('temp');if(!($file=@fopen($temp,'wb'))){trigger_error('Error writing temporary file \''.$temp.'\'',E_USER_WARNING);returnfalse;}}fwrite($file,$output);fclose($file);$this->makeDirectory(dirname($cachedFile));if(!@rename($temp,$cachedFile)){@unlink($cachedFile);@rename($temp,$cachedFile);}if($this->chmod!==null){chmod($cachedFile,$this->chmod);}self::$cache['cached'][$this->cacheId]=true;return$cachedFile;}publicfunctionclearCache(Dwoo$dwoo,$olderThan=-1){$cachedFile=$this->getCacheFilename($dwoo);return!file_exists($cachedFile)||(filectime($cachedFile)<(time()-$olderThan)&&unlink($cachedFile));}publicfunctiongetCompiledTemplate(Dwoo$dwoo,Dwoo_ICompiler$compiler=null){$compiledFile=$this->getCompiledFilename($dwoo);if($this->compilationEnforced!==true&&isset(self::$cache['compiled'][$this->compileId])===true){}elseif($this->compilationEnforced!==true&&$this->isValidCompiledFile($compiledFile)){self::$cache['compiled'][$this->compileId]=true;}else{$this->compilationEnforced=false;if($compiler===null){$compiler=$dwoo->getDefaultCompilerFactory($this->getResourceName());if($compiler===null||$compiler===array('Dwoo_Compiler','compilerFactory')){if(class_exists('Dwoo_Compiler',false)===false){includeDWOO_DIRECTORY.'Dwoo/Compiler.php';}$compiler=Dwoo_Compiler::compilerFactory();}else{$compiler=call_user_func($compiler);}}$this->compiler=$compiler;$compiler->setCustomPlugins($dwoo->getCustomPlugins());$compiler->setSecurityPolicy($dwoo->getSecurityPolicy());$this->makeDirectory(dirname($compiledFile));file_put_contents($compiledFile,$compiler->compile($dwoo,$this));if($this->chmod!==null){chmod($compiledFile,$this->chmod);}self::$cache['compiled'][$this->compileId]=true;}return$compiledFile;}protectedfunctionisValidCompiledFile($file){returnfile_exists($file);}publicstaticfunctiontemplateFactory(Dwoo$dwoo,$resourceId,$cacheTime=null,$cacheId=null,$compileId=null,Dwoo_ITemplate$parentTemplate=null){returnnewself($resourceId,$cacheTime,$cacheId,$compileId);}protectedfunctiongetCompiledFilename(Dwoo$dwoo){if($this->compileId===null){$this->compileId=$this->name;}return$dwoo->getCompileDir().$this->compileId.'.d'.Dwoo::RELEASE_TAG.'.php';}protectedfunctiongetCacheFilename(Dwoo$dwoo){if($this->cacheId===null){if(isset($_SERVER['REQUEST_URI'])===true){$cacheId=$_SERVER['REQUEST_URI'];}elseif(isset($_SERVER['SCRIPT_FILENAME'])&&isset($_SERVER['argv'])){$cacheId=$_SERVER['SCRIPT_FILENAME'].'-'.implode('-',$_SERVER['argv']);}else{$cacheId='';}$this->getCompiledFilename($dwoo);$this->cacheId=str_replace('../','__',$this->compileId.strtr($cacheId,'\\%?=!:;'.PATH_SEPARATOR,'/-------'));}return$dwoo->getCacheDir().$this->cacheId.'.html';}protectedfunctionmakeDirectory($path){if(is_dir($path)===true){return;}if($this->chmod!==null){mkdir($path,$this->chmod,true);}else{mkdir($path,0777,true);}}}classDwoo_Template_FileextendsDwoo_Template_String{protected$file;protected$includePath=null;protected$resolvedPath=null;publicfunction__construct($file,$cacheTime=null,$cacheId=null,$compileId=null,$includePath=null){$this->file=$file;$this->name=basename($file);$this->cacheTime=$cacheTime;if($compileId!==null){$this->compileId=str_replace('../','__',strtr($compileId,'\\%?=!:;'.PATH_SEPARATOR,'/-------'));}if($cacheId!==null){$this->cacheId=str_replace('../','__',strtr($cacheId,'\\%?=!:;'.PATH_SEPARATOR,'/-------'));}if(is_string($includePath)){$this->includePath=array($includePath);}elseif(is_array($includePath)){$this->includePath=$includePath;}}publicfunctionsetIncludePath($paths){if(is_array($paths)===false){$paths=array($paths);}$this->includePath=$paths;$this->resolvedPath=null;}publicfunctiongetIncludePath(){return$this->includePath;}protectedfunctionisValidCompiledFile($file){returnparent::isValidCompiledFile($file)&&(int)$this->getUid()<=filemtime($file);}publicfunctiongetSource(){returnfile_get_contents($this->getResourceIdentifier());}publicfunctiongetResourceName(){return'file';}publicfunctiongetResourceIdentifier(){if($this->resolvedPath!==null){return$this->resolvedPath;}elseif($this->includePath===null){return$this->file;}else{foreach($this->includePathas$path){if(file_exists($path.DIRECTORY_SEPARATOR.$this->file)===true){$this->resolvedPath=$path.DIRECTORY_SEPARATOR.$this->file;return$this->resolvedPath;}}thrownewDwoo_Exception('Template "'.$this->file.'" could not be found in any of your include path(s)');}}publicfunctiongetUid(){return(string)filemtime($this->getResourceIdentifier());}publicstaticfunctiontemplateFactory(Dwoo$dwoo,$resourceId,$cacheTime=null,$cacheId=null,$compileId=null,Dwoo_ITemplate$parentTemplate=null){if(DIRECTORY_SEPARATOR==='\\'){$resourceId=str_replace(array("\t","\n","\r","\f","\v"),array('\\t','\\n','\\r','\\f','\\v'),$resourceId);}$resourceId=strtr($resourceId,'\\','/');$includePath=null;if(file_exists($resourceId)===false){if($parentTemplate===null){$parentTemplate=$dwoo->getTemplate();}if($parentTemplateinstanceofDwoo_Template_File){if($includePath=$parentTemplate->getIncludePath()){if(strstr($resourceId,'../')){thrownewDwoo_Exception('When using an include path you can not reference a template into a parent directory (using ../)');}}else{$resourceId=dirname($parentTemplate->getResourceIdentifier()).DIRECTORY_SEPARATOR.$resourceId;if(file_exists($resourceId)===false){returnnull;}}}else{returnnull;}}if($policy=$dwoo->getSecurityPolicy()){while(true){if(preg_match('{^([a-z]+?)://}i',$resourceId)){thrownewDwoo_Security_Exception('The security policy prevents you to read files from external sources : <em>'.$resourceId.'</em>.');}if($includePath){break;}$resourceId=realpath($resourceId);$dirs=$policy->getAllowedDirectories();foreach($dirsas$dir=>$dummy){if(strpos($resourceId,$dir)===0){break2;}}thrownewDwoo_Security_Exception('The security policy prevents you to read <em>'.$resourceId.'</em>');}}returnnewDwoo_Template_File($resourceId,$cacheTime,$cacheId,$compileId,$includePath);}protectedfunctiongetCompiledFilename(Dwoo$dwoo){if($this->compileId===null){$this->compileId=str_replace('../','__',strtr($this->getResourceIdentifier(),'\\:','/-'));}return$dwoo->getCompileDir().$this->compileId.'.d'.Dwoo::RELEASE_TAG.'.php';}}classDwoo_DataimplementsDwoo_IDataProvider{protected$data=array();publicfunctiongetData(){return$this->data;}publicfunctionclear($name=null){if($name===null){$this->data=array();}elseif(is_array($name)){foreach($nameas$index)unset($this->data[$index]);}else{unset($this->data[$name]);}}publicfunctionsetData(array$data){$this->data=$data;}publicfunctionmergeData(array$data){$args=func_get_args();while(list(,$v)=each($args)){if(is_array($v)){$this->data=array_merge($this->data,$v);}}}publicfunctionassign($name,$val=null){if(is_array($name)){reset($name);while(list($k,$v)=each($name))$this->data[$k]=$v;}else{$this->data[$name]=$val;}}publicfunction__set($name,$value){$this->assign($name,$value);}publicfunctionassignByRef($name,&$val){$this->data[$name]=&$val;}publicfunctionappend($name,$val=null,$merge=false){if(is_array($name)){foreach($nameas$key=>$val){if(isset($this->data[$key])&&!is_array($this->data[$key])){settype($this->data[$key],'array');}if($merge===true&&is_array($val)){$this->data[$key]=$val+$this->data[$key];}else{$this->data[$key][]=$val;}}}elseif($val!==null){if(isset($this->data[$name])&&!is_array($this->data[$name])){settype($this->data[$name],'array');}if($merge===true&&is_array($val)){$this->data[$name]=$val+$this->data[$name];}else{$this->data[$name][]=$val;}}}publicfunctionappendByRef($name,&$val,$merge=false){if(isset($this->data[$name])&&!is_array($this->data[$name])){settype($this->data[$name],'array');}if($merge===true&&is_array($val)){foreach($valas$key=>&$val){$this->data[$name][$key]=&$val;}}else{$this->data[$name][]=&$val;}}publicfunctionisAssigned($name){returnisset($this->data[$name]);}publicfunction__isset($name){returnisset($this->data[$name]);}publicfunctionunassign($name){unset($this->data[$name]);}publicfunction__unset($name){unset($this->data[$name]);}publicfunctionget($name){return$this->__get($name);}publicfunction__get($name){if(isset($this->data[$name])){return$this->data[$name];}else{thrownewDwoo_Exception('Tried to read a value that was not assigned yet : "'.$name.'"');}}}
thrownewDwoo_Exception('DWOO_CACHE_DIRECTORY is deprecated, you should now set this in Dwoo\'s constructor using new Dwoo([ $compileDir [, $cacheDir ]])');
if(defined('DWOO_COMPILE_DIRECTORY'))
thrownewDwoo_Exception('DWOO_COMPILE_DIRECTORY is deprecated, you should now set this in Dwoo\'s constructor using new Dwoo([ $compileDir [, $cacheDir ]])');
if(defined('DWOO_CHMOD')){
thrownewDwoo_Exception('DWOO_CHMOD is deprecated, you should now set this on your template object using $tpl->setChmod('.DWOO_CHMOD.');');
}
// end
/**
* main dwoo class, allows communication between the compiler, template and data classes