예제 #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
 /**
  * Validates a comment for saving to the database.
  * @param Comment $comment The comment.
  * @param Text $text Errors go here.
  * @return boolean True if the comment is valid, false otherwise.
  */
 public function validateComment(Comment $comment, Text $text)
 {
     $valid = true;
     if (!Validate::stringLength($comment->getBodyRaw(), Comment::BODY_MIN_LENGTH, Comment::BODY_MAX_LENGTH)) {
         $text->addError($text->t("comments.comment") . " " . Validate::getLastError($text));
         $valid = false;
     }
     if ($comment->isByVisitor()) {
         if (!Validate::email($comment->getUserEmail())) {
             $text->addError($text->t("users.email") . " " . Validate::getLastError($text));
             $valid = false;
         }
         if (!Validate::displayName($comment->getUserDisplayName())) {
             $text->addError($text->t("users.name") . " " . Validate::getLastError($text));
             $valid = false;
         }
     }
     return $valid;
 }