Compare commits

...

39 Commits

Author SHA1 Message Date
David Goodwin 94fff02d39 fix MailboxHandler -> adding mailbox with empty quota field 4 years ago
David Goodwin e7ebc6667e update INSTALL.TXT - see also #349 4 years ago
David Goodwin 82f9db0535 composer format 4 years ago
David Goodwin d25632cc6e see: https://github.com/postfixadmin/postfixadmin/issues/347 - really patch MailboxHandler::storemore() ... 4 years ago
David Goodwin f7708520b3 postfixadmin 3.2.4 changelog 4 years ago
David Goodwin 1b517a72ff bump Smarty to v3.1.35 4 years ago
David Goodwin b3e5514709 merge: 338fb8c564 from master - see https://github.com/postfixadmin/postfixadmin/issues/347 and https://github.com/postfixadmin/postfixadmin/issues/342 4 years ago
David Goodwin 62eac78541 cope with password_validation not being in config 4 years ago
David Goodwin b4013d1166 add missing multiplier retrieval from config! - see #65 4 years ago
David Goodwin 52e639f1fc check quota_multiplier is numeric, else set it to 1; see: https://github.com/postfixadmin/postfixadmin/issues/65 - backport patch from master (not a clean cherry-pick) 4 years ago
David Goodwin c65a99ce2d change row to r everywhere; see : https://sourceforge.net/p/postfixadmin/discussion/676076/thread/616c1d25/?limit=25#7da0 - hopefully removing "row" which might be a reserved keyword for some databases etc 5 years ago
David Goodwin 938d71758a drop php 7.3 build (composer moaning); change travis badge to 3.2 branch in README.md 5 years ago
David Goodwin 88a975c640 update CHANGELOG - 3.2.3 release 5 years ago
David Goodwin e7d736aae4 see: https://github.com/postfixadmin/postfixadmin/issues/302 - check if the session key exists; and if not show something that may help 5 years ago
David Goodwin 5731742fd6 update Smarty to v3.1.33 - "This release does cover security issue CVE-2018-16831, other bug fixes (see changelog.txt) and adds a new feature of the {capture} tag (see NEW_FEATURES.txt)." 5 years ago
David Goodwin 7697bee2af remove windows code; remove array_merge (seems to just break parsing) 5 years ago
Lars Liedtke c208d63917 Update postfixadmin-cli
Make this script platform independent to be usable under e.g. FreeBSD, where bash is located in /usr/local/bin/bash and thus the script fails.
5 years ago
David Goodwin c03a42e327 try and avoid hitting : https://github.com/postfixadmin/postfixadmin/issues/51 5 years ago
David Goodwin 5e5e4a1c9b fix var quoting 5 years ago
David Goodwin fb671e6166 fix page browser test for sqlite; see #87 and #161
(not tests/CreatePageBrowserTest.php)
5 years ago
David Goodwin f9fd24aecd use PHP date for comparison - see #254 and https://sourceforge.net/p/postfixadmin/discussion/676076/thread/70ed9843c0/?limit=25#685c and #240 5 years ago
Filippo Tessarotto c08973f54a [Travis] Build also against PHP 7.3 5 years ago
David Goodwin 2181c24db4 remove quotes around table name which is not necessary as table_by_key does this 5 years ago
David Goodwin ae37943ca4
Merge pull request #242 from froonix/mysqli-persistent-ssl-bugfix
[v3.2] Persistent MySQLi connections: Missing SSL at reconnect
5 years ago
Christian Schrötter ce65c48238
Fix missing SSL at persistent MySQLi reconnect 5 years ago
David Goodwin 477ede0175 stop undefined index errors with show_vacation and show_disabled 5 years ago
David Goodwin d9326a1f38 remove show_expired code from 3.2 branch - see #235 5 years ago
David Goodwin 3ce5efacb1 php 5.6 is EOLed; I am sceptical there is any point spending time fixing travis to make it work 5 years ago
David Goodwin 006b622db9 reduce testing to just linting 5 years ago
David Goodwin 54cb34cceb Update CHANGELOG with 3.2 changes (3.2.1 release) 5 years ago
David Goodwin bdbce9ebe5 fix sql for notification resend; see #226 5 years ago
David Goodwin 9d31639eef fix postgresql compatability - see #227 5 years ago
Luca 885bad949d Fix for MySQL 8
The keyword ROW became reserved in MySQL 8.0.2
https://dev.mysql.com/doc/refman/8.0/en/keywords.html#keywords-8-0-detailed-R
5 years ago
David Goodwin 96d64d9317 try and fix #30 - cope with timestamp and numeric field number comparison better for PostgreSQL. 6 years ago
David Goodwin 8196a063a5 add Date header into smtp_from(...) function - see #203 6 years ago
David Goodwin b71aee3504 remove windows code; remove array_merge (seems to just break parsing) 6 years ago
David Goodwin 31c5e6dd2e try and fix #177 (add missing fields to sqlite db) 6 years ago
David Goodwin 57714adc00 make phar loading optional depending on the extension being present or not 6 years ago
David Goodwin ceb261036a possible fix for sqlite schema/upgrade issues; see #177 and and #176 6 years ago

@ -1,8 +1,8 @@
language: php
php:
- 5.6
- 7.0
- 7.1
- 7.2
cache:
directories:
@ -13,5 +13,5 @@ before_script:
- composer install
script:
- composer check-format
- composer lint

@ -50,13 +50,13 @@ function deldir($dir) {
$current_dir = opendir($dir);
while ($entryname = readdir($current_dir)) {
if (is_dir("$dir/$entryname") and ($entryname != "." and $entryname!="..")) {
deldir("${dir}/${entryname}");
deldir("{$dir}/{$entryname}");
} elseif ($entryname != "." and $entryname!="..") {
unlink("${dir}/${entryname}");
unlink("{$dir}/{$entryname}");
}
}
closedir($current_dir);
@rmdir(${dir});
@rmdir($dir);
}
// --- Main Start ---

