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