Esempio n. 1
0
 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'));
 }
Esempio n. 2
0
 /**
  * Hide or show inputs on the form depending on whether the user has the correct Thread permissions
  * @return void
  */
 public function checkThreadPermissions()
 {
     if ($this->thread->canLock() || $this->thread->canUnlock()) {
         $locked = !empty($_POST['locked']) || $this->thread->get('locked') ? ' checked="checked"' : '';
         $this->setPlaceholders(array('locked' => $locked, 'locked_cb' => $this->discuss->getChunk('form/disCheckbox', array('name' => 'locked', 'value' => 1, 'text' => $this->getOption('textCheckboxLocked'), 'attributes' => $locked)), 'can_lock' => true));
     }
     if ($this->thread->canStick() || $this->thread->canUnstick()) {
         $sticky = !empty($_POST['sticky']) || $this->thread->get('sticky') ? ' checked="checked"' : '';
         $this->setPlaceholders(array('sticky' => $sticky, 'sticky_cb' => $this->discuss->getChunk('form/disCheckbox', array('name' => 'sticky', 'value' => 1, 'text' => $this->getOption('textCheckboxSticky'), 'attributes' => $sticky)), 'can_stick' => true));
     }
     if ($this->thread->canSubscribe() || $this->thread->canUnsubscribe()) {
         $notify = !empty($_POST['notify']) || $this->thread->hasSubscription() ? ' checked="checked"' : '';
         $this->setPlaceholders(array('notify_cb' => $this->discuss->getChunk('form/disCheckbox', array('name' => 'notify', 'value' => 1, 'text' => $this->getOption('textCheckboxNotify'), 'attributes' => $notify)), 'can_subscribe' => true));
     }
 }
Esempio n. 3
0
 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('&#91;', '&#93;', '&lt;', '&gt;'), $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);
 }