stats.inc.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * Insipid
  4. * Personal web-bookmark-system
  5. *
  6. * Copyright 2016-2023 Johannes Keßler
  7. *
  8. * Development starting from 2011: Johannes Keßler
  9. * https://www.bananas-playground.net/projekt/insipid/
  10. *
  11. * creator:
  12. * Luke Reeves <luke@neuro-tech.net>
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation, either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see http://www.gnu.org/licenses/gpl-3.0.
  26. *
  27. */
  28. $_displayEditButton = false;
  29. if(Summoner::simpleAuthCheck() === true) {
  30. $_displayEditButton = true;
  31. $moderationAmount = $Management->moderationAmount();
  32. }
  33. if(isset($_POST['statsDeleteLocalStorage'])) {
  34. if($Management->clearLocalStorage() === true) {
  35. $TemplateData['refresh'] = 'index.php?p=stats';
  36. }
  37. else {
  38. $submitFeedback['message'] = $T->t('stats.storage.clean.fail');
  39. $submitFeedback['status'] = 'error';
  40. }
  41. }
  42. if(isset($_POST['statsCreateDBBackup'])) {
  43. require 'lib/Mysqldump.php';
  44. $dumpSettings = array(
  45. 'include-tables' => array(
  46. DB_PREFIX.'_category',
  47. DB_PREFIX.'_categoryrelation',
  48. DB_PREFIX.'_link',
  49. DB_PREFIX.'_tag',
  50. DB_PREFIX.'_tagrelation'
  51. ),
  52. 'include-views' => array(
  53. DB_PREFIX.'_combined'
  54. ),
  55. 'default-character-set' => 'utf8mb4'
  56. );
  57. $backupTmpFile = tempnam(sys_get_temp_dir(),'inspid');
  58. try {
  59. $dump = new Mysqldump('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USERNAME, DB_PASSWORD, $dumpSettings);
  60. $dump->start($backupTmpFile);
  61. } catch (Exception $e) {
  62. echo 'mysqldump-php error: ' . $e->getMessage();
  63. }
  64. header('Content-Type: application/octet-stream');
  65. header("Content-Transfer-Encoding: Binary");
  66. header("Content-disposition: attachment; filename=insipid-db-backup-full.sql");
  67. readfile($backupTmpFile);
  68. exit();
  69. }
  70. if(isset($_POST['statsImportXML'])) {
  71. $_options = array();
  72. if(isset($_FILES['importxmlfile']) && !empty($_FILES['importxmlfile'])) {
  73. $_options['overwrite'] = false;
  74. if(isset($_POST['importOverwrite'])) {
  75. $_options['overwrite'] = true;
  76. }
  77. $do = $Management->processImportFile($_FILES['importxmlfile'], $_options);
  78. if(isset($do['status']) && $do['status'] === 'success') {
  79. $submitFeedback['status'] = 'success';
  80. $submitFeedback['message'] = $do['message'];
  81. }
  82. else {
  83. $submitFeedback['message'] = $do['message'];
  84. $submitFeedback['status'] = 'error';
  85. }
  86. }
  87. else {
  88. $submitFeedback['message'] = $T->t('stats.import.missing.file');
  89. $submitFeedback['status'] = 'error';
  90. }
  91. }
  92. if(isset($_POST['statsUpdateSearchIndex'])) {
  93. if($Management->updateSearchIndex() === true) {
  94. $TemplateData['refresh'] = 'index.php?p=stats';
  95. }
  96. else {
  97. $submitFeedback['message'] = $T->t('stats.search.index.fail');
  98. $submitFeedback['status'] = 'error';
  99. }
  100. }
  101. $linkAmount = $Management->linkAmount();
  102. $tagAmount = $Management->tagAmount();
  103. $categoryAmount = $Management->categoryAmount();
  104. $localStorageAmount = $Management->storageAmount();
  105. $localStorageAmount = Summoner::humanFileSize($localStorageAmount);