MkFramework
 All Data Structures Functions
class_request.php
1 <?php
2 /*
3 This file is part of Mkframework.
4 
5 Mkframework is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License.
8 
9 Mkframework is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13 
14 You should have received a copy of the GNU Lesser General Public License
15 along with Mkframework. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
23 class _request{
24 
25  private $_tVar;
26  private $_sModule;
27  private $_sAction;
28  private $_bHasNavigation;
29 
35  public function __construct(){
36 
37  $this->_sModule=_root::getConfigVar('navigation.module.default',null);
38 
39  $this->_sAction=_root::getConfigVar('navigation.action.default',null);
40 
41  $this->_tVar=array();
42 
43  $this->_bHasNavigation=false;
44  }
51  public function getParam($sVar,$else=null){
52 
53  if(array_key_exists($sVar,$this->_tVar)){
54  if( (int)_root::getConfigVar('security.xss.enabled')==1){
55  if(is_array($this->_tVar[$sVar]) ){
56  return array_map('customHtmlentities',$this->_tVar[$sVar]);
57  }
58  return customHtmlentities($this->_tVar[$sVar]);
59  }else{
60  return $this->_tVar[$sVar];
61  }
62  }else{
63  return $else;
64  }
65  }
66 
67 
68 
69 
70 
71 
72 
73 
74 
81  public function setParam($sVar,$val){
82  $this->_tVar[$sVar]=$val;
83  if(!$this->hasNavigation()){
84  $this->loadContext();
85  }
86  }
87 
91  public function getParams(){
92  if( (int)_root::getConfigVar('security.xss.enabled')==1){
93  return array_map('customHtmlentities',$this->_tVar);
94  }else{
95  return $this->_tVar;
96  }
97  }
98 
102  public function getParamsGET(){
103  if( (int)_root::getConfigVar('security.xss.enabled')==1){
104  $tParam=array();
105  foreach($_GET as $key => $val){
106  $tParam[customHtmlentities($key)]=customHtmlentities($val);
107  }
108 
109  }else{
110  $tParam= $_GET;
111  }
112  unset($tParam[ _root::getConfigVar('navigation.var') ] );
113 
114  return $tParam;
115  }
116 
120  public function getParamsPOST(){
121  if( (int)_root::getConfigVar('security.xss.enabled')==1){
122  return array_map('customHtmlentities',$_POST);
123  }else{
124  return $_POST;
125  }
126  }
127 
133  public function getParamNav(){
134 
135  return $this->getModule().'::'.$this->getAction();
136  }
142  public function setParamNav($sNav){
143  $this->loadModuleAndAction($sNav);
144  }
145 
152  public function hasNavigation(){
153  return $this->_bHasNavigation;
154  }
160  public function setModule($sModule){
161  $this->_sModule=$sModule;
162  }
168  public function setAction($sAction){
169  $this->_sAction=$sAction;
170  }
176  public function getModule(){
177  return $this->_sModule;
178  }
184  public function getAction(){
185  return $this->_sAction;
186  }
187 
188  private function loadContext(){
189  if($this->getParam( _root::getConfigVar('navigation.var'),null)!==null ){
190  $this->loadModuleAndAction($this->getParam( _root::getConfigVar('navigation.var') ) );
191  }else{
192  $this->setModule( _root::getConfigVar('navigation.module.default'));
193  $this->setAction( _root::getConfigVar('navigation.action.default'));
194  }
195  }
201  public function loadModuleAndAction($sChaine){
202  $this->_tVar[ _root::getConfigVar('navigation.var') ]=$sChaine;
203  $this->_bHasNavigation=true;
204  $sModule='';
205  $sAction='';
206  if(preg_match('/::/',$sChaine)){
207  list($sModule,$sAction)=preg_split('/::/',$sChaine);
208  }else{
209  $sModule=$sChaine;
210  }
211  if($sAction==''){
212  $sAction='index';
213  }
214  if($sModule==''){
215  $sModule='index';
216  }
217  $this->setModule($sModule);
218  $this->setAction($sAction);
219  }
220 
226  public function isPost(){
227  if($_SERVER['REQUEST_METHOD']=='POST'){ return true;}
228  return false;
229  }
235  public function isGet(){
236  if($_SERVER['REQUEST_METHOD']=='GET'){ return true;}
237  return false;
238  }
239 
240  public function stripslashes_deep($value){
241  if(is_array($value)){
242  return array_map('stripslashes_deep', $value);
243  }else{
244  return stripslashes($value);
245  }
246  }
247  public function magic_quote(){
248  $this->_tVar=array_map('stripslashes_deep', $this->_tVar);
249  }
250 
251  public function __set($sVar,$sVal){
252  $this->_tVar[$sVar]=$sVal;
253  }
254  public function __get($sVar){
255  return $this->_tVar[$sVar];
256  }
257 
258 
259 }
setAction($sAction)
getParam($sVar, $else=null)
static getConfigVar($sCatAndVar, $uDefaut=null)
Definition: class_root.php:654
setParamNav($sNav)
loadModuleAndAction($sChaine)
setModule($sModule)
setParam($sVar, $val)