Ticket #954: guestbookWithCaptcha.diff

File guestbookWithCaptcha.diff, 3.1 kB (added by mstahv, 4 years ago)

Modifications to standard guestbook module to use captcha

  • modules/guestbook/conf.ini

    old new  
  • modules/guestbook/classes/GuestbookMgr.php

    old new  
    7676        $input->action         = ($req->get('action')) ? $req->get('action') : 'list'; 
    7777        $input->submitted      = $req->get('submitted'); 
    7878        $input->guestbook      = (object)$req->get('guestbook'); 
     79        $input->captcha      = $req->get('captcha'); 
    7980 
    8081        if ($input->submitted) { 
    8182            require_once 'Validate.php'; 
     
    9293            if (empty($input->guestbook->message)) { 
    9394                $aErrors['message'] = 'Please, fill in the message text'; 
    9495            } 
     96            if ($this->conf['GuestbookMgr']['useCaptcha']) { 
     97                require_once(SGL_MOD_DIR . '/captcha/classes/Captcha.php'); 
     98                if(!Captcha::validateKey($input->captcha)) { 
     99                    $aErrors['captcha'] = 'Please, fill in the characters shown in image.  
     100                        We require this to avoid spam. Sorry for your inconvience.'; 
     101                    $input->useCaptcha = true; 
     102                } 
     103            } 
    95104        } 
    96105        //  if errors have occured 
    97106        if (isset($aErrors) && count($aErrors)) { 
     
    112121        SGL::logMessage(null, PEAR_LOG_DEBUG); 
    113122        $output->pageTitle = 'Guestbook Manager :: Add'; 
    114123        $output->template = 'guestbookAdd.html'; 
     124         
     125        if($this->conf['GuestbookMgr']['useCaptcha']) { 
     126            $output->useCaptcha = true; 
     127        } 
    115128 
    116129        //  build ordering select object 
    117130        $output->guestbook = DB_DataObject::factory($this->conf['table']['guestbook']); 
  • modules/guestbook/templates/guestbookAdd.html

    old new  
    2727                    <textarea cols="40" rows="7" name="guestbook[message]">{guestbook.message}</textarea> 
    2828                </td> 
    2929            </tr> 
     30            {if:useCaptcha} 
    3031            <tr> 
     32                <th align="left">{translate(#Type characters shown in image#)}:</th> 
     33                <td> 
     34                    <div class="error" flexy:if="error[captcha]">{translate(error[captcha])}</div> 
     35                    <div><img src="{makeUrl(##,##,#captcha#)}" alt="captcha" /></div> 
     36                    <input type="text" name="captcha" /> 
     37                </td> 
     38            </tr> 
     39            {end:} 
     40            <tr> 
    3141                <td colspan="2" align="center"> 
    3242                    <input class="wideButton" type="submit" name="submitted" value="{translate(#Add#)}" /> 
    3343                    <input class="wideButton" type="button" name="cancel" value="{translate(#Cancel#)}"