/** * Handles uploads from media manager. * * @since 4.0 * @access public * @param string * @return */ public function upload() { // Ensure that the user is logged in EB::requireLogin(); // Only allowed users who are allowed to upload images if (!$this->acl->get('upload_image')) { $this->output(EB::exception('COM_EASYBLOG_NOT_ALLOWED', EASYBLOG_MSG_ERROR)); } // Load up media manager $mm = EB::mediamanager(); // Get uri $key = $this->input->getRaw('key'); // Get the target folder $placeId = EBMM::getUri($key); // Get the file input $file = $this->input->files->get('file'); // Check if the file is really allowed to be uploaded to the site. $state = EB::image()->canUploadFile($file); if ($state instanceof Exception) { return $this->output($state); } // MM should check if the user really has access to upload to the target folder $allowed = EBMM::hasAccess($placeId); if ($allowed instanceof Exception) { return $this->output($allowed); } // Check the image name is it got contain space, if yes need to replace to '-' $fileName = $file['name']; $file['name'] = str_replace(' ', '-', $fileName); // Upload the file now $file = $mm->upload($file, $placeId); // Response object is intended to also include // other properties like status message and status code. // Right now it only inclues the media item. $response = new stdClass(); $response->media = EBMM::getMedia($file->uri); return $this->output($response); }
/** * Moves a file or folder from destination to target * * @since 5.0 * @access public * @param string * @return */ public function move($source, $target) { $sourceUri = EBMM::getUri($source); $targetUri = EBMM::getUri($target); // Get the absolute paths $sourcePath = EBMM::getPath($sourceUri); $targetPath = EBMM::getPath($targetUri); // Get the new filename $newFileName = basename($sourcePath); // Get the absolute path to the target file / folder $newTargetPath = $targetPath . '/' . $newFileName; $newTargetUri = $targetUri . '/' . $newFileName; // Get the item details $item = $this->getItem($sourceUri); // Test if the source items really exists if ($item->type == 'folder' && !JFolder::exists($sourcePath)) { return EB::exception('Unable to locate source folder to move.'); } // Test if the source items really exists if ($item->type != 'folder' && !JFile::exists($sourcePath)) { return EB::exception('Unable to locate source file to move.'); } // Test for target path if ($item->type == 'folder' && JFolder::exists($newTargetPath)) { return EB::exception('A folder with the same name exists on the specified target path.'); } if ($item->type != 'folder' && JFile::exists($newTargetPath)) { return EB::exception('A file with the same name exists on the specified target path.'); } // If this is a folder, just move the folder if ($item->type == 'folder') { $state = JFolder::move($sourcePath, $newTargetPath); if (!$state) { return EB::exception('Unable to move folder.'); } } // Move the file if ($item->type != 'folder') { JFile::move($sourcePath, $newTargetPath); // Move variations if ($item->type == 'image') { // For images, we want to rename the variations as well. if ($item->type == 'image' && isset($item->variations)) { foreach ($item->variations as $key => $variation) { if ($key == 'system/original') { continue; } // Get the new uri $newUri = $targetUri . '/' . EBLOG_SYSTEM_VARIATION_PREFIX . '_' . $variation->name . '_' . $newFileName; $target = EasyBlogMediaManager::getPath($newUri); // Get the original file for the variation $source = EasyBlogMediaManager::getPath($variation->uri); // Check if the file exists first if (!JFile::exists($source)) { continue; } // Try to move the file now $state = JFile::move($source, $target); } } } } // Get the new item info about the moved object $item = $this->getItem($newTargetUri); return $item; }
public function uploadImage($key) { // Load up media manager $mm = EB::mediamanager(); // Get the target folder $placeId = EBMM::getUri($key); // Get the file input $file = JRequest::getVar('file', '', 'FILES', 'array'); // Check if the file is really allowed to be uploaded to the site. $state = EB::image()->canUploadFile($file); if ($state instanceof Exception) { //add error code return $state; //return $this->output($state); } // MM should check if the user really has access to upload to the target folder $allowed = EBMM::hasAccess($placeId); if ($allowed instanceof Exception) { //add error code return $state; //return $this->output($allowed); } // Check the image name is it got contain space, if yes need to replace to '-' $fileName = $file['name']; $file['name'] = str_replace(' ', '-', $fileName); // Upload the file now $file = $mm->upload($file, $placeId); // Response object is intended to also include // other properties like status message and status code. // Right now it only inclues the media item. $response = new stdClass(); $response->media = EBMM::getMedia($file->uri); //code for future use //header('Content-type: text/x-json; UTF-8'); //$resp = json_encode($response, JSON_HEX_TAG); return $response; }
/** * Creates a new variation on the site * * @since 5.0 * @access public * @param string * @return */ public function createVariation() { $name = $this->input->getCmd('name'); $key = $this->input->getRaw('key'); // Convert the key into uri $uri = EBMM::getUri($key); // Get the width and height $width = $this->input->get('width'); $height = $this->input->get('height'); $params = new stdClass(); $params->width = $width; $params->height = $height; $media = EB::mediamanager(); $item = $media->createVariation($uri, $name, $params); if ($item instanceof EasyBlogException) { return $this->ajax->reject($state); } // Response object is intended to also include // other properties like status message and status code. // Right now it only inclues the media item. $info = EBMM::getMedia($uri); return $this->ajax->resolve($info); }