2011-08-31 00:19:38 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* API: loading available images by application and image-name (without extension)
|
|
|
|
*
|
2016-05-05 11:16:27 +02:00
|
|
|
* Usage:
|
|
|
|
* - /egroupware/api/images.php?template=idots
|
|
|
|
* - /egroupware/api/images.php?template=pixelegg&debug=1 gives pretty-printed JSON
|
2011-08-31 00:19:38 +02:00
|
|
|
*
|
|
|
|
* @link www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2016-04-06 21:57:40 +02:00
|
|
|
* @package api
|
2011-08-31 00:19:38 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2016-04-06 21:57:40 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
|
2012-03-19 09:35:47 +01:00
|
|
|
// switch evtl. set output-compression off, as we cant calculate a Content-Length header with transparent compression
|
|
|
|
ini_set('zlib.output_compression', 0);
|
|
|
|
|
2011-08-31 00:19:38 +02:00
|
|
|
$GLOBALS['egw_info'] = array(
|
|
|
|
'flags' => array(
|
2016-04-06 21:57:40 +02:00
|
|
|
'currentapp' => 'api',
|
2011-08-31 00:19:38 +02:00
|
|
|
'noheader' => true,
|
|
|
|
'nocachecontrol' => true,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
include '../header.inc.php';
|
|
|
|
|
2019-03-06 13:04:20 +01:00
|
|
|
$content = json_encode(Api\Image::map(preg_match('/^[a-z0-9_-]+$/i',$_GET['template']) ? $_GET['template'] : null),
|
2016-05-05 11:16:27 +02:00
|
|
|
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));
|
2011-08-31 00:19:38 +02:00
|
|
|
|
|
|
|
// use an etag over the image mapp
|
2014-01-18 18:43:15 +01:00
|
|
|
$etag = '"'.md5($content).'"';
|
2011-08-31 00:19:38 +02:00
|
|
|
|
2014-01-18 18:43:15 +01:00
|
|
|
// headers to allow caching, egw_framework specifies etag on url to force reload, even with Expires header
|
2016-04-06 21:57:40 +02:00
|
|
|
Api\Session::cache_control(86400); // cache for one day
|
2016-05-05 11:16:27 +02:00
|
|
|
Header('Content-Type: '.(empty($_GET['debug'])?'text/javascript':'application/json').'; charset=utf-8');
|
2011-08-31 00:19:38 +02:00
|
|
|
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");
|
2016-04-06 21:57:40 +02:00
|
|
|
exit;
|
2011-08-31 00:19:38 +02:00
|
|
|
}
|
|
|
|
|
2021-06-05 20:39:39 +02:00
|
|
|
if (empty($_GET['debug'])) $content = "import './js/jsapi/egw_images.js';\n\nwindow.egw.set_images(".$content.", window.egw && window.egw.window !== window);\n";
|
2012-03-19 09:35:47 +01:00
|
|
|
|
|
|
|
// 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'))
|
|
|
|
{
|
|
|
|
$content = gzencode($content);
|
|
|
|
header('Content-Encoding: gzip');
|
|
|
|
}
|
2011-08-31 00:19:38 +02:00
|
|
|
|
|
|
|
// Content-Lenght header is important, otherwise browsers dont cache!
|
2012-03-19 09:35:47 +01:00
|
|
|
Header('Content-Length: '.bytes($content));
|
|
|
|
echo $content;
|