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


PHP Page::orderDir方法代码示例

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


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

示例1: recurse

 /**
  * Recursive function to load & build page relationships.
  *
  * @param string $directory
  * @param Page|null $parent
  * @return Page
  * @throws \RuntimeException
  * @internal
  */
 protected function recurse($directory, Page &$parent = null)
 {
     $directory = rtrim($directory, DS);
     $page = new Page();
     /** @var Config $config */
     $config = $this->grav['config'];
     /** @var Language $language */
     $language = $this->grav['language'];
     // stuff to do at root page
     if ($parent === null) {
         // Fire event for memory and time consuming plugins...
         if ($config->get('system.pages.events.page')) {
             $this->grav->fireEvent('onBuildPagesInitialized');
         }
     }
     $page->path($directory);
     if ($parent) {
         $page->parent($parent);
     }
     $page->orderDir($config->get('system.pages.order.dir'));
     $page->orderBy($config->get('system.pages.order.by'));
     // Add into instances
     if (!isset($this->instances[$page->path()])) {
         $this->instances[$page->path()] = $page;
         if ($parent && $page->path()) {
             $this->children[$parent->path()][$page->path()] = array('slug' => $page->slug());
         }
     } else {
         throw new \RuntimeException('Fatal error when creating page instances.');
     }
     $content_exists = false;
     $pages_found = glob($directory . '/*' . CONTENT_EXT);
     $page_extensions = $language->getFallbackPageExtensions();
     if ($pages_found) {
         foreach ($page_extensions as $extension) {
             foreach ($pages_found as $found) {
                 if (preg_match('/^.*\\/[0-9A-Za-z\\-\\_]+(' . $extension . ')$/', $found)) {
                     $page_found = $found;
                     $page_extension = $extension;
                     break 2;
                 }
             }
         }
     }
     if ($parent && !empty($page_found)) {
         $file = new \SplFileInfo($page_found);
         $page->init($file, $page_extension);
         $content_exists = true;
         if ($config->get('system.pages.events.page')) {
             $this->grav->fireEvent('onPageProcessed', new Event(['page' => $page]));
         }
     }
     // set current modified of page
     $last_modified = $page->modified();
     /** @var \DirectoryIterator $file */
     foreach (new \FilesystemIterator($directory) as $file) {
         $name = $file->getFilename();
         // Ignore all hidden files if set.
         if ($this->ignore_hidden) {
             if ($name && $name[0] == '.') {
                 continue;
             }
         }
         if ($file->isFile()) {
             // Update the last modified if it's newer than already found
             if (!in_array($file->getBasename(), $this->ignore_files) && ($modified = $file->getMTime()) > $last_modified) {
                 $last_modified = $modified;
             }
         } elseif ($file->isDir() && !in_array($file->getFilename(), $this->ignore_folders)) {
             if (!$page->path()) {
                 $page->path($file->getPath());
             }
             $path = $directory . DS . $name;
             $child = $this->recurse($path, $page);
             if (Utils::startsWith($name, '_')) {
                 $child->routable(false);
             }
             $this->children[$page->path()][$child->path()] = array('slug' => $child->slug());
             if ($config->get('system.pages.events.page')) {
                 $this->grav->fireEvent('onFolderProcessed', new Event(['page' => $page]));
             }
         }
     }
     // Set routability to false if no page found
     if (!$content_exists) {
         $page->routable(false);
     }
     // Override the modified and ID so that it takes the latest change into account
     $page->modified($last_modified);
     $page->id($last_modified . md5($page->filePath()));
     // Sort based on Defaults or Page Overridden sort order
//.........这里部分代码省略.........
开发者ID:clee03,项目名称:metal,代码行数:101,代码来源:Pages.php

示例2: recurse

 /**
  * Recursive function to load & build page relationships.
  *
  * @param string $directory
  * @param Page|null $parent
  * @return Page
  * @throws \RuntimeException
  * @internal
  */
 protected function recurse($directory, Page &$parent = null)
 {
     $directory = rtrim($directory, DS);
     $iterator = new \DirectoryIterator($directory);
     $page = new Page();
     /** @var Config $config */
     $config = $this->grav['config'];
     $page->path($directory);
     if ($parent) {
         $page->parent($parent);
     }
     $page->orderDir($config->get('system.pages.order.dir'));
     $page->orderBy($config->get('system.pages.order.by'));
     // Add into instances
     if (!isset($this->instances[$page->path()])) {
         $this->instances[$page->path()] = $page;
         if ($parent && $page->path()) {
             $this->children[$parent->path()][$page->path()] = array('slug' => $page->slug());
         }
     } else {
         throw new \RuntimeException('Fatal error when creating page instances.');
     }
     // set current modified of page
     $last_modified = $page->modified();
     // flat for content availability
     $content_exists = false;
     /** @var \DirectoryIterator $file */
     foreach ($iterator as $file) {
         if ($file->isDot()) {
             continue;
         }
         $name = $file->getFilename();
         if ($file->isFile()) {
             // Update the last modified if it's newer than already found
             if ($file->getBasename() !== '.DS_Store' && ($modified = $file->getMTime()) > $last_modified) {
                 $last_modified = $modified;
             }
             if (preg_match('/^[^.].*' . CONTENT_EXT . '$/', $name)) {
                 $page->init($file);
                 $content_exists = true;
                 if ($config->get('system.pages.events.page')) {
                     $this->grav->fireEvent('onPageProcessed', new Event(['page' => $page]));
                 }
             }
         } elseif ($file->isDir()) {
             if (!$page->path()) {
                 $page->path($file->getPath());
             }
             $path = $directory . DS . $name;
             $child = $this->recurse($path, $page);
             if (Utils::startsWith($name, '_')) {
                 $child->routable(false);
             }
             $this->children[$page->path()][$child->path()] = array('slug' => $child->slug());
             if ($config->get('system.pages.events.page')) {
                 $this->grav->fireEvent('onFolderProcessed', new Event(['page' => $page]));
             }
         }
     }
     // Set routability to false if no page found
     if (!$content_exists) {
         $page->routable(false);
     }
     // Override the modified and ID so that it takes the latest change into account
     $page->modified($last_modified);
     $page->id($last_modified . md5($page->filePath()));
     // Sort based on Defaults or Page Overridden sort order
     $this->children[$page->path()] = $this->sort($page);
     return $page;
 }
开发者ID:alexslack,项目名称:faith-game,代码行数:79,代码来源:Pages.php

示例3: recurse

 /**
  * Recursive function to load & build page relationships.
  *
  * @param string $directory
  * @param null $parent
  * @return Page
  * @throws \RuntimeException
  * @internal
  */
 protected function recurse($directory = PAGES_DIR, Page &$parent = null)
 {
     $directory = rtrim($directory, DS);
     $iterator = new \DirectoryIterator($directory);
     $page = new Page();
     $config = $this->grav['config'];
     $page->path($directory);
     if ($parent) {
         $page->parent($parent);
     }
     $page->orderDir($config->get('system.pages.order.dir'));
     $page->orderBy($config->get('system.pages.order.by'));
     // Add into instances
     if (!isset($this->instances[$page->path()])) {
         $this->instances[$page->path()] = $page;
         if ($parent && $page->path()) {
             $this->children[$parent->path()][$page->path()] = array('slug' => $page->slug());
         }
     } else {
         throw new \RuntimeException('Fatal error when creating page instances.');
     }
     $last_modified = 0;
     /** @var \DirectoryIterator $file */
     foreach ($iterator as $file) {
         $name = $file->getFilename();
         $date = $file->getMTime();
         if ($date > $last_modified) {
             $last_modified = $date;
         }
         if ($file->isFile() && Utils::endsWith($name, CONTENT_EXT)) {
             $page->init($file);
             if ($config->get('system.pages.events.page')) {
                 $this->grav->fireEvent('onPageProcessed', new Event(['page' => $page]));
             }
         } elseif ($file->isDir() && !$file->isDot()) {
             if (!$page->path()) {
                 $page->path($file->getPath());
             }
             $path = $directory . DS . $name;
             $child = $this->recurse($path, $page);
             if (Utils::startsWith($name, '_')) {
                 $child->routable(false);
             }
             $this->children[$page->path()][$child->path()] = array('slug' => $child->slug());
             // set the modified time if not already set
             if (!$page->date()) {
                 $page->date($file->getMTime());
             }
             // set the last modified time on pages
             $this->lastModified($file->getMTime());
             if ($config->get('system.pages.events.page')) {
                 $this->grav->fireEvent('onFolderProcessed', new Event(['page' => $page]));
             }
         }
     }
     // Override the modified and ID so that it takes the latest change
     // into account
     $page->modified($last_modified);
     $page->id($last_modified . md5($page->filePath()));
     // Sort based on Defaults or Page Overridden sort order
     $this->children[$page->path()] = $this->sort($page);
     return $page;
 }
开发者ID:miguelramos,项目名称:grav,代码行数:72,代码来源:Pages.php


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