mv template specific images from "phpgwapi" to "api" and search "api" also on client-side for image, added debug GET parameter to images.php to JSON pretty-print instead of one line javascript

This commit is contained in:
Ralf Becker 2016-05-05 09:16:27 +00:00
parent d3418d5ca3
commit 5353072052
3 changed files with 15 additions and 5 deletions

View File

@ -2,7 +2,9 @@
/** /**
* API: loading available images by application and image-name (without extension) * API: loading available images by application and image-name (without extension)
* *
* Usage: /egroupware/api/images.php?template=idots * Usage:
* - /egroupware/api/images.php?template=idots
* - /egroupware/api/images.php?template=pixelegg&debug=1 gives pretty-printed JSON
* *
* @link www.egroupware.org * @link www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de> * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
@ -26,14 +28,17 @@ $GLOBALS['egw_info'] = array(
include '../header.inc.php'; include '../header.inc.php';
$content = json_encode(Api\Image::map(preg_match('/^[a-z0-9_-]+$/i',$_GET['template']) ? $_GET['template'] : null, $_GET['svg'])); $content = json_encode(Api\Image::map(preg_match('/^[a-z0-9_-]+$/i',$_GET['template']) ? $_GET['template'] : null, $_GET['svg']),
JSON_FORCE_OBJECT | // export empty php-arrays as empty objects, not empty arrays
JSON_UNESCAPED_SLASHES | // do not escape slashes, smaller and better readable
(!empty($_GET['debug']) ? JSON_PRETTY_PRINT : 0));
// use an etag over the image mapp // use an etag over the image mapp
$etag = '"'.md5($content).'"'; $etag = '"'.md5($content).'"';
// headers to allow caching, egw_framework specifies etag on url to force reload, even with Expires header // headers to allow caching, egw_framework specifies etag on url to force reload, even with Expires header
Api\Session::cache_control(86400); // cache for one day Api\Session::cache_control(86400); // cache for one day
Header('Content-Type: text/javascript; charset=utf-8'); Header('Content-Type: '.(empty($_GET['debug'])?'text/javascript':'application/json').'; charset=utf-8');
Header('ETag: '.$etag); Header('ETag: '.$etag);
// if servers send a If-None-Match header, response with 304 Not Modified, if etag matches // if servers send a If-None-Match header, response with 304 Not Modified, if etag matches
@ -43,7 +48,7 @@ if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $
exit; exit;
} }
$content = 'egw.set_images('.$content.", egw && egw.window !== window);\n"; if (empty($_GET['debug'])) $content = 'egw.set_images('.$content.", egw && egw.window !== window);\n";
// we run our own gzip compression, to set a correct Content-Length of the encoded content // we run our own gzip compression, to set a correct Content-Length of the encoded content
if (in_array('gzip', explode(',',$_SERVER['HTTP_ACCEPT_ENCODING'])) && function_exists('gzencode')) if (in_array('gzip', explode(',',$_SERVER['HTTP_ACCEPT_ENCODING'])) && function_exists('gzencode'))

View File

@ -97,6 +97,11 @@ egw.extend('images', egw.MODULE_GLOBAL, function()
{ {
return this.webserverUrl+images[_app][_name]; return this.webserverUrl+images[_app][_name];
} }
tries['api'] = _name;
if (typeof images['api'] != 'undefined' && typeof images['api'][_name] == 'string')
{
return this.webserverUrl+images['api'][_name];
}
tries['phpgwapi'] = _name; tries['phpgwapi'] = _name;
if (typeof images['phpgwapi'] != 'undefined' && typeof images['phpgwapi'][_name] == 'string') if (typeof images['phpgwapi'] != 'undefined' && typeof images['phpgwapi'][_name] == 'string')
{ {

View File

@ -166,7 +166,7 @@ class Image
{ {
$imagedirs[] = '/'.$app.'/templates/mobile/images'; $imagedirs[] = '/'.$app.'/templates/mobile/images';
} }
if ($app == 'phpgwapi') if ($app == 'api')
{ {
$imagedirs[] = $GLOBALS['egw']->framework->template_dir.'/images'; $imagedirs[] = $GLOBALS['egw']->framework->template_dir.'/images';
} }