$blclog->info('Upgrading the database...'); $upgrade_start = microtime(true); require_once BLC_DIRECTORY . '/includes/admin/db-upgrade.php'; blcDatabaseUpgrader::upgrade_database(); $blclog->info(sprintf('--- Total: %.3f seconds', microtime(true) - $upgrade_start)); //Remove invalid DB entries $blclog->info('Cleaning up the database...'); $cleanup_start = microtime(true); blc_cleanup_database(); $blclog->info(sprintf('--- Total: %.3f seconds', microtime(true) - $cleanup_start)); //Notify modules that the plugin has been activated. This will cause container //modules to create and update synch. records for all new/modified posts and other items. $blclog->info('Notifying modules...'); $notification_start = microtime(true); $moduleManager->plugin_activated(); blc_got_unsynched_items(); $blclog->info(sprintf('--- Total: %.3f seconds', microtime(true) - $notification_start)); //Turn off load limiting if it's not available on this server. $blclog->info('Updating server load limit settings...'); $load = blcUtility::get_server_load(); if (empty($load)) { $blc_config_manager->options['enable_load_limit'] = false; $blclog->info('Disable load limit. Cannot retrieve current load average.'); } elseif ($blc_config_manager->options['enable_load_limit'] && !isset($blc_config_manager->options['server_load_limit'])) { $fifteen_minutes = floatval(end($load)); $default_load_limit = round(max(min($fifteen_minutes * 2, $fifteen_minutes + 2), 4)); $blc_config_manager->options['server_load_limit'] = $default_load_limit; $blclog->info(sprintf('Set server load limit to %.2f. Current load average is %.2f', $default_load_limit, $fifteen_minutes)); } //And optimize my DB tables, too (for good measure) $blclog->info('Optimizing the database...');
/** * (Re)create synchronization records for all containers and mark them all as unparsed. * * @param bool $forced If true, the plugin will recreate all synch. records from scratch. * @return void */ function blc_resynch($forced = false) { global $wpdb, $blclog; /* @var wpdb $wpdb */ if ($forced) { $blclog->info('... Forced resynchronization initiated'); //Drop all synchronization records $wpdb->query("TRUNCATE {$wpdb->prefix}blc_synch"); } else { $blclog->info('... Resynchronization initiated'); } //Remove invalid DB entries blc_cleanup_database(); //(Re)create and update synch. records for all container types. $blclog->info('... (Re)creating container records'); blcContainerHelper::resynch($forced); $blclog->info('... Setting resync. flags'); blc_got_unsynched_items(); //All done. $blclog->info('Database resynchronization complete.'); }
function options_page() { global $blclog; $moduleManager = blcModuleManager::getInstance(); //Prior to 1.5.2 (released 2012-05-27), there was a bug that would cause the donation flag to be //set incorrectly. So we'll unset the flag in that case. $reset_donation_flag = $this->conf->get('first_installation_timestamp', 0) < strtotime('2012-05-27 00:00') && !$this->conf->get('donation_flag_fixed', false); if ($reset_donation_flag) { $this->conf->set('user_has_donated', false); $this->conf->set('donation_flag_fixed', true); $this->conf->save_options(); } if (isset($_POST['recheck']) && !empty($_POST['recheck'])) { $this->initiate_recheck(); //Redirect back to the settings page $base_url = remove_query_arg(array('_wpnonce', 'noheader', 'updated', 'error', 'action', 'message')); wp_redirect(add_query_arg(array('recheck-initiated' => true), $base_url)); die; } if (isset($_POST['submit'])) { check_admin_referer('link-checker-options'); //Activate/deactivate modules if (!empty($_POST['module'])) { $active = array_keys($_POST['module']); $moduleManager->set_active_modules($active); } //Only post statuses that actually exist can be selected if (isset($_POST['enabled_post_statuses']) && is_array($_POST['enabled_post_statuses'])) { $available_statuses = get_post_stati(); $enabled_post_statuses = array_intersect($_POST['enabled_post_statuses'], $available_statuses); } else { $enabled_post_statuses = array(); } //At least one status must be enabled; defaults to "Published". if (empty($enabled_post_statuses)) { $enabled_post_statuses = array('publish'); } $this->conf->options['enabled_post_statuses'] = $enabled_post_statuses; //The execution time limit must be above zero $new_execution_time = intval($_POST['max_execution_time']); if ($new_execution_time > 0) { $this->conf->options['max_execution_time'] = $new_execution_time; } //The check threshold also must be > 0 $new_check_threshold = intval($_POST['check_threshold']); if ($new_check_threshold > 0) { $this->conf->options['check_threshold'] = $new_check_threshold; } $this->conf->options['mark_broken_links'] = !empty($_POST['mark_broken_links']); $new_broken_link_css = trim($_POST['broken_link_css']); $this->conf->options['broken_link_css'] = $new_broken_link_css; $this->conf->options['mark_removed_links'] = !empty($_POST['mark_removed_links']); $new_removed_link_css = trim($_POST['removed_link_css']); $this->conf->options['removed_link_css'] = $new_removed_link_css; $this->conf->options['nofollow_broken_links'] = !empty($_POST['nofollow_broken_links']); $this->conf->options['exclusion_list'] = array_filter(preg_split('/[\\s\\r\\n]+/', $_POST['exclusion_list'], -1, PREG_SPLIT_NO_EMPTY)); //Parse the custom field list $new_custom_fields = array_filter(preg_split('/[\\r\\n]+/', $_POST['blc_custom_fields'], -1, PREG_SPLIT_NO_EMPTY)); //Calculate the difference between the old custom field list and the new one (used later) $diff1 = array_diff($new_custom_fields, $this->conf->options['custom_fields']); $diff2 = array_diff($this->conf->options['custom_fields'], $new_custom_fields); $this->conf->options['custom_fields'] = $new_custom_fields; //HTTP timeout $new_timeout = intval($_POST['timeout']); if ($new_timeout > 0) { $this->conf->options['timeout'] = $new_timeout; } //Server load limit if (isset($_POST['server_load_limit'])) { $this->conf->options['server_load_limit'] = floatval($_POST['server_load_limit']); if ($this->conf->options['server_load_limit'] < 0) { $this->conf->options['server_load_limit'] = 0; } $this->conf->options['enable_load_limit'] = $this->conf->options['server_load_limit'] > 0; } //When to run the checker $this->conf->options['run_in_dashboard'] = !empty($_POST['run_in_dashboard']); $this->conf->options['run_via_cron'] = !empty($_POST['run_via_cron']); //Email notifications on/off $email_notifications = !empty($_POST['send_email_notifications']); $send_authors_email_notifications = !empty($_POST['send_authors_email_notifications']); if ($email_notifications && !$this->conf->options['send_email_notifications'] || $send_authors_email_notifications && !$this->conf->options['send_authors_email_notifications']) { /* The plugin should only send notifications about links that have become broken since the time when email notifications were turned on. If we don't do this, the first email notification will be sent nigh-immediately and list *all* broken links that the plugin currently knows about. */ $this->conf->options['last_notification_sent'] = time(); } $this->conf->options['send_email_notifications'] = $email_notifications; $this->conf->options['send_authors_email_notifications'] = $send_authors_email_notifications; //Make settings that affect our Cron events take effect immediately $this->setup_cron_events(); $this->conf->save_options(); /* If the list of custom fields was modified then we MUST resynchronize or custom fields linked with existing posts may not be detected. This is somewhat inefficient. */ if (count($diff1) > 0 || count($diff2) > 0) { $manager = blcContainerHelper::get_manager('custom_field'); if (!is_null($manager)) { $manager->resynch(); blc_got_unsynched_items(); } } //Redirect back to the settings page $base_url = remove_query_arg(array('_wpnonce', 'noheader', 'updated', 'error', 'action', 'message')); wp_redirect(add_query_arg(array('settings-updated' => true), $base_url)); } //Show a confirmation message when settings are saved. if (!empty($_GET['settings-updated'])) { echo '<div id="message" class="updated fade"><p><strong>', __('Settings saved.', 'broken-link-checker'), '</strong></p></div>'; } //Show a thank-you message when a donation is made. if (!empty($_GET['donated'])) { echo '<div id="message" class="updated fade"><p><strong>', __('Thank you for your donation!', 'broken-link-checker'), '</strong></p></div>'; $this->conf->set('user_has_donated', true); $this->conf->save_options(); } //Show one when recheck is started, too. if (!empty($_GET['recheck-initiated'])) { echo '<div id="message" class="updated fade"><p><strong>', __('Complete site recheck started.', 'broken-link-checker'), '</strong></p></div>'; } //Cull invalid and missing modules $moduleManager->validate_active_modules(); $debug = $this->get_debug_info(); $details_text = __('Details', 'broken-link-checker'); add_filter('blc-module-settings-custom_field', array(&$this, 'make_custom_field_input'), 10, 2); //Translate and markup-ify module headers for display $modules = $moduleManager->get_modules_by_category('', true, true); //Output the custom broken link/removed link styles for example links printf('<style type="text/css">%s %s</style>', $this->conf->options['broken_link_css'], $this->conf->options['removed_link_css']); $section_names = array('general' => __('General', 'broken-link-checker'), 'where' => __('Look For Links In', 'broken-link-checker'), 'which' => __('Which Links To Check', 'broken-link-checker'), 'how' => __('Protocols & APIs', 'broken-link-checker'), 'advanced' => __('Advanced', 'broken-link-checker')); ?> <!--[if lte IE 7]> <style type="text/css"> /* Simulate inline-block in IE7 */ ul.ui-tabs-nav li { display: inline; zoom: 1; } </style> <![endif]--> <div class="wrap" id="blc-settings-wrap"> <?php screen_icon(); ?> <h2><?php _e('Broken Link Checker Options', 'broken-link-checker'); ?> </h2> <div id="blc-sidebar"> <div class="metabox-holder"> <?php include BLC_DIRECTORY . '/includes/admin/sidebar.php'; ?> </div> </div> <div id="blc-admin-content"> <form name="link_checker_options" id="link_checker_options" method="post" action="<?php echo admin_url('options-general.php?page=link-checker-settings&noheader=1'); ?> "> <?php wp_nonce_field('link-checker-options'); ?> <div id="blc-tabs"> <ul class="hide-if-no-js"> <?php foreach ($section_names as $section_id => $section_name) { printf('<li id="tab-button-%s"><a href="#section-%s" title="%s">%s</a></li>', esc_attr($section_id), esc_attr($section_id), esc_attr($section_name), $section_name); } ?> </ul> <div id="section-general" class="blc-section"> <h3 class="hide-if-js"><?php echo $section_names['general']; ?> </h3> <table class="form-table"> <tr valign="top"> <th scope="row"> <?php _e('Status', 'broken-link-checker'); ?> <br> <a href="javascript:void(0)" id="blc-debug-info-toggle"><?php _e('Show debug info', 'broken-link-checker'); ?> </a> </th> <td> <div id='wsblc_full_status'> <br/><br/><br/> </div> <table id="blc-debug-info"> <?php //Output the debug info in a table foreach ($debug as $key => $value) { printf('<tr valign="top" class="blc-debug-item-%s"><th scope="row">%s</th><td>%s<div class="blc-debug-message">%s</div></td></tr>', $value['state'], $key, $value['value'], array_key_exists('message', $value) ? $value['message'] : ''); } ?> </table> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Check each link', 'broken-link-checker'); ?> </th> <td> <?php printf(__('Every %s hours', 'broken-link-checker'), sprintf('<input type="text" name="check_threshold" id="check_threshold" value="%d" size="5" maxlength="5" />', $this->conf->options['check_threshold'])); ?> <br/> <span class="description"> <?php _e('Existing links will be checked this often. New links will usually be checked ASAP.', 'broken-link-checker'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('E-mail notifications', 'broken-link-checker'); ?> </th> <td> <p style="margin-top: 0;"> <label for='send_email_notifications'> <input type="checkbox" name="send_email_notifications" id="send_email_notifications" <?php if ($this->conf->options['send_email_notifications']) { echo ' checked="checked"'; } ?> /> <?php _e('Send me e-mail notifications about newly detected broken links', 'broken-link-checker'); ?> </label><br /> </p> <p> <label for='send_authors_email_notifications'> <input type="checkbox" name="send_authors_email_notifications" id="send_authors_email_notifications" <?php if ($this->conf->options['send_authors_email_notifications']) { echo ' checked="checked"'; } ?> /> <?php _e('Send authors e-mail notifications about broken links in their posts', 'broken-link-checker'); ?> </label><br /> </p> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Link tweaks', 'broken-link-checker'); ?> </th> <td> <p style="margin-top: 0; margin-bottom: 0.5em;"> <label for='mark_broken_links'> <input type="checkbox" name="mark_broken_links" id="mark_broken_links" <?php if ($this->conf->options['mark_broken_links']) { echo ' checked="checked"'; } ?> /> <?php _e('Apply custom formatting to broken links', 'broken-link-checker'); ?> </label> | <a id="toggle-broken-link-css-editor" href="#" class="blc-toggle-link"><?php _e('Edit CSS', 'broken-link-checker'); ?> </a> </p> <div id="broken-link-css-wrap"<?php if (!blcUtility::get_cookie('broken-link-css-wrap', false)) { echo ' class="hidden"'; } ?> > <textarea name="broken_link_css" id="broken_link_css" cols='45' rows='4'/><?php if (isset($this->conf->options['broken_link_css'])) { echo $this->conf->options['broken_link_css']; } ?> </textarea> <p class="description"><?php printf(__('Example : Lorem ipsum <a %s>broken link</a>, dolor sit amet.', 'broken-link-checker'), ' href="#" class="broken_link" onclick="return false;"'); echo ' ', __('Click "Save Changes" to update example output.', 'broken-link-checker'); ?> </p> </div> <p style="margin-bottom: 0.5em;"> <label for='mark_removed_links'> <input type="checkbox" name="mark_removed_links" id="mark_removed_links" <?php if ($this->conf->options['mark_removed_links']) { echo ' checked="checked"'; } ?> /> <?php _e('Apply custom formatting to removed links', 'broken-link-checker'); ?> </label> | <a id="toggle-removed-link-css-editor" href="#" class="blc-toggle-link"><?php _e('Edit CSS', 'broken-link-checker'); ?> </a> </p> <div id="removed-link-css-wrap" <?php if (!blcUtility::get_cookie('removed-link-css-wrap', false)) { echo ' class="hidden"'; } ?> > <textarea name="removed_link_css" id="removed_link_css" cols='45' rows='4'/><?php if (isset($this->conf->options['removed_link_css'])) { echo $this->conf->options['removed_link_css']; } ?> </textarea> <p class="description"><?php printf(__('Example : Lorem ipsum <span %s>removed link</span>, dolor sit amet.', 'broken-link-checker'), ' class="removed_link"'); echo ' ', __('Click "Save Changes" to update example output.', 'broken-link-checker'); ?> </p> </div> <p> <label for='nofollow_broken_links'> <input type="checkbox" name="nofollow_broken_links" id="nofollow_broken_links" <?php if ($this->conf->options['nofollow_broken_links']) { echo ' checked="checked"'; } ?> /> <?php _e('Stop search engines from following broken links', 'broken-link-checker'); ?> </label> </p> </td> </tr> </table> </div> <div id="section-where" class="blc-section"> <h3 class="hide-if-js"><?php echo $section_names['where']; ?> </h3> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Look for links in', 'broken-link-checker'); ?> </th> <td> <?php if (!empty($modules['container'])) { uasort($modules['container'], create_function('$a, $b', 'return strcasecmp($a["Name"], $b["Name"]);')); $this->print_module_list($modules['container'], $this->conf->options); } ?> </td></tr> <tr valign="top"> <th scope="row"><?php _e('Post statuses', 'broken-link-checker'); ?> </th> <td> <?php $available_statuses = get_post_stati(array('internal' => false), 'objects'); if (isset($this->conf->options['enabled_post_statuses'])) { $enabled_post_statuses = $this->conf->options['enabled_post_statuses']; } else { $enabled_post_statuses = array(); } foreach ($available_statuses as $status => $status_object) { printf('<p><label><input type="checkbox" name="enabled_post_statuses[]" value="%s"%s> %s</label></p>', esc_attr($status), in_array($status, $enabled_post_statuses) ? ' checked="checked"' : '', $status_object->label); } ?> </td></tr> </table> </div> <div id="section-which" class="blc-section"> <h3 class="hide-if-js"><?php echo $section_names['which']; ?> </h3> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Link types', 'broken-link-checker'); ?> </th> <td> <?php if (!empty($modules['parser'])) { $this->print_module_list($modules['parser'], $this->conf->options); } else { echo __('Error : All link parsers missing!', 'broken-link-checker'); } ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Exclusion list', 'broken-link-checker'); ?> </th> <td><?php _e("Don't check links where the URL contains any of these words (one per line) :", 'broken-link-checker'); ?> <br/> <textarea name="exclusion_list" id="exclusion_list" cols='45' rows='4' wrap='off'/><?php if (isset($this->conf->options['exclusion_list'])) { echo implode("\n", $this->conf->options['exclusion_list']); } ?> </textarea> </td> </tr> </table> </div> <div id="section-how" class="blc-section"> <h3 class="hide-if-js"><?php echo $section_names['how']; ?> </h3> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Check links using', 'broken-link-checker'); ?> </th> <td> <?php if (!empty($modules['checker'])) { $modules['checker'] = array_reverse($modules['checker']); $this->print_module_list($modules['checker'], $this->conf->options); } ?> </td></tr> </table> </div> <div id="section-advanced" class="blc-section"> <h3 class="hide-if-js"><?php echo $section_names['advanced']; ?> </h3> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Timeout', 'broken-link-checker'); ?> </th> <td> <?php printf(__('%s seconds', 'broken-link-checker'), sprintf('<input type="text" name="timeout" id="blc_timeout" value="%d" size="5" maxlength="3" />', $this->conf->options['timeout'])); ?> <br/><span class="description"> <?php _e('Links that take longer than this to load will be marked as broken.', 'broken-link-checker'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Link monitor', 'broken-link-checker'); ?> </th> <td> <p> <label for='run_in_dashboard'> <input type="checkbox" name="run_in_dashboard" id="run_in_dashboard" <?php if ($this->conf->options['run_in_dashboard']) { echo ' checked="checked"'; } ?> /> <?php _e('Run continuously while the Dashboard is open', 'broken-link-checker'); ?> </label> </p> <p> <label for='run_via_cron'> <input type="checkbox" name="run_via_cron" id="run_via_cron" <?php if ($this->conf->options['run_via_cron']) { echo ' checked="checked"'; } ?> /> <?php _e('Run hourly in the background', 'broken-link-checker'); ?> </label> </p> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Max. execution time', 'broken-link-checker'); ?> </th> <td> <?php printf(__('%s seconds', 'broken-link-checker'), sprintf('<input type="text" name="max_execution_time" id="max_execution_time" value="%d" size="5" maxlength="5" />', $this->conf->options['max_execution_time'])); ?> <br/><span class="description"> <?php _e('The plugin works by periodically launching a background job that parses your posts for links, checks the discovered URLs, and performs other time-consuming tasks. Here you can set for how long, at most, the link monitor may run each time before stopping.', 'broken-link-checker'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Server load limit', 'broken-link-checker'); ?> </th> <td> <?php $load = blcUtility::get_server_load(); $available = !empty($load); if ($available) { $value = !empty($this->conf->options['server_load_limit']) ? sprintf('%.2f', $this->conf->options['server_load_limit']) : ''; printf('<input type="text" name="server_load_limit" id="server_load_limit" value="%s" size="5" maxlength="5"/> ', $value); printf(__('Current load : %s', 'broken-link-checker'), '<span id="wsblc_current_load">...</span>'); echo '<br/><span class="description">'; printf(__('Link checking will be suspended if the average <a href="%s">server load</a> rises above this number. Leave this field blank to disable load limiting.', 'broken-link-checker'), 'http://en.wikipedia.org/wiki/Load_(computing)'); echo '</span>'; } else { echo '<input type="text" disabled="disabled" value="', esc_attr(__('Not available', 'broken-link-checker')), '" size="13"/><br>'; echo '<span class="description">'; _e('Load limiting only works on Linux-like systems where <code>/proc/loadavg</code> is present and accessible.', 'broken-link-checker'); echo '</span>'; } ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Forced recheck', 'broken-link-checker'); ?> </th> <td> <input class="button" type="button" name="start-recheck" id="start-recheck" value="<?php _e('Re-check all pages', 'broken-link-checker'); ?> " /> <input type="hidden" name="recheck" value="" id="recheck" /> <br /> <span class="description"><?php _e('The "Nuclear Option". Click this button to make the plugin empty its link database and recheck the entire site from scratch.', 'broken-link-checker'); ?> </span> </td> </tr> </table> </div> </div> <p class="submit"><input type="submit" name="submit" class='button-primary' value="<?php _e('Save Changes'); ?> " /></p> </form> </div> <!-- First postbox-container --> </div> <?php //The various JS for this page is stored in a separate file for the purposes readability. include dirname($this->loader) . '/includes/admin/options-page-js.php'; }
/** * Mark as unparsed all containers that match one of the the specified formats or * container types and that were last parsed after a specific timestamp. * * Used by newly activated parsers to force the containers they're interested in * to resynchronize and thus let the parser process them. * * @param array $formats Associative array of timestamps, indexed by format IDs. * @param array $container_types Associative array of timestamps, indexed by container types. * @return bool */ static function mark_as_unsynched_where($formats, $container_types) { global $wpdb; /* @var wpdb $wpdb */ global $blclog; //Find containers that match any of the specified formats and add them to //the list of container types that need to be marked as unsynched. $module_manager = blcModuleManager::getInstance(); $containers = $module_manager->get_active_by_category('container'); foreach ($containers as $module_id => $module_data) { if ($container_manager = $module_manager->get_module($module_id)) { $fields = $container_manager->get_parseable_fields(); $container_type = $container_manager->container_type; foreach ($formats as $format => $timestamp) { if (in_array($format, $fields)) { //Choose the earliest timestamp if (isset($container_types[$container_type])) { $container_types[$container_type] = min($timestamp, $container_types[$container_type]); } else { $container_types[$container_type] = $timestamp; } } } } } if (empty($container_types)) { return true; } //Build the query to update all synch. records that match one of the specified //container types and have been parsed after the specified time. $q = "UPDATE {$wpdb->prefix}blc_synch SET synched = 0 WHERE "; $pieces = array(); foreach ($container_types as $container_type => $timestamp) { $pieces[] = $wpdb->prepare('(container_type = %s AND last_synch >= %s)', $container_type, date('Y-m-d H:i:s', $timestamp)); } $q .= implode(' OR ', $pieces); $blclog->log('...... Executing query: ' . $q); $start_time = microtime(true); $rez = $wpdb->query($q) !== false; $blclog->log(sprintf('...... %d rows affected, %.3f seconds', $wpdb->rows_affected, microtime(true) - $start_time)); blc_got_unsynched_items(); return $rez; }
/** * blcContainer::mark_as_unsynched() * Mark the container as not synchronized (not parsed, or modified since the last parse). * The plugin will attempt to (re)parse the container at the earliest opportunity. * * @return bool */ function mark_as_unsynched() { global $wpdb; $q = "INSERT INTO {$wpdb->prefix}blc_synch( container_id, container_type, synched, last_synch)\r\n\t\t\t VALUES( %d, %s, %d, '0000-00-00 00:00:00' )\r\n\t\t\t ON DUPLICATE KEY UPDATE synched = VALUES(synched)"; $rez = $wpdb->query($wpdb->prepare($q, $this->container_id, $this->container_type, 0)); blc_got_unsynched_items(); return $rez !== false; }
/** * (Re)create synchronization records for all containers and mark them all as unparsed. * * @param bool $forced If true, the plugin will recreate all synch. records from scratch. * @return void */ function blc_resynch($forced = false) { global $wpdb, $blclog; if ($forced) { $blclog->info('... Forced resynchronization initiated'); //Drop all synchronization records $wpdb->query("TRUNCATE {$wpdb->prefix}blc_synch"); } else { $blclog->info('... Resynchronization initiated'); } //(Re)create and update synch. records for all container types. $blclog->info('... (Re)creating container records'); blc_resynch_containers($forced); //Delete invalid instances $blclog->info('... Deleting invalid link instances'); blc_cleanup_instances(); //Delete orphaned links $blclog->info('... Deleting orphaned links'); blc_cleanup_links(); $blclog->info('... Setting resync. flags'); blc_got_unsynched_items(); //All done. $blclog->info('Database resynchronization complete.'); }
function options_page() { global $blc_container_registry; //Sanity check : make sure the DB is all set up if ($this->db_version != $this->conf->options['current_db_version']) { printf(__("Error: The plugin's database tables are not up to date! (Current version : %d, expected : %d)", 'broken-link-checker'), $this->conf->options['current_db_version'], $this->db_version); return; } if (isset($_GET['recheck']) && $_GET['recheck'] == 'true') { $this->initiate_recheck(); } if (isset($_POST['submit'])) { check_admin_referer('link-checker-options'); //The execution time limit must be above zero $new_execution_time = intval($_POST['max_execution_time']); if ($new_execution_time > 0) { $this->conf->options['max_execution_time'] = $new_execution_time; } //The check threshold also must be > 0 $new_check_threshold = intval($_POST['check_threshold']); if ($new_check_threshold > 0) { $this->conf->options['check_threshold'] = $new_check_threshold; } $this->conf->options['mark_broken_links'] = !empty($_POST['mark_broken_links']); $new_broken_link_css = trim($_POST['broken_link_css']); $this->conf->options['broken_link_css'] = $new_broken_link_css; $this->conf->options['mark_removed_links'] = !empty($_POST['mark_removed_links']); $new_removed_link_css = trim($_POST['removed_link_css']); $this->conf->options['removed_link_css'] = $new_removed_link_css; $this->conf->options['nofollow_broken_links'] = !empty($_POST['nofollow_broken_links']); $this->conf->options['exclusion_list'] = array_filter(preg_split('/[\\s\\r\\n]+/', $_POST['exclusion_list'], -1, PREG_SPLIT_NO_EMPTY)); //Parse the custom field list $new_custom_fields = array_filter(preg_split('/[\\s\\r\\n]+/', $_POST['blc_custom_fields'], -1, PREG_SPLIT_NO_EMPTY)); //Calculate the difference between the old custom field list and the new one (used later) $diff1 = array_diff($new_custom_fields, $this->conf->options['custom_fields']); $diff2 = array_diff($this->conf->options['custom_fields'], $new_custom_fields); $this->conf->options['custom_fields'] = $new_custom_fields; //Temporary file directory $this->conf->options['custom_tmp_dir'] = trim(stripslashes(strval($_POST['custom_tmp_dir']))); //HTTP timeout $new_timeout = intval($_POST['timeout']); if ($new_timeout > 0) { $this->conf->options['timeout'] = $new_timeout; } //Server load limit if (isset($_POST['server_load_limit'])) { $this->conf->options['server_load_limit'] = floatval($_POST['server_load_limit']); if ($this->conf->options['server_load_limit'] < 0) { $this->conf->options['server_load_limit'] = 0; } $this->conf->options['enable_load_limit'] = $this->conf->options['server_load_limit'] > 0; } //When to run the checker $this->conf->options['run_in_dashboard'] = !empty($_POST['run_in_dashboard']); $this->conf->options['run_via_cron'] = !empty($_POST['run_via_cron']); //Email notifications on/off $email_notifications = !empty($_POST['send_email_notifications']); if ($email_notifications && !$this->conf->options['send_email_notifications']) { /* The plugin should only send notifications about links that have become broken since the time when email notifications were turned on. If we don't do this, the first email notification will be sent nigh-immediately and list *all* broken links that the plugin currently knows about. */ $this->options['last_notification_sent'] = time(); } $this->conf->options['send_email_notifications'] = $email_notifications; //Make settings that affect our Cron events take effect immediately $this->setup_cron_events(); $this->conf->save_options(); /* If the list of custom fields was modified then we MUST resynchronize or custom fields linked with existing posts may not be detected. This is somewhat inefficient. */ if (count($diff1) > 0 || count($diff2) > 0) { $manager = $blc_container_registry->get_manager('custom_field'); if (!is_null($manager)) { $manager->resynch(); blc_got_unsynched_items(); } } //Redirect back to the settings page $base_url = remove_query_arg(array('_wpnonce', 'noheader', 'updated', 'error', 'action', 'message')); wp_redirect(add_query_arg(array('settings-updated' => true), $base_url)); } //Show a confirmation message when settings are saved. if (!empty($_GET['settings-updated'])) { echo '<div id="message" class="updated fade"><p><strong>', __('Settings saved.', 'broken-link-checker'), '</strong></p></div>'; } $debug = $this->get_debug_info(); $this->print_uservoice_widget(); ?> <div class="wrap"><h2><?php _e('Broken Link Checker Options', 'broken-link-checker'); ?> </h2> <form name="link_checker_options" method="post" action="<?php echo admin_url('options-general.php?page=link-checker-settings&noheader=1'); ?> "> <?php wp_nonce_field('link-checker-options'); ?> <table class="form-table"> <tr valign="top"> <th scope="row"> <?php _e('Status', 'broken-link-checker'); ?> <br> <a href="javascript:void(0)" id="blc-debug-info-toggle"><?php _e('Show debug info', 'broken-link-checker'); ?> </a> </th> <td> <div id='wsblc_full_status'> <br/><br/><br/> </div> <script type='text/javascript'> (function($){ function blcUpdateStatus(){ $.getJSON( "<?php echo admin_url('admin-ajax.php'); ?> ", { 'action' : 'blc_full_status' }, function (data, textStatus){ if ( data && ( typeof(data['text']) != 'undefined' ) ){ $('#wsblc_full_status').html(data.text); } else { $('#wsblc_full_status').html('<?php _e('[ Network error ]', 'broken-link-checker'); ?> '); } setTimeout(blcUpdateStatus, 10000); //...update every 10 seconds } ); } blcUpdateStatus();//Call it the first time })(jQuery); </script> <?php //JHS: Recheck all posts link: ?> <p><input class="button" type="button" name="recheckbutton" value="<?php _e('Re-check all pages', 'broken-link-checker'); ?> " onclick="location.replace('<?php echo basename($_SERVER['PHP_SELF']); ?> ?page=link-checker-settings&recheck=true')" /> </p> <table id="blc-debug-info"> <?php //Output the debug info in a table foreach ($debug as $key => $value) { printf('<tr valign="top" class="blc-debug-item-%s"><th scope="row">%s</th><td>%s<div class="blc-debug-message">%s</div></td></tr>', $value['state'], $key, $value['value'], array_key_exists('message', $value) ? $value['message'] : ''); } ?> </table> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Check each link', 'broken-link-checker'); ?> </th> <td> <?php printf(__('Every %s hours', 'broken-link-checker'), sprintf('<input type="text" name="check_threshold" id="check_threshold" value="%d" size="5" maxlength="5" />', $this->conf->options['check_threshold'])); ?> <br/> <span class="description"> <?php _e('Existing links will be checked this often. New links will usually be checked ASAP.', 'broken-link-checker'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Broken link CSS', 'broken-link-checker'); ?> </th> <td> <label for='mark_broken_links'> <input type="checkbox" name="mark_broken_links" id="mark_broken_links" <?php if ($this->conf->options['mark_broken_links']) { echo ' checked="checked"'; } ?> /> <?php _e('Apply <em>class="broken_link"</em> to broken links', 'broken-link-checker'); ?> </label> <br/> <textarea name="broken_link_css" id="broken_link_css" cols='45' rows='4'/><?php if (isset($this->conf->options['broken_link_css'])) { echo $this->conf->options['broken_link_css']; } ?> </textarea> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Removed link CSS', 'broken-link-checker'); ?> </th> <td> <label for='mark_removed_links'> <input type="checkbox" name="mark_removed_links" id="mark_removed_links" <?php if ($this->conf->options['mark_removed_links']) { echo ' checked="checked"'; } ?> /> <?php _e('Apply <em>class="removed_link"</em> to unlinked links', 'broken-link-checker'); ?> </label> <br/> <textarea name="removed_link_css" id="removed_link_css" cols='45' rows='4'/><?php if (isset($this->conf->options['removed_link_css'])) { echo $this->conf->options['removed_link_css']; } ?> </textarea> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Broken link SEO', 'broken-link-checker'); ?> </th> <td> <label for='nofollow_broken_links'> <input type="checkbox" name="nofollow_broken_links" id="nofollow_broken_links" <?php if ($this->conf->options['nofollow_broken_links']) { echo ' checked="checked"'; } ?> /> <?php _e('Apply <em>rel="nofollow"</em> to broken links', 'broken-link-checker'); ?> </label> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Exclusion list', 'broken-link-checker'); ?> </th> <td><?php _e("Don't check links where the URL contains any of these words (one per line) :", 'broken-link-checker'); ?> <br/> <textarea name="exclusion_list" id="exclusion_list" cols='45' rows='4' wrap='off'/><?php if (isset($this->conf->options['exclusion_list'])) { echo implode("\n", $this->conf->options['exclusion_list']); } ?> </textarea> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Custom fields', 'broken-link-checker'); ?> </th> <td><?php _e('Check URLs entered in these custom fields (one per line) :', 'broken-link-checker'); ?> <br/> <textarea name="blc_custom_fields" id="blc_custom_fields" cols='45' rows='4' /><?php if (isset($this->conf->options['custom_fields'])) { echo implode("\n", $this->conf->options['custom_fields']); } ?> </textarea> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('E-mail notifications', 'broken-link-checker'); ?> </th> <td> <p style="margin-top: 0px;"> <label for='send_email_notifications'> <input type="checkbox" name="send_email_notifications" id="send_email_notifications" <?php if ($this->conf->options['send_email_notifications']) { echo ' checked="checked"'; } ?> /> <?php _e('Send me e-mail notifications about newly detected broken links', 'broken-link-checker'); ?> </label><br> </p> </td> </tr> </table> <h3><?php _e('Advanced', 'broken-link-checker'); ?> </h3> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Timeout', 'broken-link-checker'); ?> </th> <td> <?php printf(__('%s seconds', 'broken-link-checker'), sprintf('<input type="text" name="timeout" id="blc_timeout" value="%d" size="5" maxlength="3" />', $this->conf->options['timeout'])); ?> <br/><span class="description"> <?php _e('Links that take longer than this to load will be marked as broken.', 'broken-link-checker'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Link monitor', 'broken-link-checker'); ?> </th> <td> <label for='run_in_dashboard'> <p> <input type="checkbox" name="run_in_dashboard" id="run_in_dashboard" <?php if ($this->conf->options['run_in_dashboard']) { echo ' checked="checked"'; } ?> /> <?php _e('Run continuously while the Dashboard is open', 'broken-link-checker'); ?> </p> </label> <label for='run_via_cron'> <p> <input type="checkbox" name="run_via_cron" id="run_via_cron" <?php if ($this->conf->options['run_via_cron']) { echo ' checked="checked"'; } ?> /> <?php _e('Run hourly in the background', 'broken-link-checker'); ?> </p> </label> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Max. execution time', 'broken-link-checker'); ?> </th> <td> <?php printf(__('%s seconds', 'broken-link-checker'), sprintf('<input type="text" name="max_execution_time" id="max_execution_time" value="%d" size="5" maxlength="5" />', $this->conf->options['max_execution_time'])); ?> <br/><span class="description"> <?php _e('The plugin works by periodically launching a background job that parses your posts for links, checks the discovered URLs, and performs other time-consuming tasks. Here you can set for how long, at most, the link monitor may run each time before stopping.', 'broken-link-checker'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"> <a name='lockfile_directory'></a><?php _e('Custom temporary directory', 'broken-link-checker'); ?> </th> <td> <input type="text" name="custom_tmp_dir" id="custom_tmp_dir" value="<?php echo htmlspecialchars($this->conf->options['custom_tmp_dir']); ?> " size='53' maxlength='500'/> <?php if (!empty($this->conf->options['custom_tmp_dir'])) { if (@is_dir($this->conf->options['custom_tmp_dir'])) { if (@is_writable($this->conf->options['custom_tmp_dir'])) { echo "<strong>", __('OK', 'broken-link-checker'), "</strong>"; } else { echo '<span class="error">'; _e("Error : This directory isn't writable by PHP.", 'broken-link-checker'); echo '</span>'; } } else { echo '<span class="error">'; _e("Error : This directory doesn't exist.", 'broken-link-checker'); echo '</span>'; } } ?> <br/> <span class="description"> <?php _e('Set this field if you want the plugin to use a custom directory for its lockfiles. Otherwise, leave it blank.', 'broken-link-checker'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Server load limit', 'broken-link-checker'); ?> </th> <td> <?php $load = $this->get_server_load(); $available = !empty($load); if ($available) { $value = !empty($this->conf->options['server_load_limit']) ? sprintf('%.2f', $this->conf->options['server_load_limit']) : ''; printf('<input type="text" name="server_load_limit" id="server_load_limit" value="%s" size="5" maxlength="5"/> ', $value); ?> Current load : <span id='wsblc_current_load'>...</span> <script type='text/javascript'> (function($){ function blcUpdateLoad(){ $.get( "<?php echo admin_url('admin-ajax.php'); ?> ", { 'action' : 'blc_current_load' }, function (data, textStatus){ $('#wsblc_current_load').html(data); setTimeout(blcUpdateLoad, 10000); //...update every 10 seconds } ); } blcUpdateLoad();//Call it the first time })(jQuery); </script> <?php echo '<br/><span class="description">'; printf(__('Link checking will be suspended if the average <a href="%s">server load</a> rises above this number. Leave this field blank to disable load limiting.', 'broken-link-checker'), 'http://en.wikipedia.org/wiki/Load_(computing)'); echo '</span>'; } else { echo '<input type="text" disabled="disabled" value="Not available" size="13"/><br>'; echo '<span class="description">'; _e('Load limiting only works on Linux-like systems where <code>/proc/loadavg</code> is present and accessible.', 'broken-link-checker'); echo '</span>'; } ?> </td> </tr> </table> <p class="submit"><input type="submit" name="submit" class='button-primary' value="<?php _e('Save Changes'); ?> " /></p> </form> </div> <script type='text/javascript'> jQuery(function($){ var toggleButton = $('#blc-debug-info-toggle'); toggleButton.click(function(){ var box = $('#blc-debug-info'); box.toggle(); if( box.is(':visible') ){ toggleButton.text('<?php _e('Hide debug info', 'broken-link-checker'); ?> '); } else { toggleButton.text('<?php _e('Show debug info', 'broken-link-checker'); ?> '); } }); }); </script> <?php }