Exemplo n.º 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;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 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)
 {
     // Get path and folder
     $folder = $this->getFolderItem($uri);
     $folderpath = EasyBlogMediaManager::getPath($uri);
     // Read the source directory
     $handle = @opendir($folderpath);
     if (!$handle) {
         // Perhaps the folder doesn't exist yet, we should try to create the folder.
         // $state = JFolder::create($folderpath);
         // if (!$state) {
         return $folder;
         // }
         // Read the folder
         // $handle = @opendir($folderpath);
     }
     // Scan
     // ~149ms on 700 files (first-time)
     // ~48ms on 700 files (subsequent)
     $start = microtime(true);
     // Filegroup is the array where files are stored.
     // Sort arrays are used to speed up file sorting.
     $filegroup = EasyBlogMediaManager::filegroup();
     $sort_by_modified = EasyBlogMediaManager::filegroup();
     $sort_by_title = 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;
     while (($filename = readdir($handle)) !== false) {
         // Exclude files
         if (preg_match($this->rx_exclude, $filename)) {
             continue;
         }
         // Collect variations
         // ~8ms on 700 files
         if (preg_match($this->rx_variations, $filename, $parts)) {
             if (!$includeVariations) {
                 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];
             }
             $key = $type . '/' . $name;
             $variation = new stdClass();
             $variation->name = $name;
             $variation->url = $folder->url . '/' . $filename;
             $variation->filename = $filename;
             if (!isset($variations[$source])) {
                 $variations[$source] = array();
             }
             $variations[$source][$key] = $variation;
             continue;
         }
         $item = new stdClass();
         $item->title = $filename;
         // getTitle is not needed
         $item->place = $folder->place;
         $item->uri = $folder->uri . '/' . $filename;
         $item->url = $folder->url . '/' . $filename;
         $item->key = EasyBlogMediaManager::getKey($item->uri);
         // Folder
         $filepath = $folderpath . '/' . $filename;
         if (is_dir($filepath)) {
             $item->type = 'folder';
             $item->icon = EasyBlogMediaManager::$icons['folder'];
             $item->modified = null;
             // File
         } else {
             $extension = EasyBlogMediaManager::getExtension($filename);
             $item->extension = $extension;
             $item->type = EasyBlogMediaManager::getType($extension);
             $item->icon = EasyBlogMediaManager::getIcon($extension);
             $item->modified = @filemtime($filepath);
         }
         // Get item type
         $type = $item->type;
         // Add thumbnail & preview
         if ($type == 'image') {
             $item->thumbnail = $folder->url . '/' . EBLOG_SYSTEM_VARIATION_PREFIX . '_icon_' . $filename;
             $item->preview = $folder->url . '/' . EBLOG_SYSTEM_VARIATION_PREFIX . '_thumbnail_' . $filename;
         }
         // Add to filegroup
         $filegroup[$type][] = $item;
         // Add to sort arrays
         $sort_by_title[$type][] = $item->title;
         $sort_by_modified[$type][] = $item->modified;
         $total++;
     }
     // Sort folders
     // Folder doesn't need to be sorted by modification time.
     array_multisort($sort_by_title['folder'], SORT_ASC, $filegroup['folder']);
     // Sort files
     // ~0.6ms on 700 files
     foreach (array('image', 'audio', 'video', 'file') as $type) {
         array_multisort($sort_by_modified[$type], SORT_DESC, $sort_by_title[$type], SORT_ASC, $filegroup[$type]);
     }
     // Add variations & thumbnail property
     // ~6ms on 700 files
     if ($includeVariations) {
         foreach ($filegroup['image'] as $item) {
             $sizes = isset($variations[$item->title]) ? $variations[$item->title] : array();
             // Original variation
             $variation = new stdClass();
             $variation->name = 'original';
             $variation->type = 'system';
             $variation->url = $item->url;
             $sizes['system/original'] = $variation;
             $item->variations = $sizes;
         }
     }
     $folder->contents = $filegroup;
     $folder->total = $total;
     $end = microtime(true);
     $scantime = ($end - $start) * 1000;
     $folder->scantime = $scantime;
     return $folder;
 }