include user-data and common prefs like we already do it with eg. server config

This commit is contained in:
Ralf Becker 2013-07-19 15:22:00 +00:00
parent 35ce67f62b
commit f55a668bdf
2 changed files with 60 additions and 9 deletions

View File

@ -834,24 +834,18 @@ abstract class egw_framework
{
$java_script .= $GLOBALS['egw_info']['flags']['java_script_thirst'] . "\n";
}
// add configuration and link-registry for non-popup windows
// add configuration, link-registry, images, user-data and -perferences for non-popup windows
if ($GLOBALS['egw_info']['flags']['js_link_registry'])
{
self::validate_file('/phpgwapi/config.php');
self::validate_file('/phpgwapi/images.php',array('template' => $GLOBALS['egw_info']['user']['preferences']['common']['template_set']));
self::validate_file('/phpgwapi/user.php',array('user' => $GLOBALS['egw_info']['user']['account_lid']));
}
$extra['url'] = $GLOBALS['egw_info']['server']['webserver_url'];
$extra['include'] = array_map(function($str){return substr($str,1);}, self::get_script_links(true), array(1));
$extra['app'] = $GLOBALS['egw_info']['flags']['currentapp'];
// 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'])
{
$extra['preferences'] = array('common' => $GLOBALS['egw_info']['user']['preferences']['common']);
$extra['user'] = $GLOBALS['egw']->accounts->json($GLOBALS['egw_info']['user']['account_id']);
}
// Load LABjs ONCE here
$java_script .= '<script type="text/javascript" src="'. $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/js/labjs/LAB.src.js"'." ></script>\n".
'<script type="text/javascript" src="'. $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/js/jsapi/egw.js" id="egw_script_id"';
@ -1267,7 +1261,7 @@ abstract class egw_framework
$files = '';
$to_include = $to_minify = array();
$max_modified = 0;
foreach(self::$js_include_mgr->get_included_files() as $path)
foreach(self::$js_include_mgr->get_included_files($clear_files) as $path)
{
$query = '';
list($path,$query) = explode('?',$path,2);

57
phpgwapi/user.php Normal file
View File

@ -0,0 +1,57 @@
<?php
/**
* API: loading user preferences and data
*
* Usage: /egroupware/phpgwapi/lang.php?user=123
*
* @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$
*/
// 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',
'noheader' => true,
'nocachecontrol' => true,
)
);
include '../header.inc.php';
// use an etag over config and link-registry
$preferences = json_encode($GLOBALS['egw_info']['user']['preferences']['common']);
$user = $GLOBALS['egw']->accounts->json($GLOBALS['egw_info']['user']['account_id']);
$etag = '"'.md5($preferences.$user).'"';
// 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();
}
$content = 'egw.set_preferences('.$preferences.", 'common');\n";
$content .= 'egw.set_user('.$user.");\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;