aboutsummaryrefslogtreecommitdiff
path: root/views/default/js/initialize_elgg.php
blob: 6a82b879e219c837c9a5a66b884b0ff327e440c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php 
/**
 * 
 */

?>
<script type="text/javascript">
/**
 * Don't want to cache these -- they could change for every request
 */
elgg.config.lastcache = <?php echo (int)elgg_get_config('lastcache'); ?>;

elgg.security.token.__elgg_ts = <?php echo $ts = time(); ?>;
elgg.security.token.__elgg_token = '<?php echo generate_action_token($ts); ?>';

<?php
$page_owner = elgg_get_page_owner_entity();

if ($page_owner instanceof ElggEntity) {
	$page_owner_json = array();
	foreach ($page_owner->getExportableValues() as $v) {
		$page_owner_json[$v] = $page_owner->$v;
	}
	
	$page_owner_json['subtype'] = $page_owner->getSubtype();
	$page_owner_json['url'] = $page_owner->getURL();
	
	echo 'elgg.page_owner =  '.json_encode($page_owner_json).';'; 
}

$user = get_loggedin_user();

if ($user instanceof ElggUser) {
	$user_json = array();
	foreach ($user->getExportableValues() as $v) {
		$user_json[$v] = $user->$v;
	}
	
	$user_json['subtype'] = $user->getSubtype();
	$user_json['url'] = $user->getURL();
	
	echo 'elgg.session.user = new elgg.ElggUser('.json_encode($user_json).');'; 
}
?>;
</script>