From 7fdf1d8f3b26afb8578a02a6203bbe2f60a6507f Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 18 Mar 2011 14:13:09 +0000 Subject: [PATCH] Fix: best negation --- htdocs/lib/functions.lib.php | 59 ++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index ab4f14902f3..6175c4a5973 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -87,19 +87,19 @@ function dol_getprefix() function dol_include_once($relpath) { 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. * @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) */ -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 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 { - $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 - { - // We try to get local path of file on filesystem from url - // FIXME 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... - preg_match('/^([^.]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i',$path,$regs); // Take part before '?' - if (! empty($regs[1])) $filepath = $regs[1]; - // An alternative for proxy but extremely slow - //$url = 'http://'.$_SERVER["SERVER_NAME"].DOL_URL_ROOT.$path; - //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.$filepath)) $res = DOL_URL_ROOT_ALT.$path; - } + // We try to get local path of file on filesystem from url + // 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 = DOL_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_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; @@ -149,10 +162,10 @@ function dol_clone($object) } /** - * \brief Optimize a size for some browsers (phone, smarphone, ...) - * \param size Size we want - * \param type Type of optimizing(''=Optimize for a truncate, 'width'=Optimize for screen width) - * \return int New size after optimizing + * Optimize a size for some browsers (phone, smarphone, ...) + * @param size Size we want + * @param type Type of optimizing(''=Optimize for a truncate, 'width'=Optimize for screen width) + * @return int New size after optimizing */ function dol_size($size,$type='') {