=== modified file 'CHANGELOG.txt'
--- CHANGELOG.txt	2009-11-03 09:48:34 +0000
+++ CHANGELOG.txt	2009-11-03 09:48:37 +0000
@@ -2,6 +2,7 @@
 
 Zen 6.x-2.x-dev, xxxx-xx-xx (development release)
 ------------------------
+- #621798: Change sidebar variables to be RTL friendly and $shows_blocks compatible
 - #547696: Update node.tpl to use ideas from D7
 - #620794: Update block.tpl to use ideas from D7
 - #548994: Update comment.tpl and comment-wrapper.tpl to use ideas from D7

=== modified file 'STARTERKIT/STARTERKIT.info.txt'
--- STARTERKIT/STARTERKIT.info.txt	2009-11-01 18:40:06 +0000
+++ STARTERKIT/STARTERKIT.info.txt	2009-11-03 08:18:17 +0000
@@ -60,8 +60,8 @@ conditional-stylesheets[if lte IE 6][all
   ; To add a new region, copy Zen's page.tpl.php to your sub-theme's directory,
   ; add a line line to this file, and then add the new variable to your
   ; page.tpl.php template.
-regions[left]           = first sidebar
-regions[right]          = second sidebar
+regions[sidebar_first]  = first sidebar
+regions[sidebar_second] = second sidebar
 regions[navbar]         = navigation bar
 regions[content_top]    = content top
 regions[content_bottom] = content bottom

=== modified file 'template.php'
--- template.php	2009-11-02 15:37:33 +0000
+++ template.php	2009-11-03 15:50:09 +0000
@@ -103,26 +103,61 @@ function zen_menu_local_tasks() {
  *
  * @param $region
  *   Which set of blocks to retrieve.
+ * @param $show_blocks
+ *   A boolean to determine whether to render sidebar regions or not. Should be
+ *   the same value as passed to theme_page.
  * @return
  *   A string containing the themed blocks for this region.
+ *
+ * @see zen_show_blocks_discovery()
  */
-function zen_blocks($region) {
-  $output = '';
-
-  if ($list = block_list($region)) {
-    foreach ($list as $key => $block) {
-      // $key == module_delta
-      $output .= theme('block', $block);
+function zen_blocks($region, $show_blocks = NULL) {
+  // Since Drupal 6 doesn't pass $show_blocks to theme_blocks, we manually call
+  // theme('blocks', NULL, $show_blocks) so that this function can remember the
+  // value on later calls.
+  static $render_sidebars = TRUE;
+  if (!is_null($show_blocks)) {
+    $render_sidebars = $show_blocks;
+  }
+
+  // If zen_blocks was called with a NULL region, its likely we were just
+  // setting the $render_sidebars static variable.
+  if ($region) {
+    $output = '';
+
+    // If $renders_sidebars is FALSE, don't render any region whose name begins
+    // with "sidebar_".
+    if (($render_sidebars || (strpos($region, 'sidebar_') !== 0)) && ($list = block_list($region))) {
+      foreach ($list as $key => $block) {
+        // $key == module_delta
+        $output .= theme('block', $block);
+      }
     }
-  }
 
-  // Add any content assigned to this region through drupal_set_content() calls.
-  $output .= drupal_get_content($region);
+    // Add any content assigned to this region through drupal_set_content() calls.
+    $output .= drupal_get_content($region);
 
-  $elements['#children'] = $output;
-  $elements['#region'] = $region;
+    $elements['#children'] = $output;
+    $elements['#region'] = $region;
 
-  return $output ? theme('region', $elements) : '';
+    return $output ? theme('region', $elements) : '';
+  }
+}
+
+/**
+ * Examine the $show_blocks variable before template_preprocess_page() is called.
+ *
+ * @param $vars
+ *   An array of variables to pass to the page template.
+ *
+ * @see zen_blocks()
+ */
+function zen_show_blocks_discovery(&$vars) {
+  if ($vars['show_blocks'] == FALSE) {
+    // Allow zen_blocks() to statically cache the $show_blocks variable. A TRUE
+    // value is assumed, so we only need to override when $show_blocks is FALSE.
+    theme('blocks', NULL, FALSE);
+  }
 }
 
 /**
@@ -195,15 +230,30 @@ function zen_preprocess_page(&$vars, $ho
   if (theme_get_setting('zen_wireframes')) {
     $vars['classes_array'][] = 'with-wireframes'; // Optionally add the wireframes style.
   }
-  // Add new sidebar classes in addition to Drupal core's sidebar-* classes.
-  // This provides some backwards compatibility with Zen 6.x-1.x themes.
-  if ($vars['layout'] != 'both') {
-    $new_layout = ($vars['layout'] == 'left') ? 'first' : 'second';
-    if (array_search('sidebar-' . $vars['layout'], $vars['classes_array'])) {
-      $vars['classes_array'][] = 'sidebar-' . $new_layout;
+  // We need to re-do the $layout and body classes because
+  // template_preprocess_page() assumes sidebars are named 'left' and 'right'.
+  $vars['layout'] = 'none';
+  if (!empty($vars['sidebar_first'])) {
+    $vars['layout'] = 'first';
+  }
+  if (!empty($vars['sidebar_second'])) {
+    $vars['layout'] = ($vars['layout'] == 'first') ? 'both' : 'second';
+  }
+  // If the layout is 'none', then template_preprocess_page() will already have
+  // set a 'no-sidebars' class since it won't find a 'left' or 'right' sidebar.
+  if ($vars['layout'] != 'none') {
+    // Remove the incorrect 'no-sidebars' class.
+    if ($index = array_search('no-sidebars', $vars['classes_array'])) {
+      unset($vars['classes_array'][$index]);
+    }
+    // Set the proper layout body classes.
+    if ($vars['layout'] == 'both') {
+      $vars['classes_array'][] = 'two-sidebars';
+    }
+    else {
+      $vars['classes_array'][] = 'one-sidebar';
+      $vars['classes_array'][] = 'sidebar-' . $vars['layout'];
     }
-    // Replace core's $layout variable with our naming of sidebars.
-    $vars['layout'] = $new_layout;
   }
 }
 

=== modified file 'templates/maintenance-page.tpl.php'
--- templates/maintenance-page.tpl.php	2009-11-01 18:40:06 +0000
+++ templates/maintenance-page.tpl.php	2009-11-03 08:39:36 +0000
@@ -88,15 +88,15 @@
         </div> <!-- /#navbar -->
       <?php endif; ?>
 
-      <?php if ($left): ?>
+      <?php if ($sidebar_first): ?>
         <div id="sidebar-first"><div id="sidebar-first-inner" class="region region-sidebar-first">
-          <?php print $left; ?>
+          <?php print $sidebar_first; ?>
         </div></div> <!-- /#sidebar-first-inner, /#sidebar-first -->
       <?php endif; ?>
 
-      <?php if ($right): ?>
+      <?php if ($sidebar_second): ?>
         <div id="sidebar-second"><div id="sidebar-second-inner" class="region region-sidebar-second">
-          <?php print $right; ?>
+          <?php print $sidebar_second; ?>
         </div></div> <!-- /#sidebar-second-inner, /#sidebar-second -->
       <?php endif; ?>
 

=== modified file 'templates/page.tpl.php'
--- templates/page.tpl.php	2009-11-02 18:55:05 +0000
+++ templates/page.tpl.php	2009-11-03 08:19:37 +0000
@@ -72,8 +72,8 @@
  * - $help: Dynamic help text, mostly for admin pages.
  * - $content: The main content of the current page.
  * - $feed_icons: A string of all feed icons for the current page.
- * - $left: The HTML for the first sidebar.
- * - $right: The HTML for the second sidebar.
+ * - $sidebar_first: The HTML for the first sidebar.
+ * - $sidebar_second: The HTML for the second sidebar.
  *
  * Footer/closing data:
  * - $footer_message: The footer message as defined in the admin settings.
@@ -195,15 +195,15 @@
         </div> <!-- /#navbar -->
       <?php endif; ?>
 
-      <?php if ($left): ?>
+      <?php if ($sidebar_first): ?>
         <div id="sidebar-first"><div id="sidebar-first-inner" class="region region-sidebar-first">
-          <?php print $left; ?>
+          <?php print $sidebar_first; ?>
         </div></div> <!-- /#sidebar-first-inner, /#sidebar-first -->
       <?php endif; ?>
 
-      <?php if ($right): ?>
+      <?php if ($sidebar_second): ?>
         <div id="sidebar-second"><div id="sidebar-second-inner" class="region region-sidebar-second">
-          <?php print $right; ?>
+          <?php print $sidebar_second; ?>
         </div></div> <!-- /#sidebar-second-inner, /#sidebar-second -->
       <?php endif; ?>
 

=== modified file 'zen-internals/template.theme-registry.inc'
--- zen-internals/template.theme-registry.inc	2009-11-03 17:35:45 +0000
+++ zen-internals/template.theme-registry.inc	2009-11-03 17:36:07 +0000
@@ -60,8 +60,12 @@ function _zen_theme(&$existing, $type, $
     }
   }
 
-  // The base theme registers region.tpl.php
+  // Manipulations only to be done by the base theme.
   if ($theme == 'zen') {
+    // Insert zen_show_blocks_discovery() before template_preprocess_page().
+    $existing['page']['preprocess functions'] = array_merge(array('zen_show_blocks_discovery'), $existing['page']['preprocess functions']);
+
+    // The base theme registers region.tpl.php.
     return array(
       'region' => array(
         'arguments' => array('elements' => NULL),

=== modified file 'zen.info'
--- zen.info	2009-11-01 18:40:06 +0000
+++ zen.info	2009-11-03 08:18:44 +0000
@@ -8,8 +8,8 @@ screenshot = zen-internals/screenshot.pn
 core   = 6.x
 engine = phptemplate
 
-regions[left]           = first sidebar
-regions[right]          = second sidebar
+regions[sidebar_first]  = first sidebar
+regions[sidebar_second] = second sidebar
 regions[navbar]         = navigation bar
 regions[content_top]    = content top
 regions[content_bottom] = content bottom