@ -6,6 +6,34 @@
#
# Further details on the project are available at http://postfixadmin.sf.net
Version 3.2.4 - 2020/04/17
-------------------------------------------------
- Upgrade Smarty (v3.1.35), see https://github.com/smarty-php/smarty/releases/tag/v3.1.35
- Fix issues with quota (cli mailbox creation)
- Improve database compatability (row->r).
Version 3.2.3 - 2019/09/26
-------------------------------------------------
- Upgrade Smarty (v3.1.33, upstream security fix), see https://github.com/postfixadmin/postfixadmin/commit/907bd7ee4632f87aec723e709e198bbf48ab6fbe
- Fix SQLite paging issues, see https://github.com/postfixadmin/postfixadmin/issues/161 and https://github.com/postfixadmin/postfixadmin/issues/87
- Fix postfixadmin-cli, see https://github.com/postfixadmin/postfixadmin/issues/296
Version 3.2.2 - 2019/02/09
-------------------------------------------------
- Fix MySQLi + SSL support ( ae37943ca42b4cc77b53d6e76cc88dd85c45cc17 )
Version 3.2.1 - 2019/01/12
-------------------------------------------------
- Merge fix for notification resend (vacation.pl) - see https://github.com/postfixadmin/postfixadmin/issues/226
- Improve PostgreSQL compatability - see https://github.com/postfixadmin/postfixadmin/issues/228
- Improve MySQL 8 support - see https://github.com/postfixadmin/postfixadmin/pull/232 and https://github.com/postfixadmin/postfixadmin/pull/175
- Improve SQLite support - see https://github.com/postfixadmin/postfixadmin/issues/176 and https://github.com/postfixadmin/postfixadmin/issues/177
- Remove hard dependency on Phar support ( see https://github.com/postfixadmin/postfixadmin/commit/57714adc00661a81d42287f07d7bbcf8caa44336 )
Version 3.2 - 2018/05/02
-------------------------------------------------

@ -7,14 +7,13 @@
REQUIREMENTS
------------
- Postfix 2.0 or higher.
- Apache 1.3.27 / Lighttpd 1.3.15 or higher.
- PHP 5.1.2 or higher.
- Postfix
- Apache / Lighttpd
- PHP (for web server)
- one of the following databases:
- MySQL 3.23 or higher (5.x recommended)
- MariaDB (counts as MySQL ;-)
- PostgreSQL 7.4 (or higher)
- SQLite 3.12 (or higher)
- MariaDB/MySQL
- PostgreSQL
- SQLite
READ THIS FIRST!
@ -43,13 +42,19 @@ DOCUMENTS/ folder.
(if you installed PostfixAdmin as RPM or DEB package, you can obviously skip this step.)
Assuming we are installing Postfixadmin into /srv/postfixadmin, then something like this should work :
Assuming we are installing Postfixadmin into /srv/postfixadmin, then something like this should work. Please check https://github.com/postfixadmin/postfixadmin/releases to get the latest stable release first (the 3.2.4 version/url below is probably stale)
$ mkdir -p /srv/postfixadmin
$ cd /srv/postfixadmin
$ wget -O https://github.com/postfixadmin/postfixadmin/archive/postfixadmin-3.1.tar.gz postfixadmin-3.1.tar.gz
$ tar -zxvf postfixadmin-version.tgz
$ cd /srv/
$ wget -O postfixadmin.tgz https://github.com/postfixadmin/postfixadmin/archive/postfixadmin-3.2.4.tar.gz
$ tar -zxvf postfixadmin.tgz
$ mv postfixadmin-postfixadmin-3.2 postfixadmin
Alternatively :
$ cd /srv
$ git clone https://github.com/postfixadmin/postfixadmin.git
$ cd postfixadmin
$ git checkout postfixadmin-3.2.4
2. Setup Web Server
-------------------

@ -1,4 +1,4 @@
postfixadmin [![Build Status](https://travis-ci.org/postfixadmin/postfixadmin.svg?branch=master)](https://travis-ci.org/postfixadmin/postfixadmin)
postfixadmin [![Build Status](https://travis-ci.org/postfixadmin/postfixadmin.svg?branch=postfixadmin_3.2)](https://travis-ci.org/postfixadmin/postfixadmin)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/postfixadmin/Lobby)
============

@ -286,7 +286,7 @@ sub already_notified {
if ($db_type eq 'Pg') {
$query = qq{SELECT extract( epoch from (NOW()-notified_at))::int FROM vacation_notification WHERE on_vacation=? AND notified=?};
} else { # mysql
$query = qq{SELECT NOW()-notified_at FROM vacation_notification WHERE on_vacation=? AND notified=?};
$query = qq{SELECT UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(notified_at) FROM vacation_notification WHERE on_vacation=? AND notified=?};
}
$stm = $dbh->prepare($query) or panic_prepare($query);
$stm->execute($to,$from) or panic_execute($query,"on_vacation='$to', notified='$from'");

@ -69,7 +69,9 @@ Config::write($CONF);
require_once("$incpath/languages/language.php");
require_once("$incpath/functions.inc.php");
require_once("$incpath/lib/random_compat.phar");
if (extension_loaded('Phar')) {
require_once("$incpath/lib/random_compat.phar");
}
if (defined('POSTFIXADMIN_CLI')) {
$language = 'en'; # TODO: make configurable or autodetect from locale settings

@ -525,7 +525,7 @@ function create_page_browser($idxfield, $querypart) {
}
# init row counter
$initcount = "SET @row=-1";
$initcount = "SET @r=-1";
if (db_pgsql()) {
$initcount = "CREATE TEMPORARY SEQUENCE rowcount MINVALUE 0";
}
@ -537,24 +537,26 @@ function create_page_browser($idxfield, $querypart) {
$page_size_zerobase = $page_size - 1;
$query = "
SELECT * FROM (
SELECT $idxfield AS label, @row := @row + 1 AS 'row' $querypart
) idx WHERE MOD(idx.row, $page_size) IN (0,$page_size_zerobase) OR idx.row = $count_results
SELECT $idxfield AS label, @r := @r + 1 AS 'r' $querypart
) idx WHERE MOD(idx.r, $page_size) IN (0,$page_size_zerobase) OR idx.r = $count_results
";
if (db_pgsql()) {
$query = "
SELECT * FROM (
SELECT $idxfield AS label, nextval('rowcount') AS row $querypart
) idx WHERE MOD(idx.row, $page_size) IN (0,$page_size_zerobase) OR idx.row = $count_results
SELECT $idxfield AS label, nextval('rowcount') AS r $querypart
) idx WHERE MOD(idx.r, $page_size) IN (0,$page_size_zerobase) OR idx.r = $count_results
";
}
if (db_sqlite()) {
$bits = explode('.', $idxfield);
$end = $bits[1];
$query = "
WITH idx AS (SELECT * $querypart)
SELECT $idxfield AS label, (SELECT (COUNT(*) - 1) FROM idx t1 WHERE t1.$idxfield <= t2.$idxfield) AS row
SELECT $end AS label, (SELECT (COUNT(*) - 1) FROM idx t1 WHERE t1.$end <= t2.$end ) AS r
FROM idx t2
WHERE (row % $page_size) IN (0,$page_size_zerobase) OR row = $count_results";
WHERE (r % $page_size) IN (0,$page_size_zerobase) OR r = $count_results";
}
# TODO: $query is MySQL-specific
@ -836,7 +838,8 @@ function encode_header($string, $default_charset = "utf-8") {
function random_int($min, $max) {
return mt_rand($min, $max);
}
/**/ }
/**/
}
/**
* Generate a random password of $length characters.
@ -875,6 +878,10 @@ function validate_password($password) {
$val_conf = Config::read('password_validation');
$result = array();
if (!is_array($val_conf)) {
$val_conf = [];
}
$minlen = (int) Config::read('min_password_length'); # used up to 2.3.x - check it for backward compatibility
if ($minlen > 0) {
$val_conf['/.{' . $minlen . '}/'] = "password_too_short $minlen";
@ -1338,6 +1345,7 @@ function smtp_mail($to, $from, $data, $body = "") {
. "From: " . $from . "\n"
. "Subject: " . encode_header($data) . "\n"
. "MIME-Version: 1.0\n"
. "Date: " . date('r') . "\n"
. "Content-Type: text/plain; charset=utf-8\n"
. "Content-Transfer-Encoding: 8bit\n"
. "\n"
@ -1461,7 +1469,7 @@ function db_connect($ignore_errors = false) {
if (function_exists("mysqli_real_connect")) {
$link = mysqli_init();
$link->ssl_set($CONF['database_ssl_key'], $CONF['database_ssl_cert'], $CONF['database_ssl_ca'], $CONF['database_ssl_ca_path'], $CONF['database_ssl_cipher']);
$connected = mysqli_real_connect($link, $CONF['database_host'], $CONF['database_user'], $CONF['database_password'], $CONF['database_name'], $CONF['database_port']);
$connected = mysqli_real_connect($link, $CONF['database_host'], $CONF['database_user'], $CONF['database_password'], $CONF['database_name'], $CONF['database_port'], null, constant('MYSQLI_CLIENT_SSL'));
$is_connected = $connected;
} else {
$error_text .= "<p />DEBUG INFORMATION:<br />MySQLi 5 functions not available! (php5-mysqli installed?)<br />database_type = 'mysqli' in config.inc.php, are you using a different database? $DEBUG_TEXT";
@ -1525,9 +1533,8 @@ function db_connect($ignore_errors = false) {
/**
* Returns the appropriate boolean value for the database.
* Currently only PostgreSQL and MySQL are supported.
* @param boolean $bool (REQUIRED)
* @return String or int as appropriate.
* @return string|int as appropriate for underlying db platform
*/
function db_get_boolean($bool) {
if (! (is_bool($bool) || $bool == '0' || $bool == '1')) {
@ -1988,6 +1995,11 @@ function db_where_clause($condition, $struct, $additional_raw_where = '', $searc
$querypart = $field . ' IS NOT NULL';
} else {
$querypart = $field . $operator . "'" . escape_string($value) . "'";
// might need other types adding here.
if (db_pgsql() && isset($struct[$field]) && in_array($struct[$field]['type'], array('ts', 'num')) && $value === '') {
$querypart = $field . $operator . " NULL";
}
}
if (!empty($struct[$field]['select'])) {
@ -2131,6 +2143,26 @@ function gen_show_status($show_alias) {
}
}
// Vacation CHECK
if ( isset($CONF['show_vacation']) && $CONF['show_vacation'] == 'YES' ) {
$stat_result = db_query("SELECT * FROM ". $CONF['database_tables']['vacation'] ." WHERE email = '" . $show_alias . "' AND active = '" . db_get_boolean(true) . "'") ;
if ($stat_result['rows'] == 1) {
$stat_string .= "<span style='background-color:" . $CONF['show_vacation_color'] . "'>" . $CONF['show_status_text'] . "</span>&nbsp;";
} else {
$stat_string .= $CONF['show_status_text'] . "&nbsp;";
}
}
// Disabled CHECK
if ( isset($CONF['show_disabled']) && $CONF['show_disabled'] == 'YES' ) {
$stat_result = db_query("SELECT * FROM ". $CONF['database_tables']['mailbox'] ." WHERE username = '" . $show_alias . "' AND active = '" . db_get_boolean(false) . "'");
if ($stat_result['rows'] == 1) {
$stat_string .= "<span style='background-color:" . $CONF['show_disabled_color'] . "'>" . $CONF['show_status_text'] . "</span>&nbsp;";
} else {
$stat_string .= $CONF['show_status_text'] . "&nbsp;";
}
}
// POP/IMAP CHECK
if ($CONF['show_popimap'] == 'YES') {
$stat_delimiter = "";

@ -2,14 +2,14 @@
/**
* Smarty Autoloader
*
* @package Smarty
* @package Smarty
*/
/**
* Smarty Autoloader
*
* @package Smarty
* @author Uwe Tews
* @package Smarty
* @author Uwe Tews
* Usage:
* require_once '...path/Autoloader.php';
* Smarty_Autoloader::register();
@ -20,7 +20,7 @@
*/
class Smarty_Autoloader
{
/**
/**
* Filepath to Smarty root
*
* @var string
@ -54,8 +54,8 @@ class Smarty_Autoloader
if (!defined('SMARTY_SPL_AUTOLOAD')) {
define('SMARTY_SPL_AUTOLOAD', 0);
}
if (SMARTY_SPL_AUTOLOAD &&
set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
if (SMARTY_SPL_AUTOLOAD
&& set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
) {
$registeredAutoLoadFunctions = spl_autoload_functions();
if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) {
@ -90,7 +90,7 @@ class Smarty_Autoloader
*/
public static function autoload($class)
{
if ($class[ 0 ] !== 'S' && strpos($class, 'Smarty') !== 0) {
if ($class[ 0 ] !== 'S' || strpos($class, 'Smarty') !== 0) {
return;
}
$_class = strtolower($class);

@ -27,7 +27,7 @@
* @author Uwe Tews <uwe dot tews at gmail dot com>
* @author Rodney Rehm
* @package Smarty
* @version 3.1.32
* @version 3.1.34-dev
*/
/**
* set SMARTY_DIR to absolute path to Smarty library files.
@ -112,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.32';
const SMARTY_VERSION = '3.1.34-dev-7';
/**
* define variable scopes
*/
@ -166,133 +166,157 @@ class Smarty extends Smarty_Internal_TemplateBase
const PLUGIN_COMPILER = 'compiler';
const PLUGIN_MODIFIER = 'modifier';
const PLUGIN_MODIFIERCOMPILER = 'modifiercompiler';
/**
* assigned global tpl vars
*/
public static $global_tpl_vars = array();
/**
* Flag denoting if Multibyte String functions are available
*/
public static $_MBSTRING = SMARTY_MBSTRING;
/**
* The character set to adhere to (e.g. "UTF-8")
*/
public static $_CHARSET = SMARTY_RESOURCE_CHAR_SET;
/**
* The date format to be used internally
* (accepts date() and strftime())
*/
public static $_DATE_FORMAT = SMARTY_RESOURCE_DATE_FORMAT;
/**
* Flag denoting if PCRE should run in UTF-8 mode
*/
public static $_UTF8_MODIFIER = 'u';
/**
* Flag denoting if operating system is windows
*/
public static $_IS_WINDOWS = false;
/**
* auto literal on delimiters with whitespace
*
* @var boolean
*/
public $auto_literal = true;
/**
* display error on not assigned variables
*
* @var boolean
*/
public $error_unassigned = false;
/**
* look up relative file path in include_path
*
* @var boolean
*/
public $use_include_path = false;
/**
* flag if template_dir is normalized
*
* @var bool
*/
public $_templateDirNormalized = false;
/**
* joined template directory string used in cache keys
*
* @var string
*/
public $_joined_template_dir = null;
/**
* flag if config_dir is normalized
*
* @var bool
*/
public $_configDirNormalized = false;
/**
* joined config directory string used in cache keys
*
* @var string
*/
public $_joined_config_dir = null;
/**
* default template handler
*
* @var callable
*/
public $default_template_handler_func = null;
/**
* default config handler
*
* @var callable
*/
public $default_config_handler_func = null;
/**
* default plugin handler
*
* @var callable
*/
public $default_plugin_handler_func = null;
/**
* flag if template_dir is normalized
*
* @var bool
*/
public $_compileDirNormalized = false;
/**
* flag if plugins_dir is normalized
*
* @var bool
*/
public $_pluginsDirNormalized = false;
/**
* flag if template_dir is normalized
*
* @var bool
*/
public $_cacheDirNormalized = false;
/**
* force template compiling?
*
* @var boolean
*/
public $force_compile = false;
/**
/**
* use sub dirs for compiled/cached files?
*
* @var boolean
*/
public $use_sub_dirs = false;
/**
* allow ambiguous resources (that are made unique by the resource handler)
*
* @var boolean
*/
public $allow_ambiguous_resources = false;
/**
* merge compiled includes
*
* @var boolean
*/
public $merge_compiled_includes = false;
/*
* flag for behaviour when extends: resource and {extends} tag are used simultaneous
* if false disable execution of {extends} in templates called by extends resource.
@ -301,30 +325,35 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var boolean
*/
public $extends_recursion = true;
/**
* force cache file creation
*
* @var boolean
*/
public $force_cache = false;
/**
* template left-delimiter
*
* @var string
*/
public $left_delimiter = "{";
/**
* template right-delimiter
*
* @var string
*/
public $right_delimiter = "}";
/**
* array of strings which shall be treated as literal by compiler
*
* @var array string
*/
public $literals = array();
/**
* class name
* This should be instance of Smarty_Security.
@ -333,24 +362,28 @@ class Smarty extends Smarty_Internal_TemplateBase
* @see Smarty_Security
*/
public $security_class = 'Smarty_Security';
/**
* implementation of security class
*
* @var Smarty_Security
*/
public $security_policy = null;
/**
* controls handling of PHP-blocks
*
* @var integer
*/
public $php_handling = self::PHP_PASSTHRU;
/**
* controls if the php template file resource is allowed
*
* @var bool
*/
public $allow_php_templates = false;
/**
* debug mode
* Setting this to true enables the debug-console.
@ -358,6 +391,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var boolean
*/
public $debugging = false;
/**
* This determines if debugging is enable-able from the browser.
* <ul>
@ -368,6 +402,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var string
*/
public $debugging_ctrl = 'NONE';
/**
* Name of debugging URL-param.
* Only used when $debugging_ctrl is set to 'URL'.
@ -376,54 +411,63 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var string
*/
public $smarty_debug_id = 'SMARTY_DEBUG';
/**
* Path of debug template.
*
* @var string
*/
public $debug_tpl = null;
/**
* When set, smarty uses this value as error_reporting-level.
*
* @var int
*/
public $error_reporting = null;
/**
* Controls whether variables with the same name overwrite each other.
*
* @var boolean
*/
public $config_overwrite = true;
/**
* Controls whether config values of on/true/yes and off/false/no get converted to boolean.
*
* @var boolean
*/
public $config_booleanize = true;
/**
* Controls whether hidden config sections/vars are read from the file.
*
* @var boolean
*/
public $config_read_hidden = false;
/**
* locking concurrent compiles
*
* @var boolean
*/
public $compile_locking = true;
/**
* Controls whether cache resources should use locking mechanism
*
* @var boolean
*/
public $cache_locking = false;
/**
* seconds to wait for acquiring a lock before ignoring the write lock
*
* @var float
*/
public $locking_timeout = 10;
/**
* resource type used if none given
* Must be an valid key of $registered_resources.
@ -431,6 +475,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var string
*/
public $default_resource_type = 'file';
/**
* caching type
* Must be an element of $cache_resource_types.
@ -438,160 +483,189 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var string
*/
public $caching_type = 'file';
/**
* config type
*
* @var string
*/
public $default_config_type = 'file';
/**
* check If-Modified-Since headers
*
* @var boolean
*/
public $cache_modified_check = false;
/**
* registered plugins
*
* @var array
*/
public $registered_plugins = array();
/**
* registered objects
*
* @var array
*/
public $registered_objects = array();
/**
* registered classes
*
* @var array
*/
public $registered_classes = array();
/**
* registered filters
*
* @var array
*/
public $registered_filters = array();
/**
* registered resources
*
* @var array
*/
public $registered_resources = array();
/**
* registered cache resources
*
* @var array
*/
public $registered_cache_resources = array();
/**
* autoload filter
*
* @var array
*/
public $autoload_filters = array();
/**
* default modifier
*
* @var array
*/
public $default_modifiers = array();
/**
* autoescape variable output
*
* @var boolean
*/
public $escape_html = false;
/**
* start time for execution time calculation
*
* @var int
*/
public $start_time = 0;
/**
* required by the compiler for BC
*
* @var string
*/
public $_current_file = null;
/**
* internal flag to enable parser debugging
*
* @var bool
*/
public $_parserdebug = false;
/**
* This object type (Smarty = 1, template = 2, data = 4)
*
* @var int
*/
public $_objType = 1;
/**
* Debug object
*
* @var Smarty_Internal_Debug
*/
public $_debug = null;
/**
* template directory
*
* @var array
*/
protected $template_dir = array('./templates/');
/**
* flags for normalized template directory entries
*
* @var array
*/
protected $_processedTemplateDir = array();
/**
* config directory
*
* @var array
*/
protected $config_dir = array('./configs/');
/**
* flags for normalized template directory entries
*
* @var array
*/
protected $_processedConfigDir = array();
/**
* compile directory
*
* @var string
*/
protected $compile_dir = './templates_c/';
/**
* plugins directory
*
* @var array
*/
protected $plugins_dir = array();
/**
* cache directory
*
* @var string
*/
protected $cache_dir = './cache/';
/**
* removed properties
*
* @var string[]
*/
protected $obsoleteProperties = array('resource_caching', 'template_resource_caching', 'direct_access_security',
'_dir_perms', '_file_perms', 'plugin_search_order',
'inheritance_merge_compiled_includes', 'resource_cache_mode',);
protected $obsoleteProperties = array(
'resource_caching', 'template_resource_caching', 'direct_access_security',
'_dir_perms', '_file_perms', 'plugin_search_order',
'inheritance_merge_compiled_includes', 'resource_cache_mode',
);
/**
* List of private properties which will call getter/setter on a direct access
*
* @var string[]
*/
protected $accessMap = array('template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir',
'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir',
'cache_dir' => 'CacheDir',);
protected $accessMap = array(
'template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir',
'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir',
'cache_dir' => 'CacheDir',
);
/**
* Initialize new Smarty object
@ -618,7 +692,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Enable error handler to mute expected messages
*
* @return boolean
* @return boolean
* @deprecated
*/
public static function muteExpectedErrors()
@ -639,7 +713,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Check if a template resource exists
*
* @param string $resource_name template name
* @param string $resource_name template name
*
* @return bool status
* @throws \SmartyException
@ -654,10 +728,10 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Loads security class and enables security
*
* @param string|Smarty_Security $security_class if a string is used, it must be class-name
* @param string|Smarty_Security $security_class if a string is used, it must be class-name
*
* @return Smarty current Smarty instance for chaining
* @throws SmartyException when an invalid class name is provided
* @throws \SmartyException
*/
public function enableSecurity($security_class = null)
{
@ -679,9 +753,9 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Add template directory(s)
*
* @param string|array $template_dir directory(s) of template sources
* @param string $key of the array element to assign the template dir to
* @param bool $isConfig true for config_dir
* @param string|array $template_dir directory(s) of template sources
* @param string $key of the array element to assign the template dir to
* @param bool $isConfig true for config_dir
*
* @return Smarty current Smarty instance for chaining
*/
@ -747,8 +821,8 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Set template directory
*
* @param string|array $template_dir directory(s) of template sources
* @param bool $isConfig true for config_dir
* @param string|array $template_dir directory(s) of template sources
* @param bool $isConfig true for config_dir
*
* @return \Smarty current Smarty instance for chaining
*/
@ -835,7 +909,7 @@ class Smarty extends Smarty_Internal_TemplateBase
$this->plugins_dir = (array)$this->plugins_dir;
}
foreach ($this->plugins_dir as $k => $v) {
$this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, "/\\") . DIRECTORY_SEPARATOR, true);
$this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, '/\\') . DIRECTORY_SEPARATOR, true);
}
$this->_cache[ 'plugin_files' ] = array();
$this->_pluginsDirNormalized = true;
@ -846,7 +920,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Set plugins directory
*
* @param string|array $plugins_dir directory(s) of plugins
* @param string|array $plugins_dir directory(s) of plugins
*
* @return Smarty current Smarty instance for chaining
*/
@ -901,7 +975,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Set cache directory
*
* @param string $cache_dir directory to store cached templates in
* @param string $cache_dir directory to store cached templates in
*
* @return Smarty current Smarty instance for chaining
*/
@ -915,11 +989,11 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* creates a template object
*
* @param string $template the resource handle of the template file
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
* @param boolean $do_clone flag is Smarty object shall be cloned
* @param string $template the resource handle of the template file
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
* @param boolean $do_clone flag is Smarty object shall be cloned
*
* @return \Smarty_Internal_Template template object
* @throws \SmartyException
@ -946,7 +1020,7 @@ class Smarty extends Smarty_Internal_TemplateBase
Smarty_Internal_Template::$isCacheTplObj[ $_templateId ];
$tpl->inheritance = null;
$tpl->tpl_vars = $tpl->config_vars = array();
} else if (!$do_clone && isset(Smarty_Internal_Template::$tplObjCache[ $_templateId ])) {
} elseif (!$do_clone && isset(Smarty_Internal_Template::$tplObjCache[ $_templateId ])) {
$tpl = clone Smarty_Internal_Template::$tplObjCache[ $_templateId ];
$tpl->inheritance = null;
$tpl->tpl_vars = $tpl->config_vars = array();
@ -981,11 +1055,11 @@ class Smarty extends Smarty_Internal_TemplateBase
* class name format: Smarty_PluginType_PluginName
* plugin filename format: plugintype.pluginname.php
*
* @param string $plugin_name class plugin name to load
* @param bool $check check if already loaded
* @param string $plugin_name class plugin name to load
* @param bool $check check if already loaded
*
* @throws SmartyException
* @return string |boolean filepath of loaded file or false
* @throws \SmartyException
*/
public function loadPlugin($plugin_name, $check = true)
{
@ -1004,12 +1078,13 @@ class Smarty extends Smarty_Internal_TemplateBase
* @return string
* @throws \SmartyException
*/
public function _getTemplateId($template_name,
$cache_id = null,
$compile_id = null,
$caching = null,
Smarty_Internal_Template $template = null)
{
public function _getTemplateId(
$template_name,
$cache_id = null,
$compile_id = null,
$caching = null,
Smarty_Internal_Template $template = null
) {
$template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" :
$template_name;
$cache_id = $cache_id === null ? $this->cache_id : $cache_id;
@ -1033,33 +1108,22 @@ class Smarty extends Smarty_Internal_TemplateBase
* - remove /./ and /../
* - make it absolute if required
*
* @param string $path file path
* @param bool $realpath if true - convert to absolute
* false - convert to relative
* null - keep as it is but remove /./ /../
* @param string $path file path
* @param bool $realpath if true - convert to absolute
* false - convert to relative
* null - keep as it is but
* remove /./ /../
*
* @return string
*/
public function _realpath($path, $realpath = null)
{
static $nds = null;
static $sepDotsep = null;
static $sepDot = null;
static $sepSep =null;
if (!isset($nds)) {
$nds = array('/' => '\\', '\\' => '/');
$sepDotsep = DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR;
$sepDot = DIRECTORY_SEPARATOR . '.';
$sepSep = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
}
// normalize DIRECTORY_SEPARATOR
$path = str_replace(array($nds[DIRECTORY_SEPARATOR], $sepDotsep), DIRECTORY_SEPARATOR, $path);
if (strpos($path,$sepDot) === false && (($realpath === false && $path[0] === '.') || $realpath === null) && $path[0] !== '\\') {
return $path;
}
preg_match('%^(?<root>(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(.*))$%u',
$path,
$parts);
$nds = array('/' => '\\', '\\' => '/');
preg_match(
'%^(?<root>(?:[[:alpha:]]:[\\\\/]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(.*))$%u',
$path,
$parts
);
$path = $parts[ 'path' ];
if ($parts[ 'root' ] === '\\') {
$parts[ 'root' ] = substr(getcwd(), 0, 2) . $parts[ 'root' ];
@ -1068,24 +1132,18 @@ class Smarty extends Smarty_Internal_TemplateBase
$path = getcwd() . DIRECTORY_SEPARATOR . $path;
}
}
// remove noop 'DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR' and 'DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR' patterns
$path = str_replace(array($sepDotsep,$sepSep), DIRECTORY_SEPARATOR, $path);
// resolve '..DIRECTORY_SEPARATOR' pattern, smallest first
if (strpos($path, '..' . DIRECTORY_SEPARATOR) !== false &&
preg_match_all('#[\\\\/]([.][.][\\\\/])+#u', $path, $match)
) {
$counts = array();
foreach ($match[ 0 ] as $m) {
$counts[] = (int)((strlen($m) - 1) / 3);
}
sort($counts);
foreach ($counts as $count) {
$path = preg_replace('#([\\\\/]+[^\\\\/]+){' . $count .
'}[\\\\/]+([.][.][\\\\/]+){' . $count . '}#u',
DIRECTORY_SEPARATOR,
$path);
}
}
// normalize DIRECTORY_SEPARATOR
$path = str_replace($nds[ DIRECTORY_SEPARATOR ], DIRECTORY_SEPARATOR, $path);
$parts[ 'root' ] = str_replace($nds[ DIRECTORY_SEPARATOR ], DIRECTORY_SEPARATOR, $parts[ 'root' ]);
do {
$path = preg_replace(
array('#[\\\\/]{2}#', '#[\\\\/][.][\\\\/]#', '#[\\\\/]([^\\\\/.]+)[\\\\/][.][.][\\\\/]#'),
DIRECTORY_SEPARATOR,
$path,
-1,
$count
);
} while ($count > 0);
return $realpath !== false ? $parts[ 'root' ] . $path : str_ireplace(getcwd(), '.', $parts[ 'root' ] . $path);
}
@ -1279,19 +1337,18 @@ class Smarty extends Smarty_Internal_TemplateBase
* Calls the appropriate getter function.
* Issues an E_USER_NOTICE if no valid getter is found.
*
* @param string $name property name
* @param string $name property name
*
* @return mixed
* @throws \SmartyException
*/
public function __get($name)
{
if (isset($this->accessMap[ $name ])) {
$method = 'get' . $this->accessMap[ $name ];
return $this->{$method}();
} else if (isset($this->_cache[ $name ])) {
} elseif (isset($this->_cache[ $name ])) {
return $this->_cache[ $name ];
} else if (in_array($name, $this->obsoleteProperties)) {
} elseif (in_array($name, $this->obsoleteProperties)) {
return null;
} else {
trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
@ -1307,21 +1364,18 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param string $name property name
* @param mixed $value parameter passed to setter
*
* @throws \SmartyException
*/
public function __set($name, $value)
{
if (isset($this->accessMap[ $name ])) {
$method = 'set' . $this->accessMap[ $name ];
$this->{$method}($value);
} else if (in_array($name, $this->obsoleteProperties)) {
} elseif (in_array($name, $this->obsoleteProperties)) {
return;
} elseif (is_object($value) && method_exists($value, $name)) {
$this->$name = $value;
} else {
if (is_object($value) && method_exists($value, $name)) {
$this->$name = $value;
} else {
trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
}
trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
}
}
@ -1345,7 +1399,6 @@ class Smarty extends Smarty_Internal_TemplateBase
* Normalize template_dir or config_dir
*
* @param bool $isConfig true for config_dir
*
*/
private function _normalizeTemplateConfig($isConfig)
{

@ -28,7 +28,7 @@
/**
* @ignore
*/
require_once(dirname(__FILE__) . '/Smarty.class.php');
require_once dirname(__FILE__) . '/Smarty.class.php';
/**
* Smarty Backward Compatibility Wrapper Class
@ -53,7 +53,6 @@ class SmartyBC extends Smarty
/**
* Initialize new SmartyBC object
*
*/
public function __construct()
{
@ -127,12 +126,16 @@ class SmartyBC extends Smarty
* @param boolean $smarty_args smarty argument format, else traditional
* @param array $block_methods list of methods that are block format
*
* @throws SmartyException
* @throws SmartyException
* @internal param array $block_functs list of methods that are block format
*/
public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true,
$block_methods = array())
{
public function register_object(
$object,
$object_impl,
$allowed = array(),
$smarty_args = true,
$block_methods = array()
) {
settype($allowed, 'array');
settype($smarty_args, 'boolean');
$this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
@ -326,10 +329,10 @@ class SmartyBC extends Smarty
/**
* clear cached content for the given template and cache id
*
* @param string $tpl_file name of template file
* @param string $cache_id name of cache_id
* @param string $compile_id name of compile_id
* @param string $exp_time expiration time
* @param string $tpl_file name of template file
* @param string $cache_id name of cache_id
* @param string $compile_id name of compile_id
* @param string $exp_time expiration time
*
* @return boolean
*/
@ -341,7 +344,7 @@ class SmartyBC extends Smarty
/**
* clear the entire contents of cache (all templates)
*
* @param string $exp_time expire time
* @param string $exp_time expire time
*
* @return boolean
*/
@ -353,9 +356,9 @@ class SmartyBC extends Smarty
/**
* test to see if valid cache exists for this template
*
* @param string $tpl_file name of template file
* @param string $cache_id
* @param string $compile_id
* @param string $tpl_file name of template file
* @param string $cache_id
* @param string $compile_id
*
* @return bool
* @throws \Exception
@ -379,9 +382,9 @@ class SmartyBC extends Smarty
* or all compiled template files if one is not specified.
* This function is for advanced use only, not normally needed.
*
* @param string $tpl_file
* @param string $compile_id
* @param string $exp_time
* @param string $tpl_file
* @param string $compile_id
* @param string $exp_time
*
* @return boolean results of {@link smarty_core_rm_auto()}
*/
@ -393,7 +396,7 @@ class SmartyBC extends Smarty
/**
* Checks whether requested template exists.
*
* @param string $tpl_file
* @param string $tpl_file
*
* @return bool
* @throws \SmartyException
@ -406,7 +409,7 @@ class SmartyBC extends Smarty
/**
* Returns an array containing template variables
*
* @param string $name
* @param string $name
*
* @return array
*/
@ -418,7 +421,7 @@ class SmartyBC extends Smarty
/**
* Returns an array containing config variables
*
* @param string $name
* @param string $name
*
* @return array
*/
@ -442,7 +445,7 @@ class SmartyBC extends Smarty
/**
* return a reference to a registered object
*
* @param string $name
* @param string $name
*
* @return object
*/

@ -1,5 +1,5 @@
<?php
/*
/**
* This file is part of the Smarty package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
@ -7,11 +7,10 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*
/**
* Load and register Smarty Autoloader
*/
if (!class_exists('Smarty_Autoloader')) {
require dirname(__FILE__) . '/Autoloader.php';
include dirname(__FILE__) . '/Autoloader.php';
}
Smarty_Autoloader::register(true);

@ -113,10 +113,10 @@
<div>
{foreach $template_data as $template}
<font color=brown>{$template.name}</font>
<br>&nbsp;&nbsp;<span class="exectime">
<br />&nbsp;&nbsp;<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>
<br />
{/foreach}
</div>
{/if}
@ -127,7 +127,7 @@
{foreach $assigned_vars as $vars}
<tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}">
<td><h3><font color=blue>${$vars@key}</font></h3>
{if isset($vars['nocache'])}<b>Nocache</b></br>{/if}
{if isset($vars['nocache'])}<b>Nocache</b><br />{/if}
{if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var nofilter}{/if}
</td>
<td><h3>Value</h3>{$vars['value']|debug_print_var:10:80 nofilter}</td>

@ -20,7 +20,6 @@
* - indent_char - string (" ")
* - wrap_boundary - boolean (true)
*
*
* @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat}
* (Smarty online manual)
*
@ -39,10 +38,15 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
return;
}
if (Smarty::$_MBSTRING) {
$template->_checkPlugins(array(array('function' => 'smarty_modifier_mb_wordwrap',
'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php')));
$template->_checkPlugins(
array(
array(
'function' => 'smarty_modifier_mb_wordwrap',
'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php'
)
)
);
}
$style = null;
$indent = 0;
$indent_first = 0;
@ -51,47 +55,48 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
$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;
$$_key = (string)$_val;
break;
case 'indent':
case 'indent_first':
case 'wrap':
$$_key = (int) $_val;
$$_key = (int)$_val;
break;
case 'wrap_cut':
$$_key = (bool) $_val;
$$_key = (bool)$_val;
break;
default:
trigger_error("textformat: unknown attribute '{$_key}'");
}
}
if ($style === 'email') {
$wrap = 72;
}
// split into paragraphs
$_paragraphs = preg_split('![\r\n]{2}!', $content);
foreach ($_paragraphs as &$_paragraph) {
if (!$_paragraph) {
continue;
}
// convert mult. spaces & special chars to single space
$_paragraph =
preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER,
'!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER),
array(' ',
''), $_paragraph);
preg_replace(
array(
'!\s+!' . Smarty::$_UTF8_MODIFIER,
'!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER
),
array(
' ',
''
),
$_paragraph
);
// indent first line
if ($indent_first > 0) {
$_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph;
@ -108,7 +113,6 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
}
}
$_output = implode($wrap_char . $wrap_char, $_paragraphs);
if ($assign) {
$template->assign($assign, $_output);
} else {

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsFunction
*/
/**
* Smarty {counter} function plugin
* Type: function
@ -24,50 +23,40 @@
function smarty_function_counter($params, $template)
{
static $counters = array();
$name = (isset($params[ 'name' ])) ? $params[ 'name' ] : 'default';
if (!isset($counters[ $name ])) {
$counters[ $name ] = array('start' => 1, 'skip' => 1, 'direction' => 'up', 'count' => 1);
}
$counter =& $counters[ $name ];
if (isset($params[ 'start' ])) {
$counter[ 'start' ] = $counter[ 'count' ] = (int) $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' ];
$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;
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsFunction
*/
/**
* Smarty {cycle} function plugin
* Type: function
@ -29,34 +28,29 @@
* {cycle name=row values="one,two,three" reset=true}
* {cycle name=row}
*
*
* @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle}
* @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author credit to Mark Priatel <mpriatel@rogers.com>
* @author credit to Gerard <gerard@interfold.com>
* @author credit to Jason Sweat <jsweat_php@yahoo.com>
* @version 1.3
* @author Monte Ohrt <monte at ohrt dot com>
* @author credit to Mark Priatel <mpriatel@rogers.com>
* @author credit to Gerard <gerard@interfold.com>
* @author credit to Jason Sweat <jsweat_php@yahoo.com>
* @version 1.3
*
* @param array $params parameters
* @param Smarty_Internal_Template $template template object
*
* @return string|null
*/
function smarty_function_cycle($params, $template)
{
static $cycle_vars;
$name = (empty($params[ 'name' ])) ? 'default' : $params[ 'name' ];
$print = (isset($params[ 'print' ])) ? (bool) $params[ 'print' ] : true;
$advance = (isset($params[ 'advance' ])) ? (bool) $params[ 'advance' ] : true;
$reset = (isset($params[ 'reset' ])) ? (bool) $params[ 'reset' ] : false;
$print = (isset($params[ 'print' ])) ? (bool)$params[ 'print' ] : true;
$advance = (isset($params[ 'advance' ])) ? (bool)$params[ 'advance' ] : true;
$reset = (isset($params[ 'reset' ])) ? (bool)$params[ 'reset' ] : false;
if (!isset($params[ 'values' ])) {
if (!isset($cycle_vars[ $name ][ 'values' ])) {
trigger_error('cycle: missing \'values\' parameter');
return;
}
} else {
@ -65,41 +59,34 @@ function smarty_function_cycle($params, $template)
}
$cycle_vars[ $name ][ 'values' ] = $params[ 'values' ];
}
if (isset($params[ 'delimiter' ])) {
$cycle_vars[ $name ][ 'delimiter' ] = $params[ 'delimiter' ];
} elseif (!isset($cycle_vars[ $name ][ 'delimiter' ])) {
$cycle_vars[ $name ][ 'delimiter' ] = ',';
}
if (is_array($cycle_vars[ $name ][ 'values' ])) {
$cycle_array = $cycle_vars[ $name ][ 'values' ];
} else {
$cycle_array = explode($cycle_vars[ $name ][ 'delimiter' ], $cycle_vars[ $name ][ 'values' ]);
}
if (!isset($cycle_vars[ $name ][ 'index' ]) || $reset) {
$cycle_vars[ $name ][ 'index' ] = 0;
}
if (isset($params[ 'assign' ])) {
$print = false;
$template->assign($params[ 'assign' ], $cycle_array[ $cycle_vars[ $name ][ 'index' ] ]);
}
if ($print) {
$retval = $cycle_array[ $cycle_vars[ $name ][ 'index' ] ];
} else {
$retval = null;
}
if ($advance) {
if ($cycle_vars[ $name ][ 'index' ] >= count($cycle_array) - 1) {
$cycle_vars[ $name ][ 'index' ] = 0;
} else {
$cycle_vars[ $name ][ 'index' ] ++;
$cycle_vars[ $name ][ 'index' ]++;
}
}
return $retval;
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsFunction
*/
/**
* Smarty {fetch} plugin
* Type: function
@ -26,20 +25,16 @@ function smarty_function_fetch($params, $template)
{
if (empty($params[ 'file' ])) {
trigger_error('[plugin] fetch parameter \'file\' cannot be empty', E_USER_NOTICE);
return;
}
// strip file protocol
if (stripos($params[ 'file' ], 'file://') === 0) {
$params[ 'file' ] = substr($params[ 'file' ], 7);
}
$protocol = strpos($params[ 'file' ], '://');
if ($protocol !== false) {
$protocol = strtolower(substr($params[ 'file' ], 0, $protocol));
}
if (isset($template->smarty->security_policy)) {
if ($protocol) {
// remote resource (or php stream, …)
@ -53,7 +48,6 @@ function smarty_function_fetch($params, $template)
}
}
}
$content = '';
if ($protocol === 'http') {
// http fetch
@ -104,7 +98,6 @@ function smarty_function_fetch($params, $template)
if (!empty($param_value)) {
if (!preg_match('![\w\d-]+: .+!', $param_value)) {
trigger_error("[plugin] invalid header format '{$param_value}'", E_USER_NOTICE);
return;
} else {
$extra_headers[] = $param_value;
@ -118,10 +111,9 @@ function smarty_function_fetch($params, $template)
break;
case 'proxy_port':
if (!preg_match('!\D!', $param_value)) {
$proxy_port = (int) $param_value;
$proxy_port = (int)$param_value;
} else {
trigger_error("[plugin] invalid value for attribute '{$param_key }'", E_USER_NOTICE);
return;
}
break;
@ -137,16 +129,14 @@ function smarty_function_fetch($params, $template)
break;
case 'timeout':
if (!preg_match('!\D!', $param_value)) {
$timeout = (int) $param_value;
$timeout = (int)$param_value;
} else {
trigger_error("[plugin] invalid value for attribute '{$param_key}'", E_USER_NOTICE);
return;
}
break;
default:
trigger_error("[plugin] unrecognized attribute '{$param_key}'", E_USER_NOTICE);
return;
}
}
@ -156,10 +146,8 @@ function smarty_function_fetch($params, $template)
} else {
$fp = fsockopen($server_name, $port, $errno, $errstr, $timeout);
}
if (!$fp) {
trigger_error("[plugin] unable to fetch: $errstr ($errno)", E_USER_NOTICE);
return;
} else {
if ($_is_proxy) {
@ -187,23 +175,19 @@ function smarty_function_fetch($params, $template)
if (!empty($user) && !empty($pass)) {
fputs($fp, 'Authorization: BASIC ' . base64_encode("$user:$pass") . "\r\n");
}
fputs($fp, "\r\n");
while (!feof($fp)) {
$content .= fgets($fp, 4096);
}
fclose($fp);
$csplit = preg_split("!\r\n\r\n!", $content, 2);
$content = $csplit[ 1 ];
if (!empty($params[ 'assign_headers' ])) {
$template->assign($params[ 'assign_headers' ], preg_split("!\r\n!", $csplit[ 0 ]));
}
}
} else {
trigger_error("[plugin fetch] unable to parse URL, check syntax", E_USER_NOTICE);
return;
}
} else {
@ -212,7 +196,6 @@ function smarty_function_fetch($params, $template)
throw new SmartyException("{fetch} cannot read resource '" . $params[ 'file' ] . "'");
}
}
if (!empty($params[ 'assign' ])) {
$template->assign($params[ 'assign' ], $content);
} else {

@ -29,25 +29,29 @@
* - assign (optional) - assign the output as an array to this variable
* - escape (optional) - escape the content (not value), defaults to true
*
*
* @link http://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes}
* @link http://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes}
* (Smarty online manual)
* @author Christopher Kvarme <christopher.kvarme@flashjab.com>
* @author credits to Monte Ohrt <monte at ohrt dot com>
* @version 1.0
* @author Christopher Kvarme <christopher.kvarme@flashjab.com>
* @author credits to Monte Ohrt <monte at ohrt dot com>
* @version 1.0
*
* @param array $params parameters
* @param Smarty_Internal_Template $template template object
*
* @return string
* @uses smarty_function_escape_special_chars()
* @uses smarty_function_escape_special_chars()
* @throws \SmartyException
*/
function smarty_function_html_checkboxes($params, Smarty_Internal_Template $template)
{
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->_checkPlugins(
array(
array(
'function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'
)
)
);
$name = 'checkbox';
$values = null;
$options = null;
@ -57,31 +61,25 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp
$labels = true;
$label_ids = false;
$output = null;
$extra = '';
foreach ($params as $_key => $_val) {
switch ($_key) {
case 'name':
case 'separator':
$$_key = (string) $_val;
$$_key = (string)$_val;
break;
case 'escape':
case 'labels':
case 'label_ids':
$$_key = (bool) $_val;
$$_key = (bool)$_val;
break;
case 'options':
$$_key = (array) $_val;
$$_key = (array)$_val;
break;
case 'values':
case 'output':
$$_key = array_values((array) $_val);
$$_key = array_values((array)$_val);
break;
case 'checked':
case 'selected':
if (is_array($_val)) {
@ -89,57 +87,61 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp
foreach ($_val as $_sel) {
if (is_object($_sel)) {
if (method_exists($_sel, '__toString')) {
$_sel = smarty_function_escape_special_chars((string) $_sel->__toString());
$_sel = smarty_function_escape_special_chars((string)$_sel->__toString());
} else {
trigger_error('html_checkboxes: selected attribute contains an object of class \'' .
get_class($_sel) . '\' without __toString() method', E_USER_NOTICE);
trigger_error(
'html_checkboxes: selected attribute contains an object of class \'' .
get_class($_sel) . '\' without __toString() method',
E_USER_NOTICE
);
continue;
}
} else {
$_sel = smarty_function_escape_special_chars((string) $_sel);
$_sel = smarty_function_escape_special_chars((string)$_sel);
}
$selected[ $_sel ] = true;
}
} elseif (is_object($_val)) {
if (method_exists($_val, '__toString')) {
$selected = smarty_function_escape_special_chars((string) $_val->__toString());
$selected = smarty_function_escape_special_chars((string)$_val->__toString());
} else {
trigger_error('html_checkboxes: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method', E_USER_NOTICE);
trigger_error(
'html_checkboxes: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method',
E_USER_NOTICE
);
}
} else {
$selected = smarty_function_escape_special_chars((string) $_val);
$selected = smarty_function_escape_special_chars((string)$_val);
}
break;
case 'checkboxes':
trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead',
E_USER_WARNING);
$options = (array) $_val;
trigger_error(
'html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead',
E_USER_WARNING
);
$options = (array)$_val;
break;
case 'assign':
break;
case 'strict':
break;
case 'disabled':
case 'readonly':
if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) {
trigger_error("html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute",
E_USER_NOTICE);
trigger_error(
"html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute",
E_USER_NOTICE
);
}
if ($_val === true || $_val === $_key) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
}
break;
}
// omit break; to fall through!
// no break
default:
if (!is_array($_val)) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
@ -149,34 +151,49 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp
break;
}
}
if (!isset($options) && !isset($values)) {
return '';
} /* raise error here? */
$_html_result = array();
if (isset($options)) {
foreach ($options as $_key => $_val) {
$_html_result[] =
smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels,
$label_ids, $escape);
smarty_function_html_checkboxes_output(
$name,
$_key,
$_val,
$selected,
$extra,
$separator,
$labels,
$label_ids,
$escape
);
}
} else {
foreach ($values as $_i => $_key) {
$_val = isset($output[ $_i ]) ? $output[ $_i ] : '';
$_html_result[] =
smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels,
$label_ids, $escape);
smarty_function_html_checkboxes_output(
$name,
$_key,
$_val,
$selected,
$extra,
$separator,
$labels,
$label_ids,
$escape
);
}
}
if (!empty($params[ 'assign' ])) {
$template->assign($params[ 'assign' ], $_html_result);
} else {
return implode("\n", $_html_result);
}
}
/**
* @param $name
* @param $value
@ -190,59 +207,69 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp
*
* @return string
*/
function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels,
$label_ids, $escape = true)
{
function smarty_function_html_checkboxes_output(
$name,
$value,
$output,
$selected,
$extra,
$separator,
$labels,
$label_ids,
$escape = true
) {
$_output = '';
if (is_object($value)) {
if (method_exists($value, '__toString')) {
$value = (string) $value->__toString();
$value = (string)$value->__toString();
} else {
trigger_error('html_options: value is an object of class \'' . get_class($value) .
'\' without __toString() method', E_USER_NOTICE);
trigger_error(
'html_options: value is an object of class \'' . get_class($value) .
'\' without __toString() method',
E_USER_NOTICE
);
return '';
}
} else {
$value = (string) $value;
$value = (string)$value;
}
if (is_object($output)) {
if (method_exists($output, '__toString')) {
$output = (string) $output->__toString();
$output = (string)$output->__toString();
} else {
trigger_error('html_options: output is an object of class \'' . get_class($output) .
'\' without __toString() method', E_USER_NOTICE);
trigger_error(
'html_options: output is an object of class \'' . get_class($output) .
'\' without __toString() method',
E_USER_NOTICE
);
return '';
}
} else {
$output = (string) $output;
$output = (string)$output;
}
if ($labels) {
if ($label_ids) {
$_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_',
$name . '_' . $value));
$_id = smarty_function_escape_special_chars(
preg_replace(
'![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER,
'_',
$name . '_' . $value
)
);
$_output .= '<label for="' . $_id . '">';
} else {
$_output .= '<label>';
}
}
$name = smarty_function_escape_special_chars($name);
$value = smarty_function_escape_special_chars($value);
if ($escape) {
$output = smarty_function_escape_special_chars($output);
}
$_output .= '<input type="checkbox" name="' . $name . '[]" value="' . $value . '"';
if ($labels && $label_ids) {
$_output .= ' id="' . $_id . '"';
}
if (is_array($selected)) {
if (isset($selected[ $value ])) {
$_output .= ' checked="checked"';
@ -250,13 +277,10 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
} elseif ($value === $selected) {
$_output .= ' checked="checked"';
}
$_output .= $extra . ' />' . $output;
if ($labels) {
$_output .= '</label>';
}
$_output .= $separator;
return $_output;
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsFunction
*/
/**
* Smarty {html_image} function plugin
* Type: function
@ -22,7 +21,6 @@
* - basedir - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT
* - path_prefix - prefix for path output (optional, default empty)
*
*
* @link http://www.smarty.net/manual/en/language.function.html.image.php {html_image}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
@ -38,9 +36,14 @@
*/
function smarty_function_html_image($params, Smarty_Internal_Template $template)
{
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->_checkPlugins(
array(
array(
'function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'
)
)
);
$alt = '';
$file = '';
$height = '';
@ -60,53 +63,50 @@ function smarty_function_html_image($params, Smarty_Internal_Template $template)
case 'basedir':
$$_key = $_val;
break;
case 'alt':
if (!is_array($_val)) {
$$_key = smarty_function_escape_special_chars($_val);
} else {
throw new SmartyException ("html_image: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
throw new SmartyException(
"html_image: extra attribute '{$_key}' cannot be an array",
E_USER_NOTICE
);
}
break;
case 'link':
case 'href':
$prefix = '<a href="' . $_val . '">';
$suffix = '</a>';
break;
default:
if (!is_array($_val)) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
} else {
throw new SmartyException ("html_image: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
throw new SmartyException(
"html_image: extra attribute '{$_key}' cannot be an array",
E_USER_NOTICE
);
}
break;
}
}
if (empty($file)) {
trigger_error('html_image: missing \'file\' parameter', E_USER_NOTICE);
return;
}
if ($file[ 0 ] === '/') {
$_image_path = $basedir . $file;
} else {
$_image_path = $file;
}
// strip file protocol
if (stripos($params[ 'file' ], 'file://') === 0) {
$params[ 'file' ] = substr($params[ 'file' ], 7);
}
$protocol = strpos($params[ 'file' ], '://');
if ($protocol !== false) {
$protocol = strtolower(substr($params[ 'file' ], 0, $protocol));
}
if (isset($template->smarty->security_policy)) {
if ($protocol) {
// remote resource (or php stream, …)
@ -120,25 +120,20 @@ function smarty_function_html_image($params, Smarty_Internal_Template $template)
}
}
}
if (!isset($params[ 'width' ]) || !isset($params[ 'height' ])) {
// FIXME: (rodneyrehm) getimagesize() loads the complete file off a remote resource, use custom [jpg,png,gif]header reader!
if (!$_image_data = @getimagesize($_image_path)) {
if (!file_exists($_image_path)) {
trigger_error("html_image: unable to find '{$_image_path}'", E_USER_NOTICE);
return;
} elseif (!is_readable($_image_path)) {
trigger_error("html_image: unable to read '{$_image_path}'", E_USER_NOTICE);
return;
} else {
trigger_error("html_image: '{$_image_path}' is not a valid image file", E_USER_NOTICE);
return;
}
}
if (!isset($params[ 'width' ])) {
$width = $_image_data[ 0 ];
}
@ -146,7 +141,6 @@ function smarty_function_html_image($params, Smarty_Internal_Template $template)
$height = $_image_data[ 1 ];
}
}
if (isset($params[ 'dpi' ])) {
if (strstr($_SERVER[ 'HTTP_USER_AGENT' ], 'Mac')) {
// FIXME: (rodneyrehm) wrong dpi assumption
@ -159,7 +153,6 @@ function smarty_function_html_image($params, Smarty_Internal_Template $template)
$width = round($width * $_resize);
$height = round($height * $_resize);
}
return $prefix . '<img src="' . $path_prefix . $file . '" alt="' . $alt . '" width="' . $width . '" height="' .
$height . '"' . $extra . ' />' . $suffix;
}

@ -21,25 +21,29 @@
* - id (optional) - string default not set
* - class (optional) - string default not set
*
*
* @link http://www.smarty.net/manual/en/language.function.html.options.php {html_image}
* @link http://www.smarty.net/manual/en/language.function.html.options.php {html_image}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author Ralf Strehle (minor optimization) <ralf dot strehle at yahoo dot de>
* @author Monte Ohrt <monte at ohrt dot com>
* @author Ralf Strehle (minor optimization) <ralf dot strehle at yahoo dot de>
*
* @param array $params parameters
*
* @param \Smarty_Internal_Template $template
*
* @return string
* @uses smarty_function_escape_special_chars()
* @uses smarty_function_escape_special_chars()
* @throws \SmartyException
*/
function smarty_function_html_options($params, Smarty_Internal_Template $template)
{
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->_checkPlugins(
array(
array(
'function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'
)
)
);
$name = null;
$values = null;
$options = null;
@ -47,74 +51,73 @@ function smarty_function_html_options($params, Smarty_Internal_Template $templat
$output = null;
$id = null;
$class = null;
$extra = '';
foreach ($params as $_key => $_val) {
switch ($_key) {
case 'name':
case 'class':
case 'id':
$$_key = (string) $_val;
$$_key = (string)$_val;
break;
case 'options':
$options = (array) $_val;
$options = (array)$_val;
break;
case 'values':
case 'output':
$$_key = array_values((array) $_val);
$$_key = array_values((array)$_val);
break;
case 'selected':
if (is_array($_val)) {
$selected = array();
foreach ($_val as $_sel) {
if (is_object($_sel)) {
if (method_exists($_sel, '__toString')) {
$_sel = smarty_function_escape_special_chars((string) $_sel->__toString());
$_sel = smarty_function_escape_special_chars((string)$_sel->__toString());
} else {
trigger_error('html_options: selected attribute contains an object of class \'' .
get_class($_sel) . '\' without __toString() method', E_USER_NOTICE);
trigger_error(
'html_options: selected attribute contains an object of class \'' .
get_class($_sel) . '\' without __toString() method',
E_USER_NOTICE
);
continue;
}
} else {
$_sel = smarty_function_escape_special_chars((string) $_sel);
$_sel = smarty_function_escape_special_chars((string)$_sel);
}
$selected[ $_sel ] = true;
}
} elseif (is_object($_val)) {
if (method_exists($_val, '__toString')) {
$selected = smarty_function_escape_special_chars((string) $_val->__toString());
$selected = smarty_function_escape_special_chars((string)$_val->__toString());
} else {
trigger_error('html_options: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method', E_USER_NOTICE);
trigger_error(
'html_options: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method',
E_USER_NOTICE
);
}
} else {
$selected = smarty_function_escape_special_chars((string) $_val);
$selected = smarty_function_escape_special_chars((string)$_val);
}
break;
case 'strict':
break;
case 'disabled':
case 'readonly':
if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) {
trigger_error("html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute",
E_USER_NOTICE);
trigger_error(
"html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute",
E_USER_NOTICE
);
}
if ($_val === true || $_val === $_key) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
}
break;
}
// omit break; to fall through!
// no break
default:
if (!is_array($_val)) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
@ -124,16 +127,12 @@ function smarty_function_html_options($params, Smarty_Internal_Template $templat
break;
}
}
if (!isset($options) && !isset($values)) {
/* raise error here? */
return '';
}
$_html_result = '';
$_idx = 0;
if (isset($options)) {
foreach ($options as $_key => $_val) {
$_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx);
@ -144,7 +143,6 @@ function smarty_function_html_options($params, Smarty_Internal_Template $templat
$_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx);
}
}
if (!empty($name)) {
$_html_class = !empty($class) ? ' class="' . $class . '"' : '';
$_html_id = !empty($id) ? ' id="' . $id . '"' : '';
@ -152,9 +150,9 @@ function smarty_function_html_options($params, Smarty_Internal_Template $templat
'<select name="' . $name . '"' . $_html_class . $_html_id . $extra . '>' . "\n" . $_html_result .
'</select>' . "\n";
}
return $_html_result;
}
/**
* @param $key
* @param $value
@ -181,28 +179,36 @@ function smarty_function_html_options_optoutput($key, $value, $selected, $id, $c
$_html_id = !empty($id) ? ' id="' . $id . '-' . $idx . '"' : '';
if (is_object($value)) {
if (method_exists($value, '__toString')) {
$value = smarty_function_escape_special_chars((string) $value->__toString());
$value = smarty_function_escape_special_chars((string)$value->__toString());
} else {
trigger_error('html_options: value is an object of class \'' . get_class($value) .
'\' without __toString() method', E_USER_NOTICE);
trigger_error(
'html_options: value is an object of class \'' . get_class($value) .
'\' without __toString() method',
E_USER_NOTICE
);
return '';
}
} else {
$value = smarty_function_escape_special_chars((string) $value);
$value = smarty_function_escape_special_chars((string)$value);
}
$_html_result .= $_html_class . $_html_id . '>' . $value . '</option>' . "\n";
$idx ++;
$idx++;
} else {
$_idx = 0;
$_html_result =
smarty_function_html_options_optgroup($key, $value, $selected, !empty($id) ? ($id . '-' . $idx) : null,
$class, $_idx);
$idx ++;
smarty_function_html_options_optgroup(
$key,
$value,
$selected,
!empty($id) ? ($id . '-' . $idx) : null,
$class,
$_idx
);
$idx++;
}
return $_html_result;
}
/**
* @param $key
* @param $values
@ -220,6 +226,5 @@ function smarty_function_html_options_optgroup($key, $values, $selected, $id, $c
$optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected, $id, $class, $idx);
}
$optgroup_html .= "</optgroup>\n";
return $optgroup_html;
}

@ -29,7 +29,6 @@
* {html_radios values=$ids name='box' separator='<br>' output=$names}
* {html_radios values=$ids checked=$checked separator='<br>' output=$names}
*
*
* @link http://smarty.php.net/manual/en/language.function.html.radios.php {html_radios}
* (Smarty online manual)
* @author Christopher Kvarme <christopher.kvarme@flashjab.com>
@ -45,9 +44,14 @@
*/
function smarty_function_html_radios($params, Smarty_Internal_Template $template)
{
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->_checkPlugins(
array(
array(
'function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'
)
)
);
$name = 'radio';
$values = null;
$options = null;
@ -58,73 +62,69 @@ function smarty_function_html_radios($params, Smarty_Internal_Template $template
$label_ids = false;
$output = null;
$extra = '';
foreach ($params as $_key => $_val) {
switch ($_key) {
case 'name':
case 'separator':
$$_key = (string) $_val;
$$_key = (string)$_val;
break;
case 'checked':
case 'selected':
if (is_array($_val)) {
trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING);
} elseif (is_object($_val)) {
if (method_exists($_val, '__toString')) {
$selected = smarty_function_escape_special_chars((string) $_val->__toString());
$selected = smarty_function_escape_special_chars((string)$_val->__toString());
} else {
trigger_error('html_radios: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method', E_USER_NOTICE);
trigger_error(
'html_radios: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method',
E_USER_NOTICE
);
}
} else {
$selected = (string) $_val;
$selected = (string)$_val;
}
break;
case 'escape':
case 'labels':
case 'label_ids':
$$_key = (bool) $_val;
$$_key = (bool)$_val;
break;
case 'options':
$$_key = (array) $_val;
$$_key = (array)$_val;
break;
case 'values':
case 'output':
$$_key = array_values((array) $_val);
$$_key = array_values((array)$_val);
break;
case 'radios':
trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead',
E_USER_WARNING);
$options = (array) $_val;
trigger_error(
'html_radios: the use of the "radios" attribute is deprecated, use "options" instead',
E_USER_WARNING
);
$options = (array)$_val;
break;
case 'assign':
break;
case 'strict':
break;
case 'disabled':
case 'readonly':
if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) {
trigger_error("html_options: {$_key} attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute",
E_USER_NOTICE);
trigger_error(
"html_options: {$_key} attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute",
E_USER_NOTICE
);
}
if ($_val === true || $_val === $_key) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
}
break;
}
// omit break; to fall through!
// no break
default:
if (!is_array($_val)) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
@ -134,36 +134,50 @@ function smarty_function_html_radios($params, Smarty_Internal_Template $template
break;
}
}
if (!isset($options) && !isset($values)) {
/* raise error here? */
return '';
}
$_html_result = array();
if (isset($options)) {
foreach ($options as $_key => $_val) {
$_html_result[] =
smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels,
$label_ids, $escape);
smarty_function_html_radios_output(
$name,
$_key,
$_val,
$selected,
$extra,
$separator,
$labels,
$label_ids,
$escape
);
}
} else {
foreach ($values as $_i => $_key) {
$_val = isset($output[ $_i ]) ? $output[ $_i ] : '';
$_html_result[] =
smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels,
$label_ids, $escape);
smarty_function_html_radios_output(
$name,
$_key,
$_val,
$selected,
$extra,
$separator,
$labels,
$label_ids,
$escape
);
}
}
if (!empty($params[ 'assign' ])) {
$template->assign($params[ 'assign' ], $_html_result);
} else {
return implode("\n", $_html_result);
}
}
/**
* @param $name
* @param $value
@ -177,69 +191,76 @@ function smarty_function_html_radios($params, Smarty_Internal_Template $template
*
* @return string
*/
function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids,
$escape)
{
function smarty_function_html_radios_output(
$name,
$value,
$output,
$selected,
$extra,
$separator,
$labels,
$label_ids,
$escape
) {
$_output = '';
if (is_object($value)) {
if (method_exists($value, '__toString')) {
$value = (string) $value->__toString();
$value = (string)$value->__toString();
} else {
trigger_error('html_options: value is an object of class \'' . get_class($value) .
'\' without __toString() method', E_USER_NOTICE);
trigger_error(
'html_options: value is an object of class \'' . get_class($value) .
'\' without __toString() method',
E_USER_NOTICE
);
return '';
}
} else {
$value = (string) $value;
$value = (string)$value;
}
if (is_object($output)) {
if (method_exists($output, '__toString')) {
$output = (string) $output->__toString();
$output = (string)$output->__toString();
} else {
trigger_error('html_options: output is an object of class \'' . get_class($output) .
'\' without __toString() method', E_USER_NOTICE);
trigger_error(
'html_options: output is an object of class \'' . get_class($output) .
'\' without __toString() method',
E_USER_NOTICE
);
return '';
}
} else {
$output = (string) $output;
$output = (string)$output;
}
if ($labels) {
if ($label_ids) {
$_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_',
$name . '_' . $value));
$_id = smarty_function_escape_special_chars(
preg_replace(
'![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER,
'_',
$name . '_' . $value
)
);
$_output .= '<label for="' . $_id . '">';
} else {
$_output .= '<label>';
}
}
$name = smarty_function_escape_special_chars($name);
$value = smarty_function_escape_special_chars($value);
if ($escape) {
$output = smarty_function_escape_special_chars($output);
}
$_output .= '<input type="radio" name="' . $name . '" value="' . $value . '"';
if ($labels && $label_ids) {
$_output .= ' id="' . $_id . '"';
}
if ($value === $selected) {
$_output .= ' checked="checked"';
}
$_output .= $extra . ' />' . $output;
if ($labels) {
$_output .= '</label>';
}
$_output .= $separator;
return $_output;
}

