Controller_Feed.class.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * Controller for displaying a project's feed
  4. *
  5. * @author Christopher Han <xiphux@gmail.com>
  6. * @author Christian Weiske <cweiske@cweiske.de>
  7. * @copyright Copyright (c) 2010 Christopher Han
  8. * @package GitPHP
  9. * @subpackage Controller
  10. */
  11. class GitPHP_Controller_Feed extends GitPHP_ControllerBase
  12. {
  13. /**
  14. * Number of items to put in feed
  15. *
  16. * @var int
  17. */
  18. const FeedItemCount = 100;
  19. /**
  20. * Rss feed format
  21. *
  22. * @var string
  23. */
  24. const RssFormat = 'rss';
  25. /**
  26. * Atom feed format
  27. *
  28. * @var string
  29. */
  30. const AtomFormat = 'atom';
  31. /**
  32. * Initialize controller
  33. */
  34. public function Initialize()
  35. {
  36. parent::Initialize();
  37. $this->preserveWhitespace = true;
  38. $this->DisableLogging();
  39. }
  40. /**
  41. * Gets the template for this controller
  42. *
  43. * @return string template filename
  44. */
  45. protected function GetTemplate()
  46. {
  47. if ($this->params['format'] == GitPHP_Controller_Feed::RssFormat)
  48. return 'rss.tpl';
  49. else if ($this->params['format'] == GitPHP_Controller_Feed::AtomFormat)
  50. return 'atom.tpl';
  51. }
  52. /**
  53. * Gets the cache key for this controller
  54. *
  55. * @return string cache key
  56. */
  57. protected function GetCacheKey()
  58. {
  59. return '';
  60. }
  61. /**
  62. * Gets the name of this controller's action
  63. *
  64. * @param boolean $local true if caller wants the localized action name
  65. * @return string action name
  66. */
  67. public function GetName($local = false)
  68. {
  69. if ($this->params['format'] == GitPHP_Controller_Feed::RssFormat) {
  70. if ($local && $this->resource)
  71. return $this->resource->translate('rss');
  72. else
  73. return 'rss';
  74. } else if ($this->params['format'] == GitPHP_Controller_Feed::AtomFormat) {
  75. if ($local && $this->resource)
  76. return $this->resource->translate('atom');
  77. else
  78. return 'atom';
  79. }
  80. }
  81. /**
  82. * Loads headers for this template
  83. */
  84. protected function LoadHeaders()
  85. {
  86. if ((!isset($this->params['format'])) || empty($this->params['format'])) {
  87. throw new Exception('A feed format is required');
  88. }
  89. if ($this->params['format'] == GitPHP_Controller_Feed::RssFormat) {
  90. $this->headers[] = "Content-type: application/rss+xml; charset=UTF-8";
  91. } else if ($this->params['format'] == GitPHP_Controller_Feed::AtomFormat) {
  92. $this->headers[] = "Content-type: application/atom+xml; charset=UTF-8";
  93. }
  94. }
  95. /**
  96. * Loads data for this template
  97. */
  98. protected function LoadData()
  99. {
  100. //$compat = $this->GetProject()->GetCompat();
  101. $strategy = null;
  102. //if ($compat) {
  103. $strategy = new GitPHP_LogLoad_Git($this->exe);
  104. //} else {
  105. // $strategy = new GitPHP_LogLoad_Raw();
  106. //}
  107. $log = new GitPHP_Log($this->GetProject(), $this->GetProject()->GetHeadCommit(), $strategy, GitPHP_Controller_Feed::FeedItemCount);
  108. if ($this->config->HasKey('feedfilter')) {
  109. $log->FilterCommits($this->config->GetValue('feedfilter'));
  110. }
  111. $log->FilterOldCommits(48*60*60, 20);
  112. $this->tpl->assign('log', $log);
  113. $this->tpl->assign('gitexe', $this->exe);
  114. }
  115. }