stats.inc.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * Insipid
  4. * Personal web-bookmark-system
  5. *
  6. * Copyright 2016-2020 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'] = 'Something went wrong while storage cleaning';
  39. $submitFeedback['status'] = 'error';
  40. }
  41. }
  42. if(isset($_POST['statsCreateDBBackup'])) {
  43. require_once 'lib/Mysqldump.php';
  44. $backupTmpFile = tempnam(sys_get_temp_dir(),'inspid');
  45. // mysqldump was modifed to make this work
  46. // include-views was not working while using include-tables
  47. $dumpSettings = array(
  48. 'include-tables' => array(
  49. DB_PREFIX.'_category',
  50. DB_PREFIX.'_categoryrelation',
  51. DB_PREFIX.'_link',
  52. DB_PREFIX.'_tag',
  53. DB_PREFIX.'_tagrelation'
  54. ),
  55. 'include-views' => array(
  56. DB_PREFIX.'_combined'
  57. ),
  58. 'default-character-set' => \Ifsnop\Mysqldump\Mysqldump::UTF8MB4
  59. );
  60. $dump = new Ifsnop\Mysqldump\Mysqldump(
  61. 'mysql:host='.DB_HOST.';dbname='.DB_NAME,
  62. DB_USERNAME,
  63. DB_PASSWORD,
  64. $dumpSettings
  65. );
  66. $dump->start($backupTmpFile);
  67. header('Content-Type: application/octet-stream');
  68. header("Content-Transfer-Encoding: Binary");
  69. header("Content-disposition: attachment; filename=inspid-db-backup-full.sql");
  70. readfile($backupTmpFile);
  71. exit();
  72. }
  73. if(isset($_POST['statsImportXML'])) {
  74. $_options = array();
  75. if(isset($_FILES['importxmlfile']) && !empty($_FILES['importxmlfile'])) {
  76. $_options['overwrite'] = false;
  77. if(isset($_POST['importOverwrite'])) {
  78. $_options['overwrite'] = true;
  79. }
  80. $do = $Management->processImportFile($_FILES['importxmlfile'], $_options);
  81. if(isset($do['status']) && $do['status'] === 'success') {
  82. $submitFeedback['status'] = 'success';
  83. $submitFeedback['message'] = $do['message'];
  84. }
  85. else {
  86. $submitFeedback['message'] = $do['message'];
  87. $submitFeedback['status'] = 'error';
  88. }
  89. }
  90. else {
  91. $submitFeedback['message'] = 'Please provide a import file';
  92. $submitFeedback['status'] = 'error';
  93. }
  94. }
  95. if(isset($_POST['statsUpdateSearchIndex'])) {
  96. if($Management->updateSearchIndex() === true) {
  97. $TemplateData['refresh'] = 'index.php?p=stats';
  98. }
  99. else {
  100. $submitFeedback['message'] = 'Something went wrong while search index update';
  101. $submitFeedback['status'] = 'error';
  102. }
  103. }
  104. $linkAmount = $Management->linkAmount();
  105. $tagAmount = $Management->tagAmount();
  106. $categoryAmount = $Management->categoryAmount();
  107. $localStorageAmount = $Management->storageAmount();
  108. $localStorageAmount = Summoner::humanFileSize($localStorageAmount);