You are here

function protected_node_requirements in Protected Node 6

Same name and namespace in other branches
  1. 5 protected_node.module \protected_node_requirements()

Implementation of hook_requirements().

Checks whether any role has access to protected nodes.

@link http://api.drupal.org/api/function/hook_requirements/6

Parameters

string $phase The current phase.:

File

./protected_node.install, line 16

Code

function protected_node_requirements($phase) {
  $reqs = array();
  if ($phase == 'runtime') {

    // test whether any roles were given rights to the handle protected nodes
    // Note: since this is the runtime phase we do not have to force a
    //       load of the .module file.
    $perms = protected_node_perm();
    $likes = array();
    foreach ($perms as $perm) {
      $likes[] = "perm LIKE '%%%s%%'";
    }
    $sql = "SELECT COUNT(rid) FROM {permission} WHERE " . implode(' OR ', $likes);
    $roles = db_result(db_query($sql, $perms));
    if ($roles) {
      $reqs['protected_node_rights'] = array(
        'title' => t('Protected nodes access rights'),
        'value' => format_plural($roles, 'One role has access to protected nodes. (!edit)', '@count roles have access to protected nodes. (!edit)', array(
          '!edit' => l('edit permissions', 'admin/user/permissions', array(
            'fragment' => 'module-protected_node',
          )),
        )),
        'severity' => REQUIREMENT_OK,
      );
    }
    else {
      $reqs['protected_node_rights'] = array(
        'title' => t('Protected nodes access rights'),
        'value' => t('None of the existing roles has !access', array(
          '!access' => l('permission to access protected nodes', 'admin/user/permissions', array(
            'fragment' => 'module-protected_node',
          )),
        )),
        'description' => t('Without giving access to at least one role, no-one other than the administrator (UID=1) can created protected nodes or view protected nodes'),
        'severity' => REQUIREMENT_ERROR,
      );
    }

    // File attachment are not currently protected
    switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
      case FILE_DOWNLOADS_PRIVATE:
        if (!module_exists('upload')) {
          $reqs['protected_node_attachments'] = array(
            'title' => t('Protected nodes attachments'),
            'value' => t('Private attachments protection cannot work without the !upload.', array(
              '!upload' => l('upload module', 'admin/build/modules', array(
                'fragment' => 'edit-status-upload',
              )),
            )),
            'description' => t('Please, install the upload module to protect private attachments with the node password.'),
            'severity' => REQUIREMENT_ERROR,
          );
        }
        else {
          $reqs['protected_node_attachments'] = array(
            'title' => t('Protected nodes attachments'),
            'value' => t('Private attachments are protected by Protected node'),
            'description' => t('Remember that your file are really protected only if uploaded as attachments. Other methods may make your files public and thus unprotectable.'),
            'severity' => REQUIREMENT_OK,
          );
        }
        break;
      default:
        $reqs['protected_node_attachments'] = array(
          'title' => t('Protected nodes attachments'),
          'value' => t('Public attachments are never protected by Protected node'),
          'description' => t('Public attachments are by definition public and the Protected node module cannot intervene since your web server answers those requests on its own without any interventions by Drupal. This obviously means there is no way we could prevent the download of a public file.'),
          'severity' => REQUIREMENT_WARNING,
        );
        break;
    }
  }
  return $reqs;
}