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 | <?php /** * Controller for listing projects * * @author Christopher Han <xiphux@gmail.com> * @copyright Copyright (c) 2010 Christopher Han * @package GitPHP * @subpackage Controller */ class GitPHP_Controller_ProjectList extends GitPHP_ControllerBase { /** * Initialize controller */ public function Initialize() { $this->multiProject = true; parent::Initialize(); if ($this->userList && ($this->userList->GetCount() > 0)) { if (!$this->config->GetValue('showrestrictedprojects') || (isset($this->params['opml']) && ($this->params['opml'] === true)) || (isset($this->params['txt']) && ($this->params['txt'] === true))) { $this->projectList->FilterByUser((!empty($_SESSION['gitphpuser']) ? $_SESSION['gitphpuser'] : null)); } } if (empty($this->params['sort'])) $this->params['sort'] = 'project'; } /** * Gets the template for this controller * * @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'; } /** * Gets the cache key for this controller * * @return string cache key */ protected function GetCacheKey() { $cachekey = (!empty($_SESSION['gitphpuser']) ? $_SESSION['gitphpuser'] : ''); if (isset($this->params['opml']) && ($this->params['opml'] === true)) { return $cachekey; } else if (isset($this->params['txt']) && ($this->params['txt'] === true)) { return $cachekey; } $cachekey .= '|' . $this->params['sort'] . '|' . (isset($this->params['search']) ? $this->params['search'] : ''); return $cachekey; } /** * 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 (isset($this->params['opml']) && ($this->params['opml'] === true)) { if ($local && $this->resource) { return $this->resource->translate('opml'); } return 'opml'; } else if (isset($this->params['txt']) && ($this->params['txt'] === true)) { if ($local && $this->resource) { return $this->resource->translate('project index'); } return 'project index'; } if ($local && $this->resource) { return $this->resource->translate('projects'); } return 'projects'; } /** * Loads headers for this template */ protected function LoadHeaders() { if (isset($this->params['opml']) && ($this->params['opml'] === true)) { $this->headers[] = "Content-type: text/xml; charset=UTF-8"; $this->DisableLogging(); $this->preserveWhitespace = true; } 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\""; $this->DisableLogging(); } else { parent::LoadHeaders(); } } /** * Loads data for this template */ protected function LoadData() { $this->tpl->assign('sort', $this->params['sort']); $this->projectList->Sort($this->params['sort']); 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 = $this->projectList->Filter($this->params['search']); if (count($matches) > 0) { $this->tpl->assign('projectlist', $matches); } } else { if ($this->projectList->Count() > 0) $this->tpl->assign('projectlist', $this->projectList); } } } |