示例#1
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));
     }
 }
示例#2
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'));
 }
示例#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);
 }