Changeset 1074

Show
Ignore:
Timestamp:
09/04/08 00:52:41 (4 months ago)
Author:
laurentj
Message:

worked on ticket #664: moved some classes in their own file

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/manifests/jelix-lib.mn

    r1064 r1074  
    2424  jAclDbManager.class.php 
    2525  jAclDb.class.php 
    26  jAcl2.class.php 
     26* jAcl2.class.php 
    2727  jAcl2DbUserGroup.class.php 
    2828  jAcl2DbManager.class.php 
  • trunk/build/manifests/jelix-no-opt.mn

    r932 r1074  
     1cd lib/jelix/acl 
     2  jIAcl2Driver.iface.php 
     3 
     4cd lib/jelix/auth 
     5  jIAuthDriver.iface.php 
     6 
     7 
    18cd lib/jelix/core 
     9  jBundle.class.php 
    210* jConfig.class.php 
    311  jContext.class.php 
     
    715  jException.lib.php 
    816* jIncluder.class.php 
     17  jISelector.iface.php 
    918  jLocale.class.php 
    1019  jRequest.class.php 
     
    1322* jUrl.class.php 
    1423  jSession.class.php 
     24 
     25cd lib/jelix/core/selector 
     26* jSelectorAct.class.php 
     27* jSelectorActFast.class.php 
     28* jSelectorClass.class.php 
     29  jSelectorDao.class.php 
     30  jSelectorFile.lib.php 
     31  jSelectorForm.class.php 
     32  jSelectorIface.class.php 
     33* jSelectorLoc.class.php 
     34* jSelectorModule.class.php 
     35  jSelectorSimpleFile.class.php 
     36  jSelectorTpl.class.php 
     37  jSelectorZone.class.php 
    1538 
    1639cd lib/jelix/db 
  • trunk/lib/jelix/acl/jAcl2.class.php

    r864 r1074  
    1010*/ 
    1111 
    12 /** 
    13  * interface for jAcl2 drivers 
    14  * @package jelix 
    15  * @subpackage acl 
    16  */ 
    17 interface jIAcl2Driver { 
    18  
    19     /** 
    20      * return the possible values of the right on the given subject (and on the optional resource) 
    21      * @param string $subject the key of the subject 
    22      * @param string $resource the id of a resource 
    23      * @return array list of values corresponding to the right 
    24      */ 
    25     public function getRight($subject, $resource=null); 
    26  
    27     /** 
    28      * clear some cached data, it a cache exists in the driver.. 
    29      */ 
    30     public function clearCache(); 
    31  
    32 
     12#if ENABLE_OPTIMIZED_SOURCE 
     13#includephp jIAcl2Driver.iface.php 
     14#else 
     15require(JELIX_LIB_PATH.'acl/jIAcl2Driver.iface.php'); 
     16#endif 
    3317 
    3418/** 
  • trunk/lib/jelix/auth/jAuth.class.php

    r1026 r1074  
    1414*/ 
    1515#ifnot ENABLE_PHP_JELIX 
    16 /** 
    17  * interface for auth drivers 
    18  * @package    jelix 
    19  * @subpackage auth 
    20  * @static 
    21  */ 
    22 interface jIAuthDriver { 
    23     /** 
    24      * constructor 
    25      * @param array $params driver parameters, written in the ini file of the auth plugin 
    26      */ 
    27     function __construct($params); 
    28  
    29     /** 
    30      * creates a new user object, with some first data.. 
    31      * Careful : it doesn't create a user in a database for example. Just an object. 
    32      * @param string $login the user login 
    33      * @param string $password the user password 
    34      * @return object the returned object depends on the driver 
    35      */ 
    36     public function createUserObject($login, $password); 
    37  
    38     /** 
    39     * store a new user. 
    40     * 
    41     * It create the user in a database for example 
    42     * should be call after a call of createUser and after setting some of its properties... 
    43     * @param object $user the user data container 
    44     */ 
    45     public function saveNewUser($user); 
    46  
    47     /** 
    48      * Erase user data of the user $login 
    49      * @param string $login the login of the user to remove 
    50      */ 
    51     public function removeUser($login); 
    52  
    53     /** 
    54     * save updated data of a user 
    55     * warning : should not save the password ! 
    56     * @param object $user the user data container 
    57     */ 
    58     public function updateUser($user); 
    59  
    60     /** 
    61      * return user data corresponding to the given login 
    62      * @param string $login the login of the user 
    63      * @return object the user data container 
    64      */ 
    65     public function getUser($login); 
    66  
    67     /** 
    68      * construct the user list 
    69      * @param string $pattern '' for all users 
    70      * @return array array of user object 
    71      */ 
    72     public function getUserList($pattern); 
    73  
    74     /** 
    75      * change a user password 
    76      * 
    77      * @param string $login the login of the user 
    78      * @param string $newpassword 
    79      */ 
    80     public function changePassword($login, $newpassword); 
    81  
    82     /** 
    83      * verify that the password correspond to the login 
    84      * @param string $login the login of the user 
    85      * @param string $password the password to test 
    86      * @return object|false 
    87      */ 
    88     public function verifyPassword($login, $password); 
    89 
    90  
     16#if ENABLE_OPTIMIZED_SOURCE 
     17#includephp jIAuthDriver.iface.php 
     18#else 
     19require(JELIX_LIB_PATH.'auth/jIAuthDriver.iface.php'); 
     20#endif 
    9121#endif 
    9222 
  • trunk/lib/jelix/core/jLocale.class.php

    r1039 r1074  
    1515* @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
    1616*/ 
    17  
    18  
    19 /** 
    20 * a bundle contains all readed properties in a given language, and for all charsets 
    21 * @package  jelix 
    22 * @subpackage core 
    23 */ 
    24 class jBundle { 
    25     public $fic; 
    26     public $locale; 
    27  
    28     protected $_loadedCharset = array (); 
    29     protected $_strings = array(); 
    30  
    31     /** 
    32     * constructor 
    33     * @param jSelector   $file selector of a properties file 
    34     * @param string      $locale    the code lang 
    35     */ 
    36     public function __construct ($file, $locale){ 
    37         $this->fic  = $file; 
    38         $this->locale = $locale; 
    39     } 
    40  
    41     /** 
    42     * get the translation 
    43     * @param string $key the locale key 
    44     * @param string $charset 
    45     * @return string the localized string 
    46     */ 
    47     public function get ($key, $charset = null){ 
    48  
    49         if($charset == null){ 
    50             $charset = $GLOBALS['gJConfig']->charset; 
    51         } 
    52         if (!in_array ($charset, $this->_loadedCharset)){ 
    53             $this->_loadLocales ($this->locale, $charset); 
    54         } 
    55  
    56         if (isset ($this->_strings[$charset][$key])){ 
    57             return $this->_strings[$charset][$key]; 
    58         }else{ 
    59             return null; 
    60         } 
    61     } 
    62  
    63     /** 
    64     * Loads the resources for a given locale/charset. 
    65     * @param string $locale     the locale 
    66     * @param string $charset    the charset 
    67     */ 
    68     protected function _loadLocales ($locale, $charset){ 
    69         global $gJConfig; 
    70         $this->_loadedCharset[] = $charset; 
    71  
    72         $source = $this->fic->getPath(); 
    73         $cache = $this->fic->getCompiledFilePath(); 
    74  
    75         // check if we have a compiled version of the ressources 
    76  
    77         if (is_readable ($cache)){ 
    78             $okcompile = true; 
    79  
    80             if ($gJConfig->compilation['force']){ 
    81                $okcompile = false; 
    82             }else{ 
    83                 if ($gJConfig->compilation['checkCacheFiletime']){ 
    84                     if (is_readable ($source) && filemtime($source) > filemtime($cache)){ 
    85                         $okcompile = false; 
    86                     } 
    87                 } 
    88             } 
    89  
    90             if ($okcompile) { 
    91                 include ($cache); 
    92                 $this->_strings[$charset] = $_loaded; 
    93                 return; 
    94             } 
    95         } 
    96  
    97         $this->_loadResources ($source, $charset); 
    98  
    99         if(isset($this->_strings[$charset])){ 
    100             $content = '<?php $_loaded= '.var_export($this->_strings[$charset], true).' ?>'; 
    101  
    102             jFile::write($cache, $content); 
    103         } 
    104     } 
    105  
    106  
    107     /** 
    108     * loads a given resource from its path. 
    109     */ 
    110     protected function _loadResources ($fichier, $charset){ 
    111  
    112         if (($f = @fopen ($fichier, 'r')) !== false) { 
    113             $multiline=false; 
    114             $linenumber=0; 
    115             $key=''; 
    116             while (!feof($f)) { 
    117                 if($line=fgets($f)){ 
    118                     $linenumber++; 
    119                     $line=rtrim($line); 
    120                     if($multiline){ 
    121                         if(preg_match("/^\s*(.*)\s*(\\\\?)$/U", $line, $match)){ 
    122                             $multiline= ($match[2] =="\\"); 
    123                             if (strlen ($match[1])) { 
    124                                 $sp = preg_split('/(?<!\\\\)\#/', $match[1], -1 ,PREG_SPLIT_NO_EMPTY); 
    125                                 $this->_strings[$charset][$key].=' '.trim(str_replace(array('\#','\n'),array('#',"\n"),$sp[0])); 
    126                             } else { 
    127                                 $this->_strings[$charset][$key].=' '; 
    128                             } 
    129                         }else{ 
    130                             throw new Exception('Syntaxe error in file properties '.$fichier.' line '.$linenumber,210); 
    131                         } 
    132                     }elseif(preg_match("/^\s*(.+)\s*=\s*(.*)\s*(\\\\?)$/U",$line, $match)){ 
    133                         // on a bien un cle=valeur 
    134                         $key=$match[1]; 
    135                         $multiline= ($match[3] =="\\"); 
    136                         $sp = preg_split('/(?<!\\\\)\#/', $match[2], -1 ,PREG_SPLIT_NO_EMPTY); 
    137                         if(count($sp)){ 
    138                             $value=trim(str_replace('\#','#',$sp[0])); 
    139                             if($value == '\w'){ 
    140                                 $value = ' '; 
    141                             } 
    142                         }else{ 
    143                             $value=''; 
    144                         } 
    145  
    146                         $this->_strings[$charset][$key] = str_replace(array('\#','\n'),array('#',"\n"),$value); 
    147  
    148                     }elseif(preg_match("/^\s*(\#.*)?$/",$line, $match)){ 
    149                         // ok, juste un commentaire 
    150                     }else { 
    151                         throw new Exception('Syntaxe error in file properties '.$fichier.' line '.$linenumber,211); 
    152                     } 
    153                 } 
    154             } 
    155             fclose ($f); 
    156         }else{ 
    157             throw new Exception('Cannot load the resource '.$fichier,212); 
    158         } 
    159     } 
    160 } 
    161  
    16217 
    16318/** 
  • trunk/lib/jelix/core/jSelector.class.php

    r1001 r1074  
    1111* @subpackage  core_selector 
    1212* @author      Laurent Jouanneau 
    13 * @contributor Loic Mathaud 
    14 * @contributor Rahal 
    15 * @contributor Thibault PIRONT < nuKs > 
    16 * @contributor Julien Issler 
    1713* @contributor Christophe Thiriot 
    18 * @copyright   2005-2007 Laurent Jouanneau, 2007 Loic Mathaud, 2007 Rahal 
    19 * @copyright   2007 Thibault PIRONT 
    20 * @copyright   2008 Julien Issler, 2008 Christophe Thiriot 
     14* @copyright   2005-2007 Laurent Jouanneau 
     15* @copyright   2008 Christophe Thiriot 
    2116* @link        http://www.jelix.org 
    2217* @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
    2318*/ 
     19 
     20/** 
     21 * Exception for selector errors 
     22 * @package    jelix 
     23 * @subpackage core_selector 
     24 */ 
     25class jExceptionSelector extends jException { } 
    2426 
    2527/** 
     
    5153    } 
    5254} 
    53 #ifnot ENABLE_PHP_JELIX 
    54 /** 
    55  * interface of selector classes 
    56  * @package    jelix 
    57  * @subpackage core_selector 
    58  */ 
    59 interface jISelector { 
    60     /** 
    61      * @return string file path corresponding to the resource pointing by the selector 
    62      */ 
    63     public function getPath (); 
    64     /** 
    65      * @return string file path of the compiled file (if the main file should be compiled by jelix) 
    66      */ 
    67     public function getCompiledFilePath (); 
    68     /** 
    69      * @return jICompiler the compiler used to compile file 
    70      */ 
    71     public function getCompiler(); 
    72     /** 
    73      * @return boolean true if the compiler compile many file at one time 
    74      */ 
    75     public function useMultiSourceCompiler(); 
    76     /** 
    77      * @param boolean $full true if you want a full selector ("type:...") 
    78      * @return string the selector 
    79      */ 
    80     public function toString($full=false); 
    81 } 
    82 #endif 
    83  
    84 /** 
    85  * Exception for selector errors 
    86  * @package    jelix 
    87  * @subpackage core_selector 
    88  */ 
    89 class jExceptionSelector extends jException { } 
    90  
    91 /** 
    92  * base class for all selector concerning module files 
    93  * 
    94  * General syntax for them : "module~resource". 
    95  * Syntax of resource depend on the selector type. 
    96  * module is optional. 
    97  * @package    jelix 
    98  * @subpackage core_selector 
    99  */ 
    100 abstract class jSelectorModule implements jISelector { 
    101     public $module = null; 
    102     public $resource = null; 
    103  
    104     protected $type = '_module'; 
    105     protected $_dirname=''; 
    106     protected $_suffix=''; 
    107     protected $_cacheSuffix='.php'; 
    108     protected $_path; 
    109     protected $_cachePath; 
    110     protected $_compiler = null; 
    111     protected $_compilerPath; 
    112     protected $_useMultiSourceCompiler=false; 
    113  
    114     function __construct($sel){ 
    115 #if ENABLE_PHP_JELIX 
    116         if(jelix_scan_module_sel($sel, $this)){ 
    117             if($this->module ==''){ 
    118                 $this->module = jContext::get (); 
    119             } 
    120 #else 
    121         if(preg_match("/^(([a-zA-Z0-9_\.]+)~)?([a-zA-Z0-9_\.]+)$/", $sel, $m)){ 
    122             if($m[1]!='' && $m[2]!=''){ 
    123                 $this->module = $m[2]; 
    124             }else{ 
    125                 $this->module = jContext::get (); 
    126             } 
    127             $this->resource = $m[3]; 
    128 #endif 
    129             $this->_createPath(); 
    130             $this->_createCachePath(); 
    131         }else{ 
    132             throw new jExceptionSelector('jelix~errors.selector.invalid.syntax', array($sel,$this->type)); 
    133         } 
    134     } 
    135  
    136     public function getPath (){ 
    137         return $this->_path; 
    138     } 
    139  
    140     public function getCompiledFilePath (){ 
    141         return $this->_cachePath; 
    142     } 
    143  
    144     public function getCompiler(){ 
    145         if($this->_compiler == null) return null; 
    146         $n = $this->_compiler; 
    147         require_once($this->_compilerPath); 
    148         $o = new $n(); 
    149         return $o; 
    150     } 
    151  
    152     public function useMultiSourceCompiler(){ 
    153         return $this->_useMultiSourceCompiler; 
    154     } 
    155  
    156     public function toString($full=false){ 
    157         if($full) 
    158             return $this->type.':'.$this->module.'~'.$this->resource; 
    159         else 
    160             return $this->module.'~'.$this->resource; 
    161     } 
    162  
    163     protected function _createPath(){ 
    164         global $gJConfig; 
    165         if(!isset($gJConfig->_modulesPathList[$this->module])){ 
    166             throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString(true)); 
    167         } 
    168         $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->resource.$this->_suffix; 
    169         if (!is_readable ($this->_path)){ 
    170             if($this->type == 'loc'){ 
    171                 throw new Exception('(202) The file of the locale key "'.$this->toString().'" (charset '.$this->charset.', lang '.$this->locale.') does not exist'); 
    172             }elseif($this->toString() == 'jelix~errors.selector.invalid.target'){ 
    173                 throw new Exception("Jelix Panic ! don't find localization files to show you an other error message !"); 
    174             }else{ 
    175                 throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), $this->type)); 
    176             } 
    177         } 
    178     } 
    179  
    180     protected function _createCachePath(){ 
    181         $this->_cachePath = JELIX_APP_TEMP_PATH.'compiled/'.$this->_dirname.$this->module.'~'.$this->resource.$this->_cacheSuffix; 
    182     } 
    183 } 
    184  
    185 /** 
    186  * Special Action selector for jcoordinator 
    187  * Don't use it ! Only for internal purpose. 
    188  * @internal 
    189  * @package    jelix 
    190  * @subpackage core_selector 
    191  */ 
    192 class jSelectorActFast extends jSelectorModule { 
    193     protected $type = 'act'; 
    194     public $request = ''; 
    195     public $controller = ''; 
    196     public $method=''; 
    197     protected $_dirname='actions/'; 
    198  
    199     /** 
    200      */ 
    201     function __construct($request, $module, $action){ 
    202         $this->module = $module; 
    203 #if ENABLE_OLD_ACTION_SELECTOR 
    204         if($GLOBALS['gJConfig']->enableOldActionSelector == false || strpos($action,':') !== false) 
    205             $separator = ':'; 
    206         else 
    207             $separator = '_'; 
    208         $r = explode($separator,$action); 
    209 #else 
    210         $r = explode(':',$action); 
    211 #endif 
    212         if(count($r) == 1){ 
    213             $this->controller = 'default'; 
    214             $this->method = $r[0]==''?'index':$r[0]; 
    215         }else{ 
    216             $this->controller = $r[0]=='' ? 'default':$r[0]; 
    217             $this->method = $r[1]==''?'index':$r[1]; 
    218         } 
    219         $this->resource = $this->controller.':'.$this->method; 
    220         $this->request = $request; 
    221         $this->_createPath(); 
    222     } 
    223  
    224     protected function _createPath(){ 
    225         global $gJConfig; 
    226         if(!isset($gJConfig->_modulesPathList[$this->module])){ 
    227             throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 
    228         }else{ 
    229             $this->_path = $gJConfig->_modulesPathList[$this->module].'controllers/'.$this->controller.'.'.$this->request.'.php'; 
    230         } 
    231     } 
    232  
    233     protected function _createCachePath(){ 
    234         $this->_cachePath = ''; 
    235     } 
    236  
    237     public function toString($full=false){ 
    238         if($full) 
    239             return $this->type.':'.$this->module.'~'.$this->resource.'@'.$this->request; 
    240         else 
    241             return $this->module.'~'.$this->resource.'@'.$this->request; 
    242     } 
    243  
    244     public function getClass(){ 
    245         $className = $this->controller.'Ctrl'; 
    246 #if ENABLE_OLD_CLASS_NAMING 
    247         if(!class_exists($className,false)){ 
    248             if(class_exists('CT'.$this->controller,false)) 
    249                 $className = 'CT'.$this->controller; 
    250         } 
    251 #endif 
    252         return $className; 
    253     } 
    254  
    255 } 
    25655 
    25756 
    258 /** 
    259  * Generic Action selector 
    260  * 
    261  * main syntax: "module~action@requestType". module should be a valid module name or # (#=says to get 
    262  * the module of the current request). action should be an action name (controller:method or controller_method). 
    263  * all part are optional, but it should have one part at least. 
    264  * @package    jelix 
    265  * @subpackage core_selector 
    266  */ 
    267 class jSelectorAct extends jSelectorActFast { 
    268  
    269     /** 
    270      * @param string $sel  the selector 
    271      * @param boolean $enableRequestPart true if the selector can contain the request part 
    272      */ 
    273     function __construct($sel, $enableRequestPart = false){ 
    274         global $gJCoord; 
    275  
    276 #if ENABLE_PHP_JELIX 
    277 #if ENABLE_OLD_ACTION_SELECTOR 
    278         if($GLOBALS['gJConfig']->enableOldActionSelector == false || strpos($sel,':') !== false) { 
    279             $res = jelix_scan_action_sel($sel, $this, $gJCoord->actionName); 
    280         } 
    281         else{ 
    282             $res = jelix_scan_old_action_sel($sel, $this, $gJCoord->actionName); 
    283         } 
    284         if($res){ 
    285 #else 
    286         if(jelix_scan_action_sel($sel, $this, $gJCoord->actionName)){ 
    287 #endif 
    288             if($this->module == '#'){ 
    289                 $this->module = $gJCoord->moduleName; 
    290             }elseif($this->module ==''){ 
    291                 $this->module = jContext::get (); 
    292             } 
    293  
    294             if($this->request == '') 
    295                 $this->request = $gJCoord->request->type; 
    296  
    297 #else 
    298         if(preg_match("/^(?:([a-zA-Z0-9_\.]+|\#)~)?([a-zA-Z0-9_:]+|\#)?(?:@([a-zA-Z0-9_]+))?$/", $sel, $m)){ 
    299             $m=array_pad($m,4,''); 
    300             if($m[1]!=''){ 
    301                 if($m[1] == '#') 
    302                     $this->module = $gJCoord->moduleName; 
    303                 else 
    304                     $this->module = $m[1]; 
    305             }else{ 
    306                 $this->module = jContext::get (); 
    307             } 
    308             if($m[2] == '#') 
    309                 $this->resource = $gJCoord->actionName; 
    310             else 
    311                 $this->resource = $m[2]; 
    312 #if ENABLE_OLD_ACTION_SELECTOR 
    313             if($GLOBALS['gJConfig']->enableOldActionSelector == false || strpos($this->resource,':') !== false) 
    314                 $r = explode(':',$this->resource); 
    315             else 
    316                 $r = explode('_',$this->resource); 
    317 #else 
    318             $r = explode(':',$this->resource); 
    319 #endif 
    320             if(count($r) == 1){ 
    321                 $this->controller = 'default'; 
    322                 $this->method = $r[0]==''?'index':$r[0]; 
    323             }else{ 
    324                 $this->controller = $r[0]=='' ? 'default':$r[0]; 
    325                 $this->method = $r[1]==''?'index':$r[1]; 
    326             } 
    327             $this->resource = $this->controller.':'.$this->method; 
    328  
    329             if($m[3] != '' && $enableRequestPart) 
    330                 $this->request = $m[3]; 
    331             else 
    332                 $this->request = $gJCoord->request->type; 
    333 #endif 
    334             $this->_createPath(); 
    335         }else{ 
    336             throw new jExceptionSelector('jelix~errors.selector.invalid.syntax', array($sel,$this->type)); 
    337         } 
    338     } 
    339 } 
    340  
    341 /** 
    342  * selector for business class 
    343  * 
    344  * business class is a class stored in classname.class.php file in the classes/ module directory 
    345  * or one of its subdirectory. 
    346  * syntax : "module~classname" or "module~classname. 
    347  * @package    jelix 
    348  * @subpackage core_selector 
    349  */ 
    350 class jSelectorClass extends jSelectorModule { 
    351     protected $type = 'class'; 
    352     protected $_dirname = 'classes/'; 
    353     protected $_suffix = '.class.php'; 
    354  
    355     /** 
    356     * subpath part in the resource content 
    357     * @since 1.0b2 
    358     */ 
    359     public $subpath =''; 
    360     /** 
    361     * the class name specified in the selector 
    362     * @since 1.0b2 
    363     */ 
    364     public $className = ''; 
    365  
    366     function __construct($sel){ 
    367 #if ENABLE_PHP_JELIX 
    368         if(jelix_scan_class_sel($sel, $this)){ 
    369             if($this->module ==''){ 
    370                 $this->module = jContext::get (); 
    371             } 
    372 #else 
    373         if(preg_match("/^(([a-zA-Z0-9_\.]+)~)?([a-zA-Z0-9_\.\\/]+)$/", $sel, $m)){ 
    374             if($m[1]!='' && $m[2]!=''){ 
    375                 $this->module = $m[2]; 
    376             }else{ 
    377                 $this->module = jContext::get (); 
    378             } 
    379             $this->resource = $m[3]; 
    380             if( ($p=strrpos($m[3], '/')) !== false){ 
    381                 $this->className = substr($m[3],$p+1); 
    382                 $this->subpath = substr($m[3],0,$p+1); 
    383             }else{ 
    384                 $this->className = $m[3]; 
    385                 $this->subpath =''; 
    386             } 
    387 #endif 
    388             $this->_createPath(); 
    389             $this->_createCachePath(); 
    390         }else{ 
    391             throw new jExceptionSelector('jelix~errors.selector.invalid.syntax', array($sel,$this->type)); 
    392         } 
    393     } 
    394  
    395     protected function _createPath(){ 
    396         global $gJConfig; 
    397         if (!isset($gJConfig->_modulesPathList[$this->module])) { 
    398             throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 
    399         } 
    400         $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->subpath.$this->className.$this->_suffix; 
    401  
    402         if (!file_exists($this->_path) || strpos($this->subpath,'..') !== false ) { // second test for security issues 
    403             throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), $this->type)); 
    404         } 
    405     } 
    406  
    407     protected function _createCachePath(){ 
    408         $this->_cachePath = ''; 
    409     } 
    410  
    411     public function toString($full=false){ 
    412         if($full) 
    413             return $this->type.':'.$this->module.'~'.$this->subpath.$this->className; 
    414         else 
    415             return $this->module.'~'.$this->subpath.$this->className; 
    416     } 
    417 } 
    418  
    419 /** 
    420  * selector for interface 
    421  * 
    422  * interface is stored in interfacename.iface.php file in the classes/ module directory 
    423  * or one of its subdirectory. 
    424  * syntax : "iface:module~ifacename" or "module~ifacename. 
    425  * @package    jelix 
    426  * @subpackage core_selector 
    427  * @since 1.0.3 
    428  */ 
    429 class jSelectorIface extends jSelectorClass { 
    430     protected $type = 'iface'; 
    431     protected $_dirname = 'classes/'; 
    432     protected $_suffix = '.iface.php'; 
    433 } 
    434  
    435 /** 
    436  * selector for interface 
    437  * @package    jelix 
    438  * @subpackage core_selector 
    439  * @since 1.0b2 
    440  * @deprecated 
    441  */ 
    442 class jSelectorInterface extends jSelectorIface {} 
    443  
    444 /** 
    445  * selector for localisation string 
    446  * 
    447  * localisation string are stored in file properties. 
    448  * syntax : "module~prefixFile.keyString". 
    449  * Corresponding file : locales/xx_XX/prefixFile.CCC.properties. 
    450  * xx_XX and CCC are lang and charset set in the configuration 
    451  * 
    452  * @package    jelix 
    453  * @subpackage core_selector 
    454  */ 
    455 class jSelectorLoc extends jSelectorModule { 
    456     protected $type = 'loc'; 
    457     public $fileKey = ''; 
    458     public $messageKey = ''; 
    459     public $locale =''; 
    460     public $charset=''; 
    461     public $_compiler = 'jLocalesCompiler'; 
    462     protected $_where; 
    463  
    464     function __construct($sel, $locale=null, $charset=null){ 
    465         global $gJConfig; 
    466         if ($locale === null){ 
    467             $locale = $gJConfig->locale; 
    468         } 
    469         if ($charset === null){ 
    470             $charset = $gJConfig->charset; 
    471         } 
    472         if(strpos($locale,'_') === false){ 
    473             $locale.='_'.strtoupper($locale); 
    474         } 
    475         $this->locale = $locale; 
    476         $this->charset = $charset; 
    477         $this->_suffix = '.'.$charset.'.properties'; 
    478         $this->_compilerPath=JELIX_LIB_CORE_PATH.'jLocalesCompiler.class.php'; 
    479  
    480 #if ENABLE_PHP_JELIX 
    481         if(jelix_scan_locale_sel($sel, $this)){ 
    482             if($this->module ==''){ 
    483                 $this->module = jContext::get (); 
    484             } 
    485 #else 
    486         if(preg_match("/^(([a-zA-Z0-9_\.]+)~)?([a-zA-Z0-9_]+)\.([a-zA-Z0-9_\.]+)$/", $sel, $m)){ 
    487             if($m[1]!='' && $m[2]!=''){ 
    488                 $this->module = $m[2]; 
    489             }else{ 
    490                 $this->module = jContext::get (); 
    491             } 
    492             $this->resource = $m[3]; 
    493             $this->fileKey = $m[3]; 
    494             $this->messageKey = $m[4]; 
    495 #endif 
    496             $this->_createPath(); 
    497             $this->_createCachePath(); 
    498         }else{ 
    499             throw new jExceptionSelector('jelix~errors.selector.invalid.syntax', array($sel,$this->type)); 
    500         } 
    501     } 
    502  
    503     protected function _createPath(){ 
    504         global $gJConfig; 
    505         if(!isset($gJConfig->_modulesPathList[$this->module])){ 
    506             if ($this->module == 'jelix') 
    507                 throw new Exception('jelix module is not enabled !!'); 
    508             throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 
    509         } 
    510  
    511         $locales = array($this->locale); 
    512         $lang = substr($this->locale,0,2); 
    513         $generic_locale = $lang.'_'.strtoupper($lang); 
    514         if($this->locale !== $generic_locale) 
    515             $locales[] = $generic_locale; 
    516  
    517         foreach($locales as $locale){ 
    518             // check if the locale has been overloaded 
    519             $overloadedPath = JELIX_APP_VAR_PATH.'overloads/'.$this->module.'/locales/'.$locale.'/'.$this->resource.$this->_suffix; 
    520             if (is_readable ($overloadedPath)){ 
    521                 $this->_path = $overloadedPath; 
    522                 $this->_where = 'overloaded/'; 
    523                 $this->_cacheSuffix = '.'.$locale.'.'.$this->charset.'.php'; 
    524                 return; 
    525             } 
    526             // else check for the original locale file 
    527             $path = $gJConfig->_modulesPathList[$this->module].'/locales/'.$locale.'/'.$this->resource.$this->_suffix; 
    528             if (is_readable ($path)){ 
    529                 $this->_where = 'modules/'; 
    530                 $this->_path = $path; 
    531                 $this->_cacheSuffix = '.'.$locale.'.'.$this->charset.'.php'; 
    532                 return; 
    533             } 
    534         } 
    535  
    536         // to avoid infinite loop in a specific lang or charset, we should check if we don't 
    537         // try to retrieve the same message as the one we use for the exception below, 
    538         // and if it is this message, it means that the error message doesn't exist 
    539         // in the specific lang or charset, so we retrieve it in en_EN language and UTF-8 charset 
    540         if($this->toString() == 'jelix~errors.selector.invalid.target'){ 
    541             $l = 'en_EN'; 
    542             $c = 'UTF-8'; 
    543         } 
    544         else{ 
    545             $l = null; 
    546             $c = null; 
    547         } 
    548         throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "locale"), 1, $l, $c); 
    549     } 
    550  
    551     protected function _createCachePath(){ 
    552         // on ne partage pas le même cache pour tous les emplacements possibles 
    553         // au cas où un overload était supprimé 
    554         $this->_cachePath = JELIX_APP_TEMP_PATH.'compiled/locales/'.$this->_where.$this->module.'~'.$this->resource.$this->_cacheSuffix; 
    555     } 
    556  
    557     public function toString($full=false){ 
    558         if($full) 
    559             return $this->type.':'.$this->module.'~'.$this->fileKey.'.'.$this->messageKey; 
    560         else 
    561             return $this->module.'~'.$this->fileKey.'.'.$this->messageKey; 
    562     } 
    563 } 
    564  
    565 /** 
    566  * Selector for dao file 
    567  * syntax : "module~daoName". 
    568  * file : daos/daoName.dao.xml 
    569  * @package    jelix 
    570  * @subpackage core_selector 
    571  */ 
    572 class jSelectorDao extends jSelectorModule { 
    573     protected $type = 'dao'; 
    574     public $driver; 
    575     protected $_dirname = 'daos/'; 
    576     protected $_suffix = '.dao.xml'; 
    577     protected $_where; 
    578  
    579     function __construct($sel, $driver, $isprofil=true){ 
    580         if($isprofil){ 
    581             $p = jDb::getProfil($driver); 
    582             if($p['driver'] == 'pdo'){ 
    583                 $this->driver=substr($p['dsn'],0,strpos($p['dsn'],':')); 
    584             }else{ 
    585                 $this->driver= $p['driver']; 
    586             } 
    587         }else{ 
    588             $this->driver=$driver; 
    589         } 
    590         $this->_compiler='jDaoCompiler'; 
    591         $this->_compilerPath=JELIX_LIB_PATH.'dao/jDaoCompiler.class.php'; 
    592         parent::__construct($sel); 
    593     } 
    594  
    595     protected function _createPath(){ 
    596         global $gJConfig; 
    597         if(!isset($gJConfig->_modulesPathList[$this->module])){ 
    598             throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 
    599         } 
    600  
    601         // on regarde si le dao a été redéfini 
    602         $overloadedPath = JELIX_APP_VAR_PATH.'overloads/'.$this->module.'/'.$this->_dirname.$this->resource.$this->_suffix; 
    603         if (is_readable ($overloadedPath)){ 
    604            $this->_path = $overloadedPath; 
    605            $this->_where = 'overloaded/'; 
    606            return; 
    607         } 
    608         // et sinon, on regarde si le dao existe dans le module en question 
    609         $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->resource.$this->_suffix; 
    610  
    611         if (!is_readable ($this->_path)){ 
    612             throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "dao")); 
    613         } 
    614         $this->_where = 'modules/'; 
    615     } 
    616  
    617     protected function _createCachePath(){ 
    618         // on ne partage pas le même cache pour tous les emplacements possibles 
    619         // au cas où un overload était supprimé 
    620         $this->_cachePath = JELIX_APP_TEMP_PATH.'compiled/daos/'.$this->_where.$this->module.'~'.$this->resource.'~'.$this->driver.$this->_cacheSuffix; 
    621     } 
    622  
    623     public function getDaoClass(){ 
    624         return 'cDao_'.$this->module.'_Jx_'.$this->resource.'_Jx_'.$this->driver; 
    625     } 
    626     public function getDaoRecordClass(){ 
    627         return 'cDaoRecord_'.$this->module.'_Jx_'.$this->resource.'_Jx_'.$this->driver; 
    628     } 
    629 } 
    630  
    631 /** 
    632  * Template selector 
    633  * 
    634  * syntax : "module~tplName". 
    635  * file : templates/tplName.tpl . 
    636  * @package    jelix 
    637  * @subpackage core_selector 
    638  */ 
    639 class jSelectorTpl extends jSelectorModule { 
    640     protected $type = 'tpl'; 
    641     protected $_dirname = 'templates/'; 
    642     protected $_suffix = '.tpl'; 
    643     protected $_where; 
    644     public $outputType=''; 
    645     public $trusted=true; 
    646     public $userModifiers = array(); 
    647     public $userFunctions = array(); 
    648  
    649     /** 
    650      * @param string $sel the template selector 
    651      * @param string $outputtype  the type of output (html, text..) By default, it takes the response type 
    652      * @param boolean $trusted  says if the template file is trusted or not 
    653      */ 
    654     function __construct($sel, $outputtype='', $trusted=true){ 
    655         if($outputtype == '') { 
    656     &nb