-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·87 lines (72 loc) · 2.52 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
<?php
// Session
session_start();
//var_dump($_SESSION);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Main app path
define('APP_PATH', dirname(realpath(__FILE__)) . '/app/');
//define global variable from seesion
if(!empty($_SESSION['user'])) $GLOBALS['user']=$_SESSION['user'];
$GLOBALS['id_tip_imobile_apartament']=array(4,5);
// Include config
require_once APP_PATH . 'config/config.php';
define('APP_URL', $config['domain'] . $config['folder']);
// define constant
define('DEFAULT_PAGER',10);
define('SITE_TRACK',$config['site_track']);
define('TEREN_TRACK',$config['teren_track']);
// Setup auto-loader
spl_autoload_register("auto_loader");
function auto_loader($class) {
if (false !== strpos($class, '_')) {
$tokens = explode('_', $class);
if (file_exists(APP_PATH . implode('/', $tokens) . '.php')) {
include APP_PATH . implode('/', $tokens) . '.php';
}
}
}
// Parse URL and determine current controller and action.
$url = $_SERVER['REQUEST_URI'];
if (0 === strpos($url, $config['folder'])) {
$url = substr($url, strlen($config['folder']));
}
$rev = array_reverse(explode('?', $url));
$url = array_pop($rev);
$url = trim($url, '/');
$tokens = $url ? explode('/', $url) : array();
// Determin controller and action
$controller = $config['default_controller'];
$action = $config['default_action'];
// First argument in the URL, if exists, defines the controller
if (count($tokens) >= 1) {
$controller = $tokens[0];
$tokens = (count($tokens) > 1) ? array_slice($tokens, 1) : array();
}
// Second argument in the URL, if exists, defines the action
if (count($tokens) >= 1) {
$action = $tokens[0];
$tokens = (count($tokens) > 1) ? array_slice($tokens, 1) : array();
}
// Compiles controller class name
$controller_class = 'controller_' . $controller;
// Compiles action method name
$action_method = 'action_' . $action;
// Verifies if the controller class exists, if doesn't exist then the URL is invalid
if (!class_exists($controller_class)) {
$controller = '404';
$controller_class = 'controller_404';
$action = 'index';
$action_method = 'action_index';
}
// Instantiates the controller class
$controller_instance = new $controller_class;
// Verifies if the action method exists, if doesn't exist then the URL is invalid
if (!method_exists($controller_instance, $action_method)) {
$controller = '404';
$controller_class = 'controller_404';
$controller_instance = new $controller_class;
$action = 'index';
$action_method = 'action_index';
}
// Go!
$controller_instance->$action_method($tokens);