示例#1
0
    protected function getSingleComment(Comment $comment)
    {
        $text = $this->text;
        $id = $comment->getId();
        $author = htmlSpecialChars($comment->getUserDisplayName());
        $postDate = "";
        if ($comment->getDateCreated() !== null) {
            $postDate = strFTime('%a %d %b %Y %X', $comment->getDateCreated()->getTimestamp());
        }
        $body = nl2br(htmlSpecialChars($comment->getBodyRaw()));
        $avatarUrl = User::getAvatarUrlFromEmail($comment->getUserEmail(), 40);
        // Add link and rank to author when linked to account
        if ($comment->getUserId() > 0) {
            $author = '<a href="' . $text->e($text->getUrlPage("account", $comment->getUserId())) . '">' . $author . '</a>';
        }
        // Edit and delete links
        $actionLinksHtml = $this->getActionLinks($comment);
        // Reply and context links
        if ($this->viewedOutOfContext) {
            $replyOrContextLink = <<<EOT
                <a class="arrow" href="{$text->e($comment->getUrl($text))}">
                    {$text->t("comments.view_context")}
                </a>
EOT;
        } else {
            // No child comments possible yet
            $replyOrContextLink = "";
        }
        $output = <<<COMMENT
            <article class="comment" id="comment_{$id}">
                <header>
                    <img src="{$avatarUrl}" alt="" />
                    <h3 class="comment_title">{$author}</h3>
                    <p class="comment_actions">
                        {$actionLinksHtml}
                    </p>
                    <p class="comment_date">{$postDate}</p>
                </header>
                <p class="comment_body">{$body}</p>
                <footer>
                    <p>{$replyOrContextLink}</p>
                </footer>
            </article>
COMMENT;
        return $output;
    }
示例#2
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;
    }