forked from mdurys/piwikanalyticsjs-prestashop
/
piwikanalyticsjs.php
2018 lines (1892 loc) · 105 KB
/
piwikanalyticsjs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
if (!defined('_PS_VERSION_'))
exit;
/**
* Copyright (C) 2015 Christian Jensen
*
* This file is part of PiwikAnalyticsJS for prestashop.
*
* PiwikAnalyticsJS for prestashop is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PiwikAnalyticsJS for prestashop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PiwikAnalyticsJS for prestashop. If not, see <http://www.gnu.org/licenses/>.
*
*
* @author Christian M. Jensen
* @link http://cmjnisse.github.io/piwikanalyticsjs-prestashop
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @todo config wiz, set currency to use.
*/
class piwikanalyticsjs extends Module {
private static $_isOrder = FALSE;
protected $_errors = "";
protected $piwikSite = FALSE;
protected $default_currency = array();
protected $currencies = array();
/**
* setReferralCookieTimeout
*/
const PK_RC_TIMEOUT = 262974;
/**
* setVisitorCookieTimeout
*/
const PK_VC_TIMEOUT = 569777;
/**
* setSessionCookieTimeout
*/
const PK_SC_TIMEOUT = 30;
public function __construct($name = null, $context = null) {
$this->name = 'piwikanalyticsjs';
$this->tab = 'analytics_stats';
$this->version = '0.8.3';
$this->author = 'Christian M. Jensen';
$this->displayName = 'Piwik Analytics';
$this->author_uri = 'https://cmjscripter.net';
$this->url = 'http://cmjnisse.github.io/piwikanalyticsjs-prestashop/';
$this->need_instance = 1;
/* version 1.5 uses invalid compatibility check */
if (version_compare(_PS_VERSION_, '1.6.0.0', '>='))
$this->ps_versions_compliancy = array('min' => '1.5', 'max' => _PS_VERSION_);
$this->bootstrap = true;
parent::__construct($name, ($context instanceof Context ? $context : NULL));
require_once dirname(__FILE__) . '/PKHelper.php';
//* warnings on module list page
if ($this->id && !Configuration::get(PKHelper::CPREFIX . 'TOKEN_AUTH'))
$this->warning = (isset($this->warning) && !empty($this->warning) ? $this->warning . ',<br/> ' : '') . $this->l('You need to configure the auth token');
if ($this->id && ((int) Configuration::get(PKHelper::CPREFIX . 'SITEID') <= 0))
$this->warning = (isset($this->warning) && !empty($this->warning) ? $this->warning . ',<br/> ' : '') . $this->l('You have not yet set Piwik Site ID');
if ($this->id && !Configuration::get(PKHelper::CPREFIX . 'HOST'))
$this->warning = (isset($this->warning) && !empty($this->warning) ? $this->warning . ',<br/> ' : '') . $this->l('You need to configure the Piwik server url');
$this->description = $this->l('Piwik Analytics');
$this->confirmUninstall = $this->l('Are you sure you want to delete this plugin ?');
self::$_isOrder = FALSE;
PKHelper::$error = "";
$this->_errors = PKHelper::$errors = array();
if ($this->id) {
if (version_compare(_PS_VERSION_, '1.5.0.13', "<="))
PKHelper::$_module = & $this;
}
}
public function generateWizardForm($step = 1, & $fields_form, & $helperform) {
$username = $password = $piwikhost = $usernamehttp = $passwordhttp = false;
if (Tools::getIsset('usePiwikSite') && ((int) Tools::getValue('usePiwikSite') != 0)) {
$pksiteid = (int) Tools::getValue('usePiwikSite');
if ($pksite = PKHelper::getPiwikSite2($pksiteid)) {
if (isset($pksite[0]) && is_object($pksite[0])) {
PKHelper::updatePiwikSite($pksiteid /* $idSite */, $pksite[0]->name /* $siteName */, $pksite[0]->main_url /* $urls */, 1 /* $ecommerce */, 1 /* $siteSearch */, $pksite[0]->sitesearch_keyword_parameters /* $searchKeywordParameters */, $pksite[0]->sitesearch_category_parameters /* $searchCategoryParameters */, $pksite[0]->excluded_ips /* $excludedIps */, $pksite[0]->excluded_parameters /* $excludedQueryParameters */, $pksite[0]->timezone /* $timezone */, $pksite[0]->currency /* $currency */, $pksite[0]->group /* $group */, $pksite[0]->ts_created /* $startDate */, $pksite[0]->excluded_user_agents /* $excludedUserAgents */, $pksite[0]->keep_url_fragment /* $keepURLFragments */, $pksite[0]->type /* $type */);
PKHelper::$error = PKHelper::$errors = null; // don't need them, we redirect
// save site id
Configuration::updateValue(PKHelper::CPREFIX . 'SITEID', $pksiteid);
Tools::redirectAdmin(str_replace('&pkwizard', '', $helperform->currentIndex) . "&token=" . Tools::getAdminTokenLite('AdminModules'));
} else {
$this->_errors[] = $this->displayError(sprintf($this->l("I encountered an unknown error while trying to get the selected site, id#%s"), $pksiteid));
$password = Configuration::get(PKHelper::CPREFIX . "USRPASSWD");
$username = Configuration::get(PKHelper::CPREFIX . "USRNAME");
$usernamehttp = Configuration::get(PKHelper::CPREFIX . 'PAUTHUSR');
$passwordhttp = Configuration::get(PKHelper::CPREFIX . 'PAUTHPWD');
$piwikhost = Configuration::get(PKHelper::CPREFIX . 'HOST');
}
} else {
$this->_errors[] = $this->displayError(sprintf($this->l("I'm unable, to get admin access to the selected site id #%s"), $pksiteid));
$password = Configuration::get(PKHelper::CPREFIX . "USRPASSWD");
$username = Configuration::get(PKHelper::CPREFIX . "USRNAME");
$usernamehttp = Configuration::get(PKHelper::CPREFIX . 'PAUTHUSR');
$passwordhttp = Configuration::get(PKHelper::CPREFIX . 'PAUTHPWD');
$piwikhost = Configuration::get(PKHelper::CPREFIX . 'HOST');
}
}
if (Tools::getIsset(PKHelper::CPREFIX . 'USRNAME_WIZARD'))
$username = Tools::getValue(PKHelper::CPREFIX . 'USRNAME_WIZARD');
if (Tools::getIsset(PKHelper::CPREFIX . 'USRPASSWD_WIZARD'))
$password = Tools::getValue(PKHelper::CPREFIX . 'USRPASSWD_WIZARD');
if (Tools::getIsset(PKHelper::CPREFIX . 'HOST_WIZARD'))
$piwikhost = Tools::getValue(PKHelper::CPREFIX . 'HOST_WIZARD');
if (Tools::getIsset(PKHelper::CPREFIX . 'PAUTHUSR_WIZARD'))
$usernamehttp = Tools::getValue(PKHelper::CPREFIX . 'PAUTHUSR_WIZARD', 0);
if (Tools::getIsset(PKHelper::CPREFIX . 'PAUTHPWD_WIZARD'))
$passwordhttp = Tools::getValue(PKHelper::CPREFIX . 'PAUTHPWD_WIZARD', 0);
$pkToken = false;
$pkSites = array();
if ($step == 2) {
PKHelper::$httpAuthUsername = ($usernamehttp !== false ? $usernamehttp : '');
PKHelper::$httpAuthPassword = ($passwordhttp !== false ? $passwordhttp : '');
PKHelper::$piwikHost = str_replace(array('http://', 'https://'), '', $piwikhost);
$pkToken = PKHelper::getTokenAuth($username, $password);
if (!empty(PKHelper::$error)) {
foreach (PKHelper::$errors as $key => $value) {
$this->_errors[] = $this->displayError($value);
}
$step = 1;
} else {
if ($pkToken !== false) {
// wee need to saved the token to avoid errore from PKHelper class
// @todo allow token overide 'PKHelper::getSitesWithAdminAccess' (skip missing error)
Configuration::updateValue(PKHelper::CPREFIX . 'TOKEN_AUTH', $pkToken);
if ($_pkSites = PKHelper::getSitesWithAdminAccess(false, array(
'idSite' => 0, 'pkHost' => PKHelper::$piwikHost,
'https' => (strpos($piwikhost, 'https://') !== false),
'pkModule' => 'API', 'isoCode' => NULL, 'tokenAuth' => $pkToken))) {
if (!empty($_pkSites)) {
foreach ($_pkSites as $value) {
$pkSites[] = array(
'idsite' => $value->idsite,
'name' => $value->name,
'main_url' => $value->main_url,
);
}
}
}
if (!empty(PKHelper::$error)) {
foreach (PKHelper::$errors as $key => $value) {
$this->_errors[] = $this->displayError($value);
}
$step = 1;
}
}
}
}
if ($step == 2 && is_array($pkSites) && !empty($pkSites)) {
$fields_form[0]['form']['input'][] = array(
'type' => 'html',
'name' => "<strong>{$this->l("Select a site.")}</strong>"
);
foreach ($pkSites as $key => $value) {
$fields_form[0]['form']['input'][] = array(
'name' => '', /* avoid not isset error */
'type' => 'myBtn',
'href' => $helperform->currentIndex . '&usePiwikSite=' . $value['idsite'] . "&token=" . Tools::getAdminTokenLite('AdminModules'),
/* 'class'=>'', */
'id' => 'slectedpksid_' . $value['idsite'],
/* 'extraattr' => ' onclick="return false;"', */
'icon' => 'icon-chevron-right',
'title' => '#' . $value['idsite'] . ' - ' . $value['name'] . ' [<strong>' . $value['main_url'] . '</strong>]',
);
}
$fields_form[0]['form']['buttons'][] = array(
'title' => $this->l('Cancel'),
'icon' => 'process-icon-cancel',
'class' => ' donotdisable',
'ps15style' => 'font-size: 14px; padding: 5px 10px;',
'type' => 'button',
'href' => str_replace('&pkwizard', '', $helperform->currentIndex) . "&token=" . Tools::getAdminTokenLite('AdminModules'),
'id' => 'btnCreateNewSite',
'name' => 'btnCreateNewSite',
);
$fields_form[0]['form']['buttons'][] = array(
'title' => $this->l('Create new Site'),
'icon' => 'process-icon-new',
'class' => ' pull-right donotdisable',
'type' => 'button',
'id' => 'btnCreateNewSite',
'name' => 'btnCreateNewSite',
'js' => "alert('this functionality is not implemented yet, i apologise for the inconvenience')",
);
} else if ($step == 2) {
$step = 1;
$this->_errors[] = $this->displayError($this->l("Unable to get a list websites from piwik, if you dont have any sites in piwik yet click 'Create new Site' button."));
}
$fields_form[0]['form']['input'][] = array(
'type' => 'html',
'name' => "<input type=\"hidden\" name=\"" . PKHelper::CPREFIX . 'STEP_WIZARD' . "\" id=\"" . PKHelper::CPREFIX . 'STEP_WIZARD' . "\" value=\"{$step}\" />"
);
$fields_form[0]['form']['legend']['title'] = $helperform->title . " [Step " . $step . "/2]";
if ($step != 1) {
$fields_form[0]['form']['input'][] = array(
'type' => 'html',
'name' => "<input type=\"hidden\" name=\"" . PKHelper::CPREFIX . 'HOST_WIZARD' . "\" id=\"" . PKHelper::CPREFIX . 'HOST_WIZARD' . "\" value=\"{$piwikhost}\" />"
. "<input type=\"hidden\" name=\"" . PKHelper::CPREFIX . 'USRNAME_WIZARD' . "\" id=\"" . PKHelper::CPREFIX . 'USRNAME_WIZARD' . "\" value=\"{$username}\" />"
. "<input type=\"hidden\" name=\"" . PKHelper::CPREFIX . 'USRPASSWD_WIZARD' . "\" id=\"" . PKHelper::CPREFIX . 'USRPASSWD_WIZARD' . "\" value=\"{$password}\" />"
. "<input type=\"hidden\" name=\"" . PKHelper::CPREFIX . 'PAUTHUSR_WIZARD' . "\" id=\"" . PKHelper::CPREFIX . 'PAUTHUSR_WIZARD' . "\" value=\"{$usernamehttp}\" />"
. "<input type=\"hidden\" name=\"" . PKHelper::CPREFIX . 'PAUTHPWD_WIZARD' . "\" id=\"" . PKHelper::CPREFIX . 'PAUTHPWD_WIZARD' . "\" value=\"{$passwordhttp}\" />"
);
}
if ($step == 1) {
$fields_form[0]['form']['input'][] = array(
'type' => 'text',
'label' => $this->l('Piwik Host'),
'name' => PKHelper::CPREFIX . 'HOST_WIZARD',
'desc' => $this->l('Example: http://www.example.com/piwik/'),
'hint' => $this->l('The full url to your piwik installation.!'),
'required' => true,
);
$fields_form[0]['form']['input'][] = array(
'type' => 'text',
'label' => $this->l('Piwik User name'),
'name' => PKHelper::CPREFIX . 'USRNAME_WIZARD',
'desc' => $this->l('Enter your username for Piwik, we need this in order to fetch your api authentication token'),
'required' => true,
'autocomplete' => false,
);
$fields_form[0]['form']['input'][] = array(
'type' => 'password',
'label' => $this->l('Piwik User password'),
'name' => PKHelper::CPREFIX . 'USRPASSWD_WIZARD',
'desc' => $this->l('Enter your password for Piwik, we need this in order to fetch your api authentication token'),
'required' => true,
'autocomplete' => false,
);
$fields_form[0]['form']['input'][] = array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Save username and password'),
'name' => PKHelper::CPREFIX . 'SAVE_USRPWD_WIZARD',
'desc' => $this->l('Whether or not to save the username and password, saving the username and password will enable quick(automatic) login to piwik from the integrated stats page'),
'required' => false,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
);
$fields_form[0]['form']['input'][] = array(
'type' => 'html',
'name' => "<strong>{$this->l("HTTP Basic Authorization")}</strong>"
);
$fields_form[0]['form']['input'][] = array(
'type' => 'text',
'label' => $this->l('HTTP Auth Username'),
'name' => PKHelper::CPREFIX . 'PAUTHUSR_WIZARD',
'required' => false,
'autocomplete' => false,
'desc' => $this->l('this field along with password can be used if piwik installation is protected by HTTP Basic Authorization'),
);
$fields_form[0]['form']['input'][] = array(
'type' => 'password',
'label' => $this->l('HTTP Auth Password'),
'name' => PKHelper::CPREFIX . 'PAUTHPWD_WIZARD',
'required' => false,
'autocomplete' => false,
'desc' => $this->l('this field along with username can be used if piwik installation is protected by HTTP Basic Authorization'),
);
$fields_form[0]['form']['submit'] = array(
'title' => $this->l('Next'),
'icon' => 'process-icon-next',
'class' => (version_compare(_PS_VERSION_, '1.6', '>=') ? 'btn btn-default' : 'button'),
);
$fields_form[0]['form']['buttons'][] = array(
'title' => $this->l('Cancel'),
'icon' => 'process-icon-cancel',
'class' => ' donotdisable',
'ps15style' => 'font-size: 14px; padding: 5px 10px;',
'type' => 'button',
'href' => str_replace('&pkwizard', '', $helperform->currentIndex) . "&token=" . Tools::getAdminTokenLite('AdminModules'),
'id' => 'btnCreateNewSite',
'name' => 'btnCreateNewSite',
);
$fields_form[0]['form']['buttons'][] = array(
'title' => $this->l('Create new Site'),
'icon' => 'process-icon-new',
'class' => ' pull-right donotdisable',
'type' => 'button',
'id' => 'btnCreateNewSite',
'name' => 'btnCreateNewSite',
'js' => "alert('this functionality is not implemented yet, i apologise for the inconvenience')",
);
}
$helperform->show_cancel_button = false; // link is wrong and can end up in and annoying loop
$helperform->fields_value = array(
PKHelper::CPREFIX . 'USRNAME_WIZARD' => ($username !== false ? $username : ''),
PKHelper::CPREFIX . 'USRPASSWD_WIZARD' => ($password !== false ? $password : ''),
PKHelper::CPREFIX . 'HOST_WIZARD' => ($piwikhost !== false ? $piwikhost : ''),
PKHelper::CPREFIX . 'SAVE_USRPWD_WIZARD' => 0,
PKHelper::CPREFIX . 'PAUTHUSR_WIZARD' => ($usernamehttp !== false ? $usernamehttp : ''),
PKHelper::CPREFIX . 'PAUTHPWD_WIZARD' => ($passwordhttp !== false ? $passwordhttp : ''),
);
}
/**
* get content to display in the admin area
* @return string
*/
public function getContent() {
if (Tools::getIsset('pkapicall')) {
$this->__pkapicall();
die();
}
if (version_compare(_PS_VERSION_, '1.5.0.4', "<=")) {
$this->context->controller->addJquery(_PS_JQUERY_VERSION_);
$this->context->controller->addJs($this->_path . 'js/jquery.alerts.js');
$this->context->controller->addCss($this->_path . 'js/jquery.alerts.css');
}
if (version_compare(_PS_VERSION_, '1.5.2.999', "<="))
$this->context->controller->addJqueryPlugin('fancybox', _PS_JS_DIR_ . 'jquery/plugins/');
if (version_compare(_PS_VERSION_, '1.6', "<")) {
$this->context->controller->addJqueryUI(array(
'ui.core',
'ui.widget',
));
}
if (version_compare(_PS_VERSION_, '1.5', ">="))
$this->context->controller->addJqueryPlugin('tagify', _PS_JS_DIR_ . 'jquery/plugins/');
// @todo process only returns a value on error so move them from $_html to $this->_errors
$_html = "";
$_html .= $this->processFormsUpdate();
if (Tools::isSubmit('submitUpdateWizardForm' . $this->name)) {
$_html .= $this->processWizardFormUpdate();
}
$this->piwikSite = false;
if (!Tools::getIsset('pkwizard')) { /* do not try to connect when using wizard */
if (Configuration::get(PKHelper::CPREFIX . 'TOKEN_AUTH') !== false)
$this->piwikSite = PKHelper::getPiwikSite();
}
$this->displayErrors(PKHelper::$errors);
PKHelper::$errors = PKHelper::$error = "";
$this->__setCurrencies();
//* warnings on module configure page
if (!Tools::getIsset('pkwizard')) { /* do not show them if we are using the wizard */
if ($this->id && !Configuration::get(PKHelper::CPREFIX . 'TOKEN_AUTH') && !Tools::getIsset(PKHelper::CPREFIX . 'TOKEN_AUTH')) /* avoid the same error message twice */
$this->_errors[] = $this->displayError($this->l('Piwik auth token is empty'));
if ($this->id && ((int) Configuration::get(PKHelper::CPREFIX . 'SITEID') <= 0) && !Tools::getIsset(PKHelper::CPREFIX . 'SITEID')) /* avoid the same error message twice */
$this->_errors[] = $this->displayError($this->l('Piwik site id is lower or equal to "0"'));
if ($this->id && !Configuration::get(PKHelper::CPREFIX . 'HOST'))
$this->_errors[] = $this->displayError($this->l('Piwik host cannot be empty'));
}
$fields_form = array();
$languages = Language::getLanguages(FALSE);
foreach ($languages as $languages_key => $languages_value) {
// is_default
$languages[$languages_key]['is_default'] = ($languages_value['id_lang'] == (int) Configuration::get('PS_LANG_DEFAULT') ? true : false);
}
$helper = new HelperForm();
if (version_compare(_PS_VERSION_, '1.5.0.13', "<"))
$helper->base_folder = _PS_MODULE_DIR_ . 'piwikanalyticsjs/views/templates/helpers/form/';
$helper->languages = $languages;
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->identifier = $this->identifier;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->default_form_language = (int) Configuration::get('PS_LANG_DEFAULT');
$helper->allow_employee_form_lang = (int) Configuration::get('PS_LANG_DEFAULT');
$helper->show_toolbar = false;
$helper->toolbar_scroll = false;
$fields_form[0]['form']['legend'] = array(
'title' => $this->displayName,
'image' => $this->_path . 'logox22.png'
);
if (Tools::getIsset('pkwizard')) {
$helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name . '&pkwizard';
$step = 1;
if (empty($this->_errors) && empty($_html)) {
if (Tools::getIsset(PKHelper::CPREFIX . 'STEP_WIZARD')) {
$step = Tools::getValue(PKHelper::CPREFIX . 'STEP_WIZARD', 0);
$step++;
}
}
$helper->title = $this->displayName . ' - ' . $this->l('Configuration Wizard');
$helper->submit_action = 'submitUpdateWizardForm' . $this->name;
$this->generateWizardForm($step, $fields_form, $helper);
$this->context->smarty->assign(array(
'psversion' => _PS_VERSION_,
));
if (is_array($this->_errors))
$_html = implode('', $this->_errors) . $_html;
else
$_html = $this->_errors . $_html;
return $_html
. $helper->generateForm($fields_form)
. $this->display(__FILE__, 'views/templates/admin/jsfunctions.tpl')
. $this->display(__FILE__, 'views/templates/admin/piwik_site_lookup.tpl');
}
$helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name;
$helper->title = $this->displayName;
$helper->submit_action = 'submitUpdate' . $this->name;
if ($this->piwikSite !== FALSE) {
$fields_form[0]['form']['input'][] = array(
'type' => 'html',
'name' => "<div class=\"nav nav-pills pull-right\">"
. "<i class=\"icon-wrench\" style=\"padding-right: 5px;\"></i>"
. "<a href='?controller=AdminModules&token=" . Tools::getAdminTokenLite('AdminModules') . "&configure=piwikanalyticsjs&tab_module=analytics_stats&module_name=piwikanalyticsjs&pkwizard' title='{$this->l('Click here to open piwik site lookup wizard')}' data-html='true' data-toggle='tooltip' data-original-title='{$this->l('Click here to open piwik site lookup wizard')}' class='label-tooltip'>{$this->l('Configuration Wizard')}</a>"
. "</div>"
. $this->l('Based on the settings you provided this is the info i get from Piwik!') . "<br>"
. "<strong>" . $this->l('Name') . "</strong>: <i>{$this->piwikSite[0]->name}</i><br>"
. "<strong>" . $this->l('Main Url') . "</strong>: <i>{$this->piwikSite[0]->main_url}</i><br>"
);
} else {
$fields_form[0]['form']['input'][] = array(
'type' => 'html',
'name' => "<div class=\"nav nav-pills pull-right\">"
. "<i class=\"icon-wrench\" style=\"padding-right: 5px;\"></i>"
. "<a href='?controller=AdminModules&token=" . Tools::getAdminTokenLite('AdminModules') . "&configure=piwikanalyticsjs&tab_module=analytics_stats&module_name=piwikanalyticsjs&pkwizard' title='{$this->l('Click here to open piwik site lookup wizard')}' data-html='true' data-toggle='tooltip' data-original-title='{$this->l('Click here to open piwik site lookup wizard')}' class='label-tooltip'>{$this->l('Configuration Wizard')}</a>"
. "</div>"
);
}
$fields_form[0]['form']['input'][] = array(
'type' => 'text',
'label' => $this->l('Piwik Host'),
'name' => PKHelper::CPREFIX . 'HOST',
'desc' => $this->l('Example: www.example.com/piwik/ (without protocol and with / at the end!)'),
'hint' => $this->l('The host where piwik is installed.!'),
'required' => true
);
$fields_form[0]['form']['input'][] = array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Use proxy script'),
'name' => PKHelper::CPREFIX . 'USE_PROXY',
'desc' => $this->l('Whether or not to use the proxy insted of Piwik Host'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
);
$fields_form[0]['form']['input'][] = array(
'type' => 'text',
'label' => $this->l('Proxy script'),
'name' => PKHelper::CPREFIX . 'PROXY_SCRIPT',
'hint' => $this->l('Example: www.example.com/pkproxy.php'),
'desc' => sprintf($this->l('the FULL path to proxy script to use, build-in: [%s]'), self::getModuleLink($this->name, 'piwik')),
'required' => false
);
if (function_exists('curl_version')) {
$fields_form[0]['form']['input'][] = array(
'type' => 'switch',
'is_bool' => true,
'label' => $this->l('Use cURL'),
'name' => PKHelper::CPREFIX . 'USE_CURL',
'desc' => $this->l('Whether or not to use cURL in Piwik API and proxy requests?'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
);
}
$fields_form[0]['form']['input'][] = array(
'type' => 'text',
'label' => $this->l('Piwik site id'),
'name' => PKHelper::CPREFIX . 'SITEID',
'desc' => $this->l('Example: 10'),
'hint' => $this->l('You can find piwik site id by loggin to piwik installation.'),
'required' => true
);
$fields_form[0]['form']['input'][] = array(
'type' => 'text',
'label' => $this->l('Piwik token auth'),
'name' => PKHelper::CPREFIX . 'TOKEN_AUTH',
'desc' => $this->l('You can find piwik token by loggin to piwik installation. under API'),
'required' => true
);
$fields_form[0]['form']['input'][] = array(
'type' => 'text',
'label' => $this->l('Track visitors across subdomains'),
'name' => PKHelper::CPREFIX . 'COOKIE_DOMAIN',
'desc' => $this->l('The default is the document domain; if your web site can be visited at both www.example.com and example.com, you would use: "*.example.com" OR ".example.com" without the quotes')
. '<br />'
. $this->l('Leave empty to exclude this from the tracking code'),
'hint' => $this->l('So if one visitor visits x.example.com and y.example.com, they will be counted as a unique visitor. (setCookieDomain)'),
'required' => false
);
$fields_form[0]['form']['input'][] = array(
'type' => (version_compare(_PS_VERSION_, '1.5', '>=') ? 'tags' : 'text'),
'label' => $this->l('Hide known alias URLs'),
'name' => PKHelper::CPREFIX . 'SET_DOMAINS',
'desc' => $this->l('In the "Outlinks" report, hide clicks to known alias URLs, Example: *.example.com')
. '<br />'
. $this->l('Note: to add multiple domains you must separate them with comma ","')
. '<br />'
. $this->l('Note: the currently tracked website is added to this array automatically')
. '<br />'
. $this->l('Leave empty to exclude this from the tracking code'),
'hint' => $this->l('So clicks on links to Alias URLs (eg. x.example.com) will not be counted as "Outlink". (setDomains)'),
'required' => false
);
$fields_form[0]['form']['input'][] = array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Enable client side DoNotTrack detection'),
'name' => PKHelper::CPREFIX . 'DNT',
'desc' => $this->l('So tracking requests will not be sent if visitors do not wish to be tracked.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
);
if (Configuration::get(PKHelper::CPREFIX . 'TOKEN_AUTH') !== false)
$image_tracking = PKHelper::getPiwikImageTrackingCode();
else
$image_tracking = array(
'default' => $this->l('I need Site ID and Auth Token before i can get your image tracking code'),
'proxy' => $this->l('I need Site ID and Auth Token before i can get your image tracking code')
);
$this->displayErrors(PKHelper::$errors);
PKHelper::$errors = PKHelper::$error = "";
$fields_form[0]['form']['input'][] = array(
'type' => 'html',
'name' => $this->l('Piwik image tracking code append one of them to field "Extra HTML" this will add images tracking code to all your pages') . "<br>"
. "<strong>" . $this->l('default') . "</strong>:<br /><i>{$image_tracking['default']}</i><br>"
. "<strong>" . $this->l('using proxy script') . "</strong>:<br /><i>{$image_tracking['proxy']}</i><br>"
. (version_compare(_PS_VERSION_, '1.6.0.7', '>=') ?
"<br><strong>{$this->l("Before you add the image tracking code make sure the HTMLPurifier library isn't in use, check the settings in 'Preferences => General', you can enable the HTMLPurifier again after you made your changes")}</strong>" :
""
)
);
$fields_form[0]['form']['input'][] = array(
'type' => 'textarea',
'label' => $this->l('Extra HTML'),
'name' => PKHelper::CPREFIX . 'EXHTML',
'desc' => $this->l('Some extra HTML code to put after the piwik tracking code, this can be any html of your choice'),
'rows' => 10,
'cols' => 50,
);
$fields_form[0]['form']['input'][] = array(
'type' => 'select',
'label' => $this->l('Piwik Currency'),
'name' => PKHelper::CPREFIX . 'DEFAULT_CURRENCY',
'desc' => sprintf($this->l('Based on your settings in Piwik your default currency is %s'), ($this->piwikSite !== FALSE ? $this->piwikSite[0]->currency : $this->l('unknown'))),
'options' => array(
'default' => $this->default_currency,
'query' => $this->currencies,
'id' => 'iso_code',
'name' => 'name'
),
);
$fields_form[0]['form']['input'][] = array(
'type' => 'select',
'label' => $this->l('Piwik Report date'),
'name' => PKHelper::CPREFIX . 'DREPDATE',
'desc' => $this->l('Report date to load by default from "Stats => Piwik Analytics"'),
'options' => array(
'default' => array('value' => 'day|today', 'label' => $this->l('Today')),
'query' => array(
array('str' => 'day|today', 'name' => $this->l('Today')),
array('str' => 'day|yesterday', 'name' => $this->l('Yesterday')),
array('str' => 'range|previous7', 'name' => $this->l('Previous 7 days (not including today)')),
array('str' => 'range|previous30', 'name' => $this->l('Previous 30 days (not including today)')),
array('str' => 'range|last7', 'name' => $this->l('Last 7 days (including today)')),
array('str' => 'range|last30', 'name' => $this->l('Last 30 days (including today)')),
array('str' => 'week|today', 'name' => $this->l('Current Week')),
array('str' => 'month|today', 'name' => $this->l('Current Month')),
array('str' => 'year|today', 'name' => $this->l('Current Year')),
),
'id' => 'str',
'name' => 'name'
),
);
$fields_form[0]['form']['input'][] = array(
'type' => 'text',
'label' => $this->l('Piwik User name'),
'name' => PKHelper::CPREFIX . 'USRNAME',
'desc' => $this->l('You can store your Username for Piwik here to make it easy to open piwik interface from your stats page with automatic login'),
'required' => false,
'autocomplete' => false,
);
$fields_form[0]['form']['input'][] = array(
'type' => 'password',
'label' => $this->l('Piwik User password'),
'name' => PKHelper::CPREFIX . 'USRPASSWD',
'desc' => $this->l('You can store your Password for Piwik here to make it easy to open piwik interface from your stats page with automatic login'),
'required' => false,
'autocomplete' => false,
);
$fields_form[0]['form']['submit'] = array(
'title' => $this->l('Save'),
'class' => 'btn btn-default'
);
$fields_form[1]['form'] = array(
'legend' => array(
'title' => $this->displayName . ' ' . $this->l('Advanced'),
'image' => $this->_path . 'logox22.png'
),
'input' => array(
array(
'type' => 'html',
'name' => $this->l('In this section you can modify certain aspects of the way this plugin sends products, searches, category view etc.. to piwik')
),
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Use HTTPS'),
'name' => PKHelper::CPREFIX . 'CRHTTPS',
'hint' => $this->l('ONLY enable this feature if piwik installation is accessible via https'),
'desc' => $this->l('use Hypertext Transfer Protocol Secure (HTTPS) in all requests from code to piwik, this only affects how requests are sent from proxy script to piwik, your visitors will still use the protocol they visit your shop with'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'html',
'name' => $this->l('in the next few inputs you can set how the product id is passed on to piwik')
. '<br />'
. $this->l('there are three variables you can use:')
. '<br />'
. $this->l('{ID} : this variable is replaced with id the product has in prestashop')
. '<br />'
. $this->l('{REFERENCE} : this variable is replaced with the unique reference you when adding adding/updating a product, this variable is only available in prestashop 1.5 and up')
. '<br />'
. $this->l('{ATTRID} : this variable is replaced with id the product attribute')
. '<br />'
. $this->l('in cases where only the product id is available it be parsed as ID and nothing else'),
),
array(
'type' => 'text',
'label' => $this->l('Product id V1'),
'name' => PKHelper::CPREFIX . 'PRODID_V1',
'desc' => $this->l('This template is used in case ALL three values are available ("Product ID", "Product Attribute ID" and "Product Reference")'),
'required' => false
),
array(
'type' => 'text',
'label' => $this->l('Product id V2'),
'name' => PKHelper::CPREFIX . 'PRODID_V2',
'desc' => $this->l('This template is used in case only "Product ID" and "Product Reference" are available'),
'required' => false
),
array(
'type' => 'text',
'label' => $this->l('Product id V3'),
'name' => PKHelper::CPREFIX . 'PRODID_V3',
'desc' => $this->l('This template is used in case only "Product ID" and "Product Attribute ID" are available'),
'required' => false
),
array(
'type' => 'html',
'name' => "<strong>{$this->l('Piwik Cookies')}</strong>"
),
array(
'type' => 'text',
'label' => $this->l('Piwik Session Cookie timeout'),
'name' => PKHelper::CPREFIX . 'SESSION_TIMEOUT',
'required' => false,
'hint' => $this->l('this value must be set in minutes'),
'desc' => $this->l('Piwik Session Cookie timeout, the default is 30 minutes'),
),
array(
'type' => 'text',
'label' => $this->l('Piwik Visitor Cookie timeout'),
'name' => PKHelper::CPREFIX . 'COOKIE_TIMEOUT',
'required' => false,
'hint' => $this->l('this value must be set in minutes'),
'desc' => $this->l('Piwik Visitor Cookie timeout, the default is 13 months (569777 minutes)'),
),
array(
'type' => 'text',
'label' => $this->l('Piwik Referral Cookie timeout'),
'name' => PKHelper::CPREFIX . 'RCOOKIE_TIMEOUT',
'required' => false,
'hint' => $this->l('this value must be set in minutes'),
'desc' => $this->l('Piwik Referral Cookie timeout, the default is 6 months (262974 minutes)'),
),
array(
'type' => 'html',
'name' => "<strong>{$this->l('Piwik Proxy Script Authorization? if piwik is installed behind HTTP Basic Authorization (Both password and username must be filled before the values will be used)')}</strong>"
),
array(
'type' => 'text',
'label' => $this->l('Proxy Script Username'),
'name' => PKHelper::CPREFIX . 'PAUTHUSR',
'required' => false,
'autocomplete' => false,
'desc' => $this->l('this field along with password can be used if piwik installation is protected by HTTP Basic Authorization'),
),
array(
'type' => 'password',
'label' => $this->l('Proxy Script Password'),
'name' => PKHelper::CPREFIX . 'PAUTHPWD',
'required' => false,
'autocomplete' => false,
'desc' => $this->l('this field along with username can be used if piwik installation is protected by HTTP Basic Authorization'),
),
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default'
)
);
if ($this->piwikSite !== FALSE) {
$tmp = PKHelper::getMyPiwikSites(TRUE);
$this->displayErrors(PKHelper::$errors);
PKHelper::$errors = PKHelper::$error = "";
$pksite_default = array('value' => 0, 'label' => $this->l('Choose Piwik site'));
$pksites = array();
foreach ($tmp as $pksid) {
$pksites[] = array(
'pkid' => $pksid->idsite,
'name' => "{$pksid->name} #{$pksid->idsite}",
);
}
unset($tmp, $pksid);
$pktimezone_default = array('value' => 0, 'label' => $this->l('Choose Timezone'));
$pktimezones = array();
$tmp = PKHelper::getTimezonesList();
$this->displayErrors(PKHelper::$errors);
PKHelper::$errors = PKHelper::$error = "";
foreach ($tmp as $key => $pktz) {
if (!isset($pktimezones[$key])) {
$pktimezones[$key] = array(
'name' => $this->l($key),
'query' => array(),
);
}
foreach ($pktz as $pktzK => $pktzV) {
$pktimezones[$key]['query'][] = array(
'tzId' => $pktzK,
'tzName' => $pktzV,
);
}
}
unset($tmp, $pktz, $pktzV, $pktzK);
$fields_form[2]['form'] = array(
'legend' => array(
'title' => $this->displayName . ' ' . $this->l('Advanced') . ' - ' . $this->l('Edit Piwik site'),
'image' => $this->_path . 'logox22.png'
),
'input' => array(
array(
'type' => 'select',
'label' => $this->l('Piwik Site'),
'name' => 'SPKSID',
'desc' => sprintf($this->l('Based on your settings in Piwik your default site is %s'), $this->piwikSite[0]->idsite),
'options' => array(
'default' => $pksite_default,
'query' => $pksites,
'id' => 'pkid',
'name' => 'name'
),
'onchange' => 'return ChangePKSiteEdit(this.value)',
),
array(
'type' => 'html',
'name' => $this->l('In this section you can modify your settings in piwik just so you don\'t have to login to Piwik to do this') . "<br>"
. "<strong>" . $this->l('Currently selected name') . "</strong>: <i id='wnamedsting'>{$this->piwikSite[0]->name}</i><br>"
. "<input type=\"hidden\" name=\"PKAdminIdSite\" id=\"PKAdminIdSite\" value=\"{$this->piwikSite[0]->idsite}\" />"
),
array(
'type' => 'text',
'label' => $this->l('Piwik Site Name'),
'name' => 'PKAdminSiteName',
'desc' => $this->l('Name of this site in Piwik'),
),
// array(
// 'type' => 'text',
// 'label' => $this->l('Site urls'),
// 'name' => 'PKAdminSiteUrls',
// ),
array(
'type' => 'switch',
'is_bool' => true,
'label' => $this->l('Ecommerce'),
'name' => 'PKAdminEcommerce',
'desc' => $this->l('Is this site an ecommerce site?'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('No')
)
),
),
array(
'type' => 'switch',
'is_bool' => true,
'label' => $this->l('Site Search'),
'name' => 'PKAdminSiteSearch',
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('No')
)
),
),
array(
'type' => (version_compare(_PS_VERSION_, '1.5', '>=') ? 'tags' : 'text'),
'label' => $this->l('Search Keyword Parameters'),
'name' => 'PKAdminSearchKeywordParameters',
'desc' => $this->l('the following keyword parameters must be excluded to avoid normal page views to be interpreted as searches (the tracking code will see them and make the required postback to Piwik if it is a real search), if you are only using PrestaShop with this site setting this to empty, will be sufficient')
. "<br><br><strong>tag</strong> and <strong>search_query</strong>",
),
array(
'type' => (version_compare(_PS_VERSION_, '1.5', '>=') ? 'tags' : 'text'),
'label' => $this->l('Search Category Parameters'),
'name' => 'PKAdminSearchCategoryParameters',
),
array(
'type' => (version_compare(_PS_VERSION_, '1.5', '>=') ? 'tags' : 'text'),
'label' => $this->l('Excluded ip addresses'),
'name' => 'PKAdminExcludedIps',
'desc' => $this->l('ip addresses excluded from tracking, separated by comma ","'),
),
array(
'type' => (version_compare(_PS_VERSION_, '1.5', '>=') ? 'tags' : 'text'),
'label' => $this->l('Excluded Query Parameters'),
'name' => 'PKAdminExcludedQueryParameters',
'desc' => $this->l('please read: http://piwik.org/faq/how-to/faq_81/'),
),
array(
'type' => 'select',
'label' => $this->l('Timezone'),
'name' => 'PKAdminTimezone',
'desc' => sprintf($this->l('Based on your settings in Piwik your default timezone is %s'), $this->piwikSite[0]->timezone),
'options' => array(
'default' => $pktimezone_default,
'optiongroup' => array(
'label' => 'name',
'query' => $pktimezones,
),
'options' => array(
'id' => 'tzId',
'name' => 'tzName',
'query' => 'query',
),
),
),
array(
'type' => 'select',
'label' => $this->l('Currency'),
'name' => 'PKAdminCurrency',
'desc' => sprintf($this->l('Based on your settings in Piwik your default currency is %s'), $this->piwikSite[0]->currency),
'options' => array(
'default' => $this->default_currency,
'query' => $this->currencies,
'id' => 'iso_code',
'name' => 'name'
),
),
// array(
// 'type' => 'text',
// 'label' => $this->l('Website group'),
// 'name' => 'PKAdminGroup',
// 'desc' => sprintf('Requires plugin "WebsiteGroups" before it can be used from within Piwik'),
// ),
// array(
// 'type' => 'text',
// 'label' => $this->l('Website start date'),
// 'name' => 'PKAdminStartDate',
// ),
array(
'type' => 'textarea',
'label' => $this->l('Excluded User Agents'),
'name' => 'PKAdminExcludedUserAgents',
'rows' => 10,
'cols' => 50,
'desc' => $this->l('please read: http://piwik.org/faq/how-to/faq_17483/'),
),
array(
'type' => 'switch',
'is_bool' => true,
'label' => $this->l('Keep URL Fragments'),
'name' => 'PKAdminKeepURLFragments',
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('No')
)
),
),
// array(
// 'type' => 'text',
// 'label' => $this->l('Site Type'),
// 'name' => 'PKAdminSiteType',
// ),
array('type' => 'html', 'name' => "
<button onclick=\"return submitPiwikSiteAPIUpdate()\"
id=\"submitUpdatePiwikAdmSite\" class=\"btn btn-default pull-left\"
name=\"submitUpdatePiwikAdmSite\" value=\"1\" type=\"button\">
<i class=\"process-icon-save\"></i>{$this->l('Save')}</button>"),
),
);