From 55ec92becd45e24e0b8fbd9a8fbc93f5d4c2f452 Mon Sep 17 00:00:00 2001
From: Florent Torregrosa <florent.torregrosa@gmail.com>
Date: Mon, 6 Jul 2015 17:03:26 +0200
Subject: [PATCH] Issue #2443703: Update README.txt and replace API.txt with
 protected_node.api.php

---
 API.txt                |  71 ----------------------------------
 README.txt             | 103 ++++++++++++++++++++++++++++++-------------------
 protected_node.api.php |  38 ++++++++++++++++++
 protected_node.module  |  11 ++++++
 4 files changed, 112 insertions(+), 111 deletions(-)
 delete mode 100644 API.txt
 create mode 100644 protected_node.api.php

diff --git a/API.txt b/API.txt
deleted file mode 100644
index 0357037..0000000
--- a/API.txt
+++ /dev/null
@@ -1,71 +0,0 @@
-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)
-=============================================================
-Protect 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.
diff --git a/README.txt b/README.txt
index e017abc..f0c30a3 100644
--- a/README.txt
+++ b/README.txt
@@ -1,13 +1,18 @@
+CONTENTS OF THIS FILE
+---------------------
 
-Protected Node Documentation
-----------------------------
+ * Introduction
+ * Requirements
+ * Similar modules
+ * Known conflicts
+ * Installation
+ * Configuration
+ * Documentation
+ * Maintainers
 
- * Original :   http://www.m2osw.com/doc-protected-node
- * Drupal.org : https://drupal.org/node/2176627
 
-
-Description
------------
+INTRODUCTION
+------------
 
 With the protected node module users can restrict access to a node with a
 password they provide when creating the node (or a site wide password or a per
@@ -18,16 +23,45 @@ People who want to view the node or download one of its private attachments are
 first redirected to a password query page (/protected-node). Once the user
 entered the right password, he is redirected back to the original node.
 Authorizations are stored in sessions, so users don't have to enter the
-password over and over again once provided (requires cookies.)
+password over and over again once provided (requires cookies).
+
+Email feature: The module is capable of sending the password via unencrypted
+emails. This is useful if you create a page to be viewed only by a few people
+you know.
+
+Views submodule: The module has a few extensions supporting Views. It includes
+filters and output extensions.
 
-The module includes support for sending emails, views, and rules.
+Rules submodule: The module includes a Rules extension allowing you to act on a
+protected node and test the current state of a node for the current user.
 
+ * For a full description of the module, visit the project page:
+   https://www.drupal.org/project/protected_node
+ * To submit bug reports and feature suggestions, or to track changes:
+   https://www.drupal.org/project/issues/130911
 
-Installation
+
+REQUIREMENTS
 ------------
 
 There is no special requirement for this module.
 
+
+SIMILAR MODULES
+---------------
+
+ * Protected Pages (https://www.drupal.org/project/protected_pages)
+
+
+KNOWN CONFLICTS
+---------------
+
+ * Login Destination (https://www.drupal.org/project/login_destination)
+
+
+INSTALLATION
+------------
+
 Once enabled, go to the administer permissions page to set the new permissions.
 
 Below is a matrix with permissions you must set depending on your needs.
@@ -56,46 +90,35 @@ Permissions\Cases | 1 | 2 | 3 | 4 | 5 |
 ------------------|---|---|---|---|---|
          D        |   |   |   |   | 1 |
 
-Configuration
+
+CONFIGURATION
 -------------
 
-Global settings : /admin/config/content/protected_node
+Global settings: /admin/config/content/protected_node
 
-Per content type : admin/structure/types/manage/%content_type
-In the fieldset "Protected node settings".
+Per content type: admin/structure/types/manage/%content_type in the fieldset
+"Protected node settings".
 
 You can set password on the add/edit node form in the fieldset
 "Password protect this %type_name".
 
 
-Email extension
----------------
-
-The module is capable of sending the password via unencrypted emails. This is
-useful if you create a page to be viewed only by a few people you know.
-
-
-Views extension
----------------
-
-The module has a few extensions supporting Views. It includes filters and
-output extensions.
-
-
-Rules extension
----------------
-
-The module includes a Rules extension allowing you to act on a protected node
-and test the current state of a node for the current user.
-
+DOCUMENTATION
+-------------
 
-Known conflicts
----------------
+ * Original:   http://www.m2osw.com/doc-protected-node
+ * Drupal.org: https://drupal.org/node/2176627
 
- * Login Destination
 
+MAINTAINERS
+-----------
 
-Similar Modules
----------------
+Current maintainers:
+ * Ismaeil Abouljamal (izus) - https://www.drupal.org/user/514568
+ * Florent Torregrosa (Grimreaper) - https://www.drupal.org/user/2388214
 
- * Protected Pages
+Previous maintainers:
+ * Márk Tolmács (mtolmacs) - https://www.drupal.org/user/72361
+ * AlexisWilke (AlexisWilke) - https://www.drupal.org/user/356197
+ * Adam Thomason (adam_thomason) - https://www.drupal.org/user/2576960
+ * zilverdistel (zilverdistel) - https://www.drupal.org/user/276047
diff --git a/protected_node.api.php b/protected_node.api.php
new file mode 100644
index 0000000..13ae354
--- /dev/null
+++ b/protected_node.api.php
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * @file
+ * Hooks provided by the Protected node module.
+ */
+
+/**
+ * Removes information from the 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 it gets displayed or indexed.
+ *
+ * The default implementation hides the fields. It either replace the title with
+ * "Password protected page" or keeps it intact depending on the protected node
+ * "Show Title" flag.
+ *
+ * The hook is only invoked when the node is protected and the user did not yet
+ * provide the correct password.
+ *
+ * @see protected_node_protected_node_hide()
+ */
+function hook_protected_node_hide(&$node) {
+  // Core module fields.
+  if (!$node->protected_node_show_title) {
+    $node->title = t('Password protected page');
+  }
+  $node->body = '';
+  // Remove $node->content children to avoid the user see content he/she should
+  // not see.
+  $content_children = element_children($node->content);
+  foreach ($content_children as $content_key) {
+    unset($node->content[$content_key]);
+  }
+}
diff --git a/protected_node.module b/protected_node.module
index 93576a6..ce99369 100644
--- a/protected_node.module
+++ b/protected_node.module
@@ -1175,6 +1175,17 @@ function protected_node_set_protected($param, $passwd = NULL) {
 /**
  * This method marks the specified node as unprotected.
  *
+ * 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.
+ *
  * @param[in] int $nid  The node identifier.
  *
  * @return bool
-- 
2.1.4

