? .DS_Store
? panels2compatibility.patch
Index: panelsblock.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/panelsblock/panelsblock.module,v
retrieving revision 1.9
diff -u -F^f -r1.9 panelsblock.module
--- panelsblock.module	11 Jun 2007 21:35:53 -0000	1.9
+++ panelsblock.module	6 Jul 2007 15:29:31 -0000
@@ -1,8 +1,5 @@
 <?php
-// $Id: panelsblock.module,v 1.9 2007/06/11 21:35:53 nedjo Exp $
-
-// Panels layout area used for blocks.
-define('PANELSBLOCK_DEFAULT_AREA', 'left');
+// $Id: panelsblock.module,v 1.1.2.7 2007/06/11 21:36:30 nedjo Exp $
 
 /**
  * @file
@@ -13,34 +10,57 @@
  * Implementation of hook_form_alter().
  */
 function panelsblock_form_alter($form_id, &$form) {
-  if ($form_id == 'panels_edit_form') {
+  if ($form_id == 'panels_page_edit_form') {
+
     $blocks = variable_get('panelsblock', array());
+    $pid = $form['panel_page']['#value']->pid;
+
     $form['#submit']['panelsblock_form_submit'] = array();
-    $form['panelsblock'] = array(
+    $form['left']['panelsblock'] = array(
       '#type' => 'fieldset',
       '#title' => t('Block'),
-      '#weight' => 0,
+      '#weight' => 1,
     );
-    $form['panelsblock']['expose_block'] = array(
+    $form['left']['panelsblock']['expose_block'] = array(
       '#type' => 'checkbox',
       '#title' => t('Expose as a block'),
       '#description' => t('Select whether you wish to make this panels page available as a block.'),
-      '#default_value' => $blocks[$form['did']['#value']] && $blocks[$form['did']['#value']]['expose'] ? $blocks[$form['did']['#value']]['expose'] : 0,
+      '#default_value' => $blocks[$pid] && $blocks[$pid]['expose'] ? $blocks[$pid]['expose'] : 0,
     );
-    $options = panelsblock_get_areas($form['layout']['#value']);
-    $form['panelsblock']['expose_area'] = array(
+
+    // Create an array of options, consisting of a list of panels available in
+    // the current panel page.
+    $panels = array_keys($form['panel_page']['#value']->display->panels);
+    foreach ($panels as $panel) {
+      // Create a human-friendly name for each panel.
+      if (preg_match("/row_(\d+)_(\d+)/i", $panel, $matches)) {
+        $options[$panel] = "Row {$matches[1]}, Column {$matches[2]}";
+      }      
+      else {
+        $options[$panel] = ucfirst($panel);
+      }
+    }
+
+    // Compatibility fix for Panels 2 alpha 5, which creates an empty first
+    // option if you've chosen the "Flexible" layout.
+    // TODO: this can be removed as soon as this is fixed in Panels 2.
+    if ($options_internal[0] == '') {
+      array_shift($options);
+    }
+
+    $form['left']['panelsblock']['expose_panel'] = array(
       '#type' => 'select',
-      '#title' => t('Display area'),
-      '#default_value' => $blocks[$form['did']['#value']] && $blocks[$form['did']['#value']]['area'] ? $blocks[$form['did']['#value']]['area'] : (array_key_exists(PANELSBLOCK_DEFAULT_AREA, $options) ? PANELSBLOCK_DEFAULT_AREA : ''),
+      '#title' => t('Exposed panel'),
+      '#default_value' => $blocks[$pid] && $blocks[$pid]['panel'] ? $blocks[$pid]['panel'] : $panels[0],
       '#options' => $options,
-      '#description' => t('Select the area that will be displayed.'),
+      '#description' => t('Select the panel that will be displayed. You cannot choose an empty panel.'),
     );
-    $form['panelsblock']['expose_style'] = array(
+    $form['left']['panelsblock']['expose_style'] = array(
       '#type' => 'radios',
       '#title' => t('Display style'),
       '#options' => array('default' => t('Default panels'), 'tabs' => t('Tabs')),
-      '#description' => t('Select the display style for items in this panels set.'),
-      '#default_value' => $blocks[$form['did']['#value']] && $blocks[$form['did']['#value']]['style'] ? $blocks[$form['did']['#value']]['style'] : 'default',
+      '#description' => t('Select the display style for the chosen panel.'),
+      '#default_value' => $blocks[$pid] && $blocks[$pid]['style'] ? $blocks[$pid]['style'] : 'default',
     );
   }
 }
@@ -53,10 +73,10 @@ function panelsblock_block($op = 'list',
     case 'list':
       $blocks = array();
       $panelsblocks = variable_get('panelsblock', array());
-      foreach ($panelsblocks as $did => $block) {
+      foreach ($panelsblocks as $pid => $block) {
         if ($block['expose']) {
-          if ($panels = panels_load_panels($did)) {
-            $blocks[$did] = array(
+          if ($panels = panels_page_load($pid)) {
+            $blocks[$pid] = array(
               'info' => t('@title panel', array('@title' => $panels->title ? $panels->title : $panels->path)),
             );
           }
@@ -70,14 +90,15 @@ function panelsblock_block($op = 'list',
 }
 
 /**
- * Save tabs information for a panel.
+ * Save tabs information for a panel page.
  */
 function panelsblock_form_submit($form_id, $form_values) {
   $blocks = variable_get('panelsblock', array());
-  $blocks[$form_values['did']] = array(
+  $pid = $form_values['panel_page']->pid;
+  $blocks[$pid] = array(
     'expose' => $form_values['expose_block'],
     'style' => $form_values['expose_style'],
-    'area' => $form_values['expose_area'],
+    'panel' => $form_values['expose_panel'],
   );
   variable_set('panelsblock', $blocks);
 }
@@ -85,51 +106,78 @@ function panelsblock_form_submit($form_i
 /**
  * Load a panels block.
  */
-function panelsblock_get_block($did) {
+function panelsblock_get_block($pid) {
 
   // Some types, e.g, views, can change the title and breadcrumb.
   // To avoid these changes, cache the existing values.
   $cached_title = drupal_get_title();
   $cached_breadcrumb = drupal_get_breadcrumb();
 
-  $panels = panels_load_panels($did);
-  if (!$panels) {
+  // Load a panel page and its associated display.
+  $panels_page = panels_page_load($pid);
+//dprint_r($panels_page);exit;
+//dprint_r($panels_page->display->content);exit;
+  if (!$panels_page) {
     return MENU_NOT_FOUND;
   }
 
-  $layouts = panels_get_layouts();
-  $layout = $layouts[$panels->layout];
-  $layout['css_id'] = $panels->css_id;
-
-  if (!$layout) {
-    watchdog('panels', t('Unable to find requested layout %s', array('%s' => check_plain($panels->layout))));
-    return MENU_NOT_FOUND;
-  }
+//  // $layouts = panels_get_layouts();
+//dprint_r($layouts);exit;
+  $layout = $panels_page->display->layout;
+  $css_id = $panels_page->css_id;
 
   $blocks = variable_get('panelsblock', array());
-
-  panels_is_panels_page(TRUE);
+  //print 'blocks:';
+//dprint_r($blocks);exit;
+  //panels_is_panels_page(TRUE);
+/*
   $content_types = panels_get_content_types();
   $content = array();
   panelsblock_load_content_types();
+*/
+/*
+  // Collect all pane objects that are inside the panel that will be displayed.
+  $displayed_panel = $blocks[$pid]['panel'];
+  foreach ($panels['display']->content as $pane_id -> $pane) {
+    if ($pane->panel == $displayed_panel) {
+      $panes[$pane->position] = $pane;
+    }
+  }
+  
+  // Render the pane objects in the correct order.
+  foreach ($panes as $pane) {
+    $function = $content_types[$pane->type]['callback'] .'_block';
+    if (function_exists($function)) {
+      $content[] = $function($panes->configuration);
+    }
+  }
+*/
 
-  $display_area = !empty($blocks[$did]['area']) ? $blocks[$did]['area'] : PANELSBLOCK_DEFAULT_AREA;
-
-  foreach ($panels->content as $location => $list) {
-    foreach ($list as $area) {
-      if ($area->area == $display_area) {
-        $function = $content_types[$area->type]['callback'] .'_block';
-        if (function_exists($function)) {
-          $content[] = $function($area->configuration);
-        }
+  // Remove the panes that are not inside the panel that will be displayed.
+  $displayed_panel = $blocks[$pid]['panel'];
+  foreach ($panels_page->display->content as $pane_id => $pane) {
+    if ($pane->panel != $displayed_panel) {
+      unset($panels_page->display->content[$pane_id]);
+    }
+  }
+  
+  // Render the panes. Based on code of panels_render_display().
+  $display = $panels_page->display;
+  panels_sanitize_display($display);
+  foreach ($display->content as $pane_id => $pane) {
+    if ($result = panels_get_pane_content($pane, $display->args, $display->context, $display->incoming_content)) {
+      if (panels_pane_access($pane)) {
+        //$content[$pane->panel][$pane_id] .= theme('panels_pane', $result, $display); 
+        $content[$pane->panel][$pane_id] = $result;
       }
     }
   }
 
-  $theme_function = 'panelsblock_block_'. ($blocks[$did] ? $blocks[$did]['style'] : 'default');
+  // Now put the rendered panes inside the chosen presentation (default/tabs).
+  $theme_function = 'panelsblock_block_'. ($blocks[$pid] ? $blocks[$pid]['style'] : 'default');
   $block = array(
-    'subject' => $panels->title ? $panels->title : '',
-    'content' => theme($theme_function, $did, $content),
+    'subject' => $panels_page->title ? $panels_page->title : '',
+    'content' => theme($theme_function, $pid, $content),
   );
 
   // Restore title and breadcrumb.
@@ -140,32 +188,15 @@ function panelsblock_get_block($did) {
 }
 
 /**
- * Load the supported content types.
- */
-function panelsblock_load_content_types() {
-  $path = drupal_get_path('module', 'panelsblock') . '/content_types';
-  $files = drupal_system_listing('.inc$', $path, 'name', 0);
-
-  foreach($files as $file) {
-    require_once('./' . $file->filename);
-  }
-}
-
-/**
- * Given a panel layout, return its content areas.
- */
-function panelsblock_get_areas($layout) {
-  $layouts = panels_get_layouts();
-  return $layouts[$layout]['content areas'];
-}
-
-/**
  * Default presentation of block.
  */
-function theme_panelsblock_block_default($did, $content) {
+function theme_panelsblock_block_default($pid, $content) {
   $items = array();
-  foreach ($content as $item) {
-    $items[] = '<div class="title">'. $item['title'] .'</div><div class="body">'. $item['body'] .'</div>';
+
+  foreach ($content as $panel) {
+    foreach ($panel as $pane_id => $block) {
+      $items[] = theme('block', $block);
+    }
   }
   return theme('item_list', $items);
 }
@@ -173,19 +204,18 @@ function theme_panelsblock_block_default
 /**
  * Presentation of block in tabs.
  */
-function theme_panelsblock_block_tabs($did, $content) {
+function theme_panelsblock_block_tabs($pid, $content) {
   $tabs = array();
 
-  $tabs['panelsblock_'. $did] = array(
+  $tabs['panelsblock_'. $pid] = array(
     '#type' => 'tabset',
   );
-  foreach ($content as $key => $item) {
-    $body = trim(strip_tags($item['body']));
-    if (!empty($body)) {
-      $tabs['panelsblock_'. $did]['tab_'. $key] = array(
+  foreach ($content as $panel) {
+    foreach ($panel as $pane_id => $block) {
+      $tabs["panelsblock_$pid"]["tab_$pane_id"] = array(
         '#type' => 'tabpage',
-        '#title' => $item['title'],
-        '#content' => $item['body'],
+        '#title' => $block->subject,
+        '#content' => $block->content,
       );
     }
   }
