diff --git a/TODO b/TODO index fb9000db..e39aee92 100644 --- a/TODO +++ b/TODO @@ -5,9 +5,6 @@ * sandbox for plugins, don't install when requirements are not passed * add changelog management interface * kathrine tickets - show/hide - * cache: - * hooks - * Menus in templates * csrf token protection * guild wars support like in Gesior * move rest of the pages to Twig: lostaccount, highscores, guilds, etc. diff --git a/system/hooks.php b/system/hooks.php index f4b36205..18610967 100644 --- a/system/hooks.php +++ b/system/hooks.php @@ -73,10 +73,12 @@ class Hooks $ret = true; if(isset(self::$_hooks[$type])) { - foreach(self::$_hooks[$type] as $name => $hook) - if(!$hook->execute($params)) { + foreach(self::$_hooks[$type] as $name => $hook) { + /** @var $hook Hook */ + if (!$hook->execute($params)) { $ret = false; } + } } return $ret; @@ -89,9 +91,26 @@ class Hooks public function load() { 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']); + } } } ?> diff --git a/system/libs/plugins.php b/system/libs/plugins.php index 84f83455..ea862d3b 100644 --- a/system/libs/plugins.php +++ b/system/libs/plugins.php @@ -262,6 +262,8 @@ class Plugins { $cache = Cache::getInstance(); if($cache->enabled()) { $cache->delete('templates'); + $cache->delete('hooks'); + $cache->delete('template_menus'); } $zip->close(); diff --git a/system/pages/admin/menus.php b/system/pages/admin/menus.php index 55a0a4f5..07c50c8f 100644 --- a/system/pages/admin/menus.php +++ b/system/pages/admin/menus.php @@ -42,6 +42,11 @@ if (isset($_REQUEST['template'])) { } } + $cache = Cache::getInstance(); + if ($cache->enabled()) { + $cache->delete('template_menus'); + } + success('Saved at ' . date('H:i')); } diff --git a/system/template.php b/system/template.php index 8be77608..7d136d3b 100644 --- a/system/template.php +++ b/system/template.php @@ -107,21 +107,36 @@ if($twig_loader && file_exists(BASE . $template_path)) $twig_loader->prependPath(BASE . $template_path); 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(); - $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($query->fetchAll() as $menu) { + foreach($result as $menu) { $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']); } - + $new_menus = array(); - foreach($config['menu_categories'] as $id => $options) { + foreach(config('menu_categories') as $id => $options) { if(isset($menus[$id])) $new_menus[$id] = $menus[$id]; } - + return $new_menus; -} -?> +} \ No newline at end of file