108 $this->mode = intval(
$mode, 8);
142 return $this->path =
$path;
160 $dir = opendir($this->path);
161 if (
$dir !==
false) {
162 while (
false !== ($n = readdir(
$dir))) {
164 if (is_array($exceptions)) {
165 if (!in_array($n, $exceptions)) {
169 if ((!preg_match(
'/^\\.+$/', $n) && $exceptions ==
false)
170 || ($exceptions ==
true && !preg_match(
'/^\\.(.*)$/', $n))
175 if ($item !==
false) {
183 if (
$sort || $this->sort) {
203 public function find($regexp_pattern =
'.*',
$sort =
false)
206 if (!is_array($data)) {
209 list ($dirs,
$files) = $data;
212 if (preg_match(
"/^{$regexp_pattern}$/i", $file)) {
232 $this->
cd($startsOn);
250 if (preg_match(
"/^{$pattern}$/i", $file)) {
255 foreach ($dirs as
$dir) {
257 $found = array_merge($found, $this->
findRecursive($pattern));
273 if (preg_match(
'/^[A-Z]:\\\\/i',
$path)) {
290 $match = preg_match(
'/^(\/|[A-Z]:)/',
$path);
291 return ($match == 1);
305 if (self::isWindowsPath(
$path)) {
322 if (self::isWindowsPath(
$path)) {
339 if (self::isSlashTerm(
$path)) {
357 return self::slashTerm(
$path) . $element;
373 return $this->
inPath($newdir);
389 $return = preg_match(
'/^(.*)' . preg_quote(
$dir,
'/') .
'(.*)/',
$current);
391 $return = preg_match(
'/^(.*)' . preg_quote(
$current,
'/') .
'(.*)/',
$dir);
393 return ($return == 1);
412 if ($recursive ===
false && is_dir(
$path)) {
423 foreach ($paths as $fullpath) {
424 $check = explode(
'/', $fullpath);
427 if (in_array($check[
$count - 1], $exceptions)) {
432 $this->
messages[] = sprintf(
'%s changed to %s', $fullpath,
$mode);
434 $this->
errors[] = sprintf(
'%s NOT changed to %s', $fullpath,
$mode);
437 if (empty($this->
errors)) {
457 $this->files = array();
458 $this->directories = array(
462 while (count($this->directories)) {
463 $dir = array_pop($this->directories);
467 if (
$type === null) {
472 if (
$type ===
'dir') {
491 $dirHandle = opendir(
$path);
492 while (
false !== ($item = readdir($dirHandle))) {
494 if (($hidden ===
true && $item !=
'.' && $item !=
'..')
495 || ($hidden ===
false && !preg_match(
'/^\\.(.*)$/', $item))
497 $found =
$path .
'/' . $item;
499 if ($found !==
false) {
500 if (is_dir($found)) {
501 array_push($this->directories, $found);
503 array_push($this->files, $found);
507 closedir($dirHandle);
522 if (is_dir($pathname) || empty($pathname)) {
528 if (is_file($pathname)) {
529 $this->
errors[] = sprintf(
'%s is a file', $pathname);
532 $nextPathname = substr($pathname, 0, strrpos($pathname,
'/'));
535 if (mkdir($pathname, intval(
$mode, 8))) {
536 $this->
messages[] = sprintf(
'%s created', $pathname);
539 $this->
errors[] = sprintf(
'%s NOT created', $pathname);
555 $directory = $this->
slashTerm($this->path);
556 $stack = array($directory);
559 if (is_file($stack[
$i])) {
560 $size += filesize($stack[$i]);
562 if (is_dir($stack[$i])) {
563 $dir = dir($stack[$i]);
565 while (
false !== ($entry =
$dir->read())) {
566 if ($entry ==
'.' || $entry ==
'..') {
569 $add = $stack[
$i] . $entry;
570 if (is_dir($stack[$i] . $entry)) {
595 if (is_dir(
$path) ===
true) {
596 $normal_files = glob(
$path .
'*');
601 if (preg_match(
"/(\.|\.\.)$/", $file)) {
604 if (is_file($file) ===
true) {
608 $this->
errors[] = sprintf(
'%s NOT removed',
$path);
611 if (is_dir($file) ===
true) {
612 if ($this->
delete($file) ===
false) {
620 if (rmdir(
$path) ===
false) {
621 $this->
errors[] = sprintf(
'%s NOT removed',
$path);
648 'from' => $this->path,
649 'mode' => $this->mode,
658 if (!$this->
cd($fromDir)) {
659 $this->
errors[] = sprintf(
'%s not found', $fromDir);
662 if (!is_dir($toDir)) {
663 mkdir($toDir,
$mode);
665 if (!is_writable($toDir)) {
666 $this->
errors[] = sprintf(
'%s not writable', $toDir);
669 $exceptions = array_merge(array(
'.',
'..',
'.svn'),
$options[
'skip']);
670 $handle = opendir($fromDir);
672 while (
false !== ($item = readdir($handle))) {
673 if (!in_array($item, $exceptions)) {
676 if (is_file($from)) {
677 if (
copy($from, $to)) {
679 touch($to, filemtime($from));
680 $this->
messages[] = sprintf(
'%s copied to %s', $from, $to);
682 $this->
errors[] = sprintf(
'%s NOT copied to %s', $from, $to);
686 if (mkdir($to, intval(
$mode, 8))) {
688 $this->
messages[] = sprintf(
'%s created', $to);
692 $this->
errors[] = sprintf(
'%s not created', $to);
701 if (!empty($this->
errors)) {
725 'from' => $this->path,
726 'mode' => $this->mode,
732 if ($this->
delete(
$options[
'from'])) {
771 if (strpos(
$path,
'..') ===
false) {
777 $parts = explode(
'/',
$path);
779 $newpath =
$path{0} ==
'/' ?
'/' :
'';
780 while (($part = array_shift($parts)) !== null) {
781 if ($part ==
'.' || $part ==
'') {
785 if (count($newparts) > 0) {
786 array_pop($newparts);
794 $newpath .= implode(
'/', $newparts);
812 if (preg_match(
'/[\/\\\]$/',
$path)) {
findRecursiveHelper($pattern, $sort=false)
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
static normalizePath($path)
tree($path, $hidden=true, $type=null)
static isSlashTerm($path)
chmod($path, $mode=false, $recursive=true, $exceptions=array())
read($sort=true, $exceptions=false)
if(DIRECTORY_SEPARATOR!="/") $xoops_root_path
findRecursive($pattern= '.*', $sort=false)
create($pathname, $mode=false)
treeHelper($path, $hidden)
find($regexp_pattern= '.*', $sort=false)
__construct($path= '', $create=true, $mode=false)
static addPathElement($path, $element)
static correctSlashFor($path)
static isWindowsPath($path)
inPath($path= '', $reverse=false)