View source
<?php
function cacheexclude_menu($may_cache) {
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/cacheexclude',
'title' => t('Cache exclusions'),
'description' => t('Configure pages to exclude from caching.'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'cacheexclude_admin_settings',
),
'access' => user_access('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
}
return $items;
}
function cacheexclude_admin_settings() {
$form['cacheexclude_list'] = array(
'#type' => 'textarea',
'#title' => t('Pages to exclude from caching'),
'#default_value' => variable_get('cacheexclude_list', ''),
'#width' => 40,
'#height' => 10,
'#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>',
)),
);
return system_settings_form($form);
}
function cacheexclude_init() {
$pages = trim(variable_get('cacheexclude_list', ''));
if (strlen($pages) && drupal_match_path($_GET['q'], $pages)) {
$GLOBALS['conf']['cache'] = FALSE;
}
}
if (!function_exists('drupal_match_path')) {
function drupal_match_path($path, $patterns) {
static $regexps;
if ($path == variable_get('site_frontpage', 'node') && in_array('<front>', array_map('trim', explode("\n", $patterns)))) {
return true;
}
if (!isset($regexps[$patterns])) {
$regexps[$patterns] = '/^(' . preg_replace(array(
'/(\\r\\n?|\\n)/',
'/\\\\\\*/',
'/(^|\\|)\\\\<front\\\\>($|\\|)/',
), array(
'|',
'.*',
'\\1' . preg_quote(variable_get('site_frontpage', 'node'), '/') . '\\2',
), preg_quote($patterns, '/')) . ')$/';
}
return preg_match($regexps[$patterns], $path);
}
}