示例#1
0
 /**
  * Creates a new comment for a visitor.
  * @param string $displayName Name of the visitor.
  * @param string $email E-mail of the visitor, may be empty.
  * @param Article $article The article that is commented on.
  * @param string $text The text of the comment.
  * @return Comment The comment.
  */
 public static function createForVisitor($displayName, $email, Article $article, $text)
 {
     $comment = new Comment(0);
     $comment->articleId = $article->getId();
     $comment->commentName = (string) $displayName;
     $comment->commentEmail = (string) $email;
     $comment->body = (string) $text;
     $comment->created = new DateTime();
     return $comment;
 }
 /** Returns a single article enclosed in li tags */
 public function getArticleTextListEntry(Article $article, $displayImage = false)
 {
     $text = $this->text;
     $returnValue = '<li><a href="' . $text->e($text->getUrlPage("article", $article->getId())) . '"';
     $returnValue .= 'title="' . htmlSpecialChars($article->getIntro()) . '">';
     if ($displayImage && !empty($article->featuredImage)) {
         $returnValue .= '<div class="linklist_icon_image"><img src="' . htmlSpecialChars($article->featuredImage) . '" alt="' . htmlSpecialChars($article->getTitle()) . '" /></div>';
     }
     $returnValue .= "<span>" . htmlSpecialChars($article->getTitle()) . "</span></a></li>\n";
     return $returnValue;
 }
示例#3
0
 public function testUserComment()
 {
     $user = $this->getTestUser();
     $article = Article::createArticle($user);
     $comment = Comment::createForUser($user, $article, "Some reply");
     // Check user data
     $this->assertFalse($comment->isByVisitor());
     $this->assertEquals($user->getDisplayName(), $comment->getUserDisplayName());
     $this->assertEquals($user->getUsername(), $comment->getUsername());
     $this->assertEquals($user->getEmail(), $comment->getUserEmail());
     $this->assertEquals($user->getId(), $comment->getUserId());
     $this->assertEquals($user->getRank(), $comment->getUserRank());
 }
示例#4
0
 /**
  * Deletes the given article.
  * @param Article $article Article to delete.
  * @return boolean True if the article was deleted, false if deletion failed.
  */
 public function delete(Article $article)
 {
     try {
         $this->where($this->getPrimaryKey(), '=', $article->getId())->deleteOneOrFail();
         return true;
     } catch (NotFoundException $e) {
         return false;
     } catch (PDOException $e) {
         $this->website->getText()->logException("Error deleting article", $e);
         return false;
     }
 }
示例#5
0
 /**
  * Gets the article with the given id. If the id is 0, a new article is
  * created.
  * @param ArticleRepository $repository Repository to fetch articles from.
  * @param User $currentUser Becomes the author if a new article is created.
  * @param int $id Id of the article. Use 0 to create a new article.
  * @return Article The article.
  * @throws NotFoundException If no article exists with the given id.
  */
 protected function getArticle(ArticleRepository $repository, User $currentUser, $id)
 {
     if ($id === 0) {
         $article = new Article();
         $article->setAuthor($currentUser);
         return $article;
     } else {
         $article = $repository->getArticleOrFail($id);
         if ($article->authorId === 0) {
             // There was a bug in previous versions of the CMS where the
             // author wasn't saved
             $article->setAuthor($currentUser);
         }
         return $article;
     }
 }
示例#6
0
 /**
  * Creates a new article.
  * @param User $author Author of the article.
  * @return Article The article.
  */
 public static function createArticle(User $author)
 {
     $article = new Article();
     $article->setAuthor($author);
     return $article;
 }
示例#7
0
 /**
  * Gets the markup for a single row in the table, from &lt;tr&gt;
  * to &lt;.tr&gt;.
  * @param Article $article The article to display in the row.
  * @param boolean $loggedIn True if edit/delete column must be shown,
  * false otherwise.
  * @return string The markup for the row.
  */
 protected function getTableRow(Article $article, $loggedIn)
 {
     $text = $this->text;
     $textToDisplay = '<tr><td><a href="' . $text->e($text->getUrlPage("article", $article->getId()));
     $textToDisplay .= '">' . htmlSpecialChars($article->getTitle()) . "</a>";
     if ($loggedIn) {
         // Display edit links in new cell
         $textToDisplay .= '</td><td style="width:20%">';
         $textToDisplay .= '<a class="arrow" href="' . $text->e($text->getUrlPage("edit_article", $article->getId()));
         $textToDisplay .= '">' . $text->t("main.edit") . "</a>";
         $textToDisplay .= ' <a class="arrow" href="' . $text->e($text->getUrlPage("delete_article", $article->getId()));
         $textToDisplay .= '">' . $text->t("main.delete") . "</a>";
     }
     $textToDisplay .= "</td></tr>\n";
     return $textToDisplay;
 }
    private function getArticleEditLinks(Article $article)
    {
        if (!$this->editLinks) {
            return "";
        }
        $text = $this->text;
        return <<<EDIT_LINKS
            <a class="arrow" href="{$text->e($text->getUrlPage("edit_article", $article->getId()))}">
                {$text->t("main.edit")}
            </a>
            <a class="arrow" href="{$text->e($text->getUrlPage("delete_article", $article->getId()))}">
                {$text->t("main.delete")}
            </a>
EDIT_LINKS;
    }
