moving client-data urls to api

This commit is contained in:
Ralf Becker 2016-04-06 19:57:40 +00:00
parent 5d72bbfc1c
commit 341a56dc3d
9 changed files with 56 additions and 46 deletions

View File

@ -2,21 +2,23 @@
/**
* API: loading categories and setting styles
*
* Usage: /egroupware/phpgwapi/categories.php[?app=calendar]
* Usage: /egroupware/api/categories.php[?app=calendar]
*
* @link www.egroupware.org
* @author Nathan Gray
* @package API
* @package api
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
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(
'currentapp' => 'home',
'currentapp' => 'api',
'noheader' => true,
'nocachecontrol' => true,
)
@ -25,10 +27,10 @@ $GLOBALS['egw_info'] = array(
include '../header.inc.php';
// Get appname
$appname = $_GET['app'] && $GLOBALS['egw_info']['apps'][$_GET['app']] ? $_GET['app'] : categories::GLOBAL_APPNAME;
$appname = $_GET['app'] && $GLOBALS['egw_info']['apps'][$_GET['app']] ? $_GET['app'] : Api\Categories::GLOBAL_APPNAME;
$cats = new categories('', $appname);
$categories = $cats->return_array('all',0, false, '', 'ASC','',$appname==categories::GLOBAL_APPNAME);
$cats = new Api\Categories('', $appname);
$categories = $cats->return_array('all',0, false, '', 'ASC','',$appname==Api\Categories::GLOBAL_APPNAME);
$content = "/* Category CSS for $appname */\n\n";
@ -50,7 +52,7 @@ foreach($categories as $cat)
$etag = '"'.md5($content).'"';
// headers to allow caching, egw_framework specifies etag on url to force reload, even with Expires header
egw_session::cache_control(86400); // cache for 1 day
Api\Session::cache_control(86400); // cache for 1 day
Header('Content-Type: text/css; charset=utf-8');
Header('ETag: '.$etag);
@ -58,7 +60,7 @@ Header('ETag: '.$etag);
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag)
{
header("HTTP/1.1 304 Not Modified");
common::egw_exit();
exit;
}
// we run our own gzip compression, to set a correct Content-Length of the encoded content

View File

