MkFramework
 All Data Structures Functions
plugin_routing.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 */
24 
25  private $tRoute;
26 
31  public function __construct(){
32  include _root::getConfigVar('urlrewriting.conf');
33  $this->tRoute=$tab;
34  }
35 
43  public function getLink($sNav,$tParam=null,$bAmp=null){
44  foreach($this->tRoute as $sUrl=>$tUrl){
45  if($tUrl['nav']==$sNav and !isset($tUrl['tParam']) and $tParam==null){
46  return $this->convertUrl($sUrl,$tParam);//si pas de parametres des deux cotes, c est la bonne regle
47  }elseif($tUrl['nav']==$sNav and isset($tUrl['tParam']) and is_array($tUrl['tParam']) and is_array($tParam) ){
48 
49  foreach($tUrl['tParam'] as $val){
50  if(!isset($tParam[$val])){
51  continue 2;
52  }
53  }
54 
55  return $this->convertUrl($sUrl,$tParam);
56  //si la regle demande des parametres, tous presents dans les parametres passes on choisi celle-ci
57  }
58  }
59  return _root::getLinkString($sNav,$tParam,$bAmp);
60  }
66  public function parseUrl($sUrl){
67  $sRootScript=$_SERVER['SCRIPT_NAME'];
68  $sRootScript=str_replace(_root::getConfigVar('navigation.scriptname'),'',$sRootScript);
69  $sUrl=str_replace($sRootScript,'',$sUrl);
70 
71  /*LOG*/_root::getLog()->info('plugin_routing parseUrl('.$sUrl.')');
72  if(is_array($this->tRoute)){
73  foreach($this->tRoute as $sPattern => $tUrl){
74  $sPattern=preg_replace('/:([^:])*:/','([^/]*)',$sPattern);
75  $sPattern=preg_replace('/\//','\/',$sPattern);
76 
77  if(preg_match_all('/^'.$sPattern.'$/',$sUrl,$tTrouve)){
78  _root::getRequest()->loadModuleAndAction($tUrl['nav']);
79  if(isset($tUrl['tParam']) and is_array($tTrouve[1])){
80  $j=0;
81  foreach($tTrouve as $i => $found){
82  if($i==0){
83  continue;
84  }
85  $j=$i-1;
86  _root::setParam($tUrl['tParam'][$j],$found[0]);
87  }
88  }
89  if(isset($tUrl['tParamHidden'])){
90  foreach($tUrl['tParamHidden'] as $key => $val){
91  _root::setParam($key,$val);
92  }
93  }
94  return;
95  }
96  }
97  /*LOG*/_root::getLog()->info('plugin_routing regle non trouve,
98  utilisation de 404 loadModuleAndAction('.$this->tRoute['404']['nav'].')');
99  if(_root::getConfigVar('urlrewriting.use4O4')==1){
100  _root::getRequest()->loadModuleAndAction($this->tRoute['404']['nav']);
101  }
102  }
103  }
104 
105  private function convertUrl($sUrl,$tParam=null){
106  if(is_array($tParam)){
107  foreach($tParam as $sVar => $sVal){
108  $sUrl=preg_replace('/:'.$sVar.':/',$sVal,$sUrl);
109  }
110  }
111  return $sUrl;
112  }
113 
114 
115 
116 }
static getConfigVar($sCatAndVar, $uDefaut=null)
Definition: class_root.php:654
getLink($sNav, $tParam=null, $bAmp=null)
static getRequest()
Definition: class_root.php:541
static getLinkString($sNav, $tParam=null, $bAmp=true)
Definition: class_root.php:778
static getLog()
Definition: class_root.php:610
static setParam($sVar, $uValue)
Definition: class_root.php:453