php Grav-Common-Page-Page类(方法)实例源码

下面列出了php Grav-Common-Page-Page 类(方法)源码代码实例,从而了解它的用法。

作者:fbarde    项目:grav-plugin-maintenanc   
/**
  * Initialize a maintenance page
  */
 public function onPageInitialized()
 {
     $user = $this->grav['user'];
     $user->authorise($this->maintenance['login_access']);
     if ($this->maintenance['active']) {
         if (!$user->authenticated) {
             /** @var $page */
             $page = null;
             /** @var Pages $pages */
             $pages = $this->grav['pages'];
             // Get the custom page route if specified
             $custom_page_route = $this->config->get('plugins.maintenance.maintenance_page_route');
             if ($custom_page_route) {
                 // Try to load user error page.
                 $page = $pages->dispatch($custom_page_route, true);
             }
             // If no page found yet, use the built-in one...
             if (!$page) {
                 $page = new Page();
                 $page->init(new \SplFileInfo(__DIR__ . "/pages/maintenance.md"));
             }
             // unset the old page, and use the new one
             unset($this->grav['page']);
             $this->grav['page'] = $page;
         }
     }
 }

作者:getgra    项目:grav-plugin-for   
/**
  * Create form for the given page.
  *
  * @param Page $page
  * @param null $name
  * @param null $form
  */
 public function __construct(Page $page, $name = null, $form = null)
 {
     parent::__construct();
     $this->page = $page->route();
     $header = $page->header();
     $this->rules = isset($header->rules) ? $header->rules : [];
     $this->header_data = isset($header->data) ? $header->data : [];
     if ($form) {
         $this->items = $form;
     } else {
         if (isset($header->form)) {
             $this->items = $header->form;
             // for backwards compatibility
         }
     }
     // Add form specific rules.
     if (!empty($this->items['rules']) && is_array($this->items['rules'])) {
         $this->rules += $this->items['rules'];
     }
     // Set form name if not set.
     if ($name && !is_int($name)) {
         $this->items['name'] = $name;
     } elseif (empty($this->items['name'])) {
         $this->items['name'] = $page->slug();
     }
     // Set form id if not set.
     if (empty($this->items['id'])) {
         $inflector = new Inflector();
         $this->items['id'] = $inflector->hyphenize($this->items['name']);
     }
     // Reset and initialize the form
     $this->reset();
 }

作者:nmsd    项目:gantry   
/**
  * Replaces page object with admin one.
  */
 public function onPagesInitialized()
 {
     // Create admin page.
     $page = new Page();
     $page->init(new \SplFileInfo(__DIR__ . "/pages/gantry5.md"));
     $page->slug($this->template);
     $this->grav['page'] = $page;
 }

作者:aradianof    项目:grav-plugin-jscomment   
private function mergeConfig(Page $page)
 {
     $defaults = (array) $this->grav['config']->get('plugins.jscomments');
     if (isset($page->header()->jscomments)) {
         if (is_array($page->header()->jscomments)) {
             $this->grav['config']->set('plugins.jscomments', array_replace_recursive($defaults, $page->header()->jscomments));
         }
     }
 }

作者:shahriyarahmed3    项目:doc   
/**
  * Create search result page.
  */
 public function onPageInitialized()
 {
     $page = new Page();
     $page->init(new \SplFileInfo(__DIR__ . '/pages/simplesearch.md'));
     // override the template is set in the config
     $template_override = $this->config->get('plugins.simplesearch.template');
     if ($template_override) {
         $page->template($template_override);
     }
     $this->grav['page'] = $page;
 }

作者:getgra    项目:gra   
public function testAddPage()
 {
     /** @var UniformResourceLocator $locator */
     $locator = $this->grav['locator'];
     $path = $locator->findResource('tests://') . '/fake/single-pages/01.simple-page/default.md';
     $aPage = new Page();
     $aPage->init(new \SplFileInfo($path));
     $this->pages->addPage($aPage, '/new-page');
     $this->assertTrue(in_array('/new-page', array_keys($this->pages->routes())));
     $this->assertSame($locator->findResource('tests://') . '/fake/single-pages/01.simple-page', $this->pages->routes()['/new-page']);
 }

作者:hexplo    项目:grav-plugin-simple_for   
private function mergeConfig(Page $page, $params = [])
 {
     $this->config = new Data((array) $this->grav['config']->get('plugins.simple_form'));
     if (isset($page->header()->simple_form)) {
         if (is_array($page->header()->simple_form)) {
             $this->config = new Data(array_replace_recursive($this->config->toArray(), $page->header()->simple_form));
         } else {
             $this->config->set('enabled', $page->header()->simple_form);
         }
     }
     $this->config = new Data(array_replace_recursive($this->config->toArray(), $params));
 }

作者:Roky    项目:grav-bv   
/**
  * Create form for the given page.
  *
  * @param Page $page
  */
 public function __construct(Page $page)
 {
     $this->page = $page;
     $header = $page->header();
     $this->rules = isset($header->rules) ? $header->rules : array();
     $this->data = isset($header->data) ? $header->data : array();
     $this->items = $header->form;
     // Set form name if not set.
     if (empty($this->items['name'])) {
         $this->items['name'] = $page->slug();
     }
 }

作者:indigo42    项目:blog.no42.or   
/**
  * Display error page if no page was found for the current route.
  *
  * @param Event $event
  */
 public function onPageNotFound(Event $event)
 {
     /** @var Pages $pages */
     $pages = $this->grav['pages'];
     // Try to load user error page.
     $page = $pages->dispatch($this->config->get('plugins.error.routes.404', '/error'), true);
     if (!$page) {
         // If none provided use built in error page.
         $page = new Page();
         $page->init(new \SplFileInfo(__DIR__ . '/pages/error.md'));
     }
     $event->page = $page;
     $event->stopPropagation();
 }

