Hi there, When a user has no blog posts, a simple message should be present, otherwise it looks like the system encountered an error, heres my simple patch, it will apply for 4.x and 5.x
--- blog.module.cvs 2007-04-26 14:53:23.000000000 +1000
+++ blog.module 2007-04-26 14:54:39.000000000 +1000
@@ -148,9 +148,14 @@
}
$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);
+ if ( db_num_rows($result) > 0 ) {
+ while ($node = db_fetch_object($result)) {
+ $output .= node_view(node_load($node->nid), 1);
+ }
+ } else {
+ $output .= t('
', array ('%name' => ucwords($account->name)) );
}
+
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
drupal_add_feed(url('blog/'. $account->uid .'/feed'), t('RSS - !title', array('!title' => $title)));
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | blog_no_posts-139290-35.patch | 2.33 KB | cburschka |
| #29 | blog_noposts-29.patch | 2.28 KB | robloach |
| #17 | blog_noposts.patch | 2.31 KB | matt@antinomia |
| #14 | blog_noposts_2.patch | 1.36 KB | robloach |
| #10 | blog_noposts_1.patch | 1.21 KB | Freso |
Comments
Comment #1
stevenpatzComment #2
ChrisKennedy commentedThis looks like a good idea; I agree that the current blank page is confusing. The patch needs a few tweaks though:
Comment #3
dgtlmoon commentedHi there, well spotted, i have supplied a new patch
cheers
Comment #4
ChrisKennedy commentedCloser, but the "not yet made any blog posts" line still has coding style errors due to the extra spacing. Also that second extra hunk needs to be removed.
Comment #5
msameer commentedFixed the style and removed the extra hunk.
Comment #6
ChrisKennedy commentedThat version still had several errors... here's an updated patch.
Comment #7
junyor commentedIs there any reason you're using a DIV instead of a P? A P element would be more semantically correct.
Comment #8
ChrisKennedy commentedParagraph it is.
Comment #9
Freso commentedIs there a reason for not using
theme_username()? I'm thinkingarray('%name' => theme_username($account))would be good, assuming$accountis a user object. :)Comment #10
Freso commentedPatch doesn't apply:
So I re-rolled. I'm having problems with blog.module though - neither this patch nor the one at issue 179519 work for me. :(
Comment #11
gábor hojtsyHm, reusing theme_username() seems to be a good idea indeed. But that might spit out HTML, so it should be checked, whether it escapes the name properly, so we can use !name.
Comment #12
bennybobw commentedtheme_username spits out escaped html e.g.
note that a blank page comes up also with /blog
I think this patch should be expanded to include that page as well.
Comment #13
robloachI had troubles applying this patch, and db_num_rows() was removed.
Comment #14
robloachDid a couple things here...
Comment #15
catchEmpty blogs by other users now generate page not found (which seems sensible to me) so the else statement is a bit redundant. I'd support the "You have not made any blog posts" message for global $user though.
Comment #16
robloachThere are four use cases with the patch I uploaded...
The redundant else you were talking about there is why we're talking about this. We want to display a message when a user doesn't have any blog posts, and this patch does just that, that else does that. I don't think there's anything missing from this patch...
Comment #17
matt@antinomia commentedRob's patch works for me. The attached patch adds similar functionality to the global blog page if there are no posts. A new user to Drupal would likely find this more helpful than a blank screen.
Comment #18
robloachAhh, sounds good!
Comment #19
birdmanx35 commentedThis is a feature request currently, and it adds strings, so I am moving this to 7.x-dev.
Comment #20
robloachAlthough it is kind of a feature request, it doesn't break any strings. Adding strings is okay, changing them is not.
Comment #21
birdmanx35 commentedAh, okay, thanks Rob.
Comment #22
dgtlmoon commentedYes it adds a string but what does it matter, it really cleans up the experience in an a module that goes way back in drupal's development history
Comment #23
robloachHow to test:
blog/1... See your name and "Post new blog entry"blog... And see an empty page saying "Blogs"blog/#, where # is the new user's ID and see Access Deniedblog/1... See your name, "You have no made any blog posts.", and "Post new blog entry"blog... And see "No one has made any blog posts"Comment #24
keith.smith commentedJust on a visual review of the patch, we've been referring to blog posts as "blog entries". And, while I like "posted" personally, we have "Create content", and usually use "post" as a noun rather than verb. (Although that isn't consistent, as the button on this comment page says "Post comment".) So, the strings, if they were to get in post-string-freeze, would need to say something like:
Comment #25
keith.smith commentedMy apologies -- on reflection and a bit of grepping, I was quite wrong on my assessment of the use of "Post". I count five instances of using "Post" as a piece of content, and four using "Post" as the act of creating the content. And, more importantly, blog module does say "Post new blog entry" and not "Create new blog entry".
Comment #26
robloachI think we should change those strings. The blog module has been around since the beginning, and needs as much cleaning as it can get.
Comment #27
dgtlmoon commented+1 @ rob loach :)
Comment #28
panchoThis is not a new feature, it's a bug indeed. Needs some more eyes on it, though.
Comment #29
robloachThis patch features the code changes in #17, as well as Keith's suggested string fixes in #24.
Comment #30
GreenLED commentedRan the patch.
Before:
1. Clicked through to "/blog/1"
After:
1. Message appeared,
As expected.
At this quick glance, the patch looks like it's ready to me.
Are there any other pages, etc. that are affected by this
patch or is this the only one?
» Respectfully, GreenLED
»
Comment #31
junyor commentedComment #32
catchGreenLED: only /blog - otherwise feel free to mark RTBC if you think it fixes the issue appropriately.
Comment #33
cburschkaPatch applies to DRUPAL-6. All three messages (global blog, your own blog, someone else's blog) work fine. I believe this makes two reviews.
(PS: Rob, the -p switch on diff is useful in displaying the header of the function a change was made in. Unlike -u, I'm not sure it's required practice, but it's very helpful.)
Comment #34
gábor hojtsy- 'status' is the default type, so we do not specify that in other places.
- instead of $num_rows, we should use $num_posts or something like that. I understand we are not displaying all posts, so maybe $num_displayed or something like that sounds better.
Comment #35
cburschka- 'status' removed
- $num_rows changed to $has_posts, as it is a boolean that only becomes TRUE if there is at least one post.
I tested this, but of course another review couldn't hurt.
Comment #36
gábor hojtsySince the previous version was well tested and this is only a coding style change, I committed #35. Thanks. RTBC for 7.x.
Comment #37
GreenLED commentedAdjustments:
1. Clicked through to "/blog/"
2. Message appears as expected.
3. Successfully tested using clean url on.
4. Successfully tested using clean url off.
It looks like we're ready to add this.
» Respectfully, GreenLED
»
Comment #38
gábor hojtsyComment #39
GreenLED commentedWhich patch is for 6.x, dev?
or
» Respectfully, GreenLED
»
Comment #40
catch#35 - blog_no_posts-139290-35.patch
Comment #41
dries commentedCommitted to CVS HEAD. Thanks.
Comment #42
dries commentedComment #43
dgtlmoon commented@dries: so this is HEAD, this bug should be 6.x ?
Comment #44
junyor commented@dgtlmoon: Please read the full issue. A patch was committed to the DRUPAL-6 branch on February 8th.
Comment #45
junyor commentedComment #46
dgtlmoon commentedGábor Hojtsy updated the bug to 'ready to be comitted' but said he committed it in the comment, i guess i oversighted his comment somewhere in the 46 posts..
Comment #47
robloachThis issue is fixed...
Comment #48
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.