forked from b2evolution/b2evolution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_content_blocks.plugin.php
More file actions
143 lines (121 loc) · 3.84 KB
/
Copy path_content_blocks.plugin.php
File metadata and controls
143 lines (121 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
* This file implements the Include Content Blocks plugin for b2evolution
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/gnu-gpl-license}
* @copyright (c)2003-2020 by Francois Planque - {@link http://fplanque.com/}
*
* @package plugins
*/
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
/**
* Include Content Blocks plugin.
*
* @package plugins
*/
class content_blocks_plugin extends Plugin
{
var $name;
var $code = 'content_blocks';
var $priority = 102;
var $version = '7.2.5';
var $group = 'rendering';
var $short_desc;
var $long_desc;
var $help_topic = 'include-content-blocks-plugin';
var $number_of_installs = 1;
/**
* Init
*/
function PluginInit( & $params )
{
$this->name = T_('Include Content Blocks');
$this->short_desc = T_('Render content blocks.');
$this->long_desc = sprintf( T_('This renderer display a content block found in the content by short tag %s or %s'), '<code>[include:item-slug]</code>', '<code>[cblock:item-slug]</code>' );
}
/**
* Define here default collection/blog settings that are to be made available in the backoffice.
*
* @param array Associative array of parameters.
* @return array See {@link Plugin::get_coll_setting_definitions()}.
*/
function get_coll_setting_definitions( & $params )
{
$default_params = array(
'default_post_rendering' => 'stealth',
'default_comment_rendering' => 'never',
);
$params = array_merge( $params, $default_params );
return parent::get_coll_setting_definitions( $params );
}
/**
* Perform rendering
*
* @param array Associative array of parameters
* @return boolean true if we can render something for the required output format
*/
function RenderItemAsHtml( & $params )
{
$content = & $params['data'];
if( ! ( $Item = & $this->get_Item_from_params( $params ) ) )
{ // Skip rendering without provided Item:
return false;
}
// Remove block level short tag [include:...] inside <p> blocks and move them before the paragraph:
$content = move_short_tags( $content, '#\[(include|cblock):[^\]]+\]#i' );
// Don't render several short tags because they may have dynamic
// data which should not be cached in Item's pre-rendered content:
$params['render_tag_switcher'] = false;
$params['render_tag_item_subscribe'] = false;
$params['render_tag_item_emailcapture'] = false;
$params['render_tag_item_compare'] = false;
$params['render_tag_item_fields'] = false;
$params['render_tag_item_field'] = false;
$params['render_tag_item_titlelink'] = false;
$params['render_tag_item_url'] = false;
$params['render_tag_item_link'] = false;
$params['render_tag_coll_name'] = false;
$params['render_tag_coll_shortname'] = false;
// Replace [include:item-slug] or [cblock:item-slug] short tags with item content:
$params['check_code_block'] = true;
$content = $Item->render_content_blocks( $content, $params );
return true;
}
/**
* Perform rendering of Message content
*
* @see Plugin::RenderMessageAsHtml()
*/
function RenderMessageAsHtml( & $params )
{
return true;
}
/**
* Perform rendering of Email content
*
* @see Plugin::RenderEmailAsHtml()
*/
function RenderEmailAsHtml( & $params )
{
return true;
}
/**
* Event handler: called to filter the comment's content
*
* @param array Associative array of parameters
* - 'data': the name of the author/blog (by reference)
* - 'Comment': the {@link Comment} object
*/
function FilterCommentContent( & $params )
{
$Comment = & $params['Comment'];
if( in_array( $this->code, $Comment->get_renderers_validated() ) )
{ // Always allow rendering for comment:
$render_params = array_merge( array( 'data' => & $Comment->content ), $params );
$this->RenderItemAsHtml( $render_params );
}
return false;
}
}
?>