123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
- class Homepage_blacklist extends Managed_DataObject
- {
- public $__table = 'homepage_blacklist';
- public $pattern;
- public $created;
- public $modified;
- public static function schemaDef()
- {
- return array(
- 'fields' => array(
- 'pattern' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'blacklist pattern'),
- 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
- 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
- ),
- 'primary key' => array('pattern'),
- );
- }
-
- static function getPatterns()
- {
- $patterns = self::cacheGet('homepage_blacklist:patterns');
- if ($patterns === false) {
- $patterns = array();
- $nb = new Homepage_blacklist();
- $nb->find();
- while ($nb->fetch()) {
- $patterns[] = $nb->pattern;
- }
- self::cacheSet('homepage_blacklist:patterns', $patterns);
- }
- return $patterns;
- }
-
- static function saveNew($newPatterns)
- {
- $oldPatterns = self::getPatterns();
-
- $toDelete = array_diff($oldPatterns, $newPatterns);
-
- $toInsert = array_diff($newPatterns, $oldPatterns);
- foreach ($toDelete as $pattern) {
- $nb = Homepage_blacklist::getKV('pattern', $pattern);
- if (!empty($nb)) {
- $nb->delete();
- }
- }
- foreach ($toInsert as $pattern) {
- $nb = new Homepage_blacklist();
- $nb->pattern = $pattern;
- $nb->created = common_sql_now();
- $nb->insert();
- }
- self::blow('homepage_blacklist:patterns');
- }
- static function ensurePattern($pattern)
- {
- $hb = Homepage_blacklist::getKV('pattern', $pattern);
- if (empty($nb)) {
- $hb = new Homepage_blacklist();
- $hb->pattern = $pattern;
- $hb->created = common_sql_now();
- $hb->insert();
- self::blow('homepage_blacklist:patterns');
- }
- }
- }
|