Dotclear

Changeset 748


Ignore:
Timestamp:
02/07/09 17:38:34 (14 years ago)
Author:
Oaz
Message:

renamed 'Antispam'=>'Captcha' + added tools

Location:
plugins/myForms
Files:
3 added
3 edited
1 copied
2 moved

Legend:

Unmodified
Added
Removed
  • plugins/myForms/trunk/Captcha.php

    r728 r748  
    2020# ***** END LICENSE BLOCK ***** 
    2121 
    22 define('MYFORMS_ANTISPAM_MASTER_KEY',sha1_file(dirname(__FILE__).'/../../inc/config.php')); 
     22define('MYFORMS_CAPTCHA_MASTER_KEY','gjlikgnqlnlqhaazaqots'); 
    2323 
    24 class MyFormsAntispam 
     24class MyFormsCaptcha 
    2525{ 
    2626  private $key, $img; 
     
    2828  public function __construct() { 
    2929    if (!function_exists('imagecreatetruecolor')) { 
    30       die('myforms antispam needs GD for creating images'); 
     30      die('myforms captcha needs GD for creating images'); 
    3131    } 
    3232     
     
    6363    imagepng($this->img); 
    6464    $data = base64_encode(ob_get_clean()); 
    65     return "<img src='data:image/png;base64,".$data."' alt='Anti-spam' width='100' height='25' style='vertical-align: middle;' />"; 
     65    return "<img src='data:image/png;base64,".$data."' alt='Captcha' width='100' height='25' style='vertical-align: middle;' />"; 
    6666  } 
    6767   
    6868  public function getReference() { 
    69     return crypt::hmac(MYFORMS_ANTISPAM_MASTER_KEY,$this->key); 
     69    return crypt::hmac(MYFORMS_CAPTCHA_MASTER_KEY,$this->key); 
    7070  } 
    7171   
    7272  public static function isValid($input,$reference) { 
    73     return crypt::hmac(MYFORMS_ANTISPAM_MASTER_KEY,$input) == $reference; 
     73    return crypt::hmac(MYFORMS_CAPTCHA_MASTER_KEY,$input) == $reference; 
    7474  } 
    7575   
    7676  public static function display($refFieldAttr,$inputFieldAttr) { 
    77     $antispam = new MyFormsAntispam(); 
    78     echo $antispam->getImageAsHtml(); 
    79     echo '<input type="hidden" '.$refFieldAttr.' value="'.$antispam->getReference().'" />'; 
     77    $captcha = new MyFormsCaptcha(); 
     78    echo $captcha->getImageAsHtml(); 
     79    echo '<input type="hidden" '.$refFieldAttr.' value="'.$captcha->getReference().'" />'; 
    8080    echo '<input type="text" '.$inputFieldAttr.' value="" />'; 
    8181  } 
  • plugins/myForms/trunk/TplFields.php

    r728 r748  
    2626$core->tpl->addValue('myformsFileField',array('MyFormsTplFields','FileField')); 
    2727$core->tpl->addValue('myformsHiddenField',array('MyFormsTplFields','HiddenField')); 
    28 $core->tpl->addValue('myformsAntispamField',array('MyFormsTplFields','AntispamField')); 
    29 $core->tpl->addBlock('myformsAntispamWarning',array('MyFormsTplFields','AntispamWarning')); 
     28$core->tpl->addValue('myformsCaptchaField',array('MyFormsTplFields','CaptchaField')); 
     29$core->tpl->addBlock('myformsCaptchaWarning',array('MyFormsTplFields','CaptchaWarning')); 
    3030$core->tpl->addBlock('myformsSubmit',array('MyFormsTplFields','Submit')); 
    3131 
     
    9292  } 
    9393 
    94   // Display Antispam Field 
    95   public static function AntispamField($attr,$content) 
     94  // Display Captcha Field 
     95  public static function CaptchaField($attr,$content) 
    9696  { 
    97     return '<?php MyFormsAntispam::display("'.self::GetAttributes($attr,'antispamref').'","'.self::GetAttributes($attr,'antispam').'"); ?>'; 
     97    return '<?php MyFormsCaptcha::display("'.self::GetAttributes($attr,'captcharef').'","'.self::GetAttributes($attr,'captcha').'"); ?>'; 
    9898  } 
    9999 
    100   // Display Antispam Warning when code do not match 
    101   public static function AntispamWarning($attr,$content) 
     100  // Display Warning when Captcha code do not match 
     101  public static function CaptchaWarning($attr,$content) 
    102102  { 
    103     return '<?php if( MyForms::maybeSpam() ) { ?>'.$content.'<?php } ?>'; 
     103    return '<?php if( !MyForms::validateCaptcha() ) { ?>'.$content.'<?php } ?>'; 
    104104  } 
    105105 
  • plugins/myForms/trunk/_define.php

    r728 r748  
    2323     /* Description*/         "Create a custom form page with custom action (save in db, send email, ...)", 
    2424     /* Author */             "Olivier Azeau", 
    25      /* Version */            '1.0', 
     25     /* Version */            '0.1', 
    2626     /* Permissions */        null 
    2727); 
  • plugins/myForms/trunk/_public.php

    r728 r748  
    2020 
    2121require_once("TplCore.php"); 
    22 require_once("Antispam.php"); 
     22require_once("Captcha.php"); 
    2323require_once("TplFields.php"); 
    2424 
     
    3838  private static $formHTML; 
    3939  private static $allFieldsAreValidated; 
     40  private static $captchaIsValidated; 
    4041   
    4142  public static function formGet($args) 
     
    5556  { 
    5657    global $core, $_REQUEST; 
    57     $core->tpl->setPath(array_merge($core->tpl->getPath(),array($core->plugins->moduleRoot("myForms")."/tpl"))); 
     58    $core->tpl->setPath(array_merge($core->tpl->getPath(),array($core->plugins->moduleRoot("myForms")."/default-templates"))); 
    5859     
    5960    self::loadForm(); 
    6061     
    6162    // process  form post 
    62     if( isset($_REQUEST["myforms"]) && !self::maybeSpam() && self::$allFieldsAreValidated ) { 
     63    if( isset($_REQUEST["myforms"]) && self::$captchaIsValidated && self::$allFieldsAreValidated ) { 
    6364      self::$nextFormID = false; 
    6465      self::$errors = array(); 
     
    7778  } 
    7879   
    79   public static function maybeSpam() { 
    80     return isset($_REQUEST["myforms"]["antispam"]) && !MyFormsAntispam::isValid($_REQUEST["myforms"]["antispam"],$_REQUEST["myforms"]["antispamref"]); 
    81   } 
    82    
    8380  private static function loadForm() 
    8481  { 
     
    9895    // field display and validation 
    9996    self::$allFieldsAreValidated = true; 
     97    self::$captchaIsValidated = true; 
    10098    ob_start(); 
    10199    $displayFunction = MyFormsTplCore::GetFunction('Display'); 
     
    104102  } 
    105103   
     104  public static function validateCaptcha() { 
     105    global $_REQUEST; 
     106    $captchaIsValid = !isset($_REQUEST["myforms"]) || MyFormsCaptcha::isValid($_REQUEST["myforms"]["captcha"],$_REQUEST["myforms"]["captcharef"]); 
     107    self::$captchaIsValidated = self::$captchaIsValidated && $captchaIsValid; 
     108    return $captchaIsValid; 
     109  } 
     110   
    106111  public static function validateField($fieldName,$condition) { 
    107112    global $_REQUEST; 
    108     $fieldIsValid = !isset($_REQUEST["myforms"][$fieldName]) || preg_match('#'.$condition.'#', $_REQUEST["myforms"][$fieldName]); 
     113    $fieldIsValid = !isset($_REQUEST["myforms"]) || preg_match('#'.$condition.'#', $_REQUEST["myforms"][$fieldName]); 
    109114    self::$allFieldsAreValidated = self::$allFieldsAreValidated && $fieldIsValid; 
    110115    return $fieldIsValid; 
Note: See TracChangeset for help on using the changeset viewer.

Sites map