danielebarchiesi@0
|
1 <?php
|
danielebarchiesi@0
|
2
|
danielebarchiesi@0
|
3 /**
|
danielebarchiesi@0
|
4 * @file
|
danielebarchiesi@0
|
5 * User page callbacks for tracker.module.
|
danielebarchiesi@0
|
6 */
|
danielebarchiesi@0
|
7
|
danielebarchiesi@0
|
8
|
danielebarchiesi@0
|
9 /**
|
danielebarchiesi@0
|
10 * Page callback: prints a listing of active nodes on the site.
|
danielebarchiesi@0
|
11 *
|
danielebarchiesi@0
|
12 * Queries the database for info, adds RDFa info if applicable, and generates
|
danielebarchiesi@0
|
13 * the render array that will be used to render the page.
|
danielebarchiesi@0
|
14 */
|
danielebarchiesi@0
|
15 function tracker_page($account = NULL, $set_title = FALSE) {
|
danielebarchiesi@0
|
16 if ($account) {
|
danielebarchiesi@0
|
17 $query = db_select('tracker_user', 't')->extend('PagerDefault');
|
danielebarchiesi@0
|
18 $query->condition('t.uid', $account->uid);
|
danielebarchiesi@0
|
19
|
danielebarchiesi@0
|
20 if ($set_title) {
|
danielebarchiesi@0
|
21 // When viewed from user/%user/track, display the name of the user
|
danielebarchiesi@0
|
22 // as page title -- the tab title remains Track so this needs to be done
|
danielebarchiesi@0
|
23 // here and not in the menu definition.
|
danielebarchiesi@0
|
24 drupal_set_title(format_username($account));
|
danielebarchiesi@0
|
25 }
|
danielebarchiesi@0
|
26 }
|
danielebarchiesi@0
|
27 else {
|
danielebarchiesi@0
|
28 $query = db_select('tracker_node', 't', array('target' => 'slave'))->extend('PagerDefault');
|
danielebarchiesi@0
|
29 }
|
danielebarchiesi@0
|
30
|
danielebarchiesi@0
|
31 // This array acts as a placeholder for the data selected later
|
danielebarchiesi@0
|
32 // while keeping the correct order.
|
danielebarchiesi@0
|
33 $nodes = $query
|
danielebarchiesi@0
|
34 ->addTag('node_access')
|
danielebarchiesi@0
|
35 ->fields('t', array('nid', 'changed'))
|
danielebarchiesi@0
|
36 ->condition('t.published', 1)
|
danielebarchiesi@0
|
37 ->orderBy('t.changed', 'DESC')
|
danielebarchiesi@0
|
38 ->limit(25)
|
danielebarchiesi@0
|
39 ->execute()
|
danielebarchiesi@0
|
40 ->fetchAllAssoc('nid');
|
danielebarchiesi@0
|
41
|
danielebarchiesi@0
|
42 $rows = array();
|
danielebarchiesi@0
|
43 if (!empty($nodes)) {
|
danielebarchiesi@0
|
44 // Now, get the data and put into the placeholder array.
|
danielebarchiesi@0
|
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'));
|
danielebarchiesi@0
|
46 foreach ($result as $node) {
|
danielebarchiesi@0
|
47 $node->last_activity = $nodes[$node->nid]->changed;
|
danielebarchiesi@0
|
48 $nodes[$node->nid] = $node;
|
danielebarchiesi@0
|
49 }
|
danielebarchiesi@0
|
50
|
danielebarchiesi@0
|
51 // Display the data.
|
danielebarchiesi@0
|
52 foreach ($nodes as $node) {
|
danielebarchiesi@0
|
53 // Determine the number of comments.
|
danielebarchiesi@0
|
54 $comments = 0;
|
danielebarchiesi@0
|
55 if ($node->comment_count) {
|
danielebarchiesi@0
|
56 $comments = $node->comment_count;
|
danielebarchiesi@0
|
57
|
danielebarchiesi@0
|
58 if ($new = comment_num_new($node->nid)) {
|
danielebarchiesi@0
|
59 $comments .= '<br />';
|
danielebarchiesi@0
|
60 $comments .= l(format_plural($new, '1 new', '@count new'), 'node/' . $node->nid, array('fragment' => 'new'));
|
danielebarchiesi@0
|
61 }
|
danielebarchiesi@0
|
62 }
|
danielebarchiesi@0
|
63
|
danielebarchiesi@0
|
64 $row = array(
|
danielebarchiesi@0
|
65 'type' => check_plain(node_type_get_name($node->type)),
|
danielebarchiesi@0
|
66 'title' => array('data' => l($node->title, 'node/' . $node->nid) . ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed)))),
|
danielebarchiesi@0
|
67 'author' => array('data' => theme('username', array('account' => $node))),
|
danielebarchiesi@0
|
68 'replies' => array('class' => array('replies'), 'data' => $comments),
|
danielebarchiesi@0
|
69 'last updated' => array('data' => t('!time ago', array('!time' => format_interval(REQUEST_TIME - $node->last_activity)))),
|
danielebarchiesi@0
|
70 );
|
danielebarchiesi@0
|
71
|
danielebarchiesi@0
|
72 // Adds extra RDFa markup to the $row array if the RDF module is enabled.
|
danielebarchiesi@0
|
73 if (function_exists('rdf_mapping_load')) {
|
danielebarchiesi@0
|
74 // Each node is not loaded for performance reasons, as a result we need
|
danielebarchiesi@0
|
75 // to retrieve the RDF mapping for each node type.
|
danielebarchiesi@0
|
76 $mapping = rdf_mapping_load('node', $node->type);
|
danielebarchiesi@0
|
77 // Adds RDFa markup to the title of the node. Because the RDFa markup is
|
danielebarchiesi@0
|
78 // added to the td tag which might contain HTML code, we specify an
|
danielebarchiesi@0
|
79 // empty datatype to ensure the value of the title read by the RDFa
|
danielebarchiesi@0
|
80 // parsers is a plain literal.
|
danielebarchiesi@0
|
81 $row['title'] += rdf_rdfa_attributes($mapping['title']) + array('datatype' => '');
|
danielebarchiesi@0
|
82 // Annotates the td tag containing the author of the node.
|
danielebarchiesi@0
|
83 $row['author'] += rdf_rdfa_attributes($mapping['uid']);
|
danielebarchiesi@0
|
84 // Annotates the td tag containing the number of replies. We add the
|
danielebarchiesi@0
|
85 // content attribute to ensure that only the comment count is used as
|
danielebarchiesi@0
|
86 // the value for 'num_replies'. Otherwise, other text such as a link
|
danielebarchiesi@0
|
87 // to the number of new comments could be included in the 'num_replies'
|
danielebarchiesi@0
|
88 // value.
|
danielebarchiesi@0
|
89 $row['replies'] += rdf_rdfa_attributes($mapping['comment_count']);
|
danielebarchiesi@0
|
90 $row['replies'] += array('content' => $node->comment_count);
|
danielebarchiesi@0
|
91 // If the node has no comments, we assume the node itself was modified
|
danielebarchiesi@0
|
92 // and apply 'changed' in addition to 'last_activity'. If there are
|
danielebarchiesi@0
|
93 // comments present, we cannot infer whether the node itself was
|
danielebarchiesi@0
|
94 // modified or a comment was posted, so we use only 'last_activity'.
|
danielebarchiesi@0
|
95 $mapping_last_activity = rdf_rdfa_attributes($mapping['last_activity'], $node->last_activity);
|
danielebarchiesi@0
|
96 if ($node->comment_count == 0) {
|
danielebarchiesi@0
|
97 $mapping_changed = rdf_rdfa_attributes($mapping['changed'], $node->last_activity);
|
danielebarchiesi@0
|
98 $mapping_last_activity['property'] = array_merge($mapping_last_activity['property'], $mapping_changed['property']);
|
danielebarchiesi@0
|
99 }
|
danielebarchiesi@0
|
100 $row['last updated'] += $mapping_last_activity;
|
danielebarchiesi@0
|
101
|
danielebarchiesi@0
|
102 // We need to add the about attribute on the tr tag to specify which
|
danielebarchiesi@0
|
103 // node the RDFa annotations above apply to. We move the content of
|
danielebarchiesi@0
|
104 // $row to a 'data' sub array so we can specify attributes for the row.
|
danielebarchiesi@0
|
105 $row = array('data' => $row);
|
danielebarchiesi@0
|
106 $row['about'] = url('node/' . $node->nid);
|
danielebarchiesi@0
|
107 }
|
danielebarchiesi@0
|
108 $rows[] = $row;
|
danielebarchiesi@0
|
109 }
|
danielebarchiesi@0
|
110 }
|
danielebarchiesi@0
|
111
|
danielebarchiesi@0
|
112 $page['tracker'] = array(
|
danielebarchiesi@0
|
113 '#rows' => $rows,
|
danielebarchiesi@0
|
114 '#header' => array(t('Type'), t('Title'), t('Author'), t('Replies'), t('Last updated')),
|
danielebarchiesi@0
|
115 '#theme' => 'table',
|
danielebarchiesi@0
|
116 '#empty' => t('No content available.'),
|
danielebarchiesi@0
|
117 '#attached' => array(
|
danielebarchiesi@0
|
118 'css' => array(drupal_get_path('module', 'tracker') . '/tracker.css' => array()),
|
danielebarchiesi@0
|
119 ),
|
danielebarchiesi@0
|
120 );
|
danielebarchiesi@0
|
121 $page['pager'] = array(
|
danielebarchiesi@0
|
122 '#theme' => 'pager',
|
danielebarchiesi@0
|
123 '#quantity' => 25,
|
danielebarchiesi@0
|
124 '#weight' => 10,
|
danielebarchiesi@0
|
125 );
|
danielebarchiesi@0
|
126 $page['#sorted'] = TRUE;
|
danielebarchiesi@0
|
127
|
danielebarchiesi@0
|
128 return $page;
|
danielebarchiesi@0
|
129 }
|