/** * Open a descriptor for this archive * * @param GitPHP_Archive $archive archive * @return boolean true on success */ public function Open($archive) { if (!$archive) { return false; } if ($this->handle) { return true; } $args = array(); $args[] = '--format=tar'; $args[] = "--prefix='" . $archive->GetPrefix() . "'"; $args[] = $archive->GetObject()->GetHash(); $this->handle = $this->exe->Open($archive->GetProject()->GetPath(), GIT_ARCHIVE, $args); // hack to get around the fact that gzip files // can't be compressed on the fly and the php zlib stream // doesn't seem to daisy chain with any non-file streams $this->tempfile = tempnam(sys_get_temp_dir(), "GitPHP"); $mode = 'wb'; if ($this->compressLevel) { $mode .= $this->compressLevel; } $temphandle = gzopen($this->tempfile, $mode); if ($temphandle) { while (!feof($this->handle)) { gzwrite($temphandle, fread($this->handle, 1048576)); } gzclose($temphandle); $temphandle = fopen($this->tempfile, 'rb'); } if ($this->handle) { pclose($this->handle); } $this->handle = $temphandle; return $this->handle !== false; }
/** * Open a descriptor for this archive * * @param GitPHP_Archive $archive archive * @return boolean true on success */ public function Open($archive) { if (!$archive) { return false; } if ($this->handle) { return true; } $args = array(); $args[] = '--format=tar'; $args[] = "--prefix='" . $archive->GetPrefix() . "'"; $args[] = $archive->GetObject()->GetHash(); $this->handle = $this->exe->Open($archive->GetProject()->GetPath(), GIT_ARCHIVE, $args); return $this->handle !== false; }
/** * 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); } }
/** * SupportedFormats * * Gets the supported formats for the archiver * * @access public * @static * @return array array of formats mapped to extensions */ public static function SupportedFormats() { $formats = array(); $formats[GITPHP_COMPRESS_TAR] = GitPHP_Archive::FormatToExtension(GITPHP_COMPRESS_TAR); // TODO check for git > 1.4.3 for zip $formats[GITPHP_COMPRESS_ZIP] = GitPHP_Archive::FormatToExtension(GITPHP_COMPRESS_ZIP); if (function_exists('bzcompress')) { $formats[GITPHP_COMPRESS_BZ2] = GitPHP_Archive::FormatToExtension(GITPHP_COMPRESS_BZ2); } if (function_exists('gzencode')) { $formats[GITPHP_COMPRESS_GZ] = GitPHP_Archive::FormatToExtension(GITPHP_COMPRESS_GZ); } return $formats; }
/** * 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()); }
/** * Initialize route map */ private function InitializeRoutes() { // project view $projectroute = new GitPHP_Route('projects/:project', array('project' => '[^\\?]+')); // project-specific action with hash and output method $this->routes[] = new GitPHP_Route(':action/:hash/:output', array('action' => 'blobs', 'hash' => '[0-9A-Fa-f]{4,40}|HEAD', 'output' => 'plain'), array(), $projectroute); // project-specific action with hash $this->routes[] = new GitPHP_Route(':action/:hash', array('action' => 'commits|trees|blobs|search|snapshot|commitdiff|blobdiff|blame', 'hash' => '[0-9A-Fa-f]{4,40}|HEAD'), array(), $projectroute); // project-specific action with hash or ref $this->routes[] = new GitPHP_Route(':action/:hash', array('action' => 'shortlog|log', 'hash' => '[^\\?]+'), array(), $projectroute); // map heads to shortlog $this->routes[] = new GitPHP_Route(':action/:hash', array('action' => 'heads', 'hash' => '[^\\?]+'), array('action' => 'shortlog'), $projectroute); // project-specific graphs $this->routes[] = new GitPHP_Route(':action/:graphtype', array('action' => 'graphs', 'graphtype' => '[a-z]+'), array(), $projectroute); // project-specific tag $this->routes[] = new GitPHP_Route(':action/:tag', array('action' => 'tags', 'tag' => '[^\\?]+'), array(), $projectroute); $formats = GitPHP_Archive::SupportedFormats(); if (count($formats) > 0) { $formatconstraint = implode("|", array_keys($formats)); // project specific snapshot format with hash $this->routes[] = new GitPHP_Route(':format/:hash', array('format' => $formatconstraint, 'hash' => '[0-9A-Fa-f]{4,40}|HEAD'), array('action' => 'snapshot'), $projectroute); // project specific snapshot format $this->routes[] = new GitPHP_Route(':format', array('format' => $formatconstraint), array('action' => 'snapshot'), $projectroute); } // project-specific action only $this->routes[] = new GitPHP_Route(':action', array('action' => 'tags|heads|shortlog|log|search|atom|rss|snapshot|commits|graphs|trees|blobs|history|commitdiff|blobdiff'), array(), $projectroute); $this->routes[] = $projectroute; // non-project action $this->routes[] = new GitPHP_Route(':action', array('action' => 'opml|projectindex|login|logout')); usort($this->routes, array('GitPHP_Route', 'CompareRoute')); }
/** * Gets the cached snapshot file name * * @return string cached file name */ private function CachedSnapshotFile() { $key = ($this->archive->GetObject() ? $this->archive->GetObject()->GetHash() : '') . '|' . (isset($this->params['file']) ? $this->params['file'] : '') . '|' . (isset($this->params['prefix']) ? $this->params['prefix'] : ''); $cachefile = sha1($key) . '-' . $this->archive->GetFilename(); return $cachefile; }