Пример #1
0
 /**
  * Ensure the board correctly calculates the page for the latest post in it
  * 
  * @param int $replies
  * @param int $perPage
  * @param int $expected
  * @dataProvider providerCalcLastPostPage
  */
 public function testCalcLastPostPage($replies, $perPage, $expected)
 {
     $this->board->set('last_post_replies', $replies);
     $this->modx->setOption('discuss.post_per_page', $perPage);
     $page = $this->board->calcLastPostPage();
     $this->assertEquals($expected, $page);
 }
Пример #2
0
 public function getBreadcrumbs()
 {
     $defaults = array();
     if (!empty($this->options['showTitleInBreadcrumbs'])) {
         $defaults[] = array('text' => $this->modx->lexicon('discuss.reply_to_post', array('post' => '<a class="active" href="' . $this->discuss->request->makeUrl('thread', array('thread' => $this->thread->get('id'))) . '">' . $this->post->get('title') . '</a>')), 'active' => true);
     }
     return $this->board->buildBreadcrumbs($defaults, true);
 }
Пример #3
0
 private function updateReadStates()
 {
     $this->modx->log(modX::LOG_LEVEL_INFO, 'Updating disThreadRead data...');
     $affected = $this->modx->updateCollection('disThreadRead', array('board' => $this->newBoard->get('id')), array('board' => $this->oldBoard->get('id')));
     if ($affected === false) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, 'Error updating disThreadRead table.');
     } else {
         $this->modx->log(modX::LOG_LEVEL_WARN, 'Updated ' . $affected . ' disThreadRead records.');
     }
 }
