From a15db82697831f8628b7eb39e5ad135f9b196a1b Mon Sep 17 00:00:00 2001 From: Ro Date: Thu, 28 Sep 2023 14:02:35 -0700 Subject: [PATCH] Added Exports by Heat Rating Reactivated CSV exports based on Heat Rating, which is the percentage of Current Sources the have taken action, a suspend or a silence, against an instanct. The higher the Heat Rating, the more Sources that have taken actions agaisnt it, so they should be viewed with caution --- app/Http/Controllers/ExportController.php | 62 +++++++++++++++-------- resources/views/frame.blade.php | 3 ++ resources/views/front/exports.blade.php | 24 +++++++++ routes/web.php | 3 +- 4 files changed, 71 insertions(+), 21 deletions(-) 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 exportCSV() + public function exportIndex() { - /* - $columns = [ - 'id', - 'product_name', - 'product_url', - 'price', - 'category' - ]; + return view('front.exports', [ + 'title' => "Exports" + ]); + } - $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'], - ]; + // + public function exportCSV($type, $percent) + { + $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 +
+ +
+ @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']);