2011-08-21 22:09:14 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2016-04-06 21:57:40 +02:00
|
|
|
* API: loading translation from server
|
2011-08-21 22:09:14 +02:00
|
|
|
*
|
2016-05-05 11:31:54 +02:00
|
|
|
* Usage:
|
|
|
|
* - /egroupware/api/lang.php?app=infolog&lang=de
|
|
|
|
* - /egroupware/api/lang.php?app=infolog&lang=de&debug=1 gives pretty-printed JSON
|
2011-08-21 22:09:14 +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-21 22:09:14 +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-01 10:30:49 +01:00
|
|
|
// just to be sure, noone tries something nasty ...
|
|
|
|
if (!preg_match('/^[a-z0-9_]+$/i', $_GET['app'])) die('No valid application-name given!');
|
|
|
|
if (!preg_match('/^[a-z]{2}(-[a-z]{2})?$/i', $_GET['lang'])) die('No valid lang-name given!');
|
|
|
|
|
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-21 22:09:14 +02:00
|
|
|
$GLOBALS['egw_info'] = array(
|
|
|
|
'flags' => array(
|
2016-04-06 21:57:40 +02:00
|
|
|
'currentapp' => 'api',
|
2011-08-21 22:09:14 +02:00
|
|
|
'noheader' => true,
|
|
|
|
'load_translations' => false, // do not automatically load translations
|
|
|
|
'nocachecontrol' => true,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2014-02-17 09:53:55 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
include('../header.inc.php');
|
|
|
|
}
|
2016-04-06 21:57:40 +02:00
|
|
|
catch (\EGroupware\Api\Exception\NoPermission\App $e)
|
2014-02-17 09:53:55 +01:00
|
|
|
{
|
|
|
|
// ignore missing run rights for an app, as translations of other apps are loaded sometimes without run rights
|
|
|
|
}
|
2011-08-21 22:09:14 +02:00
|
|
|
|
|
|
|
// use an etag with app, lang and a hash over the creation-times of all lang-files
|
2016-04-06 21:57:40 +02:00
|
|
|
$etag = '"'.$_GET['app'].'-'.$_GET['lang'].'-'. Api\Translation::etag($_GET['app'], $_GET['lang']).'"';
|
2014-01-09 16:32:07 +01:00
|
|
|
|
2014-01-18 18:43:15 +01:00
|
|
|
// headers to allow caching, we specify etag on url to force reload, even with Expires header
|
2016-04-06 21:57:40 +02:00
|
|
|
Api\Session::cache_control(864000); // cache for 10 days
|
2016-05-05 11:31:54 +02:00
|
|
|
Header('Content-Type: '.(empty($_GET['debug'])?'text/javascript':'application/json').'; charset=utf-8');
|
2011-08-21 22:09:14 +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-21 22:09:14 +02:00
|
|
|
}
|
|
|
|
|
2016-04-06 21:57:40 +02:00
|
|
|
Api\Translation::init(false);
|
|
|
|
Api\Translation::add_app($_GET['app'], $_GET['lang']);
|
|
|
|
if (!count(Api\Translation::$lang_arr))
|
2011-08-21 22:09:14 +02:00
|
|
|
{
|
2016-04-06 21:57:40 +02:00
|
|
|
Api\Translation::add_app($_GET['app'], 'en');
|
2011-08-21 22:09:14 +02:00
|
|
|
}
|
|
|
|
|
2014-05-27 14:11:09 +02:00
|
|
|
// fix for phrases containing \n
|
2016-05-05 11:31:54 +02:00
|
|
|
$content = str_replace('\\\\n', '\\n', json_encode(Api\Translation::$lang_arr,
|
|
|
|
JSON_UNESCAPED_UNICODE | // send utf-8 unencoded, smaller and better readable
|
|
|
|
JSON_UNESCAPED_SLASHES | // do not escape slashes, smaller and better readable
|
|
|
|
(!empty($_GET['debug']) ? JSON_PRETTY_PRINT : 0)));
|
|
|
|
|
|
|
|
if (empty($_GET['debug'])) $content = 'egw.set_lang_arr("'.$_GET['app'].'", '.$content.', egw && egw.window !== window);';
|
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-21 22:09:14 +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;
|