diff options
author | robocoder <anthon.pang@gmail.com> | 2010-07-30 11:00:24 +0400 |
---|---|---|
committer | robocoder <anthon.pang@gmail.com> | 2010-07-30 11:00:24 +0400 |
commit | 6dfb67630cafd55ad2faa8a1611be49a3f9a8177 (patch) | |
tree | 0ef69f6e2cdf6a256c7ab5125d5c701479f5ffe4 /libs/upgradephp | |
parent | d3a2455ff16db40dca1fb5cbef86dbcc37d81434 (diff) |
refs #1529 - added/tested replacement glob() function; a missing glob() is still a warning
git-svn-id: http://dev.piwik.org/svn/trunk@2817 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'libs/upgradephp')
-rw-r--r-- | libs/upgradephp/upgrade.php | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/libs/upgradephp/upgrade.php b/libs/upgradephp/upgrade.php index 63b24778a9..4bfaebb4d4 100644 --- a/libs/upgradephp/upgrade.php +++ b/libs/upgradephp/upgrade.php @@ -553,3 +553,72 @@ if(function_exists('parse_ini_file')) { return $result + $globals; } } + +/** + * fnmatch() replacement + * + * @since fnmatch() added to PHP 4.3.0; PHP 5.3.0 on Windows + * @author jk at ricochetsolutions dot com + * @author anthon (dot) pang (at) gmail (dot) com + * + * @param string $pattern shell wildcard pattern + * @param string $string tested string + * @param int $flags FNM_CASEFOLD (other flags not supported) + * @return bool True if there is a match, false otherwise + */ +if(!defined('FNM_CASEFOLD')) { define('FNM_CASEFOLD', 16); } +if(function_exists('fnmatch')) { + // provide a wrapper + function _fnmatch($pattern, $string, $flags = 0) { + return fnmatch($pattern, $string, $flags); + } +} else { + function _fnmatch($pattern, $string, $flags = 0) { + $regex = '#^' . strtr(preg_quote($pattern, '#'), array('\*' => '.*', '\?' => '.')) . '$#' . ($flags & FNM_CASEFOLD ? 'i' : ''); + return preg_match($regex, $string); + } +} + +/** + * glob() replacement. + * Behaves like glob($pattern, $flags) + * + * @author BigueNique AT yahoo DOT ca + * @author anthon (dot) pang (at) gmail (dot) com + * + * @param string $pattern + * @param int $flags GLOBL_ONLYDIR, GLOB_MARK, GLOB_NOSORT (other flags not supported; defaults to 0) + * @return array + */ +if(function_exists('glob')) { + // provide a wrapper + function _glob($pattern, $flags = 0) { + return glob($pattern, $flags); + } +} else if(function_exists('opendir') && function_exists('readdir')) { + // we can't redefine glob() if it has been disabled + function _glob($pattern, $flags = 0) { + $path = dirname($pattern); + $filePattern = basename($pattern); + if(is_dir($path) && ($handle = opendir($path)) !== false) { + $matches = array(); + while(($file = readdir($handle)) !== false) { + if(($file[0] != '.') + && _fnmatch($filePattern, $file) + && (!($flags & GLOB_ONLYDIR) || is_dir("$path/$file"))) { + $matches[] = "$path/$file" . ($flags & GLOB_MARK ? '/' : ''); + } + } + closedir($handle); + if(!($flags & GLOB_NOSORT)) { + sort($matches); + } + return $matches; + } + return false; + } +} else { + function _glob($pattern, $flags = 0) { + return false; + } +} |