/**
  * Gets the posts for the feed.
  */
 protected function readPosts()
 {
     // accessible boards
     $accessibleBoardIDArray = Board::getAccessibleBoardIDArray(array('canViewBoard', 'canEnterBoard', 'canReadThread'));
     if (!count($accessibleBoardIDArray)) {
         throw new PermissionDeniedException();
     }
     // get posts
     $attachmentPostIDArray = array();
     $sql = "SELECT\t\tpost.*\n\t\t\tFROM\t\twbb" . WBB_N . "_post post\n\t\t\tWHERE\t\tpost.threadID IN (" . implode(',', $this->threadIDArray) . ")\n\t\t\t\t\tAND post.threadID IN (SELECT threadID FROM wbb" . WBB_N . "_thread WHERE boardID IN (" . implode(',', $accessibleBoardIDArray) . "))\n\t\t\t\t\tAND post.isDeleted = 0\n\t\t\t\t\tAND post.isDisabled = 0\n\t\t\t\t\t" . ($this->hours ? "AND post.time > " . (TIME_NOW - $this->hours * 3600) : '') . "\n\t\t\tORDER BY\tpost.time DESC";
     $result = WCF::getDB()->sendQuery($sql, $this->limit);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $this->posts[] = new FeedPost(null, $row);
         // attachments
         if ($row['attachments'] != 0) {
             $attachmentPostIDArray[] = $row['postID'];
         }
     }
     // read attachments
     if (MODULE_ATTACHMENT == 1 && count($attachmentPostIDArray) > 0 && (WCF::getUser()->getPermission('user.board.canViewAttachmentPreview') || WCF::getUser()->getPermission('user.board.canDownloadAttachment'))) {
         require_once WCF_DIR . 'lib/data/attachment/MessageAttachmentList.class.php';
         $attachmentList = new MessageAttachmentList($attachmentPostIDArray, 'post');
         $attachmentList->readObjects();
         $attachments = $attachmentList->getSortedAttachments();
         // set embedded attachments
         require_once WCF_DIR . 'lib/data/message/bbcode/AttachmentBBCode.class.php';
         AttachmentBBCode::setAttachments($attachments);
     }
 }
 /**
  * Creates a new MessageAttachmentListEditor object.
  * 
  * @param	array<integer>	$containerIDArray
  * @param	string		$containerType
  * @param	integer		$packageID
  * @param	integer		$maxFileSize
  * @param	string		$allowedExtensions
  * @param	integer		$maxUploads
  * @param	integer		$thumbnailWidth
  * @param	integer		$thumbnailHeight
  * @param	boolean		$addSourceInfo
  * @param	boolean		$useEmbedded
  */
 public function __construct($containerIDArray = array(), $containerType = 'post', $packageID = PACKAGE_ID, $maxFileSize = 2000000, $allowedExtensions = "gif\njpg\njpeg\npng\nbmp\nzip\ntxt", $maxUploads = 5, $thumbnailWidth = ATTACHMENT_THUMBNAIL_WIDTH, $thumbnailHeight = ATTACHMENT_THUMBNAIL_HEIGHT, $addSourceInfo = ATTACHMENT_THUMBNAIL_ADD_SOURCE_INFO, $useEmbedded = ATTACHMENT_THUMBNAIL_USE_EMBEDDED)
 {
     if (!is_array($containerIDArray)) {
         $containerIDArray = array($containerIDArray);
     }
     $this->thumbnailWidth = $thumbnailWidth;
     $this->thumbnailHeight = $thumbnailHeight;
     $this->addSourceInfo = $addSourceInfo;
     $this->useEmbedded = $useEmbedded;
     if (!count($containerIDArray)) {
         $this->getIDHash();
     }
     // call parent constructor
     parent::__construct($containerIDArray, $containerType, $this->idHash, $packageID);
     // read attachments
     $this->readObjects();
     $this->maxFileSize = $maxFileSize;
     $this->maxUploads = $maxUploads;
     $allowedExtensions = StringUtil::unifyNewlines($allowedExtensions);
     $allowedExtensions = implode("\n", array_unique(explode("\n", $allowedExtensions)));
     $this->allowedExtensions = '/^(' . StringUtil::replace("\n", "|", StringUtil::replace('\\*', '.*', preg_quote($allowedExtensions, '/'))) . ')$/i';
     $this->allowedExtensionsDesc = self::formatAllowedExtensions($allowedExtensions);
     $this->getAttachmentHashes();
     $this->assign();
 }
 /**
  * @see Form::readData()
  */
 public function readData()
 {
     parent::readData();
     if ($this->sendPickNotification) {
         $this->solutionObj->getEditor()->sendPickNotification();
     }
     // init todo list
     $this->todoList = new ContestParticipantTodoList();
     $this->todoList->sqlConditions .= 'contest_participant.contestID = ' . intval($this->contestID);
     $this->todoList->readObjects();
     // read comments
     $this->commentList->sqlOffset = ($this->pageNo - 1) * $this->itemsPerPage;
     $this->commentList->sqlLimit = $this->itemsPerPage;
     $this->commentList->readObjects();
     // read ratings
     $this->ratingList->readObjects();
     // read attachments
     if (MODULE_ATTACHMENT == 1 && $this->solutionObj->attachments > 0) {
         require_once WCF_DIR . 'lib/data/attachment/MessageAttachmentList.class.php';
         $this->attachmentList = new MessageAttachmentList($this->solutionObj->solutionID, 'contestSolutionEntry', '', WCF::getPackageID('de.easy-coding.wcf.contest'));
         $this->attachmentList->readObjects();
         $this->attachments = $this->attachmentList->getSortedAttachments(WCF::getUser()->getPermission('user.contest.canViewAttachmentPreview'));
         // set embedded attachments
         if (WCF::getUser()->getPermission('user.contest.canViewAttachmentPreview')) {
             require_once WCF_DIR . 'lib/data/message/bbcode/AttachmentBBCode.class.php';
             AttachmentBBCode::setAttachments($this->attachments);
         }
         // remove embedded attachments from list
         if (count($this->attachments) > 0) {
             MessageAttachmentList::removeEmbeddedAttachments($this->attachments);
         }
     }
     // init sidebar
     $this->sidebar = new ContestSidebar($this->entry);
 }
 /**
  * Gets the threads for the feed.
  */
 protected function readThreads()
 {
     $boardIDArray = $this->boardIDArray;
     // include subboards
     if (count($boardIDArray)) {
         $boardIDArray = array_merge($boardIDArray, Board::getSubBoardIDArray($boardIDArray));
     }
     // accessible boards
     $accessibleBoardIDArray = Board::getAccessibleBoardIDArray(array('canViewBoard', 'canEnterBoard', 'canReadThread'));
     if (count($boardIDArray)) {
         $boardIDArray = array_intersect($boardIDArray, $accessibleBoardIDArray);
     } else {
         $boardIDArray = $accessibleBoardIDArray;
         foreach ($boardIDArray as $key => $boardID) {
             if (WCF::getUser()->isIgnoredBoard($boardID)) {
                 unset($boardIDArray[$key]);
             }
         }
     }
     // get threads
     $attachmentPostIDArray = array();
     if (count($boardIDArray)) {
         $sql = "SELECT\t\tpost.*, thread.*, post.attachments\n\t\t\t\tFROM\t\twbb" . WBB_N . "_thread thread\n\t\t\t\tLEFT JOIN\twbb" . WBB_N . "_post post\n\t\t\t\tON\t\t(post.postID = thread.firstPostID)\n\t\t\t\tWHERE\t\tthread.boardID IN (" . implode(',', $boardIDArray) . ")\n\t\t\t\t\t\tAND thread.isDeleted = 0\n\t\t\t\t\t\tAND thread.isDisabled = 0\n\t\t\t\t\t\tAND thread.movedThreadID = 0\n\t\t\t\t\t\tAND thread.time > " . ($this->hours ? TIME_NOW - $this->hours * 3600 : TIME_NOW - 30 * 86400) . "\n\t\t\t\tORDER BY\tthread.time DESC";
         $result = WCF::getDB()->sendQuery($sql, $this->limit);
         while ($row = WCF::getDB()->fetchArray($result)) {
             $this->threads[] = new FeedThread($row);
             // attachments
             if ($row['attachments'] != 0) {
                 $attachmentPostIDArray[] = $row['postID'];
             }
         }
     }
     // read attachments
     if (MODULE_ATTACHMENT == 1 && count($attachmentPostIDArray) > 0 && (WCF::getUser()->getPermission('user.board.canViewAttachmentPreview') || WCF::getUser()->getPermission('user.board.canDownloadAttachment'))) {
         require_once WCF_DIR . 'lib/data/attachment/MessageAttachmentList.class.php';
         $attachmentList = new MessageAttachmentList($attachmentPostIDArray, 'post');
         $attachmentList->readObjects();
         $attachments = $attachmentList->getSortedAttachments();
         // set embedded attachments
         require_once WCF_DIR . 'lib/data/message/bbcode/AttachmentBBCode.class.php';
         AttachmentBBCode::setAttachments($attachments);
     }
 }
 /**
  * Gets a list of attachments.
  */
 protected function readAttachments()
 {
     // read attachments
     if (MODULE_ATTACHMENT == 1 && count($this->attachmentPMIDArray)) {
         require_once WCF_DIR . 'lib/data/attachment/MessageAttachmentList.class.php';
         $this->attachmentList = new MessageAttachmentList($this->attachmentPMIDArray, 'pm', '', WCF::getPackageID('com.woltlab.wcf.data.message.pm'));
         $this->attachmentList->readObjects();
         $this->attachments = $this->attachmentList->getSortedAttachments();
         require_once WCF_DIR . 'lib/data/message/bbcode/AttachmentBBCode.class.php';
         AttachmentBBCode::setAttachments($this->attachments);
         if (count($this->attachments) > 0) {
             MessageAttachmentList::removeEmbeddedAttachments($this->attachments);
         }
     }
 }
 /**
  * @see Page::readData()
  */
 public function readData()
 {
     parent::readData();
     // show 5 entries on first page, but 20 on the following pages
     $this->eventmixList->sqlLimit = $this->pageNo <= 1 ? $this->itemsOnLandingpage : $this->itemsPerPage;
     $this->eventmixList->sqlOffset = $this->pageNo <= 1 ? 0 : ($this->pageNo - 2) * $this->itemsPerPage + $this->itemsOnLandingpage;
     // fire sql query
     $this->eventmixList->readObjects();
     // get previous entry
     $sql = "SELECT\t\t*\n\t\t\tFROM\t\twcf" . WCF_N . "_contest\n\t\t\tWHERE\t\tuserID = " . intval($this->entry->userID) . "\n\t\t\t\t\tAND (\n\t\t\t\t\t\ttime > " . intval($this->entry->time) . "\n\t\t\t\t\t\tOR (time = " . intval($this->entry->time) . " AND contestID < " . intval($this->entry->contestID) . ")\n\t\t\t\t\t)\n\t\t\tORDER BY\ttime ASC, contestID DESC";
     $this->previousEntry = new Contest(null, WCF::getDB()->getFirstRow($sql));
     if (!$this->previousEntry->contestID) {
         $this->previousEntry = null;
     }
     // get next entry
     $sql = "SELECT\t\t*\n\t\t\tFROM\t\twcf" . WCF_N . "_contest\n\t\t\tWHERE\t\tuserID = " . intval($this->entry->userID) . "\n\t\t\t\t\tAND (\n\t\t\t\t\t\ttime < " . intval($this->entry->time) . "\n\t\t\t\t\t\tOR (time = " . intval($this->entry->time) . " AND contestID > " . intval($this->entry->contestID) . ")\n\t\t\t\t\t)\n\t\t\tORDER BY\ttime DESC, contestID ASC";
     $this->nextEntry = new Contest(null, WCF::getDB()->getFirstRow($sql));
     if (!$this->nextEntry->contestID) {
         $this->nextEntry = null;
     }
     // read attachments
     if (MODULE_ATTACHMENT == 1 && $this->entry->attachments > 0) {
         require_once WCF_DIR . 'lib/data/attachment/MessageAttachmentList.class.php';
         $this->attachmentList = new MessageAttachmentList($this->contestID, 'contestEntry', '', WCF::getPackageID('de.easy-coding.wcf.contest'));
         $this->attachmentList->readObjects();
         $this->attachments = $this->attachmentList->getSortedAttachments(WCF::getUser()->getPermission('user.contest.canViewAttachmentPreview'));
         // set embedded attachments
         if (WCF::getUser()->getPermission('user.contest.canViewAttachmentPreview')) {
             require_once WCF_DIR . 'lib/data/message/bbcode/AttachmentBBCode.class.php';
             AttachmentBBCode::setAttachments($this->attachments);
         }
         // remove embedded attachments from list
         if (count($this->attachments) > 0) {
             MessageAttachmentList::removeEmbeddedAttachments($this->attachments);
         }
     }
     if ($this->entry->isOwner()) {
         // init todo list
         require_once WCF_DIR . 'lib/data/contest/owner/todo/ContestOwnerTodoList.class.php';
         $this->todoList = new ContestOwnerTodoList();
         $this->todoList->sqlConditions .= 'contest.contestID = ' . intval($this->contestID);
         $this->todoList->readObjects();
     }
     // init sidebar
     $this->sidebar = new ContestSidebar($this->entry);
 }
 /**
  * Gets a list of attachments.
  */
 protected function readAttachments()
 {
     // read attachments
     if (MODULE_ATTACHMENT == 1 && count($this->attachmentEntryIDArray) > 0) {
         require_once WCF_DIR . 'lib/data/attachment/MessageAttachmentList.class.php';
         $this->attachmentList = new MessageAttachmentList($this->attachmentEntryIDArray, 'contestEntry', '', WCF::getPackageID('de.easy-coding.wcf.contest'));
         $this->attachmentList->readObjects();
         $this->attachments = $this->attachmentList->getSortedAttachments(WCF::getUser()->getPermission('user.contest.canViewAttachmentPreview'));
         // set embedded attachments
         if (WCF::getUser()->getPermission('user.contest.canViewAttachmentPreview')) {
             require_once WCF_DIR . 'lib/data/message/bbcode/AttachmentBBCode.class.php';
             AttachmentBBCode::setAttachments($this->attachments);
         }
         // remove embedded attachments from list
         if (count($this->attachments) > 0) {
             MessageAttachmentList::removeEmbeddedAttachments($this->attachments);
         }
     }
 }
 /**
  * Sends the email notification.
  */
 public function sendNotification($post = null, $attachmentList = null)
 {
     $sql = "SELECT\t\tuser.*\n\t\t\tFROM\t\twbb" . WBB_N . "_board_subscription subscription\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_user user\n\t\t\tON\t\t(user.userID = subscription.userID)\n\t\t\tWHERE\t\tsubscription.boardID = " . $this->boardID . "\n\t\t\t\t\tAND subscription.enableNotification = 1\n\t\t\t\t\tAND subscription.emails = 0\n\t\t\t\t\tAND subscription.userID <> " . $this->userID . "\n\t\t\t\t\tAND user.userID IS NOT NULL";
     $result = WCF::getDB()->sendQuery($sql);
     if (WCF::getDB()->countRows($result)) {
         // get first post
         if ($post === null) {
             require_once WBB_DIR . 'lib/data/post/Post.class.php';
             $post = new Post($this->firstPostID);
         }
         // get attachments
         if ($attachmentList === null) {
             require_once WCF_DIR . 'lib/data/attachment/MessageAttachmentList.class.php';
             $attachmentList = new MessageAttachmentList($this->firstPostID);
             $attachmentList->readObjects();
         }
         // set attachments
         require_once WCF_DIR . 'lib/data/message/bbcode/AttachmentBBCode.class.php';
         AttachmentBBCode::setAttachments($attachmentList->getSortedAttachments());
         // parse text
         require_once WCF_DIR . 'lib/data/message/bbcode/MessageParser.class.php';
         $parser = MessageParser::getInstance();
         $parser->setOutputType('text/plain');
         $parsedText = $parser->parse($post->message, $post->enableSmilies, $post->enableHtml, $post->enableBBCodes, false);
         // truncate message
         if (!POST_NOTIFICATION_SEND_FULL_MESSAGE && StringUtil::length($parsedText) > 500) {
             $parsedText = StringUtil::substring($parsedText, 0, 500) . '...';
         }
         // send notifications
         $languages = array();
         $languages[WCF::getLanguage()->getLanguageID()] = WCF::getLanguage();
         $languages[0] = WCF::getLanguage();
         require_once WCF_DIR . 'lib/data/mail/Mail.class.php';
         require_once WCF_DIR . 'lib/data/user/User.class.php';
         require_once WBB_DIR . 'lib/data/board/Board.class.php';
         $board = Board::getBoard($this->boardID);
         while ($row = WCF::getDB()->fetchArray($result)) {
             $recipient = new User(null, $row);
             // get language
             if (!isset($languages[$recipient->languageID])) {
                 $languages[$recipient->languageID] = new Language($recipient->languageID);
             }
             // enable language
             $languages[$recipient->languageID]->setLocale();
             // send mail
             $data = array('PAGE_TITLE' => $languages[$recipient->languageID]->get(PAGE_TITLE), 'PAGE_URL' => PAGE_URL, '$recipient' => $recipient->username, '$author' => $this->username, '$boardTitle' => $languages[$recipient->languageID]->get($board->title), '$topic' => $this->topic, '$threadID' => $this->threadID, '$text' => $parsedText);
             $mail = new Mail(array($recipient->username => $recipient->email), $languages[$recipient->languageID]->get('wbb.threadAdd.notification.subject', array('$title' => $languages[$recipient->languageID]->get($board->title))), $languages[$recipient->languageID]->get('wbb.threadAdd.notification.mail', $data));
             $mail->send();
         }
         // enable user language
         WCF::getLanguage()->setLocale();
         // update notification count
         $sql = "UPDATE\twbb" . WBB_N . "_board_subscription\n\t\t\t\tSET \temails = emails + 1\n\t\t\t\tWHERE\tboardID = " . $this->boardID . "\n\t\t\t\t\tAND enableNotification = 1\n\t\t\t\t\tAND emails = 0";
         WCF::getDB()->registerShutdownUpdate($sql);
     }
 }
 /**
  * Gets a list of attachments.
  */
 protected function readAttachments()
 {
     // read attachments
     if (MODULE_ATTACHMENT == 1 && count($this->attachmentPostIDArray) > 0) {
         require_once WCF_DIR . 'lib/data/attachment/MessageAttachmentList.class.php';
         $this->attachmentList = new MessageAttachmentList($this->attachmentPostIDArray, 'post');
         $this->attachmentList->readObjects();
         $this->attachments = $this->attachmentList->getSortedAttachments($this->canViewAttachmentPreview);
         // set embedded attachments
         if ($this->canViewAttachmentPreview) {
             require_once WCF_DIR . 'lib/data/message/bbcode/AttachmentBBCode.class.php';
             AttachmentBBCode::setAttachments($this->attachments);
         }
         // remove embedded attachments from list
         if (count($this->attachments) > 0) {
             MessageAttachmentList::removeEmbeddedAttachments($this->attachments);
         }
     }
 }
 /**
  * @see Page::readData()
  */
 public function readData()
 {
     parent::readData();
     // get post list
     $this->postList = new PostAddPostList($this->thread, $this->board);
     // old thread warning
     if (REPLY_OLD_THREAD_WARNING && $this->thread->lastPostTime > 0) {
         $this->oldThreadWarning = intval(floor((TIME_NOW - $this->thread->lastPostTime) / 86400));
         if ($this->oldThreadWarning < REPLY_OLD_THREAD_WARNING) {
             $this->oldThreadWarning = 0;
         }
     }
     $this->attachments = $this->postList->attachments;
     if (count($this->attachments) > 0) {
         require_once WCF_DIR . 'lib/data/attachment/MessageAttachmentList.class.php';
         MessageAttachmentList::removeEmbeddedAttachments($this->attachments);
     }
     // default values
     if (!count($_POST)) {
         $this->closeThread = $this->thread->isClosed;
         $this->subscription = $this->thread->subscribed;
         if (!$this->subscription && WCF::getUser()->enableSubscription) {
             $this->subscription = 1;
         }
         // single quote
         if ($this->action == 'quote') {
             $post = $this->thread->getPost();
             if ($post) {
                 $this->text = "[quote='" . StringUtil::replace("'", "\\'", $post->username) . "',index.php?page=Thread&postID=" . $post->postID . "#post" . $post->postID . "]" . $post->message . "[/quote]";
                 if ($post->subject) {
                     $this->subject = WCF::getLanguage()->get('wbb.postAdd.quote.subject', array('$subject' => $post->subject));
                 }
             }
         }
     }
 }
 /**
  * @see Page::readData()
  */
 public function readData()
 {
     parent::readData();
     if (!count($_POST)) {
         $this->closeThread = $this->thread->isClosed;
         $this->text = $this->post->message;
         $this->subject = $this->post->subject;
         $this->subscription = $this->thread->subscribed;
         $this->prefix = $this->thread->prefix;
         if ($this->thread->isSticky) {
             $this->isImportant = 1;
         }
         if ($this->thread->isAnnouncement) {
             $this->isImportant = 2;
         }
         $this->boardIDs = $this->thread->getAssignedBoards();
         $this->languageID = $this->thread->languageID;
         $this->editReason = $this->post->editReason;
         $this->enableSmilies = $this->post->enableSmilies;
         $this->enableHtml = $this->post->enableHtml;
         $this->enableBBCodes = $this->post->enableBBCodes;
         $this->showSignature = $this->post->showSignature;
         // tags
         if (THREAD_ENABLE_TAGS && $this->thread->firstPostID == $this->postID) {
             $this->tags = TaggingUtil::buildString($this->thread->getTags(array($this->languageID)));
         }
     }
     // get post list
     if ($this->thread->firstPostID != $this->postID) {
         try {
             require_once WBB_DIR . 'lib/data/post/PostEditPostList.class.php';
             $this->postList = new PostEditPostList($this->post, $this->thread, $this->board);
             $this->attachments = $this->postList->attachments;
             if (count($this->attachments) > 0) {
                 require_once WCF_DIR . 'lib/data/attachment/MessageAttachmentList.class.php';
                 MessageAttachmentList::removeEmbeddedAttachments($this->attachments);
             }
         } catch (SystemException $e) {
         }
     }
 }
 /**
  * Sends e-mail notifications to all given recipients.
  * 
  * @param	array<User>
  */
 public function sendNotifications($recipients)
 {
     require_once WCF_DIR . 'lib/data/mail/Mail.class.php';
     require_once WCF_DIR . 'lib/system/language/Language.class.php';
     // get attachments
     if ($this->attachments > 0) {
         require_once WCF_DIR . 'lib/data/attachment/MessageAttachmentList.class.php';
         require_once WCF_DIR . 'lib/data/message/bbcode/AttachmentBBCode.class.php';
         $attachmentList = new MessageAttachmentList($this->pmID, 'pm');
         AttachmentBBCode::setAttachments($attachmentList->getSortedAttachments());
     }
     // get parsed text
     require_once WCF_DIR . 'lib/data/message/bbcode/MessageParser.class.php';
     $parser = MessageParser::getInstance();
     $parser->setOutputType('text/plain');
     $parsedText = $parser->parse($this->message, $this->enableSmilies, $this->enableHtml, $this->enableBBCodes, false);
     // send notifications
     $languages = array();
     $languages[0] = $languages[WCF::getLanguage()->getLanguageID()] = WCF::getLanguage();
     foreach ($recipients as $recipient) {
         // no notification for the author
         if ($recipient->userID == $this->userID) {
             continue;
         }
         // get language
         if (!isset($languages[$recipient->languageID])) {
             $languages[$recipient->languageID] = Language::getLanguageObjectByID($recipient->languageID);
         }
         // enable language
         $languages[$recipient->languageID]->setLocale();
         // send mail
         $subjectData = array('$author' => $this->username, 'PAGE_TITLE' => $languages[$recipient->languageID]->get(PAGE_TITLE));
         $messageData = array('PAGE_TITLE' => $languages[$recipient->languageID]->get(PAGE_TITLE), '$recipient' => $recipient->username, '$author' => $this->username, 'PAGE_URL' => PAGE_URL, '$subject' => $this->subject, '$text' => $parsedText);
         $mail = new Mail(array($recipient->username => $recipient->email), $languages[$recipient->languageID]->get('wcf.pm.notification.subject', $subjectData), $languages[$recipient->languageID]->get('wcf.pm.notification.mail', $messageData));
         $mail->send();
     }
     // enable user language
     WCF::getLanguage()->setLocale();
 }