[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/ctools/plugins/access/ -> node_access.inc (source)

   1  <?php
   2  // $Id: node_access.inc,v 1.7.2.2 2009/11/13 00:44:16 merlinofchaos Exp $
   3  
   4  /**
   5   * @file
   6   * Plugin to provide access control based upon node type.
   7   */
   8  
   9  /**
  10   * Plugins are described by creating a $plugin array which will be used
  11   * by the system that includes this file.
  12   */
  13  $plugin = array(
  14    'title' => t("Node: accessible"),
  15    'description' => t('Control access with built in Drupal node access test.'),
  16    'callback' => 'ctools_node_access_ctools_access_check',
  17    'default' => array('type' => 'view'),
  18    'settings form' => 'ctools_node_access_ctools_access_settings',
  19    'settings form submit' => 'ctools_node_access_ctools_access_settings_submit',
  20    'summary' => 'ctools_node_access_ctools_access_summary',
  21    'required context' => array(
  22      new ctools_context_required(t('User'), 'user'),
  23      new ctools_context_required(t('Node'), 'node'),
  24    ),
  25  );
  26  
  27  /**
  28   * Settings form for the 'by node_access' access plugin
  29   */
  30  function ctools_node_access_ctools_access_settings(&$form, &$form_state, $conf) {
  31    $form['settings']['type'] = array(
  32      '#title' => t('Operation'),
  33      '#type' => 'radios',
  34      '#options' => array(
  35        'view' => t('View'),
  36        'update' => t('Update'),
  37        'delete' => t('Delete'),
  38        'create' => t('Create nodes of the same type'),
  39      ),
  40      '#description' => t('Using built in Drupal node access rules, determine if the user can perform the selected operation on the node.'),
  41      '#default_value' => $conf['type'],
  42    );
  43  }
  44  
  45  /**
  46   * Check for access.
  47   */
  48  function ctools_node_access_ctools_access_check($conf, $context) {
  49    // As far as I know there should always be a context at this point, but this
  50    // is safe.
  51    list($user_context, $node_context) = $context;
  52    if (empty($node_context) || empty($node_context->data) || empty($node_context->data->type)) {
  53      return FALSE;
  54    }
  55  
  56    if (empty($user_context) || empty($user_context->data)) {
  57      return FALSE;
  58    }
  59  
  60    if ($conf['type'] == 'create') {
  61      return node_access('create', $node_context->data->type, $user_context->data);
  62    }
  63    else {
  64      return node_access($conf['type'], $node_context->data, $user_context->data);
  65    }
  66  }
  67  
  68  /**
  69   * Provide a summary description based upon the checked node_accesss.
  70   */
  71  function ctools_node_access_ctools_access_summary($conf, $context) {
  72    list($user_context, $node_context) = $context;
  73    $replacement = array('@user' => $user_context->identifier, '@node' => $node_context->identifier);
  74  
  75    switch ($conf['type']) {
  76      case 'view':
  77        return t('@user can view @node.', $replacement);
  78  
  79      case 'update':
  80        return t('@user can edit @node.', $replacement);
  81  
  82      case 'delete':
  83        return t('@user can delete @node.', $replacement);
  84  
  85      case 'create':
  86        return t('@user can create nodes of the same type as @node.', $replacement);
  87    }
  88  }
  89  


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7