Exemple #1
0
 public function upload()
 {
     $app = JFactory::getApplication();
     $my = JFactory::getUser();
     $cfg = EasyBlogHelper::getConfig();
     $acl = EasyBlogACLHelper::getRuleSet();
     // @rule: Only allowed users are allowed to upload images.
     if ($my->id == 0 || empty($acl->rules->upload_image)) {
         $sessionid = JRequest::getVar('sessionid');
         if ($sessionid) {
             $session = JTable::getInstance('Session');
             $session->load($sessionid);
             if (!$session->userid) {
                 $this->output($this->getMessageObj(EBLOG_MEDIA_SECURITY_ERROR, JText::_('COM_EASYBLOG_NOT_ALLOWED')));
             }
             $my = JFactory::getUser($session->userid);
         } else {
             $this->output($this->getMessageObj(EBLOG_MEDIA_SECURITY_ERROR, JText::_('COM_EASYBLOG_NOT_ALLOWED')));
         }
     }
     // Let's get the path for the current request.
     $file = JRequest::getVar('file', '', 'FILES', 'array');
     $place = JRequest::getVar('place');
     // The user might be from a subfolder?
     $source = urldecode(JRequest::getVar('path', '/'));
     // @task: Let's find the exact path first as there could be 3 possibilities here.
     // 1. Shared folder
     // 2. User folder
     $absolutePath = EasyBlogMediaManager::getAbsolutePath($source, $place);
     $absoluteURI = EasyBlogMediaManager::getAbsoluteURI($source, $place);
     // @TODO: Test if user is allowed to upload this image
     $message = $this->getMessageObj();
     $allowed = EasyImageHelper::canUploadFile($file, $message);
     if ($allowed !== true) {
         return $this->output($message);
     }
     $media = new EasyBlogMediaManager();
     $result = $media->upload($absolutePath, $absoluteURI, $file, $source, $place);
     // This should be an error if the $result is not an MMIM object.
     if (!is_object($result)) {
         $message = $this->getMessageObj('404', $result);
     } else {
         $message = $this->getMessageObj(EBLOG_MEDIA_UPLOAD_SUCCESS, JText::_('COM_EASYBLOG_IMAGE_MANAGER_UPLOAD_SUCCESS'), $result);
     }
     return $this->output($message);
 }
Exemple #2
0
 public function post()
 {
     //old  code
     /*$controller = new EasyBlogControllerMedia;
     		$op = $controller->upload();
     		*/
     $input = JFactory::getApplication()->input;
     $log_user = $this->plugin->get('user')->id;
     $res = new stdClass();
     // Let's get the path for the current request.
     $file = JRequest::getVar('file', '', 'FILES', 'array');
     if ($file['name']) {
         $place = 'user:'******'user')->id;
         // The user might be from a subfolder?
         $source = urldecode('/' . $file['name']);
         // @task: Let's find the exact path first as there could be 3 possibilities here.
         // 1. Shared folder
         // 2. User folder
         //$absolutePath 		= EasyBlogMediaManager::getAbsolutePath( $source , $place );
         //$absoluteURI		= EasyBlogMediaManager::getAbsoluteURI( $source , $place );
         $absolutePath = EasyBlogMediaManager::getPath($source);
         $absoluteURI = EasyBlogMediaManager::getUrl($source);
         $allowed = EasyImageHelper::canUploadFile($file, $message);
         if ($allowed !== true) {
             $res->status = 0;
             $res->message = 'Upload is not allowed';
             return $res;
         }
         $media = new EasyBlogMediaManager();
         $upload_result = $media->upload($absolutePath, $absoluteURI, $file, $source, $place);
         //adjustment
         $upload_result->key = $place . $source;
         $upload_result->group = 'files';
         $upload_result->parentKey = $place . '|/';
         $upload_result->friendlyPath = 'My Media/' . $source;
         unset($upload_result->variations);
         $this->plugin->setResponse($upload_result);
         return $upload_result;
     } else {
         $this->plugin->setResponse($this->getErrorResponse(404, __FUNCTION__ . ' Upload unsuccessfull.'));
     }
 }
