Want your theme to be compatible with Context module? Better check your theme_blocks

I got a bug report for the Syan theme today about problems with openpublish - all the blocks were gone. I hadn't tried openpublish before so I decided to check it out. Wow! A 10 megabyte Drupal distribution, including well over a hundred contrib modules. Furthermore, this distribution bypasses the Drupal block system and uses the Context module instead. After deleting some fix in my theme's code I discovered that theme_blocks was the culprit. I checked the Context module code and found that Context was overriding theme_blocks! It uses this to output block content through it's own system, unfortunately there appears no other way to hook into the block content other than using the theme function. If you want your theme to be compatible with the theme_blocks function in your theme, you're going to have to add some code, as commented by the Context developer yhahn in context.core.inc:

// Reroute theme_blocks() through context_blocks to determine block // visibility by context. Only override theme_blocks() if a theme // has not overridden it. It is the responsibility of any themes // implementing theme_blocks() to take advantage of context block // visibility on their own.

Thus if your theme overrides theme_blocks you're going to have something like this:

// Add first/last classes to blocks
function sooper_prt_syan_blocks($region) {
  
	if (module_exists("context")){
	  $output = '';
	  // Bail if this region is disabled.
	  $disabled_regions = context_active_values('theme_regiontoggle');
	  if (!empty($disabled_regions) && in_array($region, $disabled_regions)) {
		return '';
	  }
	  if ($list = context_block_list($region)) {
		foreach ($list as $key => $block) {
		  $output .= theme("block", $block);
		}
	  }
	  return $output . drupal_get_content($region);
	} else {
	  $output = '';
    if ($list = block_list($region)) {
      $i = 1;
      $count = count($list);
      foreach ($list as $key => $block) {
        // $key == <i>module</i>_<i>delta</i>
        if ($i == 1){ // is this the first block in this region?
          $block->first_last = 'first';
        }
        if ($i == $count){ // is this the last block in this region?
          $block->first_last = 'last';
        }
        $output .= theme('block', $block);
        $i++;
      }
    }

    // Add any content assigned to this region through drupal_set_content() calls.
    $output .= drupal_get_content($region);

    return $output;
  }
}
Not too difficult but it would be nice if Context module would throw a warning if there was a theme override of theme_blocks :)