diff --git a/libs/smarty/autoloader.php b/libs/smarty/autoloader.php new file mode 100644 index 000000000..6de36a3fd --- /dev/null +++ b/libs/smarty/autoloader.php @@ -0,0 +1,30 @@ + diff --git a/libs/smarty/plugins/block.php.php b/libs/smarty/plugins/block.php.php new file mode 100644 index 000000000..4a0aa3dd7 --- /dev/null +++ b/libs/smarty/plugins/block.php.php @@ -0,0 +1,25 @@ +allow_php_tag) { + throw new SmartyException("{php} is deprecated, set allow_php_tag = true to enable"); + } + eval($content); + return ''; +} +?> \ No newline at end of file diff --git a/libs/smarty/plugins/function.html_options_multiple.php b/libs/smarty/plugins/function.html_options_multiple.php new file mode 100644 index 000000000..826ec3bd2 --- /dev/null +++ b/libs/smarty/plugins/function.html_options_multiple.php @@ -0,0 +1,173 @@ + + * Name: html_options_multiple + * Purpose: Prints the list of tags generated from + * the passed parameters + * Params: + * + * - 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 + * + * + * @link http://www.smarty.net/manual/en/language.function.html.options.php {html_image} + * (Smarty online manual) + * @author Monte Ohrt + * @author Ralf Strehle (minor optimization) + * @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 = '' . "\n" . $_html_result . '' . "\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 = '__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 . '' . "\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 = '' . "\n"; + foreach ($values as $key => $value) { + $optgroup_html .= smarty_function_html_options_multiple_optoutput($key, $value, $selected, $id, $class, $idx); + } + $optgroup_html .= "\n"; + return $optgroup_html; +} \ No newline at end of file diff --git a/libs/smarty/plugins/modifier.daysago.php b/libs/smarty/plugins/modifier.daysago.php new file mode 100644 index 000000000..00053525f --- /dev/null +++ b/libs/smarty/plugins/modifier.daysago.php @@ -0,0 +1,41 @@ + + * Name: daysAgo + * @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'; + } +} +?> \ No newline at end of file diff --git a/libs/smarty/plugins/modifier.fsize_format.php b/libs/smarty/plugins/modifier.fsize_format.php new file mode 100644 index 000000000..78a7a5e42 --- /dev/null +++ b/libs/smarty/plugins/modifier.fsize_format.php @@ -0,0 +1,57 @@ + 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 +?> \ No newline at end of file diff --git a/libs/smarty/plugins/modifier.magicurl.php b/libs/smarty/plugins/modifier.magicurl.php new file mode 100644 index 000000000..9b815c597 --- /dev/null +++ b/libs/smarty/plugins/modifier.magicurl.php @@ -0,0 +1,20 @@ + + * Name: magicurl + * 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', '$1://$2', $str); +} +?> \ No newline at end of file diff --git a/libs/smarty/plugins/modifier.nl2br.php b/libs/smarty/plugins/modifier.nl2br.php new file mode 100644 index 000000000..d6dc55ca7 --- /dev/null +++ b/libs/smarty/plugins/modifier.nl2br.php @@ -0,0 +1,31 @@ + + * Name: nl2br + * Date: Feb 26, 2003 + * Purpose: convert \r\n, \r or \n to <> + * Input: + * - 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 + * @param string + * @return string + */ +function smarty_modifier_nl2br($string) +{ + return nl2br($string); +} +/* vim: set expandtab: */ +?> \ No newline at end of file diff --git a/libs/smarty/plugins/modifier.parray.php b/libs/smarty/plugins/modifier.parray.php new file mode 100644 index 000000000..285a4e98d --- /dev/null +++ b/libs/smarty/plugins/modifier.parray.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/libs/smarty/plugins/modifier.phpdate_format.php b/libs/smarty/plugins/modifier.phpdate_format.php new file mode 100644 index 000000000..8c2561b27 --- /dev/null +++ b/libs/smarty/plugins/modifier.phpdate_format.php @@ -0,0 +1,64 @@ +plugins_dir.'shared.make_timestamp.php'); +/** + * Smarty phpdate_format modifier plugin + * + * Type: modifier + * Name: date_format + * Purpose: format datestamps via date() + * Input: + * - 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: */ +?> \ No newline at end of file diff --git a/libs/smarty/plugins/modifier.roundup.php b/libs/smarty/plugins/modifier.roundup.php new file mode 100644 index 000000000..f1e4145d8 --- /dev/null +++ b/libs/smarty/plugins/modifier.roundup.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/libs/smarty/plugins/modifier.timeago.php b/libs/smarty/plugins/modifier.timeago.php new file mode 100644 index 000000000..686b1b0e7 --- /dev/null +++ b/libs/smarty/plugins/modifier.timeago.php @@ -0,0 +1,49 @@ + + * Name: timeAgo + * @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'; + } +} +?> \ No newline at end of file diff --git a/libs/smarty/sysplugins/smarty_config_source.php b/libs/smarty/sysplugins/smarty_config_source.php new file mode 100644 index 000000000..fd37e61f7 --- /dev/null +++ b/libs/smarty/sysplugins/smarty_config_source.php @@ -0,0 +1,94 @@ +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; + } + + /** + * <> 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'."); + } + } + + /** + * <> 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."); + } + } +} diff --git a/libs/smarty/sysplugins/smarty_internal_config.php b/libs/smarty/sysplugins/smarty_internal_config.php new file mode 100644 index 000000000..b66027f4b --- /dev/null +++ b/libs/smarty/sysplugins/smarty_internal_config.php @@ -0,0 +1,305 @@ +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."); + } +}
+ * - 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 + *