mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-24 01:48:44 +00:00
Update smarty for admin to 2.6.28
--HG-- branch : develop
This commit is contained in:
parent
53ea877a50
commit
07933bf52c
55 changed files with 5229 additions and 4882 deletions
|
@ -1,389 +1,393 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Config_File class.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* @link http://smarty.php.net/
|
||||
* @version 2.6.9
|
||||
* @copyright Copyright: 2001-2005 New Digital Group, Inc.
|
||||
* @author Andrei Zmievski <andrei@php.net>
|
||||
* @access public
|
||||
* @package Smarty
|
||||
*/
|
||||
|
||||
/* $Id: Config_File.class.php,v 1.1 2006/05/29 16:38:21 powles Exp $ */
|
||||
|
||||
/**
|
||||
* Config file reading class
|
||||
* @package Smarty
|
||||
*/
|
||||
class Config_File {
|
||||
/**#@+
|
||||
* Options
|
||||
* @var boolean
|
||||
*/
|
||||
/**
|
||||
* Controls whether variables with the same name overwrite each other.
|
||||
*/
|
||||
var $overwrite = true;
|
||||
|
||||
/**
|
||||
* Controls whether config values of on/true/yes and off/false/no get
|
||||
* converted to boolean values automatically.
|
||||
*/
|
||||
var $booleanize = true;
|
||||
|
||||
/**
|
||||
* Controls whether hidden config sections/vars are read from the file.
|
||||
*/
|
||||
var $read_hidden = true;
|
||||
|
||||
/**
|
||||
* Controls whether or not to fix mac or dos formatted newlines.
|
||||
* If set to true, \r or \r\n will be changed to \n.
|
||||
*/
|
||||
var $fix_newlines = true;
|
||||
/**#@-*/
|
||||
|
||||
/** @access private */
|
||||
var $_config_path = "";
|
||||
var $_config_data = array();
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Constructs a new config file class.
|
||||
*
|
||||
* @param string $config_path (optional) path to the config files
|
||||
*/
|
||||
function Config_File($config_path = NULL)
|
||||
{
|
||||
if (isset($config_path))
|
||||
$this->set_path($config_path);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the path where configuration files can be found.
|
||||
*
|
||||
* @param string $config_path path to the config files
|
||||
*/
|
||||
function set_path($config_path)
|
||||
{
|
||||
if (!empty($config_path)) {
|
||||
if (!is_string($config_path) || !file_exists($config_path) || !is_dir($config_path)) {
|
||||
$this->_trigger_error_msg("Bad config file path '$config_path'");
|
||||
return;
|
||||
}
|
||||
if(substr($config_path, -1) != DIRECTORY_SEPARATOR) {
|
||||
$config_path .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
$this->_config_path = $config_path;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves config info based on the file, section, and variable name.
|
||||
*
|
||||
* @param string $file_name config file to get info for
|
||||
* @param string $section_name (optional) section to get info for
|
||||
* @param string $var_name (optional) variable to get info for
|
||||
* @return string|array a value or array of values
|
||||
*/
|
||||
function &get($file_name, $section_name = NULL, $var_name = NULL)
|
||||
{
|
||||
if (empty($file_name)) {
|
||||
$this->_trigger_error_msg('Empty config file name');
|
||||
return;
|
||||
} else {
|
||||
$file_name = $this->_config_path . $file_name;
|
||||
if (!isset($this->_config_data[$file_name]))
|
||||
$this->load_file($file_name, false);
|
||||
}
|
||||
|
||||
if (!empty($var_name)) {
|
||||
if (empty($section_name)) {
|
||||
return $this->_config_data[$file_name]["vars"][$var_name];
|
||||
} else {
|
||||
if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name]))
|
||||
return $this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name];
|
||||
else
|
||||
return array();
|
||||
}
|
||||
} else {
|
||||
if (empty($section_name)) {
|
||||
return (array)$this->_config_data[$file_name]["vars"];
|
||||
} else {
|
||||
if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"]))
|
||||
return (array)$this->_config_data[$file_name]["sections"][$section_name]["vars"];
|
||||
else
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves config info based on the key.
|
||||
*
|
||||
* @param $file_name string config key (filename/section/var)
|
||||
* @return string|array same as get()
|
||||
* @uses get() retrieves information from config file and returns it
|
||||
*/
|
||||
function &get_key($config_key)
|
||||
{
|
||||
list($file_name, $section_name, $var_name) = explode('/', $config_key, 3);
|
||||
$result = &$this->get($file_name, $section_name, $var_name);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all loaded config file names.
|
||||
*
|
||||
* @return array an array of loaded config file names
|
||||
*/
|
||||
function get_file_names()
|
||||
{
|
||||
return array_keys($this->_config_data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all section names from a loaded file.
|
||||
*
|
||||
* @param string $file_name config file to get section names from
|
||||
* @return array an array of section names from the specified file
|
||||
*/
|
||||
function get_section_names($file_name)
|
||||
{
|
||||
$file_name = $this->_config_path . $file_name;
|
||||
if (!isset($this->_config_data[$file_name])) {
|
||||
$this->_trigger_error_msg("Unknown config file '$file_name'");
|
||||
return;
|
||||
}
|
||||
|
||||
return array_keys($this->_config_data[$file_name]["sections"]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all global or section variable names.
|
||||
*
|
||||
* @param string $file_name config file to get info for
|
||||
* @param string $section_name (optional) section to get info for
|
||||
* @return array an array of variables names from the specified file/section
|
||||
*/
|
||||
function get_var_names($file_name, $section = NULL)
|
||||
{
|
||||
if (empty($file_name)) {
|
||||
$this->_trigger_error_msg('Empty config file name');
|
||||
return;
|
||||
} else if (!isset($this->_config_data[$file_name])) {
|
||||
$this->_trigger_error_msg("Unknown config file '$file_name'");
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($section))
|
||||
return array_keys($this->_config_data[$file_name]["vars"]);
|
||||
else
|
||||
return array_keys($this->_config_data[$file_name]["sections"][$section]["vars"]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear loaded config data for a certain file or all files.
|
||||
*
|
||||
* @param string $file_name file to clear config data for
|
||||
*/
|
||||
function clear($file_name = NULL)
|
||||
{
|
||||
if ($file_name === NULL)
|
||||
$this->_config_data = array();
|
||||
else if (isset($this->_config_data[$file_name]))
|
||||
$this->_config_data[$file_name] = array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load a configuration file manually.
|
||||
*
|
||||
* @param string $file_name file name to load
|
||||
* @param boolean $prepend_path whether current config path should be
|
||||
* prepended to the filename
|
||||
*/
|
||||
function load_file($file_name, $prepend_path = true)
|
||||
{
|
||||
if ($prepend_path && $this->_config_path != "")
|
||||
$config_file = $this->_config_path . $file_name;
|
||||
else
|
||||
$config_file = $file_name;
|
||||
|
||||
ini_set('track_errors', true);
|
||||
$fp = @fopen($config_file, "r");
|
||||
if (!is_resource($fp)) {
|
||||
$this->_trigger_error_msg("Could not open config file '$config_file'");
|
||||
return false;
|
||||
}
|
||||
|
||||
$contents = ($size = filesize($config_file)) ? fread($fp, $size) : '';
|
||||
fclose($fp);
|
||||
|
||||
$this->_config_data[$config_file] = $this->parse_contents($contents);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the contents of a file manually.
|
||||
*
|
||||
* @param string $config_file file name of the related contents
|
||||
* @param string $contents the file-contents to parse
|
||||
*/
|
||||
function set_file_contents($config_file, $contents)
|
||||
{
|
||||
$this->_config_data[$config_file] = $this->parse_contents($contents);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse the source of a configuration file manually.
|
||||
*
|
||||
* @param string $contents the file-contents to parse
|
||||
*/
|
||||
function parse_contents($contents)
|
||||
{
|
||||
if($this->fix_newlines) {
|
||||
// fix mac/dos formatted newlines
|
||||
$contents = preg_replace('!\r\n?!', "\n", $contents);
|
||||
}
|
||||
|
||||
$config_data = array();
|
||||
$config_data['sections'] = array();
|
||||
$config_data['vars'] = array();
|
||||
|
||||
/* reference to fill with data */
|
||||
$vars =& $config_data['vars'];
|
||||
|
||||
/* parse file line by line */
|
||||
preg_match_all('!^.*\r?\n?!m', $contents, $match);
|
||||
$lines = $match[0];
|
||||
for ($i=0, $count=count($lines); $i<$count; $i++) {
|
||||
$line = $lines[$i];
|
||||
if (empty($line)) continue;
|
||||
|
||||
if ( $line{0} == '[' && preg_match('!^\[(.*?)\]!', $line, $match) ) {
|
||||
/* section found */
|
||||
if ($match[1]{0} == '.') {
|
||||
/* hidden section */
|
||||
if ($this->read_hidden) {
|
||||
$section_name = substr($match[1], 1);
|
||||
} else {
|
||||
/* break reference to $vars to ignore hidden section */
|
||||
unset($vars);
|
||||
$vars = array();
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$section_name = $match[1];
|
||||
}
|
||||
if (!isset($config_data['sections'][$section_name]))
|
||||
$config_data['sections'][$section_name] = array('vars' => array());
|
||||
$vars =& $config_data['sections'][$section_name]['vars'];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match('/^\s*(\.?\w+)\s*=\s*(.*)/s', $line, $match)) {
|
||||
/* variable found */
|
||||
$var_name = rtrim($match[1]);
|
||||
if (strpos($match[2], '"""') === 0) {
|
||||
/* handle multiline-value */
|
||||
$lines[$i] = substr($match[2], 3);
|
||||
$var_value = '';
|
||||
while ($i<$count) {
|
||||
if (($pos = strpos($lines[$i], '"""')) === false) {
|
||||
$var_value .= $lines[$i++];
|
||||
} else {
|
||||
/* end of multiline-value */
|
||||
$var_value .= substr($lines[$i], 0, $pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$booleanize = false;
|
||||
|
||||
} else {
|
||||
/* handle simple value */
|
||||
$var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', rtrim($match[2]));
|
||||
$booleanize = $this->booleanize;
|
||||
|
||||
}
|
||||
$this->_set_config_var($vars, $var_name, $var_value, $booleanize);
|
||||
}
|
||||
/* else unparsable line / means it is a comment / means ignore it */
|
||||
}
|
||||
return $config_data;
|
||||
}
|
||||
|
||||
/**#@+ @access private */
|
||||
/**
|
||||
* @param array &$container
|
||||
* @param string $var_name
|
||||
* @param mixed $var_value
|
||||
* @param boolean $booleanize determines whether $var_value is converted to
|
||||
* to true/false
|
||||
*/
|
||||
function _set_config_var(&$container, $var_name, $var_value, $booleanize)
|
||||
{
|
||||
if ($var_name{0} == '.') {
|
||||
if (!$this->read_hidden)
|
||||
return;
|
||||
else
|
||||
$var_name = substr($var_name, 1);
|
||||
}
|
||||
|
||||
if (!preg_match("/^[a-zA-Z_]\w*$/", $var_name)) {
|
||||
$this->_trigger_error_msg("Bad variable name '$var_name'");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($booleanize) {
|
||||
if (preg_match("/^(on|true|yes)$/i", $var_value))
|
||||
$var_value = true;
|
||||
else if (preg_match("/^(off|false|no)$/i", $var_value))
|
||||
$var_value = false;
|
||||
}
|
||||
|
||||
if (!isset($container[$var_name]) || $this->overwrite)
|
||||
$container[$var_name] = $var_value;
|
||||
else {
|
||||
settype($container[$var_name], 'array');
|
||||
$container[$var_name][] = $var_value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses trigger_error() creates a PHP warning/error
|
||||
* @param string $error_msg
|
||||
* @param integer $error_type one of
|
||||
*/
|
||||
function _trigger_error_msg($error_msg, $error_type = E_USER_WARNING)
|
||||
{
|
||||
trigger_error("Config_File error: $error_msg", $error_type);
|
||||
}
|
||||
/**#@-*/
|
||||
}
|
||||
|
||||
?>
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Config_File class.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* For questions, help, comments, discussion, etc., please join the
|
||||
* Smarty mailing list. Send a blank e-mail to
|
||||
* smarty-discussion-subscribe@googlegroups.com
|
||||
*
|
||||
* @link http://www.smarty.net/
|
||||
* @version 2.6.25-dev
|
||||
* @copyright Copyright: 2001-2005 New Digital Group, Inc.
|
||||
* @author Andrei Zmievski <andrei@php.net>
|
||||
* @access public
|
||||
* @package Smarty
|
||||
*/
|
||||
|
||||
/* $Id: Config_File.class.php 3149 2009-05-23 20:59:25Z monte.ohrt $ */
|
||||
|
||||
/**
|
||||
* Config file reading class
|
||||
* @package Smarty
|
||||
*/
|
||||
class Config_File {
|
||||
/**#@+
|
||||
* Options
|
||||
* @var boolean
|
||||
*/
|
||||
/**
|
||||
* Controls whether variables with the same name overwrite each other.
|
||||
*/
|
||||
var $overwrite = true;
|
||||
|
||||
/**
|
||||
* Controls whether config values of on/true/yes and off/false/no get
|
||||
* converted to boolean values automatically.
|
||||
*/
|
||||
var $booleanize = true;
|
||||
|
||||
/**
|
||||
* Controls whether hidden config sections/vars are read from the file.
|
||||
*/
|
||||
var $read_hidden = true;
|
||||
|
||||
/**
|
||||
* Controls whether or not to fix mac or dos formatted newlines.
|
||||
* If set to true, \r or \r\n will be changed to \n.
|
||||
*/
|
||||
var $fix_newlines = true;
|
||||
/**#@-*/
|
||||
|
||||
/** @access private */
|
||||
var $_config_path = "";
|
||||
var $_config_data = array();
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Constructs a new config file class.
|
||||
*
|
||||
* @param string $config_path (optional) path to the config files
|
||||
*/
|
||||
function Config_File($config_path = NULL)
|
||||
{
|
||||
if (isset($config_path))
|
||||
$this->set_path($config_path);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the path where configuration files can be found.
|
||||
*
|
||||
* @param string $config_path path to the config files
|
||||
*/
|
||||
function set_path($config_path)
|
||||
{
|
||||
if (!empty($config_path)) {
|
||||
if (!is_string($config_path) || !file_exists($config_path) || !is_dir($config_path)) {
|
||||
$this->_trigger_error_msg("Bad config file path '$config_path'");
|
||||
return;
|
||||
}
|
||||
if(substr($config_path, -1) != DIRECTORY_SEPARATOR) {
|
||||
$config_path .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
$this->_config_path = $config_path;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves config info based on the file, section, and variable name.
|
||||
*
|
||||
* @param string $file_name config file to get info for
|
||||
* @param string $section_name (optional) section to get info for
|
||||
* @param string $var_name (optional) variable to get info for
|
||||
* @return string|array a value or array of values
|
||||
*/
|
||||
function get($file_name, $section_name = NULL, $var_name = NULL)
|
||||
{
|
||||
if (empty($file_name)) {
|
||||
$this->_trigger_error_msg('Empty config file name');
|
||||
return;
|
||||
} else {
|
||||
$file_name = $this->_config_path . $file_name;
|
||||
if (!isset($this->_config_data[$file_name]))
|
||||
$this->load_file($file_name, false);
|
||||
}
|
||||
|
||||
if (!empty($var_name)) {
|
||||
if (empty($section_name)) {
|
||||
return $this->_config_data[$file_name]["vars"][$var_name];
|
||||
} else {
|
||||
if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name]))
|
||||
return $this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name];
|
||||
else
|
||||
return array();
|
||||
}
|
||||
} else {
|
||||
if (empty($section_name)) {
|
||||
return (array)$this->_config_data[$file_name]["vars"];
|
||||
} else {
|
||||
if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"]))
|
||||
return (array)$this->_config_data[$file_name]["sections"][$section_name]["vars"];
|
||||
else
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves config info based on the key.
|
||||
*
|
||||
* @param $file_name string config key (filename/section/var)
|
||||
* @return string|array same as get()
|
||||
* @uses get() retrieves information from config file and returns it
|
||||
*/
|
||||
function &get_key($config_key)
|
||||
{
|
||||
list($file_name, $section_name, $var_name) = explode('/', $config_key, 3);
|
||||
$result = &$this->get($file_name, $section_name, $var_name);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all loaded config file names.
|
||||
*
|
||||
* @return array an array of loaded config file names
|
||||
*/
|
||||
function get_file_names()
|
||||
{
|
||||
return array_keys($this->_config_data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all section names from a loaded file.
|
||||
*
|
||||
* @param string $file_name config file to get section names from
|
||||
* @return array an array of section names from the specified file
|
||||
*/
|
||||
function get_section_names($file_name)
|
||||
{
|
||||
$file_name = $this->_config_path . $file_name;
|
||||
if (!isset($this->_config_data[$file_name])) {
|
||||
$this->_trigger_error_msg("Unknown config file '$file_name'");
|
||||
return;
|
||||
}
|
||||
|
||||
return array_keys($this->_config_data[$file_name]["sections"]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all global or section variable names.
|
||||
*
|
||||
* @param string $file_name config file to get info for
|
||||
* @param string $section_name (optional) section to get info for
|
||||
* @return array an array of variables names from the specified file/section
|
||||
*/
|
||||
function get_var_names($file_name, $section = NULL)
|
||||
{
|
||||
if (empty($file_name)) {
|
||||
$this->_trigger_error_msg('Empty config file name');
|
||||
return;
|
||||
} else if (!isset($this->_config_data[$file_name])) {
|
||||
$this->_trigger_error_msg("Unknown config file '$file_name'");
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($section))
|
||||
return array_keys($this->_config_data[$file_name]["vars"]);
|
||||
else
|
||||
return array_keys($this->_config_data[$file_name]["sections"][$section]["vars"]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear loaded config data for a certain file or all files.
|
||||
*
|
||||
* @param string $file_name file to clear config data for
|
||||
*/
|
||||
function clear($file_name = NULL)
|
||||
{
|
||||
if ($file_name === NULL)
|
||||
$this->_config_data = array();
|
||||
else if (isset($this->_config_data[$file_name]))
|
||||
$this->_config_data[$file_name] = array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load a configuration file manually.
|
||||
*
|
||||
* @param string $file_name file name to load
|
||||
* @param boolean $prepend_path whether current config path should be
|
||||
* prepended to the filename
|
||||
*/
|
||||
function load_file($file_name, $prepend_path = true)
|
||||
{
|
||||
if ($prepend_path && $this->_config_path != "")
|
||||
$config_file = $this->_config_path . $file_name;
|
||||
else
|
||||
$config_file = $file_name;
|
||||
|
||||
ini_set('track_errors', true);
|
||||
$fp = @fopen($config_file, "r");
|
||||
if (!is_resource($fp)) {
|
||||
$this->_trigger_error_msg("Could not open config file '$config_file'");
|
||||
return false;
|
||||
}
|
||||
|
||||
$contents = ($size = filesize($config_file)) ? fread($fp, $size) : '';
|
||||
fclose($fp);
|
||||
|
||||
$this->_config_data[$config_file] = $this->parse_contents($contents);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the contents of a file manually.
|
||||
*
|
||||
* @param string $config_file file name of the related contents
|
||||
* @param string $contents the file-contents to parse
|
||||
*/
|
||||
function set_file_contents($config_file, $contents)
|
||||
{
|
||||
$this->_config_data[$config_file] = $this->parse_contents($contents);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse the source of a configuration file manually.
|
||||
*
|
||||
* @param string $contents the file-contents to parse
|
||||
*/
|
||||
function parse_contents($contents)
|
||||
{
|
||||
if($this->fix_newlines) {
|
||||
// fix mac/dos formatted newlines
|
||||
$contents = preg_replace('!\r\n?!', "\n", $contents);
|
||||
}
|
||||
|
||||
$config_data = array();
|
||||
$config_data['sections'] = array();
|
||||
$config_data['vars'] = array();
|
||||
|
||||
/* reference to fill with data */
|
||||
$vars =& $config_data['vars'];
|
||||
|
||||
/* parse file line by line */
|
||||
preg_match_all('!^.*\r?\n?!m', $contents, $match);
|
||||
$lines = $match[0];
|
||||
for ($i=0, $count=count($lines); $i<$count; $i++) {
|
||||
$line = $lines[$i];
|
||||
if (empty($line)) continue;
|
||||
|
||||
if ( substr($line, 0, 1) == '[' && preg_match('!^\[(.*?)\]!', $line, $match) ) {
|
||||
/* section found */
|
||||
if (substr($match[1], 0, 1) == '.') {
|
||||
/* hidden section */
|
||||
if ($this->read_hidden) {
|
||||
$section_name = substr($match[1], 1);
|
||||
} else {
|
||||
/* break reference to $vars to ignore hidden section */
|
||||
unset($vars);
|
||||
$vars = array();
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$section_name = $match[1];
|
||||
}
|
||||
if (!isset($config_data['sections'][$section_name]))
|
||||
$config_data['sections'][$section_name] = array('vars' => array());
|
||||
$vars =& $config_data['sections'][$section_name]['vars'];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match('/^\s*(\.?\w+)\s*=\s*(.*)/s', $line, $match)) {
|
||||
/* variable found */
|
||||
$var_name = rtrim($match[1]);
|
||||
if (strpos($match[2], '"""') === 0) {
|
||||
/* handle multiline-value */
|
||||
$lines[$i] = substr($match[2], 3);
|
||||
$var_value = '';
|
||||
while ($i<$count) {
|
||||
if (($pos = strpos($lines[$i], '"""')) === false) {
|
||||
$var_value .= $lines[$i++];
|
||||
} else {
|
||||
/* end of multiline-value */
|
||||
$var_value .= substr($lines[$i], 0, $pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$booleanize = false;
|
||||
|
||||
} else {
|
||||
/* handle simple value */
|
||||
$var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', rtrim($match[2]));
|
||||
$booleanize = $this->booleanize;
|
||||
|
||||
}
|
||||
$this->_set_config_var($vars, $var_name, $var_value, $booleanize);
|
||||
}
|
||||
/* else unparsable line / means it is a comment / means ignore it */
|
||||
}
|
||||
return $config_data;
|
||||
}
|
||||
|
||||
/**#@+ @access private */
|
||||
/**
|
||||
* @param array &$container
|
||||
* @param string $var_name
|
||||
* @param mixed $var_value
|
||||
* @param boolean $booleanize determines whether $var_value is converted to
|
||||
* to true/false
|
||||
*/
|
||||
function _set_config_var(&$container, $var_name, $var_value, $booleanize)
|
||||
{
|
||||
if (substr($var_name, 0, 1) == '.') {
|
||||
if (!$this->read_hidden)
|
||||
return;
|
||||
else
|
||||
$var_name = substr($var_name, 1);
|
||||
}
|
||||
|
||||
if (!preg_match("/^[a-zA-Z_]\w*$/", $var_name)) {
|
||||
$this->_trigger_error_msg("Bad variable name '$var_name'");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($booleanize) {
|
||||
if (preg_match("/^(on|true|yes)$/i", $var_value))
|
||||
$var_value = true;
|
||||
else if (preg_match("/^(off|false|no)$/i", $var_value))
|
||||
$var_value = false;
|
||||
}
|
||||
|
||||
if (!isset($container[$var_name]) || $this->overwrite)
|
||||
$container[$var_name] = $var_value;
|
||||
else {
|
||||
settype($container[$var_name], 'array');
|
||||
$container[$var_name][] = $var_value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses trigger_error() creates a PHP warning/error
|
||||
* @param string $error_msg
|
||||
* @param integer $error_type one of
|
||||
*/
|
||||
function _trigger_error_msg($error_msg, $error_type = E_USER_WARNING)
|
||||
{
|
||||
trigger_error("Config_File error: $error_msg", $error_type);
|
||||
}
|
||||
/**#@-*/
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,64 +1,157 @@
|
|||
{* Smarty *}
|
||||
|
||||
{* debug.tpl, last updated version 2.0.1 *}
|
||||
|
||||
{* debug.tpl, last updated version 2.1.0 *}
|
||||
{assign_debug_info}
|
||||
{capture assign=debug_output}
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head>
|
||||
<title>Smarty Debug Console</title>
|
||||
{literal}
|
||||
<style type="text/css">
|
||||
/* <![CDATA[ */
|
||||
body, h1, h2, td, th, p {
|
||||
font-family: sans-serif;
|
||||
font-weight: normal;
|
||||
font-size: 0.9em;
|
||||
margin: 1px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0;
|
||||
text-align: left;
|
||||
padding: 2px;
|
||||
background-color: #f0c040;
|
||||
color: black;
|
||||
font-weight: bold;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
h2 {
|
||||
background-color: #9B410E;
|
||||
color: white;
|
||||
text-align: left;
|
||||
font-weight: bold;
|
||||
padding: 2px;
|
||||
border-top: 1px solid black;
|
||||
}
|
||||
|
||||
body {
|
||||
background: black;
|
||||
}
|
||||
|
||||
p, table, div {
|
||||
background: #f0ead8;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
font-style: italic;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
th, td {
|
||||
font-family: monospace;
|
||||
vertical-align: top;
|
||||
text-align: left;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
td {
|
||||
color: green;
|
||||
}
|
||||
|
||||
.odd {
|
||||
background-color: #eeeeee;
|
||||
}
|
||||
|
||||
.even {
|
||||
background-color: #fafafa;
|
||||
}
|
||||
|
||||
.exectime {
|
||||
font-size: 0.8em;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
#table_assigned_vars th {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
#table_config_vars th {
|
||||
color: maroon;
|
||||
}
|
||||
/* ]]> */
|
||||
</style>
|
||||
{/literal}
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Smarty Debug Console</h1>
|
||||
|
||||
<h2>included templates & config files (load time in seconds)</h2>
|
||||
|
||||
<div>
|
||||
{section name=templates loop=$_debug_tpls}
|
||||
{section name=indent loop=$_debug_tpls[templates].depth} {/section}
|
||||
<font color={if $_debug_tpls[templates].type eq "template"}brown{elseif $_debug_tpls[templates].type eq "insert"}black{else}green{/if}>
|
||||
{$_debug_tpls[templates].filename|escape:html}</font>
|
||||
{if isset($_debug_tpls[templates].exec_time)}
|
||||
<span class="exectime">
|
||||
({$_debug_tpls[templates].exec_time|string_format:"%.5f"})
|
||||
{if %templates.index% eq 0}(total){/if}
|
||||
</span>
|
||||
{/if}
|
||||
<br />
|
||||
{sectionelse}
|
||||
<p>no templates included</p>
|
||||
{/section}
|
||||
</div>
|
||||
|
||||
<h2>assigned template variables</h2>
|
||||
|
||||
<table id="table_assigned_vars">
|
||||
{section name=vars loop=$_debug_keys}
|
||||
<tr class="{cycle values="odd,even"}">
|
||||
<th>{ldelim}${$_debug_keys[vars]|escape:'html'}{rdelim}</th>
|
||||
<td>{$_debug_vals[vars]|@debug_print_var}</td></tr>
|
||||
{sectionelse}
|
||||
<tr><td><p>no template variables assigned</p></td></tr>
|
||||
{/section}
|
||||
</table>
|
||||
|
||||
<h2>assigned config file variables (outer template scope)</h2>
|
||||
|
||||
<table id="table_config_vars">
|
||||
{section name=config_vars loop=$_debug_config_keys}
|
||||
<tr class="{cycle values="odd,even"}">
|
||||
<th>{ldelim}#{$_debug_config_keys[config_vars]|escape:'html'}#{rdelim}</th>
|
||||
<td>{$_debug_config_vals[config_vars]|@debug_print_var}</td></tr>
|
||||
{sectionelse}
|
||||
<tr><td><p>no config vars assigned</p></td></tr>
|
||||
{/section}
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
{/capture}
|
||||
{if isset($_smarty_debug_output) and $_smarty_debug_output eq "html"}
|
||||
<table border=0 width=100%>
|
||||
<tr bgcolor=#cccccc><th colspan=2>Smarty Debug Console</th></tr>
|
||||
<tr bgcolor=#cccccc><td colspan=2><b>included templates & config files (load time in seconds):</b></td></tr>
|
||||
{section name=templates loop=$_debug_tpls}
|
||||
<tr bgcolor={if %templates.index% is even}#eeeeee{else}#fafafa{/if}><td colspan=2><tt>{section name=indent loop=$_debug_tpls[templates].depth} {/section}<font color={if $_debug_tpls[templates].type eq "template"}brown{elseif $_debug_tpls[templates].type eq "insert"}black{else}green{/if}>{$_debug_tpls[templates].filename|escape:html}</font>{if isset($_debug_tpls[templates].exec_time)} <font size=-1><i>({$_debug_tpls[templates].exec_time|string_format:"%.5f"}){if %templates.index% eq 0} (total){/if}</i></font>{/if}</tt></td></tr>
|
||||
{sectionelse}
|
||||
<tr bgcolor=#eeeeee><td colspan=2><tt><i>no templates included</i></tt></td></tr>
|
||||
{/section}
|
||||
<tr bgcolor=#cccccc><td colspan=2><b>assigned template variables:</b></td></tr>
|
||||
{section name=vars loop=$_debug_keys}
|
||||
<tr bgcolor={if %vars.index% is even}#eeeeee{else}#fafafa{/if}><td valign=top><tt><font color=blue>{ldelim}${$_debug_keys[vars]}{rdelim}</font></tt></td><td nowrap><tt><font color=green>{$_debug_vals[vars]|@debug_print_var}</font></tt></td></tr>
|
||||
{sectionelse}
|
||||
<tr bgcolor=#eeeeee><td colspan=2><tt><i>no template variables assigned</i></tt></td></tr>
|
||||
{/section}
|
||||
<tr bgcolor=#cccccc><td colspan=2><b>assigned config file variables (outer template scope):</b></td></tr>
|
||||
{section name=config_vars loop=$_debug_config_keys}
|
||||
<tr bgcolor={if %config_vars.index% is even}#eeeeee{else}#fafafa{/if}><td valign=top><tt><font color=maroon>{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim}</font></tt></td><td><tt><font color=green>{$_debug_config_vals[config_vars]|@debug_print_var}</font></tt></td></tr>
|
||||
{sectionelse}
|
||||
<tr bgcolor=#eeeeee><td colspan=2><tt><i>no config vars assigned</i></tt></td></tr>
|
||||
{/section}
|
||||
</table>
|
||||
</BODY></HTML>
|
||||
{$debug_output}
|
||||
{else}
|
||||
<SCRIPT language=javascript>
|
||||
if( self.name == '' ) {ldelim}
|
||||
var title = 'Console';
|
||||
{rdelim}
|
||||
else {ldelim}
|
||||
var title = 'Console_' + self.name;
|
||||
{rdelim}
|
||||
_smarty_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes");
|
||||
_smarty_console.document.write("<HTML><HEAD><TITLE>Smarty Debug Console_"+self.name+"</TITLE></HEAD><BODY bgcolor=#ffffff>");
|
||||
_smarty_console.document.write("<table border=0 width=100%>");
|
||||
_smarty_console.document.write("<tr bgcolor=#cccccc><th colspan=2>Smarty Debug Console</th></tr>");
|
||||
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>included templates & config files (load time in seconds):</b></td></tr>");
|
||||
{section name=templates loop=$_debug_tpls}
|
||||
_smarty_console.document.write("<tr bgcolor={if %templates.index% is even}#eeeeee{else}#fafafa{/if}><td colspan=2><tt>{section name=indent loop=$_debug_tpls[templates].depth} {/section}<font color={if $_debug_tpls[templates].type eq "template"}brown{elseif $_debug_tpls[templates].type eq "insert"}black{else}green{/if}>{$_debug_tpls[templates].filename|escape:html|escape:javascript}</font>{if isset($_debug_tpls[templates].exec_time)} <font size=-1><i>({$_debug_tpls[templates].exec_time|string_format:"%.5f"}){if %templates.index% eq 0} (total){/if}</i></font>{/if}</tt></td></tr>");
|
||||
{sectionelse}
|
||||
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no templates included</i></tt></td></tr>");
|
||||
{/section}
|
||||
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>assigned template variables:</b></td></tr>");
|
||||
{section name=vars loop=$_debug_keys}
|
||||
_smarty_console.document.write("<tr bgcolor={if %vars.index% is even}#eeeeee{else}#fafafa{/if}><td valign=top><tt><font color=blue>{ldelim}${$_debug_keys[vars]}{rdelim}</font></tt></td><td nowrap><tt><font color=green>{$_debug_vals[vars]|@debug_print_var|escape:javascript}</font></tt></td></tr>");
|
||||
{sectionelse}
|
||||
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no template variables assigned</i></tt></td></tr>");
|
||||
{/section}
|
||||
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>assigned config file variables (outer template scope):</b></td></tr>");
|
||||
{section name=config_vars loop=$_debug_config_keys}
|
||||
_smarty_console.document.write("<tr bgcolor={if %config_vars.index% is even}#eeeeee{else}#fafafa{/if}><td valign=top><tt><font color=maroon>{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim}</font></tt></td><td><tt><font color=green>{$_debug_config_vals[config_vars]|@debug_print_var|escape:javascript}</font></tt></td></tr>");
|
||||
{sectionelse}
|
||||
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no config vars assigned</i></tt></td></tr>");
|
||||
{/section}
|
||||
_smarty_console.document.write("</table>");
|
||||
_smarty_console.document.write("</BODY></HTML>");
|
||||
_smarty_console.document.close();
|
||||
</SCRIPT>
|
||||
{/if}
|
||||
<script type="text/javascript">
|
||||
// <![CDATA[
|
||||
if ( self.name == '' ) {ldelim}
|
||||
var title = 'Console';
|
||||
{rdelim}
|
||||
else {ldelim}
|
||||
var title = 'Console_' + self.name;
|
||||
{rdelim}
|
||||
_smarty_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes");
|
||||
_smarty_console.document.write('{$debug_output|escape:'javascript'}');
|
||||
_smarty_console.document.close();
|
||||
// ]]>
|
||||
</script>
|
||||
{/if}
|
|
@ -22,7 +22,7 @@ function smarty_core_create_dir_structure($params, &$smarty)
|
|||
/* unix-style paths */
|
||||
$_dir = $params['dir'];
|
||||
$_dir_parts = preg_split('!/+!', $_dir, -1, PREG_SPLIT_NO_EMPTY);
|
||||
$_new_dir = ($_dir{0}=='/') ? '/' : getcwd().'/';
|
||||
$_new_dir = (substr($_dir, 0, 1)=='/') ? '/' : getcwd().'/';
|
||||
if($_use_open_basedir = !empty($_open_basedir_ini)) {
|
||||
$_open_basedirs = explode(':', $_open_basedir_ini);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ function smarty_core_display_debug_console($params, &$smarty)
|
|||
// set path to debug template from SMARTY_DIR
|
||||
$smarty->debug_tpl = SMARTY_DIR . 'debug.tpl';
|
||||
if($smarty->security && is_file($smarty->debug_tpl)) {
|
||||
$smarty->secure_dir[] = dirname(realpath($smarty->debug_tpl));
|
||||
$smarty->secure_dir[] = realpath($smarty->debug_tpl);
|
||||
}
|
||||
$smarty->debug_tpl = 'file:' . SMARTY_DIR . 'debug.tpl';
|
||||
}
|
||||
|
|
|
@ -27,18 +27,21 @@ function smarty_core_is_secure($params, &$smarty)
|
|||
foreach ((array)$params['resource_base_path'] as $curr_dir) {
|
||||
if ( ($_cd = realpath($curr_dir)) !== false &&
|
||||
strncmp($_rp, $_cd, strlen($_cd)) == 0 &&
|
||||
$_rp{strlen($_cd)} == DIRECTORY_SEPARATOR ) {
|
||||
substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($smarty->secure_dir)) {
|
||||
foreach ((array)$smarty->secure_dir as $curr_dir) {
|
||||
if ( ($_cd = realpath($curr_dir)) !== false &&
|
||||
strncmp($_rp, $_cd, strlen($_cd)) == 0 &&
|
||||
$_rp{strlen($_cd)} == DIRECTORY_SEPARATOR ) {
|
||||
return true;
|
||||
}
|
||||
if ( ($_cd = realpath($curr_dir)) !== false) {
|
||||
if($_cd == $_rp) {
|
||||
return true;
|
||||
} elseif (strncmp($_rp, $_cd, strlen($_cd)) == 0 &&
|
||||
substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -25,7 +25,7 @@ function smarty_core_is_trusted($params, &$smarty)
|
|||
if (!empty($curr_dir) && is_readable ($curr_dir)) {
|
||||
$_cd = realpath($curr_dir);
|
||||
if (strncmp($_rp, $_cd, strlen($_cd)) == 0
|
||||
&& $_rp{strlen($_cd)} == DIRECTORY_SEPARATOR ) {
|
||||
&& substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR ) {
|
||||
$_smarty_trusted = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ function smarty_core_process_cached_inserts($params, &$smarty)
|
|||
$replace = '';
|
||||
}
|
||||
|
||||
$params['results'] = str_replace($cached_inserts[$i], $replace, $params['results']);
|
||||
$params['results'] = substr_replace($params['results'], $replace, strpos($params['results'], $cached_inserts[$i]), strlen($cached_inserts[$i]));
|
||||
if ($smarty->debugging) {
|
||||
$_params = array();
|
||||
require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
|
||||
|
|
|
@ -20,7 +20,12 @@ function smarty_core_process_compiled_include($params, &$smarty)
|
|||
$smarty->_cache_including = true;
|
||||
|
||||
$_return = $params['results'];
|
||||
foreach ($smarty->_cache_serials as $_include_file_path=>$_cache_serial) {
|
||||
|
||||
foreach ($smarty->_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) {
|
||||
$smarty->_include($_include_file_path, true);
|
||||
}
|
||||
|
||||
foreach ($smarty->_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) {
|
||||
$_return = preg_replace_callback('!(\{nocache\:('.$_cache_serial.')#(\d+)\})!s',
|
||||
array(&$smarty, '_process_compiled_include_callback'),
|
||||
$_return);
|
||||
|
|
|
@ -90,16 +90,6 @@ function smarty_core_read_cache_file(&$params, &$smarty)
|
|||
}
|
||||
}
|
||||
|
||||
foreach ($_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) {
|
||||
if (empty($smarty->_cache_serials[$_include_file_path])) {
|
||||
$smarty->_include($_include_file_path, true);
|
||||
}
|
||||
|
||||
if ($smarty->_cache_serials[$_include_file_path] != $_cache_serial) {
|
||||
/* regenerate */
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']] = array($params['results'], $_cache_info);
|
||||
|
||||
$smarty->_cache_info = $_cache_info;
|
||||
|
|
|
@ -32,7 +32,6 @@ function smarty_core_rmdir($params, &$smarty)
|
|||
'level' => $params['level'] + 1,
|
||||
'exp_time' => $params['exp_time']
|
||||
);
|
||||
require_once(SMARTY_CORE_DIR . 'core.rmdir.php');
|
||||
smarty_core_rmdir($_params, $smarty);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -68,7 +68,7 @@ function smarty_core_write_cache_file($params, &$smarty)
|
|||
if (!empty($smarty->cache_handler_func)) {
|
||||
// use cache_handler function
|
||||
call_user_func_array($smarty->cache_handler_func,
|
||||
array('write', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], null));
|
||||
array('write', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], $smarty->_cache_info['expires']));
|
||||
} else {
|
||||
// use local cache file
|
||||
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
|
||||
function smarty_core_write_compiled_include($params, &$smarty)
|
||||
{
|
||||
$_tag_start = 'if \(\$this->caching && \!\$this->_cache_including\) \{ echo \'\{nocache\:('.$params['cache_serial'].')#(\d+)\}\';\}';
|
||||
$_tag_end = 'if \(\$this->caching && \!\$this->_cache_including\) \{ echo \'\{/nocache\:(\\2)#(\\3)\}\';\}';
|
||||
$_tag_start = 'if \(\$this->caching && \!\$this->_cache_including\)\: echo \'\{nocache\:('.$params['cache_serial'].')#(\d+)\}\'; endif;';
|
||||
$_tag_end = 'if \(\$this->caching && \!\$this->_cache_including\)\: echo \'\{/nocache\:(\\2)#(\\3)\}\'; endif;';
|
||||
|
||||
preg_match_all('!('.$_tag_start.'(.*)'.$_tag_end.')!Us',
|
||||
$params['compiled_content'], $_match_source, PREG_SET_ORDER);
|
||||
|
||||
|
||||
// no nocache-parts found: done
|
||||
if (count($_match_source)==0) return;
|
||||
|
||||
|
|
|
@ -23,8 +23,7 @@ function smarty_core_write_file($params, &$smarty)
|
|||
smarty_core_create_dir_structure($_params, $smarty);
|
||||
}
|
||||
|
||||
// write to tmp file, then rename it to avoid
|
||||
// file locking race condition
|
||||
// write to tmp file, then rename it to avoid file locking race condition
|
||||
$_tmp_file = tempnam($_dirname, 'wrt');
|
||||
|
||||
if (!($fd = @fopen($_tmp_file, 'wb'))) {
|
||||
|
@ -38,12 +37,13 @@ function smarty_core_write_file($params, &$smarty)
|
|||
fwrite($fd, $params['contents']);
|
||||
fclose($fd);
|
||||
|
||||
// Delete the file if it allready exists (this is needed on Win,
|
||||
// because it cannot overwrite files with rename()
|
||||
if (file_exists($params['filename'])) {
|
||||
if (DIRECTORY_SEPARATOR == '\\' || !@rename($_tmp_file, $params['filename'])) {
|
||||
// On platforms and filesystems that cannot overwrite with rename()
|
||||
// delete the file before renaming it -- because windows always suffers
|
||||
// this, it is short-circuited to avoid the initial rename() attempt
|
||||
@unlink($params['filename']);
|
||||
@rename($_tmp_file, $params['filename']);
|
||||
}
|
||||
@rename($_tmp_file, $params['filename']);
|
||||
@chmod($params['filename'], $smarty->_file_perms);
|
||||
|
||||
return true;
|
||||
|
@ -51,4 +51,4 @@ function smarty_core_write_file($params, &$smarty)
|
|||
|
||||
/* vim: set expandtab: */
|
||||
|
||||
?>
|
||||
?>
|
|
@ -23,6 +23,7 @@
|
|||
* indent_char: string (" ")
|
||||
* wrap_boundary: boolean (true)
|
||||
* </pre>
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string contents of the block
|
||||
* @param Smarty clever simulation of a method
|
||||
* @return string string $content re-formatted
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
* Purpose: assign a value to a template variable
|
||||
* @link http://smarty.php.net/manual/en/language.custom.functions.php#LANGUAGE.FUNCTION.ASSIGN {assign}
|
||||
* (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com> (initial author)
|
||||
* @author messju mohr <messju at lammfellpuschen dot de> (conversion to compiler function)
|
||||
* @param string containing var-attribute and value-attribute
|
||||
* @param Smarty_Compiler
|
||||
*/
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
* Type: function<br>
|
||||
* Name: assign_debug_info<br>
|
||||
* Purpose: assign debug info to the template<br>
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param array unused in this plugin, this plugin uses {@link Smarty::$_config},
|
||||
* {@link Smarty::$_tpl_vars} and {@link Smarty::$_smarty_debug_info}
|
||||
* @param Smarty
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
* Purpose: load config file vars
|
||||
* @link http://smarty.php.net/manual/en/language.function.config.load.php {config_load}
|
||||
* (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @author messju mohr <messju at lammfellpuschen dot de> (added use of resources)
|
||||
* @param array Format:
|
||||
* <pre>
|
||||
* array('file' => required config file name,
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
* Type: function<br>
|
||||
* Name: counter<br>
|
||||
* Purpose: print out a counter value
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @link http://smarty.php.net/manual/en/language.function.counter.php {counter}
|
||||
* (Smarty online manual)
|
||||
* @param array parameters
|
||||
|
|
|
@ -63,7 +63,11 @@ function smarty_function_cycle($params, &$smarty)
|
|||
$cycle_vars[$name]['values'] = $params['values'];
|
||||
}
|
||||
|
||||
$cycle_vars[$name]['delimiter'] = (isset($params['delimiter'])) ? $params['delimiter'] : ',';
|
||||
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'];
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: evaluate a template variable as a template<br>
|
||||
* @link http://smarty.php.net/manual/en/language.function.eval.php {eval}
|
||||
* (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param array
|
||||
* @param Smarty
|
||||
*/
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: fetch file, web or ftp data and display results
|
||||
* @link http://smarty.php.net/manual/en/language.function.fetch.php {fetch}
|
||||
* (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param array
|
||||
* @param Smarty
|
||||
* @return string|null if the assign parameter is passed, Smarty assigns the
|
||||
|
@ -180,12 +181,12 @@ function smarty_function_fetch($params, &$smarty)
|
|||
$content .= fgets($fp,4096);
|
||||
}
|
||||
fclose($fp);
|
||||
$csplit = split("\r\n\r\n",$content,2);
|
||||
$csplit = preg_split("!\r\n\r\n!",$content,2);
|
||||
|
||||
$content = $csplit[1];
|
||||
|
||||
if(!empty($params['assign_headers'])) {
|
||||
$smarty->assign($params['assign_headers'],split("\r\n",$csplit[0]));
|
||||
$smarty->assign($params['assign_headers'],preg_split("!\r\n!",$csplit[0]));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -19,9 +19,10 @@
|
|||
* - width = image width (optional, default actual width)
|
||||
* - basedir = base directory for absolute paths, default
|
||||
* is environment variable DOCUMENT_ROOT
|
||||
* - path_prefix = prefix for path output (optional, default empty)
|
||||
*
|
||||
* Examples: {html_image file="images/masthead.gif"}
|
||||
* Output: <img src="images/masthead.gif" width=400 height=23>
|
||||
* Examples: {html_image file="/images/masthead.gif"}
|
||||
* Output: <img src="/images/masthead.gif" width=400 height=23>
|
||||
* @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image}
|
||||
* (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
|
@ -44,6 +45,7 @@ function smarty_function_html_image($params, &$smarty)
|
|||
$extra = '';
|
||||
$prefix = '';
|
||||
$suffix = '';
|
||||
$path_prefix = '';
|
||||
$server_vars = ($smarty->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
|
||||
$basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : '';
|
||||
foreach($params as $_key => $_val) {
|
||||
|
@ -52,6 +54,7 @@ function smarty_function_html_image($params, &$smarty)
|
|||
case 'height':
|
||||
case 'width':
|
||||
case 'dpi':
|
||||
case 'path_prefix':
|
||||
case 'basedir':
|
||||
$$_key = $_val;
|
||||
break;
|
||||
|
@ -90,15 +93,9 @@ function smarty_function_html_image($params, &$smarty)
|
|||
} else {
|
||||
$_image_path = $file;
|
||||
}
|
||||
|
||||
|
||||
if(!isset($params['width']) || !isset($params['height'])) {
|
||||
if ($smarty->security &&
|
||||
($_params = array('resource_type' => 'file', 'resource_name' => $_image_path)) &&
|
||||
(require_once(SMARTY_CORE_DIR . 'core.is_secure.php')) &&
|
||||
(!smarty_core_is_secure($_params, $smarty)) ) {
|
||||
$smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE);
|
||||
|
||||
} elseif (!$_image_data = @getimagesize($_image_path)) {
|
||||
if(!$_image_data = @getimagesize($_image_path)) {
|
||||
if(!file_exists($_image_path)) {
|
||||
$smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
|
||||
return;
|
||||
|
@ -110,7 +107,13 @@ function smarty_function_html_image($params, &$smarty)
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($smarty->security &&
|
||||
($_params = array('resource_type' => 'file', 'resource_name' => $_image_path)) &&
|
||||
(require_once(SMARTY_CORE_DIR . 'core.is_secure.php')) &&
|
||||
(!smarty_core_is_secure($_params, $smarty)) ) {
|
||||
$smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE);
|
||||
}
|
||||
|
||||
if(!isset($params['width'])) {
|
||||
$width = $_image_data[0];
|
||||
}
|
||||
|
@ -131,7 +134,7 @@ function smarty_function_html_image($params, &$smarty)
|
|||
$height = round($height * $_resize);
|
||||
}
|
||||
|
||||
return $prefix . '<img src="'.$file.'" alt="'.$alt.'" width="'.$width.'" height="'.$height.'"'.$extra.' />' . $suffix;
|
||||
return $prefix . '<img src="'.$path_prefix.$file.'" alt="'.$alt.'" width="'.$width.'" height="'.$height.'"'.$extra.' />' . $suffix;
|
||||
}
|
||||
|
||||
/* vim: set expandtab: */
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
* - options (required if no values supplied) - associative array
|
||||
* - selected (optional) - string default not set
|
||||
* - output (required if not options supplied) - array
|
||||
* - disabled (optional) - string default not set (added by Yogin)
|
||||
* Purpose: Prints the list of <option> tags generated from
|
||||
* the passed parameters
|
||||
* @link http://smarty.php.net/manual/en/language.function.html.options.php {html_image}
|
||||
* (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param array
|
||||
* @param Smarty
|
||||
* @return string
|
||||
|
@ -30,26 +30,25 @@
|
|||
function smarty_function_html_options($params, &$smarty)
|
||||
{
|
||||
require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
|
||||
|
||||
|
||||
$name = null;
|
||||
$values = null;
|
||||
$options = null;
|
||||
$selected = array();
|
||||
$disabled = array();
|
||||
$output = null;
|
||||
|
||||
|
||||
$extra = '';
|
||||
|
||||
|
||||
foreach($params as $_key => $_val) {
|
||||
switch($_key) {
|
||||
case 'name':
|
||||
$$_key = (string)$_val;
|
||||
break;
|
||||
|
||||
|
||||
case 'options':
|
||||
$$_key = (array)$_val;
|
||||
break;
|
||||
|
||||
|
||||
case 'values':
|
||||
case 'output':
|
||||
$$_key = array_values((array)$_val);
|
||||
|
@ -58,12 +57,7 @@ function smarty_function_html_options($params, &$smarty)
|
|||
case 'selected':
|
||||
$$_key = array_map('strval', array_values((array)$_val));
|
||||
break;
|
||||
|
||||
case 'disabled':
|
||||
$$_key = array_map('strval', array_values((array)$_val));
|
||||
break;
|
||||
|
||||
|
||||
|
||||
default:
|
||||
if(!is_array($_val)) {
|
||||
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
|
||||
|
@ -80,15 +74,15 @@ function smarty_function_html_options($params, &$smarty)
|
|||
$_html_result = '';
|
||||
|
||||
if (isset($options)) {
|
||||
|
||||
|
||||
foreach ($options as $_key=>$_val)
|
||||
$_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $disabled);
|
||||
$_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected);
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
foreach ($values as $_i=>$_key) {
|
||||
$_val = isset($output[$_i]) ? $output[$_i] : '';
|
||||
$_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $disabled);
|
||||
$_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -101,27 +95,23 @@ function smarty_function_html_options($params, &$smarty)
|
|||
|
||||
}
|
||||
|
||||
function smarty_function_html_options_optoutput($key, $value, $selected, $disabled) {
|
||||
function smarty_function_html_options_optoutput($key, $value, $selected) {
|
||||
if(!is_array($value)) {
|
||||
$_html_result = '<option label="' . smarty_function_escape_special_chars($value) . '" value="' .
|
||||
smarty_function_escape_special_chars($key) . '"';
|
||||
if (in_array((string)$key, $selected))
|
||||
$_html_result .= ' selected="selected"';
|
||||
|
||||
if (in_array((string)$key, $disabled))
|
||||
$_html_result .= ' disabled';
|
||||
|
||||
$_html_result .= '>' . smarty_function_escape_special_chars($value) . '</option>' . "\n";
|
||||
} else {
|
||||
$_html_result = smarty_function_html_options_optgroup($key, $value, $selected, $disabled);
|
||||
$_html_result = smarty_function_html_options_optgroup($key, $value, $selected);
|
||||
}
|
||||
return $_html_result;
|
||||
}
|
||||
|
||||
function smarty_function_html_options_optgroup($key, $values, $selected, $disabled) {
|
||||
function smarty_function_html_options_optgroup($key, $values, $selected) {
|
||||
$optgroup_html = '<optgroup label="' . smarty_function_escape_special_chars($key) . '">' . "\n";
|
||||
foreach ($values as $key => $value) {
|
||||
$optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected, $disabled);
|
||||
$optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected);
|
||||
}
|
||||
$optgroup_html .= "</optgroup>\n";
|
||||
return $optgroup_html;
|
||||
|
|
|
@ -48,6 +48,7 @@ function smarty_function_html_radios($params, &$smarty)
|
|||
$selected = null;
|
||||
$separator = '';
|
||||
$labels = true;
|
||||
$label_ids = false;
|
||||
$output = null;
|
||||
$extra = '';
|
||||
|
||||
|
@ -68,6 +69,7 @@ function smarty_function_html_radios($params, &$smarty)
|
|||
break;
|
||||
|
||||
case 'labels':
|
||||
case 'label_ids':
|
||||
$$_key = (bool)$_val;
|
||||
break;
|
||||
|
||||
|
@ -106,13 +108,13 @@ function smarty_function_html_radios($params, &$smarty)
|
|||
if (isset($options)) {
|
||||
|
||||
foreach ($options as $_key=>$_val)
|
||||
$_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
|
||||
$_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids);
|
||||
|
||||
} 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);
|
||||
$_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -125,19 +127,23 @@ function smarty_function_html_radios($params, &$smarty)
|
|||
|
||||
}
|
||||
|
||||
function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels) {
|
||||
function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids) {
|
||||
$_output = '';
|
||||
if ($labels) {
|
||||
$_id = smarty_function_escape_special_chars($name . '_' . $value);
|
||||
$_output .= '<label for="' . $_id . '">';
|
||||
if($label_ids) {
|
||||
$_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!', '_', $name . '_' . $value));
|
||||
$_output .= '<label for="' . $_id . '">';
|
||||
} else {
|
||||
$_output .= '<label>';
|
||||
}
|
||||
}
|
||||
$_output .= '<input type="radio" name="'
|
||||
. smarty_function_escape_special_chars($name) . '" value="'
|
||||
. smarty_function_escape_special_chars($value) . '"';
|
||||
|
||||
if ($labels) $_output .= ' id="' . $_id . '"';
|
||||
if ($labels && $label_ids) $_output .= ' id="' . $_id . '"';
|
||||
|
||||
if ($value==$selected) {
|
||||
if ((string)$value==$selected) {
|
||||
$_output .= ' checked="checked"';
|
||||
}
|
||||
$_output .= $extra . ' />' . $output;
|
||||
|
|
|
@ -22,18 +22,22 @@
|
|||
* month values (Gary Loescher)
|
||||
* - 1.3.1 added support for choosing format for
|
||||
* day values (Marcus Bointon)
|
||||
* - 1.3.2 suppport negative timestamps, force year
|
||||
* - 1.3.2 support negative timestamps, force year
|
||||
* dropdown to include given date unless explicitly set (Monte)
|
||||
* - 1.3.4 fix behaviour of 0000-00-00 00:00:00 dates to match that
|
||||
* of 0000-00-00 dates (cybot, boots)
|
||||
* @link http://smarty.php.net/manual/en/language.function.html.select.date.php {html_select_date}
|
||||
* (Smarty online manual)
|
||||
* @version 1.3.2
|
||||
* @author Andrei Zmievski
|
||||
* @version 1.3.4
|
||||
* @author Andrei Zmievski
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param array
|
||||
* @param Smarty
|
||||
* @return string
|
||||
*/
|
||||
function smarty_function_html_select_date($params, &$smarty)
|
||||
{
|
||||
require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
|
||||
require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
|
||||
require_once $smarty->_get_plugin_filepath('function','html_options');
|
||||
/* Default values. */
|
||||
|
@ -78,6 +82,7 @@ function smarty_function_html_select_date($params, &$smarty)
|
|||
$day_empty = null;
|
||||
$month_empty = null;
|
||||
$year_empty = null;
|
||||
$extra_attrs = '';
|
||||
|
||||
foreach ($params as $_key=>$_value) {
|
||||
switch ($_key) {
|
||||
|
@ -119,24 +124,30 @@ function smarty_function_html_select_date($params, &$smarty)
|
|||
break;
|
||||
|
||||
default:
|
||||
$smarty->trigger_error("[html_select_date] unknown parameter $_key", E_USER_WARNING);
|
||||
|
||||
if(!is_array($_value)) {
|
||||
$extra_attrs .= ' '.$_key.'="'.smarty_function_escape_special_chars($_value).'"';
|
||||
} else {
|
||||
$smarty->trigger_error("html_select_date: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(preg_match('!^-\d+$!',$time)) {
|
||||
if (preg_match('!^-\d+$!', $time)) {
|
||||
// negative timestamp, use date()
|
||||
$time = date('Y-m-d',$time);
|
||||
$time = date('Y-m-d', $time);
|
||||
}
|
||||
// If $time is not in format yyyy-mm-dd
|
||||
if (!preg_match('/^\d{0,4}-\d{0,2}-\d{0,2}$/', $time)) {
|
||||
if (preg_match('/^(\d{0,4}-\d{0,2}-\d{0,2})/', $time, $found)) {
|
||||
$time = $found[1];
|
||||
} else {
|
||||
// use smarty_make_timestamp to get an unix timestamp and
|
||||
// strftime to make yyyy-mm-dd
|
||||
$time = strftime('%Y-%m-%d', smarty_make_timestamp($time));
|
||||
}
|
||||
// Now split this in pieces, which later can be used to set the select
|
||||
$time = explode("-", $time);
|
||||
|
||||
|
||||
// make syntax "+N" or "-N" work with start_year and end_year
|
||||
if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) {
|
||||
if ($match[1] == '+') {
|
||||
|
@ -152,7 +163,7 @@ function smarty_function_html_select_date($params, &$smarty)
|
|||
$start_year = strftime('%Y') - $match[2];
|
||||
}
|
||||
}
|
||||
if (strlen($time[0]) > 0) {
|
||||
if (strlen($time[0]) > 0) {
|
||||
if ($start_year > $time[0] && !isset($params['start_year'])) {
|
||||
// force start year to include given date if not explicitly set
|
||||
$start_year = $time[0];
|
||||
|
@ -167,7 +178,9 @@ function smarty_function_html_select_date($params, &$smarty)
|
|||
|
||||
$html_result = $month_result = $day_result = $year_result = "";
|
||||
|
||||
$field_separator_count = -1;
|
||||
if ($display_months) {
|
||||
$field_separator_count++;
|
||||
$month_names = array();
|
||||
$month_values = array();
|
||||
if(isset($month_empty)) {
|
||||
|
@ -194,17 +207,18 @@ function smarty_function_html_select_date($params, &$smarty)
|
|||
if (null !== $all_extra){
|
||||
$month_result .= ' ' . $all_extra;
|
||||
}
|
||||
$month_result .= '>'."\n";
|
||||
$month_result .= $extra_attrs . '>'."\n";
|
||||
|
||||
$month_result .= smarty_function_html_options(array('output' => $month_names,
|
||||
'values' => $month_values,
|
||||
'selected' => $a=$time[1] ? strftime($month_value_format, mktime(0, 0, 0, (int)$time[1], 1, 2000)) : '',
|
||||
'selected' => (int)$time[1] ? strftime($month_value_format, mktime(0, 0, 0, (int)$time[1], 1, 2000)) : '',
|
||||
'print_result' => false),
|
||||
$smarty);
|
||||
$month_result .= '</select>';
|
||||
}
|
||||
|
||||
if ($display_days) {
|
||||
$field_separator_count++;
|
||||
$days = array();
|
||||
if (isset($day_empty)) {
|
||||
$days[''] = $day_empty;
|
||||
|
@ -230,7 +244,7 @@ function smarty_function_html_select_date($params, &$smarty)
|
|||
if (null !== $day_extra){
|
||||
$day_result .= ' ' . $day_extra;
|
||||
}
|
||||
$day_result .= '>'."\n";
|
||||
$day_result .= $extra_attrs . '>'."\n";
|
||||
$day_result .= smarty_function_html_options(array('output' => $days,
|
||||
'values' => $day_values,
|
||||
'selected' => $time[2],
|
||||
|
@ -240,6 +254,7 @@ function smarty_function_html_select_date($params, &$smarty)
|
|||
}
|
||||
|
||||
if ($display_years) {
|
||||
$field_separator_count++;
|
||||
if (null !== $field_array){
|
||||
$year_name = $field_array . '[' . $prefix . 'Year]';
|
||||
} else {
|
||||
|
@ -253,7 +268,7 @@ function smarty_function_html_select_date($params, &$smarty)
|
|||
if (null !== $year_extra){
|
||||
$year_result .= ' ' . $year_extra;
|
||||
}
|
||||
$year_result .= '>';
|
||||
$year_result .= ' />';
|
||||
} else {
|
||||
$years = range((int)$start_year, (int)$end_year);
|
||||
if ($reverse_years) {
|
||||
|
@ -276,7 +291,7 @@ function smarty_function_html_select_date($params, &$smarty)
|
|||
if (null !== $year_extra){
|
||||
$year_result .= ' ' . $year_extra;
|
||||
}
|
||||
$year_result .= '>'."\n";
|
||||
$year_result .= $extra_attrs . '>'."\n";
|
||||
$year_result .= smarty_function_html_options(array('output' => $years,
|
||||
'values' => $yearvals,
|
||||
'selected' => $time[0],
|
||||
|
@ -303,7 +318,7 @@ function smarty_function_html_select_date($params, &$smarty)
|
|||
break;
|
||||
}
|
||||
// Add the field seperator
|
||||
if($i != 2) {
|
||||
if($i < $field_separator_count) {
|
||||
$html_result .= $field_separator;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
* Purpose: Prints the dropdowns for time selection
|
||||
* @link http://smarty.php.net/manual/en/language.function.html.select.time.php {html_select_time}
|
||||
* (Smarty online manual)
|
||||
* @author Roberto Berto <roberto@berto.net>
|
||||
* @credits Monte Ohrt <monte AT ohrt DOT com>
|
||||
* @param array
|
||||
* @param Smarty
|
||||
* @return string
|
||||
|
|
|
@ -15,12 +15,15 @@
|
|||
* Purpose: make an html table from an array of data<br>
|
||||
* Input:<br>
|
||||
* - loop = array to loop through
|
||||
* - cols = number of columns
|
||||
* - cols = number of columns, comma separated list of column names
|
||||
* or array of column names
|
||||
* - rows = number of rows
|
||||
* - table_attr = table attributes
|
||||
* - th_attr = table heading attributes (arrays are cycled)
|
||||
* - tr_attr = table row attributes (arrays are cycled)
|
||||
* - td_attr = table cell attributes (arrays are cycled)
|
||||
* - trailpad = value to pad trailing cells with
|
||||
* - caption = text for caption element
|
||||
* - vdir = vertical direction (default: "down", means top-to-bottom)
|
||||
* - hdir = horizontal direction (default: "right", means left-to-right)
|
||||
* - inner = inner loop (default "cols": print $loop line by line,
|
||||
|
@ -31,10 +34,12 @@
|
|||
* <pre>
|
||||
* {table loop=$data}
|
||||
* {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
|
||||
* {table loop=$data cols=4 tr_attr=$colors}
|
||||
* {table loop=$data cols="first,second,third" tr_attr=$colors}
|
||||
* </pre>
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @version 1.0
|
||||
* @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://smarty.php.net/manual/en/language.function.html.table.php {html_table}
|
||||
* (Smarty online manual)
|
||||
* @param array
|
||||
|
@ -45,13 +50,15 @@ function smarty_function_html_table($params, &$smarty)
|
|||
{
|
||||
$table_attr = 'border="1"';
|
||||
$tr_attr = '';
|
||||
$th_attr = '';
|
||||
$td_attr = '';
|
||||
$cols = 3;
|
||||
$cols = $cols_count = 3;
|
||||
$rows = 3;
|
||||
$trailpad = ' ';
|
||||
$vdir = 'down';
|
||||
$hdir = 'right';
|
||||
$inner = 'cols';
|
||||
$caption = '';
|
||||
|
||||
if (!isset($params['loop'])) {
|
||||
$smarty->trigger_error("html_table: missing 'loop' parameter");
|
||||
|
@ -65,6 +72,19 @@ function smarty_function_html_table($params, &$smarty)
|
|||
break;
|
||||
|
||||
case 'cols':
|
||||
if (is_array($_value) && !empty($_value)) {
|
||||
$cols = $_value;
|
||||
$cols_count = count($_value);
|
||||
} elseif (!is_numeric($_value) && is_string($_value) && !empty($_value)) {
|
||||
$cols = explode(',', $_value);
|
||||
$cols_count = count($cols);
|
||||
} elseif (!empty($_value)) {
|
||||
$cols_count = (int)$_value;
|
||||
} else {
|
||||
$cols_count = $cols;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'rows':
|
||||
$$_key = (int)$_value;
|
||||
break;
|
||||
|
@ -74,11 +94,13 @@ function smarty_function_html_table($params, &$smarty)
|
|||
case 'hdir':
|
||||
case 'vdir':
|
||||
case 'inner':
|
||||
case 'caption':
|
||||
$$_key = (string)$_value;
|
||||
break;
|
||||
|
||||
case 'tr_attr':
|
||||
case 'td_attr':
|
||||
case 'th_attr':
|
||||
$$_key = $_value;
|
||||
break;
|
||||
}
|
||||
|
@ -87,25 +109,42 @@ function smarty_function_html_table($params, &$smarty)
|
|||
$loop_count = count($loop);
|
||||
if (empty($params['rows'])) {
|
||||
/* no rows specified */
|
||||
$rows = ceil($loop_count/$cols);
|
||||
$rows = ceil($loop_count/$cols_count);
|
||||
} elseif (empty($params['cols'])) {
|
||||
if (!empty($params['rows'])) {
|
||||
/* no cols specified, but rows */
|
||||
$cols = ceil($loop_count/$rows);
|
||||
$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++) {
|
||||
$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++) {
|
||||
$output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n";
|
||||
$rx = ($vdir == 'down') ? $r*$cols : ($rows-1-$r)*$cols;
|
||||
$rx = ($vdir == 'down') ? $r*$cols_count : ($rows-1-$r)*$cols_count;
|
||||
|
||||
for ($c=0; $c<$cols; $c++) {
|
||||
$x = ($hdir == 'right') ? $rx+$c : $rx+$cols-1-$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) + ($x%$cols)*$rows;
|
||||
$x = floor($x/$cols_count) + ($x%$cols_count)*$rows;
|
||||
}
|
||||
|
||||
if ($x<$loop_count) {
|
||||
|
@ -116,6 +155,7 @@ function smarty_function_html_table($params, &$smarty)
|
|||
}
|
||||
$output .= "</tr>\n";
|
||||
}
|
||||
$output .= "</tbody>\n";
|
||||
$output .= "</table>\n";
|
||||
|
||||
return $output;
|
||||
|
|
|
@ -62,6 +62,8 @@ function smarty_function_mailto($params, &$smarty)
|
|||
|
||||
// netscape and mozilla do not decode %40 (@) in BCC field (bug?)
|
||||
// so, don't encode it.
|
||||
$search = array('%40', '%2C');
|
||||
$replace = array('@', ',');
|
||||
$mail_parms = array();
|
||||
foreach ($params as $var=>$value) {
|
||||
switch ($var) {
|
||||
|
@ -69,7 +71,7 @@ function smarty_function_mailto($params, &$smarty)
|
|||
case 'bcc':
|
||||
case 'followupto':
|
||||
if (!empty($value))
|
||||
$mail_parms[] = $var.'='.str_replace('%40','@',rawurlencode($value));
|
||||
$mail_parms[] = $var.'='.str_replace($search,$replace,rawurlencode($value));
|
||||
break;
|
||||
|
||||
case 'subject':
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: handle math computations in template<br>
|
||||
* @link http://smarty.php.net/manual/en/language.function.math.php {math}
|
||||
* (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param array
|
||||
* @param Smarty
|
||||
* @return string
|
||||
|
@ -26,7 +27,8 @@ function smarty_function_math($params, &$smarty)
|
|||
return;
|
||||
}
|
||||
|
||||
$equation = $params['equation'];
|
||||
// strip out backticks, not necessary for math
|
||||
$equation = str_replace('`','',$params['equation']);
|
||||
|
||||
// make sure parenthesis are balanced
|
||||
if (substr_count($equation,"(") != substr_count($equation,")")) {
|
||||
|
@ -35,7 +37,7 @@ function smarty_function_math($params, &$smarty)
|
|||
}
|
||||
|
||||
// match all vars in equation, make sure all are passed
|
||||
preg_match_all("!(?:0x[a-fA-F0-9]+)|([a-zA-Z][a-zA-Z0-9_]+)!",$equation, $match);
|
||||
preg_match_all("!(?:0x[a-fA-F0-9]+)|([a-zA-Z][a-zA-Z0-9_]*)!",$equation, $match);
|
||||
$allowed_funcs = array('int','abs','ceil','cos','exp','floor','log','log10',
|
||||
'max','min','pi','pow','rand','round','sin','sqrt','srand','tan');
|
||||
|
||||
|
@ -57,7 +59,7 @@ function smarty_function_math($params, &$smarty)
|
|||
$smarty->trigger_error("math: parameter $key: is not numeric");
|
||||
return;
|
||||
}
|
||||
$equation = preg_replace("/\b$key\b/",$val, $equation);
|
||||
$equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,4 +82,4 @@ function smarty_function_math($params, &$smarty)
|
|||
|
||||
/* vim: set expandtab: */
|
||||
|
||||
?>
|
||||
?>
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: make text pop up in windows via overlib
|
||||
* @link http://smarty.php.net/manual/en/language.function.popup.php {popup}
|
||||
* (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param array
|
||||
* @param Smarty
|
||||
* @return string
|
||||
|
@ -88,6 +89,7 @@ function smarty_function_popup($params, &$smarty)
|
|||
case 'vauto':
|
||||
case 'mouseoff':
|
||||
case 'followmouse':
|
||||
case 'closeclick':
|
||||
if ($_value) $append .= ',' . strtoupper($_key);
|
||||
break;
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: initialize overlib
|
||||
* @link http://smarty.php.net/manual/en/language.function.popup.init.php {popup_init}
|
||||
* (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param array
|
||||
* @param Smarty
|
||||
* @return string
|
||||
|
|
|
@ -14,13 +14,14 @@
|
|||
* Purpose: capitalize words in the string
|
||||
* @link http://smarty.php.net/manual/en/language.modifiers.php#LANGUAGE.MODIFIER.CAPITALIZE
|
||||
* capitalize (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function smarty_modifier_capitalize($string, $uc_digits = false)
|
||||
{
|
||||
smarty_modifier_capitalize_ucfirst(null, $uc_digits);
|
||||
return preg_replace_callback('!\b\w+\b!', 'smarty_modifier_capitalize_ucfirst', $string);
|
||||
return preg_replace_callback('!\'?\b\w(\w|\')*\b!', 'smarty_modifier_capitalize_ucfirst', $string);
|
||||
}
|
||||
|
||||
function smarty_modifier_capitalize_ucfirst($string, $uc_digits = null)
|
||||
|
@ -32,7 +33,7 @@ function smarty_modifier_capitalize_ucfirst($string, $uc_digits = null)
|
|||
return;
|
||||
}
|
||||
|
||||
if(!preg_match('!\d!',$string[0]) || $_uc_digits)
|
||||
if(substr($string[0],0,1) != "'" && !preg_match("!\d!",$string[0]) || $_uc_digits)
|
||||
return ucfirst($string[0]);
|
||||
else
|
||||
return $string[0];
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: count the number of characters in a text
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.count.characters.php
|
||||
* count_characters (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @param boolean include whitespace in the character count
|
||||
* @return integer
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: count the number of paragraphs in a text
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.count.paragraphs.php
|
||||
* count_paragraphs (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @return integer
|
||||
*/
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: count the number of sentences in a text
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.count.paragraphs.php
|
||||
* count_sentences (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @return integer
|
||||
*/
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: count the number of words in a text
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.count.words.php
|
||||
* count_words (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @return integer
|
||||
*/
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
/**
|
||||
* Include the {@link shared.make_timestamp.php} plugin
|
||||
*/
|
||||
require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
|
||||
require_once $smarty->_get_plugin_filepath('shared', 'make_timestamp');
|
||||
/**
|
||||
* Smarty date_format modifier plugin
|
||||
*
|
||||
|
@ -21,26 +21,36 @@ require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
|
|||
* - default_date: default date if $string is empty
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.date.format.php
|
||||
* date_format (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @param string
|
||||
* @param string
|
||||
* @return string|void
|
||||
* @uses smarty_make_timestamp()
|
||||
*/
|
||||
function smarty_modifier_date_format($string, $format="%b %e, %Y", $default_date=null)
|
||||
function smarty_modifier_date_format($string, $format = '%b %e, %Y', $default_date = '')
|
||||
{
|
||||
if (substr(PHP_OS,0,3) == 'WIN') {
|
||||
$_win_from = array ('%e', '%T', '%D');
|
||||
$_win_to = array ('%#d', '%H:%M:%S', '%m/%d/%y');
|
||||
$format = str_replace($_win_from, $_win_to, $format);
|
||||
}
|
||||
if($string != '') {
|
||||
return strftime($format, smarty_make_timestamp($string));
|
||||
} elseif (isset($default_date) && $default_date != '') {
|
||||
return strftime($format, smarty_make_timestamp($default_date));
|
||||
if ($string != '') {
|
||||
$timestamp = smarty_make_timestamp($string);
|
||||
} elseif ($default_date != '') {
|
||||
$timestamp = smarty_make_timestamp($default_date);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (DIRECTORY_SEPARATOR == '\\') {
|
||||
$_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));
|
||||
}
|
||||
if (strpos($format, '%l') !== false) {
|
||||
$_win_from[] = '%l';
|
||||
$_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
|
||||
}
|
||||
$format = str_replace($_win_from, $_win_to, $format);
|
||||
}
|
||||
return strftime($format, $timestamp);
|
||||
}
|
||||
|
||||
/* vim: set expandtab: */
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: formats variable contents for display in the console
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.debug.print.var.php
|
||||
* debug_print_var (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param array|object
|
||||
* @param integer
|
||||
* @param integer
|
||||
|
@ -21,33 +22,66 @@
|
|||
*/
|
||||
function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
|
||||
{
|
||||
$_replace = array("\n"=>'<i>\n</i>', "\r"=>'<i>\r</i>', "\t"=>'<i>\t</i>');
|
||||
if (is_array($var)) {
|
||||
$results = "<b>Array (".count($var).")</b>";
|
||||
foreach ($var as $curr_key => $curr_val) {
|
||||
$return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
|
||||
$results .= "<br>".str_repeat(' ', $depth*2)."<b>".strtr($curr_key, $_replace)."</b> => $return";
|
||||
}
|
||||
} else if (is_object($var)) {
|
||||
$object_vars = get_object_vars($var);
|
||||
$results = "<b>".get_class($var)." Object (".count($object_vars).")</b>";
|
||||
foreach ($object_vars as $curr_key => $curr_val) {
|
||||
$return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
|
||||
$results .= "<br>".str_repeat(' ', $depth*2)."<b>$curr_key</b> => $return";
|
||||
}
|
||||
} else if (is_resource($var)) {
|
||||
$results = '<i>'.(string)$var.'</i>';
|
||||
} else if (empty($var) && $var != "0") {
|
||||
$results = '<i>empty</i>';
|
||||
} else {
|
||||
if (strlen($var) > $length ) {
|
||||
$results = substr($var, 0, $length-3).'...';
|
||||
} else {
|
||||
$results = $var;
|
||||
}
|
||||
$results = htmlspecialchars($results);
|
||||
$results = strtr($results, $_replace);
|
||||
$_replace = array(
|
||||
"\n" => '<i>\n</i>',
|
||||
"\r" => '<i>\r</i>',
|
||||
"\t" => '<i>\t</i>'
|
||||
);
|
||||
|
||||
switch (gettype($var)) {
|
||||
case 'array' :
|
||||
$results = '<b>Array (' . count($var) . ')</b>';
|
||||
foreach ($var as $curr_key => $curr_val) {
|
||||
$results .= '<br>' . str_repeat(' ', $depth * 2)
|
||||
. '<b>' . strtr($curr_key, $_replace) . '</b> => '
|
||||
. smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
|
||||
$depth--;
|
||||
}
|
||||
break;
|
||||
case 'object' :
|
||||
$object_vars = get_object_vars($var);
|
||||
$results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>';
|
||||
foreach ($object_vars as $curr_key => $curr_val) {
|
||||
$results .= '<br>' . str_repeat(' ', $depth * 2)
|
||||
. '<b> ->' . strtr($curr_key, $_replace) . '</b> = '
|
||||
. smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
|
||||
$depth--;
|
||||
}
|
||||
break;
|
||||
case 'boolean' :
|
||||
case 'NULL' :
|
||||
case 'resource' :
|
||||
if (true === $var) {
|
||||
$results = 'true';
|
||||
} elseif (false === $var) {
|
||||
$results = 'false';
|
||||
} elseif (null === $var) {
|
||||
$results = 'null';
|
||||
} else {
|
||||
$results = htmlspecialchars((string) $var);
|
||||
}
|
||||
$results = '<i>' . $results . '</i>';
|
||||
break;
|
||||
case 'integer' :
|
||||
case 'float' :
|
||||
$results = htmlspecialchars((string) $var);
|
||||
break;
|
||||
case 'string' :
|
||||
$results = strtr($var, $_replace);
|
||||
if (strlen($var) > $length ) {
|
||||
$results = substr($var, 0, $length - 3) . '...';
|
||||
}
|
||||
$results = htmlspecialchars('"' . $results . '"');
|
||||
break;
|
||||
case 'unknown type' :
|
||||
default :
|
||||
$results = strtr((string) $var, $_replace);
|
||||
if (strlen($results) > $length ) {
|
||||
$results = substr($results, 0, $length - 3) . '...';
|
||||
}
|
||||
$results = htmlspecialchars($results);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: designate default value for empty variables
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.default.php
|
||||
* default (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @param string
|
||||
* @return string
|
||||
|
|
|
@ -14,22 +14,26 @@
|
|||
* Purpose: Escape the string according to escapement type
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.escape.php
|
||||
* escape (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @param html|htmlall|url|quotes|hex|hexentity|javascript
|
||||
* @return string
|
||||
*/
|
||||
function smarty_modifier_escape($string, $esc_type = 'html')
|
||||
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = 'ISO-8859-1')
|
||||
{
|
||||
switch ($esc_type) {
|
||||
case 'html':
|
||||
return htmlspecialchars($string, ENT_QUOTES);
|
||||
return htmlspecialchars($string, ENT_QUOTES, $char_set);
|
||||
|
||||
case 'htmlall':
|
||||
return htmlentities($string, ENT_QUOTES);
|
||||
return htmlentities($string, ENT_QUOTES, $char_set);
|
||||
|
||||
case 'url':
|
||||
return rawurlencode($string);
|
||||
|
||||
case 'urlpathinfo':
|
||||
return str_replace('%2F','/',rawurlencode($string));
|
||||
|
||||
case 'quotes':
|
||||
// escape unescaped single quotes
|
||||
return preg_replace("%(?<!\\\\)'%", "\\'", $string);
|
||||
|
@ -68,13 +72,13 @@ function smarty_modifier_escape($string, $esc_type = 'html')
|
|||
// escape non-standard chars, such as ms document quotes
|
||||
$_res = '';
|
||||
for($_i = 0, $_len = strlen($string); $_i < $_len; $_i++) {
|
||||
$_ord = ord($string{$_i});
|
||||
$_ord = ord(substr($string, $_i, 1));
|
||||
// non-standard char, escape it
|
||||
if($_ord >= 126){
|
||||
$_res .= '&#' . $_ord . ';';
|
||||
}
|
||||
else {
|
||||
$_res .= $string{$_i};
|
||||
$_res .= substr($string, $_i, 1);
|
||||
}
|
||||
}
|
||||
return $_res;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: indent lines of text
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.indent.php
|
||||
* indent (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @param integer
|
||||
* @param string
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: convert string to lowercase
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.lower.php
|
||||
* lower (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -11,9 +11,10 @@
|
|||
*
|
||||
* Type: modifier<br>
|
||||
* Name: regex_replace<br>
|
||||
* Purpose: regular epxression search/replace
|
||||
* Purpose: regular expression search/replace
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php
|
||||
* regex_replace (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @param string|array
|
||||
* @param string|array
|
||||
|
@ -21,13 +22,27 @@
|
|||
*/
|
||||
function smarty_modifier_regex_replace($string, $search, $replace)
|
||||
{
|
||||
if (preg_match('!\W(\w+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) {
|
||||
/* remove eval-modifier from $search */
|
||||
$search = substr($search, 0, -strlen($match[1])) . str_replace('e', '', $match[1]);
|
||||
}
|
||||
if(is_array($search)) {
|
||||
foreach($search as $idx => $s)
|
||||
$search[$idx] = _smarty_regex_replace_check($s);
|
||||
} else {
|
||||
$search = _smarty_regex_replace_check($search);
|
||||
}
|
||||
|
||||
return preg_replace($search, $replace, $string);
|
||||
}
|
||||
|
||||
function _smarty_regex_replace_check($search)
|
||||
{
|
||||
if (($pos = strpos($search,"\0")) !== false)
|
||||
$search = substr($search,0,$pos);
|
||||
if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) {
|
||||
/* remove eval-modifier from $search */
|
||||
$search = substr($search, 0, -strlen($match[1])) . preg_replace('![e\s]+!', '', $match[1]);
|
||||
}
|
||||
return $search;
|
||||
}
|
||||
|
||||
/* vim: set expandtab: */
|
||||
|
||||
?>
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: simple search/replace
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.replace.php
|
||||
* replace (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @param string
|
||||
* @param string
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: add spaces between characters in a string
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.spacify.php
|
||||
* spacify (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @param string
|
||||
* @return string
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: format strings via sprintf
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.string.format.php
|
||||
* string_format (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @param string
|
||||
* @return string
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: strip html tags from text
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.strip.tags.php
|
||||
* strip_tags (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @param boolean
|
||||
* @return string
|
||||
|
|
|
@ -13,29 +13,36 @@
|
|||
* Name: truncate<br>
|
||||
* Purpose: Truncate a string to a certain length if necessary,
|
||||
* optionally splitting in the middle of a word, and
|
||||
* appending the $etc string.
|
||||
* appending the $etc string or inserting $etc into the middle.
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.truncate.php
|
||||
* truncate (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @param integer
|
||||
* @param string
|
||||
* @param boolean
|
||||
* @param boolean
|
||||
* @return string
|
||||
*/
|
||||
function smarty_modifier_truncate($string, $length = 80, $etc = '...',
|
||||
$break_words = false)
|
||||
$break_words = false, $middle = false)
|
||||
{
|
||||
if ($length == 0)
|
||||
return '';
|
||||
|
||||
if (strlen($string) > $length) {
|
||||
$length -= strlen($etc);
|
||||
if (!$break_words)
|
||||
$length -= min($length, strlen($etc));
|
||||
if (!$break_words && !$middle) {
|
||||
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
|
||||
|
||||
return substr($string, 0, $length).$etc;
|
||||
} else
|
||||
}
|
||||
if(!$middle) {
|
||||
return substr($string, 0, $length) . $etc;
|
||||
} else {
|
||||
return substr($string, 0, $length/2) . $etc . substr($string, -$length/2);
|
||||
}
|
||||
} else {
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set expandtab: */
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: convert string to uppercase
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.upper.php
|
||||
* upper (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Purpose: wrap a string of text at a given length
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.wordwrap.php
|
||||
* wordwrap (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @param integer
|
||||
* @param string
|
||||
|
|
|
@ -28,35 +28,35 @@
|
|||
function smarty_outputfilter_trimwhitespace($source, &$smarty)
|
||||
{
|
||||
// Pull out the script blocks
|
||||
preg_match_all("!<script[^>]+>.*?</script>!is", $source, $match);
|
||||
preg_match_all("!<script[^>]*?>.*?</script>!is", $source, $match);
|
||||
$_script_blocks = $match[0];
|
||||
$source = preg_replace("!<script[^>]+>.*?</script>!is",
|
||||
$source = preg_replace("!<script[^>]*?>.*?</script>!is",
|
||||
'@@@SMARTY:TRIM:SCRIPT@@@', $source);
|
||||
|
||||
// Pull out the pre blocks
|
||||
preg_match_all("!<pre>.*?</pre>!is", $source, $match);
|
||||
preg_match_all("!<pre[^>]*?>.*?</pre>!is", $source, $match);
|
||||
$_pre_blocks = $match[0];
|
||||
$source = preg_replace("!<pre>.*?</pre>!is",
|
||||
$source = preg_replace("!<pre[^>]*?>.*?</pre>!is",
|
||||
'@@@SMARTY:TRIM:PRE@@@', $source);
|
||||
|
||||
|
||||
// Pull out the textarea blocks
|
||||
preg_match_all("!<textarea[^>]+>.*?</textarea>!is", $source, $match);
|
||||
preg_match_all("!<textarea[^>]*?>.*?</textarea>!is", $source, $match);
|
||||
$_textarea_blocks = $match[0];
|
||||
$source = preg_replace("!<textarea[^>]+>.*?</textarea>!is",
|
||||
$source = preg_replace("!<textarea[^>]*?>.*?</textarea>!is",
|
||||
'@@@SMARTY:TRIM:TEXTAREA@@@', $source);
|
||||
|
||||
// remove all leading spaces, tabs and carriage returns NOT
|
||||
// preceeded by a php close tag.
|
||||
$source = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source));
|
||||
|
||||
// replace script blocks
|
||||
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $source);
|
||||
// replace textarea blocks
|
||||
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@",$_textarea_blocks, $source);
|
||||
|
||||
// replace pre blocks
|
||||
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:PRE@@@",$_pre_blocks, $source);
|
||||
|
||||
// replace textarea blocks
|
||||
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@",$_textarea_blocks, $source);
|
||||
// replace script blocks
|
||||
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $source);
|
||||
|
||||
return $source;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
* Function: smarty_function_escape_special_chars<br>
|
||||
* Purpose: used by other smarty functions to escape
|
||||
* special chars except for already escaped ones
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -10,32 +10,35 @@
|
|||
* Function: smarty_make_timestamp<br>
|
||||
* Purpose: used by other smarty functions to make a timestamp
|
||||
* from a string.
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function smarty_make_timestamp($string)
|
||||
{
|
||||
if(empty($string)) {
|
||||
$string = "now";
|
||||
// use "now":
|
||||
$time = time();
|
||||
|
||||
} elseif (preg_match('/^\d{14}$/', $string)) {
|
||||
// it is mysql timestamp format of YYYYMMDDHHMMSS?
|
||||
$time = 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
|
||||
$time = (int)$string;
|
||||
|
||||
} else {
|
||||
// strtotime should handle it
|
||||
$time = strtotime($string);
|
||||
if ($time == -1 || $time === false) {
|
||||
// strtotime() was not able to parse $string, use "now":
|
||||
$time = time();
|
||||
}
|
||||
}
|
||||
$time = strtotime($string);
|
||||
if (is_numeric($time) && $time != -1)
|
||||
return $time;
|
||||
return $time;
|
||||
|
||||
// is mysql timestamp format of YYYYMMDDHHMMSS?
|
||||
if (preg_match('/^\d{14}$/', $string)) {
|
||||
$time = 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 $time;
|
||||
}
|
||||
|
||||
// couldn't recognize it, try to return a time
|
||||
$time = (int) $string;
|
||||
if ($time > 0)
|
||||
return $time;
|
||||
else
|
||||
return time();
|
||||
}
|
||||
|
||||
/* vim: set expandtab: */
|
||||
|
|
Loading…
Reference in a new issue