Index: includes/base.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/includes/base.inc,v
retrieving revision 1.3
diff -u -p -r1.3 base.inc
--- includes/base.inc	25 Jun 2009 22:15:39 -0000	1.3
+++ includes/base.inc	26 Jun 2009 20:43:55 -0000
@@ -125,4 +125,59 @@ class views_object {
       unset($this->query);
     }
   }
+
+  function export_options($indent, $prefix) {
+    $output = '';
+    foreach ($this->option_definition() as $option => $definition) {
+      $output .= $this->export_option($indent, $prefix, $this->options, $option, $definition, array());
+    }
+
+    return $output;
+  }
+
+  function export_option($indent, $prefix, $storage, $option, $definition, $parents) {
+    // Do not export options for which we have no settings.
+    if (!isset($storage[$option])) {
+      return;
+    }
+
+    if (isset($definition['export'])) {
+      if ($definition['export'] === FALSE) {
+        return;
+      }
+
+      // Special handling for some items
+      if (method_exists($this, $definition['export'])) {
+        return $this->{$definition['export']}($indent, $prefix, $storage, $option, $definition, $parents);
+      }
+    }
+
+    // Add the current option to the parents tree.
+    $parents[] = $option;
+    $output = '';
+
+    // If it has child items, export those separately.
+    if (isset($definition['contains'])) {
+      foreach ($definition['contains'] as $sub_option => $sub_definition) {
+        $output .= $this->export_option($indent, $prefix, $storage[$option], $sub_option, $sub_definition, $parents);
+      }
+    }
+    // Otherwise export just this item.
+    else {
+      $default = isset($definition['default']) ? $definition['default'] : NULL;
+
+      if ($storage[$option] !== $default) {
+        $output .= $indent . $prefix . "['" . implode("']['", $parents) . "'] = ";
+        if (isset($definition['bool'])) {
+          $output .= empty($storage[$option]) ? 'FALSE' : 'TRUE';
+        }
+        else {
+          $output .= views_var_export($storage[$option], $indent);
+        }
+
+        $output .= ";\n";
+      }
+    }
+    return $output;
+  }
 }
Index: includes/view.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/includes/view.inc,v
retrieving revision 1.165
diff -u -p -r1.165 view.inc
--- includes/view.inc	25 Jun 2009 22:06:55 -0000	1.165
+++ includes/view.inc	26 Jun 2009 20:43:57 -0000
@@ -1444,6 +1444,8 @@ class view extends views_db_object {
         continue;
       }
 
+      $output .= $display->handler->export_options($indent, '$handler->options');
+/*
       foreach ($display->handler->option_definition() as $option => $definition) {
         // Special handling for some items
         switch ($option) {
@@ -1466,6 +1468,7 @@ class view extends views_db_object {
             }
         }
       }
+*/
     }
 
     return $output;
Index: plugins/views_plugin_display.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/plugins/views_plugin_display.inc,v
retrieving revision 1.25
diff -u -p -r1.25 views_plugin_display.inc
--- plugins/views_plugin_display.inc	26 Jun 2009 00:23:42 -0000	1.25
+++ plugins/views_plugin_display.inc	26 Jun 2009 20:43:58 -0000
@@ -257,6 +257,7 @@ class views_plugin_display extends views
           'arguments' => TRUE,
           'filters' => TRUE,
         ),
+        'export' => FALSE,
       ),
       'relationships' => array(
         'default' => array(),
@@ -1874,6 +1875,46 @@ class views_plugin_display extends views
     }
   }
 
+  function export_option($indent, $prefix, $storage, $option, $definition, $parents) {
+    $output = '';
+    if (!$parents && !$this->is_default_display()) {
+      // Do not export items that are not overridden.
+      if ($this->is_defaulted($option)) {
+        return;
+      }
+
+      // If this is not defaulted and is overrideable, flip the switch to say this
+      // is overridden.
+      if ($this->defaultable_sections($option)) {
+        $output = $indent . $prefix . "['defaults']['$option'] = FALSE;\n";
+      }
+    }
+    $output .= parent::export_option($indent, $prefix, $storage, $option, $definition, $parents);
+    return $output;
+  }
+
+  function export_item($indent, $prefix, $storage, $option, $definition, $parents) {
+    $output = '';
+
+    // cut the 's' off because the data is stored as the plural form but we need
+    // the singular form. Who designed that anyway? Oh yeah, I did. :(
+    $type = substr($option, 0, -1);
+    foreach ($storage[$option] as $id => $info) {
+      $handler = views_get_handler($info['table'], $info['field'], $type);
+      if ($handler) {
+        $handler->init($this->view, $info);
+        $output .= $indent . $prefix . "['$option']['$id']['id'] = '$id';\n";
+        $output .= $indent . $prefix . "['$option']['$id']['table'] = '$info[table]';\n";
+        $output .= $indent . $prefix . "['$option']['$id']['field'] = '$info[field]';\n";
+        $output .= $handler->export_options($indent, $prefix . "['$option']['$id']");
+      }
+
+      // Prevent reference problems.
+      unset($handler);
+    }
+
+    return $output;
+  }
 }
 
 
