From 03180d00046e161227ca3d5a05d84ee2a8a9784a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C5=A1a=20Puk=C5=A1i=C4=8D?= Date: Tue, 29 Jul 2025 13:46:49 +0200 Subject: [PATCH] Downsizing: remove nzines --- config/packages/security.yaml | 1 - config/packages/workflow.yaml | 27 -- publication/Newsroom/Arts/arts.yaml | 16 ++ publication/Newsroom/Digital/digital.yaml | 23 ++ publication/Newsroom/Insight/insight.yaml | 23 ++ publication/Newsroom/Lifestyle/lifestyle.yaml | 24 ++ .../Newsroom/Reflections/reflections.yaml | 26 ++ publication/Newsroom/newsroom.yaml | 14 + src/Command/QualityCheckArticlesCommand.php | 69 ----- src/Controller/NzineController.php | 259 ------------------ src/Entity/Nzine.php | 141 ---------- src/Entity/NzineBot.php | 51 ---- src/Enum/IndexStatusEnum.php | 11 - src/Form/NzineBotType.php | 32 --- src/Form/NzineType.php | 30 -- src/Repository/NzineRepository.php | 43 --- src/Service/NzineWorkflowService.php | 147 ---------- src/Twig/Components/Organisms/ZineList.php | 37 --- .../components/Organisms/ZineList.html.twig | 16 -- templates/components/UserMenu.html.twig | 3 - templates/pages/author.html.twig | 10 - templates/pages/nzine-editor.html.twig | 66 ----- templates/pages/nzine.html.twig | 16 -- translations/messages.en.yaml | 2 - 24 files changed, 126 insertions(+), 961 deletions(-) create mode 100644 publication/Newsroom/Arts/arts.yaml create mode 100644 publication/Newsroom/Digital/digital.yaml create mode 100644 publication/Newsroom/Insight/insight.yaml create mode 100644 publication/Newsroom/Lifestyle/lifestyle.yaml create mode 100644 publication/Newsroom/Reflections/reflections.yaml create mode 100644 publication/Newsroom/newsroom.yaml delete mode 100644 src/Command/QualityCheckArticlesCommand.php delete mode 100644 src/Controller/NzineController.php delete mode 100644 src/Entity/Nzine.php delete mode 100644 src/Entity/NzineBot.php delete mode 100644 src/Enum/IndexStatusEnum.php delete mode 100644 src/Form/NzineBotType.php delete mode 100644 src/Form/NzineType.php delete mode 100644 src/Repository/NzineRepository.php delete mode 100644 src/Service/NzineWorkflowService.php delete mode 100644 src/Twig/Components/Organisms/ZineList.php delete mode 100644 templates/components/Organisms/ZineList.html.twig delete mode 100644 templates/pages/nzine-editor.html.twig delete mode 100644 templates/pages/nzine.html.twig diff --git a/config/packages/security.yaml b/config/packages/security.yaml index b32a818..8245f93 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -28,5 +28,4 @@ security: access_control: - { path: ^/admin, roles: ROLE_USER } - { path: ^/search, roles: ROLE_USER } - # - { path: ^/nzine, roles: ROLE_USER } # - { path: ^/profile, roles: ROLE_USER } diff --git a/config/packages/workflow.yaml b/config/packages/workflow.yaml index aad92b3..077dc55 100644 --- a/config/packages/workflow.yaml +++ b/config/packages/workflow.yaml @@ -35,30 +35,3 @@ framework: edit: from: published to: edited - nzine_workflow: - type: state_machine - marking_store: - type: method - property: state - supports: - - App\Entity\Nzine - initial_marking: draft - places: - - draft - - profile_created - - main_index_created - - nested_indices_created - - published - transitions: - create_profile: - from: draft - to: profile_created - create_main_index: - from: profile_created - to: main_index_created - create_nested_indices: - from: main_index_created - to: nested_indices_created - publish: - from: nested_indices_created - to: published diff --git a/publication/Newsroom/Arts/arts.yaml b/publication/Newsroom/Arts/arts.yaml new file mode 100644 index 0000000..3b58a68 --- /dev/null +++ b/publication/Newsroom/Arts/arts.yaml @@ -0,0 +1,16 @@ +tags: + - ['d', 'newsroom-magazine-by-newsroom-cat-arts'] + - ['type', 'magazine'] + - ['l', 'en, ISO-639-1'] + - ['reading-direction', 'left-to-right, top-to-bottom'] + - ['t', 'art'] + - ['title', 'Arts'] + - ['summary', 'Arts and artistic pursuits'] + - ['published_by', 'Newsroom magazine'] + - [ 'p', '7c3bd3d882304e1fb21bbe1d3eb914a6152c747f315fbed6893e99f7119048ef' ] + - ['a', '30023:e844b39d850acbb13bba1a20057250fe6b3deff5f1ecc95b6a99dc35adafb6a2:awfl8cYr_4oS1-EiY0uP2'] + - ['a', '30023:5188521b32d40b740a1388d244e22642da3515c0fb39f07057129370008eb518:Legacy-z62rgd'] + - ['a', '30023:63d59db8d29abe29db7380beb912b8f600237332b6c9978b208694e4be170f6f:Oana-Bakovi-tf09mu'] + - ['a', '30023:5708b1f601ca8c453ebf622426acc9138cf5b714e9a6ff83c4758c4f208df3b8:Music-neuroplasticity-and-mental-health-f6oavz'] + - ['a', '30023:63d59db8d29abe29db7380beb912b8f600237332b6c9978b208694e4be170f6f:feature:-katerina-kouzmitcheva'] + - ['a', '30023:1b30d27ae3a493ad07fe2507700d7b412a7d551e13099774c71347473cf04146:AI-and-the-Future-of-Sound-Transforming-Music-Creation-and-Experience-gi8u8w'] diff --git a/publication/Newsroom/Digital/digital.yaml b/publication/Newsroom/Digital/digital.yaml new file mode 100644 index 0000000..fe66bc6 --- /dev/null +++ b/publication/Newsroom/Digital/digital.yaml @@ -0,0 +1,23 @@ +tags: + - ['d', 'newsroom-magazine-by-newsroom-cat-digital'] + - ['type', 'magazine'] + - ['l', 'en, ISO-639-1'] + - ['reading-direction', 'left-to-right, top-to-bottom'] + - ['t', 'technology'] + - ['title', 'Digital'] + - ['summary', 'Current digital technologies, trends and opportunities'] + - ['published_by', 'Newsroom magazine'] + - [ 'p', '7c3bd3d882304e1fb21bbe1d3eb914a6152c747f315fbed6893e99f7119048ef' ] + - ['a', '30023:dd664d5e4016433a8cd69f005ae1480804351789b59de5af06276de65633d319:1749882441713'] + - ['a', '30023:624d01ef570a3730afa1ebedc3ed95d57259ac5f37a9f0eac9c2a0d2f122bf4a:1750083282192'] + - ['a', '30023:3b7fc823611f1aeaea63ee3bf69b25b8aa16ec6e81d1afc39026808fe194354f:8_keUAm8-jlZIDUhjzJ4L'] + - ['a', '30023:97c70a44366a6535c145b333f973ea86dfdc2d7a99da618c40c64705ad98e322:1749232910842'] + - ['a', '30023:7bc05901cbcbbbbb87b76aa42ade4b5873d3d009311975e7fdb7766e8c26d22b:Extra-Extra-Read-all-about-it-4w9ksd'] + - ['a', '30023:3c389c8f4d46ca81316743a3e33cedb1d0619f8778ee74d47265775e7a2eff7f:1742920054921'] + - ['a', '30023:97c70a44366a6535c145b333f973ea86dfdc2d7a99da618c40c64705ad98e322:1741197956785'] + - ['a', '30023:378562cd20849dce3b74d85bc3e72c84f8ab59e94aa29650e1ad1b47a6fc6773:8IphCBoygPWv90xkEHlk0'] + - ['a', '30023:a012dc823bcf80d5eadf4b6683035634bc40f1b0a52b958278b6bbc96458a70d:2-wTPCMqGqU7H2ptDSelh'] + - ['a', '30023:97c70a44366a6535c145b333f973ea86dfdc2d7a99da618c40c64705ad98e322:1738257057128'] + - ['a', '30023:65038d696843e53ff11c3316a5b1c1c71b2fdc31bffe0bfcb93b1e4c1fff8852:2025-01-06-technology-never-changes'] + - ['a', '30023:4234223996ce6549720e66dd6bc4bb7efb9f25c60c4816d7bc47a65e1d80db24:1724998869566' ] + - ['a', '30023:65038d696843e53ff11c3316a5b1c1c71b2fdc31bffe0bfcb93b1e4c1fff8852:2024-09-23-delete-the-technology'] diff --git a/publication/Newsroom/Insight/insight.yaml b/publication/Newsroom/Insight/insight.yaml new file mode 100644 index 0000000..21f9105 --- /dev/null +++ b/publication/Newsroom/Insight/insight.yaml @@ -0,0 +1,23 @@ +tags: + - ['d', 'newsroom-magazine-by-newsroom-cat-insight'] + - ['type', 'magazine'] + - ['l', 'en, ISO-639-1'] + - ['reading-direction', 'left-to-right, top-to-bottom'] + - ['t', 'technology'] + - ['t', 'business'] + - ['t', 'politics'] + - ['t', 'economics'] + - ['title', 'Insight'] + - ['summary', 'Technology, politics, economics and more'] + - ['published_by', 'Newsroom magazine'] + - ['p', '7c3bd3d882304e1fb21bbe1d3eb914a6152c747f315fbed6893e99f7119048ef' ] + - ['a', '30023:6ad3e2a34818b153c81f48c58f44e5199e7b4fc8dbe37810a000dce3c90b7740:Protocol-ibo4to'] + - ['a', '30023:4d41a7cbc9b7f7e8484d15499aa9141c73f9a39c3765cc5d5631fa1e7d3633cc:The-dollar-a-broken-contract-7loce5'] + - ['a', '30023:4234223996ce6549720e66dd6bc4bb7efb9f25c60c4816d7bc47a65e1d80db24:1736500765505' ] + - ['a', "30023:bc6ccd13a32f94d36564dac8f5963a0d69c583c9968341bbdf278b21f53098e4:money-flows-aren't-important"] + - ['a', '30023:472f440f29ef996e92a186b8d320ff180c855903882e59d50de1b8bd5669301e:japan-admits-it-has-a-problem-and-consumer-debt-hits-a-wall-in-the-us'] + - ['a', '30023:bc52210b20d3fb89326463a3518674c7edde65794a7765c7f3a9119b20bfc6de:compact-nuclear-power-revolutionizing-energy-with-modular-thorium-reactors'] + - ['a', '30023:c066aac504e1228a5853117624f2f9156b1f5b332be74bb08f281c136a41a034:purchase-vs-investment'] + - ['a', '30023:04c915daefee38317fa734444acee390a8269fe5810b2241e5e6dd343dfbecc9:Capitalism-Scales-Best-Be-Profitable-1rpxxj'] + - ['a', '30023:ed5774ac84f70a9e1ca14027e07de8e643cef5dcf3e3593266886bb745611c5c:v9WY4L0gdPul3slaO5bt2' ] + - ['a', '30023:a396e36e962a991dac21731dd45da2ee3fd9265d65f9839c15847294ec991f1c:Bitcoin-as-Escape-from-Clown-Insight'] diff --git a/publication/Newsroom/Lifestyle/lifestyle.yaml b/publication/Newsroom/Lifestyle/lifestyle.yaml new file mode 100644 index 0000000..fb2dc4f --- /dev/null +++ b/publication/Newsroom/Lifestyle/lifestyle.yaml @@ -0,0 +1,24 @@ +tags: + - ['d', 'newsroom-magazine-by-newsroom-cat-lifestyle'] + - ['type', 'magazine'] + - ['l', 'en, ISO-639-1'] + - ['reading-direction', 'left-to-right, top-to-bottom'] + - ['t', 'lifestyle'] + - ['title', 'Lifestyle'] + - ['summary', 'Lifestyle, health and wellness, travel and home'] + - ['published_by', 'Newsroom magazine'] + - [ 'p', '7c3bd3d882304e1fb21bbe1d3eb914a6152c747f315fbed6893e99f7119048ef' ] + - ['a', '30023:a3c6f928a920617444d8fd10ba65c7a21c75a280cac58ebadd0bb1ded45494fb:24127d1869d6fb0e'] + - ['a', '30023:04ed2b8f0bbe0a1330f27831108fc75379267826d544f6abb7aac50275be6756:47b47035a8b7bef0'] + - ['a', '30023:c69b71dc564fdc350acddff929f25d7202ac1470c87488608bd6d98e426ba763:wj6WLkUfYkGRaDK48ZfK8'] + - ['a', '30023:554ab6fed675985d6b99b79ad7b784ff8ca4a5b02778812e1968eee0c6cbc27e:XTbk9KAgURJbCPniEu_9g'] + - ['a', '30023:c69b71dc564fdc350acddff929f25d7202ac1470c87488608bd6d98e426ba763:QxHZzjc6kVnE1KBrKhvhc'] + - ['a', '30023:b8ca3d82ac72d2bdf0d94541898397467d59c9614fa4ce88066cbf8fe28bd6b5:Why-your-body-is-your-way-in-pe04jk'] + - ['a', '30023:6830c4094f42a138b333157c130a5353b4149cc683e2c18c6e004e22ff17c655:uvU5PQxjIOE4v5dNU3z2b'] + - ['a', '30023:554ab6fed675985d6b99b79ad7b784ff8ca4a5b02778812e1968eee0c6cbc27e:Health-Benefits-in-Nature-5eptsc'] + - ['a', '30023:db01672ec0b5219ca521f5954f99ea3560e34fc427f47b9416486c3d9f775028:1743584409108'] + - ['a', '30023:7d33ba57d8a6e8869a1f1d5215254597594ac0dbfeb01b690def8c461b82db35:DGK40bomu58dGKNVzFioK'] + - ['a', '30023:6ad3e2a34818b153c81f48c58f44e5199e7b4fc8dbe37810a000dce3c90b7740:igQitdH5ol42zbap8pGSd'] + - ['a', '30023:378562cd20849dce3b74d85bc3e72c84f8ab59e94aa29650e1ad1b47a6fc6773:Life-Beyond-Bitcoin-2hm81r'] + - ['a', '30023:378562cd20849dce3b74d85bc3e72c84f8ab59e94aa29650e1ad1b47a6fc6773:The-Benefits-of-Hiking-in-Nature-pcvs1q'] + - ['a', '30023:0b118e40d6f3dfabb17f21a94a647701f140d8b063a9e84fe6e483644edc09cb:1742976772735'] diff --git a/publication/Newsroom/Reflections/reflections.yaml b/publication/Newsroom/Reflections/reflections.yaml new file mode 100644 index 0000000..d7e2507 --- /dev/null +++ b/publication/Newsroom/Reflections/reflections.yaml @@ -0,0 +1,26 @@ +tags: + - ['d', 'newsroom-magazine-by-newsroom-cat-reflections'] + - ['type', 'magazine'] + - ['l', 'en, ISO-639-1'] + - ['reading-direction', 'left-to-right, top-to-bottom'] + - ['t', 'philosophy'] + - ['t', 'religion'] + - ['t', 'spirituality'] + - ['title', 'Reflections'] + - ['summary', 'Religion, philosophy and spirituality'] + - ['published_by', 'Newsroom magazine'] + - [ 'p', '7c3bd3d882304e1fb21bbe1d3eb914a6152c747f315fbed6893e99f7119048ef' ] + - ['a', '30023:36f96bcb0bb24a522ce2c2e867cc3548ea4c48f951ae49d24fa30f742ff3888b:sovereign-stoic-why-mastering-yourself-and-your-money-is-the-only-way-forward'] + - ['a' , '30023:96859d1496ab212d80629b3929fdb8fda7850f7fdd0b31fb265e6844b06bf54d:the-fire-in-the-freezing-forest'] + - ['a', '30023:16d114303d8203115918ca34a220e925c022c09168175a5ace5e9f3b61640947:8c5cf16c40358825'] + - ['a', '30023:d57360cb86796680f1af1830d7c33834fe7b57c580e1c598eab89e794fe7d935:Dreams-vs-Reality-806ivo'] + - ['a', '30023:8d34bd2432240c5637174a3db191878baa1c133aec739b64a264259f414be32b:Miserable-Comforters-Are-You-6kanl1'] + - ['a', '30023:6ad3e2a34818b153c81f48c58f44e5199e7b4fc8dbe37810a000dce3c90b7740:Science-0iucu9'] + - ['a', '30023:0c65eba8a81341439ac132a0fec38121ce7d68d89e56a5c2b6e88d784a08ef9a:the-real-goal-of-parenting:-raising-the-parents-of-your-grandchildren-'] + - ['a', '30023:6e0ea5d6ad5334b4e83354f06bbc1bcd90c09a8576e52bb58b7bfa9b0327f353:1746369859906'] + - ['a', '30023:8d34bd2432240c5637174a3db191878baa1c133aec739b64a264259f414be32b:Getting-to-Know-God-Through-the-Bible-hxj284'] + - ['a', '30023:f1f5954911a1c286c04be6409b773703a7c5c246607b51527517c58af4121cfe:Spiritual-Arrogance-co4zoh'] + - ['a', '30023:554ab6fed675985d6b99b79ad7b784ff8ca4a5b02778812e1968eee0c6cbc27e:0MD-jaH3Nk_VeouWXNWVB'] + - ['a', '30023:e111a40578d91eff049a350070c17536cc447cff9ec8c4abfe45d810fa441558:1743962847753'] + - ['a', '30023:378562cd20849dce3b74d85bc3e72c84f8ab59e94aa29650e1ad1b47a6fc6773:Living-a-Godly-Life-in-an-Ungodly-World-pv4d5u'] + - ['a', '30023:c1e9ab3a56a2ab6ca4bebf44ea64b2fda40ac6311e886ba86b4652169cb56b43:c0d4f9fc46fe7b39'] diff --git a/publication/Newsroom/newsroom.yaml b/publication/Newsroom/newsroom.yaml new file mode 100644 index 0000000..61db53e --- /dev/null +++ b/publication/Newsroom/newsroom.yaml @@ -0,0 +1,14 @@ +tags: + - ['d', 'newsroom-magazine-by-newsroom'] + - ['type', 'magazine'] + - ['l', 'en, ISO-639-1'] + - ['reading-direction', 'left-to-right, top-to-bottom'] + - ['title', 'Newsroom magazine'] + - ['summary', 'The first curated magazine of open content'] + - ['published_by', 'Newsroom magazine'] + - ['p', '7c3bd3d882304e1fb21bbe1d3eb914a6152c747f315fbed6893e99f7119048ef'] + - ['a', '30040:7c3bd3d882304e1fb21bbe1d3eb914a6152c747f315fbed6893e99f7119048ef:newsroom-magazine-by-newsroom-cat-insight'] + - ['a', '30040:7c3bd3d882304e1fb21bbe1d3eb914a6152c747f315fbed6893e99f7119048ef:newsroom-magazine-by-newsroom-cat-digital'] + - ['a', '30040:7c3bd3d882304e1fb21bbe1d3eb914a6152c747f315fbed6893e99f7119048ef:newsroom-magazine-by-newsroom-cat-lifestyle'] + - ['a', '30040:7c3bd3d882304e1fb21bbe1d3eb914a6152c747f315fbed6893e99f7119048ef:newsroom-magazine-by-newsroom-cat-reflections'] + - ['a', '30040:7c3bd3d882304e1fb21bbe1d3eb914a6152c747f315fbed6893e99f7119048ef:newsroom-magazine-by-newsroom-cat-arts'] diff --git a/src/Command/QualityCheckArticlesCommand.php b/src/Command/QualityCheckArticlesCommand.php deleted file mode 100644 index dfdc123..0000000 --- a/src/Command/QualityCheckArticlesCommand.php +++ /dev/null @@ -1,69 +0,0 @@ -entityManager->getRepository(Article::class)->findBy(['indexStatus' => IndexStatusEnum::NOT_INDEXED]); - $count = 0; - foreach ($articles as $article) { - if ($this->meetsCriteria($article)) { - $count += 1; - $article->setIndexStatus(IndexStatusEnum::TO_BE_INDEXED); - } else { - $article->setIndexStatus(IndexStatusEnum::DO_NOT_INDEX); - } - $this->entityManager->persist($article); - } - - $this->entityManager->flush(); - - $output->writeln($count . ' articles marked for indexing successfully.'); - - return Command::SUCCESS; - } - - private function meetsCriteria(Article $article): bool - { - $content = $article->getContent(); - - // No empty title - if (empty($article->getTitle()) || strtolower($article->getTitle()) === 'test') { - return false; - } - - // Do not index stacker news reposts - if (str_contains($content, 'originally posted at https://stacker.news')) { - return false; - } - - // Slug must not contain '/' and should not be empty - if (empty($article->getSlug()) || str_contains($article->getSlug(), '/')) { - return false; - } - - // Only index articles with more than 12 words - return str_word_count($article->getContent()) > 12; - } -} diff --git a/src/Controller/NzineController.php b/src/Controller/NzineController.php deleted file mode 100644 index 370b5dc..0000000 --- a/src/Controller/NzineController.php +++ /dev/null @@ -1,259 +0,0 @@ -createForm(NzineBotType::class); - $form->handleRequest($request); - $user = $this->getUser(); - - $nzine = $entityManager->getRepository(Nzine::class)->findAll(); - - - if ($form->isSubmitted() && $form->isValid()) { - $data = $form->getData(); - // init object - $nzine = $nzineWorkflowService->init(); - // create bot and nzine, save to persistence - $nzine = $nzineWorkflowService->createProfile($nzine, $data['name'], $data['about'], $user); - // create main index - $nzineWorkflowService->createMainIndex($nzine, $data['name'], $data['about']); - - return $this->redirectToRoute('nzine_edit', ['npub' => $nzine->getNpub() ]); - } - - return $this->render('pages/nzine-editor.html.twig', [ - 'form' => $form - ]); - } - - #[Route('/nzine/{npub}', name: 'nzine_edit')] - public function edit(Request $request, $npub, EntityManagerInterface $entityManager, - EncryptionService $encryptionService, - ManagerRegistry $managerRegistry, NostrClient $nostrClient): Response - { - $nzine = $entityManager->getRepository(Nzine::class)->findOneBy(['npub' => $npub]); - if (!$nzine) { - throw $this->createNotFoundException('N-Zine not found'); - } - try { - $bot = $entityManager->getRepository(User::class)->findOneBy(['npub' => $npub]); - } catch (Exception $e) { - // sth went wrong, but whatever - $managerRegistry->resetManager(); - } - - // existing index - $indices = $entityManager->getRepository(EventEntity::class)->findBy(['pubkey' => $npub, 'kind' => KindsEnum::PUBLICATION_INDEX]); - - $mainIndexCandidates = array_filter($indices, function ($index) use ($nzine) { - return $index->getSlug() == $nzine->getSlug(); - }); - - $mainIndex = array_pop($mainIndexCandidates); - if (empty($mainIndex)) { - throw $this->createNotFoundException('Main index not found'); - } - - $catForm = $this->createForm(NzineType::class, ['categories' => $nzine->getMainCategories()]); - $catForm->handleRequest($request); - - if ($catForm->isSubmitted() && $catForm->isValid()) { - // Process and normalize the 'tags' field - $data = $catForm->get('categories')->getData(); - - $nzine->setMainCategories($data); - - try { - $entityManager->beginTransaction(); - $entityManager->persist($nzine); - $entityManager->flush(); - $entityManager->commit(); - } catch (Exception $e) { - $entityManager->rollback(); - $managerRegistry->resetManager(); - } - - $catIndices = []; - - $bot = $nzine->getNzineBot(); - $bot->setEncryptionService($encryptionService); - $private_key = $bot->getNsec(); // decrypted en route - - foreach ($data as $cat) { - // check if such an index exists, only create new cats - $id = array_filter($indices, function ($k) use ($cat) { - return $cat['title'] === $k->getTitle(); - }); - if (!empty($id)) { continue; } - - // create new index - // currently not possible to edit existing, because there is no way to tell what has changed - // and which is the corresponding event - $slugger = new AsciiSlugger(); - $title = $cat['title']; - $slug = $mainIndex->getSlug().'-'.$slugger->slug($title)->lower(); - // create category index - $index = new Event(); - $index->setKind(KindsEnum::PUBLICATION_INDEX->value); - - $index->addTag(['d' => $slug]); - $index->addTag(['title' => $title]); - $index->addTag(['auto-update' => 'yes']); - $index->addTag(['type' => 'magazine']); - foreach ($cat['tags'] as $tag) { - $index->addTag(['t' => $tag]); - } - $index->setPublicKey($nzine->getNpub()); - - $signer = new Sign(); - $signer->signEvent($index, $private_key); - // save to persistence, first map to EventEntity - $serializer = new Serializer([new ObjectNormalizer()],[new JsonEncoder()]); - $i = $serializer->deserialize($index->toJson(), EventEntity::class, 'json'); - // don't save any more for now - $entityManager->persist($i); - $entityManager->flush(); - // TODO publish index to relays - - $catIndices[] = $index; - } - - // add the new and updated indices to the main index - foreach ($catIndices as $idx) { - //remove e tags and add new - // $tags = array_splice($mainIndex->getTags(), -3); - // $mainIndex->setTags($tags); - // TODO add relay hints - $mainIndex->addTag(['a' => KindsEnum::PUBLICATION_INDEX->value .':'. $idx->getPublicKey() .':'. $idx->getSlug()]); - // $mainIndex->addTag(['e' => $idx->getId() ]); - } - - // re-sign main index and save to relays - // $signer = new Sign(); - // $signer->signEvent($mainIndex, $private_key); - // for now, just save new index - $entityManager->flush(); - - // redirect to route nzine_view - return $this->redirectToRoute('nzine_view', [ - 'npub' => $nzine->getNpub(), - ]); - } - - return $this->render('pages/nzine-editor.html.twig', [ - 'nzine' => $nzine, - 'indices' => $indices, - 'bot' => $bot ?? null, // if null, the profile for the bot doesn't exist yet - 'catForm' => $catForm - ]); - } - - /** - * Update and (re)publish indices, - * when you want to look for new articles or - * when categories have changed - * @return void - */ - #[Route('/nzine/{npub}', name: 'nzine_update')] - public function nzineUpdate() - { - // TODO make this a separate step and publish all the indices and populate with articles all at once - - } - - - #[Route('/nzine/v/{npub}', name: 'nzine_view')] - public function nzineView($npub, EntityManagerInterface $entityManager): Response - { - $nzine = $entityManager->getRepository(Nzine::class)->findOneBy(['npub' => $npub]); - if (!$nzine) { - throw $this->createNotFoundException('N-Zine not found'); - } - // Find all index events for this nzine - $indices = $entityManager->getRepository(EventEntity::class)->findBy(['pubkey' => $npub, 'kind' => KindsEnum::PUBLICATION_INDEX]); - $mainIndexCandidates = array_filter($indices, function ($index) use ($nzine) { - return $index->getSlug() == $nzine->getSlug(); - }); - - dump($indices);die(); - - $mainIndex = array_pop($mainIndexCandidates); - - return $this->render('pages/nzine.html.twig', [ - 'nzine' => $nzine, - 'index' => $mainIndex, - 'events' => $indices, // TODO traverse all and collect all leaves - ]); - } - - #[Route('/nzine/v/{npub}/{cat}', name: 'nzine_category')] - public function nzineCategory($npub, $cat, EntityManagerInterface $entityManager): Response - { - $nzine = $entityManager->getRepository(Nzine::class)->findOneBy(['npub' => $npub]); - if (!$nzine) { - throw $this->createNotFoundException('N-Zine not found'); - } - $bot = $entityManager->getRepository(User::class)->findOneBy(['npub' => $npub]); - - $tags = []; - foreach ($nzine->getMainCategories() as $category) { - if (isset($category['title']) && $category['title'] === $cat) { - $tags = $category['tags'] ?? []; - } - } - - $all = $entityManager->getRepository(Article::class)->findAll(); - $list = array_slice($all, 0, 100); - - $filtered = []; - foreach ($tags as $tag) { - $partial = array_filter($list, function($v) use ($tag) { - /* @var Article $v */ - return in_array($tag, $v->getTopics() ?? []); - }); - $filtered = array_merge($filtered, $partial); - } - - - return $this->render('pages/nzine.html.twig', [ - 'nzine' => $nzine, - 'bot' => $bot, - 'list' => $filtered - ]); - } - -} diff --git a/src/Entity/Nzine.php b/src/Entity/Nzine.php deleted file mode 100644 index 690dec8..0000000 --- a/src/Entity/Nzine.php +++ /dev/null @@ -1,141 +0,0 @@ -mainCategories = new ArrayCollection(); - } - - public function getId(): ?int - { - return $this->id; - } - - public function getNpub(): ?string - { - return $this->npub; - } - - public function setNpub(string $npub): static - { - $this->npub = $npub; - - return $this; - } - - public function getNsec(): ?string - { - return $this->nsec; - } - - public function setNsec(?string $nsec): void - { - $this->nsec = $nsec; - } - - public function getMainCategories(): array - { - return $this->mainCategories; - } - - public function setMainCategories(array $mainCategories): static - { - $this->mainCategories = $mainCategories; - - return $this; - } - - public function getLists(): ?array - { - return $this->lists; - } - - public function setLists(?array $lists): static - { - $this->lists = $lists; - - return $this; - } - - public function getEditor(): ?string - { - return $this->editor; - } - - public function setEditor(?string $editor): static - { - $this->editor = $editor; - - return $this; - } - - public function getNzineBot(): ?NzineBot - { - return $this->nzineBot; - } - - public function setNzineBot(?NzineBot $nzineBot): void - { - $this->nzineBot = $nzineBot; - } - - public function getSlug(): ?string - { - return $this->slug; - } - - public function setSlug(?string $slug): void - { - $this->slug = $slug; - } - - public function getState(): string - { - return $this->state; - } - - public function setState(string $state): void - { - $this->state = $state; - } -} diff --git a/src/Entity/NzineBot.php b/src/Entity/NzineBot.php deleted file mode 100644 index c749902..0000000 --- a/src/Entity/NzineBot.php +++ /dev/null @@ -1,51 +0,0 @@ -encryptionService = $encryptionService; - } - - public function getId(): ?int - { - return $this->id; - } - - public function getNsec(): ?string - { - if (null === $this->nsec && null !== $this->encryptedNsec) { - $this->nsec = $this->encryptionService->decrypt($this->encryptedNsec); - } - return $this->nsec; - } - - public function setNsec(?string $nsec): self - { - $this->nsec = $nsec; - $this->encryptedNsec = $this->encryptionService->encrypt($nsec); - return $this; - } -} diff --git a/src/Enum/IndexStatusEnum.php b/src/Enum/IndexStatusEnum.php deleted file mode 100644 index 3dd0612..0000000 --- a/src/Enum/IndexStatusEnum.php +++ /dev/null @@ -1,11 +0,0 @@ -add('name', TextType::class, [ - 'required' => true - ]) - ->add('about', TextareaType::class, [ - 'required' => false - ]) - ->add('submit', SubmitType::class) - ; - } - - public function configureOptions(OptionsResolver $resolver) - { - } -} diff --git a/src/Form/NzineType.php b/src/Form/NzineType.php deleted file mode 100644 index 86d707e..0000000 --- a/src/Form/NzineType.php +++ /dev/null @@ -1,30 +0,0 @@ -add('categories', CollectionType::class, [ - 'entry_type' => MainCategoryType::class, - 'allow_add' => true, - 'allow_delete' => true, - 'by_reference' => false, - 'prototype' => true, // Enables the JavaScript prototype feature - 'label' => false, - ]); - } - - public function configureOptions(OptionsResolver $resolver): void - { - } -} diff --git a/src/Repository/NzineRepository.php b/src/Repository/NzineRepository.php deleted file mode 100644 index 30c6988..0000000 --- a/src/Repository/NzineRepository.php +++ /dev/null @@ -1,43 +0,0 @@ - - */ -class NzineRepository extends ServiceEntityRepository -{ - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, Nzine::class); - } - - // /** - // * @return Nzine[] Returns an array of Nzine objects - // */ - // public function findByExampleField($value): array - // { - // return $this->createQueryBuilder('j') - // ->andWhere('j.exampleField = :val') - // ->setParameter('val', $value) - // ->orderBy('j.id', 'ASC') - // ->setMaxResults(10) - // ->getQuery() - // ->getResult() - // ; - // } - - // public function findOneBySomeField($value): ?Nzine - // { - // return $this->createQueryBuilder('j') - // ->andWhere('j.exampleField = :val') - // ->setParameter('val', $value) - // ->getQuery() - // ->getOneOrNullResult() - // ; - // } -} diff --git a/src/Service/NzineWorkflowService.php b/src/Service/NzineWorkflowService.php deleted file mode 100644 index 84b6bb4..0000000 --- a/src/Service/NzineWorkflowService.php +++ /dev/null @@ -1,147 +0,0 @@ -nzine = $nzine; - } else { - $this->nzine = new Nzine(); - } - - return $this->nzine; - } - - public function createProfile($nzine, $name, $about, $user): Nzine - { - if (!$this->nzineWorkflow->can($nzine, 'create_profile')) { - throw new \LogicException('Cannot create profile in the current state.'); - } - - $this->nzine = $nzine; - - // create NZine bot - $key = new Key(); - $private_key = $key->generatePrivateKey(); - $bot = new NzineBot(); - $bot->setEncryptionService($this->encryptionService); - $bot->setNsec($private_key); - $this->entityManager->persist($bot); - $this->entityManager->flush(); - - // publish bot profile - $profileContent = [ - 'name' => $name, - 'about' => $about, - 'bot' => true - ]; - $profileEvent = new Event(); - $profileEvent->setKind(KindsEnum::METADATA->value); - $profileEvent->setContent(json_encode($profileContent)); - $signer = new Sign(); - $signer->signEvent($profileEvent, $private_key); - // $this->nostrClient->publishEvent($profileEvent, ['wss://purplepag.es']); - - // add EDITOR role to the user - $role = RolesEnum::EDITOR->value; - $user = $this->entityManager->getRepository(User::class)->findOneBy(['npub' => $user->getUserIdentifier()]); - $user->addRole($role); - $this->entityManager->persist($user); - - // create NZine entity - $public_key = $key->getPublicKey($private_key); - $this->nzine->setNpub($public_key); - $this->nzine->setNzineBot($bot); - $this->nzine->setEditor($user->getUserIdentifier()); - $this->nzineWorkflow->apply($this->nzine, 'create_profile'); - $this->entityManager->persist($this->nzine); - $this->entityManager->flush(); - - return $this->nzine; - } - - /** - * @throws \JsonException - */ - public function createMainIndex(Nzine $nzine, string $title, string $summary): void - { - if (!$this->nzineWorkflow->can($nzine, 'create_main_index')) { - // throw new \LogicException('Cannot create main index in the current state.'); - } - - $bot = $nzine->getNzineBot(); - $private_key = $bot->getNsec(); - - $slugger = new AsciiSlugger(); - $slug = 'nzine-'.$slugger->slug($title)->lower().'-'.rand(10000,99999); - // save slug to nzine - $nzine->setSlug($slug); - - // create NZine main index - $index = new Event(); - $index->setKind(KindsEnum::PUBLICATION_INDEX->value); - - $index->addTag(['d' => $slug]); - $index->addTag(['title' => $title]); - $index->addTag(['summary' => $summary]); - $index->addTag(['auto-update' => 'yes']); - $index->addTag(['type' => 'magazine']); - $signer = new Sign(); - $signer->signEvent($index, $private_key); - // save to persistence, first map to EventEntity - $serializer = new Serializer([new ObjectNormalizer()],[new JsonEncoder()]); - $i = $serializer->deserialize($index->toJson(), EventEntity::class, 'json'); - $this->entityManager->persist($i); - - $this->nzineWorkflow->apply($nzine, 'create_main_index'); - $this->entityManager->flush(); - } - - public function createNestedIndex(Nzine $nzine, string $categoryTitle, array $tags): void - { - if (!$this->nzineWorkflow->can($nzine, 'create_nested_indices')) { - throw new \LogicException('Cannot create nested indices in the current state.'); - } - - // Example logic: Create a nested index for the category - $nestedIndex = new EventEntity(); - // $nestedIndex->setTitle($categoryTitle); - $nestedIndex->setTags($tags); - $nestedIndex->setKind('30040'); // Assuming 30040 is the kind for publication indices - - $this->entityManager->persist($nestedIndex); - - $this->nzineWorkflow->apply($nzine, 'create_nested_indices'); - $this->entityManager->persist($nzine); - $this->entityManager->flush(); - } -} - diff --git a/src/Twig/Components/Organisms/ZineList.php b/src/Twig/Components/Organisms/ZineList.php deleted file mode 100644 index a7104fa..0000000 --- a/src/Twig/Components/Organisms/ZineList.php +++ /dev/null @@ -1,37 +0,0 @@ -nzines = $nzines ?? $this->entityManager->getRepository(Nzine::class)->findAll(); - if (count($this->nzines) > 0) { - // find indices for each nzine - foreach ($this->nzines as $zine) { - $ids = $this->entityManager->getRepository(Event::class)->findBy(['pubkey' => $zine->getNpub(), 'kind' => KindsEnum::PUBLICATION_INDEX]); - $id = array_filter($ids, function($k) use ($zine) { - return $k->getSlug() == $zine->getSlug(); - }); - if ($id) { - $this->indices[$zine->getNpub()] = array_pop($id); - } - } - } - } -} diff --git a/templates/components/Organisms/ZineList.html.twig b/templates/components/Organisms/ZineList.html.twig deleted file mode 100644 index 8c867cd..0000000 --- a/templates/components/Organisms/ZineList.html.twig +++ /dev/null @@ -1,16 +0,0 @@ -
- {% for item in nzines %} - {% if item.npub in indices|keys %} - {% set idx = indices[item.npub] %} - {% if idx|length > 0 %} - -
-

{{ idx.title }}

- -
-
-
- {% endif %} - {% endif %} - {% endfor %} -
diff --git a/templates/components/UserMenu.html.twig b/templates/components/UserMenu.html.twig index 9b9e0de..11d151f 100644 --- a/templates/components/UserMenu.html.twig +++ b/templates/components/UserMenu.html.twig @@ -14,9 +14,6 @@