diff --git a/config/routes.php b/config/routes.php index 01c8332..99cb5f3 100644 --- a/config/routes.php +++ b/config/routes.php @@ -76,6 +76,8 @@ $builder->connect('/article/{slug}', ['controller' => 'Articles', 'action' => 'view'])->setPass(['slug']); $builder->connect('/page/{slug}', ['controller' => 'Articles', 'action' => 'view'])->setPass(['slug']); + $builder->connect('/now', ['controller' => 'Articles', 'action' => 'now']); + $builder->scope("/articles", function (RouteBuilder $builder) { $builder->connect('/tagged/*', ['controller' => 'Articles', 'action' => 'tags']); $builder->connect('/v/{slug}', ['controller' => 'Articles', 'action' => 'view'])->setPass(['slug']); diff --git a/src/Controller/ArticlesController.php b/src/Controller/ArticlesController.php index 66d10bb..05420e8 100644 --- a/src/Controller/ArticlesController.php +++ b/src/Controller/ArticlesController.php @@ -26,7 +26,7 @@ class ArticlesController extends AppController public function beforeFilter(EventInterface $event) { parent::beforeFilter($event); - $this->Authentication->allowUnauthenticated(['index', 'tags', 'view']); + $this->Authentication->allowUnauthenticated(['index', 'tags', 'view', 'now']); } /** @@ -173,4 +173,18 @@ public function tags(string ...$tags) //'_serialize' => ['articles', 'tags'] ]); } + + /** + * Returns latest article tagged with NOW + * + * @param ArticlesManagerServiceInterface $articlesManager + * @return void + */ + public function now(ArticlesManagerServiceInterface $articlesManager) + { + $content = $articlesManager->getLatestNowPageContent($this->request); + $this->Authorization->skipAuthorization(); + + $this->set(compact('content')); + } } diff --git a/src/Services/ArticlesManagerService.php b/src/Services/ArticlesManagerService.php index 5472e3c..011614d 100644 --- a/src/Services/ArticlesManagerService.php +++ b/src/Services/ArticlesManagerService.php @@ -126,4 +126,24 @@ public function getHomePageContent(ServerRequest $request): ?string return $article ? $article->body : null; } + + public function getLatestNowPageContent(ServerRequest $request): ?Article + { + /** @var \MeowBlog\Model\Table\ArticlesTable $articleTable */ + $articleTable = $this->articles; + + /** @var \Cake\ORM\Query $q */ + $q = $articleTable->find('tagged', [ + 'tags' => 'now', + ])->where([ + 'Blogs.Domain' => $request->getUri()->getHost(), + 'Articles.article_type' => ArticleType::Article->value, + 'Articles.published' => 1, + ])->order(['Articles.created' => 'DESC']); + + /** @var \MeowBlog\Model\Entity\Article $savedArticle */ + $article = $q->contain(['Blogs', 'Tags'])->first(); + + return $article ? $article : null; + } } diff --git a/src/Services/ArticlesManagerServiceInterface.php b/src/Services/ArticlesManagerServiceInterface.php index 96d4894..8391e11 100644 --- a/src/Services/ArticlesManagerServiceInterface.php +++ b/src/Services/ArticlesManagerServiceInterface.php @@ -43,10 +43,18 @@ public function saveToDatabase(Article $article, ServerRequest $request): Articl /** * Return content of the homepage articles - * Home-page articles are articles that have title matched with the blog domain + * Home-page articles are articles that have title matched with the blog domain type must be Page * * @param ServerRequest $request * @return string|null */ public function getHomePageContent(ServerRequest $request): ?string; + + /** + * Return content of latest article (type: Article) tagged with Now + * + * @param ServerRequest $request + * @return Article|null + */ + public function getLatestNowPageContent(ServerRequest $request): ?Article; } diff --git a/templates/Articles/now.php b/templates/Articles/now.php new file mode 100644 index 0000000..570ec2b --- /dev/null +++ b/templates/Articles/now.php @@ -0,0 +1,20 @@ + +
+

+

created ) : '' ?>

+
+
+

Html->link('/now', 'https://nownownow.com/about', ['target' => '_blank']))?>

+
+ +

+ + Markdown->parse($content->body); ?> + +
+