change linefeed style to native on all files

This commit is contained in:
monte.ohrt
2009-11-06 14:35:00 +00:00
parent 5c2b897534
commit 3386b94e15
31 changed files with 2825 additions and 2825 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
title = Welcome to Smarty! title = Welcome to Smarty!
cutoff_size = 40 cutoff_size = 40
[setup] [setup]
bold = true bold = true

View File

@@ -1,27 +1,27 @@
<?php <?php
require('../libs/Smarty.class.php'); require('../libs/Smarty.class.php');
$smarty = new Smarty; $smarty = new Smarty;
//$smarty->force_compile = true; //$smarty->force_compile = true;
$smarty->debugging = true; $smarty->debugging = true;
$smarty->caching = true; $smarty->caching = true;
$smarty->cache_lifetime = 120; $smarty->cache_lifetime = 120;
$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill",true); $smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill",true);
$smarty->assign("FirstName",array("John","Mary","James","Henry")); $smarty->assign("FirstName",array("John","Mary","James","Henry"));
$smarty->assign("LastName",array("Doe","Smith","Johnson","Case")); $smarty->assign("LastName",array("Doe","Smith","Johnson","Case"));
$smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"), $smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),
array("I", "J", "K", "L"), array("M", "N", "O", "P"))); array("I", "J", "K", "L"), array("M", "N", "O", "P")));
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"), $smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234"))); array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
$smarty->assign("option_values", array("NY","NE","KS","IA","OK","TX")); $smarty->assign("option_values", array("NY","NE","KS","IA","OK","TX"));
$smarty->assign("option_output", array("New York","Nebraska","Kansas","Iowa","Oklahoma","Texas")); $smarty->assign("option_output", array("New York","Nebraska","Kansas","Iowa","Oklahoma","Texas"));
$smarty->assign("option_selected", "NE"); $smarty->assign("option_selected", "NE");
$smarty->display('index.tpl'); $smarty->display('index.tpl');
?> ?>

View File

@@ -1,2 +1,2 @@
</BODY> </BODY>
</HTML> </HTML>

View File

@@ -1,6 +1,6 @@
<HTML> <HTML>
<HEAD> <HEAD>
{popup_init src="/javascripts/overlib.js"} {popup_init src="/javascripts/overlib.js"}
<TITLE>{$title} - {$Name}</TITLE> <TITLE>{$title} - {$Name}</TITLE>
</HEAD> </HEAD>
<BODY bgcolor="#ffffff"> <BODY bgcolor="#ffffff">

View File

@@ -1,82 +1,82 @@
{config_load file="test.conf" section="setup"} {config_load file="test.conf" section="setup"}
{include file="header.tpl" title=foo} {include file="header.tpl" title=foo}
<PRE> <PRE>
{* bold and title are read from the config file *} {* bold and title are read from the config file *}
{if #bold#}<b>{/if} {if #bold#}<b>{/if}
{* capitalize the first letters of each word of the title *} {* capitalize the first letters of each word of the title *}
Title: {#title#|capitalize} Title: {#title#|capitalize}
{if #bold#}</b>{/if} {if #bold#}</b>{/if}
The current date and time is {$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"} The current date and time is {$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}
The value of global assigned variable $SCRIPT_NAME is {$SCRIPT_NAME} The value of global assigned variable $SCRIPT_NAME is {$SCRIPT_NAME}
Example of accessing server environment variable SERVER_NAME: {$smarty.server.SERVER_NAME} Example of accessing server environment variable SERVER_NAME: {$smarty.server.SERVER_NAME}
The value of {ldelim}$Name{rdelim} is <b>{$Name}</b> The value of {ldelim}$Name{rdelim} is <b>{$Name}</b>
variable modifier example of {ldelim}$Name|upper{rdelim} variable modifier example of {ldelim}$Name|upper{rdelim}
<b>{$Name|upper}</b> <b>{$Name|upper}</b>
An example of a section loop: An example of a section loop:
{section name=outer {section name=outer
loop=$FirstName} loop=$FirstName}
{if $smarty.section.outer.index is odd by 2} {if $smarty.section.outer.index is odd by 2}
{$smarty.section.outer.rownum} . {$FirstName[outer]} {$LastName[outer]} {$smarty.section.outer.rownum} . {$FirstName[outer]} {$LastName[outer]}
{else} {else}
{$smarty.section.outer.rownum} * {$FirstName[outer]} {$LastName[outer]} {$smarty.section.outer.rownum} * {$FirstName[outer]} {$LastName[outer]}
{/if} {/if}
{sectionelse} {sectionelse}
none none
{/section} {/section}
An example of section looped key values: An example of section looped key values:
{section name=sec1 loop=$contacts} {section name=sec1 loop=$contacts}
phone: {$contacts[sec1].phone}<br> phone: {$contacts[sec1].phone}<br>
fax: {$contacts[sec1].fax}<br> fax: {$contacts[sec1].fax}<br>
cell: {$contacts[sec1].cell}<br> cell: {$contacts[sec1].cell}<br>
{/section} {/section}
<p> <p>
testing strip tags testing strip tags
{strip} {strip}
<table border=0> <table border=0>
<tr> <tr>
<td> <td>
<A HREF="{$SCRIPT_NAME}"> <A HREF="{$SCRIPT_NAME}">
<font color="red">This is a test </font> <font color="red">This is a test </font>
</A> </A>
</td> </td>
</tr> </tr>
</table> </table>
{/strip} {/strip}
</PRE> </PRE>
This is an example of the html_select_date function: This is an example of the html_select_date function:
<form> <form>
{html_select_date start_year=1998 end_year=2010} {html_select_date start_year=1998 end_year=2010}
</form> </form>
This is an example of the html_select_time function: This is an example of the html_select_time function:
<form> <form>
{html_select_time use_24_hours=false} {html_select_time use_24_hours=false}
</form> </form>
This is an example of the html_options function: This is an example of the html_options function:
<form> <form>
<select name=states> <select name=states>
{html_options values=$option_values selected=$option_selected output=$option_output} {html_options values=$option_values selected=$option_selected output=$option_output}
</select> </select>
</form> </form>
{include file="footer.tpl"} {include file="footer.tpl"}

View File

@@ -1,136 +1,136 @@
{capture assign=debug_output} {capture assign=debug_output}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head> <head>
<title>Smarty Debug Console</title> <title>Smarty Debug Console</title>
<style type="text/css"> <style type="text/css">
{literal} {literal}
body, h1, h2, td, th, p { body, h1, h2, td, th, p {
font-family: sans-serif; font-family: sans-serif;
font-weight: normal; font-weight: normal;
font-size: 0.9em; font-size: 0.9em;
margin: 1px; margin: 1px;
padding: 0; padding: 0;
} }
h1 { h1 {
margin: 0; margin: 0;
text-align: left; text-align: left;
padding: 2px; padding: 2px;
background-color: #f0c040; background-color: #f0c040;
color: black; color: black;
font-weight: bold; font-weight: bold;
font-size: 1.2em; font-size: 1.2em;
} }
h2 { h2 {
background-color: #9B410E; background-color: #9B410E;
color: white; color: white;
text-align: left; text-align: left;
font-weight: bold; font-weight: bold;
padding: 2px; padding: 2px;
border-top: 1px solid black; border-top: 1px solid black;
} }
body { body {
background: black; background: black;
} }
p, table, div { p, table, div {
background: #f0ead8; background: #f0ead8;
} }
p { p {
margin: 0; margin: 0;
font-style: italic; font-style: italic;
text-align: center; text-align: center;
} }
table { table {
width: 100%; width: 100%;
} }
th, td { th, td {
font-family: monospace; font-family: monospace;
vertical-align: top; vertical-align: top;
text-align: left; text-align: left;
width: 50%; width: 50%;
} }
td { td {
color: green; color: green;
} }
.odd { .odd {
background-color: #eeeeee; background-color: #eeeeee;
} }
.even { .even {
background-color: #fafafa; background-color: #fafafa;
} }
.exectime { .exectime {
font-size: 0.8em; font-size: 0.8em;
font-style: italic; font-style: italic;
} }
#table_assigned_vars th { #table_assigned_vars th {
color: blue; color: blue;
} }
#table_config_vars th { #table_config_vars th {
color: maroon; color: maroon;
} }
{/literal} {/literal}
</style> </style>
</head> </head>
<body> <body>
<h1>Smarty Debug Console - Total Time {$execution_time|string_format:"%.5f"}</h1> <h1>Smarty Debug Console - Total Time {$execution_time|string_format:"%.5f"}</h1>
<h2>included templates &amp; config files (load time in seconds)</h2> <h2>included templates &amp; config files (load time in seconds)</h2>
<div> <div>
{foreach $template_data as $template} {foreach $template_data as $template}
<font color=brown>{$template.name}</font> <font color=brown>{$template.name}</font>
<span class="exectime"> <span class="exectime">
(compile {$template['compile_time']|string_format:"%.5f"}) (render {$template['render_time']|string_format:"%.5f"}) (cache {$template['cache_time']|string_format:"%.5f"}) (compile {$template['compile_time']|string_format:"%.5f"}) (render {$template['render_time']|string_format:"%.5f"}) (cache {$template['cache_time']|string_format:"%.5f"})
</span> </span>
<br> <br>
{/foreach} {/foreach}
</div> </div>
<h2>assigned template variables</h2> <h2>assigned template variables</h2>
<table id="table_assigned_vars"> <table id="table_assigned_vars">
{foreach $assigned_vars as $vars} {foreach $assigned_vars as $vars}
<tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}"> <tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}">
<th>${$vars@key|escape:'html'}</th> <th>${$vars@key|escape:'html'}</th>
<td>{$vars|debug_print_var}</td></tr> <td>{$vars|debug_print_var}</td></tr>
{/foreach} {/foreach}
</table> </table>
<h2>assigned config file variables (outer template scope)</h2> <h2>assigned config file variables (outer template scope)</h2>
<table id="table_config_vars"> <table id="table_config_vars">
{foreach $config_vars as $vars} {foreach $config_vars as $vars}
<tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}"> <tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}">
<th>{$vars@key|escape:'html'}</th> <th>{$vars@key|escape:'html'}</th>
<td>{$vars|debug_print_var}</td></tr> <td>{$vars|debug_print_var}</td></tr>
{/foreach} {/foreach}
</table> </table>
</body> </body>
</html> </html>
{/capture} {/capture}
<script type="text/javascript"> <script type="text/javascript">
{literal} if ( self.name == '' ) { {literal} if ( self.name == '' ) {
var title = 'Console'; var title = 'Console';
} }
else { else {
var title = 'Console_' + self.name; var title = 'Console_' + self.name;
}{/literal} }{/literal}
_smarty_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes"); _smarty_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes");
_smarty_console.document.write("{$debug_output|escape:'javascript'}"); _smarty_console.document.write("{$debug_output|escape:'javascript'}");
_smarty_console.document.close(); _smarty_console.document.close();
</script> </script>

View File

@@ -1,39 +1,39 @@
<?php <?php
/** /**
* Smarty plugin to execute PHP code * Smarty plugin to execute PHP code
* *
* @package Smarty * @package Smarty
* @subpackage PluginsBlock * @subpackage PluginsBlock
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty {php}{/php} block plugin * Smarty {php}{/php} block plugin
* *
* @param string $content contents of the block * @param string $content contents of the block
* @param object $smarty Smarty object * @param object $smarty Smarty object
* @param boolean $ &$repeat repeat flag * @param boolean $ &$repeat repeat flag
* @param object $template template object * @param object $template template object
* @return string content re-formatted * @return string content re-formatted
*/ */
function smarty_block_php($params, $content, $smarty, &$repeat, $template) function smarty_block_php($params, $content, $smarty, &$repeat, $template)
{ {
// get security settings // get security settings
if ($template->security && isset($smarty->security_handler)) { if ($template->security && isset($smarty->security_handler)) {
$sec_obj = $smarty->security_policy; $sec_obj = $smarty->security_policy;
} else { } else {
$sec_obj = $smarty; $sec_obj = $smarty;
} }
if (is_null($content)) { if (is_null($content)) {
if (!$smarty->allow_php_tag) { if (!$smarty->allow_php_tag) {
trigger_error("{php} is deprecated, set allow_php_tag = true to enable", E_USER_WARNING); trigger_error("{php} is deprecated, set allow_php_tag = true to enable", E_USER_WARNING);
} }
return; return;
} }
eval($content); eval($content);
return ''; return '';
} }
?> ?>

View File

