Exemple #1
0
 /**
  * Prepare topic reply form.
  *
  * @return void
  *
  * @throws RuntimeException
  * @throws KunenaExceptionAuthorise
  */
 protected function before()
 {
     parent::before();
     $catid = $this->input->getInt('catid');
     $id = $this->input->getInt('id');
     $mesid = $this->input->getInt('mesid');
     $quote = $this->input->getBool('quote', false);
     $saved = $this->app->getUserState('com_kunena.postfields');
     $this->me = KunenaUserHelper::getMyself();
     $this->template = KunenaFactory::getTemplate();
     if (!$mesid) {
         $this->topic = KunenaForumTopicHelper::get($id);
         $parent = KunenaForumMessageHelper::get($this->topic->first_post_id);
     } else {
         $parent = KunenaForumMessageHelper::get($mesid);
         $this->topic = $parent->getTopic();
     }
     $this->category = $this->topic->getCategory();
     if ($parent->isAuthorised('reply') && $this->me->canDoCaptcha()) {
         if (JPluginHelper::isEnabled('captcha')) {
             $plugin = JPluginHelper::getPlugin('captcha');
             $params = new JRegistry($plugin[0]->params);
             $captcha_pubkey = $params->get('public_key');
             $catcha_privkey = $params->get('private_key');
             if (!empty($captcha_pubkey) && !empty($catcha_privkey)) {
                 JPluginHelper::importPlugin('captcha');
                 $dispatcher = JDispatcher::getInstance();
                 $result = $dispatcher->trigger('onInit', 'dynamic_recaptcha_1');
                 $this->captchaEnabled = $result[0];
             }
         } else {
             $this->captchaEnabled = false;
         }
     }
     $parent->tryAuthorise('reply');
     // Run event.
     $params = new JRegistry();
     $params->set('ksource', 'kunena');
     $params->set('kunena_view', 'topic');
     $params->set('kunena_layout', 'reply');
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('kunena');
     $dispatcher->trigger('onKunenaPrepare', array('kunena.topic', &$this->topic, &$params, 0));
     // Can user edit topic icons?
     if ($this->config->topicicons && $this->topic->isAuthorised('edit')) {
         $this->topicIcons = $this->template->getTopicIcons(false, $saved ? $saved['icon_id'] : $this->topic->icon_id);
     }
     list($this->topic, $this->message) = $parent->newReply($saved ? $saved : $quote);
     $this->action = 'post';
     $this->allowedExtensions = KunenaAttachmentHelper::getExtensions($this->category);
     $this->post_anonymous = $saved ? $saved['anonymous'] : !empty($this->category->post_anonymous);
     $this->subscriptionschecked = $saved ? $saved['subscribe'] : $this->config->subscriptionschecked == 1;
     $this->app->setUserState('com_kunena.postfields', null);
     $this->canSubscribe = $this->canSubscribe();
     $this->headerText = JText::_('COM_KUNENA_BUTTON_MESSAGE_REPLY') . ' ' . $this->topic->subject;
 }
