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 class globalSearchPlugin extends Plugin {
26 function globalSearchPlugin () {
28 $this->name = "globalsearch" ;
29 $this->hooks[] = "site_admin_option_hook" ;
30 $this->hooks[] = "features_boxes_top" ;
33 function CallHook ($hookname, &$params) {
34 global $Language, $G_SESSION, $HTML, $group_id;
36 if ($hookname == "site_admin_option_hook") {
37 print '<li><a href="/plugins/globalsearch/edit_assoc_sites.php">'._("Admin Associated Forges").'</a></li>';
38 } elseif ($hookname == "features_boxes_top") {
39 (isset($params['returned_text'])) ? $params['returned_text'] .= $HTML->boxTop(_('Associated Forges'), 'Associated_Forges') : $params['returned_text'] = $HTML->boxTop(_('Associated Forges'), 'Associated_Forges');
40 $params['returned_text'] .= $this->show_top_n_assocsites (5) ;
41 $params['returned_text'] .= $this->search_box () ;
45 function show_globalsearch_stats_boxes() {
49 $return .= $HTML->boxTop(_("Global Search"));
50 $return .= globalsearch_box();
51 $return .= $HTML->boxMiddle(_("Top associated forges"));
52 $return .= show_top_n_assocsites(5);
53 $return .= "<div align=\"center\">".sprintf(_("Total projects in associated forges: <b>%1$d</b>"),stats_get_total_projects_assoc_sites()). "</div>";
54 $return .= $HTML->boxBottom();
58 function search_box() {
59 global $HTML,$gwords,$gexact,$otherfreeknowledge;
61 $return = '<form method="post" action="/plugins/globalsearch/">';
62 $return .= $HTML->html_text_input_img_submit('gwords', 'magnifier.png', 'search_associated_forges', '', $gwords, _('Search associated forges'));
63 $return .= $HTML->html_checkbox('otherfreeknowledge', '1', 'search_associated_forges_otherfreeknowledge', _('Extend search to include non-software projects'), $otherfreeknowledge);
64 $return .= $HTML->html_checkbox('gexact', '1', 'search_associated_forges_exact', _('Require all words'), $gexact);
71 * show_top_n_assocsites() - Show the n top ranked associated sites
73 * @param string Number of associated sites to show
76 function show_top_n_assocsites($num_assocsites) {
77 $res_top_n_assoc = db_query_params ('
78 SELECT a.title, a.link, count(*) AS numprojects
79 FROM plugin_globalsearch_assoc_site_project p, plugin_globalsearch_assoc_site a
80 WHERE p.assoc_site_id = a.assoc_site_id AND p.assoc_site_id IN
81 (SELECT assoc_site_id FROM plugin_globalsearch_assoc_site
82 WHERE status_id = 2 AND enabled=$1 ORDER BY rank LIMIT $2)
83 GROUP BY a.title, a.link',
87 if (db_numrows($res_top_n_assoc) == 0) {
88 return _('No stats available')." ".db_error();
91 $return .= '<table summary="" class="underline-link">';
92 while ($row_topdown = db_fetch_array($res_top_n_assoc)) {
93 if ($row_topdown['numprojects'] > 0) {
94 $return .= '<tr><td>';
95 $return .= '<a href="' . $row_topdown[link] . '/">';
96 $return .= $row_topdown[title] . "</a>";
98 $return .= '<td class="align-right">' . number_format($row_topdown[numprojects], 0);
99 $return .= " projects";
100 $return .= "</td></tr>\n";
103 $return .= "</table>";
109 * stats_get_total_projects_assoc_sites() - Show the total number of projects of associated sites
111 * @param string Number of associated sites to show
114 function stats_get_total_projects_assoc_sites() {
115 $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',
117 if (db_numrows($res_count) > 0) {
118 $row_count = db_fetch_array($res_count);
119 return $row_count['numprojects'];
121 return _('No stats available')." ".db_error();
128 // c-file-style: "bsd"