Projet

Général

Profil

Révision e9734207

Ajouté par Assos Assos il y a plus de 4 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/forum_access/forum_access.module
26 26
      $info = drupal_parse_info_file($path);
27 27
      $version = (isset($info['version']) ? $info['version'] : $t('Unknown'));
28 28
      $found = preg_match('/7\.x-([0-9]*)\./', $version, $matches);
29
      if ($found && $matches[1] == 1 || !$found) {
29
      if (($found && $matches[1] == 1) || !$found) {
30 30
        $cma = 'Chain Menu Access API';
31 31
        $variables = array('@Chain_Menu_Access_API' => $cma, '@module' => url('admin/modules'));
32 32
        $result[] = array(
......
115 115
      return FALSE;
116 116
    }
117 117
  }
118
  elseif (is_string($comment)) {
119
    return FALSE;
120
  }
118 121
  $node = node_load($comment->nid);
119 122

  
120 123
  // The remaining $ops are governed by OR, return FALSE by default.
......
283 286
  }
284 287
}
285 288

  
289
/**
290
 * Implements hook_form_node_form_alter().
291
 *
292
 * Allows the forum field to be optional on non-forum nodes.
293
 */
294
function forum_access_form_node_form_alter(&$form, &$form_state, $form_id) {
295
  if (isset($form['taxonomy_forums'])) {
296
    $field = field_info_instance('node', 'taxonomy_forums', $form['type']['#value']);
297
    // Make the vocabulary required for 'real' forum-nodes.
298
    if (!$field['required']) {
299
      $langcode = $form['taxonomy_forums']['#language'];
300
      $form['taxonomy_forums'][$langcode]['#required'] = FALSE;
301
    }
302
  }
303
}
304

  
305
/**
306
 * Implement hook_node_load().
307
 *
308
 * Sets $node->forum_tid to avoid confusing forum_node_view().
309
 */
310
function forum_access_node_load($nodes, $types) {
311
  foreach ($nodes as $node) {
312
    if (isset($node->taxonomy_forums) && empty($node->taxonomy_forums) && !isset($node->forum_tid)) {
313
      $node->forum_tid = NULL;
314
    }
315
  }
316
}
317

  
286 318
/**
287 319
 * Implements hook_comment_load().
288 320
 */
......
299 331
  return;
300 332
}
301 333

  
334
/**
335
 * Implements hook_query_term_access_alter().
336
 *
337
 * @param QueryAlterableInterface $query
338
 */
302 339
function forum_access_query_term_access_alter(QueryAlterableInterface $query) {
303 340
  global $user;
304 341

  
......
310 347
    $op = 'view';
311 348
  }
312 349

  
313
  // If $account can bypass node access, or there are no node access
314
  // modules, we don't need to alter the query.
315
  if (user_access('bypass node access', $account)) {
350
  // If $account can bypass node access, we let them administer the full forum
351
  // structure and see the nodes, i.e. we don't restrict the query.
352
  if (user_access('bypass node access', $account) && (strpos(current_path(), 'admin/structure/forum') === 0 || strpos(current_path(), 'node/') === 0)) {
316 353
    return;
317 354
  }
318 355

  
......
331 368
      // The node_access table has the access grants for any given node.
332 369
      $access_alias = $query->leftJoin('forum_access', 'fa', '%alias.tid = ' . $talias . '.tid');
333 370
      $acl_alias = $query->leftJoin('acl', 'acl', "%alias.number = $talias.tid AND %alias.module = 'forum_access'");
334
      $aclu_alias = $query->leftJoin('acl_user', 'aclu', "%alias.acl_id = $acl_alias.acl_id AND %alias.uid = $account->uid");
335
      $query->condition(db_or()
336
        ->isNull("$access_alias.rid")
337
        ->condition(db_and()
338
          ->condition("$access_alias.rid", $rids, 'IN')
339
          ->condition("$access_alias.grant_$op", 1, '>='))
340
        ->condition("$aclu_alias.uid", $account->uid));
371
      if (user_access('bypass node access', $account)) {
372
        // If $account can bypass node access, we allow access if any role or
373
        // account has access.
374
        $aclu_alias = $query->leftJoin('acl_user', 'aclu', "%alias.acl_id = $acl_alias.acl_id");
375
        $query->condition(db_or()
376
          ->isNull("$access_alias.rid")
377
          ->condition("$access_alias.grant_$op", 1, '>=')
378
          ->isNotNull("$aclu_alias.uid")
379
        );
380
      }
381
      else {
382
        $aclu_alias = $query->leftJoin('acl_user', 'aclu', "%alias.acl_id = $acl_alias.acl_id AND %alias.uid = $account->uid");
383
        $query->condition(db_or()
384
          ->isNull("$access_alias.rid")
385
          ->condition(db_and()
386
            ->condition("$access_alias.rid", $rids, 'IN')
387
            ->condition("$access_alias.grant_$op", 1, '>='))
388
          ->condition("$aclu_alias.uid", $account->uid));
389
      }
341 390
    }