@@ -1,103 +1,103 @@
<?php <?php
/** /**
* Smarty plugin to format text blocks * Smarty plugin to format text blocks
* *
* @package Smarty * @package Smarty
* @subpackage PluginsBlock * @subpackage PluginsBlock
*/ */
/** /**
* Smarty {textformat}{/textformat} block plugin * Smarty {textformat}{/textformat} block plugin
* *
* Type: block function<br> * Type: block function<br>
* Name: textformat<br> * Name: textformat<br>
* Purpose: format text a certain way with preset styles * Purpose: format text a certain way with preset styles
* or custom wrap/indent settings<br> * or custom wrap/indent settings<br>
* *
* @link http://smarty.php.net/manual/en/language.function.textformat.php {textformat} * @link http://smarty.php.net/manual/en/language.function.textformat.php {textformat}
(Smarty online manual) (Smarty online manual)
* @param array $params parameters * @param array $params parameters
* <pre> * <pre>
* Params: style: string (email) * Params: style: string (email)
* indent: integer (0) * indent: integer (0)
* wrap: integer (80) * wrap: integer (80)
* wrap_char string ("\n") * wrap_char string ("\n")
* indent_char: string (" ") * indent_char: string (" ")
* wrap_boundary: boolean (true) * wrap_boundary: boolean (true)
* </pre> * </pre>
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @param string $content contents of the block * @param string $content contents of the block
* @param object $smarty Smarty object * @param object $smarty Smarty object
* @param boolean &$repeat repeat flag * @param boolean &$repeat repeat flag
* @param object $template template object * @param object $template template object
* @return string content re-formatted * @return string content re-formatted
*/ */
function smarty_block_textformat($params, $content, $smarty, &$repeat, $template) function smarty_block_textformat($params, $content, $smarty, &$repeat, $template)
{ {
if (is_null($content)) { if (is_null($content)) {
return; return;
} }
$style = null; $style = null;
$indent = 0; $indent = 0;
$indent_first = 0; $indent_first = 0;
$indent_char = ' '; $indent_char = ' ';
$wrap = 80; $wrap = 80;
$wrap_char = "\n"; $wrap_char = "\n";
$wrap_cut = false; $wrap_cut = false;
$assign = null; $assign = null;
foreach ($params as $_key => $_val) { foreach ($params as $_key => $_val) {
switch ($_key) { switch ($_key) {
case 'style': case 'style':
case 'indent_char': case 'indent_char':
case 'wrap_char': case 'wrap_char':
case 'assign': case 'assign':
$$_key = (string)$_val; $$_key = (string)$_val;
break; break;
case 'indent': case 'indent':
case 'indent_first': case 'indent_first':
case 'wrap': case 'wrap':
$$_key = (int)$_val; $$_key = (int)$_val;
break; break;
case 'wrap_cut': case 'wrap_cut':
$$_key = (bool)$_val; $$_key = (bool)$_val;
break; break;
default: default:
$smarty->trigger_error("textformat: unknown attribute '$_key'"); $smarty->trigger_error("textformat: unknown attribute '$_key'");
} }
} }
if ($style == 'email') { if ($style == 'email') {
$wrap = 72; $wrap = 72;
} }
// split into paragraphs // split into paragraphs
$_paragraphs = preg_split('![\r\n][\r\n]!', $content); $_paragraphs = preg_split('![\r\n][\r\n]!', $content);
$_output = ''; $_output = '';
for($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++) { for($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++) {
if ($_paragraphs[$_x] == '') { if ($_paragraphs[$_x] == '') {
continue; continue;
} }
// convert mult. spaces & special chars to single space // convert mult. spaces & special chars to single space
$_paragraphs[$_x] = preg_replace(array('!\s+!', '!(^\s+)|(\s+$)!'), array(' ', ''), $_paragraphs[$_x]); $_paragraphs[$_x] = preg_replace(array('!\s+!', '!(^\s+)|(\s+$)!'), array(' ', ''), $_paragraphs[$_x]);
// indent first line // indent first line
if ($indent_first > 0) { if ($indent_first > 0) {
$_paragraphs[$_x] = str_repeat($indent_char, $indent_first) . $_paragraphs[$_x]; $_paragraphs[$_x] = str_repeat($indent_char, $indent_first) . $_paragraphs[$_x];
} }
// wordwrap sentences // wordwrap sentences
$_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut); $_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut);
// indent lines // indent lines
if ($indent > 0) { if ($indent > 0) {
$_paragraphs[$_x] = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraphs[$_x]); $_paragraphs[$_x] = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraphs[$_x]);
} }
} }
$_output = implode($wrap_char . $wrap_char, $_paragraphs); $_output = implode($wrap_char . $wrap_char, $_paragraphs);
return $assign ? $template->assign($assign, $_output) : $_output; return $assign ? $template->assign($assign, $_output) : $_output;
} }
?> ?>

View File

@@ -1,78 +1,78 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {counter} function plugin * Smarty {counter} function plugin
* *
* Type: function<br> * Type: function<br>
* Name: counter<br> * Name: counter<br>
* Purpose: print out a counter value * Purpose: print out a counter value
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @link http://smarty.php.net/manual/en/language.function.counter.php {counter} * @link http://smarty.php.net/manual/en/language.function.counter.php {counter}
* (Smarty online manual) * (Smarty online manual)
* @param array $params parameters * @param array $params parameters
* @param object $smarty Smarty object * @param object $smarty Smarty object
* @param object $template template object * @param object $template template object
* @return string|null * @return string|null
*/ */
function smarty_function_counter($params, $smarty, $template) function smarty_function_counter($params, $smarty, $template)
{ {
$name = (isset($params['name'])) ? $params['name'] : 'default'; $name = (isset($params['name'])) ? $params['name'] : 'default';
if (!isset($template->plugin_data['counter'][$name])) { if (!isset($template->plugin_data['counter'][$name])) {
$template->plugin_data['counter'][$name] = array( $template->plugin_data['counter'][$name] = array(
'start'=>1, 'start'=>1,
'skip'=>1, 'skip'=>1,
'direction'=>'up', 'direction'=>'up',
'count'=>1 'count'=>1
); );
} }
$counter = &$template->plugin_data['counter'][$name]; $counter = &$template->plugin_data['counter'][$name];
if (isset($params['start'])) { if (isset($params['start'])) {
$counter['start'] = $counter['count'] = (int)$params['start']; $counter['start'] = $counter['count'] = (int)$params['start'];
} }
if (!empty($params['assign'])) { if (!empty($params['assign'])) {
$counter['assign'] = $params['assign']; $counter['assign'] = $params['assign'];
} }
if (isset($counter['assign'])) { if (isset($counter['assign'])) {
$template->assign($counter['assign'], $counter['count']); $template->assign($counter['assign'], $counter['count']);
} }
if (isset($params['print'])) { if (isset($params['print'])) {
$print = (bool)$params['print']; $print = (bool)$params['print'];
} else { } else {
$print = empty($counter['assign']); $print = empty($counter['assign']);
} }
if ($print) { if ($print) {
$retval = $counter['count']; $retval = $counter['count'];
} else { } else {
$retval = null; $retval = null;
} }
if (isset($params['skip'])) { if (isset($params['skip'])) {
$counter['skip'] = $params['skip']; $counter['skip'] = $params['skip'];
} }
if (isset($params['direction'])) { if (isset($params['direction'])) {
$counter['direction'] = $params['direction']; $counter['direction'] = $params['direction'];
} }
if ($counter['direction'] == "down") if ($counter['direction'] == "down")
$counter['count'] -= $counter['skip']; $counter['count'] -= $counter['skip'];
else else
$counter['count'] += $counter['skip']; $counter['count'] += $counter['skip'];
return $retval; return $retval;
} }
?> ?>

View File

@@ -1,29 +1,29 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* @package Smarty * @package Smarty
* @subpackage PluginsModifier * @subpackage PluginsModifier
*/ */
/** /**
* Smarty count_characters modifier plugin * Smarty count_characters modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: count_characteres<br> * Name: count_characteres<br>
* Purpose: count the number of characters in a text * Purpose: count the number of characters in a text
* @link http://smarty.php.net/manual/en/language.modifier.count.characters.php * @link http://smarty.php.net/manual/en/language.modifier.count.characters.php
* count_characters (Smarty online manual) * count_characters (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @param string $string input string * @param string $string input string
* @param boolean $include_spaces include whitespace in the character count * @param boolean $include_spaces include whitespace in the character count
* @return integer number of characters * @return integer number of characters
*/ */
function smarty_modifier_count_characters($string, $include_spaces = false) function smarty_modifier_count_characters($string, $include_spaces = false)
{ {
if ($include_spaces) if ($include_spaces)
return(strlen($string)); return(strlen($string));
return preg_match_all("/[^\s]/",$string, $match); return preg_match_all("/[^\s]/",$string, $match);
} }
?> ?>

View File

@@ -1,89 +1,89 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage Debug * @subpackage Debug
*/ */
/** /**
* Smarty debug_print_var modifier plugin * Smarty debug_print_var modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: debug_print_var<br> * Name: debug_print_var<br>
* Purpose: formats variable contents for display in the console * Purpose: formats variable contents for display in the console
* *
* @link http://smarty.php.net/manual/en/language.modifier.debug.print.var.php debug_print_var (Smarty online manual) * @link http://smarty.php.net/manual/en/language.modifier.debug.print.var.php debug_print_var (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @param array $ |object * @param array $ |object
* @param integer $ * @param integer $
* @param integer $ * @param integer $
* @return string * @return string
*/ */
class Smarty_Modifier_Debug_Print_Var { class Smarty_Modifier_Debug_Print_Var {
static function execute ($var, $depth = 0, $length = 40) static function execute ($var, $depth = 0, $length = 40)
{ {
$_replace = array("\n" => '<i>\n</i>', $_replace = array("\n" => '<i>\n</i>',
"\r" => '<i>\r</i>', "\r" => '<i>\r</i>',
"\t" => '<i>\t</i>' "\t" => '<i>\t</i>'
); );
switch (gettype($var)) { switch (gettype($var)) {
case 'array' : case 'array' :
$results = '<b>Array (' . count($var) . ')</b>'; $results = '<b>Array (' . count($var) . ')</b>';
foreach ($var as $curr_key => $curr_val) { foreach ($var as $curr_key => $curr_val) {
$results .= '<br>' . str_repeat('&nbsp;', $depth * 2) $results .= '<br>' . str_repeat('&nbsp;', $depth * 2)
. '<b>' . strtr($curr_key, $_replace) . '</b> =&gt; ' . '<b>' . strtr($curr_key, $_replace) . '</b> =&gt; '
. self::execute($curr_val, ++$depth, $length); . self::execute($curr_val, ++$depth, $length);
$depth--; $depth--;
} }
break; break;
case 'object' : case 'object' :
$object_vars = get_object_vars($var); $object_vars = get_object_vars($var);
$results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>'; $results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>';
foreach ($object_vars as $curr_key => $curr_val) { foreach ($object_vars as $curr_key => $curr_val) {
$results .= '<br>' . str_repeat('&nbsp;', $depth * 2) $results .= '<br>' . str_repeat('&nbsp;', $depth * 2)
. '<b> -&gt;' . strtr($curr_key, $_replace) . '</b> = ' . '<b> -&gt;' . strtr($curr_key, $_replace) . '</b> = '
. self::execute($curr_val, ++$depth, $length); . self::execute($curr_val, ++$depth, $length);
$depth--; $depth--;
} }
break; break;
case 'boolean' : case 'boolean' :
case 'NULL' : case 'NULL' :
case 'resource' : case 'resource' :
if (true === $var) { if (true === $var) {
$results = 'true'; $results = 'true';
} elseif (false === $var) { } elseif (false === $var) {
$results = 'false'; $results = 'false';
} elseif (null === $var) { } elseif (null === $var) {
$results = 'null'; $results = 'null';
} else { } else {
$results = htmlspecialchars((string) $var); $results = htmlspecialchars((string) $var);
} }
$results = '<i>' . $results . '</i>'; $results = '<i>' . $results . '</i>';
break; break;
case 'integer' : case 'integer' :
case 'float' : case 'float' :
$results = htmlspecialchars((string) $var); $results = htmlspecialchars((string) $var);
break; break;
case 'string' : case 'string' :
$results = strtr($var, $_replace); $results = strtr($var, $_replace);
if (strlen($var) > $length) { if (strlen($var) > $length) {
$results = substr($var, 0, $length - 3) . '...'; $results = substr($var, 0, $length - 3) . '...';
} }
$results = htmlspecialchars('"' . $results . '"'); $results = htmlspecialchars('"' . $results . '"');
break; break;
case 'unknown type' : case 'unknown type' :
default : default :
$results = strtr((string) $var, $_replace); $results = strtr((string) $var, $_replace);
if (strlen($results) > $length) { if (strlen($results) > $length) {
$results = substr($results, 0, $length - 3) . '...'; $results = substr($results, 0, $length - 3) . '...';
} }
$results = htmlspecialchars($results); $results = htmlspecialchars($results);
} }
return $results; return $results;
} }
} }
?> ?>

View File

