custom spamblock-hook for contact-form plugin

Creating and modifying plugins.
Post Reply
mad-manne
Regular
Posts: 42
Joined: Wed Jan 23, 2008 4:56 pm
Location: Marl, Germany
Contact:

custom spamblock-hook for contact-form plugin

Post by mad-manne »

Hi s9y-community,
I am using the contact-form plugin, but didn't like the fact, that the text above the submit-button is the same as for normal comments. See this example:
Contact-Form wrote:Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.


To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
Both text-blocks are "triggered" via the frontend_comment-hook from within the templates of the contact-form plugin.
So I decided to give it a try, hacked around a bit and ended up with a new spamblock-hook to enable a custom message for the contact-form.

From my first tests, this seems to work but anyway I would like to present my changes to the s9y-wizards, in case I have made any mistake. If anyone else likes my changes, maybe they can find their way into the contact-from plugin someday ???

So, here's what I did ...

OPEN
plugins/serendipity_event_spamblock/serendipity_event_spamblock.php

FIND

Code: Select all

$propbag->add('version',       '1.68');
$propbag->add('event_hooks',    array( 
    'frontend_saveComment' => true,    
    'external_plugin'      => true,    
AFTER, ADD

Code: Select all

    'submit_contactform'   => true,
FIND within the function event_hook()

Code: Select all

case 'frontend_comment':
COPY
Make a copy of that complete case-block and rename it to:

Code: Select all

case 'submit_contactform':
In the copied block I SEARCHED for:

Code: Select all

echo '<br />' . PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC . '<br />';
and REPLACED it with this:

Code: Select all

echo '<br />My custom SPAMblock-message blablabla ...<br />';
OPEN
plugins/serendipity_event_contactform/plugin_contactform.tpl

FIND

Code: Select all

{serendipity_hookPlugin hook="frontend_comment" data=$commentform_entry}
REPLACE WITH

Code: Select all

{serendipity_hookPlugin hook="submit_contactform" data=$commentform_entry}
OPEN
plugins/serendipity_event_contactform/plugin_dynamicform.tpl

FIND

Code: Select all

{serendipity_hookPlugin hook="frontend_comment" data=$commentform_entry}
REPLACE WITH

Code: Select all

{serendipity_hookPlugin hook="submit_contactform" data=$commentform_entry}
I had to learn, that this was not the complete trick, because smarty complained about an illegal hook :roll:
OPEN
include/functions_smarty.inc.php

FIND

Code: Select all

    static $hookable = array('frontend_header',
                             'entries_header',
                             'entries_footer',
AFTER, ADD

Code: Select all

                             'submit_contactform',
I am pretty sure, that my last hack(on the functions_smarty.inc.php) has a better(official) way, how it can be achieved. I guess that these hooks get added during plugin-installation, but as I added a $propbag->add('event_hooks',-Line manually I had to add that to the smarty-file too ?!

I have also tried to use a construct like this in the new case-block

Code: Select all

echo '<br />' . PLUGIN_CONTACTFORM_SPAMBLOCK_MESSAGE . '<br />';
But the constant that I defined in the language-file of the contact-form plugin is apparently unknown in the focus of the spamblock-plugin.

I am looking forward to your feedback ...
Cheers,
Manfred
Try not. Do or do not. There is no try. (YODA)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: custom spamblock-hook for contact-form plugin

Post by garvinhicking »

Hi!

Those are a lot of changes, that I'd try to avoid. You'd have to redo them everytime after an s9y update.

I'd solve it like this: Only edit the template files, add your custom comment directly into the .tpl files. Hide the default outputs via CSS, by using

Code: Select all

.serendipity_commentDirection {
 display: none
}
To only hide it for the contact form, I'd add a <div class="contactform"> inside the whole .tpl file, so that you can use a CSS like this:

Code: Select all

.contactform .serendipity_commentDirection {
 display: none
}
so that you don't hide the comment information on usual blog entries.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
mad-manne
Regular
Posts: 42
Joined: Wed Jan 23, 2008 4:56 pm
Location: Marl, Germany
Contact:

Post by mad-manne »

Hi Garvin,
thanks for your quick response :wink:

Sadly I must report, that this also hides the spam-block-graphic and the text-box to enter the spamblock-code :roll: As a result, I am unable to send the contact-form, because the script complains, that the spamblock-entry is incorrect.

Actually I wouldn't mind remembering my changes and recode my solution after every update, but anyway I'd be interested in an smarter solution :mrgreen:

Any other ideas?

Cheers,
Manfred
Try not. Do or do not. There is no try. (YODA)
Post Reply