-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy patheverblock.php
2878 lines (2784 loc) · 119 KB
/
everblock.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
/**
* 2019-2024 Team Ever
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author Team Ever <https://www.team-ever.com/>
* @copyright 2019-2024 Team Ever
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
if (!defined('_PS_VERSION_')) {
exit;
}
require_once('vendor/autoload.php');
require_once _PS_MODULE_DIR_ . 'everblock/models/EverblockClass.php';
require_once _PS_MODULE_DIR_ . 'everblock/models/EverblockShortcode.php';
require_once _PS_MODULE_DIR_ . 'everblock/models/EverblockTools.php';
require_once _PS_MODULE_DIR_ . 'everblock/models/EverblockTabsClass.php';
require_once _PS_MODULE_DIR_ . 'everblock/models/EverblockFlagsClass.php';
require_once _PS_MODULE_DIR_ . 'everblock/models/EverblockFaq.php';
require_once _PS_MODULE_DIR_ . 'everblock/models/EverblockPrettyBlocks.php';
require_once _PS_MODULE_DIR_ . 'everblock/models/EverblockCache.php';
require_once _PS_MODULE_DIR_ . 'everblock/models/EverblockGpt.php';
require_once _PS_MODULE_DIR_ . 'everblock/models/EverblockCheckoutStep.php';
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
use PrestaShop\PrestaShop\Adapter\Product\PriceFormatter;
use PrestaShop\PrestaShop\Core\Product\ProductListingPresenter;
use PrestaShop\PrestaShop\Adapter\Product\ProductColorsRetriever;
use \PrestaShop\PrestaShop\Core\Product\ProductPresenter;
use PrestaShop\PrestaShop\Core\Product\ProductExtraContent;
use ScssPhp\ScssPhp\Compiler;
use Everblock\Tools\Service\ImportFile;
class Everblock extends Module
{
private $html;
private $postErrors = [];
private $postSuccess = [];
private $allowedActions = [
'saveblocks',
'restoreblocks',
'removeinlinecsstags',
'droplogs',
'refreshtokens',
'securewithapache',
];
private $bypassedControllers = [
'hookDisplayInvoiceLegalFreeText',
];
public function __construct()
{
$this->name = 'everblock';
$this->tab = 'front_office_features';
$this->version = '6.3.3';
$this->author = 'Team Ever';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Ever Block');
$this->description = $this->l('Add HTML block everywhere !');
$this->confirmUninstall = $this->l('Do yo really want to uninstall this module ?');
$this->ps_versions_compliancy = [
'min' => '1.7',
'max' => _PS_VERSION_,
];
}
public function __call($method, $args)
{
if (php_sapi_name() == 'cli') {
return;
}
$controllerTypes = [
'front',
'modulefront',
];
$context = Context::getContext();
if (!in_array($context->controller->controller_type, $controllerTypes) && !in_array($method, $this->bypassedControllers)) {
return;
}
if (Hook::isDisplayHookName(lcfirst(str_replace('hook', '', $method)))) {
return $this->everHook($method, $args);
}
}
public function install()
{
Configuration::updateValue('EVERBLOCK_TINYMCE', 1);
Configuration::updateValue('EVERPSCSS_P_LLOREM_NUMBER', 5);
Configuration::updateValue('EVERPSCSS_S_LLOREM_NUMBER', 5);
Configuration::updateValue('EVERPS_TAB_NB', 5);
Configuration::updateValue('EVERPS_FLAG_NB', 5);
Configuration::updateValue(
'EVERPS_FEATURES_AS_FLAGS',
json_encode([1]),
true
);
// Install SQL
$sql = [];
include dirname(__FILE__) . '/sql/install.php';
// Hook actionGetEverBlockBefore
if (!Hook::getIdByName('actionGetEverBlockBefore')) {
$hook = new Hook();
$hook->name = 'actionGetEverBlockBefore';
$hook->title = 'Before block is rendered';
$hook->description = 'This hook triggers before block is rendered';
$hook->save();
}
// Hook actionEverBlockChangeShortcodeBefore
if (!Hook::getIdByName('actionEverBlockChangeShortcodeBefore')) {
$hook = new Hook();
$hook->name = 'actionEverBlockChangeShortcodeBefore';
$hook->title = 'Before block shortcodes are rendered';
$hook->description = 'This hook triggers before every block shortcode is rendered';
$hook->save();
}
// Hook actionEverBlockChangeShortcodeBefore
if (!Hook::getIdByName('actionEverBlockChangeShortcodeAfter')) {
$hook = new Hook();
$hook->name = 'actionEverBlockChangeShortcodeAfter';
$hook->title = 'After block shortcodes are rendered';
$hook->description = 'This hook triggers after every block shortcode is rendered';
$hook->save();
}
return (parent::install()
&& $this->registerHook('displayHeader')
&& $this->registerHook('actionAdminControllerSetMedia')
&& $this->registerHook('actionRegisterBlock')
&& $this->installModuleTab('AdminEverBlockParent', 'IMPROVE', $this->l('Ever Block'))
&& $this->installModuleTab('AdminEverBlock', 'AdminEverBlockParent', $this->l('HTML Blocks'))
&& $this->installModuleTab('AdminEverBlockHook', 'AdminEverBlockParent', $this->l('Hooks'))
&& $this->installModuleTab('AdminEverBlockShortcode', 'AdminEverBlockParent', $this->l('Shortcodes')))
&& $this->installModuleTab('AdminEverBlockFaq', 'AdminEverBlockParent', $this->l('FAQ'));
}
public function uninstall()
{
// Uninstall SQL
$sql = [];
include dirname(__FILE__) . '/sql/uninstall.php';
Configuration::deleteByName('EVERPSCSS_CACHE');
Configuration::deleteByName('EVERPSCSS_LINKS');
Configuration::deleteByName('EVERPSJS_LINKS');
Configuration::deleteByName('EVERPSCSS_P_LLOREM_NUMBER');
Configuration::deleteByName('EVERPSCSS_S_LLOREM_NUMBER');
Configuration::deleteByName('EVERBLOCK_TINYMCE');
return (parent::uninstall()
&& $this->uninstallModuleTab('AdminEverBlockParent')
&& $this->uninstallModuleTab('AdminEverBlock')
&& $this->uninstallModuleTab('AdminEverBlockHook')
&& $this->uninstallModuleTab('AdminEverBlockShortcode')
&& $this->uninstallModuleTab('AdminEverBlockFaq'));
}
protected function installModuleTab($tabClass, $parent, $tabName)
{
$tab = new Tab();
$tab->active = 1;
$tab->class_name = $tabClass;
$tab->id_parent = (int) Tab::getIdFromClassName($parent);
$tab->position = Tab::getNewLastPosition($tab->id_parent);
$tab->module = $this->name;
if ($tabClass == 'AdminEverBlockParent') {
$tab->icon = 'icon-team-ever';
}
foreach (Language::getLanguages(false) as $lang) {
$tab->name[(int) $lang['id_lang']] = $tabName;
}
return $tab->add();
}
protected function uninstallModuleTab($tabClass)
{
$tab = new Tab((int) Tab::getIdFromClassName($tabClass));
return $tab->delete();
}
public function checkHooks()
{
// Hook displayEverblockExtraOrderStep
if (!Hook::getIdByName('displayEverblockExtraOrderStep')) {
$hook = new Hook();
$hook->name = 'displayEverblockExtraOrderStep';
$hook->title = 'Extra order step';
$hook->description = 'This hook is triggered on extra order step';
$hook->save();
}
// Hook actionGetEverBlockBefore
if (!Hook::getIdByName('actionGetEverBlockBefore')) {
$hook = new Hook();
$hook->name = 'actionGetEverBlockBefore';
$hook->title = 'Before block is rendered';
$hook->description = 'This hook triggers before block is rendered';
$hook->save();
}
// Hook actionEverBlockChangeShortcodeBefore
if (!Hook::getIdByName('actionEverBlockChangeShortcodeBefore')) {
$hook = new Hook();
$hook->name = 'actionEverBlockChangeShortcodeBefore';
$hook->title = 'Before block shortcodes are rendered';
$hook->description = 'This hook triggers before every block shortcode is rendered';
$hook->save();
}
// Hook actionEverBlockChangeShortcodeBefore
if (!Hook::getIdByName('actionEverBlockChangeShortcodeAfter')) {
$hook = new Hook();
$hook->name = 'actionEverBlockChangeShortcodeAfter';
$hook->title = 'After block shortcodes are rendered';
$hook->description = 'This hook triggers after every block shortcode is rendered';
$hook->save();
}
// Vérifier si l'onglet "AdminEverBlockParent" existe déjà
$id_tab = Tab::getIdFromClassName('AdminEverBlockParent');
if (!$id_tab) {
$tab = new Tab();
$tab->class_name = 'AdminEverBlockParent';
$tab->module = $this->name;
$tab->id_parent = Tab::getIdFromClassName('IMPROVE');
$tab->position = Tab::getNewLastPosition($tab->id_parent);
foreach (Language::getLanguages(false) as $lang) {
$tab->name[(int) $lang['id_lang']] = $this->l('Ever Block');
}
$tab->add();
}
// Vérifier si l'onglet "AdminEverBlock" existe déjà
$id_tab = Tab::getIdFromClassName('AdminEverBlock');
if (!$id_tab) {
$tab = new Tab();
$tab->class_name = 'AdminEverBlock';
$tab->module = $this->name;
$tab->id_parent = Tab::getIdFromClassName('AdminEverBlockParent');
$tab->position = Tab::getNewLastPosition($tab->id_parent);
foreach (Language::getLanguages(false) as $lang) {
$tab->name[(int) $lang['id_lang']] = $this->l('HTML blocks management');
}
$tab->add();
}
// Vérifier si l'onglet "Hook management" existe déjà
$id_tab = Tab::getIdFromClassName('AdminEverBlockHook');
if (!$id_tab) {
$tab = new Tab();
$tab->class_name = 'AdminEverBlockHook';
$tab->module = $this->name;
$tab->id_parent = Tab::getIdFromClassName('AdminEverBlockParent');
$tab->position = Tab::getNewLastPosition($tab->id_parent);
foreach (Language::getLanguages(false) as $lang) {
$tab->name[(int) $lang['id_lang']] = $this->l('Hook management');
}
$tab->add();
}
// Vérifier si l'onglet "Shortcodes management" existe déjà
$id_tab = Tab::getIdFromClassName('AdminEverBlockShortcode');
if (!$id_tab) {
$tab = new Tab();
$tab->class_name = 'AdminEverBlockShortcode';
$tab->module = $this->name;
$tab->id_parent = Tab::getIdFromClassName('AdminEverBlockParent');
$tab->position = Tab::getNewLastPosition($tab->id_parent);
foreach (Language::getLanguages(false) as $lang) {
$tab->name[(int) $lang['id_lang']] = $this->l('Shortcodes management');
}
$tab->add();
}
// Vérifier si l'onglet "FAQ management" existe déjà
$id_tab = Tab::getIdFromClassName('AdminEverBlockFaq');
if (!$id_tab) {
$tab = new Tab();
$tab->class_name = 'AdminEverBlockFaq';
$tab->module = $this->name;
$tab->id_parent = Tab::getIdFromClassName('AdminEverBlockParent');
$tab->position = Tab::getNewLastPosition($tab->id_parent);
foreach (Language::getLanguages(false) as $lang) {
$tab->name[(int) $lang['id_lang']] = $this->l('FAQ');
}
$tab->add();
}
$this->registerHook('actionCmsPageFormBuilderModifier');
$this->registerHook('actionObjectCmsUpdateAfter');
$this->registerHook('displayMaintenance');
$this->registerHook('displayPDFInvoice');
$this->registerHook('displayPDFDeliverySlip');
$this->registerHook('displayAdminOrder');
$this->registerHook('actionCheckoutRender');
$this->registerHook('displayOrderConfirmation');
$this->unregisterHook('actionDispatcherBefore');
$this->registerHook('actionGetAdminOrderButtons');
$this->registerHook('displayAdminCustomers');
$this->registerHook('actionCustomerLogoutBefore');
$this->registerHook('displayAdminProductsExtra');
$this->registerHook('actionObjectProductUpdateAfter');
$this->registerHook('actionObjectProductDeleteAfter');
$this->registerHook('displayProductExtraContent');
$this->registerHook('actionOutputHTMLBefore');
$this->registerHook('displayHeader');
$this->registerHook('actionAdminControllerSetMedia');
$this->registerHook('actionObjectEverBlockClassUpdateAfter');
$this->registerHook('actionObjectEverBlockClassDeleteAfter');
$this->registerHook('actionObjectEverblockFaqUpdateAfter');
$this->registerHook('actionObjectEverblockFaqDeleteAfter');
$this->registerHook('actionObjectEverBlockFlagsUpdateAfter');
$this->registerHook('actionObjectEverBlockFlagsDeleteAfter');
$this->registerHook('displayWrapperBottom');
$this->registerHook('displayWrapperTop');
$this->registerHook('actionProductFlagsModifier');
$this->registerHook('actionEmailAddAfterContent');
if ((bool) Module::isInstalled('prettyblocks') === true
&& (bool) Module::isEnabled('prettyblocks') === true
&& (bool) EverblockTools::moduleDirectoryExists('prettyblocks') === true
) {
$this->registerHook('actionRegisterBlock');
} else {
$this->unregisterHook('actionRegisterBlock');
}
}
public function getContent()
{
$this->createUpgradeFile();
$this->secureModuleFolder();
EverblockTools::checkAndFixDatabase();
$this->checkHooks();
$this->html = '';
if (((bool) Tools::isSubmit('submit' . $this->name . 'Module')) == true) {
$this->postValidation();
if (!count($this->postErrors)) {
$this->postProcess();
}
}
if ((bool) Tools::isSubmit('submitUploadTabsFile') === true) {
$this->uploadTabsFile();
}
if ((bool) Tools::isSubmit('submitEmptyCache') === true) {
$this->emptyAllCache();
}
if ((bool) Tools::isSubmit('submitEmptyLogs') === true) {
$purged = EverblockTools::purgeNativePrestashopLogsTable();
if ((bool) $purged === true) {
$this->postSuccess[] = $this->l('Log tables emptied');
} else {
$this->postErrors[] = $this->l('Log tables NOT emptied');
}
}
if ((bool) Tools::isSubmit('submitDropUnusedLangs') === true) {
$dropped = EverblockTools::dropUnusedLangs();
if (is_array($dropped)
&& isset($dropped['postErrors'])
&& count($dropped['postErrors']) > 0
) {
foreach ($dropped['postErrors'] as $postErrors) {
$this->postErrors[] = $postErrors;
}
}
if (is_array($dropped)
&& isset($dropped['querySuccess'])
&& count($dropped['querySuccess']) > 0
) {
foreach ($dropped['querySuccess'] as $querySuccess) {
$this->postSuccess[] = $querySuccess;
}
}
}
if ((bool) Tools::isSubmit('submitSecureModuleFoldersWithApache') === true) {
$secured = EverblockTools::secureModuleFoldersWithApache();
if (is_array($secured)
&& isset($secured['postErrors'])
&& count($secured['postErrors']) > 0
) {
foreach ($secured['postErrors'] as $postErrors) {
$this->postErrors[] = $postErrors;
}
}
if (is_array($secured)
&& isset($secured['querySuccess'])
&& count($secured['querySuccess']) > 0
) {
foreach ($secured['querySuccess'] as $querySuccess) {
$this->postSuccess[] = $querySuccess;
}
}
}
if ((bool) Tools::isSubmit('submitBackupBlocks') === true) {
$backuped = EverblockTools::exportModuleTablesSQL();
if ((bool) $backuped === true) {
$this->postSuccess[] = $this->l('Backup done');
} else {
$this->postErrors[] = $this->l('Backup failed');
}
}
if ((bool) Tools::isSubmit('submitRestoreBackup') === true) {
$restored = EverblockTools::restoreModuleTablesFromBackup();
if ((bool) $restored === true) {
$this->postSuccess[] = $this->l('Restore done');
} else {
$this->postErrors[] = $this->l('Restore failed');
}
}
if ((bool) Tools::isSubmit('submitCreateProduct') === true) {
$created = EverblockTools::generateProducts(
(int) $this->context->shop->id
);
if ((bool) $created === true) {
$this->postSuccess[] = $this->l('Products creation done');
} else {
$this->postErrors[] = $this->l('Products creation failed');
}
}
if ((bool) Tools::isSubmit('submitConvertCmsToPrettyBlocks') === true) {
$cmsPages = Db::getInstance()->executeS('
SELECT c.id_cms
FROM ' . _DB_PREFIX_ . 'cms c
INNER JOIN ' . _DB_PREFIX_ . 'cms_shop cs ON c.id_cms = cs.id_cms
WHERE cs.id_shop = ' . (int)$this->context->shop->id
);
foreach ($cmsPages as $cms) {
EverblockPrettyBlocks::convertSingleCmsToPrettyBlock(
$this->context->shop->id,
$cms['id_cms']
);
}
}
if ((bool) Tools::isSubmit('submitMigrateUrls') === true
&& Tools::getValue('EVERPS_OLD_URL')
&& Tools::getValue('EVERPS_NEW_URL')
) {
$migration = EverblockTools::migrateUrls(
Tools::getValue('EVERPS_OLD_URL'),
Tools::getValue('EVERPS_NEW_URL'),
(int) $this->context->shop->id
);
if (is_array($migration)
&& isset($migration['postErrors'])
&& count($migration['postErrors']) > 0
) {
foreach ($migration['postErrors'] as $postErrors) {
$this->postErrors[] = $postErrors;
}
}
if (is_array($migration)
&& isset($migration['querySuccess'])
&& count($migration['querySuccess']) > 0
) {
foreach ($migration['querySuccess'] as $querySuccess) {
$this->postSuccess[] = $querySuccess;
}
}
}
if (count($this->postErrors)) {
foreach ($this->postErrors as $error) {
$this->html .= $this->displayError($error);
}
}
if (count($this->postSuccess)) {
foreach ($this->postSuccess as $success) {
$this->html .= $this->displayConfirmation($success);
}
}
$blockAdminLink = 'index.php?controller=AdminEverBlock&token=';
$blockAdminLink .= Tools::getAdminTokenLite('AdminEverBlock');
$faqAdminLink = 'index.php?controller=AdminEverBlockFaq&token=';
$faqAdminLink .= Tools::getAdminTokenLite('AdminEverBlockFaq');
$hookAdminLink = 'index.php?controller=AdminEverBlockHook&token=';
$hookAdminLink .= Tools::getAdminTokenLite('AdminEverBlockHook');
$shortcodeAdminLink = 'index.php?controller=AdminEverBlockShortcode&token=';
$shortcodeAdminLink .= Tools::getAdminTokenLite('AdminEverBlockShortcode');
$cronLinks = [];
$cronToken = Tools::encrypt($this->name . '/evercron');
foreach ($this->allowedActions as $action) {
$cronLinks[$action] = $this->context->link->getModuleLink(
$this->name,
'cron',
[
'action' => $action,
'evertoken' => $cronToken,
]
);
}
$this->context->smarty->assign([
'module_name' => $this->displayName,
$this->name . '_version' => $this->version,
$this->name . '_dir' => $this->_path,
'block_admin_link' => $blockAdminLink,
'faq_admin_link' => $faqAdminLink,
'hook_admin_link' => $hookAdminLink,
'shortcode_admin_link' => $shortcodeAdminLink,
'cron_links' => $cronLinks,
]);
$this->html .= $this->context->smarty->fetch(
$this->local_path . 'views/templates/admin/header.tpl'
);
if ($this->checkLatestEverModuleVersion()) {
$this->html .= $this->context->smarty->fetch(
$this->local_path . 'views/templates/admin/upgrade.tpl'
);
}
$this->html .= $this->renderForm();
$this->html .= $this->context->smarty->fetch(
$this->local_path . 'views/templates/admin/configure.tpl'
);
$this->html .= $this->context->smarty->fetch(
$this->local_path . 'views/templates/admin/footer.tpl'
);
return $this->html;
}
protected function renderForm()
{
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$helper->module = $this;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier = $this->identifier;
$helper->submit_action = 'submit' . $this->name . 'Module';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = [
'fields_value' => $this->getConfigFormValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
];
return $helper->generateForm($this->getConfigForm());
}
protected function getConfigForm()
{
$step_position = [
[
'id_position' => 1,
'name' => $this->l('After login'),
],
[
'id_position' => 2,
'name' => $this->l('After address form'),
],
[
'id_position' => 3,
'name' => $this->l('After shipping form'),
],
];
$features = Feature::getFeatures(
(int) $this->context->language->id
);
$formFields = [];
$formFields[] = [
'form' => [
'legend' => [
'title' => $this->l('Tools'),
'icon' => 'icon-smile',
],
'buttons' => [
'emptyCache' => [
'name' => 'submitEmptyCache',
'type' => 'submit',
'class' => 'btn btn-light',
'icon' => 'process-icon-refresh',
'title' => $this->l('Empty cache'),
],
'emptyLogs' => [
'name' => 'submitEmptyLogs',
'type' => 'submit',
'class' => 'btn btn-light',
'icon' => 'process-icon-refresh',
'title' => $this->l('Empty logs'),
],
'dropUnusedLangs' => [
'name' => 'submitDropUnusedLangs',
'type' => 'submit',
'class' => 'btn btn-light',
'icon' => 'process-icon-refresh',
'title' => $this->l('Drop unused langs'),
],
'secureModuleFoldersWithApache' => [
'name' => 'submitSecureModuleFoldersWithApache',
'type' => 'submit',
'class' => 'btn btn-light',
'icon' => 'process-icon-refresh',
'title' => $this->l('Secure all modules folders using Apache'),
],
'backupBlocks' => [
'name' => 'submitBackupBlocks',
'type' => 'submit',
'class' => 'btn btn-light',
'icon' => 'process-icon-refresh',
'title' => $this->l('Backup all blocks'),
],
'restoreBackup' => [
'name' => 'submitRestoreBackup',
'type' => 'submit',
'class' => 'btn btn-light',
'icon' => 'process-icon-refresh',
'title' => $this->l('Restore backup'),
],
],
],
];
$formFields[] = [
'form' => [
'legend' => [
'title' => $this->l('Settings'),
'icon' => 'icon-smile',
],
'input' => [
[
'type' => 'text',
'lang' => true,
'label' => $this->l('New order step title'),
'desc' => $this->l('Please specify new order step title'),
'hint' => $this->l('If not set, new order step won\'t be shown'),
'name' => 'EVEROPTIONS_TITLE',
'required' => true,
],
[
'type' => 'select',
'label' => $this->l('New order step position'),
'desc' => $this->l('Please select new order step position'),
'hint' => $this->l('Will impact position of the new order step'),
'name' => 'EVEROPTIONS_POSITION',
'options' => [
'query' => $step_position,
'id' => 'id_position',
'name' => 'name',
],
],
[
'type' => 'text',
'label' => $this->l('Maintenance password'),
'desc' => $this->l('If entered, you will have a password entry form on the maintenance page'),
'hint' => $this->l('People with the password will be able to access the store in maintenance mode'),
'name' => 'EVERBLOCK_MAINTENANCE_PSSWD',
],
[
'type' => 'text',
'label' => $this->l('Chat GPT API key'),
'desc' => $this->l('Add here your Chat GPT API key, it will be used for blocks generator'),
'hint' => $this->l('Without API key, blocks generator won\'t work'),
'name' => 'EVERGPT_API_KEY',
],
[
'type' => 'text',
'label' => $this->l('Instagram access token'),
'desc' => $this->l('Add here your Instagram access token'),
'hint' => $this->l('Without access token, you wont be able to show Instagram slider'),
'name' => 'EVERINSTA_ACCESS_TOKEN',
],
[
'type' => 'text',
'label' => $this->l('Instagram profile link'),
'desc' => $this->l('Add here your Instagram profile URL'),
'hint' => $this->l('This will set a custom link to your Instagram profile'),
'name' => 'EVERINSTA_LINK',
],
[
'type' => 'switch',
'label' => $this->l('Use Google Map for store locator instead of OSM'),
'desc' => $this->l('Will use Google Map API for store locator (CMS page only)'),
'hint' => $this->l('Else Open Street Map will be used'),
'name' => 'EVERBLOCK_USE_GMAP',
'is_bool' => true,
'values' => [
[
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled'),
],
[
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled'),
],
],
],
[
'type' => 'text',
'label' => $this->l('Google Map API key (CMS page only)'),
'desc' => $this->l('Add here your Google Map API key'),
'hint' => $this->l('Without API key, auto complete wont work'),
'name' => 'EVERBLOCK_GMAP_KEY',
],
[
'type' => 'switch',
'label' => $this->l('Empty cache on saving ?'),
'desc' => $this->l('Set yes to empty cache on saving'),
'hint' => $this->l('Else cache will not be emptied'),
'name' => 'EVERPSCSS_CACHE',
'is_bool' => true,
'values' => [
[
'id' => 'active_on',
'value' => true,
'label' => $this->l('Yes'),
],
[
'id' => 'active_off',
'value' => false,
'label' => $this->l('No'),
],
],
],
[
'type' => 'switch',
'label' => $this->l('Enable front-office script for obfuscation ?'),
'desc' => $this->l('Will load JS file to manage obfuscated links'),
'hint' => $this->l('Leave it to "No" if you already have a script that manages obfuscated links'),
'name' => 'EVERBLOCK_USE_OBF',
'is_bool' => true,
'values' => [
[
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled'),
],
[
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled'),
],
],
],
[
'type' => 'switch',
'label' => $this->l('Enable slick slider scripts ?'),
'desc' => $this->l('Set yes to enable slick scripts for carousels'),
'hint' => $this->l('Else carousels wont work'),
'name' => 'EVERBLOCK_USE_SLICK',
'is_bool' => true,
'values' => [
[
'id' => 'active_on',
'value' => true,
'label' => $this->l('Yes'),
],
[
'id' => 'active_off',
'value' => false,
'label' => $this->l('No'),
],
],
],
[
'type' => 'switch',
'label' => $this->l('Extends TinyMCE on blocks management ?'),
'desc' => $this->l('Set yes to extends TinyMCE on blocs management'),
'hint' => $this->l('Else TinyMCE will be default'),
'name' => 'EVERBLOCK_TINYMCE',
'is_bool' => true,
'values' => [
[
'id' => 'active_on',
'value' => true,
'label' => $this->l('Yes'),
],
[
'id' => 'active_off',
'value' => false,
'label' => $this->l('No'),
],
],
],
[
'type' => 'textarea',
'label' => $this->l('Custom CSS'),
'desc' => $this->l('Add here your custom CSS rules'),
'hint' => $this->l('Webdesigners here can manage CSS rules'),
'name' => 'EVERPSCSS',
],
[
'type' => 'textarea',
'label' => $this->l('Custom SASS'),
'desc' => $this->l('Add here your custom SASS rules that will be added after CSS rules'),
'hint' => $this->l('Webdesigners here can manage SASS rules'),
'name' => 'EVERPSSASS',
],
[
'type' => 'textarea',
'label' => $this->l('Custom Javascript'),
'desc' => $this->l('Add here your custom Javascript rules'),
'hint' => $this->l('Webdesigners here can manage Javascript rules'),
'name' => 'EVERPSJS',
],
[
'type' => 'textarea',
'label' => $this->l('Custom CSS links'),
'desc' => $this->l('Add here your custom CSS links, one per line'),
'hint' => $this->l('Add one link per line, must be CSS'),
'name' => 'EVERPSCSS_LINKS',
],
[
'type' => 'textarea',
'label' => $this->l('Custom JS links'),
'desc' => $this->l('Add here your custom JS links, one per line'),
'hint' => $this->l('Add one link per line, must be JS'),
'name' => 'EVERPSJS_LINKS',
],
[
'type' => 'textarea',
'label' => $this->l('Header scripts'),
'desc' => $this->l('Add here your custom header scripts'),
'hint' => $this->l('Header scripts like Clarity can be added here'),
'name' => 'EVERPS_HEADER_SCRIPTS',
],
[
'type' => 'select',
'class' => 'chosen',
'multiple' => true,
'label' => $this->l('Features as flags'),
'desc' => $this->l('Please select features used for flags'),
'hint' => $this->l('The selected features will be converted into product flags'),
'name' => 'EVERPS_FEATURES_AS_FLAGS[]',
'required' => false,
'options' => [
'query' => $features,
'id' => 'id_feature',
'name' => 'name',
],
],
[
'type' => 'text',
'label' => $this->l('Number of fictitious products to create during product generation'),
'desc' => $this->l('Will generate this number of dummy products when generating'),
'hint' => $this->l('Default will be 5'),
'name' => 'EVERPS_DUMMY_NBR',
'lang' => false,
],
[
'type' => 'text',
'label' => $this->l('Default number of paragraphs when [llorem] shortcode is detected'),
'desc' => $this->l('Will generate this number of paragraphs when the [llorem] shortcode is detected'),
'hint' => $this->l('Leaving this value blank will generate five paragraphs'),
'name' => 'EVERPSCSS_P_LLOREM_NUMBER',
],
[
'type' => 'text',
'label' => $this->l('Default number of sentences per paragraphs when [llorem] shortcode is detected'),
'desc' => $this->l('Will generate this number of sentences per paragraphs when the [llorem] shortcode is detected'),
'hint' => $this->l('Leaving this value blank will generate five sentences per paragraphs'),
'name' => 'EVERPSCSS_S_LLOREM_NUMBER',
],
[
'type' => 'text',
'label' => $this->l('Migration : Old URL'),
'desc' => $this->l('If an old URL and a new one are entered, the module will be able to change the old URL to the new one in the database.'),
'hint' => $this->l('Leave empty for no use'),
'name' => 'EVERPS_OLD_URL',
'lang' => false,
],
[
'type' => 'text',
'label' => $this->l('Migration : New URL'),
'desc' => $this->l('If an old URL and a new one are entered, the module will be able to change the old URL to the new one in the database.'),
'hint' => $this->l('Leave empty for no use'),
'name' => 'EVERPS_NEW_URL',
'lang' => false,
],
[
'type' => 'text',
'label' => $this->l('Number of flags for products'),
'desc' => $this->l('Specify here the number of flags you want to have on products'),
'hint' => $this->l('The default value is 1 and cannot be less than 1'),
'name' => 'EVERPS_FLAG_NB',
],
[
'type' => 'text',
'label' => $this->l('Number of tabs for the product page'),
'desc' => $this->l('Specify here the number of tabs you want to have on the product page'),
'hint' => $this->l('The default value is 1 and cannot be less than 1'),
'name' => 'EVERPS_TAB_NB',
],
[
'type' => 'textarea',
'label' => $this->l('Title for global catalog tab'),
'desc' => $this->l('This text will be your global catalog tab title'),
'hint' => $this->l('Leaving empty will hide tab'),
'name' => 'EVER_TAB_TITLE',
'lang' => true,
'required' => true,
],
[
'type' => 'textarea',
'label' => $this->l('Text shown on global catalog tab'),
'desc' => $this->l('This text will be show on all products'),
'hint' => $this->l('Leaving empty will hide tab'),
'name' => 'EVER_TAB_CONTENT',
'lang' => true,
'required' => true,
'autoload_rte' => true,
],
],
'buttons' => [
'migrateUrls' => [
'name' => 'submitMigrateUrls',
'type' => 'submit',
'class' => 'btn btn-light',
'icon' => 'process-icon-refresh',
'title' => $this->l('Migrate URLS'),
],
'createProducts' => [
'name' => 'submitCreateProduct',
'type' => 'submit',
'class' => 'btn btn-light',
'icon' => 'process-icon-refresh',
'title' => $this->l('Create fake products'),
],
],
'submit' => [
'title' => $this->l('Save'),
],
],
];
$formFields[] = [
'form' => [
'legend' => [
'title' => $this->l('File management'),
'icon' => 'icon-smile',
],
'input' => [
[
'type' => 'file',
'label' => $this->l('Upload Excel tabs file'),
'desc' => $this->l('Will upload Excel tabs file and import datas into this module'),
'hint' => $this->l('You can then import this file in order to set up your tabs in bulk on the product sheets'),
'name' => 'TABS_FILE',
'display_image' => false,
'required' => false,
],
],
'buttons' => [
'import' => [
'name' => 'submitUploadTabsFile',
'type' => 'submit',
'class' => 'btn btn-default pull-right',
'icon' => 'process-icon-download',
'title' => $this->l('Upload file'),
],
],
],
];
if ((bool) Module::isInstalled('prettyblocks') === true
&& (bool) Module::isEnabled('prettyblocks') === true
&& (bool) EverblockTools::moduleDirectoryExists('prettyblocks') === true
) {
$formFields[] = [
'form' => [
'legend' => [
'title' => $this->l('Convert CMS to Pretty Blocks'),
'icon' => 'icon-smile',
],
'buttons' => [
'convertCmsToPrettyBlocks' => [
'name' => 'submitConvertCmsToPrettyBlocks',
'type' => 'submit',
'class' => 'btn btn-default pull-right',
'icon' => 'process-icon-download',
'title' => $this->l('Convert CMS to Prettyblocks'),
],
],
],
];
}
return $formFields;
}
protected function getConfigFormValues()
{
$idShop = (int) Context::getContext()->shop->id;
$custom_css = Tools::file_get_contents(
_PS_MODULE_DIR_ . '/' . $this->name . '/views/css/custom' . $idShop . '.css'
);
$custom_sass = Tools::file_get_contents(
_PS_MODULE_DIR_ . '/' . $this->name . '/views/css/custom' . $idShop . '.scss'
);
$custom_js = Tools::file_get_contents(
_PS_MODULE_DIR_ . '/' . $this->name . '/views/js/custom' . $idShop . '.js'
);
$filePath = _PS_MODULE_DIR_ . $this->name . '/views/js/header-scripts-' . $this->context->shop->id . '.js';
if (file_exists($filePath) && filesize($filePath) > 0) {
$headerScripts = file_get_contents($filePath);
} else {
$headerScripts = '';
}
return [
'EVEROPTIONS_POSITION' => Configuration::get('EVEROPTIONS_POSITION'),
'EVEROPTIONS_TITLE' => $this->getConfigInMultipleLangs('EVEROPTIONS_TITLE'),
'EVERBLOCK_MAINTENANCE_PSSWD' => Configuration::get('EVERBLOCK_MAINTENANCE_PSSWD'),
'EVERGPT_API_KEY' => Configuration::get('EVERGPT_API_KEY'),
'EVERINSTA_ACCESS_TOKEN' => Configuration::get('EVERINSTA_ACCESS_TOKEN'),
'EVERINSTA_LINK' => Configuration::get('EVERINSTA_LINK'),