5 * Copyright 2004 (c) Dominik Haas, GForge Team
6 * http://fusionforge.org
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once $gfcommon.'include/pre.php';
25 require_once $gfwww.'search/include/renderers/HtmlGroupSearchRenderer.class.php';
26 require_once $gfwww.'search/include/renderers/ForumsHtmlSearchRenderer.class.php';
27 require_once $gfwww.'search/include/renderers/TrackersHtmlSearchRenderer.class.php';
28 require_once $gfwww.'search/include/renderers/TasksHtmlSearchRenderer.class.php';
29 require_once $gfwww.'search/include/renderers/DocsHtmlSearchRenderer.class.php';
30 require_once $gfwww.'search/include/renderers/FrsHtmlSearchRenderer.class.php';
31 require_once $gfwww.'search/include/renderers/NewsHtmlSearchRenderer.class.php';
33 class FullProjectHtmlSearchRenderer extends HtmlGroupSearchRenderer {
43 * the words to search for
50 * flag to define whether the result must contain all words or only one of them
52 * @var boolean $isExact
59 * @param string $words words we are searching for
60 * @param int $offset offset
61 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
62 * @param int $groupId group id
65 function FullProjectHtmlSearchRenderer($words, $offset, $isExact, $groupId) {
66 $this->groupId = $groupId;
67 $this->words = $words;
68 $this->isExact = $isExact;
70 $this->HtmlGroupSearchRenderer(SEARCH__TYPE_IS_ADVANCED, $words, $isExact, '', $groupId);
74 * flush - overwrites the flush method from htmlrenderer
82 * writeBody - write the Body of the output
84 function writeBody() {
85 $title = _('Entire project search');
86 site_project_header(array('title' => $title, 'group' => $this->groupId, 'toptab' => ''));
87 echo $this->getResult();
91 * getResult - returns the Body of the output
93 * @return string result of all selected searches
95 function getResult() {
98 $group = group_get_object($this->groupId);
100 if ($group->usesForum()) {
101 $forumsRenderer = new ForumsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
103 if ($group->usesTracker()) {
104 $trackersRenderer = new TrackersHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
106 if ($group->usesPM()) {
107 $tasksRenderer = new TasksHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
109 if ($group->usesDocman()) {
110 $docsRenderer = new DocsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
112 if ($group->usesFRS()) {
113 $frsRenderer = new FrsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
115 if ($group->usesNews()) {
116 $newsRenderer = new NewsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
119 $validLength = (strlen($this->words) >= 3);
121 if (isset($trackersRenderer) && ($validLength || (is_numeric($this->words) && $trackersRenderer->searchQuery->implementsSearchById()))) {
122 $html .= $this->getPartResult($trackersRenderer, 'short_tracker', _('Tracker Search Results'));
125 if (isset($forumsRenderer) && ($validLength || (is_numeric($this->words) && $forumsRenderer->searchQuery->implementsSearchById()))) {
126 $html .= $this->getPartResult($forumsRenderer, 'short_forum', _('Forum Search Results'));
129 if (isset($tasksRenderer) && ($validLength || (is_numeric($this->words) && $tasksRenderer->searchQuery->implementsSearchById()))) {
130 $html .= $this->getPartResult($tasksRenderer, 'short_pm', _('Task Search Results'));
133 if (isset($docsRenderer) && ($validLength || (is_numeric($this->words) && $docsRenderer->searchQuery->implementsSearchById()))) {
134 $html .= $this->getPartResult($docsRenderer, 'short_docman', _('Documentation Search Results'));
137 if (isset($frsRenderer) && ($validLength || (is_numeric($this->words) && $frsRenderer->searchQuery->implementsSearchById()))) {
138 $html .= $this->getPartResult($frsRenderer, 'short_files', _('Files Search Results'));
141 if (isset($newsRenderer) && ($validLength || (is_numeric($this->words) && $newsRenderer->searchQuery->implementsSearchById()))) {
142 $html .= $this->getPartResult($newsRenderer, 'short_news', _('News Search Results'));
145 if (! $html && ! $validLength) {
146 $html .= '<p class="error">'._('Error: search query too short').'</p>';
149 // This is quite complex but the goal is to extract all the
150 // registered plugins to the hook 'search_engines' and call
152 $pluginManager = plugin_manager_get_object();
153 $searchManager = getSearchManager();
154 $engines = $searchManager->getAvailableSearchEngines();
156 if (isset($pluginManager->hooks_to_plugins['full_search_engines'])) {
157 $p_list = $pluginManager->hooks_to_plugins['full_search_engines'];
158 foreach ($p_list as $p_name) {
159 $p_obj = $pluginManager->GetPluginObject($p_name);
160 $name = $p_obj->text;
162 foreach($engines as $e) {
163 if ($e->type == $p_name) {
164 $renderer = $e->getSearchRenderer($this->words,
165 $this->offset, $this->isExact, $this->groupId);
166 $html .= $this->getPartResult($renderer, 'short_'.$p_name,
167 sprintf(_("%s Search Results"), $name));
174 $renderer = new ForumsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
175 $html .= $this->getPartResult($renderer, 'short_forum', _('Forum Search Results'));
177 $renderer = new TrackersHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
178 $html .= $this->getPartResult($renderer, 'short_tracker', _('Tracker Search Results'));
180 $renderer = new TasksHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
181 $html .= $this->getPartResult($renderer, 'short_pm', _('Task Search Results'));
183 $renderer = new DocsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
184 $html .= $this->getPartResult($renderer, 'short_docman', _('Documentation Search Results'));
186 $renderer = new FrsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
187 $html .= $this->getPartResult($renderer, 'short_files', _('Files Search Results'));
189 $renderer = new NewsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
190 $html .= $this->getPartResult($renderer, 'short_news', _('News Search Results'));
193 return $html.'<br />';
197 * getPartResult - returns the result of the given renderer
199 * @return string result of the renderer
201 function getPartResult($renderer, $section, $title='') {
203 $renderer->searchQuery->executeQuery();
208 $result .= '<h2><a name="'.$section.'"></a>'.$title.'</h2>';
210 if ($renderer->searchQuery->getRowsCount() > 0) {
211 $result .= $GLOBALS['HTML']->listTabletop($renderer->tableHeaders);
212 $result .= $renderer->getRows();
213 $result .= $GLOBALS['HTML']->listTableBottom();
214 } elseif(method_exists($renderer, 'getSections') && (count($renderer->getSections($this->groupId)) == 0)) {
215 $result .= '<p>'.sprintf(_('No matches found for <em>%s</em> - No sections available (check your permissions)'), $this->words).'</p>';
217 $result .= '<p>'.sprintf(_('No matches found for <em>%s</em>'), $this->words).'</p>';
225 // c-file-style: "bsd"