bhengh

SB translation fix: sb_print_filters V2

Feb 11th, 2013
48
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Displays the filter on sermon search page
  2. function sb_print_filters($filter, $translate_book = FALSE) {
  3. global $wpdb, $sermon_domain, $more_applied, $filter_options;
  4. $hide_filter = FALSE;
  5. if ($filter['filterhide'] == 'hide') {
  6. $hide_filter = TRUE;
  7. $js_hide = "
  8. var filter_visible = false;
  9. jQuery('#mainfilter').hide();
  10. jQuery('#show_hide_filter').text('[ SHOW ]');
  11. jQuery('#show_hide_filter').click(function() {
  12. jQuery('#mainfilter:visible').slideUp('slow');
  13. jQuery('#mainfilter:hidden').slideDown('slow');
  14. if (filter_visible) {
  15. jQuery('#show_hide_filter').text('[ SHOW ]');
  16. filter_visible = false;
  17. } else {
  18. jQuery('#show_hide_filter').text('[ HIDE ]');
  19. filter_visible = true;
  20. }
  21. return false;
  22. });";
  23. $js_hide = str_replace ('SHOW', __('Show filter', $sermon_domain), $js_hide);
  24. $js_hide = str_replace ('HIDE', __('Hide filter', $sermon_domain), $js_hide);
  25. }
  26. if ($filter['filter'] == 'oneclick') {
  27. // One click filter
  28. $hide_custom_podcast = true;
  29. $filter_options = array ('preacher', 'book', 'service', 'series', 'date', 'enddate', 'title');
  30. $output = '';
  31. foreach ($filter_options AS $filter_option)
  32. if (isset($_REQUEST[$filter_option])) {
  33. if ($filter_option != 'enddate') {
  34. if ($output != '')
  35. $output .= "\r, ";
  36. if ($filter_option == 'date') {
  37. $output .= '<strong>Date</strong>:&nbsp;';
  38. if (substr($_REQUEST['date'],0,4) == substr($_REQUEST['enddate'],0,4))
  39. $output .= substr($_REQUEST['date'],0,4).'&nbsp;(<a href="'.sb_url_minus_parameter('date', 'enddate').'">x</a>)';
  40. if (substr($_REQUEST['date'],5,2) == substr($_REQUEST['enddate'],5,2))
  41. $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>)';
  42. } else {
  43. $output .= '<strong>'.ucwords($filter_option).'</strong>:&nbsp;*'.$filter_option.'*';
  44. $output .= '&nbsp;(<a href="'.sb_url_minus_parameter($filter_option).'">x</a>)';
  45. }
  46. }
  47. $hide_custom_podcast = FALSE;
  48. }
  49. $hide_empty = sb_get_option('hide_no_attachments');
  50. $sermons=sb_get_sermons($filter, array(), 1, 99999, $hide_empty);
  51. $ids = array();
  52. foreach ($sermons as $sermon)
  53. $ids[] = $sermon->id;
  54. $ids = "('".implode ("', '", $ids)."')";
  55.  
  56. $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");
  57. $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");
  58. $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");
  59. $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");
  60. $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");
  61.  
  62. $more_applied = array();
  63. $output = str_replace ('*preacher*', isset($preachers[0]->name) ? $preachers[0]->name : '', $output);
  64. $output = str_replace ('*book*', isset($_REQUEST['book']) ? htmlentities($_REQUEST['book']) : '', $output);
  65. $output = str_replace ('*service*', isset($services[0]->name) ? $services[0]->name : '', $output);
  66. $output = str_replace ('*series*', isset($series[0]->name) ? $series[0]->name : '', $output);
  67.  
  68. echo "<span class=\"inline_controls\"><a href=\"#\" id=\"show_hide_filter\"></a></span>";
  69. if ($output != '')
  70. echo '<div class="filtered">'.__('Active filter', $sermon_domain).': '.$output."</div>\r";
  71. echo '<div id="mainfilter">';
  72. if (count($preachers) > 1)
  73. sb_print_filter_line ('preacher', $preachers, 'id', 'name', 7);
  74. if (count($book_count) > 1)
  75. sb_print_filter_line ('book', $book_count, 'name', 'name', 10, $translate_book);
  76. if (count($series) > 1)
  77. sb_print_filter_line ('series', $series, 'id', 'name', 10);
  78. if (count($services) > 1)
  79. sb_print_filter_line ('service', $services, 'id', 'name', 10);
  80. sb_print_date_filter_line ($dates);
  81. echo "</div>\r";
  82. if (count($more_applied) > 0 | $output != '' | $hide_custom_podcast === TRUE | $hide_filter === TRUE) {
  83. echo "<script type=\"text/javascript\">\r";
  84. echo "\tjQuery(document).ready(function() {\r";
  85. if ($hide_filter === TRUE)
  86. echo $js_hide."\r";
  87. if ($hide_custom_podcast === TRUE)
  88. echo "\t\tjQuery('.podcastcustom').hide();\r";
  89. if (count($more_applied) > 0) {
  90. foreach ($more_applied as $element_id) {
  91. echo "\t\tjQuery('#{$element_id}-more').hide();\r";
  92. echo "\t\tjQuery('#{$element_id}-more-link').show();\r";
  93. echo "\t\tjQuery('a#{$element_id}-toggle').click(function() {\r";
  94. echo "\t\t\tjQuery('#{$element_id}-more').show();\r";
  95. echo "\t\t\tjQuery('#{$element_id}-more-link').hide();\r";
  96. echo "\t\t\treturn false;\r";
  97. echo "\t\t});\r";
  98. }
  99. }
  100. echo "\t});\r";
  101. echo "</script>\r";
  102. }
  103. } elseif ($filter['filter'] == 'dropdown') {
  104. // Drop-down filter
  105.  
  106. if ($translate_book) {
  107. $translated_books = array_combine(sb_get_default('eng_bible_books'), sb_get_default('bible_books'));
  108. }
  109.  
  110. $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");
  111. $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");
  112. $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");
  113. $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");
  114. $sb = array(
  115. 'Title' => 'm.title',
  116. 'Preacher' => 'preacher',
  117. 'Date' => 'm.datetime',
  118. 'Passage' => 'b.id',
  119. );
  120. $di = array(
  121. __('Ascending', $sermon_domain) => 'asc',
  122. __('Descending', $sermon_domain) => 'desc',
  123. );
  124. $csb = isset($_REQUEST['sortby']) ? $_REQUEST['sortby'] : 'm.datetime';
  125. $cd = isset($_REQUEST['dir']) ? $_REQUEST['dir'] : 'desc';
  126. ?>
  127. <span class="inline_controls"><a href="#" id="show_hide_filter"></a></span>
  128. <div id="mainfilter">
  129. <form method="post" id="sermon-filter" action="<?php echo sb_display_url(); ?>">
  130. <div style="clear:both">
  131. <table class="sermonbrowser">
  132. <tr>
  133. <td class="fieldname"><?php _e('Preacher', $sermon_domain) ?></td>
  134. <td class="field"><select name="preacher" id="preacher">
  135. <option value="0" <?php echo (isset($_REQUEST['preacher']) && $_REQUEST['preacher'] != 0) ? '' : 'selected="selected"' ?>><?php _e('[All]', $sermon_domain) ?></option>
  136. <?php foreach ($preachers as $preacher): ?>
  137. <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>
  138. <?php endforeach ?>
  139. </select>
  140. </td>
  141. <td class="fieldname rightcolumn"><?php _e('Services', $sermon_domain) ?></td>
  142. <td class="field"><select name="service" id="service">
  143. <option value="0" <?php echo isset($_REQUEST['service']) && $_REQUEST['service'] != 0 ? '' : 'selected="selected"' ?>><?php _e('[All]', $sermon_domain) ?></option>
  144. <?php foreach ($services as $service): ?>
  145. <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>
  146. <?php endforeach ?>
  147. </select>
  148. </td>
  149. </tr>
  150. <tr>
  151. <td class="fieldname"><?php _e('Book', $sermon_domain) ?></td>
  152. <td class="field"><select name="book">
  153. <option value=""><?php _e('[All]', $sermon_domain) ?></option>
  154.  
  155. <?php if ($translate_book) { ?>
  156. <?php foreach ($book_count as $book): ?>
  157. <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>
  158. <?php endforeach ?>
  159. <?php }
  160. else { ?>
  161. <?php foreach ($book_count as $book): ?>
  162. <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>
  163. <?php endforeach ?>
  164. <?php } ?>
  165.  
  166. </select>
  167. </td>
  168. <td class="fieldname rightcolumn"><?php _e('Series', $sermon_domain) ?></td>
  169. <td class="field"><select name="series" id="series">
  170. <option value="0" <?php echo (isset($_REQUEST['series']) && $_REQUEST['series'] != 0) ? '' : 'selected="selected"' ?>><?php _e('[All]', $sermon_domain) ?></option>
  171. <?php foreach ($series as $item): ?>
  172. <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>
  173. <?php endforeach ?>
  174. </select>
  175. </td>
  176. </tr>
  177. <tr>
  178. <td class="fieldname"><?php _e('Start date', $sermon_domain) ?></td>
  179. <td class="field"><input type="text" name="date" id="date" value="<?php echo isset($_REQUEST['date']) ? mysql_real_escape_string($_REQUEST['date']) : '' ?>" /></td>
  180. <td class="fieldname rightcolumn"><?php _e('End date', $sermon_domain) ?></td>
  181. <td class="field"><input type="text" name="enddate" id="enddate" value="<?php echo isset($_REQUEST['enddate']) ? mysql_real_escape_string($_REQUEST['enddate']) : '' ?>" /></td>
  182. </tr>
  183. <tr>
  184. <td class="fieldname"><?php _e('Keywords', $sermon_domain) ?></td>
  185. <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>
  186. </tr>
  187. <tr>
  188. <td class="fieldname"><?php _e('Sort by', $sermon_domain) ?></td>
  189. <td class="field"><select name="sortby" id="sortby">
  190. <?php foreach ($sb as $k => $v): ?>
  191. <option value="<?php echo $v ?>" <?php echo $csb == $v ? 'selected="selected"' : '' ?>><?php _e($k, $sermon_domain) ?></option>
  192. <?php endforeach ?>
  193. </select>
  194. </td>
  195. <td class="fieldname rightcolumn"><?php _e('Direction', $sermon_domain) ?></td>
  196. <td class="field"><select name="dir" id="dir">
  197. <?php foreach ($di as $k => $v): ?>
  198. <option value="<?php echo $v ?>" <?php echo $cd == $v ? 'selected="selected"' : '' ?>><?php _e($k, $sermon_domain) ?></option>
  199. <?php endforeach ?>
  200. </select>
  201. </td>
  202. </tr>
  203. <tr>
  204. <td colspan="3">&nbsp;</td>
  205. <td class="field"><input type="submit" class="filter" value="<?php _e('Filter &raquo;', $sermon_domain) ?>"> </td>
  206. </tr>
  207. </table>
  208. <input type="hidden" name="page" value="1">
  209. </div>
  210. </form>
  211. </div>
  212. <script type="text/javascript">
  213. jQuery.datePicker.setDateFormat('ymd','-');
  214. jQuery('#date').datePicker({startDate:'01/01/1970'});
  215. jQuery('#enddate').datePicker({startDate:'01/01/1970'});
  216. <?php if ($hide_filter === TRUE) { ?>
  217. jQuery(document).ready(function() {
  218. <?php echo $js_hide; ?>
  219. });
  220. <?php } ?>
  221. </script>
  222. <?php
  223. }
  224. }
RAW Paste Data