@@ -1,48 +1,48 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* @package Smarty * @package Smarty
* @subpackage plugins * @subpackage plugins
*/ */
/** /**
* Smarty regex_replace modifier plugin * Smarty regex_replace modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: regex_replace<br> * Name: regex_replace<br>
* Purpose: regular expression search/replace * Purpose: regular expression search/replace
* @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php * @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php
* regex_replace (Smarty online manual) * regex_replace (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @param string * @param string
* @param string|array * @param string|array
* @param string|array * @param string|array
* @return string * @return string
*/ */
function smarty_modifier_regex_replace($string, $search, $replace) function smarty_modifier_regex_replace($string, $search, $replace)
{ {
if(is_array($search)) { if(is_array($search)) {
foreach($search as $idx => $s) foreach($search as $idx => $s)
$search[$idx] = _smarty_regex_replace_check($s); $search[$idx] = _smarty_regex_replace_check($s);
} else { } else {
$search = _smarty_regex_replace_check($search); $search = _smarty_regex_replace_check($search);
} }
return preg_replace($search, $replace, $string); return preg_replace($search, $replace, $string);
} }
function _smarty_regex_replace_check($search) function _smarty_regex_replace_check($search)
{ {
if (($pos = strpos($search,"\0")) !== false) if (($pos = strpos($search,"\0")) !== false)
$search = substr($search,0,$pos); $search = substr($search,0,$pos);
if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) { if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) {
/* remove eval-modifier from $search */ /* remove eval-modifier from $search */
$search = substr($search, 0, -strlen($match[1])) . preg_replace('![e\s]+!', '', $match[1]); $search = substr($search, 0, -strlen($match[1])) . preg_replace('![e\s]+!', '', $match[1]);
} }
return $search; return $search;
} }
/* vim: set expandtab: */ /* vim: set expandtab: */
?> ?>

View File

@@ -1,27 +1,27 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifier * @subpackage PluginsModifier
*/ */
/** /**
* Smarty string_format modifier plugin * Smarty string_format modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: string_format<br> * Name: string_format<br>
* Purpose: format strings via sprintf * Purpose: format strings via sprintf
* *
* @link http://smarty.php.net/manual/en/language.modifier.string.format.php string_format (Smarty online manual) * @link http://smarty.php.net/manual/en/language.modifier.string.format.php string_format (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @param string $string input string * @param string $string input string
* @param string $format format string * @param string $format format string
* @return string formatted string * @return string formatted string
*/ */
function smarty_modifier_string_format($string, $format) function smarty_modifier_string_format($string, $format)
{ {
return sprintf($format, $string); return sprintf($format, $string);
} }
?> ?>

View File

@@ -1,64 +1,64 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifier * @subpackage PluginsModifier
*/ */
/** /**
* Smarty truncate modifier plugin * Smarty truncate modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: truncate<br> * Name: truncate<br>
* Purpose: Truncate a string to a certain length if necessary, * Purpose: Truncate a string to a certain length if necessary,
* optionally splitting in the middle of a word, and * optionally splitting in the middle of a word, and
* appending the $etc string or inserting $etc into the middle. * appending the $etc string or inserting $etc into the middle.
* *
* @link http://smarty.php.net/manual/en/language.modifier.truncate.php truncate (Smarty online manual) * @link http://smarty.php.net/manual/en/language.modifier.truncate.php truncate (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @param string $string input string * @param string $string input string
* @param integer $length lenght of truncated text * @param integer $length lenght of truncated text
* @param string $etc end string * @param string $etc end string
* @param boolean $break_words truncate at word boundary * @param boolean $break_words truncate at word boundary
* @param boolean $middle truncate in the middle of text * @param boolean $middle truncate in the middle of text
* @return string truncated string * @return string truncated string
*/ */
function smarty_modifier_truncate($string, $length = 80, $etc = '...', function smarty_modifier_truncate($string, $length = 80, $etc = '...',
$break_words = false, $middle = false) $break_words = false, $middle = false)
{ {
if ($length == 0) if ($length == 0)
return ''; return '';
if (is_callable('mb_strlen')) { if (is_callable('mb_strlen')) {
if (mb_strlen($string) > $length) { if (mb_strlen($string) > $length) {
$length -= min($length, mb_strlen($etc)); $length -= min($length, mb_strlen($etc));
if (!$break_words && !$middle) { if (!$break_words && !$middle) {
$string = mb_ereg_replace('/\s+?(\S+)?$/', '', mb_substr($string, 0, $length + 1), 'p'); $string = mb_ereg_replace('/\s+?(\S+)?$/', '', mb_substr($string, 0, $length + 1), 'p');
} }
if (!$middle) { if (!$middle) {
return mb_substr($string, 0, $length) . $etc; return mb_substr($string, 0, $length) . $etc;
} else { } else {
return mb_substr($string, 0, $length / 2) . $etc . mb_substr($string, - $length / 2); return mb_substr($string, 0, $length / 2) . $etc . mb_substr($string, - $length / 2);
} }
} else { } else {
return $string; return $string;
} }
} else { } else {
if (strlen($string) > $length) { if (strlen($string) > $length) {
$length -= min($length, strlen($etc)); $length -= min($length, strlen($etc));
if (!$break_words && !$middle) { if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1)); $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1));
} }
if (!$middle) { if (!$middle) {
return substr($string, 0, $length) . $etc; return substr($string, 0, $length) . $etc;
} else { } else {
return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2); return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2);
} }
} else { } else {
return $string; return $string;
} }
} }
} }
?> ?>

View File

@@ -1,76 +1,76 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* @package Smarty * @package Smarty
* @subpackage PluginsFilter * @subpackage PluginsFilter
*/ */
/** /**
* Smarty trimwhitespace outputfilter plugin * Smarty trimwhitespace outputfilter plugin
* *
* File: outputfilter.trimwhitespace.php<br> * File: outputfilter.trimwhitespace.php<br>
* Type: outputfilter<br> * Type: outputfilter<br>
* Name: trimwhitespace<br> * Name: trimwhitespace<br>
* Date: Jan 25, 2003<br> * Date: Jan 25, 2003<br>
* Purpose: trim leading white space and blank lines from * Purpose: trim leading white space and blank lines from
* template source after it gets interpreted, cleaning * template source after it gets interpreted, cleaning
* up code and saving bandwidth. Does not affect * up code and saving bandwidth. Does not affect
* <<PRE>></PRE> and <SCRIPT></SCRIPT> blocks.<br> * <<PRE>></PRE> and <SCRIPT></SCRIPT> blocks.<br>
* Install: Drop into the plugin directory, call * Install: Drop into the plugin directory, call
* <code>$smarty->load_filter('output','trimwhitespace');</code> * <code>$smarty->load_filter('output','trimwhitespace');</code>
* from application. * from application.
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Contributions from Lars Noschinski <lars@usenet.noschinski.de> * @author Contributions from Lars Noschinski <lars@usenet.noschinski.de>
* @version 1.3 * @version 1.3
* @param string $source input string * @param string $source input string
* @param object &$smarty Smarty object * @param object &$smarty Smarty object
* @return string filtered output * @return string filtered output
*/ */
function smarty_outputfilter_trimwhitespace($source, $smarty) function smarty_outputfilter_trimwhitespace($source, $smarty)
{ {
// Pull out the script blocks // Pull out the script blocks
preg_match_all("!<script[^>]*?>.*?</script>!is", $source, $match); preg_match_all("!<script[^>]*?>.*?</script>!is", $source, $match);
$_script_blocks = $match[0]; $_script_blocks = $match[0];
$source = preg_replace("!<script[^>]*?>.*?</script>!is", $source = preg_replace("!<script[^>]*?>.*?</script>!is",
'@@@SMARTY:TRIM:SCRIPT@@@', $source); '@@@SMARTY:TRIM:SCRIPT@@@', $source);
// Pull out the pre blocks // Pull out the pre blocks
preg_match_all("!<pre[^>]*?>.*?</pre>!is", $source, $match); preg_match_all("!<pre[^>]*?>.*?</pre>!is", $source, $match);
$_pre_blocks = $match[0]; $_pre_blocks = $match[0];
$source = preg_replace("!<pre[^>]*?>.*?</pre>!is", $source = preg_replace("!<pre[^>]*?>.*?</pre>!is",
'@@@SMARTY:TRIM:PRE@@@', $source); '@@@SMARTY:TRIM:PRE@@@', $source);
// Pull out the textarea blocks // Pull out the textarea blocks
preg_match_all("!<textarea[^>]*?>.*?</textarea>!is", $source, $match); preg_match_all("!<textarea[^>]*?>.*?</textarea>!is", $source, $match);
$_textarea_blocks = $match[0]; $_textarea_blocks = $match[0];
$source = preg_replace("!<textarea[^>]*?>.*?</textarea>!is", $source = preg_replace("!<textarea[^>]*?>.*?</textarea>!is",
'@@@SMARTY:TRIM:TEXTAREA@@@', $source); '@@@SMARTY:TRIM:TEXTAREA@@@', $source);
// remove all leading spaces, tabs and carriage returns NOT // remove all leading spaces, tabs and carriage returns NOT
// preceeded by a php close tag. // preceeded by a php close tag.
$source = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source)); $source = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source));
// replace textarea blocks // replace textarea blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@",$_textarea_blocks, $source); smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@",$_textarea_blocks, $source);
// replace pre blocks // replace pre blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:PRE@@@",$_pre_blocks, $source); smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:PRE@@@",$_pre_blocks, $source);
// replace script blocks // replace script blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $source); smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $source);
return $source; return $source;
} }
function smarty_outputfilter_trimwhitespace_replace($search_str, $replace, &$subject) { function smarty_outputfilter_trimwhitespace_replace($search_str, $replace, &$subject) {
$_len = strlen($search_str); $_len = strlen($search_str);
$_pos = 0; $_pos = 0;
for ($_i=0, $_count=count($replace); $_i<$_count; $_i++) for ($_i=0, $_count=count($replace); $_i<$_count; $_i++)
if (($_pos=strpos($subject, $search_str, $_pos))!==false) if (($_pos=strpos($subject, $search_str, $_pos))!==false)
$subject = substr_replace($subject, $replace[$_i], $_pos, $_len); $subject = substr_replace($subject, $replace[$_i], $_pos, $_len);
else else
break; break;
} }
?> ?>

View File

@@ -1,21 +1,21 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsFilter * @subpackage PluginsFilter
*/ */
/** /**
* Smarty htmlspecialchars variablefilter plugin * Smarty htmlspecialchars variablefilter plugin
* *
* @param string $source input string * @param string $source input string
* @param object $ &$smarty Smarty object * @param object $ &$smarty Smarty object
* @return string filtered output * @return string filtered output
*/ */
function smarty_variablefilter_htmlspecialchars($source, &$smarty) function smarty_variablefilter_htmlspecialchars($source, &$smarty)
{ {
return htmlspecialchars($source, ENT_QUOTES); return htmlspecialchars($source, ENT_QUOTES);
} }
?> ?>

View File

