forked from pkriete/simplypost
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSP_Router.php
95 lines (80 loc) · 2.16 KB
/
SP_Router.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
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* SimplyPost
*
* @author Pascal Kriete
* @package SimplyPost
* @copyright Copyright (c) 2008, Pascal Kriete
* @license http://www.opensource.org/licenses/mit-license.php
*/
// ------------------------------------------------------------------------
/**
* Router Class
*
* Extends CI Router
*
* @package SimplyPost
* @subpackage Libraries
* @category Core Extension
* @author Pascal Kriete
*/
class SP_Router extends CI_Router {
/**
* Constructor
*
* @access public
*/
function SP_Router()
{
parent::CI_Router();
}
// --------------------------------------------------------------------
/**
* Validate Routing Request
*
* @access public
*/
function _validate_request($segments)
{
// Check the root folder first
if (file_exists(APPPATH.'controllers/'.$segments[0].EXT))
{
return $segments;
}
// Backend is special (and I know this is ugly)
global $CFG;
if ($segments[0] == $CFG->item('backend_base'))
{
// Not in the root, but not enough segments
if (count($segments) < 2)
{
//Calling the index function of a controller of the same directory...
//We'll cheat and just set our segment
$segments[1] = $segments[0];
}
// Does the requested controller exist as a full path including the directory?
if (file_exists(APPPATH.'controllers/'.$segments[0].'/'.$segments[1].EXT))
{
//Set the directory
$this->set_directory($segments[0]);
//Drop the directory segment
$segments = array_slice($segments, 1);
return $segments;
}
//Ok, that didn't work, let's try duplicating segment 1, maybe it's the same ;).
if (file_exists(APPPATH.'controllers/backend/'.$segments[1].'/'.$segments[1].EXT))
{
//We cheated so we need to fix the array
$segments[0] = $segments[1];
//Set the directory
$this->set_directory('backend/'.$segments[0]);
return $segments;
}
}
// Can't find the requested controller... where did frontend.php go?
die('Fatal Error');
}
}
// END SP_Router class
/* End of file SP_Router.php */
/* Location: ./application/libraries/SP_Router.php */