Permalink
Browse files

refs #1529 - added/tested replacement glob() function; a missing glob…

…() is still a warning
  • Loading branch information...
1 parent e64f873 commit eccdf3aeb5fbd0549a25f9ed6b981742b42cedf2 vipsoft committed Jul 30, 2010
View
@@ -368,7 +368,7 @@ private static function getMergedAssetHash ($type)
{
$mergedFileDirectory = self::getMergedFileDirectory();
- $matchingFiles = @glob( $mergedFileDirectory . "*." . $type );
+ $matchingFiles = _glob( $mergedFileDirectory . "*." . $type );
if($matchingFiles == false)
{
View
@@ -229,11 +229,11 @@ static public function unlinkRecursive($dir, $deleteRootToo)
*/
public static function globr($sDir, $sPattern, $nFlags = NULL)
{
- if(($aFiles = @glob("$sDir/$sPattern", $nFlags)) == false)
+ if(($aFiles = _glob("$sDir/$sPattern", $nFlags)) == false)
{
$aFiles = array();
}
- if(($aDirs = @glob("$sDir/*", GLOB_ONLYDIR)) != false)
+ if(($aDirs = _glob("$sDir/*", GLOB_ONLYDIR)) != false)
{
foreach ($aDirs as $sSubDir)
{
View
@@ -98,7 +98,7 @@ public function isPluginLoaded( $name )
*/
public function readPluginsDirectory()
{
- $pluginsName = @glob( PIWIK_INCLUDE_PATH . '/plugins/*', GLOB_ONLYDIR);
+ $pluginsName = _glob( PIWIK_INCLUDE_PATH . '/plugins/*', GLOB_ONLYDIR);
$pluginsName = $pluginsName == false ? array() : array_map('basename', $pluginsName);
return $pluginsName;
}
View
@@ -194,7 +194,7 @@ private function loadComponentsWithUpdateFile()
$pathToUpdates = sprintf($this->pathUpdateFilePlugins, $name) . '*.php';
}
- $files = @glob( $pathToUpdates );
+ $files = _glob( $pathToUpdates );
if($files == false)
{
$files = array();
View
@@ -546,7 +546,7 @@
'Installation_SystemCheckTimeLimitHelp' => 'On a high traffic website, executing the archiving process may require more time than currently allowed. If necessary, change the max_execution_time directive in your php.ini file.',
'Installation_SystemCheckMailHelp' => 'Feedback and Lost Password messages will not be sent without mail().',
'Installation_SystemCheckParseIniFileHelp' => 'This built-in function has been disabled on your host. Piwik will attempt to emulate this function but may encounter further security restrictions. Tracker performance will also be impacted.',
- 'Installation_SystemCheckGlobHelp' => 'This built-in function has been disabled on your host. Piwik may work without this function but at reduced functionality/capability.',
+ 'Installation_SystemCheckGlobHelp' => 'This built-in function has been disabled on your host. Piwik will attempt to emulate this function but may encounter further security restrictions. Functionality may be impacted.',
'Installation_SystemCheckDebugBacktraceHelp' => 'View::factory won\'t be able to create views for the calling module.',
'Installation_SystemCheckCreateFunctionHelp' => 'Piwik uses anonymous functions for callbacks.',
'Installation_SystemCheckEvalHelp' => 'Required by HTML QuickForm and Smarty templating system.',
@@ -553,3 +553,72 @@ function _parse_ini_file($filename, $process_sections = false)
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;
+ }
+}
@@ -729,7 +729,6 @@ public static function getSystemInformation()
'debug_backtrace',
'create_function',
'eval',
- 'glob',
);
$infos['needed_functions'] = $needed_functions;
$infos['missing_functions'] = array();
@@ -746,6 +745,7 @@ public static function getSystemInformation()
'set_time_limit',
'mail',
'parse_ini_file',
+ 'glob',
);
$infos['desired_functions'] = $desired_functions;
$infos['missing_desired_functions'] = array();
@@ -55,7 +55,7 @@ public function getAvailableLanguages()
return $this->languageNames;
}
$path = PIWIK_INCLUDE_PATH . "/lang/";
- $languages = @glob($path . "*.php");
+ $languages = _glob($path . "*.php");
$pathLength = strlen($path);
$languageNames = array();
if($languages)

0 comments on commit eccdf3a

Please sign in to comment.