From be6fd87783974438245cfd576ecec3487f91121b Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 26 Aug 2011 16:27:57 +0000 Subject: [PATCH] - 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 --- phpgwapi/config.php | 46 +++++++++++++++++++ phpgwapi/inc/class.config.inc.php | 42 +++++++++++++++++ phpgwapi/inc/class.egw_framework.inc.php | 7 ++- .../idots/class.idots_framework.inc.php | 2 +- 4 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 phpgwapi/config.php diff --git a/phpgwapi/config.php b/phpgwapi/config.php new file mode 100644 index 0000000000..8a05efb378 --- /dev/null +++ b/phpgwapi/config.php @@ -0,0 +1,46 @@ + + * @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()); \ No newline at end of file diff --git a/phpgwapi/inc/class.config.inc.php b/phpgwapi/inc/class.config.inc.php index a423108522..8d6020cdcb 100755 --- a/phpgwapi/inc/class.config.inc.php +++ b/phpgwapi/inc/class.config.inc.php @@ -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 * diff --git a/phpgwapi/inc/class.egw_framework.inc.php b/phpgwapi/inc/class.egw_framework.inc.php index 8413b9ba99..7211d2aa5c 100644 --- a/phpgwapi/inc/class.egw_framework.inc.php +++ b/phpgwapi/inc/class.egw_framework.inc.php @@ -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 .= "\n"; diff --git a/phpgwapi/templates/idots/class.idots_framework.inc.php b/phpgwapi/templates/idots/class.idots_framework.inc.php index da190f3ef0..cebcfec41b 100644 --- a/phpgwapi/templates/idots/class.idots_framework.inc.php +++ b/phpgwapi/templates/idots/class.idots_framework.inc.php @@ -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 .= ''."\n"; }