? .svn
? 532256-1_ctools_integration.patch
? 532256-3_ctools_integration.patch
? 532256-4_ctools_integration.patch
? includes/.svn
? theme/.svn
Index: features.export.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/features/features.export.inc,v
retrieving revision 1.1.2.27
diff -u -p -r1.1.2.27 features.export.inc
--- features.export.inc	24 Jul 2009 02:57:42 -0000	1.1.2.27
+++ features.export.inc	30 Jul 2009 22:32:11 -0000
@@ -693,7 +693,8 @@ function features_export_render_features
   $output[] = " */";
   $output[] = "function {$module}_{$hook}() {";
   $output[] = "  module_load_include('inc', '{$module}', '{$module}.defaults');";
-  $output[] = "  return _{$module}_{$hook}();";
+  $output[] = '  $args = func_get_args();';
+  $output[] = "  return call_user_func_array('_{$module}_{$hook}', ".'$args'.");";
   $output[] = "}";
   return implode("\n", $output);
 }
Index: features.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/features/features.module,v
retrieving revision 1.1.2.34
diff -u -p -r1.1.2.34 features.module
--- features.module	30 Jul 2009 13:41:31 -0000	1.1.2.34
+++ features.module	30 Jul 2009 22:32:11 -0000
@@ -204,7 +204,7 @@ function features_flush_caches() {
  */
 function features_include() {
   // Features provides integration on behalf of these modules.
-  $modules = array('block', 'content', 'context', 'filter', 'imagecache', 'node', 'user', 'views');
+  $modules = array('block', 'content', 'context', 'ctools', 'filter', 'imagecache', 'node', 'user', 'views');
 
   foreach (array_filter($modules, 'module_exists') as $module) {
     module_load_include('inc', 'features', "includes/features.$module");
Index: includes/features.ctools.inc
===================================================================
RCS file: includes/features.ctools.inc
diff -N includes/features.ctools.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ includes/features.ctools.inc	30 Jul 2009 22:32:11 -0000
@@ -0,0 +1,126 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_features_api().
+ */
+function ctools_features_api() {
+  return array(
+    'feature_source' => TRUE,
+  );
+}
+
+/**
+ * Implementation of hook_features_export_options().
+ */
+function ctools_features_export_options() {
+  ctools_include('export');
+  $module_schemas = ctools_export_get_schemas_by_module();
+  $export = array();
+  foreach ($module_schemas as $module => $schemas) {
+    foreach ($schemas as $table => $schema) {
+      if ($objects = ctools_export_load_object($table, 'all')) {
+        foreach ($objects as $object) {
+          $key = _ctools_features_encode_key($module, $table, $object->$schema['export']['key']);
+          $export[$key] = $key;
+        }
+      }
+    }
+  }
+  return $export;
+}
+
+/**
+ * Implementation of hook_features_export().
+ */
+function ctools_features_export($data, &$export, $module_name = '') {
+  // Define dependency on ctools -
+  // exports by ctools require ctools to be read from default definitions.
+  $export['dependencies']['ctools'] = 'ctools';
+
+  if (!isset($export['features']['ctools'])) {
+    $export['features']['ctools'] = array();
+  }
+  $delegate = array();
+  foreach ($data as $object_key) {
+    list($module, $table, $key) = _ctools_features_decode_key($object_key);
+    // If a CTools API user implements hook_features_export(), delegate task.
+    if (function_exists($module .'_features_export')) {
+      $delegate[$module][$table][$key] = $key;
+    }
+    else {
+      $export['features']['ctools'][$object_key] = $object_key;
+      $export['dependencies'][$module] = $module;
+    }
+  }
+  // Now delegate remaining work to implementers of hook_features_export().
+  // @todo: test. @todo: this could crash if a module implements hook_features_api() and hook_ctools_api().
+  return _features_populate($delegate, $export, $module_name);
+}
+
+/**
+ * Implementation of hook_features_export_render().
+ */
+function ctools_features_export_render($module = 'foo', $data) {
+  // First unpack the encoded data array.
+  $export = array();
+  foreach ($data as $object_key) {
+    list($module, $table, $key) = _ctools_features_decode_key($object_key);
+    $export[$module][$table][$key] = $key;
+  }
+
+  // Now export per module and table (= hook).
+  ctools_include('export');
+  $result = $module_hooks = array();
+  foreach ($export as $module => $tables) {
+    foreach ($tables as $table => $keys) {
+      $schema = drupal_get_schema($table);
+      $code = '  $export = array();'."\n";
+      foreach ($keys as $key) {
+        $identifier = $schema['export']['identifier'];
+        $objects = ctools_export_load_object($table, 'names', array($key));
+        $code .= ctools_export_object($table, $objects[$key], '  ', $identifier);
+        $code .= "\n";
+        $code .= '  $export[] = $'. $identifier .';'."\n";
+      }
+      $code .= '  return $export;';
+      $result[$schema['export']['default hook']] = $code;
+      $module_hooks[$module][$schema['export']['default hook']] = $schema['export'];
+    }
+  }
+
+  // Finally, add the mother hook: hook_ctools_plugin_api().
+  $code = '';
+  foreach ($module_hooks as $module => $hooks) {
+    foreach ($hooks as $api) {
+      $if = empty($code) ? 'if' : "\n".'  elsif';
+      $code .= '  '. $if .' ($module == \''. $module .'\' && $api == \''. $api['default hook'] .'\') {'."\n";
+      $code .= '    return '. features_var_export(array('version' => $api['api']['current_version']), '      ') .';'."\n";
+      $code .= '  }';
+    }
+  }
+  if (!empty($code)) {
+    $args = array();
+    $args[] = '  $args = func_get_args();';
+    $args[] = '  $module = array_shift($args);';
+    $args[] = '  $api = array_shift($args);';
+    $result['ctools_plugin_api'] = implode("\n", $args) . $code;
+  }
+
+  return $result;
+}
+  
+/**
+ * Encode a module - table - key triplet into a single string in the format 
+ * module.table.key
+ */
+function _ctools_features_encode_key($module, $table, $key) {
+  return $module .'.'. $table .'.'. $key;
+}
+
+/**
+ * Decode the result of _ctools_features_encode_key().
+ */
+function _ctools_features_decode_key($key) {
+  return explode('.', $key);
+}
\ No newline at end of file
