| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: role.inc,v 1.7.2.3 2010/07/14 01:30:19 merlinofchaos Exp $ 3 4 /** 5 * @file 6 * Plugin to provide access control based upon role membership. 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("User: role"), 15 'description' => t('Control access by role.'), 16 'callback' => 'ctools_role_ctools_access_check', 17 'default' => array('rids' => array()), 18 'settings form' => 'ctools_role_ctools_access_settings', 19 'settings form submit' => 'ctools_role_ctools_access_settings_submit', 20 'summary' => 'ctools_role_ctools_access_summary', 21 'required context' => new ctools_context_required(t('User'), 'user'), 22 ); 23 24 /** 25 * Settings form for the 'by role' access plugin 26 */ 27 function ctools_role_ctools_access_settings(&$form, &$form_state, $conf) { 28 $form['settings']['rids'] = array( 29 '#type' => 'checkboxes', 30 '#title' => t('Role'), 31 '#default_value' => $conf['rids'], 32 '#options' => ctools_get_roles(), 33 '#description' => t('Only the checked roles will be granted access.'), 34 ); 35 } 36 37 /** 38 * Compress the roles allowed to the minimum. 39 */ 40 function ctools_role_ctools_access_settings_submit(&$form, &$form_state) { 41 $form_state['values']['settings']['rids'] = array_keys(array_filter($form_state['values']['settings']['rids'])); 42 } 43 44 /** 45 * Check for access. 46 */ 47 function ctools_role_ctools_access_check($conf, $context) { 48 // As far as I know there should always be a context at this point, but this 49 // is safe. 50 if (empty($context) || empty($context->data) || !isset($context->data->roles)) { 51 return FALSE; 52 } 53 54 $roles = array_keys($context->data->roles); 55 $roles[] = $context->data->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID; 56 return (bool) array_intersect($conf['rids'], $roles); 57 } 58 59 /** 60 * Provide a summary description based upon the checked roles. 61 */ 62 function ctools_role_ctools_access_summary($conf, $context) { 63 if (!isset($conf['rids'])) { 64 $conf['rids'] = array(); 65 } 66 $roles = ctools_get_roles(); 67 68 $names = array(); 69 foreach (array_filter($conf['rids']) as $rid) { 70 $names[] = check_plain($roles[$rid]); 71 } 72 73 if (empty($names)) { 74 return t('@identifier can have any role', array('@identifier' => $context->identifier)); 75 } 76 77 return format_plural(count($names), '@identifier has role "@roles"', '@identifier has one of "@roles"', array('@roles' => implode(', ', $names), '@identifier' => $context->identifier)); 78 } 79
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |