diff --git a/classes/Core.class.php b/classes/Core.class.php index 59e6e6d..e8ba97d 100644 --- a/classes/Core.class.php +++ b/classes/Core.class.php @@ -88,6 +88,10 @@ require_once($path); } + public function getAdminCore() { + return $this->admin; + } + public function getModules() : Modules { return $this->modules; } @@ -158,6 +162,8 @@ $this->router = new Router($this); $this->admin = new CoreAdmin($this, NULL); + $this->getHooks()->runAction('core_pre_init'); + $this->router->addRoute('/', function() { if(Auth::isLoggedIn()) { Response::redirect('/overview'); @@ -310,10 +316,14 @@ exit(); } + $this->getHooks()->runAction('ajax'); + $this->router->run(true); + // Fire modals if(isset($_POST['modal']) && !empty($_POST['modal'])) { $modals = $this->getHooks()->applyFilter('modals', []); - + // @ToDo Modals context on handler not working? + foreach($modals AS $modal) { if($modal->getName() === $_POST['modal']) { $callback = $modal->getCallback('save'); @@ -331,6 +341,8 @@ } } + + $result = call_user_func_array($callback, [ $data ]); if(is_bool($result)) { @@ -344,6 +356,7 @@ } }); + $this->getHooks()->runAction('core_init'); $this->router->run(); } } diff --git a/classes/CoreAdmin.class.php b/classes/CoreAdmin.class.php index a626a27..4dbe751 100644 --- a/classes/CoreAdmin.class.php +++ b/classes/CoreAdmin.class.php @@ -6,20 +6,10 @@ use fruithost\Database; use fruithost\Response; use fruithost\ModuleInterface; - use fruithost\Modal; - use fruithost\Button; class CoreAdmin extends ModuleInterface { public function init() { - $this->addModal((new Modal('add_repository', I18N::get('Add Repository'), 'admin/modules/repository/create'))->addButton([ - (new Button())->setName('cancel')->setLabel(I18N::get('Cancel'))->addClass('btn-outline-danger')->setDismissable(), - (new Button())->setName('create')->setLabel(I18N::get('Create'))->addClass('btn-outline-success') - ])->onSave([ $this, 'onCreateRepository' ])); - - $this->addModal((new Modal('confirmation', I18N::get('Confirmation'), NULL))->addButton([ - (new Button())->setName('cancel')->setLabel(I18N::get('No'))->addClass('btn-outline-danger')->setDismissable(), - (new Button())->setName('create')->setLabel(I18N::get('Yes'))->addClass('btn-outline-success') - ])->onSave([ $this, 'onConfirmation' ])); + $this->getCore()->getHooks()->runAction('core_admin_pre_init'); $this->getRouter()->addRoute('/admin', function() { if(!Auth::isLoggedIn()) { @@ -50,32 +40,5 @@ ]); }); } - - public function onConfirmation(array $data = []) : string { - // @ToDo Check permissions? - return 'CONFIRMED'; - } - - public function onCreateRepository(array $data = []) : string | bool { - if(empty($data['repository_url']) || !filter_var($data['repository_url'], FILTER_VALIDATE_URL)) { - return I18N::get('Please enter an valid repository URL!'); - } - - $repositorys = Database::fetch('SELECT * FROM `' . DATABASE_PREFIX . 'repositorys` WHERE `url`=:url', [ - 'url' => $data['repository_url'] - ]); - - if(count($repositorys) > 0) { - return I18N::get('Repository already exists!'); - } else { - Database::insert(DATABASE_PREFIX . 'repositorys', [ - 'id' => null, - 'url' => $data['repository_url'], - 'time_updated' => NULL - ]); - } - - return true; - } } ?> \ No newline at end of file diff --git a/classes/Router.class.php b/classes/Router.class.php index f4d73c7..996decb 100644 --- a/classes/Router.class.php +++ b/classes/Router.class.php @@ -64,8 +64,9 @@ $this->redirect = $redirect; } - public function run() { - $uri = explode('/', $_SERVER['REQUEST_URI']); + public function run($ajax = false) { + // @ToDo is secure? + $uri = explode('/', ($ajax ? preg_replace('#(http|https)://([^/]+)#', '', $_SERVER['HTTP_REFERER']) : $_SERVER['REQUEST_URI'])); $name = explode('/', $_SERVER['SCRIPT_NAME']); for($i = 0; $i < sizeof($name); $i++) { diff --git a/classes/Template.class.php b/classes/Template.class.php index 86e676f..4820771 100644 --- a/classes/Template.class.php +++ b/classes/Template.class.php @@ -1,6 +1,7 @@ core; } + public function getAdminCore() { + return $this->core->getAdminCore(); + } + public function getAssigns() { return $this->assigns; } @@ -95,6 +100,10 @@ } } + if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { + exit(); + } + if(file_exists($path) && is_readable($path)) { require_once($path); } else { @@ -153,12 +162,14 @@ } public function getLanguage($short = false) { - // @ToDo + $language = $this->getCore()->getSettings('LANGUAGE', 'en_US'); + $language = Auth::getSettings('LANGUAGE', NULL, $language); + if($short) { - return 'en'; + return explode('_', $language)[0]; } - return 'en_US'; + return $language; } public function head() { diff --git a/classes/User.class.php b/classes/User.class.php index aa0467a..bca8f01 100644 --- a/classes/User.class.php +++ b/classes/User.class.php @@ -44,7 +44,43 @@ return $this->id; } + public function getFirstName() : string | null { + if($this->data == false) { + return null; + } + + return $this->data->name_first; + } + + public function getLastName() : string | null { + if($this->data == false) { + return null; + } + + return $this->data->name_last; + } + + public function getPhoneNumber() : string | null { + if($this->data == false) { + return null; + } + + return $this->data->phone_number; + } + + public function getAddress() : string | null { + if($this->data == false) { + return null; + } + + return $this->data->address; + } + public function getFullName() : string | null { + if($this->data == false) { + return ''; + } + if(empty($this->data->name_first)) { return ''; } diff --git a/default/admin/users.php b/default/admin/users.php index dfa16eb..7d55022 100644 --- a/default/admin/users.php +++ b/default/admin/users.php @@ -55,7 +55,7 @@ -
+ @@ -63,7 +63,9 @@