Skip to content

Commit

Permalink
Merge pull request #5 from tagconcierge/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mfrankiewicz authored Apr 26, 2024
2 parents 2850a13 + dee4d0e commit d17765c
Show file tree
Hide file tree
Showing 26 changed files with 763 additions and 326 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Change Log
All notable changes to this project will be documented in this file.

## [1.1.0] - 2024-04-26

### Added
* required PrestaShop and PHP version downgrade to PrestaShop 1.6+ (from 1.7.1+) and PHP 5.6+ (from 7.1+)
* ad_user_data and ad_personalization consents

### Changed

### Fixed

## [1.0.3] - 2024-04-19

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"sort-packages": true
},
"require": {
"php": "^7.1",
"php": "^5.6 || ^7.1",
"ext-json": "*"
},
"require-dev": {
Expand Down
520 changes: 326 additions & 194 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dev/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

docker-compose run -T --rm php-cli <<INPUT
docker-compose run -T --rm php-cli56 <<INPUT
rm vendor -Rf
composer install --no-dev --optimize-autoloader
INPUT
Expand All @@ -20,7 +20,7 @@ cp logo.png $RELEASE_DIR/gtmconsentmodebannerfree/logo.png
cp gtmconsentmodebannerfree.php $RELEASE_DIR/gtmconsentmodebannerfree/gtmconsentmodebannerfree.php
cp LICENSE.md $RELEASE_DIR/gtmconsentmodebannerfree/LICENSE.md

docker-compose run -T --rm php-cli <<INPUT
docker-compose run -T --rm php-cli71 <<INPUT
find $RELEASE_DIR/gtmconsentmodebannerfree/src -type f -name '*.php' | xargs sed -i 's/^namespace \(.*\);/namespace \1;\n\nif (!defined('\''_PS_VERSION_'\'')) {\n exit;\n}/g'
touch $RELEASE_DIR/gtmconsentmodebannerfree/.htaccess
composer install
Expand Down
10 changes: 8 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.7'
services:
prestashop:
image: prestashop/prestashop:8.0.3
image: prestashop/prestashop:8.1.5
links:
- mariadb
ports:
Expand All @@ -28,9 +28,15 @@ services:
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: prestashop
php-cli:
php-cli71:
image: mfrankiewicz/php:7.1-cli
working_dir: /var/www
entrypoint: bash
volumes:
- ./:/var/www
php-cli56:
image: mfrankiewicz/php:5.6-cli
working_dir: /var/www
entrypoint: bash
volumes:
- ./:/var/www
34 changes: 14 additions & 20 deletions gtmconsentmodebannerfree.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
<?php

use Configuration as PrestaShopConfiguration;
use TagConcierge\GtmConsentModeBannerFree\Hook;
use TagConcierge\GtmConsentModeBannerFree\Install\ModuleTrait;
use TagConcierge\GtmConsentModeBannerFree\Install\TagConciergeModuleInterface;
use TagConcierge\GtmConsentModeBannerFree\ValueObject\ConfigurationVO;
use Tools as PrestaShopTools;

if (!defined('_PS_VERSION_')) {
exit;
}

require_once _PS_MODULE_DIR_ . 'gtmconsentmodebannerfree/vendor/autoload.php';

