3 * Data class for nickname blacklisting
9 * @author Evan Prodromou <evan@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2009, StatusNet, Inc.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Affero General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Affero General Public License for more details.
26 * You should have received a copy of the GNU Affero General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 if (!defined('STATUSNET')) {
34 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
37 * Data class for Nickname blacklist
41 * @author Evan Prodromou <evan@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43 * @link http://status.net/
47 class Nickname_blacklist extends Managed_DataObject
49 public $__table = 'nickname_blacklist'; // table name
50 public $pattern; // varchar(255) pattern
51 public $created; // datetime not_null
52 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
54 public static function schemaDef()
58 'pattern' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'blacklist pattern'),
59 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
60 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
62 'primary key' => array('pattern'),
67 * Return a list of patterns to check
69 * @return array string patterns to check
71 static function getPatterns()
73 $patterns = self::cacheGet('nickname_blacklist:patterns');
75 if ($patterns === false) {
79 $nb = new Nickname_blacklist();
83 while ($nb->fetch()) {
84 $patterns[] = $nb->pattern;
87 self::cacheSet('nickname_blacklist:patterns', $patterns);
94 * Save new list of patterns
96 * @return array of patterns to check
98 static function saveNew($newPatterns)
100 $oldPatterns = self::getPatterns();
102 // Delete stuff that's old that not in new
103 $toDelete = array_diff($oldPatterns, $newPatterns);
105 // Insert stuff that's in new and not in old
106 $toInsert = array_diff($newPatterns, $oldPatterns);
108 foreach ($toDelete as $pattern) {
109 $nb = Nickname_blacklist::getKV('pattern', $pattern);
115 foreach ($toInsert as $pattern) {
116 $nb = new Nickname_blacklist();
117 $nb->pattern = $pattern;
118 $nb->created = common_sql_now();
122 self::blow('nickname_blacklist:patterns');
125 static function ensurePattern($pattern)
127 $nb = Nickname_blacklist::getKV('pattern', $pattern);
130 $nb = new Nickname_blacklist();
131 $nb->pattern = $pattern;
132 $nb->created = common_sql_now();
134 self::blow('nickname_blacklist:patterns');