diff --git a/app/Http/Controllers/ExportController.php b/app/Http/Controllers/ExportController.php index 9d43103..fa57006 100644 --- a/app/Http/Controllers/ExportController.php +++ b/app/Http/Controllers/ExportController.php @@ -2,34 +2,56 @@ namespace App\Http\Controllers; +use App\Models\Location; +use App\Models\Source; + class ExportController extends Controller { + public function exportIndex() + { + return view('front.exports', [ + 'title' => "Exports" + ]); + } + // - public function exportCSV() + public function exportCSV($type, $percent) { - /* - $columns = [ - 'id', - 'product_name', - 'product_url', - 'price', - 'category' - ]; - - $products = [ - [1, 'product 1', 'https://example.com/product-1', '9.99', 'category 1'], - [2, 'product 2', 'https://example.com/product-2', '19.99', 'category 2'], - [3, 'product 3', 'https://example.com/product-3', '29.99', 'category 3'], - [4, 'product 4', 'https://example.com/product-4', '39.99', 'category 4'], - ]; + $columns = []; + $list = []; + + $locations = Location::where("active", true)->get(); + $sources = Source::where("active", true)->get(); + if ($type == 'mastodon') { + $columns = [ + 'domain', + 'severity', + 'public_comment', + 'reject_media', + 'reject_reports', + 'obfuscate', + ]; + }; + + foreach ($locations as $location) { + $total = $location->block_count + $location->silence_count; + if ($total >= 2) { + $rate = $total / count($sources); + if ($rate * 100 >= $percent) { + if ($type == 'mastodon') { + $comments = str_replace(",", ";", $location->description); + array_push($list, [$location->url, $location->rating, $comments, "FALSE", "FALSE", "FALSE"]); + } + } + } + } header('Content-Type: text/csv'); - header('Content-Disposition: attachment; filename="products.csv"'); + header('Content-Disposition: attachment; filename=' . $type . "-" . $percent); echo implode(',', $columns) . PHP_EOL; - foreach ($products as $product) { - echo implode(',', $product) . PHP_EOL; + foreach ($list as $item) { + echo implode(',', $item) . PHP_EOL; } - */ } } diff --git a/resources/views/frame.blade.php b/resources/views/frame.blade.php index 8080a6d..a24854e 100644 --- a/resources/views/frame.blade.php +++ b/resources/views/frame.blade.php @@ -42,6 +42,9 @@ Listings
+ + Exports +
@if(Auth::check()) Den diff --git a/resources/views/front/exports.blade.php b/resources/views/front/exports.blade.php index e69de29..3f0dbb8 100644 --- a/resources/views/front/exports.blade.php +++ b/resources/views/front/exports.blade.php @@ -0,0 +1,24 @@ +@extends('frame') +@section('title', 'The Bad Space|Exports') + @section('main-content') + @parent +
+
+

CSV Exports

+ Heat Rating is the percentage of Current Sources that have taken action against an instance. The higher the number of Sources that have silenced and/or suspended an instance, the higher the Heat Rating.* +

For Mastodon

+ +
Heat Rating 90%
+ Heat Rating 80%
+ Heat Rating 70%
+ Heat Rating 60%
+ Heat Rating 50%
+ Heat Rating 40%
+ Heat Rating 30%
+ Heat Rating 20%
+
+ * Heating Ratings are still a work in progress so please review list before using. +

+
+
+ @endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 9c62fbd..aa2e6f2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -26,7 +26,8 @@ Route::get("/location/{uuid}", [FrontIndexController::class, 'location']); Route::post("/search", [FrontIndexController::class, 'indexSearch']); //exports -Route::get("/exports/test", [ExportController::class, 'exportCSV']); +Route::get("/exports", [ExportController::class, 'exportIndex']); +Route::get("/exports/{type}/{rate}", [ExportController::class, 'exportCSV']); //auth Route::get("/login", [AuthController::class, 'showLogin']);