@@ -1,91 +1,91 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Block * Smarty Internal Plugin Compile Block
* *
* Compiles the {block}{/block} tags * Compiles the {block}{/block} tags
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Block Class * Smarty Internal Plugin Compile Block Class
*/ */
class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {block} tag * Compiles code for the {block} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return boolean true * @return boolean true
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
$this->required_attributes = array('name'); $this->required_attributes = array('name');
$this->optional_attributes = array('assign'); $this->optional_attributes = array('assign');
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
$save = array($_attr, $compiler->template->extracted_compiled_code, $compiler->template->extract_code); $save = array($_attr, $compiler->template->extracted_compiled_code, $compiler->template->extract_code);
$this->_open_tag('block', $save); $this->_open_tag('block', $save);
$compiler->template->extract_code = true; $compiler->template->extract_code = true;
$compiler->template->extracted_compiled_code = ''; $compiler->template->extracted_compiled_code = '';
$compiler->template->has_code = false; $compiler->template->has_code = false;
return true; return true;
} }
} }
/** /**
* Smarty Internal Plugin Compile BlockClose Class * Smarty Internal Plugin Compile BlockClose Class
*/ */
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {/block} tag * Compiles code for the {/block} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
$this->smarty = $compiler->smarty; $this->smarty = $compiler->smarty;
$this->compiler->has_code = true; $this->compiler->has_code = true;
// turn off block code extraction // turn off block code extraction
$compiler->template->extract_code = false; $compiler->template->extract_code = false;
// check and get attributes // check and get attributes
$this->optional_attributes = array('name'); $this->optional_attributes = array('name');
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
$saved_data = $this->_close_tag(array('block')); $saved_data = $this->_close_tag(array('block'));
// if name does match to opening tag // if name does match to opening tag
if (isset($_attr['name']) && $saved_data[0]['name'] != $_attr['name']) { if (isset($_attr['name']) && $saved_data[0]['name'] != $_attr['name']) {
$this->compiler->trigger_template_error('mismatching name attributes "' . $saved_data[0]['name'] . '" and "' . $_attr['name'] . '"'); $this->compiler->trigger_template_error('mismatching name attributes "' . $saved_data[0]['name'] . '" and "' . $_attr['name'] . '"');
} }
$_name = trim($saved_data[0]['name'], "\"'"); $_name = trim($saved_data[0]['name'], "\"'");
if (isset($this->smarty->block_data[$_name])) { if (isset($this->smarty->block_data[$_name])) {
if (strpos($this->smarty->block_data[$_name]['compiled'], '%%%%SMARTY_PARENT%%%%') !== false) { if (strpos($this->smarty->block_data[$_name]['compiled'], '%%%%SMARTY_PARENT%%%%') !== false) {
$_output = str_replace('%%%%SMARTY_PARENT%%%%', $compiler->template->extracted_compiled_code, $this->smarty->block_data[$_name]['compiled']); $_output = str_replace('%%%%SMARTY_PARENT%%%%', $compiler->template->extracted_compiled_code, $this->smarty->block_data[$_name]['compiled']);
} elseif ($this->smarty->block_data[$_name]['mode'] == 'prepend') { } elseif ($this->smarty->block_data[$_name]['mode'] == 'prepend') {
$_output = $this->smarty->block_data[$_name]['compiled'] . $compiler->template->extracted_compiled_code; $_output = $this->smarty->block_data[$_name]['compiled'] . $compiler->template->extracted_compiled_code;
} elseif ($this->smarty->block_data[$_name]['mode'] == 'append') { } elseif ($this->smarty->block_data[$_name]['mode'] == 'append') {
$_output = $compiler->template->extracted_compiled_code . $this->smarty->block_data[$_name]['compiled']; $_output = $compiler->template->extracted_compiled_code . $this->smarty->block_data[$_name]['compiled'];
} elseif (!empty($this->smarty->block_data[$_name])) { } elseif (!empty($this->smarty->block_data[$_name])) {
$_output = $this->smarty->block_data[$_name]['compiled']; $_output = $this->smarty->block_data[$_name]['compiled'];
} }
} else { } else {
$_output = $compiler->template->extracted_compiled_code; $_output = $compiler->template->extracted_compiled_code;
} }
$compiler->template->extracted_compiled_code = $saved_data[1]; $compiler->template->extracted_compiled_code = $saved_data[1];
$compiler->template->extract_code = $saved_data[2]; $compiler->template->extract_code = $saved_data[2];
// check for includes in block tags // check for includes in block tags
preg_match('/(\<\?php \$_smarty_tpl-\>decodeProperties\(\')(.*)(\'.*\?\>)/', $_output, $matches); preg_match('/(\<\?php \$_smarty_tpl-\>decodeProperties\(\')(.*)(\'.*\?\>)/', $_output, $matches);
$_output = preg_replace(array('/(\<\?php \$_smarty_tpl-\>decodeProperties\(\')(.*)(\'.*\?\>.*\n)/', '/(\<\?php if\(\!defined\(\'SMARTY_DIR\'\)\))(.*)(\?\>.*\n)/'), '', $_output); $_output = preg_replace(array('/(\<\?php \$_smarty_tpl-\>decodeProperties\(\')(.*)(\'.*\?\>.*\n)/', '/(\<\?php if\(\!defined\(\'SMARTY_DIR\'\)\))(.*)(\?\>.*\n)/'), '', $_output);
if (isset($matches[2])) { if (isset($matches[2])) {
$prop = unserialize($matches[2]); $prop = unserialize($matches[2]);
$compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $prop['file_dependency']); $compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $prop['file_dependency']);
} }
return $_output; return $_output;
} }
} }
?> ?>

View File

@@ -1,64 +1,64 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Block Plugin * Smarty Internal Plugin Compile Block Plugin
* *
* Compiles code for the execution of block plugin * Compiles code for the execution of block plugin
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Block Plugin Class * Smarty Internal Plugin Compile Block Plugin Class
*/ */
class Smarty_Internal_Compile_Block_Plugin extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Block_Plugin extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the execution of block plugin * Compiles code for the execution of block plugin
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param string $tag name of block function * @param string $tag name of block function
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $tag) public function compile($args, $compiler, $tag)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
if (strlen($tag) < 6 || substr_compare($tag, 'close', -5, 5) != 0) { if (strlen($tag) < 6 || substr_compare($tag, 'close', -5, 5) != 0) {
// opening tag of block plugin // opening tag of block plugin
$this->required_attributes = array(); $this->required_attributes = array();
$this->optional_attributes = array('_any'); $this->optional_attributes = array('_any');
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
// convert attributes into parameter array string // convert attributes into parameter array string
$_paramsArray = array(); $_paramsArray = array();
foreach ($_attr as $_key => $_value) { foreach ($_attr as $_key => $_value) {
$_paramsArray[] = "'$_key'=>$_value"; $_paramsArray[] = "'$_key'=>$_value";
} }
$_params = 'array(' . implode(",", $_paramsArray) . ')'; $_params = 'array(' . implode(",", $_paramsArray) . ')';
$this->_open_tag($tag, array($_params, $this->compiler->nocache)); $this->_open_tag($tag, array($_params, $this->compiler->nocache));
// not cachable? // not cachable?
if (isset($this->compiler->smarty->registered_plugins[$tag]) && !$this->compiler->smarty->registered_plugins[$tag][2]) { if (isset($this->compiler->smarty->registered_plugins[$tag]) && !$this->compiler->smarty->registered_plugins[$tag][2]) {
$this->compiler->nocache = true; $this->compiler->nocache = true;
} }
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
$this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache; $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
// compile code // compile code
$output = '<?php $_block_repeat=true; $_smarty_tpl->smarty->plugin_handler->' . $tag . '(array(' . $_params . ', null, $_smarty_tpl->smarty, &$_block_repeat, $_smarty_tpl),\'block\');while ($_block_repeat) { ob_start();?>'; $output = '<?php $_block_repeat=true; $_smarty_tpl->smarty->plugin_handler->' . $tag . '(array(' . $_params . ', null, $_smarty_tpl->smarty, &$_block_repeat, $_smarty_tpl),\'block\');while ($_block_repeat) { ob_start();?>';
} else { } else {
// must endblock be nocache? // must endblock be nocache?
if ($this->compiler->nocache) { if ($this->compiler->nocache) {
$this->compiler->tag_nocache = true; $this->compiler->tag_nocache = true;
} }
// closing tag of block plugin, restore nocache // closing tag of block plugin, restore nocache
list($_params, $this->compiler->nocache) = $this->_close_tag(substr($tag, 0, -5)); list($_params, $this->compiler->nocache) = $this->_close_tag(substr($tag, 0, -5));
// This tag does create output // This tag does create output
$this->compiler->has_output = true; $this->compiler->has_output = true;
// compile code // compile code
$output = '<?php $_block_content = ob_get_clean(); $_block_repeat=false; echo $_smarty_tpl->smarty->plugin_handler->' . substr($tag, 0, -5) . '(array(' . $_params . ', $_block_content, $_smarty_tpl->smarty, &$_block_repeat, $_smarty_tpl),\'block\'); }?>'; $output = '<?php $_block_content = ob_get_clean(); $_block_repeat=false; echo $_smarty_tpl->smarty->plugin_handler->' . substr($tag, 0, -5) . '(array(' . $_params . ', $_block_content, $_smarty_tpl->smarty, &$_block_repeat, $_smarty_tpl),\'block\'); }?>';
} }
return $output; return $output;
} }
} }
?> ?>

View File

@@ -1,72 +1,72 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Capture * Smarty Internal Plugin Compile Capture
* *
* Compiles the {capture} tag * Compiles the {capture} tag
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Capture Class * Smarty Internal Plugin Compile Capture Class
*/ */
class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {capture} tag * Compiles code for the {capture} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
$this->optional_attributes = array('name', 'assign', 'append'); $this->optional_attributes = array('name', 'assign', 'append');
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
$buffer = isset($_attr['name']) ? $_attr['name'] : "'default'"; $buffer = isset($_attr['name']) ? $_attr['name'] : "'default'";
$assign = isset($_attr['assign']) ? $_attr['assign'] : null; $assign = isset($_attr['assign']) ? $_attr['assign'] : null;
$append = isset($_attr['append']) ? $_attr['append'] : null; $append = isset($_attr['append']) ? $_attr['append'] : null;
$this->compiler->_capture_stack[] = array($buffer, $assign, $append); $this->compiler->_capture_stack[] = array($buffer, $assign, $append);
$_output = "<?php ob_start(); ?>"; $_output = "<?php ob_start(); ?>";
return $_output; return $_output;
} }
} }
/** /**
* Smarty Internal Plugin Compile Captureclose Class * Smarty Internal Plugin Compile Captureclose Class
*/ */
class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {/capture} tag * Compiles code for the {/capture} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
list($buffer, $assign, $append) = array_pop($this->compiler->_capture_stack); list($buffer, $assign, $append) = array_pop($this->compiler->_capture_stack);
$_output = "<?php "; $_output = "<?php ";
if (isset($assign)) { if (isset($assign)) {
$_output .= " \$_smarty_tpl->assign($assign, ob_get_contents());"; $_output .= " \$_smarty_tpl->assign($assign, ob_get_contents());";
} }
if (isset($append)) { if (isset($append)) {
$_output .= " \$_smarty_tpl->append($append, ob_get_contents());"; $_output .= " \$_smarty_tpl->append($append, ob_get_contents());";
} }
$_output .= " \$_smarty_tpl->smarty->_smarty_vars['capture'][$buffer]=ob_get_clean(); ?>"; $_output .= " \$_smarty_tpl->smarty->_smarty_vars['capture'][$buffer]=ob_get_clean(); ?>";
return $_output; return $_output;
} }
} }
?> ?>

View File

@@ -1,34 +1,34 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Debug * Smarty Internal Plugin Compile Debug
* *
* Compiles the {debug} tag * Compiles the {debug} tag
* It opens a window the the Smarty Debugging Console * It opens a window the the Smarty Debugging Console
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Debug Class * Smarty Internal Plugin Compile Debug Class
*/ */
class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {debug} tag * Compiles code for the {debug} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
// display debug template // display debug template
$_output = "<?php \$_smarty_tpl->smarty->loadPlugin('Smarty_Internal_Debug'); Smarty_Internal_Debug::display_debug(\$_smarty_tpl->smarty); ?>"; $_output = "<?php \$_smarty_tpl->smarty->loadPlugin('Smarty_Internal_Debug'); Smarty_Internal_Debug::display_debug(\$_smarty_tpl->smarty); ?>";
return $_output; return $_output;
} }
} }
?> ?>

View File

@@ -1,109 +1,109 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile For * Smarty Internal Plugin Compile For
* *
* Compiles the {for} {forelse} {/for} tags * Compiles the {for} {forelse} {/for} tags
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile For Class * Smarty Internal Plugin Compile For Class
*/ */
class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {for} tag * Compiles code for the {for} tag
* *
* Smarty 3 does implement two different sytaxes: * Smarty 3 does implement two different sytaxes:
* *
* - {for $var in $array} * - {for $var in $array}
* For looping over arrays or iterators * For looping over arrays or iterators
* *
* - {for $x=0; $x<$y; $x++} * - {for $x=0; $x<$y; $x++}
* For general loops * For general loops
* *
* The parser is gereration different sets of attribute by which this compiler can * The parser is gereration different sets of attribute by which this compiler can
* determin which syntax is used. * determin which syntax is used.
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
// {for $x=0; $x<$y; $x++} syntax // {for $x=0; $x<$y; $x++} syntax
$this->required_attributes = array('ifexp', 'start', 'loop', 'varloop'); $this->required_attributes = array('ifexp', 'start', 'loop', 'varloop');
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
$this->_open_tag('for', array('for',$this->compiler->nocache)); $this->_open_tag('for', array('for',$this->compiler->nocache));
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
$this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache; $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
$output = "<?php "; $output = "<?php ";
foreach ($_attr['start'] as $_statement) { foreach ($_attr['start'] as $_statement) {
$output .= " \$_smarty_tpl->tpl_vars[$_statement[var]] = new Smarty_Variable;"; $output .= " \$_smarty_tpl->tpl_vars[$_statement[var]] = new Smarty_Variable;";
$output .= " \$_smarty_tpl->tpl_vars[$_statement[var]]->value = $_statement[value];\n"; $output .= " \$_smarty_tpl->tpl_vars[$_statement[var]]->value = $_statement[value];\n";
} }
$output .= " if ($_attr[ifexp]){ for (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$_attr[varloop]]->value$_attr[loop]){\n"; $output .= " if ($_attr[ifexp]){ for (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$_attr[varloop]]->value$_attr[loop]){\n";
$output .= "?>"; $output .= "?>";
// return compiled code // return compiled code
return $output; return $output;
} }
} }
/** /**
* Smarty Internal Plugin Compile Forelse Class * Smarty Internal Plugin Compile Forelse Class
*/ */
class Smarty_Internal_Compile_Forelse extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Forelse extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {forelse} tag * Compiles code for the {forelse} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
list($_open_tag, $this->compiler->nocache) = $this->_close_tag(array('for')); list($_open_tag, $this->compiler->nocache) = $this->_close_tag(array('for'));
$this->_open_tag('forelse',array('forelse', $this->compiler->nocache)); $this->_open_tag('forelse',array('forelse', $this->compiler->nocache));
return "<?php }} else { ?>"; return "<?php }} else { ?>";
} }
} }
/** /**
* Smarty Internal Plugin Compile Forclose Class * Smarty Internal Plugin Compile Forclose Class
*/ */
class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {/for} tag * Compiles code for the {/for} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
// must endblock be nocache? // must endblock be nocache?
if ($this->compiler->nocache) { if ($this->compiler->nocache) {
$this->compiler->tag_nocache = true; $this->compiler->tag_nocache = true;
} }
list($_open_tag, $this->compiler->nocache) = $this->_close_tag(array('for', 'forelse')); list($_open_tag, $this->compiler->nocache) = $this->_close_tag(array('for', 'forelse'));
if ($_open_tag == 'forelse') if ($_open_tag == 'forelse')
return "<?php } ?>"; return "<?php } ?>";
else else
return "<?php }} ?>"; return "<?php }} ?>";
} }
} }
?> ?>

