From 19e4f9783973b4c44c2607b8b0873270d6451f97 Mon Sep 17 00:00:00 2001 From: nickspencer <nick.spencer@seersco.com> Date: Thu, 13 Oct 2022 17:33:23 +0500 Subject: [PATCH 1/2] candidate branch v2.0.0 --- seers_cookie_consent_privacy_policy.info.yml | 4 +++- seers_cookie_consent_privacy_policy.module | 9 ++++++++- src/Form/SeerCookieConsentForm.php | 18 ++++++++++++++++-- src/Service/CustomFunctions.php | 12 ++++++++---- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/seers_cookie_consent_privacy_policy.info.yml b/seers_cookie_consent_privacy_policy.info.yml index a8b23fc..37b9988 100644 --- a/seers_cookie_consent_privacy_policy.info.yml +++ b/seers_cookie_consent_privacy_policy.info.yml @@ -1,6 +1,8 @@ name: 'Seers Cookie Consent Banner Privacy Policy' type: module description: 'Seers cookie consent fulfils the requirements of transparency, consent and documentation under ePrivacy Directive and GDPR.' -version: 1.0.4 +version: 2.0.0 core_version_requirement: ^7 || ^8 || ^9 package: 'Custom' +apisecretkey: '$2y$10$9ygTfodVBVM0XVCdyzEUK.0FIuLnJT0D42sIE6dIu9r/KY3XaXXyS' +endpointbaseurl: 'https://cmp.seersco.com/api/v2/' diff --git a/seers_cookie_consent_privacy_policy.module b/seers_cookie_consent_privacy_policy.module index 6c48565..315a4b8 100644 --- a/seers_cookie_consent_privacy_policy.module +++ b/seers_cookie_consent_privacy_policy.module @@ -37,13 +37,20 @@ function seers_cookie_consent_privacy_policy_page_attachments(&$page) * Initial JS. */ if (!empty($config["cookie_id"])) { + + $scriptsrc = "https://cmp.seersco.com/script/cb.js"; + + if (!empty($config["scriptbaseurl"]) && !empty($config["user_id"]) && !empty($config["domain_id"])) { + $scriptsrc = $config["scriptbaseurl"] . "banners/" . $config["user_id"] . "/" . $config["domain_id"] . "/cb.js"; + } + $page['#attached']['html_head'][] = [ [ // Add a <script> tag. '#tag' => 'script', // Add attributes to the <script> tag. '#attributes' => [ - 'src' => 'https://cmp.seersco.com/script/cb.js', + 'src' => $scriptsrc, 'type' => 'text/javascript', 'data-key' => $config["cookie_id"], 'data-name' => 'CookieXray', diff --git a/src/Form/SeerCookieConsentForm.php b/src/Form/SeerCookieConsentForm.php index 485429d..7897d3d 100644 --- a/src/Form/SeerCookieConsentForm.php +++ b/src/Form/SeerCookieConsentForm.php @@ -4,6 +4,7 @@ namespace Drupal\seers_cookie_consent_privacy_policy\Form; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; +use Symfony\Component\Yaml\Yaml; /** * Class SeerCookieConsentForm. @@ -11,6 +12,9 @@ use Drupal\Core\Form\FormStateInterface; class SeerCookieConsentForm extends ConfigFormBase { + private $apikey; + private $apibaseurl; + /** * {@inheritdoc} */ @@ -35,6 +39,10 @@ class SeerCookieConsentForm extends ConfigFormBase public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('seers_cookie_consent_privacy_policy.seercookieconsent'); + $moduleyml = Yaml::parseFile(DRUPAL_ROOT . '/'. \Drupal::service('extension.list.module')->getPath('seers_cookie_consent_privacy_policy') . '/seers_cookie_consent_privacy_policy.info.yml'); + $this->apikey = $moduleyml["apisecretkey"]; + $this->apibaseurl = $moduleyml["endpointbaseurl"]; + $user = \Drupal::currentUser(); $form['consent_url'] = [ '#type' => 'textfield', @@ -95,7 +103,7 @@ class SeerCookieConsentForm extends ConfigFormBase $postData = array( 'domain'=>$baseurl, 'email'=>$useremail, - 'secret'=>'$2y$10$9ygTfodVBVM0XVCdyzEUK.0FIuLnJT0D42sIE6dIu9r/KY3XaXXyS', + 'secret'=>$this->apikey, 'platform'=>'drupal', 'lang' => \Drupal::languageManager()->getCurrentLanguage()->getId() ); @@ -104,7 +112,7 @@ class SeerCookieConsentForm extends ConfigFormBase 'Content-Type: application/json', 'Referer: '.$baseurl ); - $url = "https://seersco.com/api/save-domain-credentials"; + $url = $this->apibaseurl . "save-domain-credentials"; $postdata = json_encode($postData); $ch = curl_init($url); @@ -128,6 +136,9 @@ class SeerCookieConsentForm extends ConfigFormBase ->set('consent_email', $useremail) ->set('consent_url', $baseurl) ->set('cookie_id', $consetid) + ->set('scriptbaseurl', ((!empty($response['cdnbaseurl'])) ? $response['cdnbaseurl'] : "" )) + ->set('user_id', ((!empty($response['user_id'])) ? $response['user_id'] : "" )) + ->set('domain_id', ((!empty($response['domain_id'])) ? $response['domain_id'] : "" )) ->set('seers_term_condition', $form_state->getValue('seers_term_condition')) ->set('seers_term_condition_url', $form_state->getValue('seers_term_condition_url')) ->save(); @@ -137,6 +148,9 @@ class SeerCookieConsentForm extends ConfigFormBase ->set('consent_email', $useremail) ->set('consent_url', $baseurl) ->set('cookie_id', "") + ->set('scriptbaseurl', "") + ->set('user_id', "") + ->set('domain_id ', "") ->set('seers_term_condition', $form_state->getValue('seers_term_condition')) ->set('seers_term_condition_url', $form_state->getValue('seers_term_condition_url')) ->save(); diff --git a/src/Service/CustomFunctions.php b/src/Service/CustomFunctions.php index 89dea3c..c2a2b75 100644 --- a/src/Service/CustomFunctions.php +++ b/src/Service/CustomFunctions.php @@ -8,7 +8,8 @@ namespace Drupal\seers_cookie_consent_privacy_policy\Service; */ class CustomFunctions { - public $apisecrekkey = '$2y$10$9ygTfodVBVM0XVCdyzEUK.0FIuLnJT0D42sIE6dIu9r/KY3XaXXyS'; + private $apikey; + private $apibaseurl; /** * Does something. @@ -17,20 +18,23 @@ class CustomFunctions { * Some value. */ public function doActiveInactive($isactive = 0, $modulename='') { + $moduleyml = Yaml::parseFile(DRUPAL_ROOT . '/'. \Drupal::service('extension.list.module')->getPath('seers_cookie_consent_privacy_policy') . '/seers_cookie_consent_privacy_policy.info.yml'); + $this->apikey = $moduleyml["apisecretkey"]; + $this->apibaseurl = $moduleyml["endpointbaseurl"]; $postData = array( 'domain' => \Drupal::request()->getHost(), 'isactive' => $isactive, - 'secret' => $this->apisecrekkey, + 'secret' => $this->apikey, 'platform' => 'drupal', - 'pluginname' => $modulename + 'pluginname' => $modulename . " v" . $moduleyml["version"] ); $request_headers = array( 'Content-Type' => 'application/json', 'Referer' => \Drupal::request()->getHost(), ); //$url = "https://seersco.backend/api/plugin-domain"; - $url = "https://cmp.seersco.com/api/plugin-domain"; + $url = $this->apibaseurl . "plugin-domain"; $curl = curl_init(); curl_setopt_array($curl, array( -- GitLab From 1813fb4c451914493050a7ae984425c9879d2e5e Mon Sep 17 00:00:00 2001 From: nickspencer <nick.spencer@seersco.com> Date: Thu, 13 Oct 2022 18:02:29 +0500 Subject: [PATCH 2/2] remove extra comment --- src/Service/CustomFunctions.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Service/CustomFunctions.php b/src/Service/CustomFunctions.php index c2a2b75..fcedc05 100644 --- a/src/Service/CustomFunctions.php +++ b/src/Service/CustomFunctions.php @@ -33,7 +33,6 @@ class CustomFunctions { 'Content-Type' => 'application/json', 'Referer' => \Drupal::request()->getHost(), ); - //$url = "https://seersco.backend/api/plugin-domain"; $url = $this->apibaseurl . "plugin-domain"; $curl = curl_init(); -- GitLab