4 // SourceForge: Breaking Down the Barriers to Open Source Development
5 // Copyright 1999-2001 (c) VA Linux Systems
6 // http://sourceforge.net
8 // Attempt to set up the include path, to fix problems with relative includes
10 require_once $gfcommon.'include/FusionForge.class.php';
11 require_once $gfcommon.'include/tag_cloud.php';
13 function show_features_boxes() {
14 GLOBAL $HTML,$sys_use_ratings,$sys_use_frs,$sys_use_project_tags;
16 plugin_hook ("features_boxes_top", array());
17 $return = '<h2 class="skip">' . _('Features Boxes') . '</h2>';
19 if ($sys_use_project_tags) {
20 $return .= $HTML->boxTop(_('Tag Cloud'), 'Tag_Cloud');
21 $return .= tag_cloud();
22 $return .= $HTML->boxMiddle(sprintf(_('%1$s Statistics'), $GLOBALS['sys_name']), 'Forge_Statistics');
24 $return .= $HTML->boxTop(sprintf(_('%1$s Statistics'), $GLOBALS['sys_name']), 'Forge_Statistics');
26 $return .= show_sitestats();
28 $return .= $HTML->boxMiddle(_('Top Project Downloads'), 'Top_Projects_Downloads');
29 $return .= show_top_downloads();
31 if ($sys_use_ratings) {
32 $return .= $HTML->boxMiddle(_('Highest Ranked Users'), 'Highest_Ranked_Users');
33 $return .= show_highest_ranked_users();
35 $return .= $HTML->boxMiddle(_('Most Active This Week'), 'Most_Active_This_Week');
36 $return .= show_highest_ranked_projects();
37 $return .= $HTML->boxMiddle(_('Recently Registered Projects'), 'Recently_Registered_Projects');
38 $return .= show_newest_projects();
39 $return .= $HTML->boxBottom();
40 plugin_hook ("features_boxes_bottom", array());
44 function show_top_downloads() {
45 // TODO yesterday is now defined as two days ago. Quick fix
46 // to allow download list to be cached before nightly
47 // aggregation is done. jbyers 2001.03.19
49 $month = date("Ym",time()-(2*3600*24));
50 $day = date("d",time()-(2*3600*24));
54 $res_topdown = db_query_params ('
55 SELECT groups.group_id,
57 groups.unix_group_name,
58 frs_dlstats_grouptotal_vw.downloads
59 FROM frs_dlstats_grouptotal_vw,groups
61 frs_dlstats_grouptotal_vw.group_id=groups.group_id AND groups.is_public=1 and groups.status=$1
62 ORDER BY downloads DESC
68 if (db_numrows($res_topdown) == 0) {
69 return _('No Stats Available');
72 while ($row_topdown = db_fetch_array($res_topdown)) {
73 if ($row_topdown['downloads'] > 0) {
74 $t_downloads = number_format($row_topdown['downloads']);
75 $t_prj_link = util_make_link_g ($row_topdown['unix_group_name'], $row_topdown['group_id'], $row_topdown['group_name']);
78 $return .= '<td class="width-stat-col1">' . $t_downloads . '</td>';
79 $return .= '<td>' . $t_prj_link . '</td>';
83 if ( $return != "" ) {
84 /* MFaure: test required to deal with a special case encountered on zforge by 20091204 */
86 $return = '<table summary="">' . $t_return . "</table>\n";
88 $return .= '<div class="align-center">' . util_make_link ('/top/', _('All the ranking'), array('class' => 'dot-link')) . '</div>';
95 function stats_getprojects_active_public() {
96 $res_count = db_query_params ('SELECT count(*) AS count FROM groups WHERE status=$1 AND is_public=1',
98 if (db_numrows($res_count) > 0) {
99 $row_count = db_fetch_array($res_count);
100 return $row_count['count'];
106 function stats_getprojects_total() {
107 $res_count = db_query_params ('SELECT count(*) AS count FROM groups WHERE status=$1 OR status=$2',
110 if (db_numrows($res_count) > 0) {
111 $row_count = db_fetch_array($res_count);
112 return $row_count['count'];
118 function stats_getpageviews_total() {
119 $res_count = db_query_params ('SELECT SUM(site_views) AS site, SUM(subdomain_views) AS subdomain FROM stats_site',
121 if (db_numrows($res_count) > 0) {
122 $row_count = db_fetch_array($res_count);
123 return ($row_count['site'] + $row_count['subdomain']);
129 function stats_downloads_total() {
130 $res_count = db_query_params ('SELECT SUM(downloads) AS downloads FROM stats_site',
132 if (db_numrows($res_count) > 0) {
133 $row_count = db_fetch_array($res_count);
134 return $row_count['downloads'];
140 function show_sitestats() {
141 global $sys_use_trove;
142 $gforge = new FusionForge();
144 $return .= _('Hosted Projects').': ';
145 if ($sys_use_trove) {
146 $return .= '<a href="softwaremap/full_list.php">';
148 $return .= '<strong>'.number_format($gforge->getNumberOfPublicHostedProjects()).'</strong>';
149 if ($sys_use_trove) {
152 $return .= "</p><p>";
153 $return .= _('Registered Users').': <strong>'.number_format($gforge->getNumberOfActiveUsers()).'</strong>';
158 function show_newest_projects() {
159 $res_newproj = db_query_params ('SELECT group_id,unix_group_name,group_name,register_time FROM groups WHERE is_public=1 AND status=$1 AND type_id=1 AND register_time > 0 ORDER BY register_time DESC', array ('A'), 10);
163 if (!$res_newproj || db_numrows($res_newproj) < 1) {
164 return _('No Stats Available')." ".db_error();
167 $return .= '<table summary="">' . "\n";
168 while ( $row_newproj = db_fetch_array($res_newproj) ) {
170 $t_prj_date = date(_('m/d'),$row_newproj['register_time']);
171 $t_prj_link = util_make_link_g ($row_newproj['unix_group_name'],$row_newproj['group_id'],$row_newproj['group_name']);
174 $return .= '<td class="width-stat-col1">' . $t_prj_date . "</td>";
175 $return .= '<td>' . $t_prj_link . '</td>';
176 $return .= "</tr>\n";
178 $return .= '</table>';
181 $return .= '<div class="align-center">'.util_make_link ('/softwaremap/full_list.php', _('All newest projects'), array('class' => 'dot-link')).'</div>';
185 function show_highest_ranked_users() {
186 //select out the users information to show the top users on the site
187 $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',
189 $rows=db_numrows($res);
190 if (!$res || $rows<1) {
191 return _('No Stats Available').db_error();
194 for ($i=0; $i<$rows; $i++) {
195 $return .= ($i+1).' - ('. number_format(db_result($res,$i,'metric'),4) .') '
196 . util_make_link_u (db_result($res,$i,'user_name'),db_result($res,$i,'user_id'),db_result($res,$i,'realname'))
200 $return .= '<div class="align-center">'.util_make_link ('/top/topusers.php', _('All users'), array('class' => 'dot-link')).'</div>';
204 function show_highest_ranked_projects() {
205 $result = db_query_params ('SELECT groups.group_name,groups.unix_group_name,groups.group_id,project_weekly_metric.ranking,project_weekly_metric.percentile FROM groups,project_weekly_metric WHERE groups.group_id=project_weekly_metric.group_id AND groups.is_public=1 AND groups.type_id=1 AND groups.status != $1 AND groups.use_stats=1 ORDER BY ranking ASC',
208 if (!$result || db_numrows($result) < 1) {
209 return _('No Stats Available')." ".db_error();
211 $return = '<table summary="">';
212 while ($row=db_fetch_array($result)) {
213 $t_prj_activity = number_format(substr($row['ranking'],0,5),0);
214 $t_prj_link = util_make_link_g ($row['unix_group_name'],$row['group_id'],$row['group_name']);
217 $return .= '<td class="width-stat-col1">'. $t_prj_activity . "</td>";
218 $return .= '<td>' . $t_prj_link . '</td>';
219 $return .= "</tr>\n";
221 $return .= "</table>";
222 $return .= '<div class="align-center">' . util_make_link ('/top/mostactive.php?type=week', _('All project activities'), array('class' => 'dot-link')) . '</div>';
230 // c-file-style: "bsd"