Development

Changeset 19570 for plugins/sfCryptoCaptchaPlugin

You must first sign up to be able to contribute.

Show
Ignore:
Timestamp:
06/26/09 01:34:44 (4 years ago)
Author:
henearkrxern
Message:

Update to version 0.0.6

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfCryptoCaptchaPlugin/trunk/README

    r19563 r19570  
    119119    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema); 
    120120 
     121## Configuration details 
     122 
     123Here are some useful configuration details 
     124 
     125The bg_img options can have many values: 
     126 
     127 1. it can be a boolean (disable background image)  
     128 2. it can be a image name (path from the symfony root)  
     129 3. or it can be a file name (an image will be randomly chosen in the file) 
     130 
     131Here's how it looks in the configuration app.yml file 
     132 
     133    [yaml] 
     134    --- 
     135    bg_img:         false                                                  #1 
     136    bg_img:         '/plugins/sfCryptoCaptchaPlugin/media/bg/leaf_bg.png'  #2 
     137    bg_img:         '/plugins/sfCryptoCaptchaPlugin/media/bg'              #3 
     138 
     139When setting the letters for the captcha, be careful to exclude characters that look alike, 
     140for example: `o` and `0` or `B` and `8` (when there is noise and funky fonts, there symbols quickly look alike). 
     141 
     142``You want to make it difficult for robots but not for your users.`` 
     143 
     144For configurations needing paths (backgrounds, refresh button, fonts) 
     145 
     146  * Be careful, the path to the refresh image must be from the __web__ root and not the symfony root dir. 
     147  * On the contrary, the path to the background images and the fonts is relative to the symfony root and the options need to start by a '/' 
     148 
     149The error messages are internationalized if the i18n is turned on for symfony. 
     150The images displayed will be in the `/plugins/sfCryptoCaptchaPlugin/media/error/%SF_CULTURE%/...` 
     151directory and the extension used will be the same as the configured `format`. If there is no i18n 
     152active, the three images will be taken from the `/plugins/sfCryptoCaptchaPlugin/media/error/` directory. 
     153 
     154The three needed images are: 
     155 
     156  * `unknown.xxx`   For unknown errors 
     157  * `too_many.xxx`  For too many requests per session (maximum 1000 requests per session) 
     158  * `refresh.xxx`   For too fast refreshes 
     159 
     160Each one of there images __must__ be present in each culture folder or in the main error folder. 
     161By default, a french and english version is provided. You can add as many languages and needed and customize the error images in any graphic editor(Gimp, Photoshop ...) as long as it is in jpeg, png or gif format. 
    121162 
    122163## Dependencies 
     
    134175 
    135176 * The pear install seems to malfunction :( 
    136  * The fonts directory is under the web directory so if you know the font name, you can download it (not very good) 
    137177 * The functionality to reuse a captcha (by saving it in clear in the user session) has been removed from the original library, it could be nice to code it back in and add an option to activate that feature - still, this is a less secure method than making a new captcha everytime. 
    138  * The display of the error messages "refreshing too fast" is not localized and is cut if the catpcha is too small. 
    139178 
    140179## Troubleshooting 
     
    147186      * you have executed the `plugin:publish-assets` command (under Windows, you may have to manually copy the sfCryptoCaptchaPlugin/web to the web/ directory) 
    148187      * the fonts directory is properly configured (in the `app.yml` file) 
    149       * the web/sfCryptoCaptchaPlugin/fonts direcotry and sub-directories have the proper permissions 
     188      * the SF_ROOT/plugins/sfCryptoCaptchaPlugin/fonts directory and sub-directories have the proper permissions 
    150189      * all the permissions of the plugin are correct 
    151190      * if there is still no image, check that the image is correctly destroyed in the sfCryptoCaptcha class with `imagedestroy($this->image);` line 220 
     
    154193    * the final paths are correct (/captcha for the image and /sfCryptoCaptchaPlugin/images/refresh.png for the refresh image) 
    155194    * there is no conflict in the url (/captcha not used by some other plugin or module of the same name) 
    156     * there is no special :format applied in the URL (the helper does not (yet) handle extensions/formats[like .html, .php etc.]) 
    157   * after checking all this, if it still doesn't work, you'll have to check everything directly in the source of the plugin. If you notice a glitch or a bug, please contact-me [henearkrxern [at] hotmail.fr] and I'll update the script. Thanks :) 
     195  * after checking all this, if it still doesn't work, you'll have to check everything directly in the source of the plugin. If you need help or you notice a glitch or a bug, please contact-me [henearkrxern [at] hotmail.fr] and I'll update the script. Thanks :) 
    158196 
    159197If your captcha does not display correctly: 
    160198 
    161   * If all the characters are not in the image, play with the character size settings(char_min_size and char_max_size) and the character spacing (char_px_spacing) and/or with the image size. 
     199  * If all the characters are not in the image (overflow), play with the character size settings(char_min_size and char_max_size) and the character spacing (char_px_spacing) and/or with the image size. 
    162200  * Play with some options and see what you come up with, hopefully, you should find where the problem is coming from. 
     201  * You have enabled the background image but your background is black: check that the path is correct and that it starts with a "/". 
     202  * If there is an error with the font (usually there will be no image - but in case you run out of problem-ideas, check the path to the font files and that it starts with a "/". 
    163203 
    164204## Copyright 
  • plugins/sfCryptoCaptchaPlugin/trunk/config/app.yml

    r19564 r19570  
    1010    bg_blue:                          255                 #quantity of blue color (0->255) 
    1111    bg_transparent:                   false               #transparent background - only works for PNG images 
    12     bg_img:                           false               # image or file (randomly choses an image in the file) [can be false, image or file path
     12    bg_img:                           false               # boolean or image or file (randomly choses an image in the file) [path from sf root
    1313    bg_border:                        true                #add a border or not 
    14   #Paths 
    15     img_dir:                          '/sfCryptoCaptchaPlugin/images' #directory of the images in the web directory 
    1614  #Characters 
    1715    char_red:                         0                   # quantity of red color  (0->255) 
     
    2725    char_vertical_offset:             true                # add a random vertical offset to letters 
    2826  #Fonts 
    29     char_fonts:                       [luggerbu.ttf,SCRAWL.ttf,Alanden_.ttf] # the randomly used fonts to generate the characters 
    30     char_fonts_dir:                   '/sfCryptoCaptchaPlugin/fonts/' #directory containing the fonts in the web directory 
     27    char_fonts:                       [luggerbu.ttf,SCRAWL.ttf,Alanden_.ttf] # the randomly used fonts to generate the characters 
     28    char_fonts_dir:                   '/plugins/sfCryptoCaptchaPlugin/media/fonts/' # directory containing the fonts in the symfony root directory 
    3129    error_font:                       'arial.ttf'         # font used for error messages 
    3230  #Authorized characters 
     
    5856    noise_color:                      3                   # noise color to use (1=character color, 2= background color, 3= random color) 
    5957    noise_on_top:                     false               # if noise is the top layer (above the caracters) 
     58  #Refresh 
     59    refresh_image:                    '/sfCryptoCaptchaPlugin/images/reload_original.png'  # use an other captcha reload image - must be in the web directory 
     60    error_images_dir:                 '/plugins/sfCryptoCaptchaPlugin/media/error/' # the path to the directory where the error images are - from the symfony root dir 
     61     
     62     
  • plugins/sfCryptoCaptchaPlugin/trunk/lib/helper/sfCryptoCaptchaHelper.php

    r17114 r19570  
    99function captcha_reload_button() 
    1010{ 
    11   $reload_img = sfConfig::get('sf_web_dir'.'/sfCryptoCaptchaPlugin/images/reload.png', '/sfCryptoCaptchaPlugin/images/reload.png'); 
    12   $refresh_url = url_for('sfCryptoCaptcha/captcha'); 
    13   $onclick = 'javascript:document.getElementById(\'captcha_img\').src=\''.$refresh_url.'/\'+Math.round(Math.random(0)*1000)+1'; 
    14   $ret = '<a style="cursor:pointer" onclick="'.$onclick.'">'.image_tag($reload_img).'</a>'; 
     11  //get the refresh image 
     12  $refresh_image = sfConfig::get('app_sf_crypto_captcha_refresh_image', '/sfCryptoCaptchaPlugin/images/reload_original.png'); 
     13   
     14  //extract the suffix if there is one 
     15  $delimiter= '_-cutter'.rand(1000,9999).'-_'; 
     16  $refresh_url = url_for('@captcha_refresh?random='.$delimiter); 
     17  $delimiter_position = strpos($refresh_url,$delimiter); 
     18  $delimiter_length = strlen($delimiter); 
     19   
     20  $length_normal_url = $delimiter_position - 1; 
     21  $suffix_offset = $delimiter_position + $delimiter_length; 
     22  $suffix_length = strlen($refresh_url) - $suffix_offset; 
     23  //cut the url in pieces 
     24  $normal_url = substr($refresh_url, 0, $length_normal_url); 
     25  $suffix = substr($refresh_url, $suffix_offset, $delimiter_length); 
     26   
     27  $onclick = 'javascript:document.getElementById(\'captcha_img\').src=\''.$normal_url.'/\'+Math.round(Math.random(0)*1000)+1+\''.$suffix.'\''; 
     28  $ret = '<a style="cursor:pointer" onclick="'.$onclick.'">'.image_tag($refresh_image).'</a>'; 
    1529  return $ret; 
    1630} 
  • plugins/sfCryptoCaptchaPlugin/trunk/lib/sfCryptoCaptcha.class.php

    r19564 r19570  
    5959          if(!$this->testQueries()) {  
    6060            $this->config['constructor_error_reason'] = 'Error - too many queries'; 
     61            $this->config['constructor_error_message'] = 'too_many'; 
    6162          } 
    6263          elseif(!$this->testLastRequest()) 
    6364          { 
    6465            $this->config['constructor_error_reason'] = 'Error - refreshing too fast'; 
     66            $this->config['constructor_error_message'] = 'refresh'; 
    6567          } 
    6668          else 
    6769          { 
    6870            $this->config['constructor_error_reason'] = 'Error - unknown reason'; 
     71            $this->config['constructor_error_message'] = 'unknown'; 
    6972          } 
    7073          return false; 
     
    149152    if($this->config['constructor_test']===false) { 
    150153      //generate error image 
    151       if(!$this->generateErrorImage($this->config['constructor_error_reason'])) 
     154      if(!$this->sendErrorImage($this->config['constructor_error_message'])) 
    152155      { 
    153156        if (sfConfig::get('sf_logging_enabled')) 
    154157        { 
    155           $message = '{seCaptcha}'; 
     158          $message = '{sfCaptcha}'; 
     159          $message .= ' - Critical Image Error - '; 
     160          $message .= 'The ERROR message(['.$this->config['constructor_error_reason'].']) image could not be sent to the user.'; 
     161          $message .= ' Possible problem with file access/path.'; 
     162          sfContext::getInstance()->getLogger()->crit($message); 
     163        }  
     164      } 
     165      elseif(!$this->generateErrorImage($this->config['constructor_error_reason'])) 
     166      { 
     167        if (sfConfig::get('sf_logging_enabled')) 
     168        { 
     169          $message = '{sfCaptcha}'; 
    156170          $message .= ' - Critical Image Error - '; 
    157171          $message .= 'The ERROR message(['.$this->config['constructor_error_reason'].']) image encoutered an error when sending to user.'; 
    158           $message .= ' Possbile problem with GD2 library.'; 
     172          $message .= ' Possible problem with GD2 library.'; 
    159173          sfContext::getInstance()->getLogger()->crit($message); 
    160174        }  
     
    702716    if($bg_type == '1') 
    703717    { 
    704       $img_read = imagecreatefromgif($this->config['bg_img']); 
     718      $img_read = imagecreatefromgif($this->captcha['bg_img']); 
    705719    } 
    706720    elseif($bg_type == '2') 
    707721    { 
    708       $img_read = imagecreatefromjpeg($this->config['bg_img']); 
     722      $img_read = imagecreatefromjpeg($this->captcha['bg_img']); 
    709723    } 
    710724    elseif($bg_type == '3') 
    711725    { 
    712       $img_read = imagecreatefrompng($this->config['bg_img']); 
     726      $img_read = imagecreatefrompng($this->captcha['bg_img']); 
    713727    } 
    714728    else 
     
    11171131  } 
    11181132   
     1133  private function sendErrorImage($error_message) 
     1134  { 
     1135    // 1) read the image depending on the sf_user culture 
     1136    // 2) send it to the browser 
     1137     
     1138    //get culture 
     1139    $culture = $this->sf_user->getCulture(); 
     1140        
     1141    //set image path 
     1142    if($this->config['use_i18n'] == true) 
     1143    { 
     1144      $image_path = $this->config['error_images_dir'].DIRECTORY_SEPARATOR.$culture.DIRECTORY_SEPARATOR.$error_message.'.'.$this->config['format']; 
     1145    } 
     1146    else 
     1147    { 
     1148      $image_path = $this->config['error_images_dir'].DIRECTORY_SEPARATOR.$error_message.'.'.$this->config['format']; 
     1149    } 
     1150    //send the finished image in JPG, GIF or PNG format 
     1151    if(strtoupper($this->config['format']) == 'JPG' || strtoupper($this->config['format']) == 'JPEG') 
     1152    { 
     1153      header("Content-type: image/jpeg"); 
     1154      readfile($image_path);  
     1155      exit; 
     1156    } 
     1157     
     1158    if(strtoupper($this->config['format']) == 'GIF') 
     1159    { 
     1160      header("Content-type: image/gif"); 
     1161      readfile($image_path); 
     1162      exit; 
     1163    } 
     1164     
     1165    if(strtoupper($this->config['format']) == 'PNG') 
     1166    { 
     1167      header("Content-type: image/png"); 
     1168      readfile($image_path); 
     1169      exit; 
     1170    } 
     1171     
     1172    return true; 
     1173  } 
     1174   
     1175   
    11191176  /** 
    11201177   * Captcha configuration getter from the app.yml 
     
    11271184  private function getConfiguration() 
    11281185  { 
     1186    $root_dir = sfConfig::get('sf_root_dir'); 
    11291187    $web_dir = sfConfig::get('sf_web_dir'); 
    11301188    //Setting image size 
     
    11371195    $this->config['bg_blue'] = sfConfig::get('app_sf_crypto_captcha_bg_blue', 255); // quantity of blue (0->255) 
    11381196    $this->config['bg_transparent'] = sfConfig::get('app_sf_crypto_captcha_bg_transparent', false); // transparent backround, only for PNG 
    1139     $this->config['bg_img'] = sfConfig::get('app_sf_crypto_captcha_bg_img', false); // boolean or image or file path.  
    1140       //If a file path is specified, an image is randomly chosen in the file 
    1141     if($this->config['bg_img'] != false) { $this->config['bg_img'] = $web_dir.$this->config['bg_img']; } 
     1197    $this->config['bg_img'] = sfConfig::get('app_sf_crypto_captcha_bg_img', false); // boolean(false) or image(path) or file (random image from file path) 
     1198    if($this->config['bg_img'] != false) { $this->config['bg_img'] = $root_dir.$this->config['bg_img']; } //The background image file must be a path from the symfony root dir 
    11421199     
    11431200    $this->config['bg_border'] = sfConfig::get('app_sf_crypto_captcha_bg_border', true); //border or not 
    1144      
    1145     $this->config['img_dir'] = sfConfig::get('app_sf_crypto_captcha_img_dir', '/sfCryptoCaptchaPlugin/images/'); // directory of images 
    1146     $this->config['img_dir'] = $web_dir.$this->config['img_dir']; 
    11471201     
    11481202    //Setting characters 
     
    11611215    //Setting fonts 
    11621216    $this->config['char_fonts'] = sfConfig::get('app_sf_crypto_captcha_char_fonts', array('luggerbu.ttf')); // the fonts used randomly to generate the characters 
    1163     $this->config['char_fonts_dir'] = sfConfig::get('app_sf_crypto_captcha_char_fonts_dir', '/sfCryptoCaptchaPlugin/fonts/'); // directory with the fonts 
    1164     $this->config['char_fonts_dir'] = $web_dir.$this->config['char_fonts_dir']; 
     1217    $this->config['char_fonts_dir'] = sfConfig::get('app_sf_crypto_captcha_char_fonts_dir', '/plugins/sfCryptoCaptchaPlugin/media/fonts/'); // directory with the fonts 
     1218    $this->config['char_fonts_dir'] = $root_dir.$this->config['char_fonts_dir']; 
    11651219    $this->config['error_font'] = sfConfig::get('app_sf_crypto_captcha_error_font', 'arial.ttf'); 
    11661220     
     
    12001254    $this->config['noise_on_top'] = sfConfig::get('app_sf_crypto_captcha_noise_on_top', false); // the noise is on the top layer 
    12011255     
     1256    //error config 
     1257    $this->config['use_i18n'] = sfConfig::get('sf_i18n', false); 
     1258    $this->config['error_images_dir'] = sfConfig::get('app_sf_crypto_captcha_error_images_dir', '/plugins/sfCryptoCaptchaPlugin/media/error/'); //the dir where the images are - from symfony root dir 
     1259    $this->config['error_images_dir'] = $root_dir.$this->config['error_images_dir']; 
     1260     
    12021261    return true; 
    12031262  } 
  • plugins/sfCryptoCaptchaPlugin/trunk/package.xml

    r19565 r19570  
    1111  <active>yes</active> 
    1212 </lead> 
    13  <date>2009-06-25</date> 
    14  <time>20:26:27</time> 
     13 <date>2009-06-26</date> 
     14 <time>01:29:36</time> 
    1515 <version> 
    16   <release>0.0.5</release> 
    17   <api>0.0.5</api> 
     16  <release>0.0.6</release> 
     17  <api>0.0.6</api> 
    1818 </version> 
    1919 <stability> 
     
    5050    </dir> 
    5151   </dir> 
    52    <dir name="web"> 
    53     <dir name="fonts"> 
     52   <dir name="media"> 
     53    <dir name="fonts"> 
    5454     <file role="data" name="Alanden_.ttf" /> 
    5555     <file role="data" name="arial.ttf" /> 
     
    6161     <file role="data" name="WAVY.ttf" /> 
    6262    </dir> 
     63    <dir name="bg"> 
     64     <file role="data" name="beige_marble.jpg" /> 
     65     <file role="data" name="leaf_bg.jpg" /> 
     66     <file role="data" name="metal_bg.jpg" /> 
     67     <file role="data" name="styrofoam.jpg" /> 
     68    </dir> 
     69    <dir name="error"> 
     70     <file role="data" name="refresh.png" /> 
     71     <file role="data" name="too_many.png" /> 
     72     <file role="data" name="unknown.png" /> 
     73     <dir name="en"> 
     74      <file role="data" name="refresh.png" /> 
     75      <file role="data" name="too_many.png" /> 
     76      <file role="data" name="unknown.png" /> 
     77     </dir> 
     78     <dir name="fr"> 
     79      <file role="data" name="refresh.png" /> 
     80      <file role="data" name="too_many.png" /> 
     81      <file role="data" name="unknown.png" /> 
     82     </dir> 
     83    </dir> 
     84   </dir> 
     85   <dir name="web"> 
    6386    <dir name="images"> 
    64      <file role="data" name="reload.png" /> 
    65      <dir name="bg"> 
    66        <file role="data" name="clear.gif" /> 
    67      </dir> 
     87     <file role="data" name="refresh_blue_big.png" /> 
     88     <file role="data" name="refresh_green_cw_small.png" /> 
     89     <file role="data" name="refresh_blue_ccw_small.png" /> 
     90     <file role="data" name="reload_blue_medium.png" /> 
     91     <file role="data" name="refresh_blue_cw_medium.png" /> 
     92     <file role="data" name="reload_blue_small.gif" /> 
     93     <file role="data" name="refresh_blue_medium.png" /> 
     94     <file role="data" name="reload_dark_green_small.gif" /> 
     95     <file role="data" name="refresh_clear_blue_medium.png" /> 
     96     <file role="data" name="reload_green_small.gif" /> 
     97     <file role="data" name="refresh_clear_blue_small.png" /> 
     98     <file role="data" name="reload_green_small.png" /> 
     99     <file role="data" name="refresh_dark_blue_big.png" /> 
     100     <file role="data" name="reload_original.png" /> 
     101     <file role="data" name="refresh_green_ccw_small.png" /> 
     102     <file role="data" name="web_refresh_green_big.png" /> 
     103     <file role="data" name="refresh_green_cw_small.gif" /> 
    68104    </dir> 
    69105   </dir> 
     
    90126  <release> 
    91127   <version> 
     128    <release>0.0.6</release> 
     129    <api>0.0.6</api> 
     130   </version> 
     131   <stability> 
     132    <release>beta</release> 
     133    <api>beta</api> 
     134   </stability> 
     135   <license uri="http://www.symfony-project.com/license">MIT license</license> 
     136   <license>MIT</license> 
     137   <date>2009-06-25</date> 
     138   <notes> 
     139     * henearkrxern: reorganisation of the plugin (media directory, fonts, backgrounds) 
     140     * henearkrxern: fonts dir specified from the symfony root and not the web dir and moved 
     141     * henearkrxern: added support for url suffixes (.php, .html, ...) 
     142     * henearkrxern: added free and/or GPL icons for the refresh button (check out the plugin web/images folder) 
     143     * henearkrxern: added some organic backgrounds 
     144     * henearkrxern: errors are now pre-generated graphics that can be internationalized 
     145   </notes> 
     146  </release> 
     147  <release> 
     148   <version> 
    92149    <release>0.0.5</release> 
    93150    <api>0.0.5</api>