From 189c3c94da73b00a15ce95e7ae5e22031ab5f076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a?= Date: Sat, 4 Aug 2012 02:15:39 +0200 Subject: [PATCH 1/5] Removed duplicated code --- htdocs/core/lib/functions.lib.php | 75 ++++++++++++------------------- 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 4d916737fbf..859b9579a2e 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1617,45 +1617,6 @@ function dol_trunc($string,$size=40,$trunc='right',$stringencoding='UTF-8',$nodo else return 'BadParam3CallingDolTrunc'; } - -/** - * Show a picto called object_picto (generic function) - * - * @param string $alt Text of alt on image - * @param string $picto Name of image to show object_picto (example: user, group, action, bill, contract, propal, product, ...) - * For external modules use imagename@mymodule to search into directory "img" of module. - * @param string $options Add more attribute on img tag (ie: class="datecallink") - * @param int $pictoisfullpath If 1, image path is a full path - * @return string Return img tag - * @see #img_picto, #img_picto_common - */ -function img_object($alt, $picto, $options='', $pictoisfullpath=0) -{ - global $conf; - - // Clean parameters - if (! preg_match('/(\.png|\.gif)$/i',$picto) && ! preg_match('/^([^@]+)@([^@]+)$/i',$picto)) $picto.='.png'; - - // Define fullpathpicto to use into src - if (! empty($pictoisfullpath)) $fullpathpicto=$picto; - else - { - // By default, we search into theme directory - $url = DOL_URL_ROOT; - $path = 'theme/'.$conf->theme; - if (! empty($conf->global->MAIN_FORCETHEMEDIR)) $path=preg_replace('/^\//','',$conf->global->MAIN_FORCETHEMEDIR).'/'.$path; - // If we ask an image into module/img (not into a theme path) - if (preg_match('/^([^@]+)@([^@]+)$/i',$picto,$regs)) { $picto = $regs[1]; $path=$regs[2]; } // If image into a module/img path - if (! preg_match('/(\.png|\.gif)$/i',$picto)) $picto.='.png'; - // If img file not into standard path, we use alternate path - if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT && ! file_exists(DOL_DOCUMENT_ROOT.'/'.$path.'/img/object_'.$picto)) $url = DOL_URL_ROOT_ALT; - - $fullpathpicto=$url.'/'.$path.'/img/object_'.$picto; - } - - return ''.dol_escape_htmltag($alt).''; -} - /** * Show picto whatever it's its name (generic function) * @@ -1670,33 +1631,55 @@ function img_object($alt, $picto, $options='', $pictoisfullpath=0) * @return string Return img tag * @see #img_object, #img_picto_common */ -function img_picto($alt, $picto, $options='', $pictoisfullpath=0) +function img_picto($alt, $picto, $options = '', $pictoisfullpath = false) { global $conf; // Clean parameters - if (! preg_match('/(\.png|\.gif)$/i',$picto) && ! preg_match('/^([^@]+)@([^@]+)$/i',$picto)) $picto.='.png'; + if (! preg_match('/(\.png|\.gif)$/i', $picto) && ! preg_match('/^([^@]+)@([^@]+)$/i', $picto)) $picto .= '.png'; // Define fullpathpicto to use into src - if (! empty($pictoisfullpath)) $fullpathpicto=$picto; + if ($pictoisfullpath) $fullpathpicto = $picto; else { // By default, we search into theme directory $url = DOL_URL_ROOT; $path = 'theme/'.$conf->theme; - if (! empty($conf->global->MAIN_FORCETHEMEDIR)) $path=preg_replace('/^\//','',$conf->global->MAIN_FORCETHEMEDIR).'/'.$path; + if (! empty($conf->global->MAIN_FORCETHEMEDIR)) $path = preg_replace('/^\//', '', $conf->global->MAIN_FORCETHEMEDIR).'/'.$path; // If we ask an image into module/img (not into a theme path) - if (preg_match('/^([^@]+)@([^@]+)$/i',$picto,$regs)) { $picto = $regs[1]; $path=$regs[2]; } // If image into a module/img path - if (! preg_match('/(\.png|\.gif)$/i',$picto)) $picto.='.png'; + if (preg_match('/^([^@]+)@([^@]+)$/i',$picto,$regs)) + { + $picto = $regs[1]; + $path = $regs[2]; + } + if (! preg_match('/(\.png|\.gif)$/i',$picto)) $picto .= '.png'; // If img file not into standard path, we use alternate path if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT && ! file_exists(DOL_DOCUMENT_ROOT.'/'.$path.'/img/'.$picto)) $url = DOL_URL_ROOT_ALT; - $fullpathpicto=$url.'/'.$path.'/img/'.$picto; + $fullpathpicto = $url.'/'.$path.'/img/'.$picto; } return ''.dol_escape_htmltag($alt).''; } +/** + * Show a picto called object_picto (generic function) + * + * @param string $alt Text of alt on image + * @param string $picto Name of image to show object_picto (example: user, group, action, bill, contract, propal, product, ...) + * For external modules use imagename@mymodule to search into directory "img" of module. + * @param string $options Add more attribute on img tag (ie: class="datecallink") + * @param int $pictoisfullpath If 1, image path is a full path + * @return string Return img tag + * @see #img_picto, #img_picto_common + */ +function img_object($alt, $picto, $options = '', $pictoisfullpath = false) +{ + global $conf; + + return img_picto($alt, 'object_'.$picto, $options, $pictoisfullpath); +} + /** * Show picto (generic function) * From 320ce03e29337d99980b5d7c89249c955ea10bde Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 4 Aug 2012 08:45:38 +0200 Subject: [PATCH 2/5] Fix: optimization see : http://mkaz.com/web-dev/php-benchmarking-isset-empty-or-var.html --- htdocs/core/lib/functions.lib.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 859b9579a2e..3e425a9922a 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1635,26 +1635,32 @@ function img_picto($alt, $picto, $options = '', $pictoisfullpath = false) { global $conf; - // Clean parameters - if (! preg_match('/(\.png|\.gif)$/i', $picto) && ! preg_match('/^([^@]+)@([^@]+)$/i', $picto)) $picto .= '.png'; - // Define fullpathpicto to use into src - if ($pictoisfullpath) $fullpathpicto = $picto; + if (! empty($pictoisfullpath)) { + // Clean parameters + if (! preg_match('/(\.png|\.gif)$/i',$picto)) + $picto .= '.png'; + $fullpathpicto = $picto; + } else { // By default, we search into theme directory $url = DOL_URL_ROOT; $path = 'theme/'.$conf->theme; - if (! empty($conf->global->MAIN_FORCETHEMEDIR)) $path = preg_replace('/^\//', '', $conf->global->MAIN_FORCETHEMEDIR).'/'.$path; + if (! empty($conf->global->MAIN_FORCETHEMEDIR)) + $path = preg_replace('/^\//', '', $conf->global->MAIN_FORCETHEMEDIR).'/'.$path; // If we ask an image into module/img (not into a theme path) if (preg_match('/^([^@]+)@([^@]+)$/i',$picto,$regs)) { $picto = $regs[1]; $path = $regs[2]; } - if (! preg_match('/(\.png|\.gif)$/i',$picto)) $picto .= '.png'; + // Clean parameters + if (! preg_match('/(\.png|\.gif)$/i',$picto)) + $picto .= '.png'; // If img file not into standard path, we use alternate path - if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT && ! file_exists(DOL_DOCUMENT_ROOT.'/'.$path.'/img/'.$picto)) $url = DOL_URL_ROOT_ALT; + if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT && ! file_exists(DOL_DOCUMENT_ROOT.'/'.$path.'/img/'.$picto)) + $url = DOL_URL_ROOT_ALT; $fullpathpicto = $url.'/'.$path.'/img/'.$picto; } @@ -1675,8 +1681,6 @@ function img_picto($alt, $picto, $options = '', $pictoisfullpath = false) */ function img_object($alt, $picto, $options = '', $pictoisfullpath = false) { - global $conf; - return img_picto($alt, 'object_'.$picto, $options, $pictoisfullpath); } @@ -1700,7 +1704,7 @@ function img_picto_common($alt, $picto, $options = '', $pictoisfullpath = 0) else { $path = DOL_URL_ROOT.'/theme/common/'.$picto; - + if (! empty($conf->global->MAIN_MODULE_CAN_OVERWRITE_COMMONICONS)) { $themepath = DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/'.$picto; @@ -1812,7 +1816,7 @@ function img_view($alt = 'default', $float = 0, $other = '') if ($alt == 'default') $alt = $langs->trans('View'); $options = ($float ? 'style="float: right" ' : '').$other; - + return img_picto($alt, 'view.png', $options); } @@ -2006,7 +2010,7 @@ function img_allow($allow, $alt = 'default') if ($alt == 'default') $alt = $langs->trans('Active'); if ($allow == 1) return img_picto($alt, 'tick.png'); - + return '-'; } @@ -2068,7 +2072,7 @@ function info_admin($text, $infoonimgalt = 0) { return img_picto($text, 'star'); } - + return '
'.img_picto($langs->trans('InfoAdmin'), 'star').' '.$text.'
'; } From e955b041ca86a0e18c5307e9b1112e7ada4b95f7 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 4 Aug 2012 09:56:25 +0200 Subject: [PATCH 3/5] Fix: just change $path value --- htdocs/core/lib/functions.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 3e425a9922a..d79f1f1a845 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1709,7 +1709,7 @@ function img_picto_common($alt, $picto, $options = '', $pictoisfullpath = 0) { $themepath = DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/'.$picto; - if (file_exists($themepath)) return img_picto($alt, $themepath, $options, 1); + if (file_exists($themepath)) $path = $themepath; } } From 46511de913d3c78d45e2d7f237638788e5e47d45 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 4 Aug 2012 13:49:04 +0200 Subject: [PATCH 4/5] Fix: remove unused code for avoid warning with IE9 --- htdocs/core/tpl/ajax/fileupload_main.tpl.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/htdocs/core/tpl/ajax/fileupload_main.tpl.php b/htdocs/core/tpl/ajax/fileupload_main.tpl.php index 9807dfb293b..dbc06934fa6 100644 --- a/htdocs/core/tpl/ajax/fileupload_main.tpl.php +++ b/htdocs/core/tpl/ajax/fileupload_main.tpl.php @@ -42,13 +42,6 @@ $(function () { // Initialize the jQuery File Upload widget: $('#fileupload').fileupload(); - // Options - $('#fileupload').fileupload('option', { - // Enable iframe cross-domain access via redirect option - redirect: window.location.href.replace(/\/[^\/]*$/,'/includes/jquery/plugins/fileupload/cors/result.html?%s'), - maxFileSize: '' - }); - // Events $('#fileupload').fileupload({ completed: function (e, data) { From 4d3e798f99af2c4464c3196e14e7c02dd71aab29 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 4 Aug 2012 14:18:02 +0200 Subject: [PATCH 5/5] Fix: remove test in $pictoisfullpath and add test in $options --- htdocs/core/lib/functions.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index d79f1f1a845..c61c16e108f 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1636,7 +1636,7 @@ function img_picto($alt, $picto, $options = '', $pictoisfullpath = false) global $conf; // Define fullpathpicto to use into src - if (! empty($pictoisfullpath)) { + if ($pictoisfullpath) { // Clean parameters if (! preg_match('/(\.png|\.gif)$/i',$picto)) $picto .= '.png'; @@ -1665,7 +1665,7 @@ function img_picto($alt, $picto, $options = '', $pictoisfullpath = false) $fullpathpicto = $url.'/'.$path.'/img/'.$picto; } - return ''.dol_escape_htmltag($alt).''; + return ''.dol_escape_htmltag($alt).''; } /**