4 * Copyright 1999-2001 (c) VA Linux Systems
5 * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
6 * http://fusionforge.org
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 // Attempt to set up the include path, to fix problems with relative includes
27 require_once $gfcommon.'include/FusionForge.class.php';
28 require_once $gfcommon.'include/tag_cloud.php';
29 require_once $gfcommon.'include/Stats.class.php';
31 function show_features_boxes() {
34 plugin_hook ("features_boxes_top", array());
35 $return = '<h2 class="skip">' . _('Features Boxes') . '</h2>';
37 if (forge_get_config('use_project_tags')) {
38 $return .= $HTML->boxTop(_('Tag Cloud'), 'Tag_Cloud');
39 $return .= tag_cloud();
40 $return .= $HTML->boxMiddle(sprintf(_('%1$s Statistics'), forge_get_config ('forge_name')), 'Forge_Statistics');
42 $return .= $HTML->boxTop(sprintf(_('%1$s Statistics'), forge_get_config ('forge_name')), 'Forge_Statistics');
44 $return .= show_sitestats();
45 if (forge_get_config('use_frs')) {
46 $return .= $HTML->boxMiddle(_('Top Project Downloads'), 'Top_Projects_Downloads');
47 $return .= show_top_downloads();
49 if (forge_get_config('use_ratings')) {
50 $return .= $HTML->boxMiddle(_('Highest Ranked Users'), 'Highest_Ranked_Users');
51 $return .= show_highest_ranked_users();
53 $return .= $HTML->boxMiddle(_('Most Active This Week'), 'Most_Active_This_Week');
54 $return .= show_highest_ranked_projects();
55 $return .= $HTML->boxMiddle(_('Recently Registered Projects'), 'Recently_Registered_Projects');
56 $return .= show_newest_projects();
57 $return .= $HTML->boxMiddle(_('System Information'), 'System_Information');
58 $ff = new FusionForge();
59 $return .= sprintf(_('%s is running %s version %s'),
60 forge_get_config ('forge_name'),
62 $ff->software_version);
63 $return .= $HTML->boxBottom();
64 plugin_hook ("features_boxes_bottom", array());
68 function show_top_downloads() {
69 // TODO yesterday is now defined as two days ago. Quick fix
70 // to allow download list to be cached before nightly
71 // aggregation is done. jbyers 2001.03.19
73 $month = date("Ym",time()-(2*3600*24));
74 $day = date("d",time()-(2*3600*24));
78 $res_topdown = db_query_params ('
79 SELECT groups.group_id,
81 groups.unix_group_name,
82 frs_dlstats_grouptotal_vw.downloads
83 FROM frs_dlstats_grouptotal_vw,groups
85 frs_dlstats_grouptotal_vw.group_id=groups.group_id AND groups.status=$1
86 ORDER BY downloads DESC
92 while (($row_topdown=db_fetch_array($res_topdown)) && ($count < 10)) {
93 if (!forge_check_perm ('project_read', $row_topdown['group_id'])) {
96 if ($row_topdown['downloads'] > 0) {
97 $t_downloads = number_format($row_topdown['downloads']);
98 $t_prj_link = util_make_link_g ($row_topdown['unix_group_name'], $row_topdown['group_id'], $row_topdown['group_name']);
101 $return .= '<td class="width-stat-col1">' . $t_downloads . '</td>';
102 $return .= '<td>' . $t_prj_link . '</td>';
107 if ( $return == "" ) {
108 return _('No Stats Available');
111 $return = '<table summary="">' . $t_return . "</table>\n";
113 $return .= '<div class="align-center">' . util_make_link ('/top/', _('All the ranking'), array('class' => 'dot-link')) . '</div>';
119 function stats_getprojects_active_public() {
120 $ff = new FusionForge();
121 return $ff->getNumberOfPublicHostedProjects();
124 function stats_getprojects_total() {
125 $ff = new FusionForge();
126 return $ff->getNumberOfHostedProjects();
129 function stats_getpageviews_total() {
130 $res_count = db_query_params ('SELECT SUM(site_views) AS site, SUM(subdomain_views) AS subdomain FROM stats_site',
132 if (db_numrows($res_count) > 0) {
133 $row_count = db_fetch_array($res_count);
134 return ($row_count['site'] + $row_count['subdomain']);
140 function stats_downloads_total() {
141 $res_count = db_query_params ('SELECT SUM(downloads) AS downloads FROM stats_site',
143 if (db_numrows($res_count) > 0) {
144 $row_count = db_fetch_array($res_count);
145 return $row_count['downloads'];
151 function show_sitestats() {
153 $gforge = new FusionForge();
155 $return .= _('Hosted Projects').': ';
156 if (forge_get_config('use_trove')) {
157 $return .= '<a href="softwaremap/full_list.php">';
159 $return .= '<strong>'.number_format($gforge->getNumberOfPublicHostedProjects()).'</strong>';
160 if (forge_get_config('use_trove')) {
163 $return .= "</p><p>";
164 $return .= _('Registered Users').': <strong>'.number_format($gforge->getNumberOfActiveUsers()).'</strong>';
169 function show_newest_projects() {
170 $res_newproj = db_query_params ('SELECT group_id,unix_group_name,group_name,register_time FROM groups WHERE status=$1 AND type_id=1 AND register_time > 0 ORDER BY register_time DESC', array ('A'));
175 while (($row_newproj=db_fetch_array($res_newproj)) && ($count < 10)) {
176 if (!forge_check_perm ('project_read', $row_newproj['group_id'])) {
181 $t_prj_date = date(_('m/d'),$row_newproj['register_time']);
182 $t_prj_link = util_make_link_g ($row_newproj['unix_group_name'],$row_newproj['group_id'],$row_newproj['group_name']);
185 $return .= '<td class="width-stat-col1">' . $t_prj_date . "</td>";
186 $return .= '<td>' . $t_prj_link . '</td>';
187 $return .= "</tr>\n";
190 if ( $return == "" ) {
191 return _('No Stats Available');
194 $return = '<table summary="">' . $t_return . "</table>\n";
197 $return .= '<div class="align-center">'.util_make_link ('/softwaremap/full_list.php', _('All newest projects'), array('class' => 'dot-link')).'</div>';
201 function show_highest_ranked_users() {
202 //select out the users information to show the top users on the site
203 $res = db_query_params('SELECT users.user_name,users.user_id,users.realname,user_metric.metric FROM user_metric,users WHERE users.user_id=user_metric.user_id AND user_metric.ranking < 11 AND users.status != $1 ORDER BY ranking ASC',
208 $rows = db_numrows($res);
210 return _('No Stats Available');
213 for ($i=0; $i < $rows; $i++) {
214 $return .= ($i+1).' - ('. number_format(db_result($res,$i,'metric'),4) .') '
215 . util_make_link_u (db_result($res, $i, 'user_name'), db_result($res, $i, 'user_id'),db_result($res,$i,'realname'))
219 $return .= '<div class="align-center">'.util_make_link('/top/topusers.php', _('All users'), array('class' => 'dot-link')).'</div>';
224 function show_highest_ranked_projects() {
225 $statsobj = new Stats();
226 $result = $statsobj->getMostActiveStats ('week', 0) ;
230 while (($row=db_fetch_array($result)) && ($count < 20)) {
231 if (!forge_check_perm ('project_read', $row['group_id'])) {
234 $t_prj_activity = number_format(substr($row['ranking'],0,5),0);
235 $t_prj_link = util_make_link_g ($row['unix_group_name'],$row['group_id'],$row['group_name']);
238 $return .= '<td class="width-stat-col1">'. $t_prj_activity . "</td>";
239 $return .= '<td>' . $t_prj_link . '</td>';
240 $return .= "</tr>\n";
244 if ( $return == "" ) {
245 return _('No Stats Available');
248 $return = '<table summary="">' . $t_return . "</table>\n";
251 $return .= '<div class="align-center">' . util_make_link ('/top/mostactive.php?type=week', _('All project activities'), array('class' => 'dot-link')) . '</div>';
258 // c-file-style: "bsd"