3 * Data class for homepage 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 Homepage 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 Homepage_blacklist extends Managed_DataObject
49 public $__table = 'homepage_blacklist'; // table name
50 public $pattern; // string pattern
51 public $created; // datetime
54 * return table definition for DB_DataObject
56 * DB_DataObject needs to know something about the table to manipulate
57 * instances. This method provides all the DB_DataObject needs to know.
59 * @return array array of column definitions
63 return array('pattern' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
64 'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
68 * return key definitions for DB_DataObject
70 * DB_DataObject needs to know about keys that the table has; this function
73 * @return array key definitions
77 return array_keys($this->keyTypes());
81 * return key definitions for Memcached_DataObject
83 * Our caching system uses the same key definitions, but uses a different
86 * @return array key definitions
90 return array('pattern' => 'K');
94 * Return a list of patterns to check
96 * @return array string patterns to check
98 static function getPatterns()
100 $patterns = self::cacheGet('homepage_blacklist:patterns');
102 if ($patterns === false) {
106 $nb = new Homepage_blacklist();
110 while ($nb->fetch()) {
111 $patterns[] = $nb->pattern;
114 self::cacheSet('homepage_blacklist:patterns', $patterns);
121 * Save new list of patterns
123 * @return array of patterns to check
125 static function saveNew($newPatterns)
127 $oldPatterns = self::getPatterns();
129 // Delete stuff that's old that not in new
130 $toDelete = array_diff($oldPatterns, $newPatterns);
132 // Insert stuff that's in new and not in old
133 $toInsert = array_diff($newPatterns, $oldPatterns);
135 foreach ($toDelete as $pattern) {
136 $nb = Homepage_blacklist::staticGet('pattern', $pattern);
142 foreach ($toInsert as $pattern) {
143 $nb = new Homepage_blacklist();
144 $nb->pattern = $pattern;
145 $nb->created = common_sql_now();
149 self::blow('homepage_blacklist:patterns');
152 static function ensurePattern($pattern)
154 $hb = Homepage_blacklist::staticGet('pattern', $pattern);
157 $hb = new Homepage_blacklist();
158 $hb->pattern = $pattern;
159 $hb->created = common_sql_now();
161 self::blow('homepage_blacklist:patterns');