| 1 | | <?php |
| 2 | | // $Id: blog.pages.inc,v 1.14 2008/10/13 00:33:01 webchick Exp $ |
| 3 | | |
| 4 | | /** |
| 5 | | * @file |
| 6 | | * Page callback file for the blog module. |
| 7 | | */ |
| 8 | | |
| 9 | | /** |
| 10 | | * Menu callback; displays a Drupal page containing recent blog entries of
a given user. |
| 11 | | */ |
| 12 | 10 | function blog_page_user($account) { |
| 13 | 4 | global $user; |
| 14 | | |
| 15 | 4 | drupal_set_title($title = t("@name's blog", array('@name' =>
$account->name)), PASS_THROUGH); |
| 16 | | |
| 17 | 4 | $items = array(); |
| 18 | | |
| 19 | 4 | if (($account->uid == $user->uid) && user_access('create blog content'))
{ |
| 20 | 4 | $items[] = l(t('Post new blog entry.'), "node/add/blog"); |
| 21 | 4 | } |
| 22 | 0 | elseif ($account->uid == $user->uid) { |
| 23 | 0 | $items[] = t('You are not allowed to post a new blog entry.'); |
| 24 | 0 | } |
| 25 | | |
| 26 | 4 | $output = theme('item_list', $items); |
| 27 | | |
| 28 | 4 | $result = 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); |
| 29 | 4 | $has_posts = FALSE; |
| 30 | | |
| 31 | 4 | while ($node = db_fetch_object($result)) { |
| 32 | 0 | $output .= node_view(node_load($node->nid), 1); |
| 33 | 0 | $has_posts = TRUE; |
| 34 | 0 | } |
| 35 | | |
| 36 | 4 | if ($has_posts) { |
| 37 | 0 | $output .= theme('pager', NULL, variable_get('default_nodes_main',
10)); |
| 38 | 0 | } |
| 39 | | else { |
| 40 | 4 | if ($account->uid == $user->uid) { |
| 41 | 4 | drupal_set_message(t('You have not created any blog entries.')); |
| 42 | 4 | } |
| 43 | | else { |
| 44 | 0 | drupal_set_message(t('!author has not created any blog entries.',
array('!author' => theme('username', $account)))); |
| 45 | | } |
| 46 | | } |
| 47 | 4 | drupal_add_feed(url('blog/' . $account->uid . '/feed'), t('RSS - !title',
array('!title' => $title))); |
| 48 | | |
| 49 | 4 | return $output; |
| 50 | 0 | } |
| 51 | | |
| 52 | | /** |
| 53 | | * Menu callback; displays a Drupal page containing recent blog entries of
all users. |
| 54 | | */ |
| 55 | 10 | function blog_page_last() { |
| 56 | 2 | global $user; |
| 57 | | |
| 58 | 2 | $output = ''; |
| 59 | 2 | $items = array(); |
| 60 | | |
| 61 | 2 | if (user_access('edit own blog')) { |
| 62 | 0 | $items[] = l(t('Create new blog entry.'), "node/add/blog"); |
| 63 | 0 | } |
| 64 | | |
| 65 | 2 | $output = theme('item_list', $items); |
| 66 | | |
| 67 | 2 | $result = pager_query(db_rewrite_sql("SELECT n.nid, 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)); |
| 68 | 2 | $has_posts = FALSE; |
| 69 | | |
| 70 | 2 | while ($node = db_fetch_object($result)) { |
| 71 | 0 | $output .= node_view(node_load($node->nid), 1); |
| 72 | 0 | $has_posts = TRUE; |
| 73 | 0 | } |
| 74 | | |
| 75 | 2 | if ($has_posts) { |
| 76 | 0 | $output .= theme('pager', NULL, variable_get('default_nodes_main',
10)); |
| 77 | 0 | } |
| 78 | | else { |
| 79 | 2 | drupal_set_message(t('No blog entries have been created.')); |
| 80 | | } |
| 81 | 2 | drupal_add_feed(url('blog/feed'), t('RSS - blogs')); |
| 82 | | |
| 83 | 2 | return $output; |
| 84 | 0 | } |
| 85 | | |
| 86 | | /** |
| 87 | | * Menu callback; displays an RSS feed containing recent blog entries of a
given user. |
| 88 | | */ |
| 89 | 10 | function blog_feed_user($account) { |
| 90 | 2 | $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)); |
| 91 | 2 | $channel['title'] = $account->name . "'s blog"; |
| 92 | 2 | $channel['link'] = url('blog/' . $account->uid, array('absolute' =>
TRUE)); |
| 93 | | |
| 94 | 2 | $items = array(); |
| 95 | 2 | while ($row = db_fetch_object($result)) { |
| 96 | 0 | $items[] = $row->nid; |
| 97 | 0 | } |
| 98 | 2 | node_feed($items, $channel); |
| 99 | 2 | } |
| 100 | | |
| 101 | | /** |
| 102 | | * Menu callback; displays an RSS feed containing recent blog entries of
all users. |
| 103 | | */ |
| 104 | 10 | function blog_feed_last() { |
| 105 | 2 | $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)); |
| 106 | 2 | $channel['title'] = variable_get('site_name', 'Drupal') . ' blogs'; |
| 107 | 2 | $channel['link'] = url('blog', array('absolute' => TRUE)); |
| 108 | | |
| 109 | 2 | $items = array(); |
| 110 | 2 | while ($row = db_fetch_object($result)) { |
| 111 | 0 | $items[] = $row->nid; |
| 112 | 0 | } |
| 113 | 2 | node_feed($items, $channel); |
| 114 | 2 | } |
| 115 | 10 | |