mirror of
https://github.com/monstra-cms/monstra.git
synced 2025-07-31 02:10:37 +02:00
Blocks Plugin: added ability create and render inline content blocks with {block_inline} and {block_inline_create}
This commit is contained in:
@@ -35,13 +35,53 @@
|
||||
|
||||
// Add shortcode {block get="blockname"}
|
||||
Shortcode::add('block', 'Block::_content');
|
||||
|
||||
// Add shortcode {block_inline name="blockname"}
|
||||
Shortcode::add('block_inline', 'Block::_inlineBlock');
|
||||
|
||||
// Add shortcode {block_inline_create name="blockname"} Block content here {/block_inline_create}
|
||||
Shortcode::add('block_inline_create', 'Block::_createInlineBlock');
|
||||
|
||||
|
||||
/**
|
||||
* Block Class
|
||||
*/
|
||||
class Block {
|
||||
|
||||
|
||||
/**
|
||||
* Inline Blocks
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $inline_blocks = array();
|
||||
|
||||
|
||||
/**
|
||||
* Create Inline Block
|
||||
*/
|
||||
public static function _createInlineBlock($attributes, $content) {
|
||||
if (isset($attributes['name'])) {
|
||||
Block::$inline_blocks[Security::safeName($attributes['name'], '_', true)] = array(
|
||||
'content' => (string)$content,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw Inline Block
|
||||
*/
|
||||
public static function _inlineBlock($attributes) {
|
||||
if (isset($attributes['name']) && isset(Block::$inline_blocks[$attributes['name']])) {
|
||||
$content = Filter::apply('content', Text::toHtml(Block::$inline_blocks[$attributes['name']]['content']));
|
||||
return $content;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get block
|
||||
*
|
||||
|
Reference in New Issue
Block a user