-
Notifications
You must be signed in to change notification settings - Fork 3
/
functions.php
2058 lines (1551 loc) · 64.4 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
/**
* Shiword functions and definitions.
*
* Sets up the theme and provides some helper functions, which are used
* in the theme as custom template tags. Others are attached to action and
* filter hooks in WordPress to change core functionality.
*
* When using a child theme (see http://codex.wordpress.org/Theme_Development and
* http://codex.wordpress.org/Child_Themes), you can override certain functions
* (those wrapped in a function_exists() call) by defining them first in your child theme's
* functions.php file. The child theme's functions.php file is included before the parent
* theme's file, so the child theme functions would be used.
*
* Functions that are not pluggable (not wrapped in function_exists()) are instead attached
* to a filter or action hook.
*
* For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
*
* @package Shiword
* @since 1.0
*/
/* Custom actions - WP hooks */
add_action( 'after_setup_theme' , 'shiword_setup' );
add_action( 'wp_enqueue_scripts' , 'shiword_stylesheet' );
add_action( 'wp_enqueue_scripts' , 'shiword_scripts' );
add_action( 'template_redirect' , 'shiword_allcat' );
add_action( 'wp_head' , 'shiword_ie6_style' );
add_action( 'wp_print_styles' , 'shiword_deregister_styles', 100 );
add_action( 'admin_bar_menu' , 'shiword_admin_bar_plus', 999 );
add_action( 'comment_form_before' , 'shiword_enqueue_comments_reply' );
add_action( 'wp_head' , 'shiword_microdata' );
/* Custom actions - theme hooks */
add_action( 'shiword_hook_body_top' , 'shiword_detect_js' );
add_action( 'shiword_hook_like_it' , 'shiword_like_it' );
add_action( 'shiword_hook_header_after' , 'shiword_main_menu', 11 );
add_action( 'shiword_hook_comments_list_before' , 'shiword_navigate_comments' );
add_action( 'shiword_hook_comments_list_after' , 'shiword_navigate_comments' );
add_action( 'shiword_hook_comments_list_after' , 'shiword_list_pings' );
add_action( 'shiword_hook_attachment_before' , 'shiword_navigate_images' );
/* Custom filters - WP hooks */
add_filter( 'embed_oembed_html' , 'shiword_wmode_transparent', 10, 3);
add_filter( 'excerpt_length' , 'shiword_excerpt_length' );
add_filter( 'excerpt_mblength' , 'shiword_excerpt_length' );
add_filter( 'get_comment_author_link' , 'shiword_add_quoted_on' );
add_filter( 'img_caption_shortcode' , 'shiword_img_caption_shortcode', 10, 3 );
add_filter( 'get_comments_number' , 'shiword_comment_count', 0);
add_filter( 'the_title' , 'shiword_title_tags_filter', 10, 2 );
add_filter( 'excerpt_more' , 'shiword_new_excerpt_more' );
add_filter( 'the_content_more_link' , 'shiword_more_link', 10, 2 );
add_filter( 'get_search_form' , 'shiword_search_form' );
add_filter( 'post_gallery' , 'shiword_gallery_shortcode', 10, 2 );
add_filter( 'use_default_gallery_style' , '__return_false' );
add_filter( 'wp_title' , 'shiword_filter_wp_title', 10, 2 );
add_filter( 'body_class' , 'shiword_filter_body_class' );
add_filter( 'comment_form_default_fields' , 'shiword_comments_form_fields' );
add_filter( 'comment_form_defaults' , 'shiword_comment_form_defaults' );
add_filter( 'the_content' , 'shiword_quote_content' );
add_filter( 'page_css_class' , 'shiword_add_parent_class', 10, 4 );
add_filter( 'wp_nav_menu_objects' , 'shiword_add_menu_parent_class' );
add_filter( 'wp_list_categories' , 'shiword_wrap_categories_count' );
add_filter( 'wp_nav_menu_items' , 'shiword_add_home_link', 10, 2 );
/* load options */
$shiword_opt = get_option( 'shiword_options' );
/* theme infos */
function shiword_get_info( $field ) {
static $infos;
if ( !isset( $infos ) ) {
$infos['theme'] = wp_get_theme( 'shiword' );
$infos['current_theme'] = wp_get_theme();
$infos['version'] = $infos['theme']? $infos['theme']['Version'] : '';
}
return $infos[$field];
}
/* load modules (accordingly to http://justintadlock.com/archives/2010/11/17/how-to-load-files-within-wordpress-themes) */
require_once( 'lib/options.php' ); // load theme default options
require_once( 'lib/widgets.php' ); // load custom widgets module
$shiword_is_mobile = false;
require_once( 'mobile/core-mobile.php' ); // load mobile functions
require_once( 'lib/custom-device-color.php' ); // load custom colors module
require_once( 'lib/my-custom-background.php' ); // load custom background module
require_once( 'lib/admin.php' ); // load admin stuff
require_once( 'lib/slider.php' ); // load slider stuff
require_once( 'lib/hooks.php' ); // load custom hooks
require_once( 'lib/breadcrumb.php' ); // load the breadcrumb module
require_once( 'quickbar.php' ); // load quickbar functions
require_once( 'lib/plugins.php' ); // plugins support
/* conditional tags */
function shiword_is_mobile() { // mobile
global $shiword_is_mobile;
return $shiword_is_mobile;
}
function shiword_is_printpreview() { //print preview
static $is_printpreview;
if ( !isset( $is_printpreview ) ) {
$is_printpreview = isset( $_GET['style'] ) && md5( $_GET['style'] ) == '8e77921d24c6f82c4bd783895e9d9cf1' ? true : false;
}
return $is_printpreview;
}
function shiword_is_allcat() { //is "all category" page
static $is_allcat;
if ( !isset( $is_allcat ) ) {
$is_allcat = isset( $_GET['allcat'] ) && md5( $_GET['allcat'] ) == '415290769594460e2e485922904f345d' ? true : false;
}
return $is_allcat;
}
// Set the content width based on the theme's design
if ( ! isset( $content_width ) )
$content_width = shiword_get_opt( 'shiword_frame_width' ) - 290;
// skip every sidebar if in print preview
if ( !function_exists( 'shiword_get_sidebar' ) ) {
function shiword_get_sidebar( $name = 'primary' ) {
if ( $name == 'primary' && shiword_get_layout() == 'wide' ) return;
if ( apply_filters( 'shiword_skip_' . $name . '_widgets_area', false ) ) return;
get_sidebar( $name );
}
}
// Add stylesheets to page
function shiword_stylesheet(){
if ( is_admin() ) return;
if ( shiword_is_mobile() ) return;
//shows print preview / normal view
if ( shiword_is_printpreview() ) { //print preview
wp_enqueue_style( 'shiword-print-style-preview', get_template_directory_uri() . '/css/print.css', false, shiword_get_info( 'version' ), 'screen' );
wp_enqueue_style( 'shiword-general-style-preview', get_template_directory_uri() . '/css/print_preview.css', false, shiword_get_info( 'version' ), 'screen' );
} else { //normal view
if ( shiword_get_opt( 'shiword_thickbox' ) ) wp_enqueue_style( 'thickbox' ); //thickbox style
wp_enqueue_style( 'shiword-general-style', get_stylesheet_uri(), false, shiword_get_info( 'version' ), 'screen' );
if ( shiword_get_opt( 'shiword_adaptive' ) ) wp_enqueue_style( 'shiword-adaptive-layout', get_template_directory_uri() . '/css/adaptive-layout.css', false, shiword_get_info( 'version' ), 'screen' );
}
//google font
if ( shiword_get_opt( 'shiword_google_font_family' ) ) wp_enqueue_style( 'shiword-google-fonts', '//fonts.googleapis.com/css?family=' . urlencode( shiword_get_opt( 'shiword_google_font_family' ) ) );
//print style
wp_enqueue_style( 'shiword-print-style', get_template_directory_uri() . '/css/print.css', false, shiword_get_info( 'version' ), 'print' );
}
function shiword_ie6_style() {
?>
<!--[if lte IE 6]><link media="screen" rel="stylesheet" href="<?php echo esc_url( get_template_directory_uri() . '/css/ie6.css' ); ?>" type="text/css" /><![endif]-->
<?php
}
// deregister style for WP-Pagenavi plugin (if installed)
function shiword_deregister_styles() {
wp_deregister_style( 'wp-pagenavi' );
}
// get js modules
function shiword_get_js_modules() {
$modules[] = 'widgets_style';
if ( shiword_get_opt( 'shiword_basic_animation_main_menu' ) ) $modules[] = 'main_menu';
if ( shiword_get_opt( 'shiword_basic_animation_navigation_buttons' ) ) $modules[] = 'navigation_buttons';
if ( shiword_get_opt( 'shiword_basic_animation_quickbar_panels' ) ) $modules[] = 'quickbar_panels';
if ( shiword_get_opt( 'shiword_basic_animation_entry_meta' ) ) $modules[] = 'entry_meta';
if ( shiword_get_opt( 'shiword_basic_animation_smooth_scroll' ) ) $modules[] = 'smooth_scroll';
if ( shiword_get_opt( 'shiword_basic_animation_resize_video' ) ) $modules[] = 'resize_video';
if ( shiword_get_opt( 'shiword_tinynav' ) ) $modules[] = 'tinynav';
if ( shiword_get_opt( 'shiword_sticky' ) ) $modules[] = 'slider';
if ( shiword_get_opt( 'shiword_qbar_minilogin' ) ) $modules[] = 'minilogin';
if ( shiword_get_opt( 'shiword_thickbox' ) ) $modules[] = 'thickbox';
if ( shiword_get_opt( 'shiword_quotethis' ) && is_singular() ) $modules[] = 'quote_this';
$modules = implode( ',', $modules);
return apply_filters( 'shiword_filter_js_modules', $modules );
}
// add scripts
if ( !function_exists( 'shiword_scripts' ) ) {
function shiword_scripts(){
if ( shiword_is_mobile() || is_admin() || shiword_is_printpreview() || ! shiword_get_opt( 'shiword_jsani' ) ) return;
//thickbox script
if ( shiword_get_opt( 'shiword_thickbox' ) ) wp_enqueue_script( 'thickbox' );
//tinynav script
if ( shiword_get_opt( 'shiword_tinynav' ) ) wp_enqueue_script( 'shiword-tinynav', get_template_directory_uri().'/js/tinynav/tinynav.min.js', array( 'jquery' ), shiword_get_info( 'version' ), true );
wp_enqueue_script( 'shiword-script', get_template_directory_uri().'/js/animations.min.js', array( 'jquery', 'hoverIntent' ), shiword_get_info( 'version' ), true ); //shiword js
$data = array(
'script_modules' => shiword_get_js_modules(),
'slider_speed' => shiword_get_opt( 'shiword_sticky_speed' ) ? shiword_get_opt( 'shiword_sticky_speed' ) : '2500',
'slider_pause' => shiword_get_opt( 'shiword_sticky_pause' ) ? shiword_get_opt( 'shiword_sticky_pause' ) : '2000',
'post_expander_wait' => esc_js( __( 'Post loading, please wait...', 'shiword' ) ),
'quote_link_text' => esc_js ( __( 'Quote', 'shiword' ) ),
'quote_link_info' => esc_attr( __( 'Add selected text as a quote', 'shiword' ) ),
'quote_link_alert' => esc_js( __( 'Nothing to quote. First of all you should select some text...', 'shiword' ) )
);
wp_localize_script( 'shiword-script', 'shiword_l10n', $data );
}
}
// detect js
function shiword_detect_js(){
?>
<script type="text/javascript">
/* <![CDATA[ */
(function(){
var c = document.body.className;
c = c.replace(/sw-no-js/, 'sw-js');
document.body.className = c;
})();
/* ]]> */
</script>
<?php
}
//enqueue the 'comment-reply' script when needed
function shiword_enqueue_comments_reply() {
if( get_option( 'thread_comments' ) )
wp_enqueue_script( 'comment-reply' );
}
// show all categories list (redirect to allcat.php if allcat=y)
if ( !function_exists( 'shiword_allcat' ) ) {
function shiword_allcat () {
if ( shiword_is_allcat() ) {
locate_template( array( 'allcat.php' ), true, false );
exit;
}
}
}
// print the next/prev post links
if ( !function_exists( 'shiword_navlinks' ) ) {
function shiword_navlinks( $position = 'top' ) {
if ( ! shiword_get_opt( 'shiword_navlinks' ) ) return;
$sep = ( get_next_post() && get_previous_post() ) ? ' - ' : '';
?>
<div class="sw-navlinks-<?php echo $position; ?>">
<?php previous_post_link( '<span class="prev">« %link</span>' ); ?>
<?php echo $sep; ?>
<?php next_post_link( '<span class="next">%link »</span>' ); ?>
<div class="fixfloat"> </div>
</div>
<?php
}
}
// print the next/prev posts page links
if ( !function_exists( 'shiword_paged_navi' ) ) {
function shiword_paged_navi() {
global $paged, $wp_query;
if ( ! shiword_get_opt( 'shiword_navlinks' ) ) return;
if ( !$paged )
$paged = 1;
if ( function_exists( 'wp_pagenavi' ) ) {
$links = wp_pagenavi( array( 'echo' => false ) );
} else {
$links = sprintf( '<span>' . __( 'page %1$s of %2$s', 'shiword' ) . '</span>', $paged, $wp_query->max_num_pages );
if ( shiword_get_opt( 'shiword_navlinks' ) )
$links = get_previous_posts_link( '«' ) . $links . get_next_posts_link( '»' );
}
?>
<div class="navigate_comments hide-if-infinite">
<?php echo apply_filters( 'shiword_filter_paged_navi', $links ); ?>
</div>
<?php
}
}
// comments navigation links
function shiword_navigate_comments() {
if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) {
?>
<div class="navigate_comments">
<?php paginate_comments_links(); ?>
</div>
<?php
}
}
// images navigation links
function shiword_navigate_images() {
global $post;
$attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );
foreach ( $attachments as $key => $attachment ) {
if ( $attachment->ID == $post->ID )
break;
}
$prev_k = $key - 1;
$next_k = $key + 1;
$prev_image = ( isset( $attachments[ $prev_k ] ) ) ? '<a class="size-thumbnail" href="' . esc_url( get_attachment_link( $attachments[ $prev_k ]->ID ) ) . '">« ' . wp_get_attachment_image( $attachments[ $prev_k ]->ID, array( 50, 50 ) ) . '</a>' : '';
$next_image = ( isset( $attachments[ $next_k ] ) ) ? '<a class="size-thumbnail" href="' . esc_url( get_attachment_link( $attachments[ $next_k ]->ID ) ) . '">' . wp_get_attachment_image( $attachments[ $next_k ]->ID, array( 50, 50 ) ) . ' »</a>' : '';
?>
<div class="img-navi">
<?php echo $prev_image; ?>
<span class="img-navi-curimg"><?php echo wp_get_attachment_image( $post->ID, array( 50, 50 ) ); ?></span>
<?php echo $next_image; ?>
</div>
<?php
}
// pings list
function shiword_list_pings() {
global $post;
$comments_by_type = &separate_comments( get_comments( 'status=approve&post_id=' . $post->ID ) );
if ( ! empty( $comments_by_type['pings'] ) ) {
?>
<ol class="commentlist pings">
<?php wp_list_comments( 'type=pings' ); ?>
</ol>
<?php
}
}
// page hierarchy
if ( !function_exists( 'shiword_multipages' ) ) {
function shiword_multipages( $r_pos ){
global $post;
$args = array(
'post_type' => 'page',
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order',
'numberposts' => 0,
);
$childrens = get_posts( $args ); // retrieve the child pages
$the_parent_page = $post->post_parent; // retrieve the parent page
$has_herarchy = false;
if ( ( $childrens ) || ( $the_parent_page ) ){ // add the hierarchy metafield ?>
<div class="metafield">
<div class="metafield_trigger mft_hier" style="right: <?php echo $r_pos; ?>px; width:16px"> </div>
<div class="metafield_content">
<?php
if ( $the_parent_page ) {
$the_parent_link = '<a href="' . esc_url( get_permalink( $the_parent_page ) ) . '" title="' . esc_attr( strip_tags( get_the_title( $the_parent_page ) ) ) . '">' . get_the_title( $the_parent_page ) . '</a>';
echo __( 'Parent page', 'shiword' ) . ': ' . $the_parent_link ; // echoes the parent
}
if ( ( $childrens ) && ( $the_parent_page ) ) { echo ' - '; } // if parent & child, echoes the separator
if ( $childrens ) {
$the_child_list = '';
foreach ( $childrens as $children ) {
$the_child_list[] = '<a href="' . esc_url( get_permalink( $children ) ) . '" title="' . esc_attr( strip_tags( get_the_title( $children ) ) ) . '">' . get_the_title( $children ) . '</a>';
}
$the_child_list = implode( ', ' , $the_child_list );
echo __( 'Child pages', 'shiword' ) . ': ' . $the_child_list; // echoes the childs
}
?>
</div>
</div>
<?php
$has_herarchy = true;
}
return $has_herarchy;
}
}
//add "like" badges to post/page
function shiword_like_it(){
$text = apply_filters( 'shiword_like_it', '' );
if ( $text )
echo '<div class="sw-I-like-it">' . $text . '<div class="fixfloat"> </div></div>';
}
// print extra info for posts/pages
if ( !function_exists( 'shiword_extrainfo' ) ) {
function shiword_extrainfo( $args = '' ) {
$defaults = array(
'auth' => 1,
'date' => 1,
'comms' => 1,
'tags' => 1,
'cats' => 1,
'hiera' => 1,
'in_index' => 1,
);
$args = wp_parse_args( $args, $defaults );
//xinfos disabled when...
if ( ! shiword_get_opt( 'shiword_xinfos_global' ) ) return; //xinfos globally disabled
if ( is_front_page() && ( get_option( 'show_on_front' ) == 'page' ) ) return; // is front page
if ( ! is_singular() && ! shiword_get_opt( 'shiword_xinfos' ) ) return; // !'in posts index' + is index
if ( ! is_singular() && ! $args['in_index'] ) return; // !'in_index' + is index
$r_pos = 10;
// animated xinfos
if ( ! shiword_get_opt( 'shiword_xinfos_static' ) ) {
?>
<div class="meta_container">
<div class="meta top_meta ani_meta">
<?php
// author
if ( $args['auth'] && ( shiword_get_opt( 'shiword_byauth' ) ) ) { ?>
<?php $post_auth = ( $args['auth'] === 1 ) ? '<a class="author vcard" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '" title="' . esc_attr( sprintf( __( 'View all posts by %s', 'shiword' ), get_the_author() ) ) . '">' . get_the_author() . '</a>' : $args['auth']; ?>
<div class="metafield_trigger" style="left: 10px;"><?php printf( __( 'by %s', 'shiword' ), $post_auth ); ?></div>
<?php
}
// categories
if ( $args['cats'] && ( shiword_get_opt( 'shiword_xinfos_cat' ) ) ) {
?>
<div class="metafield">
<div class="metafield_trigger mft_cat" style="right: <?php echo $r_pos; ?>px; width:16px"> </div>
<div class="metafield_content">
<?php echo __( 'Categories', 'shiword' ) . ': '; ?>
<?php the_category( ', ' ); ?>
</div>
</div>
<?php
$r_pos = $r_pos + 30;
}
// tags
if ( $args['tags'] && ( shiword_get_opt( 'shiword_xinfos_tag' ) ) ) {
?>
<div class="metafield">
<div class="metafield_trigger mft_tag" style="right: <?php echo $r_pos; ?>px; width:16px"> </div>
<div class="metafield_content">
<?php echo __( 'Tags', 'shiword' ) . ': '; ?>
<?php if ( !get_the_tags() ) { _e( 'No Tags', 'shiword' ); } else { the_tags( '', ', ', '' ); } ?>
</div>
</div>
<?php
$r_pos = $r_pos + 30;
}
// comments
$page_cd_nc = ( is_page() && !comments_open() && !have_comments() ); //true if page with comments disabled and no comments
if ( $args['comms'] && ( shiword_get_opt( 'shiword_xinfos_comm' ) ) && !$page_cd_nc ) {
?>
<div class="metafield">
<div class="metafield_trigger mft_comm" style="right: <?php echo $r_pos; ?>px; width:16px"> </div>
<div class="metafield_content">
<?php echo __( 'Comments', 'shiword' ) . ': '; ?>
<?php comments_popup_link( __( 'No Comments', 'shiword' ), __( '1 Comment', 'shiword', 'shiword' ), __( '% Comments', 'shiword' ) ); // number of comments?>
</div>
</div>
<?php
$r_pos = $r_pos + 30;
}
// date
if ( $args['date'] && ( shiword_get_opt( 'shiword_xinfos_date' ) ) ) {
?>
<div class="metafield">
<div class="metafield_trigger mft_date" style="right: <?php echo $r_pos; ?>px; width:16px"> </div>
<div class="metafield_content">
<?php
printf( __( 'Published on: %1$s', 'shiword' ), '<span class="published">' . get_the_time( get_option( 'date_format' ) ) . '</span>' );
?>
</div>
</div>
<?php
$r_pos = $r_pos + 30;
}
// hierarchy
if ( $args['hiera'] && is_page() && !is_front_page() ) {
?>
<?php if ( shiword_multipages( $r_pos ) ) { $r_pos = $r_pos + 30; } ?>
<?php
}
?>
<div class="metafield_trigger edit_link" style="right: <?php echo $r_pos; ?>px;"><?php edit_post_link( __( 'Edit', 'shiword' ), '' ); ?></div>
</div>
</div>
<?php
} else { //static xinfos ?>
<div class="meta">
<?php if ( $args['auth'] && shiword_get_opt( 'shiword_byauth' ) ) { printf( __( 'by %s', 'shiword' ), '<a href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '" title="' . esc_attr( sprintf( 'View all posts by %s', get_the_author() ) ) . '">' . get_the_author() . '</a>' ); echo '<br />'; }; ?>
<?php if ( $args['date'] && shiword_get_opt( 'shiword_xinfos_date' ) ) { printf( __( 'Published on: %1$s', 'shiword' ), get_the_time( get_option( 'date_format' ) ) ) ; echo '<br />'; }?>
<?php if ( $args['comms'] && shiword_get_opt( 'shiword_xinfos_comm' ) ) { echo __( 'Comments', 'shiword' ) . ': '; comments_popup_link( __( 'No Comments', 'shiword' ), __( '1 Comment', 'shiword' ), __( '% Comments', 'shiword' ) ); echo '<br />'; } ?>
<?php if ( $args['tags'] && shiword_get_opt( 'shiword_xinfos_tag' ) ) { echo __( 'Tags', 'shiword' ) . ': '; if ( !get_the_tags() ) { _e( 'No Tags', 'shiword' ); } else { the_tags( '', ', ', '' ); }; echo '<br />'; } ?>
<?php if ( $args['cats'] && shiword_get_opt( 'shiword_xinfos_cat' ) ) { echo __( 'Categories', 'shiword' ) . ': '; the_category( ', ' ); echo '<br />'; } ?>
<?php edit_post_link( __( 'Edit', 'shiword' ) ); ?>
</div>
<?php
}
}
}
// Search reminder
function shiword_search_reminder() {
$text = '';
if ( is_archive() ) {
$term = get_queried_object();
$title = '';
$type = '';
if ( is_category() || is_tag() || is_tax() ) {
if ( is_category() ) $type = __( 'Category', 'shiword' );
elseif ( is_tag() ) $type = __( 'Tag', 'shiword' );
elseif ( is_tax() ) $type = __( 'Taxonomy', 'shiword' );
$title = $term->name;
} elseif ( is_date() ) {
$type = __( 'Date', 'shiword' );
if ( is_day() ) {
$title = get_the_date();
} else if ( is_month() ) {
$title = single_month_title( ' ', false );
} else if ( is_year() ) {
$title = get_query_var( 'year' );
}
} elseif ( is_author() ) {
$type = __( 'Author', 'shiword' );
$title = $term->display_name;
}
$text = sprintf( __( '%s archive', 'shiword' ), get_bloginfo( 'name' ) ) . '<br>' . $type . ' : <span class="sw-search-term">' . $title . '</span>';
} elseif ( is_search() ) {
$text = sprintf( __( 'Search results for “%s”', 'shiword' ), '<span class="sw-search-term">' . esc_html( get_search_query() ) . '</span>' );
}
if ( $text ) {
?>
<div class="meta sw-search-reminder">
<p><?php echo $text; ?></p>
</div>
<?php
}
if ( shiword_get_opt( 'shiword_cat_description' ) && is_category() && category_description() ) {
?>
<div class="meta">
<p><?php echo category_description(); ?></p>
</div>
<?php
}
if ( is_author() ) shiword_post_details( array( 'date' => 0, 'tags' => 0, 'categories' => 0 ) );
}
// add a fix for embed videos
function shiword_wmode_transparent($html, $url, $attr) {
if ( strpos( $html, '<embed ' ) !== false ) {
$html = str_replace( '</param><embed', '</param><param name="wmode" value="transparent"></param><embed', $html);
$html = str_replace( '<embed ', '<embed wmode="transparent" ', $html);
} elseif ( strpos ( $html, 'feature=oembed' ) !== false ) {
$html = str_replace( 'feature=oembed', 'feature=oembed&wmode=transparent', $html );
}
return $html;
}
// Get first image of a post
if ( !function_exists( 'shiword_get_first_image' ) ) {
function shiword_get_first_image() {
global $post;
$first_info = array( 'img' => '', 'title' => '', 'src' => '',);
//search the images in post content
preg_match_all( '/<img[^>]+>/i', $post->post_content, $result );
//grab the first one
if ( isset( $result[0][0] ) ){
$first_info['img'] = $result[0][0];
$first_img = $result [0][0];
//get the title (if any)
preg_match_all( '/(title)=("[^"]*")/i', $first_img, $img_title );
if ( isset( $img_title[2][0] ) ){
$first_info['title'] = str_replace( '"', '', $img_title[2][0] );
}
//get the path
preg_match_all( '/(src)=("[^"]*")/i', $first_img, $img_src );
if ( isset( $img_src[2][0] ) ){
$first_info['src'] = str_replace( '"', '', $img_src[2][0] );
}
return $first_info;
} else {
return false;
}
}
}
// Get first link of a post
if ( !function_exists( 'shiword_get_first_link' ) ) {
function shiword_get_first_link() {
global $post;
$first_info = array( 'anchor' => '', 'title' => '', 'href' => '', 'text' => '' );
//search the link in post content
preg_match_all( "/<a\b[^>]*>(.*?)<\/a>/i", $post->post_content, $result );
//grab the first one
if ( isset( $result[0][0] ) ){
$first_info['anchor'] = $result[0][0];
$first_info['text'] = isset( $result[1][0] ) ? $result[1][0] : '';
//get the title (if any)
preg_match_all( '/(title)=(["\'][^"]*["\'])/i', $first_info['anchor'], $link_title );
$first_info['title'] = isset( $link_title[2][0] ) ? str_replace( array( '"', '\'' ), '', $link_title[2][0] ) : '';
//get the path
preg_match_all( '/(href)=(["\'][^"]*["\'])/i', $first_info['anchor'], $link_href );
$first_info['href'] = isset( $link_href[2][0] ) ? str_replace( array( '"', '\'' ), '', $link_href[2][0] ) : '';
return $first_info;
} else {
return false;
}
}
}
// Get first blockquote words
if ( !function_exists( 'shiword_get_blockquote' ) ) {
function shiword_get_blockquote() {
global $post;
$first_quote = array( 'quote' => '', 'cite' => '' );
//search the blockquote in post content
preg_match_all( '/<blockquote>([\w\W]*?)<\/blockquote>/', $post->post_content, $blockquote );
//grab the first one
if ( isset( $blockquote[0][0] ) ){
$first_quote['quote'] = strip_tags( $blockquote[0][0] );
$words = explode( " ", $first_quote['quote'], 6 );
if ( count( $words ) == 6 ) $words[5] = '...';
$first_quote['quote'] = implode( ' ', $words );
preg_match_all( '/<cite>([\w\W]*?)<\/cite>/', $blockquote[0][0], $cite );
$first_quote['cite'] = ( isset( $cite[1][0] ) ) ? $cite[1][0] : '';
return $first_quote;
} else {
return false;
}
}
}
// Get first gallery
if ( !function_exists( 'shiword_get_gallery_shortcode' ) ) {
function shiword_get_gallery_shortcode() {
global $post;
$pattern = get_shortcode_regex();
if ( preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches )
&& array_key_exists( 2, $matches )
&& is_array( $matches[2] )
&& in_array( 'gallery', $matches[2] ) ) // gallery shortcode is being used
{
$key = array_search( 'gallery', $matches[2] );
$attrs = shortcode_parse_atts( $matches['3'][$key] );
return $attrs;
}
}
}
// run the gallery preview
if ( !function_exists( 'shiword_gallery_preview' ) ) {
function shiword_gallery_preview() {
$attrs = shiword_get_gallery_shortcode();
$attrs['preview'] = true;
return shiword_gallery_shortcode( '', $attrs );
}
}
// the gallery preview walker
if ( !function_exists( 'shiword_gallery_preview_walker' ) ) {
function shiword_gallery_preview_walker( $attachments = '', $id = 0 ) {
if ( ! $id )
return false;
if ( empty( $attachments ) )
$attachments = get_children( array( 'post_parent' => $id, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
if ( empty( $attachments ) )
return false;
$permalink = esc_url( get_permalink( $id ) );
$images_count = count( $attachments );
$first_image = array_shift( $attachments );
if ( ( shiword_get_opt( 'shiword_xcont' ) == 1 ) || is_archive() || is_search() ) { // compact view
$first_image_data = wp_get_attachment_image_src( $first_image->ID, 'thumbnail' );
$first_image_tag = wp_get_attachment_image( $first_image->ID, 'thumbnail' );
$gallery_thumb_width = esc_attr( min( get_option('thumbnail_size_w'), $first_image_data[1] ) );
$other_imgs = array();
$other_imgs_width = 0;
} else { // normal view
$first_image_data = wp_get_attachment_image_src( $first_image->ID, 'medium' );
$first_image_tag = wp_get_attachment_image( $first_image->ID, 'medium' );
$gallery_thumb_width = esc_attr( min( get_option('medium_size_w'), $first_image_data[1] ) );
$other_imgs = array_slice( $attachments, 0, 4 );
$other_imgs_width = floor( get_option('thumbnail_size_w')/2 );
}
?>
<div class="gallery gallery-preview">
<div class="gallery-item img-caption" style="width: <?php echo $gallery_thumb_width; ?>px;">
<a href="<?php echo $permalink; ?>"><?php echo $first_image_tag; ?></a>
</div><!-- .gallery-thumb -->
<?php foreach ($other_imgs as $image) { ?>
<div class="gallery-item img-caption" style="width: <?php echo $other_imgs_width; ?>px;">
<a href="<?php echo $permalink; ?>"><?php echo wp_get_attachment_image( $image->ID, array( $other_imgs_width, $other_imgs_width ) ); ?></a>
</div>
<?php } ?>
<p class="info">
<em><?php printf( _n( 'This gallery contains <a %1$s><strong>%2$s</strong> image</a>', 'This gallery contains <a %1$s><strong>%2$s</strong> images</a>', $images_count, 'shiword' ),
'href="' . $permalink . '" title="' . __( 'View gallery', 'shiword' ) . '" rel="bookmark"',
number_format_i18n( $images_count )
); ?></em>
</p>
</div>
<?php
return true;
}
}
// get the post thumbnail or (if not set) the format related icon
function shiword_get_the_thumb( $args = '' ) {
global $post;
$defaults = array(
'id' => $post->ID,
'width' => shiword_get_opt( 'shiword_pthumb_size' ),
'height' => shiword_get_opt( 'shiword_pthumb_size' ),
'class' => '',
'linked' => 0,
'onlyformat' => 0,
);
$args = wp_parse_args( $args, $defaults );
if ( shiword_get_opt( 'shiword_pthumb_qr' ) && ! $args['onlyformat'] )
$output = '<img class="feaured-image qrcode ' . $args['class'] . '" src="http://chart.apis.google.com/chart?cht=qr&chs=' . $args['width'] . 'x' . $args['height'] . '&chl=' . urlencode( home_url() . '/?p=' . $args['id'] ) . '&chld=L|0" alt="thumbnail" />';
elseif ( has_post_thumbnail( $args['id'] ) && ! $args['onlyformat'] ) {
$output = get_the_post_thumbnail( $args['id'], array( $args['width'], $args['height'] ), array( 'class' => $args['class'] ) );
} else {
if ( shiword_is_post_format_available( $args['id'] ) ) {
$format = get_post_format( $args['id'] );
} else {
$format = 'thumb';
}
$output = '<img class="' . esc_attr( $args['class'] ) . ' wp-post-image" width="' . esc_attr( $args['width'] ) . '" height="' . esc_attr( $args['height'] ) . '" alt="thumb" src="' . esc_url( get_template_directory_uri() . '/images/thumbs/' . $format . '.png' ) . '" />';
}
if ( $args['linked'] )
$output = '<a href="' . esc_url( get_permalink( $args['id'] ) ) . '" rel="bookmark">' . $output . '</a>';
return apply_filters( 'shiword_filter_get_the_thumb', $output );
}
// display the thumb
if ( !function_exists( 'shiword_thumb' ) ) {
function shiword_thumb() {
if( shiword_get_opt( 'shiword_pthumb' ) )
echo shiword_get_the_thumb( array( 'class' => 'alignleft', 'linked' => 1 ) );
}
}
// display the post title with the featured image
if ( !function_exists( 'shiword_post_title' ) ) {
function shiword_post_title( $args = '' ) {
global $post;
$defaults = array(
'alternative' => '',
'featured' => 0,
'href' => get_permalink(),
'target' => '',
'title' => the_title_attribute( array( 'echo' => 0 ) ),
'extra' => '',
);
$args = wp_parse_args( $args, $defaults );
$post_title = $args['alternative'] ? $args['alternative'] : get_the_title();
$link_target = $args['target'] ? ' target="'.$args['target'].'"' : '';
$has_format = shiword_is_post_format_available( $post->ID );
$has_featured_image = $args['featured'] && shiword_get_opt( 'shiword_supadupa_title' ) && has_post_thumbnail( $post->ID ) && ( $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( 700, 700 ) ) ) && ( $image[1] >= 700 ) && ( $image[2] >= 200 );
if ( ! $has_format || is_singular() || ( shiword_get_opt( 'shiword_pthumb' ) && ! has_post_thumbnail( $post->ID ) ) )
$miniicon = '';
else
$miniicon = apply_filters( 'shiword_filter_mini_icon', shiword_get_the_thumb( array( 'width' => 32, 'height' => 32, 'class' => 'alignleft', 'linked' => 1, 'onlyformat' => 1 ) ) );
if ( $post_title ) $post_title = '<h2 class="storytitle entry-title">' . $miniicon . $args['extra'] . '<a title="' . esc_attr( $args['title'] ) . '" href="' . esc_url( $args['href']) . '"' . esc_attr( $link_target ) . ' rel="bookmark">' . $post_title . '</a></h2>';
shiword_hook_post_title_before();
if ( $has_featured_image ) {
?>
<div class="storycontent sd-post-title">
<img src="<?php echo esc_url( $image[0] ); ?>" width="<?php echo esc_attr( $image[1] ); ?>" height="<?php echo esc_attr( $image[2] ); ?>">
<?php echo $post_title; ?>
</div>
<?php
} else {
echo $post_title;
}
shiword_hook_post_title_after();
}
}
// print extra info for posts/pages
if ( !function_exists( 'shiword_post_details' ) ) {
function shiword_post_details( $args = '' ) {
global $post;
$defaults = array(
'author' => 1,
'date' => 1,
'tags' => 1,
'categories' => 1,
'avatar_size' => 48,
'featured' => 0,
'echo' => 1,
);
$args = wp_parse_args( $args, $defaults );
$tax_separator = apply_filters( 'shiword_filter_taxomony_separator', ', ' );
$output = '';
if ( $args['featured'] && has_post_thumbnail( $post->ID ) )
$output .= '<div class="tb-post-details post-details-thumb">' . get_the_post_thumbnail( $post->ID, 'thumbnail') . '</div>';
if ( $args['author'] )
$output .= shiword_author_badge( $post->post_author, $args['avatar_size'] );
if ( $args['categories'] )
$output .= '<div class="tb-post-details"><span class="post-details-cats">' . __( 'Categories', 'shiword' ) . ': </span>' . get_the_category_list( $tax_separator ) . '</div>';
if ( $args['tags'] ) {
$tags = get_the_tags() ? get_the_tag_list( '</span>', $tax_separator, '' ) : __( 'No Tags', 'shiword' ) . '</span>';
$output .= '<div class="tb-post-details"><span class="post-details-tags">' . __( 'Tags', 'shiword' ) . ': ' . $tags . '</div>';
}
if ( $args['date'] )
$output .= '<div class="tb-post-details"><span class="post-details-date">' . __( 'Published on', 'shiword' ) . ': </span><a href="' . esc_url( get_day_link( get_the_time( 'Y' ), get_the_time( 'm' ), get_the_time( 'd' ) ) ) . '">' . get_the_time( get_option( 'date_format' ) ) . '</a></div>';
if ( ! $args['echo'] )
return $output;
echo $output;
}
}
// get the author badge
function shiword_author_badge( $author = '', $size ) {
if ( ! $author ) return;
$name = get_the_author_meta( 'nickname', $author ); // nickname
$avatar = get_avatar( $author, $size, 'Gravatar Logo', get_the_author_meta( 'user_nicename', $author ) . '-photo' ); // gravatar
$description = get_the_author_meta( 'description', $author ); // bio
$author_link = esc_url( get_author_posts_url($author) ); // link to author posts