Passed
Pull Request — master (#4)
by
unknown
09:15 queued 24s
created

ht_pagantis::keys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
/*
3
  $Id$
4
5
  osCommerce, Open Source E-Commerce Solutions
6
  http://www.oscommerce.com
7
8
  Copyright (c) 2010 osCommerce
9
10
  Released under the GNU General Public License
11
*/
12
13
define('TABLE_PAGANTIS_CONFIG', 'pagantis_config');
14
define('MODULE_HEADER_TAGS_PAGANTIS_SDK', 'https://cdn.pagantis.com/js/pg-v2/sdk.js');
15
16
class ht_pagantis {
17
    var $code = 'ht_pagantis';
18
    var $group = 'header_tags';
19
    var $title;
20
    var $description;
21
    var $enabled = false;
22
23
    /**
24
     * ht_pagantis constructor.
25
     */
26
    function ht_pagantis() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
27
        $this->title = MODULE_HEADER_TAGS_PAGANTIS_TITLE;
28
        $this->description = MODULE_HEADER_TAGS_PAGANTIS_DESCRIPTION;
29
        $this->sort_order = 0;
0 ignored issues
show
Bug Best Practice introduced by
The property sort_order does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30
31
        if ( defined('MODULE_HEADER_TAGS_PAGANTIS_STATUS') ) {
32
            $this->enabled = (MODULE_HEADER_TAGS_PAGANTIS_STATUS == 'True');
33
        }
34
        $this->extraConfig = $this->getExtraConfig();
0 ignored issues
show
Bug Best Practice introduced by
The property extraConfig does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
35
        $this->pk = $this->getConfig('MODULE_PAYMENT_PAGANTIS_PK');
0 ignored issues
show
Bug Best Practice introduced by
The property pk does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
36
        $this->sdkFile = MODULE_HEADER_TAGS_PAGANTIS_SDK;
0 ignored issues
show
Bug Best Practice introduced by
The property sdkFile does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    private function getExtraConfig()
43
    {
44
        $checkTable = tep_db_query("SHOW TABLES LIKE '".TABLE_PAGANTIS_CONFIG."'");
0 ignored issues
show
Bug introduced by
The function tep_db_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
        $checkTable = /** @scrutinizer ignore-call */ tep_db_query("SHOW TABLES LIKE '".TABLE_PAGANTIS_CONFIG."'");
Loading history...
45
        $response = array();
46
        if (tep_db_num_rows($checkTable) > 0) {
0 ignored issues
show
Bug introduced by
The function tep_db_num_rows was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        if (/** @scrutinizer ignore-call */ tep_db_num_rows($checkTable) > 0) {
Loading history...
47
            $query       = "select * from ".TABLE_PAGANTIS_CONFIG;
48
            $result      = tep_db_query($query);
49
            $response    = array();
50
            while ($resultArray = tep_db_fetch_array($result)) {
0 ignored issues
show
Bug introduced by
The function tep_db_fetch_array was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
            while ($resultArray = /** @scrutinizer ignore-call */ tep_db_fetch_array($result)) {
Loading history...
51
                $response[$resultArray['config']] = $resultArray['value'];
52
            }
53
        }
54
        return $response;
55
    }
56
57
    /**
58
     * @param string $config
59
     * @return array
60
     */
61
    private function getConfig($config = '')
62
    {
63
            $query       = "select configuration_value from ".TABLE_CONFIGURATION . " where configuration_key = '" . $config . "'";
0 ignored issues
show
Bug introduced by
The constant TABLE_CONFIGURATION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
64
            $result      = tep_db_query($query);
0 ignored issues
show
Bug introduced by
The function tep_db_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
            $result      = /** @scrutinizer ignore-call */ tep_db_query($query);
Loading history...
65
            $resultArray = tep_db_fetch_array($result);
0 ignored issues
show
Bug introduced by
The function tep_db_fetch_array was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
            $resultArray = /** @scrutinizer ignore-call */ tep_db_fetch_array($result);
Loading history...
66
            return $resultArray['configuration_value'];
67
    }
68
69
    /**
70
     * Execute function
71
     */
72
    function execute() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
73
        global $languages_id;
74
        if (isset($GLOBALS["HTTP_GET_VARS"]["products_id"])) {
75
            $simulatorCode = 'pgSDK';
76
            if ($languages_id == '2' || $languages_id == null) {
77
                $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'] = 'pmtSDK.simulator.positions.INNER';
0 ignored issues
show
Bug Best Practice introduced by
The property extraConfig does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
78
                $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'] = 'pmtSDK.simulator.types.SIMPLE';
79
                $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_SKIN'] = 'pmtSDK.simulator.skins.BLUE';
80
                $simulatorCode = 'pmtSDK';
81
            }
82
            echo "<script src='".$this->sdkFile."'></script>". PHP_EOL;
83
            echo '<script>'. PHP_EOL;
84
            echo '        function loadSimulator()'. PHP_EOL;
85
            echo '        {'. PHP_EOL;
86
            echo '           if (typeof '.$simulatorCode.' != \'undefined\') {'. PHP_EOL;
87
            echo '               var positionSelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR']. '\';'. PHP_EOL;
88
            echo '               var priceSelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR']. '\';'. PHP_EOL;
89
            echo '               var quantitySelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR']. '\';'. PHP_EOL;
90
91
            echo '               if (positionSelector === \'default\') {'. PHP_EOL;
92
            echo '                   positionSelector = \'.buttonSet\''. PHP_EOL;
93
            echo '               }'. PHP_EOL;
94
95
            echo '               if (priceSelector === \'default\') {'. PHP_EOL;
96
            echo '                   priceSelector = \'#bodyContent>form>div>h1\''. PHP_EOL;
97
            echo '               }'. PHP_EOL;
98
99
            echo '               '.$simulatorCode.'.product_simulator = {};'. PHP_EOL;
100
            echo '               '.$simulatorCode.'.product_simulator.id = \'product-simulator\';'. PHP_EOL;
101
            echo '               '.$simulatorCode.'.product_simulator.publicKey = \'' . $this->pk . '\';'. PHP_EOL;
0 ignored issues
show
Bug introduced by
Are you sure $this->pk of type array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

101
            echo '               '.$simulatorCode.'.product_simulator.publicKey = \'' . /** @scrutinizer ignore-type */ $this->pk . '\';'. PHP_EOL;
Loading history...
102
            echo '               '.$simulatorCode.'.product_simulator.selector = positionSelector;'. PHP_EOL;
103
            echo '               '.$simulatorCode.'.product_simulator.numInstalments = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'] . '\';'. PHP_EOL;
104
            echo '               '.$simulatorCode.'.product_simulator.type = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'] . ';'. PHP_EOL;
