HTMLPurifier 4.4.0
|
00001 <?php 00002 00010 class FSTools 00011 { 00012 00013 private static $singleton; 00014 00018 static public function singleton() { 00019 if (empty(FSTools::$singleton)) FSTools::$singleton = new FSTools(); 00020 return FSTools::$singleton; 00021 } 00022 00027 static public function setSingleton($singleton) { 00028 FSTools::$singleton = $singleton; 00029 } 00030 00036 public function mkdirr($folder) { 00037 $folders = preg_split("#[\\\\/]#", $folder); 00038 $base = ''; 00039 for($i = 0, $c = count($folders); $i < $c; $i++) { 00040 if(empty($folders[$i])) { 00041 if (!$i) { 00042 // special case for root level 00043 $base .= DIRECTORY_SEPARATOR; 00044 } 00045 continue; 00046 } 00047 $base .= $folders[$i]; 00048 if(!is_dir($base)){ 00049 $this->mkdir($base); 00050 } 00051 $base .= DIRECTORY_SEPARATOR; 00052 } 00053 } 00054 00060 public function copyr($source, $dest) { 00061 // Simple copy for a file 00062 if (is_file($source)) { 00063 return $this->copy($source, $dest); 00064 } 00065 // Make destination directory 00066 if (!is_dir($dest)) { 00067 $this->mkdir($dest); 00068 } 00069 // Loop through the folder 00070 $dir = $this->dir($source); 00071 while ( false !== ($entry = $dir->read()) ) { 00072 // Skip pointers 00073 if ($entry == '.' || $entry == '..') { 00074 continue; 00075 } 00076 if (!$this->copyable($entry)) { 00077 continue; 00078 } 00079 // Deep copy directories 00080 if ($dest !== "$source/$entry") { 00081 $this->copyr("$source/$entry", "$dest/$entry"); 00082 } 00083 } 00084 // Clean up 00085 $dir->close(); 00086 return true; 00087 } 00088 00095 public function copyable($file) { 00096 return true; 00097 } 00098 00103 public function rmdirr($dirname) 00104 { 00105 // Sanity check 00106 if (!$this->file_exists($dirname)) { 00107 return false; 00108 } 00109 00110 // Simple delete for a file 00111 if ($this->is_file($dirname) || $this->is_link($dirname)) { 00112 return $this->unlink($dirname); 00113 } 00114 00115 // Loop through the folder 00116 $dir = $this->dir($dirname); 00117 while (false !== $entry = $dir->read()) { 00118 // Skip pointers 00119 if ($entry == '.' || $entry == '..') { 00120 continue; 00121 } 00122 // Recurse 00123 $this->rmdirr($dirname . DIRECTORY_SEPARATOR . $entry); 00124 } 00125 00126 // Clean up 00127 $dir->close(); 00128 return $this->rmdir($dirname); 00129 } 00130 00134 public function globr($dir, $pattern, $flags = NULL) { 00135 $files = $this->glob("$dir/$pattern", $flags); 00136 if ($files === false) $files = array(); 00137 $sub_dirs = $this->glob("$dir/*", GLOB_ONLYDIR); 00138 if ($sub_dirs === false) $sub_dirs = array(); 00139 foreach ($sub_dirs as $sub_dir) { 00140 $sub_files = $this->globr($sub_dir, $pattern, $flags); 00141 $files = array_merge($files, $sub_files); 00142 } 00143 return $files; 00144 } 00145 00151 public function __call($name, $args) { 00152 return call_user_func_array($name, $args); 00153 } 00154 00155 } 00156 00157 // vim: et sw=4 sts=4