/**
 * Inner function - Sends the results of moderation
 * @param string $feedback_request
 * @return bool
 */
function ct_send_feedback($feedback_request = null)
{
    global $ct_options, $ct_data;
    if (empty($feedback_request) && isset($_SESSION['feedback_request']) && preg_match("/^[a-z0-9\\;\\:]+\$/", $_SESSION['feedback_request'])) {
        $feedback_request = $_SESSION['feedback_request'];
        unset($_SESSION['feedback_request']);
    }
    if ($feedback_request !== null) {
        require_once 'cleantalk.class.php';
        $config = get_option('cleantalk_server');
        $ct = new Cleantalk();
        $ct->work_url = $config['ct_work_url'];
        $ct->server_url = $ct_options['server'];
        $ct->server_ttl = $config['ct_server_ttl'];
        $ct->server_changed = $config['ct_server_changed'];
        $ct_request = new CleantalkRequest();
        $ct_request->auth_key = $ct_options['apikey'];
        $ct_request->feedback = $feedback_request;
        $ct->sendFeedback($ct_request);
        if ($ct->server_change) {
            update_option('cleantalk_server', array('ct_work_url' => $ct->work_url, 'ct_server_ttl' => $ct->server_ttl, 'ct_server_changed' => time()));
        }
        return true;
    }
    return false;
}
예제 #2
0
 /**
  * Sending of manual moderation result to CleanTalk server
  * It makes CleanTalk service better
  * Use it in your modules
  * @param string Name of event generated module ('blog', 'forum', etc.)
  * @param int ID of added entity (comment, message, etc)
  * @param string Feedback type - 'Y' or 'N' only
  */
 static function SendFeedback($module, $id, $feedback)
 {
     global $APPLICATION, $DB;
     if (empty($module)) {
         return;
     }
     if (empty($id) || intval($id) < 0) {
         return;
     }
     if (empty($feedback) || $feedback != 'Y' && $feedback != 'N') {
         return;
     }
     $request_id = $DB->Query('SELECT ct_request_id FROM cleantalk_cids WHERE module=\'' . $module . '\' AND cid=' . $id)->Fetch();
     if ($request_id !== FALSE) {
         $DB->Query('DELETE FROM cleantalk_cids WHERE module=\'' . $module . '\' AND cid=' . $id);
         require_once dirname(__FILE__) . '/classes/general/cleantalk.class.php';
         $ct_key = COption::GetOptionString('cleantalk.antispam', 'key', '0');
         $ct_ws = self::GetWorkServer();
         $ct = new Cleantalk();
         $ct->work_url = $ct_ws['work_url'];
         $ct->server_url = $ct_ws['server_url'];
         $ct->server_ttl = $ct_ws['server_ttl'];
         $ct->server_changed = $ct_ws['server_changed'];
         $ct_request = new CleantalkRequest();
         $ct_request->auth_key = $ct_key;
         $ct_request->agent = 'bitrix-370';
         $ct_request->sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
         $ct_request->feedback = $request_id . ':' . ($feedback == 'Y' ? '1' : '0');
         $ct->sendFeedback($ct_request);
     }
 }