1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
namespace ClicShopping\Sites\Shop;
use core\Registry;
use core\HTML;
use core\OSCOM;
class GoogleRecaptcha {
const API = 'https://www.google.com/recaptcha/';
const SECRET_KEY = MODULES_CONTACT_US_GOOGLE_RECAPTCHA_SECRET_KEY;
const SITE_KEY = MODULES_CONTACT_US_GOOGLE_RECAPTCHA_SITE_KEY;
public function script() {
$OSCOM_Template = Registry::get('Template');
$footer ='<!-- contact_us google captcha end -->' . "\n";
// $footer .= '<script src="' . self::API . 'api.js" async defer></script>' . "\n";
$footer .= '<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer>' . "\n";
$footer .='<!-- contact_us google captcha end -->' . "\n";
return $OSCOM_Template->addBlock($footer, 'footer_scripts');
}
public function html($includeNoScript = false) {
$return = '
<script type="text/javascript">
var onloadCallback = function() {
grecaptcha.render(\'g-recaptcha\', {
\'sitekey\' : \'' . self::SITE_KEY . '\',
\'callback\': \'verifyCallback\' // optional
});
};
</script>
';
$return .= '<div id="g-recaptcha" data-callback=verifyCallback></div>';
// $return .= '<div class="g-recaptcha" data-sitekey="' . self::SITE_KEY . '"></div>';
if($includeNoScript == true) {
$return .= $this->noScript();
}
return $return;
}
private function noScript() {
$output = '<noscript>';
$output .= '<div style="width: 302px; height: 352px;">';
$output .='<div style="width: 302px; height: 352px; position: relative;">';
$output .= '<div style="width: 302px; height: 352px; position: absolute;">';
$output .= '<iframe src="' . self::API . 'api/fallback?k=' . self::SITE_KEY . '" frameborder="0" scrolling="no" style="width: 302px; height:352px; border-style: none;"></iframe>';
$output .= '</div>';
$output .= '<div style="width: 250px; height: 80px; position: absolute; border-style: none; bottom: 21px; left: 25px; margin: 0px; padding: 0px; right: 25px;">';
$output .= HTML::textAreaField('g-recaptcha-response','', '250px', '80px', 'id="g-recaptcha-response" class="g-recaptcha-response" style="border: 1px solid #c1c1c1; margin: 0px; padding: 0px; resize: none;"');
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
$output .= '</noscript>';
return $output;
}
public function check($response) {
$url = self::API . 'api/siteverify?secret=' . self::SECRET_KEY . '&response='.$response;
$response = file_get_contents($url);
if($response->success === true) {
return true;
} else {
return false;
}
}
public function display() {
$output = '<!-- contact_us secret google captcha start -->'. "\n";
$output .= $this->script();
$output .= $this->html();
return $output;
} |
Partager