From 54bf7a3d2df93da3a4e106df9c5e6981caff079e Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 31 Aug 2011 10:16:12 +0000 Subject: [PATCH] - fixed image map was empty created when not loged in (now directories are used and not $GLOBALS['egw_info']['apps']) - fixed not working vfs-image-dir - deleteing image-maps when: + apps get installed, updated or removed + admin >> register hooks + admin >> site configuration: vfs-image-dir get changed - fixed not displayed validation errors (thought there were no validation) in admin >> site config --> you need to register hooks, in order to get the admin >> site configuration validation hook ;-) --- .../class.admin_prefs_sidebox_hooks.inc.php | 2 + admin/inc/hook_config_validate.inc.php | 38 +++++++++++++++++++ admin/setup/setup.inc.php | 2 +- admin/templates/default/config.tpl | 2 + phpgwapi/inc/class.common.inc.php | 27 +++++++++++-- setup/inc/class.setup_process.inc.php | 3 ++ 6 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 admin/inc/hook_config_validate.inc.php diff --git a/admin/inc/class.admin_prefs_sidebox_hooks.inc.php b/admin/inc/class.admin_prefs_sidebox_hooks.inc.php index 39eb43a5fe..445d4ad0bc 100644 --- a/admin/inc/class.admin_prefs_sidebox_hooks.inc.php +++ b/admin/inc/class.admin_prefs_sidebox_hooks.inc.php @@ -142,6 +142,8 @@ class admin_prefs_sidebox_hooks } $GLOBALS['egw']->hooks->register_all_hooks(); + common::delete_image_map(); + if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited { $GLOBALS['egw']->invalidate_session_cache(); // in case with cache the egw_info array in the session diff --git a/admin/inc/hook_config_validate.inc.php b/admin/inc/hook_config_validate.inc.php new file mode 100644 index 0000000000..b7d7639ad9 --- /dev/null +++ b/admin/inc/hook_config_validate.inc.php @@ -0,0 +1,38 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ + +/* + Set a global flag to indicate this file was found by setup/config.php. + config.php will unset it after parsing the form values. +*/ +$GLOBALS['egw_info']['server']['found_validation_hook'] = True; + +/** + * Check VFS dir exists and delete image map to recreate it, if vfs-image-dir changes + * + * @param string + */ +function vfs_image_dir($vfs_image_dir) +{ + //error_log(__FUNCTION__.'() vfs_image_dir='.array2string($vfs_image_dir).' was '.array2string($GLOBALS['egw_info']['server']['vfs_image_dir'])); + if (!empty($vfs_image_dir)) + { + if (!egw_vfs::file_exists($vfs_image_dir) || !egw_vfs::is_dir($vfs_image_dir)) + { + $GLOBALS['config_error'] = lang('VFS directory "%1" NOT found!',$vfs_image_dir); + return; + } + } + if ($vfs_image_dir != (string)$GLOBALS['egw_info']['server']['vfs_image_dir']) + { + common::delete_image_map(); + } +} \ No newline at end of file diff --git a/admin/setup/setup.inc.php b/admin/setup/setup.inc.php index 50eb9cce36..b4db05359a 100755 --- a/admin/setup/setup.inc.php +++ b/admin/setup/setup.inc.php @@ -34,7 +34,7 @@ $setup_info['admin']['hooks'] = array( 'acl_manager', 'add_def_pref', 'after_navbar', - 'config', + 'config_validate', 'deleteaccount', 'view_user' => 'admin.uiaccounts.edit_view_user_hook', 'edit_user' => 'admin.uiaccounts.edit_view_user_hook', diff --git a/admin/templates/default/config.tpl b/admin/templates/default/config.tpl index e9bf71ade6..6abdf4929f 100644 --- a/admin/templates/default/config.tpl +++ b/admin/templates/default/config.tpl @@ -1,4 +1,6 @@ + +

{error}

diff --git a/phpgwapi/inc/class.common.inc.php b/phpgwapi/inc/class.common.inc.php index a48c6c701e..17d776f866 100644 --- a/phpgwapi/inc/class.common.inc.php +++ b/phpgwapi/inc/class.common.inc.php @@ -847,8 +847,10 @@ class common $img_types = array('png','jpg','gif','ico'); } $map = array(); - foreach($GLOBALS['egw_info']['apps'] as $app => $data) + foreach(scandir(EGW_SERVER_ROOT) as $app) { + if ($app[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app) || !file_exists(EGW_SERVER_ROOT.'/'.$app.'/templates')) continue; + $app_map =& $map[$app]; $app_map = array(); $imagedirs = array(); @@ -884,20 +886,37 @@ class common { foreach(egw_vfs::find($dir) as $img) { - if ($img[0] == '.' || !in_array($ext = self::get_extension($img, $name), $img_types) || empty($name)) continue; + if (!in_array($ext = self::get_extension($img, $name), $img_types) || empty($name)) continue; if (!isset($app_map[$name]) || array_search($ext, $img_types) < array_search(self::get_extension($app_map[$name]), $img_types)) { - $app_map[$name] = egw_vfs::download_url($dir.'/'.$img); + $app_map[$name] = egw_vfs::download_url($img); } } } //error_log(__METHOD__."('$template_set') took ".(microtime(true)-$starttime).' secs'); egw_cache::setInstance(__CLASS__, 'image_map_'.$template_set, $map, 86400); // cache for one day - + //echo "

template_set=".array2string($template_set)."

\n"; _debug_array($map); return $map; } + /** + * Delete image map cache for ALL template sets + */ + public static function delete_image_map() + { + $templates = array('idots', 'jerryr', 'jdots'); + if (($template_set = $GLOBALS['egw_info']['user']['preferences']['common']['template_set']) && !in_array($template_set, $templates)) + { + $templates[] = $template_set; + } + error_log(__METHOD__."() for templates ".array2string($templates)); + foreach($templates as $template_set) + { + egw_cache::unsetInstance(__CLASS__, 'image_map_'.$template_set); + } + } + /** * Get extension (and optional basename without extension) of a given path * diff --git a/setup/inc/class.setup_process.inc.php b/setup/inc/class.setup_process.inc.php index 8f944537b9..8cf24fdbf7 100755 --- a/setup/inc/class.setup_process.inc.php +++ b/setup/inc/class.setup_process.inc.php @@ -60,6 +60,9 @@ class setup_process function init_process() { $GLOBALS['egw_setup']->oProc = new schema_proc(); + + // delete image-map, in case new apps get installed, or existing ones updated + common::delete_image_map(); } /**