3 * FusionForge globalsearch plugin
5 * Copyright 2003-2004 GForge, LLC
6 * Copyright 2007-2009, Roland Mas
7 * Copyright 2016, Franck Villaume - TrivialDev
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; either version 2 of the License,
13 * or (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * $gwords = target words to search
28 * $gexact = 1 for search ing all words (AND), 0 - for any word (OR)
29 * $otherfreeknowledge = 1 for search in Free/Libre Knowledge Gforge Initiatives
30 * $order = "project_title" or "title" - criteria for ordering results: if empty or not allowed results are ordered by rank
33 require_once '../../env.inc.php';
34 require_once $gfcommon.'include/pre.php';
36 $otherfreeknowledge = getIntFromRequest('otherfreeknowledge') ;
37 $gwords = getStringFromRequest('gwords');
38 $order = getStringFromRequest('order', 'rank');
39 util_ensure_value_in_set ($order,
42 'project_description',
44 $offset = getIntFromRequest('offset');
45 $gexact = getStringFromRequest('gexact');
47 // Support for short aliases
48 if (!$otherfreeknowledge) {
49 $otherfreeknowledge = 0;
53 $onlysw = "AND onlysw = 'f' ";
56 function highlight_target_words($word_array,$text) {
60 $re=implode($word_array,'|');
61 return preg_replace("/($re)/i",'<span style="background-color:pink">\1</span>',$text);
64 $HTML->header(array('title'=>_('Global Project Search'),'pagename'=>'search'));
68 $gwords = htmlspecialchars(trim($gwords));
69 $gwords = preg_replace("/\s+/", ' ', $gwords);
71 // show search box which will return results on
72 // this very page (default is to open new window)
73 $gsplugin = plugin_get_object('globalsearch');
74 echo $gsplugin->search_box();
77 Force them to enter at least three characters
80 if ($gwords && (strlen($gwords) < 3)) {
81 echo $HTML->warning(_('Search must be at least three characters'));
87 echo $HTML->information(_('Enter Your Search Words Above'));
94 if (!$offset || $offset < 0) {
99 Query to find projects
102 $array = explode(" ",$gwords);
104 $qpa = db_construct_qpa(array(), 'SELECT project_title, project_link, project_description, title, link FROM plugin_globalsearch_assoc_site_project, plugin_globalsearch_assoc_site WHERE plugin_globalsearch_assoc_site_project.assoc_site_id = plugin_globalsearch_assoc_site.assoc_site_id AND enabled = $1 AND status_id = 2',
107 if ($otherfreeknowledge) {
108 $qpa = db_construct_qpa($qpa, ' AND onlysw = $1', array ('f')) ;
111 $qpa = db_construct_qpa($qpa, ' AND ((') ;
114 foreach ($array as $val) {
117 $qpa = db_construct_qpa($qpa, ' AND ') ;
119 $qpa = db_construct_qpa($qpa, ' OR ') ;
123 $qpa = db_construct_qpa($qpa, 'lower(project_title) LIKE $1', array ("%$val%")) ;
126 $qpa = db_construct_qpa($qpa, ') OR (') ;
129 foreach ($array as $val) {
132 $qpa = db_construct_qpa($qpa, ' AND ') ;
134 $qpa = db_construct_qpa($qpa, ' OR ') ;
138 $qpa = db_construct_qpa($qpa, 'lower(project_description) LIKE $1', array ("%$val%")) ;
140 $qpa = db_construct_qpa($qpa, ')) ORDER BY '.$order);
144 $result = db_query_qpa ($qpa, $limit+1, $offset);
145 $rows = $rows_returned = db_numrows($result);
147 if (!$result || $rows < 1) {
149 echo "<h2>".sprintf (_('No matches found for ā%sā'), $gwords)."</h2>";
152 if ( $rows_returned > $limit) {
156 echo "<h3>".sprintf (_('Search results for ā%sā'), $gwords)."</h3><p>\n\n";
158 $title_arr = array();
159 $title_arr[] = util_make_link('/plugins/'.$gsplugin->name.'/?gwords='.urlencode($gwords).'&order=project_title&gexact='.$gexact,
161 $title_arr[] = util_make_link('/plugins/'.$gsplugin->name.'/?gwords='.urlencode($gwords).'&order=project_description&gexact='.$gexact,
163 $title_arr[] = util_make_link('/plugins/'.$gsplugin->name.'/?gwords='.urlencode($gwords).'&order=title&gexact='.$gexact,
166 echo $GLOBALS['HTML']->listTableTop($title_arr);
168 for ( $i = 0; $i < $rows; $i++ ) {
169 print "<tr><td><a href=\""
170 . db_result($result, $i, 'project_link')."\" target=\"blank\">"
171 . html_image("ic/msg.png", 10, 12)." "
172 . highlight_target_words($array,db_result($result, $i, 'project_title'))."</a></td>
173 <td>".highlight_target_words($array,html_entity_decode(db_result($result,$i,'project_description')))."</td>
174 <td><center><a href=\"".db_result($result,$i,'link')."\" target=\"_blank\">"
175 . db_result($result,$i,'title')."</a></center></td></tr>\n";
178 echo $GLOBALS['HTML']->listTableBottom();
182 // This code puts the nice next/prev.
183 if ( !$no_rows && ( ($rows_returned > $rows) || ($offset != 0) ) ) {
187 echo "<table width=\"100%\" cellpadding=\"5\" cellspacing=\"0\">\n";
189 echo "\t<td align=\"left\">";
191 echo "<span style=\"font-family:arial, helvetica;text-decoration: none\">";
192 echo util_make_link('/plugins/'.$gsplugin->name.'/?gwords='.urlencode($gwords).'&order='.urlencode($order).'&gexact='.$gexact.'&offset='.($offset-25),
193 '<strong>'._('Previous Results').'</strong>').'</span>';
197 echo "</td>\n\t<td align=\"right\">";
198 if ( $rows_returned > $rows) {
199 echo "<span style=\"font-family:arial, helvetica;text-decoration: none\">";
200 echo util_make_link('/plugins/'.$gsplugin->name.'/?gwords='.urlencode($gwords).'&order='.urlencode($order).'&gexact='.$gexact.'&offset='.($offset+25),
201 '<strong>'._('Next Results').html_image('t.png', 15, 15, array("align"=>"middle")).'</strong>').'</span>';
205 echo "</td>\n</tr>\n";
213 // c-file-style: "bsd"