예제 #1
0
 /**
  * logic for uploading an image
  *
  * @access public
  * @return void
  * @since 0.9
  */
 function uploadimage()
 {
     $mainframe =& JFactory::getApplication();
     // Check for request forgeries
     JRequest::checkToken() or die('Invalid Token');
     $elsettings = JComponentHelper::getParams('com_redevent');
     $file = JRequest::getVar('userfile', '', 'files', 'array');
     $task = JRequest::getVar('task');
     // Set FTP credentials, if given
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     //$ftp = JClientHelper::getCredentials('ftp');
     //set the target directory
     switch ($task) {
         case 'venueimgup':
             $base_Dir = JPATH_SITE . DS . 'images' . DS . 'redevent' . DS . 'venues' . DS;
             break;
         case 'eventimgup':
             $base_Dir = JPATH_SITE . DS . 'images' . DS . 'redevent' . DS . 'events' . DS;
             break;
         case 'categoryimgup':
             $base_Dir = JPATH_SITE . DS . 'images' . DS . 'redevent' . DS . 'categories' . DS;
             break;
     }
     //do we have an upload?
     if (empty($file['name'])) {
         echo "<script> alert('" . JText::_('COM_REDEVENT_IMAGE_EMPTY') . "'); window.history.go(-1); </script>\n";
         $mainframe->close();
     }
     //check the image
     $check = redEVENTImage::check($file, $elsettings);
     if ($check === false) {
         $mainframe->redirect($_SERVER['HTTP_REFERER']);
     }
     //sanitize the image filename
     $filename = redEVENTImage::sanitize($base_Dir, $file['name']);
     $filepath = $base_Dir . $filename;
     //upload the image
     if (!JFile::upload($file['tmp_name'], $filepath)) {
         echo "<script> alert('" . JText::_('COM_REDEVENT_UPLOAD_FAILED') . "'); window.history.go(-1); </script>\n";
         $mainframe->close();
     } else {
         // create thumbnail
         redEVENTImage::thumb($filepath, dirname($filepath) . DS . 'small' . DS . $filename, $elsettings->get('imagewidth'), $elsettings->get('imageheight', 100));
         echo "<script> alert('" . JText::_('COM_REDEVENT_UPLOAD_COMPLETE') . "'); window.history.go(-1); window.parent.elSelectImage('{$filename}', '{$filename}'); </script>\n";
         $mainframe->close();
     }
 }
예제 #2
0
 /**
  * return full url to thumbnail
  *
  * @param string image path, relative to joomla images folder
  * @return url or false if it doesn't exists
  */
 public static function getThumbUrl($path, $maxdim = null)
 {
     jimport('joomla.filesystem.file');
     $app =& JFactory::getApplication();
     $settings = redEVENTHelper::config();
     if ($maxdim) {
         $width = $maxdim;
         $height = $maxdim;
     } else {
         $width = $settings->get('imagewidth', 100);
         $height = $settings->get('imageheight', 100);
     }
     $base = JURI::root();
     $thumb_name = md5(basename($path)) . $width . '_' . $height . '.png';
     if (dirname($path) != '.') {
         $thumb_path = JPATH_SITE . DS . dirname($path) . DS . 're_thumb' . DS . $thumb_name;
         $thumb_uri = $base . str_replace("\"", "/", dirname($path)) . '/re_thumb/' . $thumb_name;
     } else {
         JError::raisewarning(0, JText::sprintf('COM_REDEVENT_THUMBNAILS_WRONG_BASE_PATH', dirname($thumb_path)));
     }
     if (JFile::exists($thumb_path)) {
         return $thumb_uri;
     } else {
         if (JFile::exists(JPATH_SITE . DS . $path)) {
             //try to generate the thumb
             if (!JFolder::exists(dirname($thumb_path)) && !JFolder::create(dirname($thumb_path))) {
                 RedeventHelperLog::simpleLog(sprintf('Can\'t create path for thumbnail: %s', dirname($thumb_path)));
                 return false;
             }
             if (redEVENTImage::thumb(JPATH_SITE . DS . $path, $thumb_path, $width, $height)) {
                 return $thumb_uri;
             }
         }
     }
     return false;
 }