@ -28,13 +28,12 @@
* - 2.0 complete rewrite for performance,
* added attributes month_names, *_id
*
*
* @link http://www.smarty.net/manual/en/language.function.html.select.date.php {html_select_date}
* @link http://www.smarty.net/manual/en/language.function.html.select.date.php {html_select_date}
* (Smarty online manual)
* @version 2.0
* @author Andrei Zmievski
* @author Monte Ohrt <monte at ohrt dot com>
* @author Rodney Rehm
* @version 2.0
* @author Andrei Zmievski
* @author Monte Ohrt <monte at ohrt dot com>
* @author Rodney Rehm
*
* @param array $params parameters
*
@ -45,19 +44,24 @@
*/
function smarty_function_html_select_date($params, Smarty_Internal_Template $template)
{
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->_checkPlugins(
array(
array(
'function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'
)
)
);
// generate timestamps used for month names only
static $_month_timestamps = null;
static $_current_year = null;
if ($_month_timestamps === null) {
$_current_year = date('Y');
$_month_timestamps = array();
for ($i = 1; $i <= 12; $i ++) {
for ($i = 1; $i <= 12; $i++) {
$_month_timestamps[ $i ] = mktime(0, 0, 0, $i, 1, 2000);
}
}
/* Default values. */
$prefix = 'Date_';
$start_year = null;
@ -106,17 +110,21 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
$day_id = null;
$month_id = null;
$year_id = null;
foreach ($params as $_key => $_value) {
switch ($_key) {
case 'time':
if (!is_array($_value) && $_value !== null) {
$template->_checkPlugins(array(array('function' => 'smarty_make_timestamp',
'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php')));
$template->_checkPlugins(
array(
array(
'function' => 'smarty_make_timestamp',
'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'
)
)
);
$time = smarty_make_timestamp($_value);
}
break;
case 'month_names':
if (is_array($_value) && count($_value) === 12) {
$$_key = $_value;
@ -124,7 +132,6 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
trigger_error('html_select_date: month_names must be an array of 12 strings', E_USER_NOTICE);
}
break;
case 'prefix':
case 'field_array':
case 'start_year':
@ -151,17 +158,15 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
case 'month_id':
case 'day_id':
case 'year_id':
$$_key = (string) $_value;
$$_key = (string)$_value;
break;
case 'display_days':
case 'display_months':
case 'display_years':
case 'year_as_text':
case 'reverse_years':
$$_key = (bool) $_value;
$$_key = (bool)$_value;
break;
default:
if (!is_array($_value)) {
$extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"';
@ -171,15 +176,16 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
break;
}
}
// Note: date() is faster than strftime()
// Note: explode(date()) is faster than date() date() date()
if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) {
if (isset($params[ 'time' ][ $prefix . 'Year' ])) {
// $_REQUEST[$field_array] given
foreach (array('Y' => 'Year',
'm' => 'Month',
'd' => 'Day') as $_elementKey => $_elementName) {
foreach (array(
'Y' => 'Year',
'm' => 'Month',
'd' => 'Day'
) as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName);
$$_variableName =
isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] :
@ -187,9 +193,11 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
}
} elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Year' ])) {
// $_REQUEST given
foreach (array('Y' => 'Year',
'm' => 'Month',
'd' => 'Day') as $_elementKey => $_elementName) {
foreach (array(
'Y' => 'Year',
'm' => 'Month',
'd' => 'Day'
) as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName);
$$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ?
$params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey);
@ -207,31 +215,30 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
} else {
list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d', $time));
}
// make syntax "+N" or "-N" work with $start_year and $end_year
// Note preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match) is slower than trim+substr
foreach (array('start',
'end') as $key) {
foreach (array(
'start',
'end'
) as $key) {
$key .= '_year';
$t = $$key;
if ($t === null) {
$$key = (int) $_current_year;
$$key = (int)$_current_year;
} elseif ($t[ 0 ] === '+') {
$$key = (int) ($_current_year + (int) trim(substr($t, 1)));
$$key = (int)($_current_year + (int)trim(substr($t, 1)));
} elseif ($t[ 0 ] === '-') {
$$key = (int) ($_current_year - (int) trim(substr($t, 1)));
$$key = (int)($_current_year - (int)trim(substr($t, 1)));
} else {
$$key = (int) $$key;
$$key = (int)$$key;
}
}
// flip for ascending or descending
if (($start_year > $end_year && !$reverse_years) || ($start_year < $end_year && $reverse_years)) {
$t = $end_year;
$end_year = $start_year;
$start_year = $t;
}
// generate year <select> or <input>
if ($display_years) {
$_extra = '';
@ -242,7 +249,6 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
if ($year_extra) {
$_extra .= ' ' . $year_extra;
}
if ($year_as_text) {
$_html_years =
'<input type="text" name="' . $_name . '" value="' . $_year . '" size="4" maxlength="4"' . $_extra .
@ -250,31 +256,29 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
} else {
$_html_years = '<select name="' . $_name . '"';
if ($year_id !== null || $all_id !== null) {
$_html_years .= ' id="' . smarty_function_escape_special_chars($year_id !== null ?
($year_id ? $year_id : $_name) :
($all_id ? ($all_id . $_name) :
$_name)) . '"';
$_html_years .= ' id="' . smarty_function_escape_special_chars(
$year_id !== null ?
($year_id ? $year_id : $_name) :
($all_id ? ($all_id . $_name) :
$_name)
) . '"';
}
if ($year_size) {
$_html_years .= ' size="' . $year_size . '"';
}
$_html_years .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($year_empty) || isset($all_empty)) {
$_html_years .= '<option value="">' . (isset($year_empty) ? $year_empty : $all_empty) . '</option>' .
$option_separator;
}
$op = $start_year > $end_year ? - 1 : 1;
$op = $start_year > $end_year ? -1 : 1;
for ($i = $start_year; $op > 0 ? $i <= $end_year : $i >= $end_year; $i += $op) {
$_html_years .= '<option value="' . $i . '"' . ($_year == $i ? ' selected="selected"' : '') . '>' . $i .
'</option>' . $option_separator;
}
$_html_years .= '</select>';
}
}
// generate month <select> or <input>
if ($display_months) {
$_extra = '';
@ -285,25 +289,24 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
if ($month_extra) {
$_extra .= ' ' . $month_extra;
}
$_html_months = '<select name="' . $_name . '"';
if ($month_id !== null || $all_id !== null) {
$_html_months .= ' id="' . smarty_function_escape_special_chars($month_id !== null ?
($month_id ? $month_id : $_name) :
($all_id ? ($all_id . $_name) :
$_name)) . '"';
$_html_months .= ' id="' . smarty_function_escape_special_chars(
$month_id !== null ?
($month_id ? $month_id : $_name) :
($all_id ? ($all_id . $_name) :
$_name)
) . '"';
}
if ($month_size) {
$_html_months .= ' size="' . $month_size . '"';
}
$_html_months .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($month_empty) || isset($all_empty)) {
$_html_months .= '<option value="">' . (isset($month_empty) ? $month_empty : $all_empty) . '</option>' .
$option_separator;
}
for ($i = 1; $i <= 12; $i ++) {
for ($i = 1; $i <= 12; $i++) {
$_val = sprintf('%02d', $i);
$_text = isset($month_names) ? smarty_function_escape_special_chars($month_names[ $i ]) :
($month_format === '%m' ? $_val : strftime($month_format, $_month_timestamps[ $i ]));
@ -311,10 +314,8 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
$_html_months .= '<option value="' . $_value . '"' . ($_val == $_month ? ' selected="selected"' : '') .
'>' . $_text . '</option>' . $option_separator;
}
$_html_months .= '</select>';
}
// generate day <select> or <input>
if ($display_days) {
$_extra = '';
@ -325,37 +326,34 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
if ($day_extra) {
$_extra .= ' ' . $day_extra;
}
$_html_days = '<select name="' . $_name . '"';
if ($day_id !== null || $all_id !== null) {
$_html_days .= ' id="' .
smarty_function_escape_special_chars($day_id !== null ? ($day_id ? $day_id : $_name) :
($all_id ? ($all_id . $_name) : $_name)) . '"';
smarty_function_escape_special_chars(
$day_id !== null ? ($day_id ? $day_id : $_name) :
($all_id ? ($all_id . $_name) : $_name)
) . '"';
}
if ($day_size) {
$_html_days .= ' size="' . $day_size . '"';
}
$_html_days .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($day_empty) || isset($all_empty)) {
$_html_days .= '<option value="">' . (isset($day_empty) ? $day_empty : $all_empty) . '</option>' .
$option_separator;
}
for ($i = 1; $i <= 31; $i ++) {
for ($i = 1; $i <= 31; $i++) {
$_val = sprintf('%02d', $i);
$_text = $day_format === '%02d' ? $_val : sprintf($day_format, $i);
$_value = $day_value_format === '%02d' ? $_val : sprintf($day_value_format, $i);
$_html_days .= '<option value="' . $_value . '"' . ($_val == $_day ? ' selected="selected"' : '') . '>' .
$_text . '</option>' . $option_separator;
}
$_html_days .= '</select>';
}
// order the fields for output
$_html = '';
for ($i = 0; $i <= 2; $i ++) {
for ($i = 0; $i <= 2; $i++) {
switch ($field_order[ $i ]) {
case 'Y':
case 'y':
@ -366,7 +364,6 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
$_html .= $_html_years;
}
break;
case 'm':
case 'M':
if (isset($_html_months)) {
@ -376,7 +373,6 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
$_html .= $_html_months;
}
break;
case 'd':
case 'D':
if (isset($_html_days)) {
@ -388,6 +384,5 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
break;
}
}
return $_html;
}

@ -11,130 +11,124 @@
* Name: html_select_time
* Purpose: Prints the dropdowns for time selection
*
* @link http://www.smarty.net/manual/en/language.function.html.select.time.php {html_select_time}
* @link http://www.smarty.net/manual/en/language.function.html.select.time.php {html_select_time}
* (Smarty online manual)
* @author Roberto Berto <roberto@berto.net>
* @author Monte Ohrt <monte AT ohrt DOT com>
* @author Roberto Berto <roberto@berto.net>
* @author Monte Ohrt <monte AT ohrt DOT com>
*
* @param array $params parameters
*
* @param \Smarty_Internal_Template $template
*
* @return string
* @uses smarty_make_timestamp()
* @uses smarty_make_timestamp()
* @throws \SmartyException
*/
function smarty_function_html_select_time($params, Smarty_Internal_Template $template)
{
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->_checkPlugins(
array(
array(
'function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'
)
)
);
$prefix = 'Time_';
$field_array = null;
$field_separator = "\n";
$option_separator = "\n";
$time = null;
$display_hours = true;
$display_minutes = true;
$display_seconds = true;
$display_meridian = true;
$hour_format = '%02d';
$hour_value_format = '%02d';
$minute_format = '%02d';
$minute_value_format = '%02d';
$second_format = '%02d';
$second_value_format = '%02d';
$hour_size = null;
$minute_size = null;
$second_size = null;
$meridian_size = null;
$all_empty = null;
$hour_empty = null;
$minute_empty = null;
$second_empty = null;
$meridian_empty = null;
$all_id = null;
$hour_id = null;
$minute_id = null;
$second_id = null;
$meridian_id = null;
$use_24_hours = true;
$minute_interval = 1;
$second_interval = 1;
$extra_attrs = '';
$all_extra = null;
$hour_extra = null;
$minute_extra = null;
$second_extra = null;
$meridian_extra = null;
foreach ($params as $_key => $_value) {
switch ($_key) {
case 'time':
if (!is_array($_value) && $_value !== null) {
$template->_checkPlugins(array(array('function' => 'smarty_make_timestamp',
'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php')));
$template->_checkPlugins(
array(
array(
'function' => 'smarty_make_timestamp',
'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'
)
)
);
$time = smarty_make_timestamp($_value);
}
break;
case 'prefix':
case 'field_array':
case 'field_separator':
case 'option_separator':
case 'all_extra':
case 'hour_extra':
case 'minute_extra':
case 'second_extra':
case 'meridian_extra':
case 'all_empty':
case 'hour_empty':
case 'minute_empty':
case 'second_empty':
case 'meridian_empty':
case 'all_id':
case 'hour_id':
case 'minute_id':
case 'second_id':
case 'meridian_id':
case 'hour_format':
case 'hour_value_format':
case 'minute_format':
case 'minute_value_format':
case 'second_format':
case 'second_value_format':
$$_key = (string) $_value;
$$_key = (string)$_value;
break;
case 'display_hours':
case 'display_minutes':
case 'display_seconds':
case 'display_meridian':
case 'use_24_hours':
$$_key = (bool) $_value;
$$_key = (bool)$_value;
break;
case 'minute_interval':
case 'second_interval':
case 'hour_size':
case 'minute_size':
case 'second_size':
case 'meridian_size':
$$_key = (int) $_value;
$$_key = (int)$_value;
break;
default:
if (!is_array($_value)) {
$extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"';
@ -144,13 +138,14 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
break;
}
}
if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) {
if (isset($params[ 'time' ][ $prefix . 'Hour' ])) {
// $_REQUEST[$field_array] given
foreach (array('H' => 'Hour',
'i' => 'Minute',
's' => 'Second') as $_elementKey => $_elementName) {
foreach (array(
'H' => 'Hour',
'i' => 'Minute',
's' => 'Second'
) as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName);
$$_variableName =
isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] :
@ -163,9 +158,11 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
} elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Hour' ])) {
// $_REQUEST given
foreach (array('H' => 'Hour',
'i' => 'Minute',
's' => 'Second') as $_elementKey => $_elementName) {
foreach (array(
'H' => 'Hour',
'i' => 'Minute',
's' => 'Second'
) as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName);
$$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ?
$params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey);
@ -187,7 +184,6 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
} else {
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
}
// generate hour <select>
if ($display_hours) {
$_html_hours = '';
@ -199,42 +195,37 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
if ($hour_extra) {
$_extra .= ' ' . $hour_extra;
}
$_html_hours = '<select name="' . $_name . '"';
if ($hour_id !== null || $all_id !== null) {
$_html_hours .= ' id="' .
smarty_function_escape_special_chars($hour_id !== null ? ($hour_id ? $hour_id : $_name) :
($all_id ? ($all_id . $_name) : $_name)) . '"';
smarty_function_escape_special_chars(
$hour_id !== null ? ($hour_id ? $hour_id : $_name) :
($all_id ? ($all_id . $_name) : $_name)
) . '"';
}
if ($hour_size) {
$_html_hours .= ' size="' . $hour_size . '"';
}
$_html_hours .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($hour_empty) || isset($all_empty)) {
$_html_hours .= '<option value="">' . (isset($hour_empty) ? $hour_empty : $all_empty) . '</option>' .
$option_separator;
}
$start = $use_24_hours ? 0 : 1;
$end = $use_24_hours ? 23 : 12;
for ($i = $start; $i <= $end; $i ++) {
for ($i = $start; $i <= $end; $i++) {
$_val = sprintf('%02d', $i);
$_text = $hour_format === '%02d' ? $_val : sprintf($hour_format, $i);
$_value = $hour_value_format === '%02d' ? $_val : sprintf($hour_value_format, $i);
if (!$use_24_hours) {
$_hour12 = $_hour == 0 ? 12 : ($_hour <= 12 ? $_hour : $_hour - 12);
}
$selected = $_hour !== null ? ($use_24_hours ? $_hour == $_val : $_hour12 == $_val) : null;
$_html_hours .= '<option value="' . $_value . '"' . ($selected ? ' selected="selected"' : '') . '>' .
$_text . '</option>' . $option_separator;
}
$_html_hours .= '</select>';
}
// generate minute <select>
if ($display_minutes) {
$_html_minutes = '';
@ -246,24 +237,23 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
if ($minute_extra) {
$_extra .= ' ' . $minute_extra;
}
$_html_minutes = '<select name="' . $_name . '"';
if ($minute_id !== null || $all_id !== null) {
$_html_minutes .= ' id="' . smarty_function_escape_special_chars($minute_id !== null ?
($minute_id ? $minute_id : $_name) :
($all_id ? ($all_id . $_name) :
$_name)) . '"';
$_html_minutes .= ' id="' . smarty_function_escape_special_chars(
$minute_id !== null ?
($minute_id ? $minute_id : $_name) :
($all_id ? ($all_id . $_name) :
$_name)
) . '"';
}
if ($minute_size) {
$_html_minutes .= ' size="' . $minute_size . '"';
}
$_html_minutes .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($minute_empty) || isset($all_empty)) {
$_html_minutes .= '<option value="">' . (isset($minute_empty) ? $minute_empty : $all_empty) . '</option>' .
$option_separator;
}
$selected = $_minute !== null ? ($_minute - $_minute % $minute_interval) : null;
for ($i = 0; $i <= 59; $i += $minute_interval) {
$_val = sprintf('%02d', $i);
@ -272,10 +262,8 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
$_html_minutes .= '<option value="' . $_value . '"' . ($selected === $i ? ' selected="selected"' : '') .
'>' . $_text . '</option>' . $option_separator;
}
$_html_minutes .= '</select>';
}
// generate second <select>
if ($display_seconds) {
$_html_seconds = '';
@ -287,24 +275,23 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
if ($second_extra) {
$_extra .= ' ' . $second_extra;
}
$_html_seconds = '<select name="' . $_name . '"';
if ($second_id !== null || $all_id !== null) {
$_html_seconds .= ' id="' . smarty_function_escape_special_chars($second_id !== null ?
($second_id ? $second_id : $_name) :
($all_id ? ($all_id . $_name) :
$_name)) . '"';
$_html_seconds .= ' id="' . smarty_function_escape_special_chars(
$second_id !== null ?
($second_id ? $second_id : $_name) :
($all_id ? ($all_id . $_name) :
$_name)
) . '"';
}
if ($second_size) {
$_html_seconds .= ' size="' . $second_size . '"';
}
$_html_seconds .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($second_empty) || isset($all_empty)) {
$_html_seconds .= '<option value="">' . (isset($second_empty) ? $second_empty : $all_empty) . '</option>' .
$option_separator;
}
$selected = $_second !== null ? ($_second - $_second % $second_interval) : null;
for ($i = 0; $i <= 59; $i += $second_interval) {
$_val = sprintf('%02d', $i);
@ -313,10 +300,8 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
$_html_seconds .= '<option value="' . $_value . '"' . ($selected === $i ? ' selected="selected"' : '') .
'>' . $_text . '</option>' . $option_separator;
}
$_html_seconds .= '</select>';
}
// generate meridian <select>
if ($display_meridian && !$use_24_hours) {
$_html_meridian = '';
@ -328,36 +313,36 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
if ($meridian_extra) {
$_extra .= ' ' . $meridian_extra;
}
$_html_meridian = '<select name="' . $_name . '"';
if ($meridian_id !== null || $all_id !== null) {
$_html_meridian .= ' id="' . smarty_function_escape_special_chars($meridian_id !== null ?
($meridian_id ? $meridian_id :
$_name) :
($all_id ? ($all_id . $_name) :
$_name)) . '"';
$_html_meridian .= ' id="' . smarty_function_escape_special_chars(
$meridian_id !== null ?
($meridian_id ? $meridian_id :
$_name) :
($all_id ? ($all_id . $_name) :
$_name)
) . '"';
}
if ($meridian_size) {
$_html_meridian .= ' size="' . $meridian_size . '"';
}
$_html_meridian .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($meridian_empty) || isset($all_empty)) {
$_html_meridian .= '<option value="">' . (isset($meridian_empty) ? $meridian_empty : $all_empty) .
'</option>' . $option_separator;
}
$_html_meridian .= '<option value="am"' . ($_hour > 0 && $_hour < 12 ? ' selected="selected"' : '') .
'>AM</option>' . $option_separator . '<option value="pm"' .
($_hour < 12 ? '' : ' selected="selected"') . '>PM</option>' . $option_separator .
'</select>';
}
$_html = '';
foreach (array('_html_hours',
'_html_minutes',
'_html_seconds',
'_html_meridian') as $k) {
foreach (array(
'_html_hours',
'_html_minutes',
'_html_seconds',
'_html_meridian'
) as $k) {
if (isset($$k)) {
if ($_html) {
$_html .= $field_separator;
@ -365,6 +350,5 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
$_html .= $$k;
}
}
return $_html;
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsFunction
*/
/**
* Smarty {html_table} function plugin
* Type: function
@ -35,12 +34,11 @@
* {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
* {table loop=$data cols="first,second,third" tr_attr=$colors}
*
*
* @author Monte Ohrt <monte at ohrt dot com>
* @author credit to Messju Mohr <messju at lammfellpuschen dot de>
* @author credit to boots <boots dot smarty at yahoo dot com>
* @version 1.1
* @link http://www.smarty.net/manual/en/language.function.html.table.php {html_table}
* @author Monte Ohrt <monte at ohrt dot com>
* @author credit to Messju Mohr <messju at lammfellpuschen dot de>
* @author credit to boots <boots dot smarty at yahoo dot com>
* @version 1.1
* @link http://www.smarty.net/manual/en/language.function.html.table.php {html_table}
* (Smarty online manual)
*
* @param array $params parameters
@ -61,19 +59,15 @@ function smarty_function_html_table($params)
$inner = 'cols';
$caption = '';
$loop = null;
if (!isset($params[ 'loop' ])) {
trigger_error("html_table: missing 'loop' parameter", E_USER_WARNING);
return;
}
foreach ($params as $_key => $_value) {
switch ($_key) {
case 'loop':
$$_key = (array) $_value;
$$_key = (array)$_value;
break;
case 'cols':
if (is_array($_value) && !empty($_value)) {
$cols = $_value;
@ -82,25 +76,22 @@ function smarty_function_html_table($params)
$cols = explode(',', $_value);
$cols_count = count($cols);
} elseif (!empty($_value)) {
$cols_count = (int) $_value;
$cols_count = (int)$_value;
} else {
$cols_count = $cols;
}
break;
case 'rows':
$$_key = (int) $_value;
$$_key = (int)$_value;
break;
case 'table_attr':
case 'trailpad':
case 'hdir':
case 'vdir':
case 'inner':
case 'caption':
$$_key = (string) $_value;
$$_key = (string)$_value;
break;
case 'tr_attr':
case 'td_attr':
case 'th_attr':
@ -108,7 +99,6 @@ function smarty_function_html_table($params)
break;
}
}
$loop_count = count($loop);
if (empty($params[ 'rows' ])) {
/* no rows specified */
@ -119,37 +109,30 @@ function smarty_function_html_table($params)
$cols_count = ceil($loop_count / $rows);
}
}
$output = "<table $table_attr>\n";
if (!empty($caption)) {
$output .= '<caption>' . $caption . "</caption>\n";
}
if (is_array($cols)) {
$cols = ($hdir === 'right') ? $cols : array_reverse($cols);
$output .= "<thead><tr>\n";
for ($r = 0; $r < $cols_count; $r ++) {
for ($r = 0; $r < $cols_count; $r++) {
$output .= '<th' . smarty_function_html_table_cycle('th', $th_attr, $r) . '>';
$output .= $cols[ $r ];
$output .= "</th>\n";
}
$output .= "</tr></thead>\n";
}
$output .= "<tbody>\n";
for ($r = 0; $r < $rows; $r ++) {
for ($r = 0; $r < $rows; $r++) {
$output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n";
$rx = ($vdir === 'down') ? $r * $cols_count : ($rows - 1 - $r) * $cols_count;
for ($c = 0; $c < $cols_count; $c ++) {
for ($c = 0; $c < $cols_count; $c++) {
$x = ($hdir === 'right') ? $rx + $c : $rx + $cols_count - 1 - $c;
if ($inner !== 'cols') {
/* shuffle x to loop over rows*/
$x = floor($x / $cols_count) + ($x % $cols_count) * $rows;
}
if ($x < $loop_count) {
$output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[ $x ] . "</td>\n";
} else {
@ -160,9 +143,9 @@ function smarty_function_html_table($params)
}
$output .= "</tbody>\n";
$output .= "</table>\n";
return $output;
}
/**
* @param $name
* @param $var
@ -177,6 +160,5 @@ function smarty_function_html_table_cycle($name, $var, $no)
} else {
$ret = $var[ $no % count($var) ];
}
return ($ret) ? ' ' . $ret : '';
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsFunction
*/
/**
* Smarty {mailto} function plugin
* Type: function
@ -37,12 +36,11 @@
* {mailto address="me@domain.com" cc="you@domain.com,they@domain.com"}
* {mailto address="me@domain.com" extra='class="mailto"'}
*
*
* @link http://www.smarty.net/manual/en/language.function.mailto.php {mailto}
* @link http://www.smarty.net/manual/en/language.function.mailto.php {mailto}
* (Smarty online manual)
* @version 1.2
* @author Monte Ohrt <monte at ohrt dot com>
* @author credits to Jason Sweat (added cc, bcc and subject functionality)
* @version 1.2
* @author Monte Ohrt <monte at ohrt dot com>
* @author credits to Jason Sweat (added cc, bcc and subject functionality)
*
* @param array $params parameters
*
@ -53,15 +51,12 @@ function smarty_function_mailto($params)
static $_allowed_encoding =
array('javascript' => true, 'javascript_charcode' => true, 'hex' => true, 'none' => true);
$extra = '';
if (empty($params[ 'address' ])) {
trigger_error("mailto: missing 'address' parameter", E_USER_WARNING);
return;
} else {
$address = $params[ 'address' ];
}
$text = $address;
// netscape and mozilla do not decode %40 (@) in BCC field (bug?)
// so, don't encode it.
@ -77,61 +72,52 @@ function smarty_function_mailto($params)
$mail_parms[] = $var . '=' . str_replace($search, $replace, rawurlencode($value));
}
break;
case 'subject':
case 'newsgroups':
$mail_parms[] = $var . '=' . rawurlencode($value);
break;
case 'extra':
case 'text':
$$var = $value;
// no break
default:
}
}
if ($mail_parms) {
$address .= '?' . join('&', $mail_parms);
}
$encode = (empty($params[ 'encode' ])) ? 'none' : $params[ 'encode' ];
if (!isset($_allowed_encoding[ $encode ])) {
trigger_error("mailto: 'encode' parameter must be none, javascript, javascript_charcode or hex",
E_USER_WARNING);
trigger_error(
"mailto: 'encode' parameter must be none, javascript, javascript_charcode or hex",
E_USER_WARNING
);
return;
}
// FIXME: (rodneyrehm) document.write() excues me what? 1998 has passed!
if ($encode === 'javascript') {
$string = 'document.write(\'<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>\');';
$js_encode = '';
for ($x = 0, $_length = strlen($string); $x < $_length; $x ++) {
for ($x = 0, $_length = strlen($string); $x < $_length; $x++) {
$js_encode .= '%' . bin2hex($string[ $x ]);
}
return '<script type="text/javascript">eval(unescape(\'' . $js_encode . '\'))</script>';
} elseif ($encode === 'javascript_charcode') {
$string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
for ($x = 0, $y = strlen($string); $x < $y; $x ++) {
for ($x = 0, $y = strlen($string); $x < $y; $x++) {
$ord[] = ord($string[ $x ]);
}
$_ret = "<script type=\"text/javascript\" language=\"javascript\">\n" . "{document.write(String.fromCharCode(" .
implode(',', $ord) . "))" . "}\n" . "</script>\n";
return $_ret;
} elseif ($encode === 'hex') {
preg_match('!^(.*)(\?.*)$!', $address, $match);
if (!empty($match[ 2 ])) {
trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.", E_USER_WARNING);
return;
}
$address_encode = '';
for ($x = 0, $_length = strlen($address); $x < $_length; $x ++) {
for ($x = 0, $_length = strlen($address); $x < $_length; $x++) {
if (preg_match('!\w!' . Smarty::$_UTF8_MODIFIER, $address[ $x ])) {
$address_encode .= '%' . bin2hex($address[ $x ]);
} else {
@ -139,12 +125,10 @@ function smarty_function_mailto($params)
}
}
$text_encode = '';
for ($x = 0, $_length = strlen($text); $x < $_length; $x ++) {
for ($x = 0, $_length = strlen($text); $x < $_length; $x++) {
$text_encode .= '&#x' . bin2hex($text[ $x ]) . ';';
}
$mailto = "&#109;&#97;&#105;&#108;&#116;&#111;&#58;";
return '<a href="' . $mailto . $address_encode . '" ' . $extra . '>' . $text_encode . '</a>';
} else {
// no encoding

@ -6,16 +6,15 @@
* @package Smarty
* @subpackage PluginsFunction
*/
/**
* Smarty {math} function plugin
* Type: function
* Name: math
* Purpose: handle math computations in template
*
* @link http://www.smarty.net/manual/en/language.function.math.php {math}
* @link http://www.smarty.net/manual/en/language.function.math.php {math}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author Monte Ohrt <monte at ohrt dot com>
*
* @param array $params parameters
* @param Smarty_Internal_Template $template template object
@ -25,66 +24,71 @@
function smarty_function_math($params, $template)
{
static $_allowed_funcs =
array('int' => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true,
'log' => true, 'log10' => true, 'max' => true, 'min' => true, 'pi' => true, 'pow' => true, 'rand' => true,
'round' => true, 'sin' => true, 'sqrt' => true, 'srand' => true, 'tan' => true);
array(
'int' => true,
'abs' => true,
'ceil' => true,
'cos' => true,
'exp' => true,
'floor' => true,
'log' => true,
'log10' => true,
'max' => true,
'min' => true,
'pi' => true,
'pow' => true,
'rand' => true,
'round' => true,
'sin' => true,
'sqrt' => true,
'srand' => true,
'tan' => true
);
// be sure equation parameter is present
if (empty($params[ 'equation' ])) {
trigger_error("math: missing equation parameter", E_USER_WARNING);
return;
}
$equation = $params[ 'equation' ];
// make sure parenthesis are balanced
if (substr_count($equation, '(') !== substr_count($equation, ')')) {
trigger_error("math: unbalanced parenthesis", E_USER_WARNING);
return;
}
// disallow backticks
if (strpos($equation, '`') !== false) {
trigger_error("math: backtick character not allowed in equation", E_USER_WARNING);
return;
}
// also disallow dollar signs
if (strpos($equation, '$') !== false) {
trigger_error("math: dollar signs not allowed in equation", E_USER_WARNING);
return;
}
foreach ($params as $key => $val) {
if ($key !== 'equation' && $key !== 'format' && $key !== 'assign') {
// make sure value is not empty
if (strlen($val) === 0) {
trigger_error("math: parameter '{$key}' is empty", E_USER_WARNING);
return;
}
if (!is_numeric($val)) {
trigger_error("math: parameter '{$key}' is not numeric", E_USER_WARNING);
return;
}
}
}
// match all vars in equation, make sure all are passed
preg_match_all('!(?:0x[a-fA-F0-9]+)|([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)!', $equation, $match);
foreach ($match[ 1 ] as $curr_var) {
if ($curr_var && !isset($params[ $curr_var ]) && !isset($_allowed_funcs[ $curr_var ])) {
trigger_error("math: function call '{$curr_var}' not allowed, or missing parameter '{$curr_var}'", E_USER_WARNING);
trigger_error(
"math: function call '{$curr_var}' not allowed, or missing parameter '{$curr_var}'",
E_USER_WARNING
);
return;
}
}
foreach ($params as $key => $val) {
if ($key !== 'equation' && $key !== 'format' && $key !== 'assign') {
$equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation);
@ -92,7 +96,6 @@ function smarty_function_math($params, $template)
}
$smarty_math_result = null;
eval("\$smarty_math_result = " . $equation . ";");
if (empty($params[ 'format' ])) {
if (empty($params[ 'assign' ])) {
return $smarty_math_result;

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifier
*/
/**
* Smarty capitalize modifier plugin
* Type: modifier
@ -29,50 +28,75 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
$upper_string = mb_convert_case($string, MB_CASE_TITLE, Smarty::$_CHARSET);
} else {
// uppercase word breaks
$upper_string = preg_replace_callback("!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER,
'smarty_mod_cap_mbconvert_cb', $string);
$upper_string = preg_replace_callback(
"!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER,
'smarty_mod_cap_mbconvert_cb',
$string
);
}
// check uc_digits case
if (!$uc_digits) {
if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches,
PREG_OFFSET_CAPTURE)) {
if (preg_match_all(
"!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER,
$string,
$matches,
PREG_OFFSET_CAPTURE
)
) {
foreach ($matches[ 1 ] as $match) {
$upper_string =
substr_replace($upper_string, mb_strtolower($match[ 0 ], Smarty::$_CHARSET), $match[ 1 ],
strlen($match[ 0 ]));
substr_replace(
$upper_string,
mb_strtolower($match[ 0 ], Smarty::$_CHARSET),
$match[ 1 ],
strlen($match[ 0 ])
);
}
}
}
$upper_string =
preg_replace_callback("!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_mbconvert2_cb',
$upper_string);
preg_replace_callback(
"!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER,
'smarty_mod_cap_mbconvert2_cb',
$upper_string
);
return $upper_string;
}
// lowercase first
if ($lc_rest) {
$string = strtolower($string);
}
// uppercase (including hyphenated words)
$upper_string =
preg_replace_callback("!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst_cb',
$string);
preg_replace_callback(
"!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER,
'smarty_mod_cap_ucfirst_cb',
$string
);
// check uc_digits case
if (!$uc_digits) {
if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches,
PREG_OFFSET_CAPTURE)) {
if (preg_match_all(
"!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER,
$string,
$matches,
PREG_OFFSET_CAPTURE
)
) {
foreach ($matches[ 1 ] as $match) {
$upper_string =
substr_replace($upper_string, strtolower($match[ 0 ]), $match[ 1 ], strlen($match[ 0 ]));
}
}
}
$upper_string = preg_replace_callback("!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst2_cb',
$upper_string);
$upper_string = preg_replace_callback(
"!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER,
'smarty_mod_cap_ucfirst2_cb',
$upper_string
);
return $upper_string;
}
/*
/**
*
* Bug: create_function() use exhausts memory when used in long loops
* Fix: use declared functions for callbacks instead of using create_function()
@ -89,6 +113,7 @@ function smarty_mod_cap_mbconvert_cb($matches)
{
return stripslashes($matches[ 1 ]) . mb_convert_case(stripslashes($matches[ 2 ]), MB_CASE_UPPER, Smarty::$_CHARSET);
}
/**
* @param $matches
*
@ -98,6 +123,7 @@ function smarty_mod_cap_mbconvert2_cb($matches)
{
return stripslashes($matches[ 1 ]) . mb_convert_case(stripslashes($matches[ 3 ]), MB_CASE_UPPER, Smarty::$_CHARSET);
}
/**
* @param $matches
*
@ -107,6 +133,7 @@ function smarty_mod_cap_ucfirst_cb($matches)
{
return stripslashes($matches[ 1 ]) . ucfirst(stripslashes($matches[ 2 ]));
}
/**
* @param $matches
*

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifier
*/
/**
* Smarty date_format modifier plugin
* Type: modifier
@ -38,33 +37,37 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
static $is_loaded = false;
if (!$is_loaded) {
if (!is_callable('smarty_make_timestamp')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
include_once SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php';
}
$is_loaded = true;
}
if ($string !== '' && $string !== '0000-00-00' && $string !== '0000-00-00 00:00:00') {
if (!empty($string) && $string !== '0000-00-00' && $string !== '0000-00-00 00:00:00') {
$timestamp = smarty_make_timestamp($string);
} elseif ($default_date !== '') {
} elseif (!empty($default_date)) {
$timestamp = smarty_make_timestamp($default_date);
} else {
return;
}
if ($formatter === 'strftime' || ($formatter === 'auto' && strpos($format, '%') !== false)) {
if (Smarty::$_IS_WINDOWS) {
$_win_from = array('%D',
'%h',
'%n',
'%r',
'%R',
'%t',
'%T');
$_win_to = array('%m/%d/%y',
'%b',
"\n",
'%I:%M:%S %p',
'%H:%M',
"\t",
'%H:%M:%S');
$_win_from = array(
'%D',
'%h',
'%n',
'%r',
'%R',
'%t',
'%T'
);
$_win_to = array(
'%m/%d/%y',
'%b',
"\n",
'%I:%M:%S %p',
'%H:%M',
"\t",
'%H:%M:%S'
);
if (strpos($format, '%e') !== false) {
$_win_from[] = '%e';
$_win_to[] = sprintf('%\' 2d', date('j', $timestamp));
@ -75,7 +78,6 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
}
$format = str_replace($_win_from, $_win_to, $format);
}
return strftime($format, $timestamp);
} else {
return date($format, $timestamp);

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage Debug
*/
/**
* Smarty debug_print_var modifier plugin
* Type: modifier
@ -26,7 +25,7 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
{
$_replace = array("\n" => '\n', "\r" => '\r', "\t" => '\t');
switch (gettype($var)) {
case 'array' :
case 'array':
$results = '<b>Array (' . count($var) . ')</b>';
if ($depth === $max) {
break;
@ -34,12 +33,11 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
foreach ($var as $curr_key => $curr_val) {
$results .= '<br>' . str_repeat('&nbsp;', $depth * 2) . '<b>' . strtr($curr_key, $_replace) .
'</b> =&gt; ' .
smarty_modifier_debug_print_var($curr_val, $max, $length, ++ $depth, $objects);
$depth --;
smarty_modifier_debug_print_var($curr_val, $max, $length, ++$depth, $objects);
$depth--;
}
break;
case 'object' :
case 'object':
$object_vars = get_object_vars($var);
$results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>';
if (in_array($var, $objects)) {
@ -52,14 +50,13 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
$objects[] = $var;
foreach ($object_vars as $curr_key => $curr_val) {
$results .= '<br>' . str_repeat('&nbsp;', $depth * 2) . '<b> -&gt;' . strtr($curr_key, $_replace) .
'</b> = ' . smarty_modifier_debug_print_var($curr_val, $max, $length, ++ $depth, $objects);
$depth --;
'</b> = ' . smarty_modifier_debug_print_var($curr_val, $max, $length, ++$depth, $objects);
$depth--;
}
break;
case 'boolean' :
case 'NULL' :
case 'resource' :
case 'boolean':
case 'NULL':
case 'resource':
if (true === $var) {
$results = 'true';
} elseif (false === $var) {
@ -67,17 +64,15 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
} elseif (null === $var) {
$results = 'null';
} else {
$results = htmlspecialchars((string) $var);
$results = htmlspecialchars((string)$var);
}
$results = '<i>' . $results . '</i>';
break;
case 'integer' :
case 'float' :
$results = htmlspecialchars((string) $var);
case 'integer':
case 'float':
$results = htmlspecialchars((string)$var);
break;
case 'string' :
case 'string':
$results = strtr($var, $_replace);
if (Smarty::$_MBSTRING) {
if (mb_strlen($var, Smarty::$_CHARSET) > $length) {
@ -88,13 +83,11 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
$results = substr($var, 0, $length - 3) . '...';
}
}
$results = htmlspecialchars('"' . $results . '"', ENT_QUOTES, Smarty::$_CHARSET);
break;
case 'unknown type' :
default :
$results = strtr((string) $var, $_replace);
case 'unknown type':
default:
$results = strtr((string)$var, $_replace);
if (Smarty::$_MBSTRING) {
if (mb_strlen($results, Smarty::$_CHARSET) > $length) {
$results = mb_substr($results, 0, $length - 3, Smarty::$_CHARSET) . '...';
@ -104,9 +97,7 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
$results = substr($results, 0, $length - 3) . '...';
}
}
$results = htmlspecialchars($results, ENT_QUOTES, Smarty::$_CHARSET);
}
return $results;
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifier
*/
/**
* Smarty escape modifier plugin
* Type: modifier
@ -30,11 +29,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
}
if (!$char_set) {
$char_set = Smarty::$_CHARSET;
}
switch ($esc_type) {
case 'html':
if ($_double_encode) {
@ -48,14 +45,21 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
// php <5.2.3 - prevent double encoding
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
$string = str_replace(array('%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'), array('&',
';'), $string);
$string = str_replace(
array(
'%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'
),
array(
'&',
';'
),
$string
);
return $string;
}
}
// no break
case 'htmlall':
if (Smarty::$_MBSTRING) {
// mb_convert_encoding ignores htmlspecialchars()
@ -71,18 +75,23 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
$string =
str_replace(array('%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'), array('&',
';'), $string);
str_replace(
array(
'%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'
),
array(
'&',
';'
),
$string
);
return $string;
}
}
// htmlentities() won't convert everything, so use mb_convert_encoding
return mb_convert_encoding($string, 'HTML-ENTITIES', $char_set);
}
// no MBString fallback
if ($_double_encode) {
return htmlentities($string, ENT_QUOTES, $char_set, $double_encode);
@ -92,41 +101,43 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
} else {
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlentities($string, ENT_QUOTES, $char_set);
$string = str_replace(array('%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'), array('&',
';'), $string);
$string = str_replace(
array(
'%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'
),
array(
'&',
';'
),
$string
);
return $string;
}
}
// no break
case 'url':
return rawurlencode($string);
case 'urlpathinfo':
return str_replace('%2F', '/', rawurlencode($string));
case 'quotes':
// escape unescaped single quotes
return preg_replace("%(?<!\\\\)'%", "\\'", $string);
case 'hex':
// escape every byte into hex
// Note that the UTF-8 encoded character ä will be represented as %c3%a4
$return = '';
$_length = strlen($string);
for ($x = 0; $x < $_length; $x ++) {
for ($x = 0; $x < $_length; $x++) {
$return .= '%' . bin2hex($string[ $x ]);
}
return $return;
case 'hexentity':
$return = '';
if (Smarty::$_MBSTRING) {
if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
include_once SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php';
}
$is_loaded_1 = true;
}
@ -134,23 +145,20 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
$return .= '&#x' . strtoupper(dechex($unicode)) . ';';
}
return $return;
}
// no MBString fallback
$_length = strlen($string);
for ($x = 0; $x < $_length; $x ++) {
for ($x = 0; $x < $_length; $x++) {
$return .= '&#x' . bin2hex($string[ $x ]) . ';';
}
return $return;
case 'decentity':
$return = '';
if (Smarty::$_MBSTRING) {
if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
include_once SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php';
}
$is_loaded_1 = true;
}
@ -158,50 +166,66 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
$return .= '&#' . $unicode . ';';
}
return $return;
}
// no MBString fallback
$_length = strlen($string);
for ($x = 0; $x < $_length; $x ++) {
for ($x = 0; $x < $_length; $x++) {
$return .= '&#' . ord($string[ $x ]) . ';';
}
return $return;
case 'javascript':
// escape quotes and backslashes, newlines, etc.
return strtr($string, array('\\' => '\\\\',
"'" => "\\'",
'"' => '\\"',
"\r" => '\\r',
"\n" => '\\n',
'</' => '<\/'));
return strtr(
$string,
array(
'\\' => '\\\\',
"'" => "\\'",
'"' => '\\"',
"\r" => '\\r',
"\n" => '\\n',
'</' => '<\/'
)
);
case 'mail':
if (Smarty::$_MBSTRING) {
if (!$is_loaded_2) {
if (!is_callable('smarty_mb_str_replace')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
include_once SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php';
}
$is_loaded_2 = true;
}
return smarty_mb_str_replace(array('@',
'.'), array(' [AT] ',
' [DOT] '), $string);
return smarty_mb_str_replace(
array(
'@',
'.'
),
array(
' [AT] ',
' [DOT] '
),
$string
);
}
// no MBString fallback
return str_replace(array('@',
'.'), array(' [AT] ',
' [DOT] '), $string);
return str_replace(
array(
'@',
'.'
),
array(
' [AT] ',
' [DOT] '
),
$string
);
case 'nonstd':
// escape non-standard chars, such as ms document quotes
$return = '';
if (Smarty::$_MBSTRING) {
if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
include_once SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php';
}
$is_loaded_1 = true;
}
@ -212,12 +236,10 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
$return .= chr($unicode);
}
}
return $return;
}
$_length = strlen($string);
for ($_i = 0; $_i < $_length; $_i ++) {
for ($_i = 0; $_i < $_length; $_i++) {
$_ord = ord(substr($string, $_i, 1));
// non-standard char, escape it
if ($_ord >= 126) {
@ -226,9 +248,7 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
$return .= substr($string, $_i, 1);
}
}
return $return;
default:
return $string;
}

@ -11,13 +11,12 @@
* Name: mb_wordwrap
* Purpose: Wrap a string to a given number of characters
*
* @link http://php.net/manual/en/function.wordwrap.php for similarity
*
* @param string $str the string to wrap
* @param int $width the width of the output
* @param string $break the character used to break the line
* @param boolean $cut ignored parameter, just for the sake of
* @param string $str the string to wrap
* @param int $width the width of the output
* @param string $break the character used to break the line
* @param boolean $cut ignored parameter, just for the sake of
*
* @return string wrapped string
* @author Rodney Rehm
@ -30,30 +29,28 @@ function smarty_modifier_mb_wordwrap($str, $width = 75, $break = "\n", $cut = fa
$t = '';
$_previous = false;
$_space = false;
foreach ($tokens as $_token) {
$token_length = mb_strlen($_token, Smarty::$_CHARSET);
$_tokens = array($_token);
if ($token_length > $width) {
if ($cut) {
$_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER,
$_token,
-1,
PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
$_tokens = preg_split(
'!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER,
$_token,
-1,
PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE
);
}
}
foreach ($_tokens as $token) {
$_space = !!preg_match('!^\s$!S' . Smarty::$_UTF8_MODIFIER, $token);
$token_length = mb_strlen($token, Smarty::$_CHARSET);
$length += $token_length;
if ($length > $width) {
// remove space before inserted break
if ($_previous) {
$t = mb_substr($t, 0, -1, Smarty::$_CHARSET);
}
if (!$_space) {
// add the break before the token
if (!empty($t)) {
@ -61,7 +58,7 @@ function smarty_modifier_mb_wordwrap($str, $width = 75, $break = "\n", $cut = fa
}
$length = $token_length;
}
} else if ($token === "\n") {
} elseif ($token === "\n") {
// hard break must reset counters
$length = 0;
}
@ -70,6 +67,5 @@ function smarty_modifier_mb_wordwrap($str, $width = 75, $break = "\n", $cut = fa
$t .= $token;
}
}
return $t;
}

@ -5,16 +5,15 @@
* @package Smarty
* @subpackage PluginsModifier
*/
/**
* Smarty regex_replace modifier plugin
* Type: modifier
* Name: regex_replace
* Purpose: regular expression search/replace
*
* @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php
* @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php
* regex_replace (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author Monte Ohrt <monte at ohrt dot com>
*
* @param string $string input string
* @param string|array $search regular expression(s) to search for
@ -23,7 +22,7 @@
*
* @return string
*/
function smarty_modifier_regex_replace($string, $search, $replace, $limit = - 1)
function smarty_modifier_regex_replace($string, $search, $replace, $limit = -1)
{
if (is_array($search)) {
foreach ($search as $idx => $s) {
@ -32,7 +31,6 @@ function smarty_modifier_regex_replace($string, $search, $replace, $limit = - 1)
} else {
$search = _smarty_regex_replace_check($search);
}
return preg_replace($search, $replace, $string, $limit);
}
@ -51,8 +49,7 @@ function _smarty_regex_replace_check($search)
}
// remove eval-modifier from $search
if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[ 1 ], 'e') !== false)) {
$search = substr($search, 0, - strlen($match[ 1 ])) . preg_replace('![e\s]+!', '', $match[ 1 ]);
$search = substr($search, 0, -strlen($match[ 1 ])) . preg_replace('![e\s]+!', '', $match[ 1 ]);
}
return $search;
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifier
*/
/**
* Smarty replace modifier plugin
* Type: modifier
@ -28,12 +27,11 @@ function smarty_modifier_replace($string, $search, $replace)
if (Smarty::$_MBSTRING) {
if (!$is_loaded) {
if (!is_callable('smarty_mb_str_replace')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
include_once SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php';
}
$is_loaded = true;
}
return smarty_mb_str_replace($search, $replace, $string);
return smarty_mb_str_replace($search, $replace, $string);
}
return str_replace($search, $replace, $string);
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifier
*/
/**
* Smarty spacify modifier plugin
* Type: modifier
@ -23,5 +22,5 @@
function smarty_modifier_spacify($string, $spacify_char = ' ')
{
// well… what about charsets besides latin and UTF-8?
return implode($spacify_char, preg_split('//' . Smarty::$_UTF8_MODIFIER, $string, - 1, PREG_SPLIT_NO_EMPTY));
return implode($spacify_char, preg_split('//' . Smarty::$_UTF8_MODIFIER, $string, -1, PREG_SPLIT_NO_EMPTY));
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifier
*/
/**
* Smarty truncate modifier plugin
* Type: modifier
@ -30,25 +29,24 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
if ($length === 0) {
return '';
}
if (Smarty::$_MBSTRING) {
if (mb_strlen($string, Smarty::$_CHARSET) > $length) {
$length -= min($length, mb_strlen($etc, Smarty::$_CHARSET));
if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, '',
mb_substr($string, 0, $length + 1, Smarty::$_CHARSET));
$string = preg_replace(
'/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER,
'',
mb_substr($string, 0, $length + 1, Smarty::$_CHARSET)
);
}
if (!$middle) {
return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc;
}
return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc .
mb_substr($string, - $length / 2, $length, Smarty::$_CHARSET);
mb_substr($string, -$length / 2, $length, Smarty::$_CHARSET);
}
return $string;
}
// no MBString fallback
if (isset($string[ $length ])) {
$length -= min($length, strlen($etc));
@ -58,9 +56,7 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
if (!$middle) {
return substr($string, 0, $length) . $etc;
}
return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2);
return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2);
}
return $string;
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty cat modifier plugin
* Type: modifier
@ -15,9 +14,9 @@
* Input: string to catenate
* Example: {$var|cat:"foo"}
*
* @link http://smarty.php.net/manual/en/language.modifier.cat.php cat
* @link http://smarty.php.net/manual/en/language.modifier.cat.php cat
* (Smarty online manual)
* @author Uwe Tews
* @author Uwe Tews
*
* @param array $params parameters
*

@ -5,14 +5,14 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty count_characters modifier plugin
* Type: modifier
* Name: count_characters
* Purpose: count the number of characters in a text
*
* @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual)
* @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online
* manual)
* @author Uwe Tews
*
* @param array $params parameters

@ -5,16 +5,15 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty count_paragraphs modifier plugin
* Type: modifier
* Name: count_paragraphs
* Purpose: count the number of paragraphs in a text
*
* @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* count_paragraphs (Smarty online manual)
* @author Uwe Tews
* @author Uwe Tews
*
* @param array $params parameters
*

@ -5,16 +5,15 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty count_sentences modifier plugin
* Type: modifier
* Name: count_sentences
* Purpose: count the number of sentences in a text
*
* @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* count_sentences (Smarty online manual)
* @author Uwe Tews
* @author Uwe Tews
*
* @param array $params parameters
*

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty count_words modifier plugin
* Type: modifier

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty default modifier plugin
* Type: modifier
@ -25,11 +24,9 @@ function smarty_modifiercompiler_default($params)
if (!isset($params[ 1 ])) {
$params[ 1 ] = "''";
}
array_shift($params);
foreach ($params as $param) {
$output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)';
}
return $output;
}

@ -14,8 +14,8 @@
* @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual)
* @author Rodney Rehm
*
* @param array $params parameters
* @param Smarty_Internal_TemplateCompilerBase $compiler
* @param array $params parameters
* @param Smarty_Internal_TemplateCompilerBase $compiler
*
* @return string with compiled code
* @throws \SmartyException
@ -24,21 +24,24 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
{
static $_double_encode = null;
static $is_loaded = false;
$compiler->template->_checkPlugins(array(array('function' => 'smarty_literal_compiler_param',
'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php')));
$compiler->template->_checkPlugins(
array(
array(
'function' => 'smarty_literal_compiler_param',
'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php'
)
)
);
if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
}
try {
$esc_type = smarty_literal_compiler_param($params, 1, 'html');
$char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET);
$double_encode = smarty_literal_compiler_param($params, 3, true);
if (!$char_set) {
$char_set = Smarty::$_CHARSET;
}
switch ($esc_type) {
case 'html':
if ($_double_encode) {
@ -49,7 +52,7 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
} else {
// fall back to modifier.escape.php
}
// no break
case 'htmlall':
if (Smarty::$_MBSTRING) {
if ($_double_encode) {
@ -65,7 +68,6 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
// fall back to modifier.escape.php
}
}
// no MBString fallback
if ($_double_encode) {
// php >=5.2.3 - go native
@ -77,27 +79,23 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
} else {
// fall back to modifier.escape.php
}
// no break
case 'url':
return 'rawurlencode(' . $params[ 0 ] . ')';
case 'urlpathinfo':
return 'str_replace("%2F", "/", rawurlencode(' . $params[ 0 ] . '))';
case 'quotes':
// escape unescaped single quotes
return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[ 0 ] . ')';
case 'javascript':
// escape quotes and backslashes, newlines, etc.
return 'strtr(' . $params[ 0 ] .
return 'strtr(' .
$params[ 0 ] .
', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/" ))';
}
}
catch (SmartyException $e) {
} catch (SmartyException $e) {
// pass through to regular plugin fallback
}
// could not optimize |escape call, so fallback to regular plugin
if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
$compiler->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'file' ] =
@ -110,6 +108,5 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
$compiler->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'function' ] =
'smarty_modifier_escape';
}
return 'smarty_modifier_escape(' . join(', ', $params) . ')';
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty from_charset modifier plugin
* Type: modifier
@ -24,10 +23,8 @@ function smarty_modifiercompiler_from_charset($params)
// FIXME: (rodneyrehm) shouldn't this throw an error?
return $params[ 0 ];
}
if (!isset($params[ 1 ])) {
$params[ 1 ] = '"ISO-8859-1"';
}
return 'mb_convert_encoding(' . $params[ 0 ] . ', "' . addslashes(Smarty::$_CHARSET) . '", ' . $params[ 1 ] . ')';
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty indent modifier plugin
* Type: modifier
@ -19,7 +18,6 @@
*
* @return string with compiled code
*/
function smarty_modifiercompiler_indent($params)
{
if (!isset($params[ 1 ])) {
@ -28,6 +26,5 @@ function smarty_modifiercompiler_indent($params)
if (!isset($params[ 2 ])) {
$params[ 2 ] = "' '";
}
return 'preg_replace(\'!^!m\',str_repeat(' . $params[ 2 ] . ',' . $params[ 1 ] . '),' . $params[ 0 ] . ')';
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty lower modifier plugin
* Type: modifier
@ -20,7 +19,6 @@
*
* @return string with compiled code
*/
function smarty_modifiercompiler_lower($params)
{
if (Smarty::$_MBSTRING) {

@ -5,14 +5,13 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty noprint modifier plugin
* Type: modifier
* Name: noprint
* Purpose: return an empty string
*
* @author Uwe Tews
* @author Uwe Tews
* @return string with compiled code
*/
function smarty_modifiercompiler_noprint()

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty string_format modifier plugin
* Type: modifier

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty strip modifier plugin
* Type: modifier
@ -22,12 +21,10 @@
*
* @return string with compiled code
*/
function smarty_modifiercompiler_strip($params)
{
if (!isset($params[ 1 ])) {
$params[ 1 ] = "' '";
}
return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})";
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty strip_tags modifier plugin
* Type: modifier

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty to_charset modifier plugin
* Type: modifier
@ -24,10 +23,8 @@ function smarty_modifiercompiler_to_charset($params)
// FIXME: (rodneyrehm) shouldn't this throw an error?
return $params[ 0 ];
}
if (!isset($params[ 1 ])) {
$params[ 1 ] = '"ISO-8859-1"';
}
return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 1 ] . ', "' . addslashes(Smarty::$_CHARSET) . '")';
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty unescape modifier plugin
* Type: modifier
@ -28,22 +27,17 @@ function smarty_modifiercompiler_unescape($params)
} else {
$params[ 2 ] = "'{$params[ 2 ]}'";
}
switch (trim($params[ 1 ], '"\'')) {
case 'entity':
case 'htmlall':
if (Smarty::$_MBSTRING) {
return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 2 ] . ', \'HTML-ENTITIES\')';
}
return 'html_entity_decode(' . $params[ 0 ] . ', ENT_NOQUOTES, ' . $params[ 2 ] . ')';
case 'html':
return 'htmlspecialchars_decode(' . $params[ 0 ] . ', ENT_QUOTES)';
case 'url':
return 'rawurldecode(' . $params[ 0 ] . ')';
default:
return $params[ 0 ];
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty upper modifier plugin
* Type: modifier

@ -33,7 +33,7 @@ function smarty_modifiercompiler_wordwrap($params, Smarty_Internal_TemplateCompi
}
$function = 'wordwrap';
if (Smarty::$_MBSTRING) {
$function = $compiler->getPlugin('mb_wordwrap','modifier');
$function = $compiler->getPlugin('mb_wordwrap', 'modifier');
}
return $function . '(' . $params[ 0 ] . ',' . $params[ 1 ] . ',' . $params[ 2 ] . ',' . $params[ 3 ] . ')';
}

