| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: string_length.inc,v 1.1.2.2 2009/12/18 02:28:21 merlinofchaos Exp $ 3 4 /** 5 * @file 6 * Plugin to provide access control/visibility based on length of 7 * a string context. 8 */ 9 10 $plugin = array( 11 'title' => t("String: length"), 12 'description' => t('Control access by length of string context.'), 13 'callback' => 'ctools_string_length_ctools_access_check', 14 'settings form' => 'ctools_string_length_ctools_access_settings', 15 'summary' => 'ctools_string_length_ctools_access_summary', 16 'required context' => new ctools_context_required(t('String'), 'string'), 17 'defaults' => array('operator' => '=', 'length' => 0), 18 ); 19 20 /** 21 * Settings form for the 'by role' access plugin. 22 */ 23 function ctools_string_length_ctools_access_settings(&$form, &$form_state, $conf) { 24 $form['settings']['operator'] = array( 25 '#type' => 'radios', 26 '#title' => t('Operator'), 27 '#options' => array( 28 '>' => t('Greater than'), 29 '>=' => t('Greater than or equal to'), 30 '=' => t('Equal to'), 31 '!=' => t('Not equal to'), 32 '<' => t('Less than'), 33 '<=' => t('Less than or equal to'), 34 ), 35 '#default_value' => $conf['operator'], 36 ); 37 $form['settings']['length'] = array( 38 '#type' => 'textfield', 39 '#title' => t('Length of string'), 40 '#size' => 3, 41 '#default_value' => $conf['length'], 42 '#description' => t('Access/visibility will be granted based on string context length.'), 43 ); 44 } 45 46 /** 47 * Check for access. 48 */ 49 function ctools_string_length_ctools_access_check($conf, $context) { 50 if (empty($context) || empty($context->data)) { 51 $length = 0; 52 } 53 else { 54 $length = drupal_strlen($context->data); 55 } 56 57 switch($conf['operator']) { 58 case '<': 59 return $length < $conf['length']; 60 case '<=': 61 return $length <= $conf['length']; 62 case '==': 63 return $length == $conf['length']; 64 case '!=': 65 return $length != $conf['length']; 66 case '>': 67 return $length > $conf['length']; 68 case '>=': 69 return $length >= $conf['length']; 70 } 71 } 72 73 /** 74 * Provide a summary description based upon the checked roles. 75 */ 76 function ctools_string_length_ctools_access_summary($conf, $context) { 77 return t('@identifier must be @comp @length characters', array('@identifier' => $context->identifier, '@comp' => $conf['operator'], '@length' => $conf['length'])); 78 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |