| 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 | | } |
|---|
| 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 |
|---|