Exemple #1
0
 /**
  * @throws Exception
  */
 public function delete()
 {
     if (!JSession::checkToken('post')) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
         $this->setRedirect(KunenaRoute::_($this->baseurl, false));
         return;
     }
     $cid = JFactory::getApplication()->input->get('cid', array(), 'post', 'array');
     // Array of integers
     Joomla\Utilities\ArrayHelper::toInteger($cid);
     if (!$cid) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_NO_ATTACHMENTS_SELECTED'), 'error');
         $this->setRedirect(KunenaRoute::_($this->baseurl, false));
         return;
     }
     foreach ($cid as $id) {
         $attachment = KunenaAttachmentHelper::get($id);
         $message = $attachment->getMessage();
         $attachments = array($attachment->id, 1);
         $attach = array();
         $removeList = array_keys(array_diff_key($attachments, $attach));
         Joomla\Utilities\ArrayHelper::toInteger($removeList);
         $message->removeAttachments($removeList);
         $message->save();
         $topic = $message->getTopic();
         $attachment->delete();
         if ($topic->attachments > 0) {
             $topic->attachments = $topic->attachments - 1;
             $topic->save(false);
         }
     }
     $this->app->enqueueMessage(JText::_('COM_KUNENA_ATTACHMENTS_DELETED_SUCCESSFULLY'));
     $this->setRedirect(KunenaRoute::_($this->baseurl, false));
 }
Exemple #2
0
 /**
  * @param mixed $identifier
  * @param bool $reload
  *
  * @return KunenaAttachment
  *
  * @since  K4.0
  */
 public static function getInstance($identifier = null, $reload = false)
 {
     return KunenaAttachmentHelper::get($identifier, $reload);
 }
Exemple #3
0
 function DoAttachment($bbcode, $action, $name, $default, $params, $content)
 {
     if ($action == BBCODE_CHECK) {
         return true;
     }
     $attachments = null;
     if ($bbcode->parent instanceof KunenaForumMessage) {
         $attachments = $bbcode->parent->getAttachments();
     } elseif (is_object($bbcode->parent) && isset($bbcode->parent->attachments)) {
         $attachments =& $bbcode->parent->attachments;
     }
     /** @var KunenaAttachment $att */
     /** @var KunenaAttachment $attachment */
     $attachment = null;
     if (!empty($default)) {
         $attachment = KunenaAttachmentHelper::get($default);
         unset($attachments[$attachment->id]);
     } elseif (empty($content)) {
         $attachment = array_shift($attachments);
     } elseif (!empty($attachments)) {
         foreach ($attachments as $att) {
             if ($att->getFilename() == $content) {
                 $attachment = $att;
                 unset($attachments[$att->id]);
                 break;
             }
         }
     }
     // Display tag in activity streams etc..
     if (!isset($attachments) || !empty($bbcode->parent->forceMinimal)) {
         if ($attachment->isImage()) {
             $hide = KunenaFactory::getConfig()->showimgforguest == 0 && JFactory::getUser()->id == 0;
             if (!$hide) {
                 return "<div class=\"kmsgimage\">{$attachment->getImageLink()}</div>";
             }
         } else {
             $hide = KunenaFactory::getConfig()->showfileforguest == 0 && JFactory::getUser()->id == 0;
             if (!$hide) {
                 return "<div class=\"kmsgattach\"><h4>" . JText::_('COM_KUNENA_FILEATTACH') . "</h4>" . JText::_('COM_KUNENA_FILENAME') . " <a href=\"" . $attachment->getUrl() . "\" target=\"_blank\" rel=\"nofollow\">" . $attachment->filename . "</a><br />" . JText::_('COM_KUNENA_FILESIZE') . ' ' . number_format(intval($attachment->size) / 1024, 0, '', ',') . ' KB' . "</div>";
             }
         }
     }
     if (!$attachment && !empty($bbcode->parent->inline_attachments)) {
         foreach ($bbcode->parent->inline_attachments as $att) {
             if ($att->getFilename() == trim(strip_tags($content))) {
                 $attachment = $att;
                 break;
             }
         }
     }
     if (!$attachment) {
         return $bbcode->HTMLEncode($content);
     }
     return $this->renderAttachment($attachment, $bbcode);
 }
Exemple #4
0
 function DoAttachment($bbcode, $action, $name, $default, $params, $content)
 {
     if ($action == BBCODE_CHECK) {
         return true;
     }
     $attachments = null;
     if ($bbcode->parent instanceof KunenaForumMessage) {
         $attachments = $bbcode->parent->getAttachments();
     } elseif (is_object($bbcode->parent) && isset($bbcode->parent->attachments)) {
         $attachments =& $bbcode->parent->attachments;
     }
     // Display tag in activity streams etc..
     if (!isset($attachments) || !empty($bbcode->parent->forceMinimal)) {
         $filename = basename(trim(strip_tags($content)));
         return '[' . JText::_('COM_KUNENA_FILEATTACH') . ' ' . basename(!empty($params["name"]) ? $params["name"] : $filename) . ']';
     }
     /** @var KunenaAttachment $att */
     /** @var KunenaAttachment $attachment */
     $attachment = null;
     if (!empty($default)) {
         $attachment = KunenaAttachmentHelper::get($default);
         unset($attachments[$attachment->id]);
     } elseif (empty($content)) {
         $attachment = array_shift($attachments);
     } elseif (!empty($attachments)) {
         foreach ($attachments as $att) {
             if ($att->getFilename() == $content) {
                 $attachment = $att;
                 unset($attachments[$att->id]);
                 break;
             }
         }
     }
     // Display tag in activity streams etc..
     if (!empty($bbcode->parent->forceMinimal) || !is_object($bbcode->parent) && !isset($bbcode->parent->attachments)) {
         $filename = basename(trim(strip_tags($content)));
         return $attachment->getThumbnailLink();
     }
     if (!$attachment && !empty($bbcode->parent->inline_attachments)) {
         foreach ($bbcode->parent->inline_attachments as $att) {
             if ($att->getFilename() == trim(strip_tags($content))) {
                 $attachment = $att;
                 break;
             }
         }
     }
     if (!$attachment) {
         return $bbcode->HTMLEncode($content);
     }
     return $this->renderAttachment($attachment, $bbcode);
 }