342 391
  }
343 392
}
......
348 397
function forum_access_node_presave($node, $return_old_tid = FALSE) {
349 398
  $old_tid = &drupal_static('forum_access_node_presave');
350 399
  if (_forum_node_check_node_type($node)) {
351
    $old_tid = db_query('SELECT tid FROM {forum} WHERE nid = :nid', array(
352
      ':nid' => $node->nid,
353
    ))->fetchField();
400
    if (empty($node->nid)) {
401
      // Added for migrations, which log errors due to no nid during presave, see #3003279.
402
      $old_tid = NULL;
403
    }
404
    else {
405
      $old_tid = db_query('SELECT tid FROM {forum} WHERE nid = :nid', array(
406
        ':nid' => $node->nid,
407
      ))->fetchField();
408
    }
409
  }
410
  if (!empty($old_tid) && empty($node->taxonomy_forums['und'])) {
411
    $node->forum_tid = null;
354 412
  }
355 413
}
356 414

  
......
423 481
function forum_access_enable_moderator($enable = TRUE) {
424 482
  global $user;
425 483

  
426
  if (!$enable || $enable && !user_access('administer comments')) {
484
  if (!$enable || !user_access('administer comments')) {
427 485
    $perm = &drupal_static('user_access');
428 486
    if ($enable) {
429 487
      $perm[$user->uid]['administer comments'] = $enable;
......
508 566
/**
509 567
 * Implements hook_node_view_alter().
510 568
 *
511
 * Remove 'Add new comment' link if it shouldn't be there.
569
 * Remove 'Add new comment' link and breadcrumb if they shouldn't be there.
512 570
 */
513 571
function forum_access_node_view_alter(&$build) {
514 572
  if ($tid = _forum_access_get_tid($build['#node'])) {
515 573
    _forum_access_module_load_include('node.inc');
516 574
    _forum_access_node_view_alter($build, $tid);
517 575
  }
576

  
577
  $breadcrumb = drupal_get_breadcrumb();
578
  if (!$tid && count($breadcrumb) == 2 && strpos($breadcrumb[0], '<a href="/">') === 0 && strpos($breadcrumb[1], '<a href="/forum">') === 0) {
579
    // We must hack away the bogus breadcrumb set by forum module
580
    // (empty taxonomy_forums).
581
    $stored_breadcrumb = &drupal_static('drupal_set_breadcrumb');
582
    $stored_breadcrumb = NULL;
583
  }
518 584
}
519 585

  
520 586
/**
......
564 630
        if (!forum_access_access('view', $tid, $account)) {
565 631
          return $cache[$account->uid][$op][$nid] = NODE_ACCESS_DENY;
566 632
        }
567
        if ($op == 'update' && (user_access('edit any forum content', $account) || ($node->uid == $account->uid && user_access('edit own forum content', $account)))
568
          || $op == 'delete' && (user_access('delete any forum content', $account) || ($node->uid == $account->uid && user_access('delete own forum content', $account)))) {
633
        if (($op == 'update' && (user_access('edit any forum content', $account) || ($node->uid == $account->uid && user_access('edit own forum content', $account))))
634
          || ($op == 'delete' && (user_access('delete any forum content', $account) || ($node->uid == $account->uid && user_access('delete own forum content', $account))))) {
569 635
          return $cache[$account->uid][$op][$nid] = forum_access_node_access($node, 'view', $account);
570 636
        }
571 637
        $access = forum_access_access($op, $tid, $account);

Formats disponibles : Unified diff