diff modules/blog/blog.module @ 5:2427550111ae 6.2

Drupal 6.2
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:30:08 +0100
parents c1f4ac30525a
children fff6d4c8c043
line wrap: on
line diff
--- a/modules/blog/blog.module	Tue Dec 23 14:29:21 2008 +0100
+++ b/modules/blog/blog.module	Tue Dec 23 14:30:08 2008 +0100
@@ -1,5 +1,5 @@
 <?php
-// $Id: blog.module,v 1.297 2008/01/09 09:51:34 goba Exp $
+// $Id: blog.module,v 1.297.2.1 2008/04/09 21:11:45 goba Exp $
 
 /**
  * @file
@@ -140,19 +140,20 @@
     '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 entries', 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',
   );
@@ -168,6 +169,23 @@
 }
 
 /**
+ * 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().
  *
  * Displays the most recent 10 blog titles.