Exemple #5
0
 public function delfile()
 {
     if (!JSession::checkToken('post')) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
         $this->setRedirectBack();
         return;
     }
     $cid = JRequest::getVar('cid', array(), 'post', 'array');
     // Array of integers
     JArrayHelper::toInteger($cid);
     if (!empty($cid)) {
         $number = 0;
         foreach ($cid as $id) {
             $attachment = KunenaAttachmentHelper::get($id);
             $message = $attachment->getMessage();
             $attachments = array($attachment->id, 1);
             $attach = array();
             $removeList = array_keys(array_diff_key($attachments, $attach));
             JArrayHelper::toInteger($removeList);
             $message->removeAttachments($removeList);
             $topic = $message->getTopic();
             if ($attachment->isAuthorised('delete') && $attachment->delete()) {
                 $message->save();
                 if ($topic->attachments > 0) {
                     $topic->attachments = $topic->attachments - 1;
                     $topic->save(false);
                 }
                 $number++;
             }
         }
         if ($number > 0) {
             $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_ATTACHMENTS_DELETE_SUCCESSFULLY', $number));
             $this->setRedirectBack();
             return;
         } else {
             $this->app->enqueueMessage(JText::_('COM_KUNENA_ATTACHMENTS_DELETE_FAILED'));
             $this->setRedirectBack();
             return;
         }
     }
     $this->app->enqueueMessage(JText::_('COM_KUNENA_ATTACHMENTS_NO_ATTACHMENTS_SELECTED'));
     $this->setRedirectBack();
 }
Exemple #6
0
 /**
  * Display attachment.
  *
  * @return void
  *
  * @throws RuntimeException
  * @throws KunenaExceptionAuthorise
  */
 public function display()
 {
     KunenaFactory::loadLanguage('com_kunena');
     $format = $this->input->getWord('format', 'html');
     $id = $this->input->getInt('id', 0);
     $thumb = $this->input->getBool('thumb', false);
     $download = $this->input->getBool('download', false);
     // Run before executing action.
     $this->before();
     if ($format != 'raw' || !$id) {
         throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), 404);
     } elseif ($this->config->board_offline && !$this->me->isAdmin()) {
         // Forum is offline.
         throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_FORUM_IS_OFFLINE'), 503);
     } elseif ($this->config->regonly && !$this->me->exists()) {
         // Forum is for registered users only.
         throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_LOGIN_NOTIFICATION'), 403);
     }
     $attachment = KunenaAttachmentHelper::get($id);
     $attachment->tryAuthorise();
     $path = $attachment->getPath($thumb);
     if ($thumb && !$path) {
         $path = $attachment->getPath(false);
     }
     if (!$path) {
         // File doesn't exist.
         throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), 404);
     }
     if (headers_sent()) {
         throw new KunenaExceptionAuthorise('HTTP headers were already sent. Sending attachment failed.', 500);
     }
     // Close all output buffers, just in case.
     while (@ob_end_clean()) {
     }
     // Handle 304 Not Modified
     if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
         $etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
         if ($etag == $attachment->hash) {
             header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT', true, 304);
             // Give fast response.
             flush();
             $this->app->close();
         }
     }
     // Set file headers.
     header('ETag: ' . $attachment->hash);
     header('Pragma: public');
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT');
     if (!$download && $attachment->isImage()) {
         // By default display images inline.
         $guest = new KunenaUser();
         // If guests can access the image, we allow it to be cached for an hour.
         if ($attachment->isAuthorised('read', $guest)) {
             $maxage = 60 * 60;
             header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $maxage) . ' GMT');
             header('Cache-Control: maxage=' . $maxage);
         } else {
             header('Expires: 0');
             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         }
         header('Content-type: ' . $attachment->filetype);
         header('Content-Disposition: inline; filename="' . $attachment->getFilename(false) . '"');
     } else {
         // Otherwise force file download.
         header('Expires: 0');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Content-Description: File Transfer');
         header('Content-Type: application/force-download');
         header('Content-Type: application/octet-stream');
         header('Content-Type: application/download');
         header('Content-Disposition: attachment; filename="' . $attachment->getFilename(false) . '"');
     }
     header('Content-Transfer-Encoding: binary');
     header('Content-Length: ' . filesize($path));
     flush();
     // Output the file contents.
     @readfile($path);
     flush();
     $this->app->close();
 }
Exemple #7
0
 /**
  * Remove files with AJAX.
  *
  * @throws RuntimeException
  *
  * @return string
  */
 public function removeattachments()
 {
     // Only support JSON requests.
     if ($this->input->getWord('format', 'html') != 'json') {
         throw new RuntimeException(JText::_('Bad Request'), 400);
     }
     if (!JSession::checkToken('request')) {
         throw new RuntimeException(JText::_('Forbidden'), 403);
     }
     $attach_id = $this->input->getInt('file_id', 0);
     $success = array();
     $instance = KunenaAttachmentHelper::get($attach_id);
     $success['result'] = $instance->delete();
     unset($instance);
     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 json_encode($success);
     jexit();
 }