From 44ce0285925e69f1ffdbbb16d99a236b341a6163 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sat, 16 May 2009 10:22:56 +0000 Subject: [PATCH] "fixed not always displayed icons (eg. old nextmatch in translation-tools) and some more caching" --- phpgwapi/inc/class.common.inc.php | 86 +++++++++++++++---------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/phpgwapi/inc/class.common.inc.php b/phpgwapi/inc/class.common.inc.php index 6ebdb8671f..caf24d4a6b 100644 --- a/phpgwapi/inc/class.common.inc.php +++ b/phpgwapi/inc/class.common.inc.php @@ -811,64 +811,64 @@ class common $imagedir = '/'.$appname.'/templates/'.$GLOBALS['egw_info']['user']['preferences']['common']['template_set'].'/images'; $vfs_imagedir = $GLOBALS['egw_info']['server']['vfs_image_dir']; - if (!@is_array(self::$found_files[$appname])) + if (!isset(self::$found_files[$appname])) { $imagedir_olddefault = '/'.$appname.'/templates/default/images'; $imagedir_default = '/'.$appname.'/templates/idots/images'; - if (@is_dir(EGW_INCLUDE_ROOT.$imagedir_olddefault)) + if (file_exists(EGW_INCLUDE_ROOT.$imagedir_olddefault) && ($d = dir(EGW_INCLUDE_ROOT.$imagedir_olddefault))) { - $d = dir(EGW_INCLUDE_ROOT.$imagedir_olddefault); - while (false != ($entry = $d->read())) + while (($entry = $d->read())) { - if ($entry != '.' && $entry != '..') + if ($entry[0] != '.') { self::$found_files[$appname][$entry] = $imagedir_olddefault; } } $d->close(); } - - if (@is_dir(EGW_INCLUDE_ROOT.$imagedir_default)) + if (file_exists(EGW_INCLUDE_ROOT.$imagedir_default) && ($d = dir(EGW_INCLUDE_ROOT.$imagedir_default))) { - $d = dir(EGW_INCLUDE_ROOT.$imagedir_default); - while (false != ($entry = $d->read())) + while (($entry = $d->read())) { - if ($entry != '.' && $entry != '..') + if ($entry[0] != '.') { self::$found_files[$appname][$entry] = $imagedir_default; } } $d->close(); } - - if (@is_dir(EGW_INCLUDE_ROOT.$imagedir)) + if (file_exists(EGW_INCLUDE_ROOT.$imagedir) && ($d = dir(EGW_INCLUDE_ROOT.$imagedir))) { - $d = dir(EGW_INCLUDE_ROOT.$imagedir); - while (false != ($entry = $d->read())) + while (($entry = $d->read())) { - if ($entry != '.' && $entry != '..') + if ($entry[0] != '.') { self::$found_files[$appname][$entry] = $imagedir; } } $d->close(); } - - if (!isset(self::$found_files['vfs']) && egw_vfs::file_exists($vfs_imagedir) && + //echo $appname; _debug_array(self::$found_files[$appname]); + } + if (!isset(self::$found_files['vfs'])) + { + self::$found_files['vfs'] = array(); // so it get's scaned only once + if (egw_vfs::file_exists($vfs_imagedir) && egw_vfs::is_dir($vfs_imagedir) && ($d = egw_vfs::opendir($vfs_imagedir))) { while (($entry = readdir($d)) !== false) { if (!egw_vfs::is_dir($vfs_imagedir.'/'.$entry)) { - if (list($type,$subtype) = explode('/',egw_vfs::mime_content_type($vfs_imagedir.'/'.$entry)))// && $type == 'image') + if (list($type,$subtype) = explode('/',egw_vfs::mime_content_type($vfs_imagedir.'/'.$entry)) && $type == 'image') { - if ($type == 'image' || $type == 'application') self::$found_files['vfs'][$entry] = $vfs_imagedir; + self::$found_files['vfs'][$entry] = $vfs_imagedir; } } } closedir($d); + //echo 'vfs'; _debug_array(self::$found_files['vfs']); } } if (!$GLOBALS['egw_info']['server']['image_type']) @@ -892,7 +892,7 @@ class common break; } // then look in the selected template dir - if(self::$found_files[$appname][$image.$type]==$imagedir) + if(self::$found_files[$appname][$image.$type] == $imagedir) { $imgfile = $GLOBALS['egw_info']['server']['webserver_url'].self::$found_files[$appname][$image.$type].'/'.$image.$type; break; @@ -912,7 +912,7 @@ class common { self::find_image('phpgwapi',''); } - foreach(array_merge($img_type,array('')) as $type) + foreach($img_type as $type) { if(isset(self::$found_files['phpgwapi'][$image.$type])) { @@ -936,35 +936,35 @@ class common */ static function image($appname,$image='',$ext='',$use_lang=True) { - if (!is_array($image)) + static $cache; // do some caching in the request + + $image_found =& $cache[$appname.$image.$ext.$use_lang]; + + if (!isset($image_found)) { - if (empty($image)) + if (!is_array($image)) { - return ''; + if (empty($image)) + { + return ''; + } + } + if ($use_lang) + { + foreach((array)$image as $img) + { + $lang_images[] = $img . '_' . $GLOBALS['egw_info']['user']['preferences']['common']['lang']; + $lang_images[] = $img; + } + $image = $lang_images; } - } - if ($use_lang) - { foreach((array)$image as $img) { - $lang_images[] = $img . '_' . $GLOBALS['egw_info']['user']['preferences']['common']['lang']; - $lang_images[] = $img; + if (($image_found = self::find_image($appname,$img.$ext))) break; } - $image = $lang_images; } - foreach((array)$image as $img) - { - if(isset(self::$found_files[$appname][$img.$ext])) - { - $image_found = self::$found_files[$appname][$img.$ext].'/'.$img.$ext; - } - else - { - $image_found = self::find_image($appname,$img.$ext); - } - if ($image_found) break; - } - //echo "

".__METHOD__."($appname,".array2string($image).",$ext,$use_lang) = $image_found

\n"; + //else $cache_hit = ' *** CACHE ***'; + //echo '

'.__METHOD__."($appname,".array2string($image).",$ext,$use_lang) = ".array2string($image_found)." $cache_hit

\n"; return $image_found; }