View source
<?php
require_once drupal_get_path('module', 'module_grants_monitor') . '/module_grants_monitor.pages.inc';
define('I_CREATED', '1');
define('I_LAST_MODIFIED', '2');
function module_grants_monitor_help($path, $arg) {
switch ($path) {
case 'admin/help#module_grants_monitor':
$s = t('For documentation see the <a href="@module_grants">Module Grants project page</a>', array(
'@module_grants' => url('http://drupal.org/project/module_grants'),
));
break;
case 'accessible-content/i-created':
case 'accessible-content/i-created/published':
case 'accessible-content/i-created/not-published':
$s = t('Showing all content <em>you created</em> and still have at least view access to, filtered by publication status.');
break;
case 'accessible-content/i-created/all':
$s = t('Showing all content <em>you created</em> and still have at least view access to.');
break;
case 'accessible-content/i-last-modified':
case 'accessible-content/i-last-modified/published':
case 'accessible-content/i-last-modified/not-published':
$s = t('Showing all content <em>you last modified</em> and still have at least view access to, filtered by publication status.');
break;
case 'accessible-content/i-last-modified/all':
$s = t('Showing all content <em>you last modified</em> and still have at least view access to.');
break;
case 'accessible-content/i-can-edit':
case 'accessible-content/i-can-edit/published':
case 'accessible-content/i-can-edit/not-published':
$s = t('Showing all content you can <em>edit</em>, filtered by publication status.');
break;
case 'accessible-content/i-can-edit/all':
$s = t('Showing all content you can <em>edit</em>.');
break;
case 'accessible-content/i-can-view':
case 'accessible-content/i-can-view/published':
case 'accessible-content/i-can-view/not-published':
$s = t('Showing all content you have at least <em>view</em> access to, filtered by publication status.');
break;
case 'accessible-content/i-can-view/all':
$s = t('Showing all content you have at least <em>view</em> access to.');
break;
}
return empty($s) ? '' : '<p>' . $s . '</p>';
}
function module_grants_monitor_perm() {
return array(
'access I Created tab',
'access I Last Modified tab',
'access I Can Edit tab',
'access I Can View tab',
'access Published tab',
'access Unpublished tab',
'access All tab',
);
}
function module_grants_monitor_theme() {
return array(
'module_grants_monitor_nodes_summary' => array(
'arguments' => array(
'nodes' => NULL,
),
),
);
}
function module_grants_monitor_menu() {
$items = array();
$items['accessible-content'] = array(
'title' => 'Accessible content',
'page callback' => '_module_grants_monitor_accessible_content_summary',
'page arguments' => array(),
'access callback' => 'user_tools_user_any_access',
'access arguments' => array(
module_grants_monitor_perm(),
),
'weight' => 2,
);
$items['accessible-content/i-created'] = array(
'title' => 'I created',
'page callback' => '_module_grants_monitor_accessible_content_summary',
'page arguments' => array(
'access I Created tab',
),
'access callback' => 'user_access',
'access arguments' => array(
'access I Created tab',
),
'type' => MENU_LOCAL_TASK,
'weight' => 0,
);
$items['accessible-content/i-created/published'] = array(
'title' => 'Published',
'page callback' => 'module_grants_monitor_accessible_content_summary',
'page arguments' => array(
'view',
'1',
I_CREATED,
),
'access callback' => 'user_tools_user_all_access',
'access arguments' => array(
array(
'access I Created tab',
'access Published tab',
),
),
'type' => MENU_LOCAL_TASK,
);
$items['accessible-content/i-created/not-published'] = array(
'title' => 'Unpublished',
'page callback' => 'module_grants_monitor_accessible_content_summary',
'page arguments' => array(
'view',
'0',
I_CREATED,
),
'access callback' => 'user_tools_user_all_access',
'access arguments' => array(
array(
'access I Created tab',
'access Unpublished tab',
),
),
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
$items['accessible-content/i-created/all'] = array(
'title' => 'All',
'page callback' => 'module_grants_monitor_accessible_content_summary',
'page arguments' => array(
'view',
'-1',
I_CREATED,
),
'access callback' => 'user_tools_user_all_access',
'access arguments' => array(
array(
'access I Created tab',
'access All tab',
),
),
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
$items['accessible-content/i-last-modified'] = array(
'title' => 'I last modified',
'page callback' => '_module_grants_monitor_accessible_content_summary',
'page arguments' => array(
'access I Last Modified tab',
),
'access callback' => 'user_access',
'access arguments' => array(
'access I Last Modified tab',
),
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
$items['accessible-content/i-last-modified/published'] = array(
'title' => 'Published',
'page callback' => 'module_grants_monitor_accessible_content_summary',
'page arguments' => array(
'view',
'1',
I_LAST_MODIFIED,
),
'access callback' => 'user_tools_user_all_access',
'access arguments' => array(
array(
'access I Last Modified tab',
'access Published tab',
),
),
'type' => MENU_LOCAL_TASK,
);
$items['accessible-content/i-last-modified/not-published'] = array(
'title' => 'Unpublished',
'page callback' => 'module_grants_monitor_accessible_content_summary',
'page arguments' => array(
'view',
'0',
I_LAST_MODIFIED,
),
'access callback' => 'user_tools_user_all_access',
'access arguments' => array(
array(
'access I Last Modified tab',
'access Unpublished tab',
),
),
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
$items['accessible-content/i-last-modified/all'] = array(
'title' => 'All',
'page callback' => 'module_grants_monitor_accessible_content_summary',
'page arguments' => array(
'view',
'-1',
I_LAST_MODIFIED,
),
'access callback' => 'user_tools_user_all_access',
'access arguments' => array(
array(
'access I Last Modified tab',
'access All tab',
),
),
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
$items['accessible-content/i-can-edit'] = array(
'title' => 'I can edit',
'page callback' => '_module_grants_monitor_accessible_content_summary',
'page arguments' => array(
'access I Can Edit tab',
),
'access callback' => 'user_access',
'access arguments' => array(
'access I Can Edit tab',
),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
);
$items['accessible-content/i-can-edit/published'] = array(
'title' => 'Published',
'page callback' => 'module_grants_monitor_accessible_content_summary',
'page arguments' => array(
'update',
'1',
),
'access callback' => 'user_tools_user_all_access',
'access arguments' => array(
array(
'access I Can Edit tab',
'access Published tab',
),
),
'type' => MENU_LOCAL_TASK,
);
$items['accessible-content/i-can-edit/not-published'] = array(
'title' => 'Unpublished',
'page callback' => 'module_grants_monitor_accessible_content_summary',
'page arguments' => array(
'update',
'0',
),
'access callback' => 'user_tools_user_all_access',
'access arguments' => array(
array(
'access I Can Edit tab',
'access Unpublished tab',
),
),
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
$items['accessible-content/i-can-edit/all'] = array(
'title' => 'All',
'page callback' => 'module_grants_monitor_accessible_content_summary',
'page arguments' => array(
'update',
'-1',
),
'access callback' => 'user_tools_user_all_access',
'access arguments' => array(
array(
'access I Can Edit tab',
'access All tab',
),
),
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
$items['accessible-content/i-can-view'] = array(
'title' => 'I can view',
'page callback' => '_module_grants_monitor_accessible_content_summary',
'page arguments' => array(
'access I Can View tab',
),
'access callback' => 'user_access',
'access arguments' => array(
'access I Can View tab',
),
'type' => MENU_LOCAL_TASK,
'weight' => 15,
);
$items['accessible-content/i-can-view/published'] = array(
'title' => 'Published',
'page callback' => 'module_grants_monitor_accessible_content_summary',
'page arguments' => array(
'view',
'1',
),
'access callback' => 'user_tools_user_all_access',
'access arguments' => array(
array(
'access I Can View tab',
'access Published tab',
),
),
'type' => MENU_LOCAL_TASK,
);
$items['accessible-content/i-can-view/not-published'] = array(
'title' => 'Unpublished',
'page callback' => 'module_grants_monitor_accessible_content_summary',
'page arguments' => array(
'view',
'0',
),
'access callback' => 'user_tools_user_all_access',
'access arguments' => array(
array(
'access I Can View tab',
'access Unpublished tab',
),
),
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
$items['accessible-content/i-can-view/all'] = array(
'title' => 'All',
'page callback' => 'module_grants_monitor_accessible_content_summary',
'page arguments' => array(
'view',
'-1',
),
'access callback' => 'user_tools_user_all_access',
'access arguments' => array(
array(
'access I Can View tab',
'access All tab',
),
),
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
return $items;
}
function _module_grants_monitor_accessible_content_summary($tab1 = NULL, $tab2 = NULL, $account = NULL) {
$permissions_tab_row1 = array_slice(module_grants_monitor_perm(), 0, 4);
$permissions_tab_row2 = module_exists('revisioning') ? array(
'access Pending tab',
) : array();
$permissions_tab_row2 = array_merge($permissions_tab_row2, array_slice(module_grants_monitor_perm(), 4));
if (!$tab1) {
$tab1 = user_tools_find_first_permission($permissions_tab_row1);
}
elseif (!user_access($tab1, $account)) {
unset($tab1);
}
if (!$tab2) {
$tab2 = user_tools_find_first_permission($permissions_tab_row2);
}
elseif (!user_access($tab2, $account)) {
unset($tab2);
}
if (!($tab1 && $tab2)) {
drupal_set_message(t('For you to see the list of Accessible content your administrator must give you permissions to one or more tabs of each of the two tab rows.'), 'warning');
return '';
}
$access = 'view';
$user_filter = NO_FILTER;
$published = NO_FILTER;
$is_moderated = NO_FILTER;
$is_pending = FALSE;
switch ($tab1) {
case 'access I Created tab':
$user_filter = I_CREATED;
break;
case 'access I Last Modified tab':
$user_filter = I_LAST_MODIFIED;
break;
case 'access I Can Edit tab':
$access = 'update';
break;
}
switch ($tab2) {
case 'access Published tab':
$published = TRUE;
break;
case 'access Unpublished tab':
$published = FALSE;
break;
case 'access Pending tab':
$is_moderated = user_access('administer nodes') ? NO_FILTER : TRUE;
$is_pending = TRUE;
break;
}
return module_grants_monitor_accessible_content_summary($access, $published, $user_filter, $is_moderated, $is_pending);
}