<commit_before><?php

/*
 * This file is part of the EcommitJavascriptBundle package.
 *
 * (c) E-commit <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Ecommit\JavascriptBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class RecaptchaType extends AbstractType
{
    const RECAPTCHA_API_SERVER = 'http://www.google.com/recaptcha/api';
    const RECAPTCHA_API_SECURE_SERVER = 'https://www.google.com/recaptcha/api';
    const RECAPTCHA_API_JS_SERVER = 'http://www.google.com/recaptcha/api/js/recaptcha_ajax.js';
    
    protected $public_key;
    protected $secure;
    protected $enable;
    protected $language;
    
    public function __construct($public_key, $secure, $enable, $language)
    {
        $this->public_key = $public_key;
        $this->secure = $secure;
        $this->enable = $enable;
        $this->language = $language;
    }
    
    public function getPublicKey()
    {
        return $this->public_key;
    }
    
    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        if (!$this->enable)
        {
            return;
        }
        
        if(empty($this->public_key))
        {
            throw new \Exception('Recaptcha: Public and private keys are required');
        }
        
        if ($this->secure)
        {
            $server = self::RECAPTCHA_API_SECURE_SERVER;
        }
        else
        {
            $server = self::RECAPTCHA_API_SERVER;
        }

        $view->vars['url_challenge'] = $server.'/challenge?k='.$this->public_key;
        $view->vars['url_noscript'] = $server.'/noscript?k='.$this->public_key;
        $view->vars['public_key'] = $this->public_key;
        $view->vars['recaptcha_enable'] = $this->enable;
        $view->vars['options'] = $options['options'];
    }
    
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'options' => array(
                'theme' => 'clean',
                'lang' => $this->language,
            ),
            
            'compound'  => false,
        ));
    }
    
    public function getParent()
    {
        return 'form';
    }
    
    public function getName()
    {
        return 'recaptcha';
    }<commit_msg>RecaptchaType: Correction bug qui provoquait une erreur en cas de captcha desactive<commit_after><?php

/*
 * This file is part of the EcommitJavascriptBundle package.
 *
 * (c) E-commit <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Ecommit\JavascriptBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class RecaptchaType extends AbstractType
{
    const RECAPTCHA_API_SERVER = 'http://www.google.com/recaptcha/api';
    const RECAPTCHA_API_SECURE_SERVER = 'https://www.google.com/recaptcha/api';
    const RECAPTCHA_API_JS_SERVER = 'http://www.google.com/recaptcha/api/js/recaptcha_ajax.js';
    
    protected $public_key;
    protected $secure;
    protected $enable;
    protected $language;
    
    public function __construct($public_key, $secure, $enable, $language)
    {
        $this->public_key = $public_key;
        $this->secure = $secure;
        $this->enable = $enable;
        $this->language = $language;
    }
    
    public function getPublicKey()
    {
        return $this->public_key;
    }
    
    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        $view->vars['recaptcha_enable'] = $this->enable;
        if (!$this->enable)
        {
            return;
        }
        
        if(empty($this->public_key))
        {
            throw new \Exception('Recaptcha: Public and private keys are required');
        }
        
        if ($this->secure)
        {
            $server = self::RECAPTCHA_API_SECURE_SERVER;
        }
        else
        {
            $server = self::RECAPTCHA_API_SERVER;
        }

        $view->vars['url_challenge'] = $server.'/challenge?k='.$this->public_key;
        $view->vars['url_noscript'] = $server.'/noscript?k='.$this->public_key;
        $view->vars['public_key'] = $this->public_key;
        $view->vars['options'] = $options['options'];
    }
    
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'options' => array(
                'theme' => 'clean',
                'lang' => $this->language,
            ),
            
            'compound'  => false,
        ));
    }
    
    public function getParent()
    {
        return 'form';
    }
    
    public function getName()
    {
        return 'recaptcha';
    }
{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.0, 'mean_word_length': 2.327023498694517, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 53, 'https://': 2, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2198699', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1520, 'n_words': 295}