initialize_elgg.php 1009 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Initialize Elgg's js lib with the uncacheable data
  4. */
  5. $elgg = array(
  6. 'config' => array(
  7. 'lastcache' => (int)elgg_get_config('lastcache'),
  8. 'viewtype' => elgg_get_viewtype(),
  9. 'simplecache_enabled' => (int)elgg_is_simplecache_enabled(),
  10. ),
  11. 'security' => array(
  12. 'token' => array(
  13. '__elgg_ts' => $ts = time(),
  14. '__elgg_token' => generate_action_token($ts),
  15. ),
  16. ),
  17. 'session' => array(
  18. 'user' => null,
  19. ),
  20. );
  21. $page_owner = elgg_get_page_owner_entity();
  22. if ($page_owner instanceof ElggEntity) {
  23. $elgg['page_owner'] = $page_owner->toObject();
  24. }
  25. $user = elgg_get_logged_in_user_entity();
  26. if ($user instanceof ElggUser) {
  27. $user_object = $user->toObject();
  28. $user_object->admin = $user->isAdmin();
  29. $elgg['session']['user'] = $user_object;
  30. }
  31. ?>
  32. var elgg = <?php echo json_encode($elgg); ?>;
  33. <?php
  34. // note: elgg.session.user needs to be wrapped with elgg.ElggUser, but this class isn't
  35. // defined yet. So this is delayed until after the classes are defined, in js/lib/session.js