--- blockcache.module.orig	2006-09-17 19:02:26.000000000 +0200
+++ blockcache.module	2006-09-18 22:42:05.765760600 +0200
@@ -9,47 +9,46 @@
 
 /**
  * Implementation of hook_block().
+ * 
+ * TODO:
+ * - research / QA if bc_life really works
  */
 function blockcache_block($op = 'list', $delta = 0, $edit = array()) {
-  if ($op == 'list') {
-    return blockcache_get_blocks();
-  }
-  else if ($op == 'configure') {
-    $form['bc_type'] = array(
-      '#type' => 'radios',
-      '#title' => t('Cache type'),
-      '#options' => array('site' => t('site-wide'), 'page' => t('per page')),
-      '#default_value' => variable_get('bc_type_'. $delta, 'site'),
-      '#description' => t('Should this block be cached for each page or for the entire site? If the block content changes from page to page, you will want to select <em>per page</em>. Otherwise, select <em>site-wide</em>.'),
-    );
-    // should research this some more to see if this is really true
-    $form['bc_life'] = array(
-      '#type' => 'textfield',
-      '#title' => t('Cache lifetime'),
-      '#size' => 10,
-      '#default_value' => variable_get('bc_life_'. $delta, ''),
-      '#description' => t('Lifetime (in seconds) of this item in the cache. How often is the content of this block refreshed? Leave blank to refresh automatically when new content is created.'),
-    );
-    $r = db_fetch_object(db_query('SELECT * FROM {bc_blocks} WHERE my_delta = %d', $delta));
-    if (module_exist('help')) {
-      $helplink = t('<p>Find more help for the Block Cache module <a href="%help">here</a>.</p>', array('%help' => url('admin/help/blockcache')));
-    }
-    $form['bc_origlink'] = array(
-      '#value' => t("<div class=\"form-item\"><label>Further configuration:</label><p>The Block Cache module acts as a wrapper around the original block. Please visit <a href=\"%url\">the original block's configuration page</a> to change its configurations.</p>$helplink</div>", array('%url' => url('admin/block/configure/'. $r->module .'/'. $r->mod_delta))),
-    
-    );
-    return $form;
-  }
-  else if ($op == 'save') {
-    variable_set('bc_type_'. $delta, $edit['bc_type']);
-    variable_set('bc_life_'. $delta, trim($edit['bc_life']));
-  }
-  else if ($op == 'view') {
-    return blockcache_block_view($delta);
+  switch ($op) {
+  	case 'list':
+      return blockcache_get_blocks();
+    case 'configure':
+      $form['bc_type'] = array(
+        '#type' => 'radios',
+        '#title' => t('Cache type'),
+        '#options' => array('site' => t('site-wide'), 'page' => t('per page')),
+        '#default_value' => variable_get('bc_type_'. $delta, 'site'),
+        '#description' => t('Should this block be cached for each page or for the entire site? If the block content changes from page to page, you will want to select <em>per page</em>. Otherwise, select <em>site-wide</em>.'),
+      );
+      $form['bc_life'] = array(
+        '#type' => 'textfield',
+        '#title' => t('Cache lifetime'),
+        '#size' => 10,
+        '#default_value' => variable_get('bc_life_'. $delta, ''),
+        '#description' => t('Lifetime (in seconds) of this item in the cache. How often is the content of this block refreshed? Leave blank to refresh automatically when new content is created.'),
+      );
+      $r = db_fetch_object(db_query('SELECT * FROM {bc_blocks} WHERE my_delta = %d', $delta));
+      if (module_exist('help')) {
+        $helplink = t('<p>Find more help for the Block Cache module <a href="%help">here</a>.</p>', array('%help' => url('admin/help/blockcache')));
+      }
+      $form['bc_origlink'] = array(
+        '#value' => t("<div class=\"form-item\"><label>Further configuration:</label><p>The Block Cache module acts as a wrapper around the original block. Please visit <a href=\"%url\">the original block's configuration page</a> to change its configurations.</p>$helplink</div>", array('%url' => url('admin/block/configure/'. $r->module .'/'. $r->mod_delta))),
+      );
+      return $form;
+    case 'save':
+      variable_set('bc_type_'. $delta, $edit['bc_type']);
+      variable_set('bc_life_'. $delta, trim($edit['bc_life']));
+      break;
+    case 'view':
+      return blockcache_block_view($delta);
   }
 }
 
-
 /**
  * Implementation of hook_help().
  */
@@ -108,11 +107,11 @@ function blockcache_settings() {
  * - Yank out all of the "active" code... it's not needed
  */
 function blockcache_get_blocks() {
-  static $css;
-  if (!isset($css)) {
+  static $blockcache_css;
+  if (!isset($blockcache_css)) {
     $path = drupal_get_path('module', 'blockcache');
     theme('add_style', $path .'/blockcache.css');
-    $css = TRUE;
+    $blockcache_css = TRUE;
   }
   
   $blocks = array();
@@ -129,49 +128,50 @@ function blockcache_get_blocks() {
       $mod_blocks = module_invoke($module, 'block', 'list');
       if (is_array($mod_blocks)) {
         foreach($mod_blocks as $mod_delta => $info) {
-          // do we have this one saved?
           if ($delta = $blocks_lookup[$module][$mod_delta]) {
-            //yes...
-            
+            // block reference is already stored
           }
           else {
+            // store block reference
             $delta = db_next_id('{bc_blocks}');
             db_query('INSERT INTO {bc_blocks} (my_delta, module, mod_delta) VALUES (%d, "%s", "%s")', $delta, $module, $mod_delta);      
           }
-          $blocks[$delta]['info'] = $info['info'] . ' <em class="bc_cached">'. t('cached') .'</em>';
-          
+          $blocks[$delta]['info'] = $info['info'] .' <em class="bc_cached">'. t('cached') .'</em>';
         }
       }
     }
   }
   return $blocks;
-  
 }
 
 function blockcache_block_view($delta) {
   global $base_root;
-  $cache_name = variable_get('bc_type_'. $delta, 'site') == 'page' ? 'bc_'. $delta .'_'. $base_root . request_uri() : 'bc_'. $delta .'_'. $base_root;
+  
+  $cache_name = 'bc_'. $delta .'_'. $base_root;
+  if (variable_get('bc_type_'. $delta, 'site') == 'page') {
+    $cache_name = $cache_name . request_uri();
+  }
   $cached = cache_get($cache_name);
   if ($cached && ($cached->expire == CACHE_TEMPORARY || $cached->expire > time())) {
+    // fetch block from cache
     $block = unserialize($cached->data);
   }
   else {
-    // it's not cached. let's cache it
+    // block has to be cached
     $r = db_fetch_object(db_query('SELECT * FROM {bc_blocks} WHERE my_delta = %d', $delta));
     $block = module_invoke($r->module, 'block', 'view', $r->mod_delta);
     $cache = serialize($block);
     $expire = is_numeric(variable_get('bc_life_'.$delta, '')) ? time() + variable_get('bc_life_'.$delta, '') : CACHE_TEMPORARY;
     cache_set($cache_name, $cache, $expire);
     
-    // for testing:
+    // display debug message
     if (variable_get('bc_debug', 0) && user_access('administer nodes')) {
       drupal_set_message("Refreshed cache for module: <strong>$r->module</strong> delta: <strong>$r->mod_delta</strong> subject: <strong>{$block[subject]}</strong> as $cache_name");
     }
-    
   }
   return $block;
 }
 
 function blockcache_version(){
   return str_replace(array('$RCSf'.'ile:', ',v', '$Re'.'vision: ', '$Da'.'te: ', '$'), '', '<p style="font-size:x-small">$RCSfile: blockcache.module,v $ version: <b>$Revision: 1.1.2.1 $</b>, $Date: 2006/09/17 16:20:42 $</p>');
-}
\ No newline at end of file
+}
