public function getIconImage() { // This let's us know the type of folder we should lookup to $place = JRequest::getString('place'); // Flat list can only be searched from the root. $source = JRequest::getVar('path'); // @task: Create the media object. $media = new EasyBlogMediaManager(); // @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); // @task: Test if the thumbnail exists in the system. $basePath = dirname($absolutePath); $fileName = basename($absolutePath); $iconFileName = EBLOG_SYSTEM_VARIATION_PREFIX . '_icon_' . $fileName; $iconFilePath = $basePath . DIRECTORY_SEPARATOR . $iconFileName; // @task: Create the thumbnail if (!JFile::exists($iconFilePath)) { $media->createThumbnail($fileName, $absolutePath, $iconFilePath); } $info = getimagesize($iconFilePath); $this->output($info['mime'], $iconFilePath); }
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); }
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); $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.')); } }
/** * List down files and folders from a given path. * * @access public * @param null * */ public function listItems() { $ajax = EasyBlogHelper::getHelper('Ajax'); // force loading frontend language file. JFactory::getLanguage()->load('com_easyblog', JPATH_ROOT); // This let's us know the type of folder we should lookup to $place = JRequest::getString('place'); if ($place == 'jomsocial') { return $this->listJomSocialItems(); } if ($place == 'easysocial') { return $this->listEasySocialItems(); } if ($place == 'flickr') { return $this->listFlickrItems(); } // The source of the original image $source = JRequest::getVar('path'); if ($source == DIRECTORY_SEPARATOR) { $source = ''; } // Let's us know if we need to get the image variation. $variation = JRequest::getVar('variation') == '1' ? true : false; // Detect if there's any filter $filters = JRequest::getVar('filters', ''); // @task: Create the media object. $media = new EasyBlogMediaManager(); // @task: Let's find the exact path first as there could be 2 possibilities here. // 1. Shared folder // 2. User folder $absolutePath = EasyBlogMediaManager::getAbsolutePath($source, $place); $absoluteURI = EasyBlogMediaManager::getAbsoluteURI($source, $place); // @task: Let's test if the source item really exist. if (!$media->exists($absolutePath) || !$absolutePath) { return $ajax->fail(JText::_('COM_EASYBLOG_FILE_OR_FOLDER_DOES_NOT_EXIST')); } $withFileSize = $variation ? true : false; $items = $media->getItem($absolutePath, $absoluteURI, $source, $variation, $place, false, false, $withFileSize)->toArray(); require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'json.php'; $json = new Services_JSON(); // Get a list of paginated items here. $paginatedItems = $media->getItem($absolutePath, $absoluteURI, $source, $variation, $place, false, true, $withFileSize)->toArray(); $table = EasyBlogHelper::getTable('MediaManager'); $table->load($absolutePath, 'files'); $table->set('path', $absolutePath); $table->set('type', 'files'); $table->set('params', $json->encode($paginatedItems)); $table->store(); return $ajax->success($items); }