示例#1
0
 /**
  * Creates the commment renderer.
  * @param Text $text The website text object.
  * @param Comment[] $comments List of comments.
  * @param boolean $viewedOutOfContext Whether there should be a link to the article.
  * @param User|null $viewer The user viewing the comments, null if logged out.
  */
 public function __construct(Text $text, $comments, $viewedOutOfContext, User $viewer = null)
 {
     parent::__construct($text);
     $this->comments = $comments;
     $this->viewedByStaff = $viewer === null ? false : $viewer->hasRank(Authentication::RANK_MODERATOR);
     $this->viewedOutOfContext = $viewedOutOfContext;
     $this->viewerId = $viewer ? $viewer->getId() : 0;
 }
示例#2
0
 /** Returns the HTML of the comments of the user, including the header */
 public function get_comments_html(Website $website)
 {
     $oComments = new CommentRepository($website->getDatabase());
     $comments = $oComments->getCommentsUser($this->user->getId());
     $returnValue = '<h3 class="notable">' . $website->t("comments.comments") . "</h3>\n";
     if (count($comments) > 0) {
         $commentsTemplate = new CommentsTreeTemplate($website->getText(), $comments, true, $this->user);
         $returnValue .= $commentsTemplate->getText();
     } else {
         $returnValue .= "<p><em>" . $website->t("comments.no_comments_found_user") . "</em></p>";
     }
     return $returnValue;
 }
示例#3
0
 /**
  * Creates a new comment for the given user. This method will succeed even
  * if the given article doesn't allow comments.
  * @param User $user The author of the comment.
  * @param Article $article The article that is commented on.
  * @param string $text The comment of the user.
  * @return Comment The comment.
  */
 public static function createForUser(User $user, Article $article, $text)
 {
     $comment = new Comment(0);
     $comment->articleId = $article->getId();
     $comment->userId = $user->getId();
     $comment->userName = $user->getUsername();
     $comment->userDisplayName = $user->getDisplayName();
     $comment->userEmail = $user->getEmail();
     $comment->userRank = $user->getRank();
     $comment->created = new DateTime();
     $comment->body = (string) $text;
     return $comment;
 }
示例#4
0
    /** Gets the links for the bottom of the page */
    public function get_account_links_html(Website $website)
    {
        $textToDisplay = "";
        if ($this->editing_someone_else) {
            // Editing someone else, don't show "My account" link
            $textToDisplay .= <<<EOT
            <p>
                <a class="arrow" href="{$website->getUrlPage("account", $this->user->getId())}">
                    {$website->tReplaced("users.profile_page_of", $this->user->getDisplayName())}
                </a><br />
                <a class="arrow" href="{$website->getUrlPage("account_management")}">
                    {$website->t("main.account_management")}
                </a>
EOT;
        } else {
            $textToDisplay .= '<p><a class="arrow" href="' . $website->getUrlPage("account") . '">' . $website->t("main.my_account") . "</a>\n";
            if ($website->isLoggedInAsStaff(true)) {
                $textToDisplay .= '<br /><a class="arrow" href="' . $website->getUrlPage("account_management") . '">' . $website->t("main.account_management") . "</a>\n";
            }
            $textToDisplay .= "</p>";
        }
        return $textToDisplay;
    }
示例#5
0
 /**
  * Save that user object in the session. Doesn't modify the login cookie.
  * Null values are not permitted. Use log_out to log the current user out.
  * @param User $user The user to login
  * @return boolean Whether the user object was set. Returns false when the
  * account is banned or deleted.
  */
 public function setCurrentUser(User $user)
 {
     if (!$user->canLogIn()) {
         // User is banned or something
         return false;
     }
     $_SESSION['user_id'] = $user->getId();
     if ($user->hasRank(self::RANK_MODERATOR)) {
         // This session vars are purely used for CKEditor.
         // In rCMS there are much better, easier and safer ways to check this.
         $_SESSION['moderator'] = true;
     } else {
         $_SESSION['moderator'] = false;
     }
     $this->currentUser = $user;
     return true;
 }
示例#6
0
 /**
  * Sets the author of this article to the given user.
  * @param User $user The user.
  */
 public function setAuthor(User $user)
 {
     $this->author = $user->getDisplayName();
     $this->authorId = $user->getId();
     $this->updateLastEdited();
 }
示例#7
0
 /**
  * Creates a new document with the given title, intro and author. The
  * document is not saved automatically.
  * @param string $title Title of the document.
  * @param string $intro Intro of the document.
  * @param User $user
  * @return Document The document.
  */
 public static function createNew($title, $intro, User $user)
 {
     $document = new Document();
     $document->title = (string) $title;
     $document->intro = (string) $intro;
     $document->userId = (int) $user->getId();
     $document->created = new DateTime();
     return $document;
 }