PageRenderTime 55ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/gforge/www/search/include/renderers/AdvancedSearchHtmlSearchRenderer.class.php

https://github.com/neymanna/fusionforge
PHP | 275 lines | 153 code | 43 blank | 79 comment | 30 complexity | ae2d1bbbf067c641224e39e889b41471 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * GForge Search Engine
  4. *
  5. * Copyright 2004 (c) Dominik Haas, GForge Team
  6. *
  7. * http://gforge.org
  8. *
  9. * @version $Id$
  10. */
  11. require_once $gfwww.'include/pre.php';
  12. require_once $gfwww.'search/include/renderers/HtmlGroupSearchRenderer.class.php';
  13. class AdvancedSearchHtmlSearchRenderer extends HtmlGroupSearchRenderer {
  14. /**
  15. * group id
  16. *
  17. * @var int $groupId
  18. */
  19. var $groupId;
  20. /**
  21. * the words to search for
  22. *
  23. * @var string $words
  24. */
  25. var $words;
  26. /**
  27. * flag to define whether the result must contain all words or only one of them
  28. *
  29. * @var boolean $isExact
  30. */
  31. var $isExact;
  32. /**
  33. * selected parents sections
  34. *
  35. * @var array $selectedParentSections
  36. */
  37. var $selectedParentSections = array();
  38. /**
  39. * Constructor
  40. *
  41. * @param string $words words we are searching for
  42. * @param int $offset offset
  43. * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
  44. * @param int $groupId group id
  45. *
  46. */
  47. function AdvancedSearchHtmlSearchRenderer($words, $offset, $isExact, $groupId) {
  48. $this->groupId = $groupId;
  49. $this->words = $words;
  50. $this->isExact = $isExact;
  51. $searchQuery =& $this->searchQuery;
  52. $this->HtmlGroupSearchRenderer(SEARCH__TYPE_IS_ADVANCED, $words, $isExact, $searchQuery, $groupId);
  53. }
  54. /**
  55. * flush - overwrites the flush method from htmlrenderer
  56. */
  57. function flush() {
  58. $this->writeHeader();
  59. $this->writeBody();
  60. $this->writeFooter();
  61. }
  62. /**
  63. * writeHeader - write the header of the output
  64. */
  65. function writeHeader() {
  66. site_project_header(array('title' => _('Advanced search'), 'group' => $this->groupId, 'toptab'=>'none'));
  67. $sectionarray = $this->getSectionArray();
  68. $this->handleTransferInformation($sectionarray);
  69. $GLOBALS['HTML']->advancedSearchBox($sectionarray, $this->groupId, $this->words, $this->isExact);
  70. }
  71. /**
  72. * writeBody - write the Body of the output
  73. */
  74. function writeBody() {
  75. if (strlen($this->words) < 3) {
  76. echo '<br><h1>'._('Error: Under min length search').'<h1><br>';
  77. } else {
  78. echo $this->getResult();
  79. }
  80. }
  81. /**
  82. * getResult - returns the Body of the output
  83. *
  84. * @return string result of all selected searches
  85. */
  86. function getResult() {
  87. $html = '';
  88. if (in_array('short_forum', $this->selectedParentSections)) {
  89. $renderer = new ForumsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_forum'));
  90. $html .= $this->getPartResult($renderer, 'short_forum', _('Forum Search Results'));
  91. }
  92. if (in_array('short_tracker', $this->selectedParentSections)) {
  93. $renderer = new TrackersHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_tracker'));
  94. $html .= $this->getPartResult($renderer, 'short_tracker', _('Tracker Search Results'));
  95. }
  96. if (in_array('short_pm', $this->selectedParentSections)) {
  97. $renderer = new TasksHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_pm'));
  98. $html .= $this->getPartResult($renderer, 'short_pm', _('Task Search Results'));
  99. }
  100. if (in_array('short_docman', $this->selectedParentSections)) {
  101. $renderer = new DocsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_docman'));
  102. $html .= $this->getPartResult($renderer, 'short_docman', _('Documentation Search Results'));
  103. }
  104. if (in_array('short_files', $this->selectedParentSections)) {
  105. $renderer = new FilesHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_files'));
  106. $html .= $this->getPartResult($renderer, 'short_files', _('Files Search Results'));
  107. }
  108. if (in_array('short_news', $this->selectedParentSections)) {
  109. $renderer = new NewsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
  110. $html .= $this->getPartResult($renderer, 'short_news', _('News Search Results'));
  111. }
  112. return $html.'<br />';
  113. }
  114. /**
  115. * getPartResult - returns the result of the given renderer
  116. *
  117. * @return string result of the renderer
  118. */
  119. function getPartResult($renderer, $section, $title='') {
  120. $result = '';
  121. $renderer->searchQuery->executeQuery();
  122. $query = NULL;
  123. if ($title === '')
  124. $title = $section;
  125. $result .= '<h3><a name="'.$section.'"></a>'.$title.'</h3>';
  126. if ($renderer->searchQuery->getRowsCount() > 0) {
  127. $result .= $GLOBALS['HTML']->listTabletop($renderer->tableHeaders);
  128. $result .= $renderer->getRows();
  129. $result .= $GLOBALS['HTML']->listTableBottom();
  130. } elseif(method_exists($renderer, 'getSections') && (count($renderer->getSections($this->groupId)) == 0)) {
  131. $result .= '<p>'.sprintf(_('No matches found - No sections available (check your permissions)'), htmlspecialchars($query['words'])).'</p>';
  132. } else {
  133. $result .= '<p>'.sprintf(_('No matches found'), htmlspecialchars($query['words'])).'</p>';
  134. }
  135. return $result;
  136. }
  137. /**
  138. * getSectionArray - creates an array of sections in which the user can search
  139. *
  140. * @return array sections
  141. */
  142. function getSectionArray() {
  143. global $gfwww, $gfcommon;
  144. $sections = array();
  145. $group =& group_get_object($this->groupId);
  146. if ($group->usesForum()) {
  147. require_once $gfwww.'search/include/renderers/ForumsHtmlSearchRenderer.class.php';
  148. $undersections = ForumsHtmlSearchRenderer::getSections($this->groupId);
  149. if (count($undersections) > 0) {
  150. $sections['short_forum'] = $undersections;
  151. }
  152. }
  153. if ($group->usesTracker()) {
  154. require_once $gfwww.'search/include/renderers/TrackersHtmlSearchRenderer.class.php';
  155. $undersections = TrackersHtmlSearchRenderer::getSections($this->groupId);
  156. if (count($undersections) > 0) {
  157. $sections['short_tracker'] = $undersections;
  158. }
  159. }
  160. if ($group->usesPM()) {
  161. require_once $gfwww.'search/include/renderers/TasksHtmlSearchRenderer.class.php';
  162. $undersections = TasksHtmlSearchRenderer::getSections($this->groupId);
  163. if (count($undersections) > 0) {
  164. $sections['short_pm'] = $undersections;
  165. }
  166. }
  167. if ($group->usesDocman()) {
  168. require_once $gfwww.'search/include/renderers/DocsHtmlSearchRenderer.class.php';
  169. $undersections = DocsHtmlSearchRenderer::getSections($this->groupId);
  170. if (count($undersections) > 0) {
  171. $sections['short_docman'] = $undersections;
  172. }
  173. }
  174. if ($group->usesNews()) {
  175. require_once $gfwww.'search/include/renderers/NewsHtmlSearchRenderer.class.php';
  176. $sections['short_news'] = true;
  177. }
  178. if ($group->usesFRS()) {
  179. require_once $gfwww.'search/include/renderers/FrsHtmlSearchRenderer.class.php';
  180. $undersections = FrsHtmlSearchRenderer::getSections($this->groupId);
  181. if (count($undersections) > 0) {
  182. $sections['short_files'] = $undersections;
  183. }
  184. }
  185. return $sections;
  186. }
  187. /**
  188. * handleTransferInformation - marks parentsections if child is marked and processes cookie information
  189. *
  190. */
  191. function handleTransferInformation(&$sectionarray) {
  192. //get through all sections
  193. //if a childsection is marked to search in, mark the parent too
  194. $postArray = _getPostArray();
  195. foreach($sectionarray as $key => $section) {
  196. if(is_array($section)) {
  197. foreach ($postArray as $postkey => $postvalue) {
  198. if (substr($postkey, 0, strlen($key)) == $key) {
  199. $this->selectedParentSections[] = $key;
  200. break;
  201. }
  202. }
  203. } elseif(isset($postArray[$key])) {
  204. $this->selectedParentSections[] = $key;
  205. }
  206. }
  207. }
  208. /**
  209. * getSelectedChildSections - gets all selected child sections from the given parentsection
  210. *
  211. * @param string $parentsection the parentsection
  212. *
  213. * @return array all child sections from the parent section the user wants to search in
  214. */
  215. function getSelectedChildSections($parentsection) {
  216. $sections = array();
  217. $postArray = _getPostArray();
  218. foreach($postArray as $key => $value) {
  219. if (substr($key, 0, strlen($parentsection)) == $parentsection) {
  220. if (strlen(substr($key, strlen($parentsection) , strlen($key))) > 0) {
  221. array_push($sections, urldecode(substr($key, strlen($parentsection), strlen($key))));
  222. }
  223. }
  224. }
  225. return $sections;
  226. }
  227. }
  228. // Local Variables:
  229. // mode: php
  230. // c-file-style: "bsd"
  231. // End:
  232. ?>