1

Topic: captcha helper

Hi,

I created a simple captcha helper for Wolf cms. It makes use of the good old Securimage.
Having a captcha helper in Wolf cms makes implementing captcha's for individual plug-ins redundant and provides a consistent site-wide captcha.

Download: https://github.com/downloads/Forage/wolfcms/captcha.zip
Extract the complete contents of the zip file in "~/wolf/helpers/".

Usage example front-end (page or plug-in supplying HTML output):

<?php
    use_helper('Captcha');
    $captcha = new Captcha();

    echo '<form method="post" name="lalala">';
    echo $captcha->getCaptcha();
    echo '<input type="submit" />';
    echo '</form>'
?>

Back-end (page, plug-in etc.):

<?php
    use_helper('Captcha');
    $captcha = new Captcha();
    echo $captcha->isValid() ? 'You go girl!' : 'Nah, try again';
?>

Notes:

  • It could use a method to check whether the captcha was used on a page in the first place but I didn't came up with a solid solution for it so far

  • Audio playback button is not implemented yet. I find Securimage's solution rather ugly

  • Additional documentation for each function can be found in the helper file

  • The helper is relatively large in size, despite its simplicity. This is because I have not touched securimage's source in any way

Is this helper a candidate for inclusion in Wolf cms? If yes, what does it take in terms of code style and should I strip securimage of it's audio capabilities and unused files to reduce its size?

Please take it for a spin, test it, and provide comments and suggestions.

I hope I don't have to tell you that you should not distribute it as is yet or apply it in a production environment. It's simply not (officially) stable yet.

Last edited by Forage (2012-02-21 17:38)

Thumbs up

2

Re: captcha helper

Is it that perfect that nothing needs commenting on or is no one interested? :-S

Btw, is mvdkleijn in hibernation?

Thumbs up

3

Re: captcha helper

Forage wrote:

Is it that perfect that nothing needs commenting on or is no one interested? :-S

Btw, is mvdkleijn in hibernation?

Its interesting to me, i'll give it a try to see how it works out.
Audio playback would be welcome though.

BTW, it seems mvdkleijn is on vacation:
http://www.wolfcms.org/forum/post12517.html#p12517
And the year just started wink

4

Re: captcha helper

Forage wrote:

Is it that perfect that nothing needs commenting on or is no one interested? :-S

Sorry, I overlooked this one.

Forage wrote:

Is this helper a candidate for inclusion in Wolf cms? If yes, what does it take in terms of code style and should I strip securimage of it's audio capabilities and unused files to reduce its size?

Can't tell you if it's a candidate for inclusion as Wolf already has some sort of lightweight captcha (see comment plugin) which needs full rewrite (pending for 0.1.0). IMO, it's a bit big (1MB) so if it stays that way then the answer will probably be "no".

Anyway, we do have third-party helpers (Pagination, Install-helper) so you can offer it for the community like that.

Forage wrote:

Btw, is mvdkleijn in hibernation?

big_smile sort of, he's on a 2 week vacation. Should be back next week.

My Wolf CMS related blog Project 79 | Wolf CMS Docs

5

Re: captcha helper

Fortron wrote:

Audio playback would be welcome though.

I find its current configuration a bit dirty.
I've send some suggestions to the developer of Securimage earlier today. Lets see how that works out first.

jackie wrote:

Can't tell you if it's a candidate for inclusion as Wolf already has some sort of lightweight captcha (see comment plugin) which needs full rewrite (pending for 0.1.0).

Unfortunately that captcha can not be used by other plugins as easily. Those plugins that do need a captcha therefore resort to creating their own implementation again. This has multiple captcha styles as a result.

I've been meaning to do that rewrite for a long time now (as you can see). Got quite distracted though :-$
I'm working on it again now, hence the creation of a general captcha helper as one of the steps.

jackie wrote:

IMO, it's a bit big (1MB) so if it stays that way then the answer will probably be "no".

