Optionally unpublish new guestbook entries by default
Hetta - September 5, 2007 - 14:02
| Project: | Guestbook |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
How would I go about making all new guestbook entries unpublished, to be discarded or published only after I've seen them?
My current guestbook would be overrun by spammers if left unmoderated -- the drupal captcha would take care of the fly-by-script spammers, but I'm at pagerank 7, which makes my guestbook a very juicy target.
Thanks.

#1
+1
#2
Workaround: in the guestbook table, add a field - say, "moderated".
In the guestbook module, add code that adds a random value to that field (I've added 'y'):
line 456:
$result = db_query("INSERT INTO {guestbook} (id, anonname, anonemail, anonwebsite, author, recipient, message, created, moderated)VALUES(%d, '%s', '%s', '%s', %d, %d, '%s', %d, 'y')", $entryid, $edit['anonname'], $edit['anonemail'], $edit['anonwebsite'], 0, $uid, $message, time());
Ditto for line 462:
$result = db_query("INSERT INTO {guestbook} (id, author, recipient, message, created, moderated)VALUES(%d, %d, %d, '%s', %d, 'y')", $entryid, $user->uid, $uid, $message, time());
Then, on line 302, add a qualifier to the query:
"SELECT g.*, u1.name, u1.data, u1.picture, u2.name as commentbyFROM {guestbook} g
...
WHERE g.recipient = %d
AND g.moderated = 'n'
ORDER BY g.created DESC",
Next, update all current guestbook entries to show "n" for g.moderated - use your mysql editor of choice.
All of that gives all new guestbook entries a "y". Showing new guestbook entries requires you to use phpmysql, mysql or whatever to change that to "n" - or delete the spam, whichever is more appropriate.
(I'd much prefer a drupal admin interface patch, but this quick'n'dirty fix means that the guestbook is usable, nevermind the spammers.)
#3
#4
subscribing
#5
This feature is very necessary on our site. Did you write a custom page to approve guestbook entires Hetta? Any chance you could pass along the code?
-Drew
#6
Nope, I use phpmyadmin.
#7
Is there any other way to moderate guestbook entries without hack the module?
#8
I needed this functionality, too, so I took Hetta's idea of an additional table field and hacked the core to add built-in publish handling instead of using phpMyAdmin.
The field will need to be added to the table manually. I used a tinyint field, not null, default 0, named "published".
The code adds a header reading "UNPUBLISHED ENTRY" and a "Publish entry" link. Actual publishing code is just modified copies of the functions handling delete. I also modified the post-submission message. [As an aside, it would be helpful to have this customizable.]
This is the .module version I built on top of:
// $Id: guestbook.module,v 1.19 2009/03/10 23:14:36 sun Exp $
#9
Has this made it into the stable release Guestbook code yet ?
Very needed feature, as I for one am still on the 'Drupal+modules UI' learning curve without starting the 'How do I get dirty with the code and install a patch' one. :)
#10
No, it's not in there. Stable is still from September 2008 and my work-around is from March 2009.
#11
@Tomws: Could You attach whole module with Your patch? Or make some patch for new dev release? Because I cannot find v 1.19 to apply your patch.
I have old one 1.17 and the newest one is 1.3.2.7 and this one is much more different then 1.19 (there was code clean-up meanwhile)
#12
@Josiv: I just tarballed the directory in use on one of my sites. Attached.
#13
THX!, meanwhile I installed Mollom spam service, after few days (had to submit 'my' type of spam :) ) it seams to handle all spam for guest book...for now, but I will use this version.
#14
Thanks from me too tomws.
Initially I thought that it wasn't working as I couldn't see any buttons to check to activate the 'added feature' but I see it does it automatically. Much appreciated.
I did get this warning though, when I visited the guestbook page as an anonymous user and an authenticated user:
user warning: Unknown column 'g.published' in 'where clause' query: SELECT g.*, u1.uid, u1.name, u1.data, u1.picture, u2.name as commentby FROM cc_guestbook g LEFT JOIN cc_users u1 ON g.author = u1.uid LEFT JOIN cc_users u2 ON g.commentauthor = u2.uid WHERE g.recipient = 0 AND g.published = 1 ORDER BY g.created DESC LIMIT 0, 5 in/sites/all/modules/guestbook/guestbook.module on line 362.
So perhaps there is still something that I need to activate somewhere? Any ideas?
#15
Yes, see comment #8 above where I mentioned that I manually set up a new field on the database. That could have been included in the module hack/patch, but I didn't do it.
#16
Super - thank you. All looks fine. Great feature.
#17
@Tomws:i downloaded your tarballed directory, the module is working absolutely fine except that when i click on "add comment" link it shows me a warning :
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'theme_guestbook_form_comment_form' was given in C:\Program Files\xampp\htdocs\drupal\includes\theme.inc on line 617.
could you please look into the issue
#18
Has this been added to 6.x-2.x-dev ? [ I see there is an update available but I don't want to overwrite the changed file.]
Or will it be added to 6.x-2.0?
#19
@varun_chander: That happens even with the unmodified module, so it's an error in the code. Actually, that function doesn't exist. I didn't check to see if a bug report has been filed against it. FYI, you can cheat and make this go away by adding a dummy function:
function theme_guestbook_form_comment_form($form_state) {/**
* placeholder to eliminate error display:
* warning: call_user_func_array() [function.call-user-func-array]:
* First argument is expected to be a valid callback,
* 'theme_guestbook_form_comment_form' was given in
* /server/path/to/drupal/includes/theme.inc on line 617.
*/
}
This doesn't fix the problem, but it can cover it up.
@I_am_trying_to_...: I just downloaded the latest dev snapshot and it's still not in there.
#20
Here's a patch against the latest dev snapshot. This one also adds in the database field creation, so it should be all automated now.
If others can test this and set the status flag to reviewed and tested (assuming it works for you), then maybe it'll get the attention of the developer and get inserted into the next version.
EDIT:
Additionally, this should probably be extended to include:
1) a modified email body (or even a user-customized email body) in the notification email. Otherwise, it's just the guestbook entry message text and doesn't imply to the recipient that the message needs moderation. I've hacked this on one version but it's not included in the patch.
2) an option to disable prepublish moderation. This should be simply a new variable in the .install along with a few extra wrapping if statements.
3) Maybe move the 'published' field creation to an update function rather than the hook_schema in guestbook.install. I'm not experienced enough to know which way is best. If using an update function, the definition array should probably include a 'initial'=>1 in order to maintain the published status of existing entries.
#21
Just so I am clear... I download the Guestbook dev version AND apply your patches to it, then upload it to the site (to update the other patched dev version there) ??
[Sorry for the d'uh Q but this is the first time I have dabbled with patches and dev versions - usually stick to the 'stable' releases!]
#22
The patch doesn't use an update function, but rather a modification to the .install hook_schema to create the new db field. So I don't know that I'd replace a module on a live site with it. (Actually, I would, but I do take a risk sometimes.) Your process sounds correct, though. If you do it, take the normal backup precautions.
I tend to stick with stable, too, but I think proper patch procedure "requires" them to be generated against the latest version (which is the dev snapshot).
#23
FEEDBACK
I did as in #21. No error messages despite line already having been created in guestbook table as per #8. Can leave a message and delete a message.
A previous message that was already in table appears unaffected.
The only comment I would make is that the button for confirming an edit to a guestbook message says 'send' and not 'save' which is what I would have expected. 'send' implies to me that the automated email advice gets triggered again.
I haven't tried 'publish' yet as was unsure if I could delete the dummy guestbook entry easily if I did this.
#24
The Send/Save naming is in the module already, so that should be a separate bug report or feature request. It's an easy fix, but this patch is only aimed at the pre-publish moderation. There are a couple of other minor problems that need patching, too, but they're also separate from this thread/patch.
The Delete and Edit functions are still available even after publishing an unpublished entry, just like in the unmodified module, so you should be okay to test that fully. It doesn't offer just an Unpublish function, though.
#25
@tomws
exactly as u mentioned it has fixed the problem ....thanx buddy ...cheers life rocks ..!!
another request i would like to put in here ...is that guest book entry form is not getting displayed in another page although i changed in the settings page also ...but each time i select the "Location of entry submission form: " as "separate page " it displays the form below the entries instead of displaying it on separate page ...
could u look into the isssue ...tons of thanx before hand
#26
very nice patch tomws
thanks a lot for this usefull one
-drub4n
#27
@tomws
Hi, your patch is working well except when i am selecting (Location of entry submission form:='separate page'). guestbook module still displaying it in same page instead of new page.
Please help me
#28
@anilbhatt: I just installed the latest dev version without applying the patch and that problem is also present there, so I don't think it's a problem with the patch code. Try opening a new bug report.
#29
Hi,
Actuall i am fresher in drupal, but as a know guestbook module have problem with 'Location of entry submission form:='separate page' , its not working , i try it.
Please help me out.
#30
@anilbhatt: That bug is unrelated to the original feature request. You should file a new bug report rather than modifying an existing request.