Use translation wrapper functions
[gitphp.git] / index.php
blob:a/index.php -> blob:b/index.php
<?php <?php
/** /**
* GitPHP * GitPHP
* *
* Index * Index
* *
* @author Christopher Han <xiphux@gmail.com> * @author Christopher Han <xiphux@gmail.com>
* @copyright Copyright (c) 2010 Christopher Han * @copyright Copyright (c) 2010 Christopher Han
* @package GitPHP * @package GitPHP
*/ */
   
  /**
  * Define start time / memory for benchmarking
  */
define('GITPHP_START_TIME', microtime(true)); define('GITPHP_START_TIME', microtime(true));
define('GITPHP_START_MEM', memory_get_usage()); define('GITPHP_START_MEM', memory_get_usage());
   
/** /**
* Define some paths * Define some paths
*/ */
define('GITPHP_BASEDIR', dirname(__FILE__) . '/'); define('GITPHP_BASEDIR', dirname(__FILE__) . '/');
define('GITPHP_CONFIGDIR', GITPHP_BASEDIR . 'config/'); define('GITPHP_CONFIGDIR', GITPHP_BASEDIR . 'config/');
define('GITPHP_INCLUDEDIR', GITPHP_BASEDIR . 'include/'); define('GITPHP_INCLUDEDIR', GITPHP_BASEDIR . 'include/');
define('GITPHP_GITOBJECTDIR', GITPHP_INCLUDEDIR . 'git/');  
define('GITPHP_CONTROLLERDIR', GITPHP_INCLUDEDIR . 'controller/');  
define('GITPHP_LOCALEDIR', GITPHP_BASEDIR . 'locale/'); define('GITPHP_LOCALEDIR', GITPHP_BASEDIR . 'locale/');
  define('GITPHP_CACHEDIR', GITPHP_BASEDIR . 'cache/');
  define('GITPHP_LIBDIR', GITPHP_BASEDIR . 'lib/');
  define('GITPHP_SMARTYDIR', GITPHP_LIBDIR . 'smarty/libs/');
  define('GITPHP_GESHIDIR', GITPHP_LIBDIR . 'geshi/');
   
include_once(GITPHP_INCLUDEDIR . 'version.php'); define('GITPHP_COMPRESS_TAR', 'tar');
  define('GITPHP_COMPRESS_BZ2', 'tbz2');
  define('GITPHP_COMPRESS_GZ', 'tgz');
  define('GITPHP_COMPRESS_ZIP', 'zip');
   
require_once(GITPHP_INCLUDEDIR . 'Config.class.php'); /**
  * Low level setup
require_once(GITPHP_INCLUDEDIR . 'Resource.class.php'); */
  if (function_exists('mb_internal_encoding')) {
require_once(GITPHP_INCLUDEDIR . 'Log.class.php'); mb_internal_encoding("UTF-8");
  }
require_once(GITPHP_GITOBJECTDIR . 'ProjectList.class.php');  
   
require_once(GITPHP_INCLUDEDIR . 'MessageException.class.php');  
   
require_once(GITPHP_CONTROLLERDIR . 'Controller.class.php');  
   
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
   
  /**
  * Version header
  */
  include(GITPHP_INCLUDEDIR . 'version.php');
   
/* /**
* Set the locale based on the user's preference * Autoload setup
*/ */
if ((!isset($_COOKIE[GITPHP_LOCALE_COOKIE])) || empty($_COOKIE[GITPHP_LOCALE_COOKIE])) { require(GITPHP_INCLUDEDIR . 'AutoLoader.class.php');
  spl_autoload_register(array('GitPHP_AutoLoader', 'AutoLoad'));
   
/*  
* User's first time here, try by HTTP_ACCEPT_LANGUAGE  
*/  
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {  
$httpAcceptLang = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);  
$preferredLocale = GitPHP_Resource::FindPreferredLocale($_SERVER['HTTP_ACCEPT_LANGUAGE']);  
if (!empty($preferredLocale)) {  
setcookie(GITPHP_LOCALE_COOKIE, $preferredLocale);  
GitPHP_Resource::Instantiate($preferredLocale);  
}  
}  
   
