X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FActivitySpam%2FActivitySpamPlugin.php;h=d63d64c71893314c0379abe3fd4a7b2ca5f467a0;hb=14cb2d53980f27fb07f0327644a47e8722718a25;hp=70e2c13d614eafb00599ab93986a6ee68918b839;hpb=c5ae53166ce4b80cc57055ff220e282147177e4d;p=quix0rs-gnu-social.git diff --git a/plugins/ActivitySpam/ActivitySpamPlugin.php b/plugins/ActivitySpam/ActivitySpamPlugin.php index 70e2c13d61..d63d64c718 100644 --- a/plugins/ActivitySpam/ActivitySpamPlugin.php +++ b/plugins/ActivitySpam/ActivitySpamPlugin.php @@ -65,6 +65,11 @@ class ActivitySpamPlugin extends Plugin $this->hideSpam = common_config('activityspam', 'hidespam'); + // Let DB_DataObject find Spam_score + + common_config_set('db', 'class_location', + common_config('db', 'class_location') .':'.dirname(__FILE__)); + return true; } @@ -87,38 +92,6 @@ class ActivitySpamPlugin extends Plugin return true; } - /** - * Load related modules when needed - * - * @param string $cls Name of the class to be loaded - * - * @return boolean hook value; true means continue processing, false means stop. - */ - - function onAutoload($cls) - { - $dir = dirname(__FILE__); - - switch ($cls) - { - case 'TrainAction': - case 'SpamAction': - include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php'; - return false; - case 'Spam_score': - include_once $dir . '/'.$cls.'.php'; - return false; - case 'SpamFilter': - case 'SpamNoticeStream': - case 'TrainSpamForm': - case 'TrainHamForm': - include_once $dir . '/'.strtolower($cls).'.php'; - return false; - default: - return true; - } - } - /** * When a notice is saved, check its spam score * @@ -146,7 +119,7 @@ class ActivitySpamPlugin extends Plugin } function onNoticeDeleteRelated($notice) { - $score = Spam_score::staticGet('notice_id', $notice->id); + $score = Spam_score::getKV('notice_id', $notice->id); if (!empty($score)) { $score->delete(); } @@ -180,11 +153,12 @@ class ActivitySpamPlugin extends Plugin if (!empty($notice)) { - $score = Spam_score::staticGet('notice_id', $notice->id); + $score = Spam_score::getKV('notice_id', $notice->id); if (empty($score)) { - $this->debug("No score for notice " . $notice->id); - // XXX: show a question-mark or something + // If it's empty, we can train it. + $form = new TrainSpamForm($out, $notice); + $form->show(); } else if ($score->is_spam) { $form = new TrainHamForm($out, $notice); $form->show(); @@ -201,12 +175,12 @@ class ActivitySpamPlugin extends Plugin /** * Map URLs to actions * - * @param Net_URL_Mapper $m path-to-action mapper + * @param URLMapper $m path-to-action mapper * * @return boolean hook value; true means continue processing, false means stop. */ - function onRouterInitialized($m) + public function onRouterInitialized(URLMapper $m) { $m->connect('main/train/spam', array('action' => 'train', 'category' => 'spam')); @@ -241,12 +215,12 @@ class ActivitySpamPlugin extends Plugin return true; } - function onPluginVersion(&$versions) + function onPluginVersion(array &$versions) { $versions[] = array('name' => 'ActivitySpam', - 'version' => STATUSNET_VERSION, + 'version' => GNUSOCIAL_VERSION, 'author' => 'Evan Prodromou', - 'homepage' => 'http://status.net/wiki/Plugin:ActivitySpam', + 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/ActivitySpam', 'description' => _m('Test notices against the Activity Spam service.')); return true; @@ -257,7 +231,7 @@ class ActivitySpamPlugin extends Plugin if ($this->hideSpam) { if ($bResult) { - $score = Spam_score::staticGet('notice_id', $notice->id); + $score = Spam_score::getKV('notice_id', $notice->id); if (!empty($score) && $score->is_spam) { if (empty($profile) || @@ -275,12 +249,9 @@ class ActivitySpamPlugin extends Plugin /** * Pre-cache our spam scores if needed. */ - function onEndNoticeListPrefill(&$notices, &$profiles, $avatarSize) { + function onEndNoticeListPrefill(array &$notices, array &$profiles, array $notice_ids, Profile $scoped=null) { if ($this->hideSpam) { - foreach ($notices as $notice) { - $ids[] = $notice->id; - } - Memcached_DataObject::multiGet('Spam_score', 'notice_id', $ids); + Spam_score::multiGet('notice_id', $notice_ids); } return true; }