I know :-( This is mainly due to the audio playback support. Removal of some unused files will help as well, but at this stage I left Securimage completely intact for testing purposes.

I'd suggest stripping the helper, including audio playback, and provide a separate "full" helper for download.

Last edited by Forage (2012-02-09 14:02)

Thumbs up

6

Re: captcha helper

Back from China... (and from being down and out with the flu right after it)

I like the idea but jackie is right about the 1MB size. Having said that, I was looking at creating a generic Captcha helper in the past so I'm far from opposed to the idea. Looking forward to your next iteration. smile

Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution or see our financial report first.

7

Re: captcha helper

mvdkleijn wrote:

Back from China... (and from being down and out with the flu right after it)

Welcome back, good to hear you're feeling better now.

mvdkleijn wrote:

Looking forward to your next iteration. smile

I've updated the helper:

  • Audio files not included any more

  • Removed unused files from Securimage

  • Implemented audio playback button display

  • Introduced Captcha->challenged() to check if the user was challenged by a captcha

  • Updated Securimage code base to latest from trunk

  • Introduced new icons for refresh and play buttons

  • Improved SWF for audio playback to allow users to supply a custom icon image file through parameter icon_file

  • Added optional Captcha parameters refreshIcon, playIcon, refreshIconWidth, refreshIconHeight, playIconWidth, playIconHeight

The total helper size (compressed) is now reduced to 250kB, 1/4 of its original.

The icon and SWF changes are up for approval at Securimage and are likely to be included in Securimage by default in the future.

The audio playback button is not displayed by default when using getCaptcha(). Two conditions need to be met:

  • Set the showPlayAudioButton helper option to TRUE

  • A sub-folder, with language code as name, needs to be added to ~/wolf/helpers/securimage/audio/ containing the audio files of preference ('en' is default)

The appropriate language files can be downloaded from http://www.phpcaptcha.org/download/

At the moment I'm including links in the front-end HTML to image, php and swf files present in the helper folder. Is this recommended or is there a mode appropriate way?
Dispatcher rules are not an option as far as I can tell. Wolf would either gain a helper dependency or the Captcha helper needs to be called on each page load.

Last edited by Forage (2012-03-04 15:25)

Thumbs up

8

Re: captcha helper

Forage wrote:

At the moment I'm including links in the front-end HTML to image, php and swf files present in the helper folder. Is this recommended or is there a mode appropriate way?
Dispatcher rules are not an option as far as I can tell. Wolf would either gain a helper dependency or the Captcha helper needs to be called on each page load.

I'm wondering if this shouldn't be a Plugin rather than a Helper... Helpers are generally considered single file items. There's no reason why a plugin can't depend on another plugin after all... its easy enough for a plugin dev to use

if (Plugin::isEnabled('captcha')) { ... }
Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution or see our financial report first.

9

Re: captcha helper

mvdkleijn wrote:

I'm wondering if this shouldn't be a Plugin rather than a Helper... Helpers are generally considered single file items. There's no reason why a plugin can't depend on another plugin after all... its easy enough for a plugin dev to use

if (Plugin::isEnabled('captcha')) { ... }

I'm happy to make a plug-in of it...but you were initially against the idea ;-) (see Comments plug-in discussion)

General but occasional functionality has thus far only been implemented as a helper, and your point about the additional plug-in overhead still holds. While the current direct linking from the front-end to "internal" files isn't as clean as should be, is it worth sacrificing the efficiency of a helper?

Thumbs up

10

Re: captcha helper

Lemme think about it. smile

Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution or see our financial report first.

11

Re: captcha helper

mvdkleijn wrote:

Lemme think about it. smile

I did some more pondering about it as well and imho the cleanest solution remains the switch to a plugin while the most efficient and easiest solution is a helper.

Some ideas that came to mind are:

  • Introduce a dispatcher table in which dispatcher rules can be inserted. Helpers, however, have no initialization stage like enabling a plugin and you'll loose the ability to determine all dispatcher rules by looking at the code.

  • Introduce a general dispatcher rules file. You'd have to perform a manual action by adding the new rule(s) to the file.

  • Make Wolf CMS dependant on the helper. If it is considered a core helper, dispatcher rules for the helper can be added elsewhere in the Wolf CMS code as well

  • Introduce a URL scheme which automatically acts like a (basic) dispatcher rule based on the provided URL parameters. It would require a reserved URL path but other then that it could actually proof to be quite handy to have. The drawback would be that you'd be giving away some hints about the Wolf internals.

  • Simply ignore the fact that there's direct linking to "internal" files taking place from the front-end. A bit dirty if you ask me. It should not be recommended but it wouldn't surprise me if one or more (user contributed) plugins are already doing this.

Last edited by Forage (2012-03-11 13:30)

Thumbs up

12

Re: captcha helper

Since this is intended as a generic captcha tool, possibly extensible in the future with more than one captcha type, AND is will possibly require multiple interactions... I think a plugin with a controller would be best.

Things like a dispatcher rules file or standard (fixed) paths are not acceptable for Wolf CMS.

Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution or see our financial report first.