Code

Updated smarty to 1.0.9
[gosa.git] / gosa-core / include / smarty / plugins / modifiercompiler.count_words.php
index cd9ae5bf73055173e2b4f5371eae55a6d0974dde..dbc2f43be34c28bed1ea8642196768ac622df474 100644 (file)
@@ -1,32 +1,31 @@
 <?php\r
 /**\r
  * Smarty plugin\r
- *\r
+ * \r
  * @package Smarty\r
  * @subpackage PluginsModifierCompiler\r
  */\r
 \r
 /**\r
  * Smarty count_words modifier plugin\r
- *\r
+ * \r
  * Type:     modifier<br>\r
  * Name:     count_words<br>\r
  * Purpose:  count the number of words in a text\r
- *\r
- * @link http://www.smarty.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual)\r
- * @author Uwe Tews\r
+ * \r
+ * @link http://smarty.php.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual)\r
+ * @author Uwe Tews \r
  * @param array $params parameters\r
  * @return string with compiled code\r
 */\r
 function smarty_modifiercompiler_count_words($params, $compiler)\r
-{\r
-    if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) {\r
-        // return 'preg_match_all(\'#[\w\pL]+#u\', ' . $params[0] . ', $tmp)';\r
-        // expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592\r
-        return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/u\', ' . $params[0] . ', $tmp)';\r
-    }\r
-    // no MBString fallback\r
-    return 'str_word_count(' . $params[0] . ')';\r
-}\r
+{ \r
+    // mb_ functions available?\r
+    if (function_exists('mb_strlen')) {\r
+        return '((mb_detect_encoding(' . $params[0] . ', \'UTF-8, ISO-8859-1\') === \'UTF-8\') ? preg_match_all(\'#[\w\pL]+#u\', ' . $params[0] . ', $tmp) : preg_match_all(\'#\w+#\',' . $params[0] . ', $tmp))';\r
+    } else {\r
+        return 'str_word_count(' . $params[0] . ')';\r
+    } \r
+} \r
 \r
 ?>
\ No newline at end of file