-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPlugin.php
663 lines (612 loc) · 25.9 KB
/
Plugin.php
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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* 为博客添加图片表情功能 (初版:willin kan/正文功能:<a href="http://lt21.me">LT21</a>)
*
* @package Smilies
* @author 羽中
* @version 1.1.3
* @dependence 14.5.26-*
* @link http://www.yzmb.me/archives/net/smilies-for-typecho
*/
class Smilies_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
Typecho_Plugin::factory('Widget_Abstract_Comments')->contentEx = array('Smilies_Plugin','showsmilies');
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('Smilies_Plugin','showsmilies');
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('Smilies_Plugin','showsmilies');
Typecho_Plugin::factory('Widget_Archive')->footer = array('Smilies_Plugin','insertjs');
Typecho_Plugin::factory('admin/write-post.php')->bottom = array('Smilies_Plugin','smbutton');
Typecho_Plugin::factory('admin/write-page.php')->bottom = array('Smilies_Plugin','smbutton');
//模版调用钩子
Typecho_Plugin::factory('Widget_Comments_Archive')->callSmilies = array('Smilies_Plugin', 'output');
Helper::addAction('smilies', 'Smilies_Action');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate()
{
Helper::removeAction('smilies');
}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
$no22 = new Typecho_Widget_Helper_Form_Element_Checkbox('no22',
array(1=>_t('不使用标准组%s(仅输出下方的扩展表情项, 不影响标准代码解析)%s',' <span style="color:#999;font-size:.92857em;">','</span>')),NULL,'');
$no22->label->setAttribute('style','font-weight:normal;');
$form->addInput($no22);
$replacetxt = new Typecho_Widget_Helper_Form_Element_Checkbox('replacetxt',
array(1=>_t('替换字符表情%s(或干扰文本)%s',' <span style="color:#999;font-size:.92857em;">','</span>')),NULL,'');
$replacetxt->label->setAttribute('style','font-weight:normal;');
$form->addInput($replacetxt);
$smiliesset = new Typecho_Widget_Helper_Form_Element_Select('smiliesset',
array('qq'=>_t('扫描中...')),'qq',_t('选择表情包'),_t('预览插件目录下的表情文件夹进行排序或自定义扩展'));
$form->addInput($smiliesset);
$customset = new Typecho_Widget_Helper_Form_Element_Textarea('customset',NULL,'',_t('扩展表情组'),_t('以"表情代码%s(半角竖线)表情图片地址"的形式填写, 每行一组<br/>例: %s可覆盖此标准代码解析','<strong style="color:#467B96;">|</strong>','<font style="color:#467B96;">:smile:|http://image.com/smile.gif</font> '));
$customset->input->setAttribute('style','max-width:440px;height:180px;');
$customset->addRule(array(new Smilies_Plugin,'notag'),_t('请勿使用符号<strong><|></strong>作为表情代码, 以免造成解析错误'));
$form->addInput($customset);
$omax = new Typecho_Widget_Helper_Form_Element_Text('omax',
NULL,'21',_t('限制表情尺寸'),_t('设置表情在前台显示的最大宽度, 单位: px(不用填写)'));
$omax->input->setAttribute('class','text-s');
$omax->input->setAttribute('style','width:40px;');
$form->addInput($omax->addRule('isFloat'));
$cmax = new Typecho_Widget_Helper_Form_Element_Text('cmax',NULL,'28','⇐ '._t('选框按钮 | 评论内').' ⇒');
$cmax->input->setAttribute('class','text-s');
$cmax->label->setAttribute('style','position:absolute;color:#999;font-weight:normal;bottom:38px;left:42px;');
$cmax->input->setAttribute('style','position:absolute;width:40px;bottom:40px;left:186px;');
$cmax->setAttribute('style','position:relative');
$form->addInput($cmax->addRule('isFloat'));
$amax = new Typecho_Widget_Helper_Form_Element_Text('amax',NULL,'32',_t('正文内').' ⇒');
$amax->input->setAttribute('class','text-s');
$amax->label->setAttribute('style','position:absolute;color:#999;font-weight:normal;bottom:38px;left:230px;');
$amax->input->setAttribute('style','position:absolute;width:40px;bottom:40px;left:290px;');
$amax->setAttribute('style','position:relative');
$form->addInput($amax->addRule('isFloat'));
$textareaid = new Typecho_Widget_Helper_Form_Element_Text('textareaid',
NULL,_t('一般无需填写'),_t('指定评论框ID'),_t('若识别有误可在此手动指定主题的评论框(textarea)<strong>id</strong>'));
$textareaid->input->setAttribute('style','width:100px;');
$form->addInput($textareaid);
$allowpop = new Typecho_Widget_Helper_Form_Element_Radio('allowpop',
array(1=>_t('开启'),0=>_t('关闭')),0,_t('按钮弹窗效果'));
$form->addInput($allowpop);
$width = new Typecho_Widget_Helper_Form_Element_Text('width',NULL,'240',_t('弹窗宽度:'));
$width->input->setAttribute('class','text-s');
$width->label->setAttribute('style','color:#999;font-weight:normal;');
$width->input->setAttribute('style','position:absolute;width:45px;top:-4px;left:60px;');
$width->setAttribute('style','position:relative');
$form->addInput($width->addRule('isFloat'));
$radius = new Typecho_Widget_Helper_Form_Element_Text('radius',NULL,'11','px<span style="margin-left:8px;">'._t('圆角度:').'</span>');
$radius->input->setAttribute('class','text-s');
$radius->label->setAttribute('style','position:absolute;color:#999;font-weight:normal;bottom:7px;left:105px;');
$radius->input->setAttribute('style','position:absolute;width:40px;bottom:10px;left:174px;');
$radius->setAttribute('style','position:relative');
$form->addInput($radius->addRule('isFloat'));
$bcolor = new Typecho_Widget_Helper_Form_Element_Text('bcolor',NULL,'#bbb','px<span style="margin-left:8px;">'._t('边框颜色:').'</span>');
$bcolor->input->setAttribute('class','text-s');
$bcolor->label->setAttribute('style','position:absolute;color:#999;font-weight:normal;bottom:7px;left:214px;');
$bcolor->input->setAttribute('style','position:absolute;width:75px;bottom:10px;left:297px;');
$bcolor->setAttribute('style','position:relative');
$bcolor->addRule(array(new Smilies_Plugin,'colorformat'));
$form->addInput($bcolor);
$shadow = new Typecho_Widget_Helper_Form_Element_Select('shadow',
array(1=>_t('有'),0=>_t('无')),1,_t('边框阴影:'),'');
$shadow->label->setAttribute('style','position:absolute;color:#999;font-weight:normal;bottom:7px;left:380px;');
$shadow->input->setAttribute('style','position:absolute;bottom:11px;right:271px;');
$shadow->setAttribute('style','position:relative;');
$form->addInput($shadow);
$jqmode = new Typecho_Widget_Helper_Form_Element_Radio('jqmode',
array(1=>_t('jQuery'),0=>_t('原生js')),0,_t('功能脚本模式'),_t('仅兼容性表现略有差异, jQuery自动判断加载CDN源'));
$form->addInput($jqmode);
$postmode = new Typecho_Widget_Helper_Form_Element_Radio('postmode',
array(1=>_t('开启'),0=>_t('关闭')),0,_t('正文使用表情'),_t('编辑文章或页面时也可选择插入表情图片并发布显示'));
$form->addInput($postmode);
//排序保存隐藏域
$smsort = new Typecho_Widget_Helper_Form_Element_Hidden('smsort',
NULL,'icon_mrgreen.gif|icon_neutral.gif|icon_twisted.gif|icon_arrow.gif|icon_eek.gif|icon_smile.gif|icon_confused.gif|icon_cool.gif|icon_evil.gif|icon_biggrin.gif|icon_idea.gif|icon_redface.gif|icon_razz.gif|icon_rolleyes.gif|icon_wink.gif|icon_cry.gif|icon_surprised.gif|icon_lol.gif|icon_mad.gif|icon_sad.gif|icon_exclaim.gif|icon_question.gif');
$form->addInput($smsort);
$option = Helper::options();
$security = Helper::security();
//输出面板效果
?>
<link href="<?php $option->pluginUrl('Smilies/custom.css'); ?>" rel="stylesheet"/>
<script src="<?php $option->adminUrl('js/jquery.js'); ?>"></script>
<script src="<?php $option->pluginUrl('Smilies/custom.js'); ?>"></script>
<script>
$(function(){
//获取文件夹数据
$.post('<?php $security->index("/action/smilies"); ?>',
function(datas){
var data = $.parseJSON(datas),
opt = $('#smiliesset-0-3'),
scan = $('.scan'),
rest = $('#rest'),
input = $("input[name='smsort']"),
sortEffect = function(){
$('div').quberTip();
//排序结果输入
var reordered = function($elements){
var sortid = [];
$elements.each(function(){
sortid.push(this.id);
});
input.val(sortid.join('|'));
};
//gridly挂载回调
$('.gridly').gridly({
base: 28,
gutter: 1,
columns: 22,
callbacks: {reordered: reordered}
});
};
opt.html(data['1']);
scan.html(data['2']);
rest.html(data['3']);
sortEffect();
//菜单切换事件
opt.bind("change",function(){
var folder = $(this).val(),
dorder = data['0'][folder].join('|');
input.val(dorder);
//切换重取数据
$.ajax({
type:'post',
url:'<?php $security->index("/action/smilies"); ?>',
data:{'set':folder},
beforeSend: function(){
scan.text('<?php _e("扫描中..."); ?>');
},
success:function(sdatas){
var sdata = $.parseJSON(sdatas);
scan.html(sdata['2']);
rest.html(sdata['3']);
sortEffect();
}
});
});
}
);
//弹窗选项显隐
var al = $("#allowpop-1"),
an = $("#allowpop-0"),
op = $("#typecho-option-item-width-9, #typecho-option-item-radius-10, #typecho-option-item-bcolor-11, #typecho-option-item-shadow-12");
if (!al.is(":checked")) op.hide();
al.click(function(){
op.show();
});
an.click(function(){
op.hide();
});
});
</script>
<div style="color:#999;font-size:.92857em;"><p><?php _e('在主题comments.php文件中的适当位置插入代码%s即可显示表情选框','<strong style="color:#467B96;"><?php $comments->smilies(); ?></strong>'); ?></p></div>
<ul class="typecho-option" id="typecho-option-item-preview">
<li><label class="typecho-label" for="preview"><?php _e('标准组排序'); ?></label></li>
</ul>
<div class="table">
<div class="sample">
<div class="fix" id="0" title=":mrgreen:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_mrgreen.png'); ?>" alt=":mrgreen:"/></div>
<div class="fix" id="1" title=":neutral:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_neutral.png'); ?>" alt=":neutral:"/></div>
<div class="fix" id="2" title=":twisted:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_twisted.png'); ?>" alt=":twisted:"/></div>
<div class="fix" id="3" title=":arrow:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_arrow.png'); ?>" alt=":arrow:"/></div>
<div class="fix" id="4" title=":shock:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_eek.png'); ?>" alt=":shock:"/></div>
<div class="fix" id="5" title=":smile:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_smile.png'); ?>" alt=":smile:"/></div>
<div class="fix" id="6" title=":???:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_confused.png'); ?>" alt=":???:"/></div>
<div class="fix" id="7" title=":cool:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_cool.png'); ?>" alt=":cool:"/></div>
<div class="fix" id="8" title=":evil:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_evil.png'); ?>" alt=":evil:"/></div>
<div class="fix" id="9" title=":grin:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_biggrin.png'); ?>" alt=":grin:"/></div>
<div class="fix" id="10" title=":idea:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_idea.png'); ?>" alt=":idea:"/></div>
<div class="fix" id="11" title=":oops:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_redface.png'); ?>" alt=":oops:"/></div>
<div class="fix" id="12" title=":razz:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_razz.png'); ?>" alt=":razz:"/></div>
<div class="fix" id="13" title=":roll:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_rolleyes.png'); ?>" alt=":roll:"/></div>
<div class="fix" id="14" title=":wink:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_wink.png'); ?>" alt=":wink:"/></div>
<div class="fix" id="15" title=":cry:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_cry.png'); ?>" alt=":cry:"/></div>
<div class="fix" id="16" title=":eek:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_surprised.png'); ?>" alt=":eek:"/></div>
<div class="fix" id="17" title=":lol:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_lol.png'); ?>" alt=":lol:"/></div>
<div class="fix" id="18" title=":mad:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_mad.png'); ?>" alt=":mad:"/></div>
<div class="fix" id="19" title=":sad:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_sad.png'); ?>" alt=":sad:"/></div>
<div class="fix" id="20" title=":!:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_exclaim.png'); ?>" alt=":!:"/></div>
<div class="fix" id="21" title=":?:"><img src="<?php $option->pluginUrl('Smilies/wordpress/icon_question.png'); ?>" alt=":?:"/></div>
</div>
<div class="desc"><?php _e('⇕ 拖动下方的表情包图片与上方默认风格(对应22个<strong>标准代码</strong>)尽量保持一致 ⇕'); ?></div>
<div class="scan"><?php _e('扫描中...'); ?></div>
<div class="textsm" title="<?php _e('可替换字符表情对照'); ?>">
<div class="fix"></div>
<div class="fix">:|<br/>:-|</div>
<div class="fix"></div>
<div class="fix"></div>
<div class="fix">8O<br/>8-O</div>
<div class="fix">:)<br/>:-)</div>
<div class="fix">:?<br/>:-?</div>
<div class="fix">8)<br/>8-)</div>
<div class="fix"></div>
<div class="fix">:D<br/>:-D</div>
<div class="fix"></div>
<div class="fix"></div>
<div class="fix">:P<br/>:-P</div>
<div class="fix"></div>
<div class="fix">;)<br/>;-)</div>
<div class="fix"></div>
<div class="fix">:o<br/>:-o</div>
<div class="fix"></div>
<div class="fix">:x<br/>:-x</div>
<div class="fix">:(<br/>:-(</div>
<div class="fix"></div>
<div class="fix"></div>
</div>
</div>
<div id="more"><div id="rest"></div></div>
<?php
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
/**
* 整理表情数据
*
* @access private
* @param boolean $archive 是否为正文
* @return array
*/
private static function parsesmilies($archive=false)
{
$options = Helper::options();
$settings = $options->plugin('Smilies');
$omax = $settings->omax;
$omax = $omax ? 'max-width:'.$omax.'px;' : '';
$acmax = $archive ? $settings->amax : $settings->cmax;
$acmax = $acmax ? 'max-width:'.$acmax.'px;' : '';
//构建标准数组
$smurl = Typecho_Common::url('Smilies/'.urlencode($settings->smiliesset).'/',$options->pluginUrl);
$smsort = explode('|',$settings->smsort);
$smimg = array();
foreach ($smsort as $imgname) {
$smimg[] = $smurl.$imgname;
}
$pattern = array(':mrgreen:',':neutral:',':twisted:',':arrow:',':shock:',':smile:',':???:',':cool:',':evil:',':grin:',':idea:',':oops:',':razz:',':roll:',':wink:',':cry:',':eek:',':lol:',':mad:',':sad:',':!:',':?:');
$smtrans = array_combine($pattern,$smimg);
//并入字符数组
$textsm = array(
'8-)'=>$smtrans[':cool:'],
'8-O'=>$smtrans[':shock:'],
':-('=>$smtrans[':sad:'],
':-)'=>$smtrans[':smile:'],
':-?'=>$smtrans[':???:'],
':-D'=>$smtrans[':grin:'],
':-P'=>$smtrans[':razz:'],
':-o'=>$smtrans[':eek:'],
':-x'=>$smtrans[':mad:'],
':-|'=>$smtrans[':neutral:'],
';-)'=>$smtrans[':wink:'],
'8)'=>$smtrans[':cool:'],
'8O'=>$smtrans[':shock:'],
':('=>$smtrans[':sad:'],
':)'=>$smtrans[':smile:'],
':?'=>$smtrans[':???:'],
':D'=>$smtrans[':grin:'],
':P'=>$smtrans[':razz:'],
':o'=>$smtrans[':eek:'],
':x'=>$smtrans[':mad:'],
':|'=>$smtrans[':neutral:'],
';)'=>$smtrans[':wink:'],
);
$smtrans = $settings->replacetxt ? $smtrans+$textsm : $smtrans;
//并入扩展数组
$customset = trim(Typecho_Common::stripTags($settings->customset));
$customsm = array();
if (strpos($customset,'|')) {
$smsets = array_filter(preg_split("/(\r|\n|\r\n)/",$customset));
$smarray = array();
foreach ($smsets as $smset) {
$smarray[] = explode('|',$smset);
}
foreach ($smarray as $row) {
$customsm[trim($row['0'])] = trim($row['1']);
}
$smtrans = array_merge($smtrans,$customsm);
}
$smiliesicon1 = array();
$smiliesicon2 = array();
$smiliestag = array();
$smiliesimg = array();
$smiled = array();
foreach ($smtrans as $tag=>$grin) {
$alt = basename($grin);
//输出表情选项
if (!in_array($grin,$smiled) && !in_array($tag,array_keys($textsm))) {
$smiled[] = $grin; //过滤重复值
$icons = '<span'.($settings->jqmode ? '' :
($archive ? ' onclick="Smilies.grin("'.$tag.'");"' : ' onclick="Smilies.grin(\''.$tag.'\');"') //fix js bug
).' style="cursor:pointer;" data-tag=" '.$tag.' " title="'.$tag.'"><img style="margin:2px;'.$omax.'display:inline-block;" src="'.$grin.'" alt="'.$alt.'"/></span>';
if (in_array($tag,$pattern)) {
$smiliesicon1[] = $settings->no22 ? ($customsm ? '' : _t('扩展表情为空!')) : $icons;
} else {
$smiliesicon2[] = $icons;
$customsm[$tag] = $grin;
}
}
$smiliestag[] = $tag;
$smiliesimg[] = '<img class="smilies" src="'.$grin.'" alt="'.$alt.'" style="'.$acmax.'display:inline-block;"/>';
}
//弹窗模式按钮
$smilies = empty($customsm) && $settings->no22 ? _t('扩展表情为空!') : '<img src="'.(empty($customsm[':smile:']) && $settings->no22 ? current($customsm) : $smtrans[':smile:']).'" alt="'._t('选择表情').'" style="'.$omax.'"/>';
return array($smilies,implode('',array_merge(array_unique($smiliesicon1),$smiliesicon2)),$smiliestag,$smiliesimg);
}
/**
* 输出编辑器按钮
*
* @access public
* @return void
*/
public static function smbutton()
{
if (Helper::options()->plugin('Smilies')->postmode) {
$smilies = self::parsesmilies(true);
?>
<script>
$(function(){
var wmd = $('#wmd-image-button'),
textarea = $('#text');
if (wmd.length>0) {
wmd.after(
'<li class="wmd-button" id="wmd-sm-button" style="padding-top:5px;" title="<?php _e("插入表情"); ?>"><img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2216%22%20height%3D%2216%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20fill%3D%22%23999%22%20d%3D%22M12%202c5.514%200%2010%204.486%2010%2010s-4.486%2010-10%2010-10-4.486-10-10%204.486-10%2010-10zm0-2c-6.627%200-12%205.373-12%2012s5.373%2012%2012%2012%2012-5.373%2012-12-5.373-12-12-12zm5.507%2013.941c-1.512%201.195-3.174%201.931-5.506%201.931-2.334%200-3.996-.736-5.508-1.931l-.493.493c1.127%201.72%203.2%203.566%206.001%203.566%202.8%200%204.872-1.846%205.999-3.566l-.493-.493zm-9.007-5.941c-.828%200-1.5.671-1.5%201.5s.672%201.5%201.5%201.5%201.5-.671%201.5-1.5-.672-1.5-1.5-1.5zm7%200c-.828%200-1.5.671-1.5%201.5s.672%201.5%201.5%201.5%201.5-.671%201.5-1.5-.672-1.5-1.5-1.5z%22%2F%3E%3C%2Fsvg%3E"/></li>');
} else {
$('.url-slug').after('<button type="button" id="wmd-sm-button" class="btn btn-xs" style="margin-right:5px;"><?php _e("插入表情"); ?></button>');
}
$('#wmd-sm-button').click(function(){
$('body').append('<div id="smpanel">' +
'<div class="wmd-prompt-background" style="position:absolute;z-index:1000;opacity:0.5;top:0px;left:0px;width:100%;height:954px;"></div>' +
'<div class="wmd-prompt-dialog"><div><p><b><?php _e("插入表情"); ?></b></p>' +
'<p><?php _e("请在下方点击想要插入正文内的表情图片"); ?></p></div>' +
'<form><?php echo $smilies["1"];?></form></div></div>');
$("form span").click(function(){
var sminput = $(this).attr("data-tag"),
sel = textarea.getSelection(),
offset = (sel ? sel.start : 0)+sminput.length;
textarea.replaceSelection(sminput);
textarea.setSelection(offset,offset);
$('#smpanel').remove();
});
});
$(document).mouseup(function(e){
var dialog = $('.wmd-prompt-dialog');
if (!dialog.is(e.target) && dialog.has(e.target).length === 0){
$('#smpanel').remove();
}
});
});
</script>
<?php
}
}
/**
* 解析表情图片
*
* @access public
* @param string $content 评论内容
* @return string
*/
public static function showsmilies($content,$widget,$lastResult)
{
$content = empty($lastResult) ? $content : $lastResult;
$options = Helper::options();
//允许图片标签
$options->commentsHTMLTagAllowed .= '<img src="" alt="" style=""/>';
$archive = $widget instanceof Widget_Archive;
if ($widget instanceof Widget_Abstract_Comments || $archive && $options->plugin('Smilies')->postmode) {
$arrays = self::parsesmilies($archive);
$content = str_replace($arrays['2'],$arrays['3'],$content);
}
return $content;
}
/**
* 输出表情选框
*
* @access public
* @return void
*/
public static function output($widget='')
{
$options = Helper::options();
$settings = $options->plugin('Smilies');
$width = $settings->width;
$width = $width ? $width : '240';
$radius = $settings->radius;
$radius = false!==$radius ? $radius : '11';
$radius = 'border-radius:'.$radius.'px';
$radius = '-moz-'.$radius.';-webkit-'.$radius.';-khtml-'.$radius.';'.$radius.';';
$bcolor = $settings->bcolor;
$bcolor = $bcolor ? $bcolor : '#bbb';
$shadow = 'box-shadow:1px 3px 15px '.$bcolor;
$shadow = $settings->shadow ? '-moz-'.$shadow.';-webkit-'.$shadow.';-khtml-'.$shadow.';'.$shadow.';' : '';
//弹窗css样式
$smiliesdisplay = $settings->allowpop
? ' style="display:none;position:absolute;z-index:9999;width:'.$width.'px;margin-top:-70px;padding:5px;background-color:#fff;border:1px solid '.$bcolor.';'.$radius.$shadow.'"'
: ' style="display:block;"';
//罗列表情图标
$smilies = self::parsesmilies();
$output = '<div id="smiliesbox"'.$smiliesdisplay.'>';
$output .= $smilies['1'];
$output .= '</div>';
//弹窗风格按钮
if ($settings->allowpop) {
$output .= '<span style="cursor:pointer;" id="smiliesbutton" title="'._t('选择表情').'">'.($settings->jqmode ? $smilies['0'] : '<a href="javascript:Smilies.showBox();">'.$smilies['0'].'</a>').'</span>';
}
echo $output;
}
/**
* 输出js脚本
*
* @access public
* @return void
*/
public static function insertjs($widget)
{
$options = Helper::options();
$settings = $options->plugin('Smilies');
$textareaid = $settings->textareaid;
$textareaid = $textareaid ? $textareaid : _t('一般无需填写');
$idset = $widget->is('single') ? $textareaid : 'text';
$txtid = $settings->jqmode ? '#'.$idset : $idset;
$txtdom = 'domId("'.$txtid.'")';
if ($widget->is('single') && $idset==_t('一般无需填写')) {
$txtid = 'textarea';
$txtdom = 'domTag("'.$txtid.'")';
}
//jquery模式
if ($settings->jqmode) {
$auto = '';
$js = '
<script type="text/javascript">
$(function(){
var box = $("#smiliesbox");
$("#smiliesbutton").click(function(){
box.show();
});
$("span",box).click(function(){
$("'.$txtid.'").insert($(this).attr("data-tag"));';
if ($settings->allowpop){
$js .= '
box.hide();';
$auto = '
$(document).mouseup(function(e){
if (!box.is(e.target) && box.has(e.target).length === 0) {
box.hide();
}
});';
}
$js .= '
});'.$auto.'
$.fn.extend({
"insert": function(myValue){
var $t = $(this)[0];
if (document.selection) {
this.focus();
sel = document.selection.createRange();
sel.text = myValue;
this.focus()
} else if ($t.selectionStart || $t.selectionStart=="0") {
var startPos = $t.selectionStart;
var endPos = $t.selectionEnd;
var scrollTop = $t.scrollTop;
$t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length);
this.focus();
$t.selectionStart = startPos + myValue.length;
$t.selectionEnd = startPos + myValue.length;
$t.scrollTop = scrollTop
} else {
this.value += myValue;
this.focus()
}
}
})
});
</script>
';
//js模式
} else {
$js = '<script type="text/javascript">
Smilies = {
domId : function(id){
return document.getElementById(id);
},
domTag : function(id){
return document.getElementsByTagName(id)[0];
},
showBox : function(){
this.domId("smiliesbox").style.display = "block";
document.onclick = function(){
Smilies.closeBox();
}
},
closeBox : function(){
this.domId("smiliesbox").style.display = "none";
},
grin : function(tag){
tag = \' \' + tag + \' \'; myField = this.'.$txtdom.';
document.selection ? (myField.focus(),sel = document.selection.createRange(),sel.text = tag,myField.focus()) : this.insertTag(tag);
},
insertTag : function(tag){
myField = Smilies.'.$txtdom.';
myField.selectionStart || myField.selectionStart=="0" ? (
startPos = myField.selectionStart,
endPos = myField.selectionEnd,
cursorPos = startPos,
myField.value = myField.value.substring(0,startPos)
+ tag
+ myField.value.substring(endPos,myField.value.length),
cursorPos += tag.length,
myField.focus(),
myField.selectionStart = cursorPos,
myField.selectionEnd = cursorPos
) : (
myField.value += tag,
myField.focus()
);';
if ($settings->allowpop) {
$js .= '
this.closeBox();';
}
$js .= '
}
}
</script>
';
}
if ($widget->is('single')) {
echo ($settings->jqmode ? '<script type="text/javascript">
window.jQuery || document.write(\'<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"><\/script>\')</script>' : '').$js;
}
if ($widget instanceof Widget_Contents_Post_Edit && $settings->postmode) {
echo $js;
}
}
/**
* 检查禁用符号
*
* @access public
* @param string $input
* @return boolean
*/
public static function notag($input)
{
return !preg_match('/[\>\<]|\|\|/',$input);
}
/**
* 判断颜色格式
*
* @access public
* @param string $width
* @return boolean
*/
public static function colorformat($input)
{
return preg_match('/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/',$input);
}
}