本文整理汇总了PHP中helper::inSeoMode方法的典型用法代码示例。如果您正苦于以下问题:PHP helper::inSeoMode方法的具体用法?PHP helper::inSeoMode怎么用?PHP helper::inSeoMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helper
的用法示例。
在下文中一共展示了helper::inSeoMode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createLink
/**
* Create a link to a module's method.
*
* This method also mapped in control class to call conveniently.
* <code>
* <?php
* helper::createLink('hello', 'index', 'var1=value1&var2=value2');
* helper::createLink('hello', 'index', array('var1' => 'value1', 'var2' => 'value2');
* ?>
* </code>
* @param string $moduleName module name
* @param string $methodName method name
* @param string|array $vars the params passed to the method, can be array('key' => 'value') or key1=value1&key2=value2) or key1=value1&key2=value2
* @param string|array $alias the alias params passed to the method, can be array('key' => 'value') or key1=value1&key2=value2) or key1=value1&key2=value2
* @param string $viewType the view type
* @static
* @access public
* @return string the link string.
*/
public static function createLink($moduleName, $methodName = 'index', $vars = '', $alias = array(), $viewType = '')
{
global $app, $config;
/* Set vars and alias. */
if (!is_array($vars)) {
parse_str($vars, $vars);
}
if (!is_array($alias)) {
parse_str($alias, $alias);
}
foreach ($alias as $key => $value) {
$alias[$key] = urlencode($value);
}
/* Seo modules return directly. */
if (helper::inSeoMode() and method_exists('uri', 'create' . $moduleName . $methodName)) {
$link = call_user_func_array('uri::create' . $moduleName . $methodName, array('param' => $vars, 'alias' => $alias));
if ($link) {
return $link;
}
}
/* Set the view type. */
if (empty($viewType)) {
$viewType = $app->getViewType();
}
$link = $config->requestType == 'PATH_INFO' ? $config->webRoot : $_SERVER['SCRIPT_NAME'];
/* The PATH_INFO type. */
if ($config->requestType == 'PATH_INFO') {
/* If the method equal the default method defined in the config file and the vars is empty, convert the link. */
if ($methodName == $config->default->method and empty($vars)) {
/* If the module also equal the default module, change index-index to index.html. */
if ($moduleName == $config->default->module) {
$link .= 'index.' . $viewType;
} elseif ($viewType == $app->getViewType()) {
$link .= $moduleName . '/';
} else {
$link .= $moduleName . '.' . $viewType;
}
} else {
$link .= "{$moduleName}{$config->requestFix}{$methodName}";
foreach ($vars as $value) {
$link .= "{$config->requestFix}{$value}";
}
$link .= '.' . $viewType;
}
} elseif ($config->requestType == 'GET') {
$link .= "?{$config->moduleVar}={$moduleName}&{$config->methodVar}={$methodName}";
if ($viewType != 'html') {
$link .= "&{$config->viewVar}=" . $viewType;
}
foreach ($vars as $key => $value) {
$link .= "&{$key}={$value}";
}
}
return $link;
}
示例2: createLink
/**
* Create link.
*
* @param string $title
* @access private
* @return string
*/
private function createLink($title)
{
global $config;
if (helper::inSeoMode() && method_exists('uri', 'create' . $this->moduleName . $this->methodName)) {
$link = $_SERVER['REQUEST_URI'];
if ($this->params['pageID'] == 1) {
return html::a(preg_replace('/\\/p\\d+\\./', '.', $link), $title);
}
if (preg_match('/\\/p\\d+/', $link)) {
return html::a(preg_replace('/\\/p\\d+\\./', '/p' . $this->params['pageID'] . '.', $link), $title);
}
return html::a(str_replace('.', "/p{$this->params['pageID']}.", $link), $title);
}
return html::a(helper::createLink($this->moduleName, $this->methodName, $this->params), $title);
}
示例3: createLink
/**
* Create link.
*
* @param string $title
* @access private
* @return string
*/
private function createLink($title)
{
global $config;
if (helper::inSeoMode() && method_exists('uri', 'create' . $this->moduleName . $this->methodName)) {
$link = strip_tags(urldecode($_SERVER['REQUEST_URI']));
if ($this->params['pageID'] == 1) {
return html::a(preg_replace('/\\/p\\d+\\./', '.', $link), $title);
}
if (preg_match('/\\/p\\d+/', $link)) {
return html::a(preg_replace('/\\/p\\d+\\./', '/p' . $this->params['pageID'] . '.', $link), $title);
}
if ($config->requestType == 'PATH_INFO2') {
$link = str_replace('index.php/', 'index_php/', $link);
}
$link = str_replace('.', "/p{$this->params['pageID']}.", $link);
if ($config->requestType == 'PATH_INFO2') {
$link = str_replace('index_php/', 'index.php/', $link);
}
return html::a($link, $title);
}
return html::a(helper::createLink($this->moduleName, $this->methodName, $this->params), $title);
}
示例4: parseURI
/**
* Parse SEO URI for setRouteByPathInfo.
*
* @param uri
* return string
*/
public static function parseURI($uri)
{
global $config;
if (!helper::inSeoMode()) {
return $uri;
}
$categoryAlias = $config->seo->alias->category;
$pageAlias = $config->seo->alias->page;
$forumAlias = isset($config->seo->alias->forum) ? $config->seo->alias->forum : array();
$methodAlias = $config->seo->alias->method;
$params = array();
if (strpos($uri, '_') !== false) {
$uri = substr($uri, 0, strpos($uri, '_'));
}
/* Is there a pageID variable in the url? */
$pageID = 0;
if (preg_match('/\\/p\\d+$/', $uri, $matches)) {
$pageID = str_replace('/p', '', $matches[0]);
// Get pageID thus the flowing logic can use it.
$uri = str_replace($matches[0], '', $uri);
// Remove the pageID part from the url.
}
/* Split uri to items and try to get module and params from it. */
$items = explode('/', $uri);
$module = $items[0];
/* Use book instead of help. */
if ($module == 'help') {
$module = $items[0] = 'book';
}
/* There's no '/' in uri. */
if (strpos($uri, '/') === false) {
/* Use book instead of help. */
if ($uri == 'help') {
$uri = 'book';
}
if ($pageID and $module == 'blog' and count($items) == 1) {
$params['category'] = 0;
return seo::convertURI($module, 'index', $params, $pageID);
}
/* Not an alias, return directly. */
if (empty($categoryAlias[$uri])) {
return $uri;
}
/* The module is an alias of a category. */
$module = $categoryAlias[$uri]->module;
$params['category'] = $categoryAlias[$uri]->category;
return seo::convertURI($module, 'browse', $params, $pageID);
}
/* Is the module an alias of a category? */
if (isset($categoryAlias[$module])) {
$category = $categoryAlias[$module]->category;
// Get the category.
$module = $categoryAlias[$module]->module;
// Get the module of the alias category.
/* If the first param is number, like article/123.html, should call view method. */
if (is_numeric($items[1])) {
$params['id'] = $items[1];
return seo::convertURI($module, 'view', $params, $pageID);
} else {
if (!empty($items[1])) {
$viewparams = explode('-', $items[1]);
$id = end($viewparams);
}
if (is_numeric($id)) {
$params['id'] = $id;
return seo::convertURI($module, 'view', $params, $pageID);
}
}
$params['category'] = $category;
return seo::convertURI($module, 'browse', $params, $pageID);
}
//------------- The module is an system module-------------- */
/* Is the module an alias of a page. */
if ($module == 'page' && isset($pageAlias[$items[1]])) {
$params['page'] = $items[1];
return seo::convertURI($module, 'view', $params, $pageID);
}
if ($module == 'page' && !isset($pageAlias[$items[1]])) {
$params['page'] = $items[1];
return seo::convertURI($module, 'view', $params, $pageID);
}
if ($module == 'book' && count($items) > 2) {
$uri = str_replace('/' . $items[1], '', $uri);
$items[1] = $items[2];
}
if ($module == 'forum' && isset($pageAlias[$items[1]])) {
$method = $methodAlias[$module]['browse'];
return seo::convertURI($module, $method, $params, $pageID);
}
/* If the first param is a category id, like news/c123.html. */
if (preg_match('/^c\\d+$/', $items[1])) {
$params['category'] = str_replace('c', '', $items[1]);
$method = $methodAlias[$module]['browse'];
return seo::convertURI($module, $method, $params, $pageID);
//.........这里部分代码省略.........
示例5: createLink
/**
* Create a link to a module's method.
*
* This method also mapped in control class to call conveniently.
* <code>
* <?php
* helper::createLink('hello', 'index', 'var1=value1&var2=value2');
* helper::createLink('hello', 'index', array('var1' => 'value1', 'var2' => 'value2');
* ?>
* </code>
* @param string $moduleName module name
* @param string $methodName method name
* @param string|array $vars the params passed to the method, can be array('key' => 'value') or key1=value1&key2=value2) or key1=value1&key2=value2
* @param string|array $alias the alias params passed to the method, can be array('key' => 'value') or key1=value1&key2=value2) or key1=value1&key2=value2
* @param string $viewType the view type
* @static
* @access public
* @return string the link string.
*/
public static function createLink($moduleName, $methodName = 'index', $vars = '', $alias = array(), $viewType = '')
{
global $app, $config;
$requestType = $config->requestType;
if (defined('FIX_PATH_INFO2') and FIX_PATH_INFO2) {
$config->requestType = 'PATH_INFO2';
}
$clientLang = $app->getClientLang();
$lang = $config->langCode;
/* Set viewType is mhtml if visit with mobile.*/
if (!$viewType and RUN_MODE == 'front' and helper::getDevice() == 'mobile' and $methodName != 'oauthCallback') {
$viewType = 'mhtml';
}
/* Set vars and alias. */
if (!is_array($vars)) {
parse_str($vars, $vars);
}
if (!is_array($alias)) {
parse_str($alias, $alias);
}
foreach ($alias as $key => $value) {
$alias[$key] = urlencode($value);
}
/* Seo modules return directly. */
if (helper::inSeoMode() and method_exists('uri', 'create' . $moduleName . $methodName)) {
if ($config->requestType == 'PATH_INFO2') {
$config->webRoot = $_SERVER['SCRIPT_NAME'] . '/';
}
$link = call_user_func_array('uri::create' . $moduleName . $methodName, array('param' => $vars, 'alias' => $alias, 'viewType' => $viewType));
/* Add client lang. */
if ($lang and $link) {
$link = $config->webRoot . $lang . '/' . substr($link, strlen($config->webRoot));
}
if ($config->requestType == 'PATH_INFO2') {
$config->webRoot = getWebRoot();
}
$config->requestType = $requestType;
if ($link) {
return $link;
}
}
/* Set the view type. */
if (empty($viewType)) {
$viewType = $app->getViewType();
}
if ($config->requestType == 'PATH_INFO') {
$link = $config->webRoot;
}
if ($config->requestType == 'PATH_INFO2') {
$link = $_SERVER['SCRIPT_NAME'] . '/';
}
if ($config->requestType == 'GET') {
$link = $_SERVER['SCRIPT_NAME'];
}
if ($config->requestType != 'GET' and $lang) {
$link .= "{$lang}/";
}
/* Common method. */
if (helper::inSeoMode()) {
/* If the method equal the default method defined in the config file and the vars is empty, convert the link. */
if ($methodName == $config->default->method and empty($vars)) {
/* If the module also equal the default module, change index-index to index.html. */
if ($moduleName == $config->default->module) {
$link .= 'index.' . $viewType;
} elseif ($viewType == $app->getViewType()) {
$link .= $moduleName . '/';
} else {
$link .= $moduleName . '.' . $viewType;
}
} else {
$link .= "{$moduleName}{$config->requestFix}{$methodName}";
foreach ($vars as $value) {
$link .= "{$config->requestFix}{$value}";
}
$link .= '.' . $viewType;
}
} else {
$link .= "?{$config->moduleVar}={$moduleName}&{$config->methodVar}={$methodName}";
if ($viewType != 'html') {
$link .= "&{$config->viewVar}=" . $viewType;
}
//.........这里部分代码省略.........