本文整理汇总了PHP中Grav\Common\Page\Page类的典型用法代码示例。如果您正苦于以下问题:PHP Page类的具体用法?PHP Page怎么用?PHP Page使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Page类的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;
}
}
}
示例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();
}
示例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;
}
示例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));
}
}
}
示例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;
}
示例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']);
}
示例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));
}
示例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();
}
}
示例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();
}
示例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]));
}
示例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());
}
}
}
}
}
示例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()];
}
}
}
}
}
示例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;
}
示例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;
}
}
示例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);
}