You are here

function themekey_ui_nodeapi in ThemeKey 6.2

Same name and namespace in other branches
  1. 6.4 themekey_ui.module \themekey_ui_nodeapi()
  2. 6 themekey_ui.module \themekey_ui_nodeapi()
  3. 6.3 themekey_ui.module \themekey_ui_nodeapi()

Implements hook_nodeapi().

1 call to themekey_ui_nodeapi()
themekey_ui_nid2theme in ./themekey_ui.module
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.

File

./themekey_ui.module, line 223
ThemeKey UI is an extension for ThemeKey

Code

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,
        );
        $key = array();
        if (!$node->revision && db_result(db_query("SELECT 1 FROM {themekey_ui_node_theme} WHERE nid = %d AND vid = %d", $node->nid, $node->vid))) {
          $key = array(
            'nid',
            'vid',
          );
        }
        drupal_write_record('themekey_ui_node_theme', $item, $key);
      }
      break;
    case 'delete':
      db_query('DELETE FROM {themekey_ui_node_theme} WHERE nid = %d', $node->nid);
      break;
  }
}