blob: 99de7d2595b1fb7fd947972173bbafad0bafaf6d (
plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
* @version $Id$
*
* @package Piwik_Helper
*/
/**
* @package Piwik_Helper
*
*/
class Piwik_Url
{
static function getArrayFromCurrentQueryString()
{
$queryString = Piwik_Url::getCurrentQueryString();
$queryString = htmlspecialchars($queryString);
$urlValues = Piwik_Common::getArrayFromQueryString($queryString);
return $urlValues;
}
static function getCurrentQueryStringWithParametersModified( $params )
{
$urlValues = self::getArrayFromCurrentQueryString();
foreach($params as $key => $value)
{
$urlValues[$key] = $value;
}
$query = http_build_query($urlValues);
if(strlen($query) > 0)
{
return '?'.$query;
}
else
{
return '';
}
}
static public function redirectToUrl( $url )
{
header("Location: $url");
exit;
}
static public function getReferer()
{
if(!empty($_SERVER['HTTP_REFERER']))
{
return $_SERVER['HTTP_REFERER'];
}
return false;
}
static public function getCurrentUrl()
{
return self::getCurrentHost()
. self::getCurrentScriptName()
. self::getCurrentQueryString();
}
static public function getCurrentUrlWithoutQueryString()
{
return self::getCurrentHost()
. self::getCurrentScriptName() ;
}
/**
* Ending with /
*/
static public function getCurrentUrlWithoutFileName()
{
$host = self::getCurrentHost();
$queryString = self::getCurrentScriptName() ;
//add a fake letter case /test/test2/ returns /test which is not expected
$urlDir = dirname ($queryString . 'x');
// if we are in a subpath we add a trailing slash
if(strlen($urlDir) > 1)
{
$urlDir .= '/';
}
return $host.$urlDir;
}
static public function getCurrentScriptName()
{
$url = '';
if( !empty($_SERVER['PATH_INFO']) )
{
$url = $_SERVER['PATH_INFO'];
}
else if( !empty($_SERVER['REQUEST_URI']) )
{
if( ($pos = strpos($_SERVER['REQUEST_URI'], "?")) !== false )
{
$url = substr($_SERVER['REQUEST_URI'], 0, $pos);
}
else
{
$url = $_SERVER['REQUEST_URI'];
}
}
if(empty($url))
{
$url = $_SERVER['SCRIPT_NAME'];
}
return $url;
}
static public function getCurrentHost()
{
if(isset($_SERVER['HTTPS'])
&& ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] === true)
)
{
$url = 'https';
}
else
{
$url = 'http';
}
$url .= '://' . $_SERVER['HTTP_HOST'];
return $url;
}
static public function getCurrentQueryString()
{
$url = '';
if(isset($_SERVER['QUERY_STRING'])
&& !empty($_SERVER['QUERY_STRING']))
{
$url .= "?".$_SERVER['QUERY_STRING'];
}
return $url;
}
}
|