2
0
forked from Wavyzz/dolibarr

New: Make some changes to allow usage of alternative

$dolibarr_main_url_root variables.
Can now use several alternative path. Fix several bugs with all code.
This commit is contained in:
Laurent Destailleur
2013-07-07 03:26:51 +02:00
parent 9be6dd8b17
commit 7b5e0678db
22 changed files with 165 additions and 141 deletions

View File

@@ -244,21 +244,30 @@ function dol_include_once($relpath, $classname='')
/**
* Return path of url or filesystem. Return default_root or alternate root if file_exist fails
* Return path of url or filesystem. Return alternate root if exists
*
* @param string $path Relative path to file (if mode=0, ie: mydir/myfile, ../myfile, ...) or relative url (if mode=1).
* @param string $path Relative path to file (if mode=0) or relative url (if mode=1). Ie: mydir/myfile, ../myfile
* @param int $type 0=Used for a Filesystem path, 1=Used for an URL path (output relative), 2=Used for an URL path (output full path)
* @return string Full filsystem path (if mode=0), Full url path (if mode=1)
* @return string Full filesystem path (if mode=0), Full url path (if mode=1)
*/
function dol_buildpath($path, $type=0)
{
global $conf;
$path=preg_replace('/^\//','',$path);
if (empty($type)) // For a filesystem path
{
$res = DOL_DOCUMENT_ROOT.$path; // Standard value
if (defined('DOL_DOCUMENT_ROOT_ALT') && DOL_DOCUMENT_ROOT_ALT) // We check only if alternate feature is used
{
if (! file_exists(DOL_DOCUMENT_ROOT.$path)) $res = DOL_DOCUMENT_ROOT_ALT.$path;
}
$res = DOL_DOCUMENT_ROOT.'/'.$path; // Standard value
foreach ($conf->file->dol_document_root as $key => $dirroot) // ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
{
if ($key == 'main') continue;
if (file_exists($dirroot.'/'.$path))
{
$res=$dirroot.'/'.$path;
break;
}
}
}
else // For an url path
{
@@ -266,29 +275,23 @@ function dol_buildpath($path, $type=0)
// Note that trying to know if a file on disk exist by forging path on disk from url
// works only for some web server and some setup. This is bugged when
// using proxy, rewriting, virtual path, etc...
if ($type == 1)
$res='';
if ($type == 1) $res = DOL_URL_ROOT.'/'.$path; // Standard value
if ($type == 2) $res = DOL_MAIN_URL_ROOT.'/'.$path; // Standard value
foreach ($conf->file->dol_document_root as $key => $dirroot) // ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
{
$res = DOL_URL_ROOT.$path; // Standard value
if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT) // We check only if alternate feature is used
if ($key == 'main') continue;
preg_match('/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i',$path,$regs); // Take part before '?'
if (! empty($regs[1]))
{
preg_match('/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i',$path,$regs); // Take part before '?'
if (! empty($regs[1]))
{
if (! file_exists(DOL_DOCUMENT_ROOT.$regs[1])) $res = DOL_URL_ROOT_ALT.$path;
//print $key.'-'.$dirroot.'/'.$path.'-'.$conf->file->dol_url_root[$type].'<br>'."\n";
if (file_exists($dirroot.'/'.$path))
{
if ($type == 1) $res=DOL_URL_ROOT.$conf->file->dol_url_root[$key].'/'.$path;
if ($type == 2) $res=DOL_MAIN_URL_ROOT.$conf->file->dol_url_root[$key].'/'.$path;
break;
}
}
}
else if ($type == 2)
{
$res = DOL_MAIN_URL_ROOT.$path; // Standard value
if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT) // We check only if alternate feature is used
{
preg_match('/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i',$path,$regs); // Take part before '?'
if (! empty($regs[1]))
{
if (! file_exists(DOL_DOCUMENT_ROOT.$regs[1])) $res = DOL_MAIN_URL_ROOT_ALT.$path;
}
}
}
}
}
@@ -1714,8 +1717,16 @@ function img_picto($alt, $picto, $options = '', $pictoisfullpath = false, $srcon
}
// Clean parameters
if (! preg_match('/(\.png|\.gif)$/i',$picto)) $picto .= '.png';
// If img file is not into standard path, we use alternate path (Avoid using DOL_URL_ROOT_ALT for performane)
if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT && ! file_exists(DOL_DOCUMENT_ROOT.'/'.$path.'/img/'.$picto)) $url = DOL_URL_ROOT_ALT;
// If alt path are defined, define url where img file is, according to physical path
foreach ($conf->file->dol_document_root as $type => $dirroot) // ex: array(["main"]=>"/home/maindir/htdocs", ["alt0"]=>"/home/moddir/htdocs", ...)
{
if ($type == 'main') continue;
if (file_exists($dirroot.'/'.$path.'/img/'.$picto))
{
$url=$conf->file->dol_url_root[$type];
break;
}
}
// $url is '' or '/custom', $path is current theme or
$fullpathpicto = $url.'/'.$path.'/img/'.$picto;