You are here

function hosting_nodeapi in Hosting 6.2

Same name and namespace in other branches
  1. 5 hosting.module \hosting_nodeapi()
  2. 7.4 hosting.module \hosting_nodeapi()
  3. 7.3 hosting.module \hosting_nodeapi()

Implementation of hook_nodeapi().

This function redirects to hosting_nodeapi_$nodetype_$op calls, to save ourselves from an incessant amount of intricately nested code, and allow easier extension / maintenance.

See also

hook_nodeapi_TYPE_OP()

File

./hosting.module, line 200
Hosting module.

Code

function hosting_nodeapi(&$node, $op, $arg1, $arg2) {
  global $user;
  $return = array();
  if (in_array($node->type, hosting_context_node_types())) {
    switch ($op) {
      case 'presave':
        if (!isset($node->uid)) {
          $node->uid = $user->uid;
        }
        break;
      case 'load':
        $return = db_fetch_array(db_query("SELECT name AS hosting_name FROM {hosting_context} WHERE nid = %d", $node->nid));
        if ($return === FALSE) {

          // Should only happen on install
          $return = array();
        }
        break;
      case 'delete':
        db_query("DELETE FROM {hosting_context} WHERE nid = %d", $node->nid);
        break;
    }
  }

  // We need to practically re-invent module_invoke_all here because
  // we have to pass the node as a reference.
  $hook = "nodeapi_" . $node->type . "_" . str_replace(" ", "_", $op);
  foreach (module_implements($hook) as $module) {
    $function = $module . '_' . $hook;
    $result = $function($node, $arg1, $arg2);
    if (isset($result) && is_array($result)) {
      $return = array_merge_recursive($return, $result);
    }
    else {
      if (isset($result)) {
        $return[] = $result;
      }
    }
  }
  return $return;
}