Repository navigation
Expand file tree
/
Copy pathBootstrap.php
More file actions
104 lines (98 loc) · 4.26 KB
/
Copy pathBootstrap.php
File metadata and controls
104 lines (98 loc) · 4.26 KB
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
<?php declare(strict_types=1);
namespace Plugin\jtl_theme_editor;
use JTL\Events\Dispatcher;
use JTL\Plugin\Bootstrapper;
use JTL\Shop;
/**
* Class Bootstrap
* @package Plugin\jtl_theme_editor
*/
class Bootstrap extends Bootstrapper
{
/**
* @inheritdoc
*/
public function boot(Dispatcher $dispatcher): void
{
parent::boot($dispatcher);
$config = Shop::getSettings([\CONF_TEMPLATE])['template'];
$config['activated'] = ($config['demo']['demo_mode'] ?? 'N') === 'Y';
$config['curtheme'] = $config['theme']['theme_default'] ?? null;
if ($config['activated'] !== true || !Shop::isAdmin()) {
return;
}
$dispatcher->listen('shop.hook.' . \HOOK_INDEX_NAVI_HEAD_POSTGET, function () {
if (!isset($_POST['tpl_config_save_export'])) {
return;
}
$adminHelper = new Helper($this->getPlugin());
$result = $adminHelper->handlePost($_POST);
\header('Content-Type: application/json');
die(\json_encode($result));
});
if ($config['curtheme'] !== null) {
$dispatcher->listen('shop.hook.' . \HOOK_SMARTY_OUTPUTFILTER, function () use ($config) {
$this->addHtml($config);
});
}
$dispatcher->listen('shop.hook.' . \HOOK_LETZTERINCLUDE_CSS_JS, static function (array $args) {
if (!isset($args['cCSS_arr'])) {
return;
}
// in evo the copmiled css file is always called "bootstrap.css" - remove it
foreach ($args['cCSS_arr'] as $_idx => $_file) {
if (\strpos($_file, 'bootstrap.css') !== false) {
unset($args['cCSS_arr'][$_idx]);
break;
}
}
Shop::Smarty()->assign('tpl_editor_active', true);
});
}
/**
* @param array $config
* @throws \SmartyException
*/
private function addHtml(array $config): void
{
$plugin = $this->getPlugin();
$smarty = Shop::Smarty();
$helper = new Helper($plugin);
$tplDir = $smarty->getTemplateVars('currentTemplateDir');
$lessFile = $tplDir . 'themes/' . $config['curtheme'] . '/less/theme.less';
if ($smarty::$isChildTemplate === true && !\file_exists(PFAD_ROOT . $lessFile)) {
$parentTemplateDir = $smarty->getTemplateVars('parentTemplateDir');
if ($parentTemplateDir !== null) {
$lessFile = $parentTemplateDir . 'themes/' . $config['curtheme'] . '/less/theme.less';
$tplDir = $parentTemplateDir;
}
}
if (!\file_exists($lessFile)) {
return;
}
$html = $smarty->assign('less_vars', $helper->getOptions($config['curtheme'], $tplDir))
->assign('shop_url', Shop::getURL())
->assign('is_admin', true)
->assign('template_dir', PFAD_ROOT . $tplDir)
->assign('theme', $config['curtheme'])
->assign('tpl_config_lang_vars', $plugin->getLocalization()->getTranslations())
->fetch($plugin->getPaths()->getFrontendPath() . 'template/tpl_configurator_frontend.tpl');
\pq('body')->append('<link type="text/css" rel="stylesheet" href="' .
$plugin->getPaths()->getFrontendURL() . 'css/tpl_configurator.css" />' . "\n" .
'<link type="text/css" rel="stylesheet" href="' .
$plugin->getPaths()->getFrontendURL() . 'css/bootstrap-colorpicker.min.css" />' . "\n" .
'<link rel="stylesheet/less" type="text/css" href="' . Shop::getURL() . '/' . $lessFile . '" />' . "\n" .
'<script type="text/javascript">
var less = {
env: "development",
async: true,
fileAsync: true,
dumpLineNumbers: "comments",
relativeUrls: true
};
jtl.load("' . $plugin->getPaths()->getFrontendURL() . 'js/bootstrap-colorpicker.min.js", "' .
$plugin->getPaths()->getFrontendURL() . 'js/tpl_configurator.js", "' .
$plugin->getPaths()->getFrontendURL() . 'js/less.min.js");
</script>' . $html);
}
}