-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathpip.php
More file actions
53 lines (42 loc) · 1.75 KB
/
Copy pathpip.php
File metadata and controls
53 lines (42 loc) · 1.75 KB
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
<?php
function pip()
{
global $config;
// Set our defaults
$controller = $config['default_controller'];
$action = 'index';
$url = '';
// Get request url and script url
$request_url = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : '';
$script_url = (isset($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : '';
// If this a cron job, then use the server arguments as the url
// format your cron command like this: "/path/to/www/index.php /controller/action"
if (!$request_url && isset($_SERVER['SHELL']) && isset($_SERVER['argv']) && isset($_SERVER['argv'][1])) {
$request_url = $_SERVER['argv'][1];
}
// Get our url path and trim the / of the left and the right
if($request_url != $script_url) $url = trim(preg_replace('/'. str_replace('/', '\/', str_replace('index.php', '', $script_url)) .'/', '', $request_url, 1), '/');
// Split the url into segments
$segments = explode('/', $url);
// Do our default checks
if(isset($segments[0]) && $segments[0] != '') $controller = $segments[0];
if(isset($segments[1]) && $segments[1] != '') $action = $segments[1];
// Get our controller file
$path = APP_DIR . 'controllers/' . $controller . '.php';
if(file_exists($path)){
require_once($path);
} else {
$controller = $config['error_controller'];
require_once(APP_DIR . 'controllers/' . $controller . '.php');
}
// Check the action exists
if(!method_exists($controller, $action)){
$controller = $config['error_controller'];
require_once(APP_DIR . 'controllers/' . $controller . '.php');
$action = 'index';
}
// Create object and call method
$obj = new $controller;
die(call_user_func_array(array($obj, $action), array_slice($segments, 2)));
}
?>