示例#9
0
    /**
     * Enloses the given HTML in an invisble link to the article.
     * @param Article $article Article to link to.
     * @param string $html HTML to enclose.
     * @return string The linked HTML.
     */
    private function encloseInArticleLink(Article $article, $html)
    {
        $text = $this->text;
        return <<<LINKED
            <a class="disguised_link" href="{$text->e($text->getUrlPage("article", $article->getId()))}">
                {$html}
            </a>
LINKED;
    }
示例#10
0
 private function getNewTestArticle()
 {
     return Article::createArticle($this->getTestUser());
 }
示例#11
0
 private function writeArticleTextFull(StreamInterface $stream, Article $article, array $comments)
 {
     // Store some variables for later use
     $text = $this->text;
     $id = $article->getId();
     $loggedIn = $this->editLink;
     // Echo the sidebar
     $stream->write('<div id="sidebar_page_sidebar">');
     // Featured image
     if (!empty($article->featuredImage)) {
         $stream->write('<p><img src="' . htmlSpecialChars($article->featuredImage) . '" alt="' . htmlSpecialChars($article->getTitle()) . '" /></p>');
     }
     $stream->write('<p class="meta">');
     // Created and last edited
     $stream->write($text->t('articles.created') . " <br />&nbsp;&nbsp;&nbsp;" . $text->formatDateTime($article->getDateCreated()));
     if ($article->getDateLastEdited()) {
         $stream->write(" <br />  " . $text->t('articles.last_edited') . " <br />&nbsp;&nbsp;&nbsp;" . $text->formatDateTime($article->getDateLastEdited()));
     }
     // Category
     $stream->write(" <br /> " . $text->t('main.category') . ': ');
     $stream->write('<a href="' . $text->e($text->getUrlPage("category", $article->categoryId)) . '">');
     $stream->write($text->e($article->category) . '</a>');
     // Author
     $stream->write(" <br /> " . $text->t('articles.author') . ': ');
     $stream->write('<a href="' . $text->e($text->getUrlPage("account", $article->authorId)) . '">');
     $stream->write($text->e($article->author) . '</a>');
     // Pinned, hidden, comments
     if ($article->pinned) {
         $stream->write("<br />" . $text->t('articles.pinned') . " ");
     }
     if ($article->isHidden()) {
         $stream->write("<br />" . $text->t('articles.hidden'));
     }
     if ($loggedIn && $article->showComments) {
         $stream->write("<br />" . $text->t('comments.allowed'));
     }
     // Edit, delete
     $stream->write('</p>');
     if ($loggedIn) {
         $stream->write("<p style=\"clear:both\">");
         $stream->write('&nbsp;&nbsp;&nbsp;<a class="arrow" href="' . $text->e($text->getUrlPage("edit_article", $id)) . '">' . $text->t('main.edit') . '</a>&nbsp;&nbsp;' . '<a class="arrow" href="' . $text->e($text->getUrlPage("delete_article", $id)) . '">' . $text->t('main.delete') . '</a>');
         $stream->write("</p>");
     }
     $stream->write('</div>');
     // Article
     $stream->write('<div id="sidebar_page_content">');
     if ($loggedIn && $article->isHidden()) {
         $stream->write('<p class="meta">' . $text->t('articles.is_hidden') . "<br /> \n" . $text->t('articles.hidden.explained') . '</p>');
     }
     $stream->write('<p class="intro">' . $text->e($article->getIntro()) . '</p>');
     $stream->write($article->getBody());
     // Comments
     if ($article->showComments) {
         $commentCount = count($comments);
         // Title
         $stream->write('<h3 class="notable">' . $text->t("comments.comments"));
         if ($commentCount > 0) {
             $stream->write(' (' . $commentCount . ')');
         }
         $stream->write("</h3>\n\n");
         // "No comments found" if needed
         if ($commentCount == 0) {
             $stream->write('<p><em>' . $text->t("comments.no_comments_found") . '</em></p>');
         }
         // Comment add link
         $stream->write('<p><a class="button primary_button" href="' . $text->e($text->getUrlPage("add_comment", $id)) . '">' . $text->t("comments.add") . "</a></p>");
         // Show comments
         $commentTreeTemplate = new CommentsTreeTemplate($text, $comments, false, $this->userTemplateingComments);
         $commentTreeTemplate->writeText($stream);
     }
     $stream->write('</div>');
 }