本文整理汇总了PHP中Grav\Common\Page\Page类的典型用法代码示例。如果您正苦于以下问题:PHP Page类的具体用法?PHP Page怎么用?PHP Page使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Page类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: __construct
/**
* 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();
}
开发者ID:getgrav,项目名称:grav-plugin-form,代码行数:40,代码来源:form.php
示例3: 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
示例4: mergeConfig
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));
}
}
}
开发者ID:aradianoff,项目名称:grav-plugin-jscomments,代码行数:9,代码来源:jscomments.php
示例5: 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
示例6: 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
示例7: mergeConfig
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));
}
开发者ID:hexplor,项目名称:grav-plugin-simple_form,代码行数:12,代码来源:simple_form.php
示例8: __construct
/**
* 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();
}
}
开发者ID:Rokys,项目名称:grav-bvb,代码行数:17,代码来源:form.php
示例9: 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
示例10: __construct
/**
* 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]));
}
开发者ID:tuxknight,项目名称:daocloud-docs,代码行数:20,代码来源:form.php
示例11: addTaxonomy
/**
* 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());
}
}
}
}
}
开发者ID:qbi,项目名称:datenknoten.me,代码行数:25,代码来源:Taxonomy.php
示例12: addTaxonomy
/**
* 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()];
}
}
}
}
}
开发者ID:jeremycherfas,项目名称:grav-blog,代码行数:27,代码来源:Taxonomy.php
示例13: addDropdown
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;
}
开发者ID:jamisonjudd,项目名称:Literature-Review,代码行数:14,代码来源:Navbar.php
示例14: savePage
/**
* 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;
}
}
开发者ID:gitter-badger,项目名称:fred,代码行数:25,代码来源:fred.php
示例15: parent
/**
* 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);
}
开发者ID:realitygaps,项目名称:grav_ynh,代码行数:16,代码来源:Page.php
示例16: getFormName
/**
* @param Page $page
* @return mixed
*/
private function getFormName(Page $page)
{
$name = filter_input(INPUT_POST, '__form-name__');
if (!$name) {
$name = $page->slug();
}
return $name;
}
开发者ID:getgrav,项目名称:grav-plugin-form,代码行数:12,代码来源:form.php
示例17: 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
示例18: 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
示例19: addPage
/**
* 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;
}
开发者ID:ulilu,项目名称:grav-toctoc,代码行数:12,代码来源:Collection.php
示例20: mergeThemeConfig
/**
* 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;
}
开发者ID:bovisp,项目名称:grav-tcdd,代码行数:24,代码来源:themer.php
注:本文中的Grav\Common\Page\Page类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论