3 * FusionForge globalsearch plugin
5 * Copyright 2003-2004, GForge, LLC
6 * Copyright 2007-2009, Roland Mas
7 * Copyright 2011, Franck Villaume - Capgemini
9 * This file is part of FusionForge.
11 * FusionForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published
13 * by the Free Software Foundation; either version 2 of the License,
14 * or (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 class globalSearchPlugin extends Plugin {
27 function globalSearchPlugin() {
29 $this->name = "globalsearch";
30 $this->_addHook('site_admin_option_hook');
31 $this->_addHook('features_boxes_top');
34 function CallHook($hookname, &$params) {
37 if ($hookname == "site_admin_option_hook") {
38 print '<li><a href="/plugins/globalsearch/edit_assoc_sites.php">'._("Admin Associated Forges"). ' [' . _('Global Search plugin') . ']</a></li>';
39 } elseif ($hookname == "features_boxes_top") {
40 (isset($params['returned_text'])) ? $params['returned_text'] .= $HTML->boxTop(_('Associated Forges'), 'Associated_Forges') : $params['returned_text'] = $HTML->boxTop(_('Associated Forges'), 'Associated_Forges');
41 $params['returned_text'] .= $this->show_top_n_assocsites(5);
42 $params['returned_text'] .= $this->search_box();
47 * @return string html code to display
49 function show_globalsearch_stats_boxes() {
53 $return .= $HTML->boxTop(_("Global Search"));
54 $return .= globalsearch_box();
55 $return .= $HTML->boxMiddle(_("Top associated forges"));
56 $return .= show_top_n_assocsites(5);
57 $return .= "<div align=\"center\">".sprintf(_("Total projects in associated forges: <b>%1$d</b>"),stats_get_total_projects_assoc_sites()). "</div>";
58 $return .= $HTML->boxBottom();
63 * @return string html code to display
65 function search_box() {
66 global $HTML, $gwords, $gexact, $otherfreeknowledge;
68 $return = '<form method="post" action="/plugins/globalsearch/">';
69 $return .= $HTML->html_text_input_img_submit('gwords', 'magnifier.png', 'search_associated_forges', '', $gwords, _('Search associated forges'));
70 $return .= $HTML->html_checkbox('otherfreeknowledge', '1', 'search_associated_forges_otherfreeknowledge', _('Extend search to include non-software projects'), $otherfreeknowledge);
71 $return .= $HTML->html_checkbox('gexact', '1', 'search_associated_forges_exact', _('Require all words'), $gexact);
78 * show_top_n_assocsites() - Show the n top ranked associated sites
80 * @param string Number of associated sites to show
81 * @return string html code to display
83 function show_top_n_assocsites($num_assocsites) {
84 $res_top_n_assoc = db_query_params('
85 SELECT a.title, a.link, count(*) AS numprojects
86 FROM plugin_globalsearch_assoc_site_project p, plugin_globalsearch_assoc_site a
87 WHERE p.assoc_site_id = a.assoc_site_id AND p.assoc_site_id IN
88 (SELECT assoc_site_id FROM plugin_globalsearch_assoc_site
89 WHERE status_id = 2 AND enabled=$1 ORDER BY rank LIMIT $2)
90 GROUP BY a.title, a.link',
91 array('t', $num_assocsites));
93 if (db_numrows($res_top_n_assoc) == 0) {
94 return _('No stats available')." ".db_error();
97 $return .= '<table class="underline-link">';
98 while ($row_topdown = db_fetch_array($res_top_n_assoc)) {
99 if ($row_topdown['numprojects'] > 0) {
100 $return .= '<tr><td>';
101 $return .= '<a href="' . $row_topdown[link] . '/">';
102 $return .= $row_topdown[title] . "</a>";
104 $return .= '<td class="align-right">' . number_format($row_topdown[numprojects], 0);
105 $return .= " projects";
106 $return .= "</td></tr>\n";
109 $return .= "</table>";
115 * stats_get_total_projects_assoc_sites() - Show the total number of projects of associated sites
117 * @param string Number of associated sites to show
118 * @return string statistiques
121 function stats_get_total_projects_assoc_sites() {
122 $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',
124 if (db_numrows($res_count) > 0) {
125 $row_count = db_fetch_array($res_count);
126 return $row_count['numprojects'];
128 return _('No stats available')." ".db_error();
135 // c-file-style: "bsd"