aboutsummaryrefslogtreecommitdiff
path: root/views/default/js/initialize_elgg.php
diff options
context:
space:
mode:
Diffstat (limited to 'views/default/js/initialize_elgg.php')
-rw-r--r--views/default/js/initialize_elgg.php52
1 files changed, 52 insertions, 0 deletions
diff --git a/views/default/js/initialize_elgg.php b/views/default/js/initialize_elgg.php
new file mode 100644
index 000000000..b45c33463
--- /dev/null
+++ b/views/default/js/initialize_elgg.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Initialize Elgg's js lib with the uncacheable data
+ */
+
+if (0) { ?><script><?php }
+?>
+/**
+ * Don't want to cache these -- they could change for every request
+ */
+elgg.config.lastcache = <?php echo (int)elgg_get_config('lastcache'); ?>;
+elgg.config.viewtype = '<?php echo elgg_get_viewtype(); ?>';
+elgg.config.simplecache_enabled = <?php echo (int)elgg_is_simplecache_enabled(); ?>;
+
+elgg.security.token.__elgg_ts = <?php echo $ts = time(); ?>;
+elgg.security.token.__elgg_token = '<?php echo generate_action_token($ts); ?>';
+
+<?php
+// @todo json export should be smoother than this...
+// @todo Might also be nice to make url exportable. $entity->url? yes please!
+$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 = elgg_get_logged_in_user_entity();
+
+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();
+ $user_json['admin'] = $user->isAdmin();
+
+ echo 'elgg.session.user = new elgg.ElggUser(' . json_encode($user_json) . ');';
+}
+?>
+
+//Before the DOM is ready, but elgg's js framework is fully initalized
+elgg.trigger_hook('boot', 'system'); \ No newline at end of file