From ea7ad6318d5763829b8ee078a3622b1a46c74a68 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 30 Aug 2011 22:19:38 +0000 Subject: [PATCH] new clientside image-name to url map: egw.image(_name, _app="phpgwapi") eg. egw.image('favicon') returns '/egroupware/phpgwapi/templates/default/favicon.ico' --> pondon to serverside common::image($app,$name) method --- phpgwapi/images.php | 45 +++++++++++++++++++ phpgwapi/inc/class.egw_framework.inc.php | 1 + phpgwapi/js/jsapi/egw.js | 43 ++++++++++++++++++ .../idots/class.idots_framework.inc.php | 1 + 4 files changed, 90 insertions(+) create mode 100644 phpgwapi/images.php diff --git a/phpgwapi/images.php b/phpgwapi/images.php new file mode 100644 index 0000000000..7f221d88fd --- /dev/null +++ b/phpgwapi/images.php @@ -0,0 +1,45 @@ + + * @package phpgwapi + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ + +$GLOBALS['egw_info'] = array( + 'flags' => array( + 'currentapp' => 'home', + 'noheader' => true, + 'nocachecontrol' => true, + ) +); + +include '../header.inc.php'; + +$image_map = common::image_map(preg_match('/^[a-z0-9_-]+$/i',$_GET['template']) ? $_GET['template'] : null); + +// use an etag over the image mapp +$etag = '"'.md5(serialize($image_map)).'"'; + +// headers to allow caching +Header('Content-Type: text/javascript; charset=utf-8'); +Header('Cache-Control: public, no-transform'); +Header('Pragma: cache'); +Header('ETag: '.$etag); + +// if servers send a If-None-Match header, response with 304 Not Modified, if etag matches +if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) +{ + header("HTTP/1.1 304 Not Modified"); + common::egw_exit(); +} + +echo 'egw.set_images('.json_encode($image_map).");\n"; + +// Content-Lenght header is important, otherwise browsers dont cache! +Header('Content-Length: '.ob_get_length()); \ No newline at end of file diff --git a/phpgwapi/inc/class.egw_framework.inc.php b/phpgwapi/inc/class.egw_framework.inc.php index 7211d2aa5c..b100c9efb2 100644 --- a/phpgwapi/inc/class.egw_framework.inc.php +++ b/phpgwapi/inc/class.egw_framework.inc.php @@ -768,6 +768,7 @@ abstract class egw_framework if ($GLOBALS['egw_info']['flags']['js_link_registry']) { self::validate_file('/phpgwapi/config.php'); + self::validate_file('/phpgwapi/images.php',array('template' => $GLOBALS['egw_info']['user']['preferences']['common']['template_set'])); } $java_script .= self::get_script_links(); diff --git a/phpgwapi/js/jsapi/egw.js b/phpgwapi/js/jsapi/egw.js index 1856205e30..6d379f71bd 100644 --- a/phpgwapi/js/jsapi/egw.js +++ b/phpgwapi/js/jsapi/egw.js @@ -308,6 +308,49 @@ else set_configs: function(_configs) { this.configs = _configs; + }, + + /** + * Map to serverside available images for users template-set + */ + images: {}, + + /** + * Set imagemap, called from /phpgwapi/images.php + * + * @param array/object _images + */ + set_images: function (_images) + { + this.images = _images; + }, + + /** + * Get image URL for a given image-name and application + * + * @param string _name image-name without extension + * @param string _app application name, default phpgwapi + * @return string with URL of image + */ + image: function (_name, _app) + { + if (typeof _app == 'undefined') _app = 'phpgwapi'; + + // own instance specific images in vfs have highest precedence + if (typeof this.images['vfs'] != 'undefined' && typeof this.images['vfs'][_name] != 'undefined') + { + return this.webserverUrl+this.images['vfs'][_name]; + } + if (typeof this.images[_app] != 'undefined' && typeof this.images[_app][_name] != 'undefined') + { + return this.webserverUrl+this.images[_app][_name]; + } + if (typeof this.images['phpgwapi'] != 'undefined' && typeof this.images['phpgwapi'][_name] != 'undefined') + { + return this.webserverUrl+this.images['vfs'][_name]; + } + console.log('egw.image("'+_name+'", "'+_app+'") image NOT found!'); + return null; } }; } diff --git a/phpgwapi/templates/idots/class.idots_framework.inc.php b/phpgwapi/templates/idots/class.idots_framework.inc.php index cebcfec41b..a318915497 100644 --- a/phpgwapi/templates/idots/class.idots_framework.inc.php +++ b/phpgwapi/templates/idots/class.idots_framework.inc.php @@ -164,6 +164,7 @@ class idots_framework extends egw_framework if (!isset($GLOBALS['egw_info']['flags']['js_link_registry'])) { self::validate_file('/phpgwapi/config.php'); + self::validate_file('/phpgwapi/images.php',array('template' => $GLOBALS['egw_info']['user']['preferences']['common']['template_set'])); $content .= ''."\n";