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!
cutoff_size = 40
[setup]
bold = true
title = Welcome to Smarty!
cutoff_size = 40
[setup]
bold = true

View File

@@ -1,27 +1,27 @@
<?php
require('../libs/Smarty.class.php');
$smarty = new Smarty;
//$smarty->force_compile = true;
$smarty->debugging = true;
$smarty->caching = true;
$smarty->cache_lifetime = 120;
$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill",true);
$smarty->assign("FirstName",array("John","Mary","James","Henry"));
$smarty->assign("LastName",array("Doe","Smith","Johnson","Case"));
$smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),
array("I", "J", "K", "L"), array("M", "N", "O", "P")));
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
$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_selected", "NE");
$smarty->display('index.tpl');
?>
<?php
require('../libs/Smarty.class.php');
$smarty = new Smarty;
//$smarty->force_compile = true;
$smarty->debugging = true;
$smarty->caching = true;
$smarty->cache_lifetime = 120;
$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill",true);
$smarty->assign("FirstName",array("John","Mary","James","Henry"));
$smarty->assign("LastName",array("Doe","Smith","Johnson","Case"));
$smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),
array("I", "J", "K", "L"), array("M", "N", "O", "P")));
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
$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_selected", "NE");
$smarty->display('index.tpl');
?>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,27 +1,27 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifier
*/
/**
* Smarty string_format modifier plugin
*
* Type: modifier<br>
* Name: string_format<br>
* Purpose: format strings via sprintf
*
* @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>
* @param string $string input string
* @param string $format format string
* @return string formatted string
*/
function smarty_modifier_string_format($string, $format)
{
return sprintf($format, $string);
}
?>
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifier
*/
/**
* Smarty string_format modifier plugin
*
* Type: modifier<br>
* Name: string_format<br>
* Purpose: format strings via sprintf
*
* @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>
* @param string $string input string
* @param string $format format string
* @return string formatted string
*/
function smarty_modifier_string_format($string, $format)
{
return sprintf($format, $string);
}
?>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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