/sermon-browser/sb-includes/admin.php
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
- <?php
- /**
- * Admin functions
- *
- * Functions required exclusively in the back end.
- * @package admin_functions
- */
- /**
- * Adds javascript and CSS where required in admin
- */
- function sb_add_admin_headers() {
- if (isset($_REQUEST['page']) && substr($_REQUEST['page'],14) == 'sermon-browser')
- wp_enqueue_script('jquery');
- if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'sermon-browser/new_sermon.php') {
- wp_enqueue_script('sb_datepicker');
- wp_enqueue_script('sb_64');
- wp_enqueue_style ('sb_datepicker');
- wp_enqueue_style ('sb_style');
- }
- }
- /**
- * Display the options page and handle changes
- */
- function sb_options() {
- global $wpdb, $sermon_domain;
- //Security check
- if (!current_user_can('manage_options'))
- wp_die(__("You do not have the correct permissions to edit the SermonBrowser options", $sermon_domain));
- //Reset options to default
- if (isset($_POST['resetdefault'])) {
- $dir = sb_get_default('sermon_path');
- if (sb_display_url()=="#") {
- sb_update_option('podcast_url', site_url().sb_query_char(false).'podcast');
- } else {
- sb_update_option('podcast_url', sb_display_url().sb_query_char(false).'podcast');
- }
- sb_update_option('upload_dir', $dir);
- sb_update_option('upload_url', sb_get_default('attachment_url'));
- sb_update_option('display_method', 'dynamic');
- sb_update_option('sermons_per_page', '10');
- sb_update_option('filter_type', 'oneclick');
- sb_update_option('filter_hide', 'hide');
- sb_update_option('hide_no_attachments', false);
- sb_update_option('mp3_shortcode', '[audio:%SERMONURL%]');
- if (!is_dir(SB_ABSPATH.$dir))
- if (sb_mkdir(SB_ABSPATH.$dir))
- @chmod(SB_ABSPATH.$dir, 0777);
- if(!is_dir(SB_ABSPATH.$dir.'images') && sb_mkdir(SB_ABSPATH.$dir.'images'))
- @chmod(SB_ABSPATH.$dir.'images', 0777);
- $books = sb_get_default('bible_books');
- $eng_books = sb_get_default('eng_bible_books');
- // Reset bible books database
- $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}sb_books");
- for ($i=0; $i < count($books); $i++) {
- $wpdb->query("INSERT INTO {$wpdb->prefix}sb_books VALUES (null, '$books[$i]')");
- $wpdb->query("UPDATE {$wpdb->prefix}sb_books_sermons SET book_name='{$books[$i]}' WHERE book_name='{$eng_books[$i]}'");
- }
- // Rewrite booknames for non-English locales
- if ($books != $eng_books) {
- $sermon_books = $wpdb->get_results("SELECT id, start, end FROM {$wpdb->prefix}sb_sermons");
- foreach ($sermon_books as $sermon_book) {
- $start_verse = unserialize($sermon_book->start);
- $end_verse = unserialize($sermon_book->end);
- $start_index = array_search($start_verse[0]['book'], $eng_books, TRUE);
- $end_index = array_search($end_verse[0]['book'], $eng_books, TRUE);
- if ($start_index !== FALSE)
- $start_verse[0]['book'] = $books[$start_index];
- if ($end_index !== FALSE)
- $end_verse[0]['book'] = $books[$end_index];
- $sermon_book->start = serialize ($start_verse);
- $sermon_book->end = serialize ($end_verse);
- $wpdb->query("UPDATE {$wpdb->prefix}sb_sermons SET start='{$sermon_book->start}', end='{$sermon_book->end}' WHERE id={$sermon_book->id}");
- }
- }
- $checkSermonUpload = sb_checkSermonUploadable();
- switch ($checkSermonUpload) {
- case "unwriteable":
- echo '<div id="message" class="updated fade"><p><b>';
- if (IS_MU AND !is_site_admin()) {
- _e('Upload is disabled. Please contact your administrator.', $sermon_domain);
- } else {
- _e('Error: The upload folder is not writeable. You need to CHMOD the folder to 666 or 777.', $sermon_domain);
- }
- echo '</b></div>';
- break;
- case "notexist":
- echo '<div id="message" class="updated fade"><p><b>';
- if (IS_MU AND !is_site_admin()) {
- _e('Upload is disabled. Please contact your administrator.', $sermon_domain);
- } else {
- _e('Error: The upload folder you have specified does not exist.', $sermon_domain);
- }
- echo '</b></div>';
- break;
- default:
- echo '<div id="message" class="updated fade"><p><b>';
- _e('Default loaded successfully.', $sermon_domain);
- echo '</b></div>';
- break;
- }
- }
- // Save options
- elseif (isset($_POST['save'])) {
- $dir = rtrim(str_replace("\\", "/", $_POST['dir']), "/")."/";
- sb_update_option('podcast_url', stripslashes($_POST['podcast']));
- if (intval($_POST['perpage']) > 0)
- sb_update_option('sermons_per_page', intval($_POST['perpage']));
- if (intval($_POST['perpage']) == -100)
- update_option('show_donate_reminder', 'off');
- sb_update_option('upload_dir', $dir);
- sb_update_option('filter_type', $_POST['filtertype']);
- sb_update_option('filter_hide', isset($_POST['filterhide']));
- sb_update_option('upload_url', trailingslashit(site_url()).$dir);
- sb_update_option ('import_prompt', isset($_POST['import_prompt']));
- sb_update_option ('import_title', isset($_POST['import_title']));
- sb_update_option ('import_artist', isset($_POST['import_artist']));
- sb_update_option ('import_album', isset($_POST['import_album']));
- sb_update_option ('import_comments', isset($_POST['import_comments']));
- sb_update_option ('import_filename', stripslashes($_POST['import_filename']));
- sb_update_option ('hide_no_attachments', isset($_POST['hide_no_attachments']));
- sb_update_option('mp3_shortcode', stripslashes($_POST['mp3_shortcode']));
- if (!is_dir(SB_ABSPATH.$dir))
- if (sb_mkdir(SB_ABSPATH.$dir))
- @chmod(SB_ABSPATH.$dir, 0777);
- if(!is_dir(SB_ABSPATH.$dir.'images') && sb_mkdir(SB_ABSPATH.$sermonUploadDir.'images'))
- @chmod(SB_ABSPATH.$dir.'images', 0777);
- $checkSermonUpload = sb_checkSermonUploadable();
- switch ($checkSermonUpload) {
- case "unwriteable":
- echo '<div id="message" class="updated fade"><p><b>';
- _e('Error: The upload folder is not writeable. You need to CHMOD the folder to 666 or 777.', $sermon_domain);
- echo '</b></div>';
- break;
- case "notexist":
- echo '<div id="message" class="updated fade"><p><b>';
- _e('Error: The upload folder you have specified does not exist.', $sermon_domain);
- echo '</b></div>';
- break;
- default:
- echo '<div id="message" class="updated fade"><p><b>';
- _e('Options saved successfully.', $sermon_domain);
- echo '</b></div>';
- break;
- }
- }
- //Display error messsages when problems in php.ini
- function sb_display_error ($message) {
- global $sermon_domain;
- return '<tr><td align="right" style="color:#AA0000; font-weight:bold">'.__('Error', $sermon_domain).':</td>'.
- '<td style="color: #AA0000">'.$message.'</td></tr>';
- }
- //Display warning messsages when problems in php.ini
- function sb_display_warning ($message) {
- global $sermon_domain;
- return '<tr><td align="right" style="color:#FFDC00; font-weight:bold">'.__('Warning', $sermon_domain).':</td>'.
- '<td style="color: #FF8C00">'.$message.'</td></tr>';
- }
- sb_do_alerts();
- // HTML for options page
- ?>
- <div class="wrap">
- <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>
- <form method="post">
- <h2><?php _e('Basic Options', $sermon_domain) ?></h2>
- <br style="clear:both"/>
- <table border="0" class="widefat">
- <?php
- if (!IS_MU OR is_site_admin()) {
- ?>
- <tr>
- <td align="right" style="vertical-align:middle"><?php _e('Upload folder', $sermon_domain) ?>: </td>
- <td><input type="text" name="dir" value="<?php echo htmlspecialchars(sb_get_option('upload_dir')) ?>" style="width:100%" /></td>
- </tr>
- <?php
- } else {
- ?>
- <input type="hidden" name="dir" value="<?php echo htmlspecialchars(sb_get_option('upload_dir')) ?>">
- <?php
- }
- ?>
- <tr>
- <td align="right" style="vertical-align:middle"><?php _e('Public podcast feed', $sermon_domain) ?>: </td>
- <td><input type="text" name="podcast" value="<?php echo htmlspecialchars(sb_get_option('podcast_url')) ?>" style="width:100%" /></td>
- </tr>
- <tr>
- <td align="right"><?php _e('Private podcast feed', $sermon_domain) ?>: </td>
- <td><?php if (sb_display_url()=='') { echo htmlspecialchars(site_url()); } else { echo htmlspecialchars(sb_display_url()); } echo sb_query_char(); ?>podcast</td>
- </tr>
- <tr>
- <td align="right" style="vertical-align:middle"><?php _e('MP3 shortcode', $sermon_domain) ?>: </td>
- <td><input type="text" name="mp3_shortcode" value="<?php echo htmlspecialchars(sb_get_option('mp3_shortcode')) ?>" style="width:100%" /></td>
- </tr>
- <tr>
- <td align="right" style="vertical-align:middle"><?php _e('Sermons per page', $sermon_domain) ?>: </td>
- <td><input type="text" name="perpage" value="<?php echo sb_get_option('sermons_per_page') ?>" /></td>
- </tr>
- <tr>
- <td align="right" style="vertical-align:top" rowspan="2"><?php _e('Filter type', $sermon_domain) ?>: </td>
- <td>
- <?php
- $ft = sb_get_option('filter_type');
- $filter_options = array ('dropdown' => __('Drop-down', $sermon_domain), 'oneclick' => __('One-click', $sermon_domain), 'none' => __('None', $sermon_domain));
- foreach ($filter_options as $value => $filter_option) {
- echo "<input type=\"radio\" name=\"filtertype\" value=\"{$value}\" ";
- if ($ft == $value)
- echo 'checked="checked" ';
- echo "/> {$filter_option}<br/>\n";
- }
- ?>
- </td>
- </tr>
- <tr>
- <td>
- <input type="checkbox" name="filterhide" <?php if (sb_get_option('filter_hide') == 'hide') echo 'checked="checked" '; ?> value="hide" \> <?php _e('Minimise filter', $sermon_domain); ?>
- </td>
- </tr>
- <tr>
- <td align="right"><?php _e('Hide sermons without attachments?', $sermon_domain) ?></td>
- <td><input type="checkbox" name="hide_no_attachments" <?php if (sb_get_option('hide_no_attachments')) echo 'checked="checked" '?> value="1" \></td>
- </tr>
- <?php
- $allow_uploads = ini_get('file_uploads');
- $max_filesize = sb_return_kbytes(ini_get('upload_max_filesize'));
- $max_post = sb_return_kbytes(ini_get('post_max_size'));
- $max_execution = ini_get('max_execution_time');
- $max_input = ini_get('max_input_time');
- $max_memory = sb_return_kbytes(ini_get('memory_limit'));
- $checkSermonUpload = sb_checkSermonUploadable();
- if (IS_MU) {
- if ($checkSermonUpload=="unwriteable")
- 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));
- elseif ($checkSermonUpload=="notexist")
- sb_display_error (__('The upload folder you have specified does not exist.', $sermon_domain));
- if ($allow_uploads == '0') echo sb_display_error(__('Your administrator does not allow file uploads. You will need to upload via FTP.', $sermon_domain));
- $max_filesize = ($max_filesize < $max_post) ? $max_filesize : $max_post;
- 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));
- $max_execution = (($max_execution < $max_input) || $max_input == -1) ? $max_execution : $max_input;
- 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));
- } else {
- if ($checkSermonUpload=="unwriteable")
- 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));
- elseif ($checkSermonUpload=="notexist")
- sb_display_error (__('The upload folder you have specified does not exist.', $sermon_domain));
- 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));
- 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));
- 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));
- 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));
- 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));
- 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));
- }
- ?>
- </table>
- <h2><?php _e('Import Options', $sermon_domain) ?></h2>
- <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>') ?>
- <table border="0" class="widefat">
- <tr>
- <td align="right"><?php _e('Add files prompt to top of Add Sermon page?', $sermon_domain) ?></td>
- <td><input type="checkbox" name="import_prompt" <?php if (sb_get_option('import_prompt')) echo 'checked="checked" '?> value="1" \></td>
- </tr>
- <tr>
- <td align="right"><?php _e('Use title tag for sermon title?', $sermon_domain) ?></td>
- <td><input type="checkbox" name="import_title" <?php if (sb_get_option('import_title')) echo 'checked="checked" '?> value="1" \></td>
- </tr>
- <tr>
- <td align="right"><?php _e('Use artist tag for preacher?', $sermon_domain) ?></td>
- <td><input type="checkbox" name="import_artist" <?php if (sb_get_option('import_artist')) echo 'checked="checked" '?> value="1" \></td>
- </tr>
- <tr>
- <td align="right"><?php _e('Use album tag for series?', $sermon_domain) ?></td>
- <td><input type="checkbox" name="import_album" <?php if (sb_get_option('import_album')) echo 'checked="checked" '?> value="1" \></td>
- </tr>
- <tr>
- <td align="right"><?php _e('Use comments tag for sermon description?', $sermon_domain) ?></td>
- <td><input type="checkbox" name="import_comments" <?php if (sb_get_option('import_comments')) echo 'checked="checked" '?> value="1" \></td>
- </tr>
- <tr>
- <td align="right" style="vertical-align: middle"><?php _e('Attempt to extract date from filename', $sermon_domain) ?></td>
- <td style="vertical-align: middle"><select name="import_filename">
- <?php
- $filename_options = array ('none' => __('Disabled', $sermon_domain),
- 'uk' => __('UK-formatted date (dd-mm-yyyy)', $sermon_domain),
- 'us' => __('US-formatted date (mm-dd-yyyy)', $sermon_domain),
- 'int' => __('International formatted date (yyyy-mm-dd)', $sermon_domain)
- );
- $saved_option = sb_get_option ('import_filename');
- foreach ($filename_options as $option => $text) {
- $sel = $saved_option == $option ? ' selected = "selected"' : '';
- echo "<option value=\"{$option}\"{$sel}>{$text}</option>\n";
- }
- echo "</select>\n<br/>";
- _e ('(Use if you name your files something like 2008-11-06-eveningsermon.mp3)', $sermon_domain);
- ?>
- </td>
- </tr>
- </table>
- <p class="submit"><input type="submit" name="resetdefault" value="<?php _e('Reset to defaults', $sermon_domain) ?>" /> <input type="submit" name="save" value="<?php _e('Save', $sermon_domain) ?> »" /></p>
- </div>
- </form>
- <?php
- }
- /**
- * Display uninstall screen and perform uninstall if requested
- */
- function sb_uninstall () {
- global $sermon_domain;
- //Security check
- if (!(current_user_can('edit_plugins') | (IS_MU && current_user_can('manage_options'))))
- wp_die(__("You do not have the correct permissions to Uninstall SermonBrowser", $sermon_domain));
- if (isset($_POST['uninstall']))
- require(SB_INCLUDES_DIR.'/uninstall.php');
- ?>
- <form method="post">
- <div class="wrap">
- <?php if (IS_MU) { ?>
- <h2> <?php _e('Reset SermonBrowser', $sermon_domain); ?></h2>
- <p><?php printf(__('Clicking the %s button below will remove ALL data (sermons, preachers, series, etc.) from SermonBrowser', $sermon_domain), __('Delete all', $sermon_domain));
- echo '. ';
- _e('You will NOT be able to undo this action.', $sermon_domain) ?>
- </p>
- <?php } else { ?>
- <h2> <?php _e('Uninstall', $sermon_domain); ?></h2>
- <p><?php printf(__('Clicking the %s button below will remove ALL data (sermons, preachers, series, etc.) from SermonBrowser', $sermon_domain), __('Uninstall', $sermon_domain));
- echo ', ';
- _e('and will deactivate the SermonBrowser plugin', $sermon_domain);
- echo '. ';
- _e('You will NOT be able to undo this action.', $sermon_domain);
- echo ' ';
- _e('If you only want to temporarily disable SermonBrowser, just deactivate it from the plugins page.', $sermon_domain); ?>
- </p>
- <?php } ?>
- <table border="0" class="widefat">
- <tr>
- <td><input type="checkbox" name="wipe" value="1"> <?php _e('Also remove all uploaded files', $sermon_domain) ?></td>
- </tr>
- </table>
- <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>
- </div>
- </form>
- <script>
- jQuery("form").submit(function() {
- var yes = confirm("<?php _e('Are you REALLY REALLY sure you want to remove SermonBrowser?', $sermon_domain)?>");
- if(!yes) return false;
- });
- </script>
- <?php
- }
- /**
- * Display the templates page and handle changes
- */
- function sb_templates () {
- global $sermon_domain;
- //Security check
- if (function_exists('current_user_can')&&!current_user_can('manage_options'))
- wp_die(__("You do not have the correct permissions to edit the SermonBrowser templates", $sermon_domain));
- //Save templates or reset to default
- if (isset($_POST['save']) || isset($_POST['resetdefault'])) {
- require(SB_INCLUDES_DIR.'/dictionary.php');
- $multi = $_POST['multi'];
- $single = $_POST['single'];
- $style = $_POST['style'];
- if(isset($_POST['resetdefault'])){
- require(SB_INCLUDES_DIR.'/sb-install.php');
- $multi = sb_default_multi_template();
- $single = sb_default_single_template();
- $style = sb_default_css();
- }
- sb_update_option('search_template', $multi);
- sb_update_option('single_template', $single);
- sb_update_option('css_style', $style);
- sb_update_option('search_output', strtr($multi, sb_search_results_dictionary()));
- sb_update_option('single_output', strtr($single, sb_sermon_page_dictionary()));
- sb_update_option('style_date_modified', strtotime('now'));
- echo '<div id="message" class="updated fade"><p><b>';
- _e('Templates saved successfully.', $sermon_domain);
- echo '</b></p></div>';
- }
- sb_do_alerts();
- // HTML for templates page
- ?>
- <form method="post">
- <div class="wrap">
- <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>
- <h2><?php _e('Templates', $sermon_domain) ?></h2>
- <br/>
- <table border="0" class="widefat">
- <tr>
- <td align="right"><?php _e('Search results page', $sermon_domain) ?>: </td>
- <td>
- <?php sb_build_textarea('multi', sb_get_option('search_template')) ?>
- </td>
- </tr>
- <tr>
- <td align="right"><?php _e('Sermon page', $sermon_domain) ?>: </td>
- <td>
- <?php sb_build_textarea('single', sb_get_option('single_template')) ?>
- </td>
- </tr>
- <tr>
- <td align="right"><?php _e('Style', $sermon_domain) ?>: </td>
- <td>
- <?php sb_build_textarea('style', sb_get_option('css_style')) ?>
- </td>
- </tr>
- </table>
- <p class="submit"><input type="submit" name="resetdefault" value="<?php _e('Reset to defaults', $sermon_domain) ?>" /> <input type="submit" name="save" value="<?php _e('Save', $sermon_domain) ?> »" /></p>
- </div>
- </form>
- <script>
- jQuery("form").submit(function() {
- var yes = confirm("Are you sure ?");
- if(!yes) return false;
- });
- </script>
- <?php
- }
- /**
- * Display the preachers page and handle changes
- */
- function sb_manage_preachers() {
- global $wpdb, $sermon_domain;
- //Security check
- if (function_exists('current_user_can')&&!current_user_can('manage_categories'))
- wp_die(__("You do not have the correct permissions to manage the preachers' database", $sermon_domain));
- if (isset($_GET['saved']))
- echo '<div id="message" class="updated fade"><p><b>'.__('Preacher saved to database.', $sermon_domain).'</b></div>';
- $sermonUploadDir = sb_get_option('upload_dir');
- //Save changes
- if (isset($_POST['save'])) {
- $name = $wpdb->escape($_POST['name']);
- $description = $wpdb->escape($_POST['description']);
- $error = false;
- $pid = (int) $_REQUEST['pid'];
- if (empty($_FILES['upload']['name'])) {
- $p = $wpdb->get_row("SELECT image FROM {$wpdb->prefix}sb_preachers WHERE id = $pid");
- $filename = $p ? $p->image : '';
- } elseif ($_FILES['upload']['error'] == UPLOAD_ERR_OK) {
- $filename = basename($_FILES['upload']['name']);
- $prefix = '';
- if(!is_dir(SB_ABSPATH.$sermonUploadDir.'images') && sb_mkdir(SB_ABSPATH.$sermonUploadDir.'images'))
- @chmod(SB_ABSPATH.$sermonUploadDir.'images', 0777);
- $dest = SB_ABSPATH.$sermonUploadDir.'images/'.$filename;
- if (@move_uploaded_file($_FILES['upload']['tmp_name'], $dest))
- $filename = $prefix.mysql_real_escape_string($filename);
- else {
- $error = true;
- echo '<div id="message" class="updated fade"><p><b>'.__('Could not save uploaded file. Please try again.', $sermon_domain).'</b></div>';
- @chmod(SB_ABSPATH.$sermonUploadDir.'images', 0777);
- }
- } else {
- $error = true;
- 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>';
- }
- if ($pid == 0) {
- $wpdb->query("INSERT INTO {$wpdb->prefix}sb_preachers VALUES (null, '$name', '$description', '$filename')");
- } else {
- $wpdb->query("UPDATE {$wpdb->prefix}sb_preachers SET name = '$name', description = '$description', image = '$filename' WHERE id = $pid");
- if ($_POST['old'] != $filename)
- @unlink(SB_ABSPATH.sb_get_option('upload_dir').'images/'.mysql_real_escape_string($_POST['old']));
- }
- if(isset($_POST['remove'])){
- $wpdb->query("UPDATE {$wpdb->prefix}sb_preachers SET name = '$name', description = '$description', image = '' WHERE id = $pid");
- @unlink(SB_ABSPATH.sb_get_option('upload_dir').'images/'.mysql_real_escape_string($_POST['old']));
- }
- if(!$error)
- echo "<script>document.location = '".site_url()."/wp-admin/admin.php?page=sermon-browser/preachers.php&saved=true';</script>";
- }
- if (isset($_GET['act']) && $_GET['act'] == 'kill') {
- $die = (int) $_GET['pid'];
- if($wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}sb_sermons WHERE preacher_id = $die") > 0)
- 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>';
- else {
- $p = $wpdb->get_row("SELECT image FROM {$wpdb->prefix}sb_preachers WHERE id = $die");
- @unlink(SB_ABSPATH.sb_get_option('upload_dir').'images/'.$p->image);
- $wpdb->query("DELETE FROM {$wpdb->prefix}sb_preachers WHERE id = $die");
- }
- }
- if (isset($_GET['act']) && ($_GET['act'] == 'new' || $_GET['act'] == 'edit')) {
- if ($_GET['act'] == 'edit') $preacher = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}sb_preachers WHERE id = ".(int) $_GET['pid']);
- //Display HTML
- ?>
- <div class="wrap">
- <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>
- <h2><?php echo $_GET['act'] == 'new' ? __('Add', $sermon_domain) : __('Edit', $sermon_domain) ?> <?php _e('preacher', $sermon_domain) ?></h2>
- <br style="clear:both">
- <?php
- $checkSermonUpload = sb_checkSermonUploadable('images/');
- if ($checkSermonUpload == 'notexist') {
- echo SB_ABSPATH.$sermonUploadDir.'images';
- if (!is_dir(SB_ABSPATH.$sermonUploadDir.'images') && mkdir(SB_ABSPATH.$sermonUploadDir.'images'))
- chmod(SB_ABSPATH.$sermonUploadDir.'images', 0777);
- $checkSermonUpload = sb_checkSermonUploadable('images/');
- }
- if ($checkSermonUpload != 'writeable')
- 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>';
- ?>
- <form method="post" enctype="multipart/form-data">
- <input type="hidden" name="pid" value="<?php echo (int) $_GET['pid'] ?>">
- <fieldset>
- <table class="widefat">
- <tr>
- <td>
- <strong><?php _e('Name', $sermon_domain) ?></strong>
- <div>
- <input type="text" value="<?php echo isset($preacher->name) ? stripslashes($preacher->name) : '' ?>" name="name" size="60" style="width:400px;" />
- </div>
- </td>
- </tr>
- <tr>
- <td>
- <strong><?php _e('Description', $sermon_domain) ?></strong>
- <div>
- <textarea name="description" cols="100" rows="5"><?php echo isset($preacher->description) ? stripslashes($preacher->description) : ''?></textarea>
- </div>
- </td>
- </tr>
- <tr>
- <td>
- <?php if ($_GET['act'] == 'edit'): ?>
- <div><img src="<?php echo trailingslashit(site_url()).sb_get_option('upload_dir').'images/'.$preacher->image ?>"></div>
- <input type="hidden" name="old" value="<?php echo $preacher->image ?>">
- <?php endif ?>
- <strong><?php _e('Image', $sermon_domain) ?></strong>
- <div>
- <input type="file" name="upload">
- <label>Remove image <input type="checkbox" name="remove" value="true"></label>
- </div>
- </td>
- </tr>
- </table>
- </fieldset>
- <p class="submit"><input type="submit" name="save" value="<?php _e('Save', $sermon_domain) ?> »" /></p>
- </form>
- </div>
- <?php
- return;
- }
- $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");
- sb_do_alerts();
- ?>
- <div class="wrap">
- <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>
- <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>
- <br/>
- <table class="widefat" style="width:auto">
- <thead>
- <tr>
- <th scope="col" style="text-align:center"><?php _e('ID', $sermon_domain) ?></th>
- <th scope="col"><?php _e('Name', $sermon_domain) ?></th>
- <th scope="col" style="text-align:center"><?php _e('Image', $sermon_domain) ?></th>
- <th scope="col" style="text-align:center"><?php _e('Sermons', $sermon_domain) ?></th>
- <th scope="col" style="text-align:center"><?php _e('Actions', $sermon_domain) ?></th>
- </tr>
- </thead>
- <tbody>
- <?php foreach ((array) $preachers as $preacher): ?>
- <tr class="<?php $i=0; echo (++$i % 2 == 0) ? 'alternate' : '' ?>">
- <td style="text-align:center"><?php echo $preacher->id ?></td>
- <td><?php echo stripslashes($preacher->name) ?></td>
- <td style="text-align:center"><?php echo ($preacher->image == '') ? '' : '<img src="'.trailingslashit(site_url()).sb_get_option('upload_dir').'images/'.$preacher->image.'">' ?></td>
- <td style="text-align:center"><?php echo $preacher->sermon_count ?></td>
- <td style="text-align:center">
- <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>
- <?php if (count($preachers) < 2) { ?>
- | <a href="javascript:alert('<?php _e('You must have at least one preacher in the database.', $sermon_domain)?>')"><?php _e('Delete', $sermon_domain) ?></a>
- <?php } elseif ($preacher->sermon_count != 0) { ?>
- | <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>
- <?php } else { ?>
- | <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>
- <?php } ?>
- </td>
- </tr>
- <?php endforeach ?>
- </tbody>
- </table>
- </div>
- <?php
- }
- /**
- * Display services & series page and handle changes
- */
- function sb_manage_everything() {
- global $wpdb, $sermon_domain;
- //Security check
- if (function_exists('current_user_can')&&!current_user_can('manage_categories'))
- wp_die(__("You do not have the correct permissions to manage the series and services database", $sermon_domain));
- $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");
- $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");
- $toManage = array(
- 'Series' => array('data' => $series),
- 'Services' => array('data' => $services),
- );
- sb_do_alerts();
- ?>
- <script type="text/javascript">
- //<![CDATA[
- function updateClass(type) {
- jQuery('.' + type + ':visible').each(function(i) {
- jQuery(this).removeClass('alternate');
- if (++i % 2 == 0) {
- jQuery(this).addClass('alternate');
- }
- });
- }
- function createNewServices(s) {
- var s = 'lol';
- while ((s.indexOf('@') == -1) || (s.match(/(.*?)@(.*)/)[2].match(/[0-9]{1,2}:[0-9]{1,2}/) == null)) {
- s = prompt("<?php _e("New service's name @ default time?", $sermon_domain)?>", "<?php _e("Service's name @ 18:00", $sermon_domain)?>");
- if (s == null) { break; }
- }
- if (s != null) {
- jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/sermon.php'); ?>', {sname: s, sermon: 1}, function(r) {
- if (r) {
- sz = s.match(/(.*?)@(.*)/)[1];
- t = s.match(/(.*?)@(.*)/)[2];
- jQuery('#Services-list').append('\
- <tr style="display:none" class="Services" id="rowServices' + r + '">\
- <th style="text-align:center" scope="row">' + r + '</th>\
- <td id="Services' + r + '">' + sz + '</td>\
- <td style="text-align:center">' + t + '</td>\
- <td style="text-align:center">\
- <a id="linkServices' + r + '" href="javascript:renameServices(' + r + ', \'' + sz + '\')">Edit</a> | <a onclick="return confirm(\'Are you sure?\');" href="javascript:deleteServices(' + r + ')">Delete</a>\
- </td>\
- </tr>\
- ');
- jQuery('#rowServices' + r).fadeIn(function() {
- updateClass('Services');
- });
- };
- });
- }
- }
- function createNewSeries(s) {
- var ss = prompt("<?php _e("New series' name?", $sermon_domain)?>", "<?php _e("Series' name", $sermon_domain)?>");
- if (ss != null) {
- jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/sermon.php'); ?>', {ssname: ss, sermon: 1}, function(r) {
- if (r) {
- jQuery('#Series-list').append('\
- <tr style="display:none" class="Series" id="rowSeries' + r + '">\
- <th style="text-align:center" scope="row">' + r + '</th>\
- <td id="Series' + r + '">' + ss + '</td>\
- <td style="text-align:center">\
- <a id="linkSeries' + r + '" href="javascript:renameSeries(' + r + ', \'' + ss + '\')">Rename</a> | <a onclick="return confirm(\'Are you sure?\');" href="javascript:deleteSeries(' + r + ')">Delete</a>\
- </td>\
- </tr>\
- ');
- jQuery('#rowSeries' + r).fadeIn(function() {
- updateClass('Series');
- });
- };
- });
- }
- }
- function deleteSeries(id) {
- jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/sermon.php'); ?>', {ssname: 'dummy', ssid: id, del: 1, sermon: 1}, function(r) {
- if (r) {
- jQuery('#rowSeries' + id).fadeOut(function() {
- updateClass('Series');
- });
- };
- });
- }
- function deleteServices(id) {
- jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/sermon.php'); ?>', {sname: 'dummy', sid: id, del: 1, sermon: 1}, function(r) {
- if (r) {
- jQuery('#rowServices' + id).fadeOut(function() {
- updateClass('Services');
- });
- };
- });
- }
- function renameSeries(id, old) {
- var ss = prompt("<?php _e("New series' name?", $sermon_domain)?>", old);
- if (ss != null) {
- jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/sermon.php'); ?>', {ssid: id, ssname: ss, sermon: 1}, function(r) {
- if (r) {
- jQuery('#Series' + id).text(ss);
- jQuery('#linkSeries' + id).attr('href', 'javascript:renameSeries(' + id + ', "' + ss + '")');
- Fat.fade_element('Series' + id);
- };
- });
- }
- }
- function renameServices(id, old) {
- var s = 'lol';
- while ((s.indexOf('@') == -1) || (s.match(/(.*?)@(.*)/)[2].match(/[0-9]{1,2}:[0-9]{1,2}/) == null)) {
- s = prompt("<?php _e("New service's name @ default time?", $sermon_domain)?>", old);
- if (s == null) { break; }
- }
- if (s != null) {
- jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/sermon.php'); ?>', {sid: id, sname: s, sermon: 1}, function(r) {
- if (r) {
- sz = s.match(/(.*?)@(.*)/)[1];
- t = s.match(/(.*?)@(.*)/)[2];
- jQuery('#Services' + id).text(sz);
- jQuery('#time' + id).text(t);
- jQuery('#linkServices' + id).attr('href', 'javascript:renameServices(' + id + ', "' + s + '")');
- Fat.fade_element('Services' + id);
- Fat.fade_element('time' + id);
- };
- });
- }
- }
- //]]>
- </script>
- <a name="top"></a>
- <?php
- foreach ($toManage as $k => $v) {
- $i = 0;
- ?>
- <a name="manage-<?php echo $k ?>"></a>
- <div class="wrap">
- <?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 } ?>
- <h2><?php echo $k ?> (<a href="javascript:createNew<?php echo $k ?>()"><?php _e('add new', $sermon_domain) ?></a>)</h2>
- <br style="clear:both">
- <table class="widefat" style="width:auto">
- <thead>
- <tr>
- <th scope="col" style="text-align:center"><?php _e('ID', $sermon_domain) ?></th>
- <th scope="col"><?php _e('Name', $sermon_domain) ?></th>
- <?php echo $k == 'Services' ? '<th scope="col"><div style="text-align:center">'.__('Default time', $sermon_domain).'</div></th>' : '' ?>
- <th scope="col" style="text-align:center"><?php _e('Sermons', $sermon_domain) ?></th>
- <th scope="col" style="text-align:center"><?php _e('Actions', $sermon_domain) ?></th>
- </tr>
- </thead>
- <tbody id="<?php echo $k ?>-list">
- <?php if (is_array($v['data'])): ?>
- <?php foreach ($v['data'] as $item): ?>
- <tr class="<?php echo $k ?> <?php echo (++$i % 2 == 0) ? 'alternate' : '' ?>" id="row<?php echo $k ?><?php echo $item->id ?>">
- <th style="text-align:center" scope="row"><?php echo $item->id ?></th>
- <td id="<?php echo $k ?><?php echo $item->id ?>"><?php echo stripslashes($item->name) ?></td>
- <?php echo $k == 'Services' ? '<td style="text-align:center" id="time'.$item->id.'">'.$item->time.'</td>' : '' ?>
- <td style="text-align:center"><?php echo $item->sermon_count; ?></td>
- <td style="text-align:center">
- <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>
- <?php if (count($v['data']) < 2) { ?>
- | <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>
- <?php } elseif ($item->sermon_count == 0) { ?>
- | <a href="javascript:alert('<?php printf(__('Are you sure you want to delete %s?', $sermon_domain), $item->name); ?>')"><?php _e('Delete', $sermon_domain) ?></a>
- <?php } else { ?>
- | <a href="javascript:alert('<?php switch ($k) {
- case "Services":
- _e('Some sermons are currently assigned to that service. You can only delete services that are not used in the database.', $sermon_domain);
- break;
- case "Series":
- _e('Some sermons are currently in that series. You can only delete series that are empty.', $sermon_domain);
- break;
- case "Preachers":
- _e('That preacher has sermons in the database. You can only delete preachers who have no sermons in the database.', $sermon_domain);
- break;
- }?>')"><?php _e('Delete', $sermon_domain) ?></a>
- <?php } ?>
- </td>
- </tr>
- <?php endforeach ?>
- <?php endif ?>
- </tbody>
- </table>
- <br style="clear:both">
- <div style="text-align:right"><a href="#top">Top †</a></div>
- </div>
- <?php
- }
- }
- /**
- * Display files page and handle changes
- */
- function sb_files() {
- global $wpdb, $filetypes, $sermon_domain;
- //Security check
- if (!current_user_can('upload_files'))
- wp_die(__("You do not have the correct permissions to upload sermons", $sermon_domain));
- // sync
- sb_scan_dir();
- if (isset($_POST['import_url'])) {
- $url = $_POST['url'];
- $valid_url = false;
- if(ini_get('allow_url_fopen')) {
- $headers = array_change_key_case(get_headers($url, 1),CASE_LOWER);
- if ($headers[0] == 'HTTP/1.1 200 OK') {
- if ($_POST['import_type'] == 'download') {
- $filename = substr($url, strrpos ($url, '/')+1);
- $filename = substr($filename, 0, strrpos ($filename, '?'));
- if (file_exists(SB_ABSPATH.sb_get_option('upload_dir').$filename))
- echo '<div id="message" class="updated fade"><p><b>'.sprintf(__('File %s already exists', $sermon_domain), $filename).'</b></div>';
- else {
- $file = @fopen(SB_ABSPATH.sb_get_option('upload_dir').$filename, 'wb');
- $remote_file = @fopen($url, 'r');
- $remote_contents = '';
- while (!feof($remote_file))
- $remote_contents .= fread($remote_file, 8192);
- fwrite($file, $remote_contents);
- fclose($remote_file);
- fclose($file);
- $wpdb->query("INSERT INTO {$wpdb->prefix}sb_stuff VALUES (null, 'file', '".$wpdb->escape($filename)."', 0, 0, 0)");
- echo "<script>document.location = '".admin_url('admin.php?page=sermon-browser/new_sermon.php&getid3='.$wpdb->insert_id)."';</script>";
- }
- } else {
- $wpdb->query("INSERT INTO {$wpdb->prefix}sb_stuff VALUES (null, 'url', '".$wpdb->escape($url)."', 0, 0, 0)");
- echo "<script>document.location = '".admin_url('admin.php?page=sermon-browser/new_sermon.php&getid3='.$wpdb->insert_id)."';</script>";
- die();
- }
- } else
- echo '<div id="message" class="updated fade"><p><b>'.__('Invalid URL.', $sermon_domain).'</b></div>';
- } else
- echo '<div id="message" class="updated fade"><p><b>'.__('Your host does not allow remote downloading of files.', $sermon_domain).'</b></div>';
- }
- elseif (isset($_POST['save'])) {
- if ($_FILES['upload']['error'] == UPLOAD_ERR_OK) {
- $filename = basename($_FILES['upload']['name']);
- if (IS_MU) {
- $file_allowed = FALSE;
- global $wp_version;
- if (version_compare ($wp_version, '3.0', '<'))
- require_once(SB_ABSPATH . 'wp-includes/wpmu-functions.php');
- else
- require_once(SB_ABSPATH . 'wp-includes/ms-functions.php');
- if (function_exists('get_site_option')) {
- $allowed_extensions = explode(" ", get_site_option("upload_filetypes"));
- foreach ($allowed_extensions as $ext) {
- if (substr(strtolower($filename), -(strlen($ext)+1)) == ".".strtolower($ext))
- $file_allowed = TRUE;
- }
- }
- } else {
- $file_allowed = TRUE;
- }
- if ($file_allowed) {
- $prefix = '';
- $dest = SB_ABSPATH.sb_get_option('upload_dir').$prefix.$filename;
- if($wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}sb_stuff WHERE name = '".mysql_real_escape_string($filename)."'") == 0) {
- $filename = mysql_real_escape_string($filename);
- if (move_uploaded_file($_FILES['upload']['tmp_name'], $dest)) {
- $filename = $prefix.$filename;
- $wpdb->query("INSERT INTO {$wpdb->prefix}sb_stuff VALUES (null, 'file', '{$filename}', 0, 0, 0)");
- if (sb_import_options_set ())
- echo "<script>document.location = '".admin_url('admin.php?page=sermon-browser/new_sermon.php&getid3='.$wpdb->insert_id)."';</script>";
- else
- echo '<div id="message" class="updated fade"><p><b>'.__('Files saved to database.', $sermon_domain).'</b></div>';
- }
- } else {
- echo '<div id="message" class="updated fade"><p><b>'.__($filename. ' already exists.', $sermon_domain).'</b></div>';
- }
- } else {
- @unlink($_FILES['upload']['tmp_name']);
- echo '<div id="message" class="updated fade"><p><b>'.__('You are not permitted to upload files of that type.', $sermon_domain).'</b></div>';
- }
- }
- } elseif(isset($_POST['clean'])) {
- $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;");
- $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;");
- $wanted = array(-1);
- foreach ((array) $unlinked as $k => $file) {
- if (!file_exists(SB_ABSPATH.sb_get_option('upload_dir').$file->name)) {
- $wanted[] = $file->id;
- unset($unlinked[$k]);
- }
- }
- foreach ((array) $linked as $k => $file) {
- if (!file_exists(SB_ABSPATH.sb_get_option('upload_dir').$file->name)) {
- $wanted[] = $file->id;
- unset($unlinked[$k]);
- }
- }
- $wpdb->query("DELETE FROM {$wpdb->prefix}sb_stuff WHERE id IN (".implode(', ', (array) $wanted).")");
- $wpdb->query("DELETE FROM {$wpdb->prefix}sb_stuff WHERE type != 'file' AND sermon_id=0");
- }
- $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;");
- $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;");
- $cntu = $wpdb->get_row("SELECT COUNT(*) as cntu FROM {$wpdb->prefix}sb_stuff WHERE sermon_id = 0 AND type = 'file' ", ARRAY_A);
- $cntu = $cntu['cntu'];
- $cntl = $wpdb->get_row("SELECT COUNT(*) as cntl FROM {$wpdb->prefix}sb_stuff WHERE sermon_id <> 0 AND type = 'file' ", ARRAY_A);
- $cntl = $cntl['cntl'];
- sb_do_alerts();
- ?>
- <script>
- function rename(id, old) {
- var f = prompt("<?php _e('New file name?', $sermon_domain) ?>", old);
- if (f != null) {
- jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/uploads.php'); ?>', {fid: id, oname: old, fname: f, sermon: 1}, function(r) {
- if (r) {
- if (r == 'renamed') {
- jQuery('#' + id).text(f.substring(0,f.lastIndexOf(".")));
- jQuery('#link' + id).attr('href', 'javascript:rename(' + id + ', "' + f + '")');
- Fat.fade_element(id);
- jQuery('#s' + id).text(f.substring(0,f.lastIndexOf(".")));
- jQuery('#slink' + id).attr('href', 'javascript:rename(' + id + ', "' + f + '")');
- Fat.fade_element('s' + id);
- } else {
- if (r == 'forbidden') {
- alert('<?php _e('You are not permitted files with that extension.', $sermon_domain) ?>');
- } else {
- alert('<?php _e('The script is unable to rename your file.', $sermon_domain) ?>');
- }
- }
- };
- });
- }
- }
- function kill(id, f) {
- jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/files.php'); ?>', {fname: f, fid: id, del: 1, sermon: 1}, function(r) {
- if (r) {
- if (r == 'deleted') {
- jQuery('#file' + id).fadeOut(function() {
- jQuery('.file:visible').each(function(i) {
- jQuery(this).removeClass('alternate');
- if (++i % 2 == 0) {
- jQuery(this).addClass('alternate');
- }
- });
- });
- jQuery('#sfile' + id).fadeOut(function() {
- jQuery('.file:visible').each(function(i) {
- jQuery(this).removeClass('alternate');
- if (++i % 2 == 0) {
- jQuery(this).addClass('alternate');
- }
- });
- });
- } else {
- alert('<?php _e('The script is unable to delete your file.', $sermon_domain) ?>');
- }
- };
- });
- }
- function fetchU(st) {
- jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/uploads.php'); ?>', {fetchU: st + 1, sermon: 1}, function(r) {
- if (r) {
- jQuery('#the-list-u').html(r);
- if (st >= <?php echo sb_get_option('sermons_per_page') ?>) {
- x = st - <?php echo sb_get_option('sermons_per_page') ?>;
- jQuery('#uleft').html('<a href="javascript:fetchU(' + x + ')">« <?php _e('Previous', $sermon_domain) ?></a>');
- } else {
- jQuery('#uleft').html('');
- }
- if (st + <?php echo sb_get_option('sermons_per_page') ?> <= <?php echo $cntu ?>) {
- y = st + <?php echo sb_get_option('sermons_per_page') ?>;
- jQuery('#uright').html('<a href="javascript:fetchU(' + y + ')"><?php _e('Next', $sermon_domain) ?> »</a>');
- } else {
- jQuery('#uright').html('');
- }
- };
- });
- }
- function fetchL(st) {
- jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/files.php'); ?>', {fetchL: st + 1, sermon: 1}, function(r) {
- if (r) {
- jQuery('#the-list-l').html(r);
- if (st >= <?php echo sb_get_option('sermons_per_page') ?>) {
- x = st - <?php echo sb_get_option('sermons_per_page') ?>;
- jQuery('#left').html('<a href="javascript:fetchL(' + x + ')">« <?php _e('Previous', $sermon_domain) ?></a>');
- } else {
- jQuery('#left').html('');
- }
- if (st + <?php echo sb_get_option('sermons_per_page') ?> <= <?php echo $cntl ?>) {
- y = st + <?php echo sb_get_option('sermons_per_page') ?>;
- jQuery('#right').html('<a href="javascript:fetchL(' + y + ')"><?php _e('Next', $sermon_domain) ?> »</a>');
- } else {
- jQuery('#right').html('');
- }
- };
- });
- }
- function findNow() {
- jQuery.post('<?php echo admin_url('admin.php?page=sermon-browser/files.php'); ?>', {search: jQuery('#search').val(), sermon: 1}, function(r) {
- if (r) {
- jQuery('#the-list-s').html(r);
- };
- });
- }
- </script>
- <a name="top"></a>
- <div class="wrap">
- <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>
- <h2><?php _e('Upload Files', $sermon_domain) ?></h2>
- <?php if (!sb_import_options_set()) {
- echo '<p class="plugin-update">';
- sb_print_import_options_message();
- echo "</p>\n";
- } ?>
- <br style="clear:both">
- <?php
- sb_print_upload_form();
- ?>
- </div>
- <div class="wrap">
- <h2><?php _e('Unlinked files', $sermon_domain) ?></h2>
- <br style="clear:both">
- <table class="widefat">
- <thead>
- <tr>
- <th width="10%" scope="col"><div style="text-align:center"><?php _e('ID', $sermon_domain) ?></div></th>
- <th width="50%" scope="col"><div style="text-align:center"><?php _e('File name', $sermon_domain) ?></div></th>
- <th width="20%" scope="col"><div style="text-align:center"><?php _e('File type', $sermon_domain) ?></div></th>
- <th width="20%" scope="col"><div style="text-align:center"><?php _e('Actions', $sermon_domain) ?></div></th>
- </tr>
- </thead>
- <tbody id="the-list-u">
- <?php if (is_array($unlinked)): ?>
- <?php foreach ($unlinked as $file): ?>
- <tr class="file <?php $i=0; echo (++$i % 2 == 0) ? 'alternate' : '' ?>" id="file<?php echo $file->id ?>">
- <th style="text-align:center" scope="row"><?php echo $file->id ?></th>
- <td id="<?php echo $file->id ?>"><?php echo substr($file->name, 0, strrpos($file->name, '.')) ?></td>
- <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>
- <td style="text-align:center">
- <a id="" href="<?php echo admin_url("admin.php?page=sermon-browser/new_sermon.php&getid3={$file->id}"); ?>"><?php _e('Create sermon', $sermon_domain) ?></a> |
- <a id="link<?php echo …
Large files files are truncated, but you can click here to view the full file