Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Sep 30, 2011
2 parents b6a25df + a8e9686 commit 3835c24
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 30 deletions.
27 changes: 23 additions & 4 deletions controllers/components/recaptcha.php
Expand Up @@ -29,7 +29,7 @@ class RecaptchaComponent extends Object {
*
* @var string
*/
public $apiUrl = 'http://api-verify.recaptcha.net/verify';
public $apiUrl = 'http://www.google.com/recaptcha/api/verify';

/**
* Private API Key
Expand Down Expand Up @@ -63,8 +63,12 @@ class RecaptchaComponent extends Object {
* Callback
*
* @param object Controller object
* @param Array $settings
*/
public function initialize(Controller $controller, $settings = array()) {
if ($controller->name == 'CakeError') {
return;
}
$this->privateKey = Configure::read('Recaptcha.privateKey');
$this->Controller = $controller;

Expand All @@ -75,16 +79,26 @@ public function initialize(Controller $controller, $settings = array()) {
$defaults = array(
'modelClass' => $this->Controller->modelClass,
'errorField' => 'recaptcha',
'actions' => array());
'actions' => array()
);

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

/**
* Callback
*
* @param object Controller object
*/
public function startup(Controller $controller) {
extract($this->settings);
if ($this->enabled == true) {
$this->Controller->helpers[] = 'Recaptcha.Recaptcha';
$this->Controller->{$modelClass}->Behaviors->attach('Recaptcha.Recaptcha', array(
'field' => $errorField));
'field' => $errorField
));

$this->Controller->{$modelClass}->recaptcha = true;
if (in_array($this->Controller->action, $this->actions)) {
Expand All @@ -111,6 +125,11 @@ public function verify() {
$response = $this->_getApiResponse();
$response = explode("\n", $response);

if (empty($response[0])) {
$this->error = __d('recaptcha', 'Invalid API response, please contact the site admin.', true);
return false;
}

if ($response[0] == 'true') {
return true;
}
Expand Down
40 changes: 40 additions & 0 deletions locale/ita/LC_MESSAGES/recaptcha.po
@@ -0,0 +1,40 @@
# LANGUAGE translation of the CakePHP Categories plugin
#
# Copyright 2010, Cake Development Corporation (http://cakedc.com)
#
# Licensed under The MIT License
# Redistributions of files must retain the above copyright notice.
#
# @copyright Copyright 2010, Cake Development Corporation (http://cakedc.com)
# @license MIT License (http://www.opensource.org/licenses/mit-license.php)
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"POT-Creation-Date: 2010-09-15 15:30+0200\n"
"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n"
"Last-Translator: NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

#: /controllers/components/recaptcha.php:79
msgid "You must set your private recaptcha key using Cofigure::write('Recaptcha.privateKey', 'your-key');!"
msgstr "Devi impostare la chiave privata per poter utilizzare reCAPTCHA. Usa: Cofigure::write('Recaptcha.privateKey', 'chiave');"

#: /controllers/components/recaptcha.php:110
msgid "Incorect captcha"
msgstr "Captcha non valido"

#: /views/helpers/recaptcha.php:115
msgid "To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed."
msgstr "Per utilizzare reCAPTCHA Mailhide, devi aver istallato il modulo php mcrypt."

#: /views/helpers/recaptcha.php:147
msgid "You need to set a private and public mail hide key. Please visit http://mailhide.recaptcha.net/apikey"
msgstr "Devi registrare reCAPTCHA Mailhide API key. http://mailhide.recaptcha.net/apikey"


40 changes: 40 additions & 0 deletions locale/por/LC_MESSAGES/recaptcha.po
@@ -0,0 +1,40 @@
# LANGUAGE translation of the CakePHP Categories plugin
#
# Copyright 2010, Cake Development Corporation (http://cakedc.com)
#
# Licensed under The MIT License
# Redistributions of files must retain the above copyright notice.
#
# @copyright Copyright 2010, Cake Development Corporation (http://cakedc.com)
# @license MIT License (http://www.opensource.org/licenses/mit-license.php)
#
msgid ""
msgstr ""
"Project-Id-Version: CakePHP Recaptcha Plugin\n"
"POT-Creation-Date: 2010-09-15 15:30+0200\n"
"PO-Revision-Date: 2010-09-23 18:57-0300\n"
"Last-Translator: Renan Gonçalves <renan.saddam@gmail.com>\n"
"Language-Team: CakeDC <renan.saddam@gmail.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2;plural=n>1;\n"
"X-Poedit-Language: Portuguese\n"
"X-Poedit-Country: BRAZIL\n"

#: /controllers/components/recaptcha.php:79
msgid "You must set your private recaptcha key using Cofigure::write('Recaptcha.privateKey', 'your-key');!"
msgstr "Você deve definir a sua chave privada usando Cofigure::write('Recaptcha.privateKey', 'your-key');!"

#: /controllers/components/recaptcha.php:110
msgid "Incorect captcha"
msgstr "Captcha incorreto"

#: /views/helpers/recaptcha.php:115
msgid "To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed."
msgstr "Para usar o reCAPTCHA Mailhide, você precisa ter o módulo php mcrypt instalado."

#: /views/helpers/recaptcha.php:147
msgid "You need to set a private and public mail hide key. Please visit http://mailhide.recaptcha.net/apikey"
msgstr "Você precisa configurar uma chave privada e pública. Por favor, visite http://mailhide.recaptcha.net/apikey"

4 changes: 1 addition & 3 deletions locale/recaptcha.pot
Expand Up @@ -8,9 +8,7 @@
# @copyright Copyright 2010, Cake Development Corporation (http://cakedc.com)
# @license MIT License (http://www.opensource.org/licenses/mit-license.php)
#
#, fuzzy
msgid ""
msgstr ""
#
"Project-Id-Version: PROJECT VERSION\n"
"POT-Creation-Date: 2010-09-15 15:30+0200\n"
"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n"
Expand Down
28 changes: 28 additions & 0 deletions locale/rus/LC_MESSAGES/recaptcha.po
@@ -0,0 +1,28 @@
msgid ""
msgstr ""
"Project-Id-Version: CakePHP Recaptcha Plugin\n"
"POT-Creation-Date: 2010-09-15 15:30+0200\n"
"PO-Revision-Date: \n"
"Last-Translator: Pierre MARTIN <contact@pierre-martin.fr>\n"
"Language-Team: CakeDC <contact@cakedc.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Language: French\n"

#: /controllers/components/recaptcha.php:79
msgid "You must set your private recaptcha key using Cofigure::write('Recaptcha.privateKey', 'your-key');!"
msgstr "Vous devez définir votre clé privée Recaptcha en utilisant Configure::write('Recaptcha.privateKey', 'votre-clé'); !"

#: /controllers/components/recaptcha.php:110
msgid "Incorect captcha"
msgstr "Captcha incorrect"

#: /views/helpers/recaptcha.php:115
msgid "To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed."
msgstr "Afin d'utiliser reCAPTCHA Mailhide, vous devez avoir le module php mcrypt installé."

#: /views/helpers/recaptcha.php:147
msgid "You need to set a private and public mail hide key. Please visit http://mailhide.recaptcha.net/apikey"
msgstr "Vous devez définir les clés publique et privée mailhide. Veuillez visiter http://mailhide.recaptcha.net/apikey"

38 changes: 38 additions & 0 deletions locale/spa/LC_MESSAGES/recaptcha.po
@@ -0,0 +1,38 @@
msgid ""
msgstr ""
"Project-Id-Version: Recaptcha CakePHP plugin\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: José Lorenzo Rodríguez <jose.lorenzo@cakedc.com>\n"
"Language-Team: CakeDC <contact@cakedc.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

# LANGUAGE translation of the CakePHP Categories plugin
#
# Copyright 2010, Cake Development Corporation (http://cakedc.com)
#
# Licensed under The MIT License
# Redistributions of files must retain the above copyright notice.
#
# @copyright Copyright 2010, Cake Development Corporation (http://cakedc.com)
# @license MIT License (http://www.opensource.org/licenses/mit-license.php)
#
#
#: /controllers/components/recaptcha.php:79
msgid "You must set your private recaptcha key using Cofigure::write('Recaptcha.privateKey', 'your-key');!"
msgstr "Debes configurar tu clave privada de recaptcha usando Cofigure::write('Recaptcha.privateKey', 'your-key');"

#: /controllers/components/recaptcha.php:110
msgid "Incorect captcha"
msgstr "Transcripción incorrecta"

#: /views/helpers/recaptcha.php:115
msgid "To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed."
msgstr "Para usar la función de oculatar emails de reCAPTCHA , debes tener el modulo mcrypt de php instalado."

#: /views/helpers/recaptcha.php:147
msgid "You need to set a private and public mail hide key. Please visit http://mailhide.recaptcha.net/apikey"
msgstr "Debes configurar tus claves públicas y privadas de \"mail hide\". Por favor visita http://mailhide.recaptcha.net/apikey"

6 changes: 6 additions & 0 deletions readme.md
Expand Up @@ -19,6 +19,12 @@ In the view simply call the helpers `display()` method to render the recaptcha i

echo $this->Recaptcha->display();

You could select another theme, setup it as parameter, for istance:

echo $this->Recaptcha->display(array('theme' => 'blackglass'));

For the complete list of themes, take a look here: [http://code.google.com/intl/it-IT/apis/recaptcha/docs/customization.html](http://code.google.com/intl/it-IT/apis/recaptcha/docs/customization.html).

To check the result simply do something like this in your controller:

if (!empty($this->data)) {
Expand Down
89 changes: 89 additions & 0 deletions tests/cases/helpers/recaptcha.test.php
Expand Up @@ -52,6 +52,8 @@ class RecaptchaHelperTest extends CakeTestCase {
*/
function setup() {
$view = new View(new PostsTestController());
$this->Recaptcha = new RecaptchaHelper();
$this->Recaptcha->Html = new HtmlHelper();
ClassRegistry::addObject('view', $view);
}

Expand All @@ -64,4 +66,91 @@ function tearDown() {
ClassRegistry::flush();
unset($this->Recaptcha);
}

/**
* testSignupUrl
*
* @return void
*/
function testSignupUrl() {
$result = $this->Recaptcha->signupUrl('test');
$expected = 'http://recaptcha.net/api/getkey?domain=' . WWW_ROOT . '&amp;app=test' ;
$this->assertIdentical($expected, $result);
}

/**
* testDisplayDefault
*
* @return void
*/
function testDisplayDefault() {
$result = $this->Recaptcha->display(array('publicKey' => 'TestKey'));
$expected = <<<TEXT
<script type="text/javascript">
//<![CDATA[
var RecaptchaOptions = {
theme: "white",
lang: "en-us"
};
//]]>
</script><script type="text/javascript" src="http://api-secure.recaptcha.net/challenge?k=TestKey"></script><noscript>
<iframe src="http://api-secure.recaptcha.net/noscript?k=TestKey" height="300" width="500" frameborder="0"></iframe><br/>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript>
TEXT;
$this->assertIdentical($expected, $result);
}

/**
* testDisplayTheme
*
* @return void
*/
function testDisplayTheme() {
$result = $this->Recaptcha->display(array(
'publicKey' => 'TestKey',
'theme' => 'testTheme'));
$expected = <<<TEXT
<script type="text/javascript">
//<![CDATA[
var RecaptchaOptions = {
theme: "testTheme",
lang: "en-us"
};
//]]>
</script><script type="text/javascript" src="http://api-secure.recaptcha.net/challenge?k=TestKey"></script><noscript>
<iframe src="http://api-secure.recaptcha.net/noscript?k=TestKey" height="300" width="500" frameborder="0"></iframe><br/>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript>
TEXT;
$this->assertIdentical($expected, $result);
}

/**
* testDisplayError
*
* @return void
*/
function testDisplayError() {
$result = $this->Recaptcha->display(array(
'publicKey' => 'TestKey',
'error' => 'testError'));
$expected = <<<TEXT
<script type="text/javascript">
//<![CDATA[
var RecaptchaOptions = {
theme: "white",
lang: "en-us"
};
//]]>
</script><script type="text/javascript" src="http://api-secure.recaptcha.net/challenge?k=TestKey&amp;error=testError"></script><noscript>
<iframe src="http://api-secure.recaptcha.net/noscript?k=TestKey&amp;error=testError" height="300" width="500" frameborder="0"></iframe><br/>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript>
TEXT;
$this->assertIdentical($expected, $result);
}
}

0 comments on commit 3835c24

Please sign in to comment.