Webylon 3.2 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
  • Download
Version: current
  • 3.2
  • 3.1

Packages

  • 1c
    • exchange
      • catalog
  • auth
  • Booking
  • building
    • company
  • cart
    • shipping
    • steppedcheckout
  • Catalog
    • monument
  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • newsletter
    • publishers
    • reports
    • security
    • tasks
  • Dashboard
  • DataObjectManager
  • event
  • faq
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • googlesitemaps
  • guestbook
  • installer
  • newsletter
  • None
  • photo
    • gallery
  • PHP
  • polls
  • recaptcha
  • sapphire
    • api
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • filesystem
    • formatters
    • forms
    • i18n
    • integration
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • tools
    • validation
    • view
    • widgets
  • seo
    • open
      • graph
  • sfDateTimePlugin
  • spamprotection
  • stealth
    • captha
  • subsites
  • userform
    • pagetypes
  • userforms
  • webylon
  • widgets

Classes

  • StealthCaptchaProtector
  • StealthFieldCaptcha
  1 <?php
  2 /**
  3  * Вариант Капчи невидимой польззователю
  4  * Содержит 2 поля:
  5  * * скрытое пустое текстовым поле. Пользователь его не видит, поэтому не заполнит, а бот как правило заполняет
  6  * * скрытое поле, заполняемое спец. значением с помощью js, само значение сохраняется в сессии
  7  *
  8  * @package stealth_captha
  9  * @author menedem, dvp
 10  */
 11 class StealthFieldCaptcha extends SpamProtectorField {
 12 
 13     /**
 14      * Генерирует уникальный код
 15      * 
 16      * @return string
 17      */
 18     static function generate_captcha() {
 19         $length = 16;
 20         $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ0123456789';
 21         $numChars = strlen($chars);
 22         $string = '';
 23         for ($i = 0; $i < $length; $i++) {
 24             $string .= substr($chars, rand(1, $numChars) - 1, 1);
 25         }
 26         return $string;
 27     }
 28     
 29     public function __construct($name = "StealthChkField", $title = '', $value = null, $form = null, $rightTitle = null) {
 30         parent::__construct($name, '', '', $form, '');
 31     }   
 32     
 33     /**
 34      * Формирует html код поля
 35      * 
 36      * @return string
 37      */
 38     function Field() {
 39         Requirements::javascript(JQUERY_PATH);
 40         return $this->renderWith($this->fieldTemplates());
 41     }
 42     /*
 43     public function Field() {
 44         //Requirements::javascript(JQUERY_PATH);
 45         Requirements::javascript('stealth_captcha/javascript/script.js');
 46         $capthaText = $this->getCode();
 47 
 48         $emptyField = $this->createTag('input', array(
 49             'type' => 'text',
 50             'class' => 'text TextField',
 51             'name' => $this->Name().'[_e]',
 52             'style' => 'display: none',
 53             'data-ctext' => $capthaText,
 54             'value' => '',
 55         ));
 56 
 57         $filledField = $this->createTag('input', array(
 58             'type' => 'hidden',
 59             'class' => 'hidden stealth_filled',
 60             'name' => $this->Name().'[_f]',
 61             'data-ctext' => $capthaText,
 62             'value' => '',
 63         ));
 64 
 65         return $emptyField . $filledField;
 66     }
 67     */
 68 
 69     /**
 70      * Проверка CAPTHA
 71      *
 72      * @param Validator $validator
 73      * @return boolean
 74      */
 75     public function validate($validator) {      
 76         $capthaText = $this->getCode();
 77         if ($this->securityTokenEnabled()) {
 78             $capthaText .=  Session::get('SecurityID');
 79         }
 80 
 81         if ((!$this->value['_e'] && $this->value['_f'] && $this->value['_f'] == $capthaText)) {
 82             return true;
 83         }
 84 
 85         if ($validator) {
 86             $validator->validationError(
 87                 $this->name,
 88                 _t('StealthCaptcha.WRONG', "The text you entered doesn't match the captcha. Please try again"),
 89                 "validation",
 90                 false
 91             );
 92         }
 93         return false;
 94     }
 95     
 96     /**
 97      * Возвращает случайный код для капчи
 98      * Сохраняет сгенерированный код в сессии для последующих проверок
 99      * 
100      * @param boolean $clear - удалить код из сессии после его чтения
101      * 
102      * @return string
103      */
104     function getCode($clear=false) {
105         $capthaText = Session::get('StealthCaptcha.CText');
106         if (!$capthaText) {
107             $capthaText = self::generate_captcha();
108             Session::Set('StealthCaptcha.CText', $capthaText);
109         }
110         if ($clear) {
111             Session::clear('StealthCaptcha.CText');
112         }
113         return $capthaText;
114     }
115 }
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -
Webylon 3.2 API Docs API documentation generated by ApiGen 2.8.0