function event_hook($event, &$bag, &$eventData, $addData = null)
 {
     global $serendipity;
     $hooks =& $bag->get('event_hooks');
     if (isset($hooks[$event])) {
         switch ($event) {
             case 'frontend_saveComment':
                 if (!is_array($eventData) || serendipity_db_bool($eventData['allow_comments'])) {
                     $serendipity['csuccess'] = 'true';
                     // Check for IP listed in RBL
                     require_once (defined('S9Y_PEAR_PATH') ? S9Y_PEAR_PATH : 'bundled-libs/') . 'Net/DNSBL.php';
                     $dnsbl = new Net_DNSBL();
                     $remoteIP = $_SERVER['REMOTE_ADDR'];
                     $dnsbl->setBlacklists(explode(',', $this->get_config('rbllist')));
                     if ($dnsbl->isListed($remoteIP)) {
                         $eventData = array('allow_comments' => false);
                         // old - but missing $dnsbl->getTxt() function in delivered old DNSBL.php
                         //$serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_RBL . ' ('.implode(', ', $dnsbl->getTxt($remoteIP)).')';
                         $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_RBL . ' (' . $remoteIP . ')';
                         return false;
                     }
                     // Check for IP listed in http:BL
                     require_once 'httpbl.php';
                     $honeypot_apikey = $this->get_config('httpBL_key');
                     if (!empty($honeypot_apikey)) {
                         $h = new http_bl($honeypot_apikey);
                         // known spammer
                         // DEBUG                    $remoteIP = '206.51.226.106';
                         // A quick tip for testing: change $remoteIP = '$_SERVER['REMOTE_ADDR']; on line 89 to e.g.
                         // $remoteIP = '109.200.6.202'; // Comments should get rejected as this ip is on both blacklists right now.
                         $r = $h->query($remoteIP);
                         if ($r == 2) {
                             $eventData = array('allow_comments' => false);
                             $reason = PLUGIN_EVENT_SPAMBLOCK_REASON_HONEYPOT . $h->type_txt . ' [' . $h->type_num . '] with a score of ' . $h->score . ', last seen since ' . $h->days . ' days';
                             $serendipity['messagestack']['comments'][] = $reason;
                         }
                         return false;
                     }
                 }
                 return true;
                 break;
             default:
                 return false;
                 break;
         }
     } else {
         return false;
     }
 }
 private function performChecks()
 {
     $request = JRequest::get();
     // Calc check
     if ($this->params->get('type_calc')) {
         if ($this->_session->get('rot13', null, 'easycalccheck') == 1) {
             $spamcheckresult = base64_decode(str_rot13($this->_session->get('spamcheckresult', null, 'easycalccheck')));
         } else {
             $spamcheckresult = base64_decode($this->_session->get('spamcheckresult', null, 'easycalccheck'));
         }
         $spamcheck = JRequest::getInt($this->_session->get('spamcheck', null, 'easycalccheck'), '', 'post');
         $this->_session->clear('rot13', 'easycalccheck');
         $this->_session->clear('spamcheck', 'easycalccheck');
         $this->_session->clear('spamcheckresult', 'easycalccheck');
         if (!is_numeric($spamcheckresult) || $spamcheckresult != $spamcheck) {
             return false;
             // Failed
         }
     }
     // Hidden field
     if ($this->params->get('type_hidden')) {
         $hidden_field = $this->_session->get('hidden_field', null, 'easycalccheck');
         $this->_session->clear('hidden_field', 'easycalccheck');
         if (JRequest::getVar($hidden_field, '', 'post')) {
             return false;
             // Hidden field was filled out - failed
         }
     }
     // Time lock
     if ($this->params->get('type_time')) {
         $time = $this->_session->get('time', null, 'easycalccheck');
         $this->_session->clear('time', 'easycalccheck');
         if (time() - $this->params->get('type_time_sec') <= $time) {
             return false;
             // Submitted too fast - failed
         }
     }
     // Own Question
     // Conversion to lower case
     if ($this->params->get('question')) {
         $answer = strtolower(JRequest::getString($this->_session->get('question', null, 'easycalccheck'), '', 'post'));
         $this->_session->clear('question', 'easycalccheck');
         if ($answer != strtolower($this->params->get('question_a'))) {
             return false;
             // Question wasn't answered - failed
         }
     }
     // StopForumSpam - Check the IP Address
     // Further informations: http://www.stopforumspam.com
     if ($this->params->get('stopforumspam')) {
         $url = 'http://www.stopforumspam.com/api?ip=' . $this->_session->get('ip', null, 'easycalccheck');
         // Function test - Comment out to test - Important: Enter a active Spam-IP
         // $ip = '88.180.52.46';
         // $url = 'http://www.stopforumspam.com/api?ip='.$ip;
         $response = false;
         $is_spam = false;
         if (function_exists('curl_init')) {
             $ch = curl_init($url);
             curl_setopt($ch, CURLOPT_HEADER, 0);
             curl_setopt($ch, CURLOPT_POST, 0);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             $response = curl_exec($ch);
             curl_close($ch);
         }
         if ($response) {
             preg_match('#<appears>(.*)</appears>#', $response, $out);
             $is_spam = $out[1];
         } else {
             $response = @fopen($url, 'r');
             if ($response) {
                 while (!feof($response)) {
                     $line = fgets($response, 1024);
                     if (preg_match('#<appears>(.*)</appears>#', $line, $out)) {
                         $is_spam = $out[1];
                         break;
                     }
                 }
                 fclose($response);
             }
         }
         if ($is_spam == 'yes' and $response == true) {
             return false;
             // Spam-IP - failed
         }
     }
     // Honeypot Project
     // Further informations: http://www.projecthoneypot.org/home.php
     // BL ACCESS KEY - http://www.projecthoneypot.org/httpbl_configure.php
     if ($this->params->get('honeypot')) {
         require_once dirname(__FILE__) . DS . 'easycalccheckplus' . DS . 'honeypot.php';
         $http_blKey = $this->params->get('honeypot_key');
         if ($http_blKey) {
             $http_bl = new http_bl($http_blKey);
             $result = $http_bl->query($this->_session->get('ip', null, 'easycalccheck'));
             // Function test - Comment out to test - Important: Enter a active Spam-IP
             // $ip = '117.21.224.251';
             // $result = $http_bl->query($ip);
             if ($result == 2) {
                 return false;
             }
         }
     }
     // Akismet
     // Further informations: http://akismet.com/
     if ($this->params->get('akismet')) {
         require_once dirname(__FILE__) . DS . 'easycalccheckplus' . DS . 'akismet.php';
         $akismet_key = $this->params->get('akismet_key');
         if ($akismet_key) {
             $akismet_url = JURI::getInstance()->toString();
             $name = '';
             $email = '';
             $url = '';
             $comment = '';
             if ($request['option'] == 'com_contact') {
                 $name = $request['jform']['contact_name'];
                 $email = $request['jform']['contact_email'];
                 $comment = $request['jform']['contact_message'];
             } elseif ($request['option'] == 'com_users') {
                 $name = $request['jform']['name'];
                 $email = $request['jform']['email1'];
                 if (isset($request['jform']['email'])) {
                     $email = $request['jform']['email'];
                 }
             } elseif ($request['option'] == 'com_comprofiler') {
                 $name = $request['name'];
                 $email = $request['email'];
                 if (isset($request['checkusername'])) {
                     $name = $request['checkusername'];
                 }
                 if (isset($request['checkemail'])) {
                     $email = $request['checkemail'];
                 }
             } elseif ($request['option'] == 'com_easybookreloaded') {
                 $name = $request['gbname'];
                 $email = $request['gbmail'];
                 $comment = $request['gbtext'];
                 if (isset($request['gbpage'])) {
                     $url = $request['gbpage'];
                 }
             } elseif ($request['option'] == 'com_phocaguestbook') {
                 $name = $request['pgusername'];
                 $email = $request['email'];
                 $comment = $request['pgbcontent'];
             } elseif ($request['option'] == 'com_dfcontact') {
                 $name = $request['name'];
                 $email = $request['email'];
                 $comment = $request['message'];
             } elseif ($request['option'] == 'com_flexicontact') {
                 $name = $request['from_name'];
                 $email = $request['from_email'];
                 $comment = $request['area_data'];
             } elseif ($request['option'] == 'com_alfcontact') {
                 $name = $request['name'];
                 $email = $request['email'];
                 $comment = $request['message'];
             } elseif ($request['option'] == 'com_community') {
                 $name = $request['usernamepass'];
                 $email = $request['emailpass'];
             } elseif ($request['option'] == 'com_virtuemart') {
                 $name = $request['name'];
                 $email = $request['email'];
                 $comment = $request['comment'];
             } elseif ($request['option'] == 'com_jshopping') {
                 $name = $request['f_name'];
                 $email = $request['email'];
             }
             $akismet = new Akismet($akismet_url, $akismet_key);
             $akismet->setCommentAuthor($name);
             $akismet->setCommentAuthorEmail($email);
             $akismet->setCommentAuthorURL($url);
             $akismet->setCommentContent($comment);
             if ($akismet->isCommentSpam()) {
                 return false;
             }
         }
     }
     // ReCaptcha
     // Further informations: http://www.google.com/recaptcha
     if ($this->params->get('recaptcha') and $this->params->get('recaptcha_publickey') and $this->params->get('recaptcha_privatekey')) {
         require_once dirname(__FILE__) . DS . 'easycalccheckplus' . DS . 'recaptchalib.php';
         $privatekey = $this->params->get('recaptcha_privatekey');
         $resp = recaptcha_check_answer($privatekey, $this->_session->get('ip', null, 'easycalccheck'), $request['recaptcha_challenge_field'], $request['recaptcha_response_field']);
         if (!$resp->is_valid) {
             return false;
         }
     }
     // Botscout - Check the IP Address
     // Further informations: http://botscout.com/
     if ($this->params->get('botscout') and $this->params->get('botscout_key')) {
         $url = 'http://botscout.com/test/?ip=' . $this->_session->get('ip', null, 'easycalccheck') . '&key=' . $this->params->get('botscout_key');
         // Function test - Comment out to test - Important: Enter a active Spam-IP
         // $ip = '87.103.128.199';
         // $url = 'http://botscout.com/test/?ip='.$ip.'&key='.$this->params->get('botscout_key');
         $response = false;
         $is_spam = false;
         if (function_exists('curl_init')) {
             $ch = curl_init($url);
             curl_setopt($ch, CURLOPT_HEADER, 0);
             curl_setopt($ch, CURLOPT_POST, 0);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             $response = curl_exec($ch);
             curl_close($ch);
         }
         if ($response) {
             $is_spam = substr($response, 0, 1);
         } else {
             $response = @fopen($url, 'r');
             if ($response) {
                 while (!feof($response)) {
                     $line = fgets($response, 1024);
                     $is_spam = substr($line, 0, 1);
                 }
                 fclose($response);
             }
         }
         if ($is_spam == 'Y' and $response == true) {
             // Spam-IP - failed
             return false;
         }
     }
     // Mollom
     // Further informations: http://mollom.com/
     if ($this->params->get('mollom') and $this->params->get('mollom_publickey') and $this->params->get('mollom_privatekey')) {
         require_once dirname(__FILE__) . DS . 'easycalccheckplus' . DS . 'mollom.php';
         Mollom::setPublicKey($this->params->get('mollom_publickey'));
         Mollom::setPrivateKey($this->params->get('mollom_privatekey'));
         $servers = Mollom::getServerList();
         $name = '';
         $email = '';
         $url = '';
         $comment = '';
         if ($request['option'] == 'com_contact') {
             $name = $request['jform']['contact_name'];
             $email = $request['jform']['contact_email'];
             $comment = $request['jform']['contact_message'];
         } elseif ($request['option'] == 'com_users') {
             $name = $request['jform']['name'];
             $email = $request['jform']['email1'];
             if (isset($request['jform']['email'])) {
                 $email = $request['jform']['email'];
             }
         } elseif ($request['option'] == 'com_comprofiler') {
             $name = $request['name'];
             $email = $request['email'];
             if (isset($request['checkusername'])) {
                 $name = $request['checkusername'];
             }
             if (isset($request['checkemail'])) {
                 $email = $request['checkemail'];
             }
         } elseif ($request['option'] == 'com_easybookreloaded') {
             $name = $request['gbname'];
             $email = $request['gbmail'];
             $comment = $request['gbtext'];
             if (isset($request['gbpage'])) {
                 $url = $request['gbpage'];
             }
         } elseif ($request['option'] == 'com_phocaguestbook') {
             $name = $request['pgusername'];
             $email = $request['email'];
             $comment = $request['pgbcontent'];
         } elseif ($request['option'] == 'com_dfcontact') {
             $name = $request['name'];
             $email = $request['email'];
             $comment = $request['message'];
         } elseif ($request['option'] == 'com_flexicontact') {
             $name = $request['from_name'];
             $email = $request['from_email'];
             $comment = $request['area_data'];
         } elseif ($request['option'] == 'com_alfcontact') {
             $name = $request['name'];
             $email = $request['email'];
             $comment = $request['message'];
         } elseif ($request['option'] == 'com_community') {
             $name = $request['usernamepass'];
             $email = $request['emailpass'];
         } elseif ($request['option'] == 'com_virtuemart') {
             $name = $request['name'];
             $email = $request['email'];
             $comment = $request['comment'];
         } elseif ($request['option'] == 'com_jshopping') {
             $name = $request['f_name'];
             $email = $request['email'];
         }
         $feedback = Mollom::checkContent(null, null, $comment, $name, $url, $email);
         if ($feedback['spam'] == 'spam') {
             return false;
         }
     }
     $this->_session->clear('ip', 'easycalccheck');
     $this->_session->clear('saved_data', 'easycalccheck');
     return true;
 }