Advertisement
yummiesttag

Untitled

May 12th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. <?php
  2. /*
  3. * Made by Samerton
  4. * https://github.com/NamelessMC/Nameless/
  5. * NamelessMC version 2.0.0-pr6
  6. *
  7. * License: MIT
  8. *
  9. * Main index file
  10. */
  11.  
  12. // Uncomment to enable debugging
  13. //define('DEBUGGING', 1);
  14.  
  15. if(defined('DEBUGGING') && DEBUGGING){
  16. ini_set('display_startup_errors', 1);
  17. ini_set('display_errors', 1);
  18. error_reporting(-1);
  19. }
  20.  
  21. // Ensure PHP version >= 5.4
  22. if(version_compare(phpversion(), '5.4', '<')){
  23. die('NamelessMC is not compatible with PHP versions older than 5.4');
  24. }
  25.  
  26. // Start page load timer
  27. $start = microtime(true);
  28.  
  29. // Definitions
  30. define('PATH', '/');
  31. define('ROOT_PATH', dirname(__FILE__));
  32. $page = 'Home';
  33.  
  34. if(!ini_get('upload_tmp_dir')){
  35. $tmp_dir = sys_get_temp_dir();
  36. } else {
  37. $tmp_dir = ini_get('upload_tmp_dir');
  38. }
  39.  
  40. ini_set('open_basedir', ROOT_PATH . PATH_SEPARATOR . $tmp_dir . PATH_SEPARATOR . '/proc/stat');
  41.  
  42. // Get the directory the user is trying to access
  43. $directory = $_SERVER['REQUEST_URI'];
  44. $directories = explode("/", $directory);
  45. $lim = count($directories);
  46.  
  47. if(isset($_GET['route']) && $_GET['route'] == '/rewrite_test'){
  48. require_once('rewrite_test.php');
  49. die();
  50. }
  51.  
  52. try {
  53. // Start initialising the page
  54. require(ROOT_PATH . '/core/init.php');
  55. }
  56. catch(Exception $e) {
  57. die($e->getMessage());
  58. }
  59.  
  60. if(!isset($GLOBALS['config']['core']) && is_file(ROOT_PATH . '/install.php')) {
  61. Redirect::to('install.php');
  62. }
  63.  
  64. // Get page to load from URL
  65. if(!isset($_GET['route']) || $_GET['route'] == '/'){
  66.  
  67. if(count($directories) > 1 && (!isset($_GET['route']) || (isset($_GET['route']) && $_GET['route'] != '/')))
  68. require(ROOT_PATH . '/404.php');
  69. else
  70. // Homepage
  71. require(ROOT_PATH . '/modules/Core/pages/index.php');
  72.  
  73. } else {
  74. $route = rtrim(strtok($_GET['route'], '?'), '/');
  75.  
  76. // Check modules
  77. $modules = $pages->returnPages();
  78.  
  79. // Include the page
  80. if(array_key_exists($route, $modules)){
  81. if(!isset($modules[$route]['custom'])){
  82. $path = join(DIRECTORY_SEPARATOR, array(ROOT_PATH, 'modules', $modules[$route]['module'], $modules[$route]['file']));
  83.  
  84. if(!file_exists($path)) require(ROOT_PATH . '/404.php'); else require($path);
  85. die();
  86. } else {
  87. require(join(DIRECTORY_SEPARATOR, array(ROOT_PATH, 'modules', 'Core', 'pages', 'custom.php')));
  88. die();
  89. }
  90. } else {
  91. // Use recursion to check - might have URL parameters in path
  92. $path_array = explode('/', $route);
  93.  
  94. for($i = count($path_array) - 2; $i > 0; $i--){
  95. $new_path = '/';
  96. for($n = 1; $n <= $i; $n++){
  97. $new_path .= $path_array[$n] . '/';
  98. }
  99. $new_path = rtrim($new_path, '/');
  100. if(array_key_exists($new_path, $modules)){
  101. $path = join(DIRECTORY_SEPARATOR, array(ROOT_PATH, 'modules', $modules[$new_path]['module'], $modules[$new_path]['file']));
  102. if(file_exists($path)){
  103. require($path);
  104. die();
  105. }
  106. }
  107. }
  108.  
  109. // 404
  110. require(ROOT_PATH . '/404.php');
  111. }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement