public function execute() { $route_id = waRequest::get('route'); $routes = wa()->getRouting()->getRoutes(siteHelper::getDomain()); if (!isset($routes[$route_id])) { throw new waException('Route not found', 404); } $route = $routes[$route_id]; $app_id = $routes[$route_id]['app']; $path = $this->getConfig()->getAppsPath($app_id, 'lib/config/site.php'); $app = wa()->getAppInfo($app_id); if (file_exists($path)) { // load locale of the app if ($app_id != 'site') { waSystem::getInstance($app_id)->setActive($app_id); } $app['site'] = (include $path); // return old locale of the site if ($app_id != 'site') { waSystem::setActive('site'); } } if (isset($app['site']['params'])) { $params = $this->getParams($route_id, $app['site']['params'], $route); } else { $params = array(); } $themes = siteHelper::getThemes($app_id); if (!isset($route['theme']) && $themes) { $route['theme'] = 'default'; } if (!isset($route['theme_mobile']) && $themes) { $route['theme_mobile'] = $route['theme']; } if (!isset($route['locale'])) { $route['locale'] = ''; } if (!isset($route['_name'])) { if ($app_id == 'site') { if ($title = siteHelper::getDomain('title')) { $route['_name'] = $title; } else { $app_settings_model = new waAppSettingsModel(); $route['_name'] = $app_settings_model->get('webasyst', 'name', 'Webasyst'); } } else { $route['_name'] = $app['name']; } } $this->view->assign('route_id', $route_id); $this->view->assign('route', $route); $this->view->assign('params', $params); $this->view->assign('app_id', $app_id); $this->view->assign('app', $app); $this->view->assign('domain_id', siteHelper::getDomainId()); $this->view->assign('domain', siteHelper::getDomain()); $this->view->assign('locales', array('' => _w('Auto')) + waLocale::getAll('name')); }
/** * * Correct address (e.g. transliterate) * * @param string $address * @return string */ protected function correctAddress($address) { if ($address) { foreach (waLocale::getAll() as $lang) { $address = waLocale::transliterate($address, $lang); } } return $address; }
public function execute() { $this->getResponse()->addHeader('Content-type', 'application/json'); $t = waRequest::post('t', '', waRequest::TYPE_STRING_TRIM); $t = preg_replace('/\\s+/', '-', $t); if ($t) { foreach (waLocale::getAll() as $lang) { $t = waLocale::transliterate($t, $lang); } $t = preg_replace('/[^a-zA-Z0-9_-]+/', '', $t); } $this->response = array('t' => strtolower($t), 'placeholder' => date('Ymd')); }
function getOptions($id = null) { if (!$this->locales) { $this->locales = waLocale::getAll('name_region', !empty($this->options['all']) ? false : true); } if ($id) { if (!isset($this->locales[$id])) { throw new Exception('Unknown locale: ' . $id); } return $this->locales[$id]; } return $this->locales; }
function getOptions($id = null) { if (!$this->locales) { $this->locales = waLocale::getAll('name_region'); } if ($id) { if (!isset($this->locales[$id])) { throw new Exception('Unknown locale: ' . $id); } return $this->locales[$id]; } return $this->locales; }
public static function getAvailableLanguages() { static $options; if ($options !== null) { return $options; } $langs = waLocale::getAll('info'); $options = array(); foreach ($langs as $code => $lang) { $code = substr($code, 0, 2); $options[$code] = ifempty($lang['name'], '') . ' (' . $code . ')'; } return $options; }
public static function transliterate($slug) { $slug = preg_replace('/\\s+/', '-', $slug); if ($slug) { foreach (waLocale::getAll() as $lang) { $slug = waLocale::transliterate($slug, $lang); } } $slug = preg_replace('/[^a-zA-Z0-9_-]+/', '', $slug); if (!$slug) { $slug = date('Ymd'); } return strtolower($slug); }
public function getLocales($type = false) { return waLocale::getAll($type); }
public static function suggestUrl($str) { $str = preg_replace('/\\s+/', '-', $str); if ($str) { foreach (waLocale::getAll() as $lang) { $str = waLocale::transliterate($str, $lang); } } $str = preg_replace('/[^a-zA-Z0-9_-]+/', '', $str); if (!strlen($str)) { $str = date('Ymd'); } return strtolower($str); }
private function translit($str) { $str = preg_replace('/\\s+/', '-', $str); if ($str) { foreach (waLocale::getAll() as $locale_id => $locale) { if ($locale_id != 'en_US') { $str = waLocale::transliterate($str, $locale); } } } $str = preg_replace('/[^a-zA-Z0-9_-]+/', '', $str); return strtolower($str); }
/** * Determines user's locale. * * @param string|bool $default Default value, which is returned if user's locale cannot be determined. If true is * specified, then the same value is used for $browser_only parameter. * @param bool $browser_only Flag requiring to determine user's locale using browser headers only and to ignore * additional request parameters set using setParam() method. * @return string */ public static function getLocale($default = null, $browser_only = false) { if ($default === true || $default === 1) { $browser_only = true; } $locales = waLocale::getAll(false); if (!$browser_only && ($lang = self::param('locale'))) { foreach ($locales as $l) { if (!strcasecmp($lang, $l)) { return $l; } } } if ($default && in_array($default, $locales)) { $result = $default; } else { $result = $locales[0]; } if (!self::server('HTTP_ACCEPT_LANGUAGE')) { return $result; } preg_match_all("/([a-z]{1,8})(?:-([a-z]{1,8}))?(?:\\s*;\\s*q\\s*=\\s*(1|1\\.0{0,3}|0|0\\.[0-9]{0,3}))?\\s*(?:,|\$)/i", self::server('HTTP_ACCEPT_LANGUAGE'), $matches); $max_q = 0; for ($i = 0; $i < count($matches[0]); $i++) { $lang = $matches[1][$i]; if (!empty($matches[2][$i])) { $lang .= '_' . $matches[2][$i]; } if (!empty($matches[3][$i])) { $q = (double) $matches[3][$i]; } else { $q = 1.0; } $in_array = false; foreach ($locales as $l) { if (!strcasecmp($lang, $l)) { $in_array = $l; break; } } if ($in_array && $q > $max_q) { $result = $in_array; $max_q = $q; } elseif ($q * 0.8 > $max_q) { $n = strlen($lang); if (!empty($matches[2][$i])) { $n -= strlen($matches[2][$i]) + 1; } foreach ($locales as $l) { if (!strncasecmp($l, $lang, $n)) { $result = $l; $max_q = $q * 0.8; break; } } } } return $result; }