1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
class URLDecode |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
|
6
|
|
|
private static $array = array(); |
7
|
|
|
|
8
|
|
|
static function init() |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
$host = $_SERVER['HTTP_HOST']; |
11
|
|
|
$uri = $_SERVER['REQUEST_URI']; |
12
|
|
|
self::form_url_array($host, $uri); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
static private function form_url_array($host, $uri) |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
$uri = substr($uri, 1); |
18
|
|
|
if(strpos($uri, '?')) |
19
|
|
|
$uri = substr($uri, 0, strpos($uri, '?')); |
20
|
|
|
$uri_array = explode('/', $uri); |
21
|
|
|
|
22
|
|
|
if(!Loader::isLive()) |
23
|
|
|
$host = substr($host, strpos($host, '.') + 1); |
24
|
|
|
|
25
|
|
|
self::$array['host'] = $host; |
26
|
|
|
|
27
|
|
|
if ( |
28
|
|
|
$host == 'www.waterfallsofthekeweenaw.com' || |
29
|
|
|
$host == 'waterfallsofthekeweenaw.com' |
30
|
|
|
) { |
31
|
|
|
self::$array['site'] = 'waterfalls'; |
32
|
|
|
} else { |
33
|
|
|
self::$array['site'] = substr($host, 0, strpos($host, '.')); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
self::$array['base'] = 'http://' . (!Loader::isLive() ? 'dev.' : '') . $host . '/'; |
37
|
|
|
self::$array['uri'] = '/' . implode('/', $uri_array); |
38
|
|
|
|
39
|
|
|
if(end($uri_array) == '') |
40
|
|
|
$uri_array = array_slice($uri_array, 0, count($uri_array) - 1); |
41
|
|
|
self::$array['pieces'] = (array) $uri_array; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
static function getSite() |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
return self::$array['site']; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
static function getHost() |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
return self::$array['host']; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
static function getBase() |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
return self::$array['base']; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
static function getURI() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
return self::$array['uri']; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
static function getExtension() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$file = self::getPiece(-1); |
67
|
|
|
if(substr($file, -1) == '/') |
68
|
|
|
return false; |
69
|
|
|
return substr($file, strrpos($file, '.') + 1);; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
static function getPiece($piece = null) |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
if(!$piece) |
75
|
|
|
return self::$array['pieces']; |
76
|
|
|
|
77
|
|
|
if($piece == -1) |
78
|
|
|
return end(self::$array['pieces']); |
79
|
|
|
|
80
|
|
|
$piece = $piece - 1; |
81
|
|
|
if(array_key_exists($piece, self::$array['pieces'])) |
82
|
|
|
return self::$array['pieces'][$piece]; |
83
|
|
|
return; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
URLDecode::init(); |
89
|
|
|
|
90
|
|
|
?> |
|
|
|
|
91
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.