Projet

Général

Profil

Paste
Télécharger (5,41 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / tracker / tracker.pages.inc @ c7768a53

1
<?php
2

    
3
/**
4
 * @file
5
 * User page callbacks for tracker.module.
6
 */
7

    
8

    
9
/**
10
 * Page callback: prints a listing of active nodes on the site.
11
 *
12
 * Queries the database for info, adds RDFa info if applicable, and generates
13
 * the render array that will be used to render the page.
14
 */
15
function tracker_page($account = NULL, $set_title = FALSE) {
16
  if ($account) {
17
    $query = db_select('tracker_user', 't')->extend('PagerDefault');
18
    $query->condition('t.uid', $account->uid);
19

    
20
    if ($set_title) {
21
      // When viewed from user/%user/track, display the name of the user
22
      // as page title -- the tab title remains Track so this needs to be done
23
      // here and not in the menu definition.
24
      drupal_set_title(format_username($account));
25
    }
26
  }
27
  else {
28
    $query = db_select('tracker_node', 't', array('target' => 'slave'))->extend('PagerDefault');
29
  }
30

    
31
  // This array acts as a placeholder for the data selected later
32
  // while keeping the correct order.
33
  $nodes = $query
34
    ->addTag('node_access')
35
    ->fields('t', array('nid', 'changed'))
36
    ->condition('t.published', 1)
37
    ->orderBy('t.changed', 'DESC')
38
    ->limit(25)
39
    ->execute()
40
    ->fetchAllAssoc('nid');
41

    
42
  $rows = array();
43
  if (!empty($nodes)) {
44
    // Now, get the data and put into the placeholder array.
45
    $result = db_query('SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.nid IN (:nids)', array(':nids' => array_keys($nodes)), array('target' => 'slave'));
46
    foreach ($result as $node) {
47
      $node->last_activity = $nodes[$node->nid]->changed;
48
      $nodes[$node->nid] = $node;
49
    }
50

    
51
    // Display the data.
52
    foreach ($nodes as $node) {
53
      // Determine the number of comments.
54
      $comments = 0;
55
      if ($node->comment_count) {
56
        $comments = $node->comment_count;
57

    
58
        if ($new = comment_num_new($node->nid)) {
59
          $comments .= '<br />';
60
          $comments .= l(format_plural($new, '1 new', '@count new'), 'node/' . $node->nid, array('fragment' => 'new'));
61
        }
62
      }
63

    
64
      $row = array(
65
        'type' => check_plain(node_type_get_name($node->type)),
66
        'title' => array('data' => l($node->title, 'node/' . $node->nid) . ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed)))),
67
        'author' => array('data' => theme('username', array('account' => $node))),
68
        'replies' => array('class' => array('replies'), 'data' => $comments),
69
        'last updated' => array('data' => t('!time ago', array('!time' => format_interval(REQUEST_TIME - $node->last_activity)))),
70
      );
71

    
72
      // Adds extra RDFa markup to the $row array if the RDF module is enabled.
73
      if (function_exists('rdf_mapping_load')) {
74
        // Each node is not loaded for performance reasons, as a result we need
75
        // to retrieve the RDF mapping for each node type.
76
        $mapping = rdf_mapping_load('node', $node->type);
77
        // Adds RDFa markup to the title of the node. Because the RDFa markup is
78
        // added to the td tag which might contain HTML code, we specify an
79
        // empty datatype to ensure the value of the title read by the RDFa
80
        // parsers is a plain literal.
81
        $row['title'] += rdf_rdfa_attributes($mapping['title']) + array('datatype' => '');
82
        // Annotates the td tag containing the author of the node.
83
        $row['author'] += rdf_rdfa_attributes($mapping['uid']);
84
        // Annotates the td tag containing the number of replies. We add the
85
        // content attribute to ensure that only the comment count is used as
86
        // the value for 'num_replies'. Otherwise, other text such as a link
87
        // to the number of new comments could be included in the 'num_replies'
88
        // value.
89
        $row['replies'] += rdf_rdfa_attributes($mapping['comment_count']);
90
        $row['replies'] += array('content' => $node->comment_count);
91
        // If the node has no comments, we assume the node itself was modified
92
        // and apply 'changed' in addition to 'last_activity'.  If there are
93
        // comments present, we cannot infer whether the node itself was
94
        // modified or a comment was posted, so we use only 'last_activity'.
95
        $mapping_last_activity = rdf_rdfa_attributes($mapping['last_activity'], $node->last_activity);
96
        if ($node->comment_count == 0) {
97
          $mapping_changed = rdf_rdfa_attributes($mapping['changed'], $node->last_activity);
98
          $mapping_last_activity['property'] = array_merge($mapping_last_activity['property'], $mapping_changed['property']);
99
        }
100
        $row['last updated'] += $mapping_last_activity;
101

    
102
        // We need to add the about attribute on the tr tag to specify which
103
        // node the RDFa annotations above apply to. We move the content of
104
        // $row to a 'data' sub array so we can specify attributes for the row.
105
        $row = array('data' => $row);
106
        $row['about'] = url('node/' . $node->nid);
107
      }
108
      $rows[] = $row;
109
    }
110
  }
111

    
112
  $page['tracker'] = array(
113
    '#rows' => $rows,
114
    '#header' => array(t('Type'), t('Title'), t('Author'), t('Replies'), t('Last updated')),
115
    '#theme' => 'table',
116
    '#empty' => t('No content available.'),
117
    '#attached' => array(
118
      'css' => array(drupal_get_path('module', 'tracker') . '/tracker.css' => array()),
119
    ),
120
  );
121
  $page['pager'] = array(
122
    '#theme' => 'pager',
123
    '#weight' => 10,
124
  );
125
  $page['#sorted'] = TRUE;
126

    
127
  return $page;
128
}