예제 #1
0
 public function process()
 {
     /* setup defaults */
     $this->setPlaceholders($this->board->toArray());
     /* setup class_key - defaults to disThreadDiscussion */
     $class_key = 'disThreadDiscussion';
     if (isset($_POST['class_key'])) {
         switch ($_POST['class_key']) {
             case 'disThreadQuestion':
                 $class_key = $_POST['class_key'];
                 break;
             case 'disThreadDiscussion':
             default:
                 $class_key = 'disThreadDiscussion';
         }
     }
     $this->setPlaceholders(array('is_root' => 1, 'board' => $this->board->get('id'), 'class_key' => $class_key));
     $this->getButtons();
     $this->checkThreadPermissions();
     $this->handleAttachments();
     // show subscribe checkbox
     $notify = !empty($_POST['notify']) ? ' checked="checked"' : '';
     $this->setPlaceholders(array('notify_cb' => $this->discuss->getChunk('form/disCheckbox', array('name' => 'notify', 'value' => 1, 'text' => $this->getOption('textCheckboxNotify'), 'attributes' => $notify))));
     $this->modx->setPlaceholder('discuss.error_panel', $this->discuss->getChunk('Error'));
     /* set placeholders for FormIt inputs */
     $this->modx->setPlaceholders($this->getPlaceholders(), 'fi.');
 }
예제 #2
0
 public function initialize()
 {
     $thread = $this->getProperty('thread', false);
     if (empty($thread)) {
         $post = $this->getProperty('post', false);
         if (empty($post)) {
             $this->modx->sendErrorPage();
         }
         $this->post = $this->modx->getObject('disPost', $post);
         if (empty($this->post)) {
             $this->discuss->sendErrorPage();
         }
         /* get thread root */
         $this->thread = $this->post->getOne('Thread');
         if (empty($this->thread)) {
             $this->discuss->sendErrorPage();
         }
     } else {
         $this->thread = $this->modx->getObject('disThread', $thread);
         if (empty($this->thread)) {
             $this->discuss->sendErrorPage();
         }
         $this->post = $this->thread->getOne('FirstPost');
         if (empty($this->post)) {
             $this->discuss->sendErrorPage();
         }
     }
     $this->author = $this->post->getOne('Author');
     $this->board = $this->thread->getOne('Board');
     $this->modx->lexicon->load('discuss:post');
     if ($this->board) {
         $this->discuss->user->isModerator($this->board->get('id'));
     }
 }
예제 #3
0
 /**
  * @param string $name
  * @param string $expected
  * @dataProvider providerGetLastPostTitleUrl
  */
 public function testGetLastPostTitleUrl($name, $expected)
 {
     $this->board->set('unit_test_title', $name);
     $slug = $this->board->getLastPostTitleSlug('unit_test_title');
     $this->assertEquals($expected, $slug);
     $this->assertEquals($this->board->get('unit_test_title'), $slug);
 }
예제 #4
0
 public function process()
 {
     /* up view count and mark read */
     $this->view();
     $this->markRead();
     /* get posts */
     $this->getAnswers();
     $this->getPosts();
     $this->getLastPost();
     $this->setPlaceholder('rtl', $this->board->get('rtl'));
     $threadArray = $this->thread->toArray('', true, true);
     $this->setPlaceholders($threadArray);
     $this->setPlaceholder('title', $this->thread->get('title'));
     $this->setPlaceholder('title_value', $threadArray['title']);
     $this->setPlaceholder('views', number_format($this->getPlaceholder('views', 1)));
     $this->setPlaceholder('replies', number_format($this->getPlaceholder('replies', 0)));
     $this->setPlaceholder('url', $this->thread->getUrl(false, array(), true));
     /* set css class of thread */
     $this->thread->buildCssClass();
     $this->getQuickReplyForm();
     if ($this->discuss->user->isLoggedIn && empty($this->scriptProperties['print'])) {
         $this->getActionButtons();
     }
     if ($this->discuss->user->isLoggedIn && ($this->isModerator || $this->isAdmin) && empty($this->scriptProperties['print'])) {
         $this->getModeratorActionButtons();
     }
     /* output */
     $this->setPlaceholder('discuss.error_panel', $this->discuss->getChunk('Error'));
     $this->setPlaceholder('discuss.thread', $this->thread->get('title'));
     $this->buildPagination();
     $this->getViewing();
     $this->fireOnRenderThread();
 }
예제 #5
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.');
     }
 }
예제 #6
0
 public function getActionButtons()
 {
     $actionButtons = array();
     if ($this->discuss->user->isLoggedIn) {
         if ($this->modx->hasPermission('discuss.thread_create') && $this->board->canPost()) {
             $actionButtons[] = array('url' => $this->discuss->request->makeUrl('thread/new', array('board' => $this->board->get('id'))), 'text' => $this->modx->lexicon('discuss.thread_new'), 'cls' => 'dis-action-thread_new');
         }
         $actionButtons[] = array('url' => $this->discuss->request->makeUrl('board', array('board' => $this->board->get('id'), 'read' => 1)), 'text' => $this->modx->lexicon('discuss.mark_all_as_read'), 'cls' => 'dis-action-mark_all_as_read');
     }
     $this->setPlaceholder('actionbuttons', $this->discuss->buildActionButtons($actionButtons, 'dis-action-btns right'));
 }
예제 #7
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;
 }
예제 #8
0
 public function getPageTitle()
 {
     return $this->modx->lexicon('discuss.board') . ': ' . $this->board->get('name');
 }
예제 #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();
 }