-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsermon-publisher.php
1727 lines (1495 loc) · 52.7 KB
/
sermon-publisher.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
/*
Plugin Name: Jeff's Sermon Publisher
Plugin URI: none
Description: This plugin allows churches to easily publish weekly sermons to their wordpress-based site. Additionally, this plugin provides sample page templates to use in your own themes and three shortcodes to display the most recent series, a gallery of past sermons, and a "full" gallery comprised of both.<p>This plugin provides the following shortcodes: [sp_featured], [sp_gallery], [sp_group_gallery], [sp_full_gallery]. NOTE: I recommend you use the "Podcasting" plugin by TSG for full podcast feed control.
Author: Jeff Mikels
Text Domain: sermon-publisher
Version: 0.4
Author URI: http://jeff.mikels.cc
*/
/* TODO */
/*
implement admin options page for setting alternate upload locations like S3 servers, etc.
*/
define('SP_DO_LOG',1);
define('SP_SHOW_DEBUG',0);
define('SP_LOG_FILE', dirname(__FILE__) . '/sp_log.log');
define('SP_EXISTS', 1);
/** Add new image sizes */
add_image_size( 'sp_banner', 1040, 400, TRUE );
add_image_size( 'sp_poster', 1280, 720, TRUE );
add_image_size( 'sp_thumb', 320, 180, TRUE );
add_filter( 'image_size_names_choose', 'sp_custom_sizes' );
function sp_custom_sizes( $sizes )
{
return array_merge( $sizes, array(
'sp_banner' => __('Ultra-Wide Banner'),
'sp_poster' => __('Standard 16x9 Sermon Image'),
'sp_thumb' => __('Small 16x9 Sermon Thumbnail')
) );
}
/** CUSTOM POST TYPES */
function sp_custom_post_types()
{
register_post_type( 'sp_series_group', array
(
'labels' => array
(
'name' => __( 'Series Groups' ),
'singular_name' => __( 'Series Group' ),
'add_new' => __( 'Add New Series Group' ),
'add_new_item' => __( 'Add New Series Group' ),
'edit_item' => __( 'Edit Series Group' ),
'new_item' => __( 'New Series Group' ),
'view_item' => __( 'View Series Group' ),
'search_items' => __( 'Search Series Groups' ),
'not_found' => __( 'No Series Groups found' ),
'not_found_in_trash' => __( 'No Series Groups found in Trash' ),
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'series_group'),
'taxonomies' => array('post_tag'),
'publicly_queryable' => true,
'exclude_from_search' => false,
'menu_position' => 20,
'show_in_rest' => true,
'rest_base' => 'sp_series_group',
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields', 'genesis-layouts'),
));
register_post_type( 'sp_series', array
(
'labels' => array
(
'name' => __( 'Series Pages' ),
'singular_name' => __( 'Series Page' ),
'add_new' => __( 'Add New Series Page' ),
'add_new_item' => __( 'Add New Series Page' ),
'edit_item' => __( 'Edit Series Page' ),
'new_item' => __( 'New Series Page' ),
'view_item' => __( 'View Series Page' ),
'search_items' => __( 'Search Series Pages' ),
'not_found' => __( 'No Series Pages found' ),
'not_found_in_trash' => __( 'No Series Pages found in Trash' ),
),
'public' => true,
'has_archive' => true,
'taxonomies' => array('post_tag'),
'rewrite' => array('slug' => 'series'),
'publicly_queryable' => true,
'exclude_from_search' => false,
'menu_position' => 20,
'show_in_rest' => true,
'rest_base' => 'sp_series',
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields', 'genesis-layouts'),
));
$sermon_words = sp_get_sermon_words();
$singular = $sermon_words['singular'];
$plural = $sermon_words['plural'];
register_post_type( 'sp_sermon', array
(
'labels' => array
(
'name' => sprintf( __( '%s' ), ucwords($plural)),
'singular_name' => sprintf( __( '%s' ), ucwords($singular)),
'add_new' => sprintf( __( 'Add New %s' ), ucwords($singular)),
'add_new_item' => sprintf( __( 'Add New %s' ), ucwords($singular)),
'edit_item' => sprintf( __( 'Edit %s' ), ucwords($singular)),
'new_item' => sprintf( __( 'New %s' ), ucwords($singular)),
'view_item' => sprintf( __( 'View %s' ), ucwords($singular)),
'search_items' => sprintf( __( 'Search %s' ), ucwords($plural)),
'not_found' => sprintf( __( 'No %s Found' ), ucwords($plural)),
'not_found_in_trash' => sprintf( __( 'No %s Found in Trash' ), ucwords($plural)),
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => $singular),
'taxonomies' => array('category'),
'publicly_queryable' => true,
'exclude_from_search' => false,
'menu_position' => 20,
'show_in_rest' => true,
'rest_base' => 'sp_sermon',
'supports' => array('title', 'editor', 'author', 'custom-fields', 'podcasting', 'excerpt', 'genesis-layouts'),
) );
// return metadata in rest requests
foreach (['sp_sermon','sp_series','sp_series_group'] as $type) {
register_rest_field( $type, 'metadata', array(
'get_callback' => function ( $data ) {
return get_post_meta( $data['id'], '', '' );
}, ));
}
// return thumbnail in rest requests
foreach (['sp_sermon','sp_series','sp_series_group'] as $type) {
register_rest_field( $type, 'featured_image', array(
'get_callback' => function ( $data ) {
$id = $data['id'];
$featured_id = get_post_thumbnail_id($id);
$images = array();
foreach (['full','large','medium','thumbnail'] as $size)
{
$details = wp_get_attachment_image_src($featured_id, $size);
$images[$size] = empty($details) ? array() : $details;
}
return $images;
}, ));
}
}
add_action( 'init', 'sp_custom_post_types' );
/** META BOX CODE */
include ("sermon-meta.php");
/** WIDGETS CODE */
include ("sermon-widgets.php");
/* REST MODIFICATIONS FOR CUSTOM POST TYPES */
function sp_rest_prepare_sp_sermon($data, $post, $request) {
// $_data = [];
// $_data['title'] = $post->post_title;
// $_data['json'] = $post->json;
// $_data['notification_data'] = $post->data;
$data->data['archive_item'] = sp_get_archive_url($post->ID);
return $data;
}
add_filter("rest_prepare_sp_sermon", 'sp_rest_prepare_sp_sermon', 10, 3);
// SET UP CONTENT FILTERS FOR PLUGIN POST TYPES
// create attractive display of series gropus
function sp_series_group_content($content = '')
{
if (! sp_is_series_group()) return $content;
$content = sp_add_series_in_group($content);
return $content;
}
add_filter('the_content', 'sp_series_group_content');
// add related sermons to content on series pages
function sp_series_content($content = '')
{
if (! sp_is_series()) return $content;
$content = sp_add_sermons_in_series($content);
return $content;
}
add_filter('the_content', 'sp_series_content');
// add media player to sermon pages
function sp_sermon_content($content = '')
{
// ignore this filter for non-sermon post types
if(! sp_is_sermon()) return $content;
// ignore this filter if we are sending a feed of posts
if (!is_single() && !is_page()) return $content;
$series_graphic = sp_add_series_graphic(''); // will return nothing if there is a video
$media_player = sp_add_media_player('',false); // will return video player or audio player or both
$downloads = sp_add_downloads(''); // will return a list of downloads
$archive = sp_add_archive_link();
return $series_graphic . $media_player . $downloads . $archive . $content;
}
add_filter('the_content', 'sp_sermon_content');
// add sermon posts to feeds
function sp_add_sermons_to_feed($qv)
{
if (isset($qv['feed']) && !isset($qv['post_type']))
{
$qv['post_type'] = array('post', 'sp_sermon', 'sp_series', 'page');
//$qv['post_type']=get_post_types();
}
return $qv;
}
add_filter('request', 'sp_add_sermons_to_feed');
// unused function to hijack the series archive pages
function sp_series_archive()
{
global $wp_query;
global $first_loop_done;
if (isset($first_loop_done) && $first_loop_done) return;
$first_loop_done = True;
//sp_debug($wp_query);
if (is_admin() || ! is_archive()) return;
if (isset($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'sp_series')
{
// hijack the loop with our own series archive loop
$posts = $wp_query->posts;
$most_recent = $posts[0];
$the_rest = array_slice($posts,1);
// display the most recent series as if it were a single
$post = $most_recent;
setup_postdata($post);
?>
<div class="series most-recent">
<a href="<?php the_permalink(); ?>">
<?php print the_post_thumbnail('sp_poster',array('class' => 'fullwidth', 'title'=>get_the_title())); ?>
<div class="series-description">
<span class="series-title"><?php the_title(); ?></span>
<span class="series-excerpt"><?php sp_ensure_excerpt($post, 600); ?></span>
</div>
</a>
</div>
<div class="series series-gallery">
<?php
foreach ($the_rest as $post)
{
setup_postdata($post);
?>
<div class="series-item">
<a href="<?php the_permalink(); ?>">
<?php //print the_post_thumbnail('sp_thumb',array('class' => 'fullwidth', 'title' => get_the_title())); ?>
</a>
</div>
<?php
}
$wp_query->posts = Array();
?>
</div>
<?php
return;
}
return;
}
// add_action('loop_start', 'sp_series_archive');
// HELPER FUNCTIONS FOR CONTENT FILTERS
function sp_ensure_excerpt($post, $length=400)
{
$retval = empty($post->post_excerpt) ? substr(wp_strip_all_tags($post->post_content),0,$length) : $post->post_excerpt;
if (strlen($retval) == $length) $retval .= '...';
return $retval;
}
// SERIES PAGE MODIFICATIONS
function sp_add_sermons_in_series($content = '')
{
$sermon_words = sp_get_sermon_words();
$singular = $sermon_words['singular'];
$plural = $sermon_words['plural'];
if (! sp_is_series()) return $content;
else
{
global $post;
$series_id = $post->ID;
$series_slug = $post->post_name;
$sermons = sp_get_sermons_by_series($series_id);
$sermons_html = '<div class="sermon-listing series-'.$series_slug.'">';
// put the most recent sermon on top
if (count($sermons) > 3)
{
$sermons_html .= sprintf('<div class="sp-most-recent"><h2>Most Recent %s in this Series</h2>', ucwords($singular));
$sermon = $sermons[count($sermons) - 1];
$slug = $sermon->post_name;
$id = $sermon->ID;
$title = $sermon->post_title;
$excerpt = sp_ensure_excerpt($sermon, 1000); // longer excerpt allowed for featured post
$permalink = get_permalink($id);
$date = date('M j, Y', strtotime($sermon->post_date));
$this_html = "\n\n";
$this_html .= '<div class="sermon sermon-'.$slug.'">';
$this_html .= '<a href="' . $permalink . '">';
$this_html .= '<div class="sermon-date">' . $date . '</div>';
$this_html .= '<h3>' . $title . '</h3>';
$this_html .= '<div class="sermon-excerpt">' . $excerpt . '</div>';
$this_html .= '</a></div>' . "\n\n";
$this_html .= '</div><!-- end .sp-most-recent -->';
$sermons_html .= $this_html;
}
// make a list of all the sermons
if (count($sermons) > 0)
{
$sermons_html .= sprintf('<div class="sp-all-sermons"><h2>All %s in this Series</h2>', ucwords($plural));
foreach($sermons as $sermon)
{
$slug = $sermon->post_name;
$id = $sermon->ID;
$title = $sermon->post_title;
$excerpt = sp_ensure_excerpt($sermon, 200); // shorter excerpt for others
$permalink = get_permalink($id);
$date = date('M j, Y', strtotime($sermon->post_date));
$this_html = "\n\n";
$this_html .= '<div class="sermon sermon-'.$slug.'">';
$this_html .= '<a href="' . $permalink . '">';
$this_html .= '<div class="sermon-date">' . $date . '</div>';
$this_html .= '<h3>' . $title . '</h3>';
$this_html .= '<div class="sermon-excerpt">' . $excerpt . '</div>';
$this_html .= '</a></div>' . "\n\n";
$sermons_html .= $this_html;
}
$sermons_html .= '</div><!-- end .sp-all-sermons -->';
}
else $sermons_html .= sprintf('NO %s HAVE YET BEEN POSTED TO THIS SERIES', strtoupper($plural));
$sermons_html .= '</div> <!-- close .sermon-listing -->';
}
return $content . $sermons_html;
}
function sp_add_series_in_group($content = '')
{
global $post;
$slug = $post->post_name;
$id = $post->ID;
$selected_series = json_decode(get_post_meta($post->ID,'series_group_data',TRUE));
if (empty($selected_series)) return $content;
$content .= '<div class="sp_series_group_items">';
foreach($selected_series as $series)
{
$link = get_permalink($series->ID);
$image_url = get_the_post_thumbnail_url($series->ID, '720');
$excerpt = sp_ensure_excerpt($series);
$content .= <<<EOF
<a href="$link" class="series-post">
<img class="series-image" src="$image_url" />
<div class="series-content">
<h3 class="series-title">$series->post_title</h3>
<p class="series-description">
$excerpt...
</p>
</div>
</a>
<div class="clear"> </div>
EOF;
}
$content .= '</div> <!-- end sp_series_group_items -->';
return $content;
}
// SERMON POST MODIFICATIONS
function sp_add_series_graphic($content = '')
{
if (! sp_is_sermon()) return $content;
if (has_post_thumbnail()) return $content;
if (sp_has_video()) return $content;
// if we made it this far, we want to grab the series graphic from the sermon series page
$series_page_id = get_post_meta(get_the_ID(), 'sermon_series', TRUE);
$series_thumbnail = get_the_post_thumbnail($series_page_id, 'sp_poster', array('class' => 'fullwidth'));
return $series_thumbnail . $content;
}
// add a downloads box on sermon posts
function sp_add_downloads($content = '')
{
$content = sp_make_download_links() . $content;
return $content;
}
// add media player to sermon posts
function sp_add_media_player($content = '', $send_to_browser = TRUE)
{
global $post;
if (!sp_is_sermon()) return $content;
if ($send_to_browser)
{
print "<!-- MEDIA PLAYER -->\n";
include "media_player.php";
print "\n<!-- END MEDIA PLAYER -->\n";
return $content;
}
else
{
ob_start();
include "media_player.php";
$result = ob_get_clean();
return $result . $content;
}
}
function sp_add_archive_link($content = '')
{
if (! sp_is_sermon()) return $content;
$url = sp_get_archive_url();
if (!empty($url))
{
$content = '<a class="sp-archive-link" href="'.$url.'">' . $url . '</a>' . $content;
}
return $content;
}
function sp_get_archive_url($post_id = NULL)
{
global $post;
if ($post_id === NULL) $post_id = $post->ID;
// if $post_id is empty, we default
// to the global post in case this happens inside the loop
if (! sp_is_sermon() && empty($post_id)) return '';
$enclosures = '';
$downloads = '';
$output = '';
// do we have a metadata item linking to the internet archive?
// $ia = get_post_custom_values('sp_archive_item');
$ia = get_post_meta($post_id, 'sp_archive_item', true);
if (!empty($ia)) return $ia;
// do we have any links in the enclosures or downloads?
$enclosures = get_post_meta($post_id, 'enclosure');
$downloads = array_merge($enclosures, get_post_meta($post_id, 'download'));
foreach ($downloads as $d)
{
$url = explode("\n", $d)[0];
if (strpos($url, 'archive.org') !== false)
{
$ia = dirname($url);
return $ia;
}
}
return '';
}
// GALLERY SHORTCODE DISPLAY FUNCTIONS
function sp_most_recent_series($thumbnail_size = 'sp_poster', $before = '', $after='', $format='overlay')
{
$featured_series = sp_get_featured_series();
$featured_series_id = $featured_series->ID;
$featured_series_image = sp_get_image($featured_series_id, $thumbnail_size);
$excerpt = sp_ensure_excerpt($featured_series, 600); // allow 600 characters in the excerpt.
echo $before;
?>
<?php if ($format == 'overlay'): ?>
<div class="most-recent-series">
<div class="featured-series">
<a href="<?php echo get_permalink($featured_series_id); ?>">
<img class="featured-series-image" src="<?php echo $featured_series_image[0]; ?>" />
<div class="featured-series-image-overlay">
<div class="featured-series-image-caption">
<div class="featured-series-title"><?php echo $featured_series->post_title; ?></div>
<div class="featured-series-excerpt"><?php echo $excerpt; ?></div>
</div>
</div>
</a>
</div>
</div>
<?php elseif ($format == 'left' || $format == 'right'): ?>
<div class="most-recent-series">
<div class="featured-series-<?php echo $format; ?>">
<a href="<?php echo get_permalink($featured_series_id); ?>">
<img class="featured-series-image-<?php echo $format; ?>" src="<?php echo $featured_series_image[0]; ?>" />
<div class="featured-series-image-sidebar">
<div class="featured-series-image-caption">
<div class="featured-series-title"><?php echo $featured_series->post_title; ?></div>
<div class="featured-series-excerpt"><?php echo $excerpt; ?></div>
</div>
</div>
</a>
</div>
</div>
<div class="clear"> </div>
<?php endif; ?>
<?php
echo $after;
return $featured_series_id;
}
function sp_most_recent_sermon($thumbnail_size = 'sp_poster', $before = '', $after='', $show_image=1, $show_text=1)
{
$featured_series = sp_get_featured_series();
$featured_series_id = $featured_series->ID;
$featured_series_image = sp_get_image($featured_series_id, $thumbnail_size);
$most_recent = sp_get_most_recent_sermon();
$permalink = get_permalink($most_recent->ID);
echo $before;
?>
<?php if ($show_image == 1): ?>
<div class="most-recent-series">
<div class="featured-series">
<a href="<?php echo $permalink; ?>">
<img class="featured-series-image" src="<?php echo $featured_series_image[0]; ?>" />
<div class="featured-series-image-overlay">
<div class="featured-series-image-caption">
<div class="featured-series-title"><?php echo $most_recent->post_title; ?></div>
</div>
</div>
</a>
</div>
</div>
<?php endif;?>
<?php if ($show_text == 1): ?>
<div class="most-recent-sermon">
<!-- <a href="<?php //echo get_permalink($featured_series_id); ?>"><?php //echo $featured_series->post_title; ?> ::<br /> -->
<a href="<?php echo $permalink; ?>">
<?php echo $most_recent->post_title; ?>
</a>
<br /><?php echo get_the_date(get_option( 'date_format' ), $most_recent->ID); ?>
</div>
<?php endif; ?>
<?php
echo $after;
return $featured_series_id;
}
function sp_series_group_gallery($thumbnail_size = 'sp_thumb', $before = '', $after = '', $exclude = '')
{
$series_posts = sp_get_all_series_groups();
if (empty($series_posts)) return;
$exclude = explode(',', str_replace(' ', '', $exclude));
echo $before;
?>
<div class="series-gallery">
<?php
$classes = ['first','middle','last'];
$counter = 0;
$class = $classes[$counter];
?>
<?php foreach ($series_posts as $series): ?>
<?php if (in_array($series->ID, $exclude)) continue; ?>
<?php $series_thumbnail = sp_get_image($series->ID, $thumbnail_size); ?>
<?php $excerpt = sp_ensure_excerpt($series, 140); ?>
<div class="series-gallery-item item-<?php echo $class; ?>">
<a href="<?php print get_permalink($series->ID); ?>">
<div class="series-gallery-item-image"
style="background-size:cover;background-image:url(<?php print $series_thumbnail[0]; ?>);">
</div>
<div class="series-gallery-item-image-overlay">
<div class="series-gallery-item-image-caption">
<div class="series-gallery-item-title"><?php echo $series->post_title; ?></div>
<div class="series-gallery-item-date"><?php echo get_the_time('F Y', $series->ID); ?></div>
<div class="series-gallery-item-excerpt"><?php echo $excerpt; ?></div>
</div>
</div>
</a>
</div>
<?php $counter = ($counter + 1) % 3; ?>
<?php endforeach; ?>
</div>
<div style="clear:both;"> </div>
<?php
}
function sp_past_series_gallery($thumbnail_size = 'sp_thumb', $before = '', $after = '', $exclude = '', $limit = -1)
{
$series_posts = sp_get_all_series($limit);
if (empty($series_posts)) return;
$exclude = explode(',', str_replace(' ', '', $exclude));
echo $before;
?>
<div class="series-gallery">
<?php
$classes = array('first','middle','last');
$counter = 0;
$class = $classes[$counter];
?>
<?php foreach ($series_posts as $series): ?>
<?php if (in_array($series->ID, $exclude)) continue; ?>
<?php $series_thumbnail = sp_get_image($series->ID, $thumbnail_size); ?>
<?php $excerpt = sp_ensure_excerpt($series, 140); ?>
<div class="series-gallery-item item-<?php echo $class; ?>">
<a href="<?php print get_permalink($series->ID); ?>">
<!-- <img class="series-gallery-item-image" src="<?php print $series_thumbnail[0]; ?>" /> -->
<div class="series-gallery-item-image"
style="background-size:cover;background-image:url(<?php print $series_thumbnail[0]; ?>);">
</div>
<div class="series-gallery-item-image-overlay">
<div class="series-gallery-item-image-caption">
<div class="series-gallery-item-title"><?php echo $series->post_title; ?></div>
<div class="series-gallery-item-date"><?php echo get_the_time('F Y', $series->ID); ?></div>
<div class="series-gallery-item-excerpt"><?php echo $excerpt; ?></div>
</div>
</div>
</a>
</div>
<?php $counter = ($counter + 1) % 3; ?>
<?php endforeach; ?>
</div>
<div style="clear:both;"> </div>
<?php
}
// REGISTER GALLERY SHORTCODES
function sp_featured_helper($atts)
{
extract( shortcode_atts( array(
'thumbnail_size' => 'sp_poster',
'before' => '',
'after' => '',
'format' => 'overlay'), $atts ) );
sp_most_recent_series($thumbnail_size, $before, $after, $format);
}
function sp_gallery_helper($atts)
{
extract( shortcode_atts( array(
'thumbnail_size' => 'sp_thumb',
'before' => '',
'after' => '',
'limit' => -1,
'exclude' => ''), $atts ) );
ob_start();
sp_past_series_gallery($thumbnail_size, $before, $after, $exclude, $limit);
return ob_get_clean();
}
function sp_group_gallery_helper($atts)
{
extract( shortcode_atts( array(
'thumbnail_size' => 'sp_thumb',
'before' => '',
'after' => '',
'exclude' => ''), $atts ) );
ob_start();
sp_series_group_gallery($thumbnail_size, $before, $after, $exclude);
return ob_get_clean();
}
function sp_full_gallery_helper($atts)
{
extract( shortcode_atts( array(
'thumbnail_size' => 'sp_poster',
'before' => '',
'after' => '',
'format' => 'overlay'), $atts ) );
ob_start();
print($before);
$fid = sp_most_recent_series($thumbnail_size, '', '', $format);
sp_past_series_gallery('sp_thumb','<h2>Series Archive</h2>','',$fid);
sp_series_group_gallery('sp_thumb', '<h2>Series Groups</h2>', '', $exclude);
print($after);
return ob_get_clean();
}
add_shortcode('sp_featured', 'sp_featured_helper');
add_shortcode('sp_gallery', 'sp_gallery_helper');
add_shortcode('sp_group_gallery', 'sp_group_gallery_helper');
add_shortcode('sp_full_gallery', 'sp_full_gallery_helper');
// SERMON CONTENT HELPER FUNCTIONS
// add downloads links to posts
function sp_make_download_links()
{
if (! sp_is_sermon()) return '';
$enclosures = '';
$downloads = '';
$output = '';
$enclosures = get_post_custom_values('enclosure');
$downloads = get_post_custom_values('download');
if ($enclosures || $downloads) {
$output .= '<div class="download-links">downloads: ';
$links = [];
if ($enclosures) {
foreach ($enclosures as $enclosure) {
$encdata = explode("\n",$enclosure);
$url = $encdata[0];
$formatdata = unserialize($encdata[3]);
$links[] = "<a class=\"download-link\" href=\"${encdata[0]}\">${formatdata['format']}</a>";
}
}
if ($downloads) {
foreach ($downloads as $download) {
$encdata = explode("\n",$download);
$url = $encdata[0];
$format = $encdata[1];
$links[] = "<a class=\"download-link\" href=\"${encdata[0]}\">${format}</a>";
}
}
$output .= implode(' | ', $links);
$output .= '</div>';
}
return $output;
}
function sp_has_video()
{
// check for youtube link
$youtube_link = get_post_custom_values('youtube_link');
if (!empty($youtube_link)) return True;
// check for video enclosure
$enclosures = get_post_custom_values('enclosure');
$video_extensions = array('.mp4','.ogv','webm');
if (!empty($enclosures))
{
foreach ($enclosures as $e)
{
$encdata = explode("\n",$e);
$url = trim($encdata[0]);
if (preg_match('/mp4$|ogv$|webm$/', $url)) return True;
}
}
// neither returned true, so we return false
return False;
}
function sp_is_sermon($post_id = '')
{
global $post;
if (! isset($post) and ! $post_id) return False;
if ($post_id)
{
$p = get_post($post_id);
return $p->post_type;
}
else
{
return ($post->post_type == 'sp_sermon' && is_single());
}
}
function sp_is_series($post_id = '')
{
global $post;
if (! isset($post) and ! $post_id) return False;
if ($post_id)
{
$p = get_post($post_id);
return $p->post_type;
}
else
{
return ($post->post_type == 'sp_series' && is_single());
}
}
function sp_is_series_group($post_id = '')
{
global $post;
if (! isset($post) and ! $post_id) return False;
if ($post_id)
{
$p = get_post($post_id);
return $p->post_type;
}
else
{
return ($post->post_type == 'sp_series_group' && is_single());
}
}
function sp_get_image($post_id, $thumbnail_size)
{
$image_id = get_post_thumbnail_id($post_id);
return wp_get_attachment_image_src($image_id, $thumbnail_size);
}
function sp_get_sermons_by_series($series_page_id)
{
// grab all the 'sermon' posts who have this post's id in their 'sermon_series' custom field
$args = array (
'numberposts'=> -1,
'post_type'=>'sp_sermon',
'meta_query' => array (
array (
'key' => 'sermon_series',
'value'=> $series_page_id,
)
),
'orderby'=> 'post_date',
'order' => 'ASC'
);
return get_posts($args);
}
function sp_get_sermon_series($sermon_id)
{
$series_id = get_post_meta($sermon_id, 'sermon_series', TRUE);
if ($series_id)
{
return get_post($series_id);
}
return NULL;
}
function sp_get_most_recent_sermon()
{
$sermons = get_posts( array ('post_type' => 'sp_sermon', 'numberposts'=>1) );
if (count($sermons) != 0) return $sermons[0];
return NULL;
}
function sp_get_featured_series()
{
// first, we grab the most recent 'sermon' post, and make that series the featured one
// returns the most recent series
$most_recent = sp_get_most_recent_sermon();
if ( $most_recent )
{
$sermon_id = $most_recent->ID;
return sp_get_sermon_series($sermon_id);
}
return get_posts( array ('post_type' => 'sp_series', 'numberposts'=>1) );
}
function sp_get_all_series_groups()
{
return get_posts( array ( 'numberposts'=>-1, 'post_type' => 'sp_series_group', 'orderby' => 'menu_order', 'order' => 'ASC' ) );
}
function sp_get_all_series($limit = -1)
{
return get_posts( array ( 'numberposts'=>$limit, 'post_type' => 'sp_series', 'orderby' => 'post_date', 'order' => 'DESC' ) );
}
function sp_get_all_sermons()
{
return get_posts( array ( 'numberposts'=>-1, 'post_type' => 'sp_sermon', 'orderby' => 'post_date', 'order' => 'DESC' ) );
}
function sp_get_series_with_sermons($page = 1, $posts_per_page = 10)
{
$series = get_posts( array ( 'posts_per_page'=>$posts_per_page, 'page'=>$page, 'post_type' => 'sp_series', 'orderby' => 'post_date', 'order' => 'DESC' ) );
foreach($series as $key=>$s)
{
// get featured image
$featured_id = get_post_thumbnail_id($s->ID);
$images = array();
$image = '';
foreach (['thumbnail','medium','large','full'] as $size)
{
$details = wp_get_attachment_image_src($featured_id, $size);
if (!empty($details))
{
$s->imageUrl = $details[0];
$images[$size] = $details;
}
}
$s->images = $images;
// get child sermons
$s->children = sp_get_sermons_by_series($s->ID);
foreach ($s->children as $childkey=>$child)
{
// get enclosures
$enclosures = get_post_meta($child->ID,'enclosure');
if (is_array($enclosures))
{
foreach ($enclosures as $enclosure)
{
$enc = array();
// replace \r\n with \n
$enclosure = str_replace("\r\n", "\n", $enclosure);
$encdata = explode("\n", $enclosure);
$enc['url'] = $encdata[0];
$enc['size'] = $encdata[1];
$enc['type'] = $encdata[2];
$enc['details'] = unserialize($encdata[3]);
$format = $enc['details']['format'];
// $output['posts'][$i]['enclosures'][$format] = $enc;
$child->$format = $enc;
}
}
$s->children[$childkey] = $child;
}
$series[$key] = $s;
}
return $series;
}
function sp_get_sermon_words()
{
$options = get_option('sp_options');
$singular = empty($options['sermon_word_singular']) ? 'sermon' : $options['sermon_word_singular'];
$plural = empty($options['sermon_word_plural']) ? 'sermons' : $options['sermon_word_plural'];
return Array('singular' => $singular, 'plural' => $plural);
}
// WORDPRESS MODIFICATION FUNCTIONS
function sp_add_styles()
{
// the next line registers our stylesheet from the plugin directory
// we also say it is dependent on the theme stylesheet so that the plugin styles get
// loaded after the theme styles
wp_register_style('sp_sermon_styles', plugins_url('style.css', __FILE__) );
wp_enqueue_style('sp_sermon_styles');
print '<link rel="stylesheet" id="sp_sermon_publisher_css" href="'.plugins_url('style.css', __FILE__).'" type="text/css" />'."\n";
}
add_action('wp_head', 'sp_add_styles');
add_action('admin_head', 'sp_add_styles');
// GENERAL HELPER FUNCTIONS
function sp_url_exists($url)
{
$file = $url;
$file_headers = get_headers($file);
if(strpos($file_headers[0], '404 Not Found') === False) {
$exists = true;
}
else {
$exists = false;
}
return $exists;
}
function sp_debug($s)
{
if (SP_SHOW_DEBUG)
{
print "<pre>";
print_r($s);
print "</pre>";
}
if (SP_DO_LOG) sp_log($s);