Projet

Général

Profil

Paste
Télécharger (2,79 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / advanced_forum / includes / mark-read.inc @ 13c3c9b4

1
<?php
2

    
3
/**
4
 * @file
5
 * Holds functions relating to the Mark Forum/All Read functionality.
6
 */
7

    
8
/**
9
 * Either fill a $links array or return a string version of the link to mark read.
10
 */
11
function advanced_forum_get_mark_read_link($tid = 0, &$links = array()) {
12
  if (advanced_forum_markasread_access() && !in_array($tid, variable_get('forum_containers', array()))) {
13
    if ($tid) {
14
      $links['mark-read']['title'] = t('Mark all topics read');
15
      $links['mark-read']['href'] = "forum/markasread/$tid";
16

    
17
      return l(t('Mark all topics read') . '<span class="image-replace"></span>', "forum/markasread/$tid", array('html' => TRUE));
18
    }
19
    else {
20
      $links['mark-read']['title'] = t('Mark all forums read');
21
      $links['mark-read']['href'] = "forum/markasread";
22

    
23
      return l(t('Mark all forums read') . '<span class="image-replace"></span>', "forum/markasread", array('html' => TRUE));
24
    }
25
  }
26
}
27

    
28
/**
29
 * Marks all posts in forums or in a given forum as read by the current user.
30
 */
31
function advanced_forum_markasread($tid = NULL) {
32
  global $user;
33
  $vid = variable_get('forum_nav_vocabulary', 0);
34

    
35
  // Don't bother trying to mark things read for anonymous users.
36
  if (empty($user->uid)) {
37
    return;
38
  }
39
  // Delete all entries in the history table for the current $uid and
40
  // optionally a forum term id.
41

    
42
  // Subquery to find nids to delete from history table.
43
  $query_node = db_select('node', 'n');
44
  $query_node->join('forum', 'f', 'n.vid = f.vid');
45
  $query_node->join('taxonomy_term_data', 't', 'f.tid = t.tid');
46
  $query_node->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid');
47

    
48
  if (isset($tid)) {
49
    $query_node->condition('f.tid', $tid);
50
  }
51

    
52
  $query_node->condition('t.vid', $vid);
53
  $query_node->addField('n', 'nid');
54
  // Select query objects are one-shot, so clone for INSERT below.
55
  $query_history_insert = clone($query_node);
56
  // Delete values based upon sub-query.
57
  $query = db_delete('history')
58
    ->condition('uid', $user->uid)
59
    ->condition('nid', $query_node, 'IN')
60
    ->execute();
61

    
62
  // Now insert the nids into the history table.
63
  $query_history_insert->addExpression(':uid', 'uid', array(':uid' => $user->uid));
64
  $query_history_insert->addExpression(':time', 'timestamp', array(':time' => REQUEST_TIME));
65

    
66
  db_insert('history')
67
    ->fields(array('nid', 'uid', 'timestamp'))
68
    ->from($query_history_insert)
69
    ->execute();
70

    
71
  drupal_goto(empty($tid) ? 'forum' : 'forum/' . $tid);
72
}
73

    
74
/**
75
 * Access callback for menus and link display.
76
 *
77
 * @TODO: D7 check if needed
78
 *
79
 * This separate function is needed because the Drupal 6 menu system doesn't
80
 * run hook_menu() every time and the logged-in status of the user can get
81
 * cached and re-used for other users.
82
 */
83
function advanced_forum_markasread_access() {
84
  global $user;
85
  return user_access('access content') && $user->uid;
86
}