You are here

function protected_node_get_nids_from_protected_pages_parameter in Protected Node 7

Same name and namespace in other branches
  1. 1.0.x protected_node.fork.inc \protected_node_get_nids_from_protected_pages_parameter()

Helper function.

Transforms the $_GET['protected_pages'] in a valid list of $nids. Anything that is not valid we ignore. If there isn't at least 1 then the function generates an access denied error.

Return value

array The array of nids.

3 calls to protected_node_get_nids_from_protected_pages_parameter()
protected_node_enter_any_password in ./protected_node.fork.inc
Create the form asking the end users for the node password.
protected_node_enter_any_password_submit in ./protected_node.fork.inc
Submit callback.
protected_node_enter_any_password_validate in ./protected_node.fork.inc
Validate callback.

File

./protected_node.fork.inc, line 238
Redirected page callback file for the protected_node module.

Code

function protected_node_get_nids_from_protected_pages_parameter() {
  $nids = array();
  if (isset($_GET['protected_pages'])) {
    $nids_list = explode(',', $_GET['protected_pages']);
    foreach ($nids_list as $nid) {
      $nid = trim($nid);
      if (is_numeric($nid)) {
        $nids[] = $nid;
      }
    }

    // Make sure we have at least one destination otherwise there is no password
    // to check.
    if (count($nids) == 0) {

      // Illegal call.
      watchdog('protected_node', 'Illegal call to /protected-nodes: no nid specified.', array(), WATCHDOG_WARNING);
      drupal_access_denied();
    }
  }
  else {

    // Illegal call.
    watchdog('protected_node', 'Illegal call to /protected-nodes: no protected_pages parameter specified.', array(), WATCHDOG_WARNING);
    drupal_set_message(t("You need to enter nids in the protected_pages parameter i.e: protected-nodes?protected_pages=1,2,3"), 'error');
    drupal_access_denied();
  }
  return $nids;
}