uid); return $grants; } /** * Implementation of hook_node_access_records(). * * All node access modules must implement this hook. If the module is * interested in the privacy of the node passed in, return a list * of node access values for each grant ID we offer. Since this * example module only offers 1 grant ID, we will only ever be * returning one record. */ function node_access_example_node_access_records($node) { // We only care about the node if it's been marked private. If not, it is // treated just like any other node and we completely ignore it. if (!empty($node->private)) { $grants = array(); $grants[] = array( 'realm' => 'example', 'gid' => TRUE, 'grant_view' => TRUE, 'grant_update' => FALSE, 'grant_delete' => FALSE, 'priority' => 0, ); // For the example_author array, the GID is equivalent to a UID, which // means there are many many groups of just 1 user. $grants[] = array( 'realm' => 'example_author', 'gid' => $node->uid, 'grant_view' => TRUE, 'grant_update' => TRUE, 'grant_delete' => TRUE, 'priority' => 0, ); return $grants; } } /** * Implementation of hook_form_alter() * * This module adds a simple checkbox to the node form labeled private. If the * checkbox is labelled, only the node author and users with 'access private content' * privileges may see it. */ function node_access_example_form_alter(&$form, $form_state) { if ($form['#id'] == 'node-form') { $form['private'] = array( '#type' => 'checkbox', '#title' => t('Private'), '#description' => t('Check here if this content should be set private and only shown to privileged users.'), '#default_value' => isset($form['#node']->private) ? $form['#node']->private : FALSE, ); } } /** * Implementation of hook_nodeapi(). * * The module must track the access status of the node. */ function node_access_example_nodeapi(&$node, $op, $arg = 0) { switch ($op) { case 'load': $node->private = db_result(db_query('SELECT private FROM {node_access_example} WHERE nid = %d', $node->nid)); break; case 'insert': db_query('INSERT INTO {node_access_example} (nid, private) VALUES (%d, %d)', $node->nid, $node->private); break; case 'update': db_query('UPDATE {node_access_example} SET private = %d WHERE nid = %d', $node->private, $node->nid); break; case 'delete': db_query('DELETE FROM {node_access_example} WHERE nid = %d', $node->nid); break; } } /** * @} End of "defgroup node_access_example". */