Пример #1
0
 /**
  * Generate <div> with ReCaptcha from render.
  *
  * @param boolean $useRecaptcha Boolean of active state, for compact templating
  *
  * @return string $html
  */
 public function html($useRecaptcha = true)
 {
     if (!isset($useRecaptcha) || !$useRecaptcha) {
         return false;
     }
     if ($this->recaptcha->getPublicKey() === null) {
         throw new Exception('Missing public key');
     }
     $host = \ZendService\Recaptcha\Recaptcha::API_SERVER;
     $params = $this->recaptcha->getParams();
     if ((bool) $params['ssl'] === true) {
         $host = \ZendService\Recaptcha\Recaptcha::API_SECURE_SERVER;
     }
     $errorPart = '';
     if (!empty($params['error'])) {
         $errorPart = '&error=' . urlencode($params['error']);
     }
     $options = $this->recaptcha->getOptions();
     if (!empty($options)) {
         $encoded = \Zend\Json\Json::encode($options);
     } else {
         $encoded = "{}";
     }
     $challengeField = 'recaptcha_challenge_field';
     $responseField = 'recaptcha_response_field';
     if (!empty($name)) {
         $challengeField = $name . '[' . $challengeField . ']';
         $responseField = $name . '[' . $responseField . ']';
     }
     return $this->view->render('Service/recaptcha.phtml', ['challengeField' => $challengeField, 'errorPart' => $errorPart, 'host' => $host, 'options' => $encoded, 'publicKey' => $this->recaptcha->getPublicKey(), 'responseField' => $responseField, 'theme' => $options['theme'], 'useRecaptcha' => $useRecaptcha]);
 }