summaryrefslogtreecommitdiff
path: root/http
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-12-28 15:21:32 +0100
committeremkael <emkael@tlen.pl>2016-12-28 15:21:32 +0100
commit2e47c6fd675f316b8226672ee224796eb9dca769 (patch)
tree60a468d5f0d49d07790ddf1c4348e43f8b88da5c /http
parent4060596983c52a9c6c7d4f875fe9801dbc8b78d2 (diff)
* remembering filtered-out items
Diffstat (limited to 'http')
-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');