PageRenderTime 43ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/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

Large files files are truncated, but you can click here to view the full 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 …

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