@ -1,22 +1,24 @@
<?php
/**
* API: loading translation from from browser
* API: loading configuratino from server
*
* Usage: /egroupware/phpgwapi/lang.php?app=infolog&lang=de
* Usage: /egroupware/api/config.php
*
* @link www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @package addressbook
* @package api
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
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(
'currentapp' => 'home',
'currentapp' => 'api',
'noheader' => true,
'nocachecontrol' => true,
)
@ -25,12 +27,12 @@ $GLOBALS['egw_info'] = array(
include '../header.inc.php';
// use an etag over config and link-registry
$config = json_encode(config::clientConfigs());
$link_registry = egw_link::json_registry();
$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
egw_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('ETag: '.$etag);
@ -38,7 +40,7 @@ Header('ETag: '.$etag);
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag)
{
header("HTTP/1.1 304 Not Modified");
common::egw_exit();
exit;
}
$content = 'egw.set_configs('.$config.", egw && egw.window !== window);\n";

View File

@ -2,21 +2,23 @@
/**
* API: loading available images by application and image-name (without extension)
*
* Usage: /egroupware/phpgwapi/images.php?template=idots
* Usage: /egroupware/api/images.php?template=idots
*
* @link www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @package phpgwapi
* @package api
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
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(
'currentapp' => 'home',
'currentapp' => 'api',
'noheader' => true,
'nocachecontrol' => true,
)
@ -24,13 +26,13 @@ $GLOBALS['egw_info'] = array(
include '../header.inc.php';
$content = json_encode(common::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']));
// use an etag over the image mapp
$etag = '"'.md5($content).'"';
// headers to allow caching, egw_framework specifies etag on url to force reload, even with Expires header
egw_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('ETag: '.$etag);
@ -38,7 +40,7 @@ Header('ETag: '.$etag);
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag)
{
header("HTTP/1.1 304 Not Modified");
common::egw_exit();
exit;
}
$content = 'egw.set_images('.$content.", egw && egw.window !== window);\n";

View File

@ -1,16 +1,18 @@
<?php
/**
* API: loading translation from from browser
* API: loading translation from server
*
* Usage: /egroupware/phpgwapi/lang.php?app=infolog&lang=de
* Usage: /egroupware/api/lang.php?app=infolog&lang=de
*
* @link www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @package addressbook
* @package api
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
use EGroupware\Api;
// 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!');
@ -20,7 +22,7 @@ ini_set('zlib.output_compression', 0);
$GLOBALS['egw_info'] = array(
'flags' => array(
'currentapp' => 'home',
'currentapp' => 'api',
'noheader' => true,
'load_translations' => false, // do not automatically load translations
'nocachecontrol' => true,
@ -31,16 +33,16 @@ try
{
include('../header.inc.php');
}
catch (egw_exception_no_permission_app $e)
catch (\EGroupware\Api\Exception\NoPermission\App $e)
{
// ignore missing run rights for an app, as translations of other apps are loaded sometimes without run rights
}
// use an etag with app, lang and a hash over the creation-times of all lang-files
$etag = '"'.$_GET['app'].'-'.$_GET['lang'].'-'.translation::etag($_GET['app'], $_GET['lang']).'"';
$etag = '"'.$_GET['app'].'-'.$_GET['lang'].'-'. Api\Translation::etag($_GET['app'], $_GET['lang']).'"';
// headers to allow caching, we specify etag on url to force reload, even with Expires header
egw_session::cache_control(864000); // cache for 10 days
Api\Session::cache_control(864000); // cache for 10 days
Header('Content-Type: text/javascript; charset=utf-8');
Header('ETag: '.$etag);
@ -48,18 +50,18 @@ Header('ETag: '.$etag);
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag)
{
header("HTTP/1.1 304 Not Modified");
common::egw_exit();
exit;
}
translation::init(false);
translation::add_app($_GET['app'], $_GET['lang']);
if (!count(translation::$lang_arr))
Api\Translation::init(false);
Api\Translation::add_app($_GET['app'], $_GET['lang']);
if (!count(Api\Translation::$lang_arr))
{
translation::add_app($_GET['app'], 'en');
Api\Translation::add_app($_GET['app'], 'en');
}
// fix for phrases containing \n
$content = 'egw.set_lang_arr("'.$_GET['app'].'", '.str_replace('\\\\n', '\\n', json_encode(translation::$lang_arr)).', egw && egw.window !== window);';
$content = 'egw.set_lang_arr("'.$_GET['app'].'", '.str_replace('\\\\n', '\\n', json_encode(Api\Translation::$lang_arr)).', egw && egw.window !== window);';
// 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'))

View File

@ -1039,7 +1039,7 @@ class Categories
$cats = new Categories('',$appname);
$last_mod = $cats->return_array('all',0,1,'','DESC','last_mod', $appname == self::GLOBAL_APPNAME);
$time = count($last_mod) ? $last_mod[0]['last_mod'] : time();
$path = '/phpgwapi/categories.php?app='.$appname.'&'.$time;
$path = '/api/categories.php?app='.$appname.'&'.$time;
egw_framework::includeCSS($path);
return $path;

View File

@ -2,21 +2,23 @@
/**
* API: loading user preferences and data
*
* Usage: /egroupware/phpgwapi/lang.php?user=123
* Usage: /egroupware/api/user.php?user=123
*
* @link www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @package addressbook
* @package api
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
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(
'currentapp' => 'home',
'currentapp' => 'api',
'noheader' => true,
'nocachecontrol' => true,
)
@ -31,7 +33,7 @@ $user = $GLOBALS['egw']->accounts->json($GLOBALS['egw_info']['user']['account_id
$etag = '"'.md5($preferences.$ab_preferences.$user).'"';
// headers to allow caching, egw_framework specifies etag on url to force reload, even with Expires header
egw_session::cache_control(86400); // cache for 1 day
Api\Session::cache_control(86400); // cache for 1 day
Header('Content-Type: text/javascript; charset=utf-8');
Header('ETag: '.$etag);
@ -39,7 +41,7 @@ Header('ETag: '.$etag);
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag)
{
header("HTTP/1.1 304 Not Modified");
common::egw_exit();
exit;
}
$content = 'egw.set_preferences('.$preferences.", 'common', egw && egw.window !== window);\n";

View File

@ -1425,15 +1425,15 @@ abstract class egw_framework
// specifying etag in url to force reload, as we send expires header
if ($GLOBALS['egw_info']['flags']['js_link_registry'])
{
self::validate_file('/phpgwapi/config.php', array(
self::validate_file('/api/config.php', array(
'etag' => md5(json_encode(config::clientConfigs()).egw_link::json_registry()),
));
self::validate_file('/phpgwapi/images.php', array(
self::validate_file('/api/images.php', array(
'template' => $GLOBALS['egw_info']['server']['template_set'],
'etag' => md5(json_encode(common::image_map($GLOBALS['egw_info']['server']['template_set']))),
'svg' => html::$ua_mobile, // always load non-svg image map, ATM we use svg icons only for mobile theme
));
self::validate_file('/phpgwapi/user.php', array(
self::validate_file('/api/user.php', array(
'user' => $GLOBALS['egw_info']['user']['account_lid'],
'lang' => $GLOBALS['egw_info']['user']['preferences']['common']['lang'],
// add etag on url, so we can set an expires header

View File

@ -44,7 +44,7 @@ egw.extend('images', egw.MODULE_GLOBAL, function()
return {
/**
* Set imagemap, called from /phpgwapi/images.php
* Set imagemap, called from /api/images.php
*
* @param {array|object} _images
* @param {boolean} _need_clone _images need to be cloned, as it is from different window context

View File

@ -147,7 +147,7 @@ egw.extend('lang', egw.MODULE_GLOBAL, function()
if (typeof lang_arr[_apps[i].app] === "undefined")
{
jss.push(this.webserverUrl +
'/phpgwapi/lang.php?app=' + _apps[i].app +
'/api/lang.php?app=' + _apps[i].app +
'&lang=' + _apps[i].lang +
'&etag=' + (_apps[i].etag || this.config('max_lang_time')));
}