View source
<?php
function cacheexclude_menu() {
$items['admin/settings/cacheexclude'] = array(
'title' => t('Cache exclusions'),
'description' => t('Configure pages to exclude from caching.'),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'cacheexclude_admin_settings',
),
'access arguments' => array(
'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. Don't begin link with trailing slash. 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>',
)),
);
$full_types = node_get_types();
foreach ($full_types as $type) {
$types[$type->type] = $type->name;
}
$form['cacheexclude_node_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Content types to exclude from caching'),
'#default_value' => variable_get('cacheexclude_node_types', array()),
'#options' => $types,
'#description' => t("Check all content types that you do not want to be cached."),
);
$full_form = system_settings_form($form);
$full_form['#submit'][] = 'cacheexclude_admin_settings_submit';
return $full_form;
}
function cacheexclude_admin_settings_submit() {
cache_clear_all(NULL, 'cache_page', '*');
}
function cacheexclude_init() {
$pages = trim(variable_get('cacheexclude_list', ''));
if (!$_GET['q']) {
drupal_init_path();
}
if (strlen($pages) && (drupal_match_path($_GET['q'], $pages) || drupal_match_path(drupal_get_path_alias($_GET['q']), $pages))) {
$GLOBALS['conf']['cache'] = 0;
return;
}
if ($node = menu_get_object('node')) {
$types = array_filter(variable_get('cacheexclude_node_types', array()));
if (in_array($node->type, $types)) {
$GLOBALS['conf']['cache'] = 0;
}
}
}