You are here

function _protected_node_node_create_or_update in Protected Node 7

Same name and namespace in other branches
  1. 1.0.x protected_node.module \_protected_node_node_create_or_update()

Helper function.

Do protected node actions when creating or updating a node.

Parameters

object $node: A node object.

2 calls to _protected_node_node_create_or_update()
protected_node_node_insert in ./protected_node.module
Implements hook_node_insert().
protected_node_node_update in ./protected_node.module
Implements hook_node_update().

File

./protected_node.module, line 660
Protected Node module.

Code

function _protected_node_node_create_or_update($node) {

  // The node type is never protected if $node->protected_node_is_protected
  // is not set.
  if (!isset($node->protected_node_is_protected)) {
    return;
  }

  // Ugly but we want to keep some variables between the validation and
  // insert/update.
  global $_protected_node_emails;
  global $_protected_node_random_passwd;
  if (!empty($_protected_node_random_passwd)) {
    $node->protected_node_passwd = $_protected_node_random_passwd;
  }
  if (!empty($_protected_node_emails)) {
    $node->protected_node_emails = $_protected_node_emails;
  }
  _protected_node_save($node);

  // Send notifications if there is at least one email.
  if ($node->protected_node_is_protected && !empty($node->protected_node_emails) && $node->status == 1 && isset($node->protected_node_clear_passwd)) {
    module_load_include('mail.inc', 'protected_node');
    protected_node_send_mail($node);
  }
}