"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'])
@ -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]))
{ {
@ -935,6 +935,12 @@ class common
* @return string url of the image * @return string url of the image
*/ */
static function image($appname,$image='',$ext='',$use_lang=True) static function image($appname,$image='',$ext='',$use_lang=True)
{
static $cache; // do some caching in the request
$image_found =& $cache[$appname.$image.$ext.$use_lang];
if (!isset($image_found))
{ {
if (!is_array($image)) if (!is_array($image))
{ {
@ -954,17 +960,11 @@ class common
} }
foreach((array)$image as $img) foreach((array)$image as $img)
{ {
if(isset(self::$found_files[$appname][$img.$ext])) if (($image_found = self::find_image($appname,$img.$ext))) break;
{
$image_found = self::$found_files[$appname][$img.$ext].'/'.$img.$ext;
} }
else
{
$image_found = self::find_image($appname,$img.$ext);
} }
if ($image_found) break; //else $cache_hit = ' *** CACHE ***';
} //echo '<p>'.__METHOD__."($appname,".array2string($image).",$ext,$use_lang) = ".array2string($image_found)." $cache_hit</p>\n";
//echo "<p>".__METHOD__."($appname,".array2string($image).",$ext,$use_lang) = $image_found</p>\n";
return $image_found; return $image_found;
} }