index.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * GitPHP
  4. *
  5. * Index
  6. *
  7. * @author Christopher Han <xiphux@gmail.com>
  8. * @copyright Copyright (c) 2010 Christopher Han
  9. * @package GitPHP
  10. */
  11. /**
  12. * Define start time / memory for benchmarking
  13. */
  14. define('GITPHP_START_TIME', microtime(true));
  15. define('GITPHP_START_MEM', memory_get_usage());
  16. /**
  17. * Define some paths
  18. */
  19. define('GITPHP_BASEDIR', dirname(__FILE__) . '/');
  20. define('GITPHP_CONFIGDIR', GITPHP_BASEDIR . 'config/');
  21. define('GITPHP_INCLUDEDIR', GITPHP_BASEDIR . 'include/');
  22. define('GITPHP_LOCALEDIR', GITPHP_BASEDIR . 'locale/');
  23. define('GITPHP_CACHEDIR', GITPHP_BASEDIR . 'cache/');
  24. define('GITPHP_LIBDIR', GITPHP_BASEDIR . 'lib/');
  25. define('GITPHP_SMARTYDIR', GITPHP_LIBDIR . 'smarty/libs/');
  26. define('GITPHP_GESHIDIR', GITPHP_LIBDIR . 'geshi/');
  27. define('GITPHP_COMPRESS_TAR', 'tar');
  28. define('GITPHP_COMPRESS_BZ2', 'tbz2');
  29. define('GITPHP_COMPRESS_GZ', 'tgz');
  30. define('GITPHP_COMPRESS_ZIP', 'zip');
  31. /**
  32. * Low level setup
  33. */
  34. if (function_exists('mb_internal_encoding')) {
  35. mb_internal_encoding("UTF-8");
  36. }
  37. date_default_timezone_set('UTC');
  38. /* strlen() can be overloaded in mbstring extension, so always using mb_orig_strlen for binary data */
  39. if (!function_exists('mb_orig_strlen')) {
  40. function mb_orig_strlen($str)
  41. {
  42. return strlen($str);
  43. }
  44. }
  45. if (!function_exists('mb_orig_substr')) {
  46. function mb_orig_substr($str, $offset, $len = null)
  47. {
  48. return isset($len) ? substr($str, $offset, $len) : substr($str, $offset);
  49. }
  50. }
  51. /**
  52. * Version header
  53. */
  54. include(GITPHP_INCLUDEDIR . 'version.php');
  55. /**
  56. * Autoload setup
  57. */
  58. require(GITPHP_INCLUDEDIR . 'AutoLoader.class.php');
  59. spl_autoload_register(array('GitPHP_AutoLoader', 'AutoLoad'));
  60. $router = new GitPHP_Router();
  61. try {
  62. $controller = $router->GetController();
  63. if ($controller) {
  64. $controller->Initialize();
  65. $controller->RenderHeaders();
  66. $controller->Render();
  67. }
  68. } catch (Exception $e) {
  69. $messageController = $router->GetMessageController();
  70. $messageController->Initialize();
  71. if (!($e instanceof GitPHP_MessageException)) {
  72. $config = $messageController->GetConfig();
  73. if ($config && $config->GetValue('debug')) {
  74. throw $e;
  75. }
  76. }
  77. $messageController->SetParam('exception', $e);
  78. $messageController->RenderHeaders();
  79. $messageController->Render();
  80. unset($messageController);
  81. }
  82. unset($router);
  83. ?>