diff --git a/classes/AuthFactory.class.php b/classes/AuthFactory.class.php index 6727556..b823d55 100644 --- a/classes/AuthFactory.class.php +++ b/classes/AuthFactory.class.php @@ -42,9 +42,11 @@ return $default; } - public function logout() { + public static function logout() : bool { Session::remove('user_id'); Session::remove('user_name'); + + return true; } public function login(string $username, string $password) : bool { diff --git a/classes/Hooks.class.php b/classes/Hooks.class.php index e5863a8..c1dca3d 100644 --- a/classes/Hooks.class.php +++ b/classes/Hooks.class.php @@ -1,6 +1,8 @@ filters['all']) AS $entry) { - if(!empty($entry['method'])) { + if(!empty($entry['method']) && (isset($entry['logged_in']) && ($entry['logged_in'] == true && Auth::isLoggedIn() || $entry['logged_in'] == false))) { call_user_func_array($entry['method'], $args); } } @@ -42,9 +44,10 @@ } /* Filter */ - public function addFilter($name, $method, $priority = 50) { + public function addFilter($name, $method, $priority = 50, $logged_in = true) { $this->filters[$name][$priority][$this->createID($method)] = [ - 'method' => $method + 'method' => $method, + 'logged_in' => $logged_in ]; unset($this->merged_filters[$name]); @@ -126,7 +129,7 @@ do { foreach(current($this->filters[$name]) AS $entry) { - if(!empty($entry['method'])) { + if(!empty($entry['method']) && (isset($entry['logged_in']) && ($entry['logged_in'] == true && Auth::isLoggedIn() || $entry['logged_in'] == false))) { $args[0] = $value; $value = call_user_func_array($entry['method'], $args); } @@ -139,8 +142,8 @@ } /* Actions */ - public function addAction($name, $method, $priority = 50) { - return $this->addFilter($name, $method, $priority); + public function addAction($name, $method, $priority = 50, $logged_in = true) { + return $this->addFilter($name, $method, $priority, $logged_in); } public function removeAction($name, $method, $priority = 50) { @@ -202,7 +205,7 @@ do { foreach(current($this->filters[$name]) AS $entry) { - if(!empty($entry['method'])) { + if(!empty($entry['method']) && (isset($entry['logged_in']) && ($entry['logged_in'] == true && Auth::isLoggedIn() || $entry['logged_in'] == false))) { call_user_func_array($entry['method'], $args); } } diff --git a/classes/ModuleInterface.class.php b/classes/ModuleInterface.class.php index b73ce5e..ec0a112 100644 --- a/classes/ModuleInterface.class.php +++ b/classes/ModuleInterface.class.php @@ -48,18 +48,18 @@ return $this->instance->getSettings($name, $default); } - public function addButton($button) { + public function addButton($button, $logged_in = false) { $this->addFilter('buttons', function($buttons) use($button) { $buttons[] = $button; return $buttons; - }); + }, 10, $logged_in); } - public function addModal($modal) { + public function addModal($modal, $logged_in = false) { $this->addFilter('modals', function($modals) use($modal) { $modals[] = $modal; return $modals; - }); + }, 10, $logged_in); } public function assign($name, $value) { @@ -71,7 +71,7 @@ } /* Filter */ - public function addFilter($name, $method, $priority = 10) { + public function addFilter($name, $method, $priority = 10, $logged_in = false) { return $this->core->getHooks()->addFilter($name, $method, $priority); } diff --git a/classes/Template.class.php b/classes/Template.class.php index 20421e0..dd471ca 100644 --- a/classes/Template.class.php +++ b/classes/Template.class.php @@ -17,12 +17,12 @@ ob_start('ob_gzhandler'); - $this->core->getHooks()->addAction('html_head', [ $this, 'head_robots' ]); - $this->core->getHooks()->addAction('html_head', [ $this, 'head_scripts' ]); - $this->core->getHooks()->addAction('html_head', [ $this, 'theme_color' ]); - $this->core->getHooks()->addAction('html_head', [ $this, 'favicon' ]); - $this->core->getHooks()->addAction('html_foot', [ $this, 'foot_modals' ]); - $this->core->getHooks()->addAction('html_foot', [ $this, 'foot_scripts' ]); + $this->core->getHooks()->addAction('html_head', [ $this, 'head_robots' ], 10, false); + $this->core->getHooks()->addAction('html_head', [ $this, 'head_scripts' ], 10, false); + $this->core->getHooks()->addAction('html_head', [ $this, 'theme_color' ], 10, false); + $this->core->getHooks()->addAction('html_head', [ $this, 'favicon' ], 10, false); + $this->core->getHooks()->addAction('html_foot', [ $this, 'foot_modals' ], 10, false); + $this->core->getHooks()->addAction('html_foot', [ $this, 'foot_scripts' ], 10, false); $this->files->addStylesheet('bootstrap', $this->url('css/bootstrap/bootstrap.min.css'), '4.3.1'); $this->files->addStylesheet('jquery-ui', $this->url('css/jquery-ui/jquery-ui.css'), '1.12.1'); diff --git a/classes/TemplateDefaults.class.php b/classes/TemplateDefaults.class.php index c8651e8..2c8ad5a 100644 --- a/classes/TemplateDefaults.class.php +++ b/classes/TemplateDefaults.class.php @@ -3,7 +3,7 @@ class TemplateDefaults { public function head_robots() { - printf('', $this->getCore()->getHooks()->applyFilter('meta_robots', 'noindex,follow')); + printf('', $this->getCore()->getHooks()->applyFilter('meta_robots', 'noindex,follow', 10, false)); } public function favicon() { @@ -19,7 +19,7 @@ } public function theme_color() { - printf('', $this->getCore()->getHooks()->applyFilter('theme_color', '#007BFF')); + printf('', $this->getCore()->getHooks()->applyFilter('theme_color', '#007BFF', 10, false)); } public function head_scripts() { @@ -73,7 +73,7 @@ } public function foot_modals() { - $modals = $this->getCore()->getHooks()->applyFilter('modals', []); + $modals = $this->getCore()->getHooks()->applyFilter('modals', [], 10, false); $template = $this; foreach($modals AS $modal) {