Exemple #2
0
 /**
  * Prepare topic edit form.
  *
  * @return void
  *
  * @throws KunenaExceptionAuthorise
  */
 protected function before()
 {
     parent::before();
     $this->catid = $this->input->getInt('catid');
     $mesid = $this->input->getInt('mesid');
     $saved = $this->app->getUserState('com_kunena.postfields');
     $this->me = KunenaUserHelper::getMyself();
     $this->template = KunenaFactory::getTemplate();
     $this->message = KunenaForumMessageHelper::get($mesid);
     $this->message->tryAuthorise('edit');
     $this->topic = $this->message->getTopic();
     $this->category = $this->topic->getCategory();
     $this->template->setCategoryIconset($this->topic->getCategory()->iconset);
     if ($this->config->topicicons && $this->topic->isAuthorised('edit')) {
         $this->topicIcons = $this->template->getTopicIcons(false, $saved ? $saved['icon_id'] : $this->topic->icon_id);
     }
     // Run onKunenaPrepare event.
     $params = new JRegistry();
     $params->set('ksource', 'kunena');
     $params->set('kunena_view', 'topic');
     $params->set('kunena_layout', 'reply');
     $dispatcher = JEventDispatcher::getInstance();
     JPluginHelper::importPlugin('kunena');
     $dispatcher->trigger('onKunenaPrepare', array('kunena.topic', &$this->topic, &$params, 0));
     $this->action = 'edit';
     // Get attachments.
     $this->attachments = $this->message->getAttachments();
     // Get poll.
     if ($this->message->parent == 0 && $this->topic->isAuthorised(!$this->topic->poll_id ? 'poll.create' : 'poll.edit')) {
         $this->poll = $this->topic->getPoll();
     }
     $this->allowedExtensions = KunenaAttachmentHelper::getExtensions($this->category);
     if ($saved) {
         // Update message contents.
         $this->message->edit($saved);
     }
     $this->post_anonymous = isset($saved['anonymous']) ? $saved['anonymous'] : !empty($this->category->post_anonymous);
     $this->subscriptionschecked = isset($saved['subscribe']) ? $saved['subscribe'] : $this->config->subscriptionschecked == 1;
     $this->modified_reason = isset($saved['modified_reason']) ? $saved['modified_reason'] : '';
     $this->app->setUserState('com_kunena.postfields', null);
     $this->canSubscribe = $this->canSubscribe();
     $this->headerText = JText::_('COM_KUNENA_POST_EDIT') . ' ' . $this->topic->subject;
 }
Exemple #3
0
 /**
  * @param string $key
  * @param null|int   $catid
  *
  * @return bool
  *
  * @since  K4.0
  */
 function upload($key = 'kattachment', $catid = null)
 {
     jimport('joomla.filesystem.folder');
     $config = KunenaFactory::getConfig();
     $input = JFactory::getApplication()->input;
     $fileInput = $input->files->get($key, null, 'raw');
     $upload = KunenaUpload::getInstance(KunenaAttachmentHelper::getExtensions($catid, $this->userid));
     $uploadBasePath = JPATH_ROOT . '/media/kunena/attachments/' . $this->userid . '/';
     if (!JFolder::exists($uploadBasePath)) {
         mkdir(JPATH_ROOT . '/media/kunena/attachments/' . $this->userid . '/');
     }
     $upload->splitFilename($fileInput['name']);
     $fileInput['name'] = preg_replace('/[[:space:]]/', '', $fileInput['name']);
     $fileNameWithoutExt = JFile::stripExt($fileInput['name']);
     $fileExt = JFile::getExt($fileInput['name']);
     $fileNameWithExt = $fileInput['name'];
     if (file_exists($uploadBasePath . $fileInput['name'])) {
         for ($i = 2; file_exists($uploadBasePath . $fileNameWithoutExt . '.' . $fileExt); $i++) {
             $fileNameWithoutExt = $fileNameWithoutExt . "-{$i}";
             $fileNameWithExt = $fileNameWithoutExt . '.' . $fileExt;
         }
     }
     $fileInput['name'] = $fileNameWithExt;
     $file = $upload->upload($fileInput, $uploadBasePath . $fileNameWithoutExt);
     if ($file->success) {
         if (extension_loaded('fileinfo')) {
             $finfo = new finfo(FILEINFO_MIME);
             $type = $finfo->file($uploadBasePath . $fileNameWithExt);
         } else {
             $info = getimagesize($uploadBasePath . $fileNameWithExt);
             $type = $info['mime'];
         }
         if (stripos($type, 'image/') !== false) {
             $imageInfo = KunenaImage::getImageFileProperties($uploadBasePath . $fileNameWithExt);
             if (number_format($file->size / 1024, 2) > $config->imagesize || $imageInfo->width > $config->imagewidth || $imageInfo->height > $config->imageheight) {
                 // Calculate quality for both JPG and PNG.
                 $quality = $config->imagequality;
                 if ($quality < 1 || $quality > 100) {
                     $quality = 70;
                 }
                 if ($imageInfo->type == IMAGETYPE_PNG) {
                     $quality = intval(($quality - 1) / 10);
                 }
                 $options = array('quality' => $quality);
                 try {
                     $image = new KunenaImage($uploadBasePath . $fileNameWithExt);
                     $image = $image->resize($config->imagewidth, $config->imagewidth, false);
                     $image->toFile($uploadBasePath . $fileNameWithExt, $imageInfo->type, $options);
                     unset($image);
                 } catch (Exception $e) {
                     // TODO: better error message.
                     echo $e->getMessage();
                     return false;
                 }
             }
             $this->filetype = $imageInfo->mime;
         }
         $this->protected = (bool) $config->attachment_protection;
         $this->hash = md5_file($uploadBasePath . $fileNameWithExt);
         $this->size = $file->size;
         $this->folder = 'media/kunena/attachments/' . $this->userid;
         $this->filename = $fileInput['name'];
         $this->filename_real = $uploadBasePath . $fileNameWithExt;
         $this->caption = '';
         return true;
     }
 }
