示例#1
0
 function __construct($sel, $locale = null, $charset = null)
 {
     if ($locale === null) {
         $locale = App::config()->locale;
     }
     if ($charset === null) {
         $charset = App::config()->charset;
     }
     if (strpos($locale, '_') === false) {
         $locale = Locale::langToLocale($locale);
     }
     $this->locale = $locale;
     $this->charset = $charset;
     $this->_suffix = '.' . $charset . '.properties';
     if ($this->_scan_sel($sel)) {
         if ($this->module == '') {
             $this->module = App::getCurrentModule();
         }
         $this->_createPath();
         $this->_createCachePath();
     } else {
         throw new \Jelix\Core\Selector\Exception('jelix~errors.selector.invalid.syntax', array($sel, $this->type));
     }
 }
示例#2
0
 /**
  * check if the request is of type GET or HEAD
  */
 protected function _checkRequestType()
 {
     $allowedTypes = array('GET', 'HEAD');
     if (in_array($_SERVER['REQUEST_METHOD'], $allowedTypes)) {
         return true;
     } else {
         trigger_error(\Jelix\Locale\Locale::get('jelix~errors.rep.bad.request.method'), E_USER_WARNING);
         return false;
     }
 }
示例#3
0
 /**
  * extract parameters for the action from the path info.
  *
  * @params array $infoparsing  we have this array
  *                   array(
  *                   0=>'module',
  *                   1=>'action',
  *                   2=>'regexp_pathinfo',
  *                   3=>array('year','month'), // list of dynamic value included in the url,
  *                                         // alphabetical ascendant order
  *                   4=>array(0, 1..), // list of integer which indicates for each
  *                                   // dynamic value: 0: urlencode, 1:urlencode except '/', 2:escape, 4: lang, 8: locale
  *           
  *                   5=>array('bla'=>'whatIWant' ), // list of static values
  *                   6=>false or array('secondaries','actions')
  *                   7=>true/false  true if https is needed
  * @params array $matches  result of the match with the regexp corresponding to the url
  *
  * @return \jUrlAction or null if the handler does not accept the url
  */
 protected function parseGetParams($infoparsing, \jUrl $url, $matches)
 {
     list($module, $action, $reg, $dynamicValues, $escapes, $staticValues, $secondariesActions, $needsHttps) = $infoparsing;
     $params = $url->params;
     $params['module'] = $module;
     if ($secondariesActions && isset($params['action'])) {
         // if the action parameter exists in the current url
         // and if it is one of secondaries actions, then we keep it
         // else we take the action indicated in the url mapping
         if (strpos($params['action'], ':') === false) {
             $params['action'] = 'default:' . $params['action'];
         }
         if (!in_array($params['action'], $secondariesActions) && $action != '') {
             $params['action'] = $action;
         }
     } elseif ($action != '') {
         if (substr($action, -2) == ':*') {
             $action = substr($action, 0, -1);
             // This is an url for a whole controller
             if (isset($matches[1]) && $matches[1]) {
                 $action .= $matches[1];
             } else {
                 $action .= 'index';
             }
             $matches = array();
         }
         // else this is an url for a specific action
         $params['action'] = $action;
     } elseif (count($matches) == 2) {
         // this an url for a whole module
         if ($matches[1] == '/' || $matches[1] == '') {
             $params['action'] = 'default:index';
         } else {
             $pathInfoParts = explode('/', $matches[1]);
             $co = count($pathInfoParts);
             if ($co == 2) {
                 $params['action'] = $pathInfoParts[1] . ':index';
             } else {
                 $params['action'] = $pathInfoParts[1] . ':' . $pathInfoParts[2];
             }
         }
         $matches = array();
     }
     // let's merge static parameters
     if ($staticValues) {
         foreach ($staticValues as $n => $v) {
             if (!empty($v) && $v[0] == '$') {
                 // special statique value
                 $typeStatic = $v[1];
                 $v = substr($v, 2);
                 if ($typeStatic == 'l') {
                     App::config()->locale = Locale::langToLocale($v);
                 } elseif ($typeStatic == 'L') {
                     App::config()->locale = $v;
                 }
             }
             $params[$n] = $v;
         }
     }
     // now let's read dynamic parameters
     if (count($matches)) {
         array_shift($matches);
         foreach ($dynamicValues as $k => $name) {
             if (isset($matches[$k])) {
                 if ($escapes[$k] & self::ESCAPE_NON_ASCII) {
                     $params[$name] = \jUrl::unescape($matches[$k]);
                 } else {
                     $params[$name] = $matches[$k];
                     if ($escapes[$k] & self::ESCAPE_LANG) {
                         $v = $matches[$k];
                         if (preg_match('/^\\w{2,3}$/', $v, $m)) {
                             App::config()->locale = Locale::langToLocale($v);
                         } else {
                             App::config()->locale = $v;
                             $params[$name] = substr($v, 0, strpos('_'));
                         }
                     } elseif ($escapes[$k] & self::ESCAPE_LOCALE) {
                         $v = $matches[$k];
                         if (preg_match('/^\\w{2,3}$/', $v, $m)) {
                             App::config()->locale = $params[$name] = Locale::langToLocale($v);
                         } else {
                             App::config()->locale = $v;
                         }
                     }
                 }
             }
         }
     }
     $urlact = new \jUrlAction($params);
     $urlact->needsHttps = $needsHttps;
     return $urlact;
 }
示例#4
0
文件: Locale.php 项目: mdouchin/jelix
 protected static function tryOtherLocales($key, $args, $locale, $charset, $config)
 {
     $otherLocales = array();
     $similarLocale = self::langToLocale(substr($locale, 0, strpos($locale, '_')));
     if ($similarLocale != $locale) {
         $otherLocales[] = $similarLocale;
     }
     if ($locale != $config->locale) {
         $otherLocales[] = $config->locale;
     }
     if ($config->fallbackLocale && $locale != $config->fallbackLocale) {
         $otherLocales[] = $config->fallbackLocale;
     }
     foreach ($otherLocales as $loc) {
         try {
             return Locale::get($key, $args, $loc, $charset, false);
         } catch (\Exception $e) {
         }
     }
     return null;
 }