Index: CHANGELOG.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/themekey/CHANGELOG.txt,v
retrieving revision 1.31.2.84
diff -u -r1.31.2.84 CHANGELOG.txt
--- CHANGELOG.txt	16 Jul 2010 14:26:34 -0000	1.31.2.84
+++ CHANGELOG.txt	16 Jul 2010 14:42:02 -0000
@@ -2,6 +2,7 @@
 
 ThemeKey 6.x-2.2, 2010-xx-xx
 ----------------------------
+[#445538] mkalkbrenner: allow the author himself to select a theme for all his nodes
 [#754978] mkalkbrenner: Completed Debug for non root users/visitors
 
 
Index: themekey_ui.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/themekey/themekey_ui.install,v
retrieving revision 1.4.2.4
diff -u -r1.4.2.4 themekey_ui.install
--- themekey_ui.install	12 Mar 2010 09:04:23 -0000	1.4.2.4
+++ themekey_ui.install	16 Jul 2010 14:42:02 -0000
@@ -15,6 +15,7 @@
  */
 function themekey_ui_schema() {
   $schema = array();
+
   $schema['themekey_ui_node_theme'] = array(
     'fields' => array(
       'nid' => array(
@@ -36,6 +37,22 @@
     'primary key' => array('nid', 'vid'),
   );
 
+  $schema['themekey_ui_author_theme'] = array(
+    'fields' => array(
+      'uid' => array(
+        'description' => 'The user id.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE),
+      'theme' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => ''),
+    ),
+    'primary key' => array('uid'),
+  );
+
   return $schema;
 }
 
@@ -69,3 +86,29 @@
 
   return array();
 }
+
+
+/**
+ * Implements hook_update_N().
+ */
+function themekey_ui_update_6200() {
+  $schema['themekey_ui_author_theme'] = array(
+    'fields' => array(
+      'uid' => array(
+        'description' => 'The user id.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE),
+      'theme' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => ''),
+    ),
+    'primary key' => array('uid'),
+  );
+
+  $ret = array();
+  db_create_table($ret, 'themekey_ui_author_theme', $schema['themekey_ui_author_theme']);
+  return $ret;
+}
Index: themekey_ui.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/themekey/themekey_ui.module,v
retrieving revision 1.5.2.9
diff -u -r1.5.2.9 themekey_ui.module
--- themekey_ui.module	16 Mar 2010 13:32:59 -0000	1.5.2.9
+++ themekey_ui.module	16 Jul 2010 14:42:02 -0000
@@ -11,6 +11,9 @@
  * ThemeKey UI adds a theme option to the 'URL aliases' administration
  * if module "Path" is enabled.
  *
+ * ThemeKey UI adds a form element to user profile for theming all
+ * nodes created by this user.
+ *
  * @see themekey.module
  *
  * @author Markus Kalkbrenner | Cocomore AG
@@ -41,6 +44,12 @@
     'static' => TRUE,
   );
 
+  $attributes['themekey_ui:node_author_triggers_theme'] = array(
+    'description' => t("Property themekey_ui:node_author_triggers_theme could not be selected from the property drop down. You get this static property by activating !link. Afterwards you can move the property to any position in the rule chain. When done it triggers the switch to the theme the author selected for his nodes in his user profile.",
+                       array('!link' => l(t('Show theme option in user profile'), 'admin/settings/themekey/settings/ui'))),
+    'static' => TRUE,
+  );
+
   // Mapping functions
   $maps = array();
 
@@ -48,6 +57,10 @@
                   'dst'       => 'themekey_ui:node_triggers_theme',
                   'callback'  => 'themekey_ui_nid2theme');
 
+  $maps[] = array('src'       => 'node:nid',
+                  'dst'       => 'themekey_ui:node_author_triggers_theme',
+                  'callback'  => 'themekey_ui_author2theme');
+
   return array('attributes' => $attributes, 'maps' => $maps);
 }
 
