PageRenderTime 65ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/sermon-browser/sb-includes/frontend.php

https://github.com/Jarrod-Williams/Sermons-Browser-Plugin
PHP | 1155 lines | 1042 code | 54 blank | 59 comment | 236 complexity | 1ad5a77ab79ffbdc807cdb7756ae54df MD5 | raw file

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file