Example #1
0
if (!function_exists('mb_orig_substr')) {
    function mb_orig_substr($str, $offset, $len = null)
    {
        return isset($len) ? substr($str, $offset, $len) : substr($str, $offset);
    }
}
/**
 * Version header
 */
include GITPHP_INCLUDEDIR . 'version.php';
/**
 * Autoload setup
 */
require GITPHP_INCLUDEDIR . 'AutoLoader.class.php';
spl_autoload_register(array('GitPHP_AutoLoader', 'AutoLoad'));
$router = new GitPHP_Router();
try {
    $controller = $router->GetController();
    if ($controller) {
        $controller->Initialize();
        $controller->RenderHeaders();
        $controller->Render();
    }
} catch (Exception $e) {
    $messageController = $router->GetMessageController();
    $messageController->Initialize();
    if (!$e instanceof GitPHP_MessageException) {
        $config = $messageController->GetConfig();
        if ($config && $config->GetValue('debug')) {
            throw $e;
        }
 /**
  * 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);
     }
 }
Example #3
0
 /**
  * Generate a url
  *
  * @param array $params request parameters
  * @param boolean $full true to get full url (include protocol and hostname)
  */
 public function GetUrl($params = array(), $full = false)
 {
     if ($full) {
         $baseurl = $this->fullurl;
     } else {
         $baseurl = $this->baseurl;
     }
     if ($this->cleanurl) {
         if (substr_compare($baseurl, 'index.php', -9) === 0) {
             $baseurl = dirname($baseurl);
         }
         $baseurl = GitPHP_Util::AddSlash($baseurl, false);
     } else {
         if (substr_compare($baseurl, 'index.php', -9) !== 0) {
             $baseurl = GitPHP_Util::AddSlash($baseurl, false);
         }
     }
     if (count($params) < 1) {
         return $baseurl;
     }
     $abbreviate = $this->abbreviate;
     if ($abbreviate && !empty($params['project']) && $params['project'] instanceof GitPHP_Project) {
         if ($params['project']->GetCompat()) {
             $abbreviate = false;
         }
     }
     foreach ($params as $paramname => $paramval) {
         switch ($paramname) {
             case 'hash':
             case 'hashbase':
             case 'hashparent':
             case 'mark':
                 $params[$paramname] = GitPHP_Router::GetHash($paramval, $abbreviate);
                 break;
             case 'tag':
                 $params[$paramname] = GitPHP_Router::GetTag($paramval);
                 break;
             case 'project':
                 $params[$paramname] = GitPHP_Router::GetProject($paramval);
                 break;
         }
     }
     if ($this->cleanurl) {
         if (!empty($params['action'])) {
             switch ($params['action']) {
                 case 'blob':
                 case 'commit':
                 case 'tree':
                 case 'graph':
                 case 'tag':
                     // these actions are plural in clean urls
                     $params['action'] = $params['action'] . 's';
                     break;
             }
         }
         list($queryurl, $exclude) = $this->BuildRoute($params);
         $baseurl .= $queryurl;
         foreach ($exclude as $excludeparam) {
             unset($params[$excludeparam]);
         }
     }
     $querystr = GitPHP_Router::GetQueryString($params);
     if (empty($querystr)) {
         return $baseurl;
     }
     return $baseurl . '?' . $querystr;
 }