if (!GitPHP_Resource::Instantiated()) { $router = new GitPHP_Router();
/*  
* Create a dummy cookie to prevent browser delay  
*/  
setcookie(GITPHP_LOCALE_COOKIE, 0);  
}  
   
} else if (isset($_GET['l']) && !empty($_GET['l'])) {  
   
/*  
* User picked something  
*/  
setcookie(GITPHP_LOCALE_COOKIE, $_GET['l']);  
GitPHP_Resource::Instantiate($_GET['l']);  
   
} else if (isset($_COOKIE[GITPHP_LOCALE_COOKIE]) && !empty($_COOKIE[GITPHP_LOCALE_COOKIE])) {  
   
/*  
* Returning visitor with a preference  
*/  
GitPHP_Resource::Instantiate($_COOKIE[GITPHP_LOCALE_COOKIE]);  
   
}  
   
   
try { try {
   
// Define these here because these get used in the config file $controller = $router->GetController();
define('GITPHP_COMPRESS_BZ2', 1);  
define('GITPHP_COMPRESS_GZ', 2);  
define('GITPHP_COMPRESS_ZIP', 3);  
   
/*  
* Configuration  
*/  
GitPHP_Config::GetInstance()->LoadConfig(GITPHP_CONFIGDIR . 'gitphp.conf.php');  
   
/*  
* Use the default language in the config if user has no preference  
* with en_US as the fallback  
*/  
if (!GitPHP_Resource::Instantiated()) {  
GitPHP_Resource::Instantiate(GitPHP_Config::GetInstance()->GetValue('locale', 'en_US'));  
}  
   
/*  
* Debug  
*/  
if (GitPHP_Log::GetInstance()->GetEnabled()) {  
GitPHP_Log::GetInstance()->SetStartTime(GITPHP_START_TIME);  
GitPHP_Log::GetInstance()->SetStartMemory(GITPHP_START_MEM);  
}  
   
if (!GitPHP_Config::GetInstance()->GetValue('projectroot', null)) {  
throw new GitPHP_MessageException(__('A projectroot must be set in the config'), true);  
}  
   
/*  
* Project list  
*/  
if (file_exists(GITPHP_CONFIGDIR . 'projects.conf.php')) {  
GitPHP_ProjectList::Instantiate(GITPHP_CONFIGDIR . 'projects.conf.php', false);  
} else {  
GitPHP_ProjectList::Instantiate(GITPHP_CONFIGDIR . 'gitphp.conf.php', true);  
}  
   
$controller = GitPHP_Controller::GetController((isset($_GET['a']) ? $_GET['a'] : null));  
if ($controller) { if ($controller) {
  $controller->Initialize();
$controller->RenderHeaders(); $controller->RenderHeaders();
$controller->Render(); $controller->Render();
} }
   
} catch (Exception $e) { } catch (Exception $e) {
   
if (GitPHP_Config::GetInstance()->GetValue('debug', false)) { $messageController = $router->GetMessageController();
throw $e; $messageController->Initialize();
   
  if (!($e instanceof GitPHP_MessageException)) {
  $config = $messageController->GetConfig();
  if ($config && $config->GetValue('debug')) {
  throw $e;
  }
} }
   
if (!GitPHP_Resource::Instantiated()) { $messageController->SetParam('exception', $e);
/* $messageController->RenderHeaders();
* In case an error was thrown before instantiating $messageController->Render();
* the resource manager  
*/  
GitPHP_Resource::Instantiate('en_US');  
}  
   
require_once(GITPHP_CONTROLLERDIR . 'Controller_Message.class.php'); unset($messageController);
$controller = new GitPHP_Controller_Message();  
$controller->SetParam('message', $e->getMessage());  
if ($e instanceof GitPHP_MessageException) {  
$controller->SetParam('error', $e->Error);  
} else {  
$controller->SetParam('error', true);  
}  
$controller->Render();  
   
} }
   
if (GitPHP_Log::GetInstance()->GetEnabled()) { unset($router);
$entries = GitPHP_Log::GetInstance()->GetEntries();  
foreach ($entries as $logline) { if (isset($controller)) {
echo "\n" . $logline; $log = $controller->GetLog();
  if ($log && $log->GetEnabled()) {
  $entries = $log->GetEntries();
  foreach ($entries as $logline) {
  echo "<br />\n" . htmlspecialchars($logline, ENT_QUOTES, 'UTF-8', true);
  }
  unset($logline);
  unset($entries);
} }
  unset($controller);
} }
   
?> ?>
   
comments