forked from Moidea/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.php
1960 lines (1771 loc) · 62.1 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双核版实现自动化弹窗与页面相册功能.
* @category image
* @package HighSlide
* @author 羽中
* @version 1.4.6-rc
* @dependence 14.3.14-*
* @link http://www.jzwalk.com/archives/net/highslide-for-typecho
*/
class HighSlide_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return string
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
$info = HighSlide_Plugin::galleryinstall();
Helper::addPanel(3,'HighSlide/manage-gallery.php',_t('页面相册'),_t('配置页面相册 <span style="color:#999;">(HighSlide全功能版核心支持)</span>'),'administrator');
Helper::addAction('gallery-edit','HighSlide_Action');
Typecho_Plugin::factory('Widget_Archive')->header = array('HighSlide_Plugin','headlink');
Typecho_Plugin::factory('Widget_Archive')->footer = array('HighSlide_Plugin','footlink');
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('admin/write-post.php')->bottom = array('HighSlide_Plugin','jshelper');
Typecho_Plugin::factory('admin/write-page.php')->bottom = array('HighSlide_Plugin','jshelper');
Typecho_Plugin::factory('admin/write-post.php')->option = array('HighSlide_Plugin','uploadpanel');
return _t($info);
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate()
{
Helper::removeAction('gallery-edit');
Helper::removePanel(3,'HighSlide/manage-gallery.php');
}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
?>
<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'),
basic = $('#mode-highslide-packed-js'),
adv = $('.advanced'),
option = $('#typecho-option-item-align-9,#typecho-option-item-opac-10,#typecho-option-item-slide-11,#typecho-option-item-nextimg-12,#typecho-option-item-cpos-13,#typecho-option-item-wrap-14'),
input = option.find('input,select');
if(!full.is(':checked')) {
adv.attr('style','color:#999;font-weight:bold');
option.attr('style','color:#999');
}
full.click(function() {
adv.attr('style','color:#467B96;font-weight:bold');
option.removeAttr('style');
});
basic.click(function() {
adv.attr('style','color:#999;font-weight:bold');
option.attr('style','color:#999');
});
});
</script>
<?php
$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);
$rpmode = new Typecho_Widget_Helper_Form_Element_Radio('rpmode',
array('ahref'=>_t('链接图片'),'imgsrc'=>_t('所有图片')),'ahref',_t('应用模式'),NULL);
$form->addInput($rpmode);
$rplist = new Typecho_Widget_Helper_Form_Element_Checkbox('rplist',
array('index'=>_t('首页'),'post'=>_t('文章页'),'page'=>_t('独立页'),'archive'=>_t('索引页')),array('index','post','page','archive'),_t('应用范围'),NULL);
$form->addInput($rplist);
$lang = new Typecho_Widget_Helper_Form_Element_Radio('lang',
array('chs'=>_t('中文'),'eng'=>_t('英文')),'chs',_t('提示语言'));
$form->addInput($lang);
$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);
$butn = new Typecho_Widget_Helper_Form_Element_Radio('butn',
array('false'=>_t('不显示'),'true'=>_t('显示')),'false',_t('关闭按钮'));
$form->addInput($butn);
$ltext = new Typecho_Widget_Helper_Form_Element_Text('ltext',
NULL,'© '.$_SERVER['HTTP_HOST'].'',_t('角标文字'),_t('弹窗logo文字与显示位置,留空则不显示'));
$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->removeAttribute('class','typecho-label');
$lpos->input->setAttribute('style','position:absolute;bottom:42px;left:165px;');
$lpos->setAttribute('style','list-style:none;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('例: <a href="http://xx.jpg" title="图片说明写这"><img src="http://xxx.jpg" alt="或者写这显示"/></a><p class="advanced" style="color:#467B96;font-weight:bold;">全功能版设置 ———————————————————————————————————————</p>'));
$form->addInput($capt);
$align = new Typecho_Widget_Helper_Form_Element_Radio('align',
array('default'=>_t('默认'),'center'=>_t('居中')),'default',_t('弹窗位置'));
$form->addInput($align);
$opac = new Typecho_Widget_Helper_Form_Element_Text('opac',
NULL,'0.65',_t('背景遮罩'),_t('可填入0~1之间小数, 代表透明至纯黑'));
$opac->input->setAttribute('class','mini');
$form->addInput($opac->addRule('isFloat',_t('请填写数字')));
$slide = new Typecho_Widget_Helper_Form_Element_Radio('slide',
array('false'=>_t('关闭'),'true'=>_t('开启')),'true',_t('幻灯按钮'));
$form->addInput($slide);
$nextimg = new Typecho_Widget_Helper_Form_Element_Radio('nextimg',
array('false'=>_t('否'),'true'=>_t('是')),'false',_t('自动翻页'),_t('开启后点击图片为显示下一张'));
$form->addInput($nextimg);
$cpos = new Typecho_Widget_Helper_Form_Element_Radio('cpos',
array(''=>_t('不显示'),'caption'=>_t('底部显示'),'heading'=>_t('顶部显示')),'',_t('图片序数'));
$form->addInput($cpos);
$wrap = new Typecho_Widget_Helper_Form_Element_Checkbox('wrap',
array('draggable-header'=>_t('标题栏 <span style="color:#999;font-size:0.92857em;">支持<hs title="标题">显示</span>'),'no-footer'=>_t('无拉伸')),NULL,_t('html弹窗效果'));
$form->addInput($wrap);
//相册设置隐藏域
$storage = new Typecho_Widget_Helper_Form_Element_Hidden('storage',
array('local','qiniu','upyun','bcs'),'local');
$form->addInput($storage);
$local = new Typecho_Widget_Helper_Form_Element_Hidden('local',NULL,'/usr/uploads/HSgallery/');
$form->addInput($local);
$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);
$qiniuaccesskey = new Typecho_Widget_Helper_Form_Element_Hidden('qiniuaccesskey',NULL,'');
$form->addInput($qiniuaccesskey);
$qiniusecretkey = new Typecho_Widget_Helper_Form_Element_Hidden('qiniusecretkey',NULL,'');
$form->addInput($qiniusecretkey);
$qiniuprefix = new Typecho_Widget_Helper_Form_Element_Hidden('qiniuprefix',NULL,'usr/uploads/HSgallery/');
$form->addInput($qiniuprefix);
$upyunbucket = new Typecho_Widget_Helper_Form_Element_Hidden('upyunbucket',NULL,'');
$form->addInput($upyunbucket);
$upyundomain = new Typecho_Widget_Helper_Form_Element_Hidden('upyundomain',NULL,'http://');
$form->addInput($upyundomain);
$upyunuser = new Typecho_Widget_Helper_Form_Element_Hidden('upyunuser',NULL,'');
$form->addInput($upyunuser);
$upyunpwd = new Typecho_Widget_Helper_Form_Element_Hidden('upyunpwd',NULL,'');
$form->addInput($upyunpwd);
$upyunkey = new Typecho_Widget_Helper_Form_Element_Hidden('upyunkey',NULL,'');
$form->addInput($upyunkey);
$upyunprefix = new Typecho_Widget_Helper_Form_Element_Hidden('upyunprefix',NULL,'/usr/uploads/HSgallery/');
$form->addInput($upyunprefix);
$bcsbucket = new Typecho_Widget_Helper_Form_Element_Hidden('bcsbucket',NULL,'');
$form->addInput($bcsbucket);
$bcsapikey = new Typecho_Widget_Helper_Form_Element_Hidden('bcsapikey',NULL,'');
$form->addInput($bcsapikey);
$bcssecretkey = new Typecho_Widget_Helper_Form_Element_Hidden('bcssecretkey',NULL,'');
$form->addInput($bcssecretkey);
$bcsprefix = new Typecho_Widget_Helper_Form_Element_Hidden('bcsprefix',NULL,'/usr/uploads/HSgallery/');
$form->addInput($bcsprefix);
$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,'100');
$form->addInput($fixedwidth);
$fixedheight = new Typecho_Widget_Helper_Form_Element_Hidden('fixedheight',NULL,'200');
$form->addInput($fixedheight);
$fixedratio = new Typecho_Widget_Helper_Form_Element_Hidden('fixedratio',NULL,'4:3');
$form->addInput($fixedratio);
$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);
}
/**
* 个人用户的配置面板
*
* @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 = explode('_',$installdb->getAdapterName());
$type = array_pop($type);
$prefix = $installdb->getPrefix();
$scripts = file_get_contents('usr/plugins/HighSlide/'.$type.'.sql');
$scripts = str_replace('typecho_',$prefix,$scripts);
$scripts = str_replace('%charset%','utf8',$scripts);
$scripts = explode(';',$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&&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
* @return void
*/
public static function qiniuset($accesskey,$secretkey)
{
require_once("cloud/qiniu/io.php");
require_once("cloud/qiniu/rs.php");
require_once("cloud/qiniu/rsf.php");
Qiniu_setKeys($accesskey,$secretkey);
}
/**
* 调取又拍云许可
*
* @access public
* @return void
*/
public static function upyunset()
{
$settings = Helper::options()->plugin('HighSlide');
require_once("cloud/upyun/upyun.class.php");
return new UpYun($settings->upyunbucket,$settings->upyunuser,$settings->upyunpwd);
}
/**
* 调取百度BCS许可
*
* @access public
* @return void
*/
public static function bcsset()
{
$settings = Helper::options()->plugin('HighSlide');
require_once("cloud/bcs/bcs.class.php");
return new BaiduBCS($settings->bcsapikey,$settings->bcssecretkey,'bcs.duapp.com');
}
/**
* 输出文件前缀
*
* @access public
* @param string $path 附件源路径
* @param string $url 附件源地址
* @return Typecho_Config
*/
public static function filedata($path = NULL,$url = NULL)
{
$options = Helper::options();
$settings = $options->plugin('HighSlide');
//判断本地附件源
if (strpos($url,$options->siteUrl)===false) {
if ($settings->storage=='local') {
$prefix = ($path)?$path:$settings->local;
$fileurl = Typecho_Common::url($prefix,$options->siteUrl);
$filedir = Typecho_Common::url($prefix,__TYPECHO_ROOT_DIR__);
}
if ($settings->storage=='qiniu') {
$prefix = ($path)?$path:$settings->qiniuprefix;
$fileurl = Typecho_Common::url($prefix,$settings->qiniudomain);
$filedir = ($path)?substr($path,1):$settings->qiniuprefix;
}
if ($settings->storage=='upyun') {
$prefix = ($path)?$path:$settings->upyunprefix;
$fileurl = Typecho_Common::url($prefix,$settings->upyundomain);
$filedir = Typecho_Common::url($prefix,'');
}
if ($settings->storage=='bcs') {
$prefix = ($path)?$path:$settings->bcsprefix;
$fileurl = Typecho_Common::url($prefix,'http://bcs.duapp.com');
$filedir = Typecho_Common::url($prefix,'');
}
} else {
$fileurl = Typecho_Common::url($path,$options->siteUrl);
$filedir = Typecho_Common::url($path,__TYPECHO_ROOT_DIR__);
}
return new Typecho_Config(array('url'=>$fileurl,'dir'=>$filedir));
}
/**
* 输出上传列表
*
* @access public
* @return void
*/
public static function filelist()
{
$settings = Helper::options()->plugin('HighSlide');
$db = Typecho_Db::get();
$filedata = self::filedata();
$fileurl = $filedata->url;
$filedir = $filedata->dir;
//获取对比数据
$urls = $db->fetchAll($db->select('image','thumb')->from('table.gallery'));
$images = array();
$thumbs = array();
foreach ($urls as $url) {
$images[] = $url['image'];
$thumbs[] = $url['thumb'];
}
//获取本地列表
if ($settings->storage=='local') {
$lists = glob($filedir.'*[0-9].{gif,jpg,jpeg,png,tiff,bmp,GIF,JPG,JPEG,PNG,TIFF,BMP}',GLOB_BRACE|GLOB_NOSORT);
foreach ($lists as $list) {
$datas[] = array('key'=>$list,'fsize'=>filesize($list));
}
}
//获取七牛列表
if ($settings->storage=='qiniu') {
self::qiniuset($settings->qiniuaccesskey,$settings->qiniusecretkey);
$client = new Qiniu_MacHttpClient(null);
list($result,$error) = Qiniu_RSF_ListPrefix($client,$settings->qiniubucket,$filedir);
if ($error==null) {
$datas = $result;
}
}
//获取又拍云列表
if ($settings->storage=='upyun') {
$upyun = self::upyunset();
$lists = $upyun->getList($filedir);
foreach ($lists as $list) {
$datas[] = array('key'=>$list['name'],'fsize'=>$list['size']);
}
}
//获取百度BCS列表
if ($settings->storage=='bcs') {
$bcs = self::bcsset();
$result = $bcs->list_object($settings->bcsbucket,array('prefix'=>$filedir));
if ($result->isOK()) {
$decode = json_decode($result->body,true);
$lists = $decode['object_list'];
foreach ($lists as $list) {
$datas[] = array('key'=>$list['object'],'fsize'=>$list['size']);
}
}
}
//重构处理排序
if (!empty($datas)) {
foreach ($datas as $data) {
$name = basename($data['key']);
$keyname = (strpos($data['key'],'thumb_'))?substr($name,6,5)+1:substr($name,0,5);
$files[''.$keyname.''] = $data;
}
}
if(empty($files)) {
return false;
}
ksort($files);
$filelist = array();
$id=0;
foreach ($files as $file) {
$filename = basename($file['key']);
$filesize = number_format(ceil($file['fsize']/1024));
//过滤输出结果
if (!in_array($fileurl.$filename,$images)&&!in_array($fileurl.$filename,$thumbs)) {
$filelist[] = array('id'=>$id++,'name'=>$filename,'size'=>$filesize);
}
}
return $filelist;
}
/**
* 构建相册表单
*
* @access public
* @param string $action,$render
* @return Typecho_Widget_Helper_Form
*/
public static function form($action = NULL,$render = '1')
{
$options = Helper::options();
$settings = $options->plugin('HighSlide');
//图片编辑表单
$form1 = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/gallery-edit',$options->index),
Typecho_Widget_Helper_Form::POST_METHOD);
$image = new Typecho_Widget_Helper_Form_Element_Text('image',
NULL,"http://",_t('原图地址*'));
$form1->addInput($image);
$thumb = new Typecho_Widget_Helper_Form_Element_Text('thumb',
NULL,"http://",_t('缩略图地址*'));
$form1->addInput($thumb);
$name = new Typecho_Widget_Helper_Form_Element_Text('name',
NULL,NULL,_t('图片名称'));
$name->input->setAttribute('class','mini');
$form1->addInput($name);
$description = new Typecho_Widget_Helper_Form_Element_Textarea('description',
NULL,NULL,_t('图片描述'),_t('推荐填写, 用于展示相册中图片的文字说明效果'));
$form1->addInput($description);
$sort = new Typecho_Widget_Helper_Form_Element_Text('sort',
NULL,"1",_t('相册组*'),_t('输入数字, 对应写入[GALLERY-数字]在页面调用'));
$sort->input->setAttribute('class','w-10');
$form1->addInput($sort);
$do = new Typecho_Widget_Helper_Form_Element_Hidden('do');
$form1->addInput($do);
$gid = new Typecho_Widget_Helper_Form_Element_Hidden('gid');
$form1->addInput($gid);
$submit = new Typecho_Widget_Helper_Form_Element_Submit();
$submit->input->setAttribute('class','btn');
$form1->addItem($submit);
//相册设置表单
$form2 = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/gallery-edit?do=sync',$options->index),
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('相册风格'),_t('套装效果, 不受插件通用设置影响'));
$form2->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(无需填写), 比例注意使用半角冒号'));
$form2->addInput($thumbfix->multiMode());
$storage = new Typecho_Widget_Helper_Form_Element_Radio('storage',
array('local'=>_t('本地'),'qiniu'=>_t('七牛'),'upyun'=>_t('又拍云'),'bcs'=>_t('百度BCS')),$settings->storage,_t('储存位置'));
$form2->addInput($storage);
$local = new Typecho_Widget_Helper_Form_Element_Text('local',
NULL,$settings->local,_t('本地路径'),_t('确保首层目录可写, 结尾带/号'));
$form2->addInput($local);
$qiniubucket = new Typecho_Widget_Helper_Form_Element_Text('qiniubucket',
NULL,$settings->qiniubucket,_t('空间名称'));
$form2->addInput($qiniubucket);
$qiniudomain = new Typecho_Widget_Helper_Form_Element_Text('qiniudomain',
NULL,$settings->qiniudomain,_t('空间域名'));
$form2->addInput($qiniudomain);
$qiniuaccesskey = new Typecho_Widget_Helper_Form_Element_Text('qiniuaccesskey',
NULL,$settings->qiniuaccesskey,_t('AccessKey'));
$form2->addInput($qiniuaccesskey);
$qiniusecretkey = new Typecho_Widget_Helper_Form_Element_Text('qiniusecretkey',
NULL,$settings->qiniusecretkey,_t('SecretKey'));
$form2->addInput($qiniusecretkey);
$qiniuprefix = new Typecho_Widget_Helper_Form_Element_Text('qiniuprefix',
NULL,$settings->qiniuprefix,_t('路径前缀'),_t('注意开头不要加/号'));
$form2->addInput($qiniuprefix);
$upyunbucket = new Typecho_Widget_Helper_Form_Element_Text('upyunbucket',
NULL,$settings->upyunbucket,_t('空间名称'));
$form2->addInput($upyunbucket);
$upyundomain = new Typecho_Widget_Helper_Form_Element_Text('upyundomain',
NULL,$settings->upyundomain,_t('绑定域名'));
$form2->addInput($upyundomain);
$upyunuser = new Typecho_Widget_Helper_Form_Element_Text('upyunuser',
NULL,$settings->upyunuser,_t('操作员'));
$form2->addInput($upyunuser);
$upyunpwd = new Typecho_Widget_Helper_Form_Element_Text('upyunpwd',
NULL,$settings->upyunpwd,_t('密码'));
$form2->addInput($upyunpwd);
$upyunkey = new Typecho_Widget_Helper_Form_Element_Text('upyunkey',
NULL,$settings->upyunkey,_t('密匙'));
$form2->addInput($upyunkey);
$upyunprefix = new Typecho_Widget_Helper_Form_Element_Text('upyunprefix',
NULL,$settings->upyunprefix,_t('路径前缀'));
$form2->addInput($upyunprefix);
$bcsbucket = new Typecho_Widget_Helper_Form_Element_Text('bcsbucket',
NULL,$settings->bcsbucket,_t('空间名称'));
$form2->addInput($bcsbucket);
$bcsapikey = new Typecho_Widget_Helper_Form_Element_Text('bcsapikey',
NULL,$settings->bcsapikey,_t('APIKey'));
$form2->addInput($bcsapikey);
$bcssecretkey = new Typecho_Widget_Helper_Form_Element_Text('bcssecretkey',
NULL,$settings->bcssecretkey,_t('SecretKey'));
$form2->addInput($bcssecretkey);
$bcsprefix = new Typecho_Widget_Helper_Form_Element_Text('bcsprefix',
NULL,$settings->bcsprefix,_t('路径前缀'));
$form2->addInput($bcsprefix);
$form2->addItem($submit);
//隐藏模式
switch ($settings->storage) {
case 'local':
$qiniubucket->setAttribute('style','display:none;');
$qiniudomain->setAttribute('style','display:none;');
$qiniuaccesskey->setAttribute('style','display:none;');
$qiniusecretkey->setAttribute('style','display:none;');
$qiniuprefix->setAttribute('style','display:none;');
$upyunbucket->setAttribute('style','display:none;');
$upyundomain->setAttribute('style','display:none;');
$upyunuser->setAttribute('style','display:none;');
$upyunpwd->setAttribute('style','display:none;');
$upyunkey->setAttribute('style','display:none;');
$upyunprefix->setAttribute('style','display:none;');
$bcsbucket->setAttribute('style','display:none;');
$bcsapikey->setAttribute('style','display:none;');
$bcssecretkey->setAttribute('style','display:none;');
$bcsprefix->setAttribute('style','display:none;');
break;
case 'qiniu':
$local->setAttribute('style','display:none;');
$upyunbucket->setAttribute('style','display:none;');
$upyundomain->setAttribute('style','display:none;');
$upyunuser->setAttribute('style','display:none;');
$upyunpwd->setAttribute('style','display:none;');
$upyunkey->setAttribute('style','display:none;');
$upyunprefix->setAttribute('style','display:none;');
$bcsbucket->setAttribute('style','display:none;');
$bcsapikey->setAttribute('style','display:none;');
$bcssecretkey->setAttribute('style','display:none;');
$bcsprefix->setAttribute('style','display:none;');
break;
case 'upyun':
$local->setAttribute('style','display:none;');
$qiniubucket->setAttribute('style','display:none;');
$qiniudomain->setAttribute('style','display:none;');
$qiniuaccesskey->setAttribute('style','display:none;');
$qiniusecretkey->setAttribute('style','display:none;');
$qiniuprefix->setAttribute('style','display:none;');
$bcsbucket->setAttribute('style','display:none;');
$bcsapikey->setAttribute('style','display:none;');
$bcssecretkey->setAttribute('style','display:none;');
$bcsprefix->setAttribute('style','display:none;');
break;
case 'bcs':
$local->setAttribute('style','display:none;');
$qiniubucket->setAttribute('style','display:none;');
$qiniudomain->setAttribute('style','display:none;');
$qiniuaccesskey->setAttribute('style','display:none;');
$qiniusecretkey->setAttribute('style','display:none;');
$qiniuprefix->setAttribute('style','display:none;');
$upyunbucket->setAttribute('style','display:none;');
$upyundomain->setAttribute('style','display:none;');
$upyunuser->setAttribute('style','display:none;');
$upyunpwd->setAttribute('style','display:none;');
$upyunkey->setAttribute('style','display:none;');
$upyunprefix->setAttribute('style','display:none;');
break;
}
//更新模式
$request = Typecho_Request::getInstance();
if (isset($request->gid)&&$action!=='insert') {
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
$gallery = $db->fetchRow($db->select()->from($prefix.'gallery')->where('gid=?',$request->gid));
if (!$gallery) {
throw new Typecho_Widget_Exception(_t('图片不存在'),404);
}
$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=='2') {
$submit->value(_t('保存设置'));
$_action = 'sync';
} else {
$do->value('insert');
$submit->value(_t('添加图片'));
$_action = 'insert';
}
if (empty($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('请输入一个整数数字'));
}
if ($action=='update') {
$gid->addRule('required',_t('图片主键不存在'));
$gid->addRule(array(new HighSlide_Plugin,'galleryexists'),_t('图片不存在'));
}
$form = ($render=='1')?$form1:$form2;
return $form;
}
/**
* 判断图片主键
*
* @access public
* @param string $gid
* @return boolean
*/
public static function galleryexists($gid)
{
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
$gallery = $db->fetchRow($db->select()->from($prefix.'gallery')->where('gid=?',$gid)->limit(1));
return $gallery?true:false;
}
/**
* 判断比例格式
*
* @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;
$settings = Helper::options()->plugin('HighSlide');
$istype = self::replacelist();
//替换范围
if ($widget->is(''.$istype->index.'')||$widget->is(''.$istype->archive.'')||$widget->is(''.$istype->post.'')||$widget->is(''.$istype->page.'')) {
$pattern = '/<a(.*?)href\=\"([^\s]+)\.(jpg|gif|png|bmp)\"(.*?)>(.*?)<\/a>/si';
$replacement = '<a$1href="$2.$3" class="highslide" onclick="return hs.expand(this,{slideshowGroup:\'images\'})"$4>$5</a>';
$content = preg_replace($pattern,$replacement,$content);
//全图替换
if ($settings->rpmode=='imgsrc') {
$pattern = '/(<img[^>]+src\s*=\s*"?([^>"\s]+)"?[^>]*>)(?!<\/a>)/si';
$replacement = '<a href="$2" class="highslide" onclick="return hs.expand(this,{slideshowGroup:\'images\'})">$1</a>';
$content = preg_replace($pattern,$replacement,$content);
}
//附件链接替换
$content = preg_replace_callback('/<a(.*?)href\=\"([^\s]+)\/attachment\/(\d*|n)\/\"(.*?)>/i',array('HighSlide_Plugin','linkparse'),$content);
}
//页面相册标签替换
if ($widget->is('page')&&$settings->mode=='highslide-full.packed.js') {
$content = preg_replace_callback("/\[GALLERY([\-\d|\,]*?)\]/i",array('HighSlide_Plugin','galleryparse'),$content);
}
//html弹窗标签替换
if ($settings->mode=='highslide-full.packed.js') {
$content = preg_replace_callback("/<(hs)([^>]*)>(.*?)<\/\\1>/si",array('HighSlide_Plugin','htmlparse'),$content);
}
return $content;
}
/**
* 应用范围参数
*
* @access private
* @return array
*/
private static function replacelist()
{
$rplist = Helper::options()->plugin('HighSlide')->rplist;
$rplists = array();
if ($rplist) {
foreach ($rplist as $key=>$val) {
$key = $val;
$rplists[$key] = $val;
}
}
return new Typecho_Config($rplists);
}
/**
* 页面相册解析
*
* @access public
* @param array $matches
* @return string
*/
public static function galleryparse($matches)
{
$settings = Helper::options()->plugin('HighSlide');
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
$tmp = '';
$cover = '';
$param = substr(trim($matches[1]),1);
$sorts = ($param)?explode(',',$param):array(self::defaultsort());
foreach ($sorts as $sort) {
$gallerys = $db->fetchAll($db->select()->from($prefix.'gallery')->where('sort=?',''.$sort.'')->order($prefix.'gallery.order',Typecho_Db::SORT_ASC));
if (!empty($gallerys)) {
//封面部分
$coversets = array(array_shift($gallerys));
foreach ($coversets as $coverset) {
//幻影橱窗
if ($settings->gallery=='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> ';
}
//岁月名片
elseif ($settings->gallery=='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> ';
}
//纯白记忆
elseif ($settings->gallery=='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> ';
} else {
$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) {
//幻影橱窗
if ($settings->gallery=='gallery-in-page') {
$tmp.='<a class="highslide" href="'.$gallery['image'].'" title="'.$gallery['description'].'" onclick="return hs.expand(this,inPageOptions)"><img src="'.$gallery['thumb'].'" alt="'.$gallery['description'].'"/></a>';
}
//岁月名片
elseif ($settings->gallery=='gallery-controls-in-heading') {
$tmp.='<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>';
}
//纯白记忆
elseif ($settings->gallery=='gallery-in-box') {
$tmp.='<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>';
} else {
$tmp.='<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>';
}
}
}
}
//合并输出
$container = '<div class="hidden-container">'.$tmp.'</div>';
if ($settings->gallery=='gallery-in-page') {
$output = '<div id="gallery-area" style="width: 620px; height: 520px; margin: 0 auto; border: 1px solid silver"><div class="hidden-container">'.$cover.$tmp.'</div></div>';
} else {
$output = '<div class="highslide-gallery">'.$cover.$container.'</div>';
}
return $output;
}
/**
* 缺省相册分类
*
* @access private
* @return string
*/
private static function defaultsort()
{
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
$default = $db->fetchRow($db->select('sort')->from($prefix.'gallery')->order('sort',Typecho_Db::SORT_ASC));
return $default?$default['sort']:'';
}
/**
* html弹窗解析
*
* @access public
* @param array $matches
* @return string
*/
public static function htmlparse($matches)
{
$settings = Helper::options()->plugin('HighSlide');
$param = trim($matches[2]);
$id = 'highslide-html';
$text = 'text';
$title = '';
$ajax = '';
$addt = '';
$width = '';
$height = '';
$Movetext = 'Move';
$Movetitle = 'Move';
$Closetext = 'Close';
$Closetitle = 'Close (esc)';
$Resizetitle = 'Resize';
if ($settings->lang == 'chs') {
$Movetext = '移动';
$Movetitle = '移动';
$Closetext = '关闭';
$Closetitle = '关闭 (esc)';
$Resizetitle = '拉伸';
}
//标签参数解析
if (!empty($param)) {
if (preg_match("/id=[\"']([\w-]*)[\"']/i",$param,$out)) {
$id = trim($out[1])==''?$id:trim($out[1]);
}
if (preg_match("/text=[\"'](.*?)[\"']/si",$param,$out)) {
$text = trim($out[1])==''?$text:trim($out[1]);
}
if (preg_match("/title=[\"'](.*?)[\"']/si",$param,$out)) {
$title = trim($out[1])==''?$title:trim($out[1]);
}
if (preg_match("/ajax=[\"'](.*?)[\"']/i",$param,$out)) {
$ajax = trim($out[1])==''?$ajax:trim($out[1]);
}
if (preg_match("/width=[\"']([\w-]*)[\"']/i",$param,$out)) {
$width = trim($out[1])==''?$width:',width:'.str_replace('px','',trim($out[1]));
}
if (preg_match("/height=[\"']([\w-]*)[\"']/i",$param,$out)) {
$height = trim($out[1])==''?$height:',height:'.str_replace('px','',trim($out[1]));
}
}
//标题栏支持
if ($settings->wrap) {
$addt = (in_array('draggable-header',$settings->wrap)&&$title)?',headingText:\''.$title.'\'':'';
}
//ajax模式判断
$href = ($ajax)?$ajax:'#';
$shift = ($ajax)?'objectType:\'ajax\'':'contentId:\''.$id.'\'';
$output = '<a href="'.$href.'" onclick="return hs.htmlExpand(this,{'.$shift.$addt.$width.$height.'})" class="highslide">'.$text.'</a>';
$output .= '<div class="highslide-html-content" id="'.$id.'">';
$output .= '<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($matches[3]).'</div>';
$output .= '<div class="highslide-footer"><div><span class="highslide-resize" title="'.$Resizetitle.'"><span></span></span></div></div>';
$output .= '</div>
';
return $output;
}
/**
* 附件链接解析
*
* @access public
* @param array $matches
* @return string
*/
public static function linkparse($matches)
{
$db = Typecho_Db::get();
$cid = $matches[3];
$attach = $db->fetchRow($db->select()->from('table.contents')->where('type=\'attachment\' AND cid=?',$cid));
$attach_data = unserialize($attach['text']);
$output = '<a'.$matches[1].'href="'.Typecho_Common::url($attach_data['path'],Helper::options()->siteUrl).'" class="highslide" onclick="return hs.expand(this,{slideshowGroup:\'images\'})"'.$matches[4].'>';
return $output;
}
/**
* 附件缩略面板
*
* @access public
* @param Widget_Contents_Post_Edit $post
* @return void
*/
public static function uploadpanel($post)
{
?>
<label class="typecho-label"><?php _e('缩略图'); ?></label>
<link rel="stylesheet" type="text/css" media="all" href="<?php Helper::options()->pluginUrl('HighSlide/css/imgareaselect-animated.css'); ?>" />
<div id="preview-area" style="border:1px dashed #D9D9D6;background-color:#FFF;color:#999;" class="p">
<p id="loadattach" style="text-align:center"><a href="###" data-cid="<?php echo $post->cid; ?>"><?php _e('加载附件'); ?></a></p>
<ul id="attach-list" style="list-style:none;margin:0px 10px;padding:0px;"></ul>
</div>
<?php
}
/**
* 附件缩略脚本
*
* @access public
* @return void
*/
public static function jshelper()
{
$options = Helper::options();
$settings = $options->plugin('HighSlide');
$ratio = ($settings->thumbfix=='fixedratio')?$settings->fixedratio:'false';
$fileurl = self::filedata()->url;
?>
<script src="<?php $options->pluginUrl('HighSlide/js/imgareaselect.js'); ?>"></script>
<script type="text/javascript">
$(function() {
$('#loadattach').find('a').click(function() {
var list = $('#attach-list'),
cid = $(this).data('cid');
list.empty();
$.post('<?php $options->index('/action/gallery-edit'); ?>',
{'do':'preview','cid':cid},
function(data) {
var val = eval(data);
for(var i=0;i<val.length;i++) {
var thumb = $('<li data-name="thumb_'+val[i].name+'">').attr('style','padding:8px 0px;border-top:1px dashed #D9D9D6;')
.data('path',val[i].path).data('thumb',val[i].thumb)
.html('<img class="preview" src="'+val[i].thumb+'" alt="thumb_'+val[i].name+'" style="max-width:148px;"/><div class="info">'+val[i].tsize
+' <a class="addto" href="###" title="<?php _e('插入图链'); ?>"><i class="i-exlink"></i></a>'