Controller_Blobdiff.class.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Controller for displaying a blobdiff
  4. *
  5. * @author Christopher Han <xiphux@gmail.com>
  6. * @copyright Copyright (c) 2010 Christopher Han
  7. * @package GitPHP
  8. * @subpackage Controller
  9. */
  10. class GitPHP_Controller_Blobdiff extends GitPHP_Controller_DiffBase
  11. {
  12. /**
  13. * Gets the template for this controller
  14. *
  15. * @return string template filename
  16. */
  17. protected function GetTemplate()
  18. {
  19. if ($this->Plain()) {
  20. return 'blobdiffplain.tpl';
  21. }
  22. return 'blobdiff.tpl';
  23. }
  24. /**
  25. * Gets the cache key for this controller
  26. *
  27. * @return string cache key
  28. */
  29. protected function GetCacheKey()
  30. {
  31. return (isset($this->params['hashbase']) ? $this->params['hashbase'] : '') . '|' . (isset($this->params['hash']) ? $this->params['hash'] : '') . '|' . (isset($this->params['hashparent']) ? $this->params['hashparent'] : '') . '|' . (isset($this->params['file']) ? sha1($this->params['file']) : '') . '|' . (isset($this->params['sidebyside']) && ($this->params['sidebyside'] === true) ? '1' : '');
  32. }
  33. /**
  34. * Gets the name of this controller's action
  35. *
  36. * @param boolean $local true if caller wants the localized action name
  37. * @return string action name
  38. */
  39. public function GetName($local = false)
  40. {
  41. if ($local && $this->resource) {
  42. return $this->resource->translate('blobdiff');
  43. }
  44. return 'blobdiff';
  45. }
  46. /**
  47. * Loads headers for this template
  48. */
  49. protected function LoadHeaders()
  50. {
  51. parent::LoadHeaders();
  52. if ($this->Plain()) {
  53. $this->preserveWhitespace = true;
  54. }
  55. }
  56. /**
  57. * Loads data for this template
  58. */
  59. protected function LoadData()
  60. {
  61. if (isset($this->params['file']))
  62. $this->tpl->assign('file', $this->params['file']);
  63. $filediff = $this->GetProject()->GetObjectManager()->GetFileDiff($this->params['hashparent'], $this->params['hash']);
  64. $this->tpl->assign('filediff', $filediff);
  65. if ($this->Plain()) {
  66. return;
  67. }
  68. if (isset($this->params['sidebyside']) && ($this->params['sidebyside'] === true)) {
  69. $this->tpl->assign('sidebyside', true);
  70. }
  71. $commit = $this->GetProject()->GetCommit($this->params['hashbase']);
  72. $this->tpl->assign('commit', $commit);
  73. $blobparent = $this->GetProject()->GetObjectManager()->GetBlob($this->params['hashparent']);
  74. $blobparent->SetCommit($commit);
  75. $blobparent->SetPath($this->params['file']);
  76. $this->tpl->assign('blobparent', $blobparent);
  77. $blob = $this->GetProject()->GetObjectManager()->GetBlob($this->params['hash']);
  78. $blob->SetPath($this->params['file']);
  79. $this->tpl->assign('blob', $blob);
  80. $tree = $commit->GetTree();
  81. $this->tpl->assign('tree', $tree);
  82. }
  83. }