@ -5,85 +5,85 @@
* @package Smarty
* @subpackage PluginsFilter
*/
/**
* Smarty trimwhitespace outputfilter plugin
* Trim unnecessary whitespace from HTML markup.
*
* @author Rodney Rehm
* @author Rodney Rehm
*
* @param string $source input string
*
* @return string filtered output
* @todo substr_replace() is not overloaded by mbstring.func_overload - so this function might fail!
* @todo substr_replace() is not overloaded by mbstring.func_overload - so this function might fail!
*/
function smarty_outputfilter_trimwhitespace($source)
{
$store = array();
$_store = 0;
$_offset = 0;
// Unify Line-Breaks to \n
$source = preg_replace('/\015\012|\015|\012/', "\n", $source);
// capture Internet Explorer and KnockoutJS Conditional Comments
if (preg_match_all('#<!--((\[[^\]]+\]>.*?<!\[[^\]]+\])|(\s*/?ko\s+.+))-->#is', $source, $matches,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
if (preg_match_all(
'#<!--((\[[^\]]+\]>.*?<!\[[^\]]+\])|(\s*/?ko\s+.+))-->#is',
$source,
$matches,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER
)
) {
foreach ($matches as $match) {
$store[] = $match[ 0 ][ 0 ];
$_length = strlen($match[ 0 ][ 0 ]);
$replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
$source = substr_replace($source, $replace, $match[ 0 ][ 1 ] - $_offset, $_length);
$_offset += $_length - strlen($replace);
$_store ++;
$_store++;
}
}
// Strip all HTML-Comments
// yes, even the ones in <script> - see http://stackoverflow.com/a/808850/515124
$source = preg_replace('#<!--.*?-->#ms', '', $source);
// capture html elements not to be messed with
$_offset = 0;
if (preg_match_all('#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is',
$source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
if (preg_match_all(
'#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is',
$source,
$matches,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER
)
) {
foreach ($matches as $match) {
$store[] = $match[ 0 ][ 0 ];
$_length = strlen($match[ 0 ][ 0 ]);
$replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
$source = substr_replace($source, $replace, $match[ 0 ][ 1 ] - $_offset, $_length);
$_offset += $_length - strlen($replace);
$_store ++;
$_store++;
}
}
$expressions = array(// replace multiple spaces between tags by a single space
// can't remove them entirely, becaue that might break poorly implemented CSS display:inline-block elements
'#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2',
'#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2',
// remove spaces between attributes (but not in attribute values!)
'#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5',
// note: for some very weird reason trim() seems to remove spaces inside attributes.
// maybe a \0 byte or something is interfering?
'#^\s+<#Ss' => '<', '#>\s+$#Ss' => '>',);
'#^\s+<#Ss' => '<',
'#>\s+$#Ss' => '>',
);
$source = preg_replace(array_keys($expressions), array_values($expressions), $source);
// note: for some very weird reason trim() seems to remove spaces inside attributes.
// maybe a \0 byte or something is interfering?
// $source = trim( $source );
$_offset = 0;
if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
foreach ($matches as $match) {
$_length = strlen($match[ 0 ][ 0 ]);
$replace = $store[ $match[ 1 ][ 0 ] ];
$source = substr_replace($source, $replace, $match[ 0 ][ 1 ] + $_offset, $_length);
$_offset += strlen($replace) - $_length;
$_store ++;
$_store++;
}
}
return $source;
}

@ -5,16 +5,15 @@
* @package Smarty
* @subpackage PluginsShared
*/
/**
* escape_special_chars common function
* Function: smarty_function_escape_special_chars
* Purpose: used by other smarty functions to escape
* special chars except for already escaped ones
*
* @author Monte Ohrt <monte at ohrt dot com>
* @author Monte Ohrt <monte at ohrt dot com>
*
* @param string $string text that should by escaped
* @param string $string text that should by escaped
*
* @return string
*/
@ -29,6 +28,5 @@ function smarty_function_escape_special_chars($string)
$string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
}
}
return $string;
}

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsShared
*/
/**
* evaluate compiler parameter
*
@ -25,12 +24,12 @@ function smarty_literal_compiler_param($params, $index, $default = null)
}
// test if param is a literal
if (!preg_match('/^([\'"]?)[a-zA-Z0-9-]+(\\1)$/', $params[ $index ])) {
throw new SmartyException('$param[' . $index .
'] is not a literal and is thus not evaluatable at compile time');
throw new SmartyException(
'$param[' . $index .
'] is not a literal and is thus not evaluatable at compile time'
);
}
$t = null;
eval("\$t = " . $params[ $index ] . ";");
return $t;
}

@ -5,12 +5,11 @@
* @package Smarty
* @subpackage PluginsShared
*/
/**
* Function: smarty_make_timestamp
* Purpose: used by other smarty functions to make a timestamp from a string.
*
* @author Monte Ohrt <monte at ohrt dot com>
* @author Monte Ohrt <monte at ohrt dot com>
*
* @param DateTime|int|string $string date object, timestamp or string that can be converted using strtotime()
*
@ -21,25 +20,30 @@ function smarty_make_timestamp($string)
if (empty($string)) {
// use "now":
return time();
} elseif ($string instanceof DateTime ||
(interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)
} elseif ($string instanceof DateTime
|| (interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)
) {
return (int) $string->format('U'); // PHP 5.2 BC
return (int)$string->format('U'); // PHP 5.2 BC
} elseif (strlen($string) === 14 && ctype_digit($string)) {
// it is mysql timestamp format of YYYYMMDDHHMMSS?
return mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2), substr($string, 4, 2),
substr($string, 6, 2), substr($string, 0, 4));
return mktime(
substr($string, 8, 2),
substr($string, 10, 2),
substr($string, 12, 2),
substr($string, 4, 2),
substr($string, 6, 2),
substr($string, 0, 4)
);
} elseif (is_numeric($string)) {
// it is a numeric string, we handle it as timestamp
return (int) $string;
return (int)$string;
} else {
// strtotime should handle it
$time = strtotime($string);
if ($time === - 1 || $time === false) {
if ($time === -1 || $time === false) {
// strtotime() was not able to parse $string, use "now":
return time();
}
return $time;
}
}

@ -9,10 +9,10 @@ if (!function_exists('smarty_mb_str_replace')) {
/**
* Multibyte string replace
*
* @param string|string[] $search the string to be searched
* @param string|string[] $replace the replacement string
* @param string $subject the source string
* @param int &$count number of matches found
* @param string|string[] $search the string to be searched
* @param string|string[] $replace the replacement string
* @param string $subject the source string
* @param int &$count number of matches found
*
* @return string replaced string
* @author Rodney Rehm
@ -28,7 +28,7 @@ if (!function_exists('smarty_mb_str_replace')) {
$string = smarty_mb_str_replace($search, $replace, $string, $c);
$count += $c;
}
} else if (is_array($search)) {
} elseif (is_array($search)) {
if (!is_array($replace)) {
foreach ($search as &$string) {
$subject = smarty_mb_str_replace($string, $replace, $subject, $c);

@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsShared
*/
/**
* convert characters to their decimal unicode equivalents
*
@ -24,7 +23,6 @@ function smarty_mb_to_unicode($string, $encoding = null)
} else {
$expanded = mb_convert_encoding($string, 'UTF-32BE');
}
return unpack('N*', $expanded);
}
@ -45,10 +43,9 @@ function smarty_mb_from_unicode($unicode, $encoding = null)
if (!$encoding) {
$encoding = mb_internal_encoding();
}
foreach ((array) $unicode as $utf32be) {
foreach ((array)$unicode as $utf32be) {
$character = pack('N*', $utf32be);
$t .= mb_convert_encoding($character, $encoding, 'UTF-32BE');
}
return $t;
}

@ -25,12 +25,12 @@ abstract class Smarty_CacheResource
/**
* populate Cached Object with meta data from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param \Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
abstract public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template);
abstract public function populate(\Smarty_Template_Cached $cached, Smarty_Internal_Template $_template);
/**
* populate Cached Object with timestamp and exists from Resource
@ -50,8 +50,11 @@ abstract class Smarty_CacheResource
*
* @return boolean true or false if the cached content does not exist
*/
abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null,
$update = false);
abstract public function process(
Smarty_Internal_Template $_template,
Smarty_Template_Cached $cached = null,
$update = false
);
/**
* Write the rendered template output to cache
@ -66,11 +69,11 @@ abstract class Smarty_CacheResource
/**
* Read cached template from cache
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Internal_Template $_template template object
*
* @return string content
*/
abstract function readCachedContent(Smarty_Internal_Template $_template);
abstract public function readCachedContent(Smarty_Internal_Template $_template);
/**
* Return cached content
@ -87,7 +90,6 @@ abstract class Smarty_CacheResource
$unifunc($_template);
return ob_get_clean();
}
return null;
}
@ -133,7 +135,6 @@ abstract class Smarty_CacheResource
}
sleep(1);
}
return $hadLock;
}
@ -193,12 +194,10 @@ abstract class Smarty_CacheResource
if (!isset($type)) {
$type = $smarty->caching_type;
}
// try smarty's cache
if (isset($smarty->_cache[ 'cacheresource_handlers' ][ $type ])) {
return $smarty->_cache[ 'cacheresource_handlers' ][ $type ];
}
// try registered resource
if (isset($smarty->registered_cache_resources[ $type ])) {
// do not cache these instances as they may vary from instance to instance

@ -18,12 +18,12 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* fetch cached content and its modification time from data source
*
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $content cached content
* @param integer $mtime cache modification timestamp (epoch)
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $content cached content
* @param integer $mtime cache modification timestamp (epoch)
*
* @return void
*/
@ -34,10 +34,10 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
* {@internal implementing this method is optional.
* Only implement it if modification times can be accessed faster than loading the complete cached content.}}
*
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
*
* @return integer|boolean timestamp (epoch) the template was modified, or false if not found
*/
@ -49,12 +49,12 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* Save content to cache
*
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer|null $exp_time seconds till expiration or null
* @param string $content content to cache
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer|null $exp_time seconds till expiration or null
* @param string $content content to cache
*
* @return boolean success
*/
@ -63,10 +63,10 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* Delete content from cache
*
* @param string|null $name template name
* @param string|null $cache_id cache id
* @param string|null $compile_id compile id
* @param integer|null $exp_time seconds till expiration time in seconds or null
* @param string|null $name template name
* @param string|null $cache_id cache id
* @param string|null $compile_id compile id
* @param integer|null $exp_time seconds till expiration time in seconds or null
*
* @return integer number of deleted caches
*/
@ -75,8 +75,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* populate Cached Object with meta data from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
@ -106,12 +106,17 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
if ($mtime !== null) {
$cached->timestamp = $mtime;
$cached->exists = !!$cached->timestamp;
return;
}
$timestamp = null;
$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $cached->content,
$timestamp);
$this->fetch(
$cached->filepath,
$cached->source->name,
$cached->cache_id,
$cached->compile_id,
$cached->content,
$timestamp
);
$cached->timestamp = isset($timestamp) ? $timestamp : false;
$cached->exists = !!$cached->timestamp;
}
@ -120,50 +125,63 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
* Read the cached template and process the header
*
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Template_Cached $cached cached object
* @param boolean $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_smarty_tpl, Smarty_Template_Cached $cached = null,
$update = false)
{
public function process(
Smarty_Internal_Template $_smarty_tpl,
Smarty_Template_Cached $cached = null,
$update = false
) {
if (!$cached) {
$cached = $_smarty_tpl->cached;
}
$content = $cached->content ? $cached->content : null;
$timestamp = $cached->timestamp ? $cached->timestamp : null;
if ($content === null || !$timestamp) {
$this->fetch($_smarty_tpl->cached->filepath, $_smarty_tpl->source->name, $_smarty_tpl->cache_id,
$_smarty_tpl->compile_id, $content, $timestamp);
$this->fetch(
$_smarty_tpl->cached->filepath,
$_smarty_tpl->source->name,
$_smarty_tpl->cache_id,
$_smarty_tpl->compile_id,
$content,
$timestamp
);
}
if (isset($content)) {
eval('?>' . $content);
$cached->content = null;
return true;
}
return false;
}
/**
* Write the rendered template output to cache
*
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
*
* @return boolean success
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
return $this->save($_template->cached->filepath, $_template->source->name, $_template->cache_id,
$_template->compile_id, $_template->cache_lifetime, $content);
return $this->save(
$_template->cached->filepath,
$_template->source->name,
$_template->cache_id,
$_template->compile_id,
$_template->cache_lifetime,
$content
);
}
/**
* Read cached template from cache
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Internal_Template $_template template object
*
* @return string|boolean content
*/
@ -173,8 +191,14 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
$timestamp = null;
if ($content === null) {
$timestamp = null;
$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id,
$_template->compile_id, $content, $timestamp);
$this->fetch(
$_template->cached->filepath,
$_template->source->name,
$_template->cache_id,
$_template->compile_id,
$content,
$timestamp
);
}
if (isset($content)) {
return $content;
@ -185,8 +209,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* Empty cache
*
* @param Smarty $smarty Smarty object
* @param integer $exp_time expiration time (number of seconds, not timestamp)
* @param Smarty $smarty Smarty object
* @param integer $exp_time expiration time (number of seconds, not timestamp)
*
* @return integer number of cache files deleted
*/
@ -198,11 +222,11 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* Empty cache for a specific template
*
* @param Smarty $smarty Smarty object
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time (number of seconds, not timestamp)
* @param Smarty $smarty Smarty object
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time (number of seconds, not timestamp)
*
* @return int number of cache files deleted
* @throws \SmartyException
@ -210,7 +234,6 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{
$cache_name = null;
if (isset($resource_name)) {
$source = Smarty_Template_Source::load(null, $smarty, $resource_name);
if ($source->exists) {
@ -219,15 +242,14 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
return 0;
}
}
return $this->delete($cache_name, $cache_id, $compile_id, $exp_time);
}
/**
* Check is cache is locked for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*
* @return boolean true or false if cache is locked
*/
@ -235,7 +257,6 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
{
$id = $cached->lock_id;
$name = $cached->source->name . '.lock';
$mtime = $this->fetchTimestamp($id, $name, $cached->cache_id, $cached->compile_id);
if ($mtime === null) {
$this->fetch($id, $name, $cached->cache_id, $cached->compile_id, $content, $mtime);

@ -47,8 +47,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* populate Cached Object with meta data from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
@ -56,26 +56,32 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
{
$cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' .
$this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id);
$this->populateTimestamp($cached);
}
/**
* populate Cached Object with timestamp and exists from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Template_Cached $cached cached object
*
* @return void
*/
public function populateTimestamp(Smarty_Template_Cached $cached)
{
if (!$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $content,
$timestamp, $cached->source->uid)
if (!$this->fetch(
$cached->filepath,
$cached->source->name,
$cached->cache_id,
$cached->compile_id,
$content,
$timestamp,
$cached->source->uid
)
) {
return;
}
$cached->content = $content;
$cached->timestamp = (int) $timestamp;
$cached->timestamp = (int)$timestamp;
$cached->exists = !!$cached->timestamp;
}
@ -83,54 +89,60 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* Read the cached template and process the header
*
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Template_Cached $cached cached object
* @param boolean $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_smarty_tpl, Smarty_Template_Cached $cached = null,
$update = false)
{
public function process(
Smarty_Internal_Template $_smarty_tpl,
Smarty_Template_Cached $cached = null,
$update = false
) {
if (!$cached) {
$cached = $_smarty_tpl->cached;
}
$content = $cached->content ? $cached->content : null;
$timestamp = $cached->timestamp ? $cached->timestamp : null;
if ($content === null || !$timestamp) {
if (!$this->fetch($_smarty_tpl->cached->filepath, $_smarty_tpl->source->name, $_smarty_tpl->cache_id,
$_smarty_tpl->compile_id, $content, $timestamp, $_smarty_tpl->source->uid)
if (!$this->fetch(
$_smarty_tpl->cached->filepath,
$_smarty_tpl->source->name,
$_smarty_tpl->cache_id,
$_smarty_tpl->compile_id,
$content,
$timestamp,
$_smarty_tpl->source->uid
)
) {
return false;
}
}
if (isset($content)) {
eval('?>' . $content);
return true;
}
return false;
}
/**
* Write the rendered template output to cache
*
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
*
* @return boolean success
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
$this->addMetaTimestamp($content);
return $this->write(array($_template->cached->filepath => $content), $_template->cache_lifetime);
}
/**
* Read cached template from cache
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Internal_Template $_template template object
*
* @return string|false content
*/
@ -139,8 +151,15 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
$content = $_template->cached->content ? $_template->cached->content : null;
$timestamp = null;
if ($content === null) {
if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id,
$_template->compile_id, $content, $timestamp, $_template->source->uid)
if (!$this->fetch(
$_template->cached->filepath,
$_template->source->name,
$_template->cache_id,
$_template->compile_id,
$content,
$timestamp,
$_template->source->uid
)
) {
return false;
}
@ -155,36 +174,36 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* Empty cache
* {@internal the $exp_time argument is ignored altogether }}
*
* @param Smarty $smarty Smarty object
* @param integer $exp_time expiration time [being ignored]
* @param Smarty $smarty Smarty object
* @param integer $exp_time expiration time [being ignored]
*
* @return integer number of cache files deleted [always -1]
* @uses purge() to clear the whole store
* @uses invalidate() to mark everything outdated if purge() is inapplicable
* @uses purge() to clear the whole store
* @uses invalidate() to mark everything outdated if purge() is inapplicable
*/
public function clearAll(Smarty $smarty, $exp_time = null)
{
if (!$this->purge()) {
$this->invalidate(null);
}
return - 1;
return -1;
}
/**
* Empty cache for a specific template
* {@internal the $exp_time argument is ignored altogether}}
*
* @param Smarty $smarty Smarty object
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time [being ignored]
* @param Smarty $smarty Smarty object
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time [being ignored]
*
* @return int number of cache files deleted [always -1]
* @throws \SmartyException
* @uses buildCachedFilepath() to generate the CacheID
* @uses invalidate() to mark CacheIDs parent chain as outdated
* @uses delete() to remove CacheID from cache
* @uses buildCachedFilepath() to generate the CacheID
* @uses invalidate() to mark CacheIDs parent chain as outdated
* @uses delete() to remove CacheID from cache
*/
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{
@ -193,18 +212,17 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
$this->sanitize($compile_id);
$this->delete(array($cid));
$this->invalidate($cid, $resource_name, $cache_id, $compile_id, $uid);
return - 1;
return -1;
}
/**
* Get template's unique ID
*
* @param Smarty $smarty Smarty object
* @param string $resource_name template name
* @param Smarty $smarty Smarty object
* @param string $resource_name template name
*
* @return string filepath of cache file
* @throws \SmartyException
*
*/
protected function getTemplateUid(Smarty $smarty, $resource_name)
{
@ -220,7 +238,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Sanitize CacheID components
*
* @param string $string CacheID component to sanitize
* @param string $string CacheID component to sanitize
*
* @return string sanitized CacheID component
*/
@ -236,23 +254,28 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Fetch and prepare a cache object.
*
* @param string $cid CacheID to fetch
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $content cached content
* @param integer &$timestamp cached timestamp (epoch)
* @param string $resource_uid resource's uid
* @param string $cid CacheID to fetch
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $content cached content
* @param integer &$timestamp cached timestamp (epoch)
* @param string $resource_uid resource's uid
*
* @return boolean success
*/
protected function fetch($cid, $resource_name = null, $cache_id = null, $compile_id = null, &$content = null,
&$timestamp = null, $resource_uid = null)
{
protected function fetch(
$cid,
$resource_name = null,
$cache_id = null,
$compile_id = null,
&$content = null,
&$timestamp = null,
$resource_uid = null
) {
$t = $this->read(array($cid));
$content = !empty($t[ $cid ]) ? $t[ $cid ] : null;
$timestamp = null;
if ($content && ($timestamp = $this->getMetaTimestamp($content))) {
$invalidated =
$this->getLatestInvalidationTimestamp($cid, $resource_name, $cache_id, $compile_id, $resource_uid);
@ -261,7 +284,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
$content = null;
}
}
return !!$content;
}
@ -274,14 +296,14 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
protected function addMetaTimestamp(&$content)
{
$mt = explode(' ', microtime());
$ts = pack('NN', $mt[ 1 ], (int) ($mt[ 0 ] * 100000000));
$ts = pack('NN', $mt[ 1 ], (int)($mt[ 0 ] * 100000000));
$content = $ts . $content;
}
/**
* Extract the timestamp the $content was cached
*
* @param string &$content the cached content
* @param string &$content the cached content
*
* @return float the microtime the content was cached
*/
@ -298,17 +320,21 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Invalidate CacheID
*
* @param string $cid CacheID
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $resource_uid source's uid
* @param string $cid CacheID
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $resource_uid source's uid
*
* @return void
*/
protected function invalidate($cid = null, $resource_name = null, $cache_id = null, $compile_id = null,
$resource_uid = null)
{
protected function invalidate(
$cid = null,
$resource_name = null,
$cache_id = null,
$compile_id = null,
$resource_uid = null
) {
$now = microtime(true);
$key = null;
// invalidate everything
@ -339,17 +365,21 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Determine the latest timestamp known to the invalidation chain
*
* @param string $cid CacheID to determine latest invalidation timestamp of
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $resource_uid source's filepath
* @param string $cid CacheID to determine latest invalidation timestamp of
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $resource_uid source's filepath
*
* @return float the microtime the CacheID was invalidated
*/
protected function getLatestInvalidationTimestamp($cid, $resource_name = null, $cache_id = null, $compile_id = null,
$resource_uid = null)
{
protected function getLatestInvalidationTimestamp(
$cid,
$resource_name = null,
$cache_id = null,
$compile_id = null,
$resource_uid = null
) {
// abort if there is no CacheID
if (false && !$cid) {
return 0;
@ -358,14 +388,12 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
if (!($_cid = $this->listInvalidationKeys($cid, $resource_name, $cache_id, $compile_id, $resource_uid))) {
return 0;
}
// there are no InValidationKeys
if (!($values = $this->read($_cid))) {
return 0;
}
// make sure we're dealing with floats
$values = array_map('floatval', $values);
return max($values);
}
@ -373,18 +401,22 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* Translate a CacheID into the list of applicable InvalidationKeys.
* Splits 'some|chain|into|an|array' into array( '#clearAll#', 'some', 'some|chain', 'some|chain|into', ... )
*
* @param string $cid CacheID to translate
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $resource_uid source's filepath
* @param string $cid CacheID to translate
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $resource_uid source's filepath
*
* @return array list of InvalidationKeys
* @uses $invalidationKeyPrefix to prepend to each InvalidationKey
* @uses $invalidationKeyPrefix to prepend to each InvalidationKey
*/
protected function listInvalidationKeys($cid, $resource_name = null, $cache_id = null, $compile_id = null,
$resource_uid = null)
{
protected function listInvalidationKeys(
$cid,
$resource_name = null,
$cache_id = null,
$compile_id = null,
$resource_uid = null
) {
$t = array('IVK#ALL');
$_name = $_compile = '#';
if ($resource_name) {
@ -416,17 +448,16 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
$t[] = 'IVK#CACHE#' . $part;
$t[] = 'IVK#CID' . $_name . $part . $_compile;
// skip past delimiter position
$i ++;
$i++;
}
return $t;
}
/**
* Check is cache is locked for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*
* @return boolean true or false if cache is locked
*/
@ -434,7 +465,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
{
$key = 'LOCK#' . $cached->filepath;
$data = $this->read(array($key));
return $data && time() - $data[ $key ] < $smarty->locking_timeout;
}
@ -471,7 +501,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Read values for a set of keys from cache
*
* @param array $keys list of keys to fetch
* @param array $keys list of keys to fetch
*
* @return array list of values with the given keys used as indexes
*/
@ -480,8 +510,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Save values for a set of keys to cache
*
* @param array $keys list of values to save
* @param int $expire expiration time
* @param array $keys list of values to save
* @param int $expire expiration time
*
* @return boolean true on success, false on failure
*/
@ -490,7 +520,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Remove values from cache
*
* @param array $keys list of keys to delete
* @param array $keys list of keys to delete
*
* @return boolean true on success, false on failure
*/

@ -22,7 +22,7 @@ class Smarty_Data extends Smarty_Internal_Data
*
* @var int
*/
static $count = 0;
public static $count = 0;
/**
* Data block name
@ -50,7 +50,7 @@ class Smarty_Data extends Smarty_Internal_Data
public function __construct($_parent = null, $smarty = null, $name = null)
{
parent::__construct();
self::$count ++;
self::$count++;
$this->dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count);
$this->smarty = $smarty;
if (is_object($_parent)) {

@ -87,4 +87,4 @@ class Smarty_Internal_Block
public function callBlock(Smarty_Internal_Template $tpl)
{
}
}
}

@ -7,6 +7,7 @@
* @author Uwe Tews
* @author Rodney Rehm
*/
/**
* This class does contain all necessary methods for the HTML cache on file system
* Implements the file system as resource for the HTML cache Version ussing nocache inserts.
@ -32,11 +33,17 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
$_filepath = sha1($source->uid . $smarty->_joined_template_dir);
$cached->filepath = $smarty->getCacheDir();
if (isset($_template->cache_id)) {
$cached->filepath .= preg_replace(array('![^\w|]+!',
'![|]+!'),
array('_',
$_compile_dir_sep),
$_template->cache_id) . $_compile_dir_sep;
$cached->filepath .= preg_replace(
array(
'![^\w|]+!',
'![|]+!'
),
array(
'_',
$_compile_dir_sep
),
$_template->cache_id
) . $_compile_dir_sep;
}
if (isset($_template->compile_id)) {
$cached->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) . $_compile_dir_sep;
@ -87,10 +94,11 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
*
* @return boolean true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_smarty_tpl,
Smarty_Template_Cached $cached = null,
$update = false)
{
public function process(
Smarty_Internal_Template $_smarty_tpl,
Smarty_Template_Cached $cached = null,
$update = false
) {
$_smarty_tpl->cached->valid = false;
if ($update && defined('HHVM_VERSION')) {
eval('?>' . file_get_contents($_smarty_tpl->cached->filepath));
@ -111,15 +119,17 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath,
$content,
$_template->smarty) === true
if ($_template->smarty->ext->_writeFile->writeFile(
$_template->cached->filepath,
$content,
$_template->smarty
) === true
) {
if (function_exists('opcache_invalidate') &&
(!function_exists('ini_get') || strlen(ini_get('opcache.restrict_api'))) < 1
if (function_exists('opcache_invalidate')
&& (!function_exists('ini_get') || strlen(ini_get('opcache.restrict_api'))) < 1
) {
opcache_invalidate($_template->cached->filepath, true);
} else if (function_exists('apc_compile_file')) {
} elseif (function_exists('apc_compile_file')) {
apc_compile_file($_template->cached->filepath);
}
$cached = $_template->cached;
@ -135,7 +145,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
/**
* Read cached template from cache
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Internal_Template $_template template object
*
* @return string content
*/

@ -19,9 +19,9 @@ class Smarty_Internal_Compile_Append extends Smarty_Internal_Compile_Assign
/**
* Compiles code for the {append} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException

@ -24,21 +24,23 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
*/
public $option_flags = array('nocache', 'noscope');
/**
/**
* Valid scope names
*
* @var array
*/
public $valid_scopes = array('local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
'root' => Smarty::SCOPE_ROOT, 'global' => Smarty::SCOPE_GLOBAL,
'tpl_root' => Smarty::SCOPE_TPL_ROOT, 'smarty' => Smarty::SCOPE_SMARTY);
public $valid_scopes = array(
'local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
'root' => Smarty::SCOPE_ROOT, 'global' => Smarty::SCOPE_GLOBAL,
'tpl_root' => Smarty::SCOPE_TPL_ROOT, 'smarty' => Smarty::SCOPE_SMARTY
);
/**
* Compiles code for the {assign} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
@ -66,7 +68,7 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
}
// scope setup
if ($_attr[ 'noscope' ]) {
$_scope = - 1;
$_scope = -1;
} else {
$_scope = $compiler->convertScope($_attr, $this->valid_scopes);
}
@ -81,7 +83,7 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
if (isset($parameter[ 'smarty_internal_index' ])) {
$output =
"<?php \$_tmp_array = isset(\$_smarty_tpl->tpl_vars[{$_var}]) ? \$_smarty_tpl->tpl_vars[{$_var}]->value : array();\n";
$output .= "if (!is_array(\$_tmp_array) || \$_tmp_array instanceof ArrayAccess) {\n";
$output .= "if (!(is_array(\$_tmp_array) || \$_tmp_array instanceof ArrayAccess)) {\n";
$output .= "settype(\$_tmp_array, 'array');\n";
$output .= "}\n";
$output .= "\$_tmp_array{$parameter['smarty_internal_index']} = {$_attr['value']};\n";

@ -1,5 +1,5 @@
<?php
/*
/**
* This file is part of Smarty.
*
* (c) 2015 Uwe Tews
@ -22,6 +22,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('name');
/**
* Attribute definition: Overwrites base class.
*
@ -29,6 +30,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('name');
/**
* Attribute definition: Overwrites base class.
*
@ -36,6 +38,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
* @see Smarty_Internal_CompileBase
*/
public $option_flags = array('hide', 'nocache');
/**
* Attribute definition: Overwrites base class.
*
@ -47,10 +50,9 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
/**
* Compiles code for the {block} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
@ -67,16 +69,20 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
++$compiler->_cache[ 'blockNesting' ];
$_className = 'Block_' . preg_replace('![^\w]+!', '_', uniqid(rand(), true));
$_className = 'Block_' . preg_replace('![^\w]+!', '_', uniqid(mt_rand(), true));
$compiler->_cache[ 'blockName' ][ $compiler->_cache[ 'blockNesting' ] ] = $_attr[ 'name' ];
$compiler->_cache[ 'blockClass' ][ $compiler->_cache[ 'blockNesting' ] ] = $_className;
$compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ] = array();
$compiler->_cache[ 'blockParams' ][ 1 ][ 'subBlocks' ][ trim($_attr[ 'name' ], '"\'') ][] = $_className;
$this->openTag($compiler,
'block',
array($_attr, $compiler->nocache, $compiler->parser->current_buffer,
$compiler->template->compiled->has_nocache_code,
$compiler->template->caching));
$this->openTag(
$compiler,
'block',
array(
$_attr, $compiler->nocache, $compiler->parser->current_buffer,
$compiler->template->compiled->has_nocache_code,
$compiler->template->caching
)
);
$compiler->saveRequiredPlugins(true);
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
@ -84,18 +90,18 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
$compiler->suppressNocacheProcessing = true;
}
}
/**
* Smarty Internal Plugin Compile BlockClose Class
*
*/
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_Inheritance
{
/**
* Compiles code for the {/block} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $parameter array with compilation parameter
*
* @return bool true
*/
@ -118,13 +124,12 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$_functionCode = $compiler->parser->current_buffer;
// setup buffer for template function code
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$output = "<?php\n";
$output .= "/* {block {$_name}} */\n";
$output .= "class {$_className} extends Smarty_Internal_Block\n";
$output .= "{\n";
foreach ($_block as $property => $value) {
$output .= "public \${$property} = " . var_export($value,true) .";\n";
$output .= "public \${$property} = " . var_export($value, true) . ";\n";
}
$output .= "public function callBlock(Smarty_Internal_Template \$_smarty_tpl) {\n";
$output .= $compiler->compileRequiredPlugins();
@ -136,9 +141,13 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$output .= "ob_start();\n";
}
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php\n";
if (isset($_assign)) {
@ -148,9 +157,13 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$output .= "}\n";
$output .= "/* {/block {$_name}} */\n\n";
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
// restore old status

@ -1,5 +1,5 @@
<?php
/*
/**
* This file is part of Smarty.
*
* (c) 2015 Uwe Tews
@ -21,4 +21,4 @@ class Smarty_Internal_Compile_Block_Child extends Smarty_Internal_Compile_Child
* @var string
*/
public $tag = 'block_child';
}
}

@ -1,5 +1,5 @@
<?php
/*
/**
* This file is part of Smarty.
*
* (c) 2015 Uwe Tews
@ -28,4 +28,4 @@ class Smarty_Internal_Compile_Block_Parent extends Smarty_Internal_Compile_Child
* @var string
*/
public $blockType = 'Parent';
}
}

@ -33,16 +33,16 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
public $shorttag_order = array('levels');
/**
* Tag name may be overloaded by Smarty_Internal_Compile_Continue
*
* @var string
*/
* Tag name may be overloaded by Smarty_Internal_Compile_Continue
*
* @var string
*/
public $tag = 'break';
/**
* Compiles code for the {break} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
@ -67,7 +67,7 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
/**
* check attributes and return array of break and foreach levels
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return array
@ -78,11 +78,9 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
if (isset($_attr[ 'levels' ])) {
if (!is_numeric($_attr[ 'levels' ])) {
$compiler->trigger_template_error('level attribute must be a numeric constant', null, true);
@ -101,18 +99,18 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
if ($level_count === 0) {
break;
}
$level_count --;
$level_count--;
if ($compiler->_tag_stack[ $stack_count ][ 0 ] === 'foreach') {
$foreachLevels ++;
$foreachLevels++;
}
}
$stack_count --;
$stack_count--;
}
if ($level_count !== 0) {
$compiler->trigger_template_error("cannot {$this->tag} {$levels} level(s)", null, true);
}
if ($lastTag === 'foreach' && $this->tag === 'break' && $foreachLevels > 0) {
$foreachLevels --;
$foreachLevels--;
}
return array($levels, $foreachLevels);
}

@ -43,8 +43,8 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
/**
* Compiles the calls of user defined tags defined by {function}
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/

@ -35,29 +35,27 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
/**
* Compiles code for the {$smarty.capture.xxx}
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase$compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null)
{
$tag = trim($parameter[ 0 ], '"\'');
$name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : null;
if (!$name) {
//$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
}
return '$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl'.(isset($name)?", '{$name}')":')');
public static function compileSpecialVariable(
$args,
Smarty_Internal_TemplateCompilerBase $compiler,
$parameter = null
) {
return '$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl' .
(isset($parameter[ 1 ]) ? ", {$parameter[ 1 ]})" : ')');
}
/**
* Compiles code for the {capture} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param null $parameter
* @param null $parameter
*
* @return string compiled code
*/
@ -65,16 +63,13 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args, $parameter, 'capture');
$buffer = isset($_attr[ 'name' ]) ? $_attr[ 'name' ] : "'default'";
$assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : 'null';
$append = isset($_attr[ 'append' ]) ? $_attr[ 'append' ] : 'null';
$compiler->_cache[ 'capture_stack' ][] = array($compiler->nocache);
// maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$_output = "<?php \$_smarty_tpl->smarty->ext->_capture->open(\$_smarty_tpl, $buffer, $assign, $append);?>";
return $_output;
}
}
@ -90,9 +85,9 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/capture} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param null $parameter
* @param null $parameter
*
* @return string compiled code
*/
@ -104,9 +99,7 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
if ($compiler->nocache) {
$compiler->tag_nocache = true;
}
list($compiler->nocache) = array_pop($compiler->_cache[ 'capture_stack' ]);
return "<?php \$_smarty_tpl->smarty->ext->_capture->close(\$_smarty_tpl);?>";
}
}

