/** * Process the page * @return void */ public function process() { $this->setPlaceholders($this->thread->toArray()); $this->setPlaceholder('url', $this->thread->getUrl()); $this->getBoardList(); /* output */ $this->modx->setPlaceholder('discuss.thread', $this->thread->get('title')); }
public function handleActions() { if (!empty($this->scriptProperties['spam-thread'])) { if ($this->thread->remove(array(), true, true)) { $this->discuss->logActivity('thread_spam_remove', $this->thread->toArray(), $this->thread->getUrl()); $url = $this->discuss->request->makeUrl('board', array('board' => $this->thread->get('board'))); $this->modx->sendRedirect($url); } } }
public function handleActions() { /* process form */ if (!empty($this->scriptProperties['remove-message'])) { if ($this->thread->remove()) { /* log activity */ $this->discuss->logActivity('message_thread_remove', $this->thread->toArray(), $this->thread->getUrl()); $url = $this->discuss->request->makeUrl('messages'); $this->modx->sendRedirect($url); } } }
public function process() { if (!$this->post->remove(array(), true, true)) { $this->modx->log(modX::LOG_LEVEL_ERROR, '[Discuss] Could not remove post: ' . print_r($this->post->toArray(), true)); } else { $this->discuss->logActivity('post_spam_remove', $this->post->toArray(), $this->post->getUrl()); } if ($this->thread->get('post_first') == $this->post->get('id')) { $redirectTo = $this->discuss->request->makeUrl('board', array('board' => $this->post->get('board'))); } else { $redirectTo = $this->thread->getUrl(); } $this->modx->sendRedirect($redirectTo); }
public function initialize() { $this->post = $this->modx->getObject('disPost', $this->getProperty('post', false)); if (empty($this->post)) { $this->discuss->sendErrorPage(); } $this->thread = $this->modx->call('disThread', 'fetch', array(&$this->modx, $this->post->get('thread'))); if (empty($this->thread)) { $this->discuss->sendErrorPage(); } /* ensure user can report this post */ if (!$this->post->canReport()) { $this->modx->sendRedirect($this->thread->getUrl()); } }
public function process() { if (!$this->post->remove(array(), true)) { $this->modx->log(modX::LOG_LEVEL_ERROR, '[Discuss] Could not remove post: ' . print_r($this->post->toArray(), true)); } else { $this->discuss->logActivity('post_remove', $this->post->toArray(), $this->post->getUrl()); } /* If the thread no longer exists (last post in thread was removed), redirect to the board instead of thread */ if ($this->modx->getCount('disThread', $this->thread->get('id')) < 1) { $redirectTo = $this->discuss->request->makeUrl('board', array('board' => $this->post->get('board'))); } else { $redirectTo = $this->thread->getUrl(); } $this->modx->sendRedirect($redirectTo); }
public function getModeratorActionButtons() { $actionButtons = array(); if ($this->thread->canMove()) { $actionButtons[] = array('url' => $this->discuss->request->makeUrl('thread/move', array('thread' => $this->thread->get('id'))), 'text' => $this->modx->lexicon('discuss.thread_move'), 'cls' => 'dis-action-move dis-action-thread_move'); } if ($this->thread->canRemove()) { $actionButtons[] = array('url' => $this->discuss->request->makeUrl('thread/remove', array('thread' => $this->thread->get('id'))), 'text' => $this->modx->lexicon('discuss.thread_remove'), 'cls' => 'dis-action-remove-thread dis-action-thread_remove'); if (!empty($this->options['showMarkAsSpamOption'])) { $actionButtons[] = array('url' => $this->discuss->request->makeUrl('thread/spam', array('thread' => $this->thread->get('id'))), 'text' => $this->modx->lexicon('discuss.thread_spam'), 'cls' => 'dis-action-spam dis-action-thread_spam'); } } if ($this->thread->canUnlock() && !empty($this->options['showLockOption'])) { $actionButtons[] = array('url' => $this->thread->getUrl(false, array('lock' => 0)), 'text' => $this->modx->lexicon('discuss.thread_unlock'), 'cls' => 'dis-action-unlock dis-action-thread_unlock'); } else { if ($this->thread->canLock() && !empty($this->options['showLockOption'])) { $actionButtons[] = array('url' => $this->thread->getUrl(false, array('lock' => 1)), 'text' => $this->modx->lexicon('discuss.thread_lock'), 'cls' => 'dis-action-lock dis-action-thread_lock'); } } if ($this->thread->canUnstick() && !empty($this->options['showStickOption'])) { $actionButtons[] = array('url' => $this->thread->getUrl(false, array('sticky' => 0)), 'text' => $this->modx->lexicon('discuss.thread_unstick'), 'cls' => 'dis-action-unstick dis-action-thread_unstick'); } else { if ($this->thread->canStick() && !empty($this->options['showStickOption'])) { $actionButtons[] = array('url' => $this->thread->getUrl(false, array('sticky' => 1)), 'text' => $this->modx->lexicon('discuss.thread_stick'), 'cls' => 'dis-action-stick dis-action-thread-stick'); } } /** * TODO: Merge thread - 1.1 * $actionButtons[] = array('url' => 'javascript:void(0);', 'text' => $this->modx->lexicon('discuss.thread_merge')); */ $this->setPlaceholder('threadactionbuttons', $this->discuss->buildActionButtons($actionButtons, 'dis-action-btns right')); }
public function process() { $this->view(); $this->thread->buildCssClass(); $this->getQuickReplyForm(); $threadArray = $this->thread->toArray(); $threadArray['url'] = $this->thread->getUrl(false); $threadArray['views'] = number_format($threadArray['views']); $threadArray['replies'] = number_format($threadArray['replies']); $this->setPlaceholders($threadArray); $this->markAsRead(); $this->getThreadPosts(); $this->getLastPost(); $this->getViewing(); $this->buildPagination(); $this->getActionButtons(); $this->setPlaceholder('discuss.error_panel', $this->discuss->getChunk('Error')); $this->setPlaceholder('discuss.thread', $this->thread->get('title')); }
/** * Prepare the thread for iteration * @param disThread $thread * @return array */ protected function prepareThread(disThread $thread) { $thread->calcLastPostPage(); $thread->getUrl(); $threadArray = $thread->toArray(); $threadArray['createdon'] = strftime($this->getOption('dateFormat'), strtotime($threadArray['createdon'])); $threadArray['icons'] = ''; /* set css class */ $class = $this->getOption('clsRow'); $class = explode(',', $class); if ($this->getOption('enableHot')) { $threshold = $this->getOption('hotThreadThreshold'); if ($this->discuss->user->get('id') == $threadArray['author'] && $this->discuss->user->isLoggedIn) { $class[] = $threadArray['replies'] < $threshold ? $this->getOption('clsMyNormalThread') : $this->getOption('clsMyHotThread'); } else { $class[] = $threadArray['replies'] < $threshold ? $this->getOption('clsNormalThread') : $this->getOption('clsHotThread'); } } $threadArray['class'] = implode(' ', $class); /* if sticky/locked */ $icons = array(); if ($threadArray['locked']) { $icons[] = $this->getOption('iconLocked'); } if ($this->getOption('enableSticky') && $threadArray['sticky']) { $icons[] = $this->getOption('iconSticky'); } $threadArray['icons'] = implode($this->getOption('iconSeparator'), $icons); $threadArray['views'] = number_format($threadArray['views']); $threadArray['replies'] = number_format($threadArray['replies']); /* unread class */ $threadArray['unread'] = true; $threadArray['unread-cls'] = $this->getOption('clsUnread'); $threadArray['author_link'] = $this->getOption('canViewProfiles') ? '<a class="dis-last-post-by" href="' . $this->discuss->request->makeUrl('user', array('type' => 'username', 'user' => $threadArray['author_username'])) . '">' . $threadArray['author_username'] . '</a>' : $threadArray['author_username']; return $threadArray; }
public function process() { /* setup defaults */ $placeholders = $this->post->toArray(); $placeholders['url'] = $this->post->getUrl(); $placeholders['post'] = $this->post->get('id'); $placeholders['buttons'] = $this->discuss->getChunk('disPostButtons', array('buttons_url' => $this->discuss->config['imagesUrl'] . 'buttons/')); $placeholders['message'] = str_replace(array('[', ']', '<', '>'), array('[', ']', '<', '>'), $placeholders['message']); /* get thread root */ $placeholders['thread'] = $this->thread->get('id'); $placeholders['locked'] = $this->thread->get('locked'); $placeholders['sticky'] = $this->thread->get('sticky'); $placeholders['class_key'] = $this->thread->get('class_key'); $placeholders['is_root'] = $this->thread->get('post_first') == $this->post->get('id') ? 1 : 0; /* ensure user can modify this post */ $isModerator = $this->discuss->user->isGlobalModerator() || $this->thread->isModerator($this->discuss->user->get('id')) || $this->discuss->user->isAdmin(); $canModifyPost = $this->discuss->user->isLoggedIn && $this->modx->hasPermission('discuss.thread_modify'); $canModify = $this->discuss->user->get('id') == $this->post->get('author') || $isModerator && $canModifyPost; if (!$canModify) { $this->modx->sendRedirect($this->thread->getUrl()); } /* get attachments for post */ $attachments = $this->post->getMany('Attachments'); $idx = 1; $atts = array(); $postAttachmentRowTpl = $this->modx->getOption('postAttachmentRowTpl', $this->scriptProperties, 'post/disPostEditAttachment'); /** @var disPostAttachment $attachment */ foreach ($attachments as $attachment) { $attachmentArray = $attachment->toArray(); $attachmentArray['filesize'] = $attachment->convert(); $attachmentArray['url'] = $attachment->getUrl(); $attachmentArray['idx'] = $idx; $atts[] = $this->discuss->getChunk($postAttachmentRowTpl, $attachmentArray); $idx++; } /* attachments */ $placeholders['attachment_fields'] = ''; $placeholders['attachments'] = implode("\n", $atts); $placeholders['max_attachments'] = $this->modx->getOption('discuss.attachments_max_per_post', null, 5); $placeholders['attachmentCurIdx'] = count($attachments) + 1; if ($this->thread->canPostAttachments()) { $placeholders['attachment_fields'] = $this->discuss->getChunk('post/disAttachmentFields', $placeholders); } /* perms */ if ($placeholders['is_root']) { if ($this->thread->canLock() || $this->thread->canUnlock()) { $checked = !empty($_POST) ? !empty($_POST['locked']) : $this->thread->get('locked'); $placeholders['locked'] = $checked ? ' checked="checked"' : ''; $placeholders['locked_cb'] = $this->discuss->getChunk('form/disCheckbox', array('name' => 'locked', 'value' => 1, 'text' => $this->getOption('textCheckboxLocked'), 'attributes' => $placeholders['locked'])); $placeholders['can_lock'] = true; } if ($this->thread->canStick() || $this->thread->canUnstick()) { $checked = !empty($_POST) ? !empty($_POST['sticky']) : $this->thread->get('sticky'); $placeholders['sticky'] = $checked ? ' checked="checked"' : ''; $placeholders['sticky_cb'] = $this->discuss->getChunk('form/disCheckbox', array('name' => 'sticky', 'value' => 1, 'text' => $this->getOption('textCheckboxSticky'), 'attributes' => $placeholders['sticky'])); $placeholders['can_stick'] = true; } } /* If the editing user is the author, show him the subscribe checkbox */ if ($this->discuss->user->get('id') == $this->post->get('author') && ($this->thread->canSubscribe() || $this->thread->canUnsubscribe())) { $checked = !empty($_POST) ? !empty($_POST['notify']) : $this->thread->hasSubscription(); $placeholders['notify'] = $checked ? ' checked="checked"' : ''; $placeholders['notify_cb'] = $this->discuss->getChunk('form/disCheckbox', array('name' => 'notify', 'value' => 1, 'text' => $this->getOption('textCheckboxNotify'), 'attributes' => $placeholders['notify'])); $placeholders['can_subscribe'] = true; } $this->getThreadSummary(); /* output form to browser */ $this->modx->regClientHTMLBlock('<script type="text/javascript"> DIS.config.attachments_max_per_post = ' . $placeholders['max_attachments'] . '; DIS.DISModifyPost.init({ attachments: ' . (count($attachments) + 1) . ' }); </script>'); $this->modx->setPlaceholder('discuss.error_panel', $this->discuss->getChunk('disError')); $this->modx->setPlaceholders($placeholders, 'fi.'); $this->setPlaceholders($placeholders); }