PageRenderTime 39ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/Jarrod-Williams/Sermons-Browser-Plugin
PHP | 2578 lines | 2393 code | 70 blank | 115 comment | 440 complexity | db0b2e1073f74af9765ad3178c55c2e0 MD5 | raw file
  1. <?php
  2. /**
  3. * Admin functions
  4. *
  5. * Functions required exclusively in the back end.
  6. * @package admin_functions
  7. */
  8. /**
  9. * Adds javascript and CSS where required in admin
  10. */
  11. function sb_add_admin_headers() {
  12. if (isset($_REQUEST['page']) && substr($_REQUEST['page'],14) == 'sermon-browser')
  13. wp_enqueue_script('jquery');
  14. if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'sermon-browser/new_sermon.php') {
  15. wp_enqueue_script('sb_datepicker');
  16. wp_enqueue_script('sb_64');
  17. wp_enqueue_style ('sb_datepicker');
  18. wp_enqueue_style ('sb_style');
  19. }
  20. }
  21. /**
  22. * Display the options page and handle changes
  23. */
  24. function sb_options() {
  25. global $wpdb, $sermon_domain;
  26. //Security check
  27. if (!current_user_can('manage_options'))
  28. wp_die(__("You do not have the correct permissions to edit the SermonBrowser options", $sermon_domain));
  29. //Reset options to default
  30. if (isset($_POST['resetdefault'])) {
  31. $dir = sb_get_default('sermon_path');
  32. if (sb_display_url()=="#") {
  33. sb_update_option('podcast_url', site_url().sb_query_char(false).'podcast');
  34. } else {
  35. sb_update_option('podcast_url', sb_display_url().sb_query_char(false).'podcast');
  36. }
  37. sb_update_option('upload_dir', $dir);
  38. sb_update_option('upload_url', sb_get_default('attachment_url'));
  39. sb_update_option('display_method', 'dynamic');
  40. sb_update_option('sermons_per_page', '10');
  41. sb_update_option('filter_type', 'oneclick');
  42. sb_update_option('filter_hide', 'hide');
  43. sb_update_option('hide_no_attachments', false);
  44. sb_update_option('mp3_shortcode', '[audio:%SERMONURL%]');
  45. if (!is_dir(SB_ABSPATH.$dir))
  46. if (sb_mkdir(SB_ABSPATH.$dir))
  47. @chmod(SB_ABSPATH.$dir, 0777);
  48. if(!is_dir(SB_ABSPATH.$dir.'images') && sb_mkdir(SB_ABSPATH.$dir.'images'))
  49. @chmod(SB_ABSPATH.$dir.'images', 0777);
  50. $books = sb_get_default('bible_books');
  51. $eng_books = sb_get_default('eng_bible_books');
  52. // Reset bible books database
  53. $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}sb_books");
  54. for ($i=0; $i < count($books); $i++) {
  55. $wpdb->query("INSERT INTO {$wpdb->prefix}sb_books VALUES (null, '$books[$i]')");
  56. $wpdb->query("UPDATE {$wpdb->prefix}sb_books_sermons SET book_name='{$books[$i]}' WHERE book_name='{$eng_books[$i]}'");
  57. }
  58. // Rewrite booknames for non-English locales
  59. if ($books != $eng_books) {
  60. $sermon_books = $wpdb->get_results("SELECT id, start, end FROM {$wpdb->prefix}sb_sermons");
  61. foreach ($sermon_books as $sermon_book) {
  62. $start_verse = unserialize($sermon_book->start);
  63. $end_verse = unserialize($sermon_book->end);
  64. $start_index = array_search($start_verse[0]['book'], $eng_books, TRUE);
  65. $end_index = array_search($end_verse[0]['book'], $eng_books, TRUE);
  66. if ($start_index !== FALSE)
  67. $start_verse[0]['book'] = $books[$start_index];
  68. if ($end_index !== FALSE)
  69. $end_verse[0]['book'] = $books[$end_index];
  70. $sermon_book->start = serialize ($start_verse);
  71. $sermon_book->end = serialize ($end_verse);
  72. $wpdb->query("UPDATE {$wpdb->prefix}sb_sermons SET start='{$sermon_book->start}', end='{$sermon_book->end}' WHERE id={$sermon_book->id}");
  73. }
  74. }
  75. $checkSermonUpload = sb_checkSermonUploadable();
  76. switch ($checkSermonUpload) {
  77. case "unwriteable":
  78. echo '<div id="message" class="updated fade"><p><b>';
  79. if (IS_MU AND !is_site_admin()) {
  80. _e('Upload is disabled. Please contact your administrator.', $sermon_domain);
  81. } else {
  82. _e('Error: The upload folder is not writeable. You need to CHMOD the folder to 666 or 777.', $sermon_domain);
  83. }
  84. echo '</b></div>';
  85. break;
  86. case "notexist":
  87. echo '<div id="message" class="updated fade"><p><b>';
  88. if (IS_MU AND !is_site_admin()) {
  89. _e('Upload is disabled. Please contact your administrator.', $sermon_domain);
  90. } else {
  91. _e('Error: The upload folder you have specified does not exist.', $sermon_domain);
  92. }
  93. echo '</b></div>';
  94. break;
  95. default:
  96. echo '<div id="message" class="updated fade"><p><b>';
  97. _e('Default loaded successfully.', $sermon_domain);
  98. echo '</b></div>';
  99. break;
  100. }
  101. }
  102. // Save options
  103. elseif (isset($_POST['save'])) {
  104. $dir = rtrim(str_replace("\\", "/", $_POST['dir']), "/")."/";
  105. sb_update_option('podcast_url', stripslashes($_POST['podcast']));
  106. if (intval($_POST['perpage']) > 0)
  107. sb_update_option('sermons_per_page', intval($_POST['perpage']));
  108. if (intval($_POST['perpage']) == -100)
  109. update_option('show_donate_reminder', 'off');
  110. sb_update_option('upload_dir', $dir);
  111. sb_update_option('filter_type', $_POST['filtertype']);
  112. sb_update_option('filter_hide', isset($_POST['filterhide']));
  113. sb_update_option('upload_url', trailingslashit(site_url()).$dir);
  114. sb_update_option ('import_prompt', isset($_POST['import_prompt']));
  115. sb_update_option ('import_title', isset($_POST['import_title']));
  116. sb_update_option ('import_artist', isset($_POST['import_artist']));
  117. sb_update_option ('import_album', isset($_POST['import_album']));
  118. sb_update_option ('import_comments', isset($_POST['import_comments']));
  119. sb_update_option ('import_filename', stripslashes($_POST['import_filename']));
  120. sb_update_option ('hide_no_attachments', isset($_POST['hide_no_attachments']));
  121. sb_update_option('mp3_shortcode', stripslashes($_POST['mp3_shortcode']));
  122. if (!is_dir(SB_ABSPATH.$dir))
  123. if (sb_mkdir(SB_ABSPATH.$dir))
  124. @chmod(SB_ABSPATH.$dir, 0777);
  125. if(!is_dir(SB_ABSPATH.$dir.'images') && sb_mkdir(SB_ABSPATH.$sermonUploadDir.'images'))
  126. @chmod(SB_ABSPATH.$dir.'images', 0777);
  127. $checkSermonUpload = sb_checkSermonUploadable();
  128. switch ($checkSermonUpload) {
  129. case "unwriteable":
  130. echo '<div id="message" class="updated fade"><p><b>';
  131. _e('Error: The upload folder is not writeable. You need to CHMOD the folder to 666 or 777.', $sermon_domain);
  132. echo '</b></div>';
  133. break;
  134. case "notexist":
  135. echo '<div id="message" class="updated fade"><p><b>';
  136. _e('Error: The upload folder you have specified does not exist.', $sermon_domain);
  137. echo '</b></div>';
  138. break;
  139. default:
  140. echo '<div id="message" class="updated fade"><p><b>';
  141. _e('Options saved successfully.', $sermon_domain);
  142. echo '</b></div>';
  143. break;
  144. }
  145. }
  146. //Display error messsages when problems in php.ini
  147. function sb_display_error ($message) {
  148. global $sermon_domain;
  149. return '<tr><td align="right" style="color:#AA0000; font-weight:bold">'.__('Error', $sermon_domain).':</td>'.
  150. '<td style="color: #AA0000">'.$message.'</td></tr>';
  151. }
  152. //Display warning messsages when problems in php.ini
  153. function sb_display_warning ($message) {
  154. global $sermon_domain;
  155. return '<tr><td align="right" style="color:#FFDC00; font-weight:bold">'.__('Warning', $sermon_domain).':</td>'.
  156. '<td style="color: #FF8C00">'.$message.'</td></tr>';
  157. }
  158. sb_do_alerts();
  159. // HTML for options page
  160. ?>
  161. <div class="wrap">
  162. <a href="http://www.sermonbrowser.com/"><img src="<?php echo SB_PLUGIN_URL; ?>/sb-includes/logo-small.png" width="191" height ="35" style="margin: 1em 2em; float: right; background: #f9f9f9;" /></a>
  163. <form method="post">
  164. <h2><?php _e('Basic Options', $sermon_domain) ?></h2>
  165. <br style="clear:both"/>
  166. <table border="0" class="widefat">
  167. <?php
  168. if (!IS_MU OR is_site_admin()) {
  169. ?>
  170. <tr>
  171. <td align="right" style="vertical-align:middle"><?php _e('Upload folder', $sermon_domain) ?>: </td>
  172. <td><input type="text" name="dir" value="<?php echo htmlspecialchars(sb_get_option('upload_dir')) ?>" style="width:100%" /></td>
  173. </tr>
  174. <?php
  175. } else {
  176. ?>
  177. <input type="hidden" name="dir" value="<?php echo htmlspecialchars(sb_get_option('upload_dir')) ?>">
  178. <?php
  179. }
  180. ?>
  181. <tr>
  182. <td align="right" style="vertical-align:middle"><?php _e('Public podcast feed', $sermon_domain) ?>: </td>
  183. <td><input type="text" name="podcast" value="<?php echo htmlspecialchars(sb_get_option('podcast_url')) ?>" style="width:100%" /></td>
  184. </tr>
  185. <tr>
  186. <td align="right"><?php _e('Private podcast feed', $sermon_domain) ?>: </td>
  187. <td><?php if (sb_display_url()=='') { echo htmlspecialchars(site_url()); } else { echo htmlspecialchars(sb_display_url()); } echo sb_query_char(); ?>podcast</td>
  188. </tr>
  189. <tr>
  190. <td align="right" style="vertical-align:middle"><?php _e('MP3 shortcode', $sermon_domain) ?>: </td>
  191. <td><input type="text" name="mp3_shortcode" value="<?php echo htmlspecialchars(sb_get_option('mp3_shortcode')) ?>" style="width:100%" /></td>
  192. </tr>
  193. <tr>
  194. <td align="right" style="vertical-align:middle"><?php _e('Sermons per page', $sermon_domain) ?>: </td>
  195. <td><input type="text" name="perpage" value="<?php echo sb_get_option('sermons_per_page') ?>" /></td>
  196. </tr>
  197. <tr>
  198. <td align="right" style="vertical-align:top" rowspan="2"><?php _e('Filter type', $sermon_domain) ?>: </td>
  199. <td>
  200. <?php
  201. $ft = sb_get_option('filter_type');
  202. $filter_options = array ('dropdown' => __('Drop-down', $sermon_domain), 'oneclick' => __('One-click', $sermon_domain), 'none' => __('None', $sermon_domain));
  203. foreach ($filter_options as $value => $filter_option) {
  204. echo "<input type=\"radio\" name=\"filtertype\" value=\"{$value}\" ";
  205. if ($ft == $value)
  206. echo 'checked="checked" ';
  207. echo "/> {$filter_option}<br/>\n";
  208. }
  209. ?>
  210. </td>
  211. </tr>
  212. <tr>
  213. <td>
  214. <input type="checkbox" name="filterhide" <?php if (sb_get_option('filter_hide') == 'hide') echo 'checked="checked" '; ?> value="hide" \> <?php _e('Minimise filter', $sermon_domain); ?>
  215. </td>
  216. </tr>
  217. <tr>
  218. <td align="right"><?php _e('Hide sermons without attachments?', $sermon_domain) ?></td>
  219. <td><input type="checkbox" name="hide_no_attachments" <?php if (sb_get_option('hide_no_attachments')) echo 'checked="checked" '?> value="1" \></td>
  220. </tr>
  221. <?php
  222. $allow_uploads = ini_get('file_uploads');
  223. $max_filesize = sb_return_kbytes(ini_get('upload_max_filesize'));
  224. $max_post = sb_return_kbytes(ini_get('post_max_size'));
  225. $max_execution = ini_get('max_execution_time');
  226. $max_input = ini_get('max_input_time');
  227. $max_memory = sb_return_kbytes(ini_get('memory_limit'));
  228. $checkSermonUpload = sb_checkSermonUploadable();
  229. if (IS_MU) {
  230. if ($checkSermonUpload=="unwriteable")
  231. echo sb_display_error (__('The upload folder is not writeable. You need to specify a folder that you have permissions to write to.', $sermon_domain));
  232. elseif ($checkSermonUpload=="notexist")
  233. sb_display_error (__('The upload folder you have specified does not exist.', $sermon_domain));
  234. if ($allow_uploads == '0') echo sb_display_error(__('Your administrator does not allow file uploads. You will need to upload via FTP.', $sermon_domain));
  235. $max_filesize = ($max_filesize < $max_post) ? $max_filesize : $max_post;
  236. if ($max_filesize < 15360) echo sb_display_warning(__('The maximum file size you can upload is only ', $sermon_domain).$max_filesize.__('k. You may need to upload via FTP.', $sermon_domain));
  237. $max_execution = (($max_execution < $max_input) || $max_input == -1) ? $max_execution : $max_input;
  238. if ($max_execution < 600) echo sb_display_warning(__('The maximum time allowed for any script to run is only ', $sermon_domain).$max_execution.__(' seconds. If your files take longer than this to upload, you will need to upload via FTP.', $sermon_domain));
  239. } else {
  240. if ($checkSermonUpload=="unwriteable")
  241. echo sb_display_error (__('The upload folder is not writeable. You need to specify a folder that you have permissions to write to, or CHMOD this folder to 666 or 777.', $sermon_domain));
  242. elseif ($checkSermonUpload=="notexist")
  243. sb_display_error (__('The upload folder you have specified does not exist.', $sermon_domain));
  244. if ($allow_uploads == '0') echo sb_display_error(__('Your php.ini file does not allow uploads. Please change file_uploads in php.ini.', $sermon_domain));
  245. if ($max_filesize < 15360) echo sb_display_warning(__('The maximum file size you can upload is only ', $sermon_domain).$max_filesize.__('k. Please change upload_max_filesize to at least 15M in php.ini.', $sermon_domain));
  246. if ($max_post < 15360) echo sb_display_warning(__('The maximum file size you send through the browser is only ', $sermon_domain).$max_post.__('k. Please change post_max_size to at least 15M in php.ini.', $sermon_domain));
  247. if ($max_execution < 600) echo sb_display_warning(__('The maximum time allowed for any script to run is only ', $sermon_domain).$max_execution.__(' seconds. Please change max_execution_time to at least 600 in php.ini.', $sermon_domain));
  248. if ($max_input < 600 && $max_input != -1) echo sb_display_warning(__('The maximum time allowed for an upload script to run is only ', $sermon_domain).$max_input.__(' seconds. Please change max_input_time to at least 600 in php.ini.', $sermon_domain));
  249. if ($max_memory < 16384) echo sb_display_warning(__('The maximum amount of memory allowed is only ', $sermon_domain).$max_memory.__('k. Please change memory_limit to at least 16M in php.ini.', $sermon_domain));
  250. }
  251. ?>
  252. </table>
  253. <h2><?php _e('Import Options', $sermon_domain) ?></h2>
  254. <p><?php printf(__('SermonBrowser can speed up the process of importing existing MP3s by reading the information stored in each MP3 file and pre-filling the SermonBrowser fields. Use this section to specify what information you want imported into SermonBrowser. Once you have selected the options, go to %s to import your files.', $sermon_domain), '<a href="'.admin_url('admin.php?page=sermon-browser/files.php').'">'.__('Files', $sermon_domain).'</a>') ?>
  255. <table border="0" class="widefat">
  256. <tr>
  257. <td align="right"><?php _e('Add files prompt to top of Add Sermon page?', $sermon_domain) ?></td>
  258. <td><input type="checkbox" name="import_prompt" <?php if (sb_get_option('import_prompt')) echo 'checked="checked" '?> value="1" \></td>
  259. </tr>
  260. <tr>
  261. <td align="right"><?php _e('Use title tag for sermon title?', $sermon_domain) ?></td>
  262. <td><input type="checkbox" name="import_title" <?php if (sb_get_option('import_title')) echo 'checked="checked" '?> value="1" \></td>
  263. </tr>
  264. <tr>
  265. <td align="right"><?php _e('Use artist tag for preacher?', $sermon_domain) ?></td>
  266. <td><input type="checkbox" name="import_artist" <?php if (sb_get_option('import_artist')) echo 'checked="checked" '?> value="1" \></td>
  267. </tr>
  268. <tr>
  269. <td align="right"><?php _e('Use album tag for series?', $sermon_domain) ?></td>
  270. <td><input type="checkbox" name="import_album" <?php if (sb_get_option('import_album')) echo 'checked="checked" '?> value="1" \></td>
  271. </tr>
  272. <tr>
  273. <td align="right"><?php _e('Use comments tag for sermon description?', $sermon_domain) ?></td>
  274. <td><input type="checkbox" name="import_comments" <?php if (sb_get_option('import_comments')) echo 'checked="checked" '?> value="1" \></td>
  275. </tr>
  276. <tr>
  277. <td align="right" style="vertical-align: middle"><?php _e('Attempt to extract date from filename', $sermon_domain) ?></td>
  278. <td style="vertical-align: middle"><select name="import_filename">
  279. <?php
  280. $filename_options = array ('none' => __('Disabled', $sermon_domain),
  281. 'uk' => __('UK-formatted date (dd-mm-yyyy)', $sermon_domain),
  282. 'us' => __('US-formatted date (mm-dd-yyyy)', $sermon_domain),
  283. 'int' => __('International formatted date (yyyy-mm-dd)', $sermon_domain)
  284. );
  285. $saved_option = sb_get_option ('import_filename');
  286. foreach ($filename_options as $option => $text) {
  287. $sel = $saved_option == $option ? ' selected = "selected"' : '';
  288. echo "<option value=\"{$option}\"{$sel}>{$text}</option>\n";
  289. }
  290. echo "</select>\n<br/>";
  291. _e ('(Use if you name your files something like 2008-11-06-eveningsermon.mp3)', $sermon_domain);
  292. ?>
  293. </td>
  294. </tr>
  295. </table>
  296. <p class="submit"><input type="submit" name="resetdefault" value="<?php _e('Reset to defaults', $sermon_domain) ?>" />&nbsp;<input type="submit" name="save" value="<?php _e('Save', $sermon_domain) ?> &raquo;" /></p>
  297. </div>
  298. </form>
  299. <?php
  300. }
  301. /**
  302. * Display uninstall screen and perform uninstall if requested
  303. */
  304. function sb_uninstall () {
  305. global $sermon_domain;
  306. //Security check
  307. if (!(current_user_can('edit_plugins') | (IS_MU && current_user_can('manage_options'))))
  308. wp_die(__("You do not have the correct permissions to Uninstall SermonBrowser", $sermon_domain));
  309. if (isset($_POST['uninstall']))
  310. require(SB_INCLUDES_DIR.'/uninstall.php');
  311. ?>
  312. <form method="post">
  313. <div class="wrap">
  314. <?php if (IS_MU) { ?>
  315. <h2> <?php _e('Reset SermonBrowser', $sermon_domain); ?></h2>
  316. <p><?php printf(__('Clicking the %s button below will remove ALL data (sermons, preachers, series, etc.) from SermonBrowser', $sermon_domain), __('Delete all', $sermon_domain));
  317. echo '. ';
  318. _e('You will NOT be able to undo this action.', $sermon_domain) ?>
  319. </p>
  320. <?php } else { ?>
  321. <h2> <?php _e('Uninstall', $sermon_domain); ?></h2>
  322. <p><?php printf(__('Clicking the %s button below will remove ALL data (sermons, preachers, series, etc.) from SermonBrowser', $sermon_domain), __('Uninstall', $sermon_domain));
  323. echo ', ';
  324. _e('and will deactivate the SermonBrowser plugin', $sermon_domain);
  325. echo '. ';
  326. _e('You will NOT be able to undo this action.', $sermon_domain);
  327. echo ' ';
  328. _e('If you only want to temporarily disable SermonBrowser, just deactivate it from the plugins page.', $sermon_domain); ?>
  329. </p>
  330. <?php } ?>
  331. <table border="0" class="widefat">
  332. <tr>
  333. <td><input type="checkbox" name="wipe" value="1"> <?php _e('Also remove all uploaded files', $sermon_domain) ?></td>
  334. </tr>
  335. </table>
  336. <p class="submit"><input type="submit" name="uninstall" value="<?php if (IS_MU) { _e('Delete all', $sermon_domain); } else { _e('Uninstall', $sermon_domain); } ?>" onclick="return confirm('<?php _e('Do you REALLY want to delete all data?', $sermon_domain)?>')" /></p>
  337. </div>
  338. </form>
  339. <script>
  340. jQuery("form").submit(function() {
  341. var yes = confirm("<?php _e('Are you REALLY REALLY sure you want to remove SermonBrowser?', $sermon_domain)?>");
  342. if(!yes) return false;
  343. });
  344. </script>
  345. <?php
  346. }
  347. /**
  348. * Display the templates page and handle changes
  349. */
  350. function sb_templates () {
  351. global $sermon_domain;
  352. //Security check
  353. if (function_exists('current_user_can')&&!current_user_can('manage_options'))
  354. wp_die(__("You do not have the correct permissions to edit the SermonBrowser templates", $sermon_domain));
  355. //Save templates or reset to default
  356. if (isset($_POST['save']) || isset($_POST['resetdefault'])) {
  357. require(SB_INCLUDES_DIR.'/dictionary.php');
  358. $multi = $_POST['multi'];
  359. $single = $_POST['single'];
  360. $style = $_POST['style'];
  361. if(isset($_POST['resetdefault'])){
  362. require(SB_INCLUDES_DIR.'/sb-install.php');
  363. $multi = sb_default_multi_template();
  364. $single = sb_default_single_template();
  365. $style = sb_default_css();
  366. }
  367. sb_update_option('search_template', $multi);
  368. sb_update_option('single_template', $single);
  369. sb_update_option('css_style', $style);
  370. sb_update_option('search_output', strtr($multi, sb_search_results_dictionary()));
  371. sb_update_option('single_output', strtr($single, sb_sermon_page_dictionary()));
  372. sb_update_option('style_date_modified', strtotime('now'));
  373. echo '<div id="message" class="updated fade"><p><b>';
  374. _e('Templates saved successfully.', $sermon_domain);
  375. echo '</b></p></div>';
  376. }
  377. sb_do_alerts();
  378. // HTML for templates page
  379. ?>
  380. <form method="post">
  381. <div class="wrap">
  382. <a href="http://www.sermonbrowser.com/"><img src="<?php echo SB_PLUGIN_URL; ?>/sb-includes/logo-small.png" width="191" height ="35" style="margin: 1em 2em; float: right; background: #f9f9f9;" /></a>
  383. <h2><?php _e('Templates', $sermon_domain) ?></h2>
  384. <br/>
  385. <table border="0" class="widefat">
  386. <tr>
  387. <td align="right"><?php _e('Search results page', $sermon_domain) ?>: </td>
  388. <td>
  389. <?php sb_build_textarea('multi', sb_get_option('search_template')) ?>
  390. </td>
  391. </tr>
  392. <tr>
  393. <td align="right"><?php _e('Sermon page', $sermon_domain) ?>: </td>
  394. <td>
  395. <?php sb_build_textarea('single', sb_get_option('single_template')) ?>
  396. </td>
  397. </tr>
  398. <tr>
  399. <td align="right"><?php _e('Style', $sermon_domain) ?>: </td>
  400. <td>
  401. <?php sb_build_textarea('style', sb_get_option('css_style')) ?>
  402. </td>
  403. </tr>
  404. </table>
  405. <p class="submit"><input type="submit" name="resetdefault" value="<?php _e('Reset to defaults', $sermon_domain) ?>" />&nbsp;<input type="submit" name="save" value="<?php _e('Save', $sermon_domain) ?> &raquo;" /></p>
  406. </div>
  407. </form>
  408. <script>
  409. jQuery("form").submit(function() {
  410. var yes = confirm("Are you sure ?");
  411. if(!yes) return false;
  412. });
  413. </script>
  414. <?php
  415. }
  416. /**
  417. * Display the preachers page and handle changes
  418. */
  419. function sb_manage_preachers() {
  420. global $wpdb, $sermon_domain;
  421. //Security check
  422. if (function_exists('current_user_can')&&!current_user_can('manage_categories'))
  423. wp_die(__("You do not have the correct permissions to manage the preachers' database", $sermon_domain));
  424. if (isset($_GET['saved']))
  425. echo '<div id="message" class="updated fade"><p><b>'.__('Preacher saved to database.', $sermon_domain).'</b></div>';
  426. $sermonUploadDir = sb_get_option('upload_dir');
  427. //Save changes
  428. if (isset($_POST['save'])) {
  429. $name = $wpdb->escape($_POST['name']);
  430. $description = $wpdb->escape($_POST['description']);
  431. $error = false;
  432. $pid = (int) $_REQUEST['pid'];
  433. if (empty($_FILES['upload']['name'])) {
  434. $p = $wpdb->get_row("SELECT image FROM {$wpdb->prefix}sb_preachers WHERE id = $pid");
  435. $filename = $p ? $p->image : '';
  436. } elseif ($_FILES['upload']['error'] == UPLOAD_ERR_OK) {
  437. $filename = basename($_FILES['upload']['name']);
  438. $prefix = '';
  439. if(!is_dir(SB_ABSPATH.$sermonUploadDir.'images') && sb_mkdir(SB_ABSPATH.$sermonUploadDir.'images'))
  440. @chmod(SB_ABSPATH.$sermonUploadDir.'images', 0777);
  441. $dest = SB_ABSPATH.$sermonUploadDir.'images/'.$filename;
  442. if (@move_uploaded_file($_FILES['upload']['tmp_name'], $dest))
  443. $filename = $prefix.mysql_real_escape_string($filename);
  444. else {
  445. $error = true;
  446. echo '<div id="message" class="updated fade"><p><b>'.__('Could not save uploaded file. Please try again.', $sermon_domain).'</b></div>';
  447. @chmod(SB_ABSPATH.$sermonUploadDir.'images', 0777);
  448. }
  449. } else {
  450. $error = true;
  451. echo '<div id="message" class="updated fade"><p><b>'.__('Could not upload file. Please check the Options page for any errors or warnings.', $sermon_domain).'</b></div>';
  452. }
  453. if ($pid == 0) {
  454. $wpdb->query("INSERT INTO {$wpdb->prefix}sb_preachers VALUES (null, '$name', '$description', '$filename')");
  455. } else {
  456. $wpdb->query("UPDATE {$wpdb->prefix}sb_preachers SET name = '$name', description = '$description', image = '$filename' WHERE id = $pid");
  457. if ($_POST['old'] != $filename)
  458. @unlink(SB_ABSPATH.sb_get_option('upload_dir').'images/'.mysql_real_escape_string($_POST['old']));
  459. }
  460. if(isset($_POST['remove'])){
  461. $wpdb->query("UPDATE {$wpdb->prefix}sb_preachers SET name = '$name', description = '$description', image = '' WHERE id = $pid");
  462. @unlink(SB_ABSPATH.sb_get_option('upload_dir').'images/'.mysql_real_escape_string($_POST['old']));
  463. }
  464. if(!$error)
  465. echo "<script>document.location = '".site_url()."/wp-admin/admin.php?page=sermon-browser/preachers.php&saved=true';</script>";
  466. }
  467. if (isset($_GET['act']) && $_GET['act'] == 'kill') {
  468. $die = (int) $_GET['pid'];
  469. if($wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}sb_sermons WHERE preacher_id = $die") > 0)
  470. echo '<div id="message" class="updated fade"><p><b>'.__("You cannot delete this preacher until you first delete any sermons they have preached.", $sermon_domain).'</b></div>';
  471. else {
  472. $p = $wpdb->get_row("SELECT image FROM {$wpdb->prefix}sb_preachers WHERE id = $die");
  473. @unlink(SB_ABSPATH.sb_get_option('upload_dir').'images/'.$p->image);
  474. $wpdb->query("DELETE FROM {$wpdb->prefix}sb_preachers WHERE id = $die");
  475. }
  476. }
  477. if (isset($_GET['act']) && ($_GET['act'] == 'new' || $_GET['act'] == 'edit')) {
  478. if ($_GET['act'] == 'edit') $preacher = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}sb_preachers WHERE id = ".(int) $_GET['pid']);
  479. //Display HTML
  480. ?>
  481. <div class="wrap">
  482. <a href="http://www.sermonbrowser.com/"><img src="<?php echo SB_PLUGIN_URL; ?>/sb-includes/logo-small.png" width="191" height ="35" style="margin: 1em 2em; float: right; background: #f9f9f9;" /></a>
  483. <h2><?php echo $_GET['act'] == 'new' ? __('Add', $sermon_domain) : __('Edit', $sermon_domain) ?> <?php _e('preacher', $sermon_domain) ?></h2>
  484. <br style="clear:both">
  485. <?php
  486. $checkSermonUpload = sb_checkSermonUploadable('images/');
  487. if ($checkSermonUpload == 'notexist') {
  488. echo SB_ABSPATH.$sermonUploadDir.'images';
  489. if (!is_dir(SB_ABSPATH.$sermonUploadDir.'images') && mkdir(SB_ABSPATH.$sermonUploadDir.'images'))
  490. chmod(SB_ABSPATH.$sermonUploadDir.'images', 0777);
  491. $checkSermonUpload = sb_checkSermonUploadable('images/');
  492. }
  493. if ($checkSermonUpload != 'writeable')
  494. echo '<div id="message" class="updated fade"><p><b>'.__("The images folder is not writeable. You won't be able to upload images.", $sermon_domain).'</b></div>';
  495. ?>
  496. <form method="post" enctype="multipart/form-data">
  497. <input type="hidden" name="pid" value="<?php echo (int) $_GET['pid'] ?>">
  498. <fieldset>
  499. <table class="widefat">
  500. <tr>
  501. <td>
  502. <strong><?php _e('Name', $sermon_domain) ?></strong>
  503. <div>
  504. <input type="text" value="<?php echo isset($preacher->name) ? stripslashes($preacher->name) : '' ?>" name="name" size="60" style="width:400px;" />
  505. </div>
  506. </td>
  507. </tr>
  508. <tr>
  509. <td>
  510. <strong><?php _e('Description', $sermon_domain) ?></strong>
  511. <div>
  512. <textarea name="description" cols="100" rows="5"><?php echo isset($preacher->description) ? stripslashes($preacher->description) : ''?></textarea>
  513. </div>
  514. </td>
  515. </tr>
  516. <tr>
  517. <td>
  518. <?php if ($_GET['act'] == 'edit'): ?>
  519. <div><img src="<?php echo trailingslashit(site_url()).sb_get_option('upload_dir').'images/'.$preacher->image ?>"></div>
  520. <input type="hidden" name="old" value="<?php echo $preacher->image ?>">
  521. <?php endif ?>
  522. <strong><?php _e('Image', $sermon_domain) ?></strong>
  523. <div>
  524. <input type="file" name="upload">
  525. <label>Remove image&nbsp;<input type="checkbox" name="remove" value="true"></label>
  526. </div>
  527. </td>
  528. </tr>
  529. </table>
  530. </fieldset>
  531. <p class="submit"><input type="submit" name="save" value="<?php _e('Save', $sermon_domain) ?> &raquo;" /></p>
  532. </form>
  533. </div>
  534. <?php
  535. return;
  536. }
  537. $preachers = $wpdb->get_results("SELECT {$wpdb->prefix}sb_preachers.*, COUNT({$wpdb->prefix}sb_sermons.id) AS sermon_count FROM {$wpdb->prefix}sb_preachers LEFT JOIN {$wpdb->prefix}sb_sermons ON {$wpdb->prefix}sb_preachers.id=preacher_id GROUP BY preacher_id ORDER BY name ASC");
  538. sb_do_alerts();
  539. ?>
  540. <div class="wrap">
  541. <a href="http://www.sermonbrowser.com/"><img src="<?php echo SB_PLUGIN_URL; ?>/sb-includes/logo-small.png" width="191" height ="35" style="margin: 1em 2em; float: right; background: #f9f9f9;" /></a>
  542. <h2><?php _e('Preachers', $sermon_domain) ?> (<a href="<?php echo site_url() ?>/wp-admin/admin.php?page=sermon-browser/preachers.php&act=new"><?php _e('add new', $sermon_domain) ?></a>)</h2>
  543. <br/>
  544. <table class="widefat" style="width:auto">
  545. <thead>
  546. <tr>
  547. <th scope="col" style="text-align:center"><?php _e('ID', $sermon_domain) ?></th>
  548. <th scope="col"><?php _e('Name', $sermon_domain) ?></th>
  549. <th scope="col" style="text-align:center"><?php _e('Image', $sermon_domain) ?></th>
  550. <th scope="col" style="text-align:center"><?php _e('Sermons', $sermon_domain) ?></th>
  551. <th scope="col" style="text-align:center"><?php _e('Actions', $sermon_domain) ?></th>
  552. </tr>
  553. </thead>
  554. <tbody>
  555. <?php foreach ((array) $preachers as $preacher): ?>
  556. <tr class="<?php $i=0; echo (++$i % 2 == 0) ? 'alternate' : '' ?>">
  557. <td style="text-align:center"><?php echo $preacher->id ?></td>
  558. <td><?php echo stripslashes($preacher->name) ?></td>
  559. <td style="text-align:center"><?php echo ($preacher->image == '') ? '' : '<img src="'.trailingslashit(site_url()).sb_get_option('upload_dir').'images/'.$preacher->image.'">' ?></td>
  560. <td style="text-align:center"><?php echo $preacher->sermon_count ?></td>
  561. <td style="text-align:center">
  562. <a href="<?php echo site_url() ?>/wp-admin/admin.php?page=sermon-browser/preachers.php&act=edit&pid=<?php echo $preacher->id ?>"><?php _e('Edit', $sermon_domain) ?></a>
  563. <?php if (count($preachers) < 2) { ?>
  564. | <a href="javascript:alert('<?php _e('You must have at least one preacher in the database.', $sermon_domain)?>')"><?php _e('Delete', $sermon_domain) ?></a>
  565. <?php } elseif ($preacher->sermon_count != 0) { ?>
  566. | <a href="javascript:alert('<?php _e('You cannot delete this preacher until you first delete any sermons they have preached.', $sermon_domain)?>')"><?php _e('Delete', $sermon_domain) ?></a>
  567. <?php } else { ?>
  568. | <a onclick="return confirm('<?php printf(__('Are you sure you want to delete %s?', $sermon_domain), stripslashes($preacher->name)) ?>')" href="<?php echo site_url() ?>/wp-admin/admin.php?page=sermon-browser/preachers.php&act=kill&pid=<?php echo $preacher->id ?>"><?php _e('Delete', $sermon_domain) ?></a>
  569. <?php } ?>
  570. </td>
  571. </tr>
  572. <?php endforeach ?>
  573. </tbody>
  574. </table>
  575. </div>
  576. <?php
  577. }
  578. /**
  579. * Display services & series page and handle changes
  580. */
  581. function sb_manage_everything() {
  582. global $wpdb, $sermon_domain;
  583. //Security check
  584. if (function_exists('current_user_can')&&!current_user_can('manage_categories'))
  585. wp_die(__("You do not have the correct permissions to manage the series and services database", $sermon_domain));
  586. $series = $wpdb->get_results("SELECT {$wpdb->prefix}sb_series.*, COUNT({$wpdb->prefix}sb_sermons.id) AS sermon_count FROM {$wpdb->prefix}sb_series LEFT JOIN {$wpdb->prefix}sb_sermons ON series_id = {$wpdb->prefix}sb_series.id GROUP BY series_id ORDER BY name ASC");
  587. $services = $wpdb->get_results("SELECT {$wpdb->prefix}sb_services.*, COUNT({$wpdb->prefix}sb_sermons.id) AS sermon_count FROM {$wpdb->prefix}sb_services LEFT JOIN {$wpdb->prefix}sb_sermons ON service_id = {$wpdb->prefix}sb_services.id GROUP BY service_id ORDER BY name ASC");
  588. $toManage = array(
  589. 'Series' => array('data' => $series),
  590. 'Services' => array('data' => $services),
  591. );
  592. sb_do_alerts();
  593. ?>
  594. <script type="text/javascript">
  595. //<![CDATA[
  596. function updateClass(type) {
  597. jQuery('.' + type + ':visible').each(function(i) {
  598. jQuery(this).removeClass('alternate');
  599. if (++i % 2 == 0) {
  600. jQuery(this).addClass('alternate');
  601. }
  602. });
  603. }
  604. function createNewServices(s) {
  605. var s = 'lol';
  606. while ((s.indexOf('@') == -1) || (s.match(/(.*?)@(.*)/)[2].match(/[0-9]{1,2}:[0-9]{1,2}/) == null)) {
  607. s = prompt("<?php _e("New service's name @ default time?", $sermon_domain)?>", "<?php _e("Service's name @ 18:00", $sermon_domain)?>");
  608. if (s == null) { break; }
  609. }
  610. if (s != null) {
  611. jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/sermon.php'); ?>', {sname: s, sermon: 1}, function(r) {
  612. if (r) {
  613. sz = s.match(/(.*?)@(.*)/)[1];
  614. t = s.match(/(.*?)@(.*)/)[2];
  615. jQuery('#Services-list').append('\
  616. <tr style="display:none" class="Services" id="rowServices' + r + '">\
  617. <th style="text-align:center" scope="row">' + r + '</th>\
  618. <td id="Services' + r + '">' + sz + '</td>\
  619. <td style="text-align:center">' + t + '</td>\
  620. <td style="text-align:center">\
  621. <a id="linkServices' + r + '" href="javascript:renameServices(' + r + ', \'' + sz + '\')">Edit</a> | <a onclick="return confirm(\'Are you sure?\');" href="javascript:deleteServices(' + r + ')">Delete</a>\
  622. </td>\
  623. </tr>\
  624. ');
  625. jQuery('#rowServices' + r).fadeIn(function() {
  626. updateClass('Services');
  627. });
  628. };
  629. });
  630. }
  631. }
  632. function createNewSeries(s) {
  633. var ss = prompt("<?php _e("New series' name?", $sermon_domain)?>", "<?php _e("Series' name", $sermon_domain)?>");
  634. if (ss != null) {
  635. jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/sermon.php'); ?>', {ssname: ss, sermon: 1}, function(r) {
  636. if (r) {
  637. jQuery('#Series-list').append('\
  638. <tr style="display:none" class="Series" id="rowSeries' + r + '">\
  639. <th style="text-align:center" scope="row">' + r + '</th>\
  640. <td id="Series' + r + '">' + ss + '</td>\
  641. <td style="text-align:center">\
  642. <a id="linkSeries' + r + '" href="javascript:renameSeries(' + r + ', \'' + ss + '\')">Rename</a> | <a onclick="return confirm(\'Are you sure?\');" href="javascript:deleteSeries(' + r + ')">Delete</a>\
  643. </td>\
  644. </tr>\
  645. ');
  646. jQuery('#rowSeries' + r).fadeIn(function() {
  647. updateClass('Series');
  648. });
  649. };
  650. });
  651. }
  652. }
  653. function deleteSeries(id) {
  654. jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/sermon.php'); ?>', {ssname: 'dummy', ssid: id, del: 1, sermon: 1}, function(r) {
  655. if (r) {
  656. jQuery('#rowSeries' + id).fadeOut(function() {
  657. updateClass('Series');
  658. });
  659. };
  660. });
  661. }
  662. function deleteServices(id) {
  663. jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/sermon.php'); ?>', {sname: 'dummy', sid: id, del: 1, sermon: 1}, function(r) {
  664. if (r) {
  665. jQuery('#rowServices' + id).fadeOut(function() {
  666. updateClass('Services');
  667. });
  668. };
  669. });
  670. }
  671. function renameSeries(id, old) {
  672. var ss = prompt("<?php _e("New series' name?", $sermon_domain)?>", old);
  673. if (ss != null) {
  674. jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/sermon.php'); ?>', {ssid: id, ssname: ss, sermon: 1}, function(r) {
  675. if (r) {
  676. jQuery('#Series' + id).text(ss);
  677. jQuery('#linkSeries' + id).attr('href', 'javascript:renameSeries(' + id + ', "' + ss + '")');
  678. Fat.fade_element('Series' + id);
  679. };
  680. });
  681. }
  682. }
  683. function renameServices(id, old) {
  684. var s = 'lol';
  685. while ((s.indexOf('@') == -1) || (s.match(/(.*?)@(.*)/)[2].match(/[0-9]{1,2}:[0-9]{1,2}/) == null)) {
  686. s = prompt("<?php _e("New service's name @ default time?", $sermon_domain)?>", old);
  687. if (s == null) { break; }
  688. }
  689. if (s != null) {
  690. jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/sermon.php'); ?>', {sid: id, sname: s, sermon: 1}, function(r) {
  691. if (r) {
  692. sz = s.match(/(.*?)@(.*)/)[1];
  693. t = s.match(/(.*?)@(.*)/)[2];
  694. jQuery('#Services' + id).text(sz);
  695. jQuery('#time' + id).text(t);
  696. jQuery('#linkServices' + id).attr('href', 'javascript:renameServices(' + id + ', "' + s + '")');
  697. Fat.fade_element('Services' + id);
  698. Fat.fade_element('time' + id);
  699. };
  700. });
  701. }
  702. }
  703. //]]>
  704. </script>
  705. <a name="top"></a>
  706. <?php
  707. foreach ($toManage as $k => $v) {
  708. $i = 0;
  709. ?>
  710. <a name="manage-<?php echo $k ?>"></a>
  711. <div class="wrap">
  712. <?php if ($k == 'Series') { ?><a href="http://www.sermonbrowser.com/"><img src="<?php echo SB_PLUGIN_URL; ?>/sb-includes/logo-small.png" width="191" height ="35" style="margin: 1em 2em; float: right; background: #f9f9f9;" /></a><?php } ?>
  713. <h2><?php echo $k ?> (<a href="javascript:createNew<?php echo $k ?>()"><?php _e('add new', $sermon_domain) ?></a>)</h2>
  714. <br style="clear:both">
  715. <table class="widefat" style="width:auto">
  716. <thead>
  717. <tr>
  718. <th scope="col" style="text-align:center"><?php _e('ID', $sermon_domain) ?></th>
  719. <th scope="col"><?php _e('Name', $sermon_domain) ?></th>
  720. <?php echo $k == 'Services' ? '<th scope="col"><div style="text-align:center">'.__('Default time', $sermon_domain).'</div></th>' : '' ?>
  721. <th scope="col" style="text-align:center"><?php _e('Sermons', $sermon_domain) ?></th>
  722. <th scope="col" style="text-align:center"><?php _e('Actions', $sermon_domain) ?></th>
  723. </tr>
  724. </thead>
  725. <tbody id="<?php echo $k ?>-list">
  726. <?php if (is_array($v['data'])): ?>
  727. <?php foreach ($v['data'] as $item): ?>
  728. <tr class="<?php echo $k ?> <?php echo (++$i % 2 == 0) ? 'alternate' : '' ?>" id="row<?php echo $k ?><?php echo $item->id ?>">
  729. <th style="text-align:center" scope="row"><?php echo $item->id ?></th>
  730. <td id="<?php echo $k ?><?php echo $item->id ?>"><?php echo stripslashes($item->name) ?></td>
  731. <?php echo $k == 'Services' ? '<td style="text-align:center" id="time'.$item->id.'">'.$item->time.'</td>' : '' ?>
  732. <td style="text-align:center"><?php echo $item->sermon_count; ?></td>
  733. <td style="text-align:center">
  734. <a id="link<?php echo $k ?><?php echo $item->id ?>" href="javascript:rename<?php echo $k ?>(<?php echo $item->id ?>, '<?php echo $item->name ?><?php echo $k == 'Services' ? ' @ '.$item->time : '' ?>')"><?php echo $k == 'Services' ? __('Edit', $sermon_domain) : __('Rename', $sermon_domain) ?></a>
  735. <?php if (count($v['data']) < 2) { ?>
  736. | <a href="javascript:alert('<?php printf(__('You cannot delete this %1$s as you must have at least one %1$s in the database', $sermon_domain), $k); ?>')"><?php _e('Delete', $sermon_domain) ?></a>
  737. <?php } elseif ($item->sermon_count == 0) { ?>
  738. | <a href="javascript:alert('<?php printf(__('Are you sure you want to delete %s?', $sermon_domain), $item->name); ?>')"><?php _e('Delete', $sermon_domain) ?></a>
  739. <?php } else { ?>
  740. | <a href="javascript:alert('<?php switch ($k) {
  741. case "Services":
  742. _e('Some sermons are currently assigned to that service. You can only delete services that are not used in the database.', $sermon_domain);
  743. break;
  744. case "Series":
  745. _e('Some sermons are currently in that series. You can only delete series that are empty.', $sermon_domain);
  746. break;
  747. case "Preachers":
  748. _e('That preacher has sermons in the database. You can only delete preachers who have no sermons in the database.', $sermon_domain);
  749. break;
  750. }?>')"><?php _e('Delete', $sermon_domain) ?></a>
  751. <?php } ?>
  752. </td>
  753. </tr>
  754. <?php endforeach ?>
  755. <?php endif ?>
  756. </tbody>
  757. </table>
  758. <br style="clear:both">
  759. <div style="text-align:right"><a href="#top">Top &dagger;</a></div>
  760. </div>
  761. <?php
  762. }
  763. }
  764. /**
  765. * Display files page and handle changes
  766. */
  767. function sb_files() {
  768. global $wpdb, $filetypes, $sermon_domain;
  769. //Security check
  770. if (!current_user_can('upload_files'))
  771. wp_die(__("You do not have the correct permissions to upload sermons", $sermon_domain));
  772. // sync
  773. sb_scan_dir();
  774. if (isset($_POST['import_url'])) {
  775. $url = $_POST['url'];
  776. $valid_url = false;
  777. if(ini_get('allow_url_fopen')) {
  778. $headers = array_change_key_case(get_headers($url, 1),CASE_LOWER);
  779. if ($headers[0] == 'HTTP/1.1 200 OK') {
  780. if ($_POST['import_type'] == 'download') {
  781. $filename = substr($url, strrpos ($url, '/')+1);
  782. $filename = substr($filename, 0, strrpos ($filename, '?'));
  783. if (file_exists(SB_ABSPATH.sb_get_option('upload_dir').$filename))
  784. echo '<div id="message" class="updated fade"><p><b>'.sprintf(__('File %s already exists', $sermon_domain), $filename).'</b></div>';
  785. else {
  786. $file = @fopen(SB_ABSPATH.sb_get_option('upload_dir').$filename, 'wb');
  787. $remote_file = @fopen($url, 'r');
  788. $remote_contents = '';
  789. while (!feof($remote_file))
  790. $remote_contents .= fread($remote_file, 8192);
  791. fwrite($file, $remote_contents);
  792. fclose($remote_file);
  793. fclose($file);
  794. $wpdb->query("INSERT INTO {$wpdb->prefix}sb_stuff VALUES (null, 'file', '".$wpdb->escape($filename)."', 0, 0, 0)");
  795. echo "<script>document.location = '".admin_url('admin.php?page=sermon-browser/new_sermon.php&getid3='.$wpdb->insert_id)."';</script>";
  796. }
  797. } else {
  798. $wpdb->query("INSERT INTO {$wpdb->prefix}sb_stuff VALUES (null, 'url', '".$wpdb->escape($url)."', 0, 0, 0)");
  799. echo "<script>document.location = '".admin_url('admin.php?page=sermon-browser/new_sermon.php&getid3='.$wpdb->insert_id)."';</script>";
  800. die();
  801. }
  802. } else
  803. echo '<div id="message" class="updated fade"><p><b>'.__('Invalid URL.', $sermon_domain).'</b></div>';
  804. } else
  805. echo '<div id="message" class="updated fade"><p><b>'.__('Your host does not allow remote downloading of files.', $sermon_domain).'</b></div>';
  806. }
  807. elseif (isset($_POST['save'])) {
  808. if ($_FILES['upload']['error'] == UPLOAD_ERR_OK) {
  809. $filename = basename($_FILES['upload']['name']);
  810. if (IS_MU) {
  811. $file_allowed = FALSE;
  812. global $wp_version;
  813. if (version_compare ($wp_version, '3.0', '<'))
  814. require_once(SB_ABSPATH . 'wp-includes/wpmu-functions.php');
  815. else
  816. require_once(SB_ABSPATH . 'wp-includes/ms-functions.php');
  817. if (function_exists('get_site_option')) {
  818. $allowed_extensions = explode(" ", get_site_option("upload_filetypes"));
  819. foreach ($allowed_extensions as $ext) {
  820. if (substr(strtolower($filename), -(strlen($ext)+1)) == ".".strtolower($ext))
  821. $file_allowed = TRUE;
  822. }
  823. }
  824. } else {
  825. $file_allowed = TRUE;
  826. }
  827. if ($file_allowed) {
  828. $prefix = '';
  829. $dest = SB_ABSPATH.sb_get_option('upload_dir').$prefix.$filename;
  830. if($wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}sb_stuff WHERE name = '".mysql_real_escape_string($filename)."'") == 0) {
  831. $filename = mysql_real_escape_string($filename);
  832. if (move_uploaded_file($_FILES['upload']['tmp_name'], $dest)) {
  833. $filename = $prefix.$filename;
  834. $wpdb->query("INSERT INTO {$wpdb->prefix}sb_stuff VALUES (null, 'file', '{$filename}', 0, 0, 0)");
  835. if (sb_import_options_set ())
  836. echo "<script>document.location = '".admin_url('admin.php?page=sermon-browser/new_sermon.php&getid3='.$wpdb->insert_id)."';</script>";
  837. else
  838. echo '<div id="message" class="updated fade"><p><b>'.__('Files saved to database.', $sermon_domain).'</b></div>';
  839. }
  840. } else {
  841. echo '<div id="message" class="updated fade"><p><b>'.__($filename. ' already exists.', $sermon_domain).'</b></div>';
  842. }
  843. } else {
  844. @unlink($_FILES['upload']['tmp_name']);
  845. echo '<div id="message" class="updated fade"><p><b>'.__('You are not permitted to upload files of that type.', $sermon_domain).'</b></div>';
  846. }
  847. }
  848. } elseif(isset($_POST['clean'])) {
  849. $unlinked = $wpdb->get_results("SELECT f.*, s.title FROM {$wpdb->prefix}sb_stuff AS f LEFT JOIN {$wpdb->prefix}sb_sermons AS s ON f.sermon_id = s.id WHERE f.sermon_id = 0 AND f.type = 'file' ORDER BY f.name;");
  850. $linked = $wpdb->get_results("SELECT f.*, s.title FROM {$wpdb->prefix}sb_stuff AS f LEFT JOIN {$wpdb->prefix}sb_sermons AS s ON f.sermon_id = s.id WHERE f.sermon_id <> 0 AND f.type = 'file' ORDER BY f.name;");
  851. $wanted = array(-1);
  852. foreach ((array) $unlinked as $k => $file) {
  853. if (!file_exists(SB_ABSPATH.sb_get_option('upload_dir').$file->name)) {
  854. $wanted[] = $file->id;
  855. unset($unlinked[$k]);
  856. }
  857. }
  858. foreach ((array) $linked as $k => $file) {
  859. if (!file_exists(SB_ABSPATH.sb_get_option('upload_dir').$file->name)) {
  860. $wanted[] = $file->id;
  861. unset($unlinked[$k]);
  862. }
  863. }
  864. $wpdb->query("DELETE FROM {$wpdb->prefix}sb_stuff WHERE id IN (".implode(', ', (array) $wanted).")");
  865. $wpdb->query("DELETE FROM {$wpdb->prefix}sb_stuff WHERE type != 'file' AND sermon_id=0");
  866. }
  867. $unlinked = $wpdb->get_results("SELECT f.*, s.title FROM {$wpdb->prefix}sb_stuff AS f LEFT JOIN {$wpdb->prefix}sb_sermons AS s ON f.sermon_id = s.id WHERE f.sermon_id = 0 AND f.type = 'file' ORDER BY f.name LIMIT 10;");
  868. $linked = $wpdb->get_results("SELECT f.*, s.title FROM {$wpdb->prefix}sb_stuff AS f LEFT JOIN {$wpdb->prefix}sb_sermons AS s ON f.sermon_id = s.id WHERE f.sermon_id <> 0 AND f.type = 'file' ORDER BY f.name LIMIT 10;");
  869. $cntu = $wpdb->get_row("SELECT COUNT(*) as cntu FROM {$wpdb->prefix}sb_stuff WHERE sermon_id = 0 AND type = 'file' ", ARRAY_A);
  870. $cntu = $cntu['cntu'];
  871. $cntl = $wpdb->get_row("SELECT COUNT(*) as cntl FROM {$wpdb->prefix}sb_stuff WHERE sermon_id <> 0 AND type = 'file' ", ARRAY_A);
  872. $cntl = $cntl['cntl'];
  873. sb_do_alerts();
  874. ?>
  875. <script>
  876. function rename(id, old) {
  877. var f = prompt("<?php _e('New file name?', $sermon_domain) ?>", old);
  878. if (f != null) {
  879. jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/uploads.php'); ?>', {fid: id, oname: old, fname: f, sermon: 1}, function(r) {
  880. if (r) {
  881. if (r == 'renamed') {
  882. jQuery('#' + id).text(f.substring(0,f.lastIndexOf(".")));
  883. jQuery('#link' + id).attr('href', 'javascript:rename(' + id + ', "' + f + '")');
  884. Fat.fade_element(id);
  885. jQuery('#s' + id).text(f.substring(0,f.lastIndexOf(".")));
  886. jQuery('#slink' + id).attr('href', 'javascript:rename(' + id + ', "' + f + '")');
  887. Fat.fade_element('s' + id);
  888. } else {
  889. if (r == 'forbidden') {
  890. alert('<?php _e('You are not permitted files with that extension.', $sermon_domain) ?>');
  891. } else {
  892. alert('<?php _e('The script is unable to rename your file.', $sermon_domain) ?>');
  893. }
  894. }
  895. };
  896. });
  897. }
  898. }
  899. function kill(id, f) {
  900. jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/files.php'); ?>', {fname: f, fid: id, del: 1, sermon: 1}, function(r) {
  901. if (r) {
  902. if (r == 'deleted') {
  903. jQuery('#file' + id).fadeOut(function() {
  904. jQuery('.file:visible').each(function(i) {
  905. jQuery(this).removeClass('alternate');
  906. if (++i % 2 == 0) {
  907. jQuery(this).addClass('alternate');
  908. }
  909. });
  910. });
  911. jQuery('#sfile' + id).fadeOut(function() {
  912. jQuery('.file:visible').each(function(i) {
  913. jQuery(this).removeClass('alternate');
  914. if (++i % 2 == 0) {
  915. jQuery(this).addClass('alternate');
  916. }
  917. });
  918. });
  919. } else {
  920. alert('<?php _e('The script is unable to delete your file.', $sermon_domain) ?>');
  921. }
  922. };
  923. });
  924. }
  925. function fetchU(st) {
  926. jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/uploads.php'); ?>', {fetchU: st + 1, sermon: 1}, function(r) {
  927. if (r) {
  928. jQuery('#the-list-u').html(r);
  929. if (st >= <?php echo sb_get_option('sermons_per_page') ?>) {
  930. x = st - <?php echo sb_get_option('sermons_per_page') ?>;
  931. jQuery('#uleft').html('<a href="javascript:fetchU(' + x + ')">&laquo; <?php _e('Previous', $sermon_domain) ?></a>');
  932. } else {
  933. jQuery('#uleft').html('');
  934. }
  935. if (st + <?php echo sb_get_option('sermons_per_page') ?> <= <?php echo $cntu ?>) {
  936. y = st + <?php echo sb_get_option('sermons_per_page') ?>;
  937. jQuery('#uright').html('<a href="javascript:fetchU(' + y + ')"><?php _e('Next', $sermon_domain) ?> &raquo;</a>');
  938. } else {
  939. jQuery('#uright').html('');
  940. }
  941. };
  942. });
  943. }
  944. function fetchL(st) {
  945. jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/files.php'); ?>', {fetchL: st + 1, sermon: 1}, function(r) {
  946. if (r) {
  947. jQuery('#the-list-l').html(r);
  948. if (st >= <?php echo sb_get_option('sermons_per_page') ?>) {
  949. x = st - <?php echo sb_get_option('sermons_per_page') ?>;
  950. jQuery('#left').html('<a href="javascript:fetchL(' + x + ')">&laquo; <?php _e('Previous', $sermon_domain) ?></a>');
  951. } else {
  952. jQuery('#left').html('');
  953. }
  954. if (st + <?php echo sb_get_option('sermons_per_page') ?> <= <?php echo $cntl ?>) {
  955. y = st + <?php echo sb_get_option('sermons_per_page') ?>;
  956. jQuery('#right').html('<a href="javascript:fetchL(' + y + ')"><?php _e('Next', $sermon_domain) ?> &raquo;</a>');
  957. } else {
  958. jQuery('#right').html('');
  959. }
  960. };
  961. });
  962. }
  963. function findNow() {
  964. jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/files.php'); ?>', {search: jQuery('#search').val(), sermon: 1}, function(r) {
  965. if (r) {
  966. jQuery('#the-list-s').html(r);
  967. };
  968. });
  969. }
  970. </script>
  971. <a name="top"></a>
  972. <div class="wrap">
  973. <a href="http://www.sermonbrowser.com/"><img src="<?php echo SB_PLUGIN_URL; ?>/sb-includes/logo-small.png" width="191" height ="35" style="margin: 1em 2em; float: right; background: #f9f9f9;" /></a>
  974. <h2><?php _e('Upload Files', $sermon_domain) ?></h2>
  975. <?php if (!sb_import_options_set()) {
  976. echo '<p class="plugin-update">';
  977. sb_print_import_options_message();
  978. echo "</p>\n";
  979. } ?>
  980. <br style="clear:both">
  981. <?php
  982. sb_print_upload_form();
  983. ?>
  984. </div>
  985. <div class="wrap">
  986. <h2><?php _e('Unlinked files', $sermon_domain) ?></h2>
  987. <br style="clear:both">
  988. <table class="widefat">
  989. <thead>
  990. <tr>
  991. <th width="10%" scope="col"><div style="text-align:center"><?php _e('ID', $sermon_domain) ?></div></th>
  992. <th width="50%" scope="col"><div style="text-align:center"><?php _e('File name', $sermon_domain) ?></div></th>
  993. <th width="20%" scope="col"><div style="text-align:center"><?php _e('File type', $sermon_domain) ?></div></th>
  994. <th width="20%" scope="col"><div style="text-align:center"><?php _e('Actions', $sermon_domain) ?></div></th>
  995. </tr>
  996. </thead>
  997. <tbody id="the-list-u">
  998. <?php if (is_array($unlinked)): ?>
  999. <?php foreach ($unlinked as $file): ?>
  1000. <tr class="file <?php $i=0; echo (++$i % 2 == 0) ? 'alternate' : '' ?>" id="file<?php echo $file->id ?>">
  1001. <th style="text-align:center" scope="row"><?php echo $file->id ?></th>
  1002. <td id="<?php echo $file->id ?>"><?php echo substr($file->name, 0, strrpos($file->name, '.')) ?></td>
  1003. <td style="text-align:center"><?php echo isset($filetypes[substr($file->name, strrpos($file->name, '.') + 1)]['name']) ? $filetypes[substr($file->name, strrpos($file->name, '.') + 1)]['name'] : strtoupper(substr($file->name, strrpos($file->name, '.') + 1)) ?></td>
  1004. <td style="text-align:center">
  1005. <a id="" href="<?php echo admin_url("admin.php?page=sermon-browser/new_sermon.php&amp;getid3={$file->id}"); ?>"><?php _e('Create sermon', $sermon_domain) ?></a> |
  1006. <a id="link<?php echo $file->id ?>" href="javascript:rename(<?php echo $file->id ?>, '<?php echo $file->name ?>')"><?php _e('Rename', $sermon_domain) ?></a> | <a onclick="return confirm('Do you really want to delete <?php echo str_replace("'", '', $file->name) ?>?');" href="javascript:kill(<?php echo $file->id ?>, '<?php echo $file->name ?>');"><?php _e('Delete', $sermon_domain) ?></a>
  1007. </td>
  1008. </tr>
  1009. <?php endforeach ?>
  1010. <?php endif ?>
  1011. </tbody>
  1012. </table>
  1013. <br style="clear:both">
  1014. <div class="navigation">
  1015. <div class="alignleft" id="uleft"></div>
  1016. <div class="alignright" id="uright"></div>
  1017. </div>
  1018. </div>
  1019. <a name="linked"></a>
  1020. <div class="wrap">
  1021. <h2><?php _e('Linked files', $sermon_domain) ?></h2>
  1022. <br style="clear:both">
  1023. <table class="widefat">
  1024. <thead>
  1025. <tr>
  1026. <th scope="col"><div style="text-align:center"><?php _e('ID', $sermon_domain) ?></div></th>
  1027. <th scope="col"><div style="text-align:center"><?php _e('File name', $sermon_domain) ?></div></th>
  1028. <th scope="col"><div style="text-align:center"><?php _e('File type', $sermon_domain) ?></div></th>
  1029. <th scope="col"><div style="text-align:center"><?php _e('Sermon', $sermon_domain) ?></div></th>
  1030. <th scope="col"><div style="text-align:center"><?php _e('Actions', $sermon_domain) ?></div></th>
  1031. </tr>
  1032. </thead>
  1033. <tbody id="the-list-l">
  1034. <?php if (is_array($linked)): ?>
  1035. <?php foreach ($linked as $file): ?>
  1036. <tr class="file <?php echo (++$i % 2 == 0) ? 'alternate' : '' ?>" id="file<?php echo $file->id ?>">
  1037. <th style="text-align:center" scope="row"><?php echo $file->id ?></th>
  1038. <td id="<?php echo $file->id ?>"><?php echo substr($file->name, 0, strrpos($file->name, '.')) ?></td>
  1039. <td style="text-align:center"><?php echo isset($filetypes[substr($file->name, strrpos($file->name, '.') + 1)]['name']) ? $filetypes[substr($file->name, strrpos($file->name, '.') + 1)]['name'] : strtoupper(substr($file->name, strrpos($file->name, '.') + 1)) ?></td>
  1040. <td><?php echo stripslashes($file->title) ?></td>
  1041. <td style="text-align:center">
  1042. <script type="text/javascript" language="javascript">
  1043. function deletelinked_<?php echo $file->id;?>(filename, filesermon) {
  1044. if (confirm('Do you really want to delete '+filename+'?')) {
  1045. return confirm('This file is linked to the sermon called ['+filesermon+']. Are you sure you want to delete it?');
  1046. }
  1047. return false;
  1048. }
  1049. </script>
  1050. <a id="link<?php echo $file->id ?>" href="javascript:rename(<?php echo $file->id ?>, '<?php echo $file->name ?>')"><?php _e('Rename', $sermon_domain) ?></a> | <a onclick="return deletelinked_<?php echo $file->id;?>('<?php echo str_replace("'", '', $file->name) ?>', '<?php echo str_replace("'", '', $file->title) ?>');" href="javascript:kill(<?php echo $file->id ?>, '<?php echo $file->name ?>');"><?php _e('Delete', $sermon_domain) ?></a>
  1051. </td>
  1052. </tr>
  1053. <?php endforeach ?>
  1054. <?php endif ?>
  1055. </tbody>
  1056. </table>
  1057. <br style="clear:both">
  1058. <div class="navigation">
  1059. <div class="alignleft" id="left"></div>
  1060. <div class="alignright" id="right"></div>
  1061. </div>
  1062. </div>
  1063. <a name="search"></a>
  1064. <div class="wrap">
  1065. <h2><?php _e('Search for files', $sermon_domain) ?></h2>
  1066. <form id="searchform" name="searchform">
  1067. <p>
  1068. <input type="text" size="30" value="" id="search" />
  1069. <input type="submit" class="button" value="<?php _e('Search', $sermon_domain) ?> &raquo;" onclick="javascript:findNow();return false;" />
  1070. </p>
  1071. </form>
  1072. <table class="widefat">
  1073. <thead>
  1074. <tr>
  1075. <th scope="col"><div style="text-align:center"><?php _e('ID', $sermon_domain) ?></div></th>
  1076. <th scope="col"><div style="text-align:center"><?php _e('File name', $sermon_domain) ?></div></th>
  1077. <th scope="col"><div style="text-align:center"><?php _e('File type', $sermon_domain) ?></div></th>
  1078. <th scope="col"><div style="text-align:center"><?php _e('Sermon', $sermon_domain) ?></div></th>
  1079. <th scope="col"><div style="text-align:center"><?php _e('Actions', $sermon_domain) ?></div></th>
  1080. </tr>
  1081. </thead>
  1082. <tbody id="the-list-s">
  1083. <tr>
  1084. <td><?php _e('Search results will appear here.', $sermon_domain) ?></td>
  1085. </tr>
  1086. </tbody>
  1087. </table>
  1088. <br style="clear:both">
  1089. </div>
  1090. <script>
  1091. <?php if ($cntu > sb_get_option('sermons_per_page')): ?>
  1092. jQuery('#uright').html('<a href="javascript:fetchU(<?php echo sb_get_option('sermons_per_page') ?>)">Next &raquo;</a>');
  1093. <?php endif ?>
  1094. <?php if ($cntl > sb_get_option('sermons_per_page')): ?>
  1095. jQuery('#right').html('<a href="javascript:fetchL(<?php echo sb_get_option('sermons_per_page') ?>)">Next &raquo;</a>');
  1096. <?php endif ?>
  1097. </script>
  1098. <?php
  1099. if (isset($checkSermonUpload) && $checkSermonUpload == 'writeable') {
  1100. ?>
  1101. <div class="wrap">
  1102. <h2><?php _e('Clean up', $sermon_domain) ?></h2>
  1103. <form method="post" >
  1104. <p><?php _e('Pressing the button below scans every sermon in the database, and removes missing attachments. Use with caution!', $sermon_domain) ?></p>
  1105. <input type="submit" name="clean" value="<?php _e('Clean up missing files', $sermon_domain) ?>" />
  1106. </form>
  1107. </div>
  1108. <?php
  1109. }
  1110. }
  1111. /**
  1112. * Pings the sermon-browser gallery
  1113. */
  1114. function sb_ping_gallery() {
  1115. global $wpdb;
  1116. if((ini_get('allow_url_fopen') | function_exists('curl_init')) & get_option('blog_public') == 1 & get_option('ping_sites') != "") {
  1117. $url = "http://ping.preachingcentral.com/?sg_ping";
  1118. $url .= "&name=".rawurlencode(get_option('blogname'));
  1119. $url .= "&tagline=".rawurlencode(get_option('blogdescription'));
  1120. $url .= "&site_url=".rawurlencode(site_url());
  1121. $url .= "&sermon_url=".rawurlencode(sb_display_url());
  1122. $url .= "&most_recent=".rawurlencode($wpdb->get_var("SELECT datetime FROM {$wpdb->prefix}sb_sermons ORDER BY datetime DESC LIMIT 1"));
  1123. $url .= "&num_sermons=".rawurlencode($wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}sb_sermons"));
  1124. $url .= "&ver=".constant("SB_CURRENT_VERSION");
  1125. if (ini_get('allow_url_fopen')) {
  1126. $headers = @get_headers($url, 1);
  1127. if ($headers !="") {
  1128. $headers = array_change_key_case($headers,CASE_LOWER);
  1129. }
  1130. } else {
  1131. $curl = curl_init();
  1132. curl_setopt ($curl, CURLOPT_URL, $url);
  1133. curl_setopt ($curl, CURLOPT_HEADER, 1);
  1134. curl_setopt ($curl, CURLOPT_NOBODY, 1);
  1135. curl_setopt ($curl, CURLOPT_TIMEOUT, 2);
  1136. curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
  1137. curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, 1);
  1138. curl_setopt ($curl, CURLOPT_MAXREDIRS, 10);
  1139. $execute = curl_exec ($curl);
  1140. $info = curl_getinfo ($curl);
  1141. curl_close ($curl);
  1142. }
  1143. }
  1144. }
  1145. /**
  1146. * Displays Sermons page
  1147. */
  1148. function sb_manage_sermons() {
  1149. global $wpdb, $sermon_domain;
  1150. //Security check
  1151. if (function_exists('current_user_can') && !(current_user_can('publish_posts') || current_user_can('publish_pages')))
  1152. wp_die(__("You do not have the correct permissions to edit sermons", $sermon_domain));
  1153. sb_do_alerts();
  1154. if (isset($_GET['saved'])) {
  1155. echo '<div id="message" class="updated fade"><p><b>'.__('Sermon saved to database.', $sermon_domain).'</b></div>';
  1156. if (rand (1,5) == 1 && sb_get_option('show_donate_reminder') != 'off')
  1157. echo '<div id="message" class="updated"><p><b>'.sprintf(__('If you find SermonBrowser useful, please consider %1$ssupporting%2$s the ministry of Nathanael and Anna Ayling in Japan.', $sermon_domain), '<a href="'.admin_url('admin.php?page=sermon-browser/japan.php').'">', '</a>').'</b></div>';
  1158. }
  1159. if (isset($_GET['mid'])) {
  1160. //Security check
  1161. if (function_exists('current_user_can')&&!current_user_can('publish_posts'))
  1162. wp_die(__("You do not have the correct permissions to delete sermons", $sermon_domain));
  1163. $mid = (int) $_GET['mid'];
  1164. $wpdb->query("DELETE FROM {$wpdb->prefix}sb_sermons WHERE id = $mid;");
  1165. $wpdb->query("DELETE FROM {$wpdb->prefix}sb_sermons_tags WHERE sermon_id = $mid;");
  1166. $wpdb->query("DELETE FROM {$wpdb->prefix}sb_books_sermons WHERE sermon_id = $mid;");
  1167. $wpdb->query("UPDATE {$wpdb->prefix}sb_stuff SET sermon_id = 0 WHERE sermon_id = $mid AND type = 'file';");
  1168. $wpdb->query("DELETE FROM {$wpdb->prefix}sb_stuff WHERE sermon_id = $mid AND type <> 'file';");
  1169. sb_delete_unused_tags();
  1170. echo '<div id="message" class="updated fade"><p><b>'.__('Sermon removed from database.', $sermon_domain).'</b></div>';
  1171. }
  1172. $cnt = $wpdb->get_row("SELECT COUNT(*) FROM {$wpdb->prefix}sb_sermons", ARRAY_A);
  1173. $cnt = $cnt['COUNT(*)'];
  1174. $sermons = $wpdb->get_results("SELECT m.id, m.title, m.datetime, p.name as pname, s.name as sname, ss.name as ssname
  1175. FROM {$wpdb->prefix}sb_sermons as m
  1176. LEFT JOIN {$wpdb->prefix}sb_preachers as p ON m.preacher_id = p.id
  1177. LEFT JOIN {$wpdb->prefix}sb_services as s ON m.service_id = s.id
  1178. LEFT JOIN {$wpdb->prefix}sb_series as ss ON m.series_id = ss.id
  1179. ORDER BY m.datetime desc, s.time desc LIMIT 0, ".sb_get_option('sermons_per_page'));
  1180. $preachers = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_preachers ORDER BY name;");
  1181. $series = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_series ORDER BY name;");
  1182. ?>
  1183. <script>
  1184. function fetch(st) {
  1185. jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/sermon.php'); ?>', {fetch: st + 1, sermon: 1, title: jQuery('#search').val(), preacher: jQuery('#preacher').val(), series: jQuery('#series').val() }, function(r) {
  1186. if (r) {
  1187. jQuery('#the-list').html(r);
  1188. if (st >= <?php echo sb_get_option('sermons_per_page') ?>) {
  1189. x = st - <?php echo sb_get_option('sermons_per_page') ?>;
  1190. jQuery('#left').html('<a href="javascript:fetch(' + x + ')">&laquo; Previous</a>');
  1191. } else {
  1192. jQuery('#left').html('');
  1193. }
  1194. if (st + <?php echo sb_get_option('sermons_per_page') ?> <= <?php echo $cnt ?>) {
  1195. y = st + <?php echo sb_get_option('sermons_per_page') ?>;
  1196. jQuery('#right').html('<a href="javascript:fetch(' + y + ')">Next &raquo;</a>');
  1197. } else {
  1198. jQuery('#right').html('');
  1199. }
  1200. };
  1201. });
  1202. }
  1203. </script>
  1204. <div class="wrap">
  1205. <a href="http://www.sermonbrowser.com/"><img src="<?php echo SB_PLUGIN_URL; ?>/sb-includes/logo-small.png" width="191" height ="35" style="margin: 1em 2em; float: right; background: #f9f9f9;" /></a>
  1206. <h2>Filter</h2>
  1207. <form id="searchform" name="searchform">
  1208. <fieldset style="float:left; margin-right: 1em">
  1209. <legend><?php _e('Title', $sermon_domain) ?></legend>
  1210. <input type="text" size="17" value="" id="search" />
  1211. </fieldset>
  1212. <fieldset style="float:left; margin-right: 1em">
  1213. <legend><?php _e('Preacher', $sermon_domain) ?></legend>
  1214. <select id="preacher">
  1215. <option value="0"></option>
  1216. <?php foreach ($preachers as $preacher): ?>
  1217. <option value="<?php echo $preacher->id ?>"><?php echo htmlspecialchars(stripslashes($preacher->name), ENT_QUOTES) ?></option>
  1218. <?php endforeach ?>
  1219. </select>
  1220. </fieldset>
  1221. <fieldset style="float:left; margin-right: 1em">
  1222. <legend><?php _e('Series', $sermon_domain) ?></legend>
  1223. <select id="series">
  1224. <option value="0"></option>
  1225. <?php foreach ($series as $item): ?>
  1226. <option value="<?php echo $item->id ?>"><?php echo htmlspecialchars(stripslashes($item->name), ENT_QUOTES) ?></option>
  1227. <?php endforeach ?>
  1228. </select>
  1229. </fieldset style="float:left; margin-right: 1em">
  1230. <input type="submit" class="button" value="<?php _e('Filter', $sermon_domain) ?> &raquo;" style="float:left;margin:14px 0pt 1em; position:relative;top:0.35em;" onclick="javascript:fetch(0);return false;" />
  1231. </form>
  1232. <br style="clear:both">
  1233. <h2><?php _e('Sermons', $sermon_domain) ?></h2>
  1234. <br style="clear:both">
  1235. <table class="widefat">
  1236. <thead>
  1237. <tr>
  1238. <th scope="col" style="text-align:center"><?php _e('ID', $sermon_domain) ?></th>
  1239. <th scope="col"><?php _e('Title', $sermon_domain) ?></th>
  1240. <th scope="col"><?php _e('Preacher', $sermon_domain) ?></th>
  1241. <th scope="col"><?php _e('Date', $sermon_domain) ?></th>
  1242. <th scope="col"><?php _e('Service', $sermon_domain) ?></th>
  1243. <th scope="col"><?php _e('Series', $sermon_domain) ?></th>
  1244. <th scope="col" style="text-align:center"><?php _e('Stats', $sermon_domain) ?></th>
  1245. <th scope="col" style="text-align:center"><?php _e('Actions', $sermon_domain) ?></th>
  1246. </tr>
  1247. </thead>
  1248. <tbody id="the-list">
  1249. <?php if (is_array($sermons)): ?>
  1250. <?php foreach ($sermons as $sermon): ?>
  1251. <tr class="<?php $i=0; echo ++$i % 2 == 0 ? 'alternate' : '' ?>">
  1252. <th style="text-align:center" scope="row"><?php echo $sermon->id ?></th>
  1253. <td><?php echo stripslashes($sermon->title) ?></td>
  1254. <td><?php echo stripslashes($sermon->pname) ?></td>
  1255. <td><?php echo ($sermon->datetime == '1970-01-01 00:00:00') ? __('Unknown', $sermon_domain) : strftime('%d %b %y', strtotime($sermon->datetime)); ?></td>
  1256. <td><?php echo stripslashes($sermon->sname) ?></td>
  1257. <td><?php echo stripslashes($sermon->ssname) ?></td>
  1258. <td><?php echo sb_sermon_stats($sermon->id) ?></td>
  1259. <td style="text-align:center">
  1260. <?php //Security check
  1261. if (function_exists('current_user_can') && current_user_can('publish_posts')) { ?>
  1262. <a href="<?php echo admin_url("admin.php?page=sermon-browser/new_sermon.php&mid={$sermon->id}"); ?>"><?php _e('Edit', $sermon_domain) ?></a> | <a onclick="return confirm('Are you sure?')" href="<?php echo admin_url("admin.php?page=sermon-browser/sermon.php&mid={$sermon->id}"); ?>"><?php _e('Delete', $sermon_domain); ?></a> |
  1263. <?php } ?>
  1264. <a href="<?php echo sb_display_url().sb_query_char(true).'sermon_id='.$sermon->id;?>">View</a>
  1265. </td>
  1266. </tr>
  1267. <?php endforeach ?>
  1268. <?php endif ?>
  1269. </tbody>
  1270. </table>
  1271. <div class="navigation">
  1272. <div class="alignleft" id="left"></div>
  1273. <div class="alignright" id="right"></div>
  1274. </div>
  1275. </div>
  1276. <script>
  1277. <?php if ($cnt > sb_get_option('sermons_per_page')): ?>
  1278. jQuery('#right').html('<a href="javascript:fetch(<?php echo sb_get_option('sermons_per_page') ?>)">Next &raquo;</a>');
  1279. <?php endif ?>
  1280. </script>
  1281. <?php
  1282. }
  1283. /**
  1284. * Displays new/edit sermon page
  1285. */
  1286. function sb_new_sermon() {
  1287. global $wpdb, $sermon_domain, $allowedposttags;
  1288. $getid3=false;
  1289. //Security check
  1290. if (!(current_user_can('publish_posts') || current_user_can('publish_pages')))
  1291. wp_die(__("You do not have the correct permissions to edit or create sermons", $sermon_domain));
  1292. include_once (SB_ABSPATH.'/wp-includes/kses.php');
  1293. sb_scan_dir();
  1294. if (isset($_POST['save']) && isset($_POST['title'])) {
  1295. // prepare
  1296. $title = $wpdb->escape($_POST['title']);
  1297. $preacher_id = (int) $_POST['preacher'];
  1298. $service_id = (int) $_POST['service'];
  1299. $series_id = (int) $_POST['series'];
  1300. $time = isset($_POST['time']) ? $wpdb->escape($_POST['time']) : '';
  1301. $startz = $endz = array();
  1302. for ($foo = 0; $foo < count($_POST['start']['book']); $foo++) {
  1303. if (!empty($_POST['start']['chapter'][$foo]) && !empty($_POST['end']['chapter'][$foo]) && !empty($_POST['start']['verse'][$foo]) && !empty($_POST['end']['verse'][$foo])) {
  1304. $startz[] = array(
  1305. 'book' => $_POST['start']['book'][$foo],
  1306. 'chapter' => $_POST['start']['chapter'][$foo],
  1307. 'verse' => $_POST['start']['verse'][$foo],
  1308. );
  1309. $endz[] = array(
  1310. 'book' => $_POST['end']['book'][$foo],
  1311. 'chapter' => $_POST['end']['chapter'][$foo],
  1312. 'verse' => $_POST['end']['verse'][$foo],
  1313. );
  1314. }
  1315. }
  1316. $start = $wpdb->escape(serialize($startz));
  1317. $end = $wpdb->escape(serialize($endz));
  1318. $date = strtotime($_POST['date']);
  1319. $override = (isset($_POST['override']) && $_POST['override'] == 'on') ? 1 : 0;
  1320. if ($date) {
  1321. if (!$override) {
  1322. $service_time = $wpdb->get_var("SELECT time FROM {$wpdb->prefix}sb_services WHERE id={$service_id}");
  1323. if ($service_time)
  1324. $date = $date - strtotime('00:00') + strtotime($service_time);
  1325. } else
  1326. $date = $date - strtotime('00:00') + strtotime($_POST['time']);
  1327. $date = date('Y-m-d H:i:s', $date);
  1328. } else
  1329. $date = '1970-01-01 00:00';
  1330. if (function_exists('current_user_can') && !current_user_can('unfiltered_html')) {
  1331. $description = mysql_real_escape_string(wp_kses($_POST['description'], $allowedposttags));
  1332. } else {
  1333. $description = mysql_real_escape_string($_POST['description']);
  1334. }
  1335. // edit or not edit
  1336. if (!$_GET['mid']) { // new
  1337. //Security check
  1338. if (!current_user_can('publish_pages'))
  1339. wp_die(__("You do not have the correct permissions to create sermons", $sermon_domain));
  1340. $wpdb->query("INSERT INTO {$wpdb->prefix}sb_sermons VALUES (null, '$title', '$preacher_id', '$date', '$service_id', '$series_id', '$start', '$end', '$description', '$time', '$override', 0)");
  1341. $id = $wpdb->insert_id;
  1342. } else { // edit
  1343. //Security check
  1344. if (!current_user_can('publish_posts'))
  1345. wp_die(__("You do not have the correct permissions to edit sermons", $sermon_domain));
  1346. $id = (int) $_GET['mid'];
  1347. $wpdb->query("UPDATE {$wpdb->prefix}sb_sermons SET title = '$title', preacher_id = '$preacher_id', datetime = '$date', series_id = '$series_id', start = '$start', end = '$end', description = '$description', time = '$time', service_id = '$service_id', override = '$override' WHERE id = $id");
  1348. $wpdb->query("UPDATE {$wpdb->prefix}sb_stuff SET sermon_id = 0 WHERE sermon_id = $id AND type = 'file'");
  1349. $wpdb->query("DELETE FROM {$wpdb->prefix}sb_stuff WHERE sermon_id = $id AND type <> 'file'");
  1350. }
  1351. // deal with books
  1352. $wpdb->query("DELETE FROM {$wpdb->prefix}sb_books_sermons WHERE sermon_id = $id;");
  1353. if (isset($startz)) foreach ($startz as $i => $st) {
  1354. $wpdb->query("INSERT INTO {$wpdb->prefix}sb_books_sermons VALUES(null, '{$st['book']}', '{$st['chapter']}', '{$st['verse']}', $i, 'start', $id);");
  1355. }
  1356. if (isset($endz)) foreach ($endz as $i => $ed) {
  1357. $wpdb->query("INSERT INTO {$wpdb->prefix}sb_books_sermons VALUES(null, '{$ed['book']}', '{$ed['chapter']}', '{$ed['verse']}', $i, 'end', $id);");
  1358. }
  1359. // now previously uploaded files
  1360. foreach ($_POST['file'] as $uid => $file) {
  1361. if ($file != 0)
  1362. $wpdb->query("UPDATE {$wpdb->prefix}sb_stuff SET sermon_id = $id WHERE id = $file;");
  1363. elseif ($_FILES['upload']['error'][$uid] == UPLOAD_ERR_OK) {
  1364. $filename = basename($_FILES['upload']['name'][$uid]);
  1365. if (IS_MU) {
  1366. $file_allowed = FALSE;
  1367. global $wp_version;
  1368. if (version_compare ($wp_version, '3.0', '<'))
  1369. require_once(SB_ABSPATH . 'wp-includes/wpmu-functions.php');
  1370. if (function_exists('get_site_option')) {
  1371. $allowed_extensions = explode(' ', get_site_option('upload_filetypes'));
  1372. foreach ($allowed_extensions as $ext) {
  1373. if (substr(strtolower($filename), -(strlen($ext)+1)) == '.'.strtolower($ext))
  1374. $file_allowed = TRUE;
  1375. }
  1376. }
  1377. } else {
  1378. $file_allowed = TRUE;
  1379. }
  1380. if ($file_allowed) {
  1381. $prefix = '';
  1382. $dest = SB_ABSPATH.sb_get_option('upload_dir').$prefix.$filename;
  1383. if ($wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}sb_stuff WHERE name = '".$wpdb->escape($filename)."'") == 0 && move_uploaded_file($_FILES['upload']['tmp_name'][$uid], $dest)) {
  1384. $filename = $prefix.mysql_real_escape_string($filename);
  1385. $wpdb->query("INSERT INTO {$wpdb->prefix}sb_stuff VALUES (null, 'file', '".$wpdb->escape($filename)."', $id, 0, 0)");
  1386. } else {
  1387. echo '<div id="message" class="updated fade"><p><b>'.$filename.__(' already exists.', $sermon_domain).'</b></div>';
  1388. $error = true;
  1389. }
  1390. } else {
  1391. @unlink($_FILES['upload']['tmp_name']);
  1392. echo '<div id="message" class="updated fade"><p><b>'.__('You are not permitted to upload files of that type.', $sermon_domain).'</b></div>';
  1393. $error = true;
  1394. }
  1395. }
  1396. }
  1397. // then URLs
  1398. foreach ((array) $_POST['url'] as $urlz) {
  1399. if (!empty($urlz)) {
  1400. $urlz = mysql_real_escape_string($urlz);
  1401. $wpdb->query("INSERT INTO {$wpdb->prefix}sb_stuff VALUES(null, 'url', '$urlz', $id, 0, 0);");
  1402. }
  1403. }
  1404. // embed code next
  1405. foreach ((array) $_POST['code'] as $code) {
  1406. if (!empty($code)) {
  1407. $code = base64_encode(stripslashes($code));
  1408. $wpdb->query("INSERT INTO {$wpdb->prefix}sb_stuff VALUES(null, 'code', '$code', $id, 0, 0)");
  1409. }
  1410. }
  1411. // tags
  1412. $tags = explode(',', $_POST['tags']);
  1413. $wpdb->query("DELETE FROM {$wpdb->prefix}sb_sermons_tags WHERE sermon_id = $id;");
  1414. foreach ($tags as $tag) {
  1415. $clean_tag = trim(mysql_real_escape_string($tag));
  1416. $existing_id = $wpdb->get_var("SELECT id FROM {$wpdb->prefix}sb_tags WHERE name='$clean_tag'");
  1417. if (is_null($existing_id)) {
  1418. $wpdb->query("INSERT INTO {$wpdb->prefix}sb_tags VALUES (null, '$clean_tag')");
  1419. $existing_id = $wpdb->insert_id;
  1420. }
  1421. $wpdb->query("INSERT INTO {$wpdb->prefix}sb_sermons_tags VALUES (null, $id, $existing_id)");
  1422. }
  1423. sb_delete_unused_tags();
  1424. // everything is fine, get out of here!
  1425. if(!isset($error)) {
  1426. sb_ping_gallery();
  1427. echo "<script>document.location = '".admin_url('admin.php?page=sermon-browser/sermon.php&saved=true')."';</script>";
  1428. die();
  1429. }
  1430. }
  1431. $id3_tags = array();
  1432. if (isset($_GET['getid3'])) {
  1433. require_once(SB_INCLUDES_DIR.'/getid3/getid3.php');
  1434. $file_data = $wpdb->get_row("SELECT name, type FROM {$wpdb->prefix}sb_stuff WHERE id = ".$wpdb->escape($_GET['getid3']));
  1435. if ($file_data !== NULL) {
  1436. $getID3 = new getID3;
  1437. if ($file_data->type == 'url') {
  1438. $filename = substr($file_data->name, strrpos ($file_data->name, '/')+1);
  1439. $sermonUploadDir = SB_ABSPATH.sb_get_option('upload_dir');
  1440. $tempfilename = $sermonUploadDir.preg_replace('/([ ])/e', 'chr(rand(97,122))', ' ').'.mp3';
  1441. if ($tempfile = @fopen($tempfilename, 'wb'))
  1442. if ($remote_file = @fopen($file_data->name, 'r')) {
  1443. $remote_contents = '';
  1444. while (!feof($remote_file)) {
  1445. $remote_contents .= fread($remote_file, 8192);
  1446. if (strlen($remote_contents) > 65536)
  1447. break;
  1448. }
  1449. fwrite($tempfile, $remote_contents);
  1450. fclose($remote_file);
  1451. fclose($tempfile);
  1452. $id3_raw_tags = $getID3->analyze(realpath($tempfilename));
  1453. unlink ($tempfilename);
  1454. }
  1455. } else {
  1456. $filename = $file_data->name;
  1457. $id3_raw_tags = $getID3->analyze(realpath(SB_ABSPATH.sb_get_option('upload_dir').$filename));
  1458. }
  1459. if (!isset($id3_raw_tags['tags'])) {
  1460. echo '<div id="message" class="updated fade"><p><b>'.__('No ID3 tags found.', $sermon_domain);
  1461. if ($file_data->type == 'url')
  1462. echo ' Remote files must have id3v2 tags.';
  1463. echo '</b></div>';
  1464. }
  1465. getid3_lib::CopyTagsToComments($id3_raw_tags);
  1466. if (sb_get_option ('import_title'))
  1467. $id3_tags['title'] = @$id3_raw_tags['comments_html']['title'][0];
  1468. if (sb_get_option ('import_comments'))
  1469. $id3_tags['description'] = @$id3_raw_tags['comments_html']['comments'][0];
  1470. if (sb_get_option ('import_album')) {
  1471. $id3_tags['series'] = @$id3_raw_tags['comments_html']['album'][0];
  1472. if ($id3_tags['series'] != '') {
  1473. $series_id = $wpdb->get_var("SELECT id FROM {$wpdb->prefix}sb_series WHERE name LIKE '{$id3_tags['series']}'");
  1474. if ($series_id === NULL) {
  1475. $wpdb->query("INSERT INTO {$wpdb->prefix}sb_series VALUES (null, '{$id3_tags['series']}', '0')");
  1476. $series_id = $wpdb->insert_id;
  1477. }
  1478. $id3_tags['series'] = $series_id;
  1479. }
  1480. }
  1481. if (sb_get_option ('import_artist')) {
  1482. $id3_tags['preacher'] = @$id3_raw_tags['comments_html']['artist'][0];
  1483. if ($id3_tags['preacher'] != '') {
  1484. $preacher_id = $wpdb->get_var("SELECT id FROM {$wpdb->prefix}sb_preachers WHERE name LIKE '{$id3_tags['preacher']}'");
  1485. if ($preacher_id === NULL) {
  1486. $wpdb->query("INSERT INTO {$wpdb->prefix}sb_preachers VALUES (null, '{$id3_tags['preacher']}', '', '')");
  1487. $preacher_id = $wpdb->insert_id;
  1488. }
  1489. $id3_tags['preacher'] = $preacher_id;
  1490. }
  1491. }
  1492. $date_format = sb_get_option('import_filename');
  1493. if ($date_format != '') {
  1494. $filename = substr($filename, 0, strrpos($filename, '.'));
  1495. $filename = str_replace ('--', '-', str_replace ('/', '-', $filename));
  1496. $filename = trim(ereg_replace('[^0-9-]', '', $filename), '-');
  1497. $date = explode('-', $filename, 3);
  1498. $id3_tags['date'] = '';
  1499. if (count($date) >= 3) {
  1500. if ($date_format == 'uk')
  1501. $id3_tags['date'] = date ('Y-m-d', mktime(0, 0, 0, $date[1], $date[0], $date[2]));
  1502. elseif ($date_format == 'us')
  1503. $id3_tags['date'] = date ('Y-m-d', mktime(0, 0, 0, $date[0], $date[1], $date[2]));
  1504. elseif ($date_format == 'int')
  1505. $id3_tags['date'] = date ('Y-m-d', mktime(0, 0, 0, $date[1], $date[2], $date[0]));
  1506. }
  1507. }
  1508. }
  1509. }
  1510. // load existing data
  1511. $preachers = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_preachers ORDER BY name asc");
  1512. $services = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_services ORDER BY name asc");
  1513. $series = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_series ORDER BY name asc");
  1514. $files = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_stuff WHERE sermon_id = 0 AND type = 'file' ORDER BY name asc");
  1515. // sync
  1516. $wanted[] = -1;
  1517. foreach ((array) $files as $k => $file) {
  1518. if (!file_exists(SB_ABSPATH.sb_get_option('upload_dir').$file->name)) {
  1519. $wanted[] = $file->id;
  1520. unset($files[$k]);
  1521. }
  1522. }
  1523. foreach ($services as $service) {
  1524. $serviceId[] = $service->id;
  1525. $deftime[] = $service->time;
  1526. }
  1527. $timeArr = '';
  1528. for ($lol = 0; $lol < count($serviceId); $lol++) {
  1529. $timeArr .= "timeArr[{$serviceId[$lol]}] = '$deftime[$lol]';";
  1530. }
  1531. if (isset($_GET['mid'])) {
  1532. $mid = (int) $_GET['mid'];
  1533. $curSermon = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}sb_sermons WHERE id = $mid");
  1534. $files = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_stuff WHERE sermon_id IN (0, $mid) AND type = 'file' ORDER BY name asc");
  1535. $startArr = unserialize($curSermon->start);
  1536. $endArr = unserialize($curSermon->end);
  1537. $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 = $mid ORDER BY t.name asc");
  1538. $tags = array();
  1539. foreach ($rawtags as $tag) {
  1540. $tags[] = $tag->name;
  1541. }
  1542. $tags = implode(', ', (array) $tags);
  1543. } else
  1544. $startArr = $endArr = array();
  1545. $books = sb_get_bible_books();
  1546. ?>
  1547. <script type="text/javascript">
  1548. var timeArr = new Array();
  1549. <?php echo $timeArr ?>
  1550. function createNewPreacher(s) {
  1551. if (jQuery('#preacher')[0].value != 'newPreacher') return;
  1552. var p = prompt("<?php _e("New preacher's name?", $sermon_domain)?>", "<?php _e("Preacher's name", $sermon_domain)?>");
  1553. if (p != null) {
  1554. jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/sermon.php'); ?>', {pname: p, sermon: 1}, function(r) {
  1555. if (r) {
  1556. jQuery('#preacher option:first').before('<option value="' + r + '">' + p + '</option>');
  1557. jQuery("#preacher option[value='" + r + "']").attr('selected', 'selected');
  1558. };
  1559. });
  1560. }
  1561. }
  1562. function createNewService(s) {
  1563. if (jQuery('#service')[0].value != 'newService') {
  1564. if (!jQuery('#override')[0].checked) {
  1565. jQuery('#time').val(timeArr[jQuery('#service')[0].value]).attr('disabled', 'disabled');
  1566. }
  1567. return;
  1568. }
  1569. var s = 'lol';
  1570. while ((s.indexOf('@') == -1) || (s.match(/(.*?)@(.*)/)[2].match(/[0-9]{1,2}:[0-9]{1,2}/) == null)) {
  1571. s = prompt("<?php _e("New service's name @ default time?", $sermon_domain)?>", "<?php _e("Service's name @ 18:00", $sermon_domain)?>");
  1572. if (s == null) { break; }
  1573. }
  1574. if (s != null) {
  1575. jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/sermon.php'); ?>', {sname: s, sermon: 1}, function(r) {
  1576. if (r) {
  1577. jQuery('#service option:first').before('<option value="' + r + '">' + s.match(/(.*?)@/)[1] + '</option>');
  1578. jQuery("#service option[value='" + r + "']").attr('selected', 'selected');
  1579. jQuery('#time').val(s.match(/(.*?)@\s*(.*)/)[2]);
  1580. };
  1581. });
  1582. }
  1583. }
  1584. function createNewSeries(s) {
  1585. if (jQuery('#series')[0].value != 'newSeries') return;
  1586. var ss = prompt("<?php _e("New series' name?", $sermon_domain)?>", "<?php _e("Series' name", $sermon_domain)?>");
  1587. if (ss != null) {
  1588. jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/sermon.php'); ?>', {ssname: ss, sermon: 1}, function(r) {
  1589. if (r) {
  1590. jQuery('#series option:first').before('<option value="' + r + '">' + ss + '</option>');
  1591. jQuery("#series option[value='" + r + "']").attr('selected', 'selected');
  1592. };
  1593. });
  1594. }
  1595. }
  1596. function addPassage() {
  1597. var p = jQuery('#passage').clone();
  1598. p.attr('id', 'passage' + gpid);
  1599. jQuery('tr:first td:first', p).prepend('[<a href="javascript:removePassage(' + gpid++ + ')">x</a>] ');
  1600. jQuery("input", p).attr('value', '');
  1601. jQuery('.passage:last').after(p);
  1602. }
  1603. function removePassage(id) {
  1604. jQuery('#passage' + id).remove();
  1605. }
  1606. function syncBook(s) {
  1607. if (jQuery('#endbook')[0].value != "") return;
  1608. var slc = jQuery('#startbook')[0].value;
  1609. jQuery('.passage').each(function(i) {
  1610. if (this == jQuery(s).parents('.passage')[0]) {
  1611. jQuery('.end').each(function(j) {
  1612. if (i == j) {
  1613. jQuery("option[value='" + slc + "']", this).attr('selected', 'selected');
  1614. }
  1615. });
  1616. }
  1617. });
  1618. }
  1619. function addFile() {
  1620. var f = jQuery('#choosefile').clone();
  1621. f.attr('id', 'choose' + gfid);
  1622. jQuery(".choosefile", f).attr('name', 'choose' + gfid);
  1623. jQuery("td", f).css('display', 'none');
  1624. jQuery("td:first", f).css('display', '');
  1625. jQuery('th', f).prepend('[<a href="javascript:removeFile(' + gfid++ + ')">x</a>] ');
  1626. jQuery("option[value='0']", f).attr('selected', 'selected');
  1627. jQuery("input", f).val('');
  1628. jQuery('.choose:last').after(f);
  1629. }
  1630. function removeFile(id) {
  1631. jQuery('#choose' + id).remove();
  1632. }
  1633. function doOverride(id) {
  1634. var chk = jQuery('#override')[0].checked;
  1635. if (chk) {
  1636. jQuery('#time').removeClass('gray').attr('disabled', false);
  1637. } else {
  1638. jQuery('#time').addClass('gray').val(timeArr[jQuery('#service')[0].value]).attr('disabled', 'disabled');
  1639. }
  1640. }
  1641. var gfid = 0;
  1642. var gpid = 0;
  1643. function chooseType(id, type){
  1644. jQuery("#"+id + " td").css("display", "none");
  1645. jQuery("#"+id + " ."+type).css("display", "");
  1646. jQuery("#"+id + " td input").val('');
  1647. jQuery("#"+id + " td select").val('0');
  1648. }
  1649. </script>
  1650. <?php sb_do_alerts(); ?>
  1651. <div class="wrap">
  1652. <a href="http://www.sermonbrowser.com/"><img src="<?php echo SB_PLUGIN_URL; ?>/sb-includes/logo-small.png" width="191" height ="35" style="margin: 1em 2em; float: right; background: #f9f9f9;" /></a>
  1653. <h2><?php echo isset($_GET['mid']) ? 'Edit Sermon' : 'Add Sermon' ?></h2>
  1654. <?php if (!isset($_GET['mid']) && !isset($_GET['getid3']) && sb_get_option('import_prompt')) {
  1655. if (!sb_import_options_set()) {
  1656. echo '<p class="plugin-update">';
  1657. sb_print_import_options_message(true);
  1658. echo "</p>\n";
  1659. } else {
  1660. sb_print_upload_form();
  1661. }
  1662. } ?>
  1663. <br/>
  1664. <form method="post" enctype="multipart/form-data">
  1665. <fieldset>
  1666. <table class="widefat">
  1667. <thead>
  1668. <tr>
  1669. <th scope="col" colspan="2"><?php _e('Enter sermon details', $sermon_domain) ?></th>
  1670. </tr>
  1671. </thead>
  1672. <tr>
  1673. <td>
  1674. <strong><?php _e('Title', $sermon_domain) ?></strong>
  1675. <div>
  1676. <input type="text" value="<?php if (isset($id3_tags['title'])) echo $id3_tags['title']; elseif (isset($curSermon->title)) echo htmlspecialchars(stripslashes($curSermon->title)); ?>" name="title" size="60" style="width:400px;" />
  1677. </div>
  1678. </td>
  1679. <td>
  1680. <strong><?php _e('Tags (comma separated)', $sermon_domain) ?></strong>
  1681. <div>
  1682. <input type="text" name="tags" value="<?php echo isset($tags) ? stripslashes($tags) : ''?>" style="width:400px" />
  1683. </div>
  1684. </td>
  1685. </tr>
  1686. <tr>
  1687. <td>
  1688. <strong><?php _e('Preacher', $sermon_domain) ?></strong><br/>
  1689. <select id="preacher" name="preacher" onchange="createNewPreacher(this)">
  1690. <?php if (count($preachers) == 0): ?>
  1691. <option value="" selected="selected"></option>
  1692. <?php else: ?>
  1693. <?php foreach ($preachers as $preacher):
  1694. if (isset($id3_tags['preacher']))
  1695. $preacher_id = $id3_tags['preacher'];
  1696. elseif (isset ($curSermon->preacher_id))
  1697. $preacher_id = $curSermon->preacher_id;
  1698. else
  1699. $preacher_id = -1; ?>
  1700. <option value="<?php echo $preacher->id ?>" <?php echo $preacher->id == $preacher_id ? 'selected="selected"' : ''?>><?php echo htmlspecialchars(stripslashes($preacher->name), ENT_QUOTES) ?></option>
  1701. <?php endforeach ?>
  1702. <?php endif ?>
  1703. <option value="newPreacher"><?php _e('Create new preacher', $sermon_domain) ?></option>
  1704. </select>
  1705. </td>
  1706. <td>
  1707. <strong><?php _e('Series', $sermon_domain) ?></strong><br/>
  1708. <select id="series" name="series" onchange="createNewSeries(this)">
  1709. <?php if (count($series) == 0): ?>
  1710. <option value="" selected="selected"></option>
  1711. <?php else: ?>
  1712. <?php foreach ($series as $item):
  1713. if (isset($id3_tags['series']))
  1714. $series_id = $id3_tags['series'];
  1715. elseif (isset($curSermon->series_id))
  1716. $series_id = $curSermon->series_id;
  1717. else
  1718. $series_id = -1; ?>
  1719. <option value="<?php echo $item->id ?>" <?php echo $item->id == $series_id ? 'selected="selected"' : '' ?>><?php echo htmlspecialchars(stripslashes($item->name), ENT_QUOTES) ?></option>
  1720. <?php endforeach ?>
  1721. <?php endif ?>
  1722. <option value="newSeries"><?php _e('Create new series', $sermon_domain) ?></option>
  1723. </select>
  1724. </td>
  1725. </tr>
  1726. <tr>
  1727. <td style="overflow: visible">
  1728. <strong><?php _e('Date', $sermon_domain) ?></strong> (yyyy-mm-dd)
  1729. <div>
  1730. <input type="text" id="date" name="date" value="<?php if ((isset($curSermon->datetime) && $curSermon->datetime != '1970-01-01 00:00:00') || isset($id3_tags['date'])) echo isset($id3_tags['date']) ? $id3_tags['date'] : substr(stripslashes($curSermon->datetime),0,10) ?>" />
  1731. </div>
  1732. </td>
  1733. <td rowspan="3">
  1734. <strong><?php _e('Description', $sermon_domain) ?></strong>
  1735. <div>
  1736. <?php if (isset($id3_tags['description']))
  1737. $desc = $id3_tags['description'];
  1738. elseif (isset($curSermon->description))
  1739. $desc = stripslashes($curSermon->description);
  1740. else
  1741. $desc = ''; ?>
  1742. <textarea name="description" cols="50" rows="7"><?php echo $desc; ?></textarea>
  1743. </div>
  1744. </td>
  1745. </tr>
  1746. <tr>
  1747. <td>
  1748. <strong><?php _e('Service', $sermon_domain) ?></strong><br/>
  1749. <select id="service" name="service" onchange="createNewService(this)">
  1750. <?php if (count($services) == 0): ?>
  1751. <option value="" selected="selected"></option>
  1752. <?php else: ?>
  1753. <?php foreach ($services as $service): ?>
  1754. <option value="<?php echo $service->id ?>" <?php echo (isset($curSermon->service_id) && $service->id == $curSermon->service_id) ? 'selected="selected"' : '' ?>><?php echo htmlspecialchars(stripslashes($service->name), ENT_QUOTES) ?></option>
  1755. <?php endforeach ?>
  1756. <?php endif ?>
  1757. <option value="newService"><?php _e('Create new service', $sermon_domain) ?></option>
  1758. </select>
  1759. </td>
  1760. </tr>
  1761. <tr>
  1762. <td>
  1763. <strong><?php _e('Time', $sermon_domain) ?></strong>
  1764. <div>
  1765. <input type="text" name="time" value="<?php echo isset($curSermon->time) ? $curSermon->time : ''?>" id="time" <?php echo isset($curSermon->override) && $curSermon->override ? '' : 'disabled="disabled" class="gray"' ?> />
  1766. <input type="checkbox" name="override" style="width:30px" id="override" onchange="doOverride()" <?php echo isset($curSermon->override) && $curSermon->override ? 'checked="checked"' : ''?>> <?php _e('Override default time', $sermon_domain) ?>
  1767. </div>
  1768. </td>
  1769. </tr>
  1770. <tr>
  1771. <td colspan="2">
  1772. <strong><?php _e('Bible passage', $sermon_domain) ?></strong> (<a href="javascript:addPassage()"><?php _e('add more', $sermon_domain) ?></a>)
  1773. </td>
  1774. </tr>
  1775. <tr>
  1776. <td><?php _e('From', $sermon_domain) ?></td>
  1777. <td><?php _e('To', $sermon_domain) ?></td>
  1778. </tr>
  1779. <tr id="passage" class="passage">
  1780. <td>
  1781. <table>
  1782. <tr>
  1783. <td>
  1784. <select id="startbook" name="start[book][]" onchange="syncBook(this)" class="start1">
  1785. <option value=""></option>
  1786. <?php foreach ($books as $book): ?>
  1787. <option value="<?php echo $book ?>"><?php echo $book ?></option>
  1788. <?php endforeach ?>
  1789. </select>
  1790. </td>
  1791. <td><input type="text" style="width:60px;" name="start[chapter][]" value="" class="start2" /><br /></td>
  1792. <td><input type="text" style="width:60px;" name="start[verse][]" value="" class="start3" /><br /></td>
  1793. </tr>
  1794. </table>
  1795. </td>
  1796. <td>
  1797. <table>
  1798. <tr>
  1799. <td>
  1800. <select id="endbook" name="end[book][]" class="end">
  1801. <option value=""></option>
  1802. <?php foreach ($books as $book): ?>
  1803. <option value="<?php echo $book ?>"><?php echo $book ?></option>
  1804. <?php endforeach ?>
  1805. </select>
  1806. </td>
  1807. <td><input type="text" style="width:60px;" name="end[chapter][]" value="" class="end2" /><br /></td>
  1808. <td><input type="text" style="width:60px;" name="end[verse][]" value="" class="end3" /><br /></td>
  1809. </tr>
  1810. </table>
  1811. </td>
  1812. </tr>
  1813. <tr>
  1814. <td colspan="2">
  1815. <strong><?php _e('Attachments', $sermon_domain) ?></strong> (<a href="javascript:addFile()"><?php _e('add more', $sermon_domain) ?></a>)
  1816. </td>
  1817. </tr>
  1818. <tr >
  1819. <td colspan="2">
  1820. <table>
  1821. <tr id="choosefile" class="choose">
  1822. <th scope="row" style="padding:3px 7px">
  1823. <select class="choosefile" name="choosefile" onchange="chooseType(this.name, this.value);">
  1824. <option value="filelist"><?php _e('Choose existing file:', $sermon_domain) ?></option>
  1825. <option value="newupload"><?php _e('Upload a new one:', $sermon_domain) ?></option>
  1826. <option value="newurl"><?php _e('Enter an URL:', $sermon_domain) ?></option>
  1827. <option value="newcode"><?php _e('Enter embed or shortcode:', $sermon_domain) ?></option>
  1828. </select>
  1829. </th>
  1830. <td class="filelist">
  1831. <select id="file" name="file[]">
  1832. <?php echo count($files) == 0 ? '<option value="0">No files found</option>' : '<option value="0"></option>' ?>
  1833. <?php foreach ($files as $file): ?>
  1834. <option value="<?php echo $file->id ?>"><?php echo $file->name ?></option>
  1835. <?php endforeach ?>
  1836. </select>
  1837. </td>
  1838. <td class="newupload" style="display:none"><input type="file" size="50" name="upload[]"/></td>
  1839. <td class="newurl" style="display:none"><input type="text" size="50" name="url[]"/></td>
  1840. <td class="newcode" style="display:none"><input type="text" size="92" name="code[]"/></td>
  1841. </tr>
  1842. </table>
  1843. </td>
  1844. </tr>
  1845. </table>
  1846. </fieldset>
  1847. <p class="submit"><input type="submit" name="save" value="<?php _e('Save', $sermon_domain) ?> &raquo;" /></p>
  1848. </form>
  1849. </div>
  1850. <script type="text/javascript">
  1851. jQuery.datePicker.setDateFormat('ymd','-');
  1852. jQuery('#date').datePicker({startDate:'01/01/1970'});
  1853. <?php if (empty($curSermon->time)): ?>
  1854. jQuery('#time').val(timeArr[jQuery('*[selected]', jQuery("select[name='service']")).attr('value')]);
  1855. <?php endif ?>
  1856. <?php if (isset($mid) | (isset($filename) && $filename != '')): ?>
  1857. stuff = new Array();
  1858. type = new Array();
  1859. start1 = new Array();
  1860. start2 = new Array();
  1861. start3 = new Array();
  1862. end1 = new Array();
  1863. end2 = new Array();
  1864. end3 = new Array();
  1865. <?php
  1866. if (isset($mid)) {
  1867. $assocFiles = $wpdb->get_results("SELECT id FROM {$wpdb->prefix}sb_stuff WHERE sermon_id = {$mid} AND type = 'file' ORDER BY name asc;");
  1868. $assocURLs = $wpdb->get_results("SELECT name FROM {$wpdb->prefix}sb_stuff WHERE sermon_id = {$mid} AND type = 'url' ORDER BY name asc;");
  1869. $assocCode = $wpdb->get_results("SELECT name FROM {$wpdb->prefix}sb_stuff WHERE sermon_id = {$mid} AND type = 'code' ORDER BY name asc;");
  1870. }
  1871. else
  1872. $assocFiles = $assocURLs = $assocCode = array();
  1873. $r = false;
  1874. if (isset($filename) && $filename != '')
  1875. if ($file_data->type == 'url')
  1876. $assocURLs[]->name = $file_data->name;
  1877. else
  1878. $assocFiles[]->id = $_GET['getid3'];
  1879. ?>
  1880. <?php for ($lolz = 0; $lolz < count($assocFiles); $lolz++): ?>
  1881. <?php $r = true ?>
  1882. addFile();
  1883. stuff.push(<?php echo $assocFiles[$lolz]->id ?>);
  1884. type.push('file');
  1885. <?php endfor ?>
  1886. <?php for ($lolz = 0; $lolz < count($assocURLs); $lolz++): ?>
  1887. <?php $r = true ?>
  1888. addFile();
  1889. stuff.push('<?php echo $assocURLs[$lolz]->name ?>');
  1890. type.push('url');
  1891. <?php endfor ?>
  1892. <?php for ($lolz = 0; $lolz < count($assocCode); $lolz++): ?>
  1893. <?php $r = true ?>
  1894. addFile();
  1895. stuff.push('<?php echo $assocCode[$lolz]->name ?>');
  1896. type.push('code');
  1897. <?php endfor ?>
  1898. <?php if ($r): ?>
  1899. jQuery('.choose:last').remove();
  1900. <?php endif ?>
  1901. <?php for ($lolz = 0; $lolz < count($startArr); $lolz++): ?>
  1902. <?php if ($lolz != 0): ?>
  1903. addPassage();
  1904. <?php endif ?>
  1905. start1.push("<?php echo $startArr[$lolz]['book'] ?>");
  1906. start2.push("<?php echo $startArr[$lolz]['chapter'] ?>");
  1907. start3.push("<?php echo $startArr[$lolz]['verse'] ?>");
  1908. end1.push("<?php echo $endArr[$lolz]['book'] ?>");
  1909. end2.push("<?php echo $endArr[$lolz]['chapter'] ?>");
  1910. end3.push("<?php echo $endArr[$lolz]['verse'] ?>");
  1911. <?php endfor ?>
  1912. jQuery('.choose').each(function(i) {
  1913. switch (type[i]) {
  1914. case 'file':
  1915. jQuery("option[value='filelist']", this).attr('selected', 'selected');
  1916. jQuery('.filelist', this).css('display','');
  1917. jQuery("option[value='" + stuff[i] + "']", this).attr('selected', 'selected');
  1918. break;
  1919. case 'url':
  1920. jQuery('td', this).css('display', 'none');
  1921. jQuery("option[value='newurl']", this).attr('selected', 'selected');
  1922. jQuery('.newurl ', this).css('display','');
  1923. jQuery(".newurl input", this).val(stuff[i]);
  1924. break;
  1925. case 'code':
  1926. jQuery('td', this).css('display', 'none');
  1927. jQuery("option[value='newcode']", this).attr('selected', 'selected');
  1928. jQuery('.newcode', this).css('display','');
  1929. jQuery(".newcode input", this).val(Base64.decode(stuff[i]));
  1930. break;
  1931. }
  1932. });
  1933. jQuery('.start1').each(function(i) {
  1934. jQuery("option[value='" + start1[i] + "']", this).attr('selected', 'selected');
  1935. });
  1936. jQuery('.end').each(function(i) {
  1937. jQuery("option[value='" + end1[i] + "']", this).attr('selected', 'selected');
  1938. });
  1939. jQuery('.start2').each(function(i) {
  1940. jQuery(this).val(start2[i]);
  1941. });
  1942. jQuery('.start3').each(function(i) {
  1943. jQuery(this).val(start3[i]);
  1944. });
  1945. jQuery('.end2').each(function(i) {
  1946. jQuery(this).val(end2[i]);
  1947. });
  1948. jQuery('.end3').each(function(i) {
  1949. jQuery(this).val(end3[i]);
  1950. });
  1951. <?php endif ?>
  1952. </script>
  1953. <?php
  1954. }
  1955. /**
  1956. * Displays the help page
  1957. */
  1958. function sb_help() {
  1959. global $sermon_domain;
  1960. sb_do_alerts();
  1961. ?>
  1962. <div class="wrap">
  1963. <a href="http://www.sermonbrowser.com/"><img src="<?php echo SB_PLUGIN_URL; ?>/sb-includes/logo-small.png" width="191" height ="35" style="margin: 1em 2em; float: right; background: #f9f9f9;" /></a>
  1964. <div style="width:45%;float:right;clear:right">
  1965. <h2>Thank you</h2>
  1966. <p>A number of individuals and churches have kindly <a href="http://www.sermonbrowser.com/donate/">donated</a> to the development of Sermon Browser. Their support is very much appreciated. Since April 2011, all donations have been sent to <a href="<?php echo admin_url('admin.php?page=sermon-browser/japan.php')?>">support the ministry of Nathanael and Anna Ayling</a> in Japan.</p>
  1967. <ul style="list-style-type:circle; margin-left: 2em">
  1968. <li><a href="http://www.cambray.org/" target="_blank">Cambray Baptist Church</a>, UK</li>
  1969. <li><a href="http://www.bethel-clydach.co.uk/" target="_blank">Bethel Baptist Church</a>, Clydach, UK</li>
  1970. <li><a href="http://www.bethel-laleston.co.uk/" target="_blank">Bethel Baptist Church</a>, Laleston, UK</li>
  1971. <li><a href="http://www.hessonchurch.com/" target="_blank">Hesson Christian Fellowship</a>, Ontario, Canada</li>
  1972. <li><a href="http://www.icvineyard.org/" target="_blank">Vineyard Community Church</a>, Iowa</li>
  1973. <li><a href="http://www.cbcsd.us/" target="_blank">Chinese Bible Church of San Diego</a>, California</li>
  1974. <li><a href="http://thecreekside.org/" target="_blank">Creekside Community Church</a>, Texas</li>
  1975. <li><a href="http://stluke.info/" target="_blank">St. Luke Lutheran Church, Gales Ferry</a>, Connecticut</li>
  1976. <li><a href="http://www.bunnbaptistchurch.org/" target="_blank">Bunn Baptist Church</a>, North Carolina</li>
  1977. <li><a href="http://www.ccpconline.org" target="_blank">Christ Community Presbyterian Church</a>, Florida</li>
  1978. <li><a href="http://www.harborhawaii.org" target="_blank">Harbor Church</a>, Hawaii</li>
  1979. <li>Vicky H, UK</li>
  1980. <li>Ben S, UK</li>
  1981. <li>Tom W, UK</li>
  1982. <li>Gavin D, UK</li>
  1983. <li>Douglas C, UK</li>
  1984. <li>David A, UK</li>
  1985. <li>Thomas C, Canada</li>
  1986. <li>Daniel J, Germany</li>
  1987. <li>Hiromi O, Japan</li>
  1988. <li>David C, Australia</li>
  1989. <li>Lou B, Australia</li>
  1990. <li>Edward P, Delaware</li>
  1991. <li>Steve J, Pensylvania</li>
  1992. <li>William H, Indiana</li>
  1993. <li>Brandon E, New Jersey</li>
  1994. <li>Jamon A, Missouri</li>
  1995. <li>Chuck H, Tennessee</li>
  1996. <li>David F, Maryland</li>
  1997. <li>Antony L, California</li>
  1998. <li>David W, Florida</li>
  1999. <li>Fabio P, Connecticut</li>
  2000. <li>Bill C, Georgia</li>
  2001. <li>Scott J, Florida</li>
  2002. <li><a href="http://www.emw.org.uk/" target="_blank">Evangelical Movement of Wales</a>, UK</li>
  2003. <li><a href="http://BetterCommunication.org" target="_blank">BetterCommunication.org</a></li>
  2004. <li>Home and Outdoor Living, Indiana</li>
  2005. <li><a href="http://design.ddandhservices.com/" target="_blank">DD&H Services</a>, British Columbia</li>
  2006. <li><a href="http://www.dirtroadphotography.com" target="_blank">Dirt Road Photography</a>, Nebraska</li>
  2007. <li><a href="http://www.hardeysolutions.com/" target="_blank">Hardey Solutions</a>, Houston</li>
  2008. <li><a href="http://www.olivetreehost.com/" target="_blank">Olivetreehost.com</a></li>
  2009. <li><a href="http://www.onQsites.com/" target="_blank">onQsites</a>, South Carolina</li>
  2010. <li>Glorified Web Solutions</li>
  2011. </ul>
  2012. <p>Additional help was also received from:</p>
  2013. <ul style="list-style-type:circle; margin-left: 2em">
  2014. <li><a href="http://codeandmore.com/">Tien Do Xuan</a> (help with initial coding).
  2015. <li>James Hudson, Matthew Hiatt, Mark Bouchard (code contributions)</li>
  2016. <li>Juan Carlos and Marvin Ortega (Spanish translation)</li>
  2017. <li><a href="http://www.fatcow.com/">FatCow</a> (Russian translation)</li>
  2018. <li><a href="http://intercer.net/">Lucian Mihailescu</a> (Romanian translation)</li>
  2019. <li>Monika Gause (German translation)</li>
  2020. <li><a href="http://www.djio.com.br/sermonbrowser-em-portugues-brasileiro-pt_br/">DJIO</a> (Brazilian Portugese translation)</li>
  2021. <li>Numerous <a href="http://www.sermonbrowser.com/forum/">forum contributors</a> for feature suggestions and bug reports</li>
  2022. </ul>
  2023. </div>
  2024. <div style="width:45%;float:left">
  2025. <h2><?php _e('Help page', $sermon_domain) ?></h2>
  2026. <h3>Screencasts</h3>
  2027. <p>If you need help with using SermonBrowser for the first time, these five minute screencast tutorials should be your first port of call (the tutorials were created with an older version of SermonBrowser, and an older version of Wordpress, but things haven't changed a great deal):</p>
  2028. <ul>
  2029. <li><a href="http://www.sermonbrowser.com/tutorials/#efe-swf-1" target="_blank">Installation and Overview</a></li>
  2030. <li><a href="http://www.sermonbrowser.com/tutorials/#efe-swf-2" target="_blank">Basic Options</a></li>
  2031. <li><a href="http://www.sermonbrowser.com/tutorials/#efe-swf-3" target="_blank">Preachers, Series and Services</a></li>
  2032. <li><a href="http://www.sermonbrowser.com/tutorials/#efe-swf-4" target="_blank">Entering a new sermon</a></li>
  2033. <li><a href="http://www.sermonbrowser.com/tutorials/#efe-swf-5" target="_blank">Editing a sermon and adding embedded video</a></li>
  2034. </ul>
  2035. <h3>Template tags</h3>
  2036. <p>If you want to change the way SermonBrowser displays on your website, you'll need to edit the templates and/or CSS file. Check out this guide to <a href="http://www.sermonbrowser.com/customisation/" target="_blank">template tags</a>.</p>
  2037. <h3>Shortcode</h3>
  2038. <p>You can put individual sermons or lists of sermons on any page of your website. You do this by adding a <a href="http://www.sermonbrowser.com/customisation/" target="_blank">shortcode</a> into a WordPress post or page.</p>
  2039. <h3>Frequently asked questions</h3>
  2040. <p>A <a href="http://www.sermonbrowser.com/faq/" target="_blank">comprehensive FAQ</a> is available on sermonbrowser.com.</p>
  2041. <h3>Further help</h3>
  2042. <p>If you have a problem that the FAQ doesn't answer, or you have a feature suggestion, please use the <a href="http://www.sermonbrowser.com/forum/" target="_blank">SermonBrowser forum</a>.</p>
  2043. </div>
  2044. </form>
  2045. <?php
  2046. }
  2047. function sb_japan() {
  2048. sb_do_alerts();
  2049. ?>
  2050. <div class="wrap">
  2051. <a href="hthttp://www.sermonbrowser.com/"><img src="<?php echo SB_PLUGIN_URL; ?>/sb-includes/logo-small.png" width="191" height ="35" style="margin: 1em 2em; float: right; background: #f9f9f9;" /></a>
  2052. <h2 style=>Help support Christian ministry in Japan</h2>
  2053. <div style="float:right;clear:both; width:208px; padding-left:20px">
  2054. <img src="http://www.bethel-clydach.co.uk/wp-content/uploads/2010/01/Nathanael-and-Anna-188x300.jpg" width="188" height="300" />
  2055. </div>
  2056. <div style="width:533px; float:left">
  2057. <iframe src="http://player.vimeo.com/video/19995544?title=0&amp;byline=0&amp;portrait=0" width="533" height="300" frameborder="0"></iframe>
  2058. </div>
  2059. <div style="margin-left:553px;">
  2060. <p>Since April 2011, all gifts donated to Sermon Browser have been given to support the work of <a href="http://www.bethel-clydach.co.uk/about/mission-partners/nathanael-and-anna-ayling/">Nathanael and Anna Ayling</a> in Japan.
  2061. Nathanael and Anna are members of a small church in the UK where the the author of Sermon Browser is a minister. Together with little Ethan, they have been in Japan since April 2010, and are based in Sappororo in the north,
  2062. undergoing intensive language training so that by God's grace they can work alongside Japanese Christians to make disciples of Jesus among Japanese students. They are being cared for by <a href="http://www.omf.org/omf/japan/about_us">OMF International</a> (formerly known as the China Inland Mission, and founded by
  2063. Hudson Taylor in 1865).</p>
  2064. <p>If you value Sermon Browser, please consider supporting Nathanael and Anna. You can do this by:</p>
  2065. <ul>
  2066. <li><a href="http://ateamjapan.wordpress.com/">Looking at their blog</a>, and praying about their latest news.</li>
  2067. <li><a href="http://www.omf.org/omf/uk/omf_at_work/pray_for_omf_workers">Signing up</a> to receiving their regular prayer news.</li>
  2068. <li><form style="float:left" action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_s-xclick" /><input type="hidden" name="hosted_button_id" value="YTB9ZW4P5F536" /><input type="image" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" /><img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/en_GB/i/scr/pixel.gif" width="1" height="1" /></form> towards their ongoing support.</li>
  2069. </ul>
  2070. </div>
  2071. </div>
  2072. <?php
  2073. }
  2074. /***************************************
  2075. ** Supplementary functions **
  2076. **************************************/
  2077. /**
  2078. * Displays alerts in admin for new users
  2079. */
  2080. function sb_do_alerts() {
  2081. global $wpdb, $sermon_domain;
  2082. if (stripos(sb_get_option('mp3_shortcode'), '%SERMONURL%') === FALSE) {
  2083. echo '<div id="message" class="updated fade"><p><b>';
  2084. _e('Error:</b> The MP3 shortcode must link to individual sermon files. You do this by including <span style="color:red">%SERMONURL%</span> in your shortcode (e.g. [audio:%SERMONURL%]). SermonBrowser will then replace %SERMONURL% with a link to each sermon.', $sermon_domain);
  2085. echo '</div>';
  2086. } elseif (do_shortcode(sb_get_option('mp3_shortcode')) == sb_get_option('mp3_shortcode')) {
  2087. if ((substr(sb_get_option('mp3_shortcode'), 0, 18) == '[audio:%SERMONURL%') && !function_exists('ap_insert_player_widgets')) {
  2088. if ($wpdb->get_var("SELECT COUNT(id) FROM {$wpdb->prefix}sb_stuff WHERE name LIKE '%.mp3'")>0)
  2089. echo '<div id="message" class="updated"><p><b>'.sprintf(__('Tip: Installing the %1$sWordpress Audio Player%2$s, or another Wordpress MP3 player plugin will allow users to listen to your sermons more easily.', $sermon_domain), '<a href="'.site_url().'/wp-admin/plugin-install.php?tab=search&s=audio%20player&type=term&search=Search">', '</a>').'</b></div>';
  2090. } elseif (substr(sb_get_option('mp3_shortcode'), 0, 18) != '[audio:%SERMONURL%') {
  2091. echo '<div id="message" class="updated fade"><p><b>';
  2092. _e('Error:</b> You have specified a custom MP3 shortcode, but Wordpress doesn&#146;t know how to interpret it. Make sure the shortcode is correct, and that the appropriate plugin is activated.', $sermon_domain);
  2093. echo '</div>';
  2094. }
  2095. }
  2096. if (sb_display_url() == "") {
  2097. echo '<div id="message" class="updated"><p><b>'.__('Hint:', $sermon_domain).'</b> '.sprintf(__('%sCreate a page%s that includes the shortcode [sermons], so that SermonBrowser knows where to display the sermons on your site.', $sermon_domain), '<a href="'.site_url().'/wp-admin/page-new.php">', '</a>').'</div>';
  2098. } else {
  2099. if (!function_exists('ap_insert_player_widgets')) {
  2100. }
  2101. }
  2102. }
  2103. /**
  2104. * Show the textarea input
  2105. */
  2106. function sb_build_textarea($name, $html) {
  2107. $out = '<textarea name="'.$name.'" cols="75" rows="20" style="width:100%">';
  2108. $out .= stripslashes(str_replace('\r\n', "\n", $html));
  2109. $out .= '</textarea>';
  2110. echo $out;
  2111. }
  2112. /**
  2113. * Displays stats in the dashboard
  2114. */
  2115. function sb_rightnow () {
  2116. global $wpdb, $sermon_domain;
  2117. $file_count = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."sb_stuff WHERE type='file'");
  2118. $output_string = '';
  2119. if ($file_count > 0) {
  2120. $sermon_count = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."sb_sermons");
  2121. $preacher_count = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."sb_preachers");
  2122. $series_count = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."sb_series");
  2123. $tag_count = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."sb_tags WHERE name<>''");
  2124. $download_count = $wpdb->get_var("SELECT SUM(count) FROM ".$wpdb->prefix."sb_stuff");
  2125. if ($sermon_count == 0) {
  2126. $download_average = 0;
  2127. } else {
  2128. $download_average = round($download_count/$sermon_count, 1);
  2129. }
  2130. $most_popular = $wpdb->get_results("SELECT title, sermon_id, sum(count) AS c FROM {$wpdb->prefix}sb_stuff LEFT JOIN {$wpdb->prefix}sb_sermons ON {$wpdb->prefix}sb_sermons.id = sermon_id GROUP BY sermon_id ORDER BY c DESC LIMIT 1");
  2131. $most_popular = $most_popular[0];
  2132. $output_string .= '<p class="youhave">'.__("You have")." ";
  2133. $output_string .= '<a href="'.site_url().'/wp-admin/admin.php?page=sermon-browser/files.php">';
  2134. $output_string .= sprintf(_n('%s file', '%s files', $file_count), number_format($file_count))."</a> ";
  2135. if ($sermon_count > 0) {
  2136. $output_string .= __("in")." ".'<a href="'.admin_url('admin.php?page=sermon-browser/sermon.php').'">';
  2137. $output_string .= sprintf(_n('%s sermon', '%s sermons', $sermon_count), number_format($sermon_count))."</a> ";
  2138. }
  2139. if ($preacher_count > 0) {
  2140. $output_string .= __("from")." ".'<a href="'.site_url().'/wp-admin/admin.php?page=sermon-browser/preachers.php">';
  2141. $output_string .= sprintf(_n('%s preacher', '%s preachers', $preacher_count), number_format($preacher_count))."</a> ";
  2142. }
  2143. if ($series_count > 0) {
  2144. $output_string .= __("in")." ".'<a href="'.site_url().'/wp-admin/admin.php?page=sermon-browser/manage.php">';
  2145. $output_string .= sprintf(__('%s series'), number_format($series_count))."</a> ";
  2146. }
  2147. if ($tag_count > 0)
  2148. $output_string .= __("using")." ".sprintf(_n('%s tag', '%s tags', $tag_count), number_format($tag_count))." ";
  2149. if (substr($output_string, -1) == " ")
  2150. $output_string = substr($output_string, 0, -1);
  2151. if ($download_count > 0)
  2152. $output_string .= ". ".sprintf(_n('Only one file has been downloaded', 'They have been downloaded a total of %s times', $download_count), number_format($download_count));
  2153. if ($download_count > 1) {
  2154. $output_string .= ", ".sprintf(_n('an average of once per sermon', 'an average of %d times per sermon', $download_average), $download_average);
  2155. $most_popular_title = '<a href="'.sb_display_url().sb_query_char(true).'sermon_id='.$most_popular->sermon_id.'">'.stripslashes($most_popular->title).'</a>';
  2156. $output_string .= ". ".sprintf(__('The most popular sermon is %s, which has been downloaded %s times'), $most_popular_title, number_format($most_popular->c));
  2157. }
  2158. $output_string .= '.</p>';
  2159. }
  2160. echo $output_string;
  2161. }
  2162. /**
  2163. * Find new files uploaded by FTP
  2164. */
  2165. function sb_scan_dir() {
  2166. global $wpdb;
  2167. $files = $wpdb->get_results("SELECT name FROM {$wpdb->prefix}sb_stuff WHERE type = 'file';");
  2168. $bnn = array();
  2169. $dir = SB_ABSPATH.sb_get_option('upload_dir');
  2170. foreach ($files as $file) {
  2171. $bnn[] = $file->name;
  2172. if (!file_exists($dir.$file->name)) {
  2173. $wpdb->query("DELETE FROM {$wpdb->prefix}sb_stuff WHERE name='".mysql_real_escape_string($file->name)."' AND sermon_id=0;");
  2174. }
  2175. }
  2176. if ($dh = @opendir($dir)) {
  2177. while (false !== ($file = readdir($dh))) {
  2178. if ($file != "." && $file != ".." && !is_dir($dir.$file) && !in_array($file, $bnn)) {
  2179. $file = mysql_real_escape_string($file);
  2180. $wpdb->query("INSERT INTO {$wpdb->prefix}sb_stuff VALUES (null, 'file', '{$file}', 0, 0, 0);");
  2181. }
  2182. }
  2183. closedir($dh);
  2184. }
  2185. }
  2186. /**
  2187. * Check to see if upload folder is writeable
  2188. *
  2189. * @return string 'writeable/unwriteable/notexist'
  2190. */
  2191. function sb_checkSermonUploadable($foldername = "") {
  2192. $sermonUploadDir = SB_ABSPATH.sb_get_option('upload_dir').$foldername;
  2193. if (is_dir($sermonUploadDir)) {
  2194. //Dir exist
  2195. $fp = @fopen($sermonUploadDir.'sermontest.txt', 'w');
  2196. if ($fp) {
  2197. //Delete this test file
  2198. fclose($fp);
  2199. unset($fp);
  2200. @unlink($sermonUploadDir.'sermontest.txt');
  2201. return 'writeable';
  2202. } else {
  2203. return 'unwriteable';
  2204. }
  2205. } else {
  2206. return 'notexist';
  2207. }
  2208. return false;
  2209. }
  2210. /**
  2211. * Delete any unused tags
  2212. */
  2213. function sb_delete_unused_tags() {
  2214. global $wpdb;
  2215. $unused_tags = $wpdb->get_results("SELECT {$wpdb->prefix}sb_tags.id AS id, {$wpdb->prefix}sb_sermons_tags.id AS sid FROM {$wpdb->prefix}sb_tags LEFT JOIN {$wpdb->prefix}sb_sermons_tags ON {$wpdb->prefix}sb_tags.id = {$wpdb->prefix}sb_sermons_tags.tag_id WHERE {$wpdb->prefix}sb_sermons_tags.tag_id IS NULL");
  2216. if (is_array($unused_tags))
  2217. foreach ($unused_tags AS $unused_tag)
  2218. $wpdb->query("DELETE FROM {$wpdb->prefix}sb_tags WHERE id='{$unused_tag->id}'");
  2219. }
  2220. /**
  2221. * Displays the main sermon widget options and handles changes
  2222. */
  2223. function sb_widget_sermon_control( $widget_args = 1 ) {
  2224. global $wpdb, $sermon_domain;
  2225. global $wp_registered_widgets;
  2226. static $updated = false;
  2227. $dpreachers = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_preachers ORDER BY id;");
  2228. $dseries = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_series ORDER BY id;");
  2229. $dservices = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_services ORDER BY id;");
  2230. if ( is_numeric($widget_args) )
  2231. $widget_args = array( 'number' => $widget_args );
  2232. $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
  2233. extract( $widget_args, EXTR_SKIP );
  2234. $options = sb_get_option('sermons_widget_options');
  2235. if ( !is_array($options) )
  2236. $options = array();
  2237. if ( !$updated && !empty($_POST['sidebar']) ) {
  2238. $sidebar = (string) $_POST['sidebar'];
  2239. $sidebars_widgets = wp_get_sidebars_widgets();
  2240. if ( isset($sidebars_widgets[$sidebar]) )
  2241. $this_sidebar =& $sidebars_widgets[$sidebar];
  2242. else
  2243. $this_sidebar = array();
  2244. foreach ( $this_sidebar as $_widget_id ) {
  2245. if ( 'sb_widget_sermon' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
  2246. $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
  2247. if ( !in_array( "sermon-$widget_number", $_POST['widget-id'] ) )
  2248. unset($options[$widget_number]);
  2249. }
  2250. }
  2251. foreach ( (array) $_POST['widget-sermon'] as $widget_number => $widget_sermon_instance ) {
  2252. if ( !isset($widget_sermon_instance['limit']) && isset($options[$widget_number]) )
  2253. continue;
  2254. $limit = wp_specialchars( $widget_sermon_instance['limit'] );
  2255. $preacherz = (int) $widget_sermon_instance['preacherz'];
  2256. $preacher = (int) $widget_sermon_instance['preacher'];
  2257. $service = (int) $widget_sermon_instance['service'];
  2258. $series = (int) $widget_sermon_instance['series'];
  2259. $book = (int) $widget_sermon_instance['book'];
  2260. $title = strip_tags(stripslashes($widget_sermon_instance['title']));
  2261. $date = (int) $widget_sermon_instance['date'];
  2262. $player = (int) $widget_sermon_instance['player'];
  2263. $options[$widget_number] = array( 'limit' => $limit, 'preacherz' => $preacherz, 'book' => $book, 'preacher' => $preacher, 'service' => $service, 'series' => $series, 'title' => $title, 'date' => $date, 'player' => $player);
  2264. }
  2265. sb_update_option('sermons_widget_options', $options);
  2266. $updated = true;
  2267. }
  2268. // Display widget form
  2269. if ( -1 == $number ) {
  2270. $limit = '';
  2271. $preacherz = 0;
  2272. $book = 0;
  2273. $number = '%i%';
  2274. $preacher = '';
  2275. $service = '';
  2276. $series = '';
  2277. $title ='';
  2278. $date = '';
  2279. $player = '';
  2280. } else {
  2281. $limit = attribute_escape($options[$number]['limit']);
  2282. $preacher = attribute_escape($options[$number]['preacher']);
  2283. $service = attribute_escape($options[$number]['service']);
  2284. $series = attribute_escape($options[$number]['series']);
  2285. $preacherz = (int) $options[$number]['preacherz'];
  2286. $book = (int) $options[$number]['book'];
  2287. $title = attribute_escape($options[$number]['title']);
  2288. $date = (int) $options[$number]['date'];
  2289. $player = attribute_escape($options[$number]['player']);
  2290. }
  2291. ?>
  2292. <p><?php _e('Title:'); ?> <input class="widefat" id="widget-sermon-title" name="widget-sermon[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" /></p>
  2293. <p>
  2294. <?php _e('Number of sermons: ', $sermon_domain) ?><input class="widefat" id="widget-sermon-limit-<?php echo $number; ?>" name="widget-sermon[<?php echo $number; ?>][limit]" type="text" value="<?php echo $limit; ?>" />
  2295. <hr />
  2296. <input type="checkbox" id="widget-sermon-preacherz-<?php echo $number ?>" name="widget-sermon[<?php echo $number ?>][preacherz]" <?php echo $preacherz ? 'checked=checked' : '' ?> value="1"> <?php _e('Display preacher', $sermon_domain) ?><br />
  2297. <input type="checkbox" id="widget-sermon-book-<?php echo $number ?>" name="widget-sermon[<?php echo $number ?>][book]" <?php echo $book ? 'checked=checked' : '' ?> value="1"> <?php _e('Display bible passage', $sermon_domain) ?><br />
  2298. <input type="checkbox" id="widget-sermon-date-<?php echo $number ?>" name="widget-sermon[<?php echo $number ?>][date]" <?php echo $date ? 'checked=checked' : '' ?> value="1"> <?php _e('Display date', $sermon_domain) ?><br />
  2299. <input type="checkbox" id="widget-sermon-player-<?php echo $number ?>" name="widget-sermon[<?php echo $number ?>][player]" <?php echo $player ? 'checked=checked' : '' ?> value="1"> <?php _e('Display mini-player', $sermon_domain) ?>
  2300. <hr />
  2301. <table>
  2302. <tr>
  2303. <td><?php _e('Preacher: ', $sermon_domain) ?></td>
  2304. <td>
  2305. <select name="widget-sermon[<?php echo $number; ?>][preacher]" id="widget-sermon-preacher-<?php echo $number; ?>">
  2306. <option value="0" <?php echo $preacher ? '' : 'selected="selected"' ?>><?php _e('[All]', $sermon_domain) ?></option>
  2307. <?php foreach ($dpreachers as $cpreacher): ?>
  2308. <option value="<?php echo $cpreacher->id ?>" <?php echo $preacher == $cpreacher->id ? 'selected="selected"' : '' ?>><?php echo $cpreacher->name ?></option>
  2309. <?php endforeach ?>
  2310. </select>
  2311. </td>
  2312. </tr>
  2313. <tr>
  2314. <td><?php _e('Service: ', $sermon_domain) ?></td>
  2315. <td>
  2316. <select name="widget-sermon[<?php echo $number; ?>][service]" id="widget-sermon-service-<?php echo $number; ?>">
  2317. <option value="0" <?php echo $service ? '' : 'selected="selected"' ?>><?php _e('[All]', $sermon_domain) ?></option>
  2318. <?php foreach ($dservices as $cservice): ?>
  2319. <option value="<?php echo $cservice->id ?>" <?php echo $service == $cservice->id ? 'selected="selected"' : '' ?>><?php echo $cservice->name ?></option>
  2320. <?php endforeach ?>
  2321. </select>
  2322. </td>
  2323. </tr>
  2324. <tr>
  2325. <td><?php _e('Series: ', $sermon_domain) ?></td>
  2326. <td>
  2327. <select name="widget-sermon[<?php echo $number; ?>][series]" id="widget-sermon-series-<?php echo $number; ?>">
  2328. <option value="0" <?php echo $series ? '' : 'selected="selected"' ?>><?php _e('[All]', $sermon_domain) ?></option>
  2329. <?php foreach ($dseries as $cseries): ?>
  2330. <option value="<?php echo $cseries->id ?>" <?php echo $series == $cseries->id ? 'selected="selected"' : '' ?>><?php echo $cseries->name ?></option>
  2331. <?php endforeach ?>
  2332. </select>
  2333. </td>
  2334. </tr>
  2335. </table>
  2336. <input type="hidden" id="widget-sermon-submit-<?php echo $number; ?>" name="widget-sermon[<?php echo $number; ?>][submit]" value="1" />
  2337. </p>
  2338. <?php
  2339. }
  2340. /**
  2341. * Displays the most popular sermons widget options and handles changes
  2342. */
  2343. function sb_widget_popular_control() {
  2344. global $sermon_domain;
  2345. $options = sb_get_option('popular_widget_options');
  2346. if ( !is_array($options) )
  2347. $options = array('title' => '', 'limit' => 5, 'display_sermons' => true, 'display_series' => true, 'display_preachers' => true);
  2348. if (isset($_POST['widget-popular-sermons-submit'])) {
  2349. $title = strip_tags(stripslashes($_POST['widget-popular-title']));
  2350. $limit = (int) ($_POST['widget-popular-limit']);
  2351. $display_sermons = (isset($_POST['widget-popular-display-sermons']));
  2352. $display_series = (isset($_POST['widget-popular-display-series']));
  2353. $display_preachers = (isset($_POST['widget-popular-display-preachers']));
  2354. $options = array('title' => $title, 'limit' => $limit, 'display_sermons' => $display_sermons, 'display_series' => $display_series, 'display_preachers' => $display_preachers);
  2355. sb_update_option('popular_widget_options', $options);
  2356. }
  2357. $title = attribute_escape($options['title']);
  2358. $limit = attribute_escape($options['limit']);
  2359. $display_sermons = (boolean) attribute_escape($options['display_sermons']);
  2360. $display_series = (boolean) attribute_escape($options['display_series']);
  2361. $display_preachers = (boolean) attribute_escape($options['display_preachers']);
  2362. ?>
  2363. <p><?php _e('Title:'); ?> <input class="widefat" id="widget-popular-title" name="widget-popular-title" type="text" value="<?php echo $title; ?>" /></p>
  2364. <p>
  2365. <?php _e('Number of sermons: ', $sermon_domain) ?><select id="widget-popular-limit" name="widget-popular-limit"><?php for($i=1; $i<=15; $i++) { $sel = ($i==$limit) ? ' selected="yes"' : ''; echo "<option value=\"{$i}\"{$sel}>{$i}</option>"; } ?></select>
  2366. <div style="clear:both">
  2367. <input type="checkbox" id="widget-popular-display-sermons" name="widget-popular-display-sermons" <?php echo $display_sermons ? 'checked=checked' : '' ?> value="1"> <?php _e('Display popular sermons', $sermon_domain) ?><br />
  2368. <input type="checkbox" id="widget-popular-display-series" name="widget-popular-display-series" <?php echo $display_series ? 'checked=checked' : '' ?> value="1"> <?php _e('Display popular series', $sermon_domain) ?><br />
  2369. <input type="checkbox" id="widget-popular-display-preachers" name="widget-popular-display-preachers" <?php echo $display_preachers ? 'checked=checked' : '' ?> value="1"> <?php _e('Display popular preachers', $sermon_domain) ?><br />
  2370. </div>
  2371. <input type="hidden" id="widget-popular-sermons-submit" name="widget-popular-sermons-submit" value="1" />
  2372. </p>
  2373. <?php
  2374. }
  2375. /**
  2376. * Returns true if any ID3 import options have been selected
  2377. *
  2378. * @return boolean
  2379. */
  2380. function sb_import_options_set () {
  2381. if (!sb_get_option('import_title') && !sb_get_option('import_artist') && !sb_get_option('import_album') && !sb_get_option('import_comments') && (!sb_get_option('import_filename') || sb_get_option('import_filename') == 'none'))
  2382. return false;
  2383. else
  2384. return true;
  2385. }
  2386. /**
  2387. * Displays notice if ID3 import options have not been set
  2388. */
  2389. function sb_print_import_options_message($long = FALSE) {
  2390. global $sermon_domain;
  2391. if (!sb_import_options_set()) {
  2392. if ($long) {
  2393. _e ('SermonBrowser can automatically pre-fill this form by reading ID3 tags from MP3 files.', $sermon_domain);
  2394. echo ' ';
  2395. }
  2396. printf (__ ('You will need to set the %s before you can import MP3s and pre-fill the Add Sermons form.', $sermon_domain), '<a href="'.admin_url('admin.php?page=sermon-browser/options.php').'">'.__('import options', $sermon_domain).'</a>');
  2397. }
  2398. }
  2399. /**
  2400. * echoes the upload form
  2401. */
  2402. function sb_print_upload_form () {
  2403. global $wpdb, $sermon_domain;
  2404. ?>
  2405. <table width="100%" cellspacing="2" cellpadding="5" class="widefat">
  2406. <form method="post" enctype="multipart/form-data" action ="<?php echo admin_url('admin.php?page=sermon-browser/files.php'); ?>" >
  2407. <thead>
  2408. <tr>
  2409. <th scope="col" colspan="3"><?php if (sb_import_options_set()) printf(__("Select an MP3 file here to have the %s form pre-filled using ID3 tags.", $sermon_domain), "<a href=\"".admin_url('admin.php?page=sermon-browser/new_sermon.php')."\">".__('Add Sermons', $sermon_domain).'</a>'); else _e('Upload file', $sermon_domain);?></th>
  2410. </tr>
  2411. </thead>
  2412. <tbody>
  2413. <tr>
  2414. <th nowrap style="width:20em" valign="top" scope="row"><?php _e('File to upload', $sermon_domain) ?>: </th>
  2415. <?php
  2416. $checkSermonUpload = sb_checkSermonUploadable();
  2417. if ($checkSermonUpload == 'writeable') {
  2418. ?>
  2419. <td width ="40"><input type="file" size="40" value="" name="upload" /></td>
  2420. <td class="submit"><input type="submit" name="save" value="<?php _e('Upload', $sermon_domain) ?> &raquo;" /></td>
  2421. <?php
  2422. } else
  2423. if (IS_MU) {
  2424. ?>
  2425. <td><?php _e('Upload is disabled. Please contact your systems administrator.', $sermon_domain);?></p>
  2426. <?php
  2427. } else {
  2428. ?>
  2429. <td><?php _e('Upload is disabled. Please check your folder setting in Options.', $sermon_domain);?></p>
  2430. <?php
  2431. }
  2432. ?>
  2433. </tr>
  2434. <?php if (sb_import_options_set()) { ?>
  2435. <tr>
  2436. <th nowrap valign="top" scope="row"><?php _e('URL to import', $sermon_domain) ?>: </th>
  2437. <td>
  2438. <input type="text" size="40" value="" name="url"/><br/>
  2439. <span style="line-height: 29px"><input type="radio" name="import_type" value="remote" checked="checked" /><?php _e('Link to remote file', $sermon_domain) ?> <input type="radio" name="import_type" value="download" /><?php _e('Copy remote file to server', $sermon_domain) ?></span>
  2440. </td>
  2441. <td class="submit"><input type="submit" name="import_url" value="<?php _e('Import', $sermon_domain) ?> &raquo;" /></td>
  2442. </tr>
  2443. <?php } ?>
  2444. </form>
  2445. <?php if ($_GET['page'] == 'sermon-browser/new_sermon.php') { ?>
  2446. <form method="get" action="<?php echo admin_url();?>">
  2447. <input type="hidden" name="page" value="sermon-browser/new_sermon.php" />
  2448. <tr>
  2449. <th nowrap valign="top" scope="row"><?php _e('Choose existing file', $sermon_domain) ?>: </th>
  2450. <td>
  2451. <select name="getid3">
  2452. <?php
  2453. $files = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}sb_stuff WHERE sermon_id = 0 AND type = 'file' ORDER BY name asc");
  2454. echo count($files) == 0 ? '<option value="0">No files found</option>' : '<option value="0"></option>';
  2455. foreach ($files as $file) { ?>
  2456. <option value="<?php echo $file->id ?>"><?php echo $file->name ?></option>
  2457. <?php } ?>
  2458. </select>
  2459. </td>
  2460. <td class="submit"><input type="submit" value="<?php _e('Select', $sermon_domain) ?> &raquo;" /></td>
  2461. </tr>
  2462. </form>
  2463. <?php } ?>
  2464. </tbody>
  2465. </table>
  2466. <?php }
  2467. function sb_add_contextual_help($help) {
  2468. global $sermon_domain;
  2469. if (!isset($_GET['page']))
  2470. return $help;
  2471. else {
  2472. $out = '<h5>'.__('SermonBrowser Help', $sermon_domain)."</h5>\n";
  2473. $out .= '<div class="metabox-prefs"><p>';
  2474. switch ($_GET['page']) {
  2475. case 'sermon-browser/sermon.php':
  2476. $out .= __('From this page you can edit or delete any of your sermons. The most recent sermons are found at the top. Use the filter options to quickly find the one you want.', $sermon_domain);
  2477. break;
  2478. case 'sermon-browser/new_sermon.php':
  2479. case 'sermon-browser/files.php':
  2480. case 'sermon-browser/preachers.php':
  2481. case 'sermon-browser/manage.php':
  2482. case 'sermon-browser/options.php':
  2483. $out .= __('It&#146;s important that these options are set correctly, as otherwise SermonBrowser won&#146;t behave as you expect.', $sermon_domain).'<ul>';
  2484. $out .= '<li>'.__('The upload folder would normally be <b>wp-content/uploads/sermons</b>', $sermon_domain).'</li>';
  2485. $out .= '<li>'.__('You should only change the public podcast feed if you re-direct your podcast using a service like Feedburner. Otherwise it should be the same as the private podcast feed.', $sermon_domain).'</li>';
  2486. $out .= '<li>'.__('The MP3 shortcode you need will be in the documation of your favourite MP3 plugin. Use the tag %SERMONURL% in place of the URL of the MP3 file (e.g. [haiku url="%SERMONURL%"] or [audio:%SERMONURL%]).', $sermon_domain).'</li></ul>';
  2487. break;
  2488. case 'sermon-browser/templates.php':
  2489. $out .= sprintf(__('Template editing is one of the most powerful features of SermonBrowser. Be sure to look at the complete list of %stemplate tags%s.', $sermon_domain), '<a href="http://www.sermonbrowser.com/customisation/">', '</a>');
  2490. break;
  2491. case 'sermon-browser/uninstall.php':
  2492. case 'sermon-browser/help.php':
  2493. }
  2494. }
  2495. $out.= '</p><p><a href="http://www.sermonbrowser.com/tutorials/">'.__('Tutorial Screencasts').'</a>';
  2496. $out.= ' | <a href="http://www.sermonbrowser.com/faq/">'.__('Frequently Asked Questions').'</a>';
  2497. $out.= ' | <a href="http://www.sermonbrowser.com/forum/">'.__('Support Forum').'</a>';
  2498. $out.= ' | <a href="http://www.sermonbrowser.com/customisation/">'.__('Shortcode syntax').'</a>';
  2499. $out.= ' | <a href="http://www.sermonbrowser.com/donate/">'.__('Donate').'</a>';
  2500. $out.= '</p></div>';
  2501. return $out;
  2502. }
  2503. ?>