class GtmConsentModeBannerFree extends Module implements TagConciergeModuleInterface
class GtmConsentModeBannerFree extends Module implements TagConcierge\GtmConsentModeBannerFree\Install\TagConciergeModuleInterface
{
use ModuleTrait;
use TagConcierge\GtmConsentModeBannerFree\Install\ModuleTrait;
use TagConcierge\GtmConsentModeBannerFree\Install\CompatibilityTrait;

/** @var array */
const HOOKS = [
Hook\NotificationHook::class,
Hook\AssetsHook::class,
Hook\InitialScriptHook::class,
Hook\BannerScriptHook::class,
Hook\GtmHook::class,
Hook\CustomCssHook::class,
TagConcierge\GtmConsentModeBannerFree\Hook\NotificationHook::class,
TagConcierge\GtmConsentModeBannerFree\Hook\AssetsHook::class,
TagConcierge\GtmConsentModeBannerFree\Hook\InitialScriptHook::class,
TagConcierge\GtmConsentModeBannerFree\Hook\BannerScriptHook::class,
TagConcierge\GtmConsentModeBannerFree\Hook\GtmHook::class,
TagConcierge\GtmConsentModeBannerFree\Hook\CustomCssHook::class,
];

/** @var string */
Expand All @@ -37,8 +31,8 @@ public function __construct()
{
$this->name = 'gtmconsentmodebannerfree';
$this->author = 'Tag Concierge';
$this->version = '1.0.3';
$this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_];
$this->version = '1.1.0';
$this->ps_versions_compliancy = ['min' => '1.6.0.0', 'max' => _PS_VERSION_];
$this->bootstrap = true;
$this->tab = 'advertising_marketing';

Expand All @@ -50,17 +44,17 @@ public function __construct()
$this->init();
}

public function isPro(): bool
public function isPro()
{
return false;
}

public function getNotificationKey(): string
public function getNotificationKey()
{
return '3f06f392-93f8-4928-9135-3cfd571c8de6';
}

public function getName(): string
public function getName()
{
return $this->name;
}
Expand Down
12 changes: 9 additions & 3 deletions src/Hook/AbstractHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

abstract class AbstractHook
{
public const HOOKS = [];
const HOOKS = [];

/** @var TagConciergeModuleInterface */
protected $module;
Expand All @@ -17,12 +17,18 @@ public function __construct(TagConciergeModuleInterface $module)
$this->module = $module;
}

public function getHooks(): array
/**
* @return array
*/
public function getHooks()
{
return static::HOOKS;
}

protected function getContext(): PrestaShopContext
/**
* @return PrestaShopContext
*/
protected function getContext()
{
return PrestaShopContext::getContext();
}
Expand Down
48 changes: 35 additions & 13 deletions src/Hook/AssetsHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,50 @@ class AssetsHook extends AbstractHook
use HookTrait;

/** @var array */
public const HOOKS = [
const HOOKS = [
Hooks::ACTION_FRONT_CONTROLLER_SET_MEDIA => [
'loadAssets',
],
];

public function loadAssets(): void
/** @var string */
protected $scriptUrl = 'https://public-assets.tagconcierge.com/consent-banner/1.1.0/cb.min.js';

/** @var string */
protected $styleUrl = 'https://public-assets.tagconcierge.com/consent-banner/1.1.0/styles/light.css';

/** @var string */
protected $origin = 'remote';

/**
* @return void
*/
public function loadAssets()
{
if (false === $this->isEnabled()) {
return;
}

$this->getContext()->controller->registerJavascript(
'tag-concierge-consent-mode-banner',
'https://public-assets.tagconcierge.com/consent-banner/1.1.0/cb.min.js',
['server' => 'remote', 'position' => 'head', 'priority' => 20]
);

$this->getContext()->controller->registerStylesheet(
'tag-concierge-consent-mode-banner',
'https://public-assets.tagconcierge.com/consent-banner/1.1.0/styles/light.css',
['server' => 'remote', 'position' => 'head', 'priority' => 20]
);
$controller = $this->getContext()->controller;

if (method_exists($controller, 'registerJavascript')) {
$controller->registerJavascript(
'tag-concierge-consent-mode-banner',
$this->scriptUrl,
['server' => $this->origin, 'position' => 'head', 'priority' => 20]
);
} else {
$controller->addJS($this->scriptUrl);
}

if (method_exists($controller, 'registerJavascript')) {
$controller->registerStylesheet(
'tag-concierge-consent-mode-banner',
$this->styleUrl,
['server' => $this->origin, 'position' => 'head', 'priority' => 20]
);
} else {
$controller->addCSS($this->styleUrl);
}
}
}
41 changes: 38 additions & 3 deletions src/Hook/BannerScriptHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,43 @@ class BannerScriptHook extends AbstractHook
use HookTrait;

