当前位置: 首页>>代码示例>>PHP>>正文


PHP Page::home方法代码示例

本文整理汇总了PHP中Grav\Common\Page\Page::home方法的典型用法代码示例。如果您正苦于以下问题:PHP Page::home方法的具体用法?PHP Page::home怎么用?PHP Page::home使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Grav\Common\Page\Page的用法示例。


在下文中一共展示了Page::home方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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();
         }
//.........这里部分代码省略.........
开发者ID:dweelie,项目名称:grav,代码行数:101,代码来源:Uri.php


注:本文中的Grav\Common\Page\Page::home方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。