Changeset 51

Show
Ignore:
Timestamp:
01/25/06 01:16:35 (3 years ago)
Author:
laurentj
Message:

avancement sur les urls significatifs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix-scripts/templates/config.classic.ini.php.tpl

    r44 r51  
    5050 
    5151[urlengine] 
     52; nom du moteur d'url :  simple ou significant 
     53engine        = simple 
    5254 
    53 ;indique si vous utiliser IIS comme serveur 
     55; active l'analyse d'url (mettre �ff si vous utilisez le mod_rewrite d'apache) 
     56enable_parser = on 
     57 
     58multiview_on = off 
     59 
     60default_entrypoint= index 
     61 
     62entrypoint_extension= .php 
     63 
     64notfound_act = "jelix~notfound" 
     65 
     66;indique si vous utilisez IIS comme serveur 
    5467use_IIS = off 
    5568 
    56 ;indique le param�e dans $_GET ou est indiqu�e path_info 
     69;indique le param�e dans $_GET o indiqu�e path_info 
    5770IIS_path_key = __JELIX_URL__ 
    5871 
     
    6073IIS_stripslashes_path_key = on 
    6174 
    62 default_entrypoint= index 
    63 entrypoint_extension= .php 
    6475 
    65 engine        = default 
    66 enable_parser = on 
    67 multiview_on = off 
    68 notfound_dest = "jelix~notfound" 
     76[simple_urlengine_entrypoints] 
     77; param�es pour le moteur d'url simple : liste des points d'entr� avec les actions 
     78; qui y sont rattach� 
    6979 
    70 [urlengine_specific_entrypoints] 
     80 
    7181; nom_script_sans_suffix = "liste de selecteur d'action s�r�ar un espace" 
    7282; selecteurs : 
  • trunk/lib/jelix/core/jConfig.class.php

    r41 r51  
    5555            $config->trustedModules = array_keys($config->modulesPathList); 
    5656        } 
    57         //$config->urlengine_specific_entrypoints = array_flip($config->urlengine_specific_entrypoints); 
     57 
    5858        return $config; 
    5959    } 
  • trunk/lib/jelix/core/jCoordinator.class.php

    r44 r51  
    6262        $this->configFile = $configFile; 
    6363        $gJConfig = jConfig::load($configFile); 
    64         //$this->_initConfig(); 
    6564 
    6665        // set Error and exception handler 
    67         set_error_handler('jErrorHandler'); 
    68         set_exception_handler('JExceptionHandler'); 
     66        //set_error_handler('jErrorHandler'); 
     67        //set_exception_handler('JExceptionHandler'); 
    6968 
    7069        $this->_loadPlugins(); 
     
    102101 
    103102        $this->request = $request; 
    104                  session_start(); 
     103        session_start(); 
    105104 
    106105        $this->moduleName = $this->request->getParam('module', $gJConfig->defaultModule,true); 
     
    204203    * gets a given plugin if registered 
    205204    * @param string   $plugin_name   nom du plugin 
    206     * @param boolean  $required        if the plugin is required or not. If true, will trigger a fatal_error if the plugin is not registered. 
     205    * @param boolean  $required if the plugin is required or not. If true, will trigger a fatal_error if the plugin is not registered. 
    207206    */ 
    208207    function getPlugin ($pluginName, $required = true){ 
  • trunk/lib/jelix/core/jDefaultConfig.lib.php

    r41 r51  
    6969    'default_entrypoint' => 'index', 
    7070    'entrypoint_extension' => '.php', 
    71     'engine' => 'default', 
     71    'engine' => 'simple', 
    7272    'enable_parser' => '1', 
    7373    'multiview_on' => '', 
    74     'notfound_dest' => 'jelix~notfound' 
     74    'notfound_act' => 'jelix~notfound' 
    7575  ), 
    7676  'urlengine_specific_entrypoints' => 
  • trunk/lib/jelix/core/jIncluder.class.php

    r36 r51  
    4040        ); 
    4141    } 
    42  
    43     public static function URL(){ 
    44         return  array('jUrlCompiler', 
    45                     'core/url/jUrlCompiler.class.php', 
    46                     'actions.xml', 
    47                     'urls.php' 
    48         ); 
    49     } 
    50  
    5142 
    5243    /** 
  • trunk/lib/jelix/core/jSelector.class.php

    r44 r51  
    1717*/ 
    1818class jSelectorFactory { 
    19        function create ($id){ 
     19   function create ($id){ 
    2020        if(preg_match("/^([a-z]{3,5})\:([\w~\/\.]+)$/", $id, $m)){ 
    2121            $cname='jSelector'.$m[1]; 
     
    2424                if($sel->isValid()) 
    2525                    return $sel; 
    26                        
     26         
    2727        } 
    2828        trigger_error (jLocale::get ('jelix~errors.selector.unknown', $id)); 
    2929        $ret = null; 
    3030        return $ret; 
    31        
     31   
    3232} 
    3333 
     
    3636 */ 
    3737interface jISelector { 
    38        public function getPath (); 
     38   public function getPath (); 
    3939   public function isValid(); 
    40        public function getCompiledFilePath (); 
     40   public function getCompiledFilePath (); 
    4141   public function getCompiler(); 
    4242   public function useMultiSourceCompiler(); 
    43        public function toString($full=false); 
     43   public function toString($full=false); 
    4444} 
    4545 
     
    4848*/ 
    4949abstract class jSelectorModule implements jISelector { 
    50        public $type = '_module'; 
    51        public $module = null; 
    52        public $resource = null; 
     50   public $type = '_module'; 
     51   public $module = null; 
     52   public $resource = null; 
    5353 
    5454    private $_valid; 
     
    6262    protected $_useMultiSourceCompiler=false; 
    6363 
    64        function __construct($sel){ 
     64   function __construct($sel){ 
    6565 
    6666        if(preg_match("/^(([\w\.]+)~)?([\w\.]+)$/", $sel, $m)){ 
     
    7878        } 
    7979 
    80        
    81  
    82        public function getPath (){ 
     80   
     81 
     82   public function getPath (){ 
    8383        $this->_createPath(); 
    8484        return $this->_path; 
    85        
     85   
    8686 
    8787    public function isValid(){ 
     
    9090 
    9191 
    92        public function getCompiledFilePath (){ 
     92   public function getCompiledFilePath (){ 
    9393        $this->_createCachePath(); 
    9494        return $this->_cachePath; 
    95        
     95   
    9696 
    9797    public function getCompiler(){ 
     
    106106    } 
    107107 
    108        public function toString($full=false){ 
     108   public function toString($full=false){ 
    109109        if($full) 
    110110            return $this->type.':'.$this->module.'~'.$this->resource; 
    111111        else 
    112112            return $this->module.'~'.$this->resource; 
    113        
     113   
    114114 
    115115    protected function _createPath(){ 
     
    186186    } 
    187187 
     188    public function toString($full=false){ 
     189        if($full) 
     190            return $this->type.':'.$this->module.'~'.$this->resource.'@'.$this->request; 
     191        else 
     192            return $this->module.'~'.$this->resource.'@'.$this->request; 
     193    } 
    188194} 
    189195 
     
    372378*/ 
    373379class jSelectorPlugin implements jISelector { 
    374        public $type = 'plug'; 
     380   public $type = 'plug'; 
    375381    public $plugin=''; 
    376382    public $file = ''; 
     
    378384    private $_path; 
    379385 
    380        function __construct($sel){ 
     386   function __construct($sel){ 
    381387        global $gJConfig; 
    382388        if(preg_match("/^([\w\.]+)~([\w\.]+)$/", $sel, $m)){ 
     
    391397            $this->_valid=false; 
    392398        } 
    393        
    394  
    395        public function getPath (){ 
     399   
     400 
     401   public function getPath (){ 
    396402        global $gJConfig; 
    397403        if(isset($gJConfig->pluginsPathList[$this->plugin])){ 
     
    400406            return ''; 
    401407        } 
    402        
     408   
    403409 
    404410    public function isValid(){ 
     
    406412    } 
    407413 
    408        public function toString($full=false){ 
     414   public function toString($full=false){ 
    409415        if($full) 
    410416            return $this->type.':'.$this->plugin.'~'.$this->file; 
    411417        else 
    412418            return $this->plugin.'~'.$this->file; 
    413        
     419   
    414420 
    415421   public function getCompiler(){ return null;} 
    416422   public function useMultiSourceCompiler() { return false;} 
    417        public function getCompiledFilePath (){ return '';} 
     423   public function getCompiledFilePath (){ return '';} 
    418424 
    419425} 
     
    427433*/ 
    428434class jSelectorSimpleFile implements jISelector { 
    429        public $type = 'simplefile'; 
     435   public $type = 'simplefile'; 
    430436    public $file = ''; 
    431437    protected $_valid; 
     
    433439    protected $_basePath=''; 
    434440 
    435        function __construct($sel){ 
     441   function __construct($sel){ 
    436442        if(preg_match("/^([\w\.\/]+)$/", $sel, $m)){ 
    437443            $this->file = $m[1]; 
     
    441447            $this->_valid = false; 
    442448        } 
    443        
    444  
    445        public function getPath (){ 
     449   
     450 
     451   public function getPath (){ 
    446452        return $this->_path; 
    447        
     453   
    448454 
    449455    public function isValid(){ 
     
    451457    } 
    452458 
    453        public function toString($full=false){ 
     459   public function toString($full=false){ 
    454460        if($full) 
    455461            return $this->type.':'.$this->file; 
    456462        else 
    457463            return $this->file; 
    458        
     464   
    459465    public function getCompiler(){ return null;} 
    460466    public function useMultiSourceCompiler() { return false;} 
    461        public function getCompiledFilePath (){ return '';} 
     467   public function getCompiledFilePath (){ return '';} 
    462468} 
    463469 
     
    467473     function __construct($sel){ 
    468474        $this->_basePath = JELIX_APP_VAR_PATH; 
    469         parent::_construct($sel); 
     475        parent::__construct($sel); 
    470476     } 
    471477} 
     
    475481     function __construct($sel){ 
    476482        $this->_basePath = JELIX_APP_CONFIG_PATH; 
    477         parent::_construct($sel); 
     483        parent::__construct($sel); 
    478484     } 
    479485} 
  • trunk/lib/jelix/core/url/jUrl.class.php

    r50 r51  
    2525    */ 
    2626  public function parse($scriptNamePath, $params, $pathinfo ); 
    27    
     27 
    2828  /** 
    2929   * Modifie les donn� de l'url selon le type d'url propos�ar le moteur d'url 
     
    125125               $urlobj->requestType = $gJCoord->request->type; 
    126126            } 
    127              
     127 
    128128            $engine = & self::getEngine(); 
    129129            $engine->create($urlobj); // set path info 
     
    288288            $file = JELIX_LIB_CORE_PATH.'url/jUrlEngine.'.$GLOBALS['gJConfig']->urlengine['engine'].'.class.php'; 
    289289            if(!file_exists($file)){ 
    290                 trigger_error("Url engine doesn't exist",E_USER_ERROR); 
     290                trigger_error("Url engine doesn't exist (".$GLOBALS['gJConfig']->urlengine['engine'].')',E_USER_ERROR); 
    291291                return null; 
    292292            } 
    293293            include_once($file); 
    294294            $cl='jUrlEngine'.$GLOBALS['gJConfig']->urlengine['engine']; 
    295             $engine = new $cl();  
     295            $engine = new $cl(); 
    296296        } 
    297297        return $engine; 
  • trunk/lib/jelix/core/url/jUrlCompiler.significant.class.php

    r50 r51  
    2222* Compilateur pour le moteur d'url significatifs 
    2323*/ 
    24 class jUrlCompiler implements jISimpleCompiler{ 
     24class jUrlCompilerSignificant implements jISimpleCompiler{ 
    2525 
    2626    public function compile($aSelector){ 
    2727        global $gJCoord; 
    2828 
    29         $sourceFile = $selector->getPath(); 
    30         $cachefile = $selector->getCompiledFilePath(); 
     29        $sourceFile = $aSelector->getPath(); 
     30        $cachefile = $aSelector->getCompiledFilePath(); 
    3131 
    3232 
     
    8181        $createUrlContent="<?php \n"; 
    8282        $defaultEntrypoints=array(); 
     83        $file = new jFile(); 
    8384        foreach($xml->children() as $name=>$tag){ 
    8485           if(!preg_match("/^(.*)EntryPoint$/", $name,$m)){ 
     
    8990           $entryPoint = (string)$tag['name']; 
    9091           $isDefault =  (isset($tag['default']) ? (((string)$tag['default']) == 'true'):false); 
    91            $parseInfos = array($isDefault);            
    92             
     92           $parseInfos = array($isDefault); 
     93 
    9394           if($isDefault){ 
    94              $createUrlInfos['@'.$requestType]=array(2,$entryPoint);            
     95             $createUrlInfos['@'.$requestType]=array(2,$entryPoint); 
    9596           } 
    96             
    97             
     97 
     98 
    9899           $parseContent = "<?php \n"; 
    99100           foreach($tag->url as $url){ 
    100101               $module = (string)$url['module']; 
    101                 
    102                // dans le cas d'un point d'entr�qui est celui par defaut pour le type de requete indiqu�              // si il y a juste un module indiqu�lors on sait que toutes les actions  
     102 
     103               // dans le cas d'un point d'entr�qui est celui par defaut pour le type de requete indiqu�              // si il y a juste un module indiqu�lors on sait que toutes les actions 
    103104               // concernant ce module passeront par ce point d'entr� 
    104                if($isDefault && !isset($url['action']) && !isset($url['handler'])){                  
     105               if($isDefault && !isset($url['action']) && !isset($url['handler'])){ 
    105106                 $parseInfos[]=array($module, '', '.*', array(), array(), array() ); 
    106107                 $createUrlInfos[$module.'~@'.$requestType] = array(2,$entryPoint); 
    107108                 continue; 
    108109               } 
    109                                
     110 
    110111               $action = (string)$url['action']; 
    111                 
     112 
    112113               // si il y a un handler indiqu�on sait alors que pour le module et action indiqu�              // il faut passer par cette classe handler pour le parsing et la creation de l'url 
    113114               if(isset($url['handler'])){ 
    114115                  $class = (string)$url['handler']; 
    115116                  $parseInfos[]=array($module, $action, $class ); 
    116                   $s= new jSelectorUrlHandler($module.'~'.$action) 
     117                  $s= new jSelectorUrlHandler($module.'~'.$action); 
    117118                  $createUrlContent.="include_once('".$s->getPath()."');\n"; 
    118119                  $createUrlInfos[$module.'~'.$action.'@'.$requestType] = array(0,$entryPoint, $class); 
    119120                  continue; 
    120121               } 
    121                                
     122 
    122123               $listparam=array(); 
    123124               $escapes = array(); 
     
    125126                  $path = (string)$url['path']; 
    126127                  $regexppath = $path; 
    127                    
     128 
    128129                  if(preg_match_all("/\:([a-zA-Z]+)/",$path,$m, PREG_PATTERN_ORDER)){ 
    129130                      $listparam=$m[1]; 
    130                        
     131 
    131132                      foreach($url->var as $var){ 
    132                          
     133 
    133134                        $nom = (string) $var['name']; 
    134135                        $k = array_search($nom, $listparam); 
     
    137138                          continue; 
    138139                        } 
    139                          
     140 
    140141                        if (isset ($var['escape'])){ 
    141142                            $escapes[$k] = (((string)$var['escape']) == 'true'); 
     
    143144                            $escapes[$k] = false; 
    144145                        } 
    145                          
     146 
    146147                        if (isset ($var['regexp'])){ 
    147148                            $regexp = '('.(string)$var['regexp'].')'; 
     
    149150                            $regexp = '([^\/]+)'; 
    150151                        } 
    151      
     152 
    152153                        $regexppath = str_replace(':'.$name, $regexp, $regexppath); 
    153154                      } 
     
    164165               $createUrlInfos[$module.'~'.$action.'@'.$requestType] = array(1,$entryPoint, $listparam, $escapes,$path); 
    165166           } 
    166             
    167            $parseContent.='$PARSE_URL_INFOS = '.var_export($parseInfos, true).";\n?>"; 
    168            file_put_contents(JELIX_APP_CONFIG_PATH.'urls/'.$entryPoint.'.entrypoint.php',$parseContent); 
     167 
     168           $parseContent.='$GLOBALS[\'SIGNIFICANT_PARSEURL\'] = '.var_export($parseInfos, true).";\n?>"; 
     169 
     170           $file->write(JELIX_APP_TEMP_PATH.'compiled/urlsig/'.rawurlencode($entryPoint).'.entrypoint.php',$parseContent); 
    169171        } 
    170         $createUrlContent .='$CREATE_URL_INFOS ='.var_export($createUrlInfos, true).";\n?>"; 
    171         file_put_contents(JELIX_APP_CONFIG_PATH.'urls/creationinfos.php',$createUrlContent); 
     172        $createUrlContent .='$GLOBALS[\'SIGNIFICANT_CREATEURL\'] ='.var_export($createUrlInfos, true).";\n?>"; 
     173        $file->write(JELIX_APP_TEMP_PATH.'compiled/urlsig/creationinfos.php',$createUrlContent); 
    172174    } 
    173175 
  • trunk/lib/jelix/core/url/jUrlEngine.significant.class.php

    r50 r51  
    11<?php 
    22/** 
    3 * @package    copix 
    4 * @subpackage plugins 
    5 * @version    $Id: CopixUrlEngine.significant.class.php,v 1.1.2.1 2005/08/17 22:12:50 laurentj Exp $ 
    6 * @author    Laurent Jouanneau 
    7 * @copyright 2001-2005 CopixTeam 
    8 * @link      http://copix.aston.fr 
    9 * @link      http://copix.org 
    10 * @licence  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 
     3* @package     jelix 
     4* @subpackage  core 
     5* @version     $Id$ 
     6* @author      Jouanneau Laurent 
     7* @contributor 
     8* @copyright   2005-2006 Jouanneau laurent 
     9* @link        http://www.jelix.org 
     10* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
     11
     12* Some parts of this file are took from an experimental version of Copix Framework v2.3dev20050901, 
     13* CopixUrlEngine.significant.class.php, 
     14* copyrighted by CopixTeam and released under GNU Lesser General Public Licence 
     15* author : Laurent Jouanneau 
     16* http://www.copix.org 
    1117*/ 
    1218 
    1319 
    14 class CopixUrlEngineSignificant extends CopixUrlEngine { 
    15  
    16     /** 
    17      * liste des donn� pour la cr�ion des urls (voir structure plus loin) 
    18      */ 
    19     var $dataCreateUrl = array(); 
    20  
    21     /** 
    22     * liste des donn� pour l'analyse des urls 
    23     */ 
    24     var $dataParseUrl = array(); 
    25  
    26     function CopixUrlEngineSignificant(){ 
    27  
    28         $this->coordination = & $GLOBALS['COPIX']['COORD']; 
    29         $this->config = & $GLOBALS['COPIX']['CONFIG']; 
    30         $cplCfg = CopixInclude::SIGNIFICANTURL(); 
    31  
    32         // on change le nom de fichier de compil car on n'a pas moyen de savoir si 
    33         // la config copix a � chang�(disons que CopixInclude n'est pour le moment 
    34         // pas pr� pour v�fier �a fois le fichier de conf, et �a fois les  fichiers 
    35         // de chaque module 
    36         // @todo am�orer CopixInclude sur ce point ? 
    37         $cplCfg[2]='significant.'.md5($this->config->url_default_entrypoint.serialize($this->config->url_specific_entrypoints)).'.php'; 
    38         // charger ici les donn� sur les urls 
    39         $rv = CopixInclude::includeCacheFile($cplCfg); 
    40  
    41         $this->dataParseUrl  = & $GLOBALS['SIGNIFICANT_PARSEURL']; 
    42         $this->dataCreateUrl  = & $GLOBALS['SIGNIFICANT_CREATEURL']; 
    43     } 
    44  
    45     /** 
    46      * 
    47      */ 
    48     function parse($scriptNamePath, $params, $pathinfo ){ 
    49         $url = new CopixUrl($scriptNamePath, $params, $pathinfo); 
    50  
    51         if ($this->config->url_enable_parser){ 
    52             $urloriginal = new CopixUrl($scriptNamePath, $params, $pathinfo); 
    53             if(!$this->_parse(&$url)){ 
    54                 $url=$urloriginal; 
    55             } 
    56         } 
    57         return $url; 
    58     } 
    59  
    60     function _parse(&$url){ 
    61  
    62             $script = $url->scriptName; 
    63  
    64             if(strpos($script, $this->config->url_entrypoint_extension) !== false){ 
    65               $script=substr($script,0,- (strlen($this->config->url_entrypoint_extension))); 
    66             } 
    67             if(substr($url->pathInfo,-1) == '/' && $url->pathInfo != '/'){ 
    68                 $pathinfo = substr($url->pathInfo,0,-1); 
    69             }else{ 
    70                  $pathinfo = $url->pathInfo; 
    71             } 
    72             $foundurl = false; 
    73  
    74             if(isset($this->dataParseUrl[$script])){ 
    75               foreach($this->dataParseUrl[$script] as $mod=>$moduleinfoparsing){ 
    76                 foreach($moduleinfoparsing as $infoparsing){ 
    77  
    78                   $url->params['module']=$infoparsing[0]; 
    79                   $url->params['desc']=$infoparsing[1]; 
    80                   $url->params['action']=$infoparsing[2]; 
    81  
    82                   if($infoparsing[3]=== false){ 
    83                     // on a un tableau du style 
    84                     // array( 0=> 'module', 1=>'desc', 2=>'action', 3=>false,4=>'handler') 
    85                     $cl = $infoparsing[4]; 
    86                     $handler = new $cl(); 
    87                     if($handler->parse($url)){ 
    88                         $foundurl=true; 
    89                         break; 
    90                     } 
    91                   }else{ 
    92                       // on a un tableau du style 
    93                       /* 
    94                       array( 0=> 'module', 1=>'desc', 2=>'action', 3=>'pathinfo', 
    95                              4=>array('annee','mois'), // tableau des valeurs dynamiques, class� par ordre croissant 
    96                              5=>array(true, false), 
    97                              6=>array('bla'=>'cequejeveux' ) // tableau des valeurs statiques 
    98                       ) 
    99                       */ 
    100                       if(preg_match ($infoparsing[3], $pathinfo, $matches)){ 
    101  
    102                           // on fusionne les parametres statiques 
    103                           if ($infoparsing[6]){ 
    104                               $url->params = array_merge ($url->params, $infoparsing[6]); 
    105                           } 
    106  
    107                           if(count($matches)){ 
    108                             foreach($infoparsing[4] as $k=>$name){ 
    109                                 if(isset($matches[$k+1])){ 
    110                                     if($infoparsing[5][$k]){ 
    111                                         $url->params[$name] = CopixUrl::unescape($matches[$k+1]); 
    112                                     }else{ 
    113                                         $url->params[$name] = $matches[$k+1]; 
    114                                     } 
    115                                  } 
    116                              } 
    117                           } 
    118                           $foundurl = true; 
    119                           break; 
    120                       } 
     20class jSelectorUrlCfgSig extends jSelectorCfg { 
     21   public $type = 'urlcfgsig'; 
     22 
     23   public function getCompiler(){ 
     24      require_once(JELIX_LIB_CORE_PATH.'url/jUrlCompiler.significant.class.php'); 
     25      $o = new jUrlCompilerSignificant(); 
     26      return $o; 
     27   } 
     28   public function getCompiledFilePath (){ return JELIX_APP_TEMP_PATH.'compiled/urlsig/creationinfos.php';} 
     29
     30 
     31class jUrlEngineSignificant implements jIUrlEngine { 
     32 
     33   /** 
     34   * liste des donn� pour la cr�ion des urls (voir structure plus loin) 
     35   */ 
     36   var $dataCreateUrl = null; 
     37 
     38   /** 
     39   * liste des donn� pour l'analyse des urls 
     40   */ 
     41   var $dataParseUrl =  null; 
     42 
     43   /** 
     44   * 
     45   */ 
     46   public function parse($scriptNamePath, $params, $pathinfo ){ 
     47 
     48      $url = new jUrl($scriptNamePath, $params, $pathinfo); 
     49 
     50      if ($GLOBALS['gJConfig']->urlengine['enable_parser']){ 
     51         $sel = new jSelectorUrlCfgSig('urls.xml'); 
     52         jIncluder::inc($sel); 
     53         require_once(JELIX_APP_TEMP_PATH.'compiled/urlsig/'.rawurlencode($scriptNamePath).'.entrypoint.php'); 
     54         $this->dataCreateUrl = & $GLOBALS['SIGNIFICANT_CREATEURL']; 
     55         $this->dataParseUrl = & $GLOBALS['SIGNIFICANT_PARSEURL']; 
     56 
     57         if(!$this->_parse($url)){ 
     58            $url= new jUrl($scriptNamePath, $params, $pathinfo); 
     59         } 
     60      } 
     61      return $url; 
     62   } 
     63 
     64   protected function _parse($url){ 
     65      global $gJConfig; 
     66      /*$script = $url->scriptName; 
     67      if(strpos($script, $gJConfig->urlengine['entrypoint_extension']) !== false){ 
     68         $script=substr($script,0,- (strlen($gJConfig->urlengine['entrypoint_extension']))); 
     69      }*/ 
     70      if(substr($url->pathInfo,-1) == '/' && $url->pathInfo != '/'){ 
     71            $pathinfo = substr($url->pathInfo,0,-1); 
     72      }else{ 
     73            $pathinfo = $url->pathInfo; 
     74      } 
     75 
     76      $foundurl = false; 
     77      $isDefault = false; 
     78      foreach($this->dataParseUrl as $k=>$infoparsing){ 
     79         if($k==0){ 
     80            $isDefault = $infoparsing; 
     81            continue; 
     82         } 
     83 
     84         $url->params['module']=$infoparsing[0]; 
     85         $url->params['action']=$infoparsing[1]; 
     86 
     87         if(count($infoparsing < 4)){ 
     88            // on a un tableau du style 
     89            // array( 0=> 'module', 1=>'action', 2=>'handler') 
     90            $cl = $infoparsing[2]; 
     91            $handler = new $cl(); 
     92            if($handler->parse($url)){ 
     93               $foundurl=true; 
     94               break; 
     95            } 
     96         }else{ 
     97            /* on a un tableau du style 
     98            array( 0=>'module', 1=>'action', 2=>'regexp_pathinfo', 
     99               3=>array('annee','mois'), // tableau des valeurs dynamiques, class� par ordre croissant 
     100               4=>array(true, false), // tableau des valeurs escapes 
     101               5=>array('bla'=>'cequejeveux' ) // tableau des valeurs statiques 
     102            */ 
     103            if(preg_match ($infoparsing[2], $pathinfo, $matches)){ 
     104 
     105               // on fusionne les parametres statiques 
     106               if ($infoparsing[5]){ 
     107                  $url->params = array_merge ($url->params, $infoparsing[5]); 
     108               } 
     109 
     110               if(count($matches)){ 
     111                  array_shift($matches); 
     112                  foreach($infoparsing[3] as $k=>$name){ 
     113                     if(isset($matches[$k])){ 
     114                        if($infoparsing[4][$k]){ 
     115                              $url->params[$name] = jUrl::unescape($matches[$k]); 
     116                        }else{ 
     117                              $url->params[$name] = $matches[$k]; 
     118                        } 
     119                     } 
    121120                  } 
    122121               } 
    123                if($foundurl) 
    124                   break; 
    125             } 
    126         } 
    127  
    128         if(!$foundurl){ 
    129             $url->pathInfo=''; 
    130             $url->params = $url->getDest($this->config->url_404notfound_dest); 
    131             $foundurl = true; 
    132         } 
    133  
    134         return $foundurl; 
    135     } 
    136  
    137  
    138     /** 
    139     * @param CopixUrl    $url    url �odifier 
    140     */ 
    141     function create( &$url){ 
    142  
    143         /* 
    144         a) recupere module|desc|action -> obtient les infos pour la creation de l'url 
    145         b) r�p� un �n les parametres indiqu�dans params �artir de CopixUrl 
    146         c) remplace la valeur r�p�e dans le result et supprime le param�e de l'url 
    147         d) remplace scriptname de CopixUrl par le resultat 
    148         */ 
    149  
    150         $module = $url->getParam ('module'); 
    151         if($module === null) 
    152             $module = CopixContext::get(); 
    153         if($module == '') 
    154            $module='_'; 
    155  
    156         $desc= $url->getParam('desc',COPIX_DEFAULT_VALUE_DESC); 
    157         $action = $url->getParam('action',COPIX_DEFAULT_VALUE_ACTION); 
    158  
    159         $id = $module.'|'.$desc.'|'.$action; 
    160  
    161         $urlinfo = null; 
    162         if (isset ($this->dataCreateUrl [$id])){ 
    163  
     122               $foundurl = true; 
     123               break; 
     124            } 
     125         } 
     126      } 
     127      if(!$foundurl && !$isDefault){ 
     128         $url->pathInfo=''; 
     129         $url->params = $url->getAction($gJConfig->urlengine['notfound_act']); 
     130         $foundurl = true; 
     131      } 
     132 
     133      return ($isDefault?true:$foundurl); 
     134   } 
     135 
     136 
     137   /** 
     138   * @param jUrl    $url    url �odifier 
     139   */ 
     140   public function create( &$url){ 
     141      if($this->dataCreateUrl == null){ 
     142         $sel = new jSelectorUrlCfgSig('urls.xml'); 
     143         jIncluder::inc($sel); 
     144         $this->dataCreateUrl = & $GLOBALS['SIGNIFICANT_CREATEURL']; 
     145      } 
     146      /* 
     147      a) recupere module~action@request -> obtient les infos pour la creation de l'url 
     148      b) r�p� un �n les parametres indiqu�dans params �artir de jUrl 
     149      c) remplace la valeur r�p�e dans le result et supprime le param�e de l'url 
     150      d) remplace scriptname de jUrl par le resultat 
     151      */ 
     152 
     153      $module = $url->getParam ('module', jContext::get()); 
     154      $action = $url->getParam('action'); 
     155 
     156      $id = $module.'~'.$action.'@'.$url->requestType; 
     157      $urlinfo = null; 
     158      if (isset ($this->dataCreateUrl [$id])){ 
     159         $urlinfo = &$this->dataCreateUrl[$id]; 
     160         $url->delParam('module'); 
     161         $url->delParam('action'); 
     162      }else{ 
     163         $id = $module.'~@'.$url->requestType; 
     164         if (isset ($this->dataCreateUrl [$id])){ 
     165            $urlinfo = &$this->dataCreateUrl[$id]; 
    164166            $url->delParam('module'); 
    165             $url->delParam('desc'); 
    166             $url->delParam('action'); 
    167             $urlinfo = &$this->dataCreateUrl[$id]; 
    168  
    169             if($urlinfo[0]===false){ 
    170                 $cl = $urlinfo[1]; 
    171                 $handler = new $cl(); 
    172                 $handler->create($url); 
    173             }else{ 
    174                 $dturl = & $urlinfo[0]; 
    175                 $result = $urlinfo[2]; 
    176                 foreach ($dturl as $k=>$param){ 
    177                     if($urlinfo[1][$k]){ 
    178                         $result=str_replace('%'.($k+1), CopixUrl::escape($url->getParam($param,''),true), $result); 
    179                     }else{ 
    180                         $result=str_replace('%'.($k+1), $url->getParam($param,''), $result); 
    181                     } 
    182                     $url->delParam($param); 
    183                 } 
    184  
    185                 $url->pathInfo = $result; 
    186             } 
    187         } 
    188  
    189     } 
     167         }else{ 
     168            $id = '@'.$url->requestType; 
     169            if (isset ($this->dataCreateUrl [$id])){ 
     170               $urlinfo = &$this->dataCreateUrl[$id]; 
     171            } 
     172         } 
     173      } 
     174 
     175      if($urlinfo != null){ 
     176         /*array( 
     177         'news~show@classic' => 
     178            array(0,'entrypoint','handler') 
     179            ou 
     180            array(1,'entrypoint', 
     181                  array('annee','mois','jour','id','titre'), // liste des param�es de l'url �rendre en compte 
     182                  array(true, false..), // valeur des escapes 
     183                  "/news/%1/%2/%3/%4-%5", // forme de l'url 
     184                  ) 
     185            ou 
     186            array(2,'entrypoint'); pour les cl�du type "@request" ou "module~@request" 
     187         */ 
     188 
     189         $url->scriptName = $urlinfo[1]; 
     190 
     191         if($urlinfo[0]==0){ 
     192            $cl = $urlinfo[1]; 
     193            $handler = new $cl(); 
     194            $handler->create($url); 
     195         }elseif($urlinfo[0]==1){ 
     196            $result = $urlinfo[4]; 
     197            foreach ($urlinfo[2] as $k=>$param){ 
     198               if($urlinfo[3][$k]){ 
     199                  $result=str_replace('%'.($k+1), jUrl::escape($url->getParam($param,''),true), $result); 
     200               }else{ 
     201                  $result=str_replace('%'.($k+1), $url->getParam($param,''), $result); 
     202               } 
     203               $url->delParam($param); 
     204            } 
     205 
     206            $url->pathInfo = $result; 
     207         } 
     208      } 
     209   } 
    190210} 
    191211?> 
  • trunk/lib/jelix/core/url/jUrlEngine.simple.class.php

    r50 r51  
    99* @link        http://www.jelix.org 
    1010* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
    11 * 
    1211*/ 
    1312 
     
    2524         $url->scriptName = $this->getScript($url->requestType, $url->getParam('module'),$url->getParam('action')); 
    2625    } 
    27      
     26 
    2827    protected function getScript($requestType, $module=null, $action=null, $nosuffix=false){ 
    2928        static $urlspe = null; 
     
    3231        $script = $gJConfig->urlengine['default_entrypoint']; 
    3332 
    34         if(count($gJConfig->urlengine_specific_entrypoints)){ 
     33        if(count($gJConfig->simple_urlengine_entrypoints)){ 
    3534           if($urlspe == null){ 
    3635               $urlspe = array(); 
    37                foreach($gJConfig->urlengine_specific_entrypoints as $entrypoint=>$sel){ 
     36               foreach($gJConfig->simple_urlengine_entrypoints as $entrypoint=>$sel){ 
    3837                 $selectors = preg_split("/[\s,]+/", $sel); 
    3938                 foreach($selectors as $sel){ 
  • trunk/lib/jelix/init.php

    r45 r51  
    1111