@ -1,5 +1,5 @@
<?php
/*
/**
* This file is part of Smarty.
*
* (c) 2015 Uwe Tews
@ -40,9 +40,9 @@ class Smarty_Internal_Compile_Child extends Smarty_Internal_CompileBase
/**
* Compiles code for the {child} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
@ -51,10 +51,12 @@ class Smarty_Internal_Compile_Child extends Smarty_Internal_CompileBase
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$tag = isset($parameter[0]) ? "'{$parameter[0]}'" : "'{{$this->tag}}'";
$tag = isset($parameter[ 0 ]) ? "'{$parameter[0]}'" : "'{{$this->tag}}'";
if (!isset($compiler->_cache[ 'blockNesting' ])) {
$compiler->trigger_template_error("{$tag} used outside {block} tags ",
$compiler->parser->lex->taglineno);
$compiler->trigger_template_error(
"{$tag} used outside {block} tags ",
$compiler->parser->lex->taglineno
);
}
$compiler->has_code = true;
$compiler->suppressNocacheProcessing = true;
@ -67,11 +69,11 @@ class Smarty_Internal_Compile_Child extends Smarty_Internal_CompileBase
$output .= "ob_start();\n";
}
$output .= '$_smarty_tpl->inheritance->call' . $this->blockType . '($_smarty_tpl, $this' .
($this->blockType === 'Child' ? '' : ", {$tag}"). ");\n";
($this->blockType === 'Child' ? '' : ", {$tag}") . ");\n";
if (isset($_assign)) {
$output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
}
$output .="?>\n";
$output .= "?>\n";
return $output;
}
}
}

@ -53,14 +53,16 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
*
* @var array
*/
public $valid_scopes = array('local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
'root' => Smarty::SCOPE_ROOT, 'tpl_root' => Smarty::SCOPE_TPL_ROOT,
'smarty' => Smarty::SCOPE_SMARTY, 'global' => Smarty::SCOPE_SMARTY);
public $valid_scopes = array(
'local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
'root' => Smarty::SCOPE_ROOT, 'tpl_root' => Smarty::SCOPE_TPL_ROOT,
'smarty' => Smarty::SCOPE_SMARTY, 'global' => Smarty::SCOPE_SMARTY
);
/**
* Compiles code for the {config_load} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
@ -70,11 +72,9 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
// save possible attributes
$conf_file = $_attr[ 'file' ];
if (isset($_attr[ 'section' ])) {
@ -84,15 +84,13 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
}
// scope setup
if ($_attr[ 'noscope' ]) {
$_scope = - 1;
$_scope = -1;
} else {
$_scope = $compiler->convertScope($_attr, $this->valid_scopes);
}
// create config object
$_output =
"<?php\n\$_smarty_tpl->smarty->ext->configLoad->_loadConfigFile(\$_smarty_tpl, {$conf_file}, {$section}, {$_scope});\n?>\n";
return $_output;
}
}

@ -17,9 +17,9 @@
class Smarty_Internal_Compile_Continue extends Smarty_Internal_Compile_Break
{
/**
* Tag name
*
* @var string
*/
* Tag name
*
* @var string
*/
public $tag = 'continue';
}

