/** * Gets the object name * * @return string name */ public function GetName() { if (!empty($this->path)) { return GitPHP_Util::BaseName($this->path); } return ''; }
public function testBaseNameWin() { if (!GitPHP_Util::IsWindows()) { $this->markTestSkipped(); } $this->assertEquals('file', GitPHP_Util::BaseName('some\\path\\to\\file')); $this->assertEquals('file', GitPHP_Util::BaseName('some\\path\\to\\file\\')); $this->assertEquals('file', GitPHP_Util::BaseName('some\\path\\to\\file.ext', '.ext')); $this->assertEquals('.extfile', GitPHP_Util::BaseName('some\\path\\to\\.extfile.ext', '.ext')); }
/** * Loads headers for this template */ protected function LoadHeaders() { if ($this->Plain()) { $this->DisableLogging(); $this->preserveWhitespace = true; // XXX: Nasty hack to cache headers if (!$this->tpl->isCached('blobheaders.tpl', $this->GetFullCacheKey())) { if (isset($this->params['file'])) { $saveas = GitPHP_Util::BaseName($this->params['file']); } else { $saveas = $this->params['hash'] . ".txt"; } $headers = array(); $mime = null; if ($this->config->GetValue('filemimetype')) { if (!isset($this->params['hash']) && isset($this->params['file'])) { $commit = $this->GetProject()->GetCommit($this->params['hashbase']); $this->params['hash'] = $commit->GetTree()->PathToHash($this->params['file']); if (empty($this->params['hash'])) { throw new GitPHP_FileNotFoundException($this->params['file']); } } $blob = $this->GetProject()->GetObjectManager()->GetBlob($this->params['hash']); if (!empty($this->params['file'])) { $blob->SetPath($this->params['file']); } $mimeReader = new GitPHP_FileMimeTypeReader($blob, $this->GetMimeStrategy()); $mime = trim($mimeReader->GetMimeType()); } if ($mime) { $headers[] = "Content-type: {$mime}; charset=UTF-8"; } else { $headers[] = "Content-type: text/plain; charset=UTF-8"; } $headers[] = "Content-disposition: inline; filename=\"" . $saveas . "\""; $this->tpl->assign("blobheaders", serialize($headers)); } $out = $this->tpl->fetch('blobheaders.tpl', $this->GetFullCacheKey()); $this->headers = unserialize(trim($out)); } else { parent::LoadHeaders(); } }
/** * Loads data for this template */ protected function LoadData() { $head = $this->GetProject()->GetHeadCommit(); $data = null; if ($this->params['graphtype'] == 'commitactivity') { $data = array(); $commits = explode("\n", $this->exe->Execute($this->GetProject()->GetPath(), 'rev-list', array('--format=format:"%H %ct"', $head->GetHash()))); foreach ($commits as $commit) { if (preg_match('/^([0-9a-fA-F]{40}) ([0-9]+)$/', $commit, $regs)) { $data[] = array('CommitEpoch' => (int) $regs[2]); } } } else { if ($this->params['graphtype'] == 'languagedist') { $data = array(); include_once GITPHP_GESHIDIR . "geshi.php"; $geshi = new GeSHi("", 'php'); $files = explode("\n", $this->exe->Execute($this->GetProject()->GetPath(), 'ls-tree', array('-r', '--name-only', $head->GetTree()->GetHash()))); foreach ($files as $file) { $filename = GitPHP_Util::BaseName($file); $lang = GitPHP_Util::GeshiFilenameToLanguage($filename); if (empty($lang)) { $lang = $geshi->get_language_name_from_extension(substr(strrchr($filename, '.'), 1)); if (empty($lang)) { $lang = 'Other'; } } if (!empty($lang) && $lang !== 'Other') { $fulllang = $geshi->get_language_fullname($lang); if (!empty($fulllang)) { $lang = $fulllang; } } if (isset($data[$lang])) { $data[$lang]++; } else { $data[$lang] = 1; } } } } $this->tpl->assign('data', json_encode($data)); }