Index: trunk/core/kernel/parser/tags.php
===================================================================
diff -u -r932 -r1339
--- trunk/core/kernel/parser/tags.php (.../tags.php) (revision 932)
+++ trunk/core/kernel/parser/tags.php (.../tags.php) (revision 1339)
@@ -1,8 +1,8 @@
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, $this->Parser->Values, $tag_data);
+ $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);
@@ -68,32 +119,20 @@
return $a_len > $b_len ? -1 : 1;
}
- function ReplaceLanguageTags($tag_data)
- {
- preg_match_all("(!(la|lu)[^!]+!)", $tag_data, $res, PREG_PATTERN_ORDER);
- $language_tags = $res[0];
- uasort($language_tags, array ("Tag", "CmpParams"));
-
- $values = Array();
- $i = 0;
- foreach ($language_tags as $label) {
- array_push($values, $this->Application->Phrase($label));
- $language_tags[$i] = '/' . $language_tags[$i] . '/';
- $i++;
- }
- $tag_data = preg_replace($language_tags, $values, $tag_data);
- return $tag_data;
- }
-
function ParseTagData($tag_data)
{
- $tag_data = $this->ReplaceParams($tag_data) . ' ';
- $tag_data = $this->ReplaceLanguageTags($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);
}
@@ -132,21 +171,14 @@
$tag->CopyFrom($this);
$tag->Process();
}
- elseif ($this->Tag == 'xml') {
- $tag =& new XMLTag('', $this->Parser);
- $tag->CopyFrom($this);
- $tag->Process();
- }
else {
if ($this->Parser->SkipMode == skip) return;
- //if (!$this->ProcessMainTag()) //other main tags
- $this->ProcessTag();
+ $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();
- //$this->Parser->AppendOutput(''.$this->Tag.'');
}
}
@@ -166,64 +198,57 @@
}
else
{
- echo "Warning: can't process tag ".$this->Tag."
";
+ trigger_error('can\'t process tag '.$this->Tag,E_USER_WARNING);
}
}
-}
+
+ function GetCode($echo=false)
+ {
+ $pass_params = $this->NP;
+
+ $code = Array();
-
-// ################### TESTS ############################
-
-global $suite;
-if (isset($suite)) {
- class TestTags extends TestCase {
+ $to_pass = 'Array(';
+ foreach ($pass_params as $name => $val) {
+ $to_pass .= '"'.$name.'" => "'.$val.'",';
+ }
+ $to_pass .= ')';
- function testTagParsing()
- {
- global $application;
-
- $tag_data = "m:test param1=\"123\"";
- $tag =& new Tag($tag_data, $application->Parser);
- $this->assertEquals('m', $tag->Processor);
- $this->assertEquals('test', $tag->Tag);
- $this->assertEquals('123', $tag->GetParam('param1'));
-
- $this->assertFalse($tag->GetParam('no_such_param'));
- }
+ if ($echo) $code[] = '$o = '."'';\n";
- function testTagParamEscaping()
- {
- global $application;
+ 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;
- $tag_data = "m:test escape1='-\"-' \t\t \n \t\n escape2=\"+\\\"+\" \n escape3='*\'*' escape4='=\='";
- //$tag_data = "m:test escape1='-\"-' escape2=\"+\\\"+\" escape3='*\'*' escape4='=\='";
- $tag =& new Tag($tag_data, $application->Parser);
- $this->assertEquals('-"-', $tag->GetParam('escape1'));
- $this->assertEquals('+"+', $tag->GetParam('escape2'));
- $this->assertEquals("*'*", $tag->GetParam('escape3'));
- $this->assertEquals('=\=', $tag->GetParam('escape4'));
+ case 'endif':
+ $code[] = ' }';
+ return $code;
+
+ case 'else':
+ $code[] = ' }';
+ $code[] = ' else {';
+ return $code;
}
- function testTagParamSubstitution()
- {
- global $application;
-
- $application->Parser->SetParams( Array(
- 'prefix' => 'a_prefix',
- 'tag' => 'a_tag',
- 'param_name' => 'a_param_name',
- 'param_value' => 'a_param_value'
- )
- );
-
- $tag_data = '$prefix:$tag $param_name="$param_value"';
- $tag =& new Tag($tag_data, $application->Parser);
- $this->assertEquals('a_prefix', $tag->Processor);
- $this->assertEquals('a_tag', $tag->Tag);
- $this->assertEquals('a_param_value', $tag->GetParam('a_param_name'));
- }
+ $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 .'\'';
}
- $suite->addTest(new TestSuite("TestTags"));
}
?>
\ No newline at end of file