Issues (281)

Branch: master

Modules/Blog/Actions/ArticleCommentsRss.php (1 issue)

1
<?php
2
3
namespace Frontend\Modules\Blog\Actions;
4
5
use Frontend\Core\Engine\Base\Block as FrontendBaseBlock;
6
use Frontend\Core\Engine\Navigation as FrontendNavigation;
7
use Frontend\Core\Language\Language as FL;
8
use Frontend\Core\Engine\Rss as FrontendRSS;
9
use Frontend\Core\Engine\RssItem as FrontendRSSItem;
10
use Frontend\Modules\Blog\Engine\Model as FrontendBlogModel;
0 ignored issues
show
The type Frontend\Modules\Blog\Engine\Model was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
12
13
/**
14
 * This is the RSS-feed for comments on a certain article.
15
 */
16
class ArticleCommentsRss extends FrontendBaseBlock
17
{
18
    public function execute(): void
19
    {
20
        parent::execute();
21
22
        $this->generateRss();
23
    }
24
25
    private function generateRss()
26
    {
27
        $blogPost = $this->getBlogPost();
28
        $blogPostComments = FrontendBlogModel::getComments($blogPost['id']);
29
        $rss = new FrontendRSS(
30
            vsprintf(FL::msg('CommentsOn'), [$blogPost['title']]),
31
            $this->getRssFeedLink($blogPost),
32
            ''
33
        );
34
        $blogPostUrl = $this->getBlogPostLink($blogPost);
35
36
        foreach ($blogPostComments as $blogPostComment) {
37
            $rss->addItem($this->getRssFeedItemForBlogPostComment($blogPostComment, $blogPost['title'], $blogPostUrl));
38
        }
39
40
        $rss->parse();
41
    }
42
43
    private function getRssFeedLink(array $blogPost): string
44
    {
45
        return SITE_URL
46
               . FrontendNavigation::getUrlForBlock($this->getModule(), $this->getAction())
47
               . '/' . $blogPost['url'];
48
    }
49
50
    private function getBlogPostLink(array $blogPost): string
51
    {
52
        return SITE_URL
53
               . FrontendNavigation::getUrlForBlock($this->getModule(), 'Detail')
54
               . '/' . $blogPost['url'];
55
    }
56
57
    private function getRssFeedItemForBlogPostComment(
58
        array $blogPostComment,
59
        string $blogPostTitle,
60
        string $blogPostUrl
61
    ): FrontendRSSItem {
62
        $rssItem = new FrontendRSSItem(
63
            $blogPostComment['author'] . ' ' . FL::lbl('On') . ' ' . $blogPostTitle,
64
            $blogPostUrl . '/#comment-' . $blogPostComment['id'],
65
            $blogPostComment['text']
66
        );
67
68
        $rssItem->setPublicationDate($blogPostComment['created_on']);
69
        $rssItem->setAuthor(empty($blogPostComment['email']) ? $blogPostComment['author'] : $blogPostComment['email']);
70
71
        return $rssItem;
72
    }
73
74
    private function getBlogPost(): array
75
    {
76
        if ($this->url->getParameter(1) === null) {
77
            throw new NotFoundHttpException();
78
        }
79
80
        $blogPost = FrontendBlogModel::get($this->url->getParameter(1));
81
82
        if (empty($blogPost)) {
83
            throw new NotFoundHttpException();
84
        }
85
86
        return $blogPost;
87
    }
88
}
89