thebadspace/app/Http/Controllers/FrontIndexController.php
Ro 7feb76517a
Added blocklist updating, main nav tweaks
Implemented Oliphant's unified tier 3 blocklist and the supplementary
instance audit file that tracks how many times an instance has been
blocked by a trusted sources member. Keeping the update function manual
for now to make sure it works smooth, then well automate so it checks on
    it's on at regular intervals.

NOTE: Lists used are located at the following urls:
https://codeberg.org/oliphant/blocklists/src/branch/main/blocklists/_unified_tier3_blocklist.csv
https://codeberg.org/oliphant/blocklists/src/branch/main/blocklists/other/domain_audit_file.csv

Also simplified the main nav to just include a link to the den index
when logged in
2023-08-24 15:27:14 -07:00

101 lines
2.9 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Models\Location;
class FrontIndexController extends Controller
{
private $limit = 15;
public function start()
{
$locations = Location::where("active", true)->get();
$count = count($locations);
$recent = Location::where("active", true)
->limit(5)->orderByDesc('updated_at')->get();
//$result = DB::select("SELECT * FROM searchlocations('$terms')");
return view('front.index', [
'count' => $count,
'recent' => $recent,
'title' => "The Bad Space"
]);
}
public function indexSearch(Request $request)
{
$terms = $request->index_search;
$rawSearch = $terms;
$terms = str_replace(",", "", $terms);
$terms = str_replace(" ", "|", $terms);
$results = DB::select("SELECT * FROM searchlocations('$terms')");
$locations = Location::where("active", true)->get();
$count = count($locations);
$recent = Location::where("active", true)
->limit(5)->orderByDesc('updated_at')->get();
return view('front.index', [
'count' => $count,
'recent' => $recent,
'title' => "The Bad Space",
'results' => $results
]);
}
public function about()
{
return view('front.about', [
'title' => "ABOUT"
]);
}
public function location(string $uuid = "1")
{
$location = Location::where("uuid", $uuid)->first();
$name = "NO LOCATION FOUND";
if ($location) {
$name = $location->name;
}
return view('front.location', [
'title' => str_replace(".", " ", $name),
'location' => $location,
'images' => json_decode($location->images),
'updated' => $location->updated_at->format('Y M d'),
]);
}
public function listings(int $pageNum = 1)
{
$range = $pageNum * $this->limit - $this->limit;
$active = Location::where("active", true)->where('block_count', '>', 2)->get();
$locations = Location::where("active", true)->where('block_count', '>', 2)
->limit($this->limit)->offset($range)->orderByDesc('id')->get();
$pageCount = ceil(count($active) / $this->limit);
$next = $pageNum + 1;
if ($next > $pageCount) {
$next = 1;
}
$prev = $pageNum - 1;
if ($prev <= 0) {
$prev = $pageCount;
}
return view('front.listing', [
'title' => "Listings",
"totalPages" => $pageCount,
"prev" => $prev,
"next" => $next,
'pageNum' => $pageNum,
'locations' => $locations
]);
}
}