Changeset 3130 for tags

Show
Ignore:
Timestamp:
08/16/08 10:45:05 (3 months ago)
Author:
bricef
Message:

Report de modification sur le tag pour corriger un bug avec hébergement free

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tags/Copix_3_0_4/utils/copix/utils/CopixFile.class.php

    r1800 r3130  
    33 * @package     copix 
    44 * @subpackage  utils 
    5  * @author      Croës Gérald, Jouanneau Laurent 
     5 * @author      Croës Gérald, Jouanneau Laurent, Favre Brice 
    66 * @copyright   2001-2007 CopixTeam 
    77 * @link        http://copix.org 
     
    134134    private static function _createDir ($dir){ 
    135135        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            } 
    138142            if (DIRECTORY_SEPARATOR=='/') { 
    139143                /* unix-style paths */ 
     
    214218    public static function search ($pPattern, $pPath, $pRecursiveSearch = true){ 
    215219        $pPath = self::trailingSlash ($pPath); 
    216         $files = glob ($pPath.$pPattern); 
     220        $pPath = realpath ($pPath); 
     221        $files = self::_glob ($pPath.$pPattern); 
    217222        if ($pRecursiveSearch){ 
    218             foreach (glob ($pPath.'*', GLOB_ONLYDIR) as $file) { 
     223            foreach (self::_glob ($pPath.'*', GLOB_ONLYDIR) as $file) { 
    219224                $files = array_merge ($files, self::search ($pPattern, $file, true)); 
    220225            } 
     
    253258       
    254259        // Récupère le contenu du répertoire 
    255         $entries = glob(self::trailingSlash($pPath).'*'); 
     260        $entries = self::_glob(self::trailingSlash(realpath($pPath)).'*'); 
    256261 
    257262        // Compte le nombre d'entrées (avant filtrage) 
     
    265270        // Traite les entrées 
    266271        foreach($entries as $entry) { 
    267                  
     272            // On ne traite pas les répertoires . et .. 
     273            if ($entry == '.' || $entry == '..') { 
     274                continue; 
     275            } 
    268276            if(is_dir($entry)) { 
    269277                // Répertoire : suppresion récursive 
     
    348356    private static function _findFiles(&$result, $basePath, $relativePath, $depth, $entryFilter, $recurseFilter) { 
    349357 
    350         $entries = glob($basePath.$relativePath.'*'); 
     358        $entries = self::_glob($basePath.$relativePath.'*'); 
    351359        foreach($entries as $entry) { 
    352360            $entryRelativePath = $relativePath.basename($entry); 
     
    495503     */ 
    496504    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,  
    506514    ); 
    507515 
     
    513521     */ 
    514522    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)); 
    519531            } 
    520532        } 
     
    522534    } 
    523535 
     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    } 
    524578} 
    525  
    526 ?>