Fix: more compatible with alternative path

Fix: uniformize code
This commit is contained in:
Regis Houssin
2010-12-19 11:05:07 +00:00
parent 749b9c333e
commit 17df30b7fa
19 changed files with 142 additions and 112 deletions

View File

@@ -74,6 +74,43 @@ function dol_include_once($relpath)
return $res;
}
/**
* Make an require_once using default root and alternate root if it fails.
* @param relpath Relative path to file (Ie: mydir/myfile, ../myfile, ...)
* @return int Result
*/
function dol_require_once($relpath)
{
$res=@require_once(DOL_DOCUMENT_ROOT.$relpath);
if (! $res && defined('DOL_DOCUMENT_ROOT_ALT')) $res=@require_once(DOL_DOCUMENT_ROOT_ALT.$relpath);
return $res;
}
/**
* Make an file_exists using default root and alternate root if it fails.
* @param path Relative or absolute path to file (Ie: mydir/myfile, ../myfile, ...)
* @return int Result
*/
function dol_file_exists($path,$absolute=0)
{
$res='';
if ($absolute)
{
preg_match('/^([^<]+\.php)/i',$path,$regs);
$path = (! empty($regs[1]) ? $regs[1] : $path);
$res=DOL_URL_ROOT.$path;
if (defined('DOL_URL_ROOT_ALT') && ! file_exists(DOL_DOCUMENT_ROOT.$path)) $url=DOL_URL_ROOT_ALT.$path;
}
else
{
$res = DOL_DOCUMENT_ROOT.$path;
if (defined('DOL_DOCUMENT_ROOT_ALT') && ! file_exists(DOL_DOCUMENT_ROOT.$path)) $res = DOL_DOCUMENT_ROOT_ALT.$path;
}
return $res;
}
/**
* Create a clone of instance of object (new instance with same properties)
* This function works for both PHP4 and PHP5.