Guest User

frontend for Ben

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