Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Captcha support. Add reCaptcha Plug-in.
- Loading branch information
1 parent
0ecd79b
commit e9a20b2
Showing
16 changed files
with
725 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
administrator/language/en-GB/en-GB.plg_captcha_recaptcha.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
; $id: | ||
; Joomla! Project | ||
; Copyright (C) 2005 - 2009 Open Source Matters. All rights reserved. | ||
; License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php | ||
; Note : All ini files need to be saved as UTF-8 | ||
|
||
PLG_CAPTCHA_RECAPTCHA_XML_DESCRIPTION="" | ||
PLG_CAPTCHA_RECAPTCHA="Captcha - ReCaptcha" | ||
|
||
; Params | ||
PLG_RECAPTCHA_PUBLIC_KEY_LABEL="Public Key" | ||
PLG_RECAPTCHA_PUBLIC_KEY_DESC="Used in the JavaScript code that is served to your users." | ||
PLG_RECAPTCHA_PRIVATE_KEY_LABEL="Private Key" | ||
PLG_RECAPTCHA_PRIVATE_KEY_DESC="Used in the communication between your server and the ReCaptha server. Be sure to keep it a secret." | ||
PLG_RECAPTCHA_THEME_LABEL="Theme" | ||
PLG_RECAPTCHA_THEME_DESC="Defines which theme to use for reCAPTCHA." | ||
PLG_RECAPTCHA_THEME_RED="Red" | ||
PLG_RECAPTCHA_THEME_WHITE="White" | ||
PLG_RECAPTCHA_THEME_BLACKGLASS="BlackGlass" | ||
PLG_RECAPTCHA_THEME_CLEAN="Clean" | ||
PLG_RECAPTCHA_LANG_LABEL="Language" | ||
PLG_RECAPTCHA_LANG_DESC="Select the language for the reCAPTCHA. If default is set and the language file has custom translation, it will be used." | ||
|
||
; Error messages | ||
PLG_RECAPTCHA_ERROR_NO_PRIVATE_KEY="You must provide a Private Key. Insert one in the Plug-in Manager" | ||
PLG_RECAPTCHA_ERROR_NO_PUBLIC_KEY="You must provide a Public Key. Insert one in the <a href="_QQ_"administrator/index.php?option=com_plugins&view=plugins&filter_folder=captcha"_QQ_" rel="_QQ_"nofollow"_QQ_">Plug-in Manager</a>" | ||
PLG_RECAPTCHA_ERROR_EMPTY_SOLUTION="Empty solution not allowed." | ||
PLG_RECAPTCHA_ERROR_NO_IP="For security reasons, you must pass the remote ip to reCAPTCHA" | ||
PLG_RECAPTCHA_ERROR_UNKNOWN="Unknown error." | ||
PLG_RECAPTCHA_ERROR_INVALID_SITE_PUBLIC_KEY="We weren't able to verify the public key." | ||
PLG_RECAPTCHA_ERROR_INVALID_SITE_PRIVATE_KEY="We weren't able to verify the private key." | ||
PLG_RECAPTCHA_ERROR_INVALID_REQUEST_COOKIE="The challenge parameter of the verify script was incorrect." | ||
PLG_RECAPTCHA_ERROR_INCORRECT_CAPTCHA_SOL="The CAPTCHA solution was incorrect." | ||
PLG_RECAPTCHA_ERROR_VERIFY_PARAMS_INCORRECT="The parameters to /verify were incorrect, make sure you are passing all the required parameters." | ||
PLG_RECAPTCHA_ERROR_INVALID_REFERRER="reCAPTCHA API keys are tied to a specific domain name for security reasons." | ||
PLG_RECAPTCHA_ERROR_RECAPTCHA_NOT_REACHABLE="Unable to contact the reCAPTCHA verify server." | ||
|
||
; Uncomment(remove the ";" from the beginning of the line) the following lines if reCAPTCHA is not avaiable in your language | ||
;PLG_RECAPTCHA_CUSTOM_LANG="true" | ||
;PLG_RECAPTCHA_INSTRUCTIONS_VISUAL="Type the two words:" | ||
;PLG_RECAPTCHA_INSTRUCTIONS_AUDIO="Type what you hear:" | ||
;PLG_RECAPTCHA_PLAY_AGAIN="Play sound again" | ||
;PLG_RECAPTCHA_CANT_HEAR_THIS="Download sound as MP3" | ||
;PLG_RECAPTCHA_VISUAL_CHALLENGE="Get a visual challenge" | ||
;PLG_RECAPTCHA_AUDIO_CHALLENGE="Get an audio challenge" | ||
;PLG_RECAPTCHA_REFRESH_BTN="Get a new challenge" | ||
;PLG_RECAPTCHA_HELP_BTN="Help" | ||
;PLG_RECAPTCHA_INCORRECT_TRY_AGAIN="Incorrect. Try again." |
8 changes: 8 additions & 0 deletions
8
administrator/language/en-GB/en-GB.plg_captcha_recaptcha.sys.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
; $id: | ||
; Joomla! Project | ||
; Copyright (C) 2005 - 2009 Open Source Matters. All rights reserved. | ||
; License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php | ||
; Note : All ini files need to be saved as UTF-8 | ||
|
||
PLG_CAPTCHA_RECAPTCHA_XML_DESCRIPTION="" | ||
PLG_CAPTCHA_RECAPTCHA="Captcha - ReCaptcha" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
<?php | ||
/** | ||
* @version $Id: captcha.php | ||
* @package Joomla.Framework | ||
* @subpackage Cache | ||
* @copyright Copyright (C) 2005 - 2009 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
// No direct access | ||
defined('JPATH_BASE') or die; | ||
|
||
/** | ||
* Joomla! Captcha base object | ||
* | ||
* @abstract | ||
* @package Joomla.Framework | ||
* @subpackage Captcha | ||
* @since 1.6 | ||
*/ | ||
class JCaptcha extends JObservable | ||
{ | ||
/** | ||
* Captcha Plugin object | ||
* | ||
* @var object | ||
*/ | ||
protected $_captcha; | ||
|
||
/** | ||
* Editor Plugin name | ||
* | ||
* @var string | ||
*/ | ||
protected $_name; | ||
|
||
/** | ||
* Class constructor. | ||
* | ||
*/ | ||
public function __construct($captcha, $options) | ||
{ | ||
$this->_name = $captcha; | ||
$this->_load($options); | ||
} | ||
|
||
/** | ||
* Returns the global Captcha object, only creating it | ||
* if it doesn't already exist. | ||
* | ||
* @param string $editor The editor to use. | ||
* @return object The JCaptcha object. | ||
*/ | ||
public static function getInstance($captcha = '', $options = array()) | ||
{ | ||
static $instances; | ||
|
||
if (is_null($instances)) $instances = array(); | ||
|
||
$signature = md5(serialize(array($captcha, $options))); | ||
|
||
if (empty($instances[$signature])) { | ||
$instances[$signature] = new JCaptcha($captcha, $options); | ||
} | ||
|
||
return $instances[$signature]; | ||
} | ||
|
||
public function initialise($id) | ||
{ | ||
$args['id'] = $id ; | ||
$args['event'] = 'onInit'; | ||
|
||
try | ||
{ | ||
$this->_captcha->update($args); | ||
} | ||
catch (Exception $e) | ||
{ | ||
JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error'); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Get the HTML for the captcha. | ||
* | ||
* @return the return value of the function "onDisplay" of the selected Plugin. | ||
* @since 1.6 | ||
*/ | ||
public function display($name, $id, $class = '') | ||
{ | ||
// Check if captcha is already loaded. | ||
if(is_null(($this->_captcha))) { | ||
return; | ||
} | ||
|
||
// Initialise the Captcha. | ||
if(!$this->initialise($id)) { | ||
return; | ||
} | ||
|
||
$args['name'] = $name; | ||
$args['id'] = $id ? $id : $name; | ||
$args['class'] = $class ? 'class="'.$class.'"' : ''; | ||
$args['event'] = 'onDisplay'; | ||
|
||
return $this->_captcha->update($args); | ||
} | ||
|
||
/** | ||
* Checks if the answer is correct. | ||
* | ||
* @return the return value of the function "onCheckAnswer" of the selected Plugin. | ||
* @since 1.6 | ||
*/ | ||
public function checkAnswer($code) | ||
{ | ||
//check if captcha is already loaded | ||
if (is_null(($this->_captcha))) { | ||
return; | ||
} | ||
|
||
$args['code'] = $code; | ||
$args['event'] = 'onCheckAnswer'; | ||
|
||
return $this->_captcha->update($args); | ||
} | ||
|
||
/** | ||
* Load the Captcha. | ||
* | ||
* @since 1.6 | ||
*/ | ||
protected function _load($options) | ||
{ | ||
jimport('joomla.filesystem.file'); | ||
|
||
// Build the path to the needed captcha plugin | ||
$name = JFilterInput::getInstance()->clean($this->_name, 'cmd'); | ||
$path = JPATH_SITE.'/plugins/captcha/'.$name.'/'.$name.'.php'; | ||
|
||
if (!JFile::exists($path)) | ||
{ | ||
$path = JPATH_SITE.'/plugins/captcha/'.$name.'.php'; | ||
if (!JFile::exists($path)) | ||
{ | ||
throw new Exception(JText::sprintf('JLIB_CAPTCHA_ERROR_PLUGIN_NOT_FOUND', $name)); | ||
} | ||
} | ||
|
||
// Require plugin file | ||
require_once $path; | ||
|
||
// Get the plugin | ||
$plugin = JPluginHelper::getPlugin('captcha', $this->_name); | ||
if (!$plugin) throw new Exception(JText::sprintf('JLIB_CAPTCHA_ERROR_LOADING', $name)); | ||
$params = new JRegistry($plugin->params); | ||
$plugin->params = $params; | ||
|
||
// Build captcha plugin classname | ||
$name = 'plgCaptcha'.$this->_name; | ||
$this->_captcha = new $name($this, (array)$plugin, $options); | ||
} | ||
} |
Oops, something went wrong.