diff options
Diffstat (limited to 'libs/plugins/modifiercompiler.count_words.php')
| -rw-r--r-- | libs/plugins/modifiercompiler.count_words.php | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/libs/plugins/modifiercompiler.count_words.php b/libs/plugins/modifiercompiler.count_words.php index dbc2f43b..cd9ae5bf 100644 --- a/libs/plugins/modifiercompiler.count_words.php +++ b/libs/plugins/modifiercompiler.count_words.php @@ -1,31 +1,32 @@ <?php
/**
* Smarty plugin
- *
+ *
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty count_words modifier plugin
- *
+ *
* Type: modifier<br>
* Name: count_words<br>
* Purpose: count the number of words in a text
- *
- * @link http://smarty.php.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual)
- * @author Uwe Tews
+ *
+ * @link http://www.smarty.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual)
+ * @author Uwe Tews
* @param array $params parameters
* @return string with compiled code
*/
function smarty_modifiercompiler_count_words($params, $compiler)
-{
- // mb_ functions available?
- if (function_exists('mb_strlen')) {
- 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))';
- } else {
- return 'str_word_count(' . $params[0] . ')';
- }
-}
+{
+ if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) {
+ // return 'preg_match_all(\'#[\w\pL]+#u\', ' . $params[0] . ', $tmp)';
+ // expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592
+ return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/u\', ' . $params[0] . ', $tmp)';
+ }
+ // no MBString fallback
+ return 'str_word_count(' . $params[0] . ')';
+}
?>
\ No newline at end of file |
