2
0
forked from Wavyzz/dolibarr

New: add external theme with a module

This commit is contained in:
Regis Houssin
2012-04-30 16:51:45 +02:00
parent 8898b9a3b0
commit 18c081a7ac
3 changed files with 57 additions and 43 deletions

View File

@@ -77,6 +77,7 @@ class modMyModule extends DolibarrModules
// 'login' => 0, // Set this to 1 if module has its own login method directory (core/login) // 'login' => 0, // Set this to 1 if module has its own login method directory (core/login)
// 'substitutions' => 0, // Set this to 1 if module has its own substitution function file (core/substitutions) // 'substitutions' => 0, // Set this to 1 if module has its own substitution function file (core/substitutions)
// 'menus' => 0, // Set this to 1 if module has its own menus handler directory (core/menus) // 'menus' => 0, // Set this to 1 if module has its own menus handler directory (core/menus)
// 'theme' => 0, // Set this to 1 if module has its own theme directory (core/theme)
// 'tpl' => 0, // Set this to 1 if module overwrite template dir (core/tpl) // 'tpl' => 0, // Set this to 1 if module overwrite template dir (core/tpl)
// 'barcode' => 0, // Set this to 1 if module has its own barcode directory (core/modules/barcode) // 'barcode' => 0, // Set this to 1 if module has its own barcode directory (core/modules/barcode)
// 'models' => 0, // Set this to 1 if module has its own models directory (core/modules/xxx) // 'models' => 0, // Set this to 1 if module has its own models directory (core/modules/xxx)

View File

@@ -52,7 +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 $modules_parts = array('triggers'=>array(),'login'=>array(),'substitutions'=>array(),'menus'=>array(),'tpl'=>array(),'barcode'=>array(),'models'=>array()); // List of modules parts public $modules_parts = array('triggers'=>array(),'login'=>array(),'substitutions'=>array(),'menus'=>array(),'theme'=>array(),'tpl'=>array(),'barcode'=>array(),'models'=>array()); // List of modules parts
// TODO Remove all thoose tabs with one generic // TODO Remove all thoose tabs with one generic
public $triggers_modules = array(); public $triggers_modules = array();
@@ -188,7 +188,7 @@ class Conf
if (! isset($this->modules_parts[$partname]) || ! is_array($this->modules_parts[$partname])) { $this->modules_parts[$partname] = array(); } if (! isset($this->modules_parts[$partname]) || ! is_array($this->modules_parts[$partname])) { $this->modules_parts[$partname] = array(); }
$arrValue = json_decode($value,true); $arrValue = json_decode($value,true);
if (is_array($arrValue) && ! empty($arrValue)) $value = $arrValue; if (is_array($arrValue) && ! empty($arrValue)) $value = $arrValue;
else if (in_array($partname,array('login','menus','substitutions','triggers','tpl'))) $value = '/'.$modulename.'/core/'.$partname.'/'; else if (in_array($partname,array('login','menus','substitutions','triggers','tpl','theme'))) $value = '/'.$modulename.'/core/'.$partname.'/';
else if (in_array($partname,array('models'))) $value = '/'.$modulename.'/'; else if (in_array($partname,array('models'))) $value = '/'.$modulename.'/';
else if ($value == 1) $value = '/'.$modulename.'/core/modules/'.$partname.'/'; else if ($value == 1) $value = '/'.$modulename.'/core/modules/'.$partname.'/';
$this->$varname = array_merge($this->$varname, array($modulename => $value)); // TODO deprecated $this->$varname = array_merge($this->$varname, array($modulename => $value)); // TODO deprecated

View File

