mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-08 00:54:15 +01:00
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
This commit is contained in:
parent
dce02a03cb
commit
ea7ad6318d
45
phpgwapi/images.php
Normal file
45
phpgwapi/images.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* API: loading available images by application and image-name (without extension)
|
||||
*
|
||||
* Usage: /egroupware/phpgwapi/images.php?template=idots
|
||||
*
|
||||
* @link www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @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());
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -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 .= '<script type="text/javascript">
|
||||
egw.set_preferences('.json_encode($GLOBALS['egw_info']['user']['preferences']['common']).', "common");
|
||||
</script>'."\n";
|
||||
|
Loading…
Reference in New Issue
Block a user