From d97313617747cedadc9c454e4a0e6101732ab232 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Thu, 26 Mar 2015 10:35:06 +0000 Subject: [PATCH] module.php : first commit ! git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2064 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- module.php | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 module.php diff --git a/module.php b/module.php new file mode 100644 index 0000000..9c7d3c8 --- /dev/null +++ b/module.php @@ -0,0 +1,78 @@ + */ + +/** Module management */ +class module +{ + /** The modules are not allowed if $toplevel=0 + The modules can be in a module directory if $toplevel=1 + The modules can be in the parent directory if $toplevel=2 + The modules can be in the local directory if $toplevel=4 + The values can be added to allow multiple possibilities */ + public $toplevel = 0; + + /** List all the available (enable or disable) modules + @return array The list of the available modules names with the path */ + public function listAvailable () + { + $list = array (); + $tmp = array (); + if ($this->toplevel%2 >= 1 ) + $tmp = array_merge ($tmp, glob ("modules/*")); + if ($this->toplevel%4 >= 2 ) + $tmp = array_merge ($tmp, glob ("../*")); + if ($this->toplevel%8 >= 4 ) + $tmp = array_merge ($tmp, glob ("*")); + foreach ($tmp as $path) + { + $name = basename ($path); + if (! is_dir ($path)) continue; + if ($name === ".") continue; + if ($name === "..") continue; + if ($name === "cli") continue; + if ($name === "controllers") continue; + if ($name === "data") continue; + if ($name === "datas") continue; + if ($name === "locale") continue; + if ($name === "models") continue; + if ($name === "modules") continue; + if ($name === "public") continue; + if ($name === "views") continue; + $list[$name] = $path; + } + ksort ($list); + return $list; + } + + /** List all the enable modules coming from the configuration and available + in the system + @param $confModules array the list of the available modules coming from + the configuration. Can have some non available modules. + @return array the list of the available modules names with the path */ + public function listEnable ($confModules) + { + $listAvailable = $this->listAvailable (); + $list = array (); + foreach ($confModules as $module) + { + if (array_key_exists ($module, $listAvailable)) + $list[$module] = $listAvailable[$module]; + } + ksort ($list); + return $list; + } + + /** Return the name of the module translated in the provided language + The module name must be defined in the translation under the "modulename" + item + */ + public function translateName ($modulepath, $lang) + { + // TODO : Do really the function ! With the language selection, and + // searching in the directories + return basename ($modulepath); + } +} +