blog.pages.inc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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' => format_username($account))), PASS_THROUGH);
  12. $build = array();
  13. $query = db_select('node', 'n')->extend('PagerDefault');
  14. $nids = $query
  15. ->fields('n', array('nid', 'sticky', 'created'))
  16. ->condition('type', 'blog')
  17. ->condition('uid', $account->uid)
  18. ->condition('status', 1)
  19. ->orderBy('sticky', 'DESC')
  20. ->orderBy('created', 'DESC')
  21. ->limit(variable_get('default_nodes_main', 10))
  22. ->addTag('node_access')
  23. ->execute()
  24. ->fetchCol();
  25. if (!empty($nids)) {
  26. $nodes = node_load_multiple($nids);
  27. $build += node_view_multiple($nodes);
  28. $build['pager'] = array(
  29. '#theme' => 'pager',
  30. '#weight' => 5,
  31. );
  32. }
  33. else {
  34. if ($account->uid == $user->uid) {
  35. drupal_set_message(t('You have not created any blog entries.'));
  36. }
  37. else {
  38. drupal_set_message(t('!author has not created any blog entries.', array('!author' => theme('username', array('account' => $account)))));
  39. }
  40. }
  41. drupal_add_feed('blog/' . $account->uid . '/feed', t('RSS - !title', array('!title' => $title)));
  42. return $build;
  43. }
  44. /**
  45. * Menu callback; displays a Drupal page containing recent blog entries of all users.
  46. */
  47. function blog_page_last() {
  48. global $user;
  49. $build = array();
  50. $query = db_select('node', 'n')->extend('PagerDefault');
  51. $nids = $query
  52. ->fields('n', array('nid', 'sticky', 'created'))
  53. ->condition('type', 'blog')
  54. ->condition('status', 1)
  55. ->orderBy('sticky', 'DESC')
  56. ->orderBy('created', 'DESC')
  57. ->limit(variable_get('default_nodes_main', 10))
  58. ->addTag('node_access')
  59. ->execute()
  60. ->fetchCol();
  61. if (!empty($nids)) {
  62. $nodes = node_load_multiple($nids);
  63. $build += node_view_multiple($nodes);
  64. $build['pager'] = array(
  65. '#theme' => 'pager',
  66. '#weight' => 5,
  67. );
  68. }
  69. else {
  70. drupal_set_message(t('No blog entries have been created.'));
  71. }
  72. drupal_add_feed('blog/feed', t('RSS - blogs'));
  73. return $build;
  74. }
  75. /**
  76. * Menu callback; displays an RSS feed containing recent blog entries of a given user.
  77. */
  78. function blog_feed_user($account) {
  79. $nids = db_select('node', 'n')
  80. ->fields('n', array('nid', 'created'))
  81. ->condition('type', 'blog')
  82. ->condition('uid', $account->uid)
  83. ->condition('status', 1)
  84. ->orderBy('created', 'DESC')
  85. ->range(0, variable_get('feed_default_items', 10))
  86. ->addTag('node_access')
  87. ->execute()
  88. ->fetchCol();
  89. $channel['title'] = t("!name's blog", array('!name' => format_username($account)));
  90. $channel['link'] = url('blog/' . $account->uid, array('absolute' => TRUE));
  91. node_feed($nids, $channel);
  92. }
  93. /**
  94. * Menu callback; displays an RSS feed containing recent blog entries of all users.
  95. */
  96. function blog_feed_last() {
  97. $nids = db_select('node', 'n')
  98. ->fields('n', array('nid', 'created'))
  99. ->condition('type', 'blog')
  100. ->condition('status', 1)
  101. ->orderBy('created', 'DESC')
  102. ->range(0, variable_get('feed_default_items', 10))
  103. ->addTag('node_access')
  104. ->execute()
  105. ->fetchCol();
  106. $channel['title'] = t('!site_name blogs', array('!site_name' => variable_get('site_name', 'Drupal')));
  107. $channel['link'] = url('blog', array('absolute' => TRUE));
  108. node_feed($nids, $channel);
  109. }