/** @var array */
public const HOOKS = [
const HOOKS = [
Hooks::DISPLAY_BEFORE_BODY_CLOSING_TAG => [
'loadBannerScript',
'beforeBodyClosingTag',
],
Hooks::DISPLAY_FOOTER => [
'displayFooter'
]
];

public function loadBannerScript(): string
/**
* @return string
*/
public function beforeBodyClosingTag()
{
if (1.7 > _PS_VERSION_) {
return '';
}

return $this->loadBannerScript();
}

/**
* @return string
*/
public function displayFooter()
{
if (1.7 <= _PS_VERSION_) {
return '';
}

return $this->loadBannerScript();
}

/**
* @return string
*/
public function loadBannerScript()
{
if (false === $this->isEnabled()) {
return '';
Expand All @@ -43,6 +73,10 @@ public function loadBannerScript(): string

$consentTypes = $this->module->getSettingsService()->getConsentTypes();

$consentTypes = array_filter($consentTypes, static function ($item) {
return false === empty($item['name']);
});

$config = [
'display' => [
'mode' => $settings[ConfigurationVO::DISPLAY_MODE],
Expand Down Expand Up @@ -71,6 +105,7 @@ public function loadBannerScript(): string
];

$this->getContext()->smarty->assign('tc_gtmcb_config', $config);
$this->getContext()->smarty->assign('tc_gtmcb_cookie_removal_on_denial', PrestaShopConfiguration::get(ConfigurationVO::COOKIE_REMOVAL_ON_DENIAL));

return $this->module->render('hooks/banner_script/banner_script.tpl');
}
Expand Down
7 changes: 5 additions & 2 deletions src/Hook/CustomCssHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ class CustomCssHook extends AbstractHook
use HookTrait;

/** @var array */
public const HOOKS = [
const HOOKS = [
Hooks::DISPLAY_HEADER => [
'loadCss',
],
];

public function loadCss(): string
/**
* @return string
*/
public function loadCss()
{
if (false === $this->isEnabled()) {
return '';
Expand Down
41 changes: 37 additions & 4 deletions src/Hook/GtmHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,46 @@ class GtmHook extends AbstractHook
use HookTrait;

/** @var array */
public const HOOKS = [
const HOOKS = [
Hooks::DISPLAY_HEADER => [
'loadGtmScript',
],
Hooks::DISPLAY_AFTER_BODY_OPENING_TAG => [
'loadGtmFrame',
'displayAfterBodyOpeningTag',
],
Hooks::DISPLAY_BANNER => [
'displayBanner',
],
];

public function loadGtmScript(): string
/**
* @return string
*/
public function displayAfterBodyOpeningTag()
{
if (1.7 > _PS_VERSION_) {
return '';
}

return $this->loadGtmFrame();
}

/**
* @return string
*/
public function displayBanner()
{
if (1.7 <= _PS_VERSION_) {
return '';
}

return $this->loadGtmFrame();
}

/**
* @return string
*/
public function loadGtmScript()
{
if (false === $this->isEnabled()) {
return '';
Expand All @@ -28,7 +58,10 @@ public function loadGtmScript(): string
return PrestaShopConfiguration::get(ConfigurationVO::GTM_CONTAINER_SNIPPET_HEAD);
}

public function loadGtmFrame(): string
/**
* @return string
*/
public function loadGtmFrame()
{
if (false === $this->isEnabled()) {
return '';
Expand Down
6 changes: 5 additions & 1 deletion src/Hook/HookProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public function __construct(TagConciergeModuleInterface $module)
$this->module = $module;
}

public function provide(string $hookClass): AbstractHook
/**
* @param string $hookClass
* @return AbstractHook
*/
public function provide($hookClass)
{
if (false === isset($this->hooks[$hookClass])) {
$this->hooks[$hookClass] = new $hookClass($this->module);
Expand Down
Loading

0 comments on commit d17765c

Please sign in to comment.