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 CreditAttribution: 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 CreditAttribution: dgtlmoon commentedHi there, well spotted, i have supplied a new patch
cheers
Comment #4
ChrisKennedy CreditAttribution: 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 CreditAttribution: msameer commentedFixed the style and removed the extra hunk.
Comment #6
ChrisKennedy CreditAttribution: ChrisKennedy commentedThat version still had several errors... here's an updated patch.
Comment #7
Junyor CreditAttribution: 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 CreditAttribution: ChrisKennedy commentedParagraph it is.
Comment #9
Freso CreditAttribution: Freso commentedIs there a reason for not using
theme_username()
? I'm thinkingarray('%name' => theme_username($account))
would be good, assuming$account
is a user object. :)Comment #10
Freso CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: birdmanx35 commentedAh, okay, thanks Rob.
Comment #22
dgtlmoon CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: GreenLED commentedWhich patch is for 6.x, dev?
or
» Respectfully, GreenLED
»
Comment #40
catch#35 - blog_no_posts-139290-35.patch
Comment #41
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.
Comment #42
Dries CreditAttribution: Dries commentedComment #43
dgtlmoon CreditAttribution: dgtlmoon commented@dries: so this is HEAD, this bug should be 6.x ?
Comment #44
Junyor CreditAttribution: Junyor commented@dgtlmoon: Please read the full issue. A patch was committed to the DRUPAL-6 branch on February 8th.
Comment #45
Junyor CreditAttribution: Junyor commentedComment #46
dgtlmoon CreditAttribution: 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) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.