Index: taxonomy_theme.install
===================================================================
--- taxonomy_theme.install	(revision 1.9)
+++ taxonomy_theme.install	(revision )
@@ -23,13 +23,13 @@
         'unsigned' => TRUE,
         'not null' => TRUE,
         'default' => 0,
-        'description' => 'Primary Key: The {vocabulary}.vid of the vocabulary to which the theme is assigned.',
+        'description' => 'Primary Key: The {taxonomy_vocabulary}.vid of the vocabulary to which the theme is assigned.',
       ),
       'theme' => array(
         'type' => 'varchar',
         'length' => 255,
         'not null' => TRUE,
-        'default' => ''
+        'default' => '',
       ),
     ),
     'primary key' => array('vid'),
@@ -42,13 +42,13 @@
         'unsigned' => TRUE,
         'not null' => TRUE,
         'default' => 0,
-        'description' => 'Primary Key: The {term_data}.tid of the term to which the theme is assigned.',
+        'description' => 'Primary Key: The {taxonomy_term_data}.tid of the term to which the theme is assigned.',
       ),
       'theme' => array(
         'type' => 'varchar',
         'length' => 255,
         'not null' => TRUE,
-        'default' => ''
+        'default' => '',
       ),
     ),
     'primary key' => array('tid'),
@@ -57,19 +57,12 @@
   return $schema;
 }
 
-
 /**
- * Implements hook_install().
+ * implements hook_install()
+ * @return void
  */
 function taxonomy_theme_install() {
-  drupal_install_schema('taxonomy_theme');
+  // rebuild themekey properties
+  module_load_include('inc', 'themekey', 'themekey_build');
+  themekey_rebuild();
-}
+}
\ No newline at end of file
-
-
-/**
- * Implements hook_uninstall().
- */
-function taxonomy_theme_uninstall() {
-  // Drop tables
-  drupal_uninstall_schema('taxonomy_theme');
-}
Index: README.txt
===================================================================
--- README.txt	(revision 1.12)
+++ README.txt	(revision )
@@ -6,7 +6,7 @@
 Name: themekey
 Authors: Markus Kalkbrenner | Cocomore AG
          Thilo Wawrzik <drupal at profix898 dot de>
-Drupal: 6.x
+Drupal: 7.x
 Sponsor: Cocomore AG - http://www.cocomore.com
 
 
Index: taxonomy_theme_admin.inc
===================================================================
--- taxonomy_theme_admin.inc	(revision 1.11)
+++ taxonomy_theme_admin.inc	(revision )
@@ -8,6 +8,9 @@
  *
  * @see themekey_ui.module
  *
+ * @author Karl Fritsche | Cocomore AG (Drupal 7 Port)
+ *   @see http://drupal.org/user/619702
+ *
  * @author Markus Kalkbrenner | Cocomore AG
  *   @see http://drupal.org/user/124705
  *
@@ -15,13 +18,23 @@
  *   @see http://drupal.org/user/35192
  */
 
