diff -r d62212462f9b -r 1b4288399b1f functions.php --- a/functions.php Tue Sep 23 23:26:15 2008 -0400 +++ b/functions.php Tue Sep 23 23:26:18 2008 -0400 @@ -221,6 +221,11 @@ { global $httpd; static $smarty = array(); + if ( $theme_id === '__free__' ) + { + $smarty = array(); + return false; + } if ( !isset($smarty[$theme_id]) ) { $smarty[$theme_id] = new Smarty(); @@ -233,3 +238,61 @@ } return $smarty[$theme_id]; } + +/** + * Implementation of the "which" command in native PHP. + * @param string command + * @return string path to executable, or false on failure + */ + +function which($executable) +{ + $path = ( isset($_ENV['PATH']) ) ? $_ENV['PATH'] : ( isset($_SERVER['PATH']) ? $_SERVER['PATH'] : false ); + if ( !$path ) + // couldn't get OS's PATH + return false; + + $win32 = ( PHP_OS == 'WINNT' || PHP_OS == 'WIN32' ); + $extensions = $win32 ? array('.exe', '.com', '.bat') : array(''); + $separator = $win32 ? ';' : ':'; + $paths = explode($separator, $path); + foreach ( $paths as $dir ) + { + foreach ( $extensions as $ext ) + { + $fullpath = "$dir/{$executable}{$ext}"; + if ( file_exists($fullpath) && is_executable($fullpath) ) + { + return $fullpath; + } + } + } + return false; +} + +/** + * Reload the config. + */ + +function grey_reload_config() +{ + global $httpd; + status('reloading the config'); + + if ( file_exists('./greyhound-config.php') ) + { + require('./greyhound-config.php'); + } + else + { + // ignore this, it allows using a different config file when a Mercurial repository + // exists in Greyhound's root directory (to allow the devs to have their own config + // separate from the default) + + if ( @is_dir(GREY_ROOT . '/.hg') ) + require(GREY_ROOT . '/config.dev.php'); + else + require(GREY_ROOT . '/config.php'); + } +} +