<commit_before><?php
/**
 * Copyright 2009-2010, Cake Development Corporation (http://cakedc.com)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright Copyright 2009-2010, Cake Development Corporation (http://cakedc.com)
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

/**
 * CakePHP Recaptcha component
 *
 * @package recaptcha
 * @subpackage recaptcha.controllers.components
 */
class RecaptchaComponent extends Object {

/**
 * Name
 *
 * @var string
 */
	public $Controller = null;

/**
 * Recaptcha API Url
 *
 * @var string
 */
	public $apiUrl = 'http://www.google.com/recaptcha/api/verify';

/**
 * Private API Key
 *
 * @var string
 */
	public $privateKey = '';

/**
 * Error coming back from Recaptcha
 *
 * @var string
 */
	public $error = null;

/**
 * Actions that should automatically checked for a recaptcha input
 *
 * @var array
 */
	public $actions = array();

/**
 * Settings
 *
 * @var array
 */
	public $settings = array();

 /**
 * Callback
 *
 * @param object Controller object
 */
	public function initialize(Controller $controller, $settings = array()) {
		$this->privateKey = Configure::read('Recaptcha.privateKey');
		$this->Controller = $controller;

		if (empty($this->privateKey)) {
			throw new Exception(__d('recaptcha', "You must set your private recaptcha key using Cofigure::write('Recaptcha.privateKey', 'your-key');!", true));
		}

		$defaults = array(
			'modelClass' => $this->Controller->modelClass,
			'errorField' => 'recaptcha',
			'actions' => array());

		$this->settings = array_merge($defaults, $settings);
		$this->actions = array_merge($this->actions, $this->settings['actions']);
		extract($this->settings);

		if ($this->enabled == true) {
			$this->Controller->helpers[] = 'Recaptcha.Recaptcha';
			$this->Controller->{$modelClass}->Behaviors->attach('Recaptcha.Recaptcha', array(
				'field' => $errorField));

			$this->Controller->{$modelClass}->recaptcha = true;
			if (in_array($this->Controller->action, $this->actions)) {
				if (!$this->verify()) {
					$this->Controller->{$modelClass}->recaptcha = false;
					$this->Controller->{$modelClass}->recaptchaError = $this->error;<commit_msg>Fixed fatal error if current controller is CakeErrorController Ticket: http://bit.ly/jdcAq5<commit_after><?php
/**
 * Copyright 2009-2010, Cake Development Corporation (http://cakedc.com)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright Copyright 2009-2010, Cake Development Corporation (http://cakedc.com)
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

/**
 * CakePHP Recaptcha component
 *
 * @package recaptcha
 * @subpackage recaptcha.controllers.components
 */
class RecaptchaComponent extends Object {

/**
 * Name
 *
 * @var string
 */
	public $Controller = null;

/**
 * Recaptcha API Url
 *
 * @var string
 */
	public $apiUrl = 'http://www.google.com/recaptcha/api/verify';

/**
 * Private API Key
 *
 * @var string
 */
	public $privateKey = '';

/**
 * Error coming back from Recaptcha
 *
 * @var string
 */
	public $error = null;

/**
 * Actions that should automatically checked for a recaptcha input
 *
 * @var array
 */
	public $actions = array();

/**
 * Settings
 *
 * @var array
 */
	public $settings = array();

 /**
 * Callback
 *
 * @param object Controller object
 */
	public function initialize(Controller $controller, $settings = array()) {
		if ($controller->name == 'CakeError') {
			return;
		}
		$this->privateKey = Configure::read('Recaptcha.privateKey');
		$this->Controller = $controller;

		if (empty($this->privateKey)) {
			throw new Exception(__d('recaptcha', "You must set your private recaptcha key using Cofigure::write('Recaptcha.privateKey', 'your-key');!", true));
		}

		$defaults = array(
			'modelClass' => $this->Controller->modelClass,
			'errorField' => 'recaptcha',
			'actions' => array());

		$this->settings = array_merge($defaults, $settings);
		$this->actions = array_merge($this->actions, $this->settings['actions']);
		extract($this->settings);

		if ($this->enabled == true) {
			$this->Controller->helpers[] = 'Recaptcha.Recaptcha';
			$this->Controller->{$modelClass}->Behaviors->attach('Recaptcha.Recaptcha', array(
				'field' => $errorField));

			$this->Controller->{$modelClass}->recaptcha = true;
			if (in_array($this->Controller->action, $this->actions)) {
				if (!$this->verify()) {
					$this->Controller->{$modelClass}->recaptcha = false;
					$this->Controller->{$modelClass}->recaptchaError = $this->error;
{'fraction_non_alphanumeric': 0.17130528586839266, 'fraction_numerical': 0.007119741100323625, 'mean_word_length': 4.1001100110011, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7540439', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1413, 'n_words': 332}