Completed
Push — master ( 5ae7ff...b2cb25 )
by Harald
06:13 queued 03:00
created

ht_cookie::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
  * osCommerce Online Merchant
4
  *
5
  * @copyright (c) 2016 osCommerce; https://www.oscommerce.com
6
  * @license MIT; https://www.oscommerce.com/license/mit.txt
7
  */
8
9
  use OSC\OM\OSCOM;
10
  use OSC\OM\Registry;
11
12
  class ht_cookie {
13
    var $code = 'ht_cookie';
14
    var $group = 'header_tags';
15
    var $title;
16
    var $description;
17
    var $sort_order;
18
    var $enabled = false;
19
20
    function __construct() {
21
      $this->title = OSCOM::getDef('module_header_tags_cookie_title');
22
      $this->description = OSCOM::getDef('module_header_tags_cookie_description');
23
24
      if ( defined('MODULE_HEADER_TAGS_COOKIE_STATUS') ) {
25
        $this->sort_order = MODULE_HEADER_TAGS_COOKIE_SORT_ORDER;
26
        $this->enabled = (MODULE_HEADER_TAGS_COOKIE_STATUS == 'True');
27
      }
28
    }
29
30
    function execute() {
31
      global $oscTemplate;
32
33
      $message = OSCOM::getDef('module_header_tags_cookie_message_text');
34
      $dismiss = OSCOM::getDef('module_header_tags_cookie_dismiss_text');
35
      $more    = OSCOM::getDef('module_header_tags_cookie_more_text');
36
      $link    = OSCOM::link(MODULE_HEADER_TAGS_COOKIE_PAGE);
37
      $theme   = OSCOM::link('ext/cookieconsent2/' . MODULE_HEADER_TAGS_COOKIE_THEME . '.css', null, false);
38
39
      $script_src = OSCOM::link('ext/cookieconsent2/cookieconsent.min.js', null, false);
40
41
      $output  = <<<EOD
42
<script>window.cookieconsent_options = {"message":"{$message}", "dismiss":"{$dismiss}", "learnMore":"{$more}", "link":"{$link}", "theme":"{$theme}"};</script>
43
<script src="{$script_src}"></script>
44
EOD;
45
46
      $oscTemplate->addBlock($output . "\n", $this->group);
47
    }
48
49
    function isEnabled() {
50
      return $this->enabled;
51
    }
52
53
    function check() {
54
      return defined('MODULE_HEADER_TAGS_COOKIE_STATUS');
55
    }
56
57
    function install() {
58
      $OSCOM_Db = Registry::get('Db');
59
60
      $OSCOM_Db->save('configuration', [
61
        'configuration_title' => 'Enable Cookie Compliance Module',
62
        'configuration_key' => 'MODULE_HEADER_TAGS_COOKIE_STATUS',
63
        'configuration_value' => 'True',
64
        'configuration_description' => 'Do you want to enable this module?',
65
        'configuration_group_id' => '6',
66
        'sort_order' => '1',
67
        'set_function' => 'tep_cfg_select_option(array(\'True\', \'False\'), ',
68
        'date_added' => 'now()'
69
      ]);
70
71
      $OSCOM_Db->save('configuration', [
72
        'configuration_title' => 'Theme',
73
        'configuration_key' => 'MODULE_HEADER_TAGS_COOKIE_THEME',
74
        'configuration_value' => 'dark-top',
75
        'configuration_description' => 'Select Theme.',
76
        'configuration_group_id' => '6',
77
        'sort_order' => '1',
78
        'set_function' => 'tep_cfg_select_option(array(\'dark-top\', \'dark-floating\', \'dark-bottom\', \'light-floating\', \'light-top\', \'light-bottom\'), ',
79
        'date_added' => 'now()'
80
      ]);
81
82
      $OSCOM_Db->save('configuration', [
83
        'configuration_title' => 'Cookie Policy Page',
84
        'configuration_key' => 'MODULE_HEADER_TAGS_COOKIE_PAGE',
85
        'configuration_value' => 'privacy.php',
86
        'configuration_description' => 'The Page on your site that has details of your Cookie Policy.',
87
        'configuration_group_id' => '6',
88
        'sort_order' => '0',
89
        'date_added' => 'now()'
90
      ]);
91
92
      $OSCOM_Db->save('configuration', [
93
        'configuration_title' => 'Sort Order',
94
        'configuration_key' => 'MODULE_HEADER_TAGS_COOKIE_SORT_ORDER',
95
        'configuration_value' => '900',
96
        'configuration_description' => 'Sort order of display. Lowest is displayed first.',
97
        'configuration_group_id' => '6',
98
        'sort_order' => '0',
99
        'date_added' => 'now()'
100
      ]);
101
    }
102
103
    function remove() {
104
      return Registry::get('Db')->exec('delete from :table_configuration where configuration_key in ("' . implode('", "', $this->keys()) . '")');
105
    }
106
107
    function keys() {
108
      return array('MODULE_HEADER_TAGS_COOKIE_STATUS', 'MODULE_HEADER_TAGS_COOKIE_THEME', 'MODULE_HEADER_TAGS_COOKIE_PAGE', 'MODULE_HEADER_TAGS_COOKIE_SORT_ORDER');
109
    }
110
  }
111