+/**
+ * form alter for ui settings forms
+ *
+ * @param  $form
+ * @param  $form_state
+ * @param  $form_id
+ * @return void
+ */
 function taxonomy_theme_alter_themekey_ui_settings_form(&$form, $form_state, $form_id) {
+
+
   $vocabform = variable_get('themekey_ui_vocabform', 0);
   $form['themekey_ui']['themekey_ui_vocabform'] = array(
     '#type' => 'checkbox',
     '#title' => t('Show theme option in create/edit taxonomy vocabulary forms'),
     '#default_value' => $vocabform,
-    '#description' => t('Assign themes from create/edit taxonomy vocabulary forms. This will show a \'Theme\' section on create/edit taxonomy vocabulary pages.')
+    '#description' => t('Assign themes from create/edit taxonomy vocabulary forms. This will show a \'Theme\' section on create/edit taxonomy vocabulary pages.'),
   );
   if ($vocabform) {
     $form['themekey_ui']['vocabs'] = array(
@@ -32,14 +45,16 @@
     );
     $form['themekey_ui']['vocabs']['table'] = array(
       '#theme' => 'themekey_ui_table',
-      '#header' => array(t('Vocabulary'), t('Enabled'))
+      '#header' => array(t('Vocabulary'), t('Enabled')),
     );
 
     foreach (taxonomy_get_vocabularies() as $vocab) {
-      $form['themekey_ui']['vocabs']['table'][$vocab->vid]['title'] = array('#value' => l($vocab->name, 'admin/content/taxonomy/edit/vocabulary/' . $vocab->vid));
+      $form['themekey_ui']['vocabs']['table'][$vocab->vid]['title'] = array(
+        '#markup' => l($vocab->name, 'admin/structure/taxonomy/'.$vocab->machine_name.'/edit'),
+      );
-      $form['themekey_ui']['vocabs']['table'][$vocab->vid]['themekey_ui_vocabform|'. $vocab->vid] = array(
+      $form['themekey_ui']['vocabs']['table'][$vocab->vid]['themekey_ui_vocabform|' . $vocab->vid] = array(
         '#type' => 'checkbox',
-        '#default_value' => variable_get('themekey_ui_vocabform|'. $vocab->vid, 0),
+        '#default_value' => variable_get('themekey_ui_vocabform|' . $vocab->vid, 0),
       );
     }
   }
@@ -49,7 +64,7 @@
     '#type' => 'checkbox',
     '#title' => t('Show theme option in create/edit taxonomy term forms'),
     '#default_value' => $termform,
-    '#description' => t('Assign themes from create/edit taxonomy term forms. This will show a \'Theme\' section on create/edit taxonomy term pages.')
+    '#description' => t('Assign themes from create/edit taxonomy term forms. This will show a \'Theme\' section on create/edit taxonomy term pages.'),
   );
   if ($termform) {
     $form['themekey_ui']['term_vocabs'] = array(
@@ -60,14 +75,16 @@
     );
     $form['themekey_ui']['term_vocabs']['table'] = array(
       '#theme' => 'themekey_ui_table',
-      '#header' => array(t('Vocabulary'), t('Enabled'))
+      '#header' => array(t('Vocabulary'), t('Enabled')),
     );
 
     foreach (taxonomy_get_vocabularies() as $vocab) {
-      $form['themekey_ui']['term_vocabs']['table'][$vocab->vid]['title'] = array('#value' => l($vocab->name, 'admin/content/taxonomy/' . $vocab->vid));
+      $form['themekey_ui']['term_vocabs']['table'][$vocab->vid]['title'] = array(
+        '#markup' => l($vocab->name, 'admin/structure/taxonomy/' . $vocab->machine_name)
+      );
-      $form['themekey_ui']['term_vocabs']['table'][$vocab->vid]['themekey_ui_termform|'. $vocab->vid] = array(
+      $form['themekey_ui']['term_vocabs']['table'][$vocab->vid]['themekey_ui_termform|' . $vocab->vid] = array(
         '#type' => 'checkbox',
-        '#default_value' => variable_get('themekey_ui_termform|'. $vocab->vid, 0),
+        '#default_value' => variable_get('themekey_ui_termform|' . $vocab->vid, 0),
       );
     }
   }
@@ -78,13 +95,13 @@
 
 /**
  * Function _taxonomy_theme_form_alter().
+ * adds themekey ui select form to curretn form
  */
 function _taxonomy_theme_form_alter(&$form, $form_state, $form_id) {
   module_load_include('inc', 'themekey_ui', 'themekey_ui_admin');
 
   $form_theme = array();
   $theme = '';
-
   switch ($form_id) {
     case 'taxonomy_form_term':
       if (!variable_get('themekey_ui_termform|' . $form['vid']['#value'], 0)) {
@@ -115,6 +132,8 @@
 
 /**
  * function _taxonomy_theme_alter_submit().
+ * add/save themes set in vocabulary/terms
+ * add static rules
  */
 function _taxonomy_theme_form_alter_submit($form, &$form_state) {
   switch ($form_state['values']['form_id']) {
@@ -123,28 +142,35 @@
       themekey_update_static_rule('taxonomy_theme:term_triggers_theme', $form_state['values']['themekey_ui_termform']);
       break;
 
-    case 'taxonomy_form_term':
+   case 'taxonomy_form_term':
-      $item = array('tid' => $form_state['values']['tid'], 'theme' => $form_state['values']['themekey_ui_theme']);
-      db_lock_table('taxonomy_theme_tids');
-      if (db_result(db_query('SELECT tid FROM {taxonomy_theme_tids} WHERE tid = %d', $form_state['values']['tid']))) {
+      $item = array(
+        'tid' => $form_state['values']['tid'],
+        'theme' => $form_state['values']['themekey_ui_theme'],
+      );
+      //TODO DB LOCK TABLE
+
+      if (db_select('taxonomy_theme_tids', 't')->fields('t', array('tid'))->condition('tid', $form_state['values']['tid'])->execute()->fetchField()) {
         drupal_write_record('taxonomy_theme_tids', $item, array('tid'));
       }
       else {
         drupal_write_record('taxonomy_theme_tids', $item);
       }
-      db_unlock_tables();
+      //TODO DB UNLOCK TABLE
       break;
 
     case 'taxonomy_form_vocabulary':
-      $item = array('vid' => $form_state['values']['vid'], 'theme' => $form_state['values']['themekey_ui_theme']);
-      db_lock_table('taxonomy_theme_vids');
-      if (db_result(db_query('SELECT vid FROM {taxonomy_theme_vids} WHERE vid = %d', $form_state['values']['vid']))) {
+      $item = array(
+        'vid' => $form_state['values']['vid'],
+        'theme' => $form_state['values']['themekey_ui_theme'],
+      );
+      //TODO DB LOCK TABLE
+      if (db_select('taxonomy_theme_vids', 't')->fields('t', array('vid'))->condition('vid', $form_state['values']['vid'])->execute()->fetchField()) {
         drupal_write_record('taxonomy_theme_vids', $item, array('vid'));
       }
       else {
         drupal_write_record('taxonomy_theme_vids', $item);
       }
-      db_unlock_tables();
+      //TODO DB UNLOCK TABLE
       break;
   }
 }
Index: tests/taxonomy_theme.test
===================================================================
--- tests/taxonomy_theme.test	(revision )
+++ tests/taxonomy_theme.test	(revision )
@@ -0,0 +1,90 @@
+<?php
+
+class TaxonomyThemeWebTestCase extends DrupalWebTestCase {
+
+  protected $privileged_user;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Taxonomy Theme test',
+      'description' => 'Test the taxonomy_theme module.',
+      'group' => 'Taxonomy Theme',
+    );
+  }
+
+  public function setUp() {
+    parent::setUp('themekey', 'themekey_ui', 'taxonomy_theme');
+
+    $this->privileged_user = $this->drupalCreateUser(array(
+      'administer theme assignments', 'administer themekey settings',
+      'administer taxonomy theme', 'administer taxonomy',
+      'create article content', 'edit own article content',
+    ));
+    $this->drupalLogin($this->privileged_user);
+    theme_enable(array('garland'));
+  }
+
+  public function testVocabularyNodeTheme() {
+
+    $this->taxonomyThemeCreateNode();
+
+    // enable "Show theme option in create/edit taxonomy vocabulary forms"
+    $this->drupalPost('admin/config/user-interface/themekey/settings/ui', array('themekey_ui_vocabform' => 1), t('Save configuration'));
+    // enable "Tags" for vocab taxonomy theme
+    $this->drupalPost('admin/config/user-interface/themekey/settings/ui', array('themekey_ui_vocabform|1' => 1), t('Save configuration'));
+    
+    // taxonomy vocab: select theme
+    $this->drupalPost('admin/structure/taxonomy/tags/edit', array('themekey_ui_theme' => 'garland'), t('Save'));
+
+    $this->drupalGet('admin/structure/taxonomy/tags/edit');
+
+    // load node 1
+    $this->drupalGet('node/1');
+    // theme should be garland
+    $this->assertTheme('garland');
+  }
+
+  public function testTermNodeTheme() {
+    $this->taxonomyThemeCreateNode();
+
+    // enable "Show theme option in create/edit taxonomy term forms"
+    $this->drupalPost('admin/config/user-interface/themekey/settings/ui', array('themekey_ui_termform' => 1), t('Save configuration'));
+    // enable "Tags" for term taxonomy theme
+    $this->drupalPost('admin/config/user-interface/themekey/settings/ui', array('themekey_ui_termform|1' => 1), t('Save configuration'));
+
+    // taxonomy term 1: select theme
+    $this->drupalPost('taxonomy/term/1/edit', array('themekey_ui_theme' => 'garland'), t('Save'));
+
+    $this->drupalGet('taxonomy/term/1/edit');
+
+    // load node 1
+    $this->drupalGet('node/1');
+    // theme should be garland
+    $this->assertTheme('garland');
+    
+  }
+
+  /**
+   * add new article with a dummy tag and test if theme is bartik (default)
+   *
+   * @return void
+   */
+  function taxonomyThemeCreateNode() {
+    // add node with term
+    $this->drupalPost('node/add/article', array(
+      'title' => 'dummy',
+      'field_tags[und]' => 'dummy_tag',
+      'body[und][0][value]' => 'dummy'), t('Save'));
+
+    // load node 1
+    $this->drupalGet('node/1');
+    // theme is bartik
+    $this->assertTheme('bartik');
+
+  }
+
+  public function assertTheme($theme) {
+    $this->assertRaw('themes/' . $theme, 'current theme is ' . $theme);
+  }
+
+}
\ No newline at end of file
Index: CHANGELOG.txt
===================================================================
--- CHANGELOG.txt	(revision 1.2)
+++ CHANGELOG.txt	(revision )
@@ -1,5 +1,9 @@
 // $Id: CHANGELOG.txt,v 1.2 2010/08/20 15:36:32 mkalkbrenner Exp $
 
+Taxonomy Theme 7.x-dev, 2011-01-30
+-----------------------------------------
+[       ] kfritsche: port to Drupal 7 (Drupal 7 Code Sprint)
+
 Taxonomy Theme 6.x-1.0-beta2, 2010-xx-xx
 -----------------------------------------
 [       ] mkalkbrenner: changed code according to drupal coding standards
Index: taxonomy_theme.module
===================================================================
--- taxonomy_theme.module	(revision 1.51)
+++ taxonomy_theme.module	(revision )
@@ -2,10 +2,15 @@
 // $Id: taxonomy_theme.module,v 1.51 2010/08/20 15:36:32 mkalkbrenner Exp $
 
 /**
- * Implements hook_perm().
+ * Implements hook_permission().
  */
-function taxonomy_theme_perm() {
-  return array('administer taxonomy theme');
+function taxonomy_theme_permission() {
+  return array(
+    'administer taxonomy theme' => array(
+      'title' => t('administer taxonomy theme'),
+      'description' => t('Change theme for vocabularies and terms.'),
+    ),
+  );
 }
 
 
@@ -16,15 +21,15 @@
   switch ($form_id) {
     case 'taxonomy_form_term':
     case 'taxonomy_form_vocabulary':
-      if (user_access('administer taxonomy_theme')) {
-        require_once(drupal_get_path('module', 'taxonomy_theme') .'/taxonomy_theme_admin.inc');
+      if (user_access('administer taxonomy theme')) {
+        module_load_include('inc', 'taxonomy_theme', 'taxonomy_theme_admin');
         _taxonomy_theme_form_alter($form, $form_state, $form_id);
       }
       break;
 
     case 'themekey_ui_settings_form':
       if (user_access('administer themekey settings')) {
-        require_once(drupal_get_path('module', 'taxonomy_theme') .'/taxonomy_theme_admin.inc');
+        module_load_include('inc', 'taxonomy_theme', 'taxonomy_theme_admin');
         taxonomy_theme_alter_themekey_ui_settings_form($form, $form_state, $form_id);
       }
       break;
@@ -36,7 +41,7 @@
  * Function taxonomy_theme_form_alter_submit().
  */
 function taxonomy_theme_form_alter_submit($form, &$form_state) {
-  require_once(drupal_get_path('module', 'taxonomy_theme') .'/taxonomy_theme_admin.inc');
+   module_load_include('inc', 'taxonomy_theme', 'taxonomy_theme_admin');
   _taxonomy_theme_form_alter_submit($form, $form_state);
 }
 
@@ -57,14 +62,14 @@
   $attributes = array();
 
   $attributes['taxonomy_theme:vocabulary_triggers_theme'] = array(
-    'description' => t("Property taxonomy_theme:vocabulary_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 assigned to a taxonomy vocabulary using Taxonomy Theme if the current page is associated with this vocabulary.",
+    'description' => t("Property taxonomy_theme:vocabulary_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 assigned to a taxonomy vocabulary using Taxonomy Theme if the current page is associated with this vocabulary.", 
-      array('!link' => l(t('Show theme option in create/edit taxonomy vocabulary forms'), 'admin/settings/themekey/settings/ui'))),
+      array('!link' => l(t('Show theme option in create/edit taxonomy vocabulary forms'), 'admin/config/themekey/settings/ui'))),
     'static' => TRUE,
   );
 
   $attributes['taxonomy_theme:term_triggers_theme'] = array(
-    'description' => t("Property taxonomy_theme:term_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 assigned to a taxonomy term using Taxonomy Theme if the current page is associated with this term.",
+    'description' => t("Property taxonomy_theme:term_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 assigned to a taxonomy term using Taxonomy Theme if the current page is associated with this term.", 
-      array('!link' => l(t('Show theme option in create/edit taxonomy term forms'), 'admin/settings/themekey/settings/ui'))),
+      array('!link' => l(t('Show theme option in create/edit taxonomy term forms'), 'admin/config/themekey/settings/ui'))),
     'static' => TRUE,
   );
 
@@ -72,20 +77,29 @@
   // Mapping functions
   $maps = array();
 
-  $maps[] = array('src'       => 'taxonomy:vid',
+  $maps[] = array(
+    'src' => 'taxonomy:vid',
-                  'dst'       => 'taxonomy_theme:vocabulary_triggers_theme',
+    'dst' => 'taxonomy_theme:vocabulary_triggers_theme',
-                  'callback'  => 'taxonomy_theme_vid2theme');
+    'callback' => 'taxonomy_theme_vid2theme',
+  );
 
-  $maps[] = array('src'       => 'taxonomy:tid',
+  $maps[] = array(
+    'src' => 'taxonomy:tid',
-                  'dst'       => 'taxonomy_theme:term_triggers_theme',
+    'dst' => 'taxonomy_theme:term_triggers_theme',
-                  'callback'  => 'taxonomy_theme_tid2theme');
+    'callback' => 'taxonomy_theme_tid2theme',
+  );
 
   return array('attributes' => $attributes, 'maps' => $maps);
 }
 
-
+/**
+ * Set custom theme from given vocabulary id (vid)
+ *
+ * @param  $vid vocabulary id
+ * @return null|string
+ */
 function taxonomy_theme_vid2theme($vid) {
-  global $custom_theme;
+  $custom_theme = &drupal_static('themekey_custom_theme', '');
 
   if ($theme = taxonomy_theme_get_theme_by_vid($vid)) {
     if (themekey_check_theme_enabled($theme)) {
@@ -97,9 +111,14 @@
   return NULL;
 }
 
-
+/**
+ * Set custom theme from given term id (tid)
+ *
+ * @param  $tid term id
+ * @return null|string
+ */
 function taxonomy_theme_tid2theme($tid) {
-  global $custom_theme;
+  $custom_theme = &drupal_static('themekey_custom_theme', '');
 
   if ($theme = taxonomy_theme_get_theme_by_tid($tid)) {
     if (themekey_check_theme_enabled($theme)) {
@@ -111,12 +130,22 @@
   return NULL;
 }
 
-
+/**
+ * get theme name from vocabulary id
+ *
+ * @param  $vid vocabulary id
+ * @return theme name
+ */
 function taxonomy_theme_get_theme_by_vid($vid) {
-  return db_result(db_query('SELECT theme FROM {taxonomy_theme_vids} WHERE vid = %d', $vid));
+  return db_select('taxonomy_theme_vids', 't')->fields('t', array('theme'))->condition('vid', $vid)->execute()->fetchField();
 }
 
-
+/**
+ * get theme name from term id
+ *
+ * @param  $tid term id
+ * @return theme name
+ */
 function taxonomy_theme_get_theme_by_tid($tid) {
-  return db_result(db_query('SELECT theme FROM {taxonomy_theme_tids} WHERE tid = %d', $tid));
+  return db_select('taxonomy_theme_tids', 't')->fields('t', array('theme'))->condition('tid', $tid)->execute()->fetchField();
-}
\ No newline at end of file
+}
Index: taxonomy_theme.info
===================================================================
--- taxonomy_theme.info	(revision 1.4)
+++ taxonomy_theme.info	(revision )
@@ -2,7 +2,13 @@
 
 name = "Taxonomy Theme"
 description = "User interface for mapping themes to Taxonomy vocabularies and terms"
-core = 6.x
+core = 7.x
 dependencies[] = themekey_ui
 dependencies[] = taxonomy
 package = ThemeKey
+configure = admin/config/user-interface/themekey/settings/ui
+
+files[] = taxonomy_theme.install
+files[] = taxonomy_theme.module
+files[] = taxonomy_theme_admin.inc
+files[] = tests/taxonomy_theme.test
