From 21576021bfe440a0a02b0c179440f00e7182d321 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Wed, 23 Apr 2008 20:01:56 +0000 Subject: - Patch #249546 by pwolanin: rip menu access inheritance -- was already committed to D6. --- modules/blog/blog.module | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'modules/blog/blog.module') diff --git a/modules/blog/blog.module b/modules/blog/blog.module index d483d48f9..884b3745b 100644 --- a/modules/blog/blog.module +++ b/modules/blog/blog.module @@ -140,19 +140,20 @@ function blog_menu() { 'type' => MENU_SUGGESTED_ITEM, 'file' => 'blog.pages.inc', ); - $items['blog/%user_current'] = array( + $items['blog/%user_uid_optional'] = array( 'title' => 'My blog', 'page callback' => 'blog_page_user', 'page arguments' => array(1), - 'access callback' => 'user_access', - 'access arguments' => array('create blog content', 1), + 'access callback' => 'blog_page_user_access', + 'access arguments' => array(1), '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'), + 'access callback' => 'blog_page_user_access', + 'access arguments' => array(1), 'type' => MENU_CALLBACK, 'file' => 'blog.pages.inc', ); @@ -167,6 +168,23 @@ function blog_menu() { return $items; } +/** + * Access callback for user blog pages. + */ +function blog_page_user_access($account) { + // The visitor must be able to access the site's content. + // For a blog to 'exist' the user must either be able to + // create new blog entries, or it must have existing posts. + return $account->uid && user_access('access content') && (user_access('create blog entries', $account) || _blog_post_exists($account)); +} + +/** + * Helper function to determine if a user has blog posts already. + */ +function _blog_post_exists($account) { + return (bool)db_result(db_query_range(db_rewrite_sql("SELECT 1 FROM {node} n WHERE n.type = 'blog' AND n.uid = %d AND n.status = 1"), $account->uid, 0, 1)); +} + /** * Implementation of hook_block(). * -- cgit v1.2.3