You are here

API.txt in Protected Node 6

Same filename and directory in other branches
  1. 5 API.txt
There is now a simple API with three functions ready to be used
by 3rd party modules and a hook to allow for hiding 3rd party
data that has to be protected.


bool protected_node_set_protected(int $nid, string $passwd = NULL)
=============================================================
Protected the specified node.

$nid can be the node identifier or any other field that the node_load()
function accepts.

Unless an error occurs, the function at least protects the node. When the
$passwd parameter is specified, it also changes the password and as a side
effect kicks out all the users who had previously enter that node password.

All users will have to re-enter the password.

The function returns TRUE if the node is protected.


bool protected_node_unset_protected(int $nid)
=============================================
Unprotect the specified node.

This function ensures that the specified node is not protected anymore.
It does not delete the row from the database which means calling the
protected_node_set_protected() function with the same $nid parameter
will restore the previous state (assuming the node was protected before.)

When the node was previously protected and this call succeeds, the method
returns TRUE.

If an invalid $nid is passed, an SQL error occurs or the node was not
protected, FALSE is returned.


bool protected_node_isset_protected(int $nid)
=============================================
Check whether the specified node is protected.

This method returns TRUE if the node identified by the provided $nid is
currently protected.

Returns FALSE in all other cases (invalid $nid, SQL error, etc.)


void hook_protected_node_hide(object &$node)
============================================
Request that $node parameters that are expected to be protected to somehow
be removed from the $node.

This function gives 3rd party modules adding content to a node a chance for
hiding that content before displaying it gets displayed.

The default implementation hides the body, teaser, and CCK content. It either
replace the title with "Password protected page" or keeps it intact depending
on the protected node Show Title flag.

    function protected_node_protected_node_hide(&$node) {
      // Core module fields
      if (!$node->protected_node_show_title) {
        $node->title = t('Password protected page');
      }
      $node->teaser = '';
      $node->body = '';
      $node->content = array();
    }

The hook is only invoked when the node is protected and the user did not yet
provide the correct password.

File

API.txt
View source
  1. There is now a simple API with three functions ready to be used
  2. by 3rd party modules and a hook to allow for hiding 3rd party
  3. data that has to be protected.
  4. bool protected_node_set_protected(int $nid, string $passwd = NULL)
  5. =============================================================
  6. Protected the specified node.
  7. $nid can be the node identifier or any other field that the node_load()
  8. function accepts.
  9. Unless an error occurs, the function at least protects the node. When the
  10. $passwd parameter is specified, it also changes the password and as a side
  11. effect kicks out all the users who had previously enter that node password.
  12. All users will have to re-enter the password.
  13. The function returns TRUE if the node is protected.
  14. bool protected_node_unset_protected(int $nid)
  15. =============================================
  16. Unprotect the specified node.
  17. This function ensures that the specified node is not protected anymore.
  18. It does not delete the row from the database which means calling the
  19. protected_node_set_protected() function with the same $nid parameter
  20. will restore the previous state (assuming the node was protected before.)
  21. When the node was previously protected and this call succeeds, the method
  22. returns TRUE.
  23. If an invalid $nid is passed, an SQL error occurs or the node was not
  24. protected, FALSE is returned.
  25. bool protected_node_isset_protected(int $nid)
  26. =============================================
  27. Check whether the specified node is protected.
  28. This method returns TRUE if the node identified by the provided $nid is
  29. currently protected.
  30. Returns FALSE in all other cases (invalid $nid, SQL error, etc.)
  31. void hook_protected_node_hide(object &$node)
  32. ============================================
  33. Request that $node parameters that are expected to be protected to somehow
  34. be removed from the $node.
  35. This function gives 3rd party modules adding content to a node a chance for
  36. hiding that content before displaying it gets displayed.
  37. The default implementation hides the body, teaser, and CCK content. It either
  38. replace the title with "Password protected page" or keeps it intact depending
  39. on the protected node Show Title flag.
  40. function protected_node_protected_node_hide(&$node) {
  41. // Core module fields
  42. if (!$node->protected_node_show_title) {
  43. $node->title = t('Password protected page');
  44. }
  45. $node->teaser = '';
  46. $node->body = '';
  47. $node->content = array();
  48. }
  49. The hook is only invoked when the node is protected and the user did not yet
  50. provide the correct password.