Пример #4
0
 /**
  * Handle the rendering and options of attachments being sent to the form
  * @return void
  */
 public function handleAttachments()
 {
     $this->setPlaceholder('max_attachments', $this->modx->getOption('discuss.attachments_max_per_post', null, 5));
     $this->modx->regClientHTMLBlock('<script type="text/javascript">
     DIS.config.attachments_max_per_post = ' . $this->getPlaceholder('max_attachments') . ';
     </script>');
     if ($this->board->canPostAttachments()) {
         $this->setPlaceholders(array('attachments' => '', 'attachmentCurIdx' => 1));
         $this->setPlaceholder('attachment_fields', $this->discuss->getChunk($this->getOption('tplAttachmentFields'), $this->getPlaceholders()));
     } else {
         $this->setPlaceholders(array('attachment_fields' => '', 'attachments' => '', 'attachmentCurIdx' => 1));
     }
 }
Пример #5
0
 public function getBreadcrumbs()
 {
     /* build breadcrumbs */
     $trail = '';
     if (empty($this->board)) {
         $this->board = $this->thread->getOne('Board');
     }
     if ($this->board) {
         $default = array();
         if (!empty($this->options['showTitleInBreadcrumbs'])) {
             $default[] = array('text' => $this->modx->lexicon('discuss.modify_post_header', array('post' => $this->post->get('title'))), 'active' => true);
         }
         $this->board->buildBreadcrumbs($default, true);
         $trail = $this->board->get('trail');
     }
     return $trail;
 }
Пример #6
0
 public function getActionButtons()
 {
     /* @var array $actionButtons Thread action buttons */
     $actionButtons = array();
     if ($this->board->canPost() && $this->thread->canReply()) {
         $this->setPlaceholder('actionlink_reply', $this->discuss->request->makeUrl('thread/reply', array('thread' => $this->thread->get('id'))));
         $actionButtons[] = array('url' => $this->discuss->request->makeUrl('thread/reply', array('thread' => $this->thread->get('id'))), 'text' => $this->modx->lexicon('discuss.reply_to_thread'), 'cls' => 'dis-action-reply dis-action-reply_to-thread');
     }
     $this->setPlaceholder('actionlink_unread', $this->thread->getUrl(false, array('unread' => 1)));
     $actionButtons[] = array('url' => $this->thread->getUrl(false, array('unread' => 1)), 'text' => $this->modx->lexicon('discuss.mark_unread'));
     $this->setPlaceholder('actionlink_subscribe', '');
     $this->setPlaceholder('actionlink_unsubscribe', '');
     if ($this->thread->canUnsubscribe()) {
         if (!empty($this->options['showSubscribeOption'])) {
             $actionButtons[] = array('url' => $this->thread->getUrl(false, array('unsubscribe' => 1)), 'text' => $this->modx->lexicon('discuss.unsubscribe'), 'cls' => 'dis-action-unsubscribe');
             $this->setPlaceholder('actionlink_unsubscribe', $this->thread->getUrl(false, array('unsubscribe' => 1)));
         }
         $this->setPlaceholder('subscribed', true);
         $this->setPlaceholder('unsubscribeUrl', $this->thread->getUrl(false, array('unsubscribe' => 1)));
     } elseif ($this->thread->canSubscribe()) {
         if (!empty($this->options['showSubscribeOption'])) {
             $actionButtons[] = array('url' => $this->thread->getUrl(false, array('subscribe' => 1)), 'text' => $this->modx->lexicon('discuss.subscribe'), 'cls' => 'dis-action-subscribe');
             $this->setPlaceholder('actionlink_subscribe', $this->thread->getUrl(false, array('subscribe' => 1)));
         }
         $this->setPlaceholder('subscribed', false);
         $this->setPlaceholder('subscribeUrl', $this->thread->getUrl(false, array('subscribe' => 1)));
     }
     /* TODO: Send thread by email - 1.1
      * if ($this->modx->hasPermission('discuss.thread_send') {
      *   $actionButtons[] = array('url' => 'javascript:void(0);', 'text' => $this->modx->lexicon('discuss.thread_send'));
      * }
      */
     if ($this->thread->canPrint() && !empty($this->options['showPrintOption'])) {
         $actionButtons[] = array('url' => $this->thread->getUrl(false, array('print' => 1)), 'text' => $this->modx->lexicon('discuss.print'), 'cls' => 'dis-action-print');
         $this->setPlaceholder('actionlink_print', $this->thread->getUrl(false, array('print' => 1)));
     }
     $this->setPlaceholder('actionbuttons', $this->discuss->buildActionButtons($actionButtons, 'dis-action-btns right'));
 }
Пример #7
0
 public function getPageTitle()
 {
     return $this->modx->lexicon('discuss.board') . ': ' . $this->board->get('name');
 }
Пример #8
0
 /**
  * @return array
  */
 public function getBreadcrumbs()
 {
     return $this->board->buildBreadcrumbs();
 }
Пример #9
0
 /**
  * Import all topics for this Board
  * 
  * @param disBoard $board
  * @param array $brow
  * @return array
  */
 public function importTopics(disBoard $board, array $brow)
 {
     $sql = '
         SELECT
             FirstPost.*,
             Topic.locked AS locked,
             Topic.numReplies AS numReplies,
             Topic.numViews AS numViews,
             Topic.isSticky AS isSticky,
             Topic.ID_TOPIC AS ID_TOPIC,
             LastPost.posterTime AS latest_reply
         FROM ' . $this->getFullTableName('topics') . ' AS `Topic`
         INNER JOIN ' . $this->getFullTableName('messages') . ' AS `FirstPost` ON `FirstPost`.`ID_MSG` = `Topic`.`ID_FIRST_MSG`
         INNER JOIN ' . $this->getFullTableName('messages') . ' AS `LastPost` ON `LastPost`.`ID_MSG` = `Topic`.`ID_LAST_MSG`
         WHERE
             `Topic`.`ID_BOARD` = ' . $brow['ID_BOARD'] . '
         ORDER BY `FirstPost`.`posterTime` ASC
     ' . (!$this->config['live'] ? 'LIMIT 10' : '');
     $tst = $this->pdo->query($sql);
     if (!$tst) {
         return array();
     }
     $tIdx = 0;
     while ($trow = $tst->fetch(PDO::FETCH_ASSOC)) {
         $this->log('Importing Topic in ' . $board->get('name') . ': ' . $trow['subject']);
         /** @var disThread $thread */
         $thread = $this->modx->newObject('disThread');
         $thread->fromArray(array('board' => $board->get('id'), 'views' => $trow['numViews'], 'locked' => $trow['locked'], 'sticky' => $trow['isSticky'], 'private' => false, 'integrated_id' => $trow['ID_TOPIC']));
         if ($this->config['live']) {
             $thread->save();
         }
         /** @var disPost $threadPost */
         $threadPost = $this->modx->newObject('disPost');
         $threadPost->fromArray(array('board' => $thread->get('board'), 'thread' => $thread->get('id'), 'parent' => 0, 'title' => mb_convert_encoding($trow['subject'], $this->config['to_encoding'], $this->config['from_encoding']), 'message' => mb_convert_encoding($trow['body'], $this->config['to_encoding'], $this->config['from_encoding']), 'author' => isset($this->memberCache[$trow['ID_MEMBER']]) ? $this->memberCache[$trow['ID_MEMBER']] : 0, 'createdon' => strftime(DisSmfImport::DATETIME_FORMATTED, $trow['posterTime']), 'editedby' => !empty($trow['modifiedName']) && isset($this->memberNameCache[$trow['modifiedName']]) ? $this->memberNameCache[$trow['modifiedName']] : 0, 'editedon' => !empty($trow['modifiedTime']) ? strftime(DisSmfImport::DATETIME_FORMATTED, $trow['modifiedTime']) : null, 'icon' => $trow['icon'], 'rank' => $tIdx, 'ip' => $trow['posterIP'], 'integrated_id' => $trow['ID_MSG'], 'depth' => 0));
         if ($this->config['live']) {
             $threadPost->save();
         }
         $tIdx++;
         $postsData = $this->importPosts($thread, $threadPost, $trow);
         $thread->set('post_first', $threadPost->get('id'));
         $thread->set('author_first', $threadPost->get('author'));
         $thread->set('replies', $postsData['total']);
         if ($postsData['lastPost']) {
             $thread->set('post_last', $postsData['lastPost']->get('id'));
             $thread->set('author_last', $postsData['lastPost']->get('author'));
             $thread->set('post_last_on', strtotime($postsData['lastPost']->get('createdon')));
         } else {
             $thread->set('post_last', $threadPost->get('id'));
             $thread->set('author_last', $threadPost->get('author'));
             $thread->set('post_last_on', strtotime($threadPost->get('createdon')));
         }
         if ($this->config['live']) {
             $thread->save();
         }
     }
     $tst->closeCursor();
 }