Ejemplo n.º 1
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);
}
Ejemplo n.º 2
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);
     }
 }