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


PHP Page::init方法代码示例

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


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

示例1: onPageInitialized

 /**
  * 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;
         }
     }
 }
开发者ID:fbardel,项目名称:grav-plugin-maintenance,代码行数:30,代码来源:maintenance.php

示例2: onPagesInitialized

 /**
  * 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;
 }
开发者ID:nmsde,项目名称:gantry5,代码行数:11,代码来源:gantry5.php

示例3: onPageInitialized

 /**
  * 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;
 }
开发者ID:shahriyarahmed31,项目名称:docs,代码行数:14,代码来源:simplesearch.php

示例4: testAddPage

 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']);
 }
开发者ID:getgrav,项目名称:grav,代码行数:11,代码来源:PagesTest.php

示例5: onPageNotFound

 /**
  * 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();
 }
开发者ID:indigo423,项目名称:blog.no42.org,代码行数:19,代码来源:error.php

示例6: taskSaveas

 /**
  * Save the current page in a different language. Automatically switches to that language.
  *
  * @return bool True if the action was performed.
  */
 protected function taskSaveas()
 {
     if (!$this->authorizeTask('save', $this->dataPermissions())) {
         return false;
     }
     $data = (array) $this->data;
     $language = $data['lang'];
     if ($language) {
         $this->grav['session']->admin_lang = $language ?: 'en';
     }
     $uri = $this->grav['uri'];
     $obj = $this->admin->page($uri->route());
     $this->preparePage($obj, false, $language);
     $file = $obj->file();
     if ($file) {
         $filename = $this->determineFilenameIncludingLanguage($obj->name(), $language);
         $path = $obj->path() . DS . $filename;
         $aFile = File::instance($path);
         $aFile->save();
         $aPage = new Page();
         $aPage->init(new \SplFileInfo($path), $language . '.md');
         $aPage->header($obj->header());
         $aPage->rawMarkdown($obj->rawMarkdown());
         $aPage->validate();
         $aPage->filter();
         $aPage->save();
         $this->grav->fireEvent('onAdminAfterSave', new Event(['page' => $obj]));
     }
     $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.SUCCESSFULLY_SWITCHED_LANGUAGE'), 'info');
     $this->setRedirect('/' . $language . $uri->route());
     return true;
 }
开发者ID:getgrav,项目名称:grav-plugin-admin,代码行数:37,代码来源:admincontroller.php

示例7: onPagesInitialized

 /**
  * Sets longer path to the home page allowing us to have list of pages when we enter to pages section.
  */
 public function onPagesInitialized()
 {
     $this->session = $this->grav['session'];
     // Set original route for the home page.
     $home = '/' . trim($this->config->get('system.home.alias'), '/');
     // Disable Asset pipelining
     $this->config->set('system.assets.css_pipeline', false);
     $this->config->set('system.assets.js_pipeline', false);
     // set the default if not set before
     $this->session->expert = $this->session->expert ?: false;
     // set session variable if it's passed via the url
     if ($this->uri->param('mode') == 'expert') {
         $this->session->expert = true;
     } elseif ($this->uri->param('mode') == 'normal') {
         $this->session->expert = false;
     }
     /** @var Pages $pages */
     $pages = $this->grav['pages'];
     $this->grav['admin']->routes = $pages->routes();
     // Remove default route from routes.
     if (isset($this->grav['admin']->routes['/'])) {
         unset($this->grav['admin']->routes['/']);
     }
     $page = $pages->dispatch('/', true);
     // If page is null, the default page does not exist, and we cannot route to it
     if ($page) {
         $page->route($home);
     }
     // Make local copy of POST.
     $post = !empty($_POST) ? $_POST : array();
     // Handle tasks.
     $this->admin->task = $task = !empty($post['task']) ? $post['task'] : $this->uri->param('task');
     if ($task) {
         require_once __DIR__ . '/classes/controller.php';
         $controller = new AdminController($this->grav, $this->template, $task, $this->route, $post);
         $controller->execute();
         $controller->redirect();
     } elseif ($this->template == 'logs' && $this->route) {
         // Display RAW error message.
         echo $this->admin->logEntry();
         exit;
     }
     $self = $this;
     // Replace page service with admin.
     $this->grav['page'] = function () use($self) {
         $page = new Page();
         $page->init(new \SplFileInfo(__DIR__ . "/pages/admin/{$self->template}.md"));
         $page->slug(basename($self->template));
         return $page;
     };
 }
开发者ID:stafmaniak,项目名称:grav-plugin-admin,代码行数:54,代码来源:admin.php

示例8: onAdminPagesInitialized

 /**
  * Replaces page object with admin one.
  */
 public function onAdminPagesInitialized()
 {
     // Create admin page.
     $page = new Page();
     $page->init(new \SplFileInfo(__DIR__ . "/pages/gantry.md"));
     $page->slug('gantry');
     // Dispatch Gantry in output buffer.
     ob_start();
     $gantry = Gantry::instance();
     $gantry['router']->dispatch();
     $content = ob_get_clean();
     // Store response into the page.
     $page->content($content);
     // Hook page into Grav as current page.
     unset($this->grav['page']);
     $this->grav['page'] = function () use($page) {
         return $page;
     };
 }
开发者ID:sam-suresh,项目名称:gantry5,代码行数:22,代码来源:gantry5.php

示例9: 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;
 }
开发者ID:realitygaps,项目名称:grav_ynh,代码行数:24,代码来源:Page.php

示例10: 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

