This repository has been archived by the owner on May 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
126 lines (89 loc) · 2.61 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* Dumb-Namic
*
* Static-dynamic(ish) web framework
*
* @version b0.1
* @author The Juan Who Code <[email protected]>
* @package core
*/
define('NICE_URL',true);
define('DOMAIN','http://www.dumbnamic.dev');
define('POST_EXTENSION','html');
// Absolute path
define('ABSPATH',dirname(__FILE__).'/');
// Application path
define('APPDIR',ABSPATH.'application/');
// Clear all global variable
if($_SERVER['REQUEST_METHOD'] == 'POST'){
unset($_POST);
}else{
unset($_GET);
}
// Load application functions
if(file_exists(APPDIR.'functions.php')) include(APPDIR.'functions.php');
$page = array();
if(defined('NICE_URL') && NICE_URL == true && file_exists('.htaccess')){
$uri = array();
// Get URI
$raw_uri = rtrim(ltrim($_SERVER['REQUEST_URI'],'/'),'/');
$raw_uri = parse_url($raw_uri);
$pi = pathinfo($raw_uri['path']);
$pi['dirname'] = isset($pi['dirname']) ? ($pi['dirname'] == '.' ? '' : $pi['dirname']) : '';
$page['type'] = (isset($pi['extension']) && $pi['extension'] == POST_EXTENSION ? 'post' : 'page');
// URL Query
if(isset($raw_uri['query'])){
$query = array();
parse_str($raw_uri['query'],$query);
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$_POST = $query;
}elseif($_SERVER['REQUEST_METHOD'] == 'GET'){
$_GET = $query;
}
}
if(empty($pi['dirname'])){ // Main page
if(empty($pi['basename'])){
$page['script'][] = APPDIR.'pages/main.php';
$page['name'] = 'root';
}else{
if($page['type'] == 'post'){
$page['script'][] = APPDIR.'pages/'.$pi['filename'].'.php';
}else{
$page['script'][] = APPDIR.'pages/'.$pi['basename'].'/dynamic.php';
$page['script'][] = APPDIR.'pages/'.$pi['basename'].'/main.php';
}
$page['name'] = $pi['basename'];
}
}else{
if($page['type'] == 'post'){
$page['script'][] = APPDIR.'pages/'. $pi['dirname'].'/'.$pi['filename'].'.php';
}else{
if(!empty($pi['extension'])){
$page['script'][] = APPDIR.'pages/'. $pi['dirname'].'/'.$pi['basename'].'/main.php';
}else{
$page['script'][] = APPDIR.'pages/'. $pi['dirname'].'/'.$page['type'].'-'.$pi['filename'].'.php';
$page['script'][] = APPDIR.'pages/'. $pi['dirname'].'/'.$pi['filename'].'/main.php';
}
}
$page['name'] = ($page['type'] == 'post' ? $pi['filename'] : $pi['basename']);
}
}
$inc = '';
$page = (object)$page;
foreach($page->script as $script){
if(file_exists($script) && $inc == ''){
$inc = $script;
break;
}
}
if(file_exists($inc)){
include($inc);
}else{
if(file_exists(APPDIR.'404.php')){
include(APPDIR.'404.php');
}else{
// internal 404 page
}
}
?>