예제 #1
0
    protected function getSingleComment(Comment $comment)
    {
        $text = $this->text;
        $id = $comment->getId();
        $contextUrl = $text->e($text->getUrlPage("article", $comment->getArticleId())->withFragment('comment_' . $id));
        $returnValue = '<article class="comment_preview">';
        // Get author name (and link) and use it as the title
        $authorName = htmlSpecialChars($comment->getUserDisplayName());
        $authorId = $comment->getUserId();
        if ($authorId > 0) {
            // Add link to author profile
            $authorName = '<a href="' . $text->e($text->getUrlPage("account", $authorId)) . '">' . $authorName . "</a>";
        }
        $returnValue .= '<header><h3 class="comment_title">' . $authorName . "</h3></header>\n";
        // Get body text and limit its length
        // (Whole body links to context of comment)
        $bodyRaw = $comment->getBodyRaw();
        if (strLen($bodyRaw) > self::MAX_TEXT_LENGTH) {
            $bodyRaw = subStr($bodyRaw, 0, self::MAX_TEXT_LENGTH - 3) . '...';
        }
        $body = htmlSpecialChars($bodyRaw);
        $returnValue .= <<<EOT
            <p>
                <a class="disguised_link" href="{$contextUrl}">
                    {$body}
                </a>
            </p>
EOT;
        // Add a link for some context
        $returnValue .= <<<EOT
            <footer>
                <p>
                    <a class="arrow" href="{$contextUrl}">
                        {$text->t("comments.view_context")}
                    </a>
                </p>
            </footer>
EOT;
        $returnValue .= "</article>";
        return $returnValue;
    }