-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrontend.php
More file actions
1195 lines (1139 loc) · 51.7 KB
/
frontend.php
File metadata and controls
1195 lines (1139 loc) · 51.7 KB
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
// Error message for people using the old function
function display_sermons($options = array()) {
echo "This function is now deprecated. Use sb_display_sermons or the sermon browser widget, instead.";
}
// Function to display sermons for users to add to their template
function sb_display_sermons($options = array()) {
$default = array(
'display_preacher' => 1,
'display_passage' => 1,
'display_date' => 1,
'display_player' => 0,
'preacher' => 0,
'service' => 0,
'series' => 0,
'limit' => 5,
'url_only' => 0,
);
$options = array_merge($default, (array) $options);
extract($options);
if ($url_only == 1)
$limit = 1;
$sermons = sb_get_sermons(array(
'preacher' => $preacher,
'service' => $service,
'series' => $series
),
array(), 1, $limit
);
if ($url_only == 1)
sb_print_sermon_link($sermons[0], true, false);
else {
echo "<ul class=\"sermon-widget\">\r";
foreach ((array) $sermons as $sermon) {
echo "\t<li>";
echo "<span class=\"sermon-title\"><a href=\"";
sb_print_sermon_link($sermon, true, false);
echo "\">".stripslashes($sermon->title)."</a></span>";
if ($display_passage) {
$foo = unserialize($sermon->start);
$bar = unserialize($sermon->end);
echo "<span class=\"sermon-passage\"> (".sb_get_books($foo[0], $bar[0], FALSE).")</span>";
}
if ($display_preacher) {
echo "<span class=\"sermon-preacher\">".__('by', $sermon_domain)." <a href=\"";
sb_print_preacher_link($sermon, false);
echo "\">".stripslashes($sermon->preacher)."</a></span>";
}
if ($display_date)
echo " <span class=\"sermon-date\">".__('on', $sermon_domain)." ".sb_formatted_date ($sermon)."</span>";
if ($display_player)
sb_display_mini_player($sermon);
echo ".</li>\r";
}
echo "</ul>\r";
}
}
// Displays the widget
function sb_widget_sermon($args, $widget_args=1) {
global $sermon_domain;
extract( $args, EXTR_SKIP );
if ( is_numeric($widget_args) )
$widget_args = array( 'number' => $widget_args );
$widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
extract( $widget_args, EXTR_SKIP );
$options = sb_get_option('sermons_widget_options');
if ( !isset($options[$number]) )
return;
extract($options[$number]);
echo $before_widget;
echo $before_title . $title . $after_title;
$sermons = sb_get_sermons(array(
'preacher' => $preacher,
'service' => $service,
'series' => $series
),
array(), 1, $limit
);
$i=0;
echo "<ul class=\"sermon-widget\">";
foreach ((array) $sermons as $sermon){
$i++;
echo "<li><span class=\"sermon-title\">";
echo '<a href="'.sb_build_url(array('sermon_id' => $sermon->id), true).'">'.stripslashes($sermon->title).'</a></span>';
if ($book) {
$foo = unserialize($sermon->start);
$bar = unserialize($sermon->end);
if (isset ($foo[0]) && isset($bar[0]))
echo " <span class=\"sermon-passage\">(".sb_get_books($foo[0], $bar[0], FALSE).")</span>";
}
if ($preacherz) {
echo " <span class=\"sermon-preacher\">".__('by', $sermon_domain)." <a href=\"";
sb_print_preacher_link($sermon, false);
echo "\">".stripslashes($sermon->preacher)."</a></span>";
}
if ($date)
echo " <span class=\"sermon-date\">".__(' on ', $sermon_domain).sb_formatted_date ($sermon)."</span>";
if ($player)
sb_display_mini_player($sermon, $i);
echo ".</li>";
}
echo "</ul>";
echo $after_widget;
}
// Displays the tag cloud in the sidebar
function sb_widget_tag_cloud ($args) {
global $sermon_domain;
extract($args);
echo $before_widget;
echo $before_title.__('Sermon Browser tags', $sermon_domain).$after_title;
sb_print_tag_clouds();
echo $after_widget;
}
function sb_admin_bar_menu () {
global $wp_admin_bar, $sermon_domain;
if (!current_user_can('edit_posts') || !class_exists('WP_Admin_Bar'))
return;
if (isset($_GET['sermon_id']) && (int)$_GET['sermon_id'] != 0 && current_user_can('publish_pages')) {
$wp_admin_bar->add_menu(array('id' => 'sermon-browser-menu', 'title' => __('Edit Sermon', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/new_sermon.php&mid='.(int)$_GET['sermon_id'])));
$wp_admin_bar->add_menu(array('parent' => 'sermon-browser-menu', 'id' => 'sermon-browser-sermons', 'title' => __('List Sermons', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/sermon.php')));
} else {
$wp_admin_bar->add_menu(array('id' => 'sermon-browser-menu', 'title' => __('Sermons', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/sermon.php')));
if (current_user_can('publish_pages'))
$wp_admin_bar->add_menu(array('parent' => 'sermon-browser-menu', 'id' => 'sermon-browser-add', 'title' => __('Add Sermon', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/new_sermon.php')));
}
if (current_user_can('upload_files'))
$wp_admin_bar->add_menu(array('parent' => 'sermon-browser-menu', 'id' => 'sermon-browser-files', 'title' => __('Files', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/files.php')));
if (current_user_can('manage_categories')) {
$wp_admin_bar->add_menu(array('parent' => 'sermon-browser-menu', 'id' => 'sermon-browser-preachers', 'title' => __('Preachers', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/preachers.php')));
$wp_admin_bar->add_menu(array('parent' => 'sermon-browser-menu', 'id' => 'sermon-browser-series', 'title' => __('Series & Services', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/manage.php')));
}
if (current_user_can('manage_options')) {
$wp_admin_bar->add_menu(array('parent' => 'sermon-browser-menu', 'id' => 'sermon-browser-options', 'title' => __('Options', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/options.php')));
$wp_admin_bar->add_menu(array('parent' => 'sermon-browser-menu', 'id' => 'sermon-browser-series', 'title' => __('Templates', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/templates.php')));
}
if (current_user_can('edit_plugins'))
$wp_admin_bar->add_menu(array('parent' => 'sermon-browser-menu', 'id' => 'sermon-browser-uninstall', 'title' => __('Uninstall', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/uninstall.php')));
$wp_admin_bar->add_menu(array('parent' => 'sermon-browser-menu', 'id' => 'sermon-browser-help', 'title' => __('Help', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/help.php')));
$wp_admin_bar->add_menu(array('parent' => 'sermon-browser-menu', 'id' => 'sermon-browser-japan', 'title' => __('Pray for Japan', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/japan.php')));
$wp_admin_bar->add_menu(array('parent' => 'new-content', 'id' => 'sermon-browser-add2', 'title' => __('Sermon', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/new_sermon.php')));
}
// Sorts an object by rank
function sb_sort_object($a,$b) {
if( $a->rank == $b->rank )
return 0;
return ($a->rank < $b->rank) ? -1 : 1;
}
// Displays the most popular sermons in the sidebar
function sb_widget_popular ($args) {
global $wpdb, $sermon_domain;
extract($args);
if (!isset($suffix))
$suffix = '_w';
if (!isset($options))
$options = sb_get_option('popular_widget_options');
echo $before_widget;
if ($options['title'] != '')
echo $before_title.$options['title'].$after_title;
$jscript = '';
$trigger = array();
$output = array();
$series_final = array();
$preachers_final = array();
if ($options['display_sermons']) {
$sermons = $wpdb->get_results("SELECT sermons.id, sermons.title, sum(stuff.count) AS total
FROM {$wpdb->prefix}sb_stuff AS stuff
LEFT JOIN {$wpdb->prefix}sb_sermons AS sermons ON stuff.sermon_id = sermons.id
GROUP BY sermons.id ORDER BY total DESC LIMIT 0, {$options['limit']}");
if ($sermons) {
$output['sermons'] = '<div class="popular-sermons'.$suffix.'"><ul>';
foreach ($sermons as $sermon)
$output['sermons'] .= '<li><a href="'.sb_build_url(array('sermon_id' => $sermon->id), true).'">'.$sermon->title.'</a></li>';
$output['sermons'] .= '</ul></div>';
$trigger[] = '<a id="popular_sermons_trigger'.$suffix.'" href="#">Sermons</a>';
$jscript .= 'jQuery("#popular_sermons_trigger'.$suffix.'").click(function() {
jQuery(this).attr("style", "font-weight:bold");
jQuery("#popular_series_trigger'.$suffix.'").removeAttr("style");
jQuery("#popular_preachers_trigger'.$suffix.'").removeAttr("style");
jQuery.setSbCookie ("sermons");
jQuery("#sb_popular_wrapper'.$suffix.'").fadeOut("slow", function() {
jQuery("#sb_popular_wrapper'.$suffix.'").html("'.addslashes($output['sermons']).'").fadeIn("slow");
});
return false;
});';
}
}
if ($options['display_series']) {
$series1 = $wpdb->get_results("SELECT series.id, series.name, avg(stuff.count) AS average
FROM {$wpdb->prefix}sb_stuff AS stuff
LEFT JOIN {$wpdb->prefix}sb_sermons AS sermons ON stuff.sermon_id = sermons.id
LEFT JOIN {$wpdb->prefix}sb_series AS series ON sermons.series_id = series.id
GROUP BY series.id ORDER BY average DESC");
$series2 = $wpdb->get_results("SELECT series.id, sum(stuff.count) AS total
FROM {$wpdb->prefix}sb_stuff AS stuff
LEFT JOIN {$wpdb->prefix}sb_sermons AS sermons ON stuff.sermon_id = sermons.id
LEFT JOIN {$wpdb->prefix}sb_series AS series ON sermons.series_id = series.id
GROUP BY series.id ORDER BY total DESC");
if ($series1) {
$i=1;
foreach ($series1 as $series) {
$series_final[$series->id]->name = $series->name;
$series_final[$series->id]->rank = $i;
$series_final[$series->id]->id = $series->id;
$i++;
}
$i=1;
foreach ($series2 as $series) {
$series_final[$series->id]->rank += $i;
$i++;
}
usort($series_final,'sb_sort_object');
$series_final = array_slice($series_final, 0, $options['limit']);
$output['series'] = '<div class="popular-series'.$suffix.'"><ul>';
foreach ($series_final as $series)
$output['series'] .= '<li><a href="'.sb_build_url(array('series' => $series->id), true).'">'.$series->name.'</a></li>';
$output['series'] .= '</ul></div>';
}
$trigger[] = '<a id="popular_series_trigger'.$suffix.'" href="#">Series</a>';
$jscript .= 'jQuery("#popular_series_trigger'.$suffix.'").click(function() {
jQuery(this).attr("style", "font-weight:bold");
jQuery("#popular_sermons_trigger'.$suffix.'").removeAttr("style");
jQuery("#popular_preachers_trigger'.$suffix.'").removeAttr("style");
jQuery.setSbCookie ("series");
jQuery("#sb_popular_wrapper'.$suffix.'").fadeOut("slow", function() {
jQuery("#sb_popular_wrapper'.$suffix.'").html("'.addslashes($output['series']).'").fadeIn("slow");
});
return false;
});';
}
if ($options['display_preachers']) {
$preachers1 = $wpdb->get_results("SELECT preachers.id, preachers.name, avg(stuff.count) AS average
FROM {$wpdb->prefix}sb_stuff AS stuff
LEFT JOIN {$wpdb->prefix}sb_sermons AS sermons ON stuff.sermon_id = sermons.id
LEFT JOIN {$wpdb->prefix}sb_preachers AS preachers ON sermons.preacher_id = preachers.id
GROUP BY preachers.id
ORDER BY average DESC");
$preachers2 = $wpdb->get_results("SELECT preachers.id, sum(stuff.count) AS total
FROM {$wpdb->prefix}sb_stuff AS stuff
LEFT JOIN {$wpdb->prefix}sb_sermons AS sermons ON stuff.sermon_id = sermons.id
LEFT JOIN {$wpdb->prefix}sb_preachers AS preachers ON sermons.preacher_id = preachers.id
GROUP BY preachers.id
ORDER BY total DESC");
if ($preachers1) {
$i=1;
foreach ($preachers1 as $preacher) {
$preachers_final[$preacher->id]->name = $preacher->name;
$preachers_final[$preacher->id]->rank = $i;
$preachers_final[$preacher->id]->id = $preacher->id;
$i++;
}
$i=1;
foreach ($preachers2 as $preacher) {
$preachers_final[$preacher->id]->rank += $i;
$i++;
}
usort($preachers_final,'sb_sort_object');
$preachers_final = array_slice($preachers_final, 0, $options['limit']);
$output['preachers'] = '<div class="popular-preachers'.$suffix.'"><ul>';
foreach ($preachers_final as $preacher)
$output['preachers'] .= '<li><a href="'.sb_build_url(array('preacher' => $preacher->id), true).'">'.$preacher->name.'</a></li>';
$output['preachers'] .= '</ul></div>';
$trigger[] = '<a id="popular_preachers_trigger'.$suffix.'" href="#">Preachers</a>';
$jscript .= 'jQuery("#popular_preachers_trigger'.$suffix.'").click(function() {
jQuery(this).attr("style", "font-weight:bold");
jQuery("#popular_series_trigger'.$suffix.'").removeAttr("style");
jQuery("#popular_sermons_trigger'.$suffix.'").removeAttr("style");
jQuery.setSbCookie("preachers");
jQuery("#sb_popular_wrapper'.$suffix.'").fadeOut("slow", function() {
jQuery("#sb_popular_wrapper'.$suffix.'").html("'.addslashes($output['preachers']).'").fadeIn("slow");
});
return false;
});';
}
}
$jscript .= 'if (jQuery.getSbCookie() == "preachers") { jQuery("#popular_preachers_trigger'.$suffix.'").attr("style", "font-weight:bold"); jQuery("#sb_popular_wrapper'.$suffix.'").html("'.addslashes($output['preachers']).'")};';
$jscript .= 'if (jQuery.getSbCookie() == "series") { jQuery("#popular_series_trigger'.$suffix.'").attr("style", "font-weight:bold"); jQuery("#sb_popular_wrapper'.$suffix.'").html("'.addslashes($output['series']).'")};';
$jscript .= 'if (jQuery.getSbCookie() == "sermons") { jQuery("#popular_sermons_trigger'.$suffix.'").attr("style", "font-weight:bold"); jQuery("#sb_popular_wrapper'.$suffix.'").html("'.addslashes($output['sermons']).'")};';
echo '<p>'.implode ($trigger, ' | ').'</p>';
echo '<div id="sb_popular_wrapper'.$suffix.'">'.current($output).'</div>';
echo '<script type="text/javascript">jQuery.setSbCookie = function (value) {
document.cookie = "sb_popular="+encodeURIComponent(value);
};</script>';
echo '<script type="text/javascript">jQuery.getSbCookie = function () {
var cookieValue = null;
if (document.cookie && document.cookie != "") {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
var name = "sb_popular";
if (cookie.substring(0, name.length + 1) == (name + "=")) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}</script>';
echo '<script type="text/javascript">jQuery(document).ready(function() {'.$jscript.'});</script>';
echo $after_widget;
}
function sb_print_most_popular() {
$args['before_widget'] = '<div id="sermon_most_popular" style="border: 1px solid ; margin: 0pt 0pt 1em 2em; padding: 5px; float: right; font-size: 75%; line-height: 1em">';
$args['after_widget'] = '</div>';
$args['before_title'] = '<span class="popular_title">';
$args['after_title'] = '</span>';
$args['suffix'] = '_f';
sb_widget_popular ($args);
}
//Modify page title
function sb_page_title($title) {
global $wpdb, $sermon_domain;
if (isset($_GET['sermon_id'])) {
$id = (int)$_GET['sermon_id'];
$sermon = $wpdb->get_row("SELECT m.title, p.name FROM {$wpdb->prefix}sb_sermons as m LEFT JOIN {$wpdb->prefix}sb_preachers as p ON m.preacher_id = p.id where m.id = $id");
if ($sermon)
return $title.' ('.stripslashes($sermon->title).' - '.stripslashes($sermon->name).')';
else
return $title.' ('.__('No sermons found.', $sermon_domain).')';
}
else
return $title;
}
//Downloads external webpage. Used to add Bible passages to sermon page.
function sb_download_page ($page_url) {
if (function_exists('curl_init')) {
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $page_url);
curl_setopt ($curl, CURLOPT_TIMEOUT, 2);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_HTTPHEADER, array('Accept-Charset: utf-8;q=0.7,*;q=0.7'));
$contents = curl_exec ($curl);
$content_type = curl_getinfo( $curl, CURLINFO_CONTENT_TYPE );
curl_close ($curl);
}
else
{
$handle = @fopen ($page_url, 'r');
if ($handle) {
stream_set_blocking($handle, TRUE );
stream_set_timeout($handle, 2);
$info = socket_get_status($handle);
while (!feof($handle) && !$info['timed_out']) {
$contents .= fread($handle, 8192);
$info = socket_get_status($handle);
}
@fclose($handle);
}
}
return $contents;
}
// Returns human friendly Bible reference (e.g. John 3:1-16, not John 3:1-John 3:16)
function sb_tidy_reference ($start, $end, $add_link = FALSE, $relative_link = TRUE) {
if (!trim($start['book'])) {
return "";
}
$translated_books = array_combine(sb_get_default('eng_bible_books'), sb_get_default('bible_books'));
$start_book = $translated_books[trim($start['book'])];
$end_book = $translated_books[trim($end['book'])];
$start_chapter = trim($start['chapter']);
$end_chapter = trim($end['chapter']);
$start_verse = trim($start['verse']);
$end_verse = trim($end['verse']);
if ($add_link) {
$start_book = "<a href=\"".sb_get_book_link(trim($start['book']), $relative_link)."\">{$start_book}</a>";
$end_book = "<a href=\"".sb_get_book_link(trim($end['book']), $relative_link)."\">{$end_book}</a>";
}
if ($start_book == $end_book) {
if ($start_chapter == $end_chapter) {
if ($start_verse == $end_verse) {
$reference = "$start_book $start_chapter:$start_verse";
} else {
$reference = "$start_book $start_chapter:$start_verse-$end_verse";
}
} else {
$reference = "$start_book $start_chapter:$start_verse-$end_chapter:$end_verse";
}
} else {
$reference = "$start_book $start_chapter:$start_verse - $end_book $end_chapter:$end_verse";
}
return $reference;
}
//Print unstyled bible passage
function sb_print_bible_passage ($start, $end) {
echo "<p class='bible-passage'>".sb_tidy_reference($start, $end)."</p>";
}
// Returns human friendly Bible reference with link to filter
function sb_get_books($start, $end, $relative_link = TRUE) {
return sb_tidy_reference ($start, $end, TRUE, $relative_link);
}
//Add Bible text to single sermon page
function sb_add_bible_text ($start, $end, $version) {
if ($version == 'esv')
return sb_add_esv_text ($start, $end);
elseif ($version == 'net')
return sb_add_net_text ($start, $end);
else
return sb_add_other_bibles ($start, $end, $version);
}
//Returns ESV text
function sb_add_esv_text ($start, $end) {
// If you are experiencing errors, you should sign up for an ESV API key,
// and insert the name of your key in place of the letters IP in the URL
// below (.e.g. ...passageQuery?key=YOURAPIKEY&passage=...)
$esv_url = 'http://www.esvapi.org/v2/rest/passageQuery?key=IP&passage='.rawurlencode(sb_tidy_reference ($start, $end)).'&include-headings=false&include-footnotes=false';
return sb_download_page ($esv_url);
}
// Converts XML string to object
function sb_get_xml ($content) {
if (class_exists('SimpleXMLElement')) {
$xml = new SimpleXMLElement($content);
} else {
$xml = new SimpleXMLElement4();
$xml = $xml->xml_load_file($content, 'object', 'utf-8');
}
return $xml;
}
//Returns NET Bible text
function sb_add_net_text ($start, $end) {
$reference = str_replace(' ', '+', sb_tidy_reference ($start, $end));
$old_chapter = $start['chapter'];
$net_url = "http://labs.bible.org/api/xml/verse.php?passage={$reference}";
if (class_exists('SimpleXMLElement')) // Ignore paragraph formatting on PHP4 because xml_parse_into_struct doesn't like HTML tags
$xml = sb_get_xml(sb_download_page($net_url.'&formatting=para'));
else
$xml = sb_get_xml(sb_download_page($net_url));
$output='';
$items = array();
$items = $xml->item;
foreach ($items as $item) {
if ($item->text != '[[EMPTY]]') {
if (substr($item->text, 0, 8) == '<p class') {
$paraend = stripos($item->text, '>', 8)+1;
$output .= "\n".substr($item->text, 0, $paraend);
$item->text = substr ($item->text, $paraend);
}
if ($old_chapter == $item->chapter) {
$output .= " <span class=\"verse-num\">{$item->verse}</span>";
} else {
$output .= " <span class=\"chapter-num\">{$item->chapter}:{$item->verse}</span> ";
$old_chapter = strval($item->chapter);
}
$output .= $item->text;
}
}
return "<div class=\"net\">\r<h2>".sb_tidy_reference ($start, $end)."</h2><p>{$output} (<a href=\"http://net.bible.org/?{$reference}\">NET Bible</a>)</p></div>";
}
//Returns Bible text using SermonBrowser's own API
function sb_add_other_bibles ($start, $end, $version) {
if ($version == 'hnv')
return '<div class="'.$version.'"><p>Sorry, the Hebrew Names Version is no longer available.</p></div>';
$reference = str_replace(' ', '+', sb_tidy_reference ($start, $end));
$reference = str_replace('Psalm+', 'Psalms+', $reference); //Fix for API "Psalms" vs "Psalm"
$old_chapter = $start['chapter'];
$url = "http://api.preachingcentral.com/bible.php?passage={$reference}&version={$version}";
$xml = sb_get_xml(sb_download_page($url));
$output='';
$items = array();
$items = $xml->range->item;
if ($xml->range->item)
foreach ($xml->range->item as $item) {
if ($item->text != '[[EMPTY]]') {
if ($old_chapter == $item->chapter) {
$output .= " <span class=\"verse-num\">{$item->verse}</span>";
} else {
$output .= " <span class=\"chapter-num\">{$item->chapter}:{$item->verse}</span> ";
$old_chapter = strval($item->chapter);
}
$output .= $item->text;
}
}
return '<div class="'.$version.'"><h2>'.sb_tidy_reference ($start, $end). '</h2><p>'.$output.' (<a href="http://biblepro.bibleocean.com/dox/default.aspx">'. strtoupper($version). '</a>)</p></div>';
}
//Adds edit sermon link if current user has edit rights
function sb_edit_link ($id) {
if (current_user_can('publish_posts')) {
$id = (int)$id;
echo '<div class="sb_edit_link"><a href="'.site_url().'/wp-admin/admin.php?page=sermon-browser/new_sermon.php&mid='.$id.'">Edit Sermon</a></div>';
}
}
// Returns URL for search links
function sb_build_url($arr, $clear = false, $relative_link = false) {
global $wpdb;
// Word list for URL building purpose
$wl = array('preacher', 'title', 'date', 'enddate', 'series', 'service', 'sortby', 'dir', 'book', 'stag', 'podcast');
$foo = array_merge((array) $_GET, (array) $_POST, $arr);
foreach ($foo as $k => $v) {
if (in_array($k, array_keys($arr)) | (in_array($k, $wl) && !$clear)) {
$bar[] = rawurlencode($k).'='.rawurlencode($v);
}
}
if (isset($bar)) {
if ($relative_link and get_option('permalink_structure')) // relative links don't work if pretty permalinks are not being used
return sb_query_char().implode('&', $bar);
else
return sb_display_url().sb_query_char().implode('&', $bar);
}
else {
return sb_display_url();
}
}
// Adds javascript and CSS where required
function sb_add_headers() {
global $sermon_domain, $post, $wpdb, $wp_scripts;
if (isset($post->ID) && $post->ID != '') {
echo "<!-- Added by SermonBrowser (version ".SB_CURRENT_VERSION.") - http://www.sermonbrowser.com/ -->\r";
echo "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"".__('Sermon podcast', $sermon_domain)."\" href=\"".sb_get_option('podcast_url')."\" />\r";
wp_enqueue_style('sb_style');
$pageid = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%[sermons%' AND (post_status = 'publish' OR post_status = 'private') AND ID={$post->ID} AND post_date < NOW();");
if ($pageid !== NULL) {
if (sb_get_option('filter_type') == 'dropdown') {
wp_enqueue_script('sb_datepicker');
wp_enqueue_style ('sb_datepicker');
}
if (isset($_REQUEST['title']) || isset($_REQUEST['preacher']) || isset($_REQUEST['date']) || isset($_REQUEST['enddate']) || isset($_REQUEST['series']) || isset($_REQUEST['service']) || isset($_REQUEST['book']) || isset($_REQUEST['stag']))
echo "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"".__('Custom sermon podcast', $sermon_domain)."\" href=\"".sb_podcast_url()."\" />\r";
wp_enqueue_script('jquery');
} else {
$sidebars_widgets = wp_get_sidebars_widgets();
if (isset($sidebars_widgets['wp_inactive_widgets']))
unset($sidebars_widgets['wp_inactive_widgets']);
if (is_array($sidebars_widgets))
foreach ($sidebars_widgets as $sb_w)
if (is_array($sb_w) && in_array('sermon-browser-popular', $sb_w))
wp_enqueue_script('jquery');
}
}
}
// Formats date into words
function sb_formatted_date ($sermon) {
global $sermon_domain;
if (isset($sermon->time) && $sermon->time != '')
$sermon_time = $sermon->time;
else
$sermon_time = sb_default_time ($sermon->sid);
if ($sermon->datetime == '1970-01-01 00:00:00')
return __('Unknown Date', $sermon_domain);
else
return date_i18n(get_option('date_format'), strtotime($sermon->datetime));
}
// Returns podcast URL
function sb_podcast_url() {
return str_replace(' ', '%20', sb_build_url(array('podcast' => 1, 'dir'=>'desc', 'sortby'=>'m.datetime')));
}
// Prints sermon search URL
function sb_print_sermon_link($sermon, $echo = true, $relative_link = true) {
if ($echo)
echo sb_build_url(array('sermon_id' => $sermon->id), true, $relative_link);
else
return sb_build_url(array('sermon_id' => $sermon->id), true, $relative_link);
}
// Prints preacher search URL
function sb_print_preacher_link($sermon, $relative_link = true) {
echo sb_build_url(array('preacher' => $sermon->pid), false, $relative_link);
}
// Prints series search URL
function sb_print_series_link($sermon) {
echo sb_build_url(array('series' => $sermon->ssid), false, true);
}
// Prints service search URL
function sb_print_service_link($sermon) {
echo sb_build_url(array('service' => $sermon->sid), false, true);
}
// Prints bible book search URL
function sb_get_book_link($book_name, $relative_link = true) {
return sb_build_url(array('book' => $book_name), false, $relative_link);
}
// Prints tag search URL
function sb_get_tag_link($tag, $relative_link = true) {
return sb_build_url(array('stag' => $tag), false, $relative_link);
}
// Prints tags
function sb_print_tags($tags) {
$out = array();
foreach ((array) $tags as $tag) {
$tag = stripslashes($tag);
$out[] = '<a href="'.sb_get_tag_link($tag).'">'.$tag.'</a>';
}
$tags = implode(', ', (array) $out);
echo $tags;
}
//Prints tag cloud
function sb_print_tag_clouds($minfont=80, $maxfont=150) {
global $wpdb;
$rawtags = $wpdb->get_results("SELECT name FROM {$wpdb->prefix}sb_tags as t RIGHT JOIN {$wpdb->prefix}sb_sermons_tags as st ON t.id = st.tag_id");
foreach ($rawtags as $tag) {
if (isset($cnt[$tag->name]))
$cnt[$tag->name]++;
else
$cnt[$tag->name] = 1;
}
unset($cnt['']);
$fontrange = $maxfont - $minfont;
$maxcnt = 0;
$mincnt = 1000000;
foreach ($cnt as $cur) {
if ($cur > $maxcnt) $maxcnt = $cur;
if ($cur < $mincnt) $mincnt = $cur;
}
$cntrange = $maxcnt + 1 - $mincnt;
$minlog = log($mincnt);
$maxlog = log($maxcnt);
$logrange = $maxlog == $minlog ? 1 : $maxlog - $minlog;
arsort($cnt);
foreach ($cnt as $tag => $count) {
$size = $minfont + $fontrange * (log($count) - $minlog) / $logrange;
$out[] = '<a style="font-size:'.(int) $size.'%" href="'.sb_get_tag_link($tag, FALSE).'">'.$tag.'</a>';
}
echo implode(' ', $out);
}
//Prints link to next page
function sb_print_next_page_link($limit = 0) {
global $sermon_domain, $record_count;
if ($limit == 0)
$limit = sb_get_option('sermons_per_page');
$current = isset($_REQUEST['pagenum']) ? (int) $_REQUEST['pagenum'] : 1;
if ($current < ceil($record_count / $limit)) {
$url = sb_build_url(array('pagenum' => ++$current), false, true);
echo '<a href="'.$url.'">'.__('Next page', $sermon_domain).' »</a>';
}
}
//Prints link to previous page
function sb_print_prev_page_link($limit = 0) {
global $sermon_domain;
if ($limit == 0) $limit = sb_get_option('sermons_per_page');
$current = isset($_REQUEST['pagenum']) ? (int) $_REQUEST['pagenum'] : 1;
if ($current > 1) {
$url = sb_build_url(array('pagenum' => --$current), false, true);
echo '<a href="'.$url.'">« '.__('Previous page', $sermon_domain).'</a>';
}
}
// Print link to attached files
function sb_print_url($url) {
global $sermon_domain;
require (SB_INCLUDES_DIR.'/filetypes.php');
$pathinfo = pathinfo($url);
$ext = $pathinfo['extension'];
if ((substr($url,0,7) == "http://") or (substr($url,0,8) == 'https://'))
$url=sb_display_url().sb_query_char(FALSE).'show&url='.rawurlencode($url);
else
if (strtolower($ext) == 'mp3')
$url=sb_display_url().sb_query_char(FALSE).'show&file_name='.rawurlencode($url);
else
$url=sb_display_url().sb_query_char(FALSE).'download&file_name='.rawurlencode($url);
$uicon = $default_site_icon;
foreach ($siteicons as $site => $icon) {
if (strpos($url, $site) !== false) {
$uicon = $icon;
break;
}
}
$uicon = isset($filetypes[$ext]['icon']) ? $filetypes[$ext]['icon'] : $uicon;
if (strtolower($ext) == 'mp3') {
if ((substr(sb_get_option('mp3_shortcode'), 0, 18) == '[audio:%SERMONURL%') && function_exists('ap_insert_player_widgets')) {
echo ap_insert_player_widgets(str_ireplace('%SERMONURL%', $url, sb_get_option('mp3_shortcode')));
return;
} elseif (do_shortcode(sb_get_option('mp3_shortcode')) != sb_get_option('mp3_shortcode')) {
echo do_shortcode(str_ireplace('%SERMONURL%', $url, sb_get_option('mp3_shortcode')));
return;
}
}
$uicon = SB_PLUGIN_URL.'/sb-includes/icons/'.$uicon;
if (!isset($filetypes[$ext]['name']))
$filetypes[$ext]['name'] = sprintf(__('%s file', $sermon_domain), addslashes($ext));
else
$filetypes[$ext]['name'] = addslashes($filetypes[$ext]['name']);
echo "<a href=\"{$url}\"><img class=\"site-icon\" alt=\"{$filetypes[$ext]['name']}\" title=\"{$filetypes[$ext]['name']}\" src=\"{$uicon}\"></a>";
}
// Print link to attached external URLs
function sb_print_url_link($url) {
global $sermon_domain;
echo '<div class="sermon_file">';
sb_print_url ($url);
if (substr($url, -4) == ".mp3") {
if ((substr($url,0,7) == "http://") or (substr($url,0,8) == 'https://')) {
$param="url"; }
else {
$param="file_name"; }
$url = rawurlencode($url);
echo ' <a href="'.sb_display_url().sb_query_char().'download&'.$param.'='.$url.'">'.__('Download', $sermon_domain).'</a>';
}
echo '</div>';
}
//Decode base64 encoded data
function sb_print_code($code) {
echo do_shortcode(base64_decode($code));
}
//Prints preacher description
function sb_print_preacher_description($sermon) {
global $sermon_domain;
if (strlen($sermon->preacher_description)>0) {
echo "<div class='preacher-description'><span class='about'>" . __('About', $sermon_domain).' '.stripslashes($sermon->preacher).': </span>';
echo "<span class='description'>".stripslashes($sermon->preacher_description)."</span></div>";
}
}
//Prints preacher image
function sb_print_preacher_image($sermon) {
if ($sermon->image)
echo "<img alt='".stripslashes($sermon->preacher)."' class='preacher' src='".trailingslashit(site_url()).sb_get_option('upload_dir').'images/'.$sermon->image."'>";
}
//Prints link to sermon preached next (but not today)
function sb_print_next_sermon_link($sermon) {
global $wpdb;
$next = $wpdb->get_row("SELECT id, title FROM {$wpdb->prefix}sb_sermons WHERE DATE(datetime) > DATE('{$sermon->datetime}') AND id <> {$sermon->id} ORDER BY datetime asc LIMIT 1");
if (!$next) return;
echo '<a href="';
sb_print_sermon_link($next);
echo '">'.stripslashes($next->title).' »</a>';
}
//Prints link to sermon preached on previous days
function sb_print_prev_sermon_link($sermon) {
global $wpdb;
$prev = $wpdb->get_row("SELECT id, title FROM {$wpdb->prefix}sb_sermons WHERE DATE(datetime) < DATE('{$sermon->datetime}') AND id <> {$sermon->id} ORDER BY datetime desc LIMIT 1");
if (!$prev) return;
echo '<a href="';
sb_print_sermon_link($prev);
echo '">« '.stripslashes($prev->title).'</a>';
}
//Prints links to other sermons preached on the same day
function sb_print_sameday_sermon_link($sermon) {
global $wpdb, $sermon_domain;
$same = $wpdb->get_results("SELECT id, title FROM {$wpdb->prefix}sb_sermons WHERE DATE(datetime) = DATE('{$sermon->datetime}') AND id <> {$sermon->id}");
if (!$same) {
_e('None', $sermon_domain);
return;
}
$output = array();
foreach ($same as $cur)
$output[] = '<a href="'.sb_print_sermon_link($cur, false).'">'.stripslashes($cur->title).'</a>';
echo implode($output, ', ');
}
//Gets single sermon from the database
function sb_get_single_sermon($id) {
global $wpdb;
$id = (int) $id;
$sermon = $wpdb->get_row("SELECT m.id, m.title, m.datetime, m.start, m.end, m.description, p.id as pid, p.name as preacher, p.image as image, p.description as preacher_description, s.id as sid, s.name as service FROM {$wpdb->prefix}sb_sermons as m, {$wpdb->prefix}sb_preachers as p, {$wpdb->prefix}sb_services as s where m.preacher_id = p.id and m.service_id = s.id and m.id = {$id}");
$series = $wpdb->get_row("SELECT ss.id as ssid, ss.name as series FROM {$wpdb->prefix}sb_sermons as m, {$wpdb->prefix}sb_series as ss WHERE m.series_id = ss.id and m.id = {$id}");
if ($sermon) {
if ($series) {
$sermon->series = $series->series;
$sermon->ssid = $series->ssid;
}
else {
$sermon->series = '';
$sermon->ssid = 0;
}
$file = $code = $tags = array();
$stuff = $wpdb->get_results("SELECT f.id, f.type, f.name FROM {$wpdb->prefix}sb_stuff as f WHERE sermon_id = $id ORDER BY id desc");
$rawtags = $wpdb->get_results("SELECT t.name FROM {$wpdb->prefix}sb_sermons_tags as st LEFT JOIN {$wpdb->prefix}sb_tags as t ON st.tag_id = t.id WHERE st.sermon_id = {$sermon->id} ORDER BY t.name asc");
foreach ($rawtags as $tag) {
$tags[] = $tag->name;
}
foreach ($stuff as $cur)
${$cur->type}[] = $cur->name;
$sermon->start = unserialize($sermon->start);
$sermon->end = unserialize($sermon->end);
return array(
'Sermon' => $sermon,
'Files' => $file,
'Code' => $code,
'Tags' => $tags,
);
} else
return false;
}
//Prints the filter line for a given parameter
function sb_print_filter_line ($id, $results, $filter, $display, $max_num = 7) {
global $sermon_domain, $more_applied;
$translate_book = FALSE;
if ($id == 'book') {
$translate_book = TRUE;
$translated_books = array_combine(sb_get_default('eng_bible_books'), sb_get_default('bible_books'));
}
echo "<div id = \"{$id}\" class=\"filter\">\r<span class=\"filter-heading\">".__(ucwords($id), $sermon_domain).":</span> \r";
$i = 1;
$more = FALSE;
foreach ($results as $result) {
if ($i == $max_num) {
echo "<span id=\"{$id}-more\">";
$more = TRUE;
$more_applied[] = $id;
}
if ($i != 1)
echo ", \r";
if ($translate_book) {
echo '<a href="'.sb_build_url(array($id => $result->$filter), false, true).'">'.$translated_books[stripslashes($result->$display)].'</a> ('.$result->count.')';
}
else {
echo '<a href="'.sb_build_url(array($id => $result->$filter), false, true).'">'.stripslashes($result->$display).'</a> ('.$result->count.')';
}
$i++;
}
echo ".";
if ($more)
echo "</span>\r<span id=\"{$id}-more-link\" style=\"display:none\">… (<a id=\"{$id}-toggle\" href=\"#\"><strong>".($i-$max_num).' '.__('more', $sermon_domain).'</strong></a>)</span>';
echo '</div>';
}
//Prints the filter line for the date parameter
function sb_print_date_filter_line ($dates) {
global $more_applied, $sermon_domain;
$date_output = "<div id = \"dates\" class=\"filter\">\r<span class=\"filter-heading\">".__('Date', $sermon_domain).":</span> \r";
$first = $dates[0];
$last = end($dates);
$count = 0;
if ($first->year == $last->year) {
if ($first->month == $last->month) {
$date_output = '';
} else {
$previous_month = -1;
foreach ($dates as $date) {
if ($date->month != $previous_month) {
if ($count != 0)
$date_output .= '('.$count.'), ';
$date_output .= '<a href="'.sb_build_url(Array ('date' => $date->year.'-'.$date->month.'-01', 'enddate' => $date->year.'-'.$date->month.'-31'), false, true).'">'.strftime('%B', strtotime("{$date->year}-{$date->month}-{$date->day}")).'</a> ';
$previous_month = $date->month;
$count = 1;
} else
$count++;
}
$date_output .= '('.$count.'), ';
}
} else {
$previous_year = 0;
foreach ($dates as $date) {
if ($date->year !== $previous_year) {
if ($count !== 0)
$date_output .= '('.$count.'), ';
$date_output .= '<a href="'.sb_build_url(Array ('date' => $date->year.'-01-01', 'enddate' => $date->year.'-12-31'), false, true).'">'.$date->year.'</a> ';
$previous_year = $date->year;
$count = 1;
} else
$count++;
}
$date_output .= '('.$count.'), ';
}
if ($date_output != '')
echo rtrim($date_output, ', ')."</div>\r";
}
//Returns the filter URL minus a given parameter
function sb_url_minus_parameter ($param1, $param2='') {
global $filter_options;
$existing_params = array_merge((array) $_GET, (array) $_POST);
$returned_query = array();
foreach (array_keys($existing_params) as $query) {
if (in_array($query, $filter_options) && $query != $param1 && $query != $param2) {
$returned_query[] = "{$query}={$existing_params[$query]}";
}
}
if (count($returned_query) > 0)
return sb_display_url().sb_query_char().implode('&', $returned_query);
else
return sb_display_url();
}
//Displays the filter on sermon search page
function sb_print_filters($filter) {
global $wpdb, $sermon_domain, $more_applied, $filter_options;
$hide_filter = FALSE;
if ($filter['filterhide'] == 'hide') {
$hide_filter = TRUE;
$js_hide = "
var filter_visible = false;
jQuery('#mainfilter').hide();
jQuery('#show_hide_filter').text('[ SHOW ]');
jQuery('#show_hide_filter').click(function() {
jQuery('#mainfilter:visible').slideUp('slow');
jQuery('#mainfilter:hidden').slideDown('slow');
if (filter_visible) {
jQuery('#show_hide_filter').text('[ SHOW ]');
filter_visible = false;
} else {
jQuery('#show_hide_filter').text('[ HIDE ]');
filter_visible = true;
}
return false;
});";
$js_hide = str_replace ('SHOW', __('Show filter', $sermon_domain), $js_hide);
$js_hide = str_replace ('HIDE', __('Hide filter', $sermon_domain), $js_hide);
}
if ($filter['filter'] == 'oneclick') {
// One click filter
$hide_custom_podcast = true;
$filter_options = array ('preacher', 'book', 'service', 'series', 'date', 'enddate', 'title');
$output = '';
foreach ($filter_options AS $filter_option)
if (isset($_REQUEST[$filter_option])) {
if ($filter_option != 'enddate') {
if ($output != '')
$output .= "\r, ";
if ($filter_option == 'date') {
$output .= '<strong>'.__('Date', $sermon_domain).'</strong>: ';
if (substr($_REQUEST['date'],0,4) == substr($_REQUEST['enddate'],0,4))
$output .= substr($_REQUEST['date'],0,4).' (<a href="'.sb_url_minus_parameter('date', 'enddate').'">x</a>)';
if (substr($_REQUEST['date'],5,2) == substr($_REQUEST['enddate'],5,2))
$output .= ', '.strftime('%B', strtotime($_REQUEST['date'])).' (<a href="'.sb_build_url(Array ('date' => substr($_REQUEST['date'],0,4).'-01-01', 'enddate' => substr($_REQUEST['date'],0,4).'-12-31'), false, true).'">x</a>)';
} else {
$output .= '<strong>'.__(ucwords($filter_option), $sermon_domain).'</strong>: *'.$filter_option.'*';
$output .= ' (<a href="'.sb_url_minus_parameter($filter_option).'">x</a>)';
}
}
$hide_custom_podcast = FALSE;
}
$hide_empty = sb_get_option('hide_no_attachments');
$sermons=sb_get_sermons($filter, array(), 1, 99999, $hide_empty);
$ids = array();
foreach ($sermons as $sermon)
$ids[] = $sermon->id;
$ids = "('".implode ("', '", $ids)."')";
$preachers = $wpdb->get_results("SELECT p.*, count(p.id) AS count FROM {$wpdb->prefix}sb_preachers AS p JOIN {$wpdb->prefix}sb_sermons AS sermons ON p.id = sermons.preacher_id WHERE sermons.id IN {$ids} GROUP BY p.id ORDER BY count DESC, sermons.datetime DESC");
//$series = $wpdb->get_results("SELECT ss.*, count(ss.id) AS count FROM {$wpdb->prefix}sb_series AS ss JOIN {$wpdb->prefix}sb_sermons AS sermons ON ss.id = sermons.series_id WHERE sermons.id IN {$ids} GROUP BY ss.id ORDER BY sermons.datetime DESC");
$series = $wpdb->get_results("SELECT ss.*
FROM {$wpdb->prefix}sb_series AS ss
JOIN {$wpdb->prefix}sb_sermons AS sermons ON ss.id = sermons.series_id
JOIN {$wpdb->prefix}sb_books_sermons ON sermons.id = {$wpdb->prefix}sb_books_sermons.sermon_id
JOIN {$wpdb->prefix}sb_books ON {$wpdb->prefix}sb_books_sermons.book_name = {$wpdb->prefix}sb_books.name
GROUP BY ss.id ORDER BY {$wpdb->prefix}sb_books.order DESC");
$services = $wpdb->get_results("SELECT s.*, count(s.id) AS count FROM {$wpdb->prefix}sb_services AS s JOIN {$wpdb->prefix}sb_sermons AS sermons ON s.id = sermons.service_id WHERE sermons.id IN {$ids} GROUP BY s.id ORDER BY count DESC");
$book_count = $wpdb->get_results("SELECT bs.book_name AS name, count(distinct bs.sermon_id) AS count FROM {$wpdb->prefix}sb_books_sermons AS bs JOIN {$wpdb->prefix}sb_books as b ON bs.book_name=b.name AND bs.sermon_id IN {$ids} GROUP BY b.id");
$dates = $wpdb->get_results("SELECT YEAR(datetime) as year, MONTH (datetime) as month, DAY(datetime) as day FROM {$wpdb->prefix}sb_sermons WHERE id IN {$ids} ORDER BY datetime ASC");
$more_applied = array();
$output = str_replace ('*preacher*', isset($preachers[0]->name) ? $preachers[0]->name : '', $output);
$output = str_replace ('*book*', isset($_REQUEST['book']) ? __(htmlentities($_REQUEST['book']), $sermon_domain) : '', $output);
$output = str_replace ('*service*', isset($services[0]->name) ? $services[0]->name : '', $output);
$output = str_replace ('*series*', isset($series[0]->name) ? $series[0]->name : '', $output);
echo "<span class=\"inline_controls\"><a href=\"#\" id=\"show_hide_filter\"></a></span>";
if ($output != '')
echo '<div class="filtered">'.__('Active filter', $sermon_domain).': '.$output."</div>\r";
echo '<div id="mainfilter">';
if (count($preachers) > 1)
sb_print_filter_line ('preacher', $preachers, 'id', 'name', 7);
if (count($book_count) > 1)
sb_print_filter_line ('book', $book_count, 'name', 'name', 10);
if (count($series) > 1)
sb_print_filter_line ('series', $series, 'id', 'name', 10);
if (count($services) > 1)
sb_print_filter_line ('service', $services, 'id', 'name', 10);
sb_print_date_filter_line ($dates);
echo "</div>\r";
if (count($more_applied) > 0 | $output != '' | $hide_custom_podcast === TRUE | $hide_filter === TRUE) {
echo "<script type=\"text/javascript\">\r";
echo "\tjQuery(document).ready(function() {\r";
if ($hide_filter === TRUE)
echo $js_hide."\r";
if ($hide_custom_podcast === TRUE)
echo "\t\tjQuery('.podcastcustom').hide();\r";
if (count($more_applied) > 0) {
foreach ($more_applied as $element_id) {
echo "\t\tjQuery('#{$element_id}-more').hide();\r";
echo "\t\tjQuery('#{$element_id}-more-link').show();\r";
echo "\t\tjQuery('a#{$element_id}-toggle').click(function() {\r";