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';
12 require_once $gfcommon.'include/Stats.class.php';
14 function show_features_boxes() {
15 GLOBAL $HTML,$sys_use_ratings,$sys_use_frs,$sys_use_project_tags;
17 plugin_hook ("features_boxes_top", array());
18 $return = '<h2 class="skip">' . _('Features Boxes') . '</h2>';
20 if ($sys_use_project_tags) {
21 $return .= $HTML->boxTop(_('Tag Cloud'), 'Tag_Cloud');
22 $return .= tag_cloud();
23 $return .= $HTML->boxMiddle(sprintf(_('%1$s Statistics'), fusionforge_get_config ('forge_name')), 'Forge_Statistics');
25 $return .= $HTML->boxTop(sprintf(_('%1$s Statistics'), fusionforge_get_config ('forge_name')), 'Forge_Statistics');
27 $return .= show_sitestats();
29 $return .= $HTML->boxMiddle(_('Top Project Downloads'), 'Top_Projects_Downloads');
30 $return .= show_top_downloads();
32 if ($sys_use_ratings) {
33 $return .= $HTML->boxMiddle(_('Highest Ranked Users'), 'Highest_Ranked_Users');
34 $return .= show_highest_ranked_users();
36 $return .= $HTML->boxMiddle(_('Most Active This Week'), 'Most_Active_This_Week');
37 $return .= show_highest_ranked_projects();
38 $return .= $HTML->boxMiddle(_('Recently Registered Projects'), 'Recently_Registered_Projects');
39 $return .= show_newest_projects();
40 $return .= $HTML->boxBottom();
41 plugin_hook ("features_boxes_bottom", array());
45 function show_top_downloads() {
46 // TODO yesterday is now defined as two days ago. Quick fix
47 // to allow download list to be cached before nightly
48 // aggregation is done. jbyers 2001.03.19
50 $month = date("Ym",time()-(2*3600*24));
51 $day = date("d",time()-(2*3600*24));
55 $res_topdown = db_query_params ('
56 SELECT groups.group_id,
58 groups.unix_group_name,
59 frs_dlstats_grouptotal_vw.downloads
60 FROM frs_dlstats_grouptotal_vw,groups
62 frs_dlstats_grouptotal_vw.group_id=groups.group_id AND groups.is_public=1 and groups.status=$1
63 ORDER BY downloads DESC
69 if (db_numrows($res_topdown) == 0) {
70 return _('No Stats Available');
73 while ($row_topdown = db_fetch_array($res_topdown)) {
74 if ($row_topdown['downloads'] > 0) {
75 $t_downloads = number_format($row_topdown['downloads']);
76 $t_prj_link = util_make_link_g ($row_topdown['unix_group_name'], $row_topdown['group_id'], $row_topdown['group_name']);
79 $return .= '<td class="width-stat-col1">' . $t_downloads . '</td>';
80 $return .= '<td>' . $t_prj_link . '</td>';
84 if ( $return != "" ) {
85 /* MFaure: test required to deal with a special case encountered on zforge by 20091204 */
87 $return = '<table summary="">' . $t_return . "</table>\n";
89 $return .= '<div class="align-center">' . util_make_link ('/top/', _('All the ranking'), array('class' => 'dot-link')) . '</div>';
96 function stats_getprojects_active_public() {
97 $res_count = db_query_params ('SELECT count(*) AS count FROM groups WHERE status=$1 AND is_public=1',
99 if (db_numrows($res_count) > 0) {
100 $row_count = db_fetch_array($res_count);
101 return $row_count['count'];
107 function stats_getprojects_total() {
108 $res_count = db_query_params ('SELECT count(*) AS count FROM groups WHERE status=$1 OR status=$2',
111 if (db_numrows($res_count) > 0) {
112 $row_count = db_fetch_array($res_count);
113 return $row_count['count'];
119 function stats_getpageviews_total() {
120 $res_count = db_query_params ('SELECT SUM(site_views) AS site, SUM(subdomain_views) AS subdomain FROM stats_site',
122 if (db_numrows($res_count) > 0) {
123 $row_count = db_fetch_array($res_count);
124 return ($row_count['site'] + $row_count['subdomain']);
130 function stats_downloads_total() {
131 $res_count = db_query_params ('SELECT SUM(downloads) AS downloads FROM stats_site',
133 if (db_numrows($res_count) > 0) {
134 $row_count = db_fetch_array($res_count);
135 return $row_count['downloads'];
141 function show_sitestats() {
142 global $sys_use_trove;
143 $gforge = new FusionForge();
145 $return .= _('Hosted Projects').': ';
146 if ($sys_use_trove) {
147 $return .= '<a href="softwaremap/full_list.php">';
149 $return .= '<strong>'.number_format($gforge->getNumberOfPublicHostedProjects()).'</strong>';
150 if ($sys_use_trove) {
153 $return .= "</p><p>";
154 $return .= _('Registered Users').': <strong>'.number_format($gforge->getNumberOfActiveUsers()).'</strong>';
159 function show_newest_projects() {
160 $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);
164 if (!$res_newproj || db_numrows($res_newproj) < 1) {
165 return _('No Stats Available')." ".db_error();
168 $return .= '<table summary="">' . "\n";
169 while ( $row_newproj = db_fetch_array($res_newproj) ) {
171 $t_prj_date = date(_('m/d'),$row_newproj['register_time']);
172 $t_prj_link = util_make_link_g ($row_newproj['unix_group_name'],$row_newproj['group_id'],$row_newproj['group_name']);
175 $return .= '<td class="width-stat-col1">' . $t_prj_date . "</td>";
176 $return .= '<td>' . $t_prj_link . '</td>';
177 $return .= "</tr>\n";
179 $return .= '</table>';
182 $return .= '<div class="align-center">'.util_make_link ('/softwaremap/full_list.php', _('All newest projects'), array('class' => 'dot-link')).'</div>';
186 function show_highest_ranked_users() {
187 //select out the users information to show the top users on the site
188 $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',
190 $rows=db_numrows($res);
191 if (!$res || $rows<1) {
192 return _('No Stats Available').db_error();
195 for ($i=0; $i<$rows; $i++) {
196 $return .= ($i+1).' - ('. number_format(db_result($res,$i,'metric'),4) .') '
197 . util_make_link_u (db_result($res,$i,'user_name'),db_result($res,$i,'user_id'),db_result($res,$i,'realname'))
201 $return .= '<div class="align-center">'.util_make_link ('/top/topusers.php', _('All users'), array('class' => 'dot-link')).'</div>';
205 function show_highest_ranked_projects() {
206 $statsobj = new Stats () ;
207 $result = $statsobj->getMostActiveStats ('week', 0) ;
208 if (!$result || db_numrows($result) < 1) {
209 return _('No Stats Available')." ".db_error();
211 $return = '<table summary="">';
213 while (($row=db_fetch_array($result)) && ($count < 20)) {
214 $t_prj_activity = number_format(substr($row['ranking'],0,5),0);
215 $t_prj_link = util_make_link_g ($row['unix_group_name'],$row['group_id'],$row['group_name']);
218 $return .= '<td class="width-stat-col1">'. $t_prj_activity . "</td>";
219 $return .= '<td>' . $t_prj_link . '</td>';
220 $return .= "</tr>\n";
224 $return .= "</table>";
225 $return .= '<div class="align-center">' . util_make_link ('/top/mostactive.php?type=week', _('All project activities'), array('class' => 'dot-link')) . '</div>';
233 // c-file-style: "bsd"