@@ -159,9 +159,7 @@ function show_theme($fuser,$edit=0,$foruserprofile=false)
{ {
global $conf,$langs,$bc; global $conf,$langs,$bc;
$dirthemes=array_merge(array($conf->global->MAIN_FORCETHEMEDIR.'/theme'),(array) $conf->modules_parts['themes']);
$dirtheme=dol_buildpath($conf->global->MAIN_FORCETHEMEDIR.'/theme',0);
$urltheme=dol_buildpath($conf->global->MAIN_FORCETHEMEDIR.'/theme',1);
$selected_theme=$conf->global->MAIN_THEME; $selected_theme=$conf->global->MAIN_THEME;
if (! empty($fuser)) $selected_theme=$fuser->conf->MAIN_THEME; if (! empty($fuser)) $selected_theme=$fuser->conf->MAIN_THEME;
@@ -216,47 +214,62 @@ function show_theme($fuser,$edit=0,$foruserprofile=false)
print '<tr '.$bc[$var].'><td colspan="'.$colspan.'">'; print '<tr '.$bc[$var].'><td colspan="'.$colspan.'">';
print '<table class="nobordernopadding" width="100%">'; print '<table class="nobordernopadding" width="100%">';
$handle=opendir($dirtheme);
$i=0; $i=0;
while (($subdir = readdir($handle))!==false)
foreach($dirthemes as $dir)
{ {
if (is_dir($dirtheme."/".$subdir) && substr($subdir, 0, 1) <> '.' $dirtheme=dol_buildpath($dir,0);
&& substr($subdir, 0, 3) <> 'CVS' && ! preg_match('/common|phones/i',$subdir)) $urltheme=dol_buildpath($dir,1);
{
// Disable not stable themes if (is_dir($dirtheme))
//if ($conf->global->MAIN_FEATURES_LEVEL < 1 && preg_match('/bureau2crea/i',$subdir)) continue; {
$handle=opendir($dirtheme);
if ($i % $thumbsbyrow == 0) if (is_resource($handle))
{ {
print '<tr '.$bc[$var].'>'; while (($subdir = readdir($handle))!==false)
} {
if (is_dir($dirtheme."/".$subdir) && substr($subdir, 0, 1) <> '.'
print '<td align="center">'; && substr($subdir, 0, 3) <> 'CVS' && ! preg_match('/common|phones/i',$subdir))
$file=$dirtheme."/".$subdir."/thumb.png"; {
$url=$urltheme."/".$subdir."/thumb.png"; // Disable not stable themes
if (! file_exists($file)) $url=$urltheme."/common/nophoto.jpg"; //if ($conf->global->MAIN_FEATURES_LEVEL < 1 && preg_match('/bureau2crea/i',$subdir)) continue;
print '<table><tr><td>';
print '<a href="'.$_SERVER["PHP_SELF"].($edit?'?action=edit&theme=':'?theme=').$subdir.(GETPOST("optioncss")?'&optioncss='.GETPOST("optioncss",'alpha',1):'').($fuser?'&id='.$fuser->id:'').'" style="font-weight: normal;" alt="'.$langs->trans("Preview").'">'; if ($i % $thumbsbyrow == 0)
if ($subdir == $conf->global->MAIN_THEME) $title=$langs->trans("ThemeCurrentlyActive"); {
else $title=$langs->trans("ShowPreview"); print '<tr '.$bc[$var].'>';
print '<img src="'.$url.'" border="0" width="80" height="60" alt="'.$title.'" title="'.$title.'">'; }
print '</a>';
print '</td></tr><tr><td align="center">'; print '<td align="center">';
if ($subdir == $selected_theme) $file=$dirtheme."/".$subdir."/thumb.png";
{ $url=$urltheme."/".$subdir."/thumb.png";
print '<input '.($edit?'':'disabled').' type="radio" '.$bc[$var].' style="border: 0px;" checked name="main_theme" value="'.$subdir.'"> <b>'.$subdir.'</b>'; if (! file_exists($file)) $url=$urltheme."/common/nophoto.jpg";
} print '<table><tr><td>';
else print '<a href="'.$_SERVER["PHP_SELF"].($edit?'?action=edit&theme=':'?theme=').$subdir.(GETPOST("optioncss")?'&optioncss='.GETPOST("optioncss",'alpha',1):'').($fuser?'&id='.$fuser->id:'').'" style="font-weight: normal;" alt="'.$langs->trans("Preview").'">';
{ if ($subdir == $conf->global->MAIN_THEME) $title=$langs->trans("ThemeCurrentlyActive");
print '<input '.($edit?'':'disabled').' type="radio" '.$bc[$var].' style="border: 0px;" name="main_theme" value="'.$subdir.'"> '.$subdir; else $title=$langs->trans("ShowPreview");
} print '<img src="'.$url.'" border="0" width="80" height="60" alt="'.$title.'" title="'.$title.'">';
print '</td></tr></table></td>'; print '</a>';
print '</td></tr><tr><td align="center">';
$i++; if ($subdir == $selected_theme)
{
if ($i % $thumbsbyrow == 0) print '</tr>'; print '<input '.($edit?'':'disabled').' type="radio" '.$bc[$var].' style="border: 0px;" checked name="main_theme" value="'.$subdir.'"> <b>'.$subdir.'</b>';
} }
else
{
print '<input '.($edit?'':'disabled').' type="radio" '.$bc[$var].' style="border: 0px;" name="main_theme" value="'.$subdir.'"> '.$subdir;
}
print '</td></tr></table></td>';
$i++;
if ($i % $thumbsbyrow == 0) print '</tr>';
}
}
}
}
} }
if ($i % $thumbsbyrow != 0) if ($i % $thumbsbyrow != 0)
{ {
while ($i % $thumbsbyrow != 0) while ($i % $thumbsbyrow != 0)