Code coverage for /20081101/modules/blog/blog.pages.inc

Line #Times calledCode
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
 */
1210
function blog_page_user($account) {
134
  global $user;
14
154
  drupal_set_title($title = t("@name's blog", array('@name' =>
$account->name)), PASS_THROUGH);
16
174
  $items = array();
18
194
  if (($account->uid == $user->uid) && user_access('create blog content'))
{
204
    $items[] = l(t('Post new blog entry.'), "node/add/blog");
214
  }
220
  elseif ($account->uid == $user->uid) {
230
    $items[] = t('You are not allowed to post a new blog entry.');
240
  }
25
264
  $output = theme('item_list', $items);
27
284
  $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);
294
  $has_posts = FALSE;
30
314
  while ($node = db_fetch_object($result)) {
320
    $output .= node_view(node_load($node->nid), 1);
330
    $has_posts = TRUE;
340
  }
35
364
  if ($has_posts) {
370
    $output .= theme('pager', NULL, variable_get('default_nodes_main',
10));
380
  }
39
  else {
404
    if ($account->uid == $user->uid) {
414
      drupal_set_message(t('You have not created any blog entries.'));
424
    }
43
    else {
440
      drupal_set_message(t('!author has not created any blog entries.',
array('!author' => theme('username', $account))));
45
    }
46
  }
474
  drupal_add_feed(url('blog/' . $account->uid . '/feed'), t('RSS - !title',
array('!title' => $title)));
48
494
  return $output;
500
}
51
52
/**
53
 * Menu callback; displays a Drupal page containing recent blog entries of
all users.
54
 */
5510
function blog_page_last() {
562
  global $user;
57
582
  $output = '';
592
  $items = array();
60
612
  if (user_access('edit own blog')) {
620
    $items[] = l(t('Create new blog entry.'), "node/add/blog");
630
  }
64
652
  $output = theme('item_list', $items);
66
672
  $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));
682
  $has_posts = FALSE;
69
702
  while ($node = db_fetch_object($result)) {
710
    $output .= node_view(node_load($node->nid), 1);
720
    $has_posts = TRUE;
730
  }
74
752
  if ($has_posts) {
760
    $output .= theme('pager', NULL, variable_get('default_nodes_main',
10));
770
  }
78
  else {
792
    drupal_set_message(t('No blog entries have been created.'));
80
  }
812
  drupal_add_feed(url('blog/feed'), t('RSS - blogs'));
82
832
  return $output;
840
}
85
86
/**
87
 * Menu callback; displays an RSS feed containing recent blog entries of a
given user.
88
 */
8910
function blog_feed_user($account) {
902
  $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));
912
  $channel['title'] = $account->name . "'s blog";
922
  $channel['link'] = url('blog/' . $account->uid, array('absolute' =>
TRUE));
93
942
  $items = array();
952
  while ($row = db_fetch_object($result)) {
960
    $items[] = $row->nid;
970
  }
982
  node_feed($items, $channel);
992
}
100
101
/**
102
 * Menu callback; displays an RSS feed containing recent blog entries of
all users.
103
 */
10410
function blog_feed_last() {
1052
  $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));
1062
  $channel['title'] = variable_get('site_name', 'Drupal') . ' blogs';
1072
  $channel['link'] = url('blog', array('absolute' => TRUE));
108
1092
  $items = array();
1102
  while ($row = db_fetch_object($result)) {
1110
    $items[] = $row->nid;
1120
  }
1132
  node_feed($items, $channel);
1142
}
11510