You are here

function dynamic_background_node_nodeapi in Dynamic Background 6

Implementation of hook_nodeapi(), which is used to save and load information about the image selected for a given node.

File

modules/dynamic_background_node/dynamic_background_node.module, line 130
This module provides the node adminitrators with the option to use different dynamic background images for each node.

Code

function dynamic_background_node_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  $settings = variable_get('dynamic_background_node', array());
  if (isset($settings['content_types'][$node->type]) && $settings['content_types'][$node->type]) {
    switch ($op) {
      case 'load':
        $data = dynamic_background_node_get_data($node->nid, $node->vid);
        if ($data) {
          $node->dynamic_background = $data;
        }
        break;
      case 'insert':
      case 'update':
        if (user_access('select node background image')) {
          $data = dynamic_background_node_get_data($node->nid, $node->vid);
          if ($data) {
            db_query('UPDATE {dynamic_background_node} SET data = "%s", vid = %d WHERE nid = %d', serialize($node->dynamic_background), $node->vid, $node->nid);
          }
          else {
            db_query('INSERT INTO {dynamic_background_node} VALUES (%d, %d, "%s")', $node->nid, $node->vid, serialize($node->dynamic_background));
          }
        }
        break;
      case 'delete':
        db_query('DELETE FROM {dynamic_background_node} WHERE nid=%d', $node->nid);
        break;
    }
  }
}