Code

Readded smarty
[gosa.git] / gosa-core / include / smarty / plugins / modifiercompiler.count_characters.php
diff --git a/gosa-core/include/smarty/plugins/modifiercompiler.count_characters.php b/gosa-core/include/smarty/plugins/modifiercompiler.count_characters.php
new file mode 100644 (file)
index 0000000..ae95fda
--- /dev/null
@@ -0,0 +1,33 @@
+<?php\r
+/**\r
+ * Smarty plugin\r
+ *\r
+ * @package Smarty\r
+ * @subpackage PluginsModifierCompiler\r
+ */\r
+\r
+/**\r
+ * Smarty count_characters modifier plugin\r
+ *\r
+ * Type:     modifier<br>\r
+ * Name:     count_characteres<br>\r
+ * Purpose:  count the number of characters in a text\r
+ *\r
+ * @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual)\r
+ * @author Uwe Tews\r
+ * @param array $params parameters\r
+ * @return string with compiled code\r
+ */\r
+function smarty_modifiercompiler_count_characters($params, $compiler)\r
+{\r
+    if (!isset($params[1]) || $params[1] != 'true') {\r
+        return 'preg_match_all(\'/[^\s]/u\',' . $params[0] . ', $tmp)';\r
+    }\r
+    if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) {\r
+        return 'mb_strlen(' . $params[0] . ', SMARTY_RESOURCE_CHAR_SET)';\r
+    }\r
+    // no MBString fallback\r
+    return 'strlen(' . $params[0] . ')';\r
+}\r
+\r
+?>
\ No newline at end of file