SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | // Error message for people using the old function | |
3 | function display_sermons($options = array()) { | |
4 | echo "This function is now deprecated. Use sb_display_sermons or the sermon browser widget, instead."; | |
5 | } | |
6 | // Function to display sermons for users to add to their template | |
7 | function sb_display_sermons($options = array()) { | |
8 | $default = array( | |
9 | 'display_preacher' => 1, | |
10 | 'display_passage' => 1, | |
11 | 'display_date' => 1, | |
12 | 'display_player' => 0, | |
13 | 'preacher' => 0, | |
14 | 'service' => 0, | |
15 | 'series' => 0, | |
16 | 'limit' => 5, | |
17 | 'url_only' => 0, | |
18 | ); | |
19 | $options = array_merge($default, (array) $options); | |
20 | extract($options); | |
21 | if ($url_only == 1) | |
22 | $limit = 1; | |
23 | $sermons = sb_get_sermons(array( | |
24 | 'preacher' => $preacher, | |
25 | 'service' => $service, | |
26 | 'series' => $series | |
27 | ), | |
28 | array(), 1, $limit | |
29 | ); | |
30 | if ($url_only == 1) | |
31 | sb_print_sermon_link($sermons[0], true, false); | |
32 | else { | |
33 | echo "<ul class=\"sermon-widget\">\r"; | |
34 | foreach ((array) $sermons as $sermon) { | |
35 | echo "\t<li>"; | |
36 | echo "<span class=\"sermon-title\"><a href=\""; | |
37 | sb_print_sermon_link($sermon, true, false); | |
38 | echo "\">".stripslashes($sermon->title)."</a></span>"; | |
39 | if ($display_passage) { | |
40 | $foo = unserialize($sermon->start); | |
41 | $bar = unserialize($sermon->end); | |
42 | echo "<span class=\"sermon-passage\"> (".sb_get_books($foo[0], $bar[0]).")</span>"; | |
43 | } | |
44 | if ($display_preacher) { | |
45 | echo "<span class=\"sermon-preacher\">".__('by', $sermon_domain)." <a href=\""; | |
46 | sb_print_preacher_link($sermon, false); | |
47 | echo "\">".stripslashes($sermon->preacher)."</a></span>"; | |
48 | } | |
49 | if ($display_date) | |
50 | echo " <span class=\"sermon-date\">".__('on', $sermon_domain)." ".sb_formatted_date ($sermon)."</span>"; | |
51 | if ($display_player) | |
52 | sb_display_mini_player($sermon); | |
53 | echo ".</li>\r"; | |
54 | } | |
55 | echo "</ul>\r"; | |
56 | } | |
57 | } | |
58 | ||
59 | // Displays the widget | |
60 | function sb_widget_sermon($args, $widget_args=1) { | |
61 | global $sermon_domain; | |
62 | extract( $args, EXTR_SKIP ); | |
63 | if ( is_numeric($widget_args) ) | |
64 | $widget_args = array( 'number' => $widget_args ); | |
65 | $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); | |
66 | extract( $widget_args, EXTR_SKIP ); | |
67 | $options = sb_get_option('sermons_widget_options'); | |
68 | if ( !isset($options[$number]) ) | |
69 | return; | |
70 | extract($options[$number]); | |
71 | echo $before_widget; | |
72 | echo $before_title . $title . $after_title; | |
73 | $sermons = sb_get_sermons(array( | |
74 | 'preacher' => $preacher, | |
75 | 'service' => $service, | |
76 | 'series' => $series | |
77 | ), | |
78 | array(), 1, $limit | |
79 | ); | |
80 | $i=0; | |
81 | echo "<ul class=\"sermon-widget\">"; | |
82 | foreach ((array) $sermons as $sermon){ | |
83 | $i++; | |
84 | echo "<li><span class=\"sermon-title\">"; | |
85 | echo "<a href=".sb_build_url(array('sermon_id' => $sermon->id), true).">".stripslashes($sermon->title)."</a></span>"; | |
86 | if ($book) { | |
87 | $foo = unserialize($sermon->start); | |
88 | $bar = unserialize($sermon->end); | |
89 | if (isset ($foo[0]) && isset($bar[0])) | |
90 | echo " <span class=\"sermon-passage\">(".sb_get_books($foo[0], $bar[0], FALSE).")</span>"; | |
91 | } | |
92 | if ($preacherz) { | |
93 | echo " <span class=\"sermon-preacher\">".__('by', $sermon_domain)." <a href=\""; | |
94 | sb_print_preacher_link($sermon, false); | |
95 | echo "\">".stripslashes($sermon->preacher)."</a></span>"; | |
96 | } | |
97 | if ($date) | |
98 | echo " <span class=\"sermon-date\">".__(' on ', $sermon_domain).sb_formatted_date ($sermon)."</span>"; | |
99 | if ($player) | |
100 | sb_display_mini_player($sermon, $i); | |
101 | echo ".</li>"; | |
102 | } | |
103 | echo "</ul>"; | |
104 | echo $after_widget; | |
105 | } | |
106 | ||
107 | // Displays the tag cloud in the sidebar | |
108 | function sb_widget_tag_cloud ($args) { | |
109 | global $sermon_domain; | |
110 | extract($args); | |
111 | echo $before_widget; | |
112 | echo $before_title.__('Sermon Browser tags', $sermon_domain).$after_title; | |
113 | sb_print_tag_clouds(); | |
114 | echo $after_widget; | |
115 | } | |
116 | ||
117 | function sb_admin_bar_menu () { | |
118 | global $wp_admin_bar, $sermon_domain; | |
119 | if (!current_user_can('edit_posts') || !class_exists('WP_Admin_Bar')) | |
120 | return; | |
121 | if (isset($_GET['sermon_id']) && (int)$_GET['sermon_id'] != 0 && current_user_can('publish_pages')) { | |
122 | $wp_admin_bar->add_menu(array('id' => 'sermon-browser-menu', 'title' => __('Edit Lecture', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/new_sermon.php&mid='.(int)$_GET['sermon_id']))); | |
123 | $wp_admin_bar->add_menu(array('parent' => 'sermon-browser-menu', 'id' => 'sermon-browser-sermons', 'title' => __('List Lectures', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/sermon.php'))); | |
124 | } else { | |
125 | $wp_admin_bar->add_menu(array('id' => 'sermon-browser-menu', 'title' => __('Lectures', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/sermon.php'))); | |
126 | if (current_user_can('publish_pages')) | |
127 | $wp_admin_bar->add_menu(array('parent' => 'sermon-browser-menu', 'id' => 'sermon-browser-add', 'title' => __('Add Lectures', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/new_sermon.php'))); | |
128 | } | |
129 | if (current_user_can('upload_files')) | |
130 | $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'))); | |
131 | if (current_user_can('manage_categories')) { | |
132 | $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'))); | |
133 | $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'))); | |
134 | } | |
135 | if (current_user_can('manage_options')) { | |
136 | $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'))); | |
137 | $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'))); | |
138 | } | |
139 | if (current_user_can('edit_plugins')) | |
140 | $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'))); | |
141 | $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'))); | |
142 | $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'))); | |
143 | $wp_admin_bar->add_menu(array('parent' => 'new-content', 'id' => 'sermon-browser-add2', 'title' => __('Lecture', $sermon_domain), 'href' => admin_url('admin.php?page=sermon-browser/new_sermon.php'))); | |
144 | } | |
145 | ||
146 | // Sorts an object by rank | |
147 | function sb_sort_object($a,$b) { | |
148 | if( $a->rank == $b->rank ) | |
149 | return 0; | |
150 | return ($a->rank < $b->rank) ? -1 : 1; | |
151 | } | |
152 | ||
153 | // Displays the most popular sermons in the sidebar | |
154 | function sb_widget_popular ($args) { | |
155 | ||
156 | global $wpdb, $sermon_domain; | |
157 | extract($args); | |
158 | if (!isset($suffix)) | |
159 | $suffix = '_w'; | |
160 | if (!isset($options)) | |
161 | $options = sb_get_option('popular_widget_options'); | |
162 | echo $before_widget; | |
163 | if ($options['title'] != '') | |
164 | echo $before_title.$options['title'].$after_title; | |
165 | $jscript = ''; | |
166 | $trigger = array(); | |
167 | $output = array(); | |
168 | $series_final = array(); | |
169 | $preachers_final = array(); | |
170 | if ($options['display_sermons']) { | |
171 | $sermons = $wpdb->get_results("SELECT sermons.id, sermons.title, sum(stuff.count) AS total | |
172 | FROM {$wpdb->prefix}sb_stuff AS stuff | |
173 | LEFT JOIN {$wpdb->prefix}sb_sermons AS sermons ON stuff.sermon_id = sermons.id | |
174 | GROUP BY sermons.id ORDER BY total DESC LIMIT 0, {$options['limit']}"); | |
175 | if ($sermons) { | |
176 | $output['sermons'] = '<div class="popular-sermons'.$suffix.'"><ul>'; | |
177 | foreach ($sermons as $sermon) | |
178 | $output['sermons'] .= '<li><a href="'.sb_build_url(array('sermon_id' => $sermon->id), true).'">'.$sermon->title.'</a></li>'; | |
179 | $output['sermons'] .= '</ul></div>'; | |
180 | $trigger[] = '<a id="popular_sermons_trigger'.$suffix.'" href="#">Lectures</a>'; | |
181 | $jscript .= 'jQuery("#popular_sermons_trigger'.$suffix.'").click(function() { | |
182 | jQuery(this).attr("style", "font-weight:bold"); | |
183 | jQuery("#popular_series_trigger'.$suffix.'").removeAttr("style"); | |
184 | jQuery("#popular_preachers_trigger'.$suffix.'").removeAttr("style"); | |
185 | jQuery.setSbCookie ("sermons"); | |
186 | jQuery("#sb_popular_wrapper'.$suffix.'").fadeOut("slow", function() { | |
187 | jQuery("#sb_popular_wrapper'.$suffix.'").html("'.addslashes($output['sermons']).'").fadeIn("slow"); | |
188 | }); | |
189 | return false; | |
190 | });'; | |
191 | } | |
192 | } | |
193 | ||
194 | if ($options['display_series']) { | |
195 | $series1 = $wpdb->get_results("SELECT series.id, series.name, avg(stuff.count) AS average | |
196 | FROM {$wpdb->prefix}sb_stuff AS stuff | |
197 | LEFT JOIN {$wpdb->prefix}sb_sermons AS sermons ON stuff.sermon_id = sermons.id | |
198 | LEFT JOIN {$wpdb->prefix}sb_series AS series ON sermons.series_id = series.id | |
199 | GROUP BY series.id ORDER BY average DESC"); | |
200 | $series2 = $wpdb->get_results("SELECT series.id, sum(stuff.count) AS total | |
201 | FROM {$wpdb->prefix}sb_stuff AS stuff | |
202 | LEFT JOIN {$wpdb->prefix}sb_sermons AS sermons ON stuff.sermon_id = sermons.id | |
203 | LEFT JOIN {$wpdb->prefix}sb_series AS series ON sermons.series_id = series.id | |
204 | GROUP BY series.id ORDER BY total DESC"); | |
205 | if ($series1) { | |
206 | $i=1; | |
207 | foreach ($series1 as $series) { | |
208 | $series_final[$series->id]->name = $series->name; | |
209 | $series_final[$series->id]->rank = $i; | |
210 | $series_final[$series->id]->id = $series->id; | |
211 | $i++; | |
212 | } | |
213 | $i=1; | |
214 | foreach ($series2 as $series) { | |
215 | $series_final[$series->id]->rank += $i; | |
216 | $i++; | |
217 | } | |
218 | usort($series_final,'sb_sort_object'); | |
219 | $series_final = array_slice($series_final, 0, $options['limit']); | |
220 | $output['series'] = '<div class="popular-series'.$suffix.'"><ul>'; | |
221 | foreach ($series_final as $series) | |
222 | $output['series'] .= '<li><a href="'.sb_build_url(array('series' => $series->id), true).'">'.$series->name.'</a></li>'; | |
223 | $output['series'] .= '</ul></div>'; | |
224 | } | |
225 | $trigger[] = '<a id="popular_series_trigger'.$suffix.'" href="#">Series</a>'; | |
226 | $jscript .= 'jQuery("#popular_series_trigger'.$suffix.'").click(function() { | |
227 | jQuery(this).attr("style", "font-weight:bold"); | |
228 | jQuery("#popular_sermons_trigger'.$suffix.'").removeAttr("style"); | |
229 | jQuery("#popular_preachers_trigger'.$suffix.'").removeAttr("style"); | |
230 | jQuery.setSbCookie ("series"); | |
231 | jQuery("#sb_popular_wrapper'.$suffix.'").fadeOut("slow", function() { | |
232 | jQuery("#sb_popular_wrapper'.$suffix.'").html("'.addslashes($output['series']).'").fadeIn("slow"); | |
233 | }); | |
234 | return false; | |
235 | });'; | |
236 | } | |
237 | ||
238 | if ($options['display_preachers']) { | |
239 | $preachers1 = $wpdb->get_results("SELECT preachers.id, preachers.name, avg(stuff.count) AS average | |
240 | FROM {$wpdb->prefix}sb_stuff AS stuff | |
241 | LEFT JOIN {$wpdb->prefix}sb_sermons AS sermons ON stuff.sermon_id = sermons.id | |
242 | LEFT JOIN {$wpdb->prefix}sb_preachers AS preachers ON sermons.preacher_id = preachers.id | |
243 | GROUP BY preachers.id | |
244 | ORDER BY average DESC"); | |
245 | $preachers2 = $wpdb->get_results("SELECT preachers.id, sum(stuff.count) AS total | |
246 | FROM {$wpdb->prefix}sb_stuff AS stuff | |
247 | LEFT JOIN {$wpdb->prefix}sb_sermons AS sermons ON stuff.sermon_id = sermons.id | |
248 | LEFT JOIN {$wpdb->prefix}sb_preachers AS preachers ON sermons.preacher_id = preachers.id | |
249 | GROUP BY preachers.id | |
250 | ORDER BY total DESC"); | |
251 | if ($preachers1) { | |
252 | $i=1; | |
253 | foreach ($preachers1 as $preacher) { | |
254 | $preachers_final[$preacher->id]->name = $preacher->name; | |
255 | $preachers_final[$preacher->id]->rank = $i; | |
256 | $preachers_final[$preacher->id]->id = $preacher->id; | |
257 | $i++; | |
258 | } | |
259 | $i=1; | |
260 | foreach ($preachers2 as $preacher) { | |
261 | $preachers_final[$preacher->id]->rank += $i; | |
262 | $i++; | |
263 | } | |
264 | usort($preachers_final,'sb_sort_object'); | |
265 | $preachers_final = array_slice($preachers_final, 0, $options['limit']); | |
266 | $output['preachers'] = '<div class="popular-preachers'.$suffix.'"><ul>'; | |
267 | foreach ($preachers_final as $preacher) | |
268 | $output['preachers'] .= '<li><a href="'.sb_build_url(array('preacher' => $preacher->id), true).'">'.$preacher->name.'</a></li>'; | |
269 | $output['preachers'] .= '</ul></div>'; | |
270 | $trigger[] = '<a id="popular_preachers_trigger'.$suffix.'" href="#">Preachers</a>'; | |
271 | $jscript .= 'jQuery("#popular_preachers_trigger'.$suffix.'").click(function() { | |
272 | jQuery(this).attr("style", "font-weight:bold"); | |
273 | jQuery("#popular_series_trigger'.$suffix.'").removeAttr("style"); | |
274 | jQuery("#popular_sermons_trigger'.$suffix.'").removeAttr("style"); | |
275 | jQuery.setSbCookie("preachers"); | |
276 | jQuery("#sb_popular_wrapper'.$suffix.'").fadeOut("slow", function() { | |
277 | jQuery("#sb_popular_wrapper'.$suffix.'").html("'.addslashes($output['preachers']).'").fadeIn("slow"); | |
278 | }); | |
279 | return false; | |
280 | });'; | |
281 | } | |
282 | } | |
283 | ||
284 | $jscript .= 'if (jQuery.getSbCookie() == "preachers") { jQuery("#popular_preachers_trigger'.$suffix.'").attr("style", "font-weight:bold"); jQuery("#sb_popular_wrapper'.$suffix.'").html("'.addslashes($output['preachers']).'")};'; | |
285 | $jscript .= 'if (jQuery.getSbCookie() == "series") { jQuery("#popular_series_trigger'.$suffix.'").attr("style", "font-weight:bold"); jQuery("#sb_popular_wrapper'.$suffix.'").html("'.addslashes($output['series']).'")};'; | |
286 | $jscript .= 'if (jQuery.getSbCookie() == "sermons") { jQuery("#popular_sermons_trigger'.$suffix.'").attr("style", "font-weight:bold"); jQuery("#sb_popular_wrapper'.$suffix.'").html("'.addslashes($output['sermons']).'")};'; | |
287 | echo '<p>'.implode ($trigger, ' | ').'</p>'; | |
288 | echo '<div id="sb_popular_wrapper'.$suffix.'">'.current($output).'</div>'; | |
289 | echo '<script type="text/javascript">jQuery.setSbCookie = function (value) { | |
290 | document.cookie = "sb_popular="+encodeURIComponent(value); | |
291 | };</script>'; | |
292 | echo '<script type="text/javascript">jQuery.getSbCookie = function () { | |
293 | var cookieValue = null; | |
294 | if (document.cookie && document.cookie != "") { | |
295 | var cookies = document.cookie.split(";"); | |
296 | for (var i = 0; i < cookies.length; i++) { | |
297 | var cookie = jQuery.trim(cookies[i]); | |
298 | var name = "sb_popular"; | |
299 | if (cookie.substring(0, name.length + 1) == (name + "=")) { | |
300 | cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); | |
301 | break; | |
302 | } | |
303 | } | |
304 | } | |
305 | return cookieValue; | |
306 | }</script>'; | |
307 | echo '<script type="text/javascript">jQuery(document).ready(function() {'.$jscript.'});</script>'; | |
308 | echo $after_widget; | |
309 | } | |
310 | ||
311 | function sb_print_most_popular() { | |
312 | $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">'; | |
313 | $args['after_widget'] = '</div>'; | |
314 | $args['before_title'] = '<span class="popular_title">'; | |
315 | $args['after_title'] = '</span>'; | |
316 | $args['suffix'] = '_f'; | |
317 | sb_widget_popular ($args); | |
318 | } | |
319 | ||
320 | //Modify page title | |
321 | function sb_page_title($title) { | |
322 | global $wpdb, $sermon_domain; | |
323 | if (isset($_GET['sermon_id'])) { | |
324 | $id = (int)$_GET['sermon_id']; | |
325 | $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"); | |
326 | if ($sermon) | |
327 | return $title.' ('.stripslashes($sermon->title).' - '.stripslashes($sermon->name).')'; | |
328 | else | |
329 | return $title.' ('.__('No sermons found.', $sermon_domain).')'; | |
330 | } | |
331 | else | |
332 | return $title; | |
333 | } | |
334 | ||
335 | //Downloads external webpage. Used to add Bible passages to sermon page. | |
336 | function sb_download_page ($page_url) { | |
337 | if (function_exists('curl_init')) { | |
338 | $curl = curl_init(); | |
339 | curl_setopt ($curl, CURLOPT_URL, $page_url); | |
340 | curl_setopt ($curl, CURLOPT_TIMEOUT, 2); | |
341 | curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); | |
342 | curl_setopt ($curl, CURLOPT_HTTPHEADER, array('Accept-Charset: utf-8;q=0.7,*;q=0.7')); | |
343 | $contents = curl_exec ($curl); | |
344 | $content_type = curl_getinfo( $curl, CURLINFO_CONTENT_TYPE ); | |
345 | curl_close ($curl); | |
346 | } | |
347 | else | |
348 | { | |
349 | $handle = @fopen ($page_url, 'r'); | |
350 | if ($handle) { | |
351 | stream_set_blocking($handle, TRUE ); | |
352 | stream_set_timeout($handle, 2); | |
353 | $info = socket_get_status($handle); | |
354 | while (!feof($handle) && !$info['timed_out']) { | |
355 | $contents .= fread($handle, 8192); | |
356 | $info = socket_get_status($handle); | |
357 | } | |
358 | @fclose($handle); | |
359 | } | |
360 | } | |
361 | return $contents; | |
362 | } | |
363 | ||
364 | // Returns human friendly Bible reference (e.g. John 3:1-16, not John 3:1-John 3:16) | |
365 | function sb_tidy_reference ($start, $end, $add_link = FALSE, $relative_link = TRUE) { | |
366 | if (!trim($start['book'])) { | |
367 | return ""; | |
368 | } | |
369 | $translated_books = array_combine(sb_get_default('eng_bible_books'), sb_get_default('bible_books')); | |
370 | $start_book = $translated_books[trim($start['book'])]; | |
371 | $end_book = $translated_books[trim($end['book'])]; | |
372 | $start_chapter = trim($start['chapter']); | |
373 | $end_chapter = trim($end['chapter']); | |
374 | $start_verse = trim($start['verse']); | |
375 | $end_verse = trim($end['verse']); | |
376 | if ($add_link) { | |
377 | $start_book = "<a href=\"".sb_get_book_link($start_book, $relative_link)."\">{$start_book}</a>"; | |
378 | $end_book = "<a href=\"".sb_get_book_link($end_book, $relative_link)."\">{$end_book}</a>"; | |
379 | } | |
380 | if ($start_book == $end_book) { | |
381 | if ($start_chapter == $end_chapter) { | |
382 | if ($start_verse == $end_verse) { | |
383 | $reference = "$start_book $start_chapter:$start_verse"; | |
384 | } else { | |
385 | $reference = "$start_book $start_chapter:$start_verse-$end_verse"; | |
386 | } | |
387 | } else { | |
388 | $reference = "$start_book $start_chapter:$start_verse-$end_chapter:$end_verse"; | |
389 | } | |
390 | } else { | |
391 | $reference = "$start_book $start_chapter:$start_verse - $end_book $end_chapter:$end_verse"; | |
392 | } | |
393 | return $reference; | |
394 | } | |
395 | ||
396 | //Print unstyled bible passage | |
397 | function sb_print_bible_passage ($start, $end) { | |
398 | echo "<p class='bible-passage'>".sb_tidy_reference($start, $end)."</p>"; | |
399 | } | |
400 | ||
401 | // Returns human friendly Bible reference with link to filter | |
402 | function sb_get_books($start, $end, $relative_link = TRUE) { | |
403 | return sb_tidy_reference ($start, $end, TRUE, $relative_link); | |
404 | } | |
405 | ||
406 | //Add Bible text to single sermon page | |
407 | function sb_add_bible_text ($start, $end, $version) { | |
408 | if ($version == 'esv') | |
409 | return sb_add_esv_text ($start, $end); | |
410 | elseif ($version == 'net') | |
411 | return sb_add_net_text ($start, $end); | |
412 | else | |
413 | return sb_add_other_bibles ($start, $end, $version); | |
414 | } | |
415 | ||
416 | //Returns ESV text | |
417 | function sb_add_esv_text ($start, $end) { | |
418 | // If you are experiencing errors, you should sign up for an ESV API key, | |
419 | // and insert the name of your key in place of the letters IP in the URL | |
420 | // below (.e.g. ...passageQuery?key=YOURAPIKEY&passage=...) | |
421 | $esv_url = 'http://www.esvapi.org/v2/rest/passageQuery?key=IP&passage='.rawurlencode(sb_tidy_reference ($start, $end)).'&include-headings=false&include-footnotes=false'; | |
422 | return sb_download_page ($esv_url); | |
423 | } | |
424 | ||
425 | // Converts XML string to object | |
426 | function sb_get_xml ($content) { | |
427 | if (class_exists('SimpleXMLElement')) { | |
428 | $xml = new SimpleXMLElement($content); | |
429 | } else { | |
430 | $xml = new SimpleXMLElement4(); | |
431 | $xml = $xml->xml_load_file($content, 'object', 'utf-8'); | |
432 | } | |
433 | return $xml; | |
434 | } | |
435 | ||
436 | //Returns NET Bible text | |
437 | function sb_add_net_text ($start, $end) { | |
438 | $reference = str_replace(' ', '+', sb_tidy_reference ($start, $end)); | |
439 | $old_chapter = $start['chapter']; | |
440 | $net_url = "http://labs.bible.org/api/xml/verse.php?passage={$reference}"; | |
441 | if (class_exists('SimpleXMLElement')) // Ignore paragraph formatting on PHP4 because xml_parse_into_struct doesn't like HTML tags | |
442 | $xml = sb_get_xml(sb_download_page($net_url.'&formatting=para')); | |
443 | else | |
444 | $xml = sb_get_xml(sb_download_page($net_url)); | |
445 | $output=''; | |
446 | $items = array(); | |
447 | $items = $xml->item; | |
448 | foreach ($items as $item) { | |
449 | if ($item->text != '[[EMPTY]]') { | |
450 | if (substr($item->text, 0, 8) == '<p class') { | |
451 | $paraend = stripos($item->text, '>', 8)+1; | |
452 | $output .= "\n".substr($item->text, 0, $paraend); | |
453 | $item->text = substr ($item->text, $paraend); | |
454 | } | |
455 | if ($old_chapter == $item->chapter) { | |
456 | $output .= " <span class=\"verse-num\">{$item->verse}</span>"; | |
457 | } else { | |
458 | $output .= " <span class=\"chapter-num\">{$item->chapter}:{$item->verse}</span> "; | |
459 | $old_chapter = strval($item->chapter); | |
460 | } | |
461 | $output .= $item->text; | |
462 | } | |
463 | } | |
464 | 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>"; | |
465 | } | |
466 | ||
467 | //Returns Bible text using SermonBrowser's own API | |
468 | function sb_add_other_bibles ($start, $end, $version) { | |
469 | if ($version == 'hnv') | |
470 | return '<div class="'.$version.'"><p>Sorry, the Hebrew Names Version is no longer available.</p></div>'; | |
471 | $reference = str_replace(' ', '+', sb_tidy_reference ($start, $end)); | |
472 | $reference = str_replace('Psalm+', 'Psalms+', $reference); //Fix for API "Psalms" vs "Psalm" | |
473 | $old_chapter = $start['chapter']; | |
474 | $url = "http://api.preachingcentral.com/bible.php?passage={$reference}&version={$version}"; | |
475 | $xml = sb_get_xml(sb_download_page($url)); | |
476 | $output=''; | |
477 | $items = array(); | |
478 | $items = $xml->range->item; | |
479 | if ($xml->range->item) | |
480 | foreach ($xml->range->item as $item) { | |
481 | if ($item->text != '[[EMPTY]]') { | |
482 | if ($old_chapter == $item->chapter) { | |
483 | $output .= " <span class=\"verse-num\">{$item->verse}</span>"; | |
484 | } else { | |
485 | $output .= " <span class=\"chapter-num\">{$item->chapter}:{$item->verse}</span> "; | |
486 | $old_chapter = strval($item->chapter); | |
487 | } | |
488 | $output .= $item->text; | |
489 | } | |
490 | } | |
491 | 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>'; | |
492 | } | |
493 | ||
494 | //Adds edit sermon link if current user has edit rights | |
495 | function sb_edit_link ($id) { | |
496 | if (current_user_can('publish_posts')) { | |
497 | $id = (int)$id; | |
498 | echo '<div class="sb_edit_link"><a href="'.site_url().'/wp-admin/admin.php?page=sermon-browser/new_sermon.php&mid='.$id.'">Edit Lecture</a></div>'; | |
499 | } | |
500 | } | |
501 | ||
502 | // Returns URL for search links | |
503 | function sb_build_url($arr, $clear = false, $relative_link = false) { | |
504 | global $wpdb; | |
505 | // Word list for URL building purpose | |
506 | $wl = array('preacher', 'title', 'date', 'enddate', 'series', 'service', 'sortby', 'dir', 'book', 'stag', 'podcast'); | |
507 | $foo = array_merge((array) $_GET, (array) $_POST, $arr); | |
508 | foreach ($foo as $k => $v) { | |
509 | if (in_array($k, array_keys($arr)) | (in_array($k, $wl) && !$clear)) { | |
510 | $bar[] = rawurlencode($k).'='.rawurlencode($v); | |
511 | } | |
512 | } | |
513 | if (isset($bar)) { | |
514 | if ($relative_link and get_option('permalink_structure')) // relative links don't work if pretty permalinks are not being used | |
515 | return sb_query_char().implode('&', $bar); | |
516 | else | |
517 | return sb_display_url().sb_query_char().implode('&', $bar); | |
518 | } | |
519 | else { | |
520 | return sb_display_url(); | |
521 | } | |
522 | } | |
523 | ||
524 | // Adds javascript and CSS where required | |
525 | function sb_add_headers() { | |
526 | global $sermon_domain, $post, $wpdb, $wp_scripts; | |
527 | if (isset($post->ID) && $post->ID != '') { | |
528 | echo "<!-- Added by SermonBrowser (version ".SB_CURRENT_VERSION.") - http://www.sermonbrowser.com/ -->\r"; | |
529 | echo "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"".__('Lecture podcast', $sermon_domain)."\" href=\"".sb_get_option('podcast_url')."\" />\r"; | |
530 | wp_enqueue_style('sb_style'); | |
531 | $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();"); | |
532 | if ($pageid !== NULL) { | |
533 | if (sb_get_option('filter_type') == 'dropdown') { | |
534 | wp_enqueue_script('sb_datepicker'); | |
535 | wp_enqueue_style ('sb_datepicker'); | |
536 | } | |
537 | 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'])) | |
538 | echo "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"".__('Custom sermon podcast', $sermon_domain)."\" href=\"".sb_podcast_url()."\" />\r"; | |
539 | wp_enqueue_script('jquery'); | |
540 | } else { | |
541 | $sidebars_widgets = wp_get_sidebars_widgets(); | |
542 | if (isset($sidebars_widgets['wp_inactive_widgets'])) | |
543 | unset($sidebars_widgets['wp_inactive_widgets']); | |
544 | if (is_array($sidebars_widgets)) | |
545 | foreach ($sidebars_widgets as $sb_w) | |
546 | if (is_array($sb_w) && in_array('sermon-browser-popular', $sb_w)) | |
547 | wp_enqueue_script('jquery'); | |
548 | } | |
549 | } | |
550 | } | |
551 | ||
552 | // Formats date into words | |
553 | function sb_formatted_date ($sermon) { | |
554 | global $sermon_domain; | |
555 | if (isset($sermon->time) && $sermon->time != '') | |
556 | $sermon_time = $sermon->time; | |
557 | else | |
558 | $sermon_time = sb_default_time ($sermon->sid); | |
559 | if ($sermon->datetime == '1970-01-01 00:00:00') | |
560 | return __('Unknown Date', $sermon_domain); | |
561 | else | |
562 | return date_i18n(get_option('date_format'), strtotime($sermon->datetime)); | |
563 | } | |
564 | ||
565 | // Returns podcast URL | |
566 | function sb_podcast_url() { | |
567 | return str_replace(' ', '%20', sb_build_url(array('podcast' => 1, 'dir'=>'desc', 'sortby'=>'m.datetime'))); | |
568 | } | |
569 | ||
570 | // Prints sermon search URL | |
571 | function sb_print_sermon_link($sermon, $echo = true, $relative_link = true) { | |
572 | if ($echo) | |
573 | echo sb_build_url(array('sermon_id' => $sermon->id), true, $relative_link); | |
574 | else | |
575 | return sb_build_url(array('sermon_id' => $sermon->id), true, $relative_link); | |
576 | } | |
577 | ||
578 | // Prints preacher search URL | |
579 | function sb_print_preacher_link($sermon, $relative_link = true) { | |
580 | echo sb_build_url(array('preacher' => $sermon->pid), false, $relative_link); | |
581 | } | |
582 | ||
583 | // Prints series search URL | |
584 | function sb_print_series_link($sermon) { | |
585 | echo sb_build_url(array('series' => $sermon->ssid), false, true); | |
586 | } | |
587 | ||
588 | // Prints service search URL | |
589 | function sb_print_service_link($sermon) { | |
590 | echo sb_build_url(array('service' => $sermon->sid), false, true); | |
591 | } | |
592 | ||
593 | // Prints bible book search URL | |
594 | function sb_get_book_link($book_name, $relative_link = true) { | |
595 | return sb_build_url(array('book' => $book_name), false, $relative_link); | |
596 | } | |
597 | ||
598 | // Prints tag search URL | |
599 | function sb_get_tag_link($tag, $relative_link = true) { | |
600 | return sb_build_url(array('stag' => $tag), false, $relative_link); | |
601 | } | |
602 | ||
603 | // Prints tags | |
604 | function sb_print_tags($tags) { | |
605 | $out = array(); | |
606 | foreach ((array) $tags as $tag) { | |
607 | $tag = stripslashes($tag); | |
608 | $out[] = '<a href="'.sb_get_tag_link($tag).'">'.$tag.'</a>'; | |
609 | } | |
610 | $tags = implode(', ', (array) $out); | |
611 | echo $tags; | |
612 | } | |
613 | ||
614 | //Prints tag cloud | |
615 | function sb_print_tag_clouds($minfont=80, $maxfont=150) { | |
616 | global $wpdb; | |
617 | $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"); | |
618 | foreach ($rawtags as $tag) { | |
619 | if (isset($cnt[$tag->name])) | |
620 | $cnt[$tag->name]++; | |
621 | else | |
622 | $cnt[$tag->name] = 1; | |
623 | } | |
624 | $fontrange = $maxfont - $minfont; | |
625 | $maxcnt = 0; | |
626 | $mincnt = 1000000; | |
627 | foreach ($cnt as $cur) { | |
628 | if ($cur > $maxcnt) $maxcnt = $cur; | |
629 | if ($cur < $mincnt) $minct = $cur; | |
630 | } | |
631 | $cntrange = $maxcnt + 1 - $mincnt; | |
632 | $minlog = log($mincnt); | |
633 | $maxlog = log($maxcnt); | |
634 | $logrange = $maxlog == $minlog ? 1 : $maxlog - $minlog; | |
635 | arsort($cnt); | |
636 | foreach ($cnt as $tag => $count) { | |
637 | $size = $minfont + $fontrange * (log($count) - $minlog) / $logrange; | |
638 | $out[] = '<a style="font-size:'.(int) $size.'%" href="'.sb_get_tag_link($tag, FALSE).'">'.$tag.'</a>'; | |
639 | } | |
640 | echo implode(' ', $out); | |
641 | } | |
642 | ||
643 | //Prints link to next page | |
644 | function sb_print_next_page_link($limit = 0) { | |
645 | global $sermon_domain, $record_count; | |
646 | if ($limit == 0) | |
647 | $limit = sb_get_option('sermons_per_page'); | |
648 | $current = isset($_REQUEST['pagenum']) ? (int) $_REQUEST['pagenum'] : 1; | |
649 | if ($current < ceil($record_count / $limit)) { | |
650 | $url = sb_build_url(array('pagenum' => ++$current), false, true); | |
651 | echo '<a href="'.$url.'">'.__('Next page', $sermon_domain).' »</a>'; | |
652 | } | |
653 | } | |
654 | ||
655 | //Prints link to previous page | |
656 | function sb_print_prev_page_link($limit = 0) { | |
657 | global $sermon_domain; | |
658 | if ($limit == 0) $limit = sb_get_option('sermons_per_page'); | |
659 | $current = isset($_REQUEST['pagenum']) ? (int) $_REQUEST['pagenum'] : 1; | |
660 | if ($current > 1) { | |
661 | $url = sb_build_url(array('pagenum' => --$current), false, true); | |
662 | echo '<a href="'.$url.'">« '.__('Previous page', $sermon_domain).'</a>'; | |
663 | } | |
664 | } | |
665 | ||
666 | // Print link to attached files | |
667 | function sb_print_url($url) { | |
668 | global $sermon_domain; | |
669 | require (SB_INCLUDES_DIR.'/filetypes.php'); | |
670 | $pathinfo = pathinfo($url); | |
671 | $ext = $pathinfo['extension']; | |
672 | if ((substr($url,0,7) == "http://") or (substr($url,0,8) == 'https://')) | |
673 | $url=sb_display_url().sb_query_char(FALSE).'show&url='.rawurlencode($url); | |
674 | else | |
675 | if (strtolower($ext) == 'mp3') | |
676 | $url=sb_display_url().sb_query_char(FALSE).'show&file_name='.rawurlencode($url); | |
677 | else | |
678 | $url=sb_display_url().sb_query_char(FALSE).'download&file_name='.rawurlencode($url); | |
679 | $uicon = $default_site_icon; | |
680 | foreach ($siteicons as $site => $icon) { | |
681 | if (strpos($url, $site) !== false) { | |
682 | $uicon = $icon; | |
683 | break; | |
684 | } | |
685 | } | |
686 | $uicon = isset($filetypes[$ext]['icon']) ? $filetypes[$ext]['icon'] : $uicon; | |
687 | if (strtolower($ext) == 'mp3') { | |
688 | if ((substr(sb_get_option('mp3_shortcode'), 0, 18) == '[audio:%SERMONURL%') && function_exists('ap_insert_player_widgets')) { | |
689 | echo ap_insert_player_widgets(str_ireplace('%SERMONURL%', $url, sb_get_option('mp3_shortcode'))); | |
690 | return; | |
691 | } elseif (do_shortcode(sb_get_option('mp3_shortcode')) != sb_get_option('mp3_shortcode')) { | |
692 | echo do_shortcode(str_ireplace('%SERMONURL%', $url, sb_get_option('mp3_shortcode'))); | |
693 | return; | |
694 | } | |
695 | } | |
696 | $uicon = SB_PLUGIN_URL.'/sb-includes/icons/'.$uicon; | |
697 | if (!isset($filetypes[$ext]['name'])) | |
698 | $filetypes[$ext]['name'] = sprintf(__('%s file', $sermon_domain), addslashes($ext)); | |
699 | else | |
700 | $filetypes[$ext]['name'] = addslashes($filetypes[$ext]['name']); | |
701 | echo "<a href=\"{$url}\"><img class=\"site-icon\" alt=\"{$filetypes[$ext]['name']}\" title=\"{$filetypes[$ext]['name']}\" src=\"{$uicon}\"></a>"; | |
702 | } | |
703 | ||
704 | // Print link to attached external URLs | |
705 | function sb_print_url_link($url) { | |
706 | global $sermon_domain; | |
707 | echo '<div class="sermon_file">'; | |
708 | sb_print_url ($url); | |
709 | if (substr($url, -4) == ".mp3") { | |
710 | if ((substr($url,0,7) == "http://") or (substr($url,0,8) == 'https://')) { | |
711 | $param="url"; } | |
712 | else { | |
713 | $param="file_name"; } | |
714 | $url = rawurlencode($url); | |
715 | echo ' <a href="'.sb_display_url().sb_query_char().'download&'.$param.'='.$url.'">'.__('Download', $sermon_domain).'</a>'; | |
716 | } | |
717 | echo '</div>'; | |
718 | } | |
719 | ||
720 | //Decode base64 encoded data | |
721 | function sb_print_code($code) { | |
722 | echo do_shortcode(base64_decode($code)); | |
723 | } | |
724 | ||
725 | //Prints preacher description | |
726 | function sb_print_preacher_description($sermon) { | |
727 | global $sermon_domain; | |
728 | if (strlen($sermon->preacher_description)>0) { | |
729 | echo "<div class='preacher-description'><span class='about'>" . __('About', $sermon_domain).' '.stripslashes($sermon->preacher).': </span>'; | |
730 | echo "<span class='description'>".stripslashes($sermon->preacher_description)."</span></div>"; | |
731 | } | |
732 | } | |
733 | ||
734 | //Prints preacher image | |
735 | function sb_print_preacher_image($sermon) { | |
736 | if ($sermon->image) | |
737 | echo "<img alt='".stripslashes($sermon->preacher)."' class='preacher' src='".trailingslashit(site_url()).sb_get_option('upload_dir').'images/'.$sermon->image."'>"; | |
738 | } | |
739 | ||
740 | //Prints link to sermon preached next (but not today) | |
741 | function sb_print_next_sermon_link($sermon) { | |
742 | global $wpdb; | |
743 | $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"); | |
744 | if (!$next) return; | |
745 | echo '<a href="'; | |
746 | sb_print_sermon_link($next); | |
747 | echo '">'.stripslashes($next->title).' »</a>'; | |
748 | } | |
749 | ||
750 | //Prints link to sermon preached on previous days | |
751 | function sb_print_prev_sermon_link($sermon) { | |
752 | global $wpdb; | |
753 | $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"); | |
754 | if (!$prev) return; | |
755 | echo '<a href="'; | |
756 | sb_print_sermon_link($prev); | |
757 | echo '">« '.stripslashes($prev->title).'</a>'; | |
758 | } | |
759 | ||
760 | //Prints links to other sermons preached on the same day | |
761 | function sb_print_sameday_sermon_link($sermon) { | |
762 | global $wpdb, $sermon_domain; | |
763 | $same = $wpdb->get_results("SELECT id, title FROM {$wpdb->prefix}sb_sermons WHERE DATE(datetime) = DATE('{$sermon->datetime}') AND id <> {$sermon->id}"); | |
764 | if (!$same) { | |
765 | _e('None', $sermon_domain); | |
766 | return; | |
767 | } | |
768 | $output = array(); | |
769 | foreach ($same as $cur) | |
770 | $output[] = '<a href="'.sb_print_sermon_link($cur, false).'">'.stripslashes($cur->title).'</a>'; | |
771 | echo implode($output, ', '); | |
772 | } | |
773 | ||
774 | //Gets single sermon from the database | |
775 | function sb_get_single_sermon($id) { | |
776 | global $wpdb; | |
777 | $id = (int) $id; | |
778 | $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, ss.id as ssid, ss.name as series FROM {$wpdb->prefix}sb_sermons as m, {$wpdb->prefix}sb_preachers as p, {$wpdb->prefix}sb_services as s, {$wpdb->prefix}sb_series as ss where m.preacher_id = p.id and m.service_id = s.id and m.series_id = ss.id and m.id = {$id}"); | |
779 | if ($sermon) { | |
780 | $file = $code = $tags = array(); | |
781 | $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"); | |
782 | $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"); | |
783 | foreach ($rawtags as $tag) { | |
784 | $tags[] = $tag->name; | |
785 | } | |
786 | foreach ($stuff as $cur) | |
787 | ${$cur->type}[] = $cur->name; | |
788 | $sermon->start = unserialize($sermon->start); | |
789 | $sermon->end = unserialize($sermon->end); | |
790 | return array( | |
791 | 'Sermon' => $sermon, | |
792 | 'Files' => $file, | |
793 | 'Code' => $code, | |
794 | 'Tags' => $tags, | |
795 | ); | |
796 | } else | |
797 | return false; | |
798 | } | |
799 | ||
800 | //Prints the filter line for a given parameter | |
801 | function sb_print_filter_line ($id, $results, $filter, $display, $max_num = 7) { | |
802 | global $sermon_domain, $more_applied; | |
803 | $translate_book = FALSE; | |
804 | if ($id == 'book') { | |
805 | $translate_book = TRUE; | |
806 | $translated_books = array_combine(sb_get_default('eng_bible_books'), sb_get_default('bible_books')); | |
807 | } | |
808 | echo "<div id = \"{$id}\" class=\"filter\">\r<span class=\"filter-heading\">".__(ucwords($id), $sermon_domain).":</span> \r"; | |
809 | $i = 1; | |
810 | $more = FALSE; | |
811 | foreach ($results as $result) { | |
812 | if ($i == $max_num) { | |
813 | echo "<span id=\"{$id}-more\">"; | |
814 | $more = TRUE; | |
815 | $more_applied[] = $id; | |
816 | } | |
817 | if ($i != 1) | |
818 | echo ", \r"; | |
819 | if ($translate_book) { | |
820 | echo '<a href="'.sb_build_url(array($id => $result->$filter), false, true).'">'.$translated_books[stripslashes($result->$display)].'</a> ('.$result->count.')'; | |
821 | } | |
822 | else { | |
823 | echo '<a href="'.sb_build_url(array($id => $result->$filter), false, true).'">'.stripslashes($result->$display).'</a> ('.$result->count.')'; | |
824 | } | |
825 | $i++; | |
826 | } | |
827 | echo "."; | |
828 | if ($more) | |
829 | 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>'; | |
830 | echo '</div>'; | |
831 | } | |
832 | ||
833 | //Prints the filter line for the date parameter | |
834 | function sb_print_date_filter_line ($dates) { | |
835 | global $more_applied, $sermon_domain; | |
836 | $date_output = "<div id = \"dates\" class=\"filter\">\r<span class=\"filter-heading\">".__('Date', $sermon_domain).":</span> \r"; | |
837 | $first = $dates[0]; | |
838 | $last = end($dates); | |
839 | $count = 0; | |
840 | if ($first->year == $last->year) { | |
841 | if ($first->month == $last->month) { | |
842 | $date_output = ''; | |
843 | } else { | |
844 | $previous_month = -1; | |
845 | foreach ($dates as $date) { | |
846 | if ($date->month != $previous_month) { | |
847 | if ($count != 0) | |
848 | $date_output .= '('.$count.'), '; | |
849 | $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> '; | |
850 | $previous_month = $date->month; | |
851 | $count = 1; | |
852 | } else | |
853 | $count++; | |
854 | } | |
855 | $date_output .= '('.$count.'), '; | |
856 | } | |
857 | } else { | |
858 | $previous_year = 0; | |
859 | foreach ($dates as $date) { | |
860 | if ($date->year !== $previous_year) { | |
861 | if ($count !== 0) | |
862 | $date_output .= '('.$count.'), '; | |
863 | $date_output .= '<a href="'.sb_build_url(Array ('date' => $date->year.'-01-01', 'enddate' => $date->year.'-12-31'), false, true).'">'.$date->year.'</a> '; | |
864 | $previous_year = $date->year; | |
865 | $count = 1; | |
866 | } else | |
867 | $count++; | |
868 | } | |
869 | $date_output .= '('.$count.'), '; | |
870 | } | |
871 | if ($date_output != '') | |
872 | echo rtrim($date_output, ', ')."</div>\r"; | |
873 | } | |
874 | ||
875 | //Returns the filter URL minus a given parameter | |
876 | function sb_url_minus_parameter ($param1, $param2='') { | |
877 | global $filter_options; | |
878 | $existing_params = array_merge((array) $_GET, (array) $_POST); | |
879 | $returned_query = array(); | |
880 | foreach (array_keys($existing_params) as $query) { | |
881 | if (in_array($query, $filter_options) && $query != $param1 && $query != $param2) { | |
882 | $returned_query[] = "{$query}={$existing_params[$query]}"; | |
883 | } | |
884 | } | |
885 | if (count($returned_query) > 0) | |
886 | return sb_display_url().sb_query_char().implode('&', $returned_query); | |
887 | else | |
888 | return sb_display_url(); | |
889 | } | |
890 | ||
891 | //Displays the filter on sermon search page | |
892 | function sb_print_filters($filter) { | |
893 | global $wpdb, $sermon_domain, $more_applied, $filter_options; | |
894 | $hide_filter = FALSE; | |
895 | if ($filter['filterhide'] == 'hide') { | |
896 | $hide_filter = TRUE; | |
897 | $js_hide = " | |
898 | var filter_visible = false; | |
899 | jQuery('#mainfilter').hide(); | |
900 | jQuery('#show_hide_filter').text('[ SHOW ]'); | |
901 | jQuery('#show_hide_filter').click(function() { | |
902 | jQuery('#mainfilter:visible').slideUp('slow'); | |
903 | jQuery('#mainfilter:hidden').slideDown('slow'); | |
904 | if (filter_visible) { | |
905 | jQuery('#show_hide_filter').text('[ SHOW ]'); | |
906 | filter_visible = false; | |
907 | } else { | |
908 | jQuery('#show_hide_filter').text('[ HIDE ]'); | |
909 | filter_visible = true; | |
910 | } | |
911 | return false; | |
912 | });"; | |
913 | $js_hide = str_replace ('SHOW', __('Show filter', $sermon_domain), $js_hide); | |
914 | $js_hide = str_replace ('HIDE', __('Hide filter', $sermon_domain), $js_hide); | |
915 | } | |
916 | if ($filter['filter'] == 'oneclick') { | |
917 | // One click filter | |
918 | $hide_custom_podcast = true; | |
919 | $filter_options = array ('preacher', 'book', 'service', 'series', 'date', 'enddate', 'title'); | |
920 | $output = ''; | |
921 | foreach ($filter_options AS $filter_option) | |
922 | if (isset($_REQUEST[$filter_option])) { | |
923 | if ($filter_option != 'enddate') { | |
924 | if ($output != '') | |
925 | $output .= "\r, "; | |
926 | if ($filter_option == 'date') { | |
927 | $output .= '<strong>'.__('Date', $sermon_domain).'</strong>: '; | |
928 | if (substr($_REQUEST['date'],0,4) == substr($_REQUEST['enddate'],0,4)) | |
929 | $output .= substr($_REQUEST['date'],0,4).' (<a href="'.sb_url_minus_parameter('date', 'enddate').'">x</a>)'; | |
930 | if (substr($_REQUEST['date'],5,2) == substr($_REQUEST['enddate'],5,2)) | |
931 | $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>)'; | |
932 | } else { | |
933 | $output .= '<strong>'.__(ucwords($filter_option), $sermon_domain).'</strong>: *'.$filter_option.'*'; | |
934 | $output .= ' (<a href="'.sb_url_minus_parameter($filter_option).'">x</a>)'; | |
935 | } | |
936 | } | |
937 | $hide_custom_podcast = FALSE; | |
938 | } | |
939 | $hide_empty = sb_get_option('hide_no_attachments'); | |
940 | $sermons=sb_get_sermons($filter, array(), 1, 99999, $hide_empty); | |
941 | $ids = array(); | |
942 | foreach ($sermons as $sermon) | |
943 | $ids[] = $sermon->id; | |
944 | $ids = "('".implode ("', '", $ids)."')"; | |
945 | ||
946 | $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"); | |
947 | $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"); | |
948 | $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"); | |
949 | $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"); | |
950 | $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"); | |
951 | ||
952 | $more_applied = array(); | |
953 | $output = str_replace ('*preacher*', isset($preachers[0]->name) ? $preachers[0]->name : '', $output); | |
954 | $output = str_replace ('*book*', isset($_REQUEST['book']) ? __(htmlentities($_REQUEST['book']), $sermon_domain) : '', $output); | |
955 | $output = str_replace ('*service*', isset($services[0]->name) ? $services[0]->name : '', $output); | |
956 | $output = str_replace ('*series*', isset($series[0]->name) ? $series[0]->name : '', $output); | |
957 | ||
958 | echo "<span class=\"inline_controls\"><a href=\"#\" id=\"show_hide_filter\"></a></span>"; | |
959 | if ($output != '') | |
960 | echo '<div class="filtered">'.__('Active filter', $sermon_domain).': '.$output."</div>\r"; | |
961 | echo '<div id="mainfilter">'; | |
962 | if (count($preachers) > 1) | |
963 | sb_print_filter_line ('preacher', $preachers, 'id', 'name', 7); | |
964 | if (count($book_count) > 1) | |
965 | sb_print_filter_line ('book', $book_count, 'name', 'name', 10); | |
966 | if (count($series) > 1) | |
967 | sb_print_filter_line ('series', $series, 'id', 'name', 10); | |
968 | if (count($services) > 1) | |
969 | sb_print_filter_line ('service', $services, 'id', 'name', 10); | |
970 | sb_print_date_filter_line ($dates); | |
971 | echo "</div>\r"; | |
972 | if (count($more_applied) > 0 | $output != '' | $hide_custom_podcast === TRUE | $hide_filter === TRUE) { | |
973 | echo "<script type=\"text/javascript\">\r"; | |
974 | echo "\tjQuery(document).ready(function() {\r"; | |
975 | if ($hide_filter === TRUE) | |
976 | echo $js_hide."\r"; | |
977 | if ($hide_custom_podcast === TRUE) | |
978 | echo "\t\tjQuery('.podcastcustom').hide();\r"; | |
979 | if (count($more_applied) > 0) { | |
980 | foreach ($more_applied as $element_id) { | |
981 | echo "\t\tjQuery('#{$element_id}-more').hide();\r"; | |
982 | echo "\t\tjQuery('#{$element_id}-more-link').show();\r"; | |
983 | echo "\t\tjQuery('a#{$element_id}-toggle').click(function() {\r"; | |
984 | echo "\t\t\tjQuery('#{$element_id}-more').show();\r"; | |
985 | echo "\t\t\tjQuery('#{$element_id}-more-link').hide();\r"; | |
986 | echo "\t\t\treturn false;\r"; | |
987 | echo "\t\t});\r"; | |
988 | } | |
989 | } | |
990 | echo "\t});\r"; | |
991 | echo "</script>\r"; | |
992 | } | |
993 | } elseif ($filter['filter'] == 'dropdown') { | |
994 | // Drop-down filter | |
995 | $translated_books = array_combine(sb_get_default('eng_bible_books'), sb_get_default('bible_books')); | |
996 | $preachers = $wpdb->get_results("SELECT p.*, count(p.id) AS count FROM {$wpdb->prefix}sb_preachers AS p JOIN {$wpdb->prefix}sb_sermons AS s ON p.id = s.preacher_id GROUP BY p.id ORDER BY count DESC, s.datetime DESC"); | |
997 | $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 GROUP BY ss.id ORDER BY sermons.datetime DESC"); | |
998 | $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 GROUP BY s.id ORDER BY count DESC"); | |
999 | $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 GROUP BY b.id"); | |
1000 | $sb = array( | |
1001 | 'Title' => 'm.title', | |
1002 | 'Preacher' => 'preacher', | |
1003 | 'Date' => 'm.datetime', | |
1004 | 'Passage' => 'b.id', | |
1005 | ); | |
1006 | $di = array( | |
1007 | __('Ascending', $sermon_domain) => 'asc', | |
1008 | __('Descending', $sermon_domain) => 'desc', | |
1009 | ); | |
1010 | $csb = isset($_REQUEST['sortby']) ? $_REQUEST['sortby'] : 'm.datetime'; | |
1011 | $cd = isset($_REQUEST['dir']) ? $_REQUEST['dir'] : 'desc'; | |
1012 | ?> | |
1013 | <span class="inline_controls"><a href="#" id="show_hide_filter"></a></span> | |
1014 | <div id="mainfilter"> | |
1015 | <form method="post" id="sermon-filter" action="<?php echo sb_display_url(); ?>"> | |
1016 | <div style="clear:both"> | |
1017 | <table class="sermonbrowser"> | |
1018 | <tr> | |
1019 | <td class="fieldname"><?php _e('Speaker', $sermon_domain) ?></td> | |
1020 | <td class="field"><select name="preacher" id="preacher"> | |
1021 | <option value="0" <?php echo (isset($_REQUEST['preacher']) && $_REQUEST['preacher'] != 0) ? '' : 'selected="selected"' ?>><?php _e('[All]', $sermon_domain) ?></option> | |
1022 | <?php foreach ($preachers as $preacher): ?> | |
1023 | <option value="<?php echo $preacher->id ?>" <?php echo isset($_REQUEST['preacher']) && $_REQUEST['preacher'] == $preacher->id ? 'selected="selected"' : '' ?>><?php echo stripslashes($preacher->name).' ('.$preacher->count.')' ?></option> | |
1024 | <?php endforeach ?> | |
1025 | </select> | |
1026 | </td> | |
1027 | <td class="fieldname rightcolumn"><?php _e('Services', $sermon_domain) ?></td> | |
1028 | <td class="field"><select name="series" id="series"> | |
1029 | <option value="0" <?php echo (isset($_REQUEST['series']) && $_REQUEST['series'] != 0) ? '' : 'selected="selected"' ?>> | |
1030 | <?php _e('[All]', $sermon_domain) ?> | |
1031 | </option> | |
1032 | <?php foreach ($series as $item): ?> | |
1033 | <option value="<?php echo $item->id ?>" <?php echo isset($_REQUEST['series']) && $_REQUEST['series'] == $item->id ? 'selected="selected"' : '' ?>><?php echo stripslashes($item->name).' ('.$item->count.')' ?></option> | |
1034 | <?php endforeach ?> | |
1035 | </select></td> | |
1036 | <td width="30" class="field"> </td> | |
1037 | <td width="30" class="field"> </td> | |
1038 | <td class="field"><input type="submit" class="filter" value="<?php _e('Filter »', $sermon_domain) ?>"></td> | |
1039 | </tr> | |
1040 | </table> | |
1041 | <input type="hidden" name="page" value="1"> | |
1042 | </div> | |
1043 | </form> | |
1044 | - | <?php |
1044 | + | |
1045 | <script type="text/javascript"> | |
1046 | jQuery.datePicker.setDateFormat('ymd','-'); | |
1047 | jQuery('#date').datePicker({startDate:'01/01/1970'}); | |
1048 | jQuery('#enddate').datePicker({startDate:'01/01/1970'}); | |
1049 | <?php if ($hide_filter === TRUE) { ?> | |
1050 | jQuery(document).ready(function() { | |
1051 | <?php echo $js_hide; ?> | |
1052 | }); | |
1053 | <?php } ?> | |
1054 | </script> | |
1055 | <?php | |
1056 | } | |
1057 | } | |
1058 | // Returns the first MP3 file attached to a sermon | |
1059 | // Stats have to be turned off for iTunes compatibility | |
1060 | function sb_first_mp3($sermon, $stats= TRUE) { | |
1061 | $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; | |
1062 | if (stripos($user_agent, 'itunes') !== FALSE | stripos($user_agent, 'FeedBurner') !== FALSE) | |
1063 | $stats = FALSE; | |
1064 | $stuff = sb_get_stuff($sermon, true); | |
1065 | $stuff = array_merge((array)$stuff['Files'], (array)$stuff['URLs']); | |
1066 | foreach ((array) $stuff as $file) { | |
1067 | if (strtolower(substr($file, strrpos($file, '.') + 1)) == 'mp3') { | |
1068 | if ((substr($url,0,7) == "http://") or (substr($url,0,8) == 'https://')) { | |
1069 | if ($stats) | |
1070 | $file=sb_display_url().sb_query_char().'show&url='.rawurlencode($file); | |
1071 | } else { | |
1072 | if (!$stats) | |
1073 | $file=trailingslashit(site_url()).sb_get_option('upload_dir').rawurlencode($file); | |
1074 | else | |
1075 | $file=sb_display_url().sb_query_char().'show&file_name='.rawurlencode($file); | |
1076 | } | |
1077 | return $file; | |
1078 | break; | |
1079 | } | |
1080 | } | |
1081 | } | |
1082 | ||
1083 | //Gets colour for mini-flash player from the options of another flash player plugin. | |
1084 | function sb_get_flash_player_colour ($type) { | |
1085 | if ($type == 'foreground') { | |
1086 | //AudioPlayer v2 | |
1087 | $options = get_option('AudioPlayer_options'); | |
1088 | if ($options) | |
1089 | return $options['colorScheme']['rightbg']; | |
1090 | //AudioPlayer v1 | |
1091 | $options = get_option('audio_player_rightbgcolor'); | |
1092 | if ($options) | |
1093 | return str_replace('0x', '', $options); | |
1094 | //Default | |
1095 | return '000000'; | |
1096 | } elseif ($type == 'background') { | |
1097 | //AudioPlayer v2 | |
1098 | $options = get_option('AudioPlayer_options'); | |
1099 | if ($options) | |
1100 | if ($options['colorScheme']['transparentpagebg'] == 'true') | |
1101 | return 'transparent'; | |
1102 | else | |
1103 | return $options['colorScheme']['rightbg']; | |
1104 | //AudioPlayer v1 | |
1105 | $options = get_option('audio_player_transparentpagebgcolor'); | |
1106 | if ($options) | |
1107 | return 'transparent'; | |
1108 | else | |
1109 | return str_replace('0x', '', get_option('audio_player_pagebgcolor')); | |
1110 | ||
1111 | } | |
1112 | } | |
1113 | ||
1114 | // Displays the mini flash mp3 player | |
1115 | function sb_display_mini_player ($sermon, $id=1, $flashvars="") { | |
1116 | $filename = sb_first_mp3($sermon, FALSE); | |
1117 | if ($filename !="") { | |
1118 | $flashvars .= "&foreColor=#".sb_get_flash_player_colour ('foreground'); | |
1119 | $flashvars .= "&filename=".$filename; | |
1120 | if (substr($flashvars, 0, 1) == "&") | |
1121 | $flashvars = substr($flashvars, 1); | |
1122 | - | ?> |
1122 | + | |
1123 | if (sb_get_flash_player_colour ('background') == 'transparent') | |
1124 | echo " wmode=\"transparent\""; | |
1125 | else | |
1126 | echo " bgcolor=\"0x".sb_get_flash_player_colour ('background')."\""; | |
1127 | echo " quality=\"high\""; | |
1128 | echo " flashvars=\"".$flashvars."\""; | |
1129 | echo " src=\"".SB_PLUGIN_URL."/sb-includes/1bit.swf\""; | |
1130 | echo " type=\"application/x-shockwave-flash\"/></span>"; | |
1131 | } | |
1132 | } | |
1133 | - | </script> |
1133 | + | ?> |