function post_index() { $base = $this->getSblamBase(); $config = Server::getDefaultConfig(); $config['throttle']['enabled'] = '0'; // FIXME: this should be handled within plugins $config['linksleeve']['enabled'] = '0'; $config['dupes']['enabled'] = '0'; $sblam = new Sblam($config, $this->services); $num = !empty($_POST['num']) ? intval($_POST['num']) : 100; foreach ($this->services->getDB()->query("SELECT id FROM posts_meta WHERE spamscore IS NULL and spamcert IS NULL ORDER BY rand() LIMIT\n{$num}")->fetchAll(PDO::FETCH_ASSOC) as $r) { $score = $sblam->testPost($base->getPostById($r['id'])); $this->services->getDB()->prepareExecute("UPDATE posts_meta SET spamscore=?,spamcert=? WHERE id=?", array(round($score[0] * 100), round($score[1] * 100), $r['id'])); $this->services->getDB()->prepareExecute("UPDATE posts_data SET spamreason=? WHERE id=?", array($score[2], $r['id'])); } }
function process(ServerRequest $req) { $starttime = microtime(true); $data = $req->getData(); if ($data['ip'] == '127.0.0.1' && $req->isDefaultAccount()) { throw new ServerException('Brak klucza API', 403); } $fs = isset($data['fields']) ? explode("\n", strtolower($data['fields'])) : array(); $postdata = array(); foreach ($data as $key => $val) { if (substr($key, 0, 5) === 'POST_') { $postdata[strtolower(substr($key, 5))] = $val; } if (substr($key, 0, 6) === 'field_') { $fs[substr($key, 6)] = $val; } } list($content, $author, $email, $url) = $this->findFields($postdata, $fs); /* short-circuit filtering for testing */ if (preg_match('!^[^a-z]*to\\s+jest\\s+test\\s+(sblam|spam)[ua]?[^a-z]*$!i', $content)) { $req->returnResult(1); return; } $p = $this->postFromFields($data, $postdata, $content, $author, $email, $url, $req->getIPs()); if (!$req->storeData($p)) { dieerr(500, "Awaria bazy danych"); } $config = $req->customizeConfig($this->config); $sblam = new Sblam($config, $this->services); $rawresult = $sblam->testPost($p); list($score, $cert, $reason) = $rawresult; $endtime = microtime(true); if ($content == '' && $author == '') { $req->returnResult(1); } else { if ($cert < 0.45 || abs($score) < 0.38) { $req->returnResult($score > 0 ? 1 : -1); } else { $req->returnResult($score > 0 ? 2 : -2); } } set_time_limit(25); $rawresult = $sblam->reportResult($p, $rawresult); $req->storeResult($score, $cert, $reason, $endtime - $starttime, empty($p->bayesadded) ? 0 : 6, isset($rawresult[3]) ? Sblam::formatProfiling($rawresult[3]) : ''); }