From 51609351f2c4b5082b7e6f0744cd3811c325303f Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 11 Oct 2016 14:01:29 +0200 Subject: * initial template --- lib/smarty-plugins/block.t.php | 128 +++++++++++++++++++++++++++++++++ lib/smarty-plugins/block.vertical.php | 16 +++++ lib/smarty-plugins/function.suit.php | 24 +++++++ lib/smarty-plugins/function.varvar.php | 21 ++++++ 4 files changed, 189 insertions(+) create mode 100644 lib/smarty-plugins/block.t.php create mode 100644 lib/smarty-plugins/block.vertical.php create mode 100644 lib/smarty-plugins/function.suit.php create mode 100644 lib/smarty-plugins/function.varvar.php (limited to 'lib/smarty-plugins') diff --git a/lib/smarty-plugins/block.t.php b/lib/smarty-plugins/block.t.php new file mode 100644 index 0000000..5b6bc8e --- /dev/null +++ b/lib/smarty-plugins/block.t.php @@ -0,0 +1,128 @@ + + * @copyright 2004-2005 Sagi Bashari + */ + +/** + * Replaces arguments in a string with their values. + * Arguments are represented by % followed by their number. + * + * @param string Source string + * @param mixed Arguments, can be passed in an array or through single variables. + * @returns string Modified string + */ +function smarty_gettext_strarg($str) +{ + $tr = array(); + $p = 0; + + for ($i=1; $i < func_num_args(); $i++) { + $arg = func_get_arg($i); + + if (is_array($arg)) { + foreach ($arg as $aarg) { + $tr['%'.++$p] = $aarg; + } + } else { + $tr['%'.++$p] = $arg; + } + } + + return strtr($str, $tr); +} + +/** + * Smarty block function, provides gettext support for smarty. + * + * The block content is the text that should be translated. + * + * Any parameter that is sent to the function will be represented as %n in the translation text, + * where n is 1 for the first parameter. The following parameters are reserved: + * - escape - sets escape mode: + * - 'html' for HTML escaping, this is the default. + * - 'js' for javascript escaping. + * - 'url' for url escaping. + * - 'no'/'off'/0 - turns off escaping + * - plural - The plural version of the text (2nd parameter of ngettext()) + * - count - The item count for plural mode (3rd parameter of ngettext()) + */ +function smarty_block_t($params, $text, &$smarty) +{ + if(!$text) { + return; + } + $text = stripslashes($text); + + // set escape mode + if (isset($params['escape'])) { + $escape = $params['escape']; + unset($params['escape']); + } + + // set plural version + if (isset($params['plural'])) { + $plural = $params['plural']; + unset($params['plural']); + + // set count + if (isset($params['count'])) { + $count = $params['count']; + unset($params['count']); + } + } + + // use plural if required parameters are set + if (isset($count) && isset($plural)) { + $text = ngettext($text, $plural, $count); + } else { // use normal + $text = gettext($text); + } + + // run strarg if there are parameters + if (count($params)) { + $text = smarty_gettext_strarg($text, $params); + } + + if (!isset($escape) || $escape == 'html') { // html escape, default + $text = nl2br(htmlspecialchars($text)); + } elseif (isset($escape)) { + switch ($escape) { + case 'javascript': + case 'js': + // javascript escape + $text = str_replace('\'', '\\\'', stripslashes($text)); + break; + case 'url': + // url escape + $text = urlencode($text); + break; + } + } + return $text; +} + +?> diff --git a/lib/smarty-plugins/block.vertical.php b/lib/smarty-plugins/block.vertical.php new file mode 100644 index 0000000..f0c0c13 --- /dev/null +++ b/lib/smarty-plugins/block.vertical.php @@ -0,0 +1,16 @@ +|[^\.]\.*/', $text, $array); + + return join('
', $array[0]); + +} + +?> \ No newline at end of file diff --git a/lib/smarty-plugins/function.suit.php b/lib/smarty-plugins/function.suit.php new file mode 100644 index 0000000..eb166d9 --- /dev/null +++ b/lib/smarty-plugins/function.suit.php @@ -0,0 +1,24 @@ + '♣', + 'd' => '♦', + 'h' => '♥', + 's' => '♠' + ); + static $colors = array( + 'c' => 'black', + 'd' => 'red', + 'h' => 'red', + 's' => 'black' + ); + + return ''.$entities[$params['color']].''; + +} + +?> \ No newline at end of file diff --git a/lib/smarty-plugins/function.varvar.php b/lib/smarty-plugins/function.varvar.php new file mode 100644 index 0000000..36c9776 --- /dev/null +++ b/lib/smarty-plugins/function.varvar.php @@ -0,0 +1,21 @@ +getTemplateVars(); + $ret = $value[$params['var']]; + if ($ret) { + return $ret; + } else { + return $params['var']; + } +} +?> \ No newline at end of file -- cgit v1.2.3