123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
-
- class themes{
- var $registry;
- var $path;
- var $l10n;
-
- var $output;
- var $vars=array();
-
- function themes(){
-
- }
-
- function set($name, $value){
- $this->vars[$name] = $value;
- return true;
- }
-
- function remove($name) {
- unset($this->vars[$name]);
- return true;
- }
-
-
- function fetch($file){
- $this->exec($file);
- return $this->output;
- }
-
-
- function display($file){
- $this->exec($file);
- echo $this->output;
- }
-
-
- function exec($file){
- $this->file = $file;
- $output = file_get_contents($file);
- $this->output = $output;
- $this->registrar_vars();
- $this->__();
- $this->eval_control_structures();
-
-
- ob_start();eval($this->output);
- $this->output = stripslashes(ob_get_clean());
- }
-
- function eval_control_structures(){
-
- preg_match_all("/{header ([^}]+?)}/s",$this->output,$out);
- $headers = '';
- foreach ($out[1] as $o)
- $headers .= "header('$o');\n";
-
- $this->output = preg_replace("/{header [^}]+?}/s","",$this->output);
-
-
- $this->output = $this->quotemeta($this->output);
- $this->output = str_replace('\"','\\"',trim($this->output));
-
- $this->output = "echo \"".str_replace('"','\"',trim($this->output))."\";";
-
-
- $this->output = $headers.trim($this->output);
-
-
-
- $this->output = preg_replace_callback("/{if ([^}]+)}/",create_function('$arr','return "\";if(".stripslashes(preg_replace(array("/\\\\$([a-zA-Z0-9_]+)/s","/\\\\\\$this->vars\[\\\'([a-zA-Z0-9_]+)\\\'\]\.([a-zA-Z0-9_]+)/s"),array("\$this->vars[\'\$1\']","\\\\\\$this->vars[\\\'$1\\\'][\\\'$2\\\']"),$arr[1]))."){echo\"";'),$this->output);
- $this->output = preg_replace("/{else}/","\";}else{echo\"",$this->output);
- $this->output = preg_replace_callback("/{elseif ([^}]+)}/",create_function('$arr','return "\";}elseif(".stripslashes(preg_replace(array("/\\\\$([a-zA-Z0-9]+)/s","/\\\\\\$this->vars\[\\\'([a-zA-Z0-9]+)\\\'\]\.([a-zA-Z0-9]+)/s"),array("\$this->vars[\'\$1\']","\\\\\\$this->vars[\\\'$1\\\'][\\\'$2\\\']"),$arr[1]))."){echo\"";'),$this->output);
- $this->output = preg_replace("/{\/if}/","\";} echo \"",$this->output);
-
-
- $this->output = preg_replace_callback("/{block ([^}]+) as ([^}]+)=>[\$]([^}]+)}/",create_function('$arr','return "\";foreach(".stripslashes(preg_replace(array("/\\\\$([a-zA-Z0-9_]+)/s","/\\\\\\$this->vars\[\\\'([a-zA-Z0-9_]+)\\\'\]\.([a-zA-Z0-9_]+)/s"),array("\$this->vars[\'\$1\']","\\\\\\$this->vars[\\\'$1\\\'][\\\'$2\\\']"),$arr[1]))." as ".stripslashes(preg_replace(array("/\\\\$([a-zA-Z0-9_]+)/s","/\\\\\\$this->vars\[\\\'([a-zA-Z0-9_]+)\\\'\]\.([a-zA-Z0-9_]+)/s"),array("\$this->vars[\'\$1\']","\\\\\\$this->vars[\\\'$1\\\'][\\\'$2\\\']"),$arr[2]))."=>\$this->vars[\'".stripslashes(preg_replace(array("/\\\\$([a-zA-Z0-9_]+)/s","/\\\\\\$this->vars\[\\\'([a-zA-Z0-9_]+)\\\'\]\.([a-zA-Z0-9_]+)/s"),array("\$this->vars[\'\$1\']","\\\\\\$this->vars[\\\'$1\\\'][\\\'$2\\\']"),$arr[3]))."\']){echo\"";'),$this->output);
- $this->output = preg_replace_callback("/{block ([^}]+) as ([^}]+)}/",create_function('$arr','return "\";foreach(".stripslashes(preg_replace(array("/\\\\$([a-zA-Z0-9_]+)/s","/\\\\\\$this->vars\[\\\'([a-zA-Z0-9_]+)\\\'\]\.([a-zA-Z0-9_]+)/s"),array("\$this->vars[\'\$1\']","\\\\\\$this->vars[\\\'$1\\\'][\\\'$2\\\']"),$arr[1]))." as ".stripslashes(preg_replace(array("/\\\\$([a-zA-Z0-9_]+)/s","/\\\\\\$this->vars\[\\\'([a-zA-Z0-9_]+)\\\'\]\.([a-zA-Z0-9_]+)/s"),array("\$this->vars[\'\$1\']","\\\\\\$this->vars[\\\'$1\\\'][\\\'$2\\\']"),$arr[2]))."){echo\"";'),$this->output);
- $this->output = preg_replace("/{\/block}/","\";} echo \"",$this->output);
-
-
-
- $this->output = preg_replace("/[\$]this->vars\[\\\'([^ \.\\\]+)\\\'\]/","{\$this->vars['$1']}",$this->output);
-
-
-
- }
-
-
- function registrar_vars(){
- foreach($this->vars as $k=>$v){
-
- if(is_array($v)){
-
- foreach($v as $_k=>$_v)
- if(!is_array($_v))
- $this->output = str_replace('{'.$k.'.'.$_k.'}',$_v,$this->output);
- }else{
-
- $this->output = str_replace('{'.$k.'}',$v,$this->output);
- }
- }
-
-
-
- $patrones = array(
- '/{\$([^ \.}]+)}/s',
- '/{\$([^ \.}]+)\.([^ \.}]+)}/s'
- );
- $reemplazos = array(
- "{\$this->vars['$1']}",
- "{\$this->vars['$1']['$2']}"
- );
- $this->output = preg_replace($patrones, $reemplazos, $this->output);
- }
-
- function quotemeta($str){
- $chars = array( "\\", );
- foreach($chars as $char)
- $this->output = str_replace($char,"\\$char",$this->output);
- return $this->output;
- }
-
-
- function __(){
- $patron = "/{__\((?:'|\")([^\)]+?)(?:'|\")\)}/s";
- preg_match_all($patron,$this->output,$out);
-
- foreach($out[1] as $k=>$v){
- $this->output = preg_replace("/{__\((?:'|\")$v(?:'|\")\)}/",__($v),$this->output);
- }
- }
- }
- ?>
|