forked from imikado/mkframeworkLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_request.php
More file actions
259 lines (225 loc) · 5.7 KB
/
class_request.php
File metadata and controls
259 lines (225 loc) · 5.7 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php
/*
This file is part of Mkframework.
Mkframework is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License.
Mkframework is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Mkframework. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* _request classe pour gerer le les requete
* @author Mika
* @link http://mkf.mkdevs.com/
*/
class _request{
private $_tVar;
private $_sModule;
private $_sAction;
private $_bHasNavigation;
/**
* constructeur
* @access public
* @param array $tTab tableau de la requete $_GET, $_POST...
*/
public function __construct(){
$this->_sModule=_root::getConfigVar('navigation.module.default',null);
$this->_sAction=_root::getConfigVar('navigation.action.default',null);
$this->_tVar=array();
$this->_bHasNavigation=false;
}
/**
* retourne le parametre $sVar ou $else
* @access public
* @return undefined $else
* @param string $sVar variable a retourner
*/
public function getParam($sVar,$else=null){
if(array_key_exists($sVar,$this->_tVar)){
if( (int)_root::getConfigVar('security.xss.enabled',0)==1 or (int)_root::getConfigVar('security.xss.getParam.enabled',0)==1 ){
if(is_array($this->_tVar[$sVar]) ){
return array_map('customHtmlentities',$this->_tVar[$sVar]);
}
return customHtmlentities($this->_tVar[$sVar]);
}else{
return $this->_tVar[$sVar];
}
}else{
return $else;
}
}
/**
* force une variable de request
* @access public
* @param string $sVar
* @param string $val
*/
public function setParam($sVar,$val){
$this->_tVar[$sVar]=$val;
if(!$this->hasNavigation()){
$this->loadContext();
}
}
/**
* recupere un tableau de l'ensemble des parametres
*/
public function getParams(){
if( (int)_root::getConfigVar('security.xss.enabled')==1){
return array_map('customHtmlentities',$this->_tVar);
}else{
return $this->_tVar;
}
}
/**
* recupere un tableau de l'ensemble des parametres GET (hors navigation: module::action)
*/
public function getParamsGET(){
if( (int)_root::getConfigVar('security.xss.enabled')==1){
$tParam=array();
foreach($_GET as $key => $val){
$tParam[customHtmlentities($key)]=customHtmlentities($val);
}
}else{
$tParam= $_GET;
}
unset($tParam[ _root::getConfigVar('navigation.var') ] );
return $tParam;
}
/**
* recupere un tableau de l'ensemble des parametres POST
*/
public function getParamsPOST(){
if( (int)_root::getConfigVar('security.xss.enabled')==1){
return array_map('customHtmlentities',$_POST);
}else{
return $_POST;
}
}
/**
* retourne la valeur de navigation
* @access public
* @return string navigation (module::action)
*/
public function getParamNav(){
return $this->getModule().'::'.$this->getAction();
}
/**
* force une variable de navigation
* @access public
* @param string $sNav
*/
public function setParamNav($sNav){
$this->loadModuleAndAction($sNav);
}
/**
* retourne le parametre $sVar ou $else
* @access public
* @return undefined $else
* @param string $sVar variable a retourner
*/
public function hasNavigation(){
return $this->_bHasNavigation;
}
/**
* defini le module $sModule
* @access public
* @param string $sModule
*/
public function setModule($sModule){
$this->_sModule=$sModule;
}
/**
* defini le module $sAction
* @access public
* @param string $sAction
*/
public function setAction($sAction){
$this->_sAction=$sAction;
}
/**
* retourne le module
* @access public
* @return string
*/
public function getModule(){
return $this->_sModule;
}
/**
* retourne l'action
* @access public
* @return string
*/
public function getAction(){
return $this->_sAction;
}
private function loadContext(){
if($this->getParam( _root::getConfigVar('navigation.var'),null)!==null ){
$this->loadModuleAndAction($this->getParam( _root::getConfigVar('navigation.var') ) );
}else{
$this->setModule( _root::getConfigVar('navigation.module.default'));
$this->setAction( _root::getConfigVar('navigation.action.default'));
}
}
/**
* initialise module/action a partir d'une chaine module::action
* @access public
* @param string $sChaine
*/
public function loadModuleAndAction($sChaine){
$this->_tVar[ _root::getConfigVar('navigation.var') ]=$sChaine;
$this->_bHasNavigation=true;
$sModule='';
$sAction='';
if(preg_match('/::/',$sChaine)){
list($sModule,$sAction)=preg_split('/::/',$sChaine);
}else{
$sModule=$sChaine;
}
if($sAction==''){
$sAction='index';
}
if($sModule==''){
$sModule='index';
}
$this->setModule($sModule);
$this->setAction($sAction);
}
/**
* indique si la requete utilise la methode POST (soumission de formulaire par exple)
* @access public
* @return bool
*/
public function isPost(){
if($_SERVER['REQUEST_METHOD']=='POST'){ return true;}
return false;
}
/**
* indique si la requete utilise la methode GET
* @access public
* @return bool
*/
public function isGet(){
if($_SERVER['REQUEST_METHOD']=='GET'){ return true;}
return false;
}
public function stripslashes_deep($value){
if(is_array($value)){
return array_map('stripslashes_deep', $value);
}else{
return stripslashes($value);
}
}
public function magic_quote(){
$this->_tVar=array_map('stripslashes_deep', $this->_tVar);
}
public function __set($sVar,$sVal){
$this->_tVar[$sVar]=$sVal;
}
public function __get($sVar){
return $this->_tVar[$sVar];
}
}