feat(cadline): add com_users Cadline additions (recaptcha, easyprofile)

Cadline/JSN additions to com_users: recaptchalib.php (anti-spam), easyprofile.php views (JSN EasyProfile) — only-in-live files not caught by the core-override diff.

Signed-off-by: LÁZÁR Imre <imre@illusion.hu>
Assisted-by: claude-code@claude-opus-4-8
This commit is contained in:
LÁZÁR Imre AI Agent 2026-07-16 11:39:03 +02:00
parent 692879ea2d
commit 0433c61dba
3 changed files with 294 additions and 0 deletions

View File

@ -0,0 +1,143 @@
<?php
/**
* This is a PHP library that handles calling reCAPTCHA.
* - Documentation and latest version
* https://developers.google.com/recaptcha/docs/php
* - Get a reCAPTCHA API Key
* https://www.google.com/recaptcha/admin/create
* - Discussion group
* http://groups.google.com/group/recaptcha
*
* @copyright Copyright (c) 2014, Google Inc.
* @link http://www.google.com/recaptcha
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* A ReCaptchaResponse is returned from checkAnswer().
*/
class ReCaptchaResponse
{
public $success;
public $errorCodes;
}
class ReCaptcha
{
private static $_signupUrl = "https://www.google.com/recaptcha/admin";
private static $_siteVerifyUrl =
"https://www.google.com/recaptcha/api/siteverify?";
private $_secret;
private static $_version = "php_1.0";
/**
* Constructor.
*
* @param string $secret shared secret between site and ReCAPTCHA server.
*/
function ReCaptcha($secret)
{
if ($secret == null || $secret == "") {
die("To use reCAPTCHA you must get an API key from <a href='"
. self::$_signupUrl . "'>" . self::$_signupUrl . "</a>");
}
$this->_secret=$secret;
}
/**
* Encodes the given data into a query string format.
*
* @param array $data array of string elements to be encoded.
*
* @return string - encoded request.
*/
private function _encodeQS($data)
{
$req = "";
foreach ($data as $key => $value) {
$req .= $key . '=' . urlencode(stripslashes($value)) . '&';
}
// Cut the last '&'
$req=substr($req, 0, strlen($req)-1);
return $req;
}
/**
* Submits an HTTP GET to a reCAPTCHA server.
*
* @param string $path url path to recaptcha server.
* @param array $data array of parameters to be sent.
*
* @return array response
*/
private function _submitHTTPGet($path, $data)
{
$req = $this->_encodeQS($data);
$response = file_get_contents($path . $req);
return $response;
}
/**
* Calls the reCAPTCHA siteverify API to verify whether the user passes
* CAPTCHA test.
*
* @param string $remoteIp IP address of end user.
* @param string $response response string from recaptcha verification.
*
* @return ReCaptchaResponse
*/
public function verifyResponse($remoteIp, $response)
{
// Discard empty solution submissions
if ($response == null || strlen($response) == 0) {
$recaptchaResponse = new ReCaptchaResponse();
$recaptchaResponse->success = false;
$recaptchaResponse->errorCodes = 'missing-input';
return $recaptchaResponse;
}
$getResponse = $this->_submitHttpGet(
self::$_siteVerifyUrl,
array (
'secret' => $this->_secret,
'remoteip' => $remoteIp,
'v' => self::$_version,
'response' => $response
)
);
$answers = json_decode($getResponse, true);
$recaptchaResponse = new ReCaptchaResponse();
if (trim($answers ['success']) == true) {
$recaptchaResponse->success = true;
} else {
$recaptchaResponse->success = false;
$recaptchaResponse->errorCodes = $answers [error-codes];
}
if ($_SERVER['REMOTE_ADDR'] == '85.66.171.33') {
var_dump($recaptchaResponse);
die();
}
return $recaptchaResponse;
}
}

View File

