views_cache_bully.module in Views cache bully 6.3
Same filename and directory in other branches
Module file for views_cache_bully.
File
views_cache_bully.moduleView source
<?php
/**
* @file
* Module file for views_cache_bully.
*/
/**
* Implements hook_menu().
*/
function views_cache_bully_menu() {
$items = array();
$items['admin/settings/views-cache-bully'] = array(
'title' => 'Views Cache Bully settings',
'description' => 'Configure Views Cache Bully settings',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'views_cache_bully_admin_form',
),
'access arguments' => array(
'administer views cache bully',
),
'file' => 'views_cache_bully.admin.inc',
);
return $items;
}
/**
* Implements hook_views_api().
*/
function views_cache_bully_views_api() {
return array(
'api' => 3,
);
}
/**
* Implements hook_perm().
*/
function views_cache_bully_perm() {
return array(
'administer views cache bully',
);
}
/**
* Implements hook_form_form_id_alter().
*/
function views_cache_bully_form_views_ui_admin_settings_advanced_alter(&$form, &$form_state) {
unset($form['cache']['clear_cache']);
unset($form['cache']['views_skip_cache']);
$form['cache']['views_cache_bully'] = array(
'#markup' => t('Views Cache Bully has disabled these settings.'),
);
}
/**
* Implements hook_form_form_id_alter().
*/
function views_cache_bully_form_views_ui_edit_display_form_alter(&$form, &$form_state) {
if (isset($form_state['section']) && $form_state['section'] == 'cache') {
$view = $form_state['view'];
if (!views_cache_bully_view_is_exempt($view)) {
$form['options']['cache']['type']['#options']['none'] = t('Time-based (from Views Cache Bully)');
}
else {
$form['options']['cache']['type']['#options']['none'] = t('None (exempt from Views Cache Bully)');
}
}
}
/**
* Implements hook_views_pre_build().
*/
function views_cache_bully_views_pre_build(&$view) {
if (version_compare(views_api_version(), '3', '>=')) {
$cache_plugin = $view->display_handler
->get_plugin('cache');
}
else {
$cache_plugin = $view->display_handler
->get_cache_plugin();
}
if (!empty($cache_plugin) && get_class($cache_plugin) == 'views_plugin_cache_none') {
if (!views_cache_bully_view_is_exempt($view)) {
$view->display_handler
->override_option('cache', array(
'type' => 'time',
'results_lifespan' => variable_get('views_cache_bully_results_lifespan', 3600),
'output_lifespan' => variable_get('views_cache_bully_output_lifespan', 3600),
));
}
}
}
/**
* Returns flat array of views cache bully exempt views.
*
* @param object $view
* An initialized view object.
*
* @return boolean
* TRUE if view should be exempted from bullying.
*/
function views_cache_bully_view_is_exempt($view) {
$exemptions = array_filter(variable_get('views_cache_bully_exemptions', array()));
// If administrative settings is enabled, exempt views with exposed filters.
if (variable_get('views_cache_bully_exempt_exposed', TRUE)) {
if (empty($view->inited)) {
watchdog('views_cache_bully', t('Error, Views Cache Bully could not evaluate view exemption for view @view_name, view was not initialized.', array(
'@view_name' => $view->name,
)));
}
elseif ($view->display[$view->current_display]->handler
->uses_exposed()) {
return TRUE;
}
}
// If view is in exemption list, return TRUE.
return in_array($view->name, $exemptions);
}
Functions
Name![]() |
Description |
---|---|
views_cache_bully_form_views_ui_admin_settings_advanced_alter | Implements hook_form_form_id_alter(). |
views_cache_bully_form_views_ui_edit_display_form_alter | Implements hook_form_form_id_alter(). |
views_cache_bully_menu | Implements hook_menu(). |
views_cache_bully_perm | Implements hook_perm(). |
views_cache_bully_views_api | Implements hook_views_api(). |
views_cache_bully_views_pre_build | Implements hook_views_pre_build(). |
views_cache_bully_view_is_exempt | Returns flat array of views cache bully exempt views. |