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
develop
Ro 1 year ago
parent 0c2b8bae7c
commit 572f7c5027
Signed by: are0h
GPG Key ID: 29B551CDBD4D3B50

@ -34,7 +34,14 @@ class FrontIndexController extends Controller
$rawSearch = $terms; $rawSearch = $terms;
$terms = str_replace(",", "", $terms); $terms = str_replace(",", "", $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(); $locations = Location::where("active", true)->get();
$count = count($locations); $count = count($locations);

@ -6,17 +6,10 @@ use Illuminate\Http\Request;
use App\Models\Location; use App\Models\Location;
use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Uuid;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use League\Csv\Reader;
use App\Models\Source; use App\Models\Source;
class LocationController extends Controller 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) public function addLocation(Request $request)
{ {
$fields = $request->validate([ $fields = $request->validate([
@ -57,19 +50,10 @@ class LocationController extends Controller
public function updateLocations() public function updateLocations()
{ {
//$fresh = file($this->three);
//$deny = Reader::createFromPath($fresh, "r");
//$deny->setHeaderOffset(0);
//$list = $deny->getRecords();
//$recordCount = count($fresh);
$duplicates = 0; $duplicates = 0;
$fresh = 0; $fresh = 0;
// ['url' => "rage.love"],
//['url' => "indyapocalypse.social"],
$unified = []; $unified = [];
//$denycount = array_map('str_getcsv', file($this->defed));
//$denylist = array_map('str_getcsv', file($this->three));
$sources = Source::where("active", true)->get(); $sources = Source::where("active", true)->get();
foreach ($sources as $source) { foreach ($sources as $source) {
//parsing for mastodon //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 //once the unified list is created, update current entries or create fresh ones
foreach ($unified as $item) { foreach ($unified as $item) {
@ -140,14 +148,14 @@ class LocationController extends Controller
// make new entries for instances not present // make new entries for instances not present
++$fresh; ++$fresh;
$images = []; $images = [];
$rating = ($item['rating'] == 'defederate') ? 'suspend' : $item['rating'];
$new = Location::create([ $new = Location::create([
'uuid' => Uuid::uuid4(), 'uuid' => Uuid::uuid4(),
'name' => $item['url'], 'name' => $item['url'],
'url' => $item['url'], 'url' => $item['url'],
'description' => ($item['comment'] != null) ? $item['comment'] : "no description", 'description' => ($item['comment'] != null) ? $item['comment'] : "no description",
'active' => true, 'active' => true,
'rating' => ($item['rating'] == 'defederate') ? 'suspend', 'rating' => $rating,
'added_by' => 1, 'added_by' => 1,
'tags' => 'poor moderation, hate speech', 'tags' => 'poor moderation, hate speech',
'images' => json_encode($images), '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'); 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');
}
*/
} }
} }

Loading…
Cancel
Save