index.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * scientia
  4. *
  5. * Copyright 2023 - 2024 Johannes Keßler
  6. *
  7. * https://www.bananas-playground.net/projekt/scientia/
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see http://www.gnu.org/licenses/gpl-3.0.
  21. */
  22. mb_http_output('UTF-8');
  23. mb_internal_encoding('UTF-8');
  24. ini_set('error_reporting',-1); // E_ALL & E_STRICT
  25. ## check request
  26. $_urlToParse = filter_var($_SERVER['QUERY_STRING'],FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
  27. if(!empty($_urlToParse)) {
  28. # see http://de2.php.net/manual/en/regexp.reference.unicode.php
  29. if(preg_match('/[\p{C}\p{M}\p{Sc}\p{Sk}\p{So}\p{Zl}\p{Zp}]/u',$_urlToParse) === 1) {
  30. die('Malformed request. Make sure you know what you are doing.');
  31. }
  32. }
  33. ## config
  34. require_once('config/config.php');
  35. ## set the error reporting
  36. ini_set('log_errors',true);
  37. ini_set('error_log',PATH_SYSTEMOUT.'/error.log');
  38. if(DEBUG === true) {
  39. ini_set('display_errors',true);
  40. }
  41. else {
  42. ini_set('display_errors',false);
  43. }
  44. # time settings
  45. date_default_timezone_set(TIMEZONE);
  46. # required libs
  47. require_once('lib/summoner.class.php');
  48. require_once('lib/i18n.class.php');
  49. Summoner::simpleAuth();
  50. # i18n
  51. $i18n = new I18n();
  52. ## DB connection
  53. $DB = new mysqli(DB_HOST, DB_USERNAME,DB_PASSWORD, DB_NAME);
  54. if ($DB->connect_errno) exit('Can not connect to MySQL Server');
  55. $DB->set_charset("utf8mb4");
  56. $DB->query("SET collation_connection = 'utf8mb4_bin'");
  57. $driver = new mysqli_driver();
  58. $driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;
  59. # default values
  60. $_view = 'list';
  61. $_year = date('Y');
  62. $_month = date('m');
  63. $_day = date('d');
  64. $_id = '';
  65. $_requestDateProvided = '';
  66. $TemplateData = array();
  67. if(isset($_GET['y']) && Summoner::validate($_GET['y'], 'digit')) {
  68. $_year = trim($_GET['y']);
  69. $_requestDateProvided .= 'Y';
  70. }
  71. if(isset($_GET['m']) && Summoner::validate($_GET['m'], 'digit')) {
  72. $_month = trim($_GET['m']);
  73. $_requestDateProvided .= '-m';
  74. }
  75. if(isset($_GET['d']) && Summoner::validate($_GET['d'], 'digit')) {
  76. $_day = trim($_GET['d']);
  77. $_requestDateProvided .= '-d';
  78. }
  79. if(isset($_GET['p']) && Summoner::validate($_GET['p'], 'nospace') && $_GET['p'] == "new") {
  80. $_view = 'entry';
  81. }
  82. if(isset($_GET['id']) && Summoner::validate($_GET['id'], 'shortlink',4)) {
  83. $_id = trim($_GET['id']);
  84. $_view = 'entry';
  85. }
  86. require_once 'view/'.$_view.'/'.$_view.'.php';
  87. # header information
  88. header('Content-type: text/html; charset=UTF-8');
  89. header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
  90. header("Cache-Control: post-check=0, pre-check=0", false);
  91. header("Pragma: no-cache");
  92. if(isset($TemplateData['refresh']) && !empty($TemplateData['refresh'])) {
  93. header('Location: '.PATH_WEBROOT.$TemplateData['refresh']);
  94. exit();
  95. }
  96. require_once 'view/_head.php';
  97. require_once 'view/'.$_view.'/'.$_view.'.html';
  98. require_once 'view/_foot.php';
  99. $DB->close();