mirror of
https://github.com/flextype/flextype.git
synced 2025-08-11 15:44:49 +02:00
Content:
- added abbility to work with CONTENT SECTIONS with help of shortcodes [section] and [section_create] - getPage() method will only return data about requested page and will not insert them in global $page array. - events: onPageContentAfter and onPageContentRawAfter was removed from getPage(), use event onCurrentPageBeforeDisplayed instead.
This commit is contained in:
@@ -52,6 +52,14 @@ class Content
|
||||
*/
|
||||
private static $page = [];
|
||||
|
||||
/**
|
||||
* Sections data array
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
private static $sections = [];
|
||||
|
||||
/**
|
||||
* Protected constructor since this is a static class.
|
||||
*
|
||||
@@ -90,7 +98,7 @@ class Content
|
||||
// Init Shortcodes
|
||||
Content::initShortcodes();
|
||||
|
||||
// Set current requested page data to $page array
|
||||
// Set current requested page data to global $page array
|
||||
Content::$page = Content::getPage(Http::getUriString());
|
||||
|
||||
// Event: The page has been fully processed and not sent to the display.
|
||||
@@ -176,16 +184,14 @@ class Content
|
||||
|
||||
// Get raw page if $raw is true
|
||||
if ($raw) {
|
||||
Content::$page = Content::processPage($file_path, true);
|
||||
Event::dispatch('onPageContentRawAfter');
|
||||
$page = Content::processPage($file_path, true);
|
||||
} else {
|
||||
Content::$page = Content::processPage($file_path);
|
||||
Event::dispatch('onPageContentAfter');
|
||||
$page = Content::processPage($file_path);
|
||||
|
||||
// Get 404 page if page is not published
|
||||
if (isset(Content::$page['published']) && Content::$page['published'] === false) {
|
||||
if (isset($page['published']) && $page['published'] === false) {
|
||||
if (Filesystem::fileExists($file_path = PATH['pages'] . '/404/page.md')) {
|
||||
Content::$page = Content::processPage($file_path);
|
||||
$page = Content::processPage($file_path);
|
||||
Http::setResponseStatus(404);
|
||||
} else {
|
||||
throw new \RuntimeException("404 page file does not exist.");
|
||||
@@ -193,8 +199,8 @@ class Content
|
||||
}
|
||||
}
|
||||
|
||||
Cache::save($page_cache_id, Content::$page);
|
||||
return Content::$page;
|
||||
Cache::save($page_cache_id, $page);
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -470,17 +476,30 @@ class Content
|
||||
*/
|
||||
protected static function registerDefaultShortcodes() : void
|
||||
{
|
||||
// Shortcode: [site_url]
|
||||
Content::shortcode()->addHandler('site_url', function() {
|
||||
return Http::getBaseUrl();
|
||||
});
|
||||
|
||||
// Shortcode: [block name=block-name]
|
||||
Content::shortcode()->addHandler('block', function(ShortcodeInterface $s) {
|
||||
return Content::getBlock($s->getParameter('name'), (($s->getParameter('raw') === 'true') ? true : false));
|
||||
});
|
||||
|
||||
// Shortcode: [registry item=site.title]
|
||||
Content::shortcode()->addHandler('registry', function(ShortcodeInterface $s) {
|
||||
return Registry::get($s->getParameter('item'));
|
||||
});
|
||||
|
||||
// Shortcode: [section_create name=test]Section text here[/section_create]
|
||||
Content::shortcode()->addHandler('section_create', function(ShortcodeInterface $s) {
|
||||
Content::$sections[$s->getParameter('name')] = $s->getContent();
|
||||
});
|
||||
|
||||
// Shortcode: [section name=test]
|
||||
Content::shortcode()->addHandler('section', function(ShortcodeInterface $s) {
|
||||
return Content::$sections[$s->getParameter('name')];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user