t("Property themekey_ui:node_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 the current node using ThemeKey UI.", array('!link' => l(t('Show theme option in create/edit node forms'), 'admin/settings/themekey/settings/ui'))), '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(); $maps[] = array('src' => 'node:nid', '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); } /** * 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_nid2theme($nid) { global $custom_theme; // node_load() must not be called from hook_init(). // Therefor we have to execute SQL here using hook_nodeapi(). $node = new stdClass(); $node->nid = $nid; $node->vid = themekey_node_get_simple_node_property($nid, 'vid'); $node->type = themekey_node_get_simple_node_property($nid, 'type'); themekey_ui_nodeapi($node, 'load'); if (!empty($node->themekey_ui_theme) && themekey_check_theme_enabled($node->themekey_ui_theme)) { $custom_theme = $node->themekey_ui_theme; return 'static'; } return NULL; } /** * 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() { return array( 'themekey_ui_table' => array( 'arguments' => array('form' => NULL), ), 'themekey_ui_theme_select_form' => array( 'arguments' => array('form' => NULL), ), ); } /** * Implements hook_perm(). */ function themekey_ui_perm() { return array('assign node themes', 'assign path alias themes', 'assign theme to own nodes'); } /** * Implements hook_menu(). */ function themekey_ui_menu() { $items = array(); $items['admin/settings/themekey/settings/ui'] = array( 'title' => 'User Interface', 'access callback' => 'user_access', 'access arguments' => array('administer themekey settings'), 'file' => 'themekey_ui_admin.inc', 'page callback' => 'drupal_get_form', 'page arguments' => array('themekey_ui_settings_form'), 'type' => MENU_LOCAL_TASK, 'weight' => 1 ); return $items; } /** * Implements hook_form_alter(). */ function themekey_ui_form_alter(&$form, $form_state, $form_id) { 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')) { $type = isset($form['type']['#value']) ? $form['type']['#value'] : FALSE; if ($form_id == $type .'_node_form' && variable_get('themekey_ui_nodeform|'. $type, 1)) { module_load_include('inc', 'themekey_ui', 'themekey_ui_admin'); $description = t('Theme configuration for this node'); if (module_exists('og') && !og_is_omitted_type($type)) { $description .= '
' . t('Note:') . ' ' . t('This content type is used in organic groups. A Theme you select here will only be used to display this node if you set the theme for the organic group to %theme', array('%theme' => variable_get('theme_default', 'garland') . ' ' .t('(site default theme)'))) . '
'; } themekey_ui_theme_select_form($form, t('Theme configuration for this node'), $description, !empty($form['#node']->themekey_ui_theme) ? $form['#node']->themekey_ui_theme : 'default'); } } } } /** * Implements hook_nodeapi(). */ function themekey_ui_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { switch ($op) { case 'load': if (variable_get('themekey_ui_nodeform', 0) && variable_get('themekey_ui_nodeform|'. $node->type, 1)) { if (!empty($node->vid)) { $theme = db_result(db_query('SELECT theme FROM {themekey_ui_node_theme} WHERE nid = %d AND vid = %d', $node->nid, $node->vid)); if ($theme) { $node->themekey_ui_theme = $theme; } else { $node->themekey_ui_theme = 'default'; } } } break; case 'insert': if (!empty($node->themekey_ui_theme)) { $item = array('nid' => $node->nid, 'vid' => $node->vid, 'theme' => $node->themekey_ui_theme); drupal_write_record('themekey_ui_node_theme', $item); } break; case 'update': if (!empty($node->themekey_ui_theme)) { $item = array('nid' => $node->nid, 'vid' => $node->vid, 'theme' => $node->themekey_ui_theme); if ($node->revision) { drupal_write_record('themekey_ui_node_theme', $item); } else { drupal_write_record('themekey_ui_node_theme', $item, array('nid', 'vid')); } } break; case 'delete': db_query('DELETE FROM {themekey_ui_node_theme} WHERE nid = %d', $node->nid); 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; } }