View File

@@ -1,192 +1,192 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Foreach * Smarty Internal Plugin Compile Foreach
* *
* Compiles the {foreach} {foreachelse} {/foreach} tags * Compiles the {foreach} {foreachelse} {/foreach} tags
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Foreach Class * Smarty Internal Plugin Compile Foreach Class
*/ */
class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {foreach} tag * Compiles code for the {foreach} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
$this->required_attributes = array('from', 'item'); $this->required_attributes = array('from', 'item');
$this->optional_attributes = array('name', 'key'); $this->optional_attributes = array('name', 'key');
$tpl = $compiler->template; $tpl = $compiler->template;
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
$this->_open_tag('foreach', array('foreach',$this->compiler->nocache)); $this->_open_tag('foreach', array('foreach',$this->compiler->nocache));
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
$this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache; $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
$from = $_attr['from']; $from = $_attr['from'];
$item = $_attr['item']; $item = $_attr['item'];
if (isset($_attr['key'])) { if (isset($_attr['key'])) {
$key = $_attr['key']; $key = $_attr['key'];
} else { } else {
$key = null; $key = null;
} }
if (isset($_attr['name'])) { if (isset($_attr['name'])) {
$name = $_attr['name']; $name = $_attr['name'];
$has_name = true; $has_name = true;
$SmartyVarName = '$smarty.foreach.' . trim($name,'\'"') . '.'; $SmartyVarName = '$smarty.foreach.' . trim($name,'\'"') . '.';
} else { } else {
$name = null; $name = null;
$has_name = false; $has_name = false;
} }
$ItemVarName = '$' . trim($item,'\'"') . '@'; $ItemVarName = '$' . trim($item,'\'"') . '@';
// evaluates which Smarty variables and properties have to be computed // evaluates which Smarty variables and properties have to be computed
if ($has_name) { if ($has_name) {
$usesSmartyFirst = strpos($tpl->template_source, $SmartyVarName . 'first') !== false; $usesSmartyFirst = strpos($tpl->template_source, $SmartyVarName . 'first') !== false;
$usesSmartyLast = strpos($tpl->template_source, $SmartyVarName . 'last') !== false; $usesSmartyLast = strpos($tpl->template_source, $SmartyVarName . 'last') !== false;
$usesSmartyIndex = strpos($tpl->template_source, $SmartyVarName . 'index') !== false; $usesSmartyIndex = strpos($tpl->template_source, $SmartyVarName . 'index') !== false;
$usesSmartyIteration = strpos($tpl->template_source, $SmartyVarName . 'iteration') !== false; $usesSmartyIteration = strpos($tpl->template_source, $SmartyVarName . 'iteration') !== false;
$usesSmartyShow = strpos($tpl->template_source, $SmartyVarName . 'show') !== false; $usesSmartyShow = strpos($tpl->template_source, $SmartyVarName . 'show') !== false;
$usesSmartyTotal = $usesSmartyLast || strpos($tpl->template_source, $SmartyVarName . 'total') !== false; $usesSmartyTotal = $usesSmartyLast || strpos($tpl->template_source, $SmartyVarName . 'total') !== false;
} else { } else {
$usesSmartyFirst = false; $usesSmartyFirst = false;
$usesSmartyLast = false; $usesSmartyLast = false;
$usesSmartyTotal = false; $usesSmartyTotal = false;
} }
$usesPropFirst = $usesSmartyFirst || strpos($tpl->template_source, $ItemVarName . 'first') !== false; $usesPropFirst = $usesSmartyFirst || strpos($tpl->template_source, $ItemVarName . 'first') !== false;
$usesPropLast = $usesSmartyLast || strpos($tpl->template_source, $ItemVarName . 'last') !== false; $usesPropLast = $usesSmartyLast || strpos($tpl->template_source, $ItemVarName . 'last') !== false;
$usesPropIndex = $usesPropFirst || strpos($tpl->template_source, $ItemVarName . 'index') !== false; $usesPropIndex = $usesPropFirst || strpos($tpl->template_source, $ItemVarName . 'index') !== false;
$usesPropIteration = $usesPropLast || strpos($tpl->template_source, $ItemVarName . 'iteration') !== false; $usesPropIteration = $usesPropLast || strpos($tpl->template_source, $ItemVarName . 'iteration') !== false;
$usesPropShow = strpos($tpl->template_source, $ItemVarName . 'show') !== false; $usesPropShow = strpos($tpl->template_source, $ItemVarName . 'show') !== false;
$usesPropTotal = $usesSmartyTotal || $usesPropLast || strpos($tpl->template_source, $ItemVarName . 'total') !== false; $usesPropTotal = $usesSmartyTotal || $usesPropLast || strpos($tpl->template_source, $ItemVarName . 'total') !== false;
// generate output code // generate output code
$output = "<?php "; $output = "<?php ";
$output .= " \$_smarty_tpl->tpl_vars[$item] = new Smarty_Variable;\n"; $output .= " \$_smarty_tpl->tpl_vars[$item] = new Smarty_Variable;\n";
if ($key != null) { if ($key != null) {
$output .= " \$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable;\n"; $output .= " \$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable;\n";
} }
$output .= " \$_from = $from; if (!is_array(\$_from) && !is_object(\$_from)) { settype(\$_from, 'array');}\n"; $output .= " \$_from = $from; if (!is_array(\$_from) && !is_object(\$_from)) { settype(\$_from, 'array');}\n";
if ($usesPropTotal) { if ($usesPropTotal) {
$output .= " \$_smarty_tpl->tpl_vars[$item]->total=count(\$_from);\n"; $output .= " \$_smarty_tpl->tpl_vars[$item]->total=count(\$_from);\n";
} }
if ($usesPropIteration) { if ($usesPropIteration) {
$output .= " \$_smarty_tpl->tpl_vars[$item]->iteration=0;\n"; $output .= " \$_smarty_tpl->tpl_vars[$item]->iteration=0;\n";
} }
if ($usesPropIndex) { if ($usesPropIndex) {
$output .= " \$_smarty_tpl->tpl_vars[$item]->index=-1;\n"; $output .= " \$_smarty_tpl->tpl_vars[$item]->index=-1;\n";
} }
if ($has_name) { if ($has_name) {
if ($usesSmartyTotal) { if ($usesSmartyTotal) {
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['total'] = \$_smarty_tpl->tpl_vars[$item]->total;\n"; $output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['total'] = \$_smarty_tpl->tpl_vars[$item]->total;\n";
} }
if ($usesSmartyIteration) { if ($usesSmartyIteration) {
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['iteration']=0;\n"; $output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['iteration']=0;\n";
} }
if ($usesSmartyIndex) { if ($usesSmartyIndex) {
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['index']=-1;\n"; $output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['index']=-1;\n";
} }
} }
$output .= "if (count(\$_from) > 0){\n"; $output .= "if (count(\$_from) > 0){\n";
$output .= " foreach (\$_from as \$_smarty_tpl->tpl_vars[$item]->key => \$_smarty_tpl->tpl_vars[$item]->value){\n"; $output .= " foreach (\$_from as \$_smarty_tpl->tpl_vars[$item]->key => \$_smarty_tpl->tpl_vars[$item]->value){\n";
if ($key != null) { if ($key != null) {
$output .= " \$_smarty_tpl->tpl_vars[$key]->value = \$_smarty_tpl->tpl_vars[$item]->key;\n"; $output .= " \$_smarty_tpl->tpl_vars[$key]->value = \$_smarty_tpl->tpl_vars[$item]->key;\n";
} }
if ($usesPropIteration) { if ($usesPropIteration) {
$output .= " \$_smarty_tpl->tpl_vars[$item]->iteration++;\n"; $output .= " \$_smarty_tpl->tpl_vars[$item]->iteration++;\n";
} }
if ($usesPropIndex) { if ($usesPropIndex) {
$output .= " \$_smarty_tpl->tpl_vars[$item]->index++;\n"; $output .= " \$_smarty_tpl->tpl_vars[$item]->index++;\n";
} }
if ($usesPropFirst) { if ($usesPropFirst) {
$output .= " \$_smarty_tpl->tpl_vars[$item]->first = \$_smarty_tpl->tpl_vars[$item]->index === 0;\n"; $output .= " \$_smarty_tpl->tpl_vars[$item]->first = \$_smarty_tpl->tpl_vars[$item]->index === 0;\n";
} }
if ($usesPropLast) { if ($usesPropLast) {
$output .= " \$_smarty_tpl->tpl_vars[$item]->last = \$_smarty_tpl->tpl_vars[$item]->iteration === \$_smarty_tpl->tpl_vars[$item]->total;\n"; $output .= " \$_smarty_tpl->tpl_vars[$item]->last = \$_smarty_tpl->tpl_vars[$item]->iteration === \$_smarty_tpl->tpl_vars[$item]->total;\n";
} }
if ($has_name) { if ($has_name) {
if ($usesSmartyFirst) { if ($usesSmartyFirst) {
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['first'] = \$_smarty_tpl->tpl_vars[$item]->first;\n"; $output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['first'] = \$_smarty_tpl->tpl_vars[$item]->first;\n";
} }
if ($usesSmartyIteration) { if ($usesSmartyIteration) {
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['iteration']++;\n"; $output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['iteration']++;\n";
} }
if ($usesSmartyIndex) { if ($usesSmartyIndex) {
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['index']++;\n"; $output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['index']++;\n";
} }
if ($usesSmartyLast) { if ($usesSmartyLast) {
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['last'] = \$_smarty_tpl->tpl_vars[$item]->last;\n"; $output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['last'] = \$_smarty_tpl->tpl_vars[$item]->last;\n";
} }
} }
$output .= "?>"; $output .= "?>";
return $output; return $output;
} }
} }
/** /**
* Smarty Internal Plugin Compile Foreachelse Class * Smarty Internal Plugin Compile Foreachelse Class
*/ */
class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {foreachelse} tag * Compiles code for the {foreachelse} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
list($_open_tag, $this->compiler->nocache) = $this->_close_tag(array('foreach')); list($_open_tag, $this->compiler->nocache) = $this->_close_tag(array('foreach'));
$this->_open_tag('foreachelse',array('foreachelse', $this->compiler->nocache)); $this->_open_tag('foreachelse',array('foreachelse', $this->compiler->nocache));
return "<?php }} else { ?>"; return "<?php }} else { ?>";
} }
} }
/** /**
* Smarty Internal Plugin Compile Foreachclose Class * Smarty Internal Plugin Compile Foreachclose Class
*/ */
class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {/foreach} tag * Compiles code for the {/foreach} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
// must endblock be nocache? // must endblock be nocache?
if ($this->compiler->nocache) { if ($this->compiler->nocache) {
$this->compiler->tag_nocache = true; $this->compiler->tag_nocache = true;
} }
list($_open_tag, $this->compiler->nocache) = $this->_close_tag(array('foreach', 'foreachelse')); list($_open_tag, $this->compiler->nocache) = $this->_close_tag(array('foreach', 'foreachelse'));
if ($_open_tag == 'foreachelse') if ($_open_tag == 'foreachelse')
return "<?php } ?>"; return "<?php } ?>";
else else
return "<?php }} ?>"; return "<?php }} ?>";
} }
} }
?> ?>

View File

