Re: [SMARTY] Don't use bad words!
| From: | messju mohr | Date: | Thu, 10 Apr 2003 09:57:51 +0000 |
| Subject: | Re: [SMARTY] Don't use bad words! | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-9208@lists.php.net to get a copy of this message | ||
On Thu, Apr 10, 2003 at 03:56:23AM +0200, Joscha Feth wrote:
> Hi there :-)
>
> created a badword-plugin which x-es out all bad words defined in a file
>
> get here:
> http://dev.feth.com/PHP/Smarty/modifier.badwords.phps
>
> and grab some bad words (if you need some :) in english and german here:
> http://dev.feth.com/PHP/Smarty/modifier.badwords.zip
nice. although censorship may not always be considered nice, of
course. i hope people use such a function responsibly.
nontheless: i have two little tips for enhancement.
1.
i get a warning issued:
<b>Notice</b>: Use of undefined constant bar - assumed 'bar' in
<b>.../libs/plugins/modifier.badwords2.php(67) : regexp code</b> on line
<b>1</b><br />
i got rid of it, by adding some quotes
$replace =
'"\\1".str_repeat("'.$subst.'",strlen(\\2))."\\3"';
should read:
$replace =
'"\\1".str_repeat("'.$subst.'",strlen("\\2"))."\\3"';
and
$replace = 'str_repeat("'.$subst.'",strlen(\\1))';
should read:
$replace = 'str_repeat("'.$subst.'",strlen("\\1"))';
2.
if you call the modifier multiple times in a template the search array
is created from scratch for every call to the modifier. you may
increase performance vastly (especially for long word-lists), by
making $badwords a static variable and only initialize it on the first
call of the modifier.
sth. like:
static $badwords = null;
if (!is_array($badwords)) {
//~ read bad words from the badword-file
$badwords = file(dirname(__FILE__).DIRECTORY_SEPARATOR."badwords.txt");
//~ create preg-usable search pattern depending on the used badword-mode
array_walk($badwords,'smarty_modifier_badwords_walk',$type);
}
...
see the implementation of function.counter.php or
http://www.php.net/manual/en/language.variables.scope.php
for more
info on static scoping, if you're not familiar with it.
i didn't know about "static" myself for too long, so i HTH you ;)
greetings
messju
> greets,
> Joscha