diff --git a/classes/Database.class.php b/classes/Database.class.php index 3d221df..169a65d 100644 --- a/classes/Database.class.php +++ b/classes/Database.class.php @@ -42,6 +42,10 @@ return DatabaseFactory::getInstance()->delete($table, $parameters); } + public static function tableExists(string $table) : bool { + return DatabaseFactory::getInstance()->tableExists($table); + } + public static function deleteWhereNot(string $table, array $delete_not = [], array $parameters = []) { return DatabaseFactory::getInstance()->deleteWhereNot($table, $delete_not, $parameters); } diff --git a/classes/DatabaseFactory.class.php b/classes/DatabaseFactory.class.php index fab97e2..f89b4f7 100644 --- a/classes/DatabaseFactory.class.php +++ b/classes/DatabaseFactory.class.php @@ -24,6 +24,16 @@ return $object->errorInfo(); } + public function tableExists(string $table) : bool { + $row = $this->single('SELECT count(*) AS `result` FROM information_schema.TABLES WHERE (TABLE_SCHEMA=\'' . DATABASE_NAME . '\') AND (TABLE_NAME=\'' . $table . '\')'); + + if(isset($result) && $result !== null) { + return $result->result == 1; + } + + return false; + } + public function file(string $file, callable $callback) { if(!file_exists($file)) { call_user_func_array($callback, [ 'Can\'t found file: ' . $file ]); diff --git a/classes/Module.class.php b/classes/Module.class.php index ed12379..a759181 100644 --- a/classes/Module.class.php +++ b/classes/Module.class.php @@ -6,6 +6,7 @@ private $info = null; private $instance = null; private $enabled = false; + private $locked = false; public function __construct($path) { $this->path = $path; @@ -75,6 +76,14 @@ return basename($this->path); } + public function isFrame() : bool { + if($this->getInstance() == null) { + return false; + } + + return method_exists($this->getInstance(), 'frame') && !empty($this->getInstance()->frame()); + } + public function isEnabled() : bool { return $this->enabled; } @@ -83,11 +92,19 @@ $this->enabled = $state; } - public function init(Core $core) : Module { + public function isLocked() : bool { + return $this->locked; + } + + public function setLocked(bool $state) { + $this->locked = $state; + } + + public function init(Core $core) : Module | null { $script = sprintf('%s%smodule.php', $this->path, DS); if(!file_exists($script)) { - return; + return null; } $old = get_declared_classes(); @@ -102,7 +119,7 @@ } } - if(!empty($this->info->getCategory())) { + if(!empty($this->info->getCategory()) && !$this->isLocked()) { $core->getHooks()->addFilter($this->info->getCategory(), function($entries) use ($core) { $entries[] = (object) [ 'name' => $this->info->getName(), diff --git a/classes/ModuleInfo.class.php b/classes/ModuleInfo.class.php index 5a4fc31..785fae6 100644 --- a/classes/ModuleInfo.class.php +++ b/classes/ModuleInfo.class.php @@ -10,6 +10,7 @@ private $description = null; private $author = null; private $repository = null; + private $depencies = null; private $is_valid = false; public function __construct(string $path) { @@ -70,6 +71,10 @@ $this->repository = $data->repository; } + if(!empty($data->depencies)) { + $this->depencies = $data->depencies; + } + $this->is_valid = true; } @@ -114,5 +119,9 @@ public function getRepository() : string { return $this->repository; } + + public function getDepencies() : object { + return $this->depencies; + } } ?> \ No newline at end of file diff --git a/classes/Modules.class.php b/classes/Modules.class.php index d50ba06..dfece7d 100644 --- a/classes/Modules.class.php +++ b/classes/Modules.class.php @@ -20,6 +20,13 @@ $path = sprintf('%s%s%s', $this->getPath(), DS, $info->getFilename()); $module = new Module($path); + + foreach($module->getInfo()->getDepencies() AS $name => $version) { + if(!in_array($name, $enabled)) { + $module->setLocked(true); + } + } + $module->setEnabled(in_array(basename($path), $enabled)); $this->addModule(basename($path), $module); } diff --git a/classes/Template.class.php b/classes/Template.class.php index 7858d95..f98f055 100644 --- a/classes/Template.class.php +++ b/classes/Template.class.php @@ -97,7 +97,11 @@ } if(file_exists($handler)) { - require_once($handler); + try { + require_once($handler); + } catch(\Exception $e) { + var_dump($e); + } foreach($this->assigns AS $name => $value) { ${$name} = $value; diff --git a/default/admin/modules/list.php b/default/admin/modules/list.php index 02c9958..c9f971b 100644 --- a/default/admin/modules/list.php +++ b/default/admin/modules/list.php @@ -21,7 +21,7 @@