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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | <?php /** * GitPHP Controller ProjectList * * Controller for listing projects * * @author Christopher Han <xiphux@gmail.com> * @copyright Copyright (c) 2010 Christopher Han * @package GitPHP * @subpackage Controller */ /** * ProjectList controller class * * @package GitPHP * @subpackage Controller */ class GitPHP_Controller_ProjectList extends GitPHP_ControllerBase { /** * __construct * * Constructor * * @access public * @return controller */ public function __construct() { parent::__construct(); } /** * GetTemplate * * Gets the template for this controller * * @access protected * @return string template filename */ protected function GetTemplate() { if (isset($this->params['opml']) && ($this->params['opml'] === true)) { return 'opml.tpl'; } else if (isset($this->params['txt']) && ($this->params['txt'] === true)) { return 'projectindex.tpl'; } return 'projectlist.tpl'; } /** * GetCacheKey * * Gets the cache key for this controller * * @access protected * @return string cache key */ protected function GetCacheKey() { if (isset($this->params['opml']) && ($this->params['opml'] === true)) { return ''; } else if (isset($this->params['txt']) && ($this->params['txt'] === true)) { return ''; } return $this->params['order'] . '|' . (isset($this->params['search']) ? $this->params['search'] : ''); } /** * GetName * * Gets the name of this controller's action * * @access public * @param boolean $local true if caller wants the localized action name * @return string action name */ public function GetName($local = false) { if (isset($this->params['opml']) && ($this->params['opml'] === true)) { if ($local) { return __('opml'); } return 'opml'; } else if (isset($this->params['txt']) && ($this->params['txt'] === true)) { if ($local) { return __('project index'); } return 'project index'; } if ($local) { return __('projects'); } return 'projects'; } /** * ReadQuery * * Read query into parameters * * @access protected */ protected function ReadQuery() { if (isset($_GET['o'])) $this->params['order'] = $_GET['o']; else $this->params['order'] = 'project'; if (isset($_GET['s'])) $this->params['search'] = $_GET['s']; } /** * LoadHeaders * * Loads headers for this template * * @access protected */ protected function LoadHeaders() { if (isset($this->params['opml']) && ($this->params['opml'] === true)) { $this->headers[] = "Content-type: text/xml; charset=UTF-8"; GitPHP_Log::GetInstance()->SetEnabled(false); } else if (isset($this->params['txt']) && ($this->params['txt'] === true)) { $this->headers[] = "Content-type: text/plain; charset=utf-8"; $this->headers[] = "Content-Disposition: inline; filename=\"index.aux\""; GitPHP_Log::GetInstance()->SetEnabled(false); } } /** * LoadData * * Loads data for this template * * @access protected */ protected function LoadData() { $this->tpl->assign('order', $this->params['order']); $projectList = GitPHP_ProjectList::GetInstance(); $projectList->Sort($this->params['order']); if ((empty($this->params['opml']) || ($this->params['opml'] !== true)) && (empty($this->params['txt']) || ($this->params['txt'] !== true)) && (!empty($this->params['search']))) { $this->tpl->assign('search', $this->params['search']); $matches = $projectList->Filter($this->params['search']); if (count($matches) > 0) { $this->tpl->assign('projectlist', $matches); } } else { if ($projectList->Count() > 0) $this->tpl->assign('projectlist', $projectList); } } } |