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;
|
|
|
|
|
2009-11-01 21:26:44 +00:00
|
|
|
drupal_set_title($title = t("@name's blog", array('@name' => format_username($account))), 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,
|
2009-07-02 04:27:23 +00:00
|
|
|
'#theme' => 'item_list',
|
2009-01-27 00:22:27 +00:00
|
|
|
'#weight' => -1,
|
|
|
|
);
|
|
|
|
|
2009-04-15 13:50:08 +00:00
|
|
|
$query = db_select('node', 'n')->extend('PagerDefault');
|
|
|
|
$nids = $query
|
|
|
|
->fields('n', array('nid', 'sticky', 'created'))
|
|
|
|
->condition('type', 'blog')
|
|
|
|
->condition('uid', $account->uid)
|
|
|
|
->condition('status', 1)
|
|
|
|
->orderBy('sticky', 'DESC')
|
|
|
|
->orderBy('created', 'DESC')
|
|
|
|
->limit(variable_get('default_nodes_main', 10))
|
|
|
|
->addTag('node_access')
|
|
|
|
->execute()
|
|
|
|
->fetchCol();
|
|
|
|
|
2009-01-27 00:22:27 +00:00
|
|
|
if (!empty($nids)) {
|
|
|
|
$nodes = node_load_multiple($nids);
|
2009-12-21 13:47:32 +00:00
|
|
|
$build += node_view_multiple($nodes);
|
2009-01-27 00:22:27 +00:00
|
|
|
$build['pager'] = array(
|
2009-07-29 06:39:35 +00:00
|
|
|
'#theme' => 'pager',
|
2009-01-27 00:22:27 +00:00
|
|
|
'#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 {
|
2009-10-09 01:00:08 +00:00
|
|
|
drupal_set_message(t('!author has not created any blog entries.', array('!author' => theme('username', array('account' => $account)))));
|
2008-02-10 18:58:28 +00:00
|
|
|
}
|
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-05-21 21:12:25 +00:00
|
|
|
return $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
|
|
|
|
2009-04-15 13:50:08 +00:00
|
|
|
$query = db_select('node', 'n')->extend('PagerDefault');
|
|
|
|
$nids = $query
|
|
|
|
->fields('n', array('nid', 'sticky', 'created'))
|
|
|
|
->condition('type', 'blog')
|
|
|
|
->condition('status', 1)
|
|
|
|
->orderBy('sticky', 'DESC')
|
|
|
|
->orderBy('created', 'DESC')
|
|
|
|
->limit(variable_get('default_nodes_main', 10))
|
|
|
|
->addTag('node_access')
|
|
|
|
->execute()
|
|
|
|
->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);
|
2009-12-21 13:47:32 +00:00
|
|
|
$build += node_view_multiple($nodes);
|
2009-01-27 00:22:27 +00:00
|
|
|
$build['pager'] = array(
|
2009-07-29 06:39:35 +00:00
|
|
|
'#theme' => 'pager',
|
2009-01-27 00:22:27 +00:00
|
|
|
'#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-05-21 21:12:25 +00:00
|
|
|
return $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) {
|
2009-04-15 13:50:08 +00:00
|
|
|
|
|
|
|
$nids = db_select('node', 'n')
|
|
|
|
->fields('n', array('nid', 'created'))
|
|
|
|
->condition('type', 'blog')
|
|
|
|
->condition('uid', $account->uid)
|
|
|
|
->condition('status', 1)
|
|
|
|
->orderBy('created', 'DESC')
|
|
|
|
->range(0, variable_get('feed_default_items', 10))
|
|
|
|
->addTag('node_access')
|
|
|
|
->execute()
|
|
|
|
->fetchCol();
|
|
|
|
|
2009-11-01 21:26:44 +00:00
|
|
|
$channel['title'] = t("!name's blog", array('!name' => format_username($account)));
|
2008-04-14 17:48:46 +00:00
|
|
|
$channel['link'] = url('blog/' . $account->uid, array('absolute' => TRUE));
|
2007-07-22 06:48:25 +00:00
|
|
|
|
2009-04-15 13:50:08 +00:00
|
|
|
node_feed($nids, $channel);
|
2007-07-22 06:48:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Menu callback; displays an RSS feed containing recent blog entries of all users.
|
|
|
|
*/
|
|
|
|
function blog_feed_last() {
|
2009-04-15 13:50:08 +00:00
|
|
|
$nids = db_select('node', 'n')
|
|
|
|
->fields('n', array('nid', 'created'))
|
|
|
|
->condition('type', 'blog')
|
|
|
|
->condition('status', 1)
|
|
|
|
->orderBy('created', 'DESC')
|
|
|
|
->range(0, variable_get('feed_default_items', 10))
|
|
|
|
->addTag('node_access')
|
|
|
|
->execute()
|
|
|
|
->fetchCol();
|
|
|
|
|
2009-08-10 22:39:24 +00:00
|
|
|
$channel['title'] = t('!site_name blogs', array('!site_name' => variable_get('site_name', 'Drupal')));
|
2007-07-22 06:48:25 +00:00
|
|
|
$channel['link'] = url('blog', array('absolute' => TRUE));
|
|
|
|
|
2009-04-15 13:50:08 +00:00
|
|
|
node_feed($nids, $channel);
|
2007-07-22 06:48:25 +00:00
|
|
|
}
|