egroupware_official/api/config.php

59 lines
1.9 KiB
PHP
Raw Normal View History

<?php
/**
2016-04-06 21:57:40 +02:00
* API: loading configuratino from server
*
2016-04-06 21:57:40 +02:00
* Usage: /egroupware/api/config.php
*
* @link www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
2016-04-06 21:57:40 +02:00
* @package api
* @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;
// switch evtl. set output-compression off, as we cant calculate a Content-Length header with transparent compression
ini_set('zlib.output_compression', 0);
$GLOBALS['egw_info'] = array(
'flags' => array(
2016-04-06 21:57:40 +02:00
'currentapp' => 'api',
'noheader' => true,
'nocachecontrol' => true,
)
);
include '../header.inc.php';
// use an etag over config and link-registry
2016-04-06 21:57:40 +02:00
$config = json_encode(Api\Config::clientConfigs());
$link_registry = Api\Link::json_registry();
$etag = '"'.md5($config.$link_registry).'"';
// 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
Header('Content-Type: text/javascript; charset=utf-8');
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;
}
$content = 'egw.set_configs('.$config.", window.egw && window.egw.window !== window);\n";
$content .= 'egw.set_link_registry('.$link_registry.", undefined, window.egw && window.egw.window !== window);\n";
// 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');
}
// Content-Lenght header is important, otherwise browsers dont cache!
Header('Content-Length: '.bytes($content));
echo $content;