Beispiel #1
0
 /**
  * Retrieves a list of items from a given uri
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public function getItems($uri, $includeVariations = false)
 {
     // List down posts from the site
     $model = EB::model('MediaManager');
     $posts = $model->getPosts();
     // Get path and folder
     $folder = $this->getFolderItem($uri);
     // Get the absolute path to the main "articles" folder
     $folderPath = EasyBlogMediaManager::getPath($folder->uri);
     if (!$posts) {
         return $folder;
     }
     // Filegroup is the array where files are stored.
     // Sort arrays are used to speed up file sorting.
     $filegroup = EasyBlogMediaManager::filegroup();
     // The strategy used here is to use a single loop that build:
     // - data that is ready-to-use
     // - sort arrays so sorting becomes cheap.
     // - variations
     $variations = array();
     $total = 0;
     foreach ($posts as $post) {
         // Get the folder path of the article
         $articlePath = $folderPath . '/' . $post->id;
         // Get the uri for the article
         $uri = 'post:' . $post->id;
         $items = parent::getItems($uri);
         $filegroup['folder'][] = $items;
         $total++;
     }
     // Set the folder contents
     $folder->contents = $filegroup;
     $folder->total = $total;
     return $folder;
 }
Beispiel #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.'));
     }
 }
Beispiel #3
0
 /**
  * Retrieves a list of items from a given uri
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public function getItems($uri, $includeVariations = false)
 {
     // Retrieve a list of authors from the site.
     $model = EB::model('Blogger');
     $result = $model->getBloggers();
     // Get path and folder
     $folder = $this->getFolderItem($uri);
     // Get the absolute path to the main "articles" folder
     $folderPath = EasyBlogMediaManager::getPath($folder->uri);
     if (!$result) {
         return $folder;
     }
     // Filegroup is the array where files are stored.
     // Sort arrays are used to speed up file sorting.
     $filegroup = EasyBlogMediaManager::filegroup();
     // The strategy used here is to use a single loop that build:
     // - data that is ready-to-use
     // - sort arrays so sorting becomes cheap.
     // - variations
     $variations = array();
     $total = 0;
     // Map them with the profile table
     $authors = array();
     if ($result) {
         foreach ($result as $row) {
             $author = EB::user($row->id);
             $authorPath = $folderPath . '/' . $row->id;
             $uri = 'user:'******'folder'][] = $items;
             $total++;
         }
     }
     // Set the folder contents
     $folder->contents = $filegroup;
     $folder->total = $total;
     return $folder;
 }
Beispiel #4
0
 /**
  * Remove all image variations from the site
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public function deleteVariations($uri)
 {
     // Accepts uri or item.
     if (is_string($uri)) {
         $item = $this->getItem($uri);
     } else {
         $item = $uri;
     }
     $errors = array();
     foreach ($item->variations as $key => $variation) {
         // Skip original variation
         if ($key == 'system/original') {
             continue;
         }
         // Get the variations path
         $file = EasyBlogMediaManager::getPath($variation->uri);
         if (!JFile::exists($file)) {
             $errors[] = $file;
             continue;
         }
         $state = JFile::delete($file);
         if (!$state) {
             $errors[] = $file;
         }
     }
     if (count($errors)) {
         // TODO: Language
         return EB::exception('Unable to remove the following image variations: ' . implode(', ', $errors) . '.');
     }
     return true;
 }