-
Notifications
You must be signed in to change notification settings - Fork 21
/
functions.php
executable file
·2234 lines (2079 loc) · 89.2 KB
/
functions.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
/**
* Main Function of Tinection WordPress Theme
*
* @package Tinection
* @version 1.1.9
* @date 2015.6.7
* @author Zhiyan <[email protected]>
* @site Zhiyanblog <www.zhiyanblog.com>
* @copyright Copyright (c) 2014-2015, Zhiyan
* @license http://opensource.org/licenses/gpl-2.0.php GPL v2 or later
* @link http://www.zhiyanblog.com/tinection.html
**/
?>
<?php
/* ------------------------------------------------------------------------- *
* Custom functions
/* ------------------------------------------------------------------------- */
/* File Security Check */
if ( ! defined( 'ABSPATH' ) ) { exit; }
/* Sets the path to the parent theme directory. */
if ( !defined( 'THEME_DIR' ) ) {
define( 'THEME_DIR', get_template_directory() );
}
/* Sets the path to the parent theme directory URI. */
if ( !defined( 'THEME_URI' ) ) {
define( 'THEME_URI', get_template_directory_uri() );
}
/* ------------------------------------------------------------------------- *
* OptionTree framework integration: Use in theme mode
/* ------------------------------------------------------------------------- */
add_filter( 'ot_show_pages', '__return_false' );
add_filter( 'ot_show_new_layout', '__return_false' );
add_filter( 'ot_theme_mode', '__return_true' );
add_filter( 'ot_show_settings_import', '__return_true' );
add_filter( 'ot_show_settings_export', '__return_true' );
add_filter( 'ot_show_docs', '__return_false' );
load_template( THEME_DIR . '/admin/option/ot-loader.php' );
/* ------------------------------------------------------------------------- *
* Load theme files
/* ------------------------------------------------------------------------- */
function tin_theme_localized($local){
if(ot_get_option('lan_en')=='on'){
$local = 'en_US';
}else{
$local = 'zh_CN';
}
return $local;
}
add_filter('locale','tin_theme_localized');
if ( ! function_exists( 'tin_load' ) ) {
function tin_load() {
// Load theme options
load_template( THEME_DIR . '/admin/theme-options.php' );
// Load custom widgets
load_template( THEME_DIR . '/functions/widgets/tin-tabs.php' );
load_template( THEME_DIR . '/functions/widgets/tin-posts.php' );
load_template( THEME_DIR . '/functions/widgets/tin-posts-h.php' );
load_template( THEME_DIR . '/functions/widgets/tin-tagcloud.php' );
load_template( THEME_DIR . '/functions/widgets/tin-enhanced-text.php' );
load_template( THEME_DIR . '/functions/widgets/tin-readerwall.php' );
load_template( THEME_DIR . '/functions/widgets/tin-mailcontact.php' );
load_template( THEME_DIR . '/functions/widgets/tin-site.php' );
load_template( THEME_DIR . '/functions/widgets/tin-float-widget.php' );
load_template( THEME_DIR . '/functions/widgets/tin-bookmark.php' );
load_template( THEME_DIR . '/functions/widgets/tin-bookmark-h.php' );
load_template( THEME_DIR . '/functions/widgets/tin-subscribe.php' );
load_template( THEME_DIR . '/functions/widgets/tin-aboutsite.php' );
load_template( THEME_DIR . '/functions/widgets/tin-joinus.php' );
load_template( THEME_DIR . '/functions/widgets/tin-hotsearch.php' );
load_template( THEME_DIR . '/functions/widgets/tin-creditsrank.php' );
load_template( THEME_DIR . '/functions/widgets/tin-ucenter.php' );
load_template( THEME_DIR . '/functions/widgets/tin-donate.php' );
load_template( THEME_DIR . '/functions/widgets/tin-slider.php' );
// Load functions
load_template( THEME_DIR . '/functions/open-social.php' );
load_template( THEME_DIR . '/functions/message.php' );
load_template( THEME_DIR . '/functions/credit.php' );
load_template( THEME_DIR . '/functions/recent-user.php' );
load_template( THEME_DIR . '/functions/tracker.php' );
load_template( THEME_DIR . '/functions/user-page.php' );
load_template( THEME_DIR . '/functions/meta.php' );
load_template( THEME_DIR . '/functions/comment.php' );
load_template( THEME_DIR . '/functions/shortcode.php' );
load_template( THEME_DIR . '/functions/IP.php' );
load_template( THEME_DIR . '/functions/mail.php' );
load_template( THEME_DIR . '/functions/meta-box.php' );
load_template( THEME_DIR . '/functions/newsletter.php' );
load_template( THEME_DIR . '/functions/ua.php' );
load_template( THEME_DIR . '/functions/download.php' );
load_template( THEME_DIR . '/functions/no_category_base.php' );
load_template( THEME_DIR . '/functions/auto-save-image.php' );
load_template( THEME_DIR . '/functions-customize.php' );
if (is_admin()) {require_once( THEME_DIR . '/functions/class-tgm-plugin-activation.php' );}
// Load language
load_theme_textdomain('tinection',THEME_DIR . '/languages');
load_theme_textdomain( 'option-tree',THEME_DIR . '/admin/option/languages');
// 移除自动保存和修订版本
if(ot_get_option('wp_auto_save')=='on'){
add_action('wp_print_scripts','tin_disable_autosave' );
remove_action('post_updated','wp_save_post_revision' );
}
//建立Avatar上传文件夹
tin_add_avatar_folder();
}
}
add_action( 'after_setup_theme', 'tin_load' );
/* ------------------------------------------------------------------------- *
* 移除头部多余信息
/* ------------------------------------------------------------------------- */
function wpbeginner_remove_version(){
return;
}
add_filter('the_generator', 'wpbeginner_remove_version');//wordpress的版本号
remove_action('wp_head', 'feed_links', 2);//包含文章和评论的feed
remove_action('wp_head','index_rel_link');//当前文章的索引
remove_action('wp_head', 'feed_links_extra', 3);// 额外的feed,例如category, tag页
remove_action('wp_head', 'start_post_rel_link', 10, 0);// 开始篇
remove_action('wp_head', 'parent_post_rel_link', 10, 0);// 父篇
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // 上、下篇.
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );//rel=pre
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0 );//rel=shortlink
remove_action('wp_head', 'rel_canonical' );
/* ------------------------------------------------------------------------- *
* 前台替换wordpress自带jquery
/* ------------------------------------------------------------------------- */
if ( !is_admin() ){
function add_scripts() {
if(ot_get_option('jquery_source','local_jq')=='cdn_jq'){$jq = 'http://lib.sinaapp.com/js/jquery/1.10.2/jquery-1.10.2.min.js';}else{$jq = THEME_URI . '/includes/js/jquery.min.js';}
wp_deregister_script( 'jquery' );
//wp_deregister_script( 'jquery ui' );
wp_register_script( 'jquery', $jq );
wp_enqueue_script( 'jquery' );
wp_register_script( 'tinection', THEME_URI .'/includes/js/theme.min.js' );
}
}
add_action('wp_enqueue_scripts', 'add_scripts');
/* -------------------------------------------------- *
* WordPress 后台禁用Google Open Sans字体,加速网站
/* ------------------------------------------------- */
function remove_open_sans() {
wp_deregister_style( 'open-sans' );
wp_register_style( 'open-sans', false );
wp_enqueue_style('open-sans','');
}
add_action( 'init', 'remove_open_sans' );
/* 后台预览
/* --------- */
add_editor_style('/includes/css/editor-style.css');
/* 建立Avatar上传文件夹
/* ----------- */
function tin_add_avatar_folder() {
$upload = wp_upload_dir();
$upload_dir = $upload['basedir'];
$upload_dir = $upload_dir . '/avatars';
if (! is_dir($upload_dir)) {
mkdir( $upload_dir, 0755 );
}
}
/* 移除自动保存
/* -------------- */
function tin_disable_autosave() {
wp_deregister_script('autosave');
}
//删除已经产生的修订版本请取消下一条语句注释并刷新网站任一页面,完成后可恢复注释
//$wpdb->query("DELETE FROM $wpdb->posts WHERE post_type = 'revision'");
/* 修改后台页脚文字
/* ------------ */
function left_admin_footer_text($text) {
$text = '<span id="footer-thankyou">感谢使用<a href=http://cn.wordpress.org/ >WordPress</a>进行创作,使用<a href="http://www.zhiyanblog.com/tinection.html">Tinection</a>主题定制网站样式</span>';
return $text;
}
add_filter('admin_footer_text','left_admin_footer_text');
/* 阻止站内文章Pingback
/* --------------------- */
function tin_noself_ping( &$links ) {
$home = get_option( 'home' );
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, $home ) )
unset($links[$l]);
}
add_action('pre_ping','tin_noself_ping');
/* Theme setup
/* ------------------ */
if ( ! function_exists( 'tin_setup' ) ) {
function tin_setup() {
// 开启自动feed地址
add_theme_support( 'automatic-feed-links' );
// 开启缩略图
add_theme_support( 'post-thumbnails' );
// 增加文章形式
add_theme_support( 'post-formats', array( 'audio', 'aside', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video' ) );
// 图片上传时形成的缩略图尺寸
add_image_size( 'thumbnail', 225, 150, true );
add_image_size( 'medium', 375, 250, true );
add_image_size( 'large', 750, 500, true );
// 菜单区域
register_nav_menus( array(
'topbar' => '顶部菜单',
'footbar' => '底部菜单',
'shopcatbar' => '商城分类导航',
'pagebar' => '页面合并菜单',
) );
}
}
add_action( 'after_setup_theme', 'tin_setup' );
/* 搜索结果排除所有页面
/* --------------------- */
function search_filter_page($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts','search_filter_page');
/* 摘要长度
/* ---------- */
if ( ! function_exists( 'tin_excerpt_length' ) ) {
function tin_excerpt_length( $length ) {
return ot_get_option('excerpt-length',$length);
}
}
add_filter( 'excerpt_length', 'tin_excerpt_length', 999 );
/* 摘要去除短代码
/* ----------------- */
function tin_excerpt_delete_shortcode($excerpt){
$r = "'\[button(.*?)+\](.*?)\[\/button]|\[toggle(.*?)+\](.*?)\[\/toggle]|\[callout(.*?)+\](.*?)\[\/callout]|\[infobg(.*?)+\](.*?)\[\/infobg]|\[tinl2v(.*?)+\](.*?)\[\/tinl2v]|\[tinr2v(.*?)+\](.*?)\[\/tinr2v]|\<pre(.*?)+\>(.*?)\<\/pre>|\[php(.*?)+\](.*?)\[\/php]|\[PHP(.*?)+\](.*?)\[\/PHP]'";
return preg_replace($r, '', $excerpt);
}
add_filter( 'the_excerpt', 'tin_excerpt_delete_shortcode', 999 );
/* 替换摘要后more字样
/* -------------------- */
function new_excerpt_more($more) {
global $post;
$readmore=ot_get_option('readmore');
return '<a rel="nofollow" class="more-link" style="text-decoration:none;" href="'. get_permalink($post->ID) . '">'.$readmore.'</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
function add_nofollow_to_link($link) {
return str_replace('<a', '<a rel="nofollow"', $link);
}
add_filter('the_content_more_link','add_nofollow_to_link', 0);
/* 去除正文P标签包裹 */
//remove_filter( 'the_content', 'wpautop' );
/* 去除摘要P标签包裹 */
remove_filter( 'the_excerpt', 'wpautop' );
/* 改变正文P标签包裹优先级 */
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 12);
/* 在文本小工具不自动添加P标签 */
add_filter( 'widget_text', 'shortcode_unautop' );
/* 在文本小工具也执行短代码 */
add_filter( 'widget_text', 'do_shortcode' );
/* 登录用户浏览站点时不显示工具栏 */
add_filter('show_admin_bar', '__return_false');
/* 变更默认用户角色 投稿者增加上传图片权限 */
function tin_default_role(){
//if(get_option('default_role')!='contributor')update_option('default_role','contributor');
if ( current_user_can('contributor') && !current_user_can('upload_files') ){
$contributor = get_role('contributor');
$contributor->add_cap('upload_files');
}
}
add_action('admin_init','tin_default_role');
/* 给投稿者上传图片权限 */
function tin_allow_contributor_uploads() {
$contributor = get_role('contributor');
$contributor->add_cap('upload_files');
}
if ( current_user_can('contributor') && !current_user_can('upload_files') )
add_action('admin_init', 'tin_allow_contributor_uploads');
/* 添加链接功能 */
add_filter( 'pre_option_link_manager_enabled', '__return_true' );
/* 后台编辑器强化
/* --------------- */
function add_more_buttons($buttons){
$buttons[] = 'fontsizeselect';
$buttons[] = 'styleselect';
$buttons[] = 'fontselect';
$buttons[] = 'hr';
$buttons[] = 'sub';
$buttons[] = 'sup';
$buttons[] = 'cleanup';
$buttons[] = 'image';
$buttons[] = 'code';
$buttons[] = 'media';
$buttons[] = 'backcolor';
$buttons[] = 'visualaid';
return $buttons;
}
add_filter("mce_buttons_3", "add_more_buttons");
/* 在 WordPress 编辑器添加"下一页"按钮
/* ------------------------------------ */
function tin_add_next_page_button($mce_buttons) {
$pos = array_search('wp_more',$mce_buttons,true);
if ($pos !== false) {
$tmp_buttons = array_slice($mce_buttons, 0, $pos+1);
$tmp_buttons[] = 'wp_page';
$mce_buttons = array_merge($tmp_buttons, array_slice($mce_buttons, $pos+1));
}
return $mce_buttons;
}
add_filter('mce_buttons','tin_add_next_page_button');
/* 后台编辑器默认文本视图,防止修改文章切换视图导致代码转义
/* ---------------------------------------------------------- */
//add_filter('wp_default_editor', create_function('', 'return "html";'));
/* HTML转义
/* --------- */
//取消内容转义
remove_filter('the_content', 'wptexturize');
//取消摘要转义
//remove_filter('the_excerpt', 'wptexturize');
//取消评论转义
//remove_filter('comment_text', 'wptexturize');
/* 后台编辑器文本模式添加短代码快捷输入按钮
/* ------------------------------------------ */
function my_quicktags() {
wp_enqueue_script('my_quicktags',get_stylesheet_directory_uri().'/includes/js/my_quicktags.js',array('quicktags'));
}
add_action('admin_print_scripts', 'my_quicktags');
/* 增加用户资料字段
/* ------------------ */
function tin_add_contact_fields($contactmethods){
$contactmethods['tin_qq'] = 'QQ';
$contactmethods['tin_qq_weibo'] = __('腾讯微博','tinection');
$contactmethods['tin_sina_weibo'] = __('新浪微博','tinection');
$contactmethods['tin_weixin'] = __('微信二维码','tinection');
$contactmethods['tin_twitter'] = __('Twitter','tinection');
$contactmethods['tin_googleplus'] = 'Google+';
$contactmethods['tin_donate'] = __('支付宝收款二维码','tinection');
$contactmethods['tin_alipay_email'] = __('支付宝帐户','tinection');
return $contactmethods;
}
add_filter('user_contactmethods', 'tin_add_contact_fields');
/* 无缩略图时抓取第一张图片或输出随机图片
/* ------------------------------------ */
function catch_first_image(){
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = isset($matches [1] [0]) ? $matches [1] [0] : '';
if(empty($first_img)){
$categories = get_the_category();
foreach ($categories as $cat){
$catid = $cat->cat_ID;
break;
}
$random = mt_rand(1, 40);
$first_img = get_bloginfo ( 'stylesheet_directory' );
$catidstext = ot_get_option('catgorydefaultimg');
if(!empty($catidstext)){
$catids = explode (',' , $catidstext);
$numbers = count($catids);
$unmatchs = 0;
foreach ($catids as $catidsarray){
if ($catidsarray[0]==$catid){
$first_img .= '/images/cat-'.$catidsarray[0].'.jpg';
break;
}else{$unmatchs++; continue; }
}
if ($unmatchs == $numbers){
$first_img .= '/images/random/'.$random.'.jpg';
}
}
else{$first_img .= '/images/random/'.$random.'.jpg';}
}
return $first_img;
}
/* 抓取文章内视频或Meta指定视频
/* ----------------------------- */
function catch_first_embed(){
global $post;
$embed = '';
$embed_meta = get_post_meta($post->ID,'tin_video_url',true);
if($embed_meta){$embed=$embed_meta;}else{
$output = preg_match_all('/<embed.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$embed = isset($matches [1] [0]) ? $matches [1] [0] : '';
}
return $embed;
}
/* 缩略图采用类型
/* ----------------- */
function tin_thumb_source($src,$w=375,$h=250,$customize=true){
$timthumb = ot_get_option('timthumb');
$cloudimgsuffix = ot_get_option('cloudimgsuffix');
$layout = the_layout();
$blocks_style = ot_get_option('blocks_style');
$imgtype = substr($src,strrpos($src,'.'));
if($timthumb==='on'&&$imgtype!='.gif'){
$img = get_bloginfo('template_url').'/functions/timthumb.php?src='.$src.'&q=90&w='.$w.'&h='.$h.'&zc=1';
}else{
if(empty($cloudimgsuffix)||$customize==false) $cloudimgsuffix = '?imageView2/1/w/'.$w.'/h/'.$h.'/q/100';
$img = $src.$cloudimgsuffix;
}
if(is_home()&&$layout=='blocks'&&$blocks_style=='fluid_blocks'){
$img = $src;
}
return $img;
}
function tin_thumbnail(){
if ( has_post_thumbnail() ){
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
$imgsrc = $large_image_url[0];
}else{
$imgsrc = catch_first_image();
}
return $imgsrc;
}
/* 注册通用边栏
/* -------------- */
if ( ! function_exists( 'tin_custom_sidebars' ) ) {
function tin_custom_sidebars() {
if ( !ot_get_option('sidebar-areas') =='' ) {
$sidebars = ot_get_option('sidebar-areas', array());
if ( !empty( $sidebars ) ) {
foreach( $sidebars as $sidebar ) {
if ( isset($sidebar['title']) && !empty($sidebar['title']) && isset($sidebar['id']) && !empty($sidebar['id']) && ($sidebar['id'] !='sidebar-') ) {
register_sidebar(array('name' => ''.$sidebar['title'].'','id' => ''.strtolower($sidebar['id']).'','before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3><span class=widget-title>','after_title' => '</span></h3>'));
}
}
}
}
}
}
add_action( 'widgets_init', 'tin_custom_sidebars' );
/* 动态primary边栏
/* ------------------ */
if ( ! function_exists( 'tin_sidebar_primary' ) ) {
function tin_sidebar_primary() {
// Default sidebar
$sidebar = 'primary';
// Set sidebar based on page
if ( is_home() && ot_get_option('s1-home') ) $sidebar = ot_get_option('s1-home');
if ( is_single() && ot_get_option('s1-single') ) $sidebar = ot_get_option('s1-single');
if ( is_archive() && ot_get_option('s1-archive') ) $sidebar = ot_get_option('s1-archive');
if ( is_category() && ot_get_option('s1-archive-category') ) $sidebar = ot_get_option('s1-archive-category');
if ( is_search() && ot_get_option('s1-search') ) $sidebar = ot_get_option('s1-search');
if ( is_404() && ot_get_option('s1-404') ) $sidebar = ot_get_option('s1-404');
if ( is_page() && ot_get_option('s1-page') ) $sidebar = ot_get_option('s1-page');
// Check for page/post specific sidebar
if ( is_page() || is_single() ) {
// Reset post data
wp_reset_postdata();
global $post;
// Get meta
$meta = get_post_meta($post->ID,'tin_sidebar_primary',true);
if ( $meta ) { $sidebar = $meta; }
}
// Return sidebar
return $sidebar;
}
}
/* 注册页脚边栏
/* --------------- */
if ( ! function_exists( 'tin_sidebars' ) ) {
function tin_sidebars() {
register_sidebar(array( 'name' => 'Primary','id' => 'primary','description' => __("默认边栏区,请在后台设置选择各页面的边栏",'tinection'), 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3><span class=widget-title>','after_title' => '</span></h3>'));
register_sidebar(array( 'name' => 'Float','id' => 'float','description' => __("浮动边栏,容纳一定小工具,随鼠标滚动超出可视区域后将浮动重新显示",'tinection'), 'before_widget' => '<div id="%1$s" class="%2$s">','after_widget' => '</div>','before_title' => '<h3><span class=widget-title>','after_title' => '</span></h3>'));
if ( ot_get_option('footer-widgets') >= '1' ) { register_sidebar(array( 'name' => 'Footer 1','id' => 'footer-1', 'description' => __("底部多列边栏1",'tinection'), 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3><span class=widget-title>','after_title' => '</span></h3>')); }
if ( ot_get_option('footer-widgets') >= '2' ) { register_sidebar(array( 'name' => 'Footer 2','id' => 'footer-2', 'description' => __("底部多列边栏2",'tinection'), 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3><span class=widget-title>','after_title' => '</span></h3>')); }
if ( ot_get_option('footer-widgets') >= '3' ) { register_sidebar(array( 'name' => 'Footer 3','id' => 'footer-3', 'description' => __("底部多列边栏3",'tinection'), 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3><span class=widget-title>','after_title' => '</span></h3>')); }
if ( ot_get_option('footer-widgets') >= '4' ) { register_sidebar(array( 'name' => 'Footer 4','id' => 'footer-4', 'description' => __("底部多列边栏4",'tinection'), 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3><span class=widget-title>','after_title' => '</span></h3>')); }
if ( ot_get_option('footer-widgets-singlerow') == 'on' ) { register_sidebar(array( 'name' => 'Footer row','id' => 'footer-row', 'description' => __("底部通栏",'tinection'), 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3><span class=widget-title>','after_title' => '</span></h3>')); }
}
}
add_action( 'widgets_init', 'tin_sidebars' );
/* 字符串剪切
/* ------------------ */
function cut_str($src_str,$cut_length){
$return_str='';
$i=0;
$n=0;
$str_length=strlen($src_str);
while (($n<$cut_length) &&($i<=$str_length)){
$tmp_str=substr($src_str,$i,1);
$ascnum=ord($tmp_str);
if ($ascnum>=224){
$return_str=$return_str.substr($src_str,$i,3);
$i=$i+3;
$n=$n+2;
}
elseif ($ascnum>=192){
$return_str=$return_str.substr($src_str,$i,2);
$i=$i+2;
$n=$n+2;
}
elseif ($ascnum>=65 &&$ascnum<=90){
$return_str=$return_str.substr($src_str,$i,1);
$i=$i+1;
$n=$n+2;
}
else {
$return_str=$return_str.substr($src_str,$i,1);
$i=$i+1;
$n=$n+1;
}
}
if ($i<$str_length){
$return_str = $return_str .'...';
}
if (get_post_status() == 'private'){
$return_str = $return_str .'(private)';
}
return $return_str;
}
function utf8Substr($str, $from, $len){
return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'.
'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s',
'$1',$str);
}
/* 首页分页导航
/* -------------*/
function pagenavi( $before = '', $after = '', $p = 2 ) {
if ( is_singular() ) return;
global $wp_query, $paged;
$max_page = $wp_query->max_num_pages;
if ( $max_page == 1 )
return;
if ( empty( $paged ) )
$paged = 1;
// $before = "<span class='pg-item'><a href='".esc_html( get_pagenum_link( $i ) )."'>{$i}</a></span>";
echo $before;
if ( $paged > 1)
p_link( $paged - 1, '上一页', '<span class="pg-item pg-nav-item pg-prev">' ,'上一页' );
if ( $paged > $p + 1 )
p_link( 1, '首页','<span class="pg-item">',1 );
for( $i = $paged - $p; $i <= $paged + $p; $i++ ) {
if ( $i > 0 && $i <= $max_page )
$i == $paged ? print "<span class='pg-item pg-item-current'><span class='current'>{$i}</span></span>" : p_link( $i,'', '<span class="pg-item">',$i);
}
if ( $paged < $max_page - $p ) p_link( $max_page, __('末页','tinection'),'<span class="pg-item"> ... </span><span class="pg-item">',$max_page );
if ( $paged < $max_page ) p_link( $paged + 1,__('下一页','tinection'), '<span class="pg-item pg-nav-item pg-next">' ,__('下一页','tinection'));
echo $after;
}
function p_link( $i, $title = '', $linktype = '' , $prevnext='') {
if ( $title == '' ) $title = __("浏览第{$i}页",'tinection');
if ( $linktype == '' ) { $linktext = $i; } else { $linktext = $linktype; }
echo "{$linktext}<a href='", esc_html( get_pagenum_link( $i ) ), "' title='{$title}' class='navbutton'>{$prevnext}</a></span>";
}
/* AJAX更多文章
/* ------------- */
function ajaxmore(){
if ( is_singular() ) return;
global $wp_query, $paged;
$max_page = $wp_query->max_num_pages;
if ( $max_page == 1 )
return;
if ( empty( $paged ) )
$paged = 1;
if($paged<$max_page){
echo '<div class="ajax_btn"><div class="aload_loading"><img src="'.THEME_URI.'/images/loading.gif"></div><div class="aload"><a href="'.esc_html( get_pagenum_link( $paged+1 ) ).'">加载更多</a></div></div>';
}
}
/* 个人信息页页码分页导航
/* ----------------------- */
function tin_paginate($wp_query=''){
if(empty($wp_query)) global $wp_query;
$pages = $wp_query->max_num_pages;
if ( $pages >= 2 ):
$big = 999999999;
$paginate = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $pages,
'type' => 'array'
) );
echo '<div class="pagination">';
foreach ($paginate as $value) {
echo '<span class="pg-item">'.$value.'</span>';
}
echo '</div>';
endif;
}
/* 个人信息页页码带下拉分页导航
/* ------------------------------ */
function tin_pager($current, $max){
$paged = intval($current);
$pages = intval($max);
if($pages<2) return '';
$pager = '<div class="pagination">';
$pager .= '<div class="btn-group">';
if($paged>1) $pager .= '<a class="btn btn-default" style="float:left;padding:6px 12px;" href="' . add_query_arg('page',$paged-1) . '">'.__('上一页','tinection').'</a>';
if($paged<$pages) $pager .= '<a class="btn btn-default" style="float:left;padding:6px 12px;" href="' . add_query_arg('page',$paged+1) . '">'.__('下一页','tinection').'</a>';
if ($pages>2 ){
$pager .= '<div class="btn-group pull-right"><select class="form-control pull-right" onchange="document.location.href=this.options[this.selectedIndex].value;">';
for( $i=1; $i<=$pages; $i++ ){
$class = $paged==$i ? 'selected="selected"' : '';
$pager .= sprintf('<option %s value="%s">%s</option>', $class, add_query_arg('page',$i), sprintf(__('第 %s 页','tinection'), $i));
}
$pager .= '</select></div>';
}
$pager .= '</div></div>';
return $pager;
}
/* 首页布局
/* ----------- */
function the_layout(){
$layout = 'blog';
if(isset($_GET['layout'])){
$layout = $_GET['layout'];
}elseif(ot_get_option('layout')){
$layout = ot_get_option('layout');
}else{
$layout = 'blog';
}
if(tin_is_mobile()) $layout = 'blog';
return $layout;
}
/* 简单相关文章(用于邮件)
/* ------------------------------ */
function tin_mail_relatedpost($postid){
$tags = wp_get_post_tags($postid);
$tagIDs = array();
if ($tags) {$tagcount = count($tags);for ($i = 0;$i <$tagcount;$i++) {$tagIDs[$i] = $tags[$i]->term_id;}
$args=array(
'tag__in'=>$tagIDs,
'post__not_in'=>array($postid),
'showposts'=>5,
'orderby'=>'rand',
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {$related = '<h3 style="padding-left:10px;margin:10px 0 5px;font-size:16px;font-weight:bold;border-left:3px solid #1cbdc5;line-height:25px;height:25px;">'.__('相关文章','tinection').'</h3><ul>';
while ($my_query->have_posts()) : $my_query->the_post(); $related .= '<li style="list-style:circle;font-size:13px;"><a style="color:#1cbdc5;font-size:13px;font-family:微软雅黑,Microsoft Yahei;" href="'; $related .= get_permalink(); $related .= '" rel="bookmark" title="'; $related .= get_the_title($post->ID);$related .= '">'; $related .= get_the_title($post->ID); $related .= ' ( '; $related .= get_comments_number($post->ID); $related .= ' ) '; $related .= '</a></li>';endwhile; $related .= '</ul>';}}
return $related;
}
/* 加密文章
/* --------- */
function password_hint( $c ){
global $post, $user_ID, $user_identity;
if ( empty($post->post_password) )
return $c;
if ( isset($_COOKIE['wp-postpass_'.COOKIEHASH]) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) == $post->post_password )
return $c;
if($hint = get_post_meta($post->ID, 'password_hint', true)){
$url = get_option('siteurl').'/wp-pass.php';
if($hint)
$hint = __('密码提示:','tinection').$hint;
else
$hint = __("请输入您的密码",'tinection');
if($user_ID)
$hint .= sprintf(__('欢迎进入,您的密码是:','tinection'), $user_identity, $post->post_password);
$out = <<<END
<form method="post" action="$url">
<p>__('这篇文章是受保护的文章,请输入密码继续阅读:','tinection')</p>
<div>
<label>$hint<br/>
<input type="password" name="post_password"/></label>
<input type="submit" value="__('输入密码','tinection')" name="Submit"/>
</div>
</form>
END;
return $out;
}else{
return $c;
}
}
add_filter('the_content', 'password_hint');
/* 页面meta信息条
/* --------------- */
function tin_post_meta($special=0){
$thelayout = the_layout();
if(is_singular()){ ?>
<div id="single-meta">
<span class="single-meta-author"><i class="fa fa-user"> </i><?php the_author_posts_link();?></span>
<span class="single-meta-time"><i class="fa fa-calendar"> </i><?php echo timeago( get_gmt_from_date(get_the_time('Y-m-d G:i:s')) ) ?></span>
<?php if(is_single()){ ?><span class="single-meta-category"><i class="fa fa-folder-open"> </i><?php the_category(' ',''); ?></span><?php } ?>
<?php if ( current_user_can('level_7') ){ ?><span class="single-meta-edit"><i class="fa fa-edit"> </i><?php edit_post_link(__(' 编辑 ','tinection')); ?></span><?php } ?>
<span class="single-meta-comments"><?php if ( comments_open() ): ?>| <i class="fa fa-comments"></i> <a href="#" class="commentbtn"><?php comments_number( __('抢沙发','tinection'), __('1 条评论','tinection'), __('% 条评论','tinection') ); ?></a><?php else:?>| <i class="fa fa-comments"></i><?php _e(' 评论关闭','tinection'); ?><?php endif; ?></span>
<span class="single-meta-views"><i class="fa fa-fire"></i> <?php echo get_tin_traffic( 'single' , get_the_ID() ); ?> </span>
</div>
<?php }elseif(is_search() || (is_home() && $thelayout == 'blog') || (is_category() && $special==0) || is_tag() || is_date() ){ ?>
<div class="meta">
<?php if(!is_category()){ ?><span class="postlist-meta-cat"><i class="fa fa-bookmark"></i><?php the_category(' ', false); ?></span><?php } ?>
<span class="postlist-meta-time"><i class="fa fa-calendar"></i><?php echo timeago( get_gmt_from_date(get_the_time('Y-m-d G:i:s')) ); ?></span>
<span class="postlist-meta-views"><i class="fa fa-fire"></i><?php echo '浏览: '.get_tin_traffic( 'single' , get_the_ID() ); ?></span>
<span class="postlist-meta-comments"><?php if ( comments_open() ): ?><i class="fa fa-comments"></i><a href="<?php comments_link(); ?>"><?php comments_number( __('<span>评论: </span>0','tinection'), __('<span>评论: </span>1','tinection'), __('<span>评论: </span>%','tinection') ); ?></a><?php endif; ?></span>
</div>
<?php }elseif((is_home()) || (is_category() && $special==1)){ ?>
<div class="postlist-meta">
<div class="postlist-meta-time"><i class="fa fa-calendar"></i> <?php echo date('Y-m-j',get_the_time('U'));?></div>
<div class="postlist-meta-views" style="float:right;"><i class="fa fa-fire"></i> <?php echo get_tin_traffic( 'single' , get_the_ID() ); ?></div>
<?php get_template_part('includes/like_collect_meta'); ?>
</div>
<?php }else{ ?>
<div id="single-meta">
<span class="single-meta-author"><i class="fa fa-user"> </i><?php the_author_posts_link();?></span>
<span class="single-meta-edit"><?php edit_post_link(__(' 编辑 ','tinection')); ?></span>
<span class="single-meta-time"><i class="fa fa-calendar"> </i><?php echo timeago( get_gmt_from_date(get_the_time('Y-m-d G:i:s')) ) ?></span>
<span class="single-meta-comments"><?php if ( comments_open() ): ?>| <i class="fa fa-comments"></i> <a href="<?php comments_link(); ?>"><?php comments_number( __('0 条评论','tinection'), __('1 条评论','tinection'), __('% 条评论','tinection') ); ?></a><?php else:?>| <i class="fa fa-comments"></i><?php _e(' 评论关闭','tinection'); ?><?php endif; ?></span>
<span class="single-meta-views"><i class="fa fa-fire"></i> <?php echo get_tin_traffic( 'single' , get_the_ID() ); ?> </span>
</div>
<?php }
}
/* 时间显示方式xx以前
/* -------------------- */
function time_ago( $type = 'commennt', $day = 7 ) {
$d = $type == 'post' ? 'get_post_time' : 'get_comment_time';
if (time() - $d('U') > 60*60*24*$day) return;
echo human_time_diff($d('U'), strtotime(current_time('mysql', 0))), '前';
}
function timeago( $ptime ) {
date_default_timezone_set ('ETC/GMT');
$ptime = strtotime($ptime);
$etime = time() - $ptime;
if($etime < 1) return '刚刚';
$interval = array (
12 * 30 * 24 * 60 * 60 => '年前 ('.date('Y-m-d', $ptime).')',
30 * 24 * 60 * 60 => '个月前 ('.date('m-d', $ptime).')',
7 * 24 * 60 * 60 => '周前 ('.date('m-d', $ptime).')',
24 * 60 * 60 => '天前',
60 * 60 => '小时前',
60 => '分钟前',
1 => '秒前'
);
foreach ($interval as $secs => $str) {
$d = $etime / $secs;
if ($d >= 1) {
$r = round($d);
return $r . $str;
}
};
}
/* 输出页脚版权年份
/* ----------------- */
function tin_copyright_year(){
$u = ot_get_option('sitebuild_date');
$ny = date('Y');
$year=((int)substr($u,0,4));
if(empty($u)){
$sy=$ny;
}else{
$sy=$year;
}
return ' '.$sy.' - '.$ny.' ';
}
/* 文章目录
/* ----------- */
function content_index($content) {
if(is_single()){
$matches = array();
$ul_li = '';
$r = "/<h2>([^<]+)<\/h2>/im";
$dlinks = get_post_meta(get_the_ID(),'tin_dload',true);
$demos = get_post_meta(get_the_ID(),'tin_demo',true);
$saledl = get_post_meta(get_the_ID(),'tin_saledl',true);
if(preg_match_all($r, $content, $matches)) {
foreach($matches[1] as $num => $title) {
$content = str_replace($matches[0][$num], '<h2 id="title-'.$num.'">'.$title.'</h2>', $content);
$ul_li .= '<li><a href="#title-'.$num.'" title="'.$title.'">'.$title."</a></li>\n";
}
if((!empty($dlinks) || !empty($saledl)) && !empty($demos)){
$ul_li .= '<li><a href="#title-last" title="'.__('演示与下载','tinection').'">'.__('演示与下载','tinection').'</a></li>';
}
if((!empty($dlinks) || !empty($saledl)) && empty($demos)){
$ul_li .= '<li><a href="#title-last" title="'.__('相关下载','tinection').'">'.__('相关下载','tinection').'</a></li>';
}
if(empty($dlinks) && empty($saledl) && !empty($demos)){
$ul_li .= '<li><a href="#title-last" title="'.__('相关演示','tinection').'">'.__('相关演示','tinection').'</a></li>';
}
$content = "\n<div id=\"content-index-wrap\"><div id=\"content-index\">
<span id=\"content-index-control\" class=\"open\">[".__('收起','tinection')."]</span>
<b>文章目录</b>
<ul id=\"index-ul\">\n" . $ul_li . "</ul>
</div></div>\n" . $content;
}
}
return $content;
}
add_filter( "the_content", "content_index", 13 );
/* 文章图片添加 Lightbox 类,用于图片暗箱
/* -------------------------------- */
function lightbox_gall_replace ($content){
global $post;
$pattern = "/<a(.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>(.*?)<\/a>/i";
$replacement = '<a$1href=$2$3.$4$5 class="prettyPhoto_gall" rel="prettyPhoto[gallery1]"$6>$7</a>';
$content = preg_replace($pattern, $replacement, $content);
// $pattern2 = "/<img(.*?)src=('|\")([^>]*).(bmp|gif|jpeg|jpg|png)('|\")(.*?)\>/i";
// $replacement2 = '<a href=$2$3.$4$5 class="pirobox_gall"><img$1src=$2$3.$4$5 $6></a>';
// $content = preg_replace($pattern2, $replacement2, $content);
return $content;
}
add_filter('the_content', 'lightbox_gall_replace', 98);
/* WordPress文字标签关键词自动内链
/* --------------------------------- */
$match_num_from = 1; //一篇文章中同一個標籤少於幾次不自動鏈接
$match_num_to = 4; //一篇文章中同一個標籤最多自動鏈接幾次
function tag_sort($a, $b){
if ( $a->name == $b->name ) return 0;
return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1;
}
function tin_tag_link($content){
global $match_num_from,$match_num_to;
$posttags = get_the_tags();
if ($posttags) {
usort($posttags, "tag_sort");
$ex_word = '';
$case = '';
foreach($posttags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;
$cleankeyword = stripslashes($keyword);
$url = "<a href=\"$link\" class=\"tooltip-trigger tin\" title=\"".str_replace('%s',addcslashes($cleankeyword, '$'),__('查看更多关于 %s 的文章'))."\"";
$url .= ' target="_blank"';
$url .= ">".addcslashes($cleankeyword, '$')."</a>";
$limit = rand($match_num_from,$match_num_to);
$content = preg_replace( '|(<a[^>]+>)(.*)<pre.*?>('.$ex_word.')(.*)<\/pre>(</a[^>]*>)|U'.$case, '$1$2$4$5', $content);
$content = preg_replace( '|(<img)(.*?)('.$ex_word.')(.*?)(>)|U'.$case, '$1$2$4$5', $content);
$cleankeyword = preg_quote($cleankeyword,'\'');
$regEx = '\'(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case;
$content = preg_replace($regEx,$url,$content,$limit);
$content = str_replace( '', stripslashes($ex_word), $content);
}
}
return $content;
}
add_filter('the_content','tin_tag_link',12);
/* 文章图片自动添加alt和title信息
/* -------------------------------- */
function tin_image_alt($content){
global $post;
$pattern = "/<img(.*?)src=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<img$1src=$2$3.$4$5 alt="'.$post->post_title.'" title="'.$post->post_title.'"$6>';
$content = preg_replace($pattern,$replacement,$content);
return $content;
}
add_filter('the_content','tin_image_alt',15);
/* 高亮显示搜索关键词
/* ------------------- */
function search_word_replace($buffer){
if(is_search()){
$arr=explode(' ',get_search_query());
foreach($arr as $v){
if($v)$buffer=preg_replace('/('.$v.')/i',"<span style='color:#f00;font-weight:bold'>$1</span>",$buffer);
}
}
return $buffer;
}
/* 输出文章版权信息
/* ------------------ */
function tin_post_copyright($post_id){
$post_id = (int)$post_id;
if(!$post_id) return;
$cc = get_post_meta( $post_id, 'tin_copyright_content', true );
$cc = empty($cc) ? ot_get_option('tin_copyright_content_default') : $cc;
$cc = stripcslashes(htmlspecialchars_decode($cc));
if($cc){ ?>
<div class="sg-cp">
<i class="fa fa-bullhorn"> </i>
<?php
$cc = str_replace(array( '{name}', '{url}', '{title}', '{link}'), array(get_bloginfo('name'), home_url('/'), get_the_title($post_id), get_permalink($post_id)), $cc);
echo $cc;
?>
</div>
<?php }
}
/* 作者类别
/* ----------------- */
function the_user_level(){
$user_id=get_post($id)->post_author;
if(user_can($user_id,'install_plugins')){_e('管理员','tinection');}
elseif(user_can($user_id,'edit_others_posts')){_e('编辑','tinection');}elseif(user_can($user_id,'publish_posts')){_e('作者','tinection');}elseif(user_can($user_id,'delete_posts')){_e('投稿者','tinection');}elseif(user_can($user_id,'read')){_e('订阅者','tinection');}
}
/* 文章类型适配图标
/* ----------------- */
function the_article_icon(){
if ( is_sticky() ){echo '<i class="fa fa-star"></i>';}
elseif(get_post_type()=='store'){echo '<i class="fa fa-shopping-cart"></i>';}
elseif ( has_post_format('audio') ){echo '<i class="fa fa-headphones"></i>';}
elseif ( has_post_format('aside') ){echo '<i class="fa fa-pencil"></i>';}
elseif ( has_post_format('chat') ){echo '<i class="fa fa-comments-o"></i>';}
elseif ( has_post_format('gallery') ){echo '<i class="fa fa-picture-o"></i>';}
elseif ( has_post_format('image') ){echo '<i class="fa fa-camera"></i>';}
elseif ( has_post_format('link') ){echo '<i class="fa fa-link"></i>';}
elseif ( has_post_format('quote') ){echo '<i class="fa fa-quote-left"></i>';}
elseif ( has_post_format('status') ){echo '<i class="fa fa-bullhorn"></i>';}
elseif ( has_post_format('video') ){echo '<i class="fa fa-video-camera"></i>';}
else{echo'<i class="fa fa-expand"></i>';}
}
/* 点击评分
/* -------------- */
function tin_refresh_rate(){
$sid = $_POST['sid'];
$pid = $_POST['pid'];
$rating = get_post_meta($pid,'tin_rating',true);
$rating_array = explode(',',$rating);
$rateone = $rating_array[0];
$ratetwo = $rating_array[1];
$ratethree = $rating_array[2];
$ratefour = $rating_array[3];
$ratefive = $rating_array[4];
$rateaverage = get_post_meta($pid,'tin_rating_average',true);
empty($rateone)?$rateone=0:$rateone=$rateone;
empty($ratetwo)?$ratetwo=0:$ratetwo=$ratetwo;
empty($ratethree)?$ratethree=0:$ratethree=$ratethree;
empty($ratefour)?$ratefour=0:$ratefour=$ratefour;
empty($ratefive)?$ratefive=0:$ratefive=$ratefive;
empty($rateaverage)?$rateaverage=0:$rateaverage=$rateaverage;
$ratetimes = $rateone + $ratetwo + $ratethree + $ratefour + $ratefive;
$ratetimes++;
$ratescore = $rateone*1 + $ratetwo*2 + $ratethree*3 + $ratefour*4 + $ratefive*5;
switch($sid){
case 'starone':
$rated = $rateone;
$rated++;
$ra = ($ratescore+1)/$ratetimes;
$ratearr = array($rated,$ratetwo,$ratethree,$ratefour,$ratefive);
$ratestr = implode(',',$ratearr);
update_post_meta($pid,'tin_rating',$ratestr);
update_post_meta($pid,'tin_rating_average',$ra);