mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-30 09:48:55 +00:00
Properly update to smarty 3.1.27.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
spl_autoload_register(
|
||||
function($className)
|
||||
{
|
||||
if ($className == 'Smarty') {
|
||||
$className = 'Smarty.class';
|
||||
}
|
||||
|
||||
$paths = array(
|
||||
SMARTY_DIR,
|
||||
NN_WWW . 'pages' . DIRECTORY_SEPARATOR,
|
||||
SMARTY_DIR . 'plugins' . DIRECTORY_SEPARATOR,
|
||||
SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR
|
||||
);
|
||||
|
||||
foreach ($paths as $path)
|
||||
{
|
||||
$spec = str_replace('\\', DIRECTORY_SEPARATOR, $path . strtolower($className) . '.php');
|
||||
if (file_exists($spec)) {
|
||||
require_once $spec;
|
||||
break;
|
||||
} else if (NN_LOGAUTOLOADER) {
|
||||
var_dump($spec);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin to execute PHP code
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsBlock
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
/**
|
||||
* Smarty {php}{/php} block plugin
|
||||
*
|
||||
* @param string $content contents of the block
|
||||
* @param object $template template object
|
||||
* @param boolean $ &$repeat repeat flag
|
||||
* @return string content re-formatted
|
||||
*/
|
||||
function smarty_block_php($params, $content, $template, &$repeat)
|
||||
{
|
||||
if (!$template->allow_php_tag) {
|
||||
throw new SmartyException("{php} is deprecated, set allow_php_tag = true to enable");
|
||||
}
|
||||
eval($content);
|
||||
return '';
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsFunction
|
||||
*/
|
||||
/**
|
||||
* Smarty {html_options_multiple} function plugin
|
||||
*
|
||||
* Type: function<br>
|
||||
* Name: html_options_multiple<br>
|
||||
* Purpose: Prints the list of <option> tags generated from
|
||||
* the passed parameters<br>
|
||||
* Params:
|
||||
* <pre>
|
||||
* - name (optional) - string default "select"
|
||||
* - values (required) - if no options supplied) - array
|
||||
* - options (required) - if no values supplied) - associative array
|
||||
* - selected (optional) - string default not set
|
||||
* - output (required) - if not options supplied) - array
|
||||
* - id (optional) - string default not set
|
||||
* - class (optional) - string default not set
|
||||
* </pre>
|
||||
*
|
||||
* @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>
|
||||
* @param array $params parameters
|
||||
* @param Smarty_Internal_Template $template template object
|
||||
* @return string
|
||||
* @uses smarty_function_escape_special_chars()
|
||||
*/
|
||||
function smarty_function_html_options_multiple($params, $template)
|
||||
{
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
$name = null;
|
||||
$values = null;
|
||||
$options = null;
|
||||
$selected = null;
|
||||
$output = null;
|
||||
$id = null;
|
||||
$class = null;
|
||||
$extra = '';
|
||||
foreach ($params as $_key => $_val) {
|
||||
switch ($_key) {
|
||||
case 'name':
|
||||
case 'class':
|
||||
case 'id':
|
||||
$$_key = (string) $_val;
|
||||
break;
|
||||
case 'options':
|
||||
$options = (array) $_val;
|
||||
break;
|
||||
case 'values':
|
||||
case 'output':
|
||||
$$_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());
|
||||
} else {
|
||||
trigger_error("html_options_multiple: 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);
|
||||
}
|
||||
$selected[$_sel] = true;
|
||||
}
|
||||
} elseif (is_object($_val)) {
|
||||
if (method_exists($_val, "__toString")) {
|
||||
$selected = smarty_function_escape_special_chars((string) $_val->__toString());
|
||||
} else {
|
||||
trigger_error("html_options_multiple: 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);
|
||||
}
|
||||
break;
|
||||
case 'strict': break;
|
||||
case 'disabled':
|
||||
case 'readonly':
|
||||
if (!empty($params['strict'])) {
|
||||
if (!is_scalar($_val)) {
|
||||
trigger_error("html_options_multiple: $_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!
|
||||
default:
|
||||
if (!is_array($_val)) {
|
||||
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
|
||||
} else {
|
||||
trigger_error("html_options_multiple: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
|
||||
}
|
||||
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_multiple_optoutput($_key, $_val, $selected, $id, $class, $_idx);
|
||||
}
|
||||
} else {
|
||||
foreach ($values as $_i => $_key) {
|
||||
$_val = isset($output[$_i]) ? $output[$_i] : '';
|
||||
$_html_result .= smarty_function_html_options_multiple_optoutput($_key, $_val, $selected, $id, $class, $_idx);
|
||||
}
|
||||
}
|
||||
if (!empty($name)) {
|
||||
$_html_class = !empty($class) ? ' class="'.$class.'"' : '';
|
||||
$_html_id = !empty($id) ? ' id="'.$id.'"' : '';
|
||||
// the name needs to have [] added (this is html text [] not PHP, so that the return for the multiselect is an array
|
||||
$_html_result = '<select multiple="multiple" name="' . $name . '[]"' . $_html_class . $_html_id . $extra . '>' . "\n" . $_html_result . '</select>' . "\n";
|
||||
}
|
||||
return $_html_result;
|
||||
}
|
||||
function smarty_function_html_options_multiple_optoutput($key, $value, $selected, $id, $class, &$idx)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
$_key = smarty_function_escape_special_chars($key);
|
||||
$_html_result = '<option value="' . $_key . '"';
|
||||
if (is_array($selected)) {
|
||||
if (isset($selected[$_key])) {
|
||||
$_html_result .= ' selected="selected"';
|
||||
}
|
||||
} elseif ($_key === $selected) {
|
||||
$_html_result .= ' selected="selected"';
|
||||
}
|
||||
$_html_class = !empty($class) ? ' class="'.$class.' option"' : '';
|
||||
$_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());
|
||||
} else {
|
||||
trigger_error("html_options_multiple: 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);
|
||||
}
|
||||
$_html_result .= $_html_class . $_html_id . '>' . $value . '</option>' . "\n";
|
||||
$idx++;
|
||||
} else {
|
||||
$_idx = 0;
|
||||
$_html_result = smarty_function_html_options_multiple_optgroup($key, $value, $selected, !empty($id) ? ($id.'-'.$idx) : null, $class, $_idx);
|
||||
$idx++;
|
||||
}
|
||||
return $_html_result;
|
||||
}
|
||||
function smarty_function_html_options_multiple_optgroup($key, $values, $selected, $id, $class, &$idx)
|
||||
{
|
||||
$optgroup_html = '<optgroup label="' . smarty_function_escape_special_chars($key) . '">' . "\n";
|
||||
foreach ($values as $key => $value) {
|
||||
$optgroup_html .= smarty_function_html_options_multiple_optoutput($key, $value, $selected, $id, $class, $idx);
|
||||
}
|
||||
$optgroup_html .= "</optgroup>\n";
|
||||
return $optgroup_html;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
* @package Smarty
|
||||
* @subpackage plugins
|
||||
*/
|
||||
/**
|
||||
* Smarty date modifier plugin
|
||||
* Purpose: converts unix timestamps or datetime strings to words
|
||||
* Type: modifier<br>
|
||||
* Name: daysAgo<br>
|
||||
* @author Stephan Otto
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function smarty_modifier_daysAgo($date)
|
||||
{
|
||||
if ($date == "")
|
||||
return "n/a";
|
||||
$sec = mktime(0,0,0,date("m"), date("d"), date("Y")) - (( strtotime($date)) ? strtotime(date("Y-m-d", strtotime($date))) : strtotime(date("Y-m-d", $date)));
|
||||
$min = $sec / 60;
|
||||
$hrs = $min / 60;
|
||||
$days = $sec/60/60/24;
|
||||
if ( $hrs <= 24) return ' Today';
|
||||
if ($days >= 365)
|
||||
{
|
||||
$years = round(($days/365), 1);
|
||||
return $years.' Yr'.($years!=1?"s":"").' ago';
|
||||
}
|
||||
else if ($days >= 90)
|
||||
{
|
||||
return round($days/7).' Wks ago';
|
||||
}
|
||||
else if ($days <= 2)
|
||||
return 'Yesterday';
|
||||
else
|
||||
{
|
||||
return round($days, 0).'d ago';
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/*
|
||||
* Smarty plugin
|
||||
* -------------------------------------------------------------
|
||||
* Type: modifier
|
||||
* Name: fsize_format
|
||||
* Version: 0.2
|
||||
* Date: 2003-05-15
|
||||
* Author: Joscha Feth, joscha@feth.com
|
||||
* Purpose: formats a filesize (in bytes) to human-readable format
|
||||
* Usage: In the template, use
|
||||
{$filesize|fsize_format} => 123.45 B|KB|MB|GB|TB
|
||||
or
|
||||
{$filesize|fsize_format:"MB"} => 123.45 MB
|
||||
or
|
||||
{$filesize|fsize_format:"TB":4} => 0.0012 TB
|
||||
* Params:
|
||||
int size the filesize in bytes
|
||||
string format the format, the output shall be: B, KB, MB, GB or TB
|
||||
int precision the rounding precision
|
||||
string dec_point the decimal separator
|
||||
string thousands_sep the thousands separator
|
||||
* Install: Drop into the plugin directory
|
||||
* Version:
|
||||
* 2007-05-24 Version 0.3 - added the peta, exa, zeta, and yeta byte magnitudes thanks to coreone (at) gmail (dot) com
|
||||
* 2003-05-15 Version 0.2 - added dec_point and thousands_sep thanks to Thomas Brandl, tbrandl@barff.de
|
||||
* - made format always uppercase
|
||||
* - count sizes "on-the-fly"
|
||||
* 2003-02-21 Version 0.1 - initial release
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
function smarty_modifier_fsize_format($size,$format = '',$precision = 2, $dec_point = ".", $thousands_sep = ",")
|
||||
{
|
||||
$format = strtoupper($format);
|
||||
static $sizes = array();
|
||||
if(!count($sizes)) {
|
||||
$b = 1024;
|
||||
$sizes["B"] = 1;
|
||||
$sizes["KB"] = $sizes["B"] * $b;
|
||||
$sizes["MB"] = $sizes["KB"] * $b;
|
||||
$sizes["GB"] = $sizes["MB"] * $b;
|
||||
$sizes["TB"] = $sizes["GB"] * $b;
|
||||
$sizes["PB"] = $sizes["TB"] * $b;
|
||||
$sizes["EB"] = $sizes["PB"] * $b;
|
||||
$sizes["ZB"] = $sizes["EB"] * $b;
|
||||
$sizes["YB"] = $sizes["ZB"] * $b;
|
||||
$sizes = array_reverse($sizes,true);
|
||||
}
|
||||
//~ get "human" filesize
|
||||
foreach($sizes AS $unit => $bytes) {
|
||||
if($size > $bytes || $unit == $format) {
|
||||
//~ return formatted size
|
||||
return number_format($size / $bytes,$precision,$dec_point,$thousands_sep)." ".$unit;
|
||||
} //~ end if
|
||||
} //~ end foreach
|
||||
} //~ end function
|
||||
?>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
* @package Smarty
|
||||
* @subpackage plugins
|
||||
*/
|
||||
/**
|
||||
* Smarty magicurl modifier plugin
|
||||
*
|
||||
* Type: modifier<br>
|
||||
* Name: magicurl<br>
|
||||
* Purpose: turn www addresses into hyperlinks
|
||||
* @author bb
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function smarty_modifier_magicurl($str, $dereferrer="") {
|
||||
return preg_replace('/(https?):\/\/([A-Za-z0-9\._\-\/\?=&;%]+)/is', '<a href="'.$dereferrer.'$1://$2" target="_blank">$1://$2</a>', $str);
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
* @package Smarty
|
||||
* @subpackage plugins
|
||||
*/
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* Type: modifier<br>
|
||||
* Name: nl2br<br>
|
||||
* Date: Feb 26, 2003
|
||||
* Purpose: convert \r\n, \r or \n to <<br>>
|
||||
* Input:<br>
|
||||
* - contents = contents to replace
|
||||
* - preceed_test = if true, includes preceeding break tags
|
||||
* in replacement
|
||||
* Example: {$text|nl2br}
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.nl2br.php
|
||||
* nl2br (Smarty online manual)
|
||||
* @version 1.0
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function smarty_modifier_nl2br($string)
|
||||
{
|
||||
return nl2br($string);
|
||||
}
|
||||
/* vim: set expandtab: */
|
||||
?>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
function smarty_modifier_parray ($string,$explode,$limit=NULL)
|
||||
{
|
||||
if($limit == NULL)
|
||||
return explode( $explode , $string );
|
||||
else
|
||||
return explode( $explode , $string , $limit);
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
* phpdate_format plugin
|
||||
* Sam Easterby-Smith
|
||||
* Does exactly what the normal date_format plugin does - only it uses date() rather than strftime()
|
||||
* It also supports the various php date constants for doing things like rfc822 dates
|
||||
*/
|
||||
/**
|
||||
* Include the {@link shared.make_timestamp.php} plugin
|
||||
*/
|
||||
require_once ($smarty->plugins_dir.'shared.make_timestamp.php');
|
||||
/**
|
||||
* Smarty phpdate_format modifier plugin
|
||||
*
|
||||
* Type: modifier<br>
|
||||
* Name: date_format<br>
|
||||
* Purpose: format datestamps via date()<br>
|
||||
* Input:<br>
|
||||
* - string: input date string
|
||||
* - format: strftime format for output
|
||||
* - 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)
|
||||
* @param string
|
||||
* @param string
|
||||
* @param string
|
||||
* @return string|void
|
||||
* @uses smarty_make_timestamp()
|
||||
*/
|
||||
function smarty_modifier_phpdate_format($string, $format="Y/m/d H:i:s", $default_date=null)
|
||||
{
|
||||
/* 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 (substr($format,0,5)=='DATE_'){
|
||||
switch ($format){
|
||||
case 'DATE_ATOM': $nformat=DATE_ATOM; break;
|
||||
case 'DATE_COOKIE': $nformat=DATE_COOKIE; break;
|
||||
case 'DATE_ISO8601': $nformat=DATE_ISO8601; break;
|
||||
case 'DATE_RFC822': $nformat="D, d M y H:i:s O"; break; //The php constant is not quite right - as the time-zone comes out with invalid values like "UTC"...
|
||||
case 'DATE_RFC850': $nformat=DATE_RFC850; break;
|
||||
case 'DATE_RFC1036': $nformat=DATE_RFC1036; break;
|
||||
case 'DATE_RFC1123': $nformat=DATE_RFC1123; break;
|
||||
case 'DATE_RFC2822': $nformat=DATE_RFC2822; break;
|
||||
case 'DATE_RFC3339': $nformat=DATE_RFC3339; break;
|
||||
case 'DATE_RSS': $nformat="D, d M Y H:i:s O"; break; //as rfc822 ...
|
||||
case 'DATE_W3C': $nformat=DATE_W3C; break;
|
||||
}
|
||||
} else {
|
||||
$nformat=$format;
|
||||
}
|
||||
if($string != '') {
|
||||
return date($nformat, smarty_make_timestamp($string));
|
||||
} elseif (isset($default_date) && $default_date != '') {
|
||||
return date($nformat, smarty_make_timestamp($default_date));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* vim: set expandtab: */
|
||||
?>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
function smarty_modifier_roundup($float)
|
||||
{
|
||||
return ceil((float)$float);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
function smarty_modifier_strtotime($date)
|
||||
{
|
||||
return strtotime($date);
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
* @package Smarty
|
||||
* @subpackage plugins
|
||||
*/
|
||||
/**
|
||||
* Smarty date modifier plugin
|
||||
* Purpose: converts unix timestamps or datetime strings to words
|
||||
* Type: modifier<br>
|
||||
* Name: timeAgo<br>
|
||||
* @author Stephan Otto
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function smarty_modifier_timeAgo( $date)
|
||||
{
|
||||
if ($date == "")
|
||||
return "n/a";
|
||||
$timeStrings = array( 'now', // 0
|
||||
'Sec', 'Secs', // 1,1
|
||||
'Min','Mins', // 3,3
|
||||
'Hour', 'Hrs', // 5,5
|
||||
'Day', 'Days');
|
||||
$sec = time() - (( !is_numeric($date) && strtotime($date)) ? strtotime($date) : $date);
|
||||
if ( $sec <= 0) return $timeStrings[0];
|
||||
if ( $sec < 2) return $sec." ".$timeStrings[1];
|
||||
if ( $sec < 60) return $sec." ".$timeStrings[2];
|
||||
$min = $sec / 60;
|
||||
if ( floor($min+0.5) < 2) return floor($min+0.5)." ".$timeStrings[3];
|
||||
if ( $min < 60) return floor($min+0.5)." ".$timeStrings[4];
|
||||
$hrs = $min / 60;
|
||||
if ( floor($hrs+0.5) < 2) return floor($hrs+0.5)." ".$timeStrings[5];
|
||||
if ( $hrs < 24) return floor($hrs+0.5)." ".$timeStrings[6];
|
||||
$days = $sec/60/60/24;
|
||||
if ($days > 365)
|
||||
{
|
||||
return round(($days/365), 1).' Yrs';
|
||||
}
|
||||
else if ($days > 90)
|
||||
{
|
||||
return round($days/7).' Wks';
|
||||
}
|
||||
else
|
||||
{
|
||||
return round($days, 1).'d';
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Resource Data Object
|
||||
* Meta Data Container for Config Files
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
* @property string $content
|
||||
* @property int $timestamp
|
||||
* @property bool $exists
|
||||
*/
|
||||
class Smarty_Config_Source extends Smarty_Template_Source
|
||||
{
|
||||
/**
|
||||
* create Config Object container
|
||||
*
|
||||
* @param Smarty_Resource $handler Resource Handler this source object communicates with
|
||||
* @param Smarty $smarty Smarty instance this source object belongs to
|
||||
* @param string $resource full config_resource
|
||||
* @param string $type type of resource
|
||||
* @param string $name resource name
|
||||
* @param string $unique_resource unqiue resource name
|
||||
*/
|
||||
public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name, $unique_resource)
|
||||
{
|
||||
$this->handler = $handler; // Note: prone to circular references
|
||||
|
||||
// Note: these may be ->config_compiler_class etc in the future
|
||||
//$this->config_compiler_class = $handler->config_compiler_class;
|
||||
//$this->config_lexer_class = $handler->config_lexer_class;
|
||||
//$this->config_parser_class = $handler->config_parser_class;
|
||||
|
||||
$this->smarty = $smarty;
|
||||
$this->resource = $resource;
|
||||
$this->type = $type;
|
||||
$this->name = $name;
|
||||
$this->unique_resource = $unique_resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* <<magic>> Generic setter.
|
||||
*
|
||||
* @param string $property_name valid: content, timestamp, exists
|
||||
* @param mixed $value newly assigned value (not check for correct type)
|
||||
*
|
||||
* @throws SmartyException when the given property name is not valid
|
||||
*/
|
||||
public function __set($property_name, $value)
|
||||
{
|
||||
switch ($property_name) {
|
||||
case 'content':
|
||||
case 'timestamp':
|
||||
case 'exists':
|
||||
$this->$property_name = $value;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new SmartyException("invalid config property '$property_name'.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <<magic>> Generic getter.
|
||||
*
|
||||
* @param string $property_name valid: content, timestamp, exists
|
||||
*
|
||||
* @return mixed|void
|
||||
* @throws SmartyException when the given property name is not valid
|
||||
*/
|
||||
public function __get($property_name)
|
||||
{
|
||||
switch ($property_name) {
|
||||
case 'timestamp':
|
||||
case 'exists':
|
||||
$this->handler->populateTimestamp($this);
|
||||
|
||||
return $this->$property_name;
|
||||
|
||||
case 'content':
|
||||
return $this->content = $this->handler->getContent($this);
|
||||
|
||||
default:
|
||||
throw new SmartyException("config property '$property_name' does not exist.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Config
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Config
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Config
|
||||
* Main class for config variables
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Config
|
||||
* @ignore
|
||||
*/
|
||||
class Smarty_Internal_Config
|
||||
{
|
||||
/**
|
||||
* Smarty instance
|
||||
*
|
||||
* @var Smarty object
|
||||
*/
|
||||
public $smarty = null;
|
||||
/**
|
||||
* Object of config var storage
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $data = null;
|
||||
/**
|
||||
* Config resource
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $config_resource = null;
|
||||
/**
|
||||
* Compiled config file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $compiled_config = null;
|
||||
/**
|
||||
* filepath of compiled config file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $compiled_filepath = null;
|
||||
/**
|
||||
* Filemtime of compiled config Filemtime
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $compiled_timestamp = null;
|
||||
/**
|
||||
* flag if compiled config file is invalid and must be (re)compiled
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $mustCompile = null;
|
||||
/**
|
||||
* Config file compiler object
|
||||
*
|
||||
* @var Smarty_Internal_Config_File_Compiler object
|
||||
*/
|
||||
public $compiler_object = null;
|
||||
|
||||
/**
|
||||
* Constructor of config file object
|
||||
*
|
||||
* @param string $config_resource config file resource name
|
||||
* @param Smarty $smarty Smarty instance
|
||||
* @param object $data object for config vars storage
|
||||
*/
|
||||
public function __construct($config_resource, $smarty, $data = null)
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->smarty = $smarty;
|
||||
$this->config_resource = $config_resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the compiled filepath
|
||||
*
|
||||
* @return string the compiled filepath
|
||||
*/
|
||||
public function getCompiledFilepath()
|
||||
{
|
||||
return $this->compiled_filepath === null ?
|
||||
($this->compiled_filepath = $this->buildCompiledFilepath()) :
|
||||
$this->compiled_filepath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function buildCompiledFilepath()
|
||||
{
|
||||
$_compile_id = isset($this->smarty->compile_id) ? preg_replace('![^\w\|]+!', '_', $this->smarty->compile_id) : null;
|
||||
$_flag = (int)$this->smarty->config_read_hidden + (int)$this->smarty->config_booleanize * 2
|
||||
+ (int)$this->smarty->config_overwrite * 4;
|
||||
$_filepath = sha1(realpath($this->source->filepath) . $_flag);
|
||||
// if use_sub_dirs, break file into directories
|
||||
if ($this->smarty->use_sub_dirs) {
|
||||
$_filepath = substr($_filepath, 0, 2) . DS
|
||||
. substr($_filepath, 2, 2) . DS
|
||||
. substr($_filepath, 4, 2) . DS
|
||||
. $_filepath;
|
||||
}
|
||||
$_compile_dir_sep = $this->smarty->use_sub_dirs ? DS : '^';
|
||||
if (isset($_compile_id)) {
|
||||
$_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
|
||||
}
|
||||
$_compile_dir = $this->smarty->getCompileDir();
|
||||
|
||||
return $_compile_dir . $_filepath . '.' . basename($this->source->name) . '.config' . '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timestamp of the compiled file
|
||||
*
|
||||
* @return integer the file timestamp
|
||||
*/
|
||||
public function getCompiledTimestamp()
|
||||
{
|
||||
return $this->compiled_timestamp === null
|
||||
? ($this->compiled_timestamp = (file_exists($this->getCompiledFilepath())) ? filemtime($this->getCompiledFilepath()) : false)
|
||||
: $this->compiled_timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the current config file must be compiled
|
||||
* It does compare the timestamps of config source and the compiled config and checks the force compile configuration
|
||||
*
|
||||
* @return boolean true if the file must be compiled
|
||||
*/
|
||||
public function mustCompile()
|
||||
{
|
||||
return $this->mustCompile === null ?
|
||||
$this->mustCompile = ($this->smarty->force_compile || $this->getCompiledTimestamp() === false || $this->smarty->compile_check && $this->getCompiledTimestamp() < $this->source->timestamp) :
|
||||
$this->mustCompile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the compiled config file
|
||||
* It checks if the config file must be compiled or just read the compiled version
|
||||
*
|
||||
* @return string the compiled config file
|
||||
*/
|
||||
public function getCompiledConfig()
|
||||
{
|
||||
if ($this->compiled_config === null) {
|
||||
// see if template needs compiling.
|
||||
if ($this->mustCompile()) {
|
||||
$this->compileConfigSource();
|
||||
} else {
|
||||
$this->compiled_config = file_get_contents($this->getCompiledFilepath());
|
||||
}
|
||||
}
|
||||
|
||||
return $this->compiled_config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the config files
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function compileConfigSource()
|
||||
{
|
||||
// compile template
|
||||
if (!is_object($this->compiler_object)) {
|
||||
// load compiler
|
||||
$this->compiler_object = new Smarty_Internal_Config_File_Compiler($this->smarty);
|
||||
}
|
||||
// compile locking
|
||||
if ($this->smarty->compile_locking) {
|
||||
if ($saved_timestamp = $this->getCompiledTimestamp()) {
|
||||
touch($this->getCompiledFilepath());
|
||||
}
|
||||
}
|
||||
// call compiler
|
||||
try {
|
||||
$this->compiler_object->compileSource($this);
|
||||
} catch (Exception $e) {
|
||||
// restore old timestamp in case of error
|
||||
if ($this->smarty->compile_locking && $saved_timestamp) {
|
||||
touch($this->getCompiledFilepath(), $saved_timestamp);
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
// compiling succeeded
|
||||
// write compiled template
|
||||
Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->getCompiledConfig(), $this->smarty);
|
||||
}
|
||||
|
||||
/**
|
||||
* load config variables
|
||||
*
|
||||
* @param mixed $sections array of section names, single section or null
|
||||
* @param string $scope global,parent or local
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function loadConfigVars($sections = null, $scope = 'local')
|
||||
{
|
||||
if ($this->data instanceof Smarty_Internal_Template) {
|
||||
$this->data->properties['file_dependency'][sha1($this->source->filepath)] = array($this->source->filepath, $this->source->timestamp, 'file');
|
||||
}
|
||||
if ($this->mustCompile()) {
|
||||
$this->compileConfigSource();
|
||||
}
|
||||
// pointer to scope
|
||||
if ($scope == 'local') {
|
||||
$scope_ptr = $this->data;
|
||||
} elseif ($scope == 'parent') {
|
||||
if (isset($this->data->parent)) {
|
||||
$scope_ptr = $this->data->parent;
|
||||
} else {
|
||||
$scope_ptr = $this->data;
|
||||
}
|
||||
} elseif ($scope == 'root' || $scope == 'global') {
|
||||
$scope_ptr = $this->data;
|
||||
while (isset($scope_ptr->parent)) {
|
||||
$scope_ptr = $scope_ptr->parent;
|
||||
}
|
||||
}
|
||||
$_config_vars = array();
|
||||
include($this->getCompiledFilepath());
|
||||
// copy global config vars
|
||||
foreach ($_config_vars['vars'] as $variable => $value) {
|
||||
if ($this->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) {
|
||||
$scope_ptr->config_vars[$variable] = $value;
|
||||
} else {
|
||||
$scope_ptr->config_vars[$variable] = array_merge((array)$scope_ptr->config_vars[$variable], (array)$value);
|
||||
}
|
||||
}
|
||||
// scan sections
|
||||
if (!empty($sections)) {
|
||||
foreach ((array)$sections as $this_section) {
|
||||
if (isset($_config_vars['sections'][$this_section])) {
|
||||
foreach ($_config_vars['sections'][$this_section]['vars'] as $variable => $value) {
|
||||
if ($this->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) {
|
||||
$scope_ptr->config_vars[$variable] = $value;
|
||||
} else {
|
||||
$scope_ptr->config_vars[$variable] = array_merge((array)$scope_ptr->config_vars[$variable], (array)$value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set Smarty property in template context
|
||||
*
|
||||
* @param string $property_name property name
|
||||
* @param mixed $value value
|
||||
*
|
||||
* @throws SmartyException if $property_name is not valid
|
||||
*/
|
||||
public function __set($property_name, $value)
|
||||
{
|
||||
switch ($property_name) {
|
||||
case 'source':
|
||||
case 'compiled':
|
||||
$this->$property_name = $value;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
throw new SmartyException("invalid config property '$property_name'.");
|
||||
}
|
||||
|
||||
/**
|
||||
* get Smarty property in template context
|
||||
*
|
||||
* @param string $property_name property name
|
||||
*
|
||||
* @return \Smarty_Config_Source|\Smarty_Template_Compiled
|
||||
* @throws SmartyException if $property_name is not valid
|
||||
*/
|
||||
public function __get($property_name)
|
||||
{
|
||||
switch ($property_name) {
|
||||
case 'source':
|
||||
if (empty($this->config_resource)) {
|
||||
throw new SmartyException("Unable to parse resource name \"{$this->config_resource}\"");
|
||||
}
|
||||
$this->source = Smarty_Resource::config($this);
|
||||
|
||||
return $this->source;
|
||||
|
||||
case 'compiled':
|
||||
$this->compiled = $this->source->getCompiled($this);
|
||||
|
||||
return $this->compiled;
|
||||
}
|
||||
|
||||
throw new SmartyException("config attribute '$property_name' does not exist.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user