From 88e78f2c4a57c27877a61eab7c06d078eb034ef2 Mon Sep 17 00:00:00 2001 From: Ro Date: Wed, 12 Apr 2023 16:46:21 -0700 Subject: [PATCH] CSV Export for Mastdon Added a link to export current active sites in the DB to a consumable CSV file. More formats will be added but this one needs to be tested first based on the ubiquity of Mastodon --- public/assets/css/front/exports.css | 12 ++++++++ public/assets/css/front/start.css | 1 + src/Controller/Routes/Front/Index.php | 24 ++++++++++++++++ src/Service/HandleExports.php | 41 +++++++++++++++++++++++++++ templates/front/exports.twig | 11 +++++++ 5 files changed, 89 insertions(+) create mode 100644 public/assets/css/front/exports.css create mode 100644 src/Service/HandleExports.php create mode 100644 templates/front/exports.twig diff --git a/public/assets/css/front/exports.css b/public/assets/css/front/exports.css new file mode 100644 index 0000000..133107f --- /dev/null +++ b/public/assets/css/front/exports.css @@ -0,0 +1,12 @@ +section[role="exports"] { + background: var(--primary); + width: 100%; + max-width: 600px; + padding: 10px; + margin: 0 auto; + color: var(--white); +} + +section[role="exports"] a { + color: var(--highlight); +} diff --git a/public/assets/css/front/start.css b/public/assets/css/front/start.css index 106e4bb..74d1328 100644 --- a/public/assets/css/front/start.css +++ b/public/assets/css/front/start.css @@ -7,3 +7,4 @@ @import "about.css"; @import "listing.css"; @import "location.css"; +@import "exports.css"; diff --git a/src/Controller/Routes/Front/Index.php b/src/Controller/Routes/Front/Index.php index c5b69ae..13f0725 100644 --- a/src/Controller/Routes/Front/Index.php +++ b/src/Controller/Routes/Front/Index.php @@ -12,6 +12,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use App\Service\Auth; use App\Service\Render; use App\Service\HandleLocations; +use App\Service\HandleExports; class Index extends AbstractController { @@ -95,4 +96,27 @@ class Index extends AbstractController "prevPage" => $prev ], "About The Bad Space", "front/listing.twig"); } + + /** + * @Route("/exports/{type}", name="exports") + */ + public function showExports( + Request $request, + Auth $auth, + Render $render, + HandleLocations $locations, + HandleExports $exports, + string $type = "none" + ): Response { + switch ($type) { + case 'none': + case '': + return $render->page([], "File Exports", "front/exports.twig"); + break; + case 'mastodon': + return $exports->buildMastodonCSV(); + + break; + } + } } diff --git a/src/Service/HandleExports.php b/src/Service/HandleExports.php new file mode 100644 index 0000000..c1baca8 --- /dev/null +++ b/src/Service/HandleExports.php @@ -0,0 +1,41 @@ +locations = $locations; + } + + public function buildMastodonCSV() + { + $records = [['domain', 'severity', 'public_comment', 'reject_media', 'reject_reports', 'obfuscate']]; + $entries = $this->locations->getActiveLocations(); + foreach ($entries as $entry) { + $item = [$entry->getUrl(), $entry->getRating(), $entry->getDescription(), "FALSE", "FALSE", "FALSE"]; + array_push($records, $item); + } + + $tmp = new \SplTempFileObject(); + foreach ($records as $record) { + $tmp->fputcsv($record); + } + + $reader = Reader::createFromFileObject($tmp); + return new Response($reader->getContent(), 200, [ + 'Content-Encoding' => 'none', + 'Content-Type' => 'text/csv; charset=UTF-8', + 'Content-Disposition' => 'attachment; filename="the-bad-space-mastodon.csv"', + 'Content-Description' => 'File Transfer', + ]); + + //return $path; + } +} diff --git a/templates/front/exports.twig b/templates/front/exports.twig new file mode 100644 index 0000000..6025bf7 --- /dev/null +++ b/templates/front/exports.twig @@ -0,0 +1,11 @@ +{% extends "base/frame.twig" %} +{% block stylesheets %} + + {% endblock %} + + {% block main %} +
+

File Exports

+ For Mastodon +
+ {% endblock %}