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.')); } }
public function getVariations($uri) { // Build variations $variations = array(); // Url & paths $baseUri = dirname($uri); $filename = basename($uri); $filepath = EasyBlogMediaManager::getPath($uri); $fileurl = EasyBlogMediaManager::getUrl($uri); $folderpath = dirname($filepath); $folderurl = dirname($fileurl); // Original variation $variation = new stdClass(); $variation->key = 'system/original'; $variation->name = 'original'; $variation->type = 'system'; $variation->url = $fileurl; $variation->uri = $baseUri . '/' . basename($filename); // Get original variation width & height $info = @getimagesize($filepath); if ($info) { $variation->width = $info[0]; $variation->height = $info[1]; } $variation->size = @filesize($filepath); $variations['system/original'] = $variation; // Scan for variations $handle = @opendir($folderpath); if ($handle) { // Regex to match variations related to this file $filter = $this->rx_variations($filename); while (($filename = readdir($handle)) !== false) { if (!preg_match($filter, $filename, $parts)) { continue; } // 2.0 thumbnails if (count($parts) == 6) { $source = $parts[5]; $type = 'system'; $name = 'thumb'; // 3.5 thumbnails } else { $source = $parts[3]; $type = $this->variationTypes[$parts[1]]; $name = $parts[2]; } // Variables $key = $type . '/' . $name; $url = $folderurl . '/' . $filename; $path = $folderpath . '/' . $filename; // Create variation $variation = new stdClass(); $variation->key = $key; $variation->name = $name; $variation->type = $type; $variation->url = $url; $variation->uri = $baseUri . '/' . basename($filename); // Get variation width & height $info = @getimagesize($path); if ($info) { $variation->width = $info[0]; $variation->height = $info[1]; } $variation->size = @filesize($path); // Add to variations $variations[$key] = $variation; } } return $variations; }