@ -20,8 +20,8 @@ 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
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
@ -29,10 +29,8 @@ class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// compile always as nocache
$compiler->tag_nocache = true;
// display debug template
$_output =
"<?php \$_smarty_debug = new Smarty_Internal_Debug;\n \$_smarty_debug->display_debug(\$_smarty_tpl);\n";

@ -43,8 +43,8 @@ class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
/**
* Compiles code for the {eval} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
@ -56,16 +56,15 @@ class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
// output will be stored in a smarty variable instead of being displayed
$_assign = $_attr[ 'assign' ];
}
// create template object
$_output = "\$_template = new {$compiler->smarty->template_class}('eval:'.{$_attr[ 'var' ]}, \$_smarty_tpl->smarty, \$_smarty_tpl);";
$_output =
"\$_template = new {$compiler->smarty->template_class}('eval:'.{$_attr[ 'var' ]}, \$_smarty_tpl->smarty, \$_smarty_tpl);";
//was there an assign attribute?
if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());";
} else {
$_output .= 'echo $_template->fetch();';
}
return "<?php $_output ?>";
}
}

@ -1,5 +1,4 @@
<?php
/**
* Smarty Internal Plugin Compile extend
* Compiles the {extends} tag
@ -74,7 +73,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
} else {
$file = "'{$file}'";
}
$i ++;
$i++;
if ($i === count($files) && isset($_attr[ 'extends_resource' ])) {
$this->compileEndChild($compiler);
}
@ -108,28 +107,36 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
$inlineUids = $match[ 1 ];
}
}
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser,
'<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl' .
(isset($template) ?
", {$template}{$inlineUids}" :
'') . ");\n?>");
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
'<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl' .
(isset($template) ?
", {$template}{$inlineUids}" :
'') . ");\n?>"
);
}
/**
* Add code for including subtemplate to end of template
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
* @param string $template subtemplate name
* @param string $template subtemplate name
*
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
private function compileInclude(Smarty_Internal_TemplateCompilerBase $compiler, $template)
{
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser,
$compiler->compileTag('include',
array($template,
array('scope' => 'parent'))));
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$compiler->compileTag(
'include',
array(
$template,
array('scope' => 'parent')
)
)
);
}
/**

@ -26,15 +26,15 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
* The parser is generating different sets of attribute by which this compiler can
* determine which syntax is used.
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
{
$compiler->loopNesting ++;
$compiler->loopNesting++;
if ($parameter === 0) {
$this->required_attributes = array('start', 'to');
$this->optional_attributes = array('max', 'step');
@ -45,7 +45,6 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
$this->mapCache = array();
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$output = "<?php\n";
if ($parameter === 1) {
foreach ($_attr[ 'start' ] as $_statement) {
@ -93,7 +92,6 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
$output .= "\$_smarty_tpl->tpl_vars[$var]->last = \$_smarty_tpl->tpl_vars[$var]->iteration === \$_smarty_tpl->tpl_vars[$var]->total;";
}
$output .= '?>';
$this->openTag($compiler, 'for', array('for', $compiler->nocache));
// maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
@ -113,9 +111,9 @@ 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
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
@ -123,10 +121,8 @@ class Smarty_Internal_Compile_Forelse extends Smarty_Internal_CompileBase
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
list($openTag, $nocache) = $this->closeTag($compiler, array('for'));
$this->openTag($compiler, 'forelse', array('forelse', $nocache));
return "<?php }} else { ?>";
}
}
@ -142,24 +138,22 @@ 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
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
{
$compiler->loopNesting --;
$compiler->loopNesting--;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// must endblock be nocache?
if ($compiler->nocache) {
$compiler->tag_nocache = true;
}
list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('for', 'forelse'));
$output = "<?php }\n";
if ($openTag !== 'forelse') {
$output .= "}\n";

@ -78,7 +78,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
/**
* Compiles code for the {foreach} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
@ -87,7 +87,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$compiler->loopNesting ++;
$compiler->loopNesting++;
// init
$this->isNamed = false;
// check and get attributes
@ -119,14 +119,16 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
if ($fromName) {
foreach (array('item', 'key') as $a) {
if (isset($attributes[ $a ]) && $attributes[ $a ] === $fromName) {
$compiler->trigger_template_error("'{$a}' and 'from' may not have same variable name '{$fromName}'",
null, true);
$compiler->trigger_template_error(
"'{$a}' and 'from' may not have same variable name '{$fromName}'",
null,
true
);
}
}
}
$itemVar = "\$_smarty_tpl->tpl_vars['{$item}']";
$local = '$__foreach_' . $attributes[ 'item' ] . '_' . $this->counter ++ . '_';
$local = '$__foreach_' . $attributes[ 'item' ] . '_' . $this->counter++ . '_';
// search for used tag attributes
$itemAttr = array();
$namedAttr = array();
@ -187,8 +189,11 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
}
$needTotal = isset($itemAttr[ 'total' ]);
// Register tag
$this->openTag($compiler, 'foreach',
array('foreach', $compiler->nocache, $local, $itemVar, empty($itemAttr) ? 1 : 2));
$this->openTag(
$compiler,
'foreach',
array('foreach', $compiler->nocache, $local, $itemVar, empty($itemAttr) ? 1 : 2)
);
// maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
// generate output code
@ -214,8 +219,9 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
if (isset($itemAttr[ 'index' ])) {
$output .= "{$itemVar}->index = -1;\n";
}
$output .= "if (\$_from !== null) {\n";
$output .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n";
$output .= "{$itemVar}->do_else = true;\n";
$output .= "if (\$_from !== null) foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n";
$output .= "{$itemVar}->do_else = false;\n";
if (isset($attributes[ 'key' ]) && isset($itemAttr[ 'key' ])) {
$output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n";
}
@ -249,7 +255,6 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
$output .= "{$local}saved = {$itemVar};\n";
}
$output .= '?>';
return $output;
}
@ -277,7 +282,7 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
/**
* Compiles code for the {foreachelse} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
@ -286,14 +291,13 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
list($openTag, $nocache, $local, $itemVar, $restore) = $this->closeTag($compiler, array('foreach'));
$this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $local, $itemVar, 0));
$output = "<?php\n";
if ($restore === 2) {
$output .= "{$itemVar} = {$local}saved;\n";
}
$output .= "}\n} else {\n?>";
$output .= "}\nif ({$itemVar}->do_else) {\n?>";
return $output;
}
}
@ -309,30 +313,26 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/foreach} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$compiler->loopNesting --;
$compiler->loopNesting--;
// must endblock be nocache?
if ($compiler->nocache) {
$compiler->tag_nocache = true;
}
list($openTag, $compiler->nocache, $local, $itemVar, $restore) =
$this->closeTag($compiler, array('foreach', 'foreachelse'));
list(
$openTag, $compiler->nocache, $local, $itemVar, $restore
) = $this->closeTag($compiler, array('foreach', 'foreachelse'));
$output = "<?php\n";
if ($restore === 2) {
$output .= "{$itemVar} = {$local}saved;\n";
}
if ($restore > 0) {
$output .= "}\n";
}
$output .= "}\n";
/* @var Smarty_Internal_Compile_Foreach $foreachCompiler */
$foreachCompiler = $compiler->getTagCompiler('foreach');

