/[drupal]/contributions/modules/module_grants/module_grants.module
ViewVC logotype

Diff of /contributions/modules/module_grants/module_grants.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.17, Thu May 28 07:32:10 2009 UTC revision 1.18, Mon Jun 1 01:14:28 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: module_grants.module,v 1.10 2009/05/12 06:33:41 rdeboer Exp $  // $Id: module_grants.module,v 1.17 2009/05/28 07:32:10 rdeboer Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 11  Line 11 
11  require_once drupal_get_path('module', 'module_grants') .'/module_grants_theme.inc';  require_once drupal_get_path('module', 'module_grants') .'/module_grants_theme.inc';
12    
13  define('NO_FILTER', '-1');  define('NO_FILTER', '-1');
14    define('I_CREATED', '1');
15    define('I_LAST_MODIFIED', '2');
16    
17  /**  /**
18   * Implementation of hook_help().   * Implementation of hook_help().
19   */   */
20  function module_grants_help($path, $arg) {  function module_grants_help($path, $arg) {
21    switch ($path) {    switch ($path) {
22      case 'content-admin':      case 'accessible-content/i-created':
23        return '<p>'. t('This page shows all content that you have created and still have (at least) view access to, filtered by the tabs above. Note: access may depend on the state the content is in.') .'</p>';      case 'accessible-content/i-created/published':
24      case 'content-admin/accessible':      case 'accessible-content/i-created/not-published':
25        return '<p>'. t('This page shows all content that you have (at least) view access to, filtered by the tabs above. Note: access may depend on the state the content is in.') .'</p>';        $s = t('Showing all content that you have <em>created</em> and still have at least view access to, filtered by publication status.');
26    }        break;
27        case 'accessible-content': // default
28        case 'accessible-content/i-last-modified':
29        case 'accessible-content/i-last-modified/published':
30        case 'accessible-content/i-last-modified/not-published':
31          $s = t('Showing all content you <em>last modified</em> and to which you have at least view access, filtered by publication status.');
32          break;
33        case 'accessible-content':
34        case 'accessible-content/i-can-edit':
35        case 'accessible-content/i-can-edit/published':
36        case 'accessible-content/i-can-edit/not-published':
37          $s = t('Showing all content that you have <em>edit</em> access to, filtered by publication status.');
38          break;
39        case 'accessible-content/i-can-view':
40        case 'accessible-content/i-can-view/published':
41        case 'accessible-content/i-can-view/not-published':
42          $s = t('Showing all content that you have at least <em>view</em> access to, filtered by publication status.');
43          break;
44        }
45      return empty($s) ? '' : '<p>'. $s .'</p>';
46  }  }
47    
48  /**  /**
# Line 40  function module_grants_perm() { Line 61  function module_grants_perm() {
61  function module_grants_menu() {  function module_grants_menu() {
62    $items = array();    $items = array();
63    
64    // Create a 'View content' menu item in the Navigation menu (below    // Create an 'Acessible content' menu item in the navigation menu.
65    // 'Create content'). Add two tabs: 'I created', 'I can access')    // Add tabs: 'I created', 'I last modified', 'I can edit', 'I can view'.
66    $items['content-admin'] = array(    $items['accessible-content'] = array(
67      'title' => 'View content',      'title' => 'Accessible content',
68      'page callback' => 'show_accessible_content_summary',      'page callback' => 'show_accessible_content_summary',
69      'page arguments' => array('update', NO_FILTER, TRUE),      'page arguments' => array('view', '1', I_LAST_MODIFIED), // i-last-modified/published
70      'access arguments' => array('access content summary'),      'access arguments' => array('access content summary'),
71      'weight' => 3      'weight' => 2
72    );    );
73    
74    // 'I created' and sub tabs    // 'I created' and sub tabs
75    $items['content-admin/i-created'] = array(    $items['accessible-content/i-created'] = array(
76      'title' => 'I created',      'title' => 'I created',
77      'page callback' => 'show_accessible_content_summary',      'page callback' => 'show_accessible_content_summary',
78      'page arguments' => array('update', NO_FILTER, TRUE),      'page arguments' => array('view', '1', I_CREATED),
79      'access arguments' => array('access content summary'),      'access arguments' => array('access content summary'),
80      'type' => MENU_DEFAULT_LOCAL_TASK,      'type' => MENU_LOCAL_TASK,
81      'weight' => -10      'weight' => 0
82    );    );
83    $items['content-admin/i-created/editable'] = array(    $items['accessible-content/i-created/published'] = array(
84      'title' => 'Editable',      'title' => 'Published',
85      'page callback' => 'show_accessible_content_summary',      'page callback' => 'show_accessible_content_summary',
86      'page arguments' => array('update', NO_FILTER, TRUE),      'page arguments' => array('view', '1', I_CREATED),
87      'access arguments' => array('access content summary'),      'access arguments' => array('access content summary'),
88      'type' => MENU_DEFAULT_LOCAL_TASK,      'type' => MENU_DEFAULT_LOCAL_TASK,
89    );    );
90    $items['content-admin/i-created/not-published'] = array(    $items['accessible-content/i-created/not-published'] = array(
91      'title' => 'Not published',      'title' => 'Not published',
92      'page callback' => 'show_accessible_content_summary',      'page callback' => 'show_accessible_content_summary',
93      'page arguments' => array('view', '0', TRUE),      'page arguments' => array('view', '0', I_CREATED),
94      'access arguments' => array('access content summary'),      'access arguments' => array('access content summary'),
95      'type' => MENU_LOCAL_TASK,      'type' => MENU_LOCAL_TASK,
96    );    );
97    $items['content-admin/i-created/published'] = array(  
98      // 'I last modified' and sub tabs
99      $items['accessible-content/i-last-modified'] = array(
100        'title' => 'I last modified',
101        'page callback' => 'show_accessible_content_summary',
102        'page arguments' => array('view', '1', I_LAST_MODIFIED),
103        'access arguments' => array('access content summary'),
104        'type' => MENU_DEFAULT_LOCAL_TASK,
105        'weight' => 1
106      );
107      $items['accessible-content/i-last-modified/published'] = array(
108      'title' => 'Published',      'title' => 'Published',
109      'page callback' => 'show_accessible_content_summary',      'page callback' => 'show_accessible_content_summary',
110      'page arguments' => array('view', '1', TRUE),      'page arguments' => array('view', '1', I_LAST_MODIFIED),
111        'access arguments' => array('access content summary'),
112        'type' => MENU_DEFAULT_LOCAL_TASK,
113      );
114      $items['accessible-content/i-last-modified/not-published'] = array(
115        'title' => 'Not published',
116        'page callback' => 'show_accessible_content_summary',
117        'page arguments' => array('view', '0', I_LAST_MODIFIED),
118      'access arguments' => array('access content summary'),      'access arguments' => array('access content summary'),
119      'type' => MENU_LOCAL_TASK,      'type' => MENU_LOCAL_TASK,
120        'weight' => 1
121    );    );
122    
123    // 'I can access' and sub tabs    // 'I can edit' and sub tabs
124    $items['content-admin/accessible'] = array(    $items['accessible-content/i-can-edit'] = array(
125      'title' => 'I can access',      'title' => 'I can edit',
126      'page callback' => 'show_accessible_content_summary',      'page callback' => 'show_accessible_content_summary',
127      'page arguments' => array('update', NO_FILTER),      'page arguments' => array('update', '1'),
128      'access arguments' => array('access content summary'),      'access arguments' => array('access content summary'),
129      'type' => MENU_LOCAL_TASK,      'type' => MENU_LOCAL_TASK,
130        'weight' => 2
131    );    );
132    $items['content-admin/accessible/editable'] = array(    $items['accessible-content/i-can-edit/published'] = array(
133      'title' => 'Editable',      'title' => 'Published',
134      'page callback' => 'show_accessible_content_summary',      'page callback' => 'show_accessible_content_summary',
135      'page arguments' => array('update', NO_FILTER),      'page arguments' => array('update', '1'),
136      'access arguments' => array('access content summary'),      'access arguments' => array('access content summary'),
137      'type' => MENU_DEFAULT_LOCAL_TASK,      'type' => MENU_DEFAULT_LOCAL_TASK,
138    );    );
139    $items['content-admin/accessible/not-published'] = array(    $items['accessible-content/i-can-edit/not-published'] = array(
140      'title' => 'Not published',      'title' => 'Not published',
141      'page callback' => 'show_accessible_content_summary',      'page callback' => 'show_accessible_content_summary',
142      'page arguments' => array('view', '0'),      'page arguments' => array('update', '0'),
143      'access arguments' => array('access content summary'),      'access arguments' => array('access content summary'),
144      'type' => MENU_LOCAL_TASK,      'type' => MENU_LOCAL_TASK,
145        'weight' => 1
146    );    );
147    $items['content-admin/accessible/published'] = array(  
148      // 'I can view' and sub tabs
149      $items['accessible-content/i-can-view'] = array(
150        'title' => 'I can view',
151        'page callback' => 'show_accessible_content_summary',
152        'page arguments' => array('view', '1'),
153        'access arguments' => array('access content summary'),
154        'type' => MENU_LOCAL_TASK,
155        'weight' => 3
156      );
157      $items['accessible-content/i-can-view/published'] = array(
158      'title' => 'Published',      'title' => 'Published',
159      'page callback' => 'show_accessible_content_summary',      'page callback' => 'show_accessible_content_summary',
160      'page arguments' => array('view', '1'),      'page arguments' => array('view', '1'),
161      'access arguments' => array('access content summary'),      'access arguments' => array('access content summary'),
162        'type' => MENU_DEFAULT_LOCAL_TASK,
163      );
164      $items['accessible-content/i-can-view/not-published'] = array(
165        'title' => 'Not published',
166        'page callback' => 'show_accessible_content_summary',
167        'page arguments' => array('view', '0'),
168        'access arguments' => array('access content summary'),
169      'type' => MENU_LOCAL_TASK,      'type' => MENU_LOCAL_TASK,
170        'weight' => 1
171    );    );
172    
173    $items['admin/settings/module_grants'] = array(    $items['admin/settings/module_grants'] = array(
174      'title' => 'Module grants',      'title' => 'Module grants',
175      'description' =>  'Configure how multiple node access modules interact.',      'description' =>  'Configure how multiple node access modules interact.',
# Line 121  function module_grants_menu() { Line 181  function module_grants_menu() {
181  }  }
182    
183  /**  /**
184   * Return as a themed table a content summary of the site filtered by the   * Return as a themed table a content summary of the site filtered by the
185   * access rights of the logged-in user.   * access rights of the logged-in user.
186   *   *
187   * @param $access   * @param $access
188   *   one of 'view', 'update' or 'delete'   *   one of 'view', 'update' or 'delete'
189   * @param $published   * @param $published
190   *   1 for published-only, 0 for unpublished-only, -1 for both   *   1 for published-only, 0 for unpublished-only, -1 for both
191   * @param $created_by_user   * @param $user_filter
192   *   TRUE to filter by logged-in user   *   One of NO_FILTER, I_CREATED or I_LAST_MODIFIED
193   * @return   * @return
194   *   themed HTML   *   themed HTML
195   */   */
196  function show_accessible_content_summary($access = 'view', $published = -1, $created_by_user = FALSE) {  function show_accessible_content_summary($access = 'view', $published = -1, $user_filter = NO_FILTER) {
197    global $user;    global $user;
198    $nodes = get_nodes($access, (int)$published, $created_by_user ? $user->uid : -1);    $nodes = get_nodes($access, (int)$published, $user_filter == I_CREATED ? $user->uid : -1, $user_filter == I_LAST_MODIFIED ? $user->uid : -1);
199    return theme('nodes_summary', $nodes);    return theme('nodes_summary', $nodes);
200  }  }
201    
# Line 368  function grants_by_module($op, $account, Line 428  function grants_by_module($op, $account,
428   *  -1 (default) no filter, return content regardles of publication status   *  -1 (default) no filter, return content regardles of publication status
429   * @param $creator_uid   * @param $creator_uid
430   *   Only return content created by the user with the supplied id.   *   Only return content created by the user with the supplied id.
431   *   Defaults to -1, which means ignore creator   *   Defaults to -1, which means don't care who the creator is.
432     * @param $modifier_uid
433     *   Only return content last modified by the user with the supplied id.
434     *   Defaults to -1, which means don't care who last modifed the node.
435   * @param $pending   * @param $pending
436   *   Boolean indicating whether only nodes pending publication should be   *   Boolean indicating whether only nodes pending publication should be
437   *   returned; a pending node is defined as a node that has a revision newer   *   returned; a pending node is defined as a node that has a revision newer
438   *   than the current OR a single revision that is unpublished.   *   than the current OR a single revision that is not published.
439   * @param $order_by   * @param $order_by
440   *   name of node_revisions column to order by and direction code, defaults to   *   name of node_revisions column to order by and direction code, defaults to
441   *   'timestamp DESC'   *   'timestamp DESC'
442   * @param $max   * @param $max
443   *   Maximum number of nodes to be returned, defaults to 1000   *   Maximum number of nodes to be returned, defaults to 1000
444     * @param $show_message
445     *   Whether an informational message re publish permission should be shown
446   * @return   * @return
447   *   An array of node objects each containing nid, content type, published flag,   *   An array of node objects each containing nid, content type, published flag,
448   *   user id title+vid+user_id+timestamp of the current revision, plus taxonomy   *   user id title+vid+user_id+timestamp of the current revision, plus taxonomy
# Line 386  function grants_by_module($op, $account, Line 451  function grants_by_module($op, $account,
451   * @todo   * @todo
452   *   Allow paging, improve performance   *   Allow paging, improve performance
453   */   */
454  function get_nodes($op, $published = -1, $creator_uid = -1, $pending = FALSE, $order_by = 'timestamp DESC',  $max = 1000) {  function get_nodes($op, $published = -1, $creator_uid = -1, $modifier_uid = -1, $pending = FALSE, $order_by = 'timestamp DESC', $max = 1000, $show_message = TRUE) {
455  //drupal_set_message("op='$op', published='$published', creator_uid='$creator_uid', order_by='$order_by'", 'warning');  //drupal_set_message("op='$op', published='$published', creator=$creator_uid, modifier=$modifier_uid, pending='$pending', order_by='$order_by', max=$max, show_msg='$show_message'", 'warning');
456    $sql_select = 'SELECT n.nid, n.uid AS creator_uid, r.vid, n.type, n.status, r.title, r.uid, r.timestamp';    $sql_select = 'SELECT n.nid, r.vid, n.uid AS creator_uid, r.uid, n.type, n.status, r.title, r.timestamp';
457    $sql_from   = ' FROM {node} n INNER JOIN {node_revisions} r '. ($pending ? 'ON n.nid=r.nid' : 'ON n.vid=r.vid');    $sql_from   = ' FROM {node} n INNER JOIN {node_revisions} r '. ($pending ? 'ON n.nid=r.nid' : 'ON n.vid=r.vid');
458    $sql_where  = ($published < 0) ? '' : " WHERE n.status=$published";    $sql_where  = ($published < 0) ? '' : " WHERE n.status=$published";
459    if ($creator_uid >= 0) {    if ($creator_uid >= 0) {
460      $sql_where  = empty($sql_where) ? " WHERE n.uid=$creator_uid" : $sql_where ." AND n.uid=$creator_uid";      $sql_where  = empty($sql_where) ? " WHERE n.uid=$creator_uid" : $sql_where ." AND n.uid=$creator_uid";
461    }    }
462      if ($modifier_uid >= 0) {
463        $sql_where  = empty($sql_where) ? " WHERE r.uid=$modifier_uid" : $sql_where ." AND r.uid=$modifier_uid";
464      }
465    if ($pending) {    if ($pending) {
466      $sql_where  = empty($sql_where) ? ' WHERE' : $sql_where .' AND';      $sql_where  = empty($sql_where) ? ' WHERE' : $sql_where .' AND';
467      $sql_where .= ' (r.vid>n.vid OR (n.status=0 AND (SELECT COUNT(vid) FROM {node_revisions} WHERE nid=n.nid)=1))';      $sql_where .= ' (r.vid>n.vid OR (n.status=0 AND (SELECT COUNT(vid) FROM {node_revisions} WHERE nid=n.nid)=1))';
# Line 426  function get_nodes($op, $published = -1, Line 494  function get_nodes($op, $published = -1,
494        }        }
495      }      }
496    }    }
497      if ($show_message && !empty($nodes)) {
498        _set_info_message($published, $pending);
499      }
500    return $nodes;    return $nodes;
501  }  }
502    
503    function _set_info_message($published, $pending) {
504      if ($pending) {
505        if (user_access('administer nodes') || user_access('publish revisions')) {
506          drupal_set_message(t('You have permission to publish this content.'));
507        }
508        else {
509          drupal_set_message(t('You cannot publish any of this content, but a moderator can.'), 'warning');
510        }
511      }
512      elseif ($published != FALSE && (user_access('administer nodes') || user_access('unpublish current revision'))) {
513        drupal_set_message(t('You have permission to <em>unpublish</em> this content.'));
514      }
515      elseif ((user_access('administer nodes') || user_access('publish revisions'))) {
516        drupal_set_message(t('You have permission to <em>republish</em> this content.'));
517      }
518    }

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

  ViewVC Help
Powered by ViewVC 1.1.2