Parser =& $parser; $this->TagData = $tag_data; if ($tag_data != '') $this->ParseTagData($tag_data); $this->NP =& $this->NamedParams; } function CopyFrom(&$tag) { $this->Processor = $tag->Processor; $this->Tag = $tag->Tag; $this->TagData = $tag->TagData; $this->Params = $tag->Params; $this->NamedParams = $tag->NamedParams; $this->Parser =& $tag->Parser; } function GetFullTag() { return '<%'.$this->TagData.'%>'; } function RebuildTagData() { $res = $this->Processor.':'.$this->Tag.' '; foreach ($this->NamedParams as $name => $value) { $res .= "$name='$value' "; } return $res; } /** * Escape chars in phrase translation, that could harm parser to process tag * * @param string $text * @return string * @access private */ function EscapeReservedChars($text) { $reserved = Array('"',"'"); // = $replacement = Array('\"',"\'"); // \= return str_replace($reserved,$replacement,$text); } function ReplaceParams($tag_data) { //print_pre($this->Parser->Pattern, $tag_data); $values = $this->Parser->Values; foreach($values as $param_name => $param_value) { $values[$param_name] = $this->EscapeReservedChars($param_value); } if (is_array($this->Parser->Params)) { $tag_data = preg_replace($this->Parser->Pattern, $values, $tag_data); } //echo "got: $tag_data
"; return $tag_data; } function PreParseReplaceParams($tag_data) { //print_pre($this->Parser->Pattern, $tag_data); $values = $this->Parser->Values; foreach($values as $param_name => $param_value) { $values[$param_name] = $this->EscapeReservedChars($param_value); } /*$patterns = Array(); if ( is_array($this->Parser->Args) ) { foreach ($this->Parser->Args as $arg) { } }*/ if ($this->Parser->SkipMode == parse) { if (is_array($this->Parser->Params)) { $tag_data = preg_replace($this->Parser->Pattern, $values, $tag_data); } } //echo "got: $tag_data
"; return $tag_data; } function CmpParams($a, $b) { $a_len = strlen($a); $b_len = strlen($b); if ($a_len == $b_len) return 0; return $a_len > $b_len ? -1 : 1; } function ParseTagData($tag_data) { if (defined('EXPERIMENTAL_PRE_PARSE') ) { $tag_data = $this->PreParseReplaceParams($tag_data) . ' '; } else { $tag_data = $this->ReplaceParams($tag_data) . ' '; $tag_data = $this->Application->ReplaceLanguageTags($tag_data); } list ($key_data, $params) = explode(' ', $tag_data, 2); list($this->Processor, $this->Tag) = explode(':', $key_data); if ($params != '') $this->ParseNamedParams($params); } function ParseNamedParams($params_str) { $params =& new Params($params_str); $this->NamedParams = $params->_Params; } function GetParam($param) { if (isset($this->NP[$param])) return $this->NP[$param]; else return false; } function Process() { if ($this->Processor == 'm' || $this->Processor == 'm_TagProcessor') { //if we are procssing Main tags if ($this->Tag == 'block') { $tag =& new BlockTag('', $this->Parser); $tag->CopyFrom($this); $tag->Process(); } elseif ($this->Parser->SkipMode == skip_tags) { return; } elseif ( $this->Tag == 'if' || $this->Tag == 'ifnot' || $this->Tag == 'else' || $this->Tag == 'elseif' ) { $tag =& new ConstructTag('', $this->Parser); $tag->CopyFrom($this); $tag->Process(); } else { if ($this->Parser->SkipMode == skip) return; $this->ProcessTag(); } } else { //normal tags - processors other than main if ($this->Parser->SkipMode == skip_tags || $this->Parser->SkipMode == skip) return; //do not parse if we skipping tags $this->ProcessTag(); } } function DoProcessTag() { //$processor =& $this->Application->Processors->GetProcessor($this->Processor, $this); $processor =& $this->Application->recallObject($this->Processor); return $processor->ProcessTag($this); } function ProcessTag() { $o = $this->DoProcessTag(); if ($o !== false) { $this->Parser->AppendOutput($o); } else { trigger_error('can\'t process tag '.$this->Tag,E_USER_WARNING); } } function GetCode($echo=false) { $pass_params = $this->NP; $code = Array(); $to_pass = 'Array('; foreach ($pass_params as $name => $val) { $to_pass .= '"'.$name.'" => "'.$val.'",'; } $to_pass .= ')'; if ($echo) $code[] = '$o = '."'';\n"; switch ( $this->Tag ) { case 'param': $code[] = '$o .= $params["'.$this->NP['name'].'"];'; return $code; case 'if': $code[] = ' $__tag_processor = "'.$pass_params['prefix'].'".\'_TagProcessor\';'."\n"; $code[] = ' $processor =& $application->recallObject($__tag_processor);'."\n"; $code[] = ' $if_result = $processor->ProcessParsedTag(\''.$pass_params['function'].'\', '.$to_pass.');'."\n"; $code[] = ' if ($if_result) {'; return $code; case 'endif': $code[] = ' }'; return $code; case 'else': $code[] = ' }'; $code[] = ' else {'; return $code; } $code[] = ' $__tag_processor = "'.$this->Processor.'".\'_TagProcessor\';'."\n"; $code[] = ' $processor =& $application->recallObject($__tag_processor);'."\n"; $code[] = ' $o .= $processor->ProcessParsedTag(\''.$this->Tag.'\', '.$to_pass.');'."\n"; /*$code = ' $processor =& $application->recallObject(\''.$this->Processor.'_TagProcessor\'); $o .= $processor->ProcessParsedTag(\''.$this->Tag.'\', unserialize(\''.serialize($this->NP).'\'));';*/ if ($echo) $code[] = ' echo $o;'."\n"; return $code; //return '$o .= \'tag:'. $this->Tag .'\''; } } ?>