Initial commit

This commit is contained in:
2019-11-20 07:44:43 +01:00
commit 5bf49c4a81
41188 changed files with 5459177 additions and 0 deletions

View File

@@ -0,0 +1,143 @@
<?php
/**
* Invisiblerecaptcha Prestashop module
*
* NOTICE OF LICENSE
*
* This file is licenced under the Software License Agreement.
* With the purchase or the installation of the software in your application
* you accept the licence agreement.
*
* You must not modify, adapt or create derivative works of this source code
*
* @author Wiktor Koźmiński
* @copyright 2017-2017 Silver Rose Wiktor Koźmiński
* @license LICENSE.txt
*/
namespace Invisiblerecaptcha\Common;
/**
* Configuration class, store all config in one DB record in JSON
*/
class Config
{
const CONFIG_COLUMN_NAME = 'wk_invisiblerecaptcha_config';
/** Config data */
public $sitekey;
public $secretkey;
/** --- */
public function __construct($initialLoad = true)
{
if ($initialLoad) {
$this->load();
}
}
/**
* Purges (removes) current configuration from presta db
* @return void
*/
public static function purge()
{
\Configuration::deleteByName(self::CONFIG_COLUMN_NAME);
}
/**
* Saves current config into DB.
* @param boolean $getPostValues if set to true, get post values with 'config_' prefix
* @return void
*/
public function update($getPostValues = true)
{
if ($getPostValues) {
$this->assignPostValues();
}
$json = \Tools::jsonEncode($this);
\Configuration::updateValue(self::CONFIG_COLUMN_NAME, $json);
}
/**
* Loads config from DB.
* @return boolean false if values couldn't been loaded
*/
public function load()
{
$json = \Configuration::get(self::CONFIG_COLUMN_NAME);
if ($json === false) {
return false;
}
$values = \Tools::jsonDecode($json, true);
if (is_array($values)) {
foreach ($values as $key => $v) {
if (property_exists($this, $key)) {
$this->$key = $v;
}
}
}
return true;
}
/**
* Assign post values with prefix 'config_' to class vars.
* @return void
*/
private function assignPostValues()
{
foreach (get_object_vars($this) as $key => $value) {
$v = \Tools::getValue('config_'.$key);
if ($v !== false) {
$this->$key = $v;
}
}
}
public function getConfigFormValues()
{
$r = array(
'config_sitekey' => $this->sitekey,
'config_secretkey' => $this->secretkey,
);
return $r;
}
/**
* Create the structure of your form.
*/
public static function getConfigForm(\Module $module)
{
return array(
'form' => array(
'legend' => array(
'title' => $module->l('Settings'),
'icon' => 'icon-cogs',
),
'input' => array(
array(
'col' => 3,
'type' => 'text',
'desc' => $module->l('Enter a valid site key'),
'name' => 'config_sitekey',
'label' => $module->l('Site key'),
),
array(
'col' => 3,
'type' => 'text',
'desc' => $module->l('Enter a valid secret key'),
'name' => 'config_secretkey',
'label' => $module->l('Secret key'),
),
),
'submit' => array(
'title' => $module->l('Save'),
),
),
);
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2017 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,59 @@
<?php
/**
* Invisiblerecaptcha Prestashop module
*
* NOTICE OF LICENSE
*
* This file is licenced under the Software License Agreement.
* With the purchase or the installation of the software in your application
* you accept the licence agreement.
*
* You must not modify, adapt or create derivative works of this source code
*
* @author Wiktor Koźmiński
* @copyright 2017-2017 Silver Rose Wiktor Koźmiński
* @license LICENSE.txt
*/
namespace Invisiblerecaptcha\Recaptcha;
class Recaptcha
{
const VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify';
private $secret;
public function __construct($secret)
{
if (!$secret) {
throw new \RuntimeException('No secret provided');
}
$this->secret = $secret;
}
/**
* Checks token on google server
*
* @todo create alternative for @file_get_contents
*
* @param string $responseToken
* @return bool
*/
public function verifyResponse($responseToken)
{
$data = array(
'secret' => $this->secret,
'response' => $responseToken
);
$res = file_get_contents(self::VERIFY_URL . '?' . http_build_query($data));
$res = json_decode($res, true);
if (isset($res['success']) and $res['success'] == true) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2017 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2017 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,19 @@
<?php
/**
* Invisiblerecaptcha Prestashop module
*
* NOTICE OF LICENSE
*
* This file is licenced under the Software License Agreement.
* With the purchase or the installation of the software in your application
* you accept the licence agreement.
*
* You must not modify, adapt or create derivative works of this source code
*
* @author Wiktor Koźmiński
* @copyright 2017-2017 Silver Rose Wiktor Koźmiński
* @license LICENSE.txt
*/
require_once 'Common/Config.php';
require_once 'Recaptcha/Recaptcha.php';