This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwidgets.php
819 lines (693 loc) · 26 KB
/
widgets.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
<?php
//启用css和js
function island_widget_js() {
global $wp_customize;
if ( ! isset( $wp_customize ) ) {
wp_enqueue_script( 'dashboard-js', get_template_directory_uri() . '/js/dashboard.js', array('jquery','jquery-ui-datepicker','jquery-ui-sortable','jquery-ui-sortable', 'jquery-ui-draggable','jquery-ui-droppable','admin-widgets' ) );
}
wp_enqueue_style( 'dashboard-style', get_template_directory_uri() . '/css/dashboard.css', array() );
}
add_action( 'admin_enqueue_scripts', 'island_widget_js' );
/**
*
* 最新评论
*
*/
if( ! class_exists( 'CS_Widget_comment' ) ) {
class CS_Widget_comment extends WP_Widget {
//构建函数
function __construct() {
$widget_ops = array(
'classname' => 'cs_widget_comment',
'description' => '最新评论'
);
parent::__construct( 'cs_widget_comment', 'island最新评论', $widget_ops );
}
//前台显示函数
function widget( $args, $instance ) {
extract( $args );
echo $before_widget;
if ( ! empty( $instance['title'] ) ) {
echo $before_title . $instance['title'] . $after_title;
}
echo '<div class="textwidget" id="comment-list"><ul>';
h_comments($outer='博主',$limit= $instance['number']);
echo '</ul></div>';
echo $after_widget;
}
//数据更新函数
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = $new_instance['title'];
$instance['number'] = $new_instance['number'];
return $instance;
}
//后台表单函数
function form( $instance ) {
//
// 设置默认值
// -------------------------------------------------
$instance = wp_parse_args( $instance, array(
'title' => '最新评论',
'number' => '10',
));
//
// 标题
// -------------------------------------------------
$text_value = esc_attr( $instance['title'] );
$text_field = array(
'id' => $this->get_field_name('title'),
'name' => $this->get_field_name('title'),
'type' => 'text',
'title' => '标题',
);
echo cs_add_element( $text_field, $text_value );
//
// 金额
// -------------------------------------------------
$number_value = esc_attr( $instance['number'] );
$number_field = array(
'id' => $this->get_field_name('number'),
'name' => $this->get_field_name('number'),
'type' => 'number',
'title' => '数目',
);
echo cs_add_element( $number_field, $number_value );
}
}
}
if ( ! function_exists( 'cs_widget_init_comment' ) ) {
function cs_widget_init_comment() {
register_widget( 'CS_Widget_comment' );
}
add_action( 'widgets_init', 'cs_widget_init_comment', 2 );
}
// 小工具
// 名称: 博客统计
// 版本: 1.0
// 作者: ipeld14
// 站名: 翼帆远航
// 网址: http://www.ipeld.net
// 定义小工具的类 EfanBlogStat
class EfanBlogStat extends WP_Widget{
function EfanBlogStat(){
// 定义小工具的构造函数
$widget_ops = array('classname' => 'widget_blogstat', 'description' => '显示博客的统计信息');
$this->WP_Widget(false, 'island博客统计', $widget_ops);
}
function form($instance){
// 表单函数,控制后台显示
// $instance 为之前保存过的数据
// 如果之前没有数据的话,设置默认量
$instance = wp_parse_args(
(array)$instance,
array(
'title' => '博客统计',
'establish_time' => '2013-01-27'
)
);
/*
$instance = wp_parse_args(
(array)$instance,
array(
'title' => '博客统计',
'establish_time' => '2013-01-27',
'post_count_no' => '1',
'draft_count_no' => '0',
'comment_count_no' => '2',
'establish_date_no' => '3',
'establish_time_no' => '4',
'tag_count_no' => '0',
'page_count_no' => '0',
'cat_count_no' => '0',
'link_count_no' => '0',
'user_count_no' => '0',
'last_update_no' => '5',
'support_me' => false
)
);
*/
$title = htmlspecialchars($instance['title']);
$establish_time = htmlspecialchars($instance['establish_time']);
/*
$post_count_no = htmlspecialchars($instance['post_count_no']);
$draft_count_no = htmlspecialchars($instance['draft_count_no']);
$comment_count_no = htmlspecialchars($instance['comment_count_no']);
$establish_date_no = htmlspecialchars($instance['establish_date_no']);
$establish_time_no = htmlspecialchars($instance['establish_time_no']);
$tag_count_no = htmlspecialchars($instance['tag_count_no']);
$page_count_no = htmlspecialchars($instance['page_count_no']);
$cat_count_no = htmlspecialchars($instance['cat_count_no']);
$link_count_no = htmlspecialchars($instance['link_count_no']);
$user_count_no = htmlspecialchars($instance['user_count_no']);
$last_update_no = htmlspecialchars($instance['last_update_no']);
$support_me = $instance['support_me'];
*/
// 表格布局输出表单
$output = '<table>';
$output .= '<tr><td>标题</td><td>';
$output .= '<input id="'.$this->get_field_id('title') .'" name="'.$this->get_field_name('title').'" type="text" value="'.$instance['title'].'" />';
$output .= '</td></tr><tr><td>建站日期:</td><td>';
$output .= '<input id="'.$this->get_field_id('establish_time') .'" name="'.$this->get_field_name('establish_time').'" type="text" value="'.$instance['establish_time'].'" />';
$output .= '</td></tr></table>';
/*
$output .= '<br />输入数字1~11安排显示顺序,0表示不显示';
$output .= '<table>';
$output .= '<tr><td>日志总数:</td><td>';
$output .= '<input id="'.$this->get_field_id('post_count_no') .'" name="'.$this->get_field_name('post_count_no').'" type="text" value="'.$instance['post_count_no'].'" />';
$output .= '</td></tr>';
$output .= '<tr><td>草稿数目:</td><td>';
$output .= '<input id="'.$this->get_field_id('draft_count_no') .'" name="'.$this->get_field_name('draft_count_no').'" type="text" value="'.$instance['draft_count_no'].'" />';
$output .= '</td></tr>';
$output .= '<tr><td>评论数目:</td><td>';
$output .= '<input id="'.$this->get_field_id('comment_count_no') .'" name="'.$this->get_field_name('comment_count_no').'" type="text" value="'.$instance['comment_count_no'].'" />';
$output .= '</td></tr>';
$output .= '<tr><td>建站日期:</td><td>';
$output .= '<input id="'.$this->get_field_id('establish_date_no') .'" name="'.$this->get_field_name('establish_date_no').'" type="text" value="'.$instance['establish_date_no'].'" />';
$output .= '</td></tr>';
$output .= '<tr><td>运行天数:</td><td>';
$output .= '<input id="'.$this->get_field_id('establish_time_no') .'" name="'.$this->get_field_name('establish_time_no').'" type="text" value="'.$instance['establish_time_no'].'" />';
$output .= '</td></tr>';
$output .= '<tr><td>标签总数:</td><td>';
$output .= '<input id="'.$this->get_field_id('tag_count_no') .'" name="'.$this->get_field_name('tag_count_no').'" type="text" value="'.$instance['tag_count_no'].'" />';
$output .= '</td></tr>';
$output .= '<tr><td>页面总数:</td><td>';
$output .= '<input id="'.$this->get_field_id('page_count_no') .'" name="'.$this->get_field_name('page_count_no').'" type="text" value="'.$instance['page_count_no'].'" />';
$output .= '</td></tr>';
$output .= '<tr><td>分类总数:</td><td>';
$output .= '<input id="'.$this->get_field_id('cat_count_no') .'" name="'.$this->get_field_name('cat_count_no').'" type="text" value="'.$instance['cat_count_no'].'" />';
$output .= '</td></tr>';
$output .= '<tr><td>友链总数:</td><td>';
$output .= '<input id="'.$this->get_field_id('link_count_no') .'" name="'.$this->get_field_name('link_count_no').'" type="text" value="'.$instance['link_count_no'].'" />';
$output .= '</td></tr>';
$output .= '<tr><td>用户总数:</td><td>';
$output .= '<input id="'.$this->get_field_id('user_count_no') .'" name="'.$this->get_field_name('user_count_no').'" type="text" value="'.$instance['user_count_no'].'" />';
$output .= '</td></tr>';
$output .= '<tr><td>最后更新:</td><td>';
$output .= '<input id="'.$this->get_field_id('last_update_no') .'" name="'.$this->get_field_name('last_update_no').'" type="text" value="'.$instance['last_update_no'].'" />';
$output .= '</td></tr>';
$output .= '</table>';
*/
/*
$output .= '<label><input id="'.$this->get_field_id('support_me') .'" name="'.$this->get_field_name('support_me').'" type="checkbox" ';
if ($instance['support_me']) {
$output .= 'checked="checked"';
}
$output .= ' /> 支持开发者</label>';
*/
echo $output;
}
function update($new_instance, $old_instance){
// 更新数据的函数
$instance = $old_instance;
// 数据处理
$instance['title'] = strip_tags(stripslashes($new_instance['title']));
$instance['establish_time'] = strip_tags(stripslashes($new_instance['establish_time']));
/*
$instance['post_count_no'] = strip_tags(stripslashes($new_instance['post_count_no']));
$instance['draft_count_no'] = strip_tags(stripslashes($new_instance['draft_count_no']));
$instance['comment_count_no'] = strip_tags(stripslashes($new_instance['comment_count_no']));
$instance['establish_date_no'] = strip_tags(stripslashes($new_instance['establish_date_no']));
$instance['establish_time_no'] = strip_tags(stripslashes($new_instance['establish_time_no']));
$instance['tag_count_no'] = strip_tags(stripslashes($new_instance['tag_count_no']));
$instance['page_count_no'] = strip_tags(stripslashes($new_instance['page_count_no']));
$instance['cat_count_no'] = strip_tags(stripslashes($new_instance['cat_count_no']));
$instance['link_count_no'] = strip_tags(stripslashes($new_instance['link_count_no']));
$instance['user_count_no'] = strip_tags(stripslashes($new_instance['user_count_no']));
$instance['last_update_no'] = strip_tags(stripslashes($new_instance['last_update_no']));
*/
return $instance;
}
function widget($args, $instance){
extract($args); //展开数组
$title = apply_filters('widget_title',empty($instance['title']) ? ' ' : $instance['title']);
$establish_time = empty($instance['establish_time']) ? '2013-01-27' : $instance['establish_time'];
echo $before_widget;
echo $before_title . $title . $after_title;
echo '<ul>';
// $this->efan_get_blogstat($establish_time, $instance);
$this->efan_get_blogstat($establish_time);
echo '</ul>';
echo $after_widget;
}
function efan_get_blogstat($establish_time /*, $instance */){
// 相关数据的获取
global $wpdb;
$count_posts = wp_count_posts();
$published_posts = $count_posts->publish;
$draft_posts = $count_posts->draft;
$comments_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments");
$time = floor((time()-strtotime($establish_time))/86400);
$count_tags = wp_count_terms('post_tag');
$count_pages = wp_count_posts('page');
$page_posts = $count_pages->publish;
$count_categories = wp_count_terms('category');
$link = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'");
$users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users");
$last = $wpdb->get_results("SELECT MAX(post_modified) AS MAX_m FROM $wpdb->posts WHERE (post_type = 'post' OR post_type = 'page') AND (post_status = 'publish' OR post_status = 'private')");
$last = date('Y-n-j', strtotime($last[0]->MAX_m));
// 显示数据
/*
$op = array(
$published_posts,
$draft_posts,
$comments_count,
$establish_time,
$time,
$count_tags,
$page_posts,
$count_categories,
$link,
$users,
$last
);
$output = "";
foreach ($instance as $key => $value){
switch ($value){
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
case "10":
case "11":
default: $output .= $this->efan_get_var_name($key, $op);break;
}
}
*/
$output = '<li>日志总数:';
$output .= $published_posts;
$output .= ' 篇</li>';
$output .= '<li>评论数目:';
$output .= $comments_count;
$output .= ' 条</li>';
$output .= '<li>建站日期:';
$output .= $establish_time;
$output .= '</li>';
$output .= '<li>运行天数:';
$output .= $time;
$output .= ' 天</li>';
$output .= '<li>标签总数:';
$output .= $count_tags;
$output .= ' 个</li>';
if (is_user_logged_in()){
$output .= '<li>草稿数目:';
$output .= $draft_posts;
$output .= ' 篇</li>';
$output .= '<li>页面总数:';
$output .= $page_posts;
$output .= ' 个</li>';
$output .= '<li>分类总数:';
$output .= $count_categories;
$output .= ' 个</li>';
$output .= '<li>友链总数:';
$output .= $link;
$output .= ' 个</li>';
}
if (get_option("users_can_register") == 1){
$output .= '<li>用户总数:';
$output .= $users;
$output .= ' 个</li>';
}
$output .= '<li>最后更新:';
$output .= $last;
$output .= '</li>';
echo $output;
}
/*
function efan_get_var_name($key, $op){
extract($op);
switch ($key){
case "post_count_no": return '<li>日志总数:'.$published_posts.' 篇</li>';
case "draft_count_no": return '<li>草稿数目:'.$draft_posts.' 篇</li>';
case "comment_count_no": return '<li>评论数目:'.$draft_posts.' 条</li>';
case "establish_date_no": return '<li>建站日期:'.$establish_time.'</li>';
case "establish_time_no": return '<li>运行天数:'.$time.' 天</li>';
case "tag_count_no": return '<li>标签总数:'.$count_tags.' 个</li>';
case "page_count_no": return '<li>页面总数:'.$page_posts.' 个</li>';
case "cat_count_no": return '<li>分类总数:'.$count_categories.' 个</li>';
case "link_count_no": return '<li>友链总数:'.$link.' 个</li>';
case "user_count_no": return '<li>用户总数:'.$users.' 个</li>';
case "last_update_no": return '<li>最后更新:'.$last.'</li>';
}
}
*/
}
function EfanBlogStat(){
// 注册小工具
register_widget('EfanBlogStat');
}
add_action('widgets_init','EfanBlogStat');
/**
*
* CS框架_图像链接
*
*/
if( ! class_exists( 'CS_Widget_Link' ) ) {
class CS_Widget_Link extends WP_Widget {
//构建函数
function __construct() {
$widget_ops = array(
'classname' => 'cs_widget_link',
'description' => '图像链接小工具'
);
parent::__construct( 'cs_widget_link', 'island图像链接', $widget_ops );
}
//前台显示函数
function widget( $args, $instance ) {
extract( $args );
$NewTab = $instance['sure'];
echo '<aside class="textwidget cs_widget_link">';
echo '<a href="'. $instance['link'] .'"';
if ($NewTab == true) { echo 'target="_black"';}
echo '><img src="'. $instance['advertising'] .'" />';
echo '</a>';
echo '</aside>';
}
//数据更新函数
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = $new_instance['title'];
$instance['advertising'] = $new_instance['advertising'];
$instance['link'] = $new_instance['link'];
$instance['sure'] = $new_instance['sure'];
return $instance;
}
//后台表单函数
function form( $instance ) {
//
// 设置默认值
// -------------------------------------------------
$instance = wp_parse_args( $instance, array(
'title' => '图像链接',
'advertising' => '',
'link' => '',
'sure' => '',
));
//
// 标题
// -------------------------------------------------
$text_value = esc_attr( $instance['title'] );
$text_field = array(
'id' => $this->get_field_name('title'),
'name' => $this->get_field_name('title'),
'type' => 'text',
'title' => '标题',
);
echo cs_add_element( $text_field, $text_value );
//
// 图像
// -------------------------------------------------
$upload_value = esc_attr( $instance['advertising'] );
$upload_field = array(
'id' => $this->get_field_name('advertising'),
'name' => $this->get_field_name('advertising'),
'type' => 'upload',
'title' => '图像',
);
echo cs_add_element( $upload_field, $upload_value );
//
// 链接
// -------------------------------------------------
$link_value = esc_attr( $instance['link'] );
$link_field = array(
'id' => $this->get_field_name('link'),
'name' => $this->get_field_name('link'),
'type' => 'text',
'title' => '链接',
'attributes' => array(
'placeholder' => 'http://...'
)
);
echo cs_add_element( $link_field, $link_value );
//
// 新标签打开
// -------------------------------------------------
$switcher_value = esc_attr( $instance['sure'] );
$switcher_field = array(
'id' => $this->get_field_name('sure'),
'name' => $this->get_field_name('sure'),
'type' => 'switcher',
'title' => '新标签打开',
);
echo cs_add_element( $switcher_field, $switcher_value );
}
}
}
if ( ! function_exists( 'cs_widget_init_Link' ) ) {
function cs_widget_init_Link() {
register_widget( 'CS_Widget_Link' );
}
add_action( 'widgets_init', 'cs_widget_init_Link', 2 );
}
/**
*
* 支付宝按钮
*
*/
if( ! class_exists( 'CS_Widget_Alipay' ) ) {
class CS_Widget_Alipay extends WP_Widget {
//构建函数
function __construct() {
$widget_ops = array(
'classname' => 'cs_widget_Alipay',
'description' => '支付宝按钮'
);
parent::__construct( 'cs_widget_Alipay', 'island支付宝按钮', $widget_ops );
}
//前台显示函数
function widget( $args, $instance ) {
extract( $args );
echo '<aside class="textwidget">';
echo '<div class="pay_alipay">';
echo '<form action="https://shenghuo.alipay.com/send/payment/fill.htm" method="POST" target="_blank" accept-charset="GBK">';
echo '<input name="optEmail" type="hidden" value="'. $instance['accounts'] .'">';
echo '<input name="payAmount" type="hidden" value="'. $instance['money'] .'">';
echo '<input id="title" name="title" type="hidden" value="'. $instance['caption'] .'">';
echo '<input name="memo" type="hidden" value="'. $instance['remark'] .'">';
echo '<input style="width:100%" name="pay" type="image" value="转账" src="'. $instance['background'] .'">';
echo '</form>';
echo '</div>';
echo '</aside>';
}
//数据更新函数
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = $new_instance['title'];
$instance['accounts'] = $new_instance['accounts'];
$instance['money'] = $new_instance['money'];
$instance['caption'] = $new_instance['caption'];
$instance['remark'] = $new_instance['remark'];
$instance['background'] = $new_instance['background'];
return $instance;
}
//后台表单函数
function form( $instance ) {
//
// 设置默认值
// -------------------------------------------------
$instance = wp_parse_args( $instance, array(
'title' => '支付宝',
'accounts' => '',
'money' => '',
'caption' => '',
'remark' => '',
'background' => '',
));
//
// 标题
// -------------------------------------------------
$text_value = esc_attr( $instance['title'] );
$text_field = array(
'id' => $this->get_field_name('title'),
'name' => $this->get_field_name('title'),
'type' => 'text',
'title' => '标题',
);
echo cs_add_element( $text_field, $text_value );
//
// 账户
// -------------------------------------------------
$text_value = esc_attr( $instance['accounts'] );
$text_field = array(
'id' => $this->get_field_name('accounts'),
'name' => $this->get_field_name('accounts'),
'type' => 'text',
'title' => '账户',
);
echo cs_add_element( $text_field, $text_value );
//
// 金额
// -------------------------------------------------
$number_value = esc_attr( $instance['money'] );
$number_field = array(
'id' => $this->get_field_name('money'),
'name' => $this->get_field_name('money'),
'type' => 'number',
'title' => '金额',
);
echo cs_add_element( $number_field, $number_value );
//
// 说明
// -------------------------------------------------
$text_value = esc_attr( $instance['caption'] );
$text_field = array(
'id' => $this->get_field_name('caption'),
'name' => $this->get_field_name('caption'),
'type' => 'text',
'title' => '说明',
);
echo cs_add_element( $text_field, $text_value );
//
// 备注
// -------------------------------------------------
$textarea_value = esc_attr( $instance['remark'] );
$textarea_field = array(
'id' => $this->get_field_name('remark'),
'name' => $this->get_field_name('remark'),
'type' => 'textarea',
'title' => '备注',
);
echo cs_add_element( $textarea_field, $textarea_value );
//
// 按钮图片
// -------------------------------------------------
$upload_value = esc_attr( $instance['background'] );
$upload_field = array(
'id' => $this->get_field_name('background'),
'name' => $this->get_field_name('background'),
'type' => 'upload',
'title' => '按钮图片',
);
echo cs_add_element( $upload_field, $upload_value );
}
}
}
if ( ! function_exists( 'cs_widget_init_Alipay' ) ) {
function cs_widget_init_Alipay() {
register_widget( 'CS_Widget_Alipay' );
}
add_action( 'widgets_init', 'cs_widget_init_Alipay', 2 );
}
/**
*
* CS框架_扫码付款
*
*/
if( ! class_exists( 'CS_Widget_Qr' ) ) {
class CS_Widget_Qr extends WP_Widget {
//构建函数
function __construct() {
$widget_ops = array(
'classname' => 'cs_widget_qr',
'description' => 'island扫码付款'
);
parent::__construct( 'cs_widget_qr', 'island扫码付款', $widget_ops );
}
//前台显示函数
function widget( $args, $instance ) {
extract( $args );
echo $before_widget;
if ( ! empty( $instance['title'] ) ) {
echo $before_title . $instance['title'] . $after_title;
}
$NewTab = $instance['sure'];
echo '<div class="textwidget">';
echo '<div class="qr-text">'. $instance['text'] .'</div>';
echo '<div class="qr-wrapper clearfix"><div class="qr-caption"><i class="fa fa-jpy"></i>'. $instance['caption'] .'</div>';
echo '<div class="qr-alipay"><a href="javascript:void(0)"></a>';
echo '<div class="qr-img"><img src="'. $instance['alipay-img'] .'" />支付宝支付</div></div>';
echo '<div class="qr-weixin"><a href="javascript:void(0)"></a>';
echo '<div class="qr-img"><img src="'. $instance['weixin-img'] .'" />微信支付</div></div></div>';
echo '</div>';
echo $after_widget;
}
//数据更新函数
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = $new_instance['title'];
$instance['caption'] = $new_instance['caption'];
$instance['text'] = $new_instance['text'];
$instance['alipay-img'] = $new_instance['alipay-img'];
$instance['weixin-img'] = $new_instance['weixin-img'];
return $instance;
}
//后台表单函数
function form( $instance ) {
//
// 设置默认值
// -------------------------------------------------
$instance = wp_parse_args( $instance, array(
'title' => '扫码付款',
'text' => '',
'alipay-img' => '',
'weixin-img' => '',
));
//
// 标题
// -------------------------------------------------
$text_value = esc_attr( $instance['title'] );
$text_field = array(
'id' => $this->get_field_name('title'),
'name' => $this->get_field_name('title'),
'type' => 'text',
'title' => '标题',
);
echo cs_add_element( $text_field, $text_value );
//
// 说明
// -------------------------------------------------
$text_value = esc_attr( $instance['text'] );
$text_field = array(
'id' => $this->get_field_name('text'),
'name' => $this->get_field_name('text'),
'type' => 'textarea',
'title' => '说明',
);
echo cs_add_element( $text_field, $text_value );
//
// 数额
// -------------------------------------------------
$text_value = esc_attr( $instance['caption'] );
$text_field = array(
'id' => $this->get_field_name('caption'),
'name' => $this->get_field_name('caption'),
'type' => 'text',
'title' => '数额',
);
echo cs_add_element( $text_field, $text_value );
//
// 支付宝
// -------------------------------------------------
$upload_value = esc_attr( $instance['alipay-img'] );
$upload_field = array(
'id' => $this->get_field_name('alipay-img'),
'name' => $this->get_field_name('alipay-img'),
'type' => 'upload',
'title' => '支付宝二维码',
);
echo cs_add_element( $upload_field, $upload_value );
//
// 微信
// -------------------------------------------------
$upload_value = esc_attr( $instance['weixin-img'] );
$upload_field = array(
'id' => $this->get_field_name('weixin-img'),
'name' => $this->get_field_name('weixin-img'),
'type' => 'upload',
'title' => '微信二维码',
);
echo cs_add_element( $upload_field, $upload_value );
}
}
}
if ( ! function_exists( 'cs_widget_init_Qr' ) ) {
function cs_widget_init_Qr() {
register_widget( 'CS_Widget_Qr' );
}
add_action( 'widgets_init', 'cs_widget_init_Qr', 2 );
}