"fixed not always displayed icons (eg. old nextmatch in translation-tools) and some more caching"

This commit is contained in:
Ralf Becker 2009-05-16 10:22:56 +00:00
parent 2408fbb0c9
commit 44ce028592

View File

@ -811,64 +811,64 @@ class common
$imagedir = '/'.$appname.'/templates/'.$GLOBALS['egw_info']['user']['preferences']['common']['template_set'].'/images'; $imagedir = '/'.$appname.'/templates/'.$GLOBALS['egw_info']['user']['preferences']['common']['template_set'].'/images';
$vfs_imagedir = $GLOBALS['egw_info']['server']['vfs_image_dir']; $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_olddefault = '/'.$appname.'/templates/default/images';
$imagedir_default = '/'.$appname.'/templates/idots/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 (($entry = $d->read()))
while (false != ($entry = $d->read()))
{ {
if ($entry != '.' && $entry != '..') if ($entry[0] != '.')
{ {
self::$found_files[$appname][$entry] = $imagedir_olddefault; self::$found_files[$appname][$entry] = $imagedir_olddefault;
} }
} }
$d->close(); $d->close();
} }
if (file_exists(EGW_INCLUDE_ROOT.$imagedir_default) && ($d = dir(EGW_INCLUDE_ROOT.$imagedir_default)))
if (@is_dir(EGW_INCLUDE_ROOT.$imagedir_default))
{ {
$d = dir(EGW_INCLUDE_ROOT.$imagedir_default); while (($entry = $d->read()))
while (false != ($entry = $d->read()))
{ {
if ($entry != '.' && $entry != '..') if ($entry[0] != '.')
{ {
self::$found_files[$appname][$entry] = $imagedir_default; self::$found_files[$appname][$entry] = $imagedir_default;
} }
} }
$d->close(); $d->close();
} }
if (file_exists(EGW_INCLUDE_ROOT.$imagedir) && ($d = dir(EGW_INCLUDE_ROOT.$imagedir)))
if (@is_dir(EGW_INCLUDE_ROOT.$imagedir))
{ {
$d = dir(EGW_INCLUDE_ROOT.$imagedir); while (($entry = $d->read()))
while (false != ($entry = $d->read()))
{ {
if ($entry != '.' && $entry != '..') if ($entry[0] != '.')
{ {
self::$found_files[$appname][$entry] = $imagedir; self::$found_files[$appname][$entry] = $imagedir;
} }
} }
$d->close(); $d->close();
} }
//echo $appname; _debug_array(self::$found_files[$appname]);
if (!isset(self::$found_files['vfs']) && egw_vfs::file_exists($vfs_imagedir) && }
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))) egw_vfs::is_dir($vfs_imagedir) && ($d = egw_vfs::opendir($vfs_imagedir)))
{ {
while (($entry = readdir($d)) !== false) while (($entry = readdir($d)) !== false)
{ {
if (!egw_vfs::is_dir($vfs_imagedir.'/'.$entry)) 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); closedir($d);
//echo 'vfs'; _debug_array(self::$found_files['vfs']);
} }
} }
if (!$GLOBALS['egw_info']['server']['image_type']) if (!$GLOBALS['egw_info']['server']['image_type'])
@ -892,7 +892,7 @@ class common
break; break;
} }
// then look in the selected template dir // 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; $imgfile = $GLOBALS['egw_info']['server']['webserver_url'].self::$found_files[$appname][$image.$type].'/'.$image.$type;
break; break;
@ -912,7 +912,7 @@ class common
{ {
self::find_image('phpgwapi',''); 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])) if(isset(self::$found_files['phpgwapi'][$image.$type]))
{ {
@ -936,35 +936,35 @@ class common
*/ */
static function image($appname,$image='',$ext='',$use_lang=True) 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) foreach((array)$image as $img)
{ {
$lang_images[] = $img . '_' . $GLOBALS['egw_info']['user']['preferences']['common']['lang']; if (($image_found = self::find_image($appname,$img.$ext))) break;
$lang_images[] = $img;
} }
$image = $lang_images;
} }
foreach((array)$image as $img) //else $cache_hit = ' *** CACHE ***';
{ //echo '<p>'.__METHOD__."($appname,".array2string($image).",$ext,$use_lang) = ".array2string($image_found)." $cache_hit</p>\n";
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 "<p>".__METHOD__."($appname,".array2string($image).",$ext,$use_lang) = $image_found</p>\n";
return $image_found; return $image_found;
} }