Fix: best negation

This commit is contained in:
Regis Houssin 2011-03-18 14:13:09 +00:00
parent b4123e4e4c
commit 7fdf1d8f3b

View File

@ -87,19 +87,19 @@ function dol_getprefix()
function dol_include_once($relpath) function dol_include_once($relpath)
{ {
global $conf,$langs,$user,$mysoc; // Other global var must be retreived with $GLOBALS['var'] global $conf,$langs,$user,$mysoc; // Other global var must be retreived with $GLOBALS['var']
return include_once(dol_buildpath($relpath)); return @include_once(dol_buildpath($relpath));
} }
/** /**
* Return path of url or filesystem. Return default_root or alternate root if file_exist fails. * Return path of url or filesystem. Return default_root or alternate root if file_exist fails.
* @param path Relative path to file (if mode=0, ie: mydir/myfile, ../myfile, ...) or relative url (if mode=1). * @param path Relative path to file (if mode=0, ie: mydir/myfile, ../myfile, ...) or relative url (if mode=1).
* @param mode 0=Used for a Filesystem path, 1=Used for an URL path * @param 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 filsystem path (if mode=0), Full url path (if mode=1)
*/ */
function dol_buildpath($path,$mode=0) function dol_buildpath($path,$type=0)
{ {
if (empty($mode)) // For a filesystem path if (empty($type)) // For a filesystem path
{ {
$res = DOL_DOCUMENT_ROOT.$path; // Standard value $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 (defined('DOL_DOCUMENT_ROOT_ALT') && DOL_DOCUMENT_ROOT_ALT) // We check only if alternate feature is used
@ -109,21 +109,34 @@ function dol_buildpath($path,$mode=0)
} }
else // For an url path else // For an url path
{ {
$res = DOL_URL_ROOT.$path; // Standard value // We try to get local path of file on filesystem from url
if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT) // We check only if alternate feature is used // 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
// We try to get local path of file on filesystem from url // using proxy, rewriting, virtual path, etc...
// FIXME Trying to know if a file on disk exist by forging path on disk from url if ($type == 1)
// works only for some web server and some setup. This is bugged when {
// using proxy, rewriting, virtual path, etc... $res = DOL_URL_ROOT.$path; // Standard value
preg_match('/^([^.]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i',$path,$regs); // Take part before '?' if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT) // We check only if alternate feature is used
if (! empty($regs[1])) $filepath = $regs[1]; {
// An alternative for proxy but extremely slow preg_match('/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i',$path,$regs); // Take part before '?'
//$url = 'http://'.$_SERVER["SERVER_NAME"].DOL_URL_ROOT.$path; if (! empty($regs[1]))
//if (! @file_get_contents($url)) $res = DOL_URL_ROOT_ALT.$path; {
//if (! @fopen($url, 'r')) $res = DOL_URL_ROOT_ALT.$path; if (! file_exists(DOL_DOCUMENT_ROOT.$regs[1])) $res = DOL_URL_ROOT_ALT.$path;
if (! file_exists(DOL_DOCUMENT_ROOT.$filepath)) $res = DOL_URL_ROOT_ALT.$path; }
} }
}
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;
}
}
}
} }
return $res; return $res;
@ -149,10 +162,10 @@ function dol_clone($object)
} }
/** /**
* \brief Optimize a size for some browsers (phone, smarphone, ...) * Optimize a size for some browsers (phone, smarphone, ...)
* \param size Size we want * @param size Size we want
* \param type Type of optimizing(''=Optimize for a truncate, 'width'=Optimize for screen width) * @param type Type of optimizing(''=Optimize for a truncate, 'width'=Optimize for screen width)
* \return int New size after optimizing * @return int New size after optimizing
*/ */
function dol_size($size,$type='') function dol_size($size,$type='')
{ {