Index: panels/panels_mini/panels_mini.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/panels_mini/Attic/panels_mini.module,v
retrieving revision 1.1.2.26
diff -u -r1.1.2.26 panels_mini.module
--- panels/panels_mini/panels_mini.module	27 May 2008 20:21:14 -0000	1.1.2.26
+++ panels/panels_mini/panels_mini.module	29 May 2008 06:06:36 -0000
@@ -1112,16 +1112,17 @@
  */
 function panels_mini_export($panel_mini, $prefix = '') {
   $output = '';
-  $fields = array('name', 'title', 'requiredcontexts', 'contexts', 'relationships');
   $output .= $prefix . '$mini = new stdClass()' . ";\n";
-  $output .= $prefix . '$mini->pid = \'new\'' . ";\n";
+
+  $panel_mini->pid = 'new';
+  $fields = array('pid', 'name', 'title', 'requiredcontexts', 'contexts', 'relationships');
   foreach ($fields as $field) {
-    $output .= $prefix . '  $mini->' . $field . ' = ' . panels_var_export($panel_mini->$field, '  ') . ";\n";
+    $output .= "$prefix  " . '$mini->' . $field . ' = ' . panels_var_export($panel_mini->$field, '  ') . ";\n";
   }
   // Export the primary display
   $display = !empty($panel_mini->display) ? $panel_mini->display : panels_load_display($panel_mini->did);
-  $output .= panels_export_display($display, $prefix);
-  $output .= $prefix . '$mini->display = $display' . ";\n";
+  $output .= panels_export_display($display, "$prefix  ");
+  $output .= "$prefix  " . '$mini->display = $display' . ";\n";
 
   return $output;
 }
Index: panels/panels_page/panels_page.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/panels_page/Attic/panels_page.module,v
retrieving revision 1.1.2.49
diff -u -r1.1.2.49 panels_page.module
--- panels/panels_page/panels_page.module	28 May 2008 16:48:49 -0000	1.1.2.49
+++ panels/panels_page/panels_page.module	29 May 2008 06:06:36 -0000
@@ -997,6 +997,7 @@
  */
 function panels_page_fields() {
   return array(
+    "pid" => "'%s'",
     "name" => "'%s'",
     "title" => "'%s'",
     "arguments" => "'%s'",
@@ -1066,6 +1067,7 @@
 
   // Create strings for our query from the list of fields.
   $fields = panels_page_fields();
+  unset($fields['pid']);
   foreach ($fields as $field => $value) {
     if (isset($page->$field)) {
       $f[] = $field;
@@ -1128,19 +1130,17 @@
  */
 function panels_page_export($panel_page, $prefix = '') {
   $output = '';
-  $fields = panels_page_fields();
   $output .= $prefix . '$page = new stdClass()' . ";\n";
-  $output .= $prefix . '$page->pid = \'new\'' . ";\n";
-  foreach ($fields as $field => $q) {
-    if ($field == 'displays') {
-      continue;
-    }
 
+  $panel_page->pid = 'new';
+  $fields = panels_page_fields();
+  unset($fields['displays']);
+  foreach ($fields as $field => $q) {
     $output .= $prefix . '  $page->' . $field . ' = ' . panels_var_export($panel_page->$field, '  ') . ";\n";
   }
   // Export the primary display
   $display = !empty($panel_page->display) ? $panel_page->display : panels_load_display($panel_page->did);
-  $output .= panels_export_display($display, $prefix);
+  $output .= panels_export_display($display, "$prefix  ");
   $output .= $prefix . '$page->display = $display' . ";\n";
 
   // Export all secondary displays
Index: panels/panels.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/panels.module,v
retrieving revision 1.10.4.105
diff -u -r1.10.4.105 panels.module
--- panels/panels.module	27 May 2008 20:21:15 -0000	1.10.4.105
+++ panels/panels.module	29 May 2008 06:06:36 -0000
@@ -838,43 +838,49 @@
 function panels_export_display($display, $prefix = '') {
   $output = '';
   $output .= $prefix . '$display = new panels_display()' . ";\n";
-  $output .= $prefix . '$display->did = \'new\'' . ";\n";
-  $fields = array('name', 'layout', 'layout_settings', 'panel_settings');
+
+  $display->did = 'new';
+  $fields = array('did', 'name', 'layout', 'layout_settings', 'panel_settings');
   foreach ($fields as $field) {
-    $output .= $prefix . '$display->' . $field . ' = ' . panels_var_export($display->$field, $prefix) . ";\n";
+    $output .= "$prefix  " . '$display->' . $field . ' = ' . panels_var_export($display->$field, $prefix) . ";\n";
   }
 
-  $output .= $prefix . '$display->content = array()' . ";\n";
-  $output .= $prefix . '$display->panels = array()' . ";\n";
+  $output .= "$prefix  " . '$display->content = array()' . ";\n";
+  $output .= "$prefix  " . '$display->panels = array()' . ";\n";
   $panels = array();
 
-  $counter = 0;
-  $counters = array();
-  foreach ($display->content as $pane) {
-    $id = 'new-' . ++$counter;
-    $output .= $prefix . '$pane = new stdClass()'  . ";\n";
-    $output .= $prefix . '  $pane->pid = \'' . $id . '\'' . ";\n";
-    $fields = array('panel', 'type', 'subtype', 'access', 'configuration');
-    foreach ($fields as $field) {
-      $output .= $prefix . '  $pane->' . $field . ' = ' . panels_var_export($pane->$field, "$prefix  ") . ";\n";
-    }
-    $output .= $prefix . '$display->content[\'' . $id . '\'] = $pane' . ";\n";
-    if (!isset($counters[$pane->panel])) {
-      $counters[$pane->panel] = 0;
+  if (!empty($display->content)) { 
+    $pid_counter = 0;
+    $region_counters = array();
+    foreach ($display->content as $pane) {
+      $pane->pid = 'new-' . ++$pid_counter;
+      $output .= panels_pane_export($pane, "$prefix  ");
+      $output .= "$prefix  " . '$display->content[\'' . $pane->pid . '\'] = $pane' . ";\n";
+      if (!isset($region_counters[$pane->panel])) {
+        $region_counters[$pane->panel] = 0;
+      }
+      $output .= "$prefix  " . '$display->panels[\'' . $pane->panel . '\'][' . $region_counters[$pane->panel]++ .'] = \'' . $pane->pid . "';\n";
     }
-    $output .= $prefix . '$display->panels[\'' . $pane->panel . '\'][' . $counters[$pane->panel]++ .'] = \'' . $id . "';\n";
+  }
+  return $output;
+}
+
+function panels_pane_export($pane, $prefix = '') {
+  $output = '';
+  $output = $prefix . '$pane = new stdClass()'  . ";\n";
+  $fields = array('pid', 'panel', 'type', 'subtype', 'access', 'configuration');
+  foreach ($fields as $field) {
+    $output .= "$prefix  " . '$pane->' . $field . ' = ' . panels_var_export($pane->$field, "$prefix  ") . ";\n";
   }
   return $output;
 }
 
 function panels_var_export($object, $prefix = '') {
   if (is_array($object) && empty($object)) {
-    $output = 'array()';
-  }
-  else {
-    $output = var_export($object, TRUE);
+    return 'array()';
   }
 
+  $output = var_export($object, TRUE);
   if ($prefix) {
     $output = str_replace("\n", "\n$prefix", $output);
   }
