За последние 24 часа нас посетили 22276 программистов и 998 роботов. Сейчас ищет 661 программист ...

Как встроить рекапчу 2 на joomla 1.5?

Тема в разделе "PHP для новичков", создана пользователем VaneS, 23 сен 2020.

Метки:
  1. VaneS

    VaneS Активный пользователь

    С нами с:
    16 ноя 2011
    Сообщения:
    636
    Симпатии:
    4
    Адрес:
    Россия
    Добрый день!
    Прилетела задача встроить рекапчу 2 на joomla 1.5, а именно она должна быть в форме при регистрации пользователей!
    За основу я взял этот плагин:
    https://github.com/milkycode/joomla_recaptcha_j15
    Далее открыл файл по адресу:
    Код (Text):
    1. /components/com_user/views/register/tmpl/default.php
    В нем к форме добавил следующий код:
    PHP:
    1. <tr>
    2.   <td colspan="2">
    3.     <?php echo ReCaptcha::get('html'); ?>
    4.   </td>
    5. </tr>
    В админке прописал публичный и секретный ключ.
    В результате у меня появилась рекапча в форме.
    Далее я открыл файл:
    Код (Text):
    1. /components/com_user/controller.php
    В нем нашел функцию:
    PHP:
    1. function register_save()
    2.   {
    3.     global $mainframe;
    4.  
    5.     // Check for request forgeries
    6.     JRequest::checkToken() or jexit( 'Invalid Token' );
    7.  
    8.     // Get required system objects
    9.     $user         = clone(JFactory::getUser());
    10.     $pathway     =& $mainframe->getPathway();
    11.     $config        =& JFactory::getConfig();
    12.     $authorize    =& JFactory::getACL();
    13.     $document   =& JFactory::getDocument();
    14.  
    15.     // If user registration is not allowed, show 403 not authorized.
    16.     $usersConfig = &JComponentHelper::getParams( 'com_users' );
    17.     if ($usersConfig->get('allowUserRegistration') == '0') {
    18.       JError::raiseError( 403, JText::_( 'Access Forbidden' ));
    19.       return;
    20.     }
    21.  
    22.     // Initialize new usertype setting
    23.     $newUsertype = $usersConfig->get( 'new_usertype' );
    24.     if (!$newUsertype) {
    25.       $newUsertype = 'Registered';
    26.     }
    27.  
    28.     // Bind the post array to the user object
    29.     if (!$user->bind( JRequest::get('post'), 'usertype' )) {
    30.       JError::raiseError( 500, $user->getError());
    31.     }
    32.  
    33.     // Set some initial user values
    34.     $user->set('id', 0);
    35.     $user->set('usertype', $newUsertype);
    36.     $user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));
    37.  
    38.     $date =& JFactory::getDate();
    39.     $user->set('registerDate', $date->toMySQL());
    40.  
    41.     // If user activation is turned on, we need to set the activation information
    42.     $useractivation = $usersConfig->get( 'useractivation' );
    43.     if ($useractivation == '1')
    44.     {
    45.       jimport('joomla.user.helper');
    46.       $user->set('activation', JUtility::getHash( JUserHelper::genRandomPassword()) );
    47.       $user->set('block', '1');
    48.     }
    49.  
    50.     // If there was an error with registration, set the message and display form
    51.  
    52.     if (ReCaptcha::get('submit')) { //
    53.       if (!ReCaptcha::get('success')) {
    54.         JError::raiseWarning('', 'Неверный код проверки!'); //если не верно выводим сообщение
    55.         $this->register();
    56.         return false;
    57.        }else{
    58.       if ( !$user->save() )
    59.       {
    60.         JError::raiseWarning('', JText::_( $user->getError()));
    61.         $this->register();
    62.         return false;
    63.       }
    64.  
    65.       // Send registration confirmation mail
    66.       $password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW);
    67.       $password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); //Disallow control chars in the email
    68.       UserController::_sendMail($user, $password);
    69.  
    70.       // Everything went fine, set relevant message depending upon user activation state and display message
    71.       if ( $useractivation == 1 ) {
    72.         $message  = JText::_( 'REG_COMPLETE_ACTIVATE' );
    73.       } else {
    74.         $message = JText::_( 'REG_COMPLETE' );
    75.       }
    76.  
    77.       $this->setRedirect('index.php', $message);
    78.        }
    79.      }else{
    80.     print_r(ReCaptcha::get('submit'));
    81.     JError::raiseWarning('', 'Не удалось проверить капчу!'); //если не верно выводим сообщение
    82.     $this->register();
    83.     return false;
    84.      }
    85.   }
    Вся проверка капчи происходит тут:
    PHP:
    1. if (ReCaptcha::get('submit')) { //
    2.       if (!ReCaptcha::get('success')) {
    3.         JError::raiseWarning('', 'Неверный код проверки!'); //если не верно выводим сообщение
    4.         $this->register();
    5.         return false;
    6.        }else{
    7.       if ( !$user->save() )
    8.       {
    9.         JError::raiseWarning('', JText::_( $user->getError()));
    10.         $this->register();
    11.         return false;
    12.       }
    13.  
    14.       // Send registration confirmation mail
    15.       $password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW);
    16.       $password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); //Disallow control chars in the email
    17.       UserController::_sendMail($user, $password);
    18.  
    19.       // Everything went fine, set relevant message depending upon user activation state and display message
    20.       if ( $useractivation == 1 ) {
    21.         $message  = JText::_( 'REG_COMPLETE_ACTIVATE' );
    22.       } else {
    23.         $message = JText::_( 'REG_COMPLETE' );
    24.       }
    25.  
    26.       $this->setRedirect('index.php', $message);
    27.        }
    28.      }else{
    29.     print_r(ReCaptcha::get('submit'));
    30.     JError::raiseWarning('', 'Не удалось проверить капчу!'); //если не верно выводим сообщение
    31.     $this->register();
    32.     return false;
    33.      }
    У меня почему то не выполняется это условие:
    PHP:
    1. if (ReCaptcha::get('submit'))
    И выполняется код:
    PHP:
    1. }else{
    2.     print_r(ReCaptcha::get('submit'));
    3.     JError::raiseWarning('', 'Не удалось проверить капчу!'); //если не верно выводим сообщение
    4.     $this->register();
    5.     return false;
    6.      }
    Что я делаю не так? Заранее большое спасибо!