Ejemplo n.º 1
0
    }
    $controller = GitPHP_Controller::GetController(isset($_GET['a']) ? $_GET['a'] : null);
    if ($controller) {
        $controller->RenderHeaders();
        $controller->Render();
    }
} catch (Exception $e) {
    if (GitPHP_Config::GetInstance()->GetValue('debug', false)) {
        throw $e;
    }
    if (!GitPHP_Resource::Instantiated()) {
        /*
         * In case an error was thrown before instantiating
         * the resource manager
         */
        GitPHP_Resource::Instantiate('en_US');
    }
    require_once GITPHP_CONTROLLERDIR . 'Controller_Message.class.php';
    $controller = new GitPHP_Controller_Message();
    $controller->SetParam('message', $e->getMessage());
    if ($e instanceof GitPHP_MessageException) {
        $controller->SetParam('error', $e->Error);
        $controller->SetParam('statuscode', $e->StatusCode);
    } else {
        $controller->SetParam('error', true);
    }
    $controller->RenderHeaders();
    $controller->Render();
}
if (GitPHP_Log::GetInstance()->GetEnabled()) {
    $entries = GitPHP_Log::GetInstance()->GetEntries();
Ejemplo n.º 2
0
 /**
  * Given a list of preferred locales, try to find a matching supported locale
  *
  * @param string $httpAcceptLang HTTP Accept-Language string
  * @return string matching locale if found
  */
 public static function FindPreferredLocale($httpAcceptLang)
 {
     if (empty($httpAcceptLang)) {
         return '';
     }
     $locales = explode(',', $httpAcceptLang);
     $localePref = array();
     foreach ($locales as $locale) {
         $quality = '1.0';
         $localeData = explode(';', trim($locale));
         if (count($localeData) > 1) {
             $q = trim($localeData[1]);
             if (substr($q, 0, 2) == 'q=') {
                 $quality = substr($q, 2);
             }
         }
         $localePref[$quality][] = trim($localeData[0]);
     }
     krsort($localePref);
     $supportedLocales = GitPHP_Resource::SupportedLocales(false);
     foreach ($localePref as $quality => $qualityArray) {
         foreach ($qualityArray as $browserLocale) {
             $locale = str_replace('-', '_', $browserLocale);
             $loclen = strlen($locale);
             foreach ($supportedLocales as $lang) {
                 /* 
                  * using strncasecmp with length of the preferred
                  * locale means we can match both full
                  * language + country preference specifications
                  * (en_US) as well as just language specifications
                  * (en)
                  */
                 if (strncasecmp($locale, $lang, $loclen) === 0) {
                     return $lang;
                 }
             }
         }
     }
     return '';
 }
Ejemplo n.º 3
0
 /**
  * LoadCommonData
  *
  * Loads common data used by all templates
  *
  * @access private
  */
 private function LoadCommonData()
 {
     global $gitphp_version, $gitphp_appstring;
     $this->tpl->assign('version', $gitphp_version);
     $stylesheet = GitPHP_Config::GetInstance()->GetValue('stylesheet', 'gitphpskin.css');
     if ($stylesheet == 'gitphp.css') {
         // backwards compatibility
         $stylesheet = 'gitphpskin.css';
     }
     $this->tpl->assign('stylesheet', preg_replace('/\\.css$/', '', $stylesheet));
     $this->tpl->assign('javascript', GitPHP_Config::GetInstance()->GetValue('javascript', true));
     $this->tpl->assign('googlejs', GitPHP_Config::GetInstance()->GetValue('googlejs', false));
     $this->tpl->assign('pagetitle', GitPHP_Config::GetInstance()->GetValue('title', $gitphp_appstring));
     $this->tpl->assign('homelink', GitPHP_Config::GetInstance()->GetValue('homelink', __('projects')));
     $this->tpl->assign('action', $this->GetName());
     $this->tpl->assign('actionlocal', $this->GetName(true));
     if ($this->project) {
         $this->tpl->assign('project', $this->project);
     }
     if (GitPHP_Config::GetInstance()->GetValue('search', true)) {
         $this->tpl->assign('enablesearch', true);
     }
     if (GitPHP_Config::GetInstance()->GetValue('filesearch', true)) {
         $this->tpl->assign('filesearch', true);
     }
     if (isset($this->params['search'])) {
         $this->tpl->assign('search', $this->params['search']);
     }
     if (isset($this->params['searchtype'])) {
         $this->tpl->assign('searchtype', $this->params['searchtype']);
     }
     $this->tpl->assign('currentlocale', GitPHP_Resource::GetLocale());
     $this->tpl->assign('supportedlocales', GitPHP_Resource::SupportedLocales());
     $getvars = explode('&', $_SERVER['QUERY_STRING']);
     $getvarsmapped = array();
     foreach ($getvars as $varstr) {
         $eqpos = strpos($varstr, '=');
         if ($eqpos > 0) {
             $var = substr($varstr, 0, $eqpos);
             $val = substr($varstr, $eqpos + 1);
             if (!(empty($var) || empty($val))) {
                 $getvarsmapped[$var] = urldecode($val);
             }
         }
     }
     $this->tpl->assign('requestvars', $getvarsmapped);
     $this->tpl->assign('snapshotformats', GitPHP_Archive::SupportedFormats());
 }
Ejemplo n.º 4
0
 /**
  * Loads common data used by all templates
  */
 private function LoadCommonData()
 {
     global $gitphp_version, $gitphp_appstring;
     $this->tpl->assign('version', $gitphp_version);
     $stylesheet = $this->config->GetValue('stylesheet');
     if ($stylesheet == 'gitphp.css') {
         // backwards compatibility
         $stylesheet = 'gitphpskin.css';
     }
     $this->tpl->assign('stylesheet', preg_replace('/\\.css$/', '', $stylesheet));
     $this->tpl->assign('javascript', $this->config->GetValue('javascript'));
     $this->tpl->assign('googlejs', $this->config->GetValue('googlejs'));
     if ($this->config->HasKey('title')) {
         $this->tpl->assign('pagetitle', $this->config->GetValue('title'));
     } else {
         $this->tpl->assign('pagetitle', $gitphp_appstring);
     }
     if ($this->config->HasKey('homelink')) {
         $this->tpl->assign('homelink', $this->config->GetValue('homelink'));
     } else {
         if ($this->resource) {
             $this->tpl->assign('homelink', $this->resource->translate('projects'));
         } else {
             $this->tpl->assign('homelink', 'projects');
         }
     }
     $this->tpl->assign('action', $this->GetName());
     $this->tpl->assign('actionlocal', $this->GetName(true));
     if ($this->project) {
         $this->tpl->assign('project', $this->GetProject());
     }
     if ($this->config->GetValue('search')) {
         $this->tpl->assign('enablesearch', true);
     }
     if ($this->config->GetValue('filesearch')) {
         $this->tpl->assign('filesearch', true);
     }
     if (isset($this->params['search'])) {
         $this->tpl->assign('search', $this->params['search']);
     }
     if (isset($this->params['searchtype'])) {
         $this->tpl->assign('searchtype', $this->params['searchtype']);
     }
     if ($this->resource) {
         $this->tpl->assign('currentlocale', $this->resource->GetLocale());
         $this->tpl->assign('currentprimarylocale', $this->resource->GetPrimaryLocale());
         $this->tpl->assign('resource', $this->resource);
     } else {
         $this->tpl->assign('currentlocale', 'en_US');
         $this->tpl->assign('currentprimarylocale', 'en');
     }
     $this->tpl->assign('supportedlocales', GitPHP_Resource::SupportedLocales(true));
     if ($this->config->GetValue('graphs')) {
         $this->tpl->assign('enablegraphs', true);
     }
     $this->tpl->assign('baseurl', GitPHP_Util::BaseUrl());
     $requesturl = $_SERVER['REQUEST_URI'];
     $querypos = strpos($requesturl, '?');
     if ($querypos !== false) {
         $requesturl = substr($requesturl, 0, $querypos);
     }
     $this->tpl->assign('requesturl', $requesturl);
     if ($this->router) {
         $this->router->SetCleanUrl($this->config->GetValue('cleanurl') ? true : false);
         $this->router->SetAbbreviate($this->config->GetValue('abbreviateurl') ? true : false);
         if ($this->config->GetValue('self')) {
             $this->router->SetBaseUrl($this->config->GetValue('self'));
         }
         $this->tpl->assign('router', $this->router);
     }
     $getvars = array();
     if (isset($_SERVER['QUERY_STRING'])) {
         $getvars = explode('&', $_SERVER['QUERY_STRING']);
     }
     $getvarsmapped = array();
     foreach ($getvars as $varstr) {
         $eqpos = strpos($varstr, '=');
         if ($eqpos > 0) {
             $var = substr($varstr, 0, $eqpos);
             $val = substr($varstr, $eqpos + 1);
             if (!(empty($var) || empty($val) || $var == 'q')) {
                 $getvarsmapped[$var] = urldecode($val);
             }
         }
     }
     $this->tpl->assign('requestvars', $getvarsmapped);
     $this->tpl->assign('snapshotformats', GitPHP_Archive::SupportedFormats());
     if ($this->userList && $this->userList->GetCount() > 0) {
         $this->tpl->assign('loginenabled', true);
         if (!empty($_SESSION['gitphpuser'])) {
             $user = $this->userList->GetUser($_SESSION['gitphpuser']);
             if ($user) {
                 $this->tpl->assign('loggedinuser', $user->GetUsername());
             }
         }
     }
     if ($this->log && $this->log->GetEnabled()) {
         $this->tpl->assign('debug', true);
     }
 }
Ejemplo n.º 5
0
 /**
  * Instantiate
  *
  * Instantiates the singleton instance
  *
  * @access public
  * @static
  * @param string $locale locale to instantiate
  * @return boolean true if resource provider was instantiated successfully
  */
 public static function Instantiate($locale)
 {
     self::$instance = null;
     self::$currentLocale = '';
     $reader = null;
     if (!($locale == 'en_US' || $locale == 'en')) {
         $reader = new FileReader(GITPHP_LOCALEDIR . $locale . '/gitphp.mo');
         if (!$reader) {
             return false;
         }
     }
     self::$instance = new gettext_reader($reader);
     self::$currentLocale = $locale;
     return true;
 }