-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUrl.class.php
More file actions
69 lines (56 loc) · 2 KB
/
Url.class.php
File metadata and controls
69 lines (56 loc) · 2 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
class Url
{
private static $url = null;
private static $baseUrl = null;
public static function getURL( $id )
{
if( self::$url == null )
// Verifica se a lista de URL já foi preenchida
self::getURLList();
// Valida se existe o ID informado e retorna.
if( isset( self::$url[ $id ] ) )
return self::$url[ $id ];
// Caso não exista o ID, retorna nulo
return null;
}
public static function getBase()
{
if( self::$baseUrl != null )
return self::$baseUrl;
global $_SERVER;
$startUrl = strlen( $_SERVER["DOCUMENT_ROOT"] );
$excludeUrl = substr( $_SERVER["SCRIPT_FILENAME"], $startUrl, -9 );
if( $excludeUrl[0] == "/" )
self::$baseUrl = $excludeUrl;
else
self::$baseUrl = "/" . $excludeUrl;
return self::$baseUrl;
}
private static function getURLList()
{
global $_SERVER;
// Primeiro traz todos as pastas abaixo do index.php
$startUrl = strlen( $_SERVER["DOCUMENT_ROOT"] ) -1;
$excludeUrl = substr( $_SERVER["SCRIPT_FILENAME"], $startUrl, -10 );
// a variável$request possui toda a string da URL após o domínio.
$request = $_SERVER['REQUEST_URI'];
// Agora retira toda as pastas abaixo da pasta raiz
$request = substr( $request, strlen( $excludeUrl ) );
// Explode a URL para pegar retirar tudo após o ?
$urlTmp = explode("?", $request);
$request = $urlTmp[ 0 ];
// Explo a URL para pegar cada uma das partes da URL
$urlExplodida = explode("/", $request);
$retorna = array();
for($a = 0; $a <= count($urlExplodida); $a ++)
{
if(isset($urlExplodida[$a]) AND $urlExplodida[$a] != "")
{
array_push($retorna, $urlExplodida[$a]);
}
}
self::$url = $retorna;
}
}
?>