mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-21 23:43:17 +01:00
- sending EGroupware configuration (non-sensible stuff) to browser and make it available via egw.config(_name, _app="phpgwapi")
- sending link-registry in the same file - used javascript file uses etag to ensure there's no need to load it on each request
This commit is contained in:
parent
389486793d
commit
be6fd87783
46
phpgwapi/config.php
Normal file
46
phpgwapi/config.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* API: loading translation from from browser
|
||||
*
|
||||
* Usage: /egroupware/phpgwapi/lang.php?app=infolog&lang=de
|
||||
*
|
||||
* @link www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @package addressbook
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
$GLOBALS['egw_info'] = array(
|
||||
'flags' => array(
|
||||
'currentapp' => 'home',
|
||||
'noheader' => true,
|
||||
'nocachecontrol' => true,
|
||||
)
|
||||
);
|
||||
|
||||
include '../header.inc.php';
|
||||
|
||||
// use an etag over config and link-registry
|
||||
$config = config::clientConfigs();
|
||||
$link_registry = egw_link::json_registry();
|
||||
$etag = '"'.md5(serialize($config).$link_registry).'"';
|
||||
|
||||
// headers to allow caching
|
||||
Header('Content-Type: text/javascript; charset=utf-8');
|
||||
Header('Cache-Control: public, no-transform');
|
||||
Header('Pragma: cache');
|
||||
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");
|
||||
common::egw_exit();
|
||||
}
|
||||
|
||||
echo 'egw.set_configs('.json_encode($config).");\n";
|
||||
echo 'egw.set_link_registry('.$link_registry.");\n";
|
||||
|
||||
// Content-Lenght header is important, otherwise browsers dont cache!
|
||||
Header('Content-Length: '.ob_get_length());
|
@ -279,6 +279,48 @@ class config
|
||||
return is_array($config['types']) ? $config['types'] : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return configuration for all apps, save to be transmitted to browser
|
||||
*
|
||||
* You can add further values to the white-list, but keep in mind they are publicly visible (eg. via anon user of sitemgr)!!!
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static public function clientConfigs()
|
||||
{
|
||||
static $white_list = array(
|
||||
'all' => array('customfields', 'types'),
|
||||
'phpgwapi' => array('webserver_url','server_timezone','enforce_ssl','system_charset',
|
||||
'checkfornewversion','checkappversions','email_address_format', // admin >> site config
|
||||
'site_title','login_logo_file','login_logo_url','login_logo_title','favicon_file',
|
||||
'markuntranslated','link_list_thumbnail','enabled_spellcheck',
|
||||
'call_link','call_popup', // addressbook
|
||||
'hide_birthdays'), // calendar
|
||||
'projectmanager' => array('hours_per_workday', 'duration_units'),
|
||||
'manual' => array('manual_remote_egw_url'),
|
||||
'infolog' => array('status'),
|
||||
'timesheet' => array('status_labels'),
|
||||
);
|
||||
if (!isset(self::$configs))
|
||||
{
|
||||
self::init_static();
|
||||
}
|
||||
$client_config = array();
|
||||
foreach(self::$configs as $app => $config)
|
||||
{
|
||||
foreach($config as $name => $value)
|
||||
{
|
||||
if (strpos($name, 'pass') !== false) continue;
|
||||
|
||||
if (in_array($name, $white_list['all']) || isset($white_list[$app]) && in_array($name, $white_list[$app]))
|
||||
{
|
||||
$client_config[$app][$name] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $client_config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise our db
|
||||
*
|
||||
|
@ -764,7 +764,11 @@ abstract class egw_framework
|
||||
{
|
||||
$java_script .= $GLOBALS['egw_info']['flags']['java_script_thirst'] . "\n";
|
||||
}
|
||||
|
||||
// add configuration and link-registry for non-popup windows
|
||||
if ($GLOBALS['egw_info']['flags']['js_link_registry'])
|
||||
{
|
||||
self::validate_file('/phpgwapi/config.php');
|
||||
}
|
||||
$java_script .= self::get_script_links();
|
||||
|
||||
// set webserver_url for json
|
||||
@ -776,7 +780,6 @@ abstract class egw_framework
|
||||
// add link registry to non-popup windows, if explicit requested (idots_framework::navbar() loads it, if not explicit specified!)
|
||||
if ($GLOBALS['egw_info']['flags']['js_link_registry'])
|
||||
{
|
||||
$java_script .= 'egw.set_link_registry('.egw_link::json_registry().");\n";
|
||||
$java_script .= 'egw.set_preferences('.json_encode($GLOBALS['egw_info']['user']['preferences']['common']).', "common");';
|
||||
}
|
||||
$java_script .= "</script>\n";
|
||||
|
@ -163,8 +163,8 @@ class idots_framework extends egw_framework
|
||||
// add link registry to non-popup windows
|
||||
if (!isset($GLOBALS['egw_info']['flags']['js_link_registry']))
|
||||
{
|
||||
self::validate_file('/phpgwapi/config.php');
|
||||
$content .= '<script type="text/javascript">
|
||||
egw.set_link_registry('.egw_link::json_registry().');
|
||||
egw.set_preferences('.json_encode($GLOBALS['egw_info']['user']['preferences']['common']).', "common");
|
||||
</script>'."\n";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user