/**
  * 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));
 }
 /**
  * Loads data for this template
  */
 protected function LoadData()
 {
     $head = $this->GetProject()->GetHeadCommit();
     $this->tpl->assign('head', $head);
     $commit = $this->GetProject()->GetCommit($this->params['hashbase']);
     $this->tpl->assign('commit', $commit);
     if (!isset($this->params['hash']) && isset($this->params['file'])) {
         $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 ($this->params['file']) {
         $blob->SetPath($this->params['file']);
     }
     $blob->SetCommit($commit);
     $this->tpl->assign('blob', $blob);
     $blame = new GitPHP_FileBlame($this->GetProject(), $commit, $this->params['file'], $this->exe);
     $this->tpl->assign('blame', $blame->GetBlame());
     if (isset($this->params['output']) && $this->params['output'] == 'js') {
         return;
     }
     $this->tpl->assign('tree', $commit->GetTree());
     if ($this->config->GetValue('geshi')) {
         include_once GITPHP_GESHIDIR . "geshi.php";
         if (class_exists('GeSHi')) {
             $geshi = new GeSHi("", 'php');
             if ($geshi) {
                 $lang = GitPHP_Util::GeshiFilenameToLanguage($blob->GetName());
                 if (empty($lang)) {
                     $lang = $geshi->get_language_name_from_extension(substr(strrchr($blob->GetName(), '.'), 1));
                 }
                 if (!empty($lang)) {
                     $geshi->enable_classes();
                     $geshi->enable_strict_mode(GESHI_MAYBE);
                     $geshi->set_source($blob->GetData());
                     $geshi->set_language($lang);
                     $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
                     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
                     $output = $geshi->parse_code();
                     $bodystart = strpos($output, '<td');
                     $bodyend = strrpos($output, '</tr>');
                     if ($bodystart !== false && $bodyend !== false) {
                         $geshihead = substr($output, 0, $bodystart);
                         $geshifoot = substr($output, $bodyend);
                         $geshibody = substr($output, $bodystart, $bodyend - $bodystart);
                         $this->tpl->assign('geshihead', $geshihead);
                         $this->tpl->assign('geshibody', $geshibody);
                         $this->tpl->assign('geshifoot', $geshifoot);
                         $this->tpl->assign('geshicss', $geshi->get_stylesheet());
                         $this->tpl->assign('geshi', true);
                     }
                 }
             }
         }
     }
 }
 /**
  * Loads data for this template
  */
 protected function LoadData()
 {
     $commit = $this->GetProject()->GetCommit($this->params['hashbase']);
     $this->tpl->assign('commit', $commit);
     $tree = $commit->GetTree();
     $this->tpl->assign('tree', $commit->GetTree());
     if (!isset($this->params['hash']) && isset($this->params['file'])) {
         $this->params['hash'] = $tree->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']);
     }
     $blob->SetCommit($commit);
     $this->tpl->assign('blob', $blob);
     if ($this->Plain()) {
         return;
     }
     $head = $this->GetProject()->GetHeadCommit();
     $this->tpl->assign('head', $head);
     if ($this->config->GetValue('filemimetype')) {
         $mimeReader = new GitPHP_FileMimeTypeReader($blob, $this->GetMimeStrategy());
         $mimetype = $mimeReader->GetMimeType(true);
         if ($mimetype == 'image') {
             $this->tpl->assign('datatag', true);
             $this->tpl->assign('mime', $mimeReader->GetMimeType());
             $this->tpl->assign('data', base64_encode($blob->GetData()));
             return;
         }
     }
     if ($this->config->GetValue('geshi')) {
         include_once GITPHP_GESHIDIR . "geshi.php";
         if (class_exists('GeSHi')) {
             $geshi = new GeSHi("", 'php');
             if ($geshi) {
                 $lang = GitPHP_Util::GeshiFilenameToLanguage($blob->GetName());
                 if (empty($lang)) {
                     $lang = $geshi->get_language_name_from_extension(substr(strrchr($blob->GetName(), '.'), 1));
                 }
                 if (!empty($lang)) {
                     $geshi->enable_classes();
                     $geshi->enable_strict_mode(GESHI_MAYBE);
                     $geshi->set_source($blob->GetData());
                     $geshi->set_language($lang);
                     $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
                     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
                     $geshi->set_overall_id('blobData');
                     $this->tpl->assign('geshiout', $geshi->parse_code());
                     $this->tpl->assign('geshicss', $geshi->get_stylesheet());
                     $this->tpl->assign('geshi', true);
                     return;
                 }
             }
         }
     }
     $this->tpl->assign('bloblines', $blob->GetData(true));
 }
Beispiel #4
0
 public function testGeshiFilename()
 {
     $this->assertNull(GitPHP_Util::GeshiFilenameToLanguage('unknownfile'));
     $this->assertEquals('make', GitPHP_Util::GeshiFilenameToLanguage('Makefile'));
     $this->assertEquals('make', GitPHP_Util::GeshiFilenameToLanguage('makefile'));
 }