-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
159 lines (134 loc) · 3.99 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
require('lib/system.config.php');
require('lib/system.functions.php');
require('lib/plugins.functions.php');
require('user/config/routes.php');
require('user/config/app.php');
require('user/config/user.php');
# Define an array for controller's vars.
$_controller = array();
$_controller['current_url'] = curr_url();
$_url_match = 0;
# Check and see if we have a route match
foreach($_routes as $_route)
{
$_controller['route_url'] = url_explode($_route['url']);
# Check for an array size match between the current url and the current stored url iteration.
if(count($_controller['current_url']) == count($_controller['route_url']))
{
log_me("Looks like we've got a url count match on -- ".implode('/', $_controller['route_url']));
$size = count($_controller['current_url']);
# Compare the urls
for($i = 0; $i < $size; ++$i)
{
# Let's catch the route wildcards
if(is_route_wildcard($_controller['route_url'][$i]))
{
# We know we're dealing with a wildcard--let's find out if it's a module or action
if($_controller['route_url'][$i] == ':module')
{
$_module = str_replace(':', '', $_controller['current_url'][$i]);
log_me("The following module wildcard was found -- ".$_module);
}
if($_controller['route_url'][$i] == ':action')
{
$_action = str_replace(':', '', $_controller['current_url'][$i]);
log_me("The following action wildcard was found -- ".$_action);
}
if($_module && $_action)
{
$_url_match = 1;
log_me("Looks like we've got both a module and action wildcard; setting".' $_url_match to true');
}
# Make sure that the wildcards aren't matching on :module or :action, as these are reserved wildcards.
if($_controller['route_url'][$i] != ':module' && $_controller['route_url'][$i] != ':action')
{
# If they aren't, add the wildcard to the request array (this will allow user's to set things like id, slug, etc).
$_request[str_replace(':', '', $_controller['route_url'][$i])] = $_controller['current_url'][$i];
log_me("The following wildcard was found -- ".$_controller['route_url'][$i]);
}
}
else
{
# If the current url iteration doesn't match the route url iteration
//echo($_controller['current_url'][$i] .'--'. $_controller['route_url'][$i].'<br/>');
if($_controller['current_url'][$i] != $_controller['route_url'][$i])
{
# Set the flag
$_url_match = 0;
}
else
{
$_url_match = 1;
}
}
}
}
log_me('$_url_match is -- '.$_url_match);
if($_url_match)
{
break;
}
}
# If we have a route match, let's continue to render that route
if($_url_match)
{
# Load up any installed plugin functions.
$_list = get_autoload_list();
foreach($_list as $_autoloaded_plugin_info)
{
if($_autoloaded_plugin_info['config'])
{
require($_autoloaded_plugin_info['config']);
}
if($_autoloaded_plugin_info['functions'])
{
require($_autoloaded_plugin_info['functions']);
}
}
# Let's set our $_target var here.
$_target = DIR_MODS;
# Define our module.
if($_module)
{
$_target .= $_module;
}
else
{
$_target .= $_route['target']['module'];
}
# Define our action.
if($_action)
{
$_target .= '/'.$_action;
}
else
{
$_target .= '/'.$_route['target']['action'];
}
# Unset action.
unset($_action);
# Fetch the logic.
include($_target.'/logic.php');
# Init the content var.
$content = '';
# Fetch the view.
ob_start();
include($_target.'/view.php');
$_content .= ob_get_clean();
# If a template was specificied, we'll include that, otherwise, we'll just render the content.
if(isset($_action['template']))
{
require(DIR_TEMPLATES.$_action['template'].'.php');
}
else
{
echo $_content;
}
}
else
{
# Otherwise, let's 404 it.
fwd_404();
}
//pre($_log);