Exemple #4
0
 protected function displayEdit($tpl = null)
 {
     $this->catid = $this->state->get('item.catid');
     $mesid = $this->state->get('item.mesid');
     $saved = $this->app->getUserState('com_kunena.postfields');
     $this->message = KunenaForumMessageHelper::get($mesid);
     if (!$this->message->authorise('edit')) {
         $this->app->enqueueMessage($this->message->getError(), 'notice');
         return false;
     }
     $this->topic = $this->message->getTopic();
     $this->category = $this->topic->getCategory();
     if ($this->config->topicicons && $this->topic->authorise('edit', null, false)) {
         $this->topicIcons = $this->ktemplate->getTopicIcons(false, $saved ? $saved['icon_id'] : $this->topic->icon_id);
     }
     // Run events
     $params = new JRegistry();
     $params->set('ksource', 'kunena');
     $params->set('kunena_view', 'topic');
     $params->set('kunena_layout', 'reply');
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('kunena');
     $dispatcher->trigger('onKunenaPrepare', array('kunena.topic', &$this->topic, &$params, 0));
     $this->_prepareDocument('edit');
     $this->action = 'edit';
     // Get attachments
     $this->attachments = $this->message->getAttachments();
     // Get poll
     if ($this->message->parent == 0 && (!$this->topic->poll_id && $this->topic->authorise('poll.create', null, false) || $this->topic->poll_id && $this->topic->authorise('poll.edit', null, false))) {
         $this->poll = $this->topic->getPoll();
     }
     $this->allowedExtensions = KunenaAttachmentHelper::getExtensions($this->category);
     if ($saved) {
         // Update message contents
         $this->message->edit($saved);
     }
     $this->post_anonymous = isset($saved['anonymous']) ? $saved['anonymous'] : !empty($this->category->post_anonymous);
     $this->subscriptionschecked = isset($saved['subscribe']) ? $saved['subscribe'] : $this->config->subscriptionschecked == 1;
     $this->modified_reason = isset($saved['modified_reason']) ? $saved['modified_reason'] : '';
     $this->app->setUserState('com_kunena.postfields', null);
     $this->render('Topic/Edit', $tpl);
 }
Exemple #5
0
 /**
  * @param KunenaUser $user
  *
  * @return KunenaExceptionAuthorise|null
  */
 protected function authoriseUpload(KunenaUser $user)
 {
     // Check if attachments are allowed
     if (KunenaAttachmentHelper::getExtensions($this, $user) === false) {
         return new KunenaExceptionAuthorise(JText::_('COM_KUNENA_LIB_CATEGORY_AUTHORISE_FAILED_UPLOAD_NOT_ALLOWED'), 403);
     }
     return null;
 }
