From 2e47c6fd675f316b8226672ee224796eb9dca769 Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 28 Dec 2016 15:21:32 +0100 Subject: * remembering filtered-out items --- http/index.php | 51 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'http') 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'); -- cgit v1.2.3