danielebarchiesi@0: extend('PagerDefault'); danielebarchiesi@0: $query->condition('t.uid', $account->uid); danielebarchiesi@0: danielebarchiesi@0: if ($set_title) { danielebarchiesi@0: // When viewed from user/%user/track, display the name of the user danielebarchiesi@0: // as page title -- the tab title remains Track so this needs to be done danielebarchiesi@0: // here and not in the menu definition. danielebarchiesi@0: drupal_set_title(format_username($account)); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: $query = db_select('tracker_node', 't', array('target' => 'slave'))->extend('PagerDefault'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // This array acts as a placeholder for the data selected later danielebarchiesi@0: // while keeping the correct order. danielebarchiesi@0: $nodes = $query danielebarchiesi@0: ->addTag('node_access') danielebarchiesi@0: ->fields('t', array('nid', 'changed')) danielebarchiesi@0: ->condition('t.published', 1) danielebarchiesi@0: ->orderBy('t.changed', 'DESC') danielebarchiesi@0: ->limit(25) danielebarchiesi@0: ->execute() danielebarchiesi@0: ->fetchAllAssoc('nid'); danielebarchiesi@0: danielebarchiesi@0: $rows = array(); danielebarchiesi@0: if (!empty($nodes)) { danielebarchiesi@0: // Now, get the data and put into the placeholder array. danielebarchiesi@0: $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: foreach ($result as $node) { danielebarchiesi@0: $node->last_activity = $nodes[$node->nid]->changed; danielebarchiesi@0: $nodes[$node->nid] = $node; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Display the data. danielebarchiesi@0: foreach ($nodes as $node) { danielebarchiesi@0: // Determine the number of comments. danielebarchiesi@0: $comments = 0; danielebarchiesi@0: if ($node->comment_count) { danielebarchiesi@0: $comments = $node->comment_count; danielebarchiesi@0: danielebarchiesi@0: if ($new = comment_num_new($node->nid)) { danielebarchiesi@0: $comments .= '
'; danielebarchiesi@0: $comments .= l(format_plural($new, '1 new', '@count new'), 'node/' . $node->nid, array('fragment' => 'new')); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $row = array( danielebarchiesi@0: 'type' => check_plain(node_type_get_name($node->type)), danielebarchiesi@0: 'title' => array('data' => l($node->title, 'node/' . $node->nid) . ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed)))), danielebarchiesi@0: 'author' => array('data' => theme('username', array('account' => $node))), danielebarchiesi@0: 'replies' => array('class' => array('replies'), 'data' => $comments), danielebarchiesi@0: 'last updated' => array('data' => t('!time ago', array('!time' => format_interval(REQUEST_TIME - $node->last_activity)))), danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: // Adds extra RDFa markup to the $row array if the RDF module is enabled. danielebarchiesi@0: if (function_exists('rdf_mapping_load')) { danielebarchiesi@0: // Each node is not loaded for performance reasons, as a result we need danielebarchiesi@0: // to retrieve the RDF mapping for each node type. danielebarchiesi@0: $mapping = rdf_mapping_load('node', $node->type); danielebarchiesi@0: // Adds RDFa markup to the title of the node. Because the RDFa markup is danielebarchiesi@0: // added to the td tag which might contain HTML code, we specify an danielebarchiesi@0: // empty datatype to ensure the value of the title read by the RDFa danielebarchiesi@0: // parsers is a plain literal. danielebarchiesi@0: $row['title'] += rdf_rdfa_attributes($mapping['title']) + array('datatype' => ''); danielebarchiesi@0: // Annotates the td tag containing the author of the node. danielebarchiesi@0: $row['author'] += rdf_rdfa_attributes($mapping['uid']); danielebarchiesi@0: // Annotates the td tag containing the number of replies. We add the danielebarchiesi@0: // content attribute to ensure that only the comment count is used as danielebarchiesi@0: // the value for 'num_replies'. Otherwise, other text such as a link danielebarchiesi@0: // to the number of new comments could be included in the 'num_replies' danielebarchiesi@0: // value. danielebarchiesi@0: $row['replies'] += rdf_rdfa_attributes($mapping['comment_count']); danielebarchiesi@0: $row['replies'] += array('content' => $node->comment_count); danielebarchiesi@0: // If the node has no comments, we assume the node itself was modified danielebarchiesi@0: // and apply 'changed' in addition to 'last_activity'. If there are danielebarchiesi@0: // comments present, we cannot infer whether the node itself was danielebarchiesi@0: // modified or a comment was posted, so we use only 'last_activity'. danielebarchiesi@0: $mapping_last_activity = rdf_rdfa_attributes($mapping['last_activity'], $node->last_activity); danielebarchiesi@0: if ($node->comment_count == 0) { danielebarchiesi@0: $mapping_changed = rdf_rdfa_attributes($mapping['changed'], $node->last_activity); danielebarchiesi@0: $mapping_last_activity['property'] = array_merge($mapping_last_activity['property'], $mapping_changed['property']); danielebarchiesi@0: } danielebarchiesi@0: $row['last updated'] += $mapping_last_activity; danielebarchiesi@0: danielebarchiesi@0: // We need to add the about attribute on the tr tag to specify which danielebarchiesi@0: // node the RDFa annotations above apply to. We move the content of danielebarchiesi@0: // $row to a 'data' sub array so we can specify attributes for the row. danielebarchiesi@0: $row = array('data' => $row); danielebarchiesi@0: $row['about'] = url('node/' . $node->nid); danielebarchiesi@0: } danielebarchiesi@0: $rows[] = $row; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $page['tracker'] = array( danielebarchiesi@0: '#rows' => $rows, danielebarchiesi@0: '#header' => array(t('Type'), t('Title'), t('Author'), t('Replies'), t('Last updated')), danielebarchiesi@0: '#theme' => 'table', danielebarchiesi@0: '#empty' => t('No content available.'), danielebarchiesi@0: '#attached' => array( danielebarchiesi@0: 'css' => array(drupal_get_path('module', 'tracker') . '/tracker.css' => array()), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: $page['pager'] = array( danielebarchiesi@0: '#theme' => 'pager', danielebarchiesi@0: '#quantity' => 25, danielebarchiesi@0: '#weight' => 10, danielebarchiesi@0: ); danielebarchiesi@0: $page['#sorted'] = TRUE; danielebarchiesi@0: danielebarchiesi@0: return $page; danielebarchiesi@0: }