public function getAttachments() { $attachments = $this->post->getMany('Attachments'); $idx = 1; $atts = array(); $postAttachmentRowTpl = $this->modx->getOption('postAttachmentRowTpl', $this->scriptProperties, 'post/disPostEditAttachment'); 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++; } $placeholders['attachments'] = implode("\n", $atts); $placeholders['max_attachments'] = $this->modx->getOption('discuss.attachments_max_per_post', null, 5); $placeholders['attachmentCurIdx'] = count($attachments) + 1; $this->modx->regClientHTMLBlock('<script type="text/javascript"> DIS.config.attachments_max_per_post = ' . $placeholders['max_attachments'] . '; DIS.DISModifyMessage.init({ attachments: ' . (count($attachments) + 1) . ' }); </script>'); }
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); }