示例#1
0
 /**
  * Before save content method
  *
  * Article is passed by reference, but after the save, so no changes will be saved.
  * Method is called right after the content is saved
  *
  * @param   string   $context  The context of the content passed to the plugin (added in 1.6)
  * @param   object   $article  Model
  * @param   boolean  $isNew    If the content is just about to be created
  * @return  void
  * @since   2.5
  */
 public function onContentBeforeSave($context, $article, $isNew)
 {
     if (!App::isSite()) {
         return;
     }
     if ($article instanceof \Hubzero\Base\Object || $article instanceof \Hubzero\Database\Relational) {
         $key = $this->_key($context);
         $content = ltrim($article->get($key));
     } else {
         if (is_object($article) || is_array($article)) {
             return;
         } else {
             $content = $article;
         }
     }
     $content = preg_replace('/^<!-- \\{FORMAT:.*\\} -->/i', '', $content);
     $content = trim($content);
     if (!$content) {
         return;
     }
     // Get the detector manager
     $service = new \Hubzero\Spam\Checker();
     foreach (Event::trigger('antispam.onAntispamDetector') as $detector) {
         if (!$detector) {
             continue;
         }
         $service->registerDetector($detector);
     }
     // Check content
     $data = array('name' => User::get('name'), 'email' => User::get('email'), 'username' => User::get('username'), 'id' => User::get('id'), 'ip' => Request::ip(), 'user_agent' => Request::getVar('HTTP_USER_AGENT', null, 'server'), 'text' => $content);
     $result = $service->check($data);
     // Log errors any of the service providers may have thrown
     if ($service->getError() && App::has('log')) {
         App::get('log')->logger('debug')->info(implode(' ', $service->getErrors()));
     }
     // If the content was detected as spam...
     if ($result->isSpam()) {
         // Learn from it?
         if ($this->params->get('learn_spam', 1)) {
             Event::trigger('antispam.onAntispamTrain', array($content, true));
         }
         // If a message was set...
         if ($message = $this->params->get('message')) {
             Notify::error($message);
         }
         // Increment spam hits count...go to spam jail!
         \Hubzero\User\User::oneOrFail(User::get('id'))->reputation->incrementSpamCount();
         if ($this->params->get('log_spam')) {
             $this->log($result->isSpam(), $data);
         }
         return false;
     }
     // Content was not spam.
     // Learn from it?
     if ($this->params->get('learn_ham', 0)) {
         Event::trigger('antispam.onAntispamTrain', array($content, false));
     }
 }
示例#2
0
 /**
  * Before save content method
  *
  * Article is passed by reference, but after the save, so no changes will be saved.
  * Method is called right after the content is saved
  *
  * @param   string   $context  The context of the content passed to the plugin (added in 1.6)
  * @param   object   $article  A JTableContent object
  * @param   boolean  $isNew    If the content is just about to be created
  * @return  void
  * @since   2.5
  */
 public function onContentBeforeSave($context, $article, $isNew)
 {
     if (!App::isSite()) {
         return;
     }
     if ($article instanceof \Hubzero\Base\Object) {
         $key = $this->_key($context);
         $content = ltrim($article->get($key));
     } else {
         if (is_object($article) || is_array($article)) {
             return;
         } else {
             $content = $article;
         }
     }
     $content = preg_replace('/^<!-- \\{FORMAT:.*\\} -->/i', '', $content);
     $content = trim($content);
     if (!$content) {
         return;
     }
     // Get the detector manager
     $service = new \Hubzero\Spam\Checker();
     foreach (Event::trigger('antispam.onAntispamDetector') as $detector) {
         if (!$detector) {
             continue;
         }
         $service->registerDetector($detector);
     }
     // Check content
     $data = array('name' => User::get('name'), 'email' => User::get('email'), 'username' => User::get('username'), 'id' => User::get('id'), 'text' => $content);
     $result = $service->check($data);
     // If the content was detected as spam...
     if ($result->isSpam()) {
         // Learn from it?
         if ($this->params->get('learn_spam', 1)) {
             Event::trigger('antispam.onAntispamTrain', array($content, true));
         }
         // If a message was set...
         if ($message = $this->params->get('message')) {
             Notify::error($message);
         }
         // Increment spam hits count...go to spam jail!
         \Hubzero\User\User::oneOrFail(User::get('id'))->reputation->incrementSpamCount();
         return false;
     }
     // Content was not spam.
     // Learn from it?
     if ($this->params->get('learn_ham', 0)) {
         Event::trigger('antispam.onAntispamTrain', array($content, false));
     }
 }
示例#3
0
 /**
  * Displays a list of records
  *
  * @return  void
  */
 public function checkTask()
 {
     $results = null;
     $sample = '';
     if ($sample = Request::getVar('sample', '', 'post', 'none', 2)) {
         $service = new \Hubzero\Spam\Checker();
         foreach (Event::trigger('antispam.onAntispamDetector') as $detector) {
             if (!$detector) {
                 continue;
             }
             $service->registerDetector($detector);
         }
         $service->check($sample);
         $results = $service->getReport();
     }
     // Output the HTML
     $this->view->set('sample', $sample)->set('results', $results)->setErrors($this->getErrors())->display();
 }