list.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /*
  3. * Display List of backups
  4. *
  5. */
  6. elgg_load_js('lightbox');
  7. elgg_load_css('lightbox');
  8. //get path to default backup dir specified in plugin settings
  9. $backup_dir = elgg_get_plugin_setting('backup_dir', 'backup-tool');
  10. if (!$backup_dir || !file_exists($backup_dir)) {
  11. echo '<p><b>' . elgg_echo('backup-tool:bad_backup_dir') . '</b></p>';
  12. } else {
  13. echo '<div class="elgg-head">';
  14. //display button for create a new backup
  15. echo elgg_view('output/url', array(
  16. 'text' => elgg_echo('backup-tool:create'),
  17. 'href' => elgg_get_site_url() . "ajax/view/backup-tool/create-backup", //elgg_add_action_tokens_to_url(elgg_get_site_url() . 'action/backup-tool/create'),
  18. 'class' => 'elgg-lightbox elgg-button elgg-button-submit'
  19. ));
  20. //button for Shadule a backup
  21. echo elgg_view('output/url', array(
  22. 'text' => elgg_echo('admin:backups:schedule'),
  23. 'href' => elgg_get_site_url() . 'admin/backups/schedule',
  24. 'class' => 'elgg-button elgg-button-submit'
  25. ));
  26. //button for backup settings
  27. echo elgg_view('output/url', array(
  28. 'text' => elgg_echo('admin:backups:settings'),
  29. 'href' => elgg_get_site_url() . 'admin/plugin_settings/backup-tool',
  30. 'class' => 'elgg-button elgg-button-submit float-alt'
  31. ));
  32. echo '</div>';
  33. }
  34. $dir = opendir($backup_dir);
  35. //prepeare array with files name
  36. $backups_files = array();
  37. while ($file = readdir($dir)) {
  38. if ($file != '.' && $file != '..') {
  39. if (strpos($file, '.tar.gz.ini') == false) { //do not include inifiles in backups list
  40. $time = filemtime($backup_dir . $file);
  41. $backups_files[$time] = $file;
  42. }
  43. }
  44. }
  45. if ($backups_files) {
  46. //sorting by name
  47. ksort($backups_files);
  48. $backups_files = array_reverse($backups_files, true);
  49. $body = '<div class="elgg-module elgg-module-inline">';
  50. $body .= '<div class="elgg-head">';
  51. $body .= '<label><input type="checkbox" id="backups-checkall"> List of existing backups</label>';
  52. $body .= elgg_view("input/submit", array("value" => elgg_echo("remove"), 'class' => 'float-alt'));
  53. $body .= '</div>';
  54. $body .= '<div class="elgg-body">';
  55. $body .= '<ul class="elgg-list elgg-list-distinct">';
  56. foreach ($backups_files as $time => $backup) {
  57. //get backup options from ini file
  58. $inifile_path = $backup_dir . $backup . ".ini";
  59. if (file_exists($inifile_path)) {
  60. $inifile = fopen($inifile_path, "r");
  61. $options_string = unserialize(fgets($inifile));
  62. fclose($inifile);
  63. }else{
  64. $options_string = array('site', 'data', 'db'); //for old backups and backups without ini files
  65. }
  66. //prepeare link for downloading
  67. $restore_link = elgg_add_action_tokens_to_url(elgg_get_site_url() . "action/backup-tool/restore?file=" . $backup);
  68. $download_link = elgg_add_action_tokens_to_url(elgg_get_site_url() . "action/backup-tool/download?file=" . $backup);
  69. $remove_link = elgg_add_action_tokens_to_url(elgg_get_site_url() . "action/backup-tool/remove?file=" . $backup);
  70. //buttons
  71. $buttons = '<span class="elgg-subtext">' . number_format(filesize($backup_dir . $backup) / 1048576, 2) . 'M </span>&nbsp;&nbsp;/&nbsp;&nbsp;';
  72. $buttons .= '<span class="elgg-subtext">' . date("d.m.Y", $time) . '</span>&nbsp;&nbsp;';
  73. $buttons .= elgg_view("output/url", array("text" => elgg_echo("backup-tool:restore"), "href" => $restore_link, "class" => "elgg-button-submit elgg-button"));
  74. $buttons .= elgg_view("output/url", array("text" => elgg_echo("download"), "href" => $download_link, "class" => "elgg-button-submit elgg-button"));
  75. $buttons .= elgg_view("output/confirmlink", array("text" => elgg_echo("remove"), "href" => $remove_link, "class" => "elgg-button-submit elgg-button"));
  76. //checkbox
  77. $checkbox = elgg_view("input/checkbox", array('name' => 'file[]', 'value' => $backup));
  78. $backup_link = elgg_view("output/url", array("text" => $backup, "title" => $backup_dir . $backup, "href" => $download_link));
  79. $backup_options = '<span class="elgg-subtext">(' . implode(", ", $options_string) . ') </span>';
  80. $body .= '<li class="elgg-item">
  81. <div class="elgg-image-block clearfix">
  82. <div class="elgg-image">
  83. ' . $checkbox . '
  84. </div>
  85. <div class="elgg-image-alt">
  86. ' . $buttons . '
  87. </div>
  88. <div class="elgg-body">
  89. ' . $backup_link . ' ' . $backup_options . '
  90. </div>
  91. </div>
  92. </li>';
  93. }
  94. $body .= '</ul>';
  95. $body .= '</div>';
  96. echo elgg_view("input/form", array("id" => "backups-form", "action" => "action/backup-tool/remove", "body" => $body));
  97. }
  98. closedir($dir);