View source
<?php
define('CACHEFLUSH_UI_ENABLED', 1);
define('CACHEFLUSH_UI_MENU', 1);
function cacheflush_ui_menu() {
$items['cacheflush/%cacheflush'] = array(
'title' => 'View',
'page callback' => 'cacheflush_ui_entity_page_view',
'page arguments' => array(
1,
),
'access callback' => 'cacheflush_ui_access',
'access arguments' => array(
'view',
1,
),
'file' => 'includes/cacheflush_ui.forms.inc',
'file path' => drupal_get_path('module', 'cacheflush_ui'),
);
$items['cacheflush/%cacheflush/view'] = array(
'title' => 'View',
'page callback' => 'cacheflush_ui_entity_page_view',
'page arguments' => array(
1,
),
'access callback' => 'cacheflush_ui_access',
'access arguments' => array(
'view',
1,
),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
'file' => 'includes/cacheflush_ui.forms.inc',
'file path' => drupal_get_path('module', 'cacheflush_ui'),
);
$items['cacheflush/%cacheflush/edit'] = array(
'title' => 'Edit',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'cacheflush_form',
1,
),
'access callback' => 'cacheflush_ui_access',
'access arguments' => array(
'update',
1,
),
'type' => MENU_LOCAL_TASK,
'file' => 'includes/cacheflush_ui.forms.inc',
'file path' => drupal_get_path('module', 'cacheflush_ui'),
);
$items['cacheflush/%cacheflush/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'cacheflush_ui_delete_form',
1,
),
'access callback' => 'cacheflush_ui_access',
'access arguments' => array(
'delete',
1,
),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
'file' => 'includes/cacheflush_ui.forms.inc',
'file path' => drupal_get_path('module', 'cacheflush_ui'),
);
foreach (cacheflush_ui_get_menu_items() as $preset) {
$items["admin/cacheflush/clear/{$preset->id}"] = array(
'title' => $preset->title,
'description' => "Clear " . $preset->title . " cache.",
'page callback' => 'cacheflush_clear_preset_menu_callback',
'page arguments' => array(
3,
),
'access callback' => 'cacheflush_ui_access',
'access arguments' => array(
'clear',
$preset->id,
),
'weight' => $preset->id,
'file' => 'cacheflush.api.inc',
'file path' => drupal_get_path('module', 'cacheflush'),
);
}
return $items;
}
function cacheflush_ui_entity_info_alter(&$entity_info) {
$entity_info['cacheflush']['access callback'] = 'cacheflush_ui_access';
$entity_info['cacheflush']['view modes'] = array(
'full' => array(
'label' => t('Full'),
'custom settings' => FALSE,
),
);
$entity_info['cacheflush']['admin ui'] = array(
'path' => 'admin/structure/cacheflush',
'controller class' => 'CacheflushUIController',
);
}
function cacheflush_ui_admin_paths() {
$paths = array(
'cacheflush/*' => TRUE,
);
return $paths;
}
function cacheflush_ui_permission() {
return array(
'cacheflush administer' => array(
'title' => t('Administer cacheflush entity'),
'restrict access' => TRUE,
),
'cacheflush clear own' => array(
'title' => t('Clear own entity'),
'restrict access' => TRUE,
),
'cacheflush clear any' => array(
'title' => t('Clear any entity'),
'restrict access' => TRUE,
),
'cacheflush create new' => array(
'title' => t('Create new entity'),
'restrict access' => TRUE,
),
'cacheflush view own' => array(
'title' => t('View own entity'),
'restrict access' => TRUE,
),
'cacheflush view any' => array(
'title' => t('View any entity'),
'restrict access' => TRUE,
),
'cacheflush edit own' => array(
'title' => t('Edit own entity'),
'restrict access' => TRUE,
),
'cacheflush edit any' => array(
'title' => t('Edit any entity'),
'restrict access' => TRUE,
),
'cacheflush delete own' => array(
'title' => t('Delete own entity'),
'restrict access' => TRUE,
),
'cacheflush delete any' => array(
'title' => t('Delete any entity'),
'restrict access' => TRUE,
),
);
}
function cacheflush_ui_cacheflush_ui_operations() {
$operations = array(
'enable' => array(
'label' => t('Enable selected content'),
'callback' => 'cacheflush_ui_mass_update',
'callback arguments' => array(
'updates' => array(
'status' => 1,
),
),
),
'disable' => array(
'label' => t('Disable selected content'),
'callback' => 'cacheflush_ui_mass_update',
'callback arguments' => array(
'updates' => array(
'status' => 0,
),
),
),
'add_menu_entry' => array(
'label' => t('Add menu entry'),
'callback' => 'cacheflush_ui_mass_update',
'callback arguments' => array(
'updates' => array(
'menu' => 1,
),
),
),
'remove_menu_entry' => array(
'label' => t('Remove menu entry'),
'callback' => 'cacheflush_ui_mass_update',
'callback arguments' => array(
'updates' => array(
'menu' => 0,
),
),
),
'delete' => array(
'label' => t('Delete selected content'),
'callback' => NULL,
),
);
return $operations;
}
function cacheflush_ui_cacheflush_ui_tabs() {
$tabs = array(
'vertical_tabs_core' => array(
'name' => t('Core cache tables'),
'validation' => 'cacheflush_ui_tab_validation',
'weight' => -100,
),
'vertical_tabs_functions' => array(
'name' => t('Other core cache options'),
'validation' => 'cacheflush_ui_tab_validation',
'weight' => -90,
),
'vertical_tabs_custom' => array(
'name' => t('Contrib cache tables'),
'validation' => 'cacheflush_ui_tab_validation',
'weight' => -80,
),
'vertical_tabs_often' => array(
'name' => t('Other contrib cache options'),
'validation' => 'cacheflush_ui_tab_validation',
'weight' => -70,
),
);
return $tabs;
}
function cacheflush_ui_access($op, $entity, $account = NULL) {
global $user;
$rights =& drupal_static(__FUNCTION__, array());
if (empty($account)) {
$account = $user;
}
if ($account->uid == 1) {
return TRUE;
}
if (is_numeric($entity)) {
$entity = cacheflush_load($entity);
}
elseif (empty($entity)) {
$entity = new stdClass();
$entity->id = 0;
}
if (isset($rights[$account->uid][$entity->id][$op])) {
return $rights[$account->uid][$entity->id][$op];
}
switch ($op) {
case 'create':
$rights[$account->uid][$entity->id][$op] = user_access("cacheflush create new", $account);
break;
case 'clear':
$rights[$account->uid][$entity->id][$op] = cacheflush_ui_access_single_many('cacheflush clear any', 'cacheflush clear own', $account, $entity);
break;
case 'view':
$rights[$account->uid][$entity->id][$op] = cacheflush_ui_access_single_many('cacheflush view any', 'cacheflush view own', $account, $entity);
break;
case 'update':
$rights[$account->uid][$entity->id][$op] = cacheflush_ui_access_single_many('cacheflush edit any', 'cacheflush edit own', $account, $entity);
break;
case 'delete':
$rights[$account->uid][$entity->id][$op] = cacheflush_ui_access_single_many('cacheflush delete any', 'cacheflush delete own', $account, $entity);
break;
}
return $rights[$account->uid][$entity->id][$op];
}
function cacheflush_ui_access_single_many($any, $single, $account, $entity) {
if ($access = user_access($any, $account)) {
return TRUE;
}
else {
$access = user_access($single, $account);
if ($access && $account->uid == $entity->uid) {
return TRUE;
}
}
return FALSE;
}
function cacheflush_ui_entity_page_view($entity) {
return $entity
->view('full', NULL, TRUE);
}
function cacheflush_ui_get_path() {
$entity_info = entity_get_info('cacheflush');
return $entity_info['admin ui']['path'];
}
function cacheflush_ui_get_menu_items() {
return cacheflush_load_multiple(FALSE, array(
'status' => CACHEFLUSH_UI_ENABLED,
'menu' => CACHEFLUSH_UI_MENU,
));
}