42 $compiler->has_code =
false;
43 if ($_attr[
'type'] ==
'xml') {
44 $compiler->tag_nocache =
true;
45 $save = $compiler->template->has_nocache_code;
46 $output = addcslashes($_attr[
'code'],
"'\\");
48 $compiler->template->has_nocache_code = $save;
51 if ($_attr[
'type'] !=
'tag') {
55 $output = preg_replace_callback(
'#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i', array($this,
56 'quote'), $_attr[
'code']);
60 $compiler->tag_nocache =
true;
61 $save = $compiler->template->has_nocache_code;
62 $output = addcslashes($_attr[
'code'],
"'\\");
64 $compiler->template->has_nocache_code = $save;
67 if (!($compiler->smarty instanceof
SmartyBC)) {
68 $compiler->
trigger_template_error(
'$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it', $compiler->lex->taglineno);
70 $compiler->has_code =
true;
71 return $_attr[
'code'];
76 $compiler->has_code =
true;
77 if (!($compiler->smarty instanceof
SmartyBC)) {
78 $compiler->
trigger_template_error(
'{php}[/php} tags not allowed. Use SmartyBC to enable them', $compiler->lex->taglineno);
80 $ldel = preg_quote($compiler->smarty->left_delimiter,
'#');
81 $rdel = preg_quote($compiler->smarty->right_delimiter,
'#');
82 preg_match(
"#^({$ldel}php\\s*)((.)*?)({$rdel})#", $_attr[
'code'], $match);
83 if (!empty($match[2])) {
84 if (
'nocache' == trim($match[2])) {
85 $compiler->tag_nocache =
true;
87 $compiler->
trigger_template_error(
"illegal value of option flag \"{$match[2]}\"", $compiler->lex->taglineno);
90 return preg_replace(array(
"#^{$ldel}\\s*php\\s*(.)*?{$rdel}#",
91 "#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"), array(
'<?php ',
'?>'), $_attr[
'code']);
106 $lex->taglineno = $lex->line;
108 if (strpos($lex->value,
'<?xml') === 0) {
112 } elseif (strpos($lex->value,
'<?') === 0) {
113 $lex->phpType =
'php';
114 } elseif (strpos($lex->value,
'<%') === 0) {
115 $lex->phpType =
'asp';
117 } elseif (strpos($lex->value,
'%>') === 0) {
118 $lex->phpType =
'unmatched';
119 } elseif (strpos($lex->value,
'?>') === 0) {
121 $lex->is_xml =
false;
125 $lex->phpType =
'unmatched';
126 } elseif (strpos($lex->value,
'<s') === 0) {
127 $lex->phpType =
'script';
128 $closeTag =
'</script>';
129 } elseif (strpos($lex->value, $lex->smarty->left_delimiter) === 0) {
130 if ($lex->isAutoLiteral()) {
134 $closeTag =
"{$lex->smarty->left_delimiter}/php{$lex->smarty->right_delimiter}";
135 if ($lex->value == $closeTag) {
136 $lex->compiler->trigger_template_error(
"unexpected closing tag '{$closeTag}'");
138 $lex->phpType =
'tag';
140 if ($lex->phpType ==
'unmatched') {
146 $start = $lex->counter + strlen($lex->value);
148 if (preg_match(
'~' . preg_quote($closeTag,
'~') .
'~i', $lex->data, $match, PREG_OFFSET_CAPTURE, $start)) {
149 $close = $match[0][1];
151 $lex->compiler->trigger_template_error(
"missing closing tag '{$closeTag}'");
154 if (preg_match(
'~([/][*])|([/][/][^\n]*)|(\'[^\'\\\\]*(?:\\.[^\'\\\\]*)*\')|("[^"\\\\]*(?:\\.[^"\\\\]*)*")~', $lex->data, $match, PREG_OFFSET_CAPTURE, $start)) {
155 $value = $match[0][0];
156 $from = $pos = $match[0][1];
160 $start = $pos + strlen($value);
161 $phpCommentStart = $value ==
'/*';
162 if ($phpCommentStart) {
163 $phpCommentEnd = preg_match(
'~([*][/])~', $lex->data, $match, PREG_OFFSET_CAPTURE, $start);
164 if ($phpCommentEnd) {
165 $pos2 = $match[0][1];
166 $start = $pos2 + strlen($match[0][0]);
169 while ($close > $pos && $close < $start) {
170 if (preg_match(
'~' . preg_quote($closeTag,
'~') .
'~i', $lex->data, $match, PREG_OFFSET_CAPTURE, $from)) {
171 $close = $match[0][1];
172 $from = $close + strlen($match[0][0]);
174 $lex->compiler->trigger_template_error(
"missing closing tag '{$closeTag}'");
177 if ($phpCommentStart && (!$phpCommentEnd || $pos2 > $close)) {
178 $lex->taglineno = $lex->line + substr_count(substr($lex->data, $lex->counter, $start),
"\n");
179 $lex->compiler->trigger_template_error(
"missing PHP comment closing tag '*/'");
186 $lex->value = substr($lex->data, $lex->counter, $close + strlen($closeTag) - $lex->counter);
195 return htmlspecialchars($match[0], ENT_QUOTES);