diff --git a/classes/Core.class.php b/classes/Core.class.php index 071b5f3..dd9a8f5 100644 --- a/classes/Core.class.php +++ b/classes/Core.class.php @@ -85,7 +85,7 @@ $this->modules = new Modules($this); $this->template = new Template($this); $this->router = new Router($this); - $this->admin = new CoreAdmin($this); + $this->admin = new CoreAdmin($this, NULL); $this->router->addRoute('/', function() { if(Auth::isLoggedIn()) { diff --git a/classes/CoreAdmin.class.php b/classes/CoreAdmin.class.php index 00c3c6d..f72f8e5 100644 --- a/classes/CoreAdmin.class.php +++ b/classes/CoreAdmin.class.php @@ -21,7 +21,7 @@ Response::redirect('/'); } - $this->template->display('admin'); + $this->getTemplate()->display('admin'); }); $this->getRouter()->addRoute('^/admin(?:/([a-zA-Z0-9\-_]+))(?:/([a-zA-Z0-9\-_]+))?$', function($destination = null, $tab = NULL) { @@ -167,14 +167,27 @@ case 'modules': $upgradeable = []; $list = sprintf('%s%s%s%s%s', dirname(PATH), DS, 'temp', DS, 'update.list'); + $module = NULL; + $modules = $this->getModules(); if(file_exists($list)) { $upgradeable = json_decode(file_get_contents($list)); } + if(isset($_GET['settings'])) { + if($modules->hasModule($_GET['settings'])) { + $module = $modules->getModule($_GET['settings']); + + if(isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST' && method_exists($module->getInstance(), 'onSettings')) { + $module->getInstance()->onSettings($_POST); + } + } + } + + $data['module'] = $module; $data['upgradeable'] = $upgradeable; $data['repositorys'] = Database::fetch('SELECT * FROM `' . DATABASE_PREFIX . 'repositorys`'); - $data['modules'] = $this->getModules(); + $data['modules'] = $modules; break; } diff --git a/classes/Module.class.php b/classes/Module.class.php index 032835c..c8c8ea0 100644 --- a/classes/Module.class.php +++ b/classes/Module.class.php @@ -28,6 +28,49 @@ return $this->path; } + public function getSettings($name, $default = NULL) { + $result = Database::single('SELECT * FROM `' . DATABASE_PREFIX . 'modules_settings` WHERE `module`=:module AND `key`=:key LIMIT 1', [ + 'key' => $name, + 'module' => $this->getDirectory() + ]); + + if(!empty($result)) { + if(!empty($result->value)) { + return $result->value; + } + } + + return $default; + } + + public function setSettings($name, $value = NULL) { + if(Database::exists('SELECT `id` FROM `' . DATABASE_PREFIX . 'modules_settings` WHERE `module`=:module AND `key`=:key LIMIT 1', [ + 'module' => $this->getDirectory(), + 'key' => $name + ])) { + Database::update(DATABASE_PREFIX . 'modules_settings', [ 'module', 'key' ], [ + 'module' => $this->getDirectory(), + 'key' => $name, + 'value' => $value + ]); + } else { + Database::insert(DATABASE_PREFIX . 'modules_settings', [ + 'id' => NULL, + 'module' => $this->getDirectory(), + 'key' => $name, + 'value' => $value + ]); + } + } + + public function hasSettingsPath() { + return file_exists($this->getSettingsPath()); + } + + public function getSettingsPath() { + return sprintf('%s%sadmin.php', $this->path, DS); + } + public function getDirectory() { return basename($this->path); } @@ -55,7 +98,7 @@ foreach(array_diff($new, $old) AS $class) { if(is_subclass_of($class, 'fruithost\\ModuleInterface', true)) { $reflect = new \ReflectionClass($class); - $instance = $reflect->newInstanceArgs([ $core ]); + $instance = $reflect->newInstanceArgs([ $core, $this ]); $this->instance = $instance; } } @@ -66,7 +109,8 @@ 'name' => $this->info->getName(), 'icon' => $this->info->getIcon(), 'order' => $this->info->getOrder(), - 'url' => sprintf('/module/%s', basename($this->path)), + 'target' => $core->getHooks()->applyFilter('TARGET_' . $this->info->getName(), NULL), + 'url' => $core->getHooks()->applyFilter('URL_' . $this->info->getName(), sprintf('/module/%s', basename($this->path))), 'active' => $core->getRouter()->is(sprintf('/module/%s', basename($this->path))) ]; diff --git a/classes/ModuleInterface.class.php b/classes/ModuleInterface.class.php index bf881cf..b73ce5e 100644 --- a/classes/ModuleInterface.class.php +++ b/classes/ModuleInterface.class.php @@ -2,10 +2,12 @@ namespace fruithost; class ModuleInterface { - private $core = null; + private $core = null; + private $instance = null; - public function __construct($core) { - $this->core = $core; + public function __construct($core, $instance) { + $this->core = $core; + $this->instance = $instance; $this->init(); } @@ -34,6 +36,18 @@ return $this->core; } + public function getInstance() { + return $this->instance; + } + + public function setSettings($name, $value = NULL) { + $this->instance->setSettings($name, $value); + } + + public function getSettings($name, $default = NULL) { + return $this->instance->getSettings($name, $default); + } + public function addButton($button) { $this->addFilter('buttons', function($buttons) use($button) { $buttons[] = $button; diff --git a/classes/Session.class.php b/classes/Session.class.php index 4659550..5f63c2f 100644 --- a/classes/Session.class.php +++ b/classes/Session.class.php @@ -12,6 +12,10 @@ ]); } } + + public static function getID() { + return session_id(); + } public static function get($name) { self::init(); diff --git a/classes/Template.class.php b/classes/Template.class.php index 408a83f..c8612cc 100644 --- a/classes/Template.class.php +++ b/classes/Template.class.php @@ -47,6 +47,10 @@ return $this->core; } + public function getAssigns() { + return $this->assigns; + } + public function getFiles() { return $this->files; } @@ -55,14 +59,19 @@ $this->assigns[$name] = $value; } - public function display($file, $arguments = []) { + public function display($file, $arguments = [], $basedir = true) { $template = $this; foreach($arguments AS $name => $value) { $this->assigns[$name] = $value; } - $path = sprintf('%1$s%2$sthemes%2$s%4$s%2$s%3$s.php', dirname(PATH), DS, $file, $this->theme); + if($basedir) { + $path = sprintf('%1$s%2$sthemes%2$s%4$s%2$s%3$s.php', dirname(PATH), DS, $file, $this->theme); + } else { + $path = $file; + } + $handler = sprintf('%1$s%2$shandler%2$s%3$s.php', PATH, DS, $file); foreach($this->assigns AS $name => $value) { diff --git a/default/admin/modules.php b/default/admin/modules.php index 607d0f8..ce18029 100644 --- a/default/admin/modules.php +++ b/default/admin/modules.php @@ -13,6 +13,61 @@ $template->footer(); exit(); } + + if(isset($_GET['settings'])) { + ?> +
+