105
            echo '               '.$simulatorCode.'.product_simulator.skin = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_SKIN'] . ';'. PHP_EOL;
106
            echo '               '.$simulatorCode.'.product_simulator.position = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'] . ';'. PHP_EOL;
107
            echo '               '.$simulatorCode.'.product_simulator.itemAmountSelector = priceSelector;'. PHP_EOL;
108
109
            echo '               '.$simulatorCode.'.simulator.init('.$simulatorCode.'.product_simulator);'. PHP_EOL;
110
            echo '               clearInterval(window.PSSimulatorId);'. PHP_EOL;
111
            echo '               return true;'. PHP_EOL;
112
            echo '           }'. PHP_EOL;
113
            echo '           return false;'. PHP_EOL;
114
            echo '       }'. PHP_EOL;
115
            echo '       window.PSSimulatorId = setInterval(function () {'. PHP_EOL;
116
            echo '          loadSimulator();'. PHP_EOL;
117
            echo '       }, 2000);'. PHP_EOL;
118
            echo '</script>'. PHP_EOL;
119
120
            if ($this->isPromoted($GLOBALS["HTTP_GET_VARS"]["products_id"])) {
121
                echo "<div id='promotedText' style='display:none'><br/>".$this->extraConfig['PAGANTIS_PROMOTED_PRODUCT_CODE']."</div>";
122
                echo '<script>'. PHP_EOL;
123
                echo '        function loadPromoted()'. PHP_EOL;
124
                echo '        {'. PHP_EOL;
125
                echo 'var positionSelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR']. '\';'. PHP_EOL;
