source: sipes/modules_contrib/module_grants/module_grants_monitor/module_grants_monitor.module @ de78188

stableversion-3.0
Last change on this file since de78188 was 177a560, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el directorio de modulos contribuidos de drupal

  • Propiedad mode establecida a 100644
File size: 13.8 KB
Línea 
1<?php
2
3/**
4 * @file
5 * Accessible content monitor. Creates an 'Accessible content' link in the
6 * navigation menu to display a summary of all content accessible to the
7 * logged-in user as determined by the enabled content access modules.
8 */
9require_once drupal_get_path('module', 'module_grants_monitor') .'/module_grants_monitor.pages.inc';
10
11define('I_CREATED', '1');
12define('I_LAST_MODIFIED', '2');
13
14/**
15 * Implementation of hook_help().
16 */
17function module_grants_monitor_help($path, $arg) {
18  switch ($path) {
19    case 'admin/help#module_grants_monitor':
20      $s = t('For documentation see the <a href="@module_grants">Module Grants project page</a>',
21        array('@module_grants' => url('http://drupal.org/project/module_grants')));
22      break;
23
24    case 'accessible-content/i-created':
25    case 'accessible-content/i-created/published':
26    case 'accessible-content/i-created/not-published':
27      $s = t('Showing all content <em>you created</em> and still have at least view access to, filtered by publication status.');
28      break;
29    case 'accessible-content/i-created/all':
30      $s = t('Showing all content <em>you created</em> and still have at least view access to.');
31      break;
32    case 'accessible-content/i-last-modified':
33    case 'accessible-content/i-last-modified/published':
34    case 'accessible-content/i-last-modified/not-published':
35      $s = t('Showing all content <em>you last modified</em> and still have at least view access to, filtered by publication status.');
36      break;
37    case 'accessible-content/i-last-modified/all':
38      $s = t('Showing all content <em>you last modified</em> and still have at least view access to.');
39      break;
40    case 'accessible-content/i-can-edit':
41    case 'accessible-content/i-can-edit/published':
42    case 'accessible-content/i-can-edit/not-published':
43      $s = t('Showing all content you can <em>edit</em>, filtered by publication status.');
44      break;
45    case 'accessible-content/i-can-edit/all':
46      $s = t('Showing all content you can <em>edit</em>.');
47      break;
48    case 'accessible-content/i-can-view':
49    case 'accessible-content/i-can-view/published':
50    case 'accessible-content/i-can-view/not-published':
51      $s = t('Showing all content you have at least <em>view</em> access to, filtered by publication status.');
52      break;
53    case 'accessible-content/i-can-view/all':
54      $s = t('Showing all content you have at least <em>view</em> access to.');
55      break;
56  }
57  return empty($s) ? '' : '<p>'. $s .'</p>';
58}
59
60/**
61 * Implementation of hook_perm().
62 *
63 * The order of the permissions is relevant to the dynamic allocation of
64 * suitable default tab selections.
65 */
66function module_grants_monitor_perm() {
67  return array(
68    // tab row 1:
69    'access I Created tab', 'access I Last Modified tab', 'access I Can Edit tab', 'access I Can View tab',
70    // tab row 2:
71    'access Published tab', 'access Unpublished tab', 'access All tab');
72}
73
74/**
75 * Implementation of hook_theme().
76 *
77 * Register the theme_hooks() available in this module, with their arguments
78 * and default values.
79 */
80function module_grants_monitor_theme() {
81  return array(
82    'module_grants_monitor_nodes_summary' => array(
83        // to call theme_module_grants_monitor_nodes_summary($nodes)
84       'arguments' => array('nodes' => NULL)
85    )
86  );
87}
88
89/**
90 * Implementation of hook_menu().
91 *
92 * Define new menu items and local tasks (tabs).
93 * Existing menu items are modified through hook_menu_alter().
94 */
95function module_grants_monitor_menu() {
96  $items = array();
97
98  // Create an 'Acessible content' menu item in the navigation menu.
99  // Add tabs: 'I created', 'I last modified', 'I can edit', 'I can view', each
100  // with sub tabs 'Published', 'Unpublished', 'All'
101
102  // There's an issue w.r.t assigning default tab selections for the
103  // 'Accessible content' menu item. Core insists that each row of tabs has
104  // exactly one tab defined with type=MENU_DEFAULT_LOCAL_TASK, the other tabs
105  // having type=MENU_LOCAL_TASK.
106  // The default we set needs to be part of the subset of tabs that the user
107  // is permitted to see. The problem is that the user permissions are evaluated
108  // when the menu and its tabs are about to be rendered (in menu.inc,
109  // function theme_menu_local_tasks()), whereas the type must be defined
110  // upfront when the menu structure is created, i.e. in the lines below.
111  // The way we get around this problem is to first load the page with content
112  // according to the user permissions, by calling this module's function
113  // _module_grants_monitor_accessible_content_summary(). Then we take advantage
114  // of the Smart menus module, which overrides theme_menu_local_tasks(), to
115  // highlight as 'current' the tabs matching the content shown.
116
117  $items['accessible-content'] = array(
118    'title' => 'Accessible content',
119    'page callback' => '_module_grants_monitor_accessible_content_summary',
120    'page arguments' => array(), // tabs default based on user permissions
121    'access callback' => 'user_tools_user_any_access',
122    'access arguments' => array(module_grants_monitor_perm()),
123    'weight' => 2
124  );
125
126  // 'I created' and sub tabs
127  $items['accessible-content/i-created'] = array(
128    'title' => 'I created',
129    'page callback' => '_module_grants_monitor_accessible_content_summary',
130    'page arguments' => array('access I Created tab'), // 2nd tab defaults
131    'access callback' => 'user_access',
132    'access arguments' => array('access I Created tab'),
133    'type' => MENU_LOCAL_TASK,
134    'weight' => 0
135  );
136  $items['accessible-content/i-created/published'] = array(
137    'title' => 'Published',
138    'page callback' => 'module_grants_monitor_accessible_content_summary', // both tabs known
139    'page arguments' => array('view', '1', I_CREATED),
140    'access callback' => 'user_tools_user_all_access',
141    'access arguments' => array(array('access I Created tab', 'access Published tab')),
142    'type' => MENU_LOCAL_TASK,
143  );
144  $items['accessible-content/i-created/not-published'] = array(
145    'title' => 'Unpublished',
146    'page callback' => 'module_grants_monitor_accessible_content_summary', // both tabs known
147    'page arguments' => array('view', '0', I_CREATED),
148    'access callback' => 'user_tools_user_all_access',
149    'access arguments' => array(array('access I Created tab', 'access Unpublished tab')),
150    'type' => MENU_LOCAL_TASK,
151    'weight' => 1
152  );
153  $items['accessible-content/i-created/all'] = array(
154    'title' => 'All',
155    'page callback' => 'module_grants_monitor_accessible_content_summary', // both tabs known
156    'page arguments' => array('view', '-1', I_CREATED),
157    'access callback' => 'user_tools_user_all_access',
158    'access arguments' => array(array('access I Created tab', 'access All tab')),
159    'type' => MENU_LOCAL_TASK,
160    'weight' => 5
161  );
162
163  // 'I last modified' and sub tabs
164  $items['accessible-content/i-last-modified'] = array(
165    'title' => 'I last modified',
166    'page callback' => '_module_grants_monitor_accessible_content_summary', // 2nd tab defaults
167    'page arguments' => array('access I Last Modified tab'),
168    'access callback' => 'user_access',
169    'access arguments' => array('access I Last Modified tab'),
170    'type' => MENU_LOCAL_TASK,
171    'weight' => 5
172  );
173  $items['accessible-content/i-last-modified/published'] = array(
174    'title' => 'Published',
175    'page callback' => 'module_grants_monitor_accessible_content_summary', // both tabs known
176    'page arguments' => array('view', '1', I_LAST_MODIFIED),
177    'access callback' => 'user_tools_user_all_access',
178    'access arguments' => array(array('access I Last Modified tab', 'access Published tab')),
179    'type' => MENU_LOCAL_TASK,
180  );
181  $items['accessible-content/i-last-modified/not-published'] = array(
182    'title' => 'Unpublished',
183    'page callback' => 'module_grants_monitor_accessible_content_summary', // both tabs known
184    'page arguments' => array('view', '0', I_LAST_MODIFIED),
185    'access callback' => 'user_tools_user_all_access',
186    'access arguments' => array(array('access I Last Modified tab', 'access Unpublished tab')),
187    'type' => MENU_LOCAL_TASK,
188    'weight' => 1
189  );
190  $items['accessible-content/i-last-modified/all'] = array(
191    'title' => 'All',
192    'page callback' => 'module_grants_monitor_accessible_content_summary', // both tabs known
193    'page arguments' => array('view', '-1', I_LAST_MODIFIED),
194    'access callback' => 'user_tools_user_all_access',
195    'access arguments' => array(array('access I Last Modified tab', 'access All tab')),
196    'type' => MENU_LOCAL_TASK,
197    'weight' => 5
198  );
199
200  // 'I can edit' and sub tabs
201  $items['accessible-content/i-can-edit'] = array(
202    'title' => 'I can edit',
203    'page callback' => '_module_grants_monitor_accessible_content_summary', // 2nd tab defaults
204    'page arguments' => array('access I Can Edit tab'),
205    'access callback' => 'user_access',
206    'access arguments' => array('access I Can Edit tab'),
207    'type' => MENU_LOCAL_TASK,
208    'weight' => 10
209  );
210  $items['accessible-content/i-can-edit/published'] = array(
211    'title' => 'Published',
212    'page callback' => 'module_grants_monitor_accessible_content_summary', // both tabs known
213    'page arguments' => array('update', '1'),
214    'access callback' => 'user_tools_user_all_access',
215    'access arguments' => array(array('access I Can Edit tab', 'access Published tab')),
216    'type' => MENU_LOCAL_TASK,
217  );
218  $items['accessible-content/i-can-edit/not-published'] = array(
219    'title' => 'Unpublished',
220    'page callback' => 'module_grants_monitor_accessible_content_summary', // both tabs known
221    'page arguments' => array('update', '0'),
222    'access callback' => 'user_tools_user_all_access',
223    'access arguments' => array(array('access I Can Edit tab', 'access Unpublished tab')),
224    'type' => MENU_LOCAL_TASK,
225    'weight' => 1
226  );
227  $items['accessible-content/i-can-edit/all'] = array(
228    'title' => 'All',
229    'page callback' => 'module_grants_monitor_accessible_content_summary', // both tabs known
230    'page arguments' => array('update', '-1'),
231    'access callback' => 'user_tools_user_all_access',
232    'access arguments' => array(array('access I Can Edit tab', 'access All tab')),
233    'type' => MENU_LOCAL_TASK,
234    'weight' => 5
235  );
236
237  // 'I can view' and sub tabs
238  $items['accessible-content/i-can-view'] = array(
239    'title' => 'I can view',
240    'page callback' => '_module_grants_monitor_accessible_content_summary', // 2nd tab defaults
241    'page arguments' => array('access I Can View tab'),
242    'access callback' => 'user_access',
243    'access arguments' => array('access I Can View tab'),
244    'type' => MENU_LOCAL_TASK,
245    'weight' => 15
246  );
247  $items['accessible-content/i-can-view/published'] = array(
248    'title' => 'Published',
249    'page callback' => 'module_grants_monitor_accessible_content_summary',  // both tabs known
250    'page arguments' => array('view', '1'),
251    'access callback' => 'user_tools_user_all_access',
252    'access arguments' => array(array('access I Can View tab', 'access Published tab')),
253    'type' => MENU_LOCAL_TASK,
254  );
255  $items['accessible-content/i-can-view/not-published'] = array(
256    'title' => 'Unpublished',
257    'page callback' => 'module_grants_monitor_accessible_content_summary', // both tabs known
258    'page arguments' => array('view', '0'),
259    'access callback' => 'user_tools_user_all_access',
260    'access arguments' => array(array('access I Can View tab', 'access Unpublished tab')),
261    'type' => MENU_LOCAL_TASK,
262    'weight' => 1
263  );
264  $items['accessible-content/i-can-view/all'] = array(
265    'title' => 'All',
266    'page callback' => 'module_grants_monitor_accessible_content_summary', // both tabs known
267    'page arguments' => array('view', '-1'),
268    'access callback' => 'user_tools_user_all_access',
269    'access arguments' => array(array('access I Can View tab', 'access All tab')),
270    'type' => MENU_LOCAL_TASK,
271    'weight' => 5
272  );
273
274  return $items;
275}
276
277/**
278 * Similar to module_grants_monitor_accessible_content_summary (which it calls)
279 * but with a different parameter list based on the (lack of) default tabs, as
280 * opposed to content properties.
281 *
282 * @param $tab1
283 * @param $tab2
284 * @param $account
285 * @return unknown_type
286 */
287function _module_grants_monitor_accessible_content_summary($tab1 = NULL, $tab2 = NULL, $account = NULL) {
288  // First 4 Module Grants Monitor permissions pertain to 1st row of tabs
289  $permissions_tab_row1 = array_slice(module_grants_monitor_perm(), 0, 4);
290  // 2nd row has Revisioning perm followed by remaining Module Grants Monitor perms
291  $permissions_tab_row2 = module_exists('revisioning') ? array('access Pending tab') : array();
292  $permissions_tab_row2 = array_merge($permissions_tab_row2, array_slice(module_grants_monitor_perm(), 4));
293
294  if (!$tab1) {
295    $tab1 = user_tools_find_first_permission($permissions_tab_row1);
296  }
297  elseif (!user_access($tab1, $account)) {
298    unset($tab1);
299  }
300  if (!$tab2) {
301    $tab2 = user_tools_find_first_permission($permissions_tab_row2);
302  }
303  elseif (!user_access($tab2, $account)) {
304    unset($tab2);
305  }
306  if (!($tab1 && $tab2)) {
307    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');
308    return '';
309  }
310  $access = 'view';
311  $user_filter = NO_FILTER;
312  $published = NO_FILTER;
313  $is_moderated = NO_FILTER;
314  $is_pending = FALSE;
315  switch ($tab1) {
316    case 'access I Created tab':
317      $user_filter = I_CREATED;
318      break;
319    case 'access I Last Modified tab':
320      $user_filter = I_LAST_MODIFIED;
321      break;
322    case 'access I Can Edit tab':
323      $access = 'update';
324      break;
325  }
326  switch ($tab2) {
327    case 'access Published tab':
328      $published = TRUE;
329      break;
330    case 'access Unpublished tab':
331      $published = FALSE;
332      break;
333    case 'access Pending tab':
334      $is_moderated = user_access('administer nodes') ? NO_FILTER : TRUE;
335      $is_pending = TRUE;
336      break;
337  }
338  return module_grants_monitor_accessible_content_summary($access, $published, $user_filter, $is_moderated, $is_pending);
339}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.