@ -0,0 +1,76 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_users
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
if(class_exists('FieldsHelper')) FieldsHelper::prepareForm('com_users.user', $this->form, $this->data);
include( JPATH_SITE . '/components/com_users/views/profile/tmpl/edit.php');
$config = JComponentHelper::getParams('com_jsn');
$layout_width=$config->get('layout_width','full');
if( $layout_width == 'full' ) $max_width = 'none';
else $max_width = $config->get('layout_maxwidth','500');
$layout=$config->get('layout_form','horizontal');
$session = JFactory::getSession();
$profile_menuid = $session->get('jsn_profile_item_id_'.(JFactory::getApplication()->input->get('user_id',JFactory::getUser()->id)),false);
if($profile_menuid) $Itemid = '&Itemid='.$profile_menuid;
else $Itemid = '';
?>
<style>
div.profile-edit{max-width:<?php if ( empty($max_width) ) echo 'none'; else echo $max_width.'px'; ?>;margin:auto;}
div.profile-edit.formfullwidth{max-width:none;}
#profile_tabs{font-weight:bold;}
#member-profile.form-horizontal .control-group.privacy + .control-group .controls > input,
#member-profile.form-horizontal .control-group.privacy + .control-group .controls > .input-prepend input,
#member-profile.form-horizontal .control-group.privacy + .control-group .controls > fieldset.radio,
#member-profile.form-horizontal .control-group.privacy + .control-group .controls > fieldset.checkboxes,
#member-profile.form-horizontal .control-group.privacy + .control-group .controls > textarea{padding-right:45px !important;}
#member-profile .controls > input,#member-profile .controls > textarea,#member-profile .controls > .input-prepend,#member-profile .controls > .input-prepend input{width:100%;box-sizing:border-box;height:auto;}
#member-profile .controls > input[type="file"]{width:auto;}
#member-profile .control-label label{font-weight:bold;}
.jsn_registration_controls{border-top:1px solid #ccc;padding:20px 0 0;margin-top:20px;clear:both;}
</style>
<script>
jQuery(document).ready(function($){
$('#member-profile > .control-group .controls a').attr('href',"<?php echo JRoute::_('index.php?option=com_jsn&view=profile'.$Itemid.'&id='.JFactory::getApplication()->input->get('user_id',''),false); ?>");
if( $('div.profile-edit').parent().width() < 800 ) {
$('div.profile-edit').addClass('formfullwidth');
}
<?php if ( $layout == 'horizontal' ) : ?>
if( $('div.profile-edit').parent().width() < 500 ) {
$('#member-profile').removeClass('form-horizontal');
}
<?php endif; ?>
<?php if ( $layout == 'vertical' ) : ?>$('#member-profile').removeClass('form-horizontal');<?php endif; ?>
$(window).resize(function(){
if( $('div.profile-edit').parent().width() < 800 ) {
$('div.profile-edit').addClass('formfullwidth');
}
else {
$('div.profile-edit').removeClass('formfullwidth');
}
<?php if ( $layout == 'horizontal' ) : ?>
if( $('div.profile-edit').parent().width() < 500 ) {
$('#member-profile').removeClass('form-horizontal');
}
else {
$('#member-profile').addClass('form-horizontal');
}
<?php endif; ?>
});
$('#member-profile a.btn:not([class*="btn-"])').addClass('btn-danger');
$('#member-profile .control-group > .control-label > label').each(function(){
$(this).closest('.control-group').addClass($(this).attr('id').replace('jform_','').replace('-lbl','-group'));
});
if($('#system-message-container').length) $('#system-message-container').prependTo("#member-profile");
else $("#member-profile").prepend('<div id="system-message-container" />');
});
</script>

View File

@ -0,0 +1,75 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_users
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
include( JPATH_SITE . '/components/com_users/views/registration/tmpl/default.php');
$config = JComponentHelper::getParams('com_jsn');
$layout_width=$config->get('layout_width','full');
if( $layout_width == 'full' ) $max_width = 'none';
else $max_width = $config->get('layout_maxwidth','500');
$layout=$config->get('layout_form','horizontal');
$lang = JFactory::getLanguage();
$result = $lang->getTag();
?>
<style>
<?php if($result == "hu-HU") :?>
.spacer-container{display: none;}
<?php endif;?>
.star {display: none;}
div.registration{max-width:<?php if ( empty($max_width) ) echo 'none'; else echo $max_width.'px'; ?>;margin:auto;}
div.registration.formfullwidth{max-width:none;}
#profile_tabs{font-weight:bold;}
#member-registration.form-horizontal .control-group.privacy + .control-group .controls > input,
#member-registration.form-horizontal .control-group.privacy + .control-group .controls > .input-prepend input,
#member-registration.form-horizontal .control-group.privacy + .control-group .controls > fieldset.radio,
#member-registration.form-horizontal .control-group.privacy + .control-group .controls > fieldset.checkboxes,
#member-registration.form-horizontal .control-group.privacy + .control-group .controls > textarea{padding-right:45px !important;}
#member-registration .controls > input,#member-registration .controls > textarea,#member-registration .controls > .input-prepend,#member-registration .controls > .input-prepend input{width:100%;box-sizing:border-box;height:auto;}
#member-registration .controls > input[type="file"]{width:auto;}
#member-registration .control-label label{font-weight:bold;}
.jsn_registration_controls{border-top:1px solid #ccc;padding:20px 0 0;margin-top:20px;clear:both;}
</style>
<script>
jQuery(document).ready(function($){
if( $('div.registration').parent().width() < 800 ) {
$('div.registration').addClass('formfullwidth');
}
<?php if ( $layout == 'horizontal' ) : ?>
if( $('div.registration').parent().width() < 500 ) {
$('#member-registration').removeClass('form-horizontal');
}
<?php endif; ?>
<?php if ( $layout == 'vertical' ) : ?>$('#member-registration').removeClass('form-horizontal');<?php endif; ?>
$(window).resize(function(){
if( $('div.registration').parent().width() < 800 ) {
$('div.registration').addClass('formfullwidth');
}
else {
$('div.registration').removeClass('formfullwidth');
}
<?php if ( $layout == 'horizontal' ) : ?>
if( $('div.registration').parent().width() < 500 ) {
$('#member-registration').removeClass('form-horizontal');
}
else {
$('#member-registration').addClass('form-horizontal');
}
<?php endif; ?>
});
$('#member-registration a.btn:not([class*="btn-"])').addClass('btn-danger');
$('#member-registration .control-group > .control-label > label').each(function(){
$(this).closest('.control-group').addClass($(this).attr('id').replace('jform_','').replace('-lbl','-group'));
});
if($('#system-message-container').length) $('#system-message-container').prependTo("#member-registration");
else $("#member-registration").prepend('<div id="system-message-container" />');
});
</script>