mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
* cache hooks and template menus
This commit is contained in:
parent
1cbe452f9c
commit
933b25194c
3
TODO
3
TODO
@ -5,9 +5,6 @@
|
|||||||
* sandbox for plugins, don't install when requirements are not passed
|
* sandbox for plugins, don't install when requirements are not passed
|
||||||
* add changelog management interface
|
* add changelog management interface
|
||||||
* kathrine tickets - show/hide
|
* kathrine tickets - show/hide
|
||||||
* cache:
|
|
||||||
* hooks
|
|
||||||
* Menus in templates
|
|
||||||
* csrf token protection
|
* csrf token protection
|
||||||
* guild wars support like in Gesior
|
* guild wars support like in Gesior
|
||||||
* move rest of the pages to Twig: lostaccount, highscores, guilds, etc.
|
* move rest of the pages to Twig: lostaccount, highscores, guilds, etc.
|
||||||
|
@ -73,10 +73,12 @@ class Hooks
|
|||||||
$ret = true;
|
$ret = true;
|
||||||
if(isset(self::$_hooks[$type]))
|
if(isset(self::$_hooks[$type]))
|
||||||
{
|
{
|
||||||
foreach(self::$_hooks[$type] as $name => $hook)
|
foreach(self::$_hooks[$type] as $name => $hook) {
|
||||||
if(!$hook->execute($params)) {
|
/** @var $hook Hook */
|
||||||
|
if (!$hook->execute($params)) {
|
||||||
$ret = false;
|
$ret = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
@ -89,9 +91,26 @@ class Hooks
|
|||||||
public function load()
|
public function load()
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
$hooks = $db->query('SELECT `name`, `type`, `file` FROM `' . TABLE_PREFIX . 'hooks` WHERE `enabled` = 1 ORDER BY `ordering`;');
|
|
||||||
foreach($hooks as $hook)
|
$cache = Cache::getInstance();
|
||||||
|
if ($cache->enabled()) {
|
||||||
|
$tmp = '';
|
||||||
|
if ($cache->fetch('hooks', $tmp)) {
|
||||||
|
$hooks = unserialize($tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($hooks)) {
|
||||||
|
$hooks = $db->query('SELECT `name`, `type`, `file` FROM `' . TABLE_PREFIX . 'hooks` WHERE `enabled` = 1 ORDER BY `ordering`;')->fetchAll();
|
||||||
|
|
||||||
|
if ($cache->enabled()) {
|
||||||
|
$cache->set('hooks', serialize($hooks), 600);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($hooks as $hook) {
|
||||||
$this->register($hook['name'], $hook['type'], $hook['file']);
|
$this->register($hook['name'], $hook['type'], $hook['file']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -262,6 +262,8 @@ class Plugins {
|
|||||||
$cache = Cache::getInstance();
|
$cache = Cache::getInstance();
|
||||||
if($cache->enabled()) {
|
if($cache->enabled()) {
|
||||||
$cache->delete('templates');
|
$cache->delete('templates');
|
||||||
|
$cache->delete('hooks');
|
||||||
|
$cache->delete('template_menus');
|
||||||
}
|
}
|
||||||
|
|
||||||
$zip->close();
|
$zip->close();
|
||||||
|
@ -42,6 +42,11 @@ if (isset($_REQUEST['template'])) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cache = Cache::getInstance();
|
||||||
|
if ($cache->enabled()) {
|
||||||
|
$cache->delete('template_menus');
|
||||||
|
}
|
||||||
|
|
||||||
success('Saved at ' . date('H:i'));
|
success('Saved at ' . date('H:i'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,21 +107,36 @@ if($twig_loader && file_exists(BASE . $template_path))
|
|||||||
$twig_loader->prependPath(BASE . $template_path);
|
$twig_loader->prependPath(BASE . $template_path);
|
||||||
|
|
||||||
function get_template_menus() {
|
function get_template_menus() {
|
||||||
global $db, $config, $template_name;
|
global $db, $template_name;
|
||||||
|
|
||||||
|
$cache = Cache::getInstance();
|
||||||
|
if ($cache->enabled()) {
|
||||||
|
$tmp = '';
|
||||||
|
if ($cache->fetch('template_menus', $tmp)) {
|
||||||
|
$result = unserialize($tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($result)) {
|
||||||
|
$query = $db->query('SELECT `name`, `link`, `blank`, `color`, `category` FROM `' . TABLE_PREFIX . 'menu` WHERE `template` = ' . $db->quote($template_name) . ' ORDER BY `category`, `ordering` ASC');
|
||||||
|
$result = $query->fetchAll();
|
||||||
|
|
||||||
|
if ($cache->enabled()) {
|
||||||
|
$cache->set('template_menus', serialize($result), 600);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$menus = array();
|
$menus = array();
|
||||||
$query = $db->query('SELECT `name`, `link`, `blank`, `color`, `category` FROM `' . TABLE_PREFIX . 'menu` WHERE `template` = ' . $db->quote($template_name) . ' ORDER BY `category`, `ordering` ASC');
|
foreach($result as $menu) {
|
||||||
foreach($query->fetchAll() as $menu) {
|
|
||||||
$link_full = strpos(trim($menu['link']), 'http') === 0 ? $menu['link'] : getLink($menu['link']);
|
$link_full = strpos(trim($menu['link']), 'http') === 0 ? $menu['link'] : getLink($menu['link']);
|
||||||
$menus[$menu['category']][] = array('name' => $menu['name'], 'link' => $menu['link'], 'link_full' => $link_full, 'blank' => $menu['blank'] == 1, 'color' => $menu['color']);
|
$menus[$menu['category']][] = array('name' => $menu['name'], 'link' => $menu['link'], 'link_full' => $link_full, 'blank' => $menu['blank'] == 1, 'color' => $menu['color']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$new_menus = array();
|
$new_menus = array();
|
||||||
foreach($config['menu_categories'] as $id => $options) {
|
foreach(config('menu_categories') as $id => $options) {
|
||||||
if(isset($menus[$id]))
|
if(isset($menus[$id]))
|
||||||
$new_menus[$id] = $menus[$id];
|
$new_menus[$id] = $menus[$id];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $new_menus;
|
return $new_menus;
|
||||||
}
|
}
|
||||||
?>
|
|
Loading…
x
Reference in New Issue
Block a user