@ -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 = [];
$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');
}
*/
}
}