本文整理汇总了PHP中ZLanguage::isLangParam方法的典型用法代码示例。如果您正苦于以下问题:PHP ZLanguage::isLangParam方法的具体用法?PHP ZLanguage::isLangParam怎么用?PHP ZLanguage::isLangParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZLanguage
的用法示例。
在下文中一共展示了ZLanguage::isLangParam方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: queryStringDecode
/**
* Decode the path string into a set of variable/value pairs.
*
* This API works in conjunction with the new short urls
* system to extract a path based variable set into the Get, Post
* and request superglobals.
* A sample path is /modname/function/var1:value1.
*
* @return void
*/
public static function queryStringDecode()
{
if (self::isInstalling()) {
return;
}
// get our base parameters to work out if we need to decode the url
$module = FormUtil::getPassedValue('module', null, 'GETPOST', FILTER_SANITIZE_STRING);
$func = FormUtil::getPassedValue('func', null, 'GETPOST', FILTER_SANITIZE_STRING);
$type = FormUtil::getPassedValue('type', null, 'GETPOST', FILTER_SANITIZE_STRING);
// check if we need to decode the url
if (self::getVar('shorturls') && (empty($module) && empty($type) && empty($func))) {
// user language is not set at this stage
$lang = System::getVar('language_i18n', '');
$customentrypoint = self::getVar('entrypoint');
$expectEntrypoint = !self::getVar('shorturlsstripentrypoint');
$root = empty($customentrypoint) ? 'index.php' : $customentrypoint;
// check if we hit baseurl, e.g. domain.com/ and if we require the language URL
// then we should redirect to the language URL.
if (ZLanguage::isRequiredLangParam() && self::getCurrentUrl() == self::getBaseUrl()) {
$uri = $expectEntrypoint ? "{$root}/{$lang}" : "{$lang}";
self::redirect(self::getBaseUrl() . $uri);
self::shutDown();
}
// check if entry point is part of the URL expectation. If so throw error if it's not present
// since this URL is technically invalid.
if ($expectEntrypoint && strpos(self::getCurrentUrl(), self::getBaseUrl() . $root) !== 0) {
$protocol = System::serverGetVar('SERVER_PROTOCOL');
header("{$protocol} 404 Not Found");
echo __('The requested URL cannot be found');
system::shutDown();
}
if (!$expectEntrypoint && self::getCurrentUrl() == self::getBaseUrl() . $root) {
self::redirect(self::getHomepageUrl());
self::shutDown();
}
if (!$expectEntrypoint && strpos(self::getCurrentUrl(), self::getBaseUrl() . $root) === 0) {
$protocol = System::serverGetVar('SERVER_PROTOCOL');
header("{$protocol} 404 Not Found");
echo __('The requested URL cannot be found');
system::shutDown();
}
// get base path to work out our current url
$parsedURL = parse_url(self::getCurrentUri());
// strip any unwanted content from the provided URL
$tobestripped = array(self::getBaseUri(), "{$root}");
$path = str_replace($tobestripped, '', $parsedURL['path']);
$path = trim($path, '/');
// split the path into a set of argument strings
$args = explode('/', rtrim($path, '/'));
// ensure that each argument is properly decoded
foreach ($args as $k => $v) {
$args[$k] = urldecode($v);
}
$modinfo = null;
$frontController = $expectEntrypoint ? "{$root}/" : '';
// if no arguments present
if (!$args[0] && !isset($_GET['lang']) && !isset($_GET['theme'])) {
// we are in the homepage, checks if language code is forced
if (ZLanguage::getLangUrlRule() && $lang) {
// and redirect then
$response = new RedirectResponse(self::getCurrentUrl() . "/{$lang}");
$respose->send();
System::shutDown();
}
} else {
// check the existing shortURL parameters
// validation of the first parameter as language code
if (ZLanguage::isLangParam($args[0]) && in_array($args[0], ZLanguage::getInstalledLanguages())) {
// checks if the language is not enforced and this url is passing the default lang
if (!ZLanguage::getLangUrlRule() && $lang == $args[0]) {
// redirects the passed arguments without the default site language
array_shift($args);
foreach ($args as $k => $v) {
$args[$k] = urlencode($v);
}
$response = new RedirectResponse(self::getBaseUrl() . $frontController . ($args ? implode('/', $args) : ''));
$respose->send();
System::shutDown();
}
self::queryStringSetVar('lang', $args[0]);
array_shift($args);
} elseif (ZLanguage::getLangUrlRule()) {
// if the lang is forced, redirects the passed arguments plus the lang
foreach ($args as $k => $v) {
$args[$k] = urlencode($v);
}
$langTheme = isset($_GET['theme']) ? "{$lang}/{$_GET['theme']}" : $lang;
$response = new RedirectResponse(self::getBaseUrl() . $frontController . $langTheme . '/' . implode('/', $args));
$response->send();
System::shutDown();
//.........这里部分代码省略.........
示例2: validate_menu
private function validate_menu($array)
{
/*
* Menu should be an array of arrays:
* [id] = array(
* [lang] = array (
* [data][lang] = [lang]
* [data][parent] = exist
* )
* )
*/
if (!is_array($array)) {
return false;
}
$ids = array_keys($array);
$ids[] = 0;
foreach ($array as $id => $node) {
if (!is_numeric($id) || !is_array($node)) {
return false;
}
foreach ($node as $lang => $data) {
if (!ZLanguage::isLangParam($lang)
|| !is_array($data)
|| empty($data['name'])
|| !ZLanguage::isLangParam($data['lang'])
|| !in_array($data['parent'],$ids)){
return false;
}
}
}
return true;
}
示例3: queryStringDecode
//.........这里部分代码省略.........
self::shutDown();
}
if (!$expectEntrypoint && strpos(self::getCurrentUrl(), self::getBaseUrl() . $root) === 0) {
$protocol = self::serverGetVar('SERVER_PROTOCOL');
header("{$protocol} 404 Not Found");
echo __('The requested URL cannot be found');
self::shutDown();
}
// get base path to work out our current url
$parsedURL = parse_url(self::getCurrentUri());
// strip any unwanted content from the provided URL
$tobestripped = array(self::getBaseUri(), "{$root}");
$path = str_replace($tobestripped, '', $parsedURL['path']);
$path = trim($path, '/');
// split the path into a set of argument strings
$args = explode('/', rtrim($path, '/'));
// ensure that each argument is properly decoded
foreach ($args as $k => $v) {
$args[$k] = urldecode($v);
}
$modinfo = null;
$frontController = $expectEntrypoint ? "{$root}/" : '';
// if no arguments present
if (!$args[0] && !isset($_GET['lang']) && !isset($_GET['theme'])) {
// we are in the homepage, checks if language code is forced
if (ZLanguage::getLangUrlRule() && $lang) {
// and redirect then
self::redirect(self::getCurrentUrl() . "/{$lang}", array(), 302, true);
self::shutDown();
}
} else {
// check the existing shortURL parameters
// validation of the first parameter as language code
if (ZLanguage::isLangParam($args[0]) && in_array($args[0], ZLanguage::getInstalledLanguages())) {
// checks if the language is not enforced and this url is passing the default lang
if (!ZLanguage::getLangUrlRule() && $lang == $args[0]) {
// redirects the passed arguments without the default site language
array_shift($args);
foreach ($args as $k => $v) {
$args[$k] = urlencode($v);
}
self::redirect(self::getBaseUrl() . $frontController . ($args ? implode('/', $args) : ''), array(), 302, true);
self::shutDown();
}
self::queryStringSetVar('lang', $args[0], $request);
array_shift($args);
} elseif (ZLanguage::getLangUrlRule()) {
// if the lang is forced, redirects the passed arguments plus the lang
foreach ($args as $k => $v) {
$args[$k] = urlencode($v);
}
$langTheme = isset($_GET['theme']) ? "{$lang}/{$_GET['theme']}" : $lang;
self::redirect(self::getBaseUrl() . $frontController . $langTheme . '/' . implode('/', $args), array(), 302, true);
self::shutDown();
}
// check if there are remaining arguments
if ($args) {
// try the first argument as a module
$modinfo = ModUtil::getInfoFromName($args[0]);
if ($modinfo) {
array_shift($args);
}
}
// if that fails maybe it's a theme
if ($args && !$modinfo) {
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($args[0]));
示例4: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
if (\System::isInstalling()) {
return;
}
$request = $event->getRequest();
if ($request->attributes->has('_controller')) {
// routing is already done
return;
}
/**
* It is possible the code below will throw an exception. The absence of a try/catch block here
* allows this exception to 'bubble up' to the exception handler.
* @see \Zikula\Bundle\CoreBundle\EventListener\ExceptionListener
*/
if ($request->isXmlHttpRequest()) {
$this->ajax($event);
}
$module = $request->attributes->get('_zkModule');
$type = $request->attributes->get('_zkType', 'user');
$func = $request->attributes->get('_zkFunc', 'index');
$arguments = $request->attributes->get('_zkArgs');
// get module information
$modinfo = ModUtil::getInfoFromName($module);
if (!$module) {
// module could not be filtered from url.
$path = $event->getRequest()->getPathInfo();
if ($path == '' || $path == '/') {
$isAllowedNonModulePage = true;
} else {
$customentrypoint = System::getVar('entrypoint');
$root = empty($customentrypoint) ? 'index.php' : $customentrypoint;
// get base path to work out our current url
$parsedURL = parse_url($request->getRequestUri());
// strip any unwanted content from the provided URL
$toBeStripped = array($request->getBasePath(), "{$root}");
$path = str_replace($toBeStripped, '', $parsedURL['path']);
$path = trim($path, '/');
$args = explode('/', rtrim($path, '/'));
// if only arg is a lang param, then allow this Uri
$isAllowedNonModulePage = count($args) == 1 && \ZLanguage::isLangParam($args[0]) && in_array($args[0], \ZLanguage::getInstalledLanguages());
}
if ($isAllowedNonModulePage) {
// we have a static homepage
$this->setResponse($event, new Response(''));
} else {
throw new NotFoundHttpException(__('Page not found.'));
}
} else {
if (!$modinfo) {
throw new NotFoundHttpException(__('Page not found.'));
}
// call the requested/homepage module
$moduleBundle = ModUtil::getModule($module);
if (null !== $moduleBundle) {
$return = ModUtil::func($modinfo['name'], $type, $func);
} else {
$return = ModUtil::func($modinfo['name'], $type, $func, $arguments);
}
if (false === $return) {
// hack for BC since modules currently use ModUtil::func without expecting exceptions - drak.
throw new NotFoundHttpException(__('Page not found.'));
} else {
if (true === $return) {
// controllers should not return boolean anymore, this is BC for the time being.
$response = new PlainResponse();
} else {
if (false === $return instanceof Response) {
$response = new Response($return);
} else {
$response = $return;
}
}
$this->setResponse($event, $response);
}
}
}