3 * FusionForge globalsearch plugin
5 * Copyright 2003-2004, GForge, LLC
6 * Copyright 2007-2009, Roland Mas
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.
25 require_once '../../../www/env.inc.php';
26 require_once $gfcommon.'include/pre.php';
27 require_once $gfcommon.'/include/FusionForge.class.php';
29 function show_globalsearch_stats_boxes() {
33 $return .= $HTML->boxTop(_("Global Search"));
34 $return .= globalsearch_box();
35 $return .= $HTML->boxMiddle(_("Top associated forges"));
36 $return .= show_top_n_assocsites(5);
37 $return .= "<div align=\"center\">".sprintf(_("Total projects in associated forges: <b>%1$d</b>"),stats_get_total_projects_assoc_sites()). "</div>";
38 $return .= $HTML->boxBottom();
42 function globalsearch_box() {
43 global $gwords,$gexact,$otherfreeknowledge;
45 $return = 'Search in other associated forges:<br />
46 <form method="post" action="/plugins/globalsearch/"/>
47 <input width="100%" type="text" name="gwords" value="'.$gwords.'"/>
48 <input type="submit" name="Search" value="'._("Search").'" /><br/>
49 <input type="checkbox" name="otherfreeknowledge" value="1"'.( $otherfreeknowledge ? ' checked' : ' unchecked' ).'>'._('Extend search to include non-software projects').'<br/>
50 <input type="checkbox" name="gexact" value="1"'.( $gexact ? ' checked' : ' unchecked' ).'>'._("Require all words").'</form>';
55 * show_top_n_assocsites() - Show the n top ranked associated sites
57 * @param string Number of associated sites to show
61 function show_top_n_assocsites($num_assocsites) {
62 $res_top_n_assoc = db_query_params ('
63 SELECT a.title, a.link, count(*) AS numprojects
64 FROM plugin_globalsearch_assoc_site_project p, plugin_globalsearch_assoc_site a
65 WHERE p.assoc_site_id = a.assoc_site_id AND p.assoc_site_id IN
66 (SELECT assoc_site_id FROM plugin_globalsearch_assoc_site
67 WHERE status_id = 2 AND enabled=$1 ORDER BY rank LIMIT $2)
68 GROUP BY a.title, a.link',
72 if (db_numrows($res_top_n_assoc) == 0) {
73 return _('No stats available')." ".db_error();
76 $return .= "<div align=\"left\"><table>";
77 while ($row_topdown = db_fetch_array($res_top_n_assoc)) {
78 if ($row_topdown['numprojects'] > 0)
79 $return .= "<tr><td><a href=\"$row_topdown[link]/\">";
80 $return .= $row_topdown[title]."</a></td>";
81 $return .= "<td><div align=\"right\">". number_format($row_topdown[numprojects], 0);
82 $return .= " projects</div></td></tr>\n";
84 $return .= "</div></table>";
90 * stats_get_total_projects_assoc_sites() - Show the total number of projects of associated sites
92 * @param string Number of associated sites to show
96 function stats_get_total_projects_assoc_sites() {
97 $res_count = db_query_params ('SELECT count(*) AS numprojects FROM plugin_globalsearch_assoc_site_project p, plugin_globalsearch_assoc_site a WHERE p.assoc_site_id = a.assoc_site_id AND a.status_id = 2',
99 if (db_numrows($res_count) > 0) {
100 $row_count = db_fetch_array($res_count);
101 return $row_count['numprojects'];
103 return _('No stats available')." ".db_error();
109 // c-file-style: "bsd"