2007-07-22 06:48:25 +00:00
< ? php
// $Id$
/**
* @ file
* Page callback file for the blog module .
*/
/**
* Menu callback ; displays a Drupal page containing recent blog entries of a given user .
*/
function blog_page_user ( $account ) {
global $user ;
2008-10-13 00:33:05 +00:00
drupal_set_title ( $title = t ( " @name's blog " , array ( '@name' => $account -> name )), PASS_THROUGH );
2007-10-24 11:17:01 +00:00
$items = array ();
2008-05-22 19:27:13 +00:00
if (( $account -> uid == $user -> uid ) && user_access ( 'create blog content' )) {
2007-10-24 11:17:01 +00:00
$items [] = l ( t ( 'Post new blog entry.' ), " node/add/blog " );
2007-07-22 06:48:25 +00:00
}
2008-10-12 04:30:09 +00:00
elseif ( $account -> uid == $user -> uid ) {
2008-01-21 12:05:36 +00:00
$items [] = t ( 'You are not allowed to post a new blog entry.' );
2007-10-24 11:17:01 +00:00
}
2009-01-27 00:22:27 +00:00
$build [ 'blog_actions' ] = array (
'#items' => $items ,
'#theme' => 'list' ,
'#weight' => - 1 ,
);
$nids = pager_query ( db_rewrite_sql ( " SELECT n.nid, n.sticky, n.created FROM { node} n WHERE n.type = 'blog' AND n.uid = %d AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC " ), variable_get ( 'default_nodes_main' , 10 ), 0 , NULL , $account -> uid ) -> fetchCol ();
if ( ! empty ( $nids )) {
$nodes = node_load_multiple ( $nids );
$build += node_build_multiple ( $nodes );
$build [ 'pager' ] = array (
'#markup' => theme ( 'pager' , NULL , variable_get ( 'default_nodes_main' , 10 )),
'#weight' => 5 ,
);
2008-02-10 18:58:28 +00:00
}
else {
if ( $account -> uid == $user -> uid ) {
drupal_set_message ( t ( 'You have not created any blog entries.' ));
}
else {
drupal_set_message ( t ( '!author has not created any blog entries.' , array ( '!author' => theme ( 'username' , $account ))));
}
2007-07-22 06:48:25 +00:00
}
2008-04-14 17:48:46 +00:00
drupal_add_feed ( url ( 'blog/' . $account -> uid . '/feed' ), t ( 'RSS - !title' , array ( '!title' => $title )));
2007-10-24 11:17:01 +00:00
2009-01-27 00:22:27 +00:00
return drupal_get_page ( $build );
2007-07-22 06:48:25 +00:00
}
/**
* Menu callback ; displays a Drupal page containing recent blog entries of all users .
*/
function blog_page_last () {
global $user ;
2009-01-27 00:22:27 +00:00
$build = array ();
2008-02-10 18:58:28 +00:00
if ( user_access ( 'edit own blog' )) {
$items [] = l ( t ( 'Create new blog entry.' ), " node/add/blog " );
2009-01-27 00:22:27 +00:00
$build [ 'blog_actions' ] = array (
'#items' => $items ,
'#theme' => 'list' ,
'#weight' => - 1 ,
);
2008-02-10 18:58:28 +00:00
}
2009-01-27 00:22:27 +00:00
$nids = pager_query ( db_rewrite_sql ( " SELECT n.nid, n.sticky, n.created FROM { node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC " ), variable_get ( 'default_nodes_main' , 10 )) -> fetchCol ();
2008-02-10 18:58:28 +00:00
2009-01-27 00:22:27 +00:00
if ( ! empty ( $nids )) {
$nodes = node_load_multiple ( $nids );
$build += node_build_multiple ( $nodes );
$build [ 'pager' ] = array (
'#markup' => theme ( 'pager' , NULL , variable_get ( 'default_nodes_main' , 10 )),
'#weight' => 5 ,
);
2008-02-10 18:58:28 +00:00
}
else {
drupal_set_message ( t ( 'No blog entries have been created.' ));
2007-07-22 06:48:25 +00:00
}
drupal_add_feed ( url ( 'blog/feed' ), t ( 'RSS - blogs' ));
2009-01-27 00:22:27 +00:00
return drupal_get_page ( $build );
2007-07-22 06:48:25 +00:00
}
/**
* Menu callback ; displays an RSS feed containing recent blog entries of a given user .
*/
2007-10-24 11:17:01 +00:00
function blog_feed_user ( $account ) {
$result = db_query_range ( db_rewrite_sql ( " SELECT n.nid, n.created FROM { node} n WHERE n.type = 'blog' AND n.uid = %d AND n.status = 1 ORDER BY n.created DESC " ), $account -> uid , 0 , variable_get ( 'feed_default_items' , 10 ));
2008-04-14 17:48:46 +00:00
$channel [ 'title' ] = $account -> name . " 's blog " ;
$channel [ 'link' ] = url ( 'blog/' . $account -> uid , array ( 'absolute' => TRUE ));
2007-07-22 06:48:25 +00:00
2007-10-25 17:44:38 +00:00
$items = array ();
2007-07-22 06:48:25 +00:00
while ( $row = db_fetch_object ( $result )) {
$items [] = $row -> nid ;
}
node_feed ( $items , $channel );
}
/**
* Menu callback ; displays an RSS feed containing recent blog entries of all users .
*/
function blog_feed_last () {
$result = db_query_range ( db_rewrite_sql ( " SELECT n.nid, n.created FROM { node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC " ), 0 , variable_get ( 'feed_default_items' , 10 ));
2008-04-14 17:48:46 +00:00
$channel [ 'title' ] = variable_get ( 'site_name' , 'Drupal' ) . ' blogs' ;
2007-07-22 06:48:25 +00:00
$channel [ 'link' ] = url ( 'blog' , array ( 'absolute' => TRUE ));
2007-12-14 10:40:51 +00:00
$items = array ();
2007-07-22 06:48:25 +00:00
while ( $row = db_fetch_object ( $result )) {
$items [] = $row -> nid ;
}
node_feed ( $items , $channel );
}