@@ -1,79 +1,79 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Function * Smarty Internal Plugin Compile Function
* *
* Compiles the {function} {/function} tags * Compiles the {function} {/function} tags
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Function Class * Smarty Internal Plugin Compile Function Class
*/ */
class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {function} tag * Compiles code for the {function} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return boolean true * @return boolean true
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
$this->required_attributes = array('name'); $this->required_attributes = array('name');
$this->optional_attributes = array('_any'); $this->optional_attributes = array('_any');
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
$save = array($_attr, $compiler->template->extracted_compiled_code, $compiler->template->extract_code); $save = array($_attr, $compiler->template->extracted_compiled_code, $compiler->template->extract_code);
$this->_open_tag('function', $save); $this->_open_tag('function', $save);
$_name = trim($_attr['name'], "'"); $_name = trim($_attr['name'], "'");
foreach ($_attr as $_key => $_data) { foreach ($_attr as $_key => $_data) {
$compiler->template->properties['function'][$_name]['parameter'][$_key] = $_data; $compiler->template->properties['function'][$_name]['parameter'][$_key] = $_data;
} }
// make function known for recursive calls // make function known for recursive calls
$this->compiler->smarty->template_functions[$_name]['compiled'] = ''; $this->compiler->smarty->template_functions[$_name]['compiled'] = '';
$compiler->template->extract_code = true; $compiler->template->extract_code = true;
$compiler->template->extracted_compiled_code = ''; $compiler->template->extracted_compiled_code = '';
$compiler->template->has_code = false; $compiler->template->has_code = false;
return true; return true;
} }
} }
/** /**
* Smarty Internal Plugin Compile Functionclose Class * Smarty Internal Plugin Compile Functionclose Class
*/ */
class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {/function} tag * Compiles code for the {/function} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return boolean true * @return boolean true
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
$this->compiler->has_code = false; $this->compiler->has_code = false;
// turn off block code extraction // turn off block code extraction
$compiler->template->extract_code = false; $compiler->template->extract_code = false;
// check and get attributes // check and get attributes
$this->optional_attributes = array('name'); $this->optional_attributes = array('name');
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
$saved_data = $this->_close_tag(array('function')); $saved_data = $this->_close_tag(array('function'));
// if name does match to opening tag // if name does match to opening tag
if (isset($_attr['name']) && $saved_data[0]['name'] != $_attr['name']) { if (isset($_attr['name']) && $saved_data[0]['name'] != $_attr['name']) {
$this->compiler->trigger_template_error('mismatching name attributes "' . $saved_data[0]['name'] . '" and "' . $_attr['name'] . '"'); $this->compiler->trigger_template_error('mismatching name attributes "' . $saved_data[0]['name'] . '" and "' . $_attr['name'] . '"');
} }
$_name = trim($saved_data[0]['name'], "'"); $_name = trim($saved_data[0]['name'], "'");
$compiler->template->properties['function'][$_name]['compiled'] = str_replace("\n",'_%n',$compiler->template->extracted_compiled_code); $compiler->template->properties['function'][$_name]['compiled'] = str_replace("\n",'_%n',$compiler->template->extracted_compiled_code);
$this->compiler->smarty->template_functions[$_name]['compiled'] = $compiler->template->extracted_compiled_code; $this->compiler->smarty->template_functions[$_name]['compiled'] = $compiler->template->extracted_compiled_code;
$this->compiler->smarty->template_functions[$_name]['parameter'] = $compiler->template->properties['function'][$_name]['parameter']; $this->compiler->smarty->template_functions[$_name]['parameter'] = $compiler->template->properties['function'][$_name]['parameter'];
$compiler->template->extracted_compiled_code = $saved_data[1]; $compiler->template->extracted_compiled_code = $saved_data[1];
$compiler->template->extract_code = $saved_data[2]; $compiler->template->extract_code = $saved_data[2];
return true; return true;
} }
} }
?> ?>

View File

@@ -1,114 +1,114 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile If * Smarty Internal Plugin Compile If
* *
* Compiles the {if} {else} {elseif} {/if} tags * Compiles the {if} {else} {elseif} {/if} tags
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile If Class * Smarty Internal Plugin Compile If Class
*/ */
class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {if} tag * Compiles code for the {if} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
$this->required_attributes = array('if condition'); $this->required_attributes = array('if condition');
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
$this->_open_tag('if',array(1,$compiler->tag_nocache)); $this->_open_tag('if',array(1,$compiler->tag_nocache));
if (is_array($args['if condition'])) { if (is_array($args['if condition'])) {
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[".$args['if condition']['var']."])) \$_smarty_tpl->tpl_vars[".$args['if condition']['var']."] = new Smarty_Variable;"; $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[".$args['if condition']['var']."])) \$_smarty_tpl->tpl_vars[".$args['if condition']['var']."] = new Smarty_Variable;";
$_output .= "if (\$_smarty_tpl->tpl_vars[".$args['if condition']['var']."]->value = ".$args['if condition']['value']."){?>"; $_output .= "if (\$_smarty_tpl->tpl_vars[".$args['if condition']['var']."]->value = ".$args['if condition']['value']."){?>";
return $_output; return $_output;
} else { } else {
return '<?php if (' . $args['if condition'] . '){?>'; return '<?php if (' . $args['if condition'] . '){?>';
} }
} }
} }
/** /**
* Smarty Internal Plugin Compile Else Class * Smarty Internal Plugin Compile Else Class
*/ */
class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {else} tag * Compiles code for the {else} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
list($nesting, $compiler->tag_nocache) = $this->_close_tag(array('if', 'elseif')); list($nesting, $compiler->tag_nocache) = $this->_close_tag(array('if', 'elseif'));
$this->_open_tag('else',array($nesting,$compiler->tag_nocache)); $this->_open_tag('else',array($nesting,$compiler->tag_nocache));
return '<?php }else{ ?>'; return '<?php }else{ ?>';
} }
} }
/** /**
* Smarty Internal Plugin Compile ElseIf Class * Smarty Internal Plugin Compile ElseIf Class
*/ */
class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {elseif} tag * Compiles code for the {elseif} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
$this->required_attributes = array('if condition'); $this->required_attributes = array('if condition');
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
list($nesting, $compiler->tag_nocache) = $this->_close_tag(array('if', 'elseif')); list($nesting, $compiler->tag_nocache) = $this->_close_tag(array('if', 'elseif'));
if (empty($this->compiler->prefix_code)) { if (empty($this->compiler->prefix_code)) {
$this->_open_tag('elseif', array($nesting, $compiler->tag_nocache)); $this->_open_tag('elseif', array($nesting, $compiler->tag_nocache));
return '<?php }elseif(' . $args['if condition'] . '){?>'; return '<?php }elseif(' . $args['if condition'] . '){?>';
} else { } else {
$tmp = ''; $tmp = '';
foreach ($this->compiler->prefix_code as $code) $tmp .= $code; foreach ($this->compiler->prefix_code as $code) $tmp .= $code;
$this->compiler->prefix_code = array(); $this->compiler->prefix_code = array();
$this->_open_tag('elseif', array($nesting + 1, $compiler->tag_nocache)); $this->_open_tag('elseif', array($nesting + 1, $compiler->tag_nocache));
return '<?php }else{?>' . $tmp . '<?php if (' . $args['if condition'] . '){?>'; return '<?php }else{?>' . $tmp . '<?php if (' . $args['if condition'] . '){?>';
} }
} }
} }
/** /**
* Smarty Internal Plugin Compile Ifclose Class * Smarty Internal Plugin Compile Ifclose Class
*/ */
class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {/if} tag * Compiles code for the {/if} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
list($nesting, $compiler->tag_nocache) = $this->_close_tag(array('if', 'else', 'elseif')); list($nesting, $compiler->tag_nocache) = $this->_close_tag(array('if', 'else', 'elseif'));
$tmp = ''; $tmp = '';
for ($i = 0; $i < $nesting ; $i++) $tmp .= '}'; for ($i = 0; $i < $nesting ; $i++) $tmp .= '}';
return "<?php $tmp?>"; return "<?php $tmp?>";
} }
} }
?> ?>

View File

@@ -1,159 +1,159 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Include * Smarty Internal Plugin Compile Include
* *
* Compiles the {include} tag * Compiles the {include} tag
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Include Class * Smarty Internal Plugin Compile Include Class
*/ */
class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {include} tag * Compiles code for the {include} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
$this->required_attributes = array('file'); $this->required_attributes = array('file');
$this->optional_attributes = array('_any'); $this->optional_attributes = array('_any');
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
// save posible attributes // save posible attributes
$include_file = $_attr['file']; $include_file = $_attr['file'];
$has_compiled_template = false; $has_compiled_template = false;
if ($compiler->smarty->merge_compiled_includes) { if ($compiler->smarty->merge_compiled_includes) {
// check if compiled code can be merged (contains no variable part) // check if compiled code can be merged (contains no variable part)
if (!$compiler->has_variable_string && (substr_count($include_file, '"') == 2 or substr_count($include_file, "'") == 2) and substr_count($include_file, '(') == 0) { if (!$compiler->has_variable_string && (substr_count($include_file, '"') == 2 or substr_count($include_file, "'") == 2) and substr_count($include_file, '(') == 0) {
eval("\$tmp = $include_file;"); eval("\$tmp = $include_file;");
if ($this->compiler->template->template_resource != $tmp) { if ($this->compiler->template->template_resource != $tmp) {
$tpl = $compiler->smarty->createTemplate ($tmp, $compiler->template->cache_id, $compiler->template->compile_id, $compiler->template); $tpl = $compiler->smarty->createTemplate ($tmp, $compiler->template->cache_id, $compiler->template->compile_id, $compiler->template);
if ($tpl->usesCompiler() && $tpl->isExisting()) { if ($tpl->usesCompiler() && $tpl->isExisting()) {
do { do {
$must_compile = false; $must_compile = false;
$prop = array(); $prop = array();
$compiled_tpl = $tpl->getCompiledTemplate(); $compiled_tpl = $tpl->getCompiledTemplate();
preg_match('/(\<\?php \$_smarty_tpl-\>decodeProperties\(\')(.*)(\'.*\?\>)/', $compiled_tpl, $matches); preg_match('/(\<\?php \$_smarty_tpl-\>decodeProperties\(\')(.*)(\'.*\?\>)/', $compiled_tpl, $matches);
$compiled_tpl = preg_replace(array('/(\<\?php \$_smarty_tpl-\>decodeProperties\(\')(.*)(\'.*\?\>.*\n)/', '/(\<\?php if\(\!defined\(\'SMARTY_DIR\'\)\))(.*)(\?\>.*\n)/'), '', $compiled_tpl); $compiled_tpl = preg_replace(array('/(\<\?php \$_smarty_tpl-\>decodeProperties\(\')(.*)(\'.*\?\>.*\n)/', '/(\<\?php if\(\!defined\(\'SMARTY_DIR\'\)\))(.*)(\?\>.*\n)/'), '', $compiled_tpl);
// var_dump($matches, $compiled_tpl); // var_dump($matches, $compiled_tpl);
if (isset($matches[2])) { if (isset($matches[2])) {
$prop = unserialize($matches[2]); $prop = unserialize($matches[2]);
foreach ($prop['file_dependency'] as $_file_to_check) { foreach ($prop['file_dependency'] as $_file_to_check) {
If (is_file($_file_to_check[0])) { If (is_file($_file_to_check[0])) {
$mtime = filemtime($_file_to_check[0]); $mtime = filemtime($_file_to_check[0]);
} else { } else {
$tpl->parseResourceName($_file_to_check[0], $resource_type, $resource_name, $resource_handler); $tpl->parseResourceName($_file_to_check[0], $resource_type, $resource_name, $resource_handler);
$mtime = $resource_handler->getTemplateTimestampTypeName($resource_type, $resource_name); $mtime = $resource_handler->getTemplateTimestampTypeName($resource_type, $resource_name);
} }
If ($mtime != $_file_to_check[1]) { If ($mtime != $_file_to_check[1]) {
$must_compile = true; $must_compile = true;
break; break;
} }
} }
if ($must_compile) { if ($must_compile) {
// recompile // recompile
$tpl->compileTemplateSource(); $tpl->compileTemplateSource();
} }
} }
} while ($must_compile); } while ($must_compile);
if (isset($prop['file_dependency'])) { if (isset($prop['file_dependency'])) {
$compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $prop['file_dependency']); $compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $prop['file_dependency']);
} }
$has_compiled_template = true; $has_compiled_template = true;
} }
} }
} }
} }
if (isset($_attr['assign'])) { if (isset($_attr['assign'])) {
// output will be stored in a smarty variable instead of beind displayed // output will be stored in a smarty variable instead of beind displayed
$_assign = $_attr['assign']; $_assign = $_attr['assign'];
} }
$_parent_scope = SMARTY_LOCAL_SCOPE; $_parent_scope = SMARTY_LOCAL_SCOPE;
if (isset($_attr['scope'])) { if (isset($_attr['scope'])) {
if ($_attr['scope'] == '\'parent\'') { if ($_attr['scope'] == '\'parent\'') {
$_parent_scope = SMARTY_PARENT_SCOPE; $_parent_scope = SMARTY_PARENT_SCOPE;
} elseif ($_attr['scope'] == '\'root\'') { } elseif ($_attr['scope'] == '\'root\'') {
$_parent_scope = SMARTY_ROOT_SCOPE; $_parent_scope = SMARTY_ROOT_SCOPE;
} elseif ($_attr['scope'] == '\'global\'') { } elseif ($_attr['scope'] == '\'global\'') {
$_parent_scope = SMARTY_GLOBAL_SCOPE; $_parent_scope = SMARTY_GLOBAL_SCOPE;
} }
} }
// default for included templates // default for included templates
if ($compiler->template->caching) { if ($compiler->template->caching) {
$_caching = SMARTY_CACHING_LIFETIME_CURRENT; $_caching = SMARTY_CACHING_LIFETIME_CURRENT;
} else { } else {
$_caching = SMARTY_CACHING_OFF; $_caching = SMARTY_CACHING_OFF;
} }
/* /*
* if the {include} tag provides individual parameter for caching * if the {include} tag provides individual parameter for caching
* it will not be included into the common cache file and treated like * it will not be included into the common cache file and treated like
* a nocache section * a nocache section
*/ */
if (isset($_attr['cache_lifetime'])) { if (isset($_attr['cache_lifetime'])) {
$_cache_lifetime = $_attr['cache_lifetime']; $_cache_lifetime = $_attr['cache_lifetime'];
$this->compiler->tag_nocache = true; $this->compiler->tag_nocache = true;
} }
if (isset($_attr['nocache'])) { if (isset($_attr['nocache'])) {
if ($_attr['nocache'] == 'true') { if ($_attr['nocache'] == 'true') {
$this->compiler->tag_nocache = true; $this->compiler->tag_nocache = true;
} }
} }
if (isset($_attr['caching'])) { if (isset($_attr['caching'])) {
if ($_attr['caching'] == 'true') { if ($_attr['caching'] == 'true') {
$_caching = SMARTY_CACHING_LIFETIME_CURRENT; $_caching = SMARTY_CACHING_LIFETIME_CURRENT;
} else { } else {
$_caching = SMARTY_CACHING_OFF; $_caching = SMARTY_CACHING_OFF;
} }
} }
// create template object // create template object
$_output = "<?php \$_template = new Smarty_Template ($include_file, \$_smarty_tpl->smarty, \$_smarty_tpl, \$_smarty_tpl->cache_id, \$_smarty_tpl->compile_id);"; $_output = "<?php \$_template = new Smarty_Template ($include_file, \$_smarty_tpl->smarty, \$_smarty_tpl, \$_smarty_tpl->cache_id, \$_smarty_tpl->compile_id);";
// delete {include} standard attributes // delete {include} standard attributes
unset($_attr['file'], $_attr['assign'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope']); unset($_attr['file'], $_attr['assign'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope']);
// remaining attributes must be assigned as smarty variable // remaining attributes must be assigned as smarty variable
if (!empty($_attr)) { if (!empty($_attr)) {
if ($_parent_scope == SMARTY_LOCAL_SCOPE) { if ($_parent_scope == SMARTY_LOCAL_SCOPE) {
// create variables // create variables
foreach ($_attr as $_key => $_value) { foreach ($_attr as $_key => $_value) {
$_output .= "\$_template->assign('$_key',$_value);"; $_output .= "\$_template->assign('$_key',$_value);";
} }
} else { } else {
$this->compiler->trigger_template_error('variable passing not allowed in parent/global scope'); $this->compiler->trigger_template_error('variable passing not allowed in parent/global scope');
} }
} }
// add caching parameter if required // add caching parameter if required
if (isset($_cache_lifetime)) { if (isset($_cache_lifetime)) {
$_output .= "\$_template->cache_lifetime = $_cache_lifetime;"; $_output .= "\$_template->cache_lifetime = $_cache_lifetime;";
$_caching = SMARTY_CACHING_LIFETIME_CURRENT; $_caching = SMARTY_CACHING_LIFETIME_CURRENT;
} }
$_output .= "\$_template->caching = $_caching;"; $_output .= "\$_template->caching = $_caching;";
// was there an assign attribute // was there an assign attribute
if (isset($_assign)) { if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch()); ?>"; $_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch()); ?>";
} else { } else {
if ($has_compiled_template) { if ($has_compiled_template) {
$_output .= " \$_tpl_stack[] = \$_smarty_tpl; \$_smarty_tpl = \$_template;?>\n"; $_output .= " \$_tpl_stack[] = \$_smarty_tpl; \$_smarty_tpl = \$_template;?>\n";
$_output .= $compiled_tpl . "<?php /* End of included template \"" . $tpl->getTemplateFilepath() . "\" */ ?>"; $_output .= $compiled_tpl . "<?php /* End of included template \"" . $tpl->getTemplateFilepath() . "\" */ ?>";
$_output .= "<?php \$_smarty_tpl = array_pop(\$_tpl_stack);?>"; $_output .= "<?php \$_smarty_tpl = array_pop(\$_tpl_stack);?>";
} else { } else {
$_output .= " echo \$_template->fetch(); ?>"; $_output .= " echo \$_template->fetch(); ?>";
} }
} }
if ($_parent_scope != SMARTY_LOCAL_SCOPE) { if ($_parent_scope != SMARTY_LOCAL_SCOPE) {
$_output .= "<?php \$_template->updateParentVariables($_parent_scope); ?>"; $_output .= "<?php \$_template->updateParentVariables($_parent_scope); ?>";
} }
$_output .= "<?php unset(\$_template); ?>"; $_output .= "<?php unset(\$_template); ?>";
return $_output; return $_output;
} }
} }
?> ?>