Exemple #6
0
 /**
  * Prepare topic creation form.
  *
  * @return bool
  *
  * @throws RuntimeException
  */
 protected function before()
 {
     parent::before();
     $catid = $this->input->getInt('catid', 0);
     $saved = $this->app->getUserState('com_kunena.postfields');
     $this->me = KunenaUserHelper::getMyself();
     $this->template = KunenaFactory::getTemplate();
     $categories = KunenaForumCategoryHelper::getCategories();
     $arrayanynomousbox = array();
     $arraypollcatid = array();
     foreach ($categories as $category) {
         if (!$category->isSection() && $category->allow_anonymous) {
             $arrayanynomousbox[] = '"' . $category->id . '":' . $category->post_anonymous;
         }
         if (!$category->isSection() && $category->allow_polls) {
             $arraypollcatid[] = '"' . $category->id . '":1';
         }
     }
     $arrayanynomousbox = implode(',', $arrayanynomousbox);
     $arraypollcatid = implode(',', $arraypollcatid);
     // FIXME: We need to proxy this...
     $this->document = JFactory::getDocument();
     $this->document->addScriptDeclaration('var arrayanynomousbox={' . $arrayanynomousbox . '}');
     $this->document->addScriptDeclaration('var pollcategoriesid = {' . $arraypollcatid . '};');
     $this->category = KunenaForumCategoryHelper::get($catid);
     list($this->topic, $this->message) = $this->category->newTopic($saved);
     $this->template->setCategoryIconset($this->topic->getCategory()->iconset);
     // Get topic icons if they are enabled.
     if ($this->config->topicicons) {
         $this->topicIcons = $this->template->getTopicIcons(false, $saved ? $saved['icon_id'] : 0, $this->topic->getCategory()->iconset);
     }
     if ($this->topic->isAuthorised('create') && $this->me->canDoCaptcha()) {
         if (JPluginHelper::isEnabled('captcha')) {
             $plugin = JPluginHelper::getPlugin('captcha');
             $params = new JRegistry($plugin[0]->params);
             $captcha_pubkey = $params->get('public_key');
             $catcha_privkey = $params->get('private_key');
             if (!empty($captcha_pubkey) && !empty($catcha_privkey)) {
                 JPluginHelper::importPlugin('captcha');
                 $dispatcher = JDispatcher::getInstance();
                 $result = $dispatcher->trigger('onInit', 'dynamic_recaptcha_1');
                 $this->captchaEnabled = $result[0];
             }
         }
     } else {
         $this->captchaEnabled = false;
     }
     if (!$this->topic->category_id) {
         throw new KunenaExceptionAuthorise(JText::sprintf('COM_KUNENA_POST_NEW_TOPIC_NO_PERMISSIONS', $this->topic->getError()), $this->me->exists() ? 403 : 401);
     }
     $options = array();
     $selected = $this->topic->category_id;
     if ($this->config->pickup_category) {
         $options[] = JHtml::_('select.option', '', JText::_('COM_KUNENA_SELECT_CATEGORY'), 'value', 'text');
         $selected = 0;
     }
     if ($saved) {
         $selected = $saved['catid'];
     }
     $cat_params = array('ordering' => 'ordering', 'toplevel' => 0, 'sections' => 0, 'direction' => 1, 'hide_lonely' => 1, 'action' => 'topic.create');
     $this->selectcatlist = JHtml::_('kunenaforum.categorylist', 'catid', $catid, $options, $cat_params, 'class="form-control inputbox required"', 'value', 'text', $selected, 'postcatid');
     $this->action = 'post';
     $this->allowedExtensions = KunenaAttachmentHelper::getExtensions($this->category);
     if ($arraypollcatid) {
         $this->poll = $this->topic->getPoll();
     }
     $this->post_anonymous = $saved ? $saved['anonymous'] : !empty($this->category->post_anonymous);
     $this->subscriptionschecked = $saved ? $saved['subscribe'] : $this->config->subscriptionschecked == 1;
     $this->app->setUserState('com_kunena.postfields', null);
     $this->canSubscribe = $this->canSubscribe();
     $this->headerText = JText::_('COM_KUNENA_NEW_TOPIC');
     return true;
 }
