public function __construct(Router $_router, $_ = array()) { $this->lang = $_router->getLang(); if (!in_array($this->lang, \Ker\Config::getOne("allowedLanguages"))) { $this->lang = \Ker\Config::getOne("defaultLanguage"); $this->setError(404); return; } $this->module = $_router->getModule(); $this->action = $_router->getAction(); $this->data = $_router->getData(); $this->extra = $_router->getExtra(); $view = $this->getView(); if (!$this->module) { $this->module = "Index"; $this->action = "index"; } elseif (isset($_["requireViewFile"]) and $_["requireViewFile"] and !file_exists($view::getViewFile($this->lang, $this->module, $this->action))) { $this->setError(404); } }
/** * Возвращает алиас языка с урла (если он там указан) * * @return */ public function GetLangAliasFromUrl() { return Router::getLang(); }
/** * Return URL of current route * * @access public * @param array $args * @return string * @sicne 1.0.0-alpha * @version 1.0.0-alpha */ public function url(array $args = []) { $aTemp = []; $sRawURL = $this->rawURL; preg_match_all('/\\{[a-zA-Z0-9_]*\\}/', $sRawURL, $aTemp); $GET_variables = $aTemp[0]; unset($aTemp); if (count($GET_variables) > 0) { foreach ($GET_variables as $mValue) { $sVaName = str_replace(["{", "}"], "", $mValue); if (isset($args[$sVaName])) { $sReplaceTo = $args[$sVaName]; unset($args[$sVaName]); } else { $sReplaceTo = NULL; } $sRawURL = str_replace($mValue, $sReplaceTo, $sRawURL); } } $sReplacedURL = str_replace(['(', ')'], ['', ''], $sRawURL); $sURL = rtrim($sReplacedURL, '/'); if (!empty($args)) { foreach ($args as $sKey => $sValue) { if (!empty($sValue)) { Router::addAttrToURL($sURL, $sKey, $sValue); } } } $sDefaultLang = Router::getLang(); $sLang = Helper\Arrays::get($args, 'lang', $sDefaultLang); $aLangs = Config::get('base.languages'); $sFirstLang = array_shift($aLangs); if ($sLang == $sFirstLang) { return Router::getBase() . $sURL; } else { return Router::getBase() . '/' . $sLang . $sURL; } }
public function UpdateBlockRoutes() { if (Router::getLang()) { $aBlocks = Config::Get('block'); foreach ($aBlocks as $name => $block) { if (isset($block['path'])) { $aPath = array(); foreach ($block['path'] as $path) { $aPath[] = str_replace(Config::Get('path.root.web'), Config::Get('path.root.web') . '/' . $this->PluginL10n_L10n_GetAliasByLang(Config::Get('lang.current')), $path); } Config::Set('block.' . $name . '.path', $aPath); } } } }