New: Now all features can be provided by a module with all files inside

the directory of module.
This commit is contained in:
Laurent Destailleur 2012-02-22 16:18:03 +01:00
parent e4cf111ac2
commit 2647cb72ac
11 changed files with 154 additions and 107 deletions

View File

@ -106,25 +106,32 @@ $barcodelist=array();
clearstatcache(); clearstatcache();
foreach ($conf->file->dol_document_root as $dirroot) // Check if there is external substitution to do asked by plugins
{ $dirbarcode=array_merge(array("/core/modules/barcode/"),$conf->barcode_modules);
$dir = $dirroot . "/core/modules/barcode/";
$handle=@opendir($dir); foreach($dirbarcode as $reldir)
{
$dir=dol_buildpath($reldir,0);
$newdir=dol_osencode($dir);
// Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
if (! is_dir($newdir)) continue;
$handle=@opendir($newdir);
if (is_resource($handle)) if (is_resource($handle))
{ {
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
{ {
if (is_readable($dir.$file)) if (is_readable($newdir.$file))
{ {
if (preg_match('/(.*)\.modules\.php$/i',$file,$reg)) if (preg_match('/(.*)\.modules\.php$/i',$file,$reg))
{ {
$filebis=$reg[1]; $filebis=$reg[1];
// Chargement de la classe de codage // Chargement de la classe de codage
require_once($dir.$file); require_once($newdir.$file);
$classname = "mod".ucfirst($filebis); $classname = "mod".ucfirst($filebis);
$module = new $classname($db); $module = new $classname($db);
@ -190,12 +197,16 @@ if ($resql)
if ($obj->coder && $obj->coder != -1) if ($obj->coder && $obj->coder != -1)
{ {
$result=0; $result=0;
// Chargement de la classe de codage
foreach ($conf->file->dol_document_root as $dirroot) foreach($dirbarcode as $reldir)
{ {
$dir=$dirroot . "/core/modules/barcode/"; $dir=dol_buildpath($reldir,0);
$result=@include_once($dir.$obj->coder.".modules.php"); $newdir=dol_osencode($dir);
//print $dir.$obj->coder.".modules.php - ".$result;
// Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
if (! is_dir($newdir)) continue;
$result=@include_once($newdir.$obj->coder.".modules.php");
if ($result) break; if ($result) break;
} }
if ($result) if ($result)

View File

@ -43,8 +43,8 @@ $dirstandard = array("/core/menus/standard");
$dirsmartphone = array("/core/menus/smartphone"); $dirsmartphone = array("/core/menus/smartphone");
foreach($conf->menus_modules as $dir) foreach($conf->menus_modules as $dir)
{ {
$dirstandard[]=$dir.'/standard'; $dirstandard[]=$dir.'standard';
$dirsmartphone[]=$dir.'/standard'; $dirsmartphone[]=$dir.'standard';
} }

View File

@ -36,8 +36,8 @@ $dirstandard = array("/core/menus/standard");
$dirsmartphone = array("/core/menus/smartphone"); $dirsmartphone = array("/core/menus/smartphone");
foreach($conf->menus_modules as $dir) foreach($conf->menus_modules as $dir)
{ {
$dirstandard[]=$dir.'/standard'; $dirstandard[]=$dir.'standard';
$dirsmartphone[]=$dir.'/standard'; $dirsmartphone[]=$dir.'standard';
} }
$mesg=$_GET["mesg"]; $mesg=$_GET["mesg"];

View File

@ -52,6 +52,7 @@ class Conf
public $smart_menu; public $smart_menu;
public $modules = array(); // List of activated modules public $modules = array(); // List of activated modules
public $css_modules = array(); public $css_modules = array();
public $tabs_modules = array(); public $tabs_modules = array();
public $triggers_modules = array(); public $triggers_modules = array();
@ -59,6 +60,8 @@ class Conf
public $hooks_modules = array(); public $hooks_modules = array();
public $login_method_modules = array(); public $login_method_modules = array();
public $sms_engine_modules = array(); public $sms_engine_modules = array();
public $barcode_modules = array();
public $substitutions_modules = array();
var $logbuffer = array(); var $logbuffer = array();
@ -142,33 +145,16 @@ class Conf
// If this is constant for a css file activated by a module // If this is constant for a css file activated by a module
if (preg_match('/^MAIN_MODULE_([A-Z_]+)_CSS$/i',$key)) if (preg_match('/^MAIN_MODULE_([A-Z_]+)_CSS$/i',$key))
{ {
$this->css_modules[]=$value; $modulename = strtolower($reg[1]);
$this->css_modules[$modulename]=$value;
} }
// If this is constant for a new tab page activated by a module // If this is constant for a new tab page activated by a module.
elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_TABS_/i',$key)) elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_TABS_/i',$key))
{ {
$params=explode(':',$value,2); $params=explode(':',$value,2);
$this->tabs_modules[$params[0]][]=$value; $this->tabs_modules[$params[0]][]=$value;
} }
// If this is constant for a new tab page activated by a module // If this is constant for hook activated by a module. Value is list of hooked tabs separated with ':'
elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_MENUS/i',$key,$reg))
{
$modulename = strtolower($reg[1]);
$this->menus_modules[] = '/'.$modulename.'/core/menus';
}
// If this is constant for triggers activated by a module
elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_TRIGGERS$/i',$key,$reg))
{
$modulename = strtolower($reg[1]);
$this->triggers_modules[] = '/'.$modulename.'/core/triggers/';
}
// If this is constant for login method activated by a module
elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_LOGIN_METHOD$/i',$key,$reg))
{
$modulename = strtolower($reg[1]);
$this->login_method_modules[] = dol_buildpath('/'.$modulename.'/core/login/');
}
// If this is constant for hook activated by a module. Value is list of hooked tabs separated with :
elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_HOOKS$/i',$key,$reg)) elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_HOOKS$/i',$key,$reg))
{ {
$modulename = strtolower($reg[1]); $modulename = strtolower($reg[1]);
@ -184,7 +170,41 @@ class Conf
$module=strtolower($reg[1]); $module=strtolower($reg[1]);
$this->sms_engine_modules[$module]=$module; // Add this module in list of modules that provide SMS $this->sms_engine_modules[$module]=$module; // Add this module in list of modules that provide SMS
} }
// If this is a module constant // If this is constant for triggers activated by a module
elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_BARCODE$/i',$key,$reg))
{
$modulename = strtolower($reg[1]);
$this->barcode_modules[$modulename] = '/'.$modulename.'/core/modules/barcode/';
}
// TODO All of this part could be mutualized into one generic part
// If this is constant for login method activated by a module
elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_LOGIN$/i',$key,$reg))
{
$modulename = strtolower($reg[1]);
$this->login_method_modules[$modulename] = '/'.$modulename.'/core/login/';
}
// If this is constant for a new tab page activated by a module
elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_MENUS$/i',$key,$reg))
{
$modulename = strtolower($reg[1]);
$this->menus_modules[$modulename] = '/'.$modulename.'/core/menus/';
}
// If this is constant for triggers activated by a module
elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_TRIGGERS$/i',$key,$reg))
{
$modulename = strtolower($reg[1]);
$this->triggers_modules[$modulename] = '/'.$modulename.'/core/triggers/';
}
// If this is constant for triggers activated by a module
elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_SUBSTITUTIONS$/i',$key,$reg))
{
$modulename = strtolower($reg[1]);
$this->substitutions_modules[$modulename] = '/'.$modulename.'/core/substitutions/';
}
// If this is a module constant (must be at end)
elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)$/i',$key,$reg)) elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)$/i',$key,$reg))
{ {
$module=strtolower($reg[1]); $module=strtolower($reg[1]);

View File

@ -78,18 +78,18 @@ class Interfaces
foreach($dirtriggers as $reldir) foreach($dirtriggers as $reldir)
{ {
$dir=dol_buildpath($reldir,0); $dir=dol_buildpath($reldir,0);
$dir=dol_osencode($dir); $newdir=dol_osencode($dir);
//print "xx".$dir;exit; //print "xx".$dir;exit;
// Check if directory exists // Check if directory exists (we do not use dol_is_dir to avoir loading files.lib.php at each call)
if (! dol_is_dir($dir)) continue; if (! is_dir($newdir)) continue;
$handle=opendir($dir); $handle=opendir($newdir);
if (is_resource($handle)) if (is_resource($handle))
{ {
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
if (is_readable($dir."/".$file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php$/i',$file,$reg)) if (is_readable($newdir."/".$file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php$/i',$file,$reg))
{ {
$part1=$reg[1]; $part1=$reg[1];
$part2=$reg[2]; $part2=$reg[2];
@ -107,7 +107,7 @@ class Interfaces
} }
else else
{ {
include_once($dir.'/'.$file); include_once($newdir.'/'.$file);
} }
// Check if trigger file is disabled by name // Check if trigger file is disabled by name
@ -207,17 +207,18 @@ class Interfaces
foreach($dirtriggers as $reldir) foreach($dirtriggers as $reldir)
{ {
$dir=dol_buildpath($reldir,0); $dir=dol_buildpath($reldir,0);
$newdir=dol_osencode($dir);
//print "xx".$dir;exit; //print "xx".$dir;exit;
// Check if directory exists // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php at each call)
if (!is_dir($dir)) continue; if (! is_dir($newdir)) continue;
$handle=opendir($dir); $handle=opendir($newdir);
if (is_resource($handle)) if (is_resource($handle))
{ {
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
if (is_readable($dir.'/'.$file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/',$file,$reg)) if (is_readable($newdir.'/'.$file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/',$file,$reg))
{ {
$part1=$reg[1]; $part1=$reg[1];
$part2=$reg[2]; $part2=$reg[2];
@ -232,7 +233,7 @@ class Interfaces
} }
else else
{ {
include_once($dir.'/'.$file); include_once($newdir.'/'.$file);
} }
$files[$i] = $file; $files[$i] = $file;

View File

@ -593,21 +593,21 @@ class Translate
{ {
global $conf; global $conf;
/*
$outlang=$this->defaultlang; // Output language we want
$outlangarray=explode('_',$outlang,2);
// If lang is xx_XX, then we use xx
if (strtolower($outlangarray[0]) == strtolower($outlangarray[1])) $outlang=$outlangarray[0];
*/
$newnumber=$number; $newnumber=$number;
foreach ($conf->file->dol_document_root as $dirroot)
$dirsubstitutions=array_merge(array(),$conf->substitutions_modules);
foreach($dirsubstitutions as $reldir)
{ {
$dir=$dirroot."/core/modules/substitutions"; $dir=dol_buildpath($reldir,0);
$newdir=dol_osencode($dir);
// Check if directory exists
if (! dol_is_dir($dir)) continue;
$fonc='numberwords'; $fonc='numberwords';
if (file_exists($dir.'/functions_'.$fonc.'.lib.php')) if (file_exists($newdir.'/functions_'.$fonc.'.lib.php'))
{ {
include_once($dir.'/functions_'.$fonc.'.lib.php'); include_once($newdir.'/functions_'.$fonc.'.lib.php');
$newnumber=numberwords_getLabelFromNumber($this,$number,$isamount); $newnumber=numberwords_getLabelFromNumber($this,$number,$isamount);
break; break;
} }

View File

@ -3405,6 +3405,7 @@ function dol_textishtml($msg,$option=0)
* @param string $chaine Source string in which we must do substitution * @param string $chaine Source string in which we must do substitution
* @param array $substitutionarray Array with key->val to substitute * @param array $substitutionarray Array with key->val to substitute
* @return string Output string after subsitutions * @return string Output string after subsitutions
* @see make_substitutions
*/ */
function make_substitutions($chaine,$substitutionarray) function make_substitutions($chaine,$substitutionarray)
{ {
@ -3425,6 +3426,7 @@ function make_substitutions($chaine,$substitutionarray)
* @param Translate $outputlangs If we want substitution from special constants, we provide a language * @param Translate $outputlangs If we want substitution from special constants, we provide a language
* @param Object $object If we want substitution from special constants, we provide data in a source object * @param Object $object If we want substitution from special constants, we provide data in a source object
* @return void * @return void
* @see make_substitutions
*/ */
function complete_substitutions_array(&$substitutionarray,$outputlangs,$object='') function complete_substitutions_array(&$substitutionarray,$outputlangs,$object='')
{ {
@ -3433,26 +3435,29 @@ function complete_substitutions_array(&$substitutionarray,$outputlangs,$object='
require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'); require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
// Check if there is external substitution to do asked by plugins // Check if there is external substitution to do asked by plugins
// We look files into the core/modules/substitutions directory $dirsubstitutions=array_merge(array(),$conf->substitutions_modules);
// By default, there is no such external plugins.
foreach ($conf->file->dol_document_root as $dirroot) foreach($dirsubstitutions as $reldir)
{ {
$substitfiles=dol_dir_list($dirroot.'/core/modules/substitutions','files',0,'functions_'); $dir=dol_buildpath($reldir,0);
// Check if directory exists
if (! dol_is_dir($dir)) continue;
$substitfiles=dol_dir_list($dir,'files',0,'functions_');
foreach($substitfiles as $substitfile) foreach($substitfiles as $substitfile)
{ {
if (preg_match('/functions_(.*)\.lib\.php/i',$substitfile['name'],$reg)) if (preg_match('/functions_(.*)\.lib\.php/i',$substitfile['name'],$reg))
{ {
$module=$reg[1]; $module=$reg[1];
if (! empty($conf->$module->enabled)) // If module enabled
{ dol_syslog("Library functions_".$substitfile['name']." found into ".$dir);
dol_syslog("Library functions_".$module.".lib.php found into ".$dirroot); require_once($dir.$substitfile['name']);
require_once($dirroot."/core/modules/substitutions/functions_".$module.".lib.php");
$function_name=$module."_completesubstitutionarray"; $function_name=$module."_completesubstitutionarray";
$function_name($substitutionarray,$outputlangs,$object); $function_name($substitutionarray,$outputlangs,$object);
} }
} }
} }
}
} }
/** /**

View File

@ -63,8 +63,10 @@ function checkLoginPassEntity($usertotest,$passwordtotest,$entitytotest,$authmod
// Validation of login/pass/entity with a third party login module method // Validation of login/pass/entity with a third party login module method
if (! empty($conf->login_method_modules) && is_array($conf->login_method_modules)) if (! empty($conf->login_method_modules) && is_array($conf->login_method_modules))
{ {
foreach($conf->login_method_modules as $dir) foreach($conf->login_method_modules as $reldir)
{ {
$dir=dol_buildpath($reldir,0);
$newdir=dol_osencode($dir); $newdir=dol_osencode($dir);
// Check if directory exists // Check if directory exists

View File

@ -177,7 +177,7 @@ abstract class DolibarrModules
// Remove activation of module's triggers (MAIN_MODULE_MYMODULE_TRIGGERS in llx_const) // Remove activation of module's triggers (MAIN_MODULE_MYMODULE_TRIGGERS in llx_const)
if (! $err) $err+=$this->delete_triggers(); if (! $err) $err+=$this->delete_triggers();
// Remove activation of module's authentification method (MAIN_MODULE_MYMODULE_LOGIN_METHOD in llx_const) // Remove activation of module's authentification method (MAIN_MODULE_MYMODULE_LOGIN in llx_const)
if (! $err) $err+=$this->delete_login_method(); if (! $err) $err+=$this->delete_login_method();
// Remove constants defined by modules // Remove constants defined by modules
@ -1424,7 +1424,7 @@ abstract class DolibarrModules
$sql.= ", entity"; $sql.= ", entity";
$sql.= ")"; $sql.= ")";
$sql.= " VALUES ("; $sql.= " VALUES (";
$sql.= $this->db->encrypt($this->const_name."_LOGIN_METHOD",1); $sql.= $this->db->encrypt($this->const_name."_LOGIN",1);
$sql.= ", 'chaine'"; $sql.= ", 'chaine'";
$sql.= ", ".$this->db->encrypt($this->login_method,1); $sql.= ", ".$this->db->encrypt($this->login_method,1);
$sql.= ", null"; $sql.= ", null";
@ -1455,7 +1455,7 @@ abstract class DolibarrModules
$err=0; $err=0;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name')." LIKE '".$this->const_name."_LOGIN_METHOD'"; $sql.= " WHERE ".$this->db->decrypt('name')." LIKE '".$this->const_name."_LOGIN'";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
dol_syslog(get_class($this)."::delete_login_method sql=".$sql); dol_syslog(get_class($this)."::delete_login_method sql=".$sql);

View File

@ -1173,10 +1173,10 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a
if (! class_exists('MenuTop')) if (! class_exists('MenuTop'))
{ {
$menufound=0; $menufound=0;
$dirmenus=array_merge(array("/core/menus"),$conf->menus_modules); $dirmenus=array_merge(array("/core/menus/"),$conf->menus_modules);
foreach($dirmenus as $dirmenu) foreach($dirmenus as $dirmenu)
{ {
$menufound=dol_include_once($dirmenu."/standard/".$top_menu); $menufound=dol_include_once($dirmenu."standard/".$top_menu);
if ($menufound) break; if ($menufound) break;
} }
if (! $menufound) // If failed to include, we try with standard if (! $menufound) // If failed to include, we try with standard
@ -1382,10 +1382,10 @@ function left_menu($menu_array_before, $helppagename='', $moresearchform='', $me
if (! class_exists('MenuLeft')) if (! class_exists('MenuLeft'))
{ {
$menufound=0; $menufound=0;
$dirmenus=array_merge(array("/core/menus"),$conf->menus_modules); $dirmenus=array_merge(array("/core/menus/"),$conf->menus_modules);
foreach($dirmenus as $dirmenu) foreach($dirmenus as $dirmenu)
{ {
$menufound=dol_include_once($dirmenu."/standard/".$left_menu); $menufound=dol_include_once($dirmenu."standard/".$left_menu);
if ($menufound) break; if ($menufound) break;
} }
if (! $menufound) // If failed to include, we try with standard if (! $menufound) // If failed to include, we try with standard

View File

@ -335,15 +335,23 @@ if ($modulepart == 'barcode')
$encoding=$_GET["encoding"]; $encoding=$_GET["encoding"];
$readable=$_GET["readable"]?$_GET["readable"]:"Y"; $readable=$_GET["readable"]?$_GET["readable"]:"Y";
// Output files with barcode generators $dirbarcode=array_merge(array("/core/modules/barcode/"),$conf->barcode_modules);
foreach ($conf->file->dol_document_root as $dirroot)
$result=0;
foreach($dirbarcode as $reldir)
{ {
$dir=$dirroot . "/core/modules/barcode/"; $dir=dol_buildpath($reldir,0);
$result=@include_once($dir.$generator.".modules.php"); $newdir=dol_osencode($dir);
// Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
if (! is_dir($newdir)) continue;
$result=@include_once($newdir.$generator.".modules.php");
if ($result) break; if ($result) break;
} }
// Chargement de la classe de codage // Load barcode class
$classname = "mod".ucfirst($generator); $classname = "mod".ucfirst($generator);
$module = new $classname($db); $module = new $classname($db);
if ($module->encodingIsSupported($encoding)) if ($module->encodingIsSupported($encoding))