summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2010-02-06 15:54:24 +0100
committerEvan Prodromou <evan@status.net>2010-02-06 15:54:24 +0100
commit8f3c0efe0c703cae68e29d65a76fdf2b1410c33d (patch)
tree35b8625071e94cfa1ce5c8cb1145665433dcc337 /plugins
parentceb0236dfb4274927a9c5cbbdda19a3e14830cca (diff)
BlacklistPlugin accepts config values for patterns
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Blacklist/BlacklistPlugin.php31
1 files changed, 29 insertions, 2 deletions
diff --git a/plugins/Blacklist/BlacklistPlugin.php b/plugins/Blacklist/BlacklistPlugin.php
index 0d10c1615..2d53093b2 100644
--- a/plugins/Blacklist/BlacklistPlugin.php
+++ b/plugins/Blacklist/BlacklistPlugin.php
@@ -48,6 +48,33 @@ class BlacklistPlugin extends Plugin
public $nicknames = array();
public $urls = array();
+ private $_nicknamePatterns = array();
+ private $_urlPatterns = array();
+
+ function initialize()
+ {
+ $this->_nicknamePatterns = array_merge($this->nicknames,
+ $this->_configArray('blacklist', 'nicknames'));
+
+ $this->_urlPatterns = array_merge($this->urls,
+ $this->_configArray('blacklist', 'urls'));
+ }
+
+ function _configArray($section, $setting)
+ {
+ $config = common_config($section, $setting);
+
+ if (empty($config)) {
+ return array();
+ } else if (is_array($config)) {
+ return $config;
+ } else if (is_string($config)) {
+ return explode("\t", $config);
+ } else {
+ throw new Exception("Unknown data type for config $section + $setting");
+ }
+ }
+
/**
* Hook registration to prevent blacklisted homepages or nicknames
*
@@ -173,7 +200,7 @@ class BlacklistPlugin extends Plugin
private function _checkUrl($url)
{
- foreach ($this->urls as $pattern) {
+ foreach ($this->_urlPatterns as $pattern) {
if (preg_match("/$pattern/", $url)) {
return false;
}
@@ -194,7 +221,7 @@ class BlacklistPlugin extends Plugin
private function _checkNickname($nickname)
{
- foreach ($this->nicknames as $pattern) {
+ foreach ($this->_nicknamePatterns as $pattern) {
if (preg_match("/$pattern/", $nickname)) {
return false;
}