Exemple #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)
 {
     // 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;
 }
Exemple #2
0
        </div>
    </div>

    <div class="eb-composer-viewport push-bottom" data-scrolly="y">
        <div class="eb-composer-viewport-content" data-scrolly-viewport>

            <div class="eb-mm-folder-content-panel">

                <div class="eb-mm-filegroup type-folder" data-eb-mm-filegroup>
                    <div class="eb-mm-filegroup-body">
                        <div class="eb-mm-filelist view-list">
                            <?php 
foreach ($authors as $author) {
    ?>
                            <div data-type="user" data-key="<?php 
    echo EasyBlogMediaManager::getKey('user:' . $author->id);
    ?>
" data-eb-mm-file="" class="eb-mm-file type-folder is-search-result">
                                <img src="<?php 
    echo $author->getAvatar();
    ?>
" width="16" />&nbsp;
                                <span data-eb-mm-file-title><?php 
    echo $author->getName();
    ?>
</span>
                                <b class="fa fa-angle-right"></b>
                            </div>
                            <?php 
}
?>
Exemple #3
0
        </div>
    </div>

    <div class="eb-composer-viewport" data-scrolly="y">
        <div class="eb-composer-viewport-content" data-scrolly-viewport>

            <div class="eb-mm-folder-content-panel">
                <div class="eb-mm-filegroup type-folder" data-eb-mm-filegroup>
                    <div class="eb-mm-filegroup-body">
                        <div class="eb-mm-filelist view-list">
                            <?php 
foreach ($posts as $post) {
    ?>
                            <div data-key="<?php 
    echo EasyBlogMediaManager::getKey('post:' . $post->id);
    ?>
" data-eb-mm-file="" class="eb-mm-file type-folder">
                                <i class="fa fa-file"></i>
                                <span>
                                    <?php 
    if ($post->title) {
        ?>
                                        <?php 
        echo $post->title;
        ?>
                                    <?php 
    } else {
        ?>
                                        <?php 
        echo JText::sprintf('COM_EASYBLOG_MM_PLACE_POST_UNTITLED', $post->id);