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


PHP Page::media方法代码示例

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


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

示例1: processPage

 /**
  * Twig process that renders a page item. It supports two variations:
  * 1) Handles modular pages by rendering a specific page based on its modular twig template
  * 2) Renders individual page items for twig processing before the site rendering
  *
  * @param  Page   $item    The page item to render
  * @param  string $content Optional content override
  * @return string          The rendered output
  * @throws \Twig_Error_Loader
  */
 public function processPage(Page $item, $content = null)
 {
     $content = $content !== null ? $content : $item->content();
     // override the twig header vars for local resolution
     $this->grav->fireEvent('onTwigPageVariables');
     $twig_vars = $this->twig_vars;
     $twig_vars['page'] = $item;
     $twig_vars['media'] = $item->media();
     $twig_vars['header'] = $item->header();
     $local_twig = clone $this->twig;
     // Get Twig template layout
     if ($item->modularTwig()) {
         $twig_vars['content'] = $content;
         $template = $item->template() . TEMPLATE_EXT;
         $output = $local_twig->render($template, $twig_vars);
     } else {
         $name = '@Page:' . $item->path();
         $this->setTemplate($name, $content);
         $output = $local_twig->render($name, $twig_vars);
     }
     return $output;
 }
开发者ID:qbi,项目名称:datenknoten.me,代码行数:32,代码来源:Twig.php

示例2: processPage

 /**
  * Twig process that renders a page item. It supports two variations:
  * 1) Handles modular pages by rendering a specific page based on its modular twig template
  * 2) Renders individual page items for twig processing before the site rendering
  *
  * @param  Page   $item    The page item to render
  * @param  string $content Optional content override
  * @return string          The rendered output
  * @throws \Twig_Error_Loader
  */
 public function processPage(Page $item, $content = null)
 {
     $content = $content !== null ? $content : $item->content();
     // override the twig header vars for local resolution
     $this->grav->fireEvent('onTwigPageVariables');
     $twig_vars = $this->twig_vars;
     $twig_vars['page'] = $item;
     $twig_vars['media'] = $item->media();
     $twig_vars['header'] = $item->header();
     $local_twig = clone $this->twig;
     $modular_twig = $item->modularTwig();
     $process_twig = isset($item->header()->process['twig']) ? $item->header()->process['twig'] : false;
     try {
         // Process Modular Twig
         if ($modular_twig) {
             $twig_vars['content'] = $content;
             $template = $item->template() . TEMPLATE_EXT;
             $output = $content = $local_twig->render($template, $twig_vars);
         }
         // Process in-page Twig
         if (!$modular_twig || $modular_twig && $process_twig) {
             $name = '@Page:' . $item->path();
             $this->setTemplate($name, $content);
             $output = $local_twig->render($name, $twig_vars);
         }
     } catch (\Twig_Error_Loader $e) {
         throw new \RuntimeException($e->getRawMessage(), 404, $e);
     }
     return $output;
 }
开发者ID:sunilkgrao,项目名称:grav-test,代码行数:40,代码来源:Twig.php

示例3: inlineImage

 protected function inlineImage($excerpt)
 {
     if (preg_match($this->twig_link_regex, $excerpt['text'], $matches)) {
         $excerpt['text'] = str_replace($matches[1], '/', $excerpt['text']);
         $excerpt = parent::inlineImage($excerpt);
         $excerpt['element']['attributes']['src'] = $matches[1];
         $excerpt['extent'] = $excerpt['extent'] + strlen($matches[1]) - 1;
         return $excerpt;
     } else {
         $excerpt['type'] = 'image';
         $excerpt = parent::inlineImage($excerpt);
     }
     // Some stuff we will need
     $actions = [];
     $media = null;
     // if this is an image
     if (isset($excerpt['element']['attributes']['src'])) {
         $alt = $excerpt['element']['attributes']['alt'] ?: '';
         $title = $excerpt['element']['attributes']['title'] ?: '';
         $class = isset($excerpt['element']['attributes']['class']) ? $excerpt['element']['attributes']['class'] : '';
         //get the url and parse it
         $url = parse_url(htmlspecialchars_decode($excerpt['element']['attributes']['src']));
         $this_host = isset($url['host']) && $url['host'] == $this->uri->host();
         // if there is no host set but there is a path, the file is local
         if ((!isset($url['host']) || $this_host) && isset($url['path'])) {
             $path_parts = pathinfo($url['path']);
             // get the local path to page media if possible
             if ($path_parts['dirname'] == $this->page->url(false, false, false)) {
                 // get the media objects for this page
                 $media = $this->page->media();
             } else {
                 // see if this is an external page to this one
                 $base_url = rtrim(self::getGrav()['base_url_relative'] . self::getGrav()['pages']->base(), '/');
                 $page_route = '/' . ltrim(str_replace($base_url, '', $path_parts['dirname']), '/');
                 $ext_page = $this->pages->dispatch($page_route, true);
                 if ($ext_page) {
                     $media = $ext_page->media();
                 }
             }
             // if there is a media file that matches the path referenced..
             if ($media && isset($media->all()[$path_parts['basename']])) {
                 // get the medium object
                 $medium = $media->all()[$path_parts['basename']];
                 // if there is a query, then parse it and build action calls
                 if (isset($url['query'])) {
                     $actions = array_reduce(explode('&', $url['query']), function ($carry, $item) {
                         $parts = explode('=', $item, 2);
                         $value = isset($parts[1]) ? $parts[1] : null;
                         $carry[] = ['method' => $parts[0], 'params' => $value];
                         return $carry;
                     }, []);
                 }
                 // loop through actions for the image and call them
                 foreach ($actions as $action) {
                     $medium = call_user_func_array([$medium, $action['method']], explode(',', urldecode($action['params'])));
                 }
                 if (isset($url['fragment'])) {
                     $medium->urlHash($url['fragment']);
                 }
                 $excerpt['element'] = $medium->parseDownElement($title, $alt, $class, true);
             } else {
                 // not a current page media file, see if it needs converting to relative
                 $excerpt['element']['attributes']['src'] = Uri::buildUrl($url);
             }
         }
     }
     return $excerpt;
 }
开发者ID:jeremycherfas,项目名称:grav-blog,代码行数:68,代码来源:ParsedownGravTrait.php


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