You are here

function headerimage_nodeapi in Header image 6

Same name and namespace in other branches
  1. 5 headerimage.module \headerimage_nodeapi()

Implementation of hook_nodeapi

File

./headerimage.module, line 548
headerimage.module Conditionally display an node in a block.

Code

function headerimage_nodeapi(&$node, $op) {
  if (!empty($node->type) && in_array($node->type, variable_get('headerimage_node_type', array()), true)) {
    switch ($op) {
      case 'update':
        db_query("DELETE from {headerimage} WHERE nid = %d", $node->nid);
      case 'insert':

        // Pack all conditions into one array
        $conditions = variable_get(headerimage_condition_types, array(
          'nid' => 'nid',
        ));
        if (!empty($conditions)) {
          foreach ($conditions as $condition) {
            if ($condition != '0') {
              $name = 'headerimage_condition_' . $condition;
              $conditions[$condition] = $node->{$name};
            }
          }
        }
        db_query("INSERT INTO {headerimage} (nid, block, weight, conditions)\n                 VALUES (%d, %d, %d, '%s')", $node->nid, $node->headerimage_block, $node->headerimage_weight, serialize($conditions));
        break;
      case 'prepare':

        // Load data from database if node is edited
        $result = db_fetch_object(db_query("SELECT * from {headerimage} where nid = %d", $node->nid));
        $node->headerimage_block = $result->block;
        $node->headerimage_weight = $result->weight;
        $conditions = unserialize($result->conditions);
        if (!empty($conditions)) {
          foreach ($conditions as $condition => $value) {
            $name = 'headerimage_condition_' . $condition;
            $node->{$name} = $value;
          }
        }
        break;
      case 'delete':
        db_query("DELETE from {headerimage} WHERE nid = %d", $node->nid);
        break;
    }
  }
}