Exemplo n.º 1
0
    }
    // For the header's pagenav
    $info = git_get_commit_info($page['project'], $page['commit_id']);
    $page['commit_id'] = $info['h'];
    $page['tree_id'] = $info['tree'];
    $page['pathinfo'] = git_get_path_info($page['project'], $page['commit_id'], $page['path']);
    $page['data'] = fix_encoding(join("\n", run_git($page['project'], "cat-file blob {$page['hash']}")));
    $page['lastlog'] = git_get_commit_info($page['project'], 'HEAD', $page['path']);
    // GeSHi support
    if ($conf['geshi'] && strpos($page['path'], '.')) {
        $old_mask = error_reporting(E_ALL ^ E_NOTICE);
        require_once $conf['geshi_path'];
        $parts = explode('.', $page['path']);
        $ext = array_pop($parts);
        $geshi = new Geshi($page['data']);
        $lang = $geshi->get_language_name_from_extension($ext);
        if (strlen($lang) > 0) {
            $geshi->set_language($lang);
            if (is_int($conf['geshi_line_numbers'])) {
                if ($conf['geshi_line_numbers'] == 0) {
                    $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
                } else {
                    $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, $conf['geshi_line_numbers']);
                }
            }
            $page['html_data'] = $geshi->parse_code();
        }
        error_reporting($old_mask);
    }
} elseif (in_array($action, array_keys(VGPlugin::$plugin_actions))) {
    VGPlugin::$plugin_actions[$action]->action($action);
Exemplo n.º 2
0
function git_blob($projectroot, $project, $hash, $file, $hashbase)
{
    global $gitphp_conf, $tpl;
    $cachekey = sha1($project) . "|" . $hashbase . "|" . $hash . "|" . sha1($file);
    if (!$tpl->is_cached('blob.tpl', $cachekey)) {
        $head = git_read_head($projectroot . $project);
        if (!isset($hashbase)) {
            $hashbase = $head;
        }
        if (!isset($hash) && isset($file)) {
            $hash = git_get_hash_by_path($projectroot . $project, $hashbase, $file, "blob");
        }
        $catout = git_cat_file($projectroot . $project, $hash);
        $tpl->assign("hash", $hash);
        $tpl->assign("hashbase", $hashbase);
        $tpl->assign("head", $head);
        if ($co = git_read_commit($projectroot . $project, $hashbase)) {
            $tpl->assign("fullnav", TRUE);
            $refs = read_info_ref($projectroot . $project);
            $tpl->assign("tree", $co['tree']);
            $tpl->assign("title", $co['title']);
            if (isset($file)) {
                $tpl->assign("file", $file);
            }
            if ($hashbase == "HEAD") {
                if (isset($refs[$head])) {
                    $tpl->assign("hashbaseref", $refs[$head]);
                }
            } else {
                if (isset($refs[$hashbase])) {
                    $tpl->assign("hashbaseref", $refs[$hashbase]);
                }
            }
        }
        $paths = git_path_trees($projectroot . $project, $hashbase, $file);
        $tpl->assign("paths", $paths);
        if ($gitphp_conf['filemimetype']) {
            $mime = file_mime($catout, $file);
            if ($mime) {
                $mimetype = strtok($mime, "/");
            }
        }
        if ($mimetype == "image") {
            $tpl->assign("mime", $mime);
            $tpl->assign("data", base64_encode($catout));
        } else {
            $usedgeshi = $gitphp_conf['geshi'];
            if ($usedgeshi) {
                $usedgeshi = FALSE;
                include_once $gitphp_conf['geshiroot'] . "geshi.php";
                if (class_exists("GeSHi")) {
                    $geshi = new GeSHi($catout, $lang = Geshi::get_language_name_from_extension(substr(strrchr($file, '.'), 1)));
                    if ($geshi) {
                        $lang = "";
                        if (isset($file)) {
                            $lang = $geshi->get_language_name_from_extension(substr(strrchr($file, '.'), 1));
                        }
                        if (isset($lang) && strlen($lang) > 0) {
                            #$geshi->set_source($catout);
                            #$geshi->set_language($lang);
                            #$geshi->set_header_type(GESHI_HEADER_DIV);
                            #$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
                            $tpl->assign("geshiout", $geshi->parse_code());
                            $usedgeshi = TRUE;
                        }
                    }
                }
            }
            if (!$usedgeshi) {
                $lines = explode("\n", $catout);
                $tpl->assign("lines", $lines);
            }
        }
    }
    $tpl->display('blob.tpl', $cachekey);
}
Exemplo n.º 3
0
 /**
  * Display a file using appropriate highlighting
  *
  * @return void
  */
 public function showAction()
 {
     include_once 'geshi/geshi.php';
     $this->view->project = $this->_project;
     $config = new USVN_Config_Ini(USVN_CONFIG_FILE, USVN_CONFIG_SECTION);
     $project_name = str_replace(USVN_URL_SEP, '/', $this->_project->name);
     $svn_file_path = $this->getRequest()->getParam('file');
     $this->view->path = $svn_file_path;
     $local_file_path = USVN_SVNUtils::getRepositoryPath($config->subversion->path . "/svn/" . $project_name . "/" . $svn_file_path);
     $file_ext = pathinfo($svn_file_path, PATHINFO_EXTENSION);
     $revision = $this->getRequest()->getParam('rev');
     $file_rev = '';
     if (!empty($revision)) {
         if (is_numeric($revision) && $revision > 0) {
             $cmd = USVN_SVNUtils::svnCommand("log --non-interactive --revision {$revision} --quiet {$local_file_path}");
             $verif = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($cmd, $return);
             if (!$return) {
                 $this->view->revision = $revision;
                 $file_rev = '--revision ' . $revision;
             }
         }
     }
     if (empty($file_rev)) {
         $cmd = USVN_SVNUtils::svnCommand("info {$local_file_path}");
         $infos = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($cmd, $return);
         if (preg_match_all('#^([^:]+): (.*)$#m', $infos, $tmp)) {
             $infos = array();
             foreach ($tmp[1] as $k => $v) {
                 $infos[$v] = $tmp[2][$k];
             }
             $this->view->revision = $infos['Last Changed Rev'];
             if ($revision) {
                 $this->view->message = T_("The requested revision does not exist. Switching to the last changed revision.");
             }
         }
     }
     $cmd = USVN_SVNUtils::svnCommand("log --non-interactive --quiet {$local_file_path}");
     $revs = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($cmd, $return);
     if (preg_match_all('#^r([0-9]+) \\|#m', $revs, $tmp)) {
         $revs = array();
         $this->view->prev_revision = NULL;
         $this->view->next_revision = NULL;
         foreach ($tmp[1] as $k => $rev) {
             if ($this->view->prev_revision === NULL && intval($rev) < intval($this->view->revision)) {
                 $this->view->prev_revision = $rev;
             }
             if ($rev > $this->view->revision) {
                 $this->view->next_revision = $rev;
             }
             $revs[] = $rev;
         }
         $this->view->select_revisions = $revs;
     }
     $cmd = USVN_SVNUtils::svnCommand("cat --non-interactive {$file_rev} {$local_file_path}");
     $source = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($cmd, $return);
     if ($return) {
         throw new USVN_Exception(T_("Can't read from subversion repository.\nCommand:\n%s\n\nError:\n%s"), $cmd, $message);
     } else {
         $this->view->color_view = $this->getRequest()->getParam('color');
         $this->view->diff_view = $this->getRequest()->getParam('diff');
         $this->view->diff_revision = $this->getRequest()->getParam('drev');
         if ($this->view->diff_revision >= $this->view->revision) {
             $this->view->diff_revision = $this->view->prev_revision;
         }
         if ($this->getRequest()->getParam('post') === NULL) {
             $this->view->color_view = 1;
         }
         $geshi = new Geshi();
         $lang_name = $geshi->get_language_name_from_extension($file_ext);
         $this->view->language = $lang_name;
         $geshi->set_language($this->view->color_view ? $lang_name : NULL, true);
         $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
         if ($this->view->diff_view && ($this->view->diff_revision || $this->view->prev_revision)) {
             $d_revs = ($this->view->diff_revision ? $this->view->diff_revision : $this->view->prev_revision) . ':' . $this->view->revision;
             $cmd = USVN_SVNUtils::svnCommand("diff --non-interactive --revision {$d_revs} {$local_file_path}");
             $diff = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($cmd, $return);
             if ($return) {
                 $this->view->message = T_('The requested diff revision does not exist.');
             } else {
                 $new_source = array();
                 $source = explode("\n", $source);
                 array_pop($source);
                 // Skip the final "\n"
                 $diff = explode("\n", $diff);
                 array_pop($diff);
                 // Skip the final "\n"
                 $source_line = NULL;
                 $count_line = 0;
                 $diff_lines = array();
                 while (($line = array_shift($diff)) !== NULL) {
                     $line = trim($line);
                     if (preg_match('#^@@ \\-[0-9,]+ \\+([0-9]+),[0-9]+ @@$#', $line, $tmp)) {
                         if ($source_line === NULL) {
                             $source_line = 1;
                         }
                         while (intval($source_line) < intval($tmp[1])) {
                             array_push($new_source, array_shift($source));
                             $source_line++;
                             $count_line++;
                         }
                         continue;
                     }
                     if ($source_line !== NULL) {
                         $diff_char = substr($line, 0, 1);
                         if ($diff_char == '\\') {
                             continue;
                         } elseif ($diff_char == '-') {
                             array_push($new_source, substr($line, 1));
                             $diff_lines[$count_line] = '-';
                         } else {
                             if ($diff_char == '+') {
                                 $diff_lines[$count_line] = '+';
                             }
                             array_push($new_source, array_shift($source));
                             $source_line++;
                         }
                         $count_line++;
                     }
                 }
                 if (count($source)) {
                     $new_source = array_merge($new_source, $source);
                 }
                 $source = implode("\n", $new_source);
                 unset($new_source);
                 $this->view->diff_lines = $diff_lines;
             }
         }
         $geshi->set_source($source);
         $geshi->set_header_type(GESHI_HEADER_DIV);
         $this->view->highlighted_source = $geshi->parse_code();
         if ($this->view->diff_view) {
             if (preg_match('#^<div ([^>]*)><ol>(.*)</ol></div>(\\s*)$#s', $this->view->highlighted_source, $tmp)) {
                 $this->view->diff_div = $tmp[1];
                 $this->view->highlighted_source = $tmp[2];
             }
         }
     }
 }