/[drupal]/contributions/modules/drupalorg/blocks_and_nodes/quick_stats.module
ViewVC logotype

Contents of /contributions/modules/drupalorg/blocks_and_nodes/quick_stats.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Fri Apr 17 23:03:11 2009 UTC (7 months, 1 week ago) by kbahey
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +31 -20 lines
File MIME type: text/x-php
Add some vital statistics about drupal.org
1 <?php
2 // $Id: quick_stats.module,v 1.5 2009/01/29 14:23:20 goba Exp $
3
4 /**
5 * Implementation of hook_nodeapi().
6 */
7 function quick_stats_nodeapi(&$node, $op = 'view', $teaser = FALSE, $page = FALSE) {
8 if ($op == 'view' && $page) {
9 $extra = '';
10 switch ($node->nid) {
11 case 146019:
12 $extra = quick_stats_handbook();
13 break;
14 case 190833:
15 $extra = quick_stats_report();
16 break;
17 }
18 $node->content['body']['#value'] .= $extra;
19 }
20 }
21
22 /**
23 * Handbook contribution stats.
24 */
25 function quick_stats_handbook() {
26 $total_count = 0;
27 $add_count = 0;
28 $delete_count = 0;
29 $newbie_count = 0;
30 $newbies = array();
31
32 // Retrieve a listing of all book pages added in the past week that are still in
33 // the node table:
34 $result = db_query("SELECT nid, title FROM {node} WHERE type = 'book' AND created >= %d", time() - 604800);
35 $books = array();
36 while ($book = db_fetch_object($result)) {
37 $books[$book->nid] = $book->title;
38 }
39
40 // Retrieve listing of *all* added book pages for the past week.
41 $result = db_query("SELECT wid, uid, link FROM {watchdog} WHERE message LIKE 'book: add%' AND type='content'");
42 while ($row = db_fetch_object($result)) {
43 $total_count++;
44 preg_match('!node/(\d+)!', $row->link, $matches);
45 $nid = $matches[1];
46 if (isset($books[$nid])) {
47 // Book was added and hasn't been deleted.
48 $add_count++;
49 if (!user_is_on_docs_team($row->uid)) {
50 // Book was created by a new user; not someone on docs team.
51 $newbie_count++;
52 $newbies[$row->uid][] = $nid;
53 }
54 }
55 else {
56 // Book page was spam.
57 $delete_count++;
58 }
59 }
60
61 // Get list of new contributors.
62 foreach ($newbies as $uid => $nodes) {
63 $name = db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $uid));
64 $newbies[$uid] = l($name, "user/$uid");
65 foreach ($nodes as $nid) {
66 $title = $books[$nid];
67 $newbie_nodes[$uid][] = l($title, "node/$nid");
68 }
69 }
70
71 $output .= "In the past week, a total of $total_count handbook pages were created. Of those, $delete_count were spam. Of the $add_count added, $newbie_count were created by people not on the documentation team: ". theme('new_contributions', $newbies, $newbie_nodes);
72
73 return $output;
74 }
75
76 /**
77 * Check whether the user by the given uid is on the docs team.
78 */
79 function user_is_on_docs_team($uid) {
80 // Role 4 = site maintaner, 5 = docs maintainer.
81 return db_result(db_query("SELECT 1 FROM {users_roles} WHERE uid = %d AND (rid = %d OR rid = %d)", $uid, 4, 5));
82 }
83
84 /**
85 * Theme the new contributors list.
86 */
87 function theme_new_contributions($newbies, $newbie_nodes) {
88 $output = '';
89 foreach ($newbies as $uid => $user) {
90 $output .= '<h3>'. $user .'</h3>';
91 $output .= theme('item_list', $newbie_nodes[$uid]);
92 }
93 return $output;
94 }
95
96 /**
97 * Overall quick stats for drupal.org.
98 */
99 function quick_stats_report() {
100 $output .= "<dl>";
101
102 $nodes = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE status = 1"));
103 $output .= "<dt>All content nodes:</dt><dd>". $nodes ." (excluding unpublished nodes)</dd>";
104
105 $nodes_last_year = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE created > %d AND status = 1", strtotime("1 year ago", time())));
106 $output .= "<dt>All content nodes in the last year:</dt><dd>". $nodes_last_year ." (excluding unpublished nodes)</dd>";
107
108 $book = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type = 'book' AND status = 1"));
109 $output .= "<dt>Book nodes:</dt><dd>". $book ."</dd>";
110
111 $users = db_result(db_query("SELECT COUNT(*) FROM {users} WHERE status = 1"));
112 $output .= "<dt>Users:</dt><dd>". $users ." (excludes blocked users)</dd>";
113
114 $comments = db_result(db_query("SELECT COUNT(*) FROM {comments} WHERE status = 1"));
115 $output .= "<dt>Comments:</dt><dd>". $comments ." (excluding unpublished comments)</dd>";
116
117 $projects = db_result(db_query("SELECT COUNT(*) FROM {project_projects}"));
118 $output .= "<dt>Total projects:</dt><dd>". $projects ."</dd>";
119
120 $issues = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type = 'project_issue' AND status = 1"));
121 $output .= "<dt>Total issues:</dt><dd>". $issues ." (excluding unpublished issues)</dd>";
122
123 $issues_year = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type = 'project_issue' AND created > %d AND status = 1", strtotime("1 year ago", time())));
124 $output .= "<dt>Issues in the last Year:</dt><dd>". $issues_year ."</dd>";
125
126 $followups = db_result(db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {comments} c ON n.nid = c.nid WHERE n.type = 'project_issue' AND n.status = 1"));
127 $output .= "<dt>Followups on issues:</dt><dd>". $followups ."</dd>";
128
129 $followups_year = db_result(db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {comments} c ON n.nid = c.nid WHERE n.type = 'project_issue' AND n.status = 1 AND n.created > (UNIX_TIMESTAMP() - 24 * 60* 60* 365)"));
130 $output .= "<dt>Followups on issues in last year:</dt><dd>". $followups_year ."</dd>";
131
132 $cvs_accts_approved = db_result(db_query('SELECT COUNT(*) FROM {cvs_accounts} WHERE status = %d', CVS_APPROVED));
133 $output .= "<dt>CVS accounts:</dt><dd>". $cvs_accts_approved ."</dd>";
134
135 $cvs_commits = db_result(db_query('SELECT COUNT(*) FROM {cvs_messages}'));
136 $output .= "<dt>CVS commits:</dt><dd>". $cvs_commits ."</dd>";
137
138 $cvs_commits_year = db_result(db_query('SELECT COUNT(*) FROM {cvs_messages} WHERE created > %d', strtotime("1 year ago")));
139 $output .= "<dt>CVS commits in last year:</dt><dd>". $cvs_commits_year ."</dd>";
140
141 $output .= "</dl>";
142
143 return $output;
144 }
145
146 /**
147 * Implementation of hook_theme().
148 */
149 function quick_stats_theme() {
150 return array(
151 'new_contributions' => array(
152 'arguments' => array('newbies' => NULL, 'newbie_nodes' => NULL),
153 ),
154 );
155 }

  ViewVC Help
Powered by ViewVC 1.1.2