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 @ c169e7c4

1
<?php
2

    
3

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

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

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

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

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

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

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

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

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

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

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

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