Files
DomFramework/module.php

79 lines
2.5 KiB
PHP

<?php
/** DomFramework
@package domframework
@author Dominique Fournier <dominique@fournier38.fr> */
/** 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 array $confModules 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);
}
}