blog.pages.inc

  1. 7.x drupal-7.x/modules/blog/blog.pages.inc
  2. 6.x drupal-6.x/modules/blog/blog.pages.inc

Page callback file for the blog module.

File

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