Skip to content

Commit 3da3e62

Browse files
committed
Option to reset menus
1 parent d5dd729 commit 3da3e62

File tree

3 files changed

+58
-18
lines changed

3 files changed

+58
-18
lines changed

admin/pages/menus.php

+54-18
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@
5959
}
6060
}
6161

62-
$cache = Cache::getInstance();
63-
if ($cache->enabled()) {
64-
$cache->delete('template_menus');
65-
}
66-
62+
onTemplateMenusChange();
6763
success('Saved at ' . date('H:i'));
6864
}
6965

@@ -93,30 +89,62 @@
9389
Menu::where('template', $template)->where('category', $id)->update(['color' => str_replace('#', '', $color)]);
9490
}
9591

96-
$cache = Cache::getInstance();
97-
if ($cache->enabled()) {
98-
$cache->delete('template_menus');
99-
}
92+
onTemplateMenusChange();
93+
success('Colors has been reset at ' . date('H:i'));
94+
}
10095

101-
success('Colors has been reset.');
96+
if (isset($_GET['reset_menus'])) {
97+
$configMenus = config('menus');
98+
if (isset($configMenus)) {
99+
Plugins::installMenus($template, config('menus'), true);
100+
101+
onTemplateMenusChange();
102+
success('Menus has been reset at ' . date('H:i'));
103+
}
104+
else {
105+
error("This template don't support reinstalling menus.");
106+
}
102107
}
103108

104109
$title = 'Menus - ' . $template;
110+
111+
$canChangeColor = isset($config['menu_default_color']);
112+
foreach ($config['menu_categories'] as $id => $options) {
113+
if (isset($options['default_links_color'])) {
114+
$canChangeColor = true;
115+
}
116+
}
105117
?>
106118
<div align="center" class="text-center">
107119
<p class="note">You are editing: <?= $template ?><br/><br/>
108120
Hint: You can drag menu items.<br/>
109121
Hint: Add links to external sites using: <b>http://</b> or <b>https://</b> prefix.<br/>
110122
Not all templates support blank and colorful links.
111123
</p>
112-
<?php if (isset($config['menu_default_color'])) {?>
113-
<form method="post" action="?p=menus&reset_colors" onsubmit="return confirm('Do you really want to reset colors?');">
114-
<?php csrf(); ?>
115-
<input type="hidden" name="template" value="<?php echo $template ?>"/>
116-
<button type="submit" class="btn btn-danger">Reset Colors to default</button>
117-
</form>
118-
<br/>
119-
<?php } ?>
124+
<div class="row text-center">
125+
<div class="col-md-2 col-sm-1"></div>
126+
<div class="col-md-8 col-sm-10">
127+
<div class="row justify-content-center">
128+
<?php if (isset($config['menus'])) {?>
129+
<form method="post" action="?p=menus&reset_menus" onsubmit="return confirm('Do you really want to reset menus?');">
130+
<?php csrf(); ?>
131+
<input type="hidden" name="template" value="<?php echo $template ?>"/>
132+
<button type="submit" class="btn btn-danger">Reset Menus to default</button>
133+
</form>
134+
<br/>
135+
<?php } ?>
136+
<?php if ($canChangeColor) {?>
137+
<form method="post" action="?p=menus&reset_colors" onsubmit="return confirm('Do you really want to reset colors?');">
138+
<?php csrf(); ?>
139+
<input type="hidden" name="template" value="<?php echo $template ?>"/>
140+
<button type="submit" class="btn btn-warning" style="margin-left: 20px">Reset Colors to default</button>
141+
</form>
142+
<br/>
143+
<?php } ?>
144+
</div>
145+
</div>
146+
<div class="col-md-2 col-sm-1"></div>
147+
</div>
120148
</div>
121149
<?php
122150
$menus = Menu::query()
@@ -198,3 +226,11 @@
198226
'templates' => $templates
199227
));
200228
}
229+
230+
function onTemplateMenusChange(): void
231+
{
232+
$cache = Cache::getInstance();
233+
if ($cache->enabled()) {
234+
$cache->delete('template_menus');
235+
}
236+
}

templates/kathrine/config.php

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
MENU_CATEGORY_LIBRARY => array('id' => 'library', 'name' => 'Library'),
99
MENU_CATEGORY_SHOP => array('id' => 'shops', 'name' => 'Shop')
1010
);
11+
12+
$config['menus'] = require __DIR__ . '/menus.php';

templates/tibiacom/config.php

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
MENU_CATEGORY_LIBRARY => array('id' => 'library', 'name' => 'Library'),
1010
MENU_CATEGORY_SHOP => array('id' => 'shops', 'name' => 'Shop')
1111
);
12+
13+
$config['menus'] = require __DIR__ . '/menus.php';

0 commit comments

Comments
 (0)