本文整理汇总了PHP中Grav\Common\Page\Page::rawRoute方法的典型用法代码示例。如果您正苦于以下问题:PHP Page::rawRoute方法的具体用法?PHP Page::rawRoute怎么用?PHP Page::rawRoute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grav\Common\Page\Page
的用法示例。
在下文中一共展示了Page::rawRoute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: translatedLanguages
/**
* Return an array with the routes of other translated languages
* @return array the page translated languages
*/
public function translatedLanguages()
{
$filename = substr($this->name, 0, -strlen($this->extension()));
$config = self::getGrav()['config'];
$languages = $config->get('system.languages.supported', []);
$translatedLanguages = [];
foreach ($languages as $language) {
$path = $this->path . DS . $this->folder . DS . $filename . '.' . $language . '.md';
if (file_exists($path)) {
$aPage = new Page();
$aPage->init(new \SplFileInfo($path), $language . '.md');
$route = isset($aPage->header()->routes['default']) ? $aPage->header()->routes['default'] : $aPage->rawRoute();
if (!$route) {
$route = $aPage->slug();
}
$translatedLanguages[$language] = $route;
}
}
return $translatedLanguages;
}
示例2: convertUrl
/**
* Converts links from absolute '/' or relative (../..) to a Grav friendly format
*
* @param Page $page the current page to use as reference
* @param string $url the URL as it was written in the markdown
* @param string $type the type of URL, image | link
* @param bool $absolute if null, will use system default, if true will use absolute links internally
*
* @return string the more friendly formatted url
*/
public static function convertUrl(Page $page, $url, $type = 'link', $absolute = false)
{
$grav = Grav::instance();
$uri = $grav['uri'];
// Link processing should prepend language
$language = $grav['language'];
$language_append = '';
if ($type == 'link' && $language->enabled()) {
$language_append = $language->getLanguageURLPrefix();
}
// Handle Excerpt style $url array
if (is_array($url)) {
$url_path = $url['path'];
} else {
$url_path = $url;
}
$external = false;
$base = $grav['base_url_relative'];
$base_url = rtrim($base . $grav['pages']->base(), '/') . $language_append;
$pages_dir = $grav['locator']->findResource('page://');
// if absolute and starts with a base_url move on
if (isset($url['scheme']) && Utils::startsWith($url['scheme'], 'http')) {
$external = true;
} elseif ($url_path == '' && isset($url['fragment'])) {
$external = true;
} elseif ($base_url != '' && Utils::startsWith($url_path, $base_url) || $url_path == '/') {
$url_path = $base_url . $url_path;
} else {
// see if page is relative to this or absolute
if (Utils::startsWith($url_path, '/')) {
$normalized_url = Utils::normalizePath($base_url . $url_path);
$normalized_path = Utils::normalizePath($pages_dir . $url_path);
} else {
$page_route = $page->home() && !empty($url_path) ? $page->rawRoute() : $page->route();
$normalized_url = $base_url . Utils::normalizePath($page_route . '/' . $url_path);
$normalized_path = Utils::normalizePath($page->path() . '/' . $url_path);
}
// special check to see if path checking is required.
$just_path = str_replace($normalized_url, '', $normalized_path);
if ($just_path == $page->path() || $normalized_url == '/') {
$url_path = $normalized_url;
} else {
$url_bits = static::parseUrl($normalized_path);
$full_path = $url_bits['path'];
$raw_full_path = rawurldecode($full_path);
if (file_exists($raw_full_path)) {
$full_path = $raw_full_path;
} elseif (file_exists($full_path)) {
// do nothing
} else {
$full_path = false;
}
if ($full_path) {
$path_info = pathinfo($full_path);
$page_path = $path_info['dirname'];
$filename = '';
if ($url_path == '..') {
$page_path = $full_path;
} else {
// save the filename if a file is part of the path
if (is_file($full_path)) {
if ($path_info['extension'] != 'md') {
$filename = '/' . $path_info['basename'];
}
} else {
$page_path = $full_path;
}
}
// get page instances and try to find one that fits
$instances = $grav['pages']->instances();
if (isset($instances[$page_path])) {
/** @var Page $target */
$target = $instances[$page_path];
$url_bits['path'] = $base_url . rtrim($target->route(), '/') . $filename;
$url_path = Uri::buildUrl($url_bits);
} else {
$url_path = $normalized_url;
}
} else {
$url_path = $normalized_url;
}
}
}
// handle absolute URLs
if (!$external && ($absolute === true || $grav['config']->get('system.absolute_urls', false))) {
$url['scheme'] = str_replace('://', '', $uri->scheme());
$url['host'] = $uri->host();
if ($uri->port() != 80 && $uri->port() != 443) {
$url['port'] = $uri->port();
}
//.........这里部分代码省略.........