Exemple #7
0
 /**
  * Upload files with AJAX.
  *
  * @throws RuntimeException
  */
 public function upload()
 {
     // Only support JSON requests.
     if ($this->input->getWord('format', 'html') != 'json') {
         throw new RuntimeException(JText::_('Bad Request'), 400);
     }
     $upload = KunenaUpload::getInstance();
     // We are converting all exceptions into JSON.
     try {
         if (!JSession::checkToken('request')) {
             throw new RuntimeException(JText::_('Forbidden'), 403);
         }
         $me = KunenaUserHelper::getMyself();
         $catid = $this->input->getInt('catid', 0);
         $mesid = $this->input->getInt('mesid', 0);
         if ($mesid) {
             $message = KunenaForumMessageHelper::get($mesid);
             $message->tryAuthorise('attachment.create');
             $category = $message->getCategory();
         } else {
             $category = KunenaForumCategoryHelper::get($catid);
             // TODO: Some room for improvements in here... (maybe ask user to pick up category first)
             if ($category->id) {
                 if (stripos($this->input->getString('mime'), 'image/') !== false) {
                     $category->tryAuthorise('topic.post.attachment.createimage');
                 } else {
                     $category->tryAuthorise('topic.post.attachment.createfile');
                 }
             }
         }
         $caption = $this->input->getString('caption');
         $options = array('filename' => $this->input->getString('filename'), 'size' => $this->input->getInt('size'), 'mime' => $this->input->getString('mime'), 'hash' => $this->input->getString('hash'), 'chunkStart' => $this->input->getInt('chunkStart', 0), 'chunkEnd' => $this->input->getInt('chunkEnd', 0));
         // Upload!
         $upload->addExtensions(KunenaAttachmentHelper::getExtensions($category->id, $me->userid));
         $response = (object) $upload->ajaxUpload($options);
         if (!empty($response->completed)) {
             // We have it all, lets create the attachment.
             $uploadFile = $upload->getProtectedFile();
             list($basename, $extension) = $upload->splitFilename();
             $attachment = new KunenaAttachment();
             $attachment->bind(array('mesid' => 0, 'userid' => (int) $me->userid, 'protected' => null, 'hash' => $response->hash, 'size' => $response->size, 'folder' => null, 'filetype' => $response->mime, 'filename' => null, 'filename_real' => $response->filename, 'caption' => $caption));
             // Resize image if needed.
             if ($attachment->isImage()) {
                 $imageInfo = KunenaImage::getImageFileProperties($uploadFile);
                 $config = KunenaConfig::getInstance();
                 if ($imageInfo->width > $config->imagewidth || $imageInfo->height > $config->imageheight) {
                     // Calculate quality for both JPG and PNG.
                     $quality = $config->imagequality;
                     if ($quality < 1 || $quality > 100) {
                         $quality = 70;
                     }
                     if ($imageInfo->type == IMAGETYPE_PNG) {
                         $quality = intval(($quality - 1) / 10);
                     }
                     $image = new KunenaImage($uploadFile);
                     $image = $image->resize($config->imagewidth, $config->imageheight, false);
                     $options = array('quality' => $quality);
                     $image->toFile($uploadFile, $imageInfo->type, $options);
                     unset($image);
                     $attachment->hash = md5_file($uploadFile);
                     $attachment->size = filesize($uploadFile);
                 }
             }
             $attachment->saveFile($uploadFile, $basename, $extension, true);
             // Set id and override response variables just in case if attachment was modified.
             $response->id = $attachment->id;
             $response->hash = $attachment->hash;
             $response->size = $attachment->size;
             $response->mime = $attachment->filetype;
             $response->filename = $attachment->filename_real;
         }
     } catch (Exception $response) {
         $upload->cleanup();
         // Use the exception as the response.
     }
     header('Content-type: application/json');
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header("Cache-Control: no-store, no-cache, must-revalidate");
     header("Cache-Control: post-check=0, pre-check=0", false);
     header("Pragma: no-cache");
     while (@ob_end_clean()) {
     }
     echo $upload->ajaxResponse($response);
     jexit();
 }