作者:tuxknigh    项目:daocloud-doc   
/**
  * Create form for the given page.
  *
  * @param Page $page
  */
 public function __construct(Page $page)
 {
     $this->page = $page;
     $header = $page->header();
     $this->rules = isset($header->rules) ? $header->rules : array();
     $this->data = isset($header->data) ? $header->data : array();
     $this->items = $header->form;
     // Set form name if not set.
     if (empty($this->items['name'])) {
         $this->items['name'] = $page->slug();
     }
     $this->reset();
     // Fire event
     self::getGrav()->fireEvent('onFormInitialized', new Event(['form' => $this]));
 }

作者:qb    项目:datenknoten.m   
/**
  * Takes an individual page and processes the taxonomies configured in its header. It
  * then adds those taxonomies to the map
  *
  * @param Page $page the page to process
  * @param array $page_taxonomy
  */
 public function addTaxonomy(Page $page, $page_taxonomy = null)
 {
     if (!$page_taxonomy) {
         $page_taxonomy = $page->taxonomy();
     }
     /** @var Config $config */
     $config = $this->grav['config'];
     if ($config->get('site.taxonomies') && count($page_taxonomy) > 0) {
         foreach ((array) $config->get('site.taxonomies') as $taxonomy) {
             if (isset($page_taxonomy[$taxonomy])) {
                 foreach ((array) $page_taxonomy[$taxonomy] as $item) {
                     // TODO: move to pages class?
                     $this->taxonomy_map[$taxonomy][(string) $item][$page->path()] = array('slug' => $page->slug());
                 }
             }
         }
     }
 }

作者:jeremycherfa    项目:grav-blo   
/**
  * Takes an individual page and processes the taxonomies configured in its header. It
  * then adds those taxonomies to the map
  *
  * @param Page  $page the page to process
  * @param array $page_taxonomy
  */
 public function addTaxonomy(Page $page, $page_taxonomy = null)
 {
     if (!$page_taxonomy) {
         $page_taxonomy = $page->taxonomy();
     }
     if (!$page->published() || empty($page_taxonomy)) {
         return;
     }
     /** @var Config $config */
     $config = $this->grav['config'];
     if ($config->get('site.taxonomies')) {
         foreach ((array) $config->get('site.taxonomies') as $taxonomy) {
             if (isset($page_taxonomy[$taxonomy])) {
                 foreach ((array) $page_taxonomy[$taxonomy] as $item) {
                     $this->taxonomy_map[$taxonomy][(string) $item][$page->path()] = ['slug' => $page->slug()];
                 }
             }
         }
     }
 }

作者:jamisonjud    项目:Literature-Revie   
private function addDropdown(Page $page, array $configuration)
 {
     $dropdownItems = array();
     $children = $page->children();
     foreach ($children as $child) {
         if (!$child->published()) {
             continue;
         }
         $dropdownItems[] = $this->addLink($child, $configuration);
     }
     $dropdown = $this->addLink($page, $configuration, 'dropdown');
     $dropdown['items'] = $dropdownItems;
     return $dropdown;
 }

作者:gitter-badge    项目:fre   
/**
  * Get Page informations 
  * update content
  * save page
  * 
  * @param Page Page that has to be saved
  * @return void - calls ajaxoutput
  */
 public function savePage(\Grav\Common\Page\Page $page)
 {
     // get local names for some objects
     $input = $this->post;
     $user = $this->grav['user'];
     // Check Permissions for Save
     if ($user->authenticated && $user->authorize("site.editor")) {
         var_dump($input);
         // Fill content last because it also renders the output.
         if (isset($input['content'])) {
             $page->rawMarkdown((string) $input['content']);
         }
     } else {
         $this->json_response = ['status' => 'unauthorized', 'message' => 'You have insufficient permissions for editing. Make sure you logged in.'];
         return;
     }
 }

作者:realitygap    项目:grav_yn   
/**
  * Gets and Sets the parent object for this page
  *
  * @param  Page $var the parent page object
  * @return Page|null the parent page object if it exists.
  */
 public function parent(Page $var = null)
 {
     if ($var) {
         $this->parent = $var->path();
         return $var;
     }
     /** @var Pages $pages */
     $pages = self::getGrav()['pages'];
     return $pages->get($this->parent);
 }

作者:getgra    项目:grav-plugin-for   
/**
  * @param Page $page
  * @return mixed
  */
 private function getFormName(Page $page)
 {
     $name = filter_input(INPUT_POST, '__form-name__');
     if (!$name) {
         $name = $page->slug();
     }
     return $name;
 }

作者:alexslac    项目:faith-gam   
/**
  * 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;
 }

作者:clee0    项目:meta   
/**
  * 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
//.........这里部分代码省略.........

作者:ulil    项目:grav-tocto   
/**
  * Add a single page to a collection
  *
  * @param Page $page
  *
  * @return $this
  */
 public function addPage(Page $page)
 {
     $this->items[$page->path()] = ['slug' => $page->slug()];
     return $this;
 }

作者:bovis    项目:grav-tcd   
/**
  * Merge global and page theme settings
  *
  * @param Page  $page    The page to merge the page theme configurations
  *                       with the theme settings.
  * @param bool  $default The default value in case no theme setting was
  *                       found.
  *
  * @return array
  */
 protected function mergeThemeConfig(Page $page, $default = null)
 {
     while ($page && !$page->root()) {
         if (isset($page->header()->theme)) {
             $theme = $page->header()->theme;
             if ($theme === '@default') {
                 $theme = $default;
             }
             return $theme;
         }
         $page = $page->parent();
     }
     return $default;
 }


问题


面经


文章

微信
公众号

扫码关注公众号