Advertisement
bhengh

SB translation fix: sb_print_filters

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