summaryrefslogtreecommitdiff
path: root/http/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'http/index.php')
-rw-r--r--http/index.php51
1 files changed, 38 insertions, 13 deletions
diff --git a/http/index.php b/http/index.php
index e4c1ca5..1c0fae3 100644
--- a/http/index.php
+++ b/http/index.php
@@ -57,25 +57,50 @@ if ($user) {
unset($content->httpstatus);
if ($spamFilter) {
+ $db = new PDO('sqlite:../spamlinks.db');
+ $spamQuery = $db->prepare('SELECT id FROM spamlinks WHERE username = :name');
+ $spamQuery->bindParam(':name', $user);
+ $spamQuery->execute();
+ $spamContent = array_map(
+ function($row) {
+ return $row[0];
+ },
+ $spamQuery->fetchAll()
+ );
+ $spamHashes = [];
$filteredContent = [];
foreach ($content as $c) {
- $urls = array_map(
- function($url) {
- return $url->expanded_url;
- },
- $c->entities->urls
- );
- if (!$urls) {
- $filteredContent[] = $c;
- } else {
- sort($urls);
- $urlHash = md5(implode('|', $urls));
- $filteredContent[$urlHash] = $c;
+ if (!in_array($c->id_str, $spamContent)) {
+ $urls = array_map(
+ function($url) {
+ return $url->expanded_url;
+ },
+ $c->entities->urls
+ );
+ if (!$urls) {
+ $filteredContent[] = $c;
+ } else {
+ sort($urls);
+ $urlHash = md5(implode('|', $urls));
+ if (isset($filteredContent[$urlHash])) {
+ $spamHashes[] = $c->id_str;
+ }
+ $filteredContent[$urlHash] = $c;
+ }
}
}
usort($filteredContent, function($c1, $c2) { return strcmp($c1->id_str, $c2->id_str); });
- array_reverse($filteredContent);
$content = $filteredContent;
+ if ($spamHashes) {
+ foreach ($spamHashes as $hash) {
+ $insertQuery = $db->prepare(
+ 'INSERT INTO spamlinks(id, username) VALUES (?, ?)'
+ );
+ $insertQuery->bindParam(1, $hash);
+ $insertQuery->bindParam(2, $user);
+ $insertQuery->execute();
+ }
+ }
}
require_once('../lib/smarty3/Smarty.class.php');