1 <?php\r
2 /**\r
3 * Smarty plugin\r
4 *\r
5 * @package Smarty\r
6 * @subpackage PluginsModifierCompiler\r
7 */\r
8 \r
9 /**\r
10 * Smarty count_words modifier plugin\r
11 *\r
12 * Type: modifier<br>\r
13 * Name: count_words<br>\r
14 * Purpose: count the number of words in a text\r
15 *\r
16 * @link http://www.smarty.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual)\r
17 * @author Uwe Tews\r
18 * @param array $params parameters\r
19 * @return string with compiled code\r
20 */\r
21 function smarty_modifiercompiler_count_words($params, $compiler)\r
22 {\r
23 if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) {\r
24 // return 'preg_match_all(\'#[\w\pL]+#u\', ' . $params[0] . ', $tmp)';\r
25 // expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592\r
26 return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/u\', ' . $params[0] . ', $tmp)';\r
27 }\r
28 // no MBString fallback\r
29 return 'str_word_count(' . $params[0] . ')';\r
30 }\r
31 \r
32 ?>