Exemplo n.º 1
0
 /**
  * Recursive directory scanning
  *
  * Returns an array of a given directory's content. The array contains
  * two arrays: dirs and files. Directory's content is fetched recursively.
  *
  * @param string		$dirName		Directory name
  * @param array		$contents		Contents array. Leave it empty
  * @return array
  */
 public static function getDirList($dirName, &$contents = null)
 {
     if (!$contents) {
         $contents = array('dirs' => array(), 'files' => array());
     }
     $exclude_list = array('.', '..', '.svn');
     if (empty($res)) {
         $res = array();
     }
     $dirName = preg_replace('|/$|', '', $dirName);
     if (!is_dir($dirName)) {
         throw new Exception(sprintf(__('%s is not a directory.'), $dirName));
     }
     $contents['dirs'][] = $dirName;
     $d = @dir($dirName);
     if ($d === false) {
         throw new Exception(__('Unable to open directory.'));
     }
     while ($entry = $d->read()) {
         if (!in_array($entry, $exclude_list)) {
             if (is_dir($dirName . '/' . $entry)) {
                 files::getDirList($dirName . '/' . $entry, $contents);
             } else {
                 $contents['files'][] = $dirName . '/' . $entry;
             }
         }
     }
     $d->close();
     return $contents;
 }
Exemplo n.º 2
0
 protected function removeAssetsFiles($sAssetsDir, $aLockedFiles = array())
 {
     $aFiles = files::getDirList($sAssetsDir);
     foreach ($aFiles['files'] as $sFiles) {
         if (!in_array($sFiles, $aLockedFiles)) {
             unlink($sFiles);
         }
     }
     foreach (array_reverse($aFiles['dirs']) as $sDir) {
         if (!util::dirHasFiles($sDir)) {
             files::deltree($sDir);
         }
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * Root directories
  *
  * Returns an array of directory under {@link $root} directory.
  *
  * @uses fileItem
  * @return array
  */
 public function getRootDirs()
 {
     $d = files::getDirList($this->root);
     $dir = array();
     foreach ($d['dirs'] as $v) {
         $dir[] = new fileItem($v, $this->root, $this->root_url);
     }
     return $dir;
 }
Exemplo n.º 4
0
 function makePackage($name, $dir, $remove_path = '', $gzip = true)
 {
     if ($gzip && !function_exists('gzcompress')) {
         return false;
     }
     if (($filelist = files::getDirList($dir)) === false) {
         return false;
     }
     $res = array('name' => $name, 'dirs' => array(), 'files' => array());
     foreach ($filelist['dirs'] as $v) {
         $res['dirs'][] = preg_replace('/^' . preg_quote($remove_path, '/') . '/', '', $v);
     }
     foreach ($filelist['files'] as $v) {
         $f_content = base64_encode(file_get_contents($v));
         $v = preg_replace('/^' . preg_quote($remove_path, '/') . '/', '', $v);
         $res['files'][$v] = $f_content;
     }
     $res = serialize($res);
     if ($gzip) {
         $res = gzencode($res);
     }
     return $res;
 }