Пример #1
0
 private function updateCommentFromRequest(Comment $comment, Request $request)
 {
     $comment->setBodyRaw($request->getRequestString("comment", ""));
     if ($comment->isByVisitor()) {
         $name = $request->getRequestString("name", "");
         $email = $request->getRequestString("email", "");
         $comment->setByVisitor($name, $email);
     }
 }
Пример #2
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;
    }
Пример #3
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;
 }
Пример #4
0
 private function fetchComment(Request $request, Article $article, User $user = null)
 {
     $commentText = $request->getRequestString("comment", "");
     if ($user !== null) {
         return Comment::createForUser($user, $article, $commentText);
     } else {
         $displayName = $request->getRequestString("name", "");
         $email = $request->getRequestString("email", "");
         return Comment::createForVisitor($displayName, $email, $article, $commentText);
     }
 }
Пример #5
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;
    }
Пример #6
0
 public function testChangeVisitor()
 {
     $article = new Article();
     $comment = Comment::createForVisitor("Bob", "", $article, "Some reply");
     $comment->setByVisitor("Alice", "*****@*****.**");
     $this->assertEquals("Alice", $comment->getUserDisplayName());
     $this->assertEquals("*****@*****.**", $comment->getUserEmail());
 }