elgg.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Core Elgg JavaScript file
  4. */
  5. global $CONFIG;
  6. // this warning is due to the change in JS boot order in Elgg 1.9
  7. echo <<<JS
  8. if (typeof elgg != 'object') {
  9. throw new Error('elgg configuration object is not defined! You must include the js/initialize_elgg view in html head before JS library files!');
  10. }
  11. JS;
  12. $lib_dir = 'js/lib';
  13. $classes_dir = 'js/classes';
  14. $files = array(
  15. // these must come first
  16. 'vendors/sprintf',
  17. "$lib_dir/elgglib",
  18. // class definitions
  19. "$classes_dir/ElggEntity",
  20. "$classes_dir/ElggUser",
  21. "$classes_dir/ElggPriorityList",
  22. //libraries
  23. "$lib_dir/prototypes",
  24. "$lib_dir/hooks",
  25. "$lib_dir/security",
  26. "$lib_dir/languages",
  27. "$lib_dir/ajax",
  28. "$lib_dir/session",
  29. "$lib_dir/pageowner",
  30. "$lib_dir/configuration",
  31. "$lib_dir/comments",
  32. //ui
  33. "$lib_dir/ui",
  34. "$lib_dir/ui.widgets",
  35. );
  36. $root_path = elgg_get_root_path();
  37. foreach ($files as $file) {
  38. readfile("{$root_path}$file.js");
  39. // putting a new line between the files to address https://github.com/elgg/elgg/issues/3081
  40. echo "\n";
  41. }
  42. /**
  43. * Set some values that are cacheable
  44. */
  45. ?>
  46. //<script>
  47. elgg.version = '<?php echo elgg_get_version(); ?>';
  48. elgg.release = '<?php echo elgg_get_version(true); ?>';
  49. elgg.config.wwwroot = '<?php echo elgg_get_site_url(); ?>';
  50. // refresh token 3 times during its lifetime (in microseconds 1000 * 1/3)
  51. elgg.security.interval = <?php echo (int)_elgg_services()->actions->getActionTokenTimeout() * 333; ?>;
  52. elgg.config.language = '<?php echo (empty($CONFIG->language) ? 'en' : $CONFIG->language); ?>';
  53. !function () {
  54. define('elgg', ['jquery', 'languages/' + elgg.get_language()], function($, translations) {
  55. elgg.add_translation(elgg.get_language(), translations);
  56. $(function() {
  57. elgg.trigger_hook('init', 'system');
  58. elgg.trigger_hook('ready', 'system');
  59. });
  60. return elgg;
  61. });
  62. }();
  63. require(['elgg']); // Forces the define() function to always run
  64. <?php
  65. echo elgg_view_deprecated('js/initialise_elgg', array(), "Use the view js/elgg.", 1.8);
  66. ?>
  67. elgg.trigger_hook('boot', 'system');