start.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. elgg_register_event_handler('init', 'system', 'file_takeout_init');
  3. $show_site_menu = elgg_get_plugin_setting('file_takeout_site_menu');
  4. if ($show_site_menu == 'yes') {
  5. $menu_item = new ElggMenuItem('File Takeout', elgg_echo('File Takeout'), 'file_takeout');
  6. elgg_register_menu_item('site', $menu_item);
  7. }
  8. elgg_register_event_handler('pagesetup', 'system', 'file_takeout_plugin_pagesetup');
  9. function file_takeout_init() {
  10. elgg_register_page_handler('file_takeout','page_handler_file_takeout');
  11. elgg_register_page_handler('file_takeout_download', 'page_handler_file_takeout_download');
  12. }
  13. function page_handler_file_takeout($page) {
  14. include elgg_get_plugins_path() . 'file_takeout/file_takeout.php';
  15. }
  16. /**
  17. * Download the Archive ZIP to computer
  18. */
  19. function page_handler_file_takeout_download($page) {
  20. $file_guid = $page[0];
  21. $file_name = $file_guid.'.zip';
  22. $file_path = elgg_get_data_path();
  23. if (file_exists($file_path.$file_name)){
  24. $mime = "application/octet-stream";
  25. header("Pragma: public");
  26. header("Content-type: $mime");
  27. header("Content-Disposition: attachment; filename=\"$file_name\"");
  28. ob_clean();
  29. flush();
  30. readfile($file_path.$file_name);
  31. exit;
  32. } else {
  33. register_error(elgg_echo("file:downloadfailed"));
  34. forward('/file_takeout');
  35. }
  36. }
  37. /**
  38. * File Takeout user settings sidebar menu
  39. */
  40. function file_takeout_plugin_pagesetup() {
  41. if (elgg_in_context("settings") && elgg_get_logged_in_user_guid()) {
  42. $user = elgg_get_page_owner_entity();
  43. if (!$user) {
  44. $user = elgg_get_logged_in_user_entity();
  45. }
  46. if (elgg_is_active_plugin('file_takeout')) {
  47. $params = array(
  48. 'name' => 'file_takeout_link',
  49. 'text' => elgg_echo('File Takeout'),
  50. 'href' => "file_takeout",
  51. 'section' => "file_takeout",
  52. );
  53. elgg_register_menu_item('page', $params);
  54. }
  55. }
  56. }
  57. ?>