@ -16,7 +16,6 @@
*/
class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
{
/**
* Attribute definition: Overwrites base class.
*
@ -44,7 +43,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
/**
* Compiles code for the {function} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return bool true
@ -54,15 +53,16 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
unset($_attr[ 'nocache' ]);
$_name = trim($_attr[ 'name' ], '\'"');
$compiler->parent_compiler->tpl_function[ $_name ] = array();
$save = array($_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
$compiler->template->caching);
$save = array(
$_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
$compiler->template->caching
);
$this->openTag($compiler, 'function', $save);
// Init temporary context
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
@ -80,7 +80,6 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
*/
class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
{
/**
* Compiler object
*
@ -91,7 +90,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/function} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param object|\Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return bool true
@ -125,7 +124,6 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$_functionCode = $compiler->parser->current_buffer;
// setup buffer for template function code
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->compiled->nocache_hash}";
$_funcNameCaching = $_funcName . '_nocache';
if ($compiler->template->compiled->has_nocache_code) {
@ -143,9 +141,13 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->saveTemplateVariables(\\\$_smarty_tpl, '{$_name}');\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value, \\\$_smarty_tpl->isRenderingCache);\n}\n?>";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";?>";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n";
@ -154,13 +156,21 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "}\n}\n";
$output .= "/*/ {$_funcName}_nocache */\n\n";
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser,
preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
array($this, 'removeNocache'),
$_functionCode->to_smarty_php($compiler->parser)));
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$_functionCode = new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
preg_replace_callback(
"/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
array($this, 'removeNocache'),
$_functionCode->to_smarty_php($compiler->parser)
)
);
}
$compiler->parent_compiler->tpl_function[ $_name ][ 'call_name' ] = $_funcName;
$output = "<?php\n";
@ -169,20 +179,29 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "function {$_funcName}(Smarty_Internal_Template \$_smarty_tpl,\$params) {\n";
$output .= $_paramsCode;
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value, \$_smarty_tpl->isRenderingCache);\n}\n";
$output .= $compiler->compileCheckPlugins(array_merge($compiler->required_plugins[ 'compiled' ], $compiler->required_plugins[ 'nocache' ]));
$output .= $compiler->compileCheckPlugins(array_merge($compiler->required_plugins[ 'compiled' ],
$compiler->required_plugins[ 'nocache' ]));
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php\n}}\n";
$output .= "/*/ {$_funcName} */\n\n";
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$compiler->parent_compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
// restore old buffer
// restore old buffer
$compiler->parser->current_buffer = $saved_data[ 1 ];
// restore old status
$compiler->restoreRequiredPlugins();
@ -198,11 +217,14 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
*
* @return string
*/
function removeNocache($match)
public function removeNocache($match)
{
$code =
preg_replace("/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
'', $match[ 0 ]);
preg_replace(
"/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
'',
$match[ 0 ]
);
$code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code);
return $code;
}

@ -33,11 +33,9 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
$this->openTag($compiler, 'if', array(1, $compiler->nocache));
// must whole block be nocache ?
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
if (!isset($parameter['if condition'])) {
if (!isset($parameter[ 'if condition' ])) {
$compiler->trigger_template_error('missing if condition', null, true);
}
if (is_array($parameter[ 'if condition' ])) {
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
@ -55,8 +53,11 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
$assignCompiler = new Smarty_Internal_Compile_Assign();
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
$_output .= $assignCompiler->compile($assignAttr, $compiler,
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]));
$_output .= $assignCompiler->compile(
$assignAttr,
$compiler,
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])
);
} else {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
$_output .= $assignCompiler->compile($assignAttr, $compiler, array());
@ -84,12 +85,11 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
*/
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
$this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache));
return '<?php } else { ?>';
}
}
@ -116,13 +116,10 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
if (!isset($parameter['if condition'])) {
if (!isset($parameter[ 'if condition' ])) {
$compiler->trigger_template_error('missing elseif condition', null, true);
}
$assignCode = '';
$var = '';
if (is_array($parameter[ 'if condition' ])) {
@ -143,8 +140,11 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
$assignAttr[][ 'value' ] = $prefixVar;
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
$assignCode .= $assignCompiler->compile($assignAttr, $compiler,
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]));
$assignCode .= $assignCompiler->compile(
$assignAttr,
$compiler,
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])
);
} else {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
$assignCode .= $assignCompiler->compile($assignAttr, $compiler, array());
@ -152,7 +152,6 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
} else {
$condition_by_assign = false;
}
$prefixCode = $compiler->getPrefixCode();
if (empty($prefixCode)) {
if ($condition_by_assign) {
@ -200,10 +199,9 @@ class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase
}
list($nesting, $compiler->nocache) = $this->closeTag($compiler, array('if', 'else', 'elseif'));
$tmp = '';
for ($i = 0; $i < $nesting; $i ++) {
for ($i = 0; $i < $nesting; $i++) {
$tmp .= '}';
}
return "<?php {$tmp}?>";
}
}

