functions.php
changeset 50 1b4288399b1f
parent 34 3b817b961984
child 52 ab3541465382
equal deleted inserted replaced
49:d62212462f9b 50:1b4288399b1f
   219 
   219 
   220 function load_theme($theme_id)
   220 function load_theme($theme_id)
   221 {
   221 {
   222   global $httpd;
   222   global $httpd;
   223   static $smarty = array();
   223   static $smarty = array();
       
   224   if ( $theme_id === '__free__' )
       
   225   {
       
   226     $smarty = array();
       
   227     return false;
       
   228   }
   224   if ( !isset($smarty[$theme_id]) )
   229   if ( !isset($smarty[$theme_id]) )
   225   {
   230   {
   226     $smarty[$theme_id] = new Smarty();
   231     $smarty[$theme_id] = new Smarty();
   227     $smarty[$theme_id]->template_dir = GREY_ROOT . "/themes/$theme_id";
   232     $smarty[$theme_id]->template_dir = GREY_ROOT . "/themes/$theme_id";
   228     if ( !is_dir("./compiled/$theme_id") )
   233     if ( !is_dir("./compiled/$theme_id") )
   231     $smarty[$theme_id]->config_dir = "./config";
   236     $smarty[$theme_id]->config_dir = "./config";
   232     $httpd->add_handler("themes/$theme_id", 'dir', GREY_ROOT . "/themes/$theme_id");
   237     $httpd->add_handler("themes/$theme_id", 'dir', GREY_ROOT . "/themes/$theme_id");
   233   }
   238   }
   234   return $smarty[$theme_id];
   239   return $smarty[$theme_id];
   235 }
   240 }
       
   241 
       
   242 /**
       
   243  * Implementation of the "which" command in native PHP.
       
   244  * @param string command
       
   245  * @return string path to executable, or false on failure
       
   246  */
       
   247 
       
   248 function which($executable)
       
   249 {
       
   250   $path = ( isset($_ENV['PATH']) ) ? $_ENV['PATH'] : ( isset($_SERVER['PATH']) ? $_SERVER['PATH'] : false );
       
   251   if ( !$path )
       
   252     // couldn't get OS's PATH
       
   253     return false;
       
   254     
       
   255   $win32 = ( PHP_OS == 'WINNT' || PHP_OS == 'WIN32' );
       
   256   $extensions = $win32 ? array('.exe', '.com', '.bat') : array('');
       
   257   $separator = $win32 ? ';' : ':';
       
   258   $paths = explode($separator, $path);
       
   259   foreach ( $paths as $dir )
       
   260   {
       
   261     foreach ( $extensions as $ext )
       
   262     {
       
   263       $fullpath = "$dir/{$executable}{$ext}";
       
   264       if ( file_exists($fullpath) && is_executable($fullpath) )
       
   265       {
       
   266         return $fullpath;
       
   267       }
       
   268     }
       
   269   }
       
   270   return false;
       
   271 }
       
   272 
       
   273 /**
       
   274  * Reload the config.
       
   275  */
       
   276 
       
   277 function grey_reload_config()
       
   278 {
       
   279   global $httpd;
       
   280   status('reloading the config');
       
   281   
       
   282   if ( file_exists('./greyhound-config.php') )
       
   283   {
       
   284     require('./greyhound-config.php');
       
   285   }
       
   286   else
       
   287   {
       
   288     // ignore this, it allows using a different config file when a Mercurial repository
       
   289     // exists in Greyhound's root directory (to allow the devs to have their own config
       
   290     // separate from the default)
       
   291     
       
   292     if ( @is_dir(GREY_ROOT . '/.hg') )
       
   293       require(GREY_ROOT . '/config.dev.php');
       
   294     else
       
   295       require(GREY_ROOT . '/config.php');
       
   296   }
       
   297 }
       
   298