function blc_print_installation_errors() { global $blc_config_manager, $wpdb; /** @var wpdb $wpdb */ if ($blc_config_manager->options['installation_complete']) { return; } $messages = array('<strong>' . __('Broken Link Checker installation failed. Try deactivating and then reactivating the plugin.', 'broken-link-checker') . '</strong>'); if (!$blc_config_manager->db_option_loaded) { $messages[] = sprintf('<strong>Failed to load plugin settings from the "%s" option.</strong>', $blc_config_manager->option_name); $messages[] = ''; $serialized_config = $wpdb->get_var(sprintf('SELECT option_value FROM `%s` WHERE option_name = "%s"', $wpdb->options, $blc_config_manager->option_name)); if ($serialized_config === null) { $messages[] = "Option doesn't exist in the {$wpdb->options} table."; } else { $messages[] = "Option exists in the {$wpdb->options} table and has the following value:"; $messages[] = ''; $messages[] = '<textarea cols="120" rows="20">' . htmlentities($serialized_config) . '</textarea>'; } } else { $logger = new blcCachedOptionLogger('blc_installation_log'); $messages = array_merge($messages, array('installation_complete = ' . (isset($blc_config_manager->options['installation_complete']) ? intval($blc_config_manager->options['installation_complete']) : 'no value'), 'installation_flag_cleared_on = ' . $blc_config_manager->options['installation_flag_cleared_on'], 'installation_flag_set_on = ' . $blc_config_manager->options['installation_flag_set_on'], '', '<em>Installation log follows :</em>'), $logger->get_messages()); } echo "<div class='error'><p>", implode("<br>\n", $messages), "</p></div>"; }
<?php global $blclog, $blc_config_manager, $wpdb; $queryCnt = $wpdb->num_queries; //Completing the installation/upgrade is required for the plugin to work, so make sure //the script doesn't get aborted by (for example) the browser timing out. set_time_limit(300); //5 minutes should be plenty, anything more would probably indicate an infinite loop or a deadlock ignore_user_abort(true); //Log installation progress to a DB option $blclog = new blcCachedOptionLogger('blc_installation_log'); register_shutdown_function(array(&$blclog, 'save')); //Make sure the log is saved even if the plugin crashes $blclog->clear(); $blclog->info(sprintf('Plugin activated at %s.', date_i18n('Y-m-d H:i:s'))); $activation_start = microtime(true); //Reset the "installation_complete" flag $blc_config_manager->options['installation_complete'] = false; $blc_config_manager->options['installation_flag_cleared_on'] = date('c') . ' (' . microtime(true) . ')'; //Note the time of the first installation (not very accurate, but still useful) if (empty($blc_config_manager->options['first_installation_timestamp'])) { $blc_config_manager->options['first_installation_timestamp'] = time(); } $blc_config_manager->save_options(); $blclog->info('Installation/update begins.'); //Load the base classes and utilities require_once BLC_DIRECTORY . '/includes/links.php'; require_once BLC_DIRECTORY . '/includes/link-query.php'; require_once BLC_DIRECTORY . '/includes/instances.php'; require_once BLC_DIRECTORY . '/includes/utility-class.php'; //Load the module subsystem
function blc_print_installation_errors() { global $blc_config_manager; if ($blc_config_manager->options['installation_complete']) { return; } $logger = new blcCachedOptionLogger('blc_installation_log'); $messages = array_merge(array('<strong>' . __('Broken Link Checker installation failed. Try deactivating and then reactivating the plugin.', 'broken-link-checker') . '</strong>', '', '<em>Installation log follows :</em>'), $logger->get_messages()); echo "<div class='error'><p>", implode("<br>\n", $messages), "</p></div>"; }
/** * Collect various debugging information and return it in an associative array * * @return array */ function get_debug_info() { /** @var wpdb $wpdb */ global $wpdb; //Collect some information that's useful for debugging $debug = array(); //PHP version. Any one is fine as long as WP supports it. $debug[__('PHP version', 'broken-link-checker')] = array('state' => 'ok', 'value' => phpversion()); //MySQL version $debug[__('MySQL version', 'broken-link-checker')] = array('state' => 'ok', 'value' => $wpdb->db_version()); //CURL presence and version if (function_exists('curl_version')) { $version = curl_version(); if (version_compare($version['version'], '7.16.0', '<=')) { $data = array('state' => 'warning', 'value' => $version['version'], 'message' => __('You have an old version of CURL. Redirect detection may not work properly.', 'broken-link-checker')); } else { $data = array('state' => 'ok', 'value' => $version['version']); } } else { $data = array('state' => 'warning', 'value' => __('Not installed', 'broken-link-checker')); } $debug[__('CURL version', 'broken-link-checker')] = $data; //Snoopy presence if (class_exists('Snoopy') || file_exists(ABSPATH . WPINC . '/class-snoopy.php')) { $data = array('state' => 'ok', 'value' => __('Installed', 'broken-link-checker')); } else { //No Snoopy? This should never happen, but if it does we *must* have CURL. if (function_exists('curl_init')) { $data = array('state' => 'ok', 'value' => __('Not installed', 'broken-link-checker')); } else { $data = array('state' => 'error', 'value' => __('Not installed', 'broken-link-checker'), 'message' => __('You must have either CURL or Snoopy installed for the plugin to work!', 'broken-link-checker')); } } $debug['Snoopy'] = $data; //Safe_mode status if (blcUtility::is_safe_mode()) { $debug['Safe mode'] = array('state' => 'warning', 'value' => __('On', 'broken-link-checker'), 'message' => __('Redirects may be detected as broken links when safe_mode is on.', 'broken-link-checker')); } else { $debug['Safe mode'] = array('state' => 'ok', 'value' => __('Off', 'broken-link-checker')); } //Open_basedir status if (blcUtility::is_open_basedir()) { $debug['open_basedir'] = array('state' => 'warning', 'value' => sprintf(__('On ( %s )', 'broken-link-checker'), ini_get('open_basedir')), 'message' => __('Redirects may be detected as broken links when open_basedir is on.', 'broken-link-checker')); } else { $debug['open_basedir'] = array('state' => 'ok', 'value' => __('Off', 'broken-link-checker')); } //Default PHP execution time limit $debug['Default PHP execution time limit'] = array('state' => 'ok', 'value' => sprintf(__('%s seconds'), ini_get('max_execution_time'))); //Resynch flag. $debug['Resynch. flag'] = array('state' => 'ok', 'value' => sprintf('%d', $this->conf->options['need_resynch'] ? '1 (resynch. required)' : '0 (resynch. not required)')); //Synch records $synch_records = intval($wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}blc_synch")); $data = array('state' => 'ok', 'value' => sprintf('%d', $synch_records)); if ($synch_records == 0) { $data['state'] = 'warning'; $data['message'] = __('If this value is zero even after several page reloads you have probably encountered a bug.', 'broken-link-checker'); } $debug['Synch. records'] = $data; //Total links and instances (including invalid ones) $all_links = intval($wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}blc_links")); $all_instances = intval($wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}blc_instances")); //Show the number of unparsed containers. Useful for debugging. For performance, //this is only shown when we have no links/instances yet. if ($all_links == 0 && $all_instances == 0) { $unparsed_items = intval($wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}blc_synch WHERE synched=0")); $debug['Unparsed items'] = array('state' => 'warning', 'value' => $unparsed_items); } //Links & instances if ($all_links > 0 && $all_instances > 0) { $debug['Link records'] = array('state' => 'ok', 'value' => sprintf('%d (%d)', $all_links, $all_instances)); } else { $debug['Link records'] = array('state' => 'warning', 'value' => sprintf('%d (%d)', $all_links, $all_instances)); } //Installation log $logger = new blcCachedOptionLogger('blc_installation_log'); $installation_log = $logger->get_messages(); if (!empty($installation_log)) { $debug['Installation log'] = array('state' => $this->conf->options['installation_complete'] ? 'ok' : 'error', 'value' => implode("<br>\n", $installation_log)); } else { $debug['Installation log'] = array('state' => 'warning', 'value' => 'No installation log found found.'); } return $debug; }
<?php global $blclog, $blc_config_manager, $wpdb; $queryCnt = $wpdb->num_queries; //Completing the installation/upgrade is required for the plugin to work, so make sure //the script doesn't get aborted by (for example) the browser timing out. set_time_limit(300); //5 minutes should be plenty, anything more would probably indicate an infinite loop or a deadlock ignore_user_abort(true); //Log installation progress to a DB option $blclog = new blcCachedOptionLogger('blc_installation_log'); register_shutdown_function(array(&$blclog, 'save')); //Make sure the log is saved even if the plugin crashes $blclog->clear(); $blclog->info(sprintf('Plugin activated at %s.', date_i18n('Y-m-d H:i:s'))); //Reset the "installation_complete" flag $blc_config_manager->options['installation_complete'] = false; $blc_config_manager->options['installation_flag_cleared_on'] = date('c') . ' (' . microtime(true) . ')'; //Note the time of the first installation (not very accurate, but still useful) if (empty($blc_config_manager->options['first_installation_timestamp'])) { $blc_config_manager->options['first_installation_timestamp'] = time(); } $blc_config_manager->save_options(); $blclog->info('Installation/update begins.'); //Load the base classes and utilities require_once BLC_DIRECTORY . '/includes/links.php'; require_once BLC_DIRECTORY . '/includes/link-query.php'; require_once BLC_DIRECTORY . '/includes/instances.php'; require_once BLC_DIRECTORY . '/includes/utility-class.php'; //Load the module subsystem require_once BLC_DIRECTORY . '/includes/modules.php';