I'm not good with regular expressions and I met huge problems with changing rain.tpl class. Whole class is available here (I don't want to copy-paste whole file here).
The thing is that I'd like to parse {_(word)}
into <?= __('word') ?>
because it's a lot easier to use than {function="__('word')"}
.
I tried to change it myself but I can't put proper regular expressions into methods and output are more and more errors.
EDIT:
The part of parsing function responsible for parsing {function="__('word')"}
etc looks like this:
//function
elseif( preg_match( '/\{function="(\w*)(.*?)"\}/', $html, $code ) ){
//tag
$tag = $code[ 0 ];
//function
$function = $code[ 1 ];
// check if there's any function disabled by black_list
$this->function_check( $tag );
if( empty( $code[ 2 ] ) )
$parsed_function = $function . "()";
else
// parse the function
$parsed_function = $function . $this->var_replace( $code[ 2 ], $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level );
//if code
$compiled_code .= "<?php echo $parsed_function; ?>";
}
And the functions that calls the parsing (there are some regular expressions too) look like it:
protected function compileTemplate( $template_code, $tpl_basedir ){
//tag list
$tag_regexp = array( 'loop' => '(\{loop(?: name){0,1}="\${0,1}[^"]*"\})',
'loop_close' => '(\{\/loop\})',
'if' => '(\{if(?: condition){0,1}="[^"]*"\})',
'elseif' => '(\{elseif(?: condition){0,1}="[^"]*"\})',
'else' => '(\{else\})',
'if_close' => '(\{\/if\})',
'function' => '(\{function="[^"]*"\})',
'noparse' => '(\{noparse\})',
'noparse_close'=> '(\{\/noparse\})',
'ignore' => '(\{ignore\}|\{\*)',
'ignore_close' => '(\{\/ignore\}|\*\})',
'include' => '(\{include="[^"]*"(?: cache="[^"]*")?\})',
'template_info'=> '(\{\$template_info\})',
'function' => '(\{function="(\w*?)(?:.*?)"\})'
);
$tag_regexp = "/" . join( "|", $tag_regexp ) . "/";
//split the code with the tags regexp
$template_code = preg_split ( $tag_regexp, $template_code, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
//path replace (src of img, background and href of link)
$template_code = $this->path_replace( $template_code, $tpl_basedir );
//compile the code
$compiled_code = $this->compileCode( $template_code );
//return the compiled code
return $compiled_code;
}
Hope it's enough for you to help me without downloading and reading the whole class file. Hope someone knows this template and can help me :)