-
Notifications
You must be signed in to change notification settings - Fork 2
/
Plugin.php
2054 lines (1880 loc) · 68.7 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
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* 为博客添加HighSlide弹窗效果与相册功能
*
* @package HighSlide
* @author 羽中
* @version 1.4.7
* @dependence 14.5.26-*
* @link http://www.yzmb.me/archives/net/highslide-for-typecho
*/
class HighSlide_Plugin implements Typecho_Plugin_Interface
{
/**
* 相册组ID集合
*
* @access private
* @var array
*/
private static $ids = array();
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return string
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
Helper::addPanel(3,'HighSlide/manage-gallery.php',_t('页面相册'),_t('配置页面相册'),'administrator');
Helper::addAction('gallery-edit','HighSlide_Action');
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('HighSlide_Plugin','autohighslide');
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('HighSlide_Plugin','autohighslide');
Typecho_Plugin::factory('Widget_Upload')->deleteHandle = array('HighSlide_Plugin','deleteHandle');
Typecho_Plugin::factory('Widget_Archive')->header = array('HighSlide_Plugin','headlink');
Typecho_Plugin::factory('Widget_Archive')->footer = array('HighSlide_Plugin','footlink');
Typecho_Plugin::factory('admin/write-post.php')->bottom = array('HighSlide_Plugin','attachpanel');
Typecho_Plugin::factory('admin/write-page.php')->bottom = array('HighSlide_Plugin','attachpanel');
return self::galleryinstall();
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate()
{
Helper::removePanel(3,'HighSlide/manage-gallery.php');
Helper::removeAction('gallery-edit');
}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
$mode = new Typecho_Widget_Helper_Form_Element_Radio('mode',
array('highslide.packed.js'=>_t('基础版 <span style="color:#999;font-size:0.92857em;">(25.2K)仅支持插图弹窗</span>'),'highslide-full.packed.js'=>_t('全功能版 <span style="color:#999;font-size:0.92857em;">(46.8K)支持html弹窗/插图幻灯/页面相册等</span>')),'highslide.packed.js',_t('核心选择'));
$form->addInput($mode);
$rpopt = new Typecho_Widget_Helper_Form_Element_Checkbox('rpopt',
array('link'=>_t('链接至图片'),'img'=>_t('所有图片')),NULL,_t('弹窗模式'),_t('默认将目标为图片的<strong>超链接</strong>(包括文字)转化为弹窗效果,也可以选择将所有图片直接转化为原图弹窗'));
$rpopt->input->setAttribute('disabled','true');
$form->addInput($rpopt);
$rplist = new Typecho_Widget_Helper_Form_Element_Checkbox('rplist',
array('index'=>_t('首页'),'post'=>_t('文章'),'page'=>_t('独立页面'),'archive'=>_t('归档页面')),array('index','post','page'),_t('应用范围'),_t('取消勾选的页面类型将不会加载插件脚本与替换效果, 归档页包括按时间/标签等索引的列表型页面'));
$form->addInput($rplist);
$outline= new Typecho_Widget_Helper_Form_Element_Radio('outline',
array(''=>_t('无边框'),'rounded-white'=>_t('圆角白'),'rounded-black'=>_t('圆角黑'),'glossy-dark'=>_t('亮泽黑'),'outer-glow'=>_t('外发光'),'beveled'=>_t('半透明')),'',_t('边框风格'));
$form->addInput($outline);
$cbutton = new Typecho_Widget_Helper_Form_Element_Radio('cbutton',
array(1=>_t('显示'),0=>_t('不显示')),0,_t('关闭按钮'));
$form->addInput($cbutton);
$ltext = new Typecho_Widget_Helper_Form_Element_Text('ltext',
NULL,'© '.$_SERVER['HTTP_HOST'].'',_t('角标文字'));
$ltext->input->setAttribute('class','mini');
$form->addInput($ltext);
$lpos = new Typecho_Widget_Helper_Form_Element_Select('lpos',
array('top left'=>_t('左上'),'top center'=>_t('中上'),'top right'=>_t('右上'),'bottom left'=>_t('左下'),'bottom center'=>_t('中下'),'bottom right'=>_t('右下')),'top left','');
$lpos->input->setAttribute('style','position:absolute;bottom:16px;left:173px;');
$lpos->setAttribute('style','position:relative');
$form->addInput($lpos);
$capt = new Typecho_Widget_Helper_Form_Element_Radio('capt',
array(''=>_t('不显示'),'this.a.title'=>_t('显示链接title'),'this.thumb.alt'=>_t('显示图片alt')),'',_t('图片说明'),_t('例:%s图片说明写这%s或者写这显示%s',' <a href="http://xx.jpg" title="','"><img src="http://xxx.jpg" alt="','"/></a>'));
$form->addInput($capt);
$lang = new Typecho_Widget_Helper_Form_Element_Radio('lang',
array('en'=>_t('英文'),'cn'=>_t('中文')),'en',_t('提示语言'),'<p id="advanced" style="color:#467B96;font-weight:bold;">'._t('全功能版设置').' ———————————————————————————————————————</p>');
$form->addInput($lang);
$fullalign = new Typecho_Widget_Helper_Form_Element_Radio('fullalign',
array('default'=>_t('触发位置'),'center'=>_t('页面居中')),'default',_t('弹窗定位'));
$form->addInput($fullalign);
$fullopac = new Typecho_Widget_Helper_Form_Element_Text('fullopac',
NULL,'0.65',_t('背景遮罩'),_t('从透明至纯黑, 可填写0至1间的小数'));
$fullopac->input->setAttribute('class','mini');
$form->addInput($fullopac->addRule('isFloat',_t('请填写数字')));
$fullslide = new Typecho_Widget_Helper_Form_Element_Radio('fullslide',
array(1=>_t('开启'),0=>_t('关闭')),1,_t('幻灯面板'));
$form->addInput($fullslide);
$fullnextimg = new Typecho_Widget_Helper_Form_Element_Radio('fullnextimg',
array(1=>_t('是'),0=>_t('否')),0,_t('自动翻页'),_t('点击图片不关闭弹窗而是显示下一张'));
$form->addInput($fullnextimg);
$fullcpos = new Typecho_Widget_Helper_Form_Element_Radio('fullcpos',
array(''=>_t('不显示'),'caption'=>_t('底部显示'),'heading'=>_t('顶部显示')),'',_t('图片序数'));
$form->addInput($fullcpos);
$fullwrap = new Typecho_Widget_Helper_Form_Element_Checkbox('fullwrap',
array('draggable-header'=>_t('显示标题栏%s如: %s标题%s',' <span style="color:#999;font-size:0.92857em;">','<hs title="','"></span>'),'no-footer'=>_t('禁用拉伸')),NULL,_t('html弹窗'));
$form->addInput($fullwrap);
//输出面板效果
?>
<script type="text/javascript" src="<?php Helper::options()->adminUrl('js/jquery.js'); ?>"></script>
<script type="text/javascript">
$(function(){
var full = $('#mode-highslide-full-packed-js'),
adv = $('#advanced'),
opt = $('ul[id^="typecho-option-item-full"]');
$('#rpopt-link').prop('checked','true');
//全功能开关效果
if (!full.is(':checked')) disable();
full.click(function(){
adv.attr('style','color:#467B96;font-weight:bold;');
opt.removeAttr('style');
$('input',opt).removeAttr('disabled');
});
$('#mode-highslide-packed-js').click(function(){
disable();
});
function disable(){
$('#fullalign-default,#fullslide-1,#fullnextimg-0').attr('checked','true');
$('#fullopac-0-11').val('0.65');
adv.attr('style','color:#999;font-weight:bold;');
opt.attr('style','color:#999;');
$('input',opt).attr('disabled','true');
}
});
</script>
<?php
//相册设置隐藏域
$gallery = new Typecho_Widget_Helper_Form_Element_Hidden('gallery',
array('gallery-horizontal-strip','gallery-thumbstrip-above','gallery-vertical-strip','gallery-in-box','gallery-floating-thumbs','gallery-floating-caption','gallery-controls-in-heading','gallery-in-page'),'gallery-horizontal-strip');
$form->addInput($gallery);
$thumbfix = new Typecho_Widget_Helper_Form_Element_Hidden('thumbfix',
array('fixedwidth','fixedheight','fixedratio'),'fixedwidth');
$form->addInput($thumbfix);
$fixedwidth = new Typecho_Widget_Helper_Form_Element_Hidden('fixedwidth',NULL,'200');
$form->addInput($fixedwidth);
$fixedheight = new Typecho_Widget_Helper_Form_Element_Hidden('fixedheight',NULL,'100');
$form->addInput($fixedheight);
$fixedratio = new Typecho_Widget_Helper_Form_Element_Hidden('fixedratio',NULL,'4:3');
$form->addInput($fixedratio);
$thumbapi = new Typecho_Widget_Helper_Form_Element_Hidden('thumbapi',
array(0,1),0);
$form->addInput($thumbapi);
$storage = new Typecho_Widget_Helper_Form_Element_Hidden('storage',
array('local','qiniu','scs','nos','cos'),'local');
$form->addInput($storage);
$path = new Typecho_Widget_Helper_Form_Element_Hidden('path',NULL,'/usr/uploads/HSgallery/');
$form->addInput($path);
$cloudtoo = new Typecho_Widget_Helper_Form_Element_Hidden('cloudtoo',
array(0,1),0);
$form->addInput($cloudtoo);
$qiniubucket = new Typecho_Widget_Helper_Form_Element_Hidden('qiniubucket',NULL,'');
$form->addInput($qiniubucket);
$qiniudomain = new Typecho_Widget_Helper_Form_Element_Hidden('qiniudomain',NULL,'http://');
$form->addInput($qiniudomain);
$qiniuak = new Typecho_Widget_Helper_Form_Element_Hidden('qiniuak',NULL,'');
$form->addInput($qiniuak);
$qiniusk = new Typecho_Widget_Helper_Form_Element_Hidden('qiniusk',NULL,'');
$form->addInput($qiniusk);
$scsbucket = new Typecho_Widget_Helper_Form_Element_Hidden('scsbucket',NULL,'');
$form->addInput($scsbucket);
$scsdomain = new Typecho_Widget_Helper_Form_Element_Hidden('scsdomain',NULL,'http://');
$form->addInput($scsdomain);
$scsimgx = new Typecho_Widget_Helper_Form_Element_Hidden('scsimgx',NULL,'http://*.applinzi.com|*');
$form->addInput($scsimgx);
$scsak = new Typecho_Widget_Helper_Form_Element_Hidden('scsak',NULL,'');
$form->addInput($scsak);
$scssk = new Typecho_Widget_Helper_Form_Element_Hidden('scssk',NULL,'');
$form->addInput($scssk);
$nosbucket = new Typecho_Widget_Helper_Form_Element_Hidden('nosbucket',NULL,'');
$form->addInput($nosbucket);
$nosdomain = new Typecho_Widget_Helper_Form_Element_Hidden('nosdomain',NULL,'http://');
$form->addInput($nosdomain);
$nosak = new Typecho_Widget_Helper_Form_Element_Hidden('nosak',NULL,'');
$form->addInput($nosak);
$nosas = new Typecho_Widget_Helper_Form_Element_Hidden('nosas',NULL,'');
$form->addInput($nosas);
$nosep = new Typecho_Widget_Helper_Form_Element_Hidden('nosep',
array('nos-eastchina1.126.net'),'nos-eastchina1.126.net');
$form->addInput($nosep);
$cosbucket = new Typecho_Widget_Helper_Form_Element_Hidden('cosbucket',NULL,'');
$form->addInput($cosbucket);
$cosdomain = new Typecho_Widget_Helper_Form_Element_Hidden('cosdomain',NULL,'http://*.image.myqcloud.com');
$form->addInput($cosdomain);
$cosai = new Typecho_Widget_Helper_Form_Element_Hidden('cosai',NULL,'');
$form->addInput($cosai);
$cossi = new Typecho_Widget_Helper_Form_Element_Hidden('cossi',NULL,'');
$form->addInput($cossi);
$cossk = new Typecho_Widget_Helper_Form_Element_Hidden('cossk',NULL,'');
$form->addInput($cossk);
$cosrg = new Typecho_Widget_Helper_Form_Element_Hidden('cosrg',array('sh','gz','cd','tj','bj','sgp','hk','ca','ger'),'sh');
$form->addInput($cosrg);
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
/**
* 初始化数据表
*
* @access public
* @return string
* @throws Typecho_Plugin_Exception
*/
public static function galleryinstall()
{
$installdb = Typecho_Db::get();
$type = array_pop(explode('_',$installdb->getAdapterName()));
$prefix = $installdb->getPrefix();
$scripts = file_get_contents('usr/plugins/HighSlide/'.$type.'.sql');
$scripts = explode(';',str_replace('%charset%','utf8',str_replace('typecho_',$prefix,$scripts)));
try {
foreach ($scripts as $script) {
$script = trim($script);
if ($script) {
$installdb->query($script,Typecho_Db::WRITE);
}
}
return _t('建立页面相册数据表, 插件启用成功');
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if (('Mysql'==$type && ('42S01'==$code || 1050==$code)) ||
('SQLite'==$type && ('HY000'==$code || 1==$code))) {
try {
$script = 'SELECT `gid`,`name`,`thumb`,`sort`,`image`,`description`,`order` from `'.$prefix.'gallery`';
$installdb->query($script,Typecho_Db::READ);
return _t('检测到页面相册数据表, 插件启用成功');
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
throw new Typecho_Plugin_Exception(_t('数据表检测失败, 插件启用失败. 错误号: '.$code));
}
} else {
throw new Typecho_Plugin_Exception(_t('数据表建立失败, 插件启用失败. 错误号: '.$code));
}
}
}
/**
* 调取七牛许可
*
* @access public
* @param string $key,$secret
* @return Qiniu\Auth
*/
public static function qiniuset($key,$secret)
{
require_once('cloud/qiniu/autoload.php');
return new Qiniu\Auth($key,$secret);
}
/**
* 调取新浪云SCS许可
*
* @access public
* @param string $key,$secret
* @return SCS
*/
public static function scsset($key,$secret)
{
require_once('cloud/scs/SCS.php');
return new SCS($key,$secret);
}
/**
* 调取网易云NOS许可
*
* @access public
* @param string $key,$secret,$endpoint
* @return NOS\NosClient
*/
public static function nosset($key,$secret,$endpoint)
{
require_once('cloud/nos/autoload.php');
return new NOS\NosClient($key,$secret,$endpoint);
}
/**
* 调取腾讯云COS许可
*
* @access public
* @param string $region
* @return qcloudcos\Cosapi
*/
public static function cosset($region)
{
require_once('cloud/cos/include.php');
qcloudcos\Cosapi::setRegion($region);
return new qcloudcos\Cosapi();
}
/**
* 输出路由参数
*
* @access public
* @param string $url 原图地址
* @param boolean $isatt 是否来自附件
* @return Typecho_Config
*/
public static function route($url=NULL,$isatt=false)
{
$options = Helper::options();
$settings = $options->plugin('HighSlide');
$localsite = $options->siteUrl;
$qiniusite = $settings->qiniudomain;
$qiniusite = $qiniusite=='http://' ? '' : $qiniusite;
$scssite = $settings->scsdomain;
$scssite = $scssite && $scssite!=='http://' ? $scssite : 'http://'.$settings->scsbucket.'.cdn.sinacloud.net';
$nossite = $settings->nosdomain;
$nossite = $nossite=='http://' ? '' : $nossite;
$cossite = $settings->cosdomain;
$cossite = $cossite!=='http://*.image.myqcloud.com' && $cossite!=='http://' ? $cossite : '';
//获取路径前缀
$dname = '';
$durl = '';
if ($url) {
$source = parse_url($url);
$dname = dirname($url);
$durl = 0===strpos($dname,$localsite) ? $localsite : $source['scheme'].'://'.$source['host'];
}
//按储存来源获取地址
switch (true) {
case !$url && $settings->storage=='local' || 0===strpos($url,$localsite) :
$site = $localsite;
$from = 'local';
break;
case !$url && $settings->storage=='qiniu' || $qiniusite && 0===strpos($url,$qiniusite) :
$site = $qiniusite;
$from = 'qiniu';
break;
case !$url && $settings->storage=='scs' || 0===strpos($url,$scssite) :
if ($url) {
$dname = dirname(str_replace($scssite,'',$url)); //fix 子目录
}
$site = $scssite;
$from = 'scs';
break;
case !$url && $settings->storage=='nos' || $nossite && 0===strpos($url,$nossite) :
$site = $nossite;
$from = 'nos';
break;
case !$url && $settings->storage=='cos' || $cossite && 0===strpos($url,$cossite) :
$site = $cossite;
$from = 'cos';
break;
default :
$site = '';
$from = '';
}
$filedir = $isatt ? str_replace($durl,'',$dname.'/') : $settings->path;
$filedir = substr(Typecho_Common::url($filedir,''),1); //处理"/"号
$filedir = $filedir ? $filedir : '';
return new Typecho_Config(array(
'dir'=>$filedir,
'url'=>$url ? $url : Typecho_Common::url($filedir,$site),
'site'=>$site,
'from'=>$from //判断url来源
));
}
/**
* 构建相册表单
*
* @access public
* @param string $action,$render
* @return Typecho_Widget_Helper_Form
*/
public static function form($action=NULL,$render='g')
{
$options = Helper::options();
$settings = $options->plugin('HighSlide');
$security = Helper::security();
//图片编辑表单
$gform = new Typecho_Widget_Helper_Form($security->getIndex('/action/gallery-edit'),
Typecho_Widget_Helper_Form::POST_METHOD);
$image = new Typecho_Widget_Helper_Form_Element_Text('image',
NULL,NULL,_t('原图地址*'));
$gform->addInput($image);
$thumb = new Typecho_Widget_Helper_Form_Element_Text('thumb',
NULL,NULL,_t('缩略图地址*'));
$gform->addInput($thumb);
$name = new Typecho_Widget_Helper_Form_Element_Text('name',
NULL,NULL,_t('图片名称'));
$name->input->setAttribute('class','mini');
$gform->addInput($name);
$description = new Typecho_Widget_Helper_Form_Element_Textarea('description',
NULL,NULL,_t('图片描述'),_t('推荐填写, 用于展示相册中图片的文字说明效果'));
$gform->addInput($description);
$sort = new Typecho_Widget_Helper_Form_Element_Text('sort',
NULL,'1',_t('相册组*'),_t('输入数字, 对应标签[GALLERY-数字]在页面调用'));
$sort->input->setAttribute('class','w-10');
$gform->addInput($sort);
$do = new Typecho_Widget_Helper_Form_Element_Hidden('do');
$gform->addInput($do);
$gid = new Typecho_Widget_Helper_Form_Element_Hidden('gid');
$gform->addInput($gid);
$submit = new Typecho_Widget_Helper_Form_Element_Submit();
$submit->input->setAttribute('class','btn');
$gform->addItem($submit);
//相册设置表单
$sform = new Typecho_Widget_Helper_Form($security->getIndex('/action/gallery-edit?do=sync'),
Typecho_Widget_Helper_Form::POST_METHOD);
$gallery = new Typecho_Widget_Helper_Form_Element_Select('gallery',
array('gallery-horizontal-strip'=>_t('连环画册'),'gallery-thumbstrip-above'=>_t('黑色影夹'),'gallery-vertical-strip'=>_t('时光胶带'),'gallery-in-box'=>_t('纯白记忆'),'gallery-floating-thumbs'=>_t('往事片段'),'gallery-floating-caption'=>_t('沉默注脚'),'gallery-controls-in-heading'=>_t('岁月名片'),'gallery-in-page'=>_t('幻影橱窗(单相册)')),$settings->gallery,_t('相册风格'));
$sform->addInput($gallery);
$thumboptions = array(
'fixedwidth'=>_t('固定宽度 %s',' <input type="text" class="w-10 text-s mono" name="fixedwidth" value="'.$settings->fixedwidth.'"/>'),
'fixedheight'=>_t('固定高度 %s',' <input type="text" class="w-10 text-s mono" name="fixedheight" value="'.$settings->fixedheight.'"/>'),
'fixedratio'=>_t('固定比例 %s',' <input type="text" class="w-10 text-s mono" name="fixedratio" value="'.$settings->fixedratio.'"/>'),
);
$thumbfix = new Typecho_Widget_Helper_Form_Element_Radio('thumbfix',
$thumboptions,$settings->thumbfix,_t('缩略图规格'),_t('宽高单位px不用填写, 比例带“:”号, 同步影响正文附件缩略图'));
$sform->addInput($thumbfix->multiMode());
$thumbapi = new Typecho_Widget_Helper_Form_Element_Radio('thumbapi',
array(0=>_t('本地GD库渲染'),1=>_t('云端API演算')),$settings->thumbapi,_t('缩略图生成方式'),_t('API方式将按照原图url生成访问缓存, 不会占用额外储存空间'));
$sform->addInput($thumbapi);
$storage = new Typecho_Widget_Helper_Form_Element_Radio('storage',
array('local'=>_t('本地'),'qiniu'=>_t('<a href="https://portal.qiniu.com/signup?code=3lgwdq6pao2tu" target="_blank">七牛</a>'),'scs'=>_t('<a href="http://www.sinacloud.com/public/login/inviter/gaimrn-mddmzeKWrhKWnroB4fWt9rnlsf6K6dg.html" target="_blank">新浪云SCS</a>'),'nos'=>_t('<a href="https://www.163yun.com/nos/free" target="_blank">网易云NOS</a>'),'cos'=>_t('<a href="https://cloud.tencent.com/product/cos" target="_blank">腾讯云COS</a>')),$settings->storage,_t('储存位置%s','<div id="tooltip" style="display:none;"></div>'));
$storage->setAttribute('style','position:relative;font-size:98%'); //fix IE换行
$sform->addInput($storage);
$path = new Typecho_Widget_Helper_Form_Element_Text('path',
NULL,$settings->path,_t('路径前缀'),_t('“/”号结尾, 本地路径请确保可写, 云端前缀将忽略开头的“/”号'));
$sform->addInput($path);
$qiniubucket = new Typecho_Widget_Helper_Form_Element_Text('qiniubucket',
NULL,$settings->qiniubucket,_t('空间名称'));
$sform->addInput($qiniubucket);
$qiniudomain = new Typecho_Widget_Helper_Form_Element_Text('qiniudomain',
NULL,$settings->qiniudomain,_t('访问域名'));
$sform->addInput($qiniudomain);
$qiniuak = new Typecho_Widget_Helper_Form_Element_Text('qiniuak',
NULL,$settings->qiniuak,_t('AccessKey'));
$sform->addInput($qiniuak);
$qiniusk = new Typecho_Widget_Helper_Form_Element_Text('qiniusk',
NULL,$settings->qiniusk,_t('SecretKey'));
$sform->addInput($qiniusk);
$scsbucket = new Typecho_Widget_Helper_Form_Element_Text('scsbucket',
NULL,$settings->scsbucket,_t('Bucket名称'));
$sform->addInput($scsbucket);
$scsdomain = new Typecho_Widget_Helper_Form_Element_Text('scsdomain',
NULL,$settings->scsdomain,_t('绑定域名'),_t('未申请<a href="http://open.sinastorage.com/?c=console&a=parked_domain" target="_blank">域名绑定</a>留空即可'));
$sform->addInput($scsdomain);
$scsimgx = new Typecho_Widget_Helper_Form_Element_Text('scsimgx',
NULL,$settings->scsimgx,_t('图片处理服务 (新Imgxs)'),_t('填写<a href="https://imgxs.sinacloud.com" target="_blank">服务实例</a>域名和<a href="https://imgxs.sinacloud.com/#/detail/origin" target="_blank">源站标识</a>用|号隔开, 留空则使用原<a href="http://scs.sinacloud.com/doc/scs/imgx" target="_blank">imgx</a>免费子域名API'));
$sform->addInput($scsimgx);
$scsak = new Typecho_Widget_Helper_Form_Element_Text('scsak',
NULL,$settings->scsak,_t('Access Key'));
$sform->addInput($scsak);
$scssk = new Typecho_Widget_Helper_Form_Element_Text('scssk',
NULL,$settings->scssk,_t('Secret Key'));
$sform->addInput($scssk);
$nosbucket = new Typecho_Widget_Helper_Form_Element_Text('nosbucket',
NULL,$settings->nosbucket,_t('桶名称'));
$sform->addInput($nosbucket);
$nosdomain = new Typecho_Widget_Helper_Form_Element_Text('nosdomain',
NULL,$settings->nosdomain,_t('域名'));
$sform->addInput($nosdomain);
$nosak = new Typecho_Widget_Helper_Form_Element_Text('nosak',
NULL,$settings->nosak,_t('Access Key'));
$sform->addInput($nosak);
$nosas = new Typecho_Widget_Helper_Form_Element_Text('nosas',
NULL,$settings->nosas,_t('Access Secret'));
$sform->addInput($nosas);
$nosep = new Typecho_Widget_Helper_Form_Element_Radio('nosep',
array('nos-eastchina1.126.net'=>_t('华东1')),$settings->nosep, _t('数据中心'));
$sform->addInput($nosep);
$cosbucket = new Typecho_Widget_Helper_Form_Element_Text('cosbucket',
NULL,$settings->cosbucket,_t('Bucket名称'));
$sform->addInput($cosbucket);
$cosdomain = new Typecho_Widget_Helper_Form_Element_Text('cosdomain',
NULL,$settings->cosdomain,_t('访问域名'),_t('使用API方式生成缩略图须填写%s万象优图%s的图片处理/加速域名','<a href="https://console.qcloud.com/ci/bucket" target="_blank">','</a>'));
$sform->addInput($cosdomain);
$cosai = new Typecho_Widget_Helper_Form_Element_Text('cosai',
NULL,$settings->cosai,_t('APPID'),_t('可通过%s腾讯云控制台%s【账号信息】查看','<a href="https://console.cloud.tencent.com/developer" target="_blank">','</a>'));
$sform->addInput($cosai);
$cossi = new Typecho_Widget_Helper_Form_Element_Text('cossi',
NULL,$settings->cossi,_t('SecretId'));
$sform->addInput($cossi);
$cossk = new Typecho_Widget_Helper_Form_Element_Text('cossk',
NULL,$settings->cossk,_t('SecretKey'));
$sform->addInput($cossk);
$cosrg = new Typecho_Widget_Helper_Form_Element_Select('cosrg',
array('sh'=>_t('华东(上海)'),'gz'=>_t('华南(广州)'),'cd'=>_t('西南(成都)'),'tj'=>_t('华北(北京一区)'),'bj'=>_t('北京'),'sgp'=>_t('新加坡'),'hk'=>_t('香港'),'ca'=>_t('多伦多'),'ger'=>_t('法兰克福')),$settings->cosrg, _t('所属地区'));
$sform->addInput($cosrg);
$cloudtoo = new Typecho_Widget_Helper_Form_Element_Select('cloudtoo',
array(0=>_t('否'),1=>_t('是')),$settings->cloudtoo,_t('正文附件缩略图也使用该云储存'));
$cloudtoo->label->setAttribute('style','color:#999;font-weight:normal;font-size:.92857em;');
$cloudtoo->input->setAttribute('style','position:absolute;font-size:.92857em;height:24px;bottom:-2px;left:184px;');
$cloudtoo->setAttribute('style','position:relative');
$sform->addInput($cloudtoo);
$sform->addItem($submit);
$request = Typecho_Request::getInstance();
//修改图片模式
if (isset($request->gid) && $action!=='insert') {
$db = Typecho_Db::get();
$gallery = $db->fetchRow($db->select()->from('table.gallery')->where('gid = ?',$request->filter('int')->gid));
if (!$gallery) {
throw new Typecho_Widget_Exception(_t('修改图片不存在'));
}
$thumb->value($gallery['thumb']);
$image->value($gallery['image']);
$sort->value($gallery['sort']);
$name->value($gallery['name']);
$description->value($gallery['description']);
$do->value('update');
$gid->value($gallery['gid']);
$submit->value(_t('修改图片'));
$_action = 'update';
//保存设置模式
} elseif ($action=='sync' && $render=='s') {
$submit->value(_t('保存设置'));
$_action = 'sync';
//添加图片模式
} else {
$do->value('insert');
$submit->value(_t('添加图片'));
$_action = 'insert';
}
if (!$action) {
$action = $_action;
}
//验证表单规则
if ($action=='insert' || $action=='update') {
$thumb->addRule('required',_t('图片地址不能为空'));
$image->addRule('required',_t('图片地址不能为空'));
$sort->addRule('required',_t('相册组不能为空'));
$thumb->addRule('url',_t('请填写合法的图片地址'));
$image->addRule('url',_t('请填写合法的图片地址'));
$sort->addRule('isInteger',_t('请填写整数数字'));
}
return $render=='g' ? $gform : $sform;
}
/**
* 判断比例格式
*
* @access public
* @param string $ratio
* @return boolean
*/
public static function ratioformat($ratio)
{
return preg_match('/^\d*:\d*$/',$ratio);
}
/**
* 输出标签替换
*
* @access public
* @param string $content
* @return string
*/
public static function autohighslide($content,$widget,$lastResult)
{
$content = empty($lastResult) ? $content : $lastResult;
if ($widget instanceof Widget_Archive) {
$options = Helper::options();
$settings = $options->plugin('HighSlide');
$type = self::replacelist();
//判断替换范围
if ($widget->is(''.$type['index'].'') || $widget->is(''.$type['archive'].'') || $widget->is(''.$type['post'].'') || $widget->is(''.$type['page'].'')) {
$content = preg_replace('/<a(.*?)href=\"([^\s]+)\.(jpg|gif|png|bmp)\"(.*?)>(.*?)<\/a>/si'
,'<a$1href="$2.$3" class="highslide" onclick="return hs.expand(this,{slideshowGroup:\'images\'})"$4>$5</a>',$content);
//所有图片弹窗
if ($settings->rpopt) {
$content = preg_replace('/(<img[^>]+src\s*=\s*"?([^>"\s]+)"?[^>]*>)(?!<\/a>)/si'
,'<a href="$2" class="highslide" onclick="return hs.expand(this,{slideshowGroup:\'images\'})">$1</a>',$content);
}
//兼容旧版附件
if (strpos($content,'/attachment/')) {
$content = preg_replace_callback('/<a(.*?)href=\"([^\s]+)\/attachment\/(\d*)\/\"(.*?)>/i',array('HighSlide_Plugin','linkparse'),$content);
}
}
//相册标签替换
if ($settings->mode=='highslide-full.packed.js' && $widget->is('page')) {
$content = preg_replace_callback('/\[GALLERY([\-\d|,]*?)\]/i',array('HighSlide_Plugin','galleryparse'),$content);
}
$version = explode('/',$options->version);
$sign = '</hs>';
$pattern = '/<(hs)(.*?)>(.*?)<\/\\1>/si';
//markdown fix
if ($version['1']=='17.10.30' && $widget->isMarkdown && !stripos($content,'</hs>')) {
$sign = '</hs>';
$pattern = '/<(hs)(.*?)>(.*?)<\/\\1>/si';
}
//html标签替换
if ($settings->mode=='highslide-full.packed.js' && false!==stripos($content,$sign)) {
$content = preg_replace_callback($pattern,array('HighSlide_Plugin','htmlparse'),$content);
}
}
return $content;
}
/**
* 输出范围参数
*
* @access private
* @return array
*/
private static function replacelist()
{
$rplist = Helper::options()->plugin('HighSlide')->rplist;
$rplists = array('index'=>'','archive'=>'','post'=>'','page'=>'');
if ($rplist) {
foreach ($rplist as $key=>$val) {
$key = $val;
$rplists[$key] = $val;
}
}
return $rplists;
}
/**
* 页面相册解析
*
* @access public
* @param array $match
* @return string
*/
public static function galleryparse($match)
{
$output = '<span style="font-weight:bold;color:#467B96;">'._t('相册数据为空').'</span>';
$sort = self::defaultsort();
if ($sort) {
$settings = Helper::options()->plugin('HighSlide');
$db = Typecho_Db::get();
$gallerys = array();
$coversets = array();
$cover = '';
$body = '';
//记录相册组ID
$param = substr(trim($match['1']),1);
$param = $param ? $param : $sort;
static $count = 0;
++$count;
self::$ids[] = $param;
$sorts = array_filter(explode(',',$param));
foreach ($sorts as $sort) {
$gallerys = $db->fetchAll($db->select()->from('table.gallery')->where('sort = ?',''.$sort.'')->order('table.gallery.order',Typecho_Db::SORT_ASC));
if ($gallerys) {
//输出封面部分
$coversets = array(array_shift($gallerys));
foreach ($coversets as $coverset) {
switch ($settings->gallery) {
case 'gallery-in-page' :
$cover .= '<a id="thumb'.$sort.'" class="highslide" href="'.$coverset['image'].'" title="'.$coverset['description'].'" onclick="return hs.expand(this,inPageOptions)"><img src="'.$coverset['thumb'].'" alt="'.$coverset['description'].'"/></a> ';
break;
case 'gallery-controls-in-heading' :
$cover .= '<a id="thumb'.$sort.'" class="highslide" href="'.$coverset['image'].'" title="'.$coverset['description'].'" onclick="return hs.expand(this,{slideshowGroup:\'group'.$sort.'\'})"><img src="'.$coverset['thumb'].'" alt="'.$coverset['description'].'"/></a><div class="highslide-heading">'.$coverset['description'].'</div> ';
break;
case 'gallery-in-box' :
$cover .= '<a id="thumb'.$sort.'" class="highslide" href="'.$coverset['image'].'" title="'.$coverset['description'].'" onclick="return hs.expand(this,{slideshowGroup:\'group'.$sort.'\'})"><img src="'.$coverset['thumb'].'" alt="'.$coverset['description'].'"/></a><div class="highslide-caption">'.$coverset['description'].'</div> ';
break;
default :
$cover .= '<a id="thumb'.$sort.'" class="highslide" href="'.$coverset['image'].'" title="'.$coverset['description'].'" onclick="return hs.expand(this,{slideshowGroup:\'group'.$sort.'\'})"><img src="'.$coverset['thumb'].'" alt="'.$coverset['description'].'"/></a> ';
}
}
//输出列表部分
foreach ($gallerys as $gallery) {
switch ($settings->gallery) {
case 'gallery-in-page' :
$body .= '<a class="highslide" href="'.$gallery['image'].'" title="'.$gallery['description'].'" onclick="return hs.expand(this,inPageOptions)"><img src="'.$gallery['thumb'].'" alt="'.$gallery['description'].'"/></a>';
break;
case 'gallery-controls-in-heading' :
$body .= '<a class="highslide" href="'.$gallery['image'].'" title="'.$gallery['description'].'" onclick="return hs.expand(this,{slideshowGroup:\'group'.$sort.'\'})"><img src="'.$gallery['thumb'].'" alt="'.$gallery['description'].'"/></a><div class="highslide-heading">'.$gallery['description'].'</div>';
break;
case 'gallery-in-box' :
$body .= '<a class="highslide" href="'.$gallery['image'].'" title="'.$gallery['description'].'" onclick="return hs.expand(this,{slideshowGroup:\'group'.$sort.'\'})"><img src="'.$gallery['thumb'].'" alt="'.$gallery['description'].'"/></a><div class="highslide-caption">'.$gallery['description'].'</div>';
break;
default :
$body .= '<a class="highslide" href="'.$gallery['image'].'" title="'.$gallery['description'].'" onclick="return hs.expand(this,{slideshowGroup:\'group'.$sort.'\'})"><img src="'.$gallery['thumb'].'" alt="'.$gallery['description'].'"/></a>';
}
}
}
}
$output = $settings->gallery=='gallery-in-page'
? '<div id="gallery-area" style="width:620px;height:520px;margin:0 auto;border:1px solid silver;"><div class="hidden-container">'.$cover.$body.'</div></div>'
: '<div class="highslide-gallery">'.$cover.'<div class="hidden-container">'.$body.'</div></div>';
}
return $output;
}
/**
* 缺省相册分类
*
* @access public
* @return string
*/
public static function defaultsort()
{
$db = Typecho_Db::get();
$default = $db->fetchRow($db->select('sort')->from('table.gallery')->order('sort',Typecho_Db::SORT_ASC));
return $default ? $default['sort'] : '';
}
/**
* html弹窗解析
*
* @access public
* @param array $match
* @return string
*/
public static function htmlparse($match)
{
$settings = Helper::options()->plugin('HighSlide');
$fullwrap = $settings->fullwrap;
//准备默认设置
$id = 'highslide-html';
$text = 'text';
$title = '';
$href = '#';
$width = '';
$height = '';
$Movetext = 'Move';
$Movetitle = 'Move';
$Closetext = 'Close';
$Closetitle = 'Close (esc)';
$Resizetitle = 'Resize';
if ($settings->lang=='cn') {
$Movetext = '移动';
$Movetitle = '移动';
$Closetext = '关闭';
$Closetitle = '关闭 (esc)';
$Resizetitle = '拉伸';
}
$param = htmlspecialchars_decode(trim($match['2'])); //markdown fix
//解析标签参数
if ($param) {
if (preg_match('/id=["\']([\w-]*)["\']/i',$param,$out)) {
$id = trim($out[1]) ? trim($out[1]) : $id;
}
if (preg_match('/text=["\'](.*?)["\']/si',$param,$out)) {
$text = trim($out[1]) ? trim($out[1]) : $text;
}
if (preg_match('/title=["\'](.*?)["\']/si',$param,$out)) {
$title = trim($out[1]) ? trim($out[1]) : $title;
}
if (preg_match('/ajax=["\'](.*?)["\']/i',$param,$out)) {
$href = trim($out[1]) ? trim($out[1]) : $href;
}
if (preg_match('/width=["\']([\w-]*)["\']/i',$param,$out)) {
$width = trim($out[1]) ? ',width:'.strtr(trim($out[1]),'px','') : $width;
}
if (preg_match('/height=["\']([\w-]*)["\']/i',$param,$out)) {
$height = trim($out[1]) ? ',height:'.strtr(trim($out[1]),'px','') : $height;
}
}
$output = '<a href="'.$href.'" onclick="return hs.htmlExpand(this,{';
$output .= $href=='#' ? 'contentId:\''.$id.'\'' : 'objectType:\'ajax\''; //ajax判断
$output .= in_array('draggable-header',($fullwrap ? $fullwrap : array())) && $title ? ',headingText:\''.$title.'\'' : ''; //标题栏显示
$output .= $width.$height.'})" class="highslide">'.$text.'</a>';
$output .= '<div class="highslide-html-content" id="'.$id.'"><div class="highslide-header"><ul><li class="highslide-move"><a href="#" onclick="return false" title="'.$Movetitle.'"><span>'.$Movetext.'</span></a></li>';
$output .= '<li class="highslide-close"><a href="#" onclick="return hs.close(this)" title="'.$Closetitle.'"><span>'.$Closetext.'</span></a></li></ul></div>';
$output .= '<div class="highslide-body">'.trim($match['3']).'</div><div class="highslide-footer"><div><span class="highslide-resize" title="'.$Resizetitle.'"><span></span></span></div></div></div>
';
return $output;
}
/**
* 附件链接解析
*
* @access public
* @param array $match
* @return string
*/
public static function linkparse($match)
{
$db = Typecho_Db::get();
$cid = $match['3'];
$attach = $db->fetchRow($db->select()->from('table.contents')->where('type = ?','attachment')->where('cid = ?',$cid));
if ($attach) {
$text = unserialize($attach['text']);
$output = '<a'.$match['1'].'href="'.Typecho_Common::url($text['path'],Helper::options()->siteUrl).'" class="highslide" onclick="return hs.expand(this,{slideshowGroup:\'images\'})"'.$match['4'].'>';
return $output;
}
}
/**
* 内文附件脚本
*
* @access public
* @return void
*/
public static function attachpanel()
{
$options = Helper::options();
$settings = $options->plugin('HighSlide');
$security = Helper::security();
$request = Typecho_Request::getInstance();
$cid = !empty($request->cid) ? '?cid='.$request->filter('int')->cid : '';
?>
<link rel="stylesheet" type="text/css" media="all" href="<?php $options->pluginUrl('HighSlide/css/imgareaselect-animated.css'); ?>"/>
<script src="<?php $options->pluginUrl('HighSlide/js/imgareaselect.js'); ?>"></script>
<script type="text/javascript">
$(function(){
<?php
//输出编辑器按钮
if ($settings->mode=='highslide-full.packed.js') {
?>
var wmd = $('#wmd-image-button');
if (wmd.length>0) {
wmd.after(
'<li class="wmd-button" id="wmd-hs-button" style="padding-top:5px;" title="<?php _e("插入Html弹窗"); ?>"><img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2214%22%20height%3D%2214%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20fill%3D%22%23999%22%20d%3D%22M17%2016h-4v8h-2v-8h-4l5-6%205%206zm7%208h-9v-2h7v-16h-20v16h7v2h-9v-24h24v24z%22%2F%3E%3C%2Fsvg%3E"/></li>');
} else {
$('.url-slug').after('<button type="button" id="wmd-hs-button" class="btn btn-xs" style="margin-right:5px;"><?php _e("插入Html弹窗"); ?></button>');
}
$('#wmd-hs-button').click(function(){
$('body').append('<div id="hsanel">' +
'<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("插入Html弹窗"); ?></b></p>' +
'<p><?php _e("请在下方的输入框内输入要实现弹窗效果的链接与内容"); ?></p></div>' +
'<form><input type="text"></input><button type="button" class="btn btn-s primary" id="ok"><?php _e("确定"); ?></button>' +
'<button type="button" class="btn btn-s" id="cancel"><?php _e("取消"); ?></button></form>' +
'</div></div>');
var hslog = $('.wmd-prompt-dialog input'),
textarea = $('#text');
hslog.val('<hs text="链接文字">弹窗内容</hs>').select();
$('#cancel').click(function(){
$('#hsanel').remove();
textarea.focus();
});
$('#ok').click(function(){
var hsinput = hslog.val(),
sel = textarea.getSelection(),
offset = (sel ? sel.start : 0)+hsinput.length;
textarea.replaceSelection(hsinput);
textarea.setSelection(offset,offset);
$('#hsanel').remove();
});
});
<?php
}
?>
var list = $('#file-list');
list.before('<button type="button" id="loadattach" class="btn btn-xs"><?php _e('缩略图模式'); ?> <i class="i-caret-right"></i></button>');
list.after('<ul id="image-list" style="list-style:none;margin:0px 10px;padding:0px;max-height:800px;overflow:auto;display:none;"></ul>');
//点击切换模式
$('#loadattach').click(function(){
var it = $('i',$(this)),
button = it.parent(),
pre = $('#image-list');
if (it.attr('class')=='i-caret-left') {
button.html('<?php _e('缩略图模式'); ?> <i class="i-caret-right">');
} else {
button.html('<?php _e('普通模式'); ?> <i class="i-caret-left">');
}
$('img[id^="image-"]').imgAreaSelect({remove:true});
//上传切回普通
$('.upload-file').click(function(){
button.html('<?php _e('缩略图模式'); ?> <i class="i-caret-right">');
$('img[id^="image-"]').imgAreaSelect({remove:true});
pre.hide();
list.show();
});
pre.html('<li class="loading"><?php _e('图片预览加载中...'); ?></li>');
$.post('<?php $security->index('/action/gallery-edit'.$cid); ?>',
{'do':'preview'},
function(data){
list.empty();
pre.empty();
var val = $.parseJSON(data);
for (var i=0;i<val.length;i++) {
//其他附件显示
var cid = val[i].cid,
isimg = val[i].isimg,
url = val[i].url,
title = val[i].title,
size = val[i].size,
fli = $('<li data-cid="'+cid+'">').attr('data-url',val[i].url).attr('data-image',isimg)
.html('<input type="hidden" name="attachment[]" value="'+cid+'"/>'
+'<a class="insert" title="<?php _e('点击插入文件'); ?>" href="###">'+title+'</a><div class="info">'+size
+'<a class="file" target="_blank" href="<?php $options->adminUrl('media.php?cid='); ?>'+cid+'" title="<?php _e('编辑'); ?>"><i class="i-edit"></i></a>'
+'<a href="###" class="delete" title="<?php _e('删除'); ?>"><i class="i-delete"></i></a></div>')
.appendTo(list);
attachInsertEvent(fli);
attachDeleteEvent(fli);
//图片附件显示
if (isimg) {
var name = val[i].name,
t = title.indexOf('thumb_'), //判断缩略图
aurl = val[i].aurl,
hash = '?r='+Math.floor(Math.random()*200),
turl = val[i].turl,
li = $('<li data-url="'+(aurl ? turl : url)+'">').attr('style','padding:8px 0px;border-top:1px dashed #D9D9D6;')
.attr('data-turl',turl).data('cid',cid).data('name',name).data('title',title).data('url',url).data('aurl',aurl)
.html((t==0 ? '<img src="'+(aurl ? aurl : url+hash)+'" alt="'+title+'" style="max-width:50%;"/>'
: '<input type="hidden" name="imgname" value="'+name+'"/>'
+'<img id="image-'+cid+'" src="'+url+hash+'" alt="'+name+'" style="max-width:100%;"/>'
+'<input type="hidden" name="x1" value="" id="x1"/>'
+'<input type="hidden" name="y1" value="" id="y1"/>'
+'<input type="hidden" name="x2" value="" id="x2"/>'
+'<input type="hidden" name="y2" value="" id="y2"/>'
+'<input type="hidden" name="w" value="" id="w"/>'
+'<input type="hidden" name="h" value="" id="h"/>')
+'<div class="info">'+size
+ (t==0 ? ' <a class="addto" href="###" title="<?php _e('插入图链'); ?>"><i class="mime-image"></i></a>'
: ' <a class="crop" href="###" title="<?php _e('截取缩略图'); ?>"><i class="mime-application"></i></a>')
+'</div>')
.appendTo(pre),
ti = li.siblings('li[data-turl="'+turl+'"]');
if (t==0) li.insertAfter(ti); //关联位置
iasEffectEvent(li);
thumbCropEvent(li);
imageAddtoEvent(li);
}
}