Esempio n. 1
0
 /**
  * Uploads the images temporary to the cache folder
  * If the user doesn't save his entry the cron job will delete
  * the images
  *
  * @param   array  $file  - the file array
  *
  * @return boolean
  */
 public function uploadTmp($file)
 {
     $appl = JFactory::getApplication();
     // Total length of post back data in bytes.
     $contentLength = (int) $_SERVER['CONTENT_LENGTH'];
     $mediaHelper = new CompojoomHelperMedia();
     // Maximum allowed size of post back data in MB.
     $postMaxSize = $mediaHelper->toBytes(ini_get('post_max_size'));
     // Maximum allowed size of script execution in MB.
     $memoryLimit = $mediaHelper->toBytes(ini_get('memory_limit'));
     // Check for the total size of post back data.
     if ($postMaxSize > 0 && $contentLength > $postMaxSize || $memoryLimit != -1 && $contentLength > $memoryLimit) {
         $appl->enqueueMessage(JText::_('LIB_COMPOJOOM_ERROR_WARNUPLOADTOOLARGE'));
         return false;
     }
     // Do we have a file?
     if (isset($file['name'])) {
         JLoader::import('joomla.filesystem.file');
         $user = JFactory::getUser();
         $canUpload = $user->authorise('core.multimedia.create', $this->component);
         $params = JComponentHelper::getParams($this->component);
         $sizes = (array) $params->get('thumbs');
         // Some cameras just add whitespace, let's change this
         $file['name'] = str_replace(' ', '_', $file['name']);
         // Some users are uploading files with umlauts, change them to normal characters, otherwise we get an error on upload
         $file['name'] = preg_replace("/&([a-z])[a-z]+;/i", "\$1", htmlentities($file['name']));
         // The user doesn't seem to have upload privilegies
         if (!$canUpload) {
             $appl->enqueueMessage(JText::_('LIB_COMPOJOOM_YOU_DONT_HAVE_UPLOAD_PRIVILEGES'));
             return false;
         }
         // Check if we pass all other checks
         if (!$mediaHelper->canUpload($file, $this->component)) {
             return false;
         }
         // Get a (very!) randomised name
         $serverkey = JFactory::getConfig()->get('secret', '');
         $sig = microtime() . $serverkey;
         if (function_exists('sha256')) {
             $mangledname = sha256($sig);
         } elseif (function_exists('sha1')) {
             $mangledname = sha1($sig);
         } else {
             $mangledname = md5($sig);
         }
         $mangledname .= '_' . $file['name'];
         // ...and its full path
         $filepath = JPath::clean($this->getFilePath() . $mangledname);
         // If we have a name clash, abort the upload
         if (JFile::exists($filepath)) {
             $appl->enqueueMessage(JText::_('LIB_COMPOJOOM_ATTACHMENTS_ERR_NAMECLASH'));
             return false;
         }
         // Do the upload
         if (!JFile::upload($file['tmp_name'], $filepath)) {
             $appl->enqueueMessage(JText::_('LIB_COMPOJOOM_ATTACHMENTS_ERR_CANTJFILEUPLOAD'));
             return false;
         }
         // Get the MIME type
         if (function_exists('mime_content_type')) {
             $mime = mime_content_type($filepath);
         } elseif (function_exists('finfo_open')) {
             $finfo = finfo_open(FILEINFO_MIME_TYPE);
             $mime = finfo_file($finfo, $filepath);
         } else {
             $mime = 'application/octet-stream';
         }
         // Create a temporary thumb file
         $image = new CompojoomImage($filepath);
         $thumbs = $image->createThumbs($sizes['small']);
         $imageData = base64_encode(file_get_contents($thumbs[0]->getPath()));
         // Now remove the thumb
         JFile::delete($thumbs[0]->getPath());
         // Format the image SRC:  data:{mime};base64,{data};
         $src = 'data: ' . $mime . ';base64,' . $imageData;
         // Return the file info
         $fileData = array('name' => $mangledname, 'title' => JFile::stripExt($file['name']), 'thumbnailUrl' => $src, 'size' => $file['size'], 'type' => $file['type'], 'deleteType' => 'delete', 'url' => '', 'deleteUrl' => $this->deleteUrl . '&file=' . $mangledname);
         return $fileData;
     } else {
         $appl->enqueueMessage(JText::_('LIB_COMPOJOOM_ATTACHMENTS_ERR_NOFILE'));
         return false;
     }
 }
Esempio n. 2
0
/**
 * @package    Lib_Compojoom
 * @author     DanielDimitrov <*****@*****.**>
 * @date       10.02.2015
 *
 * @copyright  Copyright (C) 2008 - 2013 compojoom.com . All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE
 */
defined('_JEXEC') or die('Restricted access');
$user = JFactory::getUser();
// If the user doesn't have create permissions, then don't show anything
if (!$user->authorise('core.multimedia.create', $displayData['component'])) {
    return;
}
$imageSize = $displayData['imageSize'];
$mediaHelper = new CompojoomHelperMedia();
$canDelete = $user->authorise('core.multimedia.delete', $displayData['component']) || $user->authorise('core.multimedia.delete.own', $displayData['component']);
JHTML::stylesheet('media/lib_compojoom/third/font-awesome/css/font-awesome.min.css');
JHtml::stylesheet('media/lib_compojoom/css/jquery.fileupload.css');
JHtml::stylesheet('media/lib_compojoom/css/jquery.fileupload-ui.css');
CompojoomHtmlBehavior::jquery();
JHtml::script('media/lib_compojoom/js/jquery.ui.custom.js');
JHtml::script('media/lib_compojoom/js/tmpl.min.js');
JHtml::script('media/lib_compojoom/js/canvas-to-blob.min.js');
JHtml::script('media/lib_compojoom/js/load-image.all.min.js');
JHtml::script('media/lib_compojoom/js/jquery.iframe-transport.js');
JHtml::script('media/lib_compojoom/js/jquery.fileupload.js');
JHtml::script('media/lib_compojoom/js/jquery.fileupload-process.js');
JHtml::script('media/lib_compojoom/js/jquery.fileupload-image.js');
JHtml::script('media/lib_compojoom/js/jquery.fileupload-audio.js');
JHtml::script('media/lib_compojoom/js/jquery.fileupload-video.js');