t("Path: comparison"), 'description' => t('Control access by path match.'), 'callback' => 'ctools_path_ctools_access_check', 'settings form' => 'ctools_path_ctools_access_settings', 'summary' => 'ctools_path_ctools_access_summary', 'required context' => new ctools_context_required(t('String'), 'string'), 'defaults' => array('visibility' => '1', 'pages' => ''), ); /** * Settings form */ function ctools_path_ctools_access_settings(&$form, &$form_state, $conf) { $access = user_access('use PHP for block visibility'); $options = array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')); $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' => '')); if ($access) { $options[] = t('Show if the following PHP code returns TRUE (PHP-mode, experts only).'); $description .= ' '. t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '')); } $form['settings']['visibility'] = array( '#type' => 'radios', '#title' => t('Show block on specific pages'), '#options' => $options, '#default_value' => $conf['visibility'], ); $form['settings']['pages'] = array( '#type' => 'textarea', '#title' => t('Pages'), '#default_value' => $conf['pages'], '#description' => $description, ); } /** * Check for access */ function ctools_path_ctools_access_check($conf, $context) { if (empty($context) || empty($context->data)) { $path = ''; } else { $path = $context->data; } $pages = $conf['pages']; if ($pages) { if ($conf['visibility'] < 2) { $page_match = drupal_match_path($path, $pages); if ($path != $_GET['q']) { $page_match = $page_match || drupal_match_path($_GET['q'], $pages); } // When $conf['visibility'] has a value of 0, the panel is displayed on // all pages except those listed in $conf['pages']. When set to 1, it // is displayed only on those pages listed in $conf['visibility']. $page_match = !($conf['visibility'] xor $page_match); } else { $page_match = drupal_eval($pages); } } else { $page_match = TRUE; } return $page_match; } /** * Provide a summary description based upon the specified context */ function ctools_path_ctools_access_summary($conf, $context) { $values = array('@value' => $conf['pages']); switch ($conf['visibility']) { case '0': return t('All pages exept "@value"', $values); case '1': return t('Only on pages "@value"', $values); case '2': return t('PHP code return TRUE'); } }