@@ -88,6 +101,36 @@
 
 
 /**
+ * This function implements the interface of a ThemeKey
+ * mapping function but doesn't set a ThemeKey property's
+ * value. It sets the global variable $custom_theme to a
+ * theme directly which will cause ThemeKey to use this
+ * theme.
+ *
+ * @param $nid
+ *   a node id, current value of ThemeKey property node:nid
+ *
+ * @return
+ *   string "static" if global custom theme has been set
+ *   or NULL if no theme has been assigned to the node
+ */
+function themekey_ui_author2theme($nid) {
+  global $custom_theme;
+
+  // node_load() must not be called from hook_init().
+  // Therefor we have to execute SQL here.
+  if ($theme = db_result(db_query("SELECT theme FROM {node} JOIN {themekey_ui_author_theme} USING (uid) WHERE nid = %d", $nid))) {
+    if ('default' != $theme) {
+      $custom_theme = $theme;
+      return 'static';
+    }
+  }
+
+  return NULL;
+}
+
+
+/**
  * Implements hook_theme().
  */
 function themekey_ui_theme() {
@@ -106,7 +149,7 @@
  * Implements hook_perm().
  */
 function themekey_ui_perm() {
-  return array('assign node themes', 'assign path alias themes');
+  return array('assign node themes', 'assign path alias themes', 'assign theme to own nodes');
 }
 
 
@@ -134,13 +177,26 @@
  * Implements hook_form_alter().
  */
 function themekey_ui_form_alter(&$form, $form_state, $form_id) {
-  if ($form_id == 'path_admin_form') {
+  if ('path_admin_form' == $form_id) {
     // path aliases form
     if (user_access('assign path alias themes') && variable_get('themekey_ui_pathalias', 0)) {
       module_load_include('inc', 'themekey_ui', 'themekey_ui_admin');
       themekey_ui_pathalias($form);
     }
   }
+  elseif ('user_profile_form' == $form_id) {
+    if (user_access('assign theme to own nodes') && variable_get('themekey_ui_author', 0)) {
+      module_load_include('inc', 'themekey_ui', 'themekey_ui_admin');
+
+      // to avoid a sql query to load his nodes themes every time a user is loaded we do this query here
+      $theme = FALSE;
+      if (!empty($form['#uid'])) {
+        $theme = db_result(db_query("SELECT theme FROM {themekey_ui_author_theme} WHERE uid = %d", $form['#uid']));
+      }
+
+      themekey_ui_theme_select_form($form, t('Theme configuration for my nodes'), t('Every node I create will be shown to other users using this theme.'), $theme ? $theme : 'default', $form['theme_select']['#weight'], FALSE);
+    }
+  }
   else {
     // node form?
     if (variable_get('themekey_ui_nodeform', 0) && user_access('assign node themes')) {
@@ -201,3 +257,33 @@
       break;
   }
 }
+
+/**
+ * Implements hook_user()
+ */
+function themekey_ui_user($op, &$edit, &$account, $category = NULL) {
+  switch ($op) {
+    case 'insert':
+    case 'update':
+      if (user_access('assign theme to own nodes') && variable_get('themekey_ui_author', 0) && !empty($edit['themekey_ui_theme'])) {
+        $author_theme = array(
+          'uid' => $account->uid,
+          'theme' => $edit['themekey_ui_theme'],
+        );
+
+        if (db_result(db_query("SELECT 1 FROM {themekey_ui_author_theme} WHERE uid = %d", $account->uid))) {
+          drupal_write_record('themekey_ui_author_theme', $author_theme, array('uid'));
+        }
+        else {
+          drupal_write_record('themekey_ui_author_theme', $author_theme);
+        }
+
+        $edit['themekey_ui_theme'] = NULL;
+      }
+      break;
+
+    case 'delete':
+      db_query("DELETE FROM {themekey_ui_author_theme} WHERE uid = %d", $account->uid);
+      break;
+  }
+}
Index: themekey_ui_admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/themekey/themekey_ui_admin.inc,v
retrieving revision 1.5.2.12
diff -u -r1.5.2.12 themekey_ui_admin.inc
--- themekey_ui_admin.inc	14 May 2010 20:54:20 -0000	1.5.2.12
+++ themekey_ui_admin.inc	16 Jul 2010 14:42:02 -0000
@@ -69,6 +69,13 @@
     }
   }
 
+  $form['themekey_ui']['themekey_ui_author'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Show theme option in user profile'),
+    '#default_value' => variable_get('themekey_ui_author', 0),
+    '#description' => t('Assign themes from create/edit node forms. This will show a \'Theme\' section on create/edit node pages.')
+  );
+
   $form['buttons']['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Save configuration'),
@@ -93,6 +100,7 @@
   }
 
   themekey_update_static_rule('themekey_ui:node_triggers_theme', $form_state['values']['themekey_ui_nodeform']);
+  themekey_update_static_rule('themekey_ui:node_author_triggers_theme', $form_state['values']['themekey_ui_author']);
 
   drupal_set_message(t('The configuration options have been saved.'));
 }
@@ -127,7 +135,7 @@
     '#title' => $title,
     '#description' => $description,
     '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
+    '#collapsed' => $collapsed,
     '#theme' => 'themekey_ui_theme_select_form'
   );
 
@@ -164,7 +172,7 @@
 
   if (!is_null($weight)) {
     // if we always set weight to '0' array_splice in themekey_ui_pathalias() will not work
-    $form['#weight'] = $weight;
+    $form['themekey_ui_themes']['#weight'] = $weight;
   }
 }
 
