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.
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 by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FusionForge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 // Attempt to set up the include path, to fix problems with relative includes
28 require_once $gfcommon.'include/FusionForge.class.php';
29 require_once $gfcommon.'include/tag_cloud.php';
30 require_once $gfcommon.'include/Stats.class.php';
32 function show_features_boxes() {
35 plugin_hook ("features_boxes_top", array());
36 $return = '<h2 class="skip">' . _('Features Boxes') . '</h2>';
38 if (forge_get_config('use_project_tags')) {
39 $return .= $HTML->boxTop(_('Tag Cloud'), 'Tag_Cloud');
40 $return .= tag_cloud();
41 $return .= $HTML->boxMiddle(sprintf(_('%1$s Statistics'), forge_get_config ('forge_name')), 'Forge_Statistics');
43 $return .= $HTML->boxTop(sprintf(_('%1$s Statistics'), forge_get_config ('forge_name')), 'Forge_Statistics');
45 $return .= show_sitestats();
46 if (forge_get_config('use_frs')) {
47 $return .= $HTML->boxMiddle(_('Top Project Downloads'), 'Top_Projects_Downloads');
48 $return .= show_top_downloads();
50 if (forge_get_config('use_ratings')) {
51 $return .= $HTML->boxMiddle(_('Highest Ranked Users'), 'Highest_Ranked_Users');
52 $return .= show_highest_ranked_users();
54 $return .= $HTML->boxMiddle(_('Most Active This Week'), 'Most_Active_This_Week');
55 $return .= show_highest_ranked_projects();
56 $return .= $HTML->boxMiddle(_('Recently Registered Projects'), 'Recently_Registered_Projects');
57 $return .= show_newest_projects();
58 $return .= $HTML->boxMiddle(_('System Information'), 'System_Information');
59 $ff = new FusionForge();
60 $return .= sprintf(_('%s is running %s version %s'),
61 forge_get_config ('forge_name'),
63 $ff->software_version);
64 $return .= $HTML->boxBottom();
65 plugin_hook ("features_boxes_bottom", array());
69 function show_top_downloads() {
70 // TODO yesterday is now defined as two days ago. Quick fix
71 // to allow download list to be cached before nightly
72 // aggregation is done. jbyers 2001.03.19
74 $month = date("Ym",time()-(2*3600*24));
75 $day = date("d",time()-(2*3600*24));
79 $res_topdown = db_query_params ('
80 SELECT groups.group_id,
82 groups.unix_group_name,
83 frs_dlstats_grouptotal_vw.downloads
84 FROM frs_dlstats_grouptotal_vw,groups
86 frs_dlstats_grouptotal_vw.group_id=groups.group_id AND groups.is_public=1 and groups.status=$1
87 ORDER BY downloads DESC
93 while (($row_topdown=db_fetch_array($res_topdown)) && ($count < 10)) {
94 if (!forge_check_perm ('project_read', $row_topdown['group_id'])) {
97 if ($row_topdown['downloads'] > 0) {
98 $t_downloads = number_format($row_topdown['downloads']);
99 $t_prj_link = util_make_link_g ($row_topdown['unix_group_name'], $row_topdown['group_id'], $row_topdown['group_name']);
102 $return .= '<td class="width-stat-col1">' . $t_downloads . '</td>';
103 $return .= '<td>' . $t_prj_link . '</td>';
108 if ( $return == "" ) {
109 return _('No Stats Available');
112 $return = '<table summary="">' . $t_return . "</table>\n";
114 $return .= '<div class="align-center">' . util_make_link ('/top/', _('All the ranking'), array('class' => 'dot-link')) . '</div>';
120 function stats_getprojects_active_public() {
121 $ff = new FusionForge();
122 return $ff->getNumberOfPublicHostedProjects();
125 function stats_getprojects_total() {
126 $ff = new FusionForge();
127 return $ff->getNumberOfHostedProjects();
130 function stats_getpageviews_total() {
131 $res_count = db_query_params ('SELECT SUM(site_views) AS site, SUM(subdomain_views) AS subdomain FROM stats_site',
133 if (db_numrows($res_count) > 0) {
134 $row_count = db_fetch_array($res_count);
135 return ($row_count['site'] + $row_count['subdomain']);
141 function stats_downloads_total() {
142 $res_count = db_query_params ('SELECT SUM(downloads) AS downloads FROM stats_site',
144 if (db_numrows($res_count) > 0) {
145 $row_count = db_fetch_array($res_count);
146 return $row_count['downloads'];
152 function show_sitestats() {
154 $gforge = new FusionForge();
156 $return .= _('Hosted Projects').': ';
157 if (forge_get_config('use_trove')) {
158 $return .= '<a href="softwaremap/full_list.php">';
160 $return .= '<strong>'.number_format($gforge->getNumberOfPublicHostedProjects()).'</strong>';
161 if (forge_get_config('use_trove')) {
164 $return .= "</p><p>";
165 $return .= _('Registered Users').': <strong>'.number_format($gforge->getNumberOfActiveUsers()).'</strong>';
170 function show_newest_projects() {
171 $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'));
176 while (($row_newproj=db_fetch_array($res_newproj)) && ($count < 10)) {
177 if (!forge_check_perm ('project_read', $row_newproj['group_id'])) {
182 $t_prj_date = date(_('m/d'),$row_newproj['register_time']);
183 $t_prj_link = util_make_link_g ($row_newproj['unix_group_name'],$row_newproj['group_id'],$row_newproj['group_name']);
186 $return .= '<td class="width-stat-col1">' . $t_prj_date . "</td>";
187 $return .= '<td>' . $t_prj_link . '</td>';
188 $return .= "</tr>\n";
191 if ( $return == "" ) {
192 return _('No Stats Available');
195 $return = '<table summary="">' . $t_return . "</table>\n";
198 $return .= '<div class="align-center">'.util_make_link ('/softwaremap/full_list.php', _('All newest projects'), array('class' => 'dot-link')).'</div>';
202 function show_highest_ranked_users() {
203 //select out the users information to show the top users on the site
204 $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',
209 $rows = db_numrows($res);
211 return _('No Stats Available');
214 for ($i=0; $i < $rows; $i++) {
215 $return .= ($i+1).' - ('. number_format(db_result($res,$i,'metric'),4) .') '
216 . util_make_link_u (db_result($res, $i, 'user_name'), db_result($res, $i, 'user_id'),db_result($res,$i,'realname'))
220 $return .= '<div class="align-center">'.util_make_link('/top/topusers.php', _('All users'), array('class' => 'dot-link')).'</div>';
225 function show_highest_ranked_projects() {
226 $statsobj = new Stats();
227 $result = $statsobj->getMostActiveStats ('week', 0) ;
231 while (($row=db_fetch_array($result)) && ($count < 20)) {
232 if (!forge_check_perm ('project_read', $row['group_id'])) {
235 $t_prj_activity = number_format(substr($row['ranking'],0,5),0);
236 $t_prj_link = util_make_link_g ($row['unix_group_name'],$row['group_id'],$row['group_name']);
239 $return .= '<td class="width-stat-col1">'. $t_prj_activity . "</td>";
240 $return .= '<td>' . $t_prj_link . '</td>';
241 $return .= "</tr>\n";
245 if ( $return == "" ) {
246 return _('No Stats Available');
249 $return = '<table summary="">' . $t_return . "</table>\n";
252 $return .= '<div class="align-center">' . util_make_link ('/top/mostactive.php?type=week', _('All project activities'), array('class' => 'dot-link')) . '</div>';
259 // c-file-style: "bsd"