set_include_path(get_include_path().PATH_SEPARATOR.dirname(__FILE__));define('DWOO_DIRECTORY',dirname(__FILE__).DIRECTORY_SEPARATOR);if(defined('DWOO_CACHE_DIRECTORY')===false)define('DWOO_CACHE_DIRECTORY',DWOO_DIRECTORY.'cache'.DIRECTORY_SEPARATOR);if(defined('DWOO_COMPILE_DIRECTORY')===false)define('DWOO_COMPILE_DIRECTORY',DWOO_DIRECTORY.'compiled'.DIRECTORY_SEPARATOR);if(defined('DWOO_CHMOD')===false)define('DWOO_CHMOD',0777);if(is_writable(DWOO_CACHE_DIRECTORY)===false)thrownewDwoo_Exception('Dwoo cache directory must be writable, either chmod "'.DWOO_CACHE_DIRECTORY.'" to make it writable or define DWOO_CACHE_DIRECTORY to a writable directory before including Dwoo.php');if(is_writable(DWOO_COMPILE_DIRECTORY)===false)thrownewDwoo_Exception('Dwoo compile directory must be writable, either chmod "'.DWOO_COMPILE_DIRECTORY.'" to make it writable or define DWOO_COMPILE_DIRECTORY to a writable directory before including Dwoo.php');if((file_exists(DWOO_COMPILE_DIRECTORY.DIRECTORY_SEPARATOR.'classpath.cache.php')&&includeDWOO_COMPILE_DIRECTORY.DIRECTORY_SEPARATOR.'classpath.cache.php')===false)Dwoo_Loader::rebuildClassPathCache(DWOO_DIRECTORY.'plugins',DWOO_COMPILE_DIRECTORY.DIRECTORY_SEPARATOR.'classpath.cache.php');classDwoo{constVERSION="0.3.4";constRELEASE_TAG=8;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;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$template=null;protected$runtimePlugins;protected$data;protected$scope;protected$scopeTree;protected$stack;protected$curBlock;protected$buffer;publicfunction__construct(){$this->cacheDir=DWOO_CACHE_DIRECTORY.DIRECTORY_SEPARATOR;$this->compileDir=DWOO_COMPILE_DIRECTORY.DIRECTORY_SEPARATOR;}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);elseif(is_string($_tpl))$_tpl=newDwoo_Template_String($_tpl);elsethrownewDwoo_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;elsethrownewDwoo_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){readfile($file);$this->template=null;}else{$this->template=null;returnfile_get_contents($file);}}else{$out=include$_tpl->getCompiledTemplate($this,$_compiler);if($out===false){$_tpl->forceCompilation();$out=include$_tpl->getCompiledTemplate($this,$_compiler);}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);}$this->template=null;if($doCache===true){$_tpl->cache($this,$out);if($_output===true)echo$out;elsereturn$out;}else{if($_output===true)echo$out;elsereturn$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){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,'callback'=>$callback,'class'=>(is_object($callback[0])?get_class($callback[0]):$callback[0]));else$this->plugins[$name]=array('type'=>self::CLASS_PLUGIN,'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,'callback'=>$callback,'class'=>$callback);else$this->plugins[$name]=array('type'=>self::CLASS_PLUGIN,'callback'=>$callback,'class'=>$callback,'function'=>'process');}elseif(function_exists($callback)){$this->plugins[$name]=array('type'=>self::FUNC_PLUGIN,'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){$name=str_replace('Dwoo_Filter_','',$callback);$class='Dwoo_Filter_'.$name;if(!class_exists($class,false)&&!function_exists($class))Dwoo_Loader::loadPlugin($name);if(class_exists($class,false))$callback=array(new$class($this),'process');elseif(function_exists($class))$callback=$class;else$this->triggerError('Wrong filter name, 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"',E_USER_ERROR);$this->filters[]=$callback;}else{$this->filters[]=$callback;}}publicfunctionremoveFilter($callback){if(($index=array_search($callback,$this->filters,true))!==false)unset($this->filters[$index]);elseif(($index=array_search('Dwoo_Filter_'.str_replace('Dwoo_Filter_','',$callback),$this->filters,true))!==false)unset($this->filters[$index]);else{$class='Dwoo_Filter_'.str_replace('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');$interfaces=class_implements($class,false);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);}publicfunctiongetCustomPlugins(){return$this->plugins;}publicfunctiongetCacheDir(){return$this->cacheDir;}publicfunctionsetCacheDir($dir){$this->cacheDir=rtrim($dir,'/\\').DIRECTORY_SEPARATOR;}publicfunctiongetCompileDir(){return$this->compileDir;}publicfunctionsetCompileDir($dir){$this->compileDir=rtrim($dir,'/\\').DIRECTORY_SEPARATOR;}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;}publicfunctionisCached(Dwoo_ITemplate$tpl){returnis_string($tpl->getCachedTemplate($this));}publicfunctionclearCache($olderThan=-1){$cacheDirs=newRecursiveDirectoryIterator($this->cacheDir);$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){if(isset($this->resources[$resourceName]))returncall_user_func(array($this->resources[$resourceName]['class'],'templateFactory'),$this,$resourceId,$cacheTime,$cacheId,$compileId);elsethrownewDwoo_Exception('Unknown resource type : '.$resourceName);}publicfunctionisArray($value,$checkIsEmpty=false,$allowNonCountable=false){if(is_array($value)===true){if($checkIsEmpty===false)returntrue;elsereturncount($value)>0;}elseif($valueinstanceofIterator){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){trigger_error('Dwoo error: '.$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]);elsecall_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]);elsecall_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{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]);elsereturncall_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]);elsewhile(($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]);elsewhile(($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('#(\[|->|\.)?([a-z0-9_]+)\]?#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]];elsereturnnull;}else{if(is_object($data)&&property_exists($data,$m[2][$k]))$data=$data->$m[2][$k];elsereturnnull;}}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);elsereturn$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==='_root'||$varstr==='__'){return$this->data;$varstr=substr($varstr,6);}elseif($varstr==='_parent'||$varstr==='_'){$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];elsereturnnull;}if(substr($varstr,0,1)==='.')$varstr='dwoo'.$varstr;preg_match_all('#(\[|->|\.)?([a-z0-9_]+)\]?#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]);elsereturnnull;}if($cur!==$this->globals){array_shift($m[2]);array_shift($m[1]);}}elseif($i==='_root'||$i==='__'){$cur=$this->data;array_shift($m[2]);array_shift($m[1]);}elseif($i==='_parent'||$i==='_'){$tree=$this->scopeTree;$cur=$this->data;while(true){array_pop($tree);array_shift($m[2]);array_shift($m[1]);if(current($m[2])==='_parent'||current($m[2])==='_')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]];elsereturnnull;}elseif($sep==='->'){if(is_object($cur)&&property_exists($cur,$m[2][$k]))$cur=$cur->$m[2][$k];elsereturnnull;}elsereturnnull;}return$cur;}publicfunctionassignInScope($value,$scope){$tree=&$this->scopeTree;$data=&$this->data;if(strstr($scope,'.')===false&&strstr($scope,'->')===false){$this->scope[$scope]=$value;}else{preg_match_all('#(\[|->|\.)?([a-z0-9_]+)\]?#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];}elsereturnfalse;}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;}elsereturnfalse;}}publicfunctionsetScope($scope){$old=$this->scopeTree;if(empty($scope))return$old;if(is_array($scope)===false)$scope=explode('.',$scope);while(($bit=array_shift($scope))!==null){if($bit==='_parent'||$bit==='_'){array_pop($this->scopeTree);reset($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==='_root'||$bit==='__'){$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){$prev=$this->setScope(array('_root'));$this->setScope($scope);return$prev;}}classDwoo_Loader{protectedstatic$paths=array();publicstatic$classpath=array();publicstaticfunctionrebuildClassPathCache($path,$cacheFile){if($cacheFile!==false){$tmp=self::$classpath;self::$classpath=array();}$list=glob($path.DIRECTORY_SEPARATOR.'*');if(is_array($list))foreach($listas$f){if(is_dir($f))self::rebuildClassPathCache($f,false);elseself::$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,'<?php Dwoo_Loader::$classpath = '.var_export(self::$classpath,true).' + Dwoo_Loader::$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)');self::$classpath+=$tmp;}}publicstaticfunctionloadPlugin($class,$forceRehash=true){if(!isset(self::$classpath[$class])||!includeself::$classpath[$class]){if($forceRehash){self::rebuildClassPathCache(DWOO_DIRECTORY.'plugins',DWOO_COMPILE_DIRECTORY.DIRECTORY_SEPARATOR.'classpath.cache.php');foreach(self::$pathsas$path=>$file)self::rebuildClassPathCache($path,$file);if(isset(self::$classpath[$class]))includeself::$classpath[$class];elsethrownewDwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?',E_USER_NOTICE);}elsethrownewDwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?',E_USER_NOTICE);}}publicstaticfunctionaddDirectory($pluginDir){if(!isset(self::$paths[$pluginDir])){$cacheFile=DWOO_COMPILE_DIRECTORY.DIRECTORY_SEPARATOR.'classpath-'.substr(strtr($pluginDir,':/\\.','----'),strlen($pluginDir)>80?-80:0).'.cache.php';self::$paths[$pluginDir]=$cacheFile;if(file_exists($cacheFile))include$cacheFile;elseDwoo_Loader::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','count','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;}}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);}interfaceDwoo_ICompilable_Block{}abstractclassDwoo_Plugin{protected$dwoo;publicfunction__construct(Dwoo$dwoo){$this->dwoo=$dwoo;}}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('.implode(', ',$compiler->getCompiledParams($params)).'));'.$append.Dwoo_Compiler::PHP_CLOSE;}publicstaticfunctionpostProcessing(Dwoo_Compiler$compiler,array$params,$prepend='',$append=''){returnDwoo_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;publicfunction__construct($templateString,$cacheTime=null,$cacheId=null,$compileId=null){$this->template=$templateString;$this->name=hash('md4',$templateString);$this->cacheTime=$cacheTime;if($compileId!==null){$this->compileId=strtr($compileId,'\\%?=!:;'.PATH_SEPARATOR,'/-------');}if($cacheId!==null){$this->cacheId=strtr($cacheId,'\\%?=!:;'.PATH_SEPARATOR,'/-------');}}publicfunctiongetCacheTime(){return$this->cacheTime;}publicfunctionsetCacheTime($seconds=null){$this->cacheTime=$seconds;}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){$cachedFile=$this->getCacheFilename($dwoo);if($this->cacheTime!==null)$cacheLength=$this->cacheTime;else$cacheLength=$dwoo->getCacheTime();if($cacheLength===0){returnfalse;}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);}chmod($cachedFile,DWOO_CHMOD);self::$cache['cached'][$this->cacheId]=true;returntrue;}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&&file_exists($compiledFile)===true){self::$cache['compiled'][$this->compileId]=true;}else{$this->compilationEnforced=false;if($compiler===null){$compiler=$dwoo->getDefaultCompilerFactory('string');if($compiler===null||$compiler===array('Dwoo_Compiler','compilerFactory')){if(class_exists('Dwoo_Compiler',false)===false)include'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));chmod($compiledFile,DWOO_CHMOD);self::$cache['compiled'][$this->compileId]=true;}return$compiledFile;}publicstaticfunctiontemplateFactory(Dwoo$dwoo,$resourceId,$cacheTime=null,$cacheId=null,$compileId=null){returnfalse;}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']);$this->cacheId=strtr($cacheId,'\\%?=!:;'.PATH_SEPARATOR,'/-------');}return$dwoo->getCacheDir().$this->cacheId.'.html';}protectedfunctionmakeDirectory($path){if(is_dir($path)===true)return;mkdir($path,DWOO_CHMOD,true);}}classDwoo_Template_FileextendsDwoo_Template_String{protected$file;publicfunction__construct($file,$cacheTime=null,$cacheId=null,$compileId=null){$this->file=$file;$this->name=basename($file);$this->cacheTime=$cacheTime;if($compileId!==null){$this->compileId=strtr($compileId,'\\%?=!:;'.PATH_SEPARATOR,'/-------');}if($cacheId!==null){$this->cacheId=strtr($cacheId,'\\%?=!:;'.PATH_SEPARATOR,'/-------');}}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&&file_exists($compiledFile)===true&&filemtime($this->file)<=filemtime($compiledFile)){self::$cache['compiled'][$this->compileId]=true;}else{$this->compilationEnforced=false;if($compiler===null){$compiler=$dwoo->getDefaultCompilerFactory('string');if($compiler===null||$compiler===array('Dwoo_Compiler','compilerFactory')){if(class_exists('Dwoo_Compiler',false)===false)include'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));chmod($compiledFile,DWOO_CHMOD);self::$cache['compiled'][$this->compileId]=true;}return$compiledFile;}publicfunctiongetSource(){returnfile_get_contents($this->file);}publicfunctiongetResourceName(){return'file';}publicfunctiongetResourceIdentifier(){return$this->file;}publicfunctiongetUid(){return(string)filemtime($this->file);}publicstaticfunctiontemplateFactory(Dwoo$dwoo,$resourceId,$cacheTime=null,$cacheId=null,$compileId=null){$resourceId=str_replace(array("\t","\n","\r"),array('\\t','\\n','\\r'),$resourceId);if(file_exists($resourceId)===false){$tpl=$dwoo->getTemplate();if($tplinstanceofDwoo_Template_File){$resourceId=dirname($tpl->getResourceIdentifier()).DIRECTORY_SEPARATOR.$resourceId;if(file_exists($resourceId)===false)returnnull;}elsereturnnull;}if($policy=$dwoo->getSecurityPolicy()){$tpl=$dwoo->getTemplate();if($tplinstanceofDwoo_Template_File&&$resourceId===$tpl->getResourceIdentifier())return$dwoo->triggerError('You can not include a template into itself',E_USER_WARNING);}returnnewDwoo_Template_File($resourceId,$cacheTime,$cacheId,$compileId);}protectedfunctiongetCompiledFilename(Dwoo$dwoo){if($this->compileId===null){$this->compileId=implode('/',array_slice(explode('/',strtr($this->file,'\\','/')),-3));}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]);}elseunset($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;}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;}}
\ No newline at end of file
set_include_path(get_include_path().PATH_SEPARATOR.dirname(__FILE__));define('DWOO_DIRECTORY',dirname(__FILE__).DIRECTORY_SEPARATOR);if(defined('DWOO_CACHE_DIRECTORY')===false)define('DWOO_CACHE_DIRECTORY',DWOO_DIRECTORY.'cache'.DIRECTORY_SEPARATOR);if(defined('DWOO_COMPILE_DIRECTORY')===false)define('DWOO_COMPILE_DIRECTORY',DWOO_DIRECTORY.'compiled'.DIRECTORY_SEPARATOR);if(defined('DWOO_CHMOD')===false)define('DWOO_CHMOD',0777);if(is_writable(DWOO_CACHE_DIRECTORY)===false)thrownewDwoo_Exception('Dwoo cache directory must be writable, either chmod "'.DWOO_CACHE_DIRECTORY.'" to make it writable or define DWOO_CACHE_DIRECTORY to a writable directory before including Dwoo.php');if(is_writable(DWOO_COMPILE_DIRECTORY)===false)thrownewDwoo_Exception('Dwoo compile directory must be writable, either chmod "'.DWOO_COMPILE_DIRECTORY.'" to make it writable or define DWOO_COMPILE_DIRECTORY to a writable directory before including Dwoo.php');if((file_exists(DWOO_COMPILE_DIRECTORY.DIRECTORY_SEPARATOR.'classpath.cache.php')&&includeDWOO_COMPILE_DIRECTORY.DIRECTORY_SEPARATOR.'classpath.cache.php')===false)Dwoo_Loader::rebuildClassPathCache(DWOO_DIRECTORY.'plugins',DWOO_COMPILE_DIRECTORY.DIRECTORY_SEPARATOR.'classpath.cache.php');classDwoo{constVERSION="0.3.4";constRELEASE_TAG=8;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;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$template=null;protected$runtimePlugins;protected$data;protected$scope;protected$scopeTree;protected$stack;protected$curBlock;protected$buffer;publicfunction__construct(){$this->cacheDir=DWOO_CACHE_DIRECTORY.DIRECTORY_SEPARATOR;$this->compileDir=DWOO_COMPILE_DIRECTORY.DIRECTORY_SEPARATOR;}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);elseif(is_string($_tpl))$_tpl=newDwoo_Template_String($_tpl);elsethrownewDwoo_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;elsethrownewDwoo_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){readfile($file);$this->template=null;}else{$this->template=null;returnfile_get_contents($file);}}else{$out=include$_tpl->getCompiledTemplate($this,$_compiler);if($out===false){$_tpl->forceCompilation();$out=include$_tpl->getCompiledTemplate($this,$_compiler);}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);}$this->template=null;if($doCache===true){$_tpl->cache($this,$out);if($_output===true)echo$out;elsereturn$out;}else{if($_output===true)echo$out;elsereturn$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){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,'callback'=>$callback,'class'=>(is_object($callback[0])?get_class($callback[0]):$callback[0]));else$this->plugins[$name]=array('type'=>self::CLASS_PLUGIN,'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,'callback'=>$callback,'class'=>$callback);else$this->plugins[$name]=array('type'=>self::CLASS_PLUGIN,'callback'=>$callback,'class'=>$callback,'function'=>'process');}elseif(function_exists($callback)){$this->plugins[$name]=array('type'=>self::FUNC_PLUGIN,'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){$name=str_replace('Dwoo_Filter_','',$callback);$class='Dwoo_Filter_'.$name;if(!class_exists($class,false)&&!function_exists($class))Dwoo_Loader::loadPlugin($name);if(class_exists($class,false))$callback=array(new$class($this),'process');elseif(function_exists($class))$callback=$class;elsethrownewDwoo_Exception('Wrong filter name, 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($callback,$this->filters,true))!==false)unset($this->filters[$index]);elseif(($index=array_search('Dwoo_Filter_'.str_replace('Dwoo_Filter_','',$callback),$this->filters,true))!==false)unset($this->filters[$index]);else{$class='Dwoo_Filter_'.str_replace('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');$interfaces=class_implements($class,false);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);}publicfunctiongetCustomPlugins(){return$this->plugins;}publicfunctiongetCacheDir(){return$this->cacheDir;}publicfunctionsetCacheDir($dir){$this->cacheDir=rtrim($dir,'/\\').DIRECTORY_SEPARATOR;}publicfunctiongetCompileDir(){return$this->compileDir;}publicfunctionsetCompileDir($dir){$this->compileDir=rtrim($dir,'/\\').DIRECTORY_SEPARATOR;}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;}publicfunctionisCached(Dwoo_ITemplate$tpl){returnis_string($tpl->getCachedTemplate($this));}publicfunctionclearCache($olderThan=-1){$cacheDirs=newRecursiveDirectoryIterator($this->cacheDir);$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){if(isset($this->resources[$resourceName]))returncall_user_func(array($this->resources[$resourceName]['class'],'templateFactory'),$this,$resourceId,$cacheTime,$cacheId,$compileId);elsethrownewDwoo_Exception('Unknown resource type : '.$resourceName);}publicfunctionisArray($value,$checkIsEmpty=false,$allowNonCountable=false){if(is_array($value)===true){if($checkIsEmpty===false)returntrue;elsereturncount($value)>0;}elseif($valueinstanceofIterator){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){trigger_error('Dwoo error (in '.$this->template->getResourceIdentifier().') : '.$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]);elsecall_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]);elsecall_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{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]);elsereturncall_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]);elsewhile(($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]);elsewhile(($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('#(\[|->|\.)?([a-z0-9_]+)\]?#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]];elsereturnnull;}else{if(is_object($data)&&property_exists($data,$m[2][$k]))$data=$data->$m[2][$k];elsereturnnull;}}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);elsereturn$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==='_root'||$varstr==='__'){return$this->data;$varstr=substr($varstr,6);}elseif($varstr==='_parent'||$varstr==='_'){$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];elsereturnnull;}if(substr($varstr,0,1)==='.')$varstr='dwoo'.$varstr;preg_match_all('#(\[|->|\.)?([a-z0-9_]+)\]?#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]);elsereturnnull;}if($cur!==$this->globals){array_shift($m[2]);array_shift($m[1]);}}elseif($i==='_root'||$i==='__'){$cur=$this->data;array_shift($m[2]);array_shift($m[1]);}elseif($i==='_parent'||$i==='_'){$tree=$this->scopeTree;$cur=$this->data;while(true){array_pop($tree);array_shift($m[2]);array_shift($m[1]);if(current($m[2])==='_parent'||current($m[2])==='_')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]];elsereturnnull;}elseif($sep==='->'){if(is_object($cur)&&property_exists($cur,$m[2][$k]))$cur=$cur->$m[2][$k];elsereturnnull;}elsereturnnull;}return$cur;}publicfunctionassignInScope($value,$scope){$tree=&$this->scopeTree;$data=&$this->data;if(strstr($scope,'.')===false&&strstr($scope,'->')===false){$this->scope[$scope]=$value;}else{preg_match_all('#(\[|->|\.)?([a-z0-9_]+)\]?#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];}elsereturnfalse;}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;}elsereturnfalse;}}publicfunctionsetScope($scope){$old=$this->scopeTree;if(empty($scope))return$old;if(is_array($scope)===false)$scope=explode('.',$scope);while(($bit=array_shift($scope))!==null){if($bit==='_parent'||$bit==='_'){array_pop($this->scopeTree);reset($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==='_root'||$bit==='__'){$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){$prev=$this->setScope(array('_root'));$this->setScope($scope);return$prev;}}classDwoo_Loader{protectedstatic$paths=array();publicstatic$classpath=array();publicstaticfunctionrebuildClassPathCache($path,$cacheFile){if($cacheFile!==false){$tmp=self::$classpath;self::$classpath=array();}$list=glob($path.DIRECTORY_SEPARATOR.'*');if(is_array($list))foreach($listas$f){if(is_dir($f))self::rebuildClassPathCache($f,false);elseself::$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,'<?php Dwoo_Loader::$classpath = '.var_export(self::$classpath,true).' + Dwoo_Loader::$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)');self::$classpath+=$tmp;}}publicstaticfunctionloadPlugin($class,$forceRehash=true){if(!isset(self::$classpath[$class])||!includeself::$classpath[$class]){if($forceRehash){self::rebuildClassPathCache(DWOO_DIRECTORY.'plugins',DWOO_COMPILE_DIRECTORY.DIRECTORY_SEPARATOR.'classpath.cache.php');foreach(self::$pathsas$path=>$file)self::rebuildClassPathCache($path,$file);if(isset(self::$classpath[$class]))includeself::$classpath[$class];elsethrownewDwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?',E_USER_NOTICE);}elsethrownewDwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?',E_USER_NOTICE);}}publicstaticfunctionaddDirectory($pluginDir){if(!isset(self::$paths[$pluginDir])){$cacheFile=DWOO_COMPILE_DIRECTORY.DIRECTORY_SEPARATOR.'classpath-'.substr(strtr($pluginDir,':/\\.','----'),strlen($pluginDir)>80?-80:0).'.cache.php';self::$paths[$pluginDir]=$cacheFile;if(file_exists($cacheFile))include$cacheFile;elseDwoo_Loader::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','count','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);}interfaceDwoo_ICompilable_Block{}abstractclassDwoo_Plugin{protected$dwoo;publicfunction__construct(Dwoo$dwoo){$this->dwoo=$dwoo;}}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('.implode(', ',$compiler->getCompiledParams($params)).'));'.$append.Dwoo_Compiler::PHP_CLOSE;}publicstaticfunctionpostProcessing(Dwoo_Compiler$compiler,array$params,$prepend='',$append=''){returnDwoo_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;publicfunction__construct($templateString,$cacheTime=null,$cacheId=null,$compileId=null){$this->template=$templateString;$this->name=hash('md4',$templateString);$this->cacheTime=$cacheTime;if($compileId!==null){$this->compileId=strtr($compileId,'\\%?=!:;'.PATH_SEPARATOR,'/-------');}if($cacheId!==null){$this->cacheId=strtr($cacheId,'\\%?=!:;'.PATH_SEPARATOR,'/-------');}}publicfunctiongetCacheTime(){return$this->cacheTime;}publicfunctionsetCacheTime($seconds=null){$this->cacheTime=$seconds;}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){$cachedFile=$this->getCacheFilename($dwoo);if($this->cacheTime!==null)$cacheLength=$this->cacheTime;else$cacheLength=$dwoo->getCacheTime();if($cacheLength===0){returnfalse;}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);}chmod($cachedFile,DWOO_CHMOD);self::$cache['cached'][$this->cacheId]=true;returntrue;}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&&file_exists($compiledFile)===true){self::$cache['compiled'][$this->compileId]=true;}else{$this->compilationEnforced=false;if($compiler===null){$compiler=$dwoo->getDefaultCompilerFactory('string');if($compiler===null||$compiler===array('Dwoo_Compiler','compilerFactory')){if(class_exists('Dwoo_Compiler',false)===false)include'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));chmod($compiledFile,DWOO_CHMOD);self::$cache['compiled'][$this->compileId]=true;}return$compiledFile;}publicstaticfunctiontemplateFactory(Dwoo$dwoo,$resourceId,$cacheTime=null,$cacheId=null,$compileId=null){returnfalse;}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']);$this->cacheId=strtr($cacheId,'\\%?=!:;'.PATH_SEPARATOR,'/-------');}return$dwoo->getCacheDir().$this->cacheId.'.html';}protectedfunctionmakeDirectory($path){if(is_dir($path)===true)return;mkdir($path,DWOO_CHMOD,true);}}classDwoo_Template_FileextendsDwoo_Template_String{protected$file;publicfunction__construct($file,$cacheTime=null,$cacheId=null,$compileId=null){$this->file=$file;$this->name=basename($file);$this->cacheTime=$cacheTime;if($compileId!==null){$this->compileId=strtr($compileId,'\\%?=!:;'.PATH_SEPARATOR,'/-------');}if($cacheId!==null){$this->cacheId=strtr($cacheId,'\\%?=!:;'.PATH_SEPARATOR,'/-------');}}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&&file_exists($compiledFile)===true&&filemtime($this->file)<=filemtime($compiledFile)){self::$cache['compiled'][$this->compileId]=true;}else{$this->compilationEnforced=false;if($compiler===null){$compiler=$dwoo->getDefaultCompilerFactory('string');if($compiler===null||$compiler===array('Dwoo_Compiler','compilerFactory')){if(class_exists('Dwoo_Compiler',false)===false)include'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));chmod($compiledFile,DWOO_CHMOD);self::$cache['compiled'][$this->compileId]=true;}return$compiledFile;}publicfunctiongetSource(){returnfile_get_contents($this->file);}publicfunctiongetResourceName(){return'file';}publicfunctiongetResourceIdentifier(){return$this->file;}publicfunctiongetUid(){return(string)filemtime($this->file);}publicstaticfunctiontemplateFactory(Dwoo$dwoo,$resourceId,$cacheTime=null,$cacheId=null,$compileId=null){$resourceId=str_replace(array("\t","\n","\r"),array('\\t','\\n','\\r'),$resourceId);if(file_exists($resourceId)===false){$tpl=$dwoo->getTemplate();if($tplinstanceofDwoo_Template_File){$resourceId=dirname($tpl->getResourceIdentifier()).DIRECTORY_SEPARATOR.$resourceId;if(file_exists($resourceId)===false)returnnull;}elsereturnnull;}if($policy=$dwoo->getSecurityPolicy()){$tpl=$dwoo->getTemplate();if($tplinstanceofDwoo_Template_File&&$resourceId===$tpl->getResourceIdentifier())return$dwoo->triggerError('You can not include a template into itself',E_USER_WARNING);}returnnewDwoo_Template_File($resourceId,$cacheTime,$cacheId,$compileId);}protectedfunctiongetCompiledFilename(Dwoo$dwoo){if($this->compileId===null){$this->compileId=implode('/',array_slice(explode('/',strtr($this->file,'\\','/')),-3));}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]);}elseunset($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;}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;}}
$this->triggerError('Wrong filter name, 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"',E_USER_ERROR);
thrownewDwoo_Exception('Wrong filter name, 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"');
@@ -272,7 +272,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
elseif(function_exists($class))
$callback=$class;
else
$this->triggerError('Wrong pre-processor name, when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Processor_name"',E_USER_ERROR);
thrownewDwoo_Exception('Wrong pre-processor name, when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Processor_name"');
$this->processors['pre'][]=$callback;
}
...
...
@@ -329,7 +329,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
elseif(function_exists($class))
$callback=$class;
else
$this->triggerError('Wrong post-processor name, when using autoload the processor must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Processor_name"',E_USER_ERROR);
thrownewDwoo_Exception('Wrong post-processor name, when using autoload the processor must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Processor_name"');
$this->processors['post'][]=$callback;
}
...
...
@@ -564,7 +564,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
$endpos=strpos($tpl,$this->rd,$pos);
if($endpos===false)
$this->triggerError('A template tag was not closed, started with <em>'.substr($tpl,$pos,100).'</em>',E_USER_ERROR);
thrownewDwoo_Compilation_Exception('A template tag was not closed, started with <em>'.substr($tpl,$pos,100).'</em>');
while(substr($tpl,$endpos-1,1)==='\\')
{
...
...
@@ -653,7 +653,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
@@ -1147,7 +1147,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
elseif($pluginType&Dwoo::SMARTY_BLOCK)
{
if($curBlock!=='root'||is_array($parsingParams))
$this->triggerError('Block plugins can not be used as other plugin\'s arguments',E_USER_ERROR);
thrownewDwoo_Compilation_Exception('Block plugins can not be used as other plugin\'s arguments');
if($state===2)
{
...
...
@@ -1200,7 +1200,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
$output='';
if(is_array($parsingParams)||$curBlock!=='root')
return$this->triggerError('Do can not be used inside another function or block',E_USER_ERROR);
thrownewDwoo_Compilation_Exception('Do can not be used inside another function or block');
else
returnself::PHP_OPEN.$output.self::PHP_CLOSE;
}
...
...
@@ -1322,7 +1322,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
$strend=strpos($in,$first,$o);
if($strend===false)
{
$this->triggerError('Unfinished string in : <strong>'.substr($in,0,$from).'<u>'.substr($in,$from,$to-$from).'</u>'.substr($in,$to).'</strong>',E_USER_ERROR);
thrownewDwoo_Compilation_Exception('Unfinished string in : <strong>'.substr($in,0,$from).'<u>'.substr($in,$from,$to-$from).'</u>'.substr($in,$to).'</strong>');
}
if(substr($in,$strend-1,1)==='\\')
{
...
...
@@ -1393,7 +1393,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
@@ -2316,7 +2316,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
}
}
else
$this->triggerError('Plugin "'.$name.'" could not be found',E_USER_ERROR);
thrownewDwoo_Exception('Plugin "'.$name.'" could not be found');
$pluginType++;
}
}
...
...
@@ -2381,7 +2381,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
if(count($ps)===0)
{
if($v[1]===false)
$this->triggerError('Rest argument missing for '.str_replace(array('Dwoo_Plugin_','_compile'),'',(is_array($callback)?$callback[0]:$callback)),E_USER_ERROR);
thrownewDwoo_Compilation_Exception('Rest argument missing for '.str_replace(array('Dwoo_Plugin_','_compile'),'',(is_array($callback)?$callback[0]:$callback)));
else
break;
}
...
...
@@ -2404,7 +2404,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
}
// parameter is not defined and not optional, throw error
elseif($v[1]===false)
$this->triggerError('Argument '.$k.'/'.$v[0].' missing for '.str_replace(array('Dwoo_Plugin_','_compile'),'',(is_array($callback)?$callback[0]:$callback)),E_USER_ERROR);
thrownewDwoo_Compilation_Exception('Argument '.$k.'/'.$v[0].' missing for '.str_replace(array('Dwoo_Plugin_','_compile'),'',(is_array($callback)?$callback[0]:$callback)));
// enforce lowercased null if default value is null (php outputs NULL with var export)
elseif($v[2]===null)
$paramlist[$v[0]]=array('null',null);
...
...
@@ -2425,7 +2425,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
if(count($params)===0)
{
if($v[1]===false)
$this->triggerError('Rest argument missing for '.str_replace(array('Dwoo_Plugin_','_compile'),'',(is_array($callback)?$callback[0]:$callback)),E_USER_ERROR);
thrownewDwoo_Compilation_Exception('Rest argument missing for '.str_replace(array('Dwoo_Plugin_','_compile'),'',(is_array($callback)?$callback[0]:$callback)));
else
break;
}
...
...
@@ -2448,7 +2448,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
}
// parameter is not defined and not optional, throw error
elseif($v[1]===false)
$this->triggerError('Argument '.$k.'/'.$v[0].' missing for '.str_replace(array('Dwoo_Plugin_','_compile'),'',(is_array($callback)?$callback[0]:$callback)),E_USER_ERROR);
thrownewDwoo_Compilation_Exception('Argument '.$k.'/'.$v[0].' missing for '.str_replace(array('Dwoo_Plugin_','_compile'),'',(is_array($callback)?$callback[0]:$callback)));
// enforce lowercased null if default value is null (php outputs NULL with var export)
elseif($v[2]===null)
$paramlist[$v[0]]=array('null',null);
...
...
@@ -2459,7 +2459,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
}
// parser failed miserably
else
$this->triggerError('This should not happen, please report it if you see this message',E_USER_ERROR);
thrownewDwoo_Compilation_Exception('This should not happen, please report it if you see this message');
return$paramlist;
}
...
...
@@ -2507,15 +2507,4 @@ class Dwoo_Compiler implements Dwoo_ICompiler
self::$instance=newself;
returnself::$instance;
}
/**
* triggers a compiler error
*
* @param string $message error message
* @param int $level error level, one of the PHP's E_* constants
@@ -105,7 +105,7 @@ class Dwoo_Plugin_if extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
next($params);
}
else
$compiler->triggerError('If : Syntax error : syntax should be "if $a is [not] div by $b", found '.$params[$k-1].' is '.($negate?'not ':'').'div '.$params[$k+$ptr+1].' '.$params[$k+$ptr+2],E_USER_ERROR);
thrownewDwoo_Compilation_Exception('If : Syntax error : syntax should be "if $a is [not] div by $b", found '.$params[$k-1].' is '.($negate?'not ':'').'div '.$params[$k+$ptr+1].' '.$params[$k+$ptr+2]);
break;
case'"even"':
$a=array_pop($p);
...
...
@@ -138,7 +138,7 @@ class Dwoo_Plugin_if extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
next($params);
break;
default:
$compiler->triggerError('If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found '.$params[$k-1].' is '.$params[$k+$ptr+1],E_USER_ERROR);
thrownewDwoo_Compilation_Exception('If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found '.$params[$k-1].' is '.$params[$k+$ptr+1]);
$this->compiler->triggerError('The Smarty Compatibility Module has detected that you use |@'.$matches[1].' in your template, this might lead to problems as Dwoo interprets the @ operator differently than Smarty, see http://wiki.dwoo.org/index.php/Syntax#The_.40_Operator',E_USER_NOTICE);
trigger_error('The Smarty Compatibility Module has detected that you use |@'.$matches[1].' in your template, this might lead to problems as Dwoo interprets the @ operator differently than Smarty, see http://wiki.dwoo.org/index.php/Syntax#The_.40_Operator',E_USER_NOTICE);
returnpreg_replace($smarty,$dwoo,$input);
}
...
...
@@ -73,7 +73,7 @@ class Dwoo_Processor_smarty_compat extends Dwoo_Processor
$params['altcontent']=$matches[14];
if(empty($params['name']))
$this->compiler->triggerError('Missing parameter <em>name</em> for section tag');
thrownewDwoo_Compilation_Exception('Missing parameter <em>name</em> for section tag');