diff --git a/www/pages/BasePage.php b/www/pages/BasePage.php index 1ab7b3b62..0fa583f17 100644 --- a/www/pages/BasePage.php +++ b/www/pages/BasePage.php @@ -103,6 +103,10 @@ class BasePage $this->smarty->setCompileDir(SMARTY_DIR . 'templates_c/'); $this->smarty->setConfigDir(SMARTY_DIR . 'configs/'); $this->smarty->setCacheDir(SMARTY_DIR . 'cache/'); + $this->smarty->setPluginsDir([ + NN_WWW . 'plugins/', + SMARTY_DIR . 'plugins/', + ]); $this->smarty->error_reporting = ((NN_DEBUG ? E_ALL : E_ALL - E_NOTICE)); if (isset($_SERVER['SERVER_NAME'])) { diff --git a/www/plugins/block.php.php b/www/plugins/block.php.php new file mode 100755 index 000000000..4a0aa3dd7 --- /dev/null +++ b/www/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/www/plugins/function.getcatval.php b/www/plugins/function.getcatval.php new file mode 100755 index 000000000..89b7220fb --- /dev/null +++ b/www/plugins/function.getcatval.php @@ -0,0 +1,35 @@ +. + * @author niel + * @copyright 2016 nZEDb + */ + +use newznab\Category; + +/** + * Returns the value of the specified Category constant. + * @usage {getcatval category=BOOKS_COMICS} + * + *@param string $category Name of constant whose value to return. + * + *@return Value of the specified Category constant. + */ +function smarty_function_getcatval($params) +{ + return Category::getCategoryValue($params['category']); +} + +?> diff --git a/www/plugins/function.html_options_multiple.php b/www/plugins/function.html_options_multiple.php new file mode 100755 index 000000000..3446dd9a3 --- /dev/null +++ b/www/plugins/function.html_options_multiple.php @@ -0,0 +1,174 @@ + + * 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/www/plugins/modifier.daysago.php b/www/plugins/modifier.daysago.php new file mode 100755 index 000000000..00053525f --- /dev/null +++ b/www/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/www/plugins/modifier.fsize_format.php b/www/plugins/modifier.fsize_format.php new file mode 100755 index 000000000..78a7a5e42 --- /dev/null +++ b/www/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/www/plugins/modifier.magicurl.php b/www/plugins/modifier.magicurl.php new file mode 100755 index 000000000..9b815c597 --- /dev/null +++ b/www/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/www/plugins/modifier.nl2br.php b/www/plugins/modifier.nl2br.php new file mode 100755 index 000000000..d6dc55ca7 --- /dev/null +++ b/www/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/www/plugins/modifier.parray.php b/www/plugins/modifier.parray.php new file mode 100755 index 000000000..285a4e98d --- /dev/null +++ b/www/plugins/modifier.parray.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/www/plugins/modifier.phpdate_format.php b/www/plugins/modifier.phpdate_format.php new file mode 100755 index 000000000..1aea14c97 --- /dev/null +++ b/www/plugins/modifier.phpdate_format.php @@ -0,0 +1,88 @@ +plugins_dir) && is_dir($smarty->plugins_dir): + $plugins_dir = $smarty->plugins_dir; + break; + case is_array($smarty->plugins_dir): + $plugins_dir = ''; + foreach ($smarty->plugins_dir as $dir) { + if (is_string($dir) && is_dir($dir)) { + $plugins_dir = $dir; + break; + } + } + break; + default: + $plugins_dir = ''; +} +if (!is_dir($plugins_dir)) { + exit('Fatal: Unable to find smarty plugins directory.' . PHP_EOL); +} +// End fix by nZEDb. +require_once ($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/www/plugins/modifier.strtotime.php b/www/plugins/modifier.strtotime.php new file mode 100755 index 000000000..16c9c39c4 --- /dev/null +++ b/www/plugins/modifier.strtotime.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/www/plugins/modifier.timeago.php b/www/plugins/modifier.timeago.php new file mode 100755 index 000000000..686b1b0e7 --- /dev/null +++ b/www/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
+ * - 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 + *