Guest User

Piwigo get_fs_directories

a guest
Feb 1st, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. /**
  2.  * Returns an array containing sub-directories which are potentially
  3.  * a category.
  4.  * Directories named ".svn", "thumbnail", "pwg_high" or "pwg_representative"
  5.  * are omitted.
  6.  * Directories are sorted by mtime.
  7.  *
  8.  * @param string $basedir (eg: ./galleries)
  9.  * @return string[]
  10.  */
  11. function get_fs_directories($path, $recursive = true)
  12. {
  13.   global $conf;
  14.  
  15.   $lsdir = array();
  16.   $dirs = array();
  17.   $path = rtrim($path, '/');
  18.  
  19.   $exclude_folders = array_merge(
  20.     $conf['sync_exclude_folders'],
  21.     array(
  22.       '.', '..', '.svn',
  23.       'thumbnail', 'pwg_high',
  24.       'pwg_representative',
  25.       )
  26.     );
  27.   $exclude_folders = array_flip($exclude_folders);
  28.  
  29.   if (is_dir($path))
  30.   {
  31.     $lsdir = glob("$path/{,.}*", GLOB_ONLYDIR | GLOB_BRACE);
  32.     usort($lsdir, function($a, $b) {
  33.       return filemtime($a) > filemtime($b);
  34.     });
  35.     foreach ($lsdir as $i => $node)
  36.     {
  37.       if (!isset($exclude_folders[preg_replace("/.*\//", '', $node)]))
  38.       {
  39.         $dirs[] = $node;
  40.         if ($recursive)
  41.         {
  42.           $dirs = array_merge($dirs, get_fs_directories($node));
  43.         }
  44.       }
  45.     }
  46.   }
  47.   return $dirs;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment