Index: xstatistics.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/xstatistics/xstatistics.module,v
retrieving revision 1.2
diff -u -r1.2 xstatistics.module
--- xstatistics.module	2 Aug 2005 19:44:21 -0000	1.2
+++ xstatistics.module	30 Oct 2005 13:24:51 -0000
@@ -16,9 +16,10 @@
   $output = "";
 
   switch ($section) {
-   case 'admin/system/modules#description':
+   case 'admin/modules#description':
       $output = t("Extends statistics for your site.");
       break;
+    case 'admin/help#xstatistics':
     case 'admin/statistics/summary':
       $output = t("This page shows usage statistics of your site");
       break;
@@ -26,7 +27,55 @@
   return $output;
 }
 
-function xstatistics_summary() {
+
+function xstatistics_block($op = 'list', $delta = 0) {
+  $block = array();
+  $title = array(t('Site Summary'), t('Site Usage'));
+
+  switch ($op) {
+    case 'list':
+      $block[0]['info'] = $title[0];
+      $block[1]['info'] = $title[1];
+      break;
+
+    case 'view':
+      switch ($delta) {
+        case 0:
+          $block['subject'] = t($title[$delta]);
+          $block['content'] = xstatistics_summary('block');
+          break;
+        case 1:
+          $block['subject'] = t($title[$delta]);
+          $block['content'] = xstatistics_usage('block');
+          break;
+        }
+      break;
+    }
+    return $block;
+}
+
+function xstatistics_summary($mode = 'page') {
+  $output = xstatistics_do_summary();
+  return xstatistics_output($mode, $output);
+}
+
+function xstatistics_usage($mode = 'page') {
+  $output = xstatistics_do_usage();
+  return xstatistics_output($mode, $output);
+}
+
+function xstatistics_output($mode = 'page', $output) {
+  switch($mode) {
+    case 'page':
+      print theme($mode, $output);
+      break;
+    case 'block':
+      return $output;
+      break;
+  }
+}
+
+function xstatistics_do_summary() {
   //prepare amount of node_views
   //todo rewrite to use count() and sum()
   $res =  db_query("SELECT totalcount, daycount FROM {node_counter}");
@@ -41,19 +90,18 @@
   $count_pageviews_day = db_fetch_array(db_query("SELECT COUNT(path) AS hits FROM {accesslog} WHERE timestamp >= %d", (time()-86400)));
 
   $header = array("description", "value");
-  $rows = array(array(t("Total amount of external referrers today"),$count_referrer_ext_day['referrers']),
-          array(t("Total amount of internal referrers today"),$count_referrer_int_day['referrers']),
-          array(t("Total amount of viewed nodes today"),$count_nodes_view_day),
-          array(t("Total amount of viewed nodes all time"),$count_nodes_view_tot),
-          array(t("Total amount of viewed pages today"), $count_pageviews_day['hits']),
-          array(t("Total amount of hits today"), $count_hits_day['hits'])
+  $rows = array(array(t("External referrers today"),$count_referrer_ext_day['referrers']),
+          array(t("Internal referrers today"),$count_referrer_int_day['referrers']),
+          array(t("Viewed nodes today"),$count_nodes_view_day),
+          array(t("Viewed nodes all time"),$count_nodes_view_tot),
+          array(t("Viewed pages today"), $count_pageviews_day['hits']),
+          array(t("Hits today"), $count_hits_day['hits'])
           );
   
-  $output = theme('table',$header, $rows);
-  print theme('page',$output);
+  return theme('table', $header, $rows);
 }
 
-function xstatistics_usage() {
+function xstatistics_do_usage() {
   //prepare amount of nodes
   $count_nodes_tot = db_fetch_array(db_query("SELECT COUNT(nid) FROM {node}"));
   $count_nodes_pub = db_fetch_array(db_query("SELECT COUNT(nid) FROM {node} WHERE status=1"));
@@ -66,14 +114,12 @@
   $count_comments_tot =  db_fetch_array(db_query("SELECT COUNT(cid) FROM {comments} WHERE status=0"));
 
   $header = array("description", "value");
-  $rows = array(array(t("Total amount of nodes"),$count_nodes_tot['COUNT(nid)']),
-          array(t("Total amount of published nodes"),$count_nodes_pub['COUNT(nid)']),
-          array(t("Total amount of nodes in the queue"),$count_nodes_que['COUNT(nid)']),
-          array(t("Total amount of comments"),$count_comments_tot['COUNT(cid)']),
-          array(t("Total amount of users"),$count_users_tot['COUNT(uid)']),
+  $rows = array(array(t("Nodes"),$count_nodes_tot['COUNT(nid)']),
+          array(t("Published nodes"),$count_nodes_pub['COUNT(nid)']),
+          array(t("Nodes in the queue"),$count_nodes_que['COUNT(nid)']),
+          array(t("Comments"),$count_comments_tot['COUNT(cid)']),
+          array(t("Users"),$count_users_tot['COUNT(uid)']),
           );
   
-  $output = theme('table', $header, $rows);
-  print theme('page', $output);
+  return theme('table', $header, $rows);
 }
-?>
\ No newline at end of file
