[evolvis-commits] r10278: finalized Grand Unified Search work based on Dominik Haas' patch [ #833] ↵
mirabilos at evolvis.org
mirabilos at evolvis.org
Thu Feb 24 17:41:48 CET 2011
Author: mirabilos
Date: 2011-02-24 17:41:47 +0100 (Thu, 24 Feb 2011)
New Revision: 10278
Added:
trunk/gforge_base/evolvisforge-5.1/gforge/www/search/advanced_search.php
trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/AdvancedSearchHtmlSearchRenderer.class
Modified:
trunk/gforge_base/evolvisforge-5.1/gforge/www/include/Layout.class
trunk/gforge_base/evolvisforge-5.1/gforge/www/include/languages/Base.tab
trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/DocsHtmlSearchRenderer.class
trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/ForumsHtmlSearchRenderer.class
trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/FrsHtmlSearchRenderer.class
trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/TrackersHtmlSearchRenderer.class
Log:
finalized Grand Unified Search work based on Dominik Haas' patch [#833]
Modified: trunk/gforge_base/evolvisforge-5.1/gforge/www/include/Layout.class
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/www/include/Layout.class 2011-02-24 16:41:46 UTC (rev 10277)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/www/include/Layout.class 2011-02-24 16:41:47 UTC (rev 10278)
@@ -27,7 +27,7 @@
* @var string $imgroot
*/
var $imgroot = '/themes/gforge/images/';
- var $COLOR_CONTENT_BACK= 'ffffff';
+ var $COLOR_CONTENT_BACK= '#ffffff';
var $COLOR_LTBACK1= '#eeeeef';
var $COLOR_LTBACK2= '#fafafa';
var $COLOR_SELECTED_TAB= '#e0e0e0';
@@ -830,18 +830,158 @@
print '<input type="hidden" value="'.$value.'" name="'.$name.'" />';
}
print '</td><td>';
- print '
- <input type="text" size="12" name="words" value="'.$words.'" />';
+ print '<input type="text" size="12" name="words" value="'.$words.'" />';
print '</td><td> </td><td>';
print '<input type="submit" name="Search" value="'.$Language->getText('searchbox','search').'" />';
+ print '</td>';
- print '
- </td></tr></table>';
+ if (isset($group_id)) {
+ print '
+ <td width="10"> </td>
+ <td><b><a style="color: #FFFFFF" href="/search/advanced_search.php?group_id='.$group_id.'"> '.$Language->getText('searchbox', 'advanced_search').'</a></b></td>';
+ }
+ print '</tr></table>';
print '</form>';
}
+
+ function advancedSearchBox($sectionsArray, $group_id, $words, $isExact) {
+ global $Language;
+ // display the searchmask
+ print '
+ <form name="advancedsearch" action="'.$PHP_SELF.'" method="post">
+ <input type="hidden" name="search" value="1"/>
+ <input type="hidden" name="group_id" value="'.$group_id.'"/>
+ <div align="center"><br />
+ <table border="0">
+ <tr>
+ <td colspan ="2">
+ <input type="text" size="60" name="words" value="'.stripslashes(htmlspecialchars($words)).'" />
+ <input type="submit" name="submitbutton" value="'.$Language->getText('advanced_search', 'search_button').'" />
+ </td>
+ </tr>
+ <tr>
+ <td valign="top">
+ <input type="radio" name="mode" value="'.SEARCH__MODE_AND.'" '.($isExact ? 'checked="checked"' : '').' />'.$Language->getText('advanced_search', 'and_search').'
+ </td>
+ <td>
+ <input type="radio" name="mode" value="'.SEARCH__MODE_OR.'" '.(!$isExact ? 'checked="checked"' : '').' />'.$Language->getText('advanced_search', 'or_search').'
+ </td>
+ </tr>
+ </table><br /></div>'
+ .$this->createUnderSections($sectionsArray).'
+ </form>';
+
+ //create javascript methods for select none/all
+ print '
+ <script type="text/javascript">
+ <!-- method for disable/enable checkboxes
+ function setCheckBoxes(parent, checked) {
+
+
+ for (var i = 0; i < document.advancedsearch.elements.length; i++)
+ if (document.advancedsearch.elements[i].type == "checkbox")
+ if (document.advancedsearch.elements[i].name.substr(0, parent.length) == parent)
+ document.advancedsearch.elements[i].checked = checked;
+ }
+ //-->
+ </script>
+ ';
+
+ }
+
+ function createUnderSections($sectionsArray) {
+ global $Language;
+ $countLines = 0;
+ foreach ($sectionsArray as $section) {
+ if(is_array($section)) {
+ $countLines += (3 + count ($section));
+ } else {
+ //2 lines one for section name and one for checkbox
+ $countLines += 3;
+ }
+ }
+ $breakLimit = round($countLines/3);
+ $break = $breakLimit;
+ $countLines = 0;
+ $return = '
+ <table width="100%" border="0" cellspacing="0" cellpadding="2" style="background-color:'. $this->COLOR_HTMLBOX_TITLE .'">
+ <tr>
+ <td>
+ <table width="100%" cellspacing="0" border="0">
+ <tr style="font-weight: bold; background-color:'. $this->COLOR_HTMLBOX_TITLE .'">
+ <td colspan="2">'.$Language->getText('advanced_search', 'search_in').':</td>
+ <td align="right">'.$Language->getText('advanced_search', 'select').' <a href="javascript:setCheckBoxes(\'\', true)">'.$Language->getText('advanced_search', 'all').'</a> / <a href="javascript:setCheckBoxes(\'\', false)">'.$Language->getText('advanced_search', 'none').'</a></td>
+ </tr>
+ <tr height="20" style="background-color:'. $this->COLOR_CONTENT_BACK .'">
+ <td colspan="3"> </td>
+ </tr>
+ <tr align="center" valign="top" style="background-color:'. $this->COLOR_CONTENT_BACK .'">
+ <td>';
+ foreach($sectionsArray as $key => $section) {
+ $oldcountlines = $countLines;
+ if (is_array($section)) {
+ $countLines += (3 + count ($section));
+ } else {
+ $countLines += 3;
+ }
+
+ if ($countLines >= $break) {
+ //if the next block is so large that shifting it to the next column hits the breakpoint better
+ //the second part of statement (behind &&) proofs, that no 4th column is added
+ if ((($countLines - $break) >= ($break - $countLines)) && ((($break + $breakLimit)/$breakLimit) <= 3)) {
+ $return .= '</td><td>';
+ $break += $breakLimit;
+ }
+ }
+
+ $return .= '<table width="90%" border="0" cellpadding="1" cellspacing="0" style="background-color:'. $this->COLOR_HTMLBOX_TITLE.'">
+ <tr><td><table width="100%" border="0" cellspacing="0" cellpadding="3">
+ <tr style="background-color:'. $this->COLOR_HTMLBOX_TITLE .'; font-weight: bold">
+ <td cellspacing="0">
+ <a href="#'.$key.'">'.$Language->getText('group', $key).'</a>'
+ .' </td>
+ <td align="right">'
+ .$Language->getText('advanced_search', 'select').' <a href="javascript:setCheckBoxes(\''.$key.'\', true)">'.$Language->getText('advanced_search', 'all').'</a> / <a href="javascript:setCheckBoxes(\''.$key.'\', false)">'.$Language->getText('advanced_search', 'none').'</a>
+ </td>
+ </tr>
+ <tr style="background-color:'. $this->COLOR_CONTENT_BACK.'">
+ <td colspan="2">';
+
+ if (!is_array($section)) {
+ $return .= ' <input type="checkbox" name="'.urlencode($key).'"';
+ if (isset($GLOBALS[urlencode($key)]))
+ $return .= ' checked="checked" ';
+ $return .= ' /></input>'.$Language->getText('group', $key).'<br />';
+ }
+ else
+ foreach($section as $underkey => $undersection) {
+ $return .= ' <input type="checkbox" name="'.urlencode($key.$underkey).'"';
+ if (isset($GLOBALS[urlencode($key.$underkey)]))
+ $return .= ' checked ';
+ $return .= '></input>'.$undersection.'<br />';
+
+ }
+
+ $return .= ' </td>
+ </tr>
+ </table></td></tr></table><br />';
+
+ if ($countLines >= $break) {
+ if (($countLines - $break) < ($break - $countLines)) {
+ $return .= '</td><td width="33%">';
+ $break += $breakLimit;
+ }
+ }
+ }
+
+ return $return.' </td>
+ </tr>
+ </table></td></tr></table>';
+ }
+
/**
* beginSubMenu() - Opening a submenu.
*
Modified: trunk/gforge_base/evolvisforge-5.1/gforge/www/include/languages/Base.tab
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/www/include/languages/Base.tab 2011-02-24 16:41:46 UTC (rev 10277)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/www/include/languages/Base.tab 2011-02-24 16:41:47 UTC (rev 10278)
@@ -513,6 +513,16 @@
admin_vhost virtual_host_administration Virtual Host Administration
admin_vhost virtual_host_entry_updated Virtual Host entry updated.
admin_vhost virtual_host_name Virtual Host Name
+advanced_search and_search with all words
+advanced_search all all
+advanced_search or_search with one word
+advanced_search none none
+advanced_search search_button Search
+advanced_search search_in Search in
+advanced_search select Select
+advanced_search headline $1 Search Result
+advanced_search no_matches_found No matches found
+advanced_search no_matches_found_no_under_section No matches found - No sections available (check your permissions)
artifact_canned required_fields ArtifactCanned: name and assignee are Required
artifact_category required_fields ArtifactCategory: name and assignee are Required
calendar april April
@@ -2150,6 +2160,7 @@
search tasks_created_by Created By
search tasks_completed Completed
search title Search
+searchbox advanced_search Advanced search
searchbox docs This project's documents
searchbox forum This forum
searchbox forums This project's forums
Added: trunk/gforge_base/evolvisforge-5.1/gforge/www/search/advanced_search.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/www/search/advanced_search.php (rev 0)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/www/search/advanced_search.php 2011-02-24 16:41:47 UTC (rev 10278)
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ * GForge Search Engine
+ *
+ * Copyright 2004 (c) Dominik Haas, GForge Team
+ *
+ * http://gforge.org
+ *
+ * @version $Id$
+ */
+
+require_once('pre.php');
+require_once('common/include/escapingUtils.php');
+require_once('include/renderers/AdvancedSearchHtmlSearchRenderer.class');
+
+$offset = getIntFromRequest('offset');
+$words = getStringFromRequest('words');
+$mode = getStringFromRequest('mode', SEARCH__MODE_AND);
+
+if ($mode == SEARCH__MODE_AND) {
+ $exact = true;
+} else {
+ $exact = false;
+}
+
+if (!isset($search)) {
+ $searchQuery = new AdvancedSearchHtmlSearchRenderer($words, $offset, true, $group_id);
+ //just display the header and footer if search is not set
+ $searchQuery->writeHeader();
+ $searchQuery->writeFooter();
+} else {
+ if ($mode == SEARCH__MODE_AND) {
+ $exact = true;
+ } else {
+ $exact = false;
+ }
+ $searchQuery = new AdvancedSearchHtmlSearchRenderer($words, $offset, $exact, $group_id);
+ $searchQuery->flush();
+}
+
+?>
\ No newline at end of file
Added: trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/AdvancedSearchHtmlSearchRenderer.class
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/AdvancedSearchHtmlSearchRenderer.class (rev 0)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/AdvancedSearchHtmlSearchRenderer.class 2011-02-24 16:41:47 UTC (rev 10278)
@@ -0,0 +1,263 @@
+<?php
+
+/**
+ * GForge Search Engine
+ *
+ * Copyright 2004 (c) Dominik Haas, GForge Team
+ *
+ * http://gforge.org
+ *
+ * @version $Id$
+ */
+
+require_once('pre.php');
+require_once('www/search/include/renderers/HtmlGroupSearchRenderer.class');
+
+class AdvancedSearchHtmlSearchRenderer extends HtmlGroupSearchRenderer {
+
+ /**
+ * group id
+ *
+ * @var int $groupId
+ */
+ var $groupId;
+
+ /**
+ * the words to search for
+ *
+ * @var string $words
+ */
+ var $words;
+
+ /**
+ * flag to define whether the result must contain all words or only one of them
+ *
+ * @var boolean $isExact
+ */
+ var $isExact;
+
+ /**
+ * selected parents sections
+ *
+ * @var array $selectedParentSections
+ */
+ var $selectedParentSections = array();
+
+ /**
+ * Constructor
+ *
+ * @param string $words words we are searching for
+ * @param int $offset offset
+ * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
+ * @param int $groupId group id
+ *
+ */
+ function AdvancedSearchHtmlSearchRenderer($words, $offset, $isExact, $groupId) {
+ $this->groupId = $groupId;
+ $this->words = $words;
+ $this->isExact = $isExact;
+
+ $this->HtmlGroupSearchRenderer(SEARCH__TYPE_IS_ADVANCED, $words, $isExact, $searchQuery, $groupId);
+ }
+
+ /**
+ * flush - overwrites the flush method from htmlrenderer
+ */
+ function flush() {
+ $this->writeHeader();
+ $this->writeBody();
+ $this->writeFooter();
+ }
+
+ /**
+ * writeHeader - write the header of the output
+ */
+ function writeHeader() {
+ site_project_header(array('title' => $this->Language->getText('advanced_search', 'project_search'), 'group' => $this->groupId, 'pagename' => 'advanced search', ));
+ $sectionarray = $this->getSectionArray();
+ $this->handleTransferInformation($sectionarray);
+
+ $GLOBALS['HTML']->advancedSearchBox($sectionarray, $this->groupId, $this->words, $this->isExact);
+ }
+
+ /**
+ * writeBody - write the Body of the output
+ */
+ function writeBody() {
+ if (strlen($this->words) < 3) {
+ echo '<br><h1>'.$this->Language->getText('advanced_search', 'error_search_minlength').'<h1><br>';
+ } else {
+ echo $this->getResult();
+ }
+ }
+
+ /**
+ * getResult - returns the Body of the output
+ *
+ * @return string result of all selected searches
+ */
+ function getResult() {
+ $html = '';
+
+ if (in_array('short_forum', $this->selectedParentSections)) {
+ $renderer = new ForumsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_forum'));
+ $html .= $this->getPartResult($renderer, 'short_forum');
+ }
+
+ if (in_array('short_tracker', $this->selectedParentSections)) {
+ $renderer = new TrackersHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_tracker'));
+ $html .= $this->getPartResult($renderer, 'short_tracker');
+ }
+
+ if (in_array('short_pm', $this->selectedParentSections)) {
+ $renderer = new TasksHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_pm'));
+ $html .= $this->getPartResult($renderer, 'short_pm');
+ }
+
+ if (in_array('short_docman', $this->selectedParentSections)) {
+ $renderer = new DocsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_docman'));
+ $html .= $this->getPartResult($renderer, 'short_docman');
+ }
+
+ if (in_array('short_files', $this->selectedParentSections)) {
+ $renderer = new FilesHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_files'));
+ $html .= $this->getPartResult($renderer, 'short_files');
+ }
+
+ if (in_array('short_news', $this->selectedParentSections)) {
+ $renderer = new NewsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
+ $html .= $this->getPartResult($renderer, 'short_news');
+ }
+
+ return $html.'<br />';
+ }
+
+ /**
+ * getPartResult - returns the result of the given renderer
+ *
+ * @return string result of the renderer
+ */
+ function getPartResult($renderer, $section) {
+ $result = '';
+ $renderer->searchQuery->executeQuery();
+
+ $result .= '<h3><a name="'.$section.'"></a>'.$this->Language->getText('advanced_search', 'headline', array($this->Language->getText('group', $section))).'</h3>';
+
+ if ($renderer->searchQuery->getRowsCount() > 0) {
+ $result .= $GLOBALS['HTML']->listTabletop($renderer->tableHeaders);
+ $result .= $renderer->getRows();
+ $result .= $GLOBALS['HTML']->listTableBottom();
+ } elseif(method_exists($renderer, 'getSections') && (count($renderer->getSections($this->groupId)) == 0)) {
+ $result .= '<p>'.$this->Language->getText('advanced_search', 'no_matches_found_no_under_section', array(htmlspecialchars($query['words']))).'</p>';
+ } else {
+ $result .= '<p>'.$this->Language->getText('advanced_search', 'no_matches_found', array(htmlspecialchars($query['words']))).'</p>';
+ }
+ return $result;
+ }
+
+ /**
+ * getSectionArray - creates an array of sections in which the user can search
+ *
+ * @return array sections
+ */
+ function getSectionArray() {
+ $sections = array();
+ $group =& group_get_object($this->groupId);
+
+ if ($group->usesForum()) {
+ require_once('ForumsHtmlSearchRenderer.class');
+ $undersections = ForumsHtmlSearchRenderer::getSections($this->groupId);
+ if (count($undersections) > 0) {
+ $sections['short_forum'] = $undersections;
+ }
+ }
+
+ if ($group->usesTracker()) {
+ require_once('TrackersHtmlSearchRenderer.class');
+ $undersections = TrackersHtmlSearchRenderer::getSections($this->groupId);
+ if (count($undersections) > 0) {
+ $sections['short_tracker'] = $undersections;
+ }
+ }
+
+ if ($group->usesPM()) {
+ require_once('TasksHtmlSearchRenderer.class');
+ $undersections = TasksHtmlSearchRenderer::getSections($this->groupId);
+ if (count($undersections) > 0) {
+ $sections['short_pm'] = $undersections;
+ }
+
+ }
+
+ if ($group->usesDocman()) {
+ require_once('DocsHtmlSearchRenderer.class');
+ $undersections = DocsHtmlSearchRenderer::getSections($this->groupId);
+ if (count($undersections) > 0) {
+ $sections['short_docman'] = $undersections;
+ }
+ }
+
+ if ($group->usesNews()) {
+ require_once('NewsHtmlSearchRenderer.class');
+ $sections['short_news'] = true;
+ }
+
+ if ($group->usesFRS()) {
+ require_once('FrsHtmlSearchRenderer.class');
+ $undersections = FrsHtmlSearchRenderer::getSections($this->groupId);
+ if (count($undersections) > 0) {
+ $sections['short_files'] = $undersections;
+ }
+ }
+
+ return $sections;
+ }
+
+ /**
+ * handleTransferInformation - marks parentsections if child is marked and processes cookie information
+ *
+ */
+ function handleTransferInformation(&$sectionarray) {
+ //get through all sections
+ //if a childsection is marked to search in, mark the parent too
+
+ $postArray = _getPostArray();
+
+ foreach($sectionarray as $key => $section) {
+ if(is_array($section)) {
+ foreach ($postArray as $postkey => $postvalue) {
+ if (substr($postkey, 0, strlen($key)) == $key) {
+ $this->selectedParentSections[] = $key;
+ break;
+ }
+ }
+ } elseif(isset($postArray[$key])) {
+ $this->selectedParentSections[] = $key;
+ }
+ }
+
+ }
+
+ /**
+ * getSelectedChildSections - gets all selected child sections from the given parentsection
+ *
+ * @param string $parentsection the parentsection
+ *
+ * @return array all child sections from the parent section the user wants to search in
+ */
+ function getSelectedChildSections($parentsection) {
+ $sections = array();
+ $postArray = _getPostArray();
+
+ foreach($postArray as $key => $value) {
+ if (substr($key, 0, strlen($parentsection)) == $parentsection) {
+ if (strlen(substr($key, strlen($parentsection) , strlen($key))) > 0) {
+ array_push($sections, urldecode(substr($key, strlen($parentsection), strlen($key))));
+ }
+ }
+ }
+ return $sections;
+ }
+}
+
+?>
\ No newline at end of file
Modified: trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/DocsHtmlSearchRenderer.class
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/DocsHtmlSearchRenderer.class 2011-02-24 16:41:46 UTC (rev 10277)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/DocsHtmlSearchRenderer.class 2011-02-24 16:41:47 UTC (rev 10278)
@@ -84,7 +84,7 @@
function getSections($groupId) {
$userIsGroupMember = $this->isGroupMember($groupId);
- return $this->searchQuery->getSections($groupId, $userIsGroupMember);
+ return DocsSearchQuery::getSections($groupId, $userIsGroupMember);
}
}
Modified: trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/ForumsHtmlSearchRenderer.class
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/ForumsHtmlSearchRenderer.class 2011-02-24 16:41:46 UTC (rev 10277)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/ForumsHtmlSearchRenderer.class 2011-02-24 16:41:47 UTC (rev 10278)
@@ -81,7 +81,7 @@
function getSections($groupId) {
$userIsGroupMember = $this->isGroupMember($groupId);
- return $this->searchQuery->getSections($groupId, $userIsGroupMember);
+ return ForumsSearchQuery::getSections($groupId, $userIsGroupMember);
}
}
Modified: trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/FrsHtmlSearchRenderer.class
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/FrsHtmlSearchRenderer.class 2011-02-24 16:41:46 UTC (rev 10277)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/FrsHtmlSearchRenderer.class 2011-02-24 16:41:47 UTC (rev 10278)
@@ -80,7 +80,7 @@
function getSections($groupId) {
$userIsGroupMember = $this->isGroupMember($groupId);
- return FilesSearchQuery::getSections($groupId, $userIsGroupMember);
+ return FrsSearchQuery::getSections($groupId, $userIsGroupMember);
}
}
Modified: trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/TrackersHtmlSearchRenderer.class
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/TrackersHtmlSearchRenderer.class 2011-02-24 16:41:46 UTC (rev 10277)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/www/search/include/renderers/TrackersHtmlSearchRenderer.class 2011-02-24 16:41:47 UTC (rev 10278)
@@ -85,7 +85,7 @@
function getSections($groupId) {
$userIsGroupMember = $this->isGroupMember($groupId);
- return $this->searchQuery->getSections($groupId, $userIsGroupMember);
+ return TrackersSearchQuery::getSections($groupId, $userIsGroupMember);
}
}
More information about the evolvis-commits
mailing list