summaryrefslogtreecommitdiff
path: root/lib/smarty-plugins
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-10-11 14:01:29 +0200
committeremkael <emkael@tlen.pl>2016-10-11 14:01:29 +0200
commit51609351f2c4b5082b7e6f0744cd3811c325303f (patch)
tree739015e9ec69bc185ebe30db21369ae0b8b692ce /lib/smarty-plugins
parent8d1b0dad63e3906efa9393ef01d08b77d83417b5 (diff)
* initial template
Diffstat (limited to 'lib/smarty-plugins')
-rw-r--r--lib/smarty-plugins/block.t.php128
-rw-r--r--lib/smarty-plugins/block.vertical.php16
-rw-r--r--lib/smarty-plugins/function.suit.php24
-rw-r--r--lib/smarty-plugins/function.varvar.php21
4 files changed, 189 insertions, 0 deletions
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 @@
+<?php
+/**
+ * block.t.php - Smarty gettext block plugin
+ *
+ * ------------------------------------------------------------------------- *
+ * 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 *
+ * ------------------------------------------------------------------------- *
+ *
+ * Installation: simply copy this file to the smarty plugins directory.
+ *
+ * @package smarty-gettext
+ * @version $Id: block.t.php 5422 2009-08-27 17:04:11Z rtasarz $
+ * @link http://smarty-gettext.sourceforge.net/
+ * @author Sagi Bashari <sagi@boom.org.il>
+ * @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 @@
+<?php
+
+function smarty_block_vertical($params, $text, &$smarty) {
+
+ if (isset($params['strip'])) {
+ $text = strip_tags($text);
+ }
+
+ $array = array();
+ preg_match_all('/<.*>|[^\.]\.*/', $text, $array);
+
+ return join('<br />', $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 @@
+<?php
+
+function smarty_function_suit($params, &$smarty) {
+
+ $params['color'] = strtolower($params['color']);
+
+ static $entities = array(
+ 'c' => '&clubs;',
+ 'd' => '&diams;',
+ 'h' => '&hearts;',
+ 's' => '&spades;'
+ );
+ static $colors = array(
+ 'c' => 'black',
+ 'd' => 'red',
+ 'h' => 'red',
+ 's' => 'black'
+ );
+
+ return '<span style="color: '.$colors[$params['color']].'">'.$entities[$params['color']].'</span>';
+
+}
+
+?> \ 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 @@
+<?php
+/**
+ * Smarty {varvar} function plugin
+ *
+ * Type: function
+ * Name: varvar
+ * Purpose: Assume the input is a string, and if a smarty variable with that name
+ * is set, return its value. Otherwise, return the original string
+ * @param array
+ * @param Smarty
+ */
+function smarty_function_varvar($params, &$smarty) {
+ $value = $smarty->getTemplateVars();
+ $ret = $value[$params['var']];
+ if ($ret) {
+ return $ret;
+ } else {
+ return $params['var'];
+ }
+}
+?> \ No newline at end of file