Index: ckeditor.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ckeditor/ckeditor.module,v
retrieving revision 1.4.2.31
diff -u -p -r1.4.2.31 ckeditor.module
--- ckeditor.module	27 Sep 2010 12:49:01 -0000	1.4.2.31
+++ ckeditor.module	11 Nov 2010 14:36:25 -0000
@@ -1126,3 +1126,20 @@ function ckeditor_get_nodetype($get_q) {
 
   return $nodetype;
 }
+
+/**
+ * Implementation of hook_features_api()
+ * 
+ * Allow exporting of CKEditor profiles by the Features module
+ */
+function ckeditor_features_api() {
+  return array(
+    'ckeditor_profile' => array(
+      'name' => t('CKEditor profiles'),
+      'default_hook' => 'ckeditor_profile_defaults',
+      'default_file' => FEATURES_DEFAULTS_INCLUDED,
+      'file' => drupal_get_path('module', 'ckeditor') .'/includes/ckeditor.features.inc',
+    )
+  );
+}
+
Index: includes/ckeditor.features.inc
===================================================================
RCS file: includes/ckeditor.features.inc
diff -N includes/ckeditor.features.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ includes/ckeditor.features.inc	11 Nov 2010 14:36:25 -0000
@@ -0,0 +1,92 @@
+<?php
+
+/**
+ * Implementation of hook_features_export_options()
+ */
+function ckeditor_profile_features_export_options()  {
+  $options = array();
+  foreach (ckeditor_profile_load() as $name => $profile) {
+    $options[$name] = $profile->name;
+  }
+  return $options;
+}
+
+/**
+ * Implementation of hook_features_export()
+ */
+function ckeditor_profile_features_export($data, &$export, $module_name = '') {
+  $pipe = array();
+  foreach ($data as $name) {
+    $profile = ckeditor_profile_load($name);
+    if ($profile) {
+      $export['features']['ckeditor_profile'][$name] = $name;
+
+      // Write dependencies on all the roles referenced by this profile
+      foreach ($profile->rids as $rid => $role_name) {
+        $pipe['user_role'][] = $role_name;
+      }
+    }
+  }
+  $export['dependencies'][] = 'ckeditor';
+  return $pipe;
+}
+
+/**
+ * Implementation of hook_features_export_render()
+ */
+function ckeditor_profile_features_export_render($module_name, $data) {
+  $profiles = array();
+  $roles = user_roles();
+  foreach ($data as $name) {
+    $profile = (array)ckeditor_profile_load($name);
+
+    // Convert Role IDs into role names only
+    $roles = array_values($profile['rids']);
+    if (empty($roles)) {
+      $profile['roles'] = array();
+    }
+    else {
+      $profile['roles'] = array_combine($roles, $roles);
+    }
+    unset($profile['rids']);
+
+    $profiles[$name] = $profile;
+  }
+  $code = '  $data = '. features_var_export($profiles, '  ') .';'. PHP_EOL;
+  $code .= '  return $data;';
+
+  return array('ckeditor_profile_defaults' => $code);
+}
+
+/**
+ * Implementation of hook_features_revert()
+ */
+function ckeditor_profile_features_revert($module) {
+  $data = module_invoke($module, 'ckeditor_profile_defaults');
+  $roles = user_roles();
+  foreach ($data as $name => $profile) {
+    // Convert role names back into rids
+    foreach ($profile['settings']['roles'] as &$role) {
+      if ($rid = array_search($role, $user_roles)) {
+        $role = $rid;
+      }
+    }
+
+    // Restore the profile settings
+    db_query("DELETE FROM {ckeditor_settings} WHERE name = '%s'", $name);
+    db_query("INSERT INTO {ckeditor_settings} (name, settings) VALUES('%s', '%s')", $name, serialize($profile['settings']));
+
+    // Restore the profile roles
+    foreach ($roles as $rid => $role_name) {
+      if (in_array($role_name, $profile['roles'])) {
+        if (!db_result(db_query("SELECT rid FROM {ckeditor_role} WHERE rid = %d AND name = '%s'", $rid, $name))) {
+          db_query("INSERT INTO {ckeditor_role} (rid, name) VALUES(%d, '%s')", $rid, $name);
+        }
+      }
+      else {
+        // Make sure they don't have access
+        db_query("DELETE FROM {ckeditor_role} WHERE rid = %d AND name = '%s'", $rid, $name);
+      }
+    }
+  }
+}