示例11: authorizePage

 /**
  * Authorize Page
  */
 public function authorizePage()
 {
     /** @var User $user */
     $user = $this->grav['user'];
     /** @var Page $page */
     $page = $this->grav['page'];
     if (!$page) {
         return;
     }
     $header = $page->header();
     $rules = isset($header->access) ? (array) $header->access : [];
     $config = $this->mergeConfig($page);
     if ($config->get('parent_acl')) {
         // If page has no ACL rules, use its parent's rules
         if (!$rules) {
             $parent = $page->parent();
             while (!$rules and $parent) {
                 $header = $parent->header();
                 $rules = isset($header->access) ? (array) $header->access : [];
                 $parent = $parent->parent();
             }
         }
     }
     // Continue to the page if it has no ACL rules.
     if (!$rules) {
         return;
     }
     // Continue to the page if user is authorized to access the page.
     foreach ($rules as $rule => $value) {
         if ($user->authorize($rule) == $value) {
             return;
         }
     }
     // User is not logged in; redirect to login page.
     if ($this->route && !$user->authenticated) {
         $this->grav->redirect($this->route, 302);
     }
     /** @var Language $l */
     $l = $this->grav['language'];
     // Reset page with login page.
     if (!$user->authenticated) {
         $page = new Page();
         // Get the admin Login page is needed, else teh default
         if ($this->isAdmin()) {
             $login_file = $this->grav['locator']->findResource("plugins://admin/pages/admin/login.md");
             $page->init(new \SplFileInfo($login_file));
         } else {
             $page->init(new \SplFileInfo(__DIR__ . "/pages/login.md"));
         }
         $page->slug(basename($this->route));
         $this->authenticated = false;
         unset($this->grav['page']);
         $this->grav['page'] = $page;
     } else {
         $this->grav['messages']->add($l->translate('PLUGIN_LOGIN.ACCESS_DENIED'), 'info');
         $this->authenticated = false;
         $twig = $this->grav['twig'];
         $twig->twig_vars['notAuthorized'] = true;
     }
 }
开发者ID:allencloud,项目名称:daocloud-docs,代码行数:63,代码来源:login.php

示例12: 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

示例13: onPageInitialized

 /**
  * 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);
     }
     // allows us to redefine the page service without triggering RuntimeException: Cannot override frozen service
     // "page" issue
     unset($this->grav['page']);
     $this->grav['page'] = $page;
 }
开发者ID:hibbittsdesign,项目名称:cmpt-363-153-website,代码行数:17,代码来源:simplesearch.php

示例14: onPagesInitialized

 /**
  * Build search results.
  */
 public function onPagesInitialized()
 {
     /** @var Taxonomy $taxonomy_map */
     $taxonomy_map = $this->grav['taxonomy'];
     $filters = (array) $this->config->get('plugins.simplesearch.filters');
     $operator = $this->config->get('plugins.simplesearch.filter_combinator', 'and');
     $this->collection = new Collection();
     $this->collection->append($taxonomy_map->findTaxonomy($filters, $operator)->toArray());
     $extras = [];
     /** @var Page $page */
     foreach ($this->collection as $page) {
         foreach ($this->query as $query) {
             $query = trim($query);
             if (stripos($page->content(), $query) === false && stripos($page->title(), $query) === false) {
                 $this->collection->remove($page);
                 continue;
             }
             if ($page->modular()) {
                 $this->collection->remove($page);
                 $parent = $page->parent();
                 $extras[$parent->path()] = ['slug' => $parent->slug()];
             }
         }
     }
     if (!empty($extras)) {
         $this->collection->append($extras);
     }
     // create the search page
     $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);
     }
     // allows us to redefine the page service without triggering RuntimeException: Cannot override frozen service
     // "page" issue
     unset($this->grav['page']);
     $this->grav['page'] = $page;
 }
开发者ID:gabykode,项目名称:tf,代码行数:43,代码来源:simplesearch.php

示例15: register

 public function register(Container $container)
 {
     $container['page'] = function ($c) {
         /** @var Grav $c */
         /** @var Pages $pages */
         $pages = $c['pages'];
         /** @var Language $language */
         $language = $c['language'];
         /** @var Uri $uri */
         $uri = $c['uri'];
         $path = $uri->path();
         // Don't trim to support trailing slash default routes
         $path = $path ?: '/';
         $page = $pages->dispatch($path);
         // Redirection tests
         if ($page) {
             if ($c['config']->get('system.force_ssl')) {
                 if (!isset($_SERVER['HTTPS']) || $_SERVER["HTTPS"] != "on") {
                     $url = "https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
                     $c->redirect($url);
                 }
             }
             $url = $page->route();
             if ($uri->params()) {
                 if ($url == '/') {
                     //Avoid double slash
                     $url = $uri->params();
                 } else {
                     $url .= $uri->params();
                 }
             }
             if ($uri->query()) {
                 $url .= '?' . $uri->query();
             }
             if ($uri->fragment()) {
                 $url .= '#' . $uri->fragment();
             }
             // Language-specific redirection scenarios
             if ($language->enabled()) {
                 if ($language->isLanguageInUrl() && !$language->isIncludeDefaultLanguage()) {
                     $c->redirect($url);
                 }
                 if (!$language->isLanguageInUrl() && $language->isIncludeDefaultLanguage()) {
                     $c->redirectLangSafe($url);
                 }
             }
             // Default route test and redirect
             if ($c['config']->get('system.pages.redirect_default_route') && $page->route() != $path) {
                 $c->redirectLangSafe($url);
             }
         }
         // if page is not found, try some fallback stuff
         if (!$page || !$page->routable()) {
             // Try fallback URL stuff...
             $c->fallbackUrl($path);
             if (!$page) {
                 $path = $c['locator']->findResource('system://pages/notfound.md');
                 $page = new Page();
                 $page->init(new \SplFileInfo($path));
                 $page->routable(false);
             }
         }
         return $page;
     };
 }
开发者ID:indigo423,项目名称:blog.no42.org,代码行数:65,代码来源:PageServiceProvider.php


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