diff --git a/context_respect.info b/context_respect.info
index d790916..6b4278b 100644
--- a/context_respect.info
+++ b/context_respect.info
@@ -1,11 +1,8 @@
 name = Context Respect
 description = "Respect normal block visibility."
 package = "Context"
-core = "6.x"
+core = "7.x"
 dependencies[] = ctools
 dependencies[] = context
-
-version = "6.x-3.0-beta1"
-core = "6.x"
+core = "7.x"
 project = "context_reaction"
-datestamp = "1278977706"
\ No newline at end of file
diff --git a/plugins/context_respect_reaction_block.inc b/plugins/context_respect_reaction_block.inc
index 0849fef..2cce362 100644
--- a/plugins/context_respect_reaction_block.inc
+++ b/plugins/context_respect_reaction_block.inc
@@ -1,7 +1,8 @@
 <?php
+// $Id: context_reaction_block.inc,v 1.1.2.35.2.10 2010/12/09 22:24:25 yhahn Exp $
 
 /**
- * Expose permissions as context reactions.
+ * Expose blocks as context reactions.
  */
 class context_respect_reaction_block extends context_reaction {
   /**
@@ -57,7 +58,7 @@ class context_respect_reaction_block extends context_reaction {
       '#tree' => TRUE,
       '#theme' => 'context_block_regions_form',
     );
-    foreach (system_region_list($theme_key) as $region => $label) {
+    foreach (system_region_list($theme_key, REGIONS_VISIBLE) as $region => $label) {
       $form['blocks'][$region] = array(
         '#type' => 'item',
         '#title' => $label,
@@ -113,34 +114,35 @@ class context_respect_reaction_block extends context_reaction {
    */
   function editor_form($context) {
     $form = array();
-    if (module_exists('jquery_ui')) {
-      jquery_ui_add(array('ui.draggable', 'ui.droppable', 'ui.sortable'));
-      drupal_add_js(drupal_get_path('module', 'context_ui') .'/json2.js');
-      drupal_add_js(drupal_get_path('module', 'context') .'/plugins/context_reaction_block.js');
-      drupal_add_css(drupal_get_path('module', 'context') .'/plugins/context_reaction_block.css');
-
-      // We might be called multiple times so use a static to ensure this is set just once.
-      static $once;
-      if (!isset($once)) {
-        $settings = array(
-          'path' => url($_GET['q']),
-          'params' => (object) array_diff_key($_GET, array('q' => '')),
-          'scriptPlaceholder' => theme('context_block_script_placeholder', ''),
-        );
-        drupal_add_js(array('contextBlockEditor' => $settings), 'setting');
-        $once = TRUE;
-      }
-
-      $form['state'] = array(
-        '#type' => 'hidden',
-        '#attributes' => array('class' => 'context-block-editor-state'),
+    drupal_add_library('system', 'ui.droppable');
+    drupal_add_library('system', 'ui.sortable');
+    drupal_add_js(drupal_get_path('module', 'context_ui') .'/json2.js');
+    drupal_add_js(drupal_get_path('module', 'context') .'/plugins/context_reaction_block.js');
+    drupal_add_css(drupal_get_path('module', 'context') .'/plugins/context_reaction_block.css');
+
+    // We might be called multiple times so use a static to ensure this is set just once.
+    static $once;
+    if (!isset($once)) {
+      $settings = array(
+        'path' => url($_GET['q']),
+        'params' => (object) array_diff_key($_GET, array('q' => '')),
+        'scriptPlaceholder' => theme('context_block_script_placeholder', array('text' => '')),
       );
-      $form['browser'] = array(
-        '#type' => 'markup',
-        '#value' => theme('context_block_browser', $this->get_blocks(NULL, NULL, $this->rebuild_needed()), $context),
-      );
-      $this->rebuild_needed(FALSE);
+      drupal_add_js(array('contextBlockEditor' => $settings), 'setting');
+      $once = TRUE;
     }
+
+    $form['state'] = array(
+      '#type' => 'hidden',
+      '#attributes' => array('class' => array('context-block-editor-state')),
+    );
+    $form['browser'] = array(
+      '#markup' => theme('context_block_browser', array(
+        'blocks' => $this->get_blocks(NULL, NULL, $this->rebuild_needed()),
+        'context' => $context
+      )),
+    );
+    $this->rebuild_needed(FALSE);
     return $form;
   }
 
@@ -186,16 +188,6 @@ class context_respect_reaction_block extends context_reaction {
    */
   function settings_form() {
     $form = array();
-    $form['context_reaction_block_disable_core'] = array(
-      '#title' => t('Core block system'),
-      '#type' => 'select',
-      '#options' => array(
-        FALSE => t('Enabled'),
-        TRUE => t('Disabled'),
-      ),
-      '#default_value' => variable_get('context_reaction_block_disable_core', FALSE),
-      '#description' => t('If enabled Context will include blocks enabled through the core block system when rendering regions. Disable to improve performance and hide the core block administration UI.')
-    );
     $form['context_reaction_block_all_regions'] = array(
       '#title' => t('Show all regions'),
       '#type' => 'checkbox',
@@ -208,214 +200,164 @@ class context_respect_reaction_block extends context_reaction {
   /**
    * Execute.
    */
-  function execute($region) {
+  function execute(&$page) {
+    global $theme;
+
+    // The theme system might not yet be initialized. We need $theme.
+    drupal_theme_initialize();
+
     // If the context_block querystring param is set, switch to AJAX rendering.
     // Note that we check the output buffer for any content to ensure that we
     // are not in the middle of a PHP template render.
     if (isset($_GET['context_block']) && !ob_get_contents()) {
       return $this->render_ajax($_GET['context_block']);
     }
-    if ($this->is_enabled_region($region)) {
-      return theme('context_block_editable_region', $region, $this->block_list($region), $this->is_editable());
+
+    // Populate all block regions
+    $all_regions = system_region_list($theme);
+
+    // Load all region content assigned via blocks.
+    foreach (array_keys($all_regions) as $region) {
+      if ($this->is_enabled_region($region)) {
+        $page[$region] = isset($page[$region]) ? array_merge($page[$region], $this->block_get_blocks_by_region($region)) : $this->block_get_blocks_by_region($region);
+      }
     }
-    return '';
+  }
+
+  /**
+   * Return a list of enabled regions for which blocks should be built.
+   * Split out into a separate method for easy overrides in extending classes.
+   */
+  protected function is_enabled_region($region) {
+    global $theme;
+    $regions = array_keys(system_region_list($theme));
+    return in_array($region, $regions, TRUE);
   }
 
   /**
    * Determine whether inline editing requirements are met and that the current
    * user may edit.
    */
-  protected function is_editable($reset = FALSE) {
+  protected function is_editable_region($region, $reset = FALSE) {
     // Check requirements.
     // Generally speaking, it does not make sense to allow anonymous users to
     // edit a context inline. Though it may be possible to save (and restore)
     // an edited context to an anonymous user's cookie or session, it's an
     // edge case and probably not something we want to encourage anyway.
-    static $editable;
-    if (!isset($editable) || $reset) {
+    static $requirements;
+    if (!isset($requirements) || $reset) {
       global $user;
-      if (module_exists('jquery_ui') && $user->uid) {
-        $editable = TRUE;
-        jquery_ui_add(array('ui.draggable', 'ui.droppable', 'ui.sortable'));
+      if ($user->uid) {
+        $requirements = TRUE;
+        drupal_add_library('system', 'ui.droppable');
+        drupal_add_library('system', 'ui.sortable');
         drupal_add_js(drupal_get_path('module', 'context') .'/plugins/context_reaction_block.js');
         drupal_add_css(drupal_get_path('module', 'context') .'/plugins/context_reaction_block.css');
       }
       else {
-        $editable = FALSE;
+        $requirements = FALSE;
       }
     }
-    return $editable;
+    // Check that this region is not locked by the theme.
+    global $theme;
+    $info = system_get_info('theme', $theme);
+    if ($info && isset($info['regions_locked']) && in_array($region, $info['regions_locked'])) {
+      return FALSE;
+    }
+    // Check that this region is not hidden
+    $visible = system_region_list($theme, REGIONS_VISIBLE);
+    return $requirements && $this->is_enabled_region($region) && isset($visible[$region]);
   }
 
   /**
-   * Return a list of enabled regions for which blocks should be built.
-   * Split out into a separate method for easy overrides in extending classes.
+   * Add markup for making a block editable.
    */
-  protected function is_enabled_region($region) {
-    global $theme;
-    $regions = array_keys(system_region_list($theme));
-    return in_array($region, $regions, TRUE);
+  protected function editable_block($block) {
+    if (!empty($block->content['#markup']) || element_children($block->content)) {
+      $block->content = array(
+        'content' => $block->content,
+        'context' => array('#markup' => "<a id='context-block-{$block->module}-{$block->delta}' class='context-block editable edit-{$block->context}'></a>"),
+      );
+    }
+    return $block;
+  }
+
+  /**
+   * Add markup for making a region editable.
+   */
+  protected function editable_region($region, $build) {
+    if ($this->is_editable_region($region) && (!empty($build) || variable_get('context_reaction_block_all_regions', FALSE))) {
+      global $theme;
+      $regions = system_region_list($theme);
+      $name = isset($regions[$region]) ? $regions[$region] : $region;
+      $build['context']['#markup'] = "<a class='context-block-region' id='context-block-region-{$region}'>{$name}</a>";
+    }
+    return $build;
   }
 
   /**
-  * An alternative version of block_list() that provides any context enabled blocks.
+  * Get a renderable array of a region containing all enabled blocks.
   */
-  function block_list($region) {
-    static $build_queue;
-    static $build_contexts;
-    static $context_blocks = array();
-    static $empty_blocks = array();
-    global $user;
-    $rids = array_keys($user->roles);
+  function block_get_blocks_by_region($region) {
+    module_load_include('module', 'block', 'block');
 
-    // Static cache a region => block array of blocks that should be built *if*
-    // the given region is requested. Note that the blocks are not themselves
-    // built in this first run as not all regions may be requested even if
-    // active contexts include blocks in those regions.
+    $build = array();
+    if ($list = $this->block_list($region)) {
+      $build = _block_get_renderable_array($list);
+    }
+    if ($this->is_editable_region($region)) {
+      $build = $this->editable_region($region, $build);
+    }
+    return $build;
+  }
+
+  /**
+   * An alternative version of block_list() that provides any context enabled blocks.
+   */
+  function block_list($region) {
+    module_load_include('module', 'block', 'block');
+    $context_blocks = &drupal_static('context_reaction_block_list');;
     $contexts = context_active_contexts();
-    if (!isset($build_queue) || $build_contexts != array_keys($contexts)) {
+    if (!isset($context_blocks)) {
       $info = $this->get_blocks();
-      $build_queue = array();
-      $build_contexts = array_keys($contexts);
+      $context_blocks = array();
       foreach ($contexts as $context) {
         $options = $this->fetch_from_context($context);
         if (!empty($options['blocks'])) {
           foreach ($options['blocks'] as $block) {
             $block = (object) $block;
+            $block->title = NULL;
             $block->context = $context->name;
             $block->bid = "{$block->module}-{$block->delta}";
-            $block->cache = isset($info[$block->bid]->cache) ? $info[$block->bid]->cache : BLOCK_NO_CACHE;
-            $page_match = TRUE;
-            $role_match = TRUE;
+            $block->cache = isset($info[$block->bid]->cache) ? $info[$block->bid]->cache : DRUPAL_NO_CACHE;
             
-            // check role access
-            if (!drupal_match_path($_GET['q'], 'admin/build/context/*')) {
-              $block_rids = db_query("SELECT rid FROM {blocks_roles} WHERE module = '%s' AND delta = '%s'", $block->module, $block->delta);
-              while ($block_rid = db_result($block_rids)) {
-                if (in_array($block_rid, $rids)) {
-                  // found a matching role
-                  $role_match = TRUE;
-                  break;
-                }
-                else {
-                  // didn't match the role
-                  $role_match = FALSE;
-                }
-              }
-            }
+            //Check role access
+            $role_match = $this->check_role_match($block);
             
-            // check page access
-            $block_data = db_fetch_object(db_query("SELECT pages, visibility FROM {blocks} WHERE module = '%s' AND delta = '%s'", $block->module, $block->delta));
-            if ($block_data->pages && !drupal_match_path($_GET['q'], 'admin/build/context/*')) {
-              if ($block_data->visibility < 2) {
-                $path = drupal_get_path_alias($_GET['q']);
-                // Compare with the internal and path alias (if any).
-                $page_match = drupal_match_path($path, $block_data->pages);
-                if ($path != $_GET['q']) {
-                  $page_match = $page_match || drupal_match_path($_GET['q'], $block_data->pages);
-                }
-                // When $block->visibility has a value of 0, the block is displayed on
-                // all pages except those listed in $block->pages. When set to 1, it
-                // is displayed only on those pages listed in $block->pages.
-                $page_match = !($block_data->visibility xor $page_match);
-              }
-              else {
-                $page_match = drupal_eval($block_data->pages);
-              }
-            }
+            //Check path access
+            $page_match = $this->check_page_match($block);
             
-            // add to region
-            if ($page_match && $role_match) {
-              $build_queue[$block->region][] = $block;
+            if($page_match && $role_match) {
+              $context_blocks[$block->region][$block->bid] = $block;
             }
           }
         }
       }
-    }
+      foreach ($context_blocks as $r => $blocks) {
+        $context_blocks[$r] = _block_render_blocks($blocks);
 
-    // Context blocks.
-    if (!isset($context_blocks[$region])) {
-      $context_blocks[$region] = array();
-      $empty_blocks[$region] = array();
-      if (!empty($build_queue[$region])) {
-        foreach ($build_queue[$region] as $block) {
-          $block = $this->build_block($block);
-          if (!empty($block->content)) {
-            $context_blocks[$region][] = $block;
-          }
-          else {
-            $empty_blocks[$region][] = $block;
+        // Make blocks editable if allowed.
+        if ($this->is_editable_region($r)) {
+          foreach ($context_blocks[$r] as $key => $block) {
+            $context_blocks[$r][$key] = $this->editable_block($block);
           }
         }
-      }
-    }
-
-    // Get core blocks only if enabled.
-    $blocks = !variable_get('context_reaction_block_disable_core', FALSE) ? block_list($region) : array();
-    $blocks = array_merge($blocks, $context_blocks[$region]);
 
-    // Only include empty blocks if all regions should be shown or there are
-    // non-empty blocks in the same region.
-    $all_regions = variable_get('context_reaction_block_all_regions', FALSE);
-    if ($this->is_editable() && ($all_regions || !empty($blocks))) {
-      $blocks = array_merge($blocks, $empty_blocks[$region]);
-    }
-
-    // Sort everything.
-    uasort($blocks, array('context_respect_reaction_block', 'block_sort'));
-    return $blocks;
-  }
-
-  /**
-   * Build a block's content. Largely taken from block_list().
-   */
-  protected function build_block($block, $reset = FALSE) {
-    // Block caching is not compatible with node_access modules. We also
-    // preserve the submission of forms in blocks, by fetching from cache
-    // only if the request method is 'GET'.
-    static $cacheable;
-    if (!isset($cacheable) || $reset) {
-      $cacheable = !count(module_implements('node_grants')) && $_SERVER['REQUEST_METHOD'] == 'GET';
-    }
-
-    if (!isset($block->content)) {
-      $block->content = '';
-      // Try fetching the block from cache.
-      if ($cacheable && ($cid = _block_get_cache_id($block))) {
-        if ($cache = cache_get($cid, 'cache_block')) {
-          $array = $cache->data;
-        }
-        else {
-          $array = module_invoke($block->module, 'block', 'view', $block->delta);
-          cache_set($cid, $array, 'cache_block', CACHE_TEMPORARY);
-        }
-      }
-      // Otherwise build block.
-      else {
-        $array = module_invoke($block->module, 'block', 'view', $block->delta);
-      }
-      if (isset($array) && is_array($array)) {
-        foreach ($array as $k => $v) {
-          $block->$k = $v;
-        }
+        // Sort blocks.
+        uasort($context_blocks[$r], array('context_reaction_block', 'block_sort'));
       }
     }
-    if (!empty($block->content)) {
-      // Only query for custom block title if block core compatibility is enabled.
-      if (!variable_get('context_reaction_block_disable_core', FALSE)) {
-        global $user, $theme_key;
-        $block->title = db_result(db_query("SELECT title FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block->module, $block->delta, $theme_key));
-      }
-      // Override default block title if a custom display title is present.
-      if (!empty($block->title)) {
-        // Check plain here to allow module generated titles to keep any markup.
-        $block->subject = $block->title == '<none>' ? '' : check_plain($block->title);
-      }
-      if (!isset($block->subject)) {
-        $block->subject = '';
-      }
-    }
-    return $block;
+    return isset($context_blocks[$region]) ? $context_blocks[$region] : array();
   }
 
   /**
@@ -457,8 +399,6 @@ class context_respect_reaction_block extends context_reaction {
    */
   function get_blocks($region = NULL, $context = NULL, $reset = FALSE) {
     static $block_info;
-    global $user;
-    $rids = array_keys($user->roles);
 
     if (!isset($block_info) || $reset) {
       $block_info = array();
@@ -467,58 +407,15 @@ class context_respect_reaction_block extends context_reaction {
       }
       if (empty($block_info)) {
         $block_info = array();
-        foreach (module_implements('block') as $module) {
-          $module_blocks = module_invoke($module, 'block', 'list');
+        foreach (module_implements('block_info') as $module) {
+          $module_blocks = module_invoke($module, 'block_info');
           if (!empty($module_blocks)) {
             foreach ($module_blocks as $delta => $block) {
               $block = (object) $block;
               $block->module = $module;
               $block->delta = $delta;
               $block->bid = "{$block->module}-{$block->delta}";
-              
-              $page_match = TRUE;
-              $role_match = TRUE;
-              
-              // check role access
-              if (!drupal_match_path($_GET['q'], 'admin/build/context/*')) {
-                $block_rids = db_query("SELECT rid FROM {blocks_roles} WHERE module = '%s' AND delta = '%s'", $block->module, $block->delta);
-                while ($block_rid = db_result($block_rids)) {
-                  if (in_array($block_rid, $rids)) {
-                    // found a matching role
-                    $role_match = TRUE;
-                    break;
-                  }
-                  else {
-                    // didn't match the role
-                    $role_match = FALSE;
-                  }
-                }
-              }
-              
-              // check page access
-              $block_data = db_fetch_object(db_query("SELECT pages, visibility FROM {blocks} WHERE module = '%s' AND delta = '%s'", $block->module, $block->delta));
-              if ($block_data->pages && !drupal_match_path($_GET['q'], 'admin/build/context/*')) {
-                if ($block_data->visibility < 2) {
-                  $path = drupal_get_path_alias($_GET['q']);
-                  // Compare with the internal and path alias (if any).
-                  $page_match = drupal_match_path($path, $block_data->pages);
-                  if ($path != $_GET['q']) {
-                    $page_match = $page_match || drupal_match_path($_GET['q'], $block_data->pages);
-                  }
-                  // When $block->visibility has a value of 0, the block is displayed on
-                  // all pages except those listed in $block->pages. When set to 1, it
-                  // is displayed only on those pages listed in $block->pages.
-                  $page_match = !($block_data->visibility xor $page_match);
-                }
-                else {
-                  $page_match = drupal_eval($block_data->pages);
-                }
-              }
-              
-              // add to region
-              if ($page_match && $role_match) {
-                $block_info[$block->bid] = $block;
-              }
+              $block_info[$block->bid] = $block;
             }
           }
         }
@@ -529,12 +426,18 @@ class context_respect_reaction_block extends context_reaction {
       drupal_alter('context_block_info', $block_info);
 
       // Gather only region info from the database.
-      $theme_key = variable_get('theme_default', 'garland');
-      $result = db_query("SELECT module,weight,delta,region,status FROM {blocks} WHERE theme = '%s' ORDER BY weight ASC", $theme_key);
-      while ($row = db_fetch_object($result)) {
-        if ($row->status && isset($block_info["{$row->module}-{$row->delta}"])) {
-          $block_info["{$row->module}-{$row->delta}"]->weight = $row->weight;
-          $block_info["{$row->module}-{$row->delta}"]->region = $row->region;
+      if (module_exists('block')) {
+        $theme_key = variable_get('theme_default', 'garland');
+        $result = db_select('block')
+          ->fields('block', array('module','weight','delta','region'))
+          ->condition('theme', $theme_key)
+          ->condition('status', 1)
+          ->execute();
+        foreach ($result as $row) {
+          if (isset($block_info["{$row->module}-{$row->delta}"])) {
+            $block_info["{$row->module}-{$row->delta}"]->weight = $row->weight;
+            $block_info["{$row->module}-{$row->delta}"]->region = $row->region;
+          }
         }
       }
     }
@@ -570,7 +473,7 @@ class context_respect_reaction_block extends context_reaction {
           }
         }
       }
-      uasort($blocks, array('context_respect_reaction_block', 'block_sort'));
+      uasort($blocks, array('context_reaction_block', 'block_sort'));
     }
     return $blocks;
   }
@@ -581,6 +484,68 @@ class context_respect_reaction_block extends context_reaction {
   static function block_sort($a, $b) {
     return ($a->weight - $b->weight);
   }
+  
+  /**
+   * Helper function for determining if authenticated user has access
+   * to a block.
+   *
+   * @param $block
+   *  A block object.
+   *
+   * @return $role_match
+   *   Boolean determining if logged in user has block access
+   */
+  protected function check_role_match($block) {
+    global $user;
+    //Always return true for admin user
+    if($user->uid == 1) {
+      return true;
+    }
+    $rids = array_keys($user->roles);
+    $result = db_query("SELECT rid FROM {block_role} b WHERE b.delta = :delta and b.module = :module", array(':delta' => $block->delta, ':module' => $block->module));
+    $role_match = FALSE;
+    foreach($result as $b) {
+      if(in_array($b->rid,$rids)) {
+        $role_match = TRUE;
+        break;
+      }
+    }
+    return $role_match;
+  }
+  
+  /**
+   * Helper function for determining if page level access is granted to current
+   * block.
+   * 
+   * @param $block
+   *  A block object.
+   *
+   * @return $page_match
+   *   Boolean determining if page access is granted to block
+   */
+  protected function check_page_match($block) {
+    $block_data = db_query("SELECT pages, visibility FROM {block} b where b.delta = :delta and b.module = :module", array(':delta' => $block->delta, ':module' => $block->module))->fetch();
+    $page_match = TRUE;
+    //Bpass check if there are no pages set for a block
+    if (!$block_data->pages || drupal_match_path($_GET['q'], 'admin/structure/context*' || !$block_data)) {
+      return TRUE;
+    }
+    if($block_data->visibility < 2) {
+      $path = drupal_get_path_alias($_GET['q']);
+      $page_match = drupal_match_path($path, $block_data->pages);
+      if ($path != $_GET['q']) {
+        $page_match = $page_match || drupal_match_path($_GET['q'], $block_data->pages);
+      }
+      // When $block->visibility has a value of 0, the block is displayed on
+      // all pages except those listed in $block->pages. When set to 1, it
+      // is displayed only on those pages listed in $block->pages.
+      $page_match = !($block_data->visibility xor $page_match);
+    }
+    elseif (module_exists('php')) {
+      $page_match = php_eval($block->pages);
+    }
+    return $page_match;
+  }
 
   /**
    * Compatibility wrapper around json_decode().
@@ -642,15 +607,15 @@ class context_respect_reaction_block extends context_reaction {
    */
   function render_ajax($param) {
     // Besure the page isn't a 404 or 403.
-    $headers = drupal_set_header();
-    foreach (explode("\n", $headers) as $header) {
+    $headers = drupal_get_http_header();
+    foreach (explode($headers) as $header) {
       if ($header == "HTTP/1.1 404 Not Found" || $header == "HTTP/1.1 403 Forbidden") {
         return;
       }
     }
     // Set the header right away. This will inform any players in the stack
     // that we are in the middle of responding to an AJAX request.
-    drupal_set_header('Content-Type: text/javascript; charset=utf-8');
+    drupal_add_http_header('Content-Type', 'text/javascript; charset=utf-8');
 
     if (strpos($param, ',') !== FALSE) {
       list($bid, $context) = explode(',', $param);
@@ -659,40 +624,23 @@ class context_respect_reaction_block extends context_reaction {
       // Ensure $bid is valid.
       $info = $this->get_blocks();
       if (isset($info[$bid])) {
+        module_load_include('module', 'block', 'block');
         $block = $info[$bid];
         $block->context = $context;
         $block->region = '';
-        $block = $this->build_block($block);
-
-        if (empty($block->content)) {
-          $block->content = "<div class='context-block-empty'>". t('This block appears empty when displayed on this page.') ."</div>";
-        }
-
-        $css = array();
-
-        // On behalf of panels we try to load some css, but we don't support
-        // panels inside panels currently.
-        if ($block->module == 'panels_mini') {
-          $panel = panels_mini_load($block->delta);
-          $layout = panels_get_layout($panel->display->layout);
-          if (!empty($layout['css'])) {
-            if (file_exists(path_to_theme() . '/' . $layout['css'])) {
-              $css[] = path_to_theme() . '/' . $layout['css'];
-            }
-            else {
-              $css[] = $layout['path'] . '/' . $layout['css'];
-            }
-          }
+        $block = array_shift(_block_render_blocks(array($block)));
+        if (empty($block->content['#markup'])) {
+          $block->content['#markup'] = "<div class='context-block-empty'>". t('This block appears empty when displayed on this page.') ."</div>";
         }
-        echo drupal_to_js(array(
+        $block = $this->editable_block($block);
+        echo drupal_json_encode(array(
           'status' => 1,
-          'block' => theme('context_block_editable_block', $block),
-          'css' => $css,
+          'block' => drupal_render(_block_get_renderable_array(array($block))),
         ));
-        exit;
+        drupal_exit();
       }
     }
-    echo drupal_to_js(array('status' => 0));
-    exit;
+    echo drupal_json_encode(array('status' => 0));
+    drupal_exit();
   }
-}
\ No newline at end of file
+}