126
                echo 'if (positionSelector === \'default\') {'. PHP_EOL;
127
                echo 'positionSelector = \'.buttonSet\''. PHP_EOL;
128
                echo '}'. PHP_EOL;
129
                echo 'var docFather = document.querySelector(positionSelector);'.PHP_EOL;
130
                echo 'if (typeof docFather != \'undefined\') {'. PHP_EOL;
131
                echo 'var promotedNode = document.getElementById("promotedText");'.PHP_EOL;
132
                echo 'docFather.appendChild(promotedNode);'.PHP_EOL;
133
                echo 'promotedNode.style.display=""' . PHP_EOL;
134
                echo '               return true;'. PHP_EOL;
135
                echo '       }'. PHP_EOL;
136
                echo '               return false;'. PHP_EOL;
137
                echo '       }'. PHP_EOL;
138
                echo '       window.PSPromotedId = setInterval(function () {'. PHP_EOL;
139
                echo '          loadPromoted();'. PHP_EOL;
140
                echo '       }, 2000);'. PHP_EOL;
141
                echo '</script>'. PHP_EOL;
142
            }
143
        }
144
    }
145
146
    /**
147
     * @return bool
148
     */
149
    function isEnabled() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
150
        return $this->enabled;
151
    }
152
153
    /**
154
     * @return bool
155
     */
156
    function check() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
157
        return defined('MODULE_HEADER_TAGS_PAGANTIS_STATUS');
158
    }
159
160
    /**
161
     * install
162
     */
163
    function install() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
164
        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Pagantis Module', 'MODULE_HEADER_TAGS_PAGANTIS_STATUS', 'True', '', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
0 ignored issues
show
Bug introduced by
The constant TABLE_CONFIGURATION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function tep_db_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

164
        /** @scrutinizer ignore-call */ 
165
        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Pagantis Module', 'MODULE_HEADER_TAGS_PAGANTIS_STATUS', 'True', '', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
Loading history...
165
166
    }
167
168
    /**
169
     * remove
170
     */
171
    function remove() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
172
        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
0 ignored issues
show
Bug introduced by
The function tep_db_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

172
        /** @scrutinizer ignore-call */ 
173
        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
Loading history...
Bug introduced by
The constant TABLE_CONFIGURATION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
173
    }
174
175
    /**
176
     * @return array
177
     */
178
    function keys() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
179
        return array('MODULE_HEADER_TAGS_PAGANTIS_STATUS');
180
    }
181
182
    /**
183
     * @param $productId
184
     *
185
     * @return bool
186
     */
187
    private function isPromoted($productId)
0 ignored issues
show
Unused Code introduced by
The parameter $productId is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

187
    private function isPromoted(/** @scrutinizer ignore-unused */ $productId)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
188
    {
189
        //HOOK WHILE PROMOTED AMOUNT IS NOT WORKING
190
        return false;
191
192
        if ($this->extraConfig['PAGANTIS_PROMOTION'] == '') {
0 ignored issues
show
Unused Code introduced by
IfNode is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
193
            $promotedProducts = array();
194
        } else {
195
            $promotedProducts = array_values((array)unserialize($this->extraConfig['PAGANTIS_PROMOTION']));
196
        }
197
198
        return (in_array($productId, $promotedProducts));
199
    }
200
}
201
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
202