2007-08-23 16:01:01 +00:00
< ? php
// $Id$
/**
* @ file
* User page callbacks for the tracker module .
*/
/**
2009-08-31 06:52:50 +00:00
* Menu callback ; prints a listing of active nodes on the site .
2007-08-23 16:01:01 +00:00
*/
2007-11-06 08:51:23 +00:00
function tracker_page ( $account = NULL , $set_title = FALSE ) {
if ( $account ) {
2009-08-31 06:52:50 +00:00
$query = db_select ( 'tracker_user' , 't' ) -> extend ( 'PagerDefault' );
$query -> condition ( 't.uid' , $account -> uid );
2007-11-06 08:51:23 +00:00
if ( $set_title ) {
// When viewed from user/%user/track, display the name of the user
// as page title -- the tab title remains Track so this needs to be done
2008-12-30 16:43:20 +00:00
// here and not in the menu definition.
2008-10-13 00:33:05 +00:00
drupal_set_title ( $account -> name );
2007-11-06 08:51:23 +00:00
}
2007-08-23 16:01:01 +00:00
}
2009-08-31 06:52:50 +00:00
else {
$query = db_select ( 'tracker_node' , 't' ) -> extend ( 'PagerDefault' );
}
// This array acts as a placeholder for the data selected later
// while keeping the correct order.
$nodes = $query
-> addTag ( 'node_access' )
-> fields ( 't' , array ( 'nid' , 'changed' ))
-> condition ( 't.published' , 1 )
-> orderBy ( 't.changed' , 'DESC' )
-> limit ( 25 )
-> execute ()
-> fetchAllAssoc ( 'nid' );
2007-08-23 16:01:01 +00:00
2009-08-31 06:52:50 +00:00
if ( ! empty ( $nodes )) {
// Now, get the data and put into the placeholder array
$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 )));
foreach ( $result as $node ) {
$node -> last_activity = $nodes [ $node -> nid ] -> changed ;
$nodes [ $node -> nid ] = $node ;
}
2009-04-05 12:26:12 +00:00
2009-08-31 06:52:50 +00:00
// Finally display the data
$rows = array ();
foreach ( $nodes as $node ) {
// Determine the number of comments:
$comments = 0 ;
if ( $node -> comment_count ) {
$comments = $node -> comment_count ;
2007-08-23 16:01:01 +00:00
2009-08-31 06:52:50 +00:00
if ( $new = comment_num_new ( $node -> nid )) {
$comments .= '<br />' ;
$comments .= l ( format_plural ( $new , '1 new' , '@count new' ), 'node/' . $node -> nid , array ( 'fragment' => 'new' ));
}
2007-08-23 16:01:01 +00:00
}
2009-08-31 06:52:50 +00:00
$rows [] = array (
check_plain ( node_type_get_name ( $node -> type )),
l ( $node -> title , 'node/' . $node -> nid ) . ' ' . theme ( 'mark' , node_mark ( $node -> nid , $node -> changed )),
theme ( 'username' , $node ),
array ( 'class' => array ( 'replies' ), 'data' => $comments ),
t ( '!time ago' , array ( '!time' => format_interval ( REQUEST_TIME - $node -> last_activity )))
);
}
2007-08-23 16:01:01 +00:00
}
2009-08-31 06:52:50 +00:00
else {
2007-08-23 16:01:01 +00:00
$rows [] = array ( array ( 'data' => t ( 'No posts available.' ), 'colspan' => '5' ));
}
2009-07-02 04:27:23 +00:00
$page [ 'tracker' ] = array (
'#rows' => $rows ,
'#header' => array ( t ( 'Type' ), t ( 'Post' ), t ( 'Author' ), t ( 'Replies' ), t ( 'Last updated' )),
'#theme' => 'table' ,
'#attached_css' => array ( drupal_get_path ( 'module' , 'tracker' ) . '/tracker.css' => array ( 'preprocess' => FALSE )),
);
$page [ 'pager' ] = array (
'#theme' => 'pager' ,
'#quantity' => 25 ,
'#weight' => 10 ,
);
$page [ '#sorted' ] = TRUE ;
2007-08-23 16:01:01 +00:00
2009-07-02 04:27:23 +00:00
return $page ;
2007-08-23 16:01:01 +00:00
}