This repository has been archived by the owner. It is now read-only.
forked from b2evolution/b2evolution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_quicktags.plugin.php
More file actions
466 lines (410 loc) · 16.4 KB
/
_quicktags.plugin.php
File metadata and controls
466 lines (410 loc) · 16.4 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
<?php
/**
* This file implements the Quicktags 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-2016 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 quicktags_plugin extends Plugin
{
var $code = 'b2evQTag';
var $name = 'Quick Tags';
var $priority = 30;
var $version = '6.7.9';
var $group = 'editor';
var $number_of_installs = 1;
/**
* Init
*/
function PluginInit( & $params )
{
$this->short_desc = T_('Easy HTML tags inserting');
$this->long_desc = T_('This plugin will display a toolbar with buttons to quickly insert HTML tags around selected text in a post.');
}
/**
* Event handler: Called when displaying editor toolbars on post/item form.
*
* This is for post/item edit forms only. Comments, PMs and emails use different events.
*
* @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 )
{
$Item = & $params['Item'];
if( empty( $Item ) || ! $Item->get_type_setting( 'allow_html' ) )
{ // Only when HTML is allowed in post:
return false;
}
$item_Blog = & $Item->get_Blog();
if( ! $this->get_coll_setting( 'coll_use_for_posts', $item_Blog ) )
{ // This plugin is disabled to use for posts:
return false;
}
return $this->DisplayCodeToolbar( $params );
}
/**
* Event handler: Called when displaying editor toolbars on comment form.
*
* @param array Associative array of parameters
* @return boolean did we display a toolbar?
*/
function DisplayCommentToolbar( & $params )
{
$Comment = & $params['Comment'];
if( $Comment )
{ // Get a post of the comment:
$comment_Item = & $Comment->get_Item();
}
if( empty( $comment_Item ) || ! $comment_Item->get_type_setting( 'allow_html' ) )
{ // Only when HTML is allowed in post:
return false;
}
$item_Blog = & $comment_Item->get_Blog();
if( ! $this->get_coll_setting( 'coll_use_for_comments', $item_Blog ) )
{ // This plugin is disabled to use for comments:
return false;
}
return $this->DisplayCodeToolbar( $params );
}
/**
* Display a code toolbar
*
* @param array Associative array of parameters
* @return boolean did we display a toolbar?
*/
function DisplayCodeToolbar( & $params )
{
global $Hit;
if( $Hit->is_lynx() )
{ // let's deactivate quicktags on Lynx, because they don't work there.
return false;
}
$params = array_merge( array(
'js_prefix' => '', // Use different prefix if you use several toolbars on one page
), $params );
$simple = ( isset( $params['edit_layout'] ) && $params['edit_layout'] == 'inskin' );
// Load js to work with textarea
require_js( 'functions.js', 'blog', true, true );
?><script type="text/javascript">
//<![CDATA[
var <?php echo $params['js_prefix']; ?>b2evoButtons = new Array();
var <?php echo $params['js_prefix']; ?>b2evoLinks = new Array();
var <?php echo $params['js_prefix']; ?>b2evoOpenTags = new Array();
function <?php echo $params['js_prefix']; ?>b2evoButton(id, display, style, tagStart, tagEnd, access, tit, open, grp_pos)
{
this.id = id; // used to name the toolbar button
this.display = display; // label on button
this.style = style; // style on button
this.tagStart = tagStart; // open tag
this.tagEnd = tagEnd; // close tag
this.access = access; // access key
this.tit = tit; // title
this.open = open; // set to -1 if tag does not need to be closed
this.grp_pos = grp_pos; // position in the group, e.g. 'last'
}
<?php
if( $simple )
{ ?>
<?php echo $params['js_prefix']; ?>b2evoButtons[<?php echo $params['js_prefix']; ?>b2evoButtons.length] = new <?php echo $params['js_prefix']; ?>b2evoButton(
'<?php echo $params['js_prefix']; ?>b2evo_bold'
,'bold', 'font-weight:bold;'
,'<b>','</b>'
,'b'
,'<?php echo TS_('Bold [Alt-B]') ?>'
);
<?php echo $params['js_prefix']; ?>b2evoButtons[<?php echo $params['js_prefix']; ?>b2evoButtons.length] = new <?php echo $params['js_prefix']; ?>b2evoButton(
'<?php echo $params['js_prefix']; ?>b2evo_italic'
,'italic', 'font-style:italic;'
,'<i>','</i>'
,'i'
,'<?php echo TS_('Italic [Alt-I]') ?>', -1, 'last'
);
<?php
}
else
{
?>
<?php echo $params['js_prefix']; ?>b2evoButtons[<?php echo $params['js_prefix']; ?>b2evoButtons.length] = new <?php echo $params['js_prefix']; ?>b2evoButton(
'<?php echo $params['js_prefix']; ?>b2evo_ins'
,'ins', ''
,'<ins>','</ins>'
,'b'
,'<?php echo TS_('INSerted') ?>'
);
<?php echo $params['js_prefix']; ?>b2evoButtons[<?php echo $params['js_prefix']; ?>b2evoButtons.length] = new <?php echo $params['js_prefix']; ?>b2evoButton(
'<?php echo $params['js_prefix']; ?>b2evo_del'
,'del', 'text-decoration:line-through;'
,'<del>','</del>'
,'i'
,'<?php echo TS_('DELeted') ?>'
);
<?php echo $params['js_prefix']; ?>b2evoButtons[<?php echo $params['js_prefix']; ?>b2evoButtons.length] = new <?php echo $params['js_prefix']; ?>b2evoButton(
'<?php echo $params['js_prefix']; ?>b2evo_strong'
,'str', 'font-weight:bold;'
,'<strong>','</strong>'
,'s'
,'<?php echo TS_('STRong [Alt-S]') ?>'
);
<?php echo $params['js_prefix']; ?>b2evoButtons[<?php echo $params['js_prefix']; ?>b2evoButtons.length] = new <?php echo $params['js_prefix']; ?>b2evoButton(
'<?php echo $params['js_prefix']; ?>b2evo_em'
,'em', 'font-style:italic;'
,'<em>','</em>'
,'e'
,'<?php echo TS_('EMphasis [Alt-E]') ?>'
);
<?php echo $params['js_prefix']; ?>b2evoButtons[<?php echo $params['js_prefix']; ?>b2evoButtons.length] = new <?php echo $params['js_prefix']; ?>b2evoButton(
'<?php echo $params['js_prefix']; ?>b2evo_code'
,'code', ''
,'<code>','</code>'
,'c'
,'<?php echo TS_('CODE [Alt-C]') ?>', -1, 'last'
);
<?php echo $params['js_prefix']; ?>b2evoButtons[<?php echo $params['js_prefix']; ?>b2evoButtons.length] = new <?php echo $params['js_prefix']; ?>b2evoButton(
'<?php echo $params['js_prefix']; ?>b2evo_par'
,'p', ''
,'<p>','</p>'
,'p'
,'<?php echo TS_('Paragraph [Alt-P]') ?>'
);
<?php echo $params['js_prefix']; ?>b2evoButtons[<?php echo $params['js_prefix']; ?>b2evoButtons.length] = new <?php echo $params['js_prefix']; ?>b2evoButton(
'<?php echo $params['js_prefix']; ?>b2evo_block'
,'block', ''
,'<blockquote>','</blockquote>'
,'b'
,'<?php echo TS_('BLOCKQUOTE [Alt-B]') ?>'
);
<?php echo $params['js_prefix']; ?>b2evoButtons[<?php echo $params['js_prefix']; ?>b2evoButtons.length] = new <?php echo $params['js_prefix']; ?>b2evoButton(
'<?php echo $params['js_prefix']; ?>b2evo_pre'
,'pre', ''
,'<pre>','</pre>'
,'r'
,'<?php echo TS_('PREformatted text [Alt-R]') ?>'
);
<?php echo $params['js_prefix']; ?>b2evoButtons[<?php echo $params['js_prefix']; ?>b2evoButtons.length] = new <?php echo $params['js_prefix']; ?>b2evoButton(
'<?php echo $params['js_prefix']; ?>b2evo_ul'
,'ul', ''
,'<ul>\n','</ul>\n\n'
,'u'
,'<?php echo TS_('Unordered List [Alt-U]') ?>'
);
<?php echo $params['js_prefix']; ?>b2evoButtons[<?php echo $params['js_prefix']; ?>b2evoButtons.length] = new <?php echo $params['js_prefix']; ?>b2evoButton(
'<?php echo $params['js_prefix']; ?>b2evo_ol'
,'ol', ''
,'<ol>\n','</ol>\n\n'
,'o'
,'<?php echo TS_('Ordered List [Alt-O]') ?>'
);
<?php echo $params['js_prefix']; ?>b2evoButtons[<?php echo $params['js_prefix']; ?>b2evoButtons.length] = new <?php echo $params['js_prefix']; ?>b2evoButton(
'<?php echo $params['js_prefix']; ?>b2evo_li'
,'li', ''
,' <li>','</li>\n'
,'l'
,'<?php echo TS_('List Item [Alt-L]') ?>', -1, 'last'
);
<?php
}
?>
<?php echo $params['js_prefix']; ?>b2evoButtons[<?php echo $params['js_prefix']; ?>b2evoButtons.length] = new <?php echo $params['js_prefix']; ?>b2evoButton(
'<?php echo $params['js_prefix']; ?>b2evo_img'
,'<?php echo ($simple ? 'image' : 'img') ?>', ''
,'',''
,'g'
,'<?php echo TS_('IMaGe [Alt-G]') ?>'
,-1
); // special case
<?php echo $params['js_prefix']; ?>b2evoButtons[<?php echo $params['js_prefix']; ?>b2evoButtons.length] = new <?php echo $params['js_prefix']; ?>b2evoButton(
'<?php echo $params['js_prefix']; ?>b2evo_link'
,'link', 'text-decoration:underline;'
,'','</a>'
,'a'
,'<?php echo TS_('A href [Alt-A]') ?>'
); // special case
function <?php echo $params['js_prefix']; ?>b2evoGetButton(button, i)
{
var r = '';
if( button.id == '<?php echo $params['js_prefix']; ?>b2evo_img' )
{
r += '<input type="button" id="' + button.id + '" accesskey="' + button.access + '" title="' + button.tit
+ '" style="' + button.style + '" class="<?php echo $this->get_template( 'toolbar_button_class' ); ?>" data-func="<?php echo $params['js_prefix']; ?>b2evoInsertImage|<?php echo $params['js_prefix']; ?>b2evoCanvas" value="' + button.display + '" />';
}
else if( button.id == '<?php echo $params['js_prefix']; ?>b2evo_link' )
{
r += '<input type="button" id="' + button.id + '" accesskey="' + button.access + '" title="' + button.tit
+ '" style="' + button.style + '" class="<?php echo $this->get_template( 'toolbar_button_class' ); ?>" data-func="<?php echo $params['js_prefix']; ?>b2evoInsertLink|<?php echo $params['js_prefix']; ?>b2evoCanvas|'+i+'" value="' + button.display + '" />';
}
else
{ // Normal buttons:
r += '<input type="button" id="' + button.id + '" accesskey="' + button.access + '" title="' + button.tit
+ '" style="' + button.style + '" class="<?php echo $this->get_template( 'toolbar_button_class' ); ?>" data-func="<?php echo $params['js_prefix']; ?>b2evoInsertTag|<?php echo $params['js_prefix']; ?>b2evoCanvas|'+i+'" value="' + button.display + '" />';
}
return r;
}
// Memorize a new open tag
function <?php echo $params['js_prefix']; ?>b2evoAddTag(button)
{
if( <?php echo $params['js_prefix']; ?>b2evoButtons[button].tagEnd != '' )
{
<?php echo $params['js_prefix']; ?>b2evoOpenTags[<?php echo $params['js_prefix']; ?>b2evoOpenTags.length] = button;
document.getElementById(<?php echo $params['js_prefix']; ?>b2evoButtons[button].id).value = '/' + document.getElementById(<?php echo $params['js_prefix']; ?>b2evoButtons[button].id).value;
}
}
// Forget about an open tag
function <?php echo $params['js_prefix']; ?>b2evoRemoveTag(button)
{
for (i = 0; i < <?php echo $params['js_prefix']; ?>b2evoOpenTags.length; i++)
{
if (<?php echo $params['js_prefix']; ?>b2evoOpenTags[i] == button)
{
<?php echo $params['js_prefix']; ?>b2evoOpenTags.splice(i, 1);
document.getElementById(<?php echo $params['js_prefix']; ?>b2evoButtons[button].id).value = document.getElementById(<?php echo $params['js_prefix']; ?>b2evoButtons[button].id).value.replace('/', '');
}
}
}
function <?php echo $params['js_prefix']; ?>b2evoCheckOpenTags(button)
{
var tag = 0;
for (i = 0; i < <?php echo $params['js_prefix']; ?>b2evoOpenTags.length; i++)
{
if (<?php echo $params['js_prefix']; ?>b2evoOpenTags[i] == button)
{
tag++;
}
}
if (tag > 0)
{
return true; // tag found
}
else
{
return false; // tag not found
}
}
function <?php echo $params['js_prefix']; ?>b2evoCloseAllTags()
{
var count = <?php echo $params['js_prefix']; ?>b2evoOpenTags.length;
for (o = 0; o < count; o++)
{
<?php echo $params['js_prefix']; ?>b2evoInsertTag(<?php echo $params['js_prefix']; ?>b2evoCanvas, <?php echo $params['js_prefix']; ?>b2evoOpenTags[<?php echo $params['js_prefix']; ?>b2evoOpenTags.length - 1]);
}
}
function <?php echo $params['js_prefix']; ?>b2evoToolbar( title )
{
var r = '<?php echo format_to_js( $this->get_template( 'toolbar_title_before' ) ); ?>' + title + '<?php echo format_to_js( $this->get_template( 'toolbar_title_after' ) ); ?>'
+ '<?php echo format_to_js( $this->get_template( 'toolbar_group_before' ) ); ?>';
for (var i = 0; i < <?php echo $params['js_prefix']; ?>b2evoButtons.length; i++)
{
r += <?php echo $params['js_prefix']; ?>b2evoGetButton( <?php echo $params['js_prefix']; ?>b2evoButtons[i], i );
if( <?php echo $params['js_prefix']; ?>b2evoButtons[i].grp_pos == 'last' && i > 0 && i < <?php echo $params['js_prefix']; ?>b2evoButtons.length - 1 )
{ // Separator between groups
r += '<?php echo format_to_js( $this->get_template( 'toolbar_group_after' ).$this->get_template( 'toolbar_group_before' ) ); ?>';
}
}
r += '<?php echo format_to_js( $this->get_template( 'toolbar_group_after' ).$this->get_template( 'toolbar_group_before' ) ); ?>'
+ '<input type="button" id="b2evo_close" class="<?php echo $this->get_template( 'toolbar_button_class' ); ?>" data-func="<?php echo $params['js_prefix']; ?>b2evoCloseAllTags" title="<?php echo format_to_output( T_('Close all tags'), 'htmlattr' ); ?>" value="<?php echo ($simple ? 'close all tags' : 'X') ?>" />'
+ '<?php echo format_to_js( $this->get_template( 'toolbar_group_after' ) ); ?>';
jQuery( '.<?php echo $params['js_prefix'].$this->code ?>_toolbar' ).html( r );
}
/**
* insertion code
*/
function <?php echo $params['js_prefix']; ?>b2evoInsertTag( myField, i )
{
// we need to know if something is selected.
// First, ask plugins, then try IE and Mozilla.
var sel_text = b2evo_Callbacks.trigger_callback("get_selected_text_for_"+myField.id);
var focus_when_finished = false; // used for IE
if( sel_text == null )
{ // detect selection:
//IE support
if(document.selection)
{
myField.focus();
var sel = document.selection.createRange();
sel_text = sel.text;
focus_when_finished = true;
}
//MOZILLA/NETSCAPE support
else if(myField.selectionStart || myField.selectionStart == '0')
{
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
sel_text = (startPos != endPos);
}
}
if( sel_text )
{ // some text selected
textarea_wrap_selection( myField, <?php echo $params['js_prefix']; ?>b2evoButtons[i].tagStart, <?php echo $params['js_prefix']; ?>b2evoButtons[i].tagEnd, 0 );
}
else
{
if( !<?php echo $params['js_prefix']; ?>b2evoCheckOpenTags(i) || <?php echo $params['js_prefix']; ?>b2evoButtons[i].tagEnd == '')
{
textarea_wrap_selection( myField, <?php echo $params['js_prefix']; ?>b2evoButtons[i].tagStart, '', 0 );
<?php echo $params['js_prefix']; ?>b2evoAddTag(i);
}
else
{
textarea_wrap_selection( myField, '', <?php echo $params['js_prefix']; ?>b2evoButtons[i].tagEnd, 0 );
<?php echo $params['js_prefix']; ?>b2evoRemoveTag(i);
}
}
if(focus_when_finished)
{
myField.focus();
}
}
function <?php echo $params['js_prefix']; ?>b2evoInsertLink(myField, i, defaultValue)
{
if (!defaultValue)
{
defaultValue = 'http://';
}
if (!<?php echo $params['js_prefix']; ?>b2evoCheckOpenTags(i)) {
var URL = prompt( '<?php echo TS_('URL') ?>:', defaultValue);
if (URL)
{
b2evoButtons[i].tagStart = '<a href="' + URL + '">';
<?php echo $params['js_prefix']; ?>b2evoInsertTag(myField, i);
}
}
else
{
<?php echo $params['js_prefix']; ?>b2evoInsertTag( myField, i );
}
}
function <?php echo $params['js_prefix']; ?>b2evoInsertImage(myField)
{
var myValue = prompt( '<?php echo TS_('URL') ?>:', 'http://' );
if (myValue) {
myValue = '<img src="'
+ myValue
+ '" alt="' + prompt('<?php echo TS_('ALTernate text') ?>:', '')
+ '" title="' + prompt('<?php echo TS_('Title') ?>:', '')
+ '" />';
textarea_wrap_selection( myField, myValue, '', 1 );
}
}
//]]>
</script><?php
echo $this->get_template( 'toolbar_before', array( '$toolbar_class$' => $params['js_prefix'].$this->code.'_toolbar' ) );
echo $this->get_template( 'toolbar_after' );
?><script type="text/javascript"><?php echo $params['js_prefix']; ?>b2evoToolbar( 'HTML: ' );</script><?php
return true;
}
}
?>