@ -7,6 +7,7 @@
* @subpackage Compiler
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Include Class
*
@ -19,6 +20,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* caching mode to create nocache code but no cache file
*/
const CACHING_NOCACHE_CODE = 9999;
/**
* Attribute definition: Overwrites base class.
*
@ -26,6 +28,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('file');
/**
* Attribute definition: Overwrites base class.
*
@ -33,6 +36,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('file');
/**
* Attribute definition: Overwrites base class.
*
@ -40,6 +44,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $option_flags = array('nocache', 'inline', 'caching');
/**
* Attribute definition: Overwrites base class.
*
@ -47,20 +52,23 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('_any');
/**
* Valid scope names
*
* @var array
*/
public $valid_scopes = array('parent' => Smarty::SCOPE_PARENT, 'root' => Smarty::SCOPE_ROOT,
'global' => Smarty::SCOPE_GLOBAL, 'tpl_root' => Smarty::SCOPE_TPL_ROOT,
'smarty' => Smarty::SCOPE_SMARTY);
public $valid_scopes = array(
'parent' => Smarty::SCOPE_PARENT, 'root' => Smarty::SCOPE_ROOT,
'global' => Smarty::SCOPE_GLOBAL, 'tpl_root' => Smarty::SCOPE_TPL_ROOT,
'smarty' => Smarty::SCOPE_SMARTY
);
/**
* Compiles code for the {include} tag
*
* @param array $args array with attributes from parser
* @param Smarty_Internal_SmartyTemplateCompiler $compiler compiler object
* @param array $args array with attributes from parser
* @param Smarty_Internal_SmartyTemplateCompiler $compiler compiler object
*
* @return string
* @throws \Exception
@ -193,9 +201,14 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching'));
$compiler->smarty->allow_ambiguous_resources = true;
/* @var Smarty_Internal_Template $tpl */
$tpl = new $compiler->smarty->template_class (trim($fullResourceName, '"\''), $compiler->smarty,
$compiler->template, $compiler->template->cache_id, $c_id,
$_caching);
$tpl = new $compiler->smarty->template_class(
trim($fullResourceName, '"\''),
$compiler->smarty,
$compiler->template,
$compiler->template->cache_id,
$c_id,
$_caching
);
$uid = $tpl->source->type . $tpl->source->uid;
if (!isset($compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ])) {
$has_compiled_template = $this->compileInlineTemplate($compiler, $tpl, $t_hash);
@ -269,16 +282,17 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
*
* @param \Smarty_Internal_SmartyTemplateCompiler $compiler
* @param \Smarty_Internal_Template $tpl
* @param string $t_hash
* @param string $t_hash
*
* @return bool
* @throws \Exception
* @throws \SmartyException
*/
public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $compiler,
Smarty_Internal_Template $tpl,
$t_hash)
{
public function compileInlineTemplate(
Smarty_Internal_SmartyTemplateCompiler $compiler,
Smarty_Internal_Template $tpl,
$t_hash
) {
$uid = $tpl->source->type . $tpl->source->uid;
if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) {
$compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ][ 'uid' ] = $tpl->source->uid;
@ -317,9 +331,11 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
if ($tpl->compiled->has_nocache_code) {
// replace nocache_hash
$compiled_code =
str_replace("{$tpl->compiled->nocache_hash}",
$compiler->template->compiled->nocache_hash,
$compiled_code);
str_replace(
"{$tpl->compiled->nocache_hash}",
$compiler->template->compiled->nocache_hash,
$compiled_code
);
$compiler->template->compiled->has_nocache_code = true;
}
$compiler->parent_compiler->mergedSubTemplatesCode[ $tpl->compiled->unifunc ] = $compiled_code;

@ -7,6 +7,7 @@
* @subpackage Compiler
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Insert Class
*
@ -42,7 +43,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
/**
* Compiles code for the {include_php} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string
@ -56,7 +57,10 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
}
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
/** @var Smarty_Internal_Template $_smarty_tpl
/**
*
*
* @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_smarty_tpl = $compiler->template;

@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('name');
/**
* Attribute definition: Overwrites base class.
*
@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('name');
/**
* Attribute definition: Overwrites base class.
*
@ -41,7 +43,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
/**
* Compiles code for the {insert} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
@ -104,11 +106,13 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
}
// code for script file loading
$_output .= "require_once '{$_filepath}' ;";
require_once $_filepath;
include_once $_filepath;
if (!is_callable($_function)) {
$compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'",
null,
true);
$compiler->trigger_template_error(
" {insert} function '{$_function}' is not callable in script file '{$_script}'",
null,
true
);
}
} else {
$_filepath = 'null';
@ -117,9 +121,11 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
if (!is_callable($_function)) {
// try plugin
if (!$_function = $compiler->getPlugin($_name, 'insert')) {
$compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'",
null,
true);
$compiler->trigger_template_error(
"{insert} no function or plugin found for '{$_name}'",
null,
true
);
}
}
}
@ -145,6 +151,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
$_output .= "echo {$_function}({$_params},\$_smarty_tpl);?>";
}
}
$compiler->template->compiled->has_nocache_code = true;
return $_output;
}
}

@ -16,11 +16,11 @@
*/
class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase
{
/**
/**
* Compiles code for the {ldelim} tag
* This tag does output the left delimiter
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code

@ -41,11 +41,11 @@ class Smarty_Internal_Compile_Make_Nocache extends Smarty_Internal_CompileBase
/**
* Compiles code for the {make_nocache} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
*/
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// check and get attributes

@ -27,7 +27,7 @@ class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase
* Compiles code for the {nocache} tag
* This tag does not generate compiled output. It only sets a compiler flag.
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return bool
@ -40,7 +40,6 @@ class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase
$compiler->nocache = true;
// this tag does not return compiled code
$compiler->has_code = false;
return true;
}
}
@ -57,7 +56,7 @@ class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase
* Compiles code for the {/nocache} tag
* This tag does not generate compiled output. It only sets a compiler flag.
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return bool
@ -69,7 +68,6 @@ class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase
list($compiler->nocache) = $this->closeTag($compiler, array('nocache'));
// this tag does not return compiled code
$compiler->has_code = false;
return true;
}
}

@ -1,5 +1,5 @@
<?php
/*
/**
* This file is part of Smarty.
*
* (c) 2015 Uwe Tews
@ -15,7 +15,6 @@
*/
class Smarty_Internal_Compile_Parent extends Smarty_Internal_Compile_Child
{
/**
* Tag name
*
@ -29,4 +28,4 @@ class Smarty_Internal_Compile_Parent extends Smarty_Internal_Compile_Child
* @var string
*/
public $blockType = 'Parent';
}
}

@ -34,11 +34,11 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
/**
* Compiles code for the execution of block plugin
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of block plugin
* @param string $function PHP function name
* @param array $parameter array with compilation parameter
* @param string $tag name of block plugin
* @param string $function PHP function name
*
* @return string compiled code
* @throws \SmartyCompilerException
@ -46,15 +46,14 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function = null)
{
if (!isset($tag[ 5 ]) || substr($tag, - 5) !== 'close') {
if (!isset($tag[ 5 ]) || substr($tag, -5) !== 'close') {
// opening tag of block plugin
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$this->nesting ++;
$this->nesting++;
unset($_attr[ 'nocache' ]);
list($callback, $_paramsArray, $callable) = $this->setup($compiler, $_attr, $tag, $function);
$_params = 'array(' . implode(',', $_paramsArray) . ')';
// compile code
$output = "<?php ";
if (is_array($callback)) {
@ -75,7 +74,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
$compiler->tag_nocache = true;
}
// closing tag of block plugin, restore nocache
list($_params, $compiler->nocache, $callback) = $this->closeTag($compiler, substr($tag, 0, - 5));
list($_params, $compiler->nocache, $callback) = $this->closeTag($compiler, substr($tag, 0, -5));
// compile code
if (!isset($parameter[ 'modifier_list' ])) {
$mod_pre = $mod_post = $mod_content = '';
@ -84,11 +83,17 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
$mod_content2 = "\$_block_content{$this->nesting}";
$mod_content = "\$_block_content{$this->nesting} = ob_get_clean();\n";
$mod_pre = "ob_start();\n";
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifier_list' ],
'value' => 'ob_get_clean()')) . ";\n";
$mod_post = 'echo ' . $compiler->compileTag(
'private_modifier',
array(),
array(
'modifierlist' => $parameter[ 'modifier_list' ],
'value' => 'ob_get_clean()'
)
) . ";\n";
}
$output = "<?php {$mod_content}\$_block_repeat=false;\n{$mod_pre}echo {$callback}({$_params}, {$mod_content2}, \$_smarty_tpl, \$_block_repeat);\n{$mod_post}}\n";
$output =
"<?php {$mod_content}\$_block_repeat=false;\n{$mod_pre}echo {$callback}({$_params}, {$mod_content2}, \$_smarty_tpl, \$_block_repeat);\n{$mod_post}}\n";
$output .= 'array_pop($_smarty_tpl->smarty->_cache[\'_tag_stack\']);?>';
}
return $output;
@ -98,9 +103,9 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
* Setup callback and parameter array
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
* @param array $_attr attributes
* @param string $tag
* @param string $function
* @param array $_attr attributes
* @param string $tag
* @param string $function
*
* @return array
*/

@ -16,28 +16,6 @@
*/
class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_CompileBase
{
/**
* Preg search pattern
*
* @var string
*/
private $propertyPreg = '';
/**
* Offsets in preg match result
*
* @var array
*/
private $resultOffsets = array();
/**
* Start offset
*
* @var int
*/
private $startOffset = 0;
/**
* Name of this tag
*
@ -71,10 +49,31 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
*/
public $matchResults = array();
/**
* Preg search pattern
*
* @var string
*/
private $propertyPreg = '';
/**
* Offsets in preg match result
*
* @var array
*/
private $resultOffsets = array();
/**
* Start offset
*
* @var int
*/
private $startOffset = 0;
/**
* Scan sources for used tag attributes
*
* @param array $attributes
* @param array $attributes
* @param \Smarty_Internal_TemplateCompilerBase $compiler
*
* @throws \SmartyException
@ -82,10 +81,10 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
public function scanForProperties($attributes, Smarty_Internal_TemplateCompilerBase $compiler)
{
$this->propertyPreg = '~(';
$this->startOffset = 0;
$this->startOffset = 1;
$this->resultOffsets = array();
$this->matchResults = array('named' => array(), 'item' => array());
if ($this->isNamed) {
if (isset($attributes[ 'name' ])) {
$this->buildPropertyPreg(true, $attributes);
}
if (isset($this->itemProperties)) {
@ -112,19 +111,19 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
public function buildPropertyPreg($named, $attributes)
{
if ($named) {
$this->resultOffsets[ 'named' ] = $this->startOffset + 4;
$this->propertyPreg .= "(([\$]smarty[.]{$this->tagName}[.]" . ($this->tagName === 'section' ? "|[\[]\s*" : '')
. "){$attributes['name']}[.](";
$this->resultOffsets[ 'named' ] = $this->startOffset = $this->startOffset + 3;
$this->propertyPreg .= "(([\$]smarty[.]{$this->tagName}[.]" .
($this->tagName === 'section' ? "|[\[]\s*" : '') .
"){$attributes['name']}[.](";
$properties = $this->nameProperties;
} else {
$this->resultOffsets[ 'item' ] = $this->startOffset + 3;
$this->resultOffsets[ 'item' ] = $this->startOffset = $this->startOffset + 2;
$this->propertyPreg .= "([\$]{$attributes['item']}[@](";
$properties = $this->itemProperties;
}
$this->startOffset += count($properties) + 2;
$propName = reset($properties);
while ($propName) {
$this->propertyPreg .= "({$propName})";
$this->propertyPreg .= "{$propName}";
$propName = next($properties);
if ($propName) {
$this->propertyPreg .= '|';
@ -140,11 +139,11 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
*/
public function matchProperty($source)
{
preg_match_all($this->propertyPreg, $source, $match, PREG_SET_ORDER);
preg_match_all($this->propertyPreg, $source, $match);
foreach ($this->resultOffsets as $key => $offset) {
foreach ($match as $m) {
if (isset($m[ $offset ]) && !empty($m[ $offset ])) {
$this->matchResults[ $key ][ strtolower($m[ $offset ]) ] = true;
foreach ($match[ $offset ] as $m) {
if (!empty($m)) {
$this->matchResults[ $key ][ strtolower($m) ] = true;
}
}
}
@ -181,8 +180,11 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
if ((isset($nextCompiler->smarty->autoload_filters[ 'pre' ]) ||
isset($nextCompiler->smarty->registered_filters[ 'pre' ]))
) {
$_content = $nextCompiler->smarty->ext->_filterHandler->runFilter('pre', $_content,
$nextCompiler->template);
$_content = $nextCompiler->smarty->ext->_filterHandler->runFilter(
'pre',
$_content,
$nextCompiler->template
);
}
$this->matchProperty($_content);
}
@ -202,9 +204,9 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
/**
* Compiles code for the {$smarty.foreach.xxx} or {$smarty.section.xxx}tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
@ -223,4 +225,4 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
$tagVar = "'__smarty_{$tag}_{$name}'";
return "(isset(\$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}'] : null)";
}
}
}

@ -35,11 +35,11 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
/**
* Compiles code for the execution of function plugin
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of function plugin
* @param string $function PHP function name
* @param array $parameter array with compilation parameter
* @param string $tag name of function plugin
* @param string $function PHP function name
*
* @return string compiled code
* @throws \SmartyCompilerException
@ -49,7 +49,6 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
unset($_attr[ 'nocache' ]);
// convert attributes into parameter array string
$_paramsArray = array();
@ -64,9 +63,14 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
// compile code
$output = "{$function}({$_params},\$_smarty_tpl)";
if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
$output = $compiler->compileTag(
'private_modifier',
array(),
array(
'modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output
)
);
}
$output = "<?php echo {$output};?>\n";
return $output;

@ -1,5 +1,4 @@
<?php
/**
* Smarty Internal Plugin Compile Modifier
* Compiles code for modifier execution
@ -20,9 +19,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
/**
* Compiles code for modifier execution
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
@ -52,8 +51,12 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])) {
if (is_callable($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ])) {
$output =
sprintf('call_user_func_array($_smarty_tpl->registered_plugins[ \'%s\' ][ %s ][ 0 ], array( %s ))',
Smarty::PLUGIN_MODIFIER, var_export($modifier, true), $params);
sprintf(
'call_user_func_array($_smarty_tpl->registered_plugins[ \'%s\' ][ %s ][ 0 ], array( %s ))',
Smarty::PLUGIN_MODIFIER,
var_export($modifier, true),
$params
);
$compiler->known_modifier_type[ $modifier ] = $type;
break 2;
}
@ -63,8 +66,11 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// registered modifier compiler
if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ])) {
$output =
call_user_func($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ],
$single_modifier, $compiler->smarty);
call_user_func(
$compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ],
$single_modifier,
$compiler->smarty
);
$compiler->known_modifier_type[ $modifier ] = $type;
break 2;
}
@ -73,8 +79,8 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// modifiercompiler plugin
if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
// check if modifier allowed
if (!is_object($compiler->smarty->security_policy) ||
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
if (!is_object($compiler->smarty->security_policy)
|| $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) {
$plugin = 'smarty_modifiercompiler_' . $modifier;
$output = $plugin($single_modifier, $compiler);
@ -87,8 +93,8 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// modifier plugin
if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) {
// check if modifier allowed
if (!is_object($compiler->smarty->security_policy) ||
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
if (!is_object($compiler->smarty->security_policy)
|| $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) {
$output = "{$function}({$params})";
}
@ -100,8 +106,8 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// PHP function
if (is_callable($modifier)) {
// check if modifier allowed
if (!is_object($compiler->smarty->security_policy) ||
$compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)
if (!is_object($compiler->smarty->security_policy)
|| $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)
) {
$output = "{$modifier}({$params})";
}
@ -111,26 +117,27 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
break;
case 6:
// default plugin handler
if (isset($compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ]) ||
(is_callable($compiler->smarty->default_plugin_handler_func) &&
$compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))
if (isset($compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])
|| (is_callable($compiler->smarty->default_plugin_handler_func)
&& $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))
) {
$function = $compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ];
// check if modifier allowed
if (!is_object($compiler->smarty->security_policy) ||
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
if (!is_object($compiler->smarty->security_policy)
|| $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) {
if (!is_array($function)) {
$output = "{$function}({$params})";
} else {
if (is_object($function[ 0 ])) {
$output = $function[ 0 ] . '->'. $function[ 1 ] . '(' . $params . ')';
$output = $function[ 0 ] . '->' . $function[ 1 ] . '(' . $params . ')';
} else {
$output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')';
}
}
}
if (isset($compiler->required_plugins[ 'nocache' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ]) ||
if (isset($compiler->required_plugins[ 'nocache' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ])
||
isset($compiler->required_plugins[ 'compiled' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ])
) {
// was a plugin
@ -146,7 +153,6 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
$compiler->trigger_template_error("unknown modifier '{$modifier}'", null, true);
}
}
return $output;
}
}
}

@ -20,9 +20,9 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
* Setup callback and parameter array
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
* @param array $_attr attributes
* @param string $tag
* @param string $method
* @param array $_attr attributes
* @param string $tag
* @param string $method
*
* @return array
*/

@ -27,11 +27,11 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
/**
* Compiles code for the execution of function plugin
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of function
* @param string $method name of method to call
* @param array $parameter array with compilation parameter
* @param string $tag name of function
* @param string $method name of method to call
*
* @return string compiled code
* @throws \SmartyCompilerException
@ -70,8 +70,11 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
$output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}";
}
if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ], 'value' => $output));
$output = $compiler->compileTag(
'private_modifier',
array(),
array('modifierlist' => $parameter[ 'modifierlist' ], 'value' => $output)
);
}
if (empty($_assign)) {
return "<?php echo {$output};?>\n";

@ -16,7 +16,6 @@
*/
class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
{
/**
* Attribute definition: Overwrites base class.
*
@ -43,10 +42,16 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
if ($_attr[ 'type' ] === 'xml') {
$compiler->tag_nocache = true;
$output = addcslashes($_attr[ 'code' ], "'\\");
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$compiler->processNocacheCode("<?php echo '{$output}';?>",
true)));
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$compiler->processNocacheCode(
"<?php echo '{$output}';?>\n",
true
)
)
);
return '';
}
if ($_attr[ 'type' ] !== 'tag') {
@ -54,23 +59,37 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
return '';
} elseif ($compiler->php_handling === Smarty::PHP_QUOTE) {
$output =
preg_replace_callback('#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i',
array($this, 'quote'), $_attr[ 'code' ]);
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Text($output));
preg_replace_callback(
'#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i',
array($this, 'quote'),
$_attr[ 'code' ]
);
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new Smarty_Internal_ParseTree_Text($output)
);
return '';
} elseif ($compiler->php_handling === Smarty::PHP_PASSTHRU || $_attr[ 'type' ] === 'unmatched') {
$compiler->tag_nocache = true;
$output = addcslashes($_attr[ 'code' ], "'\\");
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$compiler->processNocacheCode("<?php echo '{$output}';?>",
true)));
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$compiler->processNocacheCode(
"<?php echo '{$output}';?>\n",
true
)
)
);
return '';
} elseif ($compiler->php_handling === Smarty::PHP_ALLOW) {
if (!($compiler->smarty instanceof SmartyBC)) {
$compiler->trigger_template_error('$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it',
null, true);
$compiler->trigger_template_error(
'$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it',
null,
true
);
}
$compiler->has_code = true;
return $_attr[ 'code' ];
@ -80,8 +99,11 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
} else {
$compiler->has_code = true;
if (!($compiler->smarty instanceof SmartyBC)) {
$compiler->trigger_template_error('{php}{/php} tags not allowed. Use SmartyBC to enable them', null,
true);
$compiler->trigger_template_error(
'{php}{/php} tags not allowed. Use SmartyBC to enable them',
null,
true
);
}
$ldel = preg_quote($compiler->smarty->left_delimiter, '#');
$rdel = preg_quote($compiler->smarty->right_delimiter, '#');
@ -93,8 +115,11 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
$compiler->trigger_template_error("illegal value of option flag '{$match[2]}'", null, true);
}
}
return preg_replace(array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#", "#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"),
array('<?php ', '?>'), $_attr[ 'code' ]);
return preg_replace(
array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#", "#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"),
array('<?php ', '?>'),
$_attr[ 'code' ]
);
}
}
@ -148,8 +173,10 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
if ($lex->phpType === 'unmatched') {
return;
}
if (($lex->phpType === 'php' || $lex->phpType === 'asp') &&
($lex->compiler->php_handling === Smarty::PHP_PASSTHRU || $lex->compiler->php_handling === Smarty::PHP_QUOTE)
if (($lex->phpType === 'php' || $lex->phpType === 'asp')
&&
($lex->compiler->php_handling === Smarty::PHP_PASSTHRU ||
$lex->compiler->php_handling === Smarty::PHP_QUOTE)
) {
return;
}
@ -161,8 +188,14 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
$lex->compiler->trigger_template_error("missing closing tag '{$closeTag}'");
}
while ($body) {
if (preg_match('~([/][*])|([/][/][^\n]*)|(\'[^\'\\\\]*(?:\\.[^\'\\\\]*)*\')|("[^"\\\\]*(?:\\.[^"\\\\]*)*")~',
$lex->data, $match, PREG_OFFSET_CAPTURE, $start)) {
if (preg_match(
'~([/][*])|([/][/][^\n]*)|(\'[^\'\\\\]*(?:\\.[^\'\\\\]*)*\')|("[^"\\\\]*(?:\\.[^"\\\\]*)*")~',
$lex->data,
$match,
PREG_OFFSET_CAPTURE,
$start
)
) {
$value = $match[ 0 ][ 0 ];
$from = $pos = $match[ 0 ][ 1 ];
if ($pos > $close) {
@ -178,8 +211,14 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
}
}
while ($close > $pos && $close < $start) {
if (preg_match('~' . preg_quote($closeTag, '~') . '~i', $lex->data, $match, PREG_OFFSET_CAPTURE,
$from)) {
if (preg_match(
'~' . preg_quote($closeTag, '~') . '~i',
$lex->data,
$match,
PREG_OFFSET_CAPTURE,
$from
)
) {
$close = $match[ 0 ][ 1 ];
$from = $close + strlen($match[ 0 ][ 0 ]);
} else {

@ -49,9 +49,14 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
$output = $parameter[ 'value' ];
// tag modifier
if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
$output = $compiler->compileTag(
'private_modifier',
array(),
array(
'modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output
)
);
}
if (isset($_attr[ 'assign' ])) {
// assign output to variable
@ -64,9 +69,12 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
if (empty($compiler->default_modifier_list)) {
$modifierlist = array();
foreach ($compiler->smarty->default_modifiers as $key => $single_default_modifier) {
preg_match_all('/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/',
$single_default_modifier, $mod_array);
for ($i = 0, $count = count($mod_array[ 0 ]); $i < $count; $i ++) {
preg_match_all(
'/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/',
$single_default_modifier,
$mod_array
);
for ($i = 0, $count = count($mod_array[ 0 ]); $i < $count; $i++) {
if ($mod_array[ 0 ][ $i ] !== ':') {
$modifierlist[ $key ][] = $mod_array[ 0 ][ $i ];
}
@ -74,9 +82,14 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
}
$compiler->default_modifier_list = $modifierlist;
}
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $compiler->default_modifier_list,
'value' => $output));
$output = $compiler->compileTag(
'private_modifier',
array(),
array(
'modifierlist' => $compiler->default_modifier_list,
'value' => $output
)
);
}
// autoescape html
if ($compiler->template->smarty->escape_html) {
@ -85,7 +98,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
// loop over registered filters
if (!empty($compiler->template->smarty->registered_filters[ Smarty::FILTER_VARIABLE ])) {
foreach ($compiler->template->smarty->registered_filters[ Smarty::FILTER_VARIABLE ] as $key =>
$function) {
$function) {
if (!is_array($function)) {
$output = "{$function}({$output},\$_smarty_tpl)";
} elseif (is_object($function[ 0 ])) {
@ -98,8 +111,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
}
// auto loaded filters
if (isset($compiler->smarty->autoload_filters[ Smarty::FILTER_VARIABLE ])) {
foreach ((array) $compiler->template->smarty->autoload_filters[ Smarty::FILTER_VARIABLE ] as $name)
{
foreach ((array)$compiler->template->smarty->autoload_filters[ Smarty::FILTER_VARIABLE ] as $name) {
$result = $this->compile_variable_filter($compiler, $name, $output);
if ($result !== false) {
$output = $result;
@ -110,19 +122,21 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
}
}
foreach ($compiler->variable_filters as $filter) {
if (count($filter) === 1 &&
($result = $this->compile_variable_filter($compiler, $filter[ 0 ], $output)) !== false
if (count($filter) === 1
&& ($result = $this->compile_variable_filter($compiler, $filter[ 0 ], $output)) !== false
) {
$output = $result;
} else {
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => array($filter), 'value' => $output));
$output = $compiler->compileTag(
'private_modifier',
array(),
array('modifierlist' => array($filter), 'value' => $output)
);
}
}
}
$output = "<?php echo {$output};?>\n";
}
return $output;
}
@ -136,12 +150,12 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
*/
private function compile_variable_filter(Smarty_Internal_TemplateCompilerBase $compiler, $name, $output)
{
$function= $compiler->getPlugin($name, 'variablefilter');
if ($function) {
$function = $compiler->getPlugin($name, 'variablefilter');
if ($function) {
return "{$function}({$output},\$_smarty_tpl)";
} else {
} else {
// not found
return false;
}
}
}
}

@ -20,9 +20,9 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
* Setup callback, parameter array and nocache mode
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
* @param array $_attr attributes
* @param string $tag
* @param null $function
* @param array $_attr attributes
* @param string $tag
* @param null $function
*
* @return array
*/

@ -27,10 +27,10 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
/**
* Compiles code for the execution of a registered function
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of function
* @param array $parameter array with compilation parameter
* @param string $tag name of function
*
* @return string compiled code
* @throws \SmartyCompilerException
@ -45,8 +45,8 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
$tag_info = $compiler->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ];
$is_registered = true;
} else {
$tag_info = $compiler->default_handler_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ];
$is_registered = false;
$tag_info = $compiler->default_handler_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ];
$is_registered = false;
}
// not cacheable?
$compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[ 1 ];
@ -76,11 +76,16 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
}
}
if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
$output = $compiler->compileTag(
'private_modifier',
array(),
array(
'modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output
)
);
}
$output = "<?php echo {$output};?>\n";
return $output;
}
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save