| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: path_visibility.inc,v 1.1.2.1 2010/02/23 20:58:38 merlinofchaos Exp $ 3 4 /** 5 * @file 6 * Plugin to provide access control/visibility based on path. 7 */ 8 9 $plugin = array( 10 'title' => t('String: URL path'), 11 'description' => t('Control access by the current path.'), 12 'callback' => 'ctools_path_visibility_ctools_access_check', 13 'settings form' => 'ctools_path_visibility_ctools_access_settings', 14 'summary' => 'ctools_path_visibility_ctools_access_summary', 15 'required context' => new ctools_context_optional(t('Path'), 'string'), 16 'default' => array('visibility_setting' => 1, 'paths' => ''), 17 ); 18 19 /** 20 * Settings form 21 */ 22 function ctools_path_visibility_ctools_access_settings(&$form, &$form_state, $conf) { 23 $form['settings']['note'] = array( 24 '#value' => '<div class="description">' . t('Note: if no context is chosen, the current page path will be used.') . '</div>', 25 ); 26 27 $form['settings']['visibility_setting'] = array( 28 '#type' => 'radios', 29 '#options' => array( 30 1 => t('Allow access on the following pages'), 31 0 => t('Allow access on all pages except the following pages'), 32 ), 33 '#default_value' => $conf['visibility_setting'], 34 ); 35 36 $form['settings']['paths'] = array( 37 '#type' => 'textarea', 38 '#title' => t('Paths'), 39 '#default_value' => $conf['paths'], 40 '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')), 41 ); 42 } 43 44 /** 45 * Check for access. 46 */ 47 function ctools_path_visibility_ctools_access_check($conf, $context) { 48 if (isset($context->data)) { 49 $base_path = $context->data; 50 } 51 else { 52 $base_path = $_GET['q']; 53 } 54 55 $path = drupal_get_path_alias($base_path); 56 $page_match = drupal_match_path($path, $conf['paths']); 57 58 // If there's a path alias, we may still be at the un-aliased path 59 // so check that as well. 60 if (!isset($context->data) && $path != $base_path) { 61 $page_match = $page_match || drupal_match_path($base_path, $conf['paths']); 62 } 63 64 // When $conf['visibility_setting'] has a value of 0, the block is displayed 65 // on all pages except those listed in $block->pages. When set to 1, it 66 // is displayed only on those pages listed in $block->pages. 67 $page_match = !($conf['visibility_setting'] xor $page_match); 68 69 return $page_match; 70 } 71 72 /** 73 * Provide a summary description. 74 */ 75 function ctools_path_visibility_ctools_access_summary($conf, $context) { 76 $paths = array(); 77 foreach (explode("\n", $conf['paths']) as $path) { 78 $paths[] = check_plain($path); 79 } 80 81 $identifier = $context->type == 'any' ? t('Current path') : $context->identifier; 82 if ($conf['visibility_setting']) { 83 return format_plural(count($paths), '@identifier is "@paths"', '@identifier type is one of "@paths"', array('@paths' => implode(', ', $paths), '@identifier' => $identifier)); 84 } 85 else { 86 return format_plural(count($paths), '@identifier is not "@paths"', '@identifier type is not one of "@paths"', array('@paths' => implode(', ', $paths), '@identifier' => $identifier)); 87 } 88 }
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 |