View File

@@ -1,170 +1,170 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Section * Smarty Internal Plugin Compile Section
* *
* Compiles the {section} {sectionelse} {/section} tags * Compiles the {section} {sectionelse} {/section} tags
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Section Class * Smarty Internal Plugin Compile Section Class
*/ */
class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {section} tag * Compiles code for the {section} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
$this->required_attributes = array('name', 'loop'); $this->required_attributes = array('name', 'loop');
$this->optional_attributes = array('start', 'step', 'max', 'show'); $this->optional_attributes = array('start', 'step', 'max', 'show');
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
$this->_open_tag('section', array('section',$this->compiler->nocache)); $this->_open_tag('section', array('section',$this->compiler->nocache));
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
$this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache; $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
$output = "<?php "; $output = "<?php ";
$section_name = $_attr['name']; $section_name = $_attr['name'];
$output .= "unset(\$_smarty_tpl->tpl_vars['smarty']->value['section'][$section_name]);\n"; $output .= "unset(\$_smarty_tpl->tpl_vars['smarty']->value['section'][$section_name]);\n";
$section_props = "\$_smarty_tpl->tpl_vars['smarty']->value['section'][$section_name]"; $section_props = "\$_smarty_tpl->tpl_vars['smarty']->value['section'][$section_name]";
foreach ($_attr as $attr_name => $attr_value) { foreach ($_attr as $attr_name => $attr_value) {
switch ($attr_name) { switch ($attr_name) {
case 'loop': case 'loop':
$output .= "{$section_props}['loop'] = is_array(\$_loop=$attr_value) ? count(\$_loop) : max(0, (int)\$_loop); unset(\$_loop);\n"; $output .= "{$section_props}['loop'] = is_array(\$_loop=$attr_value) ? count(\$_loop) : max(0, (int)\$_loop); unset(\$_loop);\n";
break; break;
case 'show': case 'show':
if (is_bool($attr_value)) if (is_bool($attr_value))
$show_attr_value = $attr_value ? 'true' : 'false'; $show_attr_value = $attr_value ? 'true' : 'false';
else else
$show_attr_value = "(bool)$attr_value"; $show_attr_value = "(bool)$attr_value";
$output .= "{$section_props}['show'] = $show_attr_value;\n"; $output .= "{$section_props}['show'] = $show_attr_value;\n";
break; break;
case 'name': case 'name':
$output .= "{$section_props}['$attr_name'] = $attr_value;\n"; $output .= "{$section_props}['$attr_name'] = $attr_value;\n";
break; break;
case 'max': case 'max':
case 'start': case 'start':
$output .= "{$section_props}['$attr_name'] = (int)$attr_value;\n"; $output .= "{$section_props}['$attr_name'] = (int)$attr_value;\n";
break; break;
case 'step': case 'step':
$output .= "{$section_props}['$attr_name'] = ((int)$attr_value) == 0 ? 1 : (int)$attr_value;\n"; $output .= "{$section_props}['$attr_name'] = ((int)$attr_value) == 0 ? 1 : (int)$attr_value;\n";
break; break;
} }
} }
if (!isset($_attr['show'])) if (!isset($_attr['show']))
$output .= "{$section_props}['show'] = true;\n"; $output .= "{$section_props}['show'] = true;\n";
if (!isset($_attr['loop'])) if (!isset($_attr['loop']))
$output .= "{$section_props}['loop'] = 1;\n"; $output .= "{$section_props}['loop'] = 1;\n";
if (!isset($_attr['max'])) if (!isset($_attr['max']))
$output .= "{$section_props}['max'] = {$section_props}['loop'];\n"; $output .= "{$section_props}['max'] = {$section_props}['loop'];\n";
else else
$output .= "if ({$section_props}['max'] < 0)\n" . " {$section_props}['max'] = {$section_props}['loop'];\n"; $output .= "if ({$section_props}['max'] < 0)\n" . " {$section_props}['max'] = {$section_props}['loop'];\n";
if (!isset($_attr['step'])) if (!isset($_attr['step']))
$output .= "{$section_props}['step'] = 1;\n"; $output .= "{$section_props}['step'] = 1;\n";
if (!isset($_attr['start'])) if (!isset($_attr['start']))
$output .= "{$section_props}['start'] = {$section_props}['step'] > 0 ? 0 : {$section_props}['loop']-1;\n"; $output .= "{$section_props}['start'] = {$section_props}['step'] > 0 ? 0 : {$section_props}['loop']-1;\n";
else { else {
$output .= "if ({$section_props}['start'] < 0)\n" . " {$section_props}['start'] = max({$section_props}['step'] > 0 ? 0 : -1, {$section_props}['loop'] + {$section_props}['start']);\n" . "else\n" . " {$section_props}['start'] = min({$section_props}['start'], {$section_props}['step'] > 0 ? {$section_props}['loop'] : {$section_props}['loop']-1);\n"; $output .= "if ({$section_props}['start'] < 0)\n" . " {$section_props}['start'] = max({$section_props}['step'] > 0 ? 0 : -1, {$section_props}['loop'] + {$section_props}['start']);\n" . "else\n" . " {$section_props}['start'] = min({$section_props}['start'], {$section_props}['step'] > 0 ? {$section_props}['loop'] : {$section_props}['loop']-1);\n";
} }
$output .= "if ({$section_props}['show']) {\n"; $output .= "if ({$section_props}['show']) {\n";
if (!isset($_attr['start']) && !isset($_attr['step']) && !isset($_attr['max'])) { if (!isset($_attr['start']) && !isset($_attr['step']) && !isset($_attr['max'])) {
$output .= " {$section_props}['total'] = {$section_props}['loop'];\n"; $output .= " {$section_props}['total'] = {$section_props}['loop'];\n";
} else { } else {
$output .= " {$section_props}['total'] = min(ceil(({$section_props}['step'] > 0 ? {$section_props}['loop'] - {$section_props}['start'] : {$section_props}['start']+1)/abs({$section_props}['step'])), {$section_props}['max']);\n"; $output .= " {$section_props}['total'] = min(ceil(({$section_props}['step'] > 0 ? {$section_props}['loop'] - {$section_props}['start'] : {$section_props}['start']+1)/abs({$section_props}['step'])), {$section_props}['max']);\n";
} }
$output .= " if ({$section_props}['total'] == 0)\n" . " {$section_props}['show'] = false;\n" . "} else\n" . " {$section_props}['total'] = 0;\n"; $output .= " if ({$section_props}['total'] == 0)\n" . " {$section_props}['show'] = false;\n" . "} else\n" . " {$section_props}['total'] = 0;\n";
$output .= "if ({$section_props}['show']):\n"; $output .= "if ({$section_props}['show']):\n";
$output .= " $output .= "
for ({$section_props}['index'] = {$section_props}['start'], {$section_props}['iteration'] = 1; for ({$section_props}['index'] = {$section_props}['start'], {$section_props}['iteration'] = 1;
{$section_props}['iteration'] <= {$section_props}['total']; {$section_props}['iteration'] <= {$section_props}['total'];
{$section_props}['index'] += {$section_props}['step'], {$section_props}['iteration']++):\n"; {$section_props}['index'] += {$section_props}['step'], {$section_props}['iteration']++):\n";
$output .= "{$section_props}['rownum'] = {$section_props}['iteration'];\n"; $output .= "{$section_props}['rownum'] = {$section_props}['iteration'];\n";
$output .= "{$section_props}['index_prev'] = {$section_props}['index'] - {$section_props}['step'];\n"; $output .= "{$section_props}['index_prev'] = {$section_props}['index'] - {$section_props}['step'];\n";
$output .= "{$section_props}['index_next'] = {$section_props}['index'] + {$section_props}['step'];\n"; $output .= "{$section_props}['index_next'] = {$section_props}['index'] + {$section_props}['step'];\n";
$output .= "{$section_props}['first'] = ({$section_props}['iteration'] == 1);\n"; $output .= "{$section_props}['first'] = ({$section_props}['iteration'] == 1);\n";
$output .= "{$section_props}['last'] = ({$section_props}['iteration'] == {$section_props}['total']);\n"; $output .= "{$section_props}['last'] = ({$section_props}['iteration'] == {$section_props}['total']);\n";
$output .= "?>"; $output .= "?>";
return $output; return $output;
} }
} }
/** /**
* Smarty Internal Plugin Compile Sectionelse Class * Smarty Internal Plugin Compile Sectionelse Class
*/ */
class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {sectionelse} tag * Compiles code for the {sectionelse} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
list($_open_tag, $this->compiler->nocache) = $this->_close_tag(array('section')); list($_open_tag, $this->compiler->nocache) = $this->_close_tag(array('section'));
$this->_open_tag('sectionelse',array('sectionelse', $this->compiler->nocache)); $this->_open_tag('sectionelse',array('sectionelse', $this->compiler->nocache));
return "<?php endfor; else: ?>"; return "<?php endfor; else: ?>";
} }
} }
/** /**
* Smarty Internal Plugin Compile Sectionclose Class * Smarty Internal Plugin Compile Sectionclose Class
*/ */
class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {/section} tag * Compiles code for the {/section} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
// must endblock be nocache? // must endblock be nocache?
if ($this->compiler->nocache) { if ($this->compiler->nocache) {
$this->compiler->tag_nocache = true; $this->compiler->tag_nocache = true;
} }
list($_open_tag, $this->compiler->nocache) = $this->_close_tag(array('section', 'sectionelse')); list($_open_tag, $this->compiler->nocache) = $this->_close_tag(array('section', 'sectionelse'));
if ($_open_tag == 'sectionelse') if ($_open_tag == 'sectionelse')
return "<?php endif; ?>"; return "<?php endif; ?>";
else else
return "<?php endfor; endif; ?>"; return "<?php endfor; endif; ?>";
} }
} }
?> ?>

View File

@@ -1,106 +1,106 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Special Smarty Variable * Smarty Internal Plugin Compile Special Smarty Variable
* *
* Compiles the special $smarty variables * Compiles the special $smarty variables
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile special Smarty Variable Class * Smarty Internal Plugin Compile special Smarty Variable Class
*/ */
class Smarty_Internal_Compile_Special_Smarty_Variable extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Special_Smarty_Variable extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the speical $smarty variables * Compiles code for the speical $smarty variables
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$_index = explode(',', str_replace(array(']['), array(','), substr($args,1,strlen($args)-2))); $_index = explode(',', str_replace(array(']['), array(','), substr($args,1,strlen($args)-2)));
$compiled_ref = ' '; $compiled_ref = ' ';
switch (trim($_index[0], "'")) { switch (trim($_index[0], "'")) {
case 'foreach': case 'foreach':
return "\$_smarty_tpl->getVariable('smarty')->value$args"; return "\$_smarty_tpl->getVariable('smarty')->value$args";
case 'section': case 'section':
return "\$_smarty_tpl->getVariable('smarty')->value$args"; return "\$_smarty_tpl->getVariable('smarty')->value$args";
case 'capture': case 'capture':
return "\$_smarty_tpl->smarty->_smarty_vars$args"; return "\$_smarty_tpl->smarty->_smarty_vars$args";
case 'now': case 'now':
return 'time()'; return 'time()';
case 'get': case 'get':
$compiled_ref = "\$_GET"; $compiled_ref = "\$_GET";
break; break;
case 'post': case 'post':
$compiled_ref = "\$_POST"; $compiled_ref = "\$_POST";
break; break;
case 'cookies': case 'cookies':
$compiled_ref = "\$_COOKIE"; $compiled_ref = "\$_COOKIE";
break; break;
case 'env': case 'env':
$compiled_ref = "\$_ENV"; $compiled_ref = "\$_ENV";
break; break;
case 'server': case 'server':
$compiled_ref = "\$_SERVER"; $compiled_ref = "\$_SERVER";
break; break;
case 'session': case 'session':
$compiled_ref = "\$_SESSION"; $compiled_ref = "\$_SESSION";
break; break;
case 'request': case 'request':
$compiled_ref = "\$_REQUEST"; $compiled_ref = "\$_REQUEST";
break; break;
case 'template': case 'template':
$_template_name = basename($compiler->template->getTemplateFilepath()); $_template_name = basename($compiler->template->getTemplateFilepath());
return "'$_template_name'"; return "'$_template_name'";
case 'current_dir': case 'current_dir':
$_template_dir_name = dirname($compiler->template->getTemplateFilepath()); $_template_dir_name = dirname($compiler->template->getTemplateFilepath());
return "'$_template_dir_name'"; return "'$_template_dir_name'";
case 'version': case 'version':
$_version = Smarty::$_version; $_version = Smarty::$_version;
return "'$_version'"; return "'$_version'";
case 'const': case 'const':
if ($compiler->smarty->security && !$compiler->smarty->security_policy->allow_constants) { if ($compiler->smarty->security && !$compiler->smarty->security_policy->allow_constants) {
$compiler->trigger_template_error("(secure mode) constants not permitted"); $compiler->trigger_template_error("(secure mode) constants not permitted");
break; break;
} }
return '@' . trim($_index[1], "'"); return '@' . trim($_index[1], "'");
case 'config': case 'config':
return "\$_smarty_tpl->getConfigVariable($_index[1])"; return "\$_smarty_tpl->getConfigVariable($_index[1])";
case 'ldelim': case 'ldelim':
$_ldelim = $compiler->smarty->left_delimiter; $_ldelim = $compiler->smarty->left_delimiter;
return "'$_ldelim'"; return "'$_ldelim'";
case 'rdelim': case 'rdelim':
$_rdelim = $compiler->smarty->right_delimiter; $_rdelim = $compiler->smarty->right_delimiter;
return "'$_rdelim'"; return "'$_rdelim'";
default: default:
$compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is an unknown reference'); $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is an unknown reference');
break; break;
} }
if (isset($_index[1])) { if (isset($_index[1])) {
array_shift($_index); array_shift($_index);
foreach ($_index as $_ind) { foreach ($_index as $_ind) {
$compiled_ref = $compiled_ref . "[$_ind]"; $compiled_ref = $compiled_ref . "[$_ind]";
} }
} }
return $compiled_ref; return $compiled_ref;
} }
} }
?> ?>

View File

@@ -1,59 +1,59 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Strip * Smarty Internal Plugin Compile Strip
* *
* Compiles the {strip} {/strip} tags * Compiles the {strip} {/strip} tags
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Strip Class * Smarty Internal Plugin Compile Strip Class
*/ */
class Smarty_Internal_Compile_Strip extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Strip extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {strip} tag * Compiles code for the {strip} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
$this->_open_tag('strip'); $this->_open_tag('strip');
$_output = "<?php ob_start(); ?>"; $_output = "<?php ob_start(); ?>";
return $_output; return $_output;
} }
} }
/** /**
* Smarty Internal Plugin Compile Stripclose Class * Smarty Internal Plugin Compile Stripclose Class
*/ */
class Smarty_Internal_Compile_Stripclose extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Stripclose extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {/strip} tag * Compiles code for the {/strip} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
$saved_attr = $this->_close_tag(array('strip')); $saved_attr = $this->_close_tag(array('strip'));
$_output = "<?php echo preg_replace('![\t ]*[\r\n]+[\t ]*!', '', ob_get_clean()); ?>\n"; $_output = "<?php echo preg_replace('![\t ]*[\r\n]+[\t ]*!', '', ob_get_clean()); ?>\n";
return $_output; return $_output;
} }
} }
?> ?>

View File

@@ -1,66 +1,66 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile While * Smarty Internal Plugin Compile While
* *
* Compiles the {while} tag * Compiles the {while} tag
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile While Class * Smarty Internal Plugin Compile While Class
*/ */
class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {while} tag * Compiles code for the {while} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
$this->required_attributes = array('if condition'); $this->required_attributes = array('if condition');
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
$this->_open_tag('while', $this->compiler->nocache); $this->_open_tag('while', $this->compiler->nocache);
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
$this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache; $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
if (is_array($args['if condition'])) { if (is_array($args['if condition'])) {
$_output = " <?php if (!isset(\$_smarty_tpl->tpl_vars[".$args['if condition']['var']."])) \$_smarty_tpl->tpl_vars[".$args['if condition']['var']."] = new Smarty_Variable;\n"; $_output = " <?php if (!isset(\$_smarty_tpl->tpl_vars[".$args['if condition']['var']."])) \$_smarty_tpl->tpl_vars[".$args['if condition']['var']."] = new Smarty_Variable;\n";
$_output .= " while (\$_smarty_tpl->tpl_vars[".$args['if condition']['var']."]->value = ".$args['if condition']['value'].") {\n ?>"; $_output .= " while (\$_smarty_tpl->tpl_vars[".$args['if condition']['var']."]->value = ".$args['if condition']['value'].") {\n ?>";
return $_output; return $_output;
} else { } else {
return '<?php while (' . $args['if condition'] . ') { ?>'; return '<?php while (' . $args['if condition'] . ') { ?>';
} }
} }
} }
/** /**
* Smarty Internal Plugin Compile Whileclose Class * Smarty Internal Plugin Compile Whileclose Class
*/ */
class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {/while} tag * Compiles code for the {/while} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
// must endblock be nocache? // must endblock be nocache?
if ($this->compiler->nocache) { if ($this->compiler->nocache) {
$this->compiler->tag_nocache = true; $this->compiler->tag_nocache = true;
} }
$this->compiler->nocache = $this->_close_tag(array('while')); $this->compiler->nocache = $this->_close_tag(array('while'));
return "<?php }?>"; return "<?php }?>";
} }
} }
?> ?>

View File

@@ -1,84 +1,84 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage Security * @subpackage Security
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* This class does contain the security settings * This class does contain the security settings
*/ */
class Smarty_Security { class Smarty_Security {
/** /**
* This determines how Smarty handles "<?php ... ?>" tags in templates. * This determines how Smarty handles "<?php ... ?>" tags in templates.
* possible values: * possible values:
* <ul> * <ul>
* <li>SMARTY_PHP_PASSTHRU -> echo PHP tags as they are</li> * <li>SMARTY_PHP_PASSTHRU -> echo PHP tags as they are</li>
* <li>SMARTY_PHP_QUOTE -> escape tags as entities</li> * <li>SMARTY_PHP_QUOTE -> escape tags as entities</li>
* <li>SMARTY_PHP_REMOVE -> remove php tags</li> * <li>SMARTY_PHP_REMOVE -> remove php tags</li>
* <li>SMARTY_PHP_ALLOW -> execute php tags</li> * <li>SMARTY_PHP_ALLOW -> execute php tags</li>
* </ul> * </ul>
* *
* @var integer * @var integer
*/ */
public $php_handling = SMARTY_PHP_PASSTHRU; public $php_handling = SMARTY_PHP_PASSTHRU;
/** /**
* This is the list of template directories that are considered secure. * This is the list of template directories that are considered secure.
* One directory per array element. * One directory per array element.
* $template_dir is in this list implicitly. * $template_dir is in this list implicitly.
* *
* @var array * @var array
*/ */
public $secure_dir = array(); public $secure_dir = array();
/** /**
* This is an array of directories where trusted php scripts reside. * This is an array of directories where trusted php scripts reside.
* {@link $security} is disabled during their inclusion/execution. * {@link $security} is disabled during their inclusion/execution.
* *
* @var array * @var array
*/ */
public $trusted_dir = array(); public $trusted_dir = array();
/** /**
* This is an array of trusted PHP functions. * This is an array of trusted PHP functions.
* *
* If empty all functions are allowed. * If empty all functions are allowed.
* If set to 'none' none is allowed. * If set to 'none' none is allowed.
* @var array * @var array
*/ */
public $php_functions = array('isset', 'empty', public $php_functions = array('isset', 'empty',
'count', 'sizeof','in_array', 'is_array','time','nl2br'); 'count', 'sizeof','in_array', 'is_array','time','nl2br');
/** /**
* This is an array of trusted modifers. * This is an array of trusted modifers.
* *
* If empty all modifiers are allowed. * If empty all modifiers are allowed.
* If set to 'none' none is allowed. * If set to 'none' none is allowed.
* @var array * @var array
*/ */
public $modifiers = array('escape','count'); public $modifiers = array('escape','count');
/** /**
* This is an array of trusted streams. * This is an array of trusted streams.
* *
* If empty all streams are allowed. * If empty all streams are allowed.
* If set to 'none' none is allowed. * If set to 'none' none is allowed.
* @var array * @var array
*/ */
public $streams = array('file'); public $streams = array('file');
/** /**
+ flag if constants can be accessed from template + flag if constants can be accessed from template
*/ */
public $allow_constants = true; public $allow_constants = true;
/** /**
+ flag if {php} tag can be executed + flag if {php} tag can be executed
*/ */
public $allow_php_tag = false; public $allow_php_tag = false;
} }
?> ?>