From 572f7c50274f5bdc22fcb947d37824c3de213af2 Mon Sep 17 00:00:00 2001 From: Ro Date: Mon, 11 Sep 2023 17:40:13 -0700 Subject: [PATCH] Fix for filtering, quick fix for rating term swap There was a small syntax bug that was causing the sytem to error out when resetting rating terms. Also plugged a bug that was returning locations with ony one block count, which is below the criteria for instances that should be listed and shown in search results --- app/Http/Controllers/FrontIndexController.php | 9 ++- app/Http/Controllers/LocationController.php | 65 ++++++++----------- 2 files changed, 35 insertions(+), 39 deletions(-) diff --git a/app/Http/Controllers/FrontIndexController.php b/app/Http/Controllers/FrontIndexController.php index ad612cb..b8b058e 100644 --- a/app/Http/Controllers/FrontIndexController.php +++ b/app/Http/Controllers/FrontIndexController.php @@ -34,7 +34,14 @@ class FrontIndexController extends Controller $rawSearch = $terms; $terms = str_replace(",", "", $terms); $terms = str_replace(" ", "|", $terms); - $results = DB::select("SELECT * FROM searchlocations('$terms')"); + $raw = DB::select("SELECT * FROM searchlocations('$terms')"); + $results = []; + + foreach ($raw as $item) { + if ($item->block_count > 2) { + array_push($results, $item); + } + } $locations = Location::where("active", true)->get(); $count = count($locations); diff --git a/app/Http/Controllers/LocationController.php b/app/Http/Controllers/LocationController.php index a82b1ba..baeaff5 100644 --- a/app/Http/Controllers/LocationController.php +++ b/app/Http/Controllers/LocationController.php @@ -6,17 +6,10 @@ use Illuminate\Http\Request; use App\Models\Location; use Ramsey\Uuid\Uuid; use Illuminate\Support\Facades\Auth; -use League\Csv\Reader; use App\Models\Source; class LocationController extends Controller { - //url to oli's unified tier 3 list - private $three = 'https://codeberg.org/oliphant/blocklists/raw/branch/main/blocklists/_unified_tier3_blocklist.csv'; - - //url to oli's domain audit containin block counts per domain - private $defed = 'https://codeberg.org/oliphant/blocklists/raw/branch/main/blocklists/other/domain_audit_file.csv'; - public function addLocation(Request $request) { $fields = $request->validate([ @@ -57,19 +50,10 @@ class LocationController extends Controller public function updateLocations() { - //$fresh = file($this->three); - //$deny = Reader::createFromPath($fresh, "r"); - //$deny->setHeaderOffset(0); - //$list = $deny->getRecords(); - //$recordCount = count($fresh); $duplicates = 0; $fresh = 0; - // ['url' => "rage.love"], - //['url' => "indyapocalypse.social"], $unified = []; - //$denycount = array_map('str_getcsv', file($this->defed)); - //$denylist = array_map('str_getcsv', file($this->three)); $sources = Source::where("active", true)->get(); foreach ($sources as $source) { //parsing for mastodon @@ -121,6 +105,30 @@ class LocationController extends Controller } } + //get all locations and sort which are present in unified or not + /* + $sorted = []; + $listed = 0; + $notlisted = 0; + foreach (Location::all() as $location) { + if (array_search($location->url, array_column($unified, 'url'))) { + ++$listed; + // locations present in unfied, so updated + array_push($sorted, [ + 'location' => $location, + 'listed' => true + ]); + } else { + ++$notlisted; + //locations not present + array_push($sorted, [ + 'location' => $location, + 'listed' => false + ]); + } + }; + */ + //once the unified list is created, update current entries or create fresh ones foreach ($unified as $item) { @@ -140,14 +148,14 @@ class LocationController extends Controller // make new entries for instances not present ++$fresh; $images = []; - - $new = Location::create([ + $rating = ($item['rating'] == 'defederate') ? 'suspend' : $item['rating']; + $new = Location::create([ 'uuid' => Uuid::uuid4(), 'name' => $item['url'], 'url' => $item['url'], 'description' => ($item['comment'] != null) ? $item['comment'] : "no description", 'active' => true, - 'rating' => ($item['rating'] == 'defederate') ? 'suspend', + 'rating' => $rating, 'added_by' => 1, 'tags' => 'poor moderation, hate speech', 'images' => json_encode($images), @@ -156,25 +164,6 @@ class LocationController extends Controller } } - //$lookfor = '0sint.social'; - //$index = array_search($lookfor, array_column($unified, 'url')); - //return back()->with('message', 'TOTAL: ' . count($unified) . " - " . $unified[$index]['count'] . " COUNT"); return back()->with('message', $duplicates . ' UPDATED - ' . $fresh . ' CREATED'); - - //$domain = $csv[1000][0]; - //$record = null; - - /* - foreach ($blockcount as $line) { - if ($line[0] == $domain) { - $record = $line; - } - } - if ($record != null) { - return back()->with('message', $domain . ' has ' . $record[1] . ' blocks.'); - } else { - return back()->with('message', 'NO MATCHES'); - } - */ } }