예제 #1
0
function silencespammer($filter, $user, $minimum, $percent)
{
    printfnq("Testing user %s\n", $user->nickname);
    $profile = Profile::getKV('id', $user->id);
    if ($profile->isSilenced()) {
        printfnq("Already silenced %s\n", $user->nickname);
        return;
    }
    $cnt = $profile->noticeCount();
    if ($cnt < $minimum) {
        printfnq("Only %d notices posted (minimum %d); skipping\n", $cnt, $minimum);
        return;
    }
    $ss = new Spam_score();
    $ss->query(sprintf("SELECT count(*) as spam_count " . "FROM notice join spam_score on notice.id = spam_score.notice_id " . "WHERE notice.profile_id = %d AND spam_score.is_spam = 1", $profile->id));
    while ($ss->fetch()) {
        $spam_count = $ss->spam_count;
    }
    $spam_percent = $spam_count * 100.0 / $cnt;
    if ($spam_percent > $percent) {
        printfnq("Silencing user %s (%d/%d = %0.2f%% spam)\n", $user->nickname, $spam_count, $cnt, $spam_percent);
        try {
            $profile->silence();
        } catch (Exception $e) {
            printfnq("Error: %s", $e->getMessage());
        }
    }
}
예제 #2
0
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $ss = new Spam_score();
     $ss->is_spam = 1;
     $ss->selectAdd();
     $ss->selectAdd('notice_id');
     Notice::addWhereSinceId($ss, $since_id, 'notice_id');
     Notice::addWhereMaxId($ss, $max_id, 'notice_id');
     $ss->orderBy('notice_created DESC, notice_id DESC');
     if (!is_null($offset)) {
         $ss->limit($offset, $limit);
     }
     $ids = array();
     if ($ss->find()) {
         while ($ss->fetch()) {
             $ids[] = $ss->notice_id;
         }
     }
     return $ids;
 }
예제 #3
0
function testUser($filter, $user)
{
    printfnq("Testing user %s\n", $user->nickname);
    $profile = Profile::getKV('id', $user->id);
    $str = new ProfileNoticeStream($profile, $profile);
    $offset = 0;
    $limit = 100;
    do {
        $notice = $str->getNotices($offset, $limit);
        while ($notice->fetch()) {
            try {
                printfv("Testing notice %d...", $notice->id);
                $result = $filter->test($notice);
                Spam_score::save($notice, $result);
                printfv("%s\n", $result->isSpam ? "SPAM" : "HAM");
            } catch (Exception $e) {
                printfnq("ERROR testing notice %d: %s\n", $notice->id, $e->getMessage());
            }
        }
        $offset += $notice->N;
    } while ($notice->N > 0);
}
예제 #4
0
 protected static function upgradeNoticeCreated()
 {
     $score = new Spam_score();
     $score->whereAdd('notice_created IS NULL');
     if ($score->find()) {
         while ($score->fetch()) {
             $notice = Notice::staticGet('id', $score->notice_id);
             if (!empty($notice)) {
                 $orig = clone $score;
                 $score->notice_created = $notice->created;
                 $score->update($orig);
             }
         }
     }
 }
 /**
  * Pre-cache our spam scores if needed.
  */
 function onEndNoticeListPrefill(array &$notices, array &$profiles, array $notice_ids, Profile $scoped = null)
 {
     if ($this->hideSpam) {
         Spam_score::multiGet('notice_id', $notice_ids);
     }
     return true;
 }
예제 #6
0
 /**
  * Handler method
  *
  * @param array $argarray is ignored since it's now passed in in prepare()
  *
  * @return void
  */
 function handle($argarray = null)
 {
     // Train
     $this->filter->trainOnError($this->notice, $this->category);
     // Re-test
     $result = $this->filter->test($this->notice);
     // Update or insert
     $score = Spam_score::save($this->notice, $result);
     // Show new toggle form
     if ($this->category === SpamFilter::SPAM) {
         $form = new TrainHamForm($this, $this->notice);
     } else {
         $form = new TrainSpamForm($this, $this->notice);
     }
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Page title for page on which we train the spam filter for ham or spam
         $this->element('title', null, _('Train spam filter'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $form->show();
         $this->elementEnd('body');
         $this->endHTML();
     } else {
         common_redirect(common_local_url('spam'), 303);
     }
 }
예제 #7
0
 function onEndNoticeInScope($notice, $profile, &$bResult)
 {
     if ($this->hideSpam) {
         if ($bResult) {
             $score = Spam_score::staticGet('notice_id', $notice->id);
             if (!empty($score) && $score->is_spam) {
                 if (empty($profile) || $profile->id !== $notice->profile_id && !$profile->hasRight(self::REVIEWSPAM)) {
                     $bResult = false;
                 }
             }
         }
     }
     return true;
 }