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

Diff of /contributions/modules/forum_access/forum_access.module

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

revision 1.49, Sun Sep 20 01:09:20 2009 UTC revision 1.50, Sun Oct 4 22:43:46 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: forum_access.module,v 1.48 2009/09/19 14:16:33 salvis Exp $  // $Id: forum_access.module,v 1.49 2009/09/20 01:09:20 salvis Exp $
3    
4  /**  /**
5   * @file forum_access.module   * @file forum_access.module
# Line 122  function forum_access_init() { Line 122  function forum_access_init() {
122      $node = node_load($nid);      $node = node_load($nid);
123      if ($tid = _forum_access_get_tid($node)) {      if ($tid = _forum_access_get_tid($node)) {
124        foreach ($access as $a) {        foreach ($access as $a) {
125          if (forum_access_access($tid, $a)) {          if ($level = forum_access_access($tid, $a)) {
126            module_load_include('node.inc', 'forum_access');            module_load_include('node.inc', 'forum_access');
127            $user->_forum_access_moderator = TRUE;            $user->_forum_access_moderator = $level;
128            if (arg(0) == 'comment' || arg(0) == 'node' && arg(2) == 'edit') {            if (arg(0) == 'comment' || arg(0) == 'node' && arg(2) == 'edit') {
129              _forum_access_enable_moderator();              _forum_access_enable_moderator();
130            }            }
# Line 367  function forum_access_disable() { Line 367  function forum_access_disable() {
367   * $tid -- the tid of the forum   * $tid -- the tid of the forum
368   * $type -- view, update, delete or create   * $type -- view, update, delete or create
369   * $account -- the account to test for. If NULL use current user.   * $account -- the account to test for. If NULL use current user.
370     *
371     * Return:
372     *   FALSE - access not granted
373     *   1     - access granted
374     *   2     - access granted for forum moderator
375     *   3     - user has 'administer nodes' (this occurs also when in
376     *           forum moderator mode!)
377   */   */
378  function forum_access_access($tid, $type, $account = NULL) {  function forum_access_access($tid, $type, $account = NULL) {
379    static $cache = array();    static $cache = array();
# Line 377  function forum_access_access($tid, $type Line 384  function forum_access_access($tid, $type
384    
385    if ($account->uid == 1 ||    if ($account->uid == 1 ||
386        user_access('administer nodes') && array_search($type, array('view', 'update', 'delete')) !== FALSE) {        user_access('administer nodes') && array_search($type, array('view', 'update', 'delete')) !== FALSE) {
387      return TRUE;      return 3;
388    }    }
389    
390    if (!isset($cache[$account->uid][$tid][$type])) {    if (!isset($cache[$account->uid][$tid][$type])) {
# Line 385  function forum_access_access($tid, $type Line 392  function forum_access_access($tid, $type
392      $result = db_result(db_query("SELECT tid FROM {forum_access} WHERE rid IN (%s) AND grant_%s = 1 AND tid = %d", $roles, $type, $tid));      $result = db_result(db_query("SELECT tid FROM {forum_access} WHERE rid IN (%s) AND grant_%s = 1 AND tid = %d", $roles, $type, $tid));
393    
394      if ($result) {      if ($result) {
395        $cache[$account->uid][$tid][$type] = TRUE;        $cache[$account->uid][$tid][$type] = 1;
396      }      }
397      else {      else {
398        // check our moderators too        // check our moderators too
399        $acl_id = db_result(db_query("SELECT acl_id from {acl} WHERE module = 'forum_access' AND name = '%d'", $tid));        $acl_id = db_result(db_query("SELECT acl_id from {acl} WHERE module = 'forum_access' AND name = '%d'", $tid));
400        $result = db_result(db_query("SELECT uid FROM {acl_user} WHERE acl_id = %d AND uid = %d", $acl_id, $account->uid));        $result = db_result(db_query("SELECT uid FROM {acl_user} WHERE acl_id = %d AND uid = %d", $acl_id, $account->uid));
401        if ($result) {        if ($result) {
402          $cache[$account->uid][$tid][$type] = TRUE;          $cache[$account->uid][$tid][$type] = 2;
403        }        }
404        else {        else {
405          $cache[$account->uid][$tid][$type] = FALSE;          $cache[$account->uid][$tid][$type] = FALSE;

Legend:
Removed from v.1.49  
changed lines
  Added in v.1.50

  ViewVC Help
Powered by ViewVC 1.1.2