MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mcontext.class
Ir para a documentação deste ficheiro.
1
<?php
2
class
MContext
3
{
4
const
DISPATCH
= 1;
5
const
MODULE
= 3;
6
const
ACTION
= 5;
7
const
DELIMITER
= 6;
8
const
TYPE
= 7;
9
10
public
$manager
;
11
public
$module
;
12
public
$action
;
13
public
$item
;
14
private
$actionTokens;
15
private
$currentToken;
16
private
$path;
17
private
$queryString;
18
private
$vars;
19
private
$host;
20
private
$dispatch;
21
public
$style
;
// 0 - old; 1 = new without rewrite; 2 = new with rewrite
22
public
$isFile
;
23
public
$isRoot
;
24
public
$fileName
;
25
public
$fileArea
;
26
public
$fileType
;
27
public
$scramble
;
28
29
30
public
function
__construct
(
$url
=
''
,
$style
= 0,
$scramble
=
false
)
31
{
32
global
$MIOLO
;
33
34
$this->dispatch =
$MIOLO
->getConf(
'options.dispatch'
);
35
36
if
(empty(
$url
))
37
{
38
$httpHost = isset($_SERVER[
'HTTP_HOST'
]) ? $_SERVER[
'HTTP_HOST'
] :
null
;
39
$scriptName = isset($_SERVER[
'SCRIPT_NAME'
]) ? $_SERVER[
'SCRIPT_NAME'
] :
null
;
40
$pathInfo = isset($_SERVER[
'PATH_INFO'
]) ? $_SERVER[
'PATH_INFO'
] :
null
;
41
$queryString = isset($_SERVER[
'QUERY_STRING'
]) ? $_SERVER[
'QUERY_STRING'
] :
null
;
42
$url
=
"http://$httpHost$scriptName$pathInfo"
;
43
if
($queryString !=
''
)
44
{
45
$url
.=
"?{$queryString}"
;
46
}
47
}
48
$this->style = (int)
$style
;
49
$this->scramble = (bool)
$scramble
;
50
if
(strpos(
$url
,
'MIOLO_URI'
))
51
{
52
$url
= $this->parseScramble(
$url
);
53
}
54
$this->parseUrl(
$url
);
55
56
if
(!$this->module)
57
{
58
$this->module =
$MIOLO
->getConf(
'options.startup'
);
59
}
60
if
(!$this->action)
61
{
62
$this->action =
'main'
;
63
$this->GetTokens();
64
}
65
}
66
67
private
function
parseScramble(
$url
)
68
{
69
global
$MIOLO
;
70
$urlParts = parse_url(
$url
);
71
parse_str($urlParts[
'query'
], $this->vars);
72
$url
= preg_replace(
'/\?MIOLO_URI=.*/'
,
$MIOLO
->UnScramble($this->vars[
'MIOLO_URI'
]),
$url
);
73
return
$url
;
74
}
75
76
private
function
parseUrl(
$url
)
77
{
78
$url
= str_replace(
'&'
,
'&'
,
$url
);
79
$urlParts = parse_url(
$url
);
80
$this->path = isset($urlParts[
'path'
]) ? $urlParts[
'path'
] :
''
;
81
82
$this->host =
'//'
. isset($urlParts[
'host'
]) ? $urlParts[
'host'
] :
''
;
83
if
( !empty($urlParts[
'port'
]) )
84
{
85
$this->host .=
':'
. $urlParts[
'port'
];
86
}
87
88
89
if
( !empty($urlParts[
'query'
]) )
90
{
91
$this->queryString = $urlParts[
'query'
];
92
parse_str($this->queryString, $this->vars);
93
}
94
95
96
if
(($this->path !=
"/{$this->dispatch}"
) || ($this->queryString !=
''
))
97
{
98
$this->style = (strpos(
$url
,
'module'
) ? 0 : 1);
99
$this->parseURI();
100
}
101
}
102
103
private
function
parseURI()
104
{
105
global
$MIOLO
;
106
107
$uri = trim($this->path) . (($this->queryString !=
''
) ?
'?'
. $this->queryString :
''
);
108
109
if
( strpos($uri,
'index.php'
) === FALSE )
110
{
111
$uri = $_SERVER[
'SCRIPT_NAME'
];
112
}
113
114
$regexp = ($this->style == 0) ?
115
"#\/({$this->dispatch})(\?)module=([^&]*)(&?action=([^&.]*)(&|\.|$)(.*)|$)#"
:
116
"#\/({$this->dispatch})(/?)([^\/]*)(/([^&.]*)(&|\.|$)(.*)|$)#"
;
117
$this->isFile =
false
;
118
if
(preg_match($regexp, $uri, $parts))
119
{
120
$this->dispatch = isset($parts[self::DISPATCH]) ? $parts[
self::DISPATCH
] :
null
;
121
$this->module = isset($parts[self::MODULE]) ? $parts[
self::MODULE
] :
null
;
122
$this->action = isset($parts[self::ACTION]) ? str_replace(
'/'
,
':'
, $parts[self::ACTION]) : null;
123
$this->delimiter = isset($parts[self::DELIMITER]) ? $parts[
self::DELIMITER
] :
null
;
124
$this->fileType = isset($parts[self::TYPE]) ? $parts[
self::TYPE
] :
null
;
125
$this->GetTokens();
126
}
127
else
128
{
129
if
(
$MIOLO
->getConf(
'options.dispatch.ignore'
) ==
'true'
)
130
{
131
// do nothing
132
// undocumented temporary workaround.. ;-)
133
}
134
else
135
{
136
// TODO: Display a default 404 error page not found message
137
if
( !isset($_REQUEST[
'webservice'
]) && !isset($_REQUEST[
'WSDL'
]) && strpos($uri,
'wsdl.php'
) === FALSE )
138
{
139
//die ('invalid URL - regexp: '.$uri);
140
}
141
}
142
}
143
}
144
145
private
function
GetTokens()
146
{
147
$this->actionTokens = explode(
':'
, $this->action);
148
$this->currentToken = 0;
149
150
if
($this->delimiter ==
'.'
)
151
{
152
$this->fileArea = array_shift($this->actionTokens);
153
$fileName
= array_pop($this->actionTokens);
154
155
if
(
$fileName
!= NULL)
156
{
157
$this->isRoot = ($this->module ==
'miolo'
);
158
$this->isFile =
true
;
159
$path = implode(
'/'
, $this->actionTokens);
160
$this->fileName = ($path !=
''
?
'/'
. $path .
'/'
:
'/'
) .
$fileName
.
'.'
. $this->fileType;
161
}
162
else
163
{
164
die (
'invalid URL - filetype'
);
165
}
166
}
167
}
168
169
function
SetStyle
($value = 0)
170
{
171
$this->style = $value;
172
}
173
174
function
GetStyle
()
175
{
176
return
$this->style
;
177
}
178
179
function
GetAction
($index = 0)
180
{
181
$action
= ($index >= 0) && ($index < count($this->actionTokens)) ? $this->actionTokens[$index] : NULL;
182
183
return
$action
;
184
}
185
186
function
GetVar
($name)
187
{
188
return
isset($this->vars[$name]) ? $this->vars[$name] :
null
;
189
}
190
191
public
function
getVars
()
192
{
193
return
$this->vars;
194
}
195
196
function
ShiftAction
()
197
{
198
$action
= $this->currentToken < count($this->actionTokens) ? $this->actionTokens[$this->currentToken++] :
null
;
199
return
$action
;
200
}
201
202
function
PushAction
($a)
203
{
204
if
($this->action)
205
$this->action .=
'/'
;
206
207
$this->action .= $a;
208
209
$this->actionTokens = explode(
'/'
, $this->action);
210
$this->currentToken = 0;
211
}
212
213
function
ComposeURL
($dispatch =
''
,
$module
=
''
,
$action
=
''
, $args =
''
,
$scramble
=
false
)
214
{
215
global
$MIOLO
;
216
217
$dispatch = ($dispatch ==
''
) ? $this->dispatch : $dispatch;
218
$module
= (
$module
==
''
) ? $this->module :
$module
;
219
$action
= (
$action
==
''
) ? (($this->action ==
''
) ?
'main'
:
$this->action
) :
$action
;
220
221
$amp =
'&'
;
222
if
($this->style)
223
{
224
$action
= str_replace(
':'
,
'/'
,
$action
);
225
$url
=
"/$module/$action"
. ($args ?
'?'
. $args :
''
);
226
}
227
else
228
{
229
$url
=
"?module=$module"
. $amp .
"action=$action"
. ($args ? $amp . $args :
''
);
230
}
231
232
if
($this->scramble ||
$scramble
)
233
{
234
$url
=
"$dispatch?MIOLO_URI="
.
$MIOLO
->Scramble(
$url
);
235
}
236
else
237
{
238
$url
=
"$dispatch"
.
$url
;
239
}
240
return
$url
;
241
}
242
243
public
function
getPreviousAction
()
244
{
245
$tokens = explode(
':'
,$this->action);
246
unset($tokens[
sizeof
($tokens)-1]);
247
return
implode(
':'
,$tokens);
248
}
249
250
}
251
?>
MContext
Definição
mcontext.class:3
MContext\SetStyle
SetStyle($value=0)
Definição
mcontext.class:169
MContext\getPreviousAction
getPreviousAction()
Definição
mcontext.class:243
MContext\__construct
__construct($url='', $style=0, $scramble=false)
Definição
mcontext.class:30
MContext\$manager
$manager
Definição
mcontext.class:10
MContext\$style
$style
Definição
mcontext.class:21
MContext\GetStyle
GetStyle()
Definição
mcontext.class:174
MContext\GetAction
GetAction($index=0)
Definição
mcontext.class:179
MContext\ComposeURL
ComposeURL($dispatch='', $module='', $action='', $args='', $scramble=false)
Definição
mcontext.class:213
MContext\MODULE
const MODULE
Definição
mcontext.class:5
MContext\$fileName
$fileName
Definição
mcontext.class:24
MContext\$isFile
$isFile
Definição
mcontext.class:22
MContext\PushAction
PushAction($a)
Definição
mcontext.class:202
MContext\TYPE
const TYPE
Definição
mcontext.class:8
MContext\DISPATCH
const DISPATCH
Definição
mcontext.class:4
MContext\ShiftAction
ShiftAction()
Definição
mcontext.class:196
MContext\$item
$item
Definição
mcontext.class:13
MContext\$action
$action
Definição
mcontext.class:12
MContext\$fileArea
$fileArea
Definição
mcontext.class:25
MContext\$fileType
$fileType
Definição
mcontext.class:26
MContext\GetVar
GetVar($name)
Definição
mcontext.class:186
MContext\$isRoot
$isRoot
Definição
mcontext.class:23
MContext\getVars
getVars()
Definição
mcontext.class:191
MContext\$scramble
$scramble
Definição
mcontext.class:27
MContext\$module
$module
Definição
mcontext.class:11
MContext\DELIMITER
const DELIMITER
Definição
mcontext.class:7
MContext\ACTION
const ACTION
Definição
mcontext.class:6
$MIOLO
$MIOLO
Definição
mdatetimefield.class:25
$url
$url
Definição
base.php:2
classes
utils
mcontext.class
Gerado por
1.10.0