forked from b2evolution/b2evolution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_shortcodes.plugin.php
More file actions
125 lines (109 loc) · 4.17 KB
/
_shortcodes.plugin.php
File metadata and controls
125 lines (109 loc) · 4.17 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
<?php
/**
* This file implements the Shortcodes Toolbar plugin for b2evolution
*
* This is Ron's remix!
* Includes code from the WordPress team -
* http://sourceforge.net/project/memberlist.php?group_id=51422
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/gnu-gpl-license}
* @copyright (c)2003-2015 by Francois Planque - {@link http://fplanque.com/}
*
* @package plugins
*/
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
/**
* @package plugins
*/
class shortcodes_plugin extends Plugin
{
var $code = 'evo_shortcodes';
var $name = 'Short Codes';
var $priority = 40;
var $version = '5.0.0';
var $group = 'editor';
var $number_of_installs = 1;
/**
* Init
*/
function PluginInit( & $params )
{
$this->short_desc = T_('Short codes inserting');
$this->long_desc = T_('This plugin will display a toolbar with buttons to quickly insert short codes.');
}
/**
* Display a toolbar
*
* @todo dh> This seems to be a lot of Javascript. Please try exporting it in a
* (dynamically created) .js src file. Then we could use cache headers
* to let the browser cache it.
* @param array Associative array of parameters
* @return boolean did we display a toolbar?
*/
function AdminDisplayToolbar( & $params )
{
global $Hit, $edited_Comment;
if( ! empty( $edited_Comment ) )
{ // Don't display the toolbars on edit comment form
return false;
}
if( $Hit->is_lynx() )
{ // let's deactivate quicktags on Lynx, because they don't work there.
return false;
}
if( ! empty( $params['Item'] ) && ( $params['Item']->is_intro() || ! $params['Item']->get_type_setting( 'allow_breaks' ) ) )
{ // Teaser and page breaks are not allowed for current item type and for all intro items:
return false;
}
// Load js to work with textarea
require_js( 'functions.js', 'blog', true, true );
?><script type="text/javascript">
//<![CDATA[
var shortcodes_buttons = new Array();
function shortcodes_button( id, text, tag, title, style )
{
this.id = id; // used to name the toolbar button
this.text = text; // label on button
this.tag = tag; // tag code to insert
this.title = title; // title
this.style = style; // style on button
}
shortcodes_buttons[shortcodes_buttons.length] = new shortcodes_button(
'shortcodes_teaserbreak', '[teaserbreak]', '[teaserbreak]',
'<?php echo TS_('Teaser break') ?>', ''
);
shortcodes_buttons[shortcodes_buttons.length] = new shortcodes_button(
'shortcodes_pagebreak', '[pagebreak]', '[pagebreak]',
'<?php echo TS_('Page break') ?>'
);
function shortcodes_toolbar( title )
{
document.write( '<?php echo $this->get_template( 'toolbar_title_before' ); ?>' + title + '<?php echo $this->get_template( 'toolbar_title_after' ); ?>' );
document.write( '<?php echo $this->get_template( 'toolbar_group_before' ); ?>' );
for( var i = 0; i < shortcodes_buttons.length; i++ )
{
var button = shortcodes_buttons[i];
document.write( '<input type="button" id="' + button.id + '" title="' + button.title + '"'
+ ( typeof( button.style ) != 'undefined' ? ' style="' + button.style + '"' : '' ) + ' class="<?php echo $this->get_template( 'toolbar_button_class' ); ?>" data-func="shortcodes_insert_tag|b2evoCanvas|'+i+'" value="' + button.text + '" />' );
}
document.write( '<?php echo $this->get_template( 'toolbar_group_after' ); ?>' );
}
function shortcodes_insert_tag( canvas_field, i )
{
if( typeof( tinyMCE ) != 'undefined' && typeof( tinyMCE.activeEditor ) != 'undefined' && tinyMCE.activeEditor )
{ // tinyMCE plugin is active now, we should focus cursor to the edit area
tinyMCE.execCommand( 'mceFocus', false, tinyMCE.activeEditor.id );
}
// Insert tag text in area
textarea_wrap_selection( canvas_field, shortcodes_buttons[i].tag, '', 0 );
}
//]]>
</script><?php
echo $this->get_template( 'toolbar_before', array( '$toolbar_class$' => 'shortcodes_toolbar' ) );
?><script type="text/javascript">shortcodes_toolbar( '<?php echo TS_('Shortcodes:'); ?>' );</script><?php
echo $this->get_template( 'toolbar_after' );
return true;
}
}
?>