5 * Copyright 2004 (c) Dominik Haas, GForge Team
6 * Copyright 2012, Franck Villaume - TrivialDev
7 * http://fusionforge.org
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once $gfcommon.'include/pre.php';
26 require_once $gfwww.'search/include/renderers/HtmlGroupSearchRenderer.class.php';
27 require_once $gfwww.'search/include/renderers/ForumsHtmlSearchRenderer.class.php';
28 require_once $gfwww.'search/include/renderers/TrackersHtmlSearchRenderer.class.php';
29 require_once $gfwww.'search/include/renderers/TasksHtmlSearchRenderer.class.php';
30 require_once $gfwww.'search/include/renderers/DocsHtmlSearchRenderer.class.php';
31 require_once $gfwww.'search/include/renderers/FrsHtmlSearchRenderer.class.php';
32 require_once $gfwww.'search/include/renderers/NewsHtmlSearchRenderer.class.php';
34 class FullProjectHtmlSearchRenderer extends HtmlGroupSearchRenderer {
44 * the words to search for
51 * flag to define whether the result must contain all words or only one of them
53 * @var boolean $isExact
60 * @param string $words words we are searching for
61 * @param int $offset offset
62 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
63 * @param int $groupId group id
66 function FullProjectHtmlSearchRenderer($words, $offset, $isExact, $groupId) {
67 $this->groupId = $groupId;
68 $this->words = $words;
69 $this->isExact = $isExact;
71 $this->HtmlGroupSearchRenderer(SEARCH__TYPE_IS_ADVANCED, $words, $isExact, '', $groupId);
75 * flush - overwrites the flush method from htmlrenderer
83 * writeBody - write the Body of the output
85 function writeBody() {
86 $title = _('Entire project search');
87 site_project_header(array('title' => $title, 'group' => $this->groupId, 'toptab' => 'home'));
88 echo $this->getResult();
92 * getResult - returns the Body of the output
94 * @return string result of all selected searches
96 function getResult() {
99 $group = group_get_object($this->groupId);
101 if ($group->usesForum()) {
102 $forumsRenderer = new ForumsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
104 if ($group->usesTracker()) {
105 $trackersRenderer = new TrackersHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
107 if ($group->usesPM()) {
108 $tasksRenderer = new TasksHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
110 if ($group->usesDocman()) {
111 $docsRenderer = new DocsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
113 if ($group->usesFRS()) {
114 $frsRenderer = new FrsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
116 if ($group->usesNews()) {
117 $newsRenderer = new NewsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
120 $validLength = (strlen($this->words) >= 3);
122 if (isset($trackersRenderer) && ($validLength || (is_numeric($this->words) && $trackersRenderer->searchQuery->implementsSearchById()))) {
123 $html .= $this->getPartResult($trackersRenderer, 'short_tracker', _('Tracker Search Results'));
126 if (isset($forumsRenderer) && ($validLength || (is_numeric($this->words) && $forumsRenderer->searchQuery->implementsSearchById()))) {
127 $html .= $this->getPartResult($forumsRenderer, 'short_forum', _('Forum Search Results'));
130 if (isset($tasksRenderer) && ($validLength || (is_numeric($this->words) && $tasksRenderer->searchQuery->implementsSearchById()))) {
131 $html .= $this->getPartResult($tasksRenderer, 'short_pm', _('Task Search Results'));
134 if (isset($docsRenderer) && ($validLength || (is_numeric($this->words) && $docsRenderer->searchQuery->implementsSearchById()))) {
135 $html .= $this->getPartResult($docsRenderer, 'short_docman', _('Documentation Search Results'));
138 if (isset($frsRenderer) && ($validLength || (is_numeric($this->words) && $frsRenderer->searchQuery->implementsSearchById()))) {
139 $html .= $this->getPartResult($frsRenderer, 'short_files', _('Files Search Results'));
142 if (isset($newsRenderer) && ($validLength || (is_numeric($this->words) && $newsRenderer->searchQuery->implementsSearchById()))) {
143 $html .= $this->getPartResult($newsRenderer, 'short_news', _('News Search Results'));
146 if (! $html && ! $validLength) {
147 $html .= '<p class="error">'._('Error: search query too short').'</p>';
150 // This is quite complex but the goal is to extract all the
151 // registered plugins to the hook 'search_engines' and call
153 $pluginManager = plugin_manager_get_object();
154 $searchManager = getSearchManager();
155 $engines = $searchManager->getAvailableSearchEngines();
157 if (isset($pluginManager->hooks_to_plugins['full_search_engines'])) {
158 $p_list = $pluginManager->hooks_to_plugins['full_search_engines'];
159 foreach ($p_list as $p_name) {
160 $p_obj = $pluginManager->GetPluginObject($p_name);
161 $name = $p_obj->text;
163 foreach($engines as $e) {
164 if ($e->type == $p_name) {
165 $renderer = $e->getSearchRenderer($this->words,
166 $this->offset, $this->isExact, $this->groupId);
167 $html .= $this->getPartResult($renderer, 'short_'.$p_name,
168 sprintf(_("%s Search Results"), $name));
175 $renderer = new ForumsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
176 $html .= $this->getPartResult($renderer, 'short_forum', _('Forum Search Results'));
178 $renderer = new TrackersHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
179 $html .= $this->getPartResult($renderer, 'short_tracker', _('Tracker Search Results'));
181 $renderer = new TasksHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
182 $html .= $this->getPartResult($renderer, 'short_pm', _('Task Search Results'));
184 $renderer = new DocsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
185 $html .= $this->getPartResult($renderer, 'short_docman', _('Documentation Search Results'));
187 $renderer = new FrsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
188 $html .= $this->getPartResult($renderer, 'short_files', _('Files Search Results'));
190 $renderer = new NewsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
191 $html .= $this->getPartResult($renderer, 'short_news', _('News Search Results'));
194 return $html.'<br />';
198 * getPartResult - returns the result of the given renderer
200 * @return string result of the renderer
202 function getPartResult($renderer, $section, $title='') {
204 $renderer->searchQuery->executeQuery();
209 $result .= '<h2><a name="'.$section.'"></a>'.$title.'</h2>';
211 if ($renderer->searchQuery->getRowsCount() > 0) {
212 $result .= $GLOBALS['HTML']->listTabletop($renderer->tableHeaders);
213 $result .= $renderer->getRows();
214 $result .= $GLOBALS['HTML']->listTableBottom();
215 } elseif(method_exists($renderer, 'getSections') && (count($renderer->getSections($this->groupId)) == 0)) {
216 $result .= '<p>'.sprintf(_('No matches found for <em>%s</em> - No sections available (check your permissions)'), $this->words).'</p>';
218 $result .= '<p>'.sprintf(_('No matches found for <em>%s</em>'), $this->words).'</p>';
226 // c-file-style: "bsd"