示例#1
0
 function setup(&$Model, $settings)
 {
     if (!is_array($settings)) {
         $settings = array('privatekey' => $settings);
     }
     if (empty($this->settings[$Model->alias])) {
         $this->settings[$Model->alias] = array();
     }
     $defSettings = $this->defSettings;
     App::import('Lib', 'Captcha.CaptchaConfig');
     $defSettings['privatekey'] = CaptchaConfig::load('PrivateKey');
     $this->settings[$Model->alias] = array_merge($defSettings, $this->settings[$Model->alias], (array) $settings);
 }
 function load($path = true)
 {
     $_this =& CaptchaConfig::getInstance();
     if (!$_this->loaded) {
         config('plugins/captcha');
         $config = Configure::read('Captcha');
         $config = Set::merge($_this->defaultConfig, $config);
         $config = $_this->_parseTrueToDefault($config);
         Configure::write('Captcha', $config);
         $_this->loaded = true;
     }
     if (!empty($path)) {
         return Configure::read('Captcha' . ($path !== true ? '.' . $path : ''));
     }
 }
示例#3
0
    function captcha($fieldName = 'captcha', $options = array())
    {
        App::import('Vendor', 'Captcha.recaptchalib');
        if (is_array($fieldName)) {
            $options = $fieldName;
            $fieldName = 'captcha';
        }
        if (!empty($options) && !is_array($options) && strlen($options) >= 40) {
            $options = array('key' => $options);
        }
        if (empty($options['key']) && strlen($fieldName) >= 40) {
            $options['key'] = $fieldName;
            $fieldName = 'captcha';
        }
        App::import('Lib', 'Captcha.CaptchaConfig');
        $defOpt = array('theme' => CaptchaConfig::load('theme'), 'lang' => substr(Configure::read('Config.language'), 0, 2), 'key' => CaptchaConfig::load('publicKey'));
        $opt = array_merge($defOpt, $options);
        $moreJsOpt = '';
        $html = '';
        if ($opt['theme'] == 'custom') {
            $moreJsOpt .= 'custom_theme_widget: "recaptcha_widget",';
            $view =& ClassRegistry::getObject('view');
            $html .= $view->element('custom_theme', array('plugin' => 'captcha'));
        }
        $html .= '
			<script type="text/javascript">
				 var RecaptchaOptions = {
					theme : "' . $opt['theme'] . '",
					' . $moreJsOpt . '
					lang : "' . $opt['lang'] . '"
				 };
			</script>';
        $html .= $this->Form->hidden($fieldName, array('value' => 1));
        $error = null;
        $error = $this->Form->error($fieldName, null, array('wrap' => false, 'escape' => false));
        $html .= recaptcha_get_html($opt['key'], $error);
        return $html;
    }
示例#4
0
 public function __construct(CaptchaConfig $config)
 {
     $this->isRunnableEnvironment();
     $config->isValid();
     $this->config = $config;
 }