Exemple #3
0
 function newMediaObject($blogid, $username, $password, $file)
 {
     jimport('joomla.utilities.error');
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     global $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
     EasyBlogXMLRPCHelper::loginUser($username, $password);
     $user = JUser::getInstance($username);
     $acl = EasyBlogACLHelper::getRuleSet($user->id);
     if (empty($acl->rules->upload_image)) {
         return new xmlrpcresp(0, $xmlrpcerruser + 2, JText::_('YOU DO NOT HAVE IMAGE UPLOAD RIGHT'));
     }
     $config = EasyBlogHelper::getConfig();
     $main_image_path = $config->get('main_image_path');
     $main_image_path = rtrim($main_image_path, '/');
     $rel_upload_path = $main_image_path . '/' . $user->id;
     $userUploadPath = JPATH_ROOT . DIRECTORY_SEPARATOR . str_ireplace('/', DIRECTORY_SEPARATOR, $main_image_path . DIRECTORY_SEPARATOR . $user->id);
     $folder = JPath::clean($userUploadPath);
     $dir = $userUploadPath . DIRECTORY_SEPARATOR;
     $tmp_dir = JPATH_ROOT . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
     if (!JFolder::exists($dir)) {
         JFolder::create($dir);
     }
     if (strpos($file['name'], '/') !== FALSE) {
         $file['name'] = substr($file['name'], strrpos($file['name'], '/') + 1);
     } elseif (strpos($file['name'], '\\' !== FALSE)) {
         $file['name'] = substr($file['name'], strrpos($file['name'], '\\') + 1);
     }
     // Set FTP credentials, if given
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     $ftp = JClientHelper::getCredentials('ftp');
     $file['name'] = JFile::makesafe($file['name']);
     //$file['name']	= substr($file['name'], 0, -4) . rand() . '.' . JFile::getExt($file['name']);
     $file['name'] = substr($file['name'], 0, -4) . '.' . JFile::getExt($file['name']);
     // write to temp folder
     $file['tmp_name'] = $tmp_dir . $file['name'];
     @JFile::write($file['tmp_name'], $file['bits']);
     $file['size'] = 0;
     $error = '';
     $allowed = EasyImageHelper::canUploadFile($file);
     if ($allowed !== true) {
         @JFile::delete($file['tmp_name']);
         return new xmlrpcresp(0, $xmlrpcerruser + 1, 'The file is not valid');
     }
     // @JFile::write( $dir . $file['name'], $file['bits']);
     // @task: Ensure that images goes through the same resizing format when uploading via media manager.
     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'mediamanager.php';
     $media = new EasyBlogMediaManager();
     $result = $media->upload($dir, $userUploadPath, $file, '/', 'user');
     @JFile::delete($file['tmp_name']);
     $file['name'] = EasyBlogXMLRPCHelper::cleanImageName($file['name']);
     $fileUrl = rtrim(JURI::root(), '/') . '/' . $rel_upload_path . '/' . $file['name'];
     return new xmlrpcresp(new xmlrpcval(array('url' => new xmlrpcval($fileUrl)), 'struct'));
 }
Exemple #4
0
 /**
  * Handles photo uploads via the microblogging page.
  *
  * @access	public
  * @param	null
  **/
 public function uploadPhoto()
 {
     $my = JFactory::getUser();
     $config = EasyBlogHelper::getConfig();
     if (!$my->id) {
         return $this->outputJSON(array('type' => 'error', 'message' => JText::_('You need to be logged in first')));
     }
     $file = JRequest::getVar('photo-source', '', 'files', 'array');
     if (!isset($file['tmp_name'])) {
         return $this->outputJSON(array('type' => 'error', 'message' => JText::_('There is an error when uploading the image to the server. Perhaps the temporary folder <strong>upload_tmp_path</strong> was not configured correctly.')));
     }
     require_once EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'image.php';
     // @rule: Photos should be stored in the user's home folder by default.
     $imagePath = str_ireplace(array("/", "\\"), DIRECTORY_SEPARATOR, rtrim($config->get('main_image_path'), '/'));
     $userUploadPath = JPATH_ROOT . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $imagePath . DIRECTORY_SEPARATOR . $my->id);
     $storageFolder = JPath::clean($userUploadPath);
     // @rule: Get the image URI
     $imageURI = rtrim(str_ireplace('\\', '/', $config->get('main_image_path')), '/') . '/' . $my->id;
     $imageURI = rtrim(JURI::root(), '/') . '/' . $imageURI;
     // Set FTP credentials, if given
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     // Make the filename safe
     jimport('joomla.filesystem.file');
     $file['name'] = JFile::makeSafe($file['name']);
     // After making the filename safe, and the first character begins with . , we need to rename this file. Perhaps it's a unicode character
     $file['name'] = trim($file['name']);
     $filename = strtolower($file['name']);
     if (strpos($filename, '.') === false) {
         $filename = EB::date()->toFormat("%Y%m%d-%H%M%S") . '.' . $filename;
     } else {
         if (strpos($filename, '.') == 0) {
             $filename = EB::date()->toFormat("%Y%m%d-%H%M%S") . $filename;
         }
     }
     // remove the spacing in the filename.
     $filename = str_ireplace(' ', '-', $filename);
     $storagePath = JPath::clean($storageFolder . DIRECTORY_SEPARATOR . $filename);
     // 		// @task: try to rename the file if another image with the same name exists
     // 		if( JFile::exists( $storagePath ) )
     // 		{
     // 			$i	= 1;
     // 			while( JFile::exists( $storagePath ) )
     // 			{
     // 				$tmpName	= $i . '_' . EB::date()->toFormat( "%Y%m%d-%H%M%S" ) . '_' . $filename;
     // 				$storagePath	= JPath::clean( $storageFolder . DIRECTORY_SEPARATOR . $tmpName );
     // 				$i++;
     // 			}
     // 			$filename	= $tmpName;
     // 		}
     $allowed = EasyImageHelper::canUploadFile($file);
     if ($allowed !== true) {
         return $this->outputJSON(array('type' => 'error', 'message' => $allowed));
     }
     // @rule: Pass to EasyBlogImageHelper to upload the image
     // $result		= EasyImageHelper::upload( $storageFolder , $filename , $file , $imageURI , $storagePath );
     // 		// @task: Ensure that images goes through the same resizing format when uploading via media manager.
     $result = new stdClass();
     $result->message = JText::_('COM_EASYBLOG_IMAGE_MANAGER_UPLOAD_ERROR');
     $result->item = '';
     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'mediamanager.php';
     $media = new EasyBlogMediaManager();
     $uploaded = $media->upload($file, 'user:'******'COM_EASYBLOG_IMAGE_MANAGER_UPLOAD_SUCCESS');
         $result->item = $uploaded;
     } else {
         // failed.
         $result->item->url = '';
     }
     return $this->outputJSON(array('type' => 'success', 'message' => $result->message, 'uri' => $result->item->url));
 }