From 8903cda5ca13f96aad3d9a074937644347620054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Hojtsy?= Date: Wed, 24 Oct 2007 11:17:01 +0000 Subject: [PATCH] #179519 by chx, webchick and Desbeers: fix blog/[uid] to only display posts for that user and also set proper title --- modules/blog/blog.module | 10 ++----- modules/blog/blog.pages.inc | 59 +++++++++++++------------------------ modules/user/user.module | 2 +- 3 files changed, 23 insertions(+), 48 deletions(-) diff --git a/modules/blog/blog.module b/modules/blog/blog.module index 53dbbc716a6..e43a804356e 100644 --- a/modules/blog/blog.module +++ b/modules/blog/blog.module @@ -145,22 +145,16 @@ function blog_menu() { 'type' => MENU_SUGGESTED_ITEM, 'file' => 'blog.pages.inc', ); - $items['blog/%user/view'] = array( - 'title' => 'Blogs', - 'page callback' => 'blog_page_user', - 'access arguments' => array('access content'), - 'type' => MENU_CALLBACK, - 'file' => 'blog.pages.inc', - ); $items['blog/%user_current'] = array( 'title' => 'My blog', + 'page callback' => 'blog_page_user', 'page arguments' => array(1), - 'access arguments' => array('edit own blog'), 'file' => 'blog.pages.inc', ); $items['blog/%user/feed'] = array( 'title' => 'Blogs', 'page callback' => 'blog_feed_user', + 'page arguments' => array(1), 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, 'file' => 'blog.pages.inc', diff --git a/modules/blog/blog.pages.inc b/modules/blog/blog.pages.inc index 996db4d574f..14951b85556 100644 --- a/modules/blog/blog.pages.inc +++ b/modules/blog/blog.pages.inc @@ -12,37 +12,27 @@ function blog_page_user($account) { global $user; - $account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1)); + drupal_set_title($title = t("@name's blog", array('@name' => $account->name))); - if (!empty($account->uid)) { - drupal_set_title($title = t("@name's blog", array('@name' => $account->name))); + $items = array(); - if (($account->uid == $user->uid) && user_access('edit own blog')) { - $output = '
  • '. l(t('Post new blog entry.'), "node/add/blog") .'
  • '; - } - else if ($account->uid == $user->uid) { - $output = '
  • '. t('You are not allowed to post a new blog entry.') .'
  • '; - } - - if ($output) { - $output = ''; - } - else { - $output = ''; - } - - $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); - while ($node = db_fetch_object($result)) { - $output .= node_view(node_load($node->nid), 1); - } - $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); - drupal_add_feed(url('blog/'. $account->uid .'/feed'), t('RSS - !title', array('!title' => $title))); - - return $output; + if (($account->uid == $user->uid) && user_access('edit own blog')) { + $items[] = l(t('Post new blog entry.'), "node/add/blog"); } - else { - drupal_not_found(); + else if ($account->uid == $user->uid) { + $items[] = t('You are not allowed to post a new blog entry.') .''; } + + $output = theme('item_list', $items); + + $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); + while ($node = db_fetch_object($result)) { + $output .= node_view(node_load($node->nid), 1); + } + $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); + drupal_add_feed(url('blog/'. $account->uid .'/feed'), t('RSS - !title', array('!title' => $title))); + + return $output; } /** @@ -67,19 +57,10 @@ function blog_page_last() { /** * Menu callback; displays an RSS feed containing recent blog entries of a given user. */ -function blog_feed_user($uid = 0) { - global $user; - - if ($uid) { - $account = user_load(array('uid' => $uid, 'status' => 1)); - } - else { - $account = $user; - } - - $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"), $uid, 0, variable_get('feed_default_items', 10)); +function blog_feed_user($account) { + $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)); $channel['title'] = $account->name ."'s blog"; - $channel['link'] = url("blog/$uid", array('absolute' => TRUE)); + $channel['link'] = url('blog/'. $account->uid, array('absolute' => TRUE)); while ($row = db_fetch_object($result)) { $items[] = $row->nid; diff --git a/modules/user/user.module b/modules/user/user.module index 801f8f5f2fd..193bec33b08 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1068,7 +1068,7 @@ function user_init() { } function user_current_load($arg) { - return $arg ? user_load($arg) : user_load($GLOBALS['user']->uid); + return $arg ? user_load($arg) : FALSE; } function user_current_to_arg($arg) {