- Timestamp:
- 08/16/08 10:45:05 (3 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tags/Copix_3_0_4/utils/copix/utils/CopixFile.class.php
r1800 r3130 3 3 * @package copix 4 4 * @subpackage utils 5 * @author Croës Gérald, Jouanneau Laurent 5 * @author Croës Gérald, Jouanneau Laurent, Favre Brice 6 6 * @copyright 2001-2007 CopixTeam 7 7 * @link http://copix.org … … 134 134 private static function _createDir ($dir){ 135 135 if (!file_exists ($dir)) { 136 $_open_basedir_ini = ini_get('open_basedir'); 137 136 $_open_basedir_ini = ini_get ('open_basedir'); 137 $_safe_mode = ini_get ('safe_mode'); 138 139 if ($_open_basedir_ini === false && $_safe_mode == 1){ 140 $_open_basedir_ini = $_ENV['DOCUMENT_ROOT']; 141 } 138 142 if (DIRECTORY_SEPARATOR=='/') { 139 143 /* unix-style paths */ … … 214 218 public static function search ($pPattern, $pPath, $pRecursiveSearch = true){ 215 219 $pPath = self::trailingSlash ($pPath); 216 $files = glob ($pPath.$pPattern); 220 $pPath = realpath ($pPath); 221 $files = self::_glob ($pPath.$pPattern); 217 222 if ($pRecursiveSearch){ 218 foreach ( glob ($pPath.'*', GLOB_ONLYDIR) as $file) {223 foreach (self::_glob ($pPath.'*', GLOB_ONLYDIR) as $file) { 219 224 $files = array_merge ($files, self::search ($pPattern, $file, true)); 220 225 } … … 253 258 254 259 // Récupère le contenu du répertoire 255 $entries = glob(self::trailingSlash($pPath).'*');260 $entries = self::_glob(self::trailingSlash(realpath($pPath)).'*'); 256 261 257 262 // Compte le nombre d'entrées (avant filtrage) … … 265 270 // Traite les entrées 266 271 foreach($entries as $entry) { 267 272 // On ne traite pas les répertoires . et .. 273 if ($entry == '.' || $entry == '..') { 274 continue; 275 } 268 276 if(is_dir($entry)) { 269 277 // Répertoire : suppresion récursive … … 348 356 private static function _findFiles(&$result, $basePath, $relativePath, $depth, $entryFilter, $recurseFilter) { 349 357 350 $entries = glob($basePath.$relativePath.'*');358 $entries = self::_glob($basePath.$relativePath.'*'); 351 359 foreach($entries as $entry) { 352 360 $entryRelativePath = $relativePath.basename($entry); … … 495 503 */ 496 504 private static $_copixPathPrefixes = array( 497 'COPIX_CACHE_PATH' ,498 'COPIX_LOG_PATH' ,499 'COPIX_TEMP_PATH' ,500 'COPIX_VAR_PATH' ,501 'COPIX_PROJECT_PATH' ,502 'COPIX_SMARTY_PATH' ,503 'COPIX_UTILS_PATH' ,504 'COPIX_CORE_PATH' ,505 'COPIX_PATH' ,505 'COPIX_CACHE_PATH' => true, 506 'COPIX_LOG_PATH' => true, 507 'COPIX_TEMP_PATH' => true, 508 'COPIX_VAR_PATH' => true, 509 'COPIX_PROJECT_PATH' => true, 510 'COPIX_SMARTY_PATH' => true, 511 'COPIX_UTILS_PATH' => true, 512 'COPIX_CORE_PATH' => true, 513 'COPIX_PATH' => true, 506 514 ); 507 515 … … 513 521 */ 514 522 public static function getCopixPathPrefix($pPath) { 515 foreach(self::$_copixPathPrefixes as $key) { 516 @list(,$relativePath) = explode(constant($key), $pPath); 517 if($relativePath) { 518 return array($key, $relativePath); 523 $pPath = CopixConfig::getRealPath($pPath); 524 foreach(self::$_copixPathPrefixes as $name=>$path) { 525 if($path === true) { 526 $path = self::$_copixPathPrefixes[$name] = CopixConfig::getRealPath(constant($name)); 527 } 528 $length = strlen($path); 529 if(substr($pPath,0,$length) == $path) { 530 return array($name, substr($pPath,$length)); 519 531 } 520 532 } … … 522 534 } 523 535 536 /** 537 * Fonction glob surchargeant glob PHP et safe_glob 538 * 539 * @param string $pattern 540 * @param int $flags 541 * @return unknown 542 */ 543 private static function _glob ($pattern, $flags=null){ 544 $result = glob ($pattern, $flags); 545 if ($result === false){ 546 $result = self::_safe_glob ($pattern, $flags); 547 } 548 return $result; 549 } 550 /** 551 * Fonction safe_glob pour pallier les sécurités mise en place sur certains hébergeur 552 * 553 * @param string $pattern 554 * @param int $flags 555 * @return array ou boolean 556 */ 557 private static function _safe_glob ($pattern, $flags=null){ 558 $split = explode('/',$pattern); 559 $match = array_pop ($split); 560 $path = implode ('/',$split); 561 if (($dir=opendir($path)) !== false) { 562 $glob = array(); 563 while(($file=readdir($dir))!==false) { 564 if (fnmatch($match,$file)) { 565 if ((is_dir("$path/$file"))||(!($flags&GLOB_ONLYDIR))) { 566 if ($flags&GLOB_MARK) $file.='/'; 567 $glob[]=$file; 568 } 569 } 570 } 571 closedir($dir); 572 if (!($flags&GLOB_NOSORT)) sort($glob); 573 return $glob; 574 } else { 575 return false; 576 } 577 } 524 578 } 525 526 ?>
