PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/include/display.git_blob.php

http://github.com/Upliner/gitphp-glip
PHP | 95 lines | 76 code | 11 blank | 8 comment | 21 complexity | 7731b3a34375feaeb7c99e9a02a9a95d MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * display.git_blob.php
  4. * gitphp: A PHP git repository browser
  5. * Component: Display - blob
  6. *
  7. * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
  8. * Copyright (C) 2009 Michael Vigovsky <xvmv@mail.ru>
  9. */
  10. require_once('glip/lib/glip.php');
  11. require_once('glip.git_read_head.php');
  12. require_once('glip.git_get_hash_by_path.php');
  13. require_once('glip.git_read_commit.php');
  14. require_once('glip.git_path_trees.php');
  15. require_once('glip.read_info_ref.php');
  16. require_once('util.file_mime.php');
  17. function git_blob($projectroot, $project, $hash, $file, $hashbase)
  18. {
  19. global $gitphp_conf,$tpl;
  20. $cachekey = sha1($project) . "|" . $hashbase . "|" . $hash . "|" . sha1($file);
  21. $git = new Git($projectroot . $project);
  22. if (isset($hash)) $hash = $git->revParse($hash);
  23. if (isset($hashbase)) $hashbase = $git->revParse($hashbase);
  24. if (!$tpl->is_cached('blob.tpl',$cachekey)) {
  25. $head = git_read_head($git);
  26. if (!isset($hashbase))
  27. $hashbase = $head;
  28. if (!isset($hash) && isset($file))
  29. $hash = git_get_hash_by_path($git, $git->getObject($hashbase),$file,"blob");
  30. $catout = $git->getObject($hash)->data;
  31. $tpl->assign("hash",sha1_hex($hash));
  32. $tpl->assign("hashbase",sha1_hex($hashbase));
  33. $tpl->assign("head", sha1_hex($head));
  34. if ($co = git_read_commit($git, $hashbase)) {
  35. $tpl->assign("fullnav",TRUE);
  36. $refs = read_info_ref($git);
  37. $tpl->assign("tree",$co['tree']);
  38. $tpl->assign("title",$co['title']);
  39. if (isset($file))
  40. $tpl->assign("file",$file);
  41. if (isset($refs[$hashbase]))
  42. $tpl->assign("hashbaseref",$refs[$hashbase]);
  43. }
  44. $paths = git_path_trees($git, $git->getObject($hashbase), $file);
  45. $tpl->assign("paths",$paths);
  46. if ($gitphp_conf['filemimetype']) {
  47. $mime = file_mime($catout,$file);
  48. if ($mime)
  49. $mimetype = strtok($mime, "/");
  50. }
  51. if ($mimetype == "image") {
  52. $tpl->assign("mime", $mime);
  53. $tpl->assign("data", base64_encode($catout));
  54. } else {
  55. $usedgeshi = $gitphp_conf['geshi'];
  56. if ($usedgeshi) {
  57. $usedgeshi = FALSE;
  58. include_once($gitphp_conf['geshiroot'] . "geshi.php");
  59. if (class_exists("GeSHi")) {
  60. $geshi = new GeSHi("",'php');
  61. if ($geshi) {
  62. $lang = "";
  63. if (isset($file))
  64. $lang = $geshi->get_language_name_from_extension(substr(strrchr($file,'.'),1));
  65. if (isset($lang) && (strlen($lang) > 0)) {
  66. $geshi->set_source($catout);
  67. $geshi->set_language($lang);
  68. $geshi->set_header_type(GESHI_HEADER_DIV);
  69. $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
  70. $tpl->assign("geshiout",$geshi->parse_code());
  71. $usedgeshi = TRUE;
  72. }
  73. }
  74. }
  75. }
  76. if (!$usedgeshi) {
  77. $lines = explode("\n",$catout);
  78. $tpl->assign("lines",$lines);
  79. }
  80. }
  81. }
  82. $tpl->display('blob.tpl', $cachekey);
  83. }
  84. ?>