/** * An augmented scandir() which will ensure any Aliases are included in the relevant * directory scans; this makes the Aliases behave very similarly to actual directories. */ public function scandir($dir, $filemask, $see_thumbnail_dir, $glob_flags_or, $glob_flags_and) { $dir = self::enforceTrailingSlash($dir); // collect the real items first: $coll = parent::scandir($dir, $filemask, $see_thumbnail_dir, $glob_flags_or, $glob_flags_and); FM_vardumper($this, 'scandir4Alias', $coll); if ($coll === false) { return $coll; } $flags = GLOB_NODOTS | GLOB_NOHIDDEN | GLOB_NOSORT; $flags &= $glob_flags_and; $flags |= $glob_flags_or; // make sure we keep the guarantee that the '..' entry, when present, is the very last one, intact: $doubledot = array_pop($coll['dirs']); if ($doubledot !== null && $doubledot !== '..') { $coll['dirs'][] = $doubledot; $doubledot = null; } // we must check against thumbnail path again, as it MAY be an alias, itself! $tndir = null; if (!$see_thumbnail_dir) { $tn_uri = $this->options['thumbnailPath']; $tnpath = $this->url_path2file_path($tn_uri); //if (FileManagerUtility::startswith($dir, $tnpath)) // return false; $tnparent = self::getParentDir($tnpath); $just_below_thumbnail_dir = FileManagerUtility::startswith($dir, $tnparent); if ($just_below_thumbnail_dir) { $tndir = basename(substr($tn_uri, 0, -1)); } } // now see if we need to add any aliases as elements: if (isset($this->scandir_alias_lu_arr) && !empty($this->scandir_alias_lu_arr[$dir])) { $a_base = $this->scandir_alias_lu_arr[$dir]; $d = $coll['dirs']; $f = $coll['files']; foreach ($a_base[false] as $a_elem) { if (!in_array($a_elem, $d, true) && $tndir !== $a_elem && (!($flags & GLOB_NOHIDDEN) || $a_elem[0] != '.')) { //$coll['special_indir_mappings'][1][] = array_push($coll['dirs'], $a_elem) - 1; $coll['dirs'][] = $a_elem; } } foreach ($a_base[true] as $a_elem) { if (!in_array($a_elem, $f, true) && (!($flags & GLOB_NOHIDDEN) || $a_elem[0] != '.')) { //$coll['special_indir_mappings'][0][] = array_push($coll['files'], $a_elem) - 1; $coll['files'][] = $a_elem; } } } // make sure we keep the guarantee that the '..' entry, when present, is the very last one, intact: if ($doubledot !== null) { $coll['dirs'][] = $doubledot; } return $coll; }
public function scandir($dir, $filemask = '*', $see_thumbnail_dir = false) { $dir = self::enforceTrailingSlash($dir); // collect the real items first: $coll = parent::scandir($dir, $filemask, $see_thumbnail_dir); if ($coll === false) { return $coll; } // make sure we keep the guarantee that the '..' entry, when present, is the very last one, intact: $doubledot = array_pop($coll); if ($doubledot !== null && $doubledot !== '..') { $coll[] = $doubledot; $doubledot = null; } // we must check against thumbnail path again, as it MAY be an alias, itself! $tndir = null; if (!$see_thumbnail_dir) { $tn_uri = $this->options['thumbnailPath']; $tnpath = $this->url_path2file_path($tn_uri); //if (FileManagerUtility::startswith($dir, $tnpath)) // return false; $tnparent = self::getParentDir($tnpath); $just_below_thumbnail_dir = FileManagerUtility::startswith($dir, $tnparent); if ($just_below_thumbnail_dir) { $tndir = basename(substr($tn_uri, 0, -1)); } } // now see if we need to add any aliases as elements: if (isset($this->scandir_alias_lu_arr) && !empty($this->scandir_alias_lu_arr[$dir])) { foreach ($this->scandir_alias_lu_arr[$dir] as $a_elem) { if (!in_array($a_elem, $coll, true) && $tndir !== $a_elem) { $coll[] = $a_elem; } } } // make sure we keep the guarantee that the '..' entry, when present, is the very last one, intact: if ($doubledot !== null) { $coll[] = $doubledot; } return $coll; }
/** * glob() wrapper: accepts the same options as Tooling.php::safe_glob() * * However, this method will also ensure the '..' directory entry is only returned, * even while asked for, when the parent directory can be legally traversed by the FileManager. * * Return a dual array (possibly empty) of directories and files, or FALSE on error. * * IMPORTANT: this function GUARANTEES that, when present at all, the double-dot '..' * entry is the very last entry in the array. * This guarantee is important as onView() et al depend on it. */ public function scandir($dir, $filemask, $see_thumbnail_dir, $glob_flags_or, $glob_flags_and) { // list files, except the thumbnail folder itself or any file in it: $dir = self::enforceTrailingSlash($dir); $just_below_thumbnail_dir = false; if (!$see_thumbnail_dir) { $tnpath = $this->thumbnailCacheDir; if (FileManagerUtility::startswith($dir, $tnpath)) { return false; } $tnparent = $this->thumbnailCacheParentDir; $just_below_thumbnail_dir = $dir == $tnparent; $tndir = basename(substr($this->options['URLpath4thumbnails'], 0, -1)); } $at_basedir = $this->managedBaseDir == $dir; $flags = GLOB_NODOTS | GLOB_NOHIDDEN | GLOB_NOSORT; $flags &= $glob_flags_and; $flags |= $glob_flags_or; $coll = safe_glob($dir . $filemask, $flags); if ($coll !== false) { if ($just_below_thumbnail_dir) { foreach ($coll['dirs'] as $k => $dir) { if ($dir === $tndir) { unset($coll['dirs'][$k]); break; } } } if (!$at_basedir) { $coll['dirs'][] = '..'; } } return $coll; }
/** * glob() wrapper: accepts the same options as Tooling.php::safe_glob() * * However, this method will also ensure the '..' directory entry is only returned, * even while asked for, when the parent directory can be legally traversed by the FileManager. * * Always return an array (possibly empty) * * IMPORTANT: this function GUARANTEES that, when present at all, the double-dot '..' * entry is the very last entry in the array. * This guarantee is important as onView() et al depend on it. */ protected function scandir($dir, $filemask = '*', $see_thumbnail_dir = false) { // list files, except the thumbnail folder itself or any file in it: $dir = self::enforceTrailingSlash($dir); $just_below_thumbnail_dir = false; if (!$see_thumbnail_dir) { $tnpath = $this->url_path2file_path($this->options['thumbnailPath']); if (FileManagerUtility::startswith($dir, $tnpath)) { return false; } $tnparent = $this->url_path2file_path(self::getParentDir($this->options['thumbnailPath'])); $just_below_thumbnail_dir = $dir == $tnparent; $tndir = basename(substr($this->options['thumbnailPath'], 0, -1)); } $at_basedir = $this->url_path2file_path($this->options['directory']) == $dir; $files = safe_glob($dir . $filemask, GLOB_NODOTS | GLOB_NOSORT); if ($just_below_thumbnail_dir) { $f = array(); foreach ($files as $file) { if ($file !== $tndir) { $f[] = $file; } } unset($files); $files = $f; } if (!$at_basedir) { $files[] = '..'; } return $files; }