index.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php // ini_set('display_errors', 1); // IMPORTANT not to use in production
  2. use Tracy\Debugger;
  3. use DocPHT\Core\Session\Session;
  4. /**
  5. * This file is part of the DocPHT project.
  6. *
  7. * @author Valentino Pesce
  8. * @copyright (c) Valentino Pesce <valentino@iltuobrand.it>
  9. * @copyright (c) Craig Crosby <creecros@gmail.com>
  10. *
  11. * For the full copyright and license information, please view the LICENSE
  12. * file that was distributed with this source code.
  13. */
  14. $autoload = 'vendor/autoload.php';
  15. $constants = 'src/core/constants.php';
  16. $configurationFile = 'src/config/config.php';
  17. $installFolder = 'install';
  18. if (file_exists($configurationFile) && file_exists($installFolder)) {
  19. $files = glob($installFolder.'/partial/*');
  20. foreach($files as $file){
  21. if(is_file($file)) {
  22. unlink($file);
  23. }
  24. if (is_dir_empty($installFolder.'/partial'))
  25. rmdir($installFolder.'/partial');
  26. }
  27. $files = glob($installFolder.'/*');
  28. foreach($files as $file){
  29. if(is_file($file)) {
  30. unlink($file);
  31. }
  32. if (is_dir_empty($installFolder))
  33. rmdir($installFolder);
  34. }
  35. if (file_exists($installFolder.'/partial') && file_exists($installFolder)) {
  36. include 'install/error.php';
  37. } else {
  38. require $configurationFile;
  39. header('Location:'.BASE_URL.'login');
  40. }
  41. } elseif (!file_exists($configurationFile) && !file_exists($installFolder)) {
  42. mkdir($installFolder, 0755, true);
  43. mkdir($installFolder.'/partial', 0755, true);
  44. $files = glob('temp/install/partial/*');
  45. foreach($files as $file){
  46. if(is_file($file)) {
  47. error_log($file,0);
  48. copy($file, $installFolder . "/partial/" . pathinfo($file,PATHINFO_BASENAME));
  49. }
  50. }
  51. $files = glob('temp/install/*');
  52. foreach($files as $file){
  53. if(is_file($file)) {
  54. copy($file, $installFolder . "/" . pathinfo($file,PATHINFO_BASENAME));
  55. }
  56. }
  57. include 'install/config.php';
  58. } elseif (!file_exists($configurationFile)) {
  59. include 'install/config.php';
  60. } elseif (file_exists($autoload)) {
  61. require $autoload;
  62. $session = new Session();
  63. $session->sessionExpiration();
  64. $session->preventStealingSession();
  65. require $constants;
  66. require $configurationFile;
  67. // Debugger::enable(Debugger::DEVELOPMENT); // IMPORTANT not to use in production
  68. $loader = new Nette\Loaders\RobotLoader;
  69. $loader->addDirectory(__DIR__ . '/src');
  70. $loader->setTempDirectory(__DIR__ . '/temp');
  71. $loader->register();
  72. $app = System\App::instance();
  73. $app->request = System\Request::instance();
  74. $app->route = System\Route::instance($app->request);
  75. $route = $app->route;
  76. include 'src/route.php';
  77. $route->end();
  78. }
  79. function is_dir_empty($dir)
  80. {
  81. if (!is_readable($dir)) return NULL;
  82. return (count(scandir($dir)) == 2);
  83. }