public static function inspect()
 {
     $repo = Git::open(ABSPATH);
     if (is_object($repo) && $repo->test_git()) {
         $status_data = $repo->run('status --porcelain');
         $changed_files = array();
         if (preg_match_all('/(^.+?)\\s(.*)$/m', $status_data, $changes, PREG_SET_ORDER)) {
             foreach ($changes as $changed_item) {
                 $change = trim($changed_item[1]);
                 $file = trim($changed_item[2]);
                 $changed_files[$change][] = $file;
             }
         }
         $routine_options = ACI_Routine_Handler::get_options(__CLASS__);
         if (!is_array($routine_options)) {
             $routine_options = array();
         }
         if (!is_array($routine_options['changed_files'])) {
             $routine_options['changed_files'] = array();
         }
         if (empty($routine_options['ignore_files'])) {
             $routine_options['ignore_files'] = self::$_default_ignore_files;
         } else {
             if (!is_array($routine_options['ignore_files'])) {
                 $routine_options['ignore_files'] = (array) $routine_options['ignore_files'];
             }
         }
         foreach (array_keys($changed_files) as $change) {
             foreach ($routine_options['ignore_files'] as $file_path) {
                 if (!empty($file_path)) {
                     $files_to_ignore = preg_grep('/^' . str_replace('\\*', '*', preg_quote($file_path, '/') . '/'), $changed_files[$change]);
                     if (is_array($files_to_ignore) && count($files_to_ignore) > 0) {
                         foreach (array_keys($files_to_ignore) as $ignore_file_key) {
                             unset($changed_files[$change][$ignore_file_key]);
                         }
                     }
                 }
             }
             if (count($changed_files[$change]) > 0) {
                 switch ($change) {
                     case 'A':
                         AC_Inspector::log('Git repository has ' . count($changed_files[$change]) . ' NEW file(s).', __CLASS__);
                         break;
                     case 'M':
                         AC_Inspector::log('Git repository has ' . count($changed_files[$change]) . ' MODIFIED file(s).', __CLASS__);
                         break;
                     case 'D':
                         AC_Inspector::log('Git repository has ' . count($changed_files[$change]) . ' DELETED file(s).', __CLASS__);
                         break;
                     case '??':
                         AC_Inspector::log('Git repository has ' . count($changed_files[$change]) . ' UNTRACKED file(s).', __CLASS__);
                         break;
                 }
             }
         }
         $routine_options['changed_files'] = $changed_files;
         ACI_Routine_Handler::set_options(__CLASS__, $routine_options);
     }
 }
 public static function inspect()
 {
     // Do the inspection and log a message like this:
     AC_Inspector::log("Enter appropriate log text here.", __CLASS__);
     // Return whatever is expected of the hook this routine is attached to,
     // nothing if the standard "ac_inspection" cron job hook
     return "";
 }
 public static function inspect($user_id, $old_user_data = array())
 {
     $current_user = wp_get_current_user();
     $updated_user = get_user_by('id', $user_id);
     if (!$updated_user instanceof WP_User) {
         return "";
     }
     $changed_user_properties = array();
     foreach (get_object_vars($updated_user->data) as $property_key => $property_val) {
         if (in_array(gettype($property_val), array("integer", "string", "boolean")) && $old_user_data->{$property_key} != $property_val) {
             switch ($property_key) {
                 case "ID":
                 case "user_login":
                 case "user_nicename":
                 case "user_registered":
                 case "user_activation_key":
                 case "user_status":
                     // Because changes in any of the above is beyond the scope of this logging routine...
                     break;
                 case "user_pass":
                     $changed_user_properties[$property_key] = "password";
                     break;
                 case "user_email":
                     $changed_user_properties[$property_key] = "e-mail";
                     break;
                 case "user_url":
                     $changed_user_properties[$property_key] = "homepage";
                     break;
                 case "display_name":
                     $changed_user_properties[$property_key] = "display name";
                     break;
             }
         }
     }
     foreach ($changed_user_properties as $property_key => $property_label) {
         if ($property_key != 'user_pass') {
             $log_message = "The " . $property_label . " setting for " . $updated_user->display_name . " (" . $updated_user->user_login . ") " . "was changed from '" . $old_user_data->{$property_key} . "'' to '" . $updated_user->data->{$property_key} . "'";
         } else {
             $log_message = "The " . $property_label . " setting for " . $updated_user->display_name . " (" . $updated_user->user_login . ") " . "was changed";
         }
         if ($current_user instanceof WP_User) {
             $log_message .= " by " . $current_user->display_name . " (" . $current_user->user_login . ")";
         }
         if (is_multisite() && is_plugin_active_for_network(ACI_PLUGIN_BASENAME)) {
             $site_name = get_blog_details($site_id)->blogname;
             $log_message .= " on " . $site_name;
         }
         $log_message .= ".";
         AC_Inspector::log($log_message, __CLASS__);
     }
     return "";
 }
 public static function inspect($user_id)
 {
     $current_user = wp_get_current_user();
     $new_user = get_user_by('id', $user_id);
     if (!$current_user instanceof WP_User) {
         return "";
     }
     if ($current_user instanceof WP_User) {
         $log_message = $new_user->display_name . " (" . $new_user->user_login . ") " . "was registered as a new user by " . $current_user->display_name . " (" . $current_user->user_login . ").";
     } else {
         $log_message = $new_user->display_name . " (" . $new_user->user_login . ") " . "registered as a new user.";
     }
     AC_Inspector::log($log_message, __CLASS__);
     return "";
 }
 public static function inspect($site)
 {
     $user = wp_get_current_user();
     $usermsg = $user instanceof WP_User ? ' (user: '******')' : '';
     switch (current_filter()) {
         case 'activate_blog':
             $status = 'activated';
             break;
         case 'deactivate_blog':
             $status = 'deactivated';
             break;
     }
     $message = 'Site ' . get_blog_details($site)->blogname . ' (id: ' . $site . ')' . ' was ' . $status . $usermsg;
     AC_Inspector::log($message, __CLASS__);
     return "";
 }
 public static function inspect($user_id, $role, $site_id)
 {
     $current_user = wp_get_current_user();
     $added_user = get_user_by('id', $user_id);
     $site_name = get_blog_details($site_id)->blogname;
     if (!$added_user instanceof WP_User) {
         return "";
     }
     if ($current_user instanceof WP_User) {
         $log_message = $added_user->display_name . " (" . $added_user->user_login . ") " . "was added as " . $role . " to " . $site_name . " by " . $current_user->display_name . " (" . $current_user->user_login . ").";
     } else {
         $log_message = $added_user->display_name . " (" . $added_user->user_login . ") " . "was added as " . $role . " to " . $site_name . ".";
     }
     AC_Inspector::log($log_message, __CLASS__);
     return "";
 }
 public static function inspect($plugin)
 {
     $user = wp_get_current_user();
     $site = is_multisite() ? ' on "' . get_blog_details(get_current_blog_id())->blogname . '"' : '';
     $usermsg = $user instanceof WP_User ? ' (user: '******')' : '';
     switch (current_filter()) {
         case 'activate_plugin':
             $status = 'activated';
             break;
         case 'deactivate_plugin':
             $status = 'deactivated';
             break;
     }
     if (!empty($status)) {
         $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin);
         $message = 'Plugin "' . $plugin_data['Name'] . '" was ' . $status . $usermsg . $site;
         AC_Inspector::log($message, __CLASS__);
     }
     return "";
 }
        public function routine_settings_field($args)
        {
            $routine = $args['routine'];
            $log_levels = AC_Inspector::get_log_levels();
            $routine_settings = ACI_Routine_Handler::get_options($routine);
            $schedules = false;
            if (ACI_Routine_Handler::is_scheduled($routine)) {
                $schedules = wp_get_schedules();
            }
            if (!empty($routine_settings['description'])) {
                ?>

				<tr valign="top">
					<td colspan="2" class="description-row" scope="row" valign="top"><div class="howto"><?php 
                echo $routine_settings['description'];
                ?>
</div></td>
				</tr>

			<?php 
            }
            if (isset($routine_settings['site_specific_settings']) && is_multisite() && is_plugin_active_for_network(ACI_PLUGIN_BASENAME)) {
                ?>

				<tr valign="top">
					<td scope="row" valign="top"><?php 
                _e('Site specific settings', ACI_PLUGIN_TEXTDOMAIN);
                ?>
</td>
					<td>
						<select id="<?php 
                echo $routine;
                ?>
_site_specific_settings" name="<?php 
                echo self::$_plugin_action_slug;
                ?>
[<?php 
                echo $routine;
                ?>
][site_specific_settings]">
							<option value="1"<?php 
                echo $routine_settings['site_specific_settings'] ? " selected" : "";
                ?>
><?php 
                _e('Yes', ACI_PLUGIN_TEXTDOMAIN);
                ?>
</option>
							<option value="0"<?php 
                echo $routine_settings['site_specific_settings'] ? "" : " selected";
                ?>
><?php 
                _e('No', ACI_PLUGIN_TEXTDOMAIN);
                ?>
</option>
						</select>
						<div class="howto"><?php 
                _e('Submit your settings to enable/disable site-specific settings', ACI_PLUGIN_TEXTDOMAIN);
                ?>
</div>
					</td>
				</tr>

			<?php 
            }
            if ($routine_settings['site_specific_settings'] && is_multisite() && is_plugin_active_for_network(ACI_PLUGIN_BASENAME)) {
                global $wpdb;
                $site_blog_ids = $wpdb->get_col("SELECT blog_id FROM " . $wpdb->prefix . "blogs");
                if (is_array($site_blog_ids)) {
                    foreach ($site_blog_ids as $site_blog_id) {
                        $sitename = get_blog_details($site_blog_id)->blogname;
                        ?>

						<tr valign="top">
							<td scope="row" valign="top"><?php 
                        printf(__('Log level on %s', ACI_PLUGIN_TEXTDOMAIN), $sitename);
                        ?>
</td>
							<td>
								<select id="<?php 
                        echo $routine;
                        ?>
_<?php 
                        echo $site_blog_id;
                        ?>
_log_level" name="<?php 
                        echo self::$_plugin_action_slug;
                        ?>
[<?php 
                        echo $routine;
                        ?>
][<?php 
                        echo $site_blog_id;
                        ?>
][log_level]">
									<?php 
                        foreach ($log_levels as $level) {
                            ?>
										<option value="<?php 
                            echo $level;
                            ?>
"<?php 
                            echo $level == $routine_settings[$site_blog_id]['log_level'] ? " selected" : "";
                            ?>
><?php 
                            _e(ucfirst($level), ACI_PLUGIN_TEXTDOMAIN);
                            ?>
</option>
									<?php 
                        }
                        ?>
								</select>
							</td>
						</tr>

						<?php 
                        if ($schedules) {
                            if (!array_key_exists('schedule', $routine_settings[$site_blog_id]) || empty($routine_settings[$site_blog_id]['schedule']) || !in_array($routine_settings[$site_blog_id]['schedule'], array_keys($schedules))) {
                                $scheduled = 'daily';
                            } else {
                                $scheduled = $routine_settings[$site_blog_id]['schedule'];
                            }
                            ?>

							<tr valign="top">
								<td scope="row" valign="top"><?php 
                            printf(__('Recurrence on %s', ACI_PLUGIN_TEXTDOMAIN), $sitename);
                            ?>
</td>
								<td>
									<select id="<?php 
                            echo $routine;
                            ?>
_<?php 
                            echo $site_blog_id;
                            ?>
_schedule" name="<?php 
                            echo self::$_plugin_action_slug;
                            ?>
[<?php 
                            echo $routine;
                            ?>
][<?php 
                            echo $site_blog_id;
                            ?>
][schedule]">
										<?php 
                            foreach (array_keys($schedules) as $schedule) {
                                ?>
											<option value="<?php 
                                echo $schedule;
                                ?>
"<?php 
                                echo $schedule == $scheduled ? " selected" : "";
                                ?>
><?php 
                                _e($schedules[$schedule]['display'], ACI_PLUGIN_TEXTDOMAIN);
                                ?>
</option>
										<?php 
                            }
                            ?>
									</select>
								</td>
							</tr>

						<?php 
                        }
                    }
                }
            } else {
                ?>

				<tr valign="top">
					<td scope="row"><?php 
                _e('Log level', ACI_PLUGIN_TEXTDOMAIN);
                ?>
</td>
					<td>
						<select id="<?php 
                echo $routine;
                ?>
_log_level" name="<?php 
                echo self::$_plugin_action_slug;
                ?>
[<?php 
                echo $routine;
                ?>
][log_level]">
							<?php 
                foreach ($log_levels as $level) {
                    ?>
								<option value="<?php 
                    echo $level;
                    ?>
"<?php 
                    echo $level == $routine_settings['log_level'] ? " selected" : "";
                    ?>
><?php 
                    _e(ucfirst($level), ACI_PLUGIN_TEXTDOMAIN);
                    ?>
</option>
							<?php 
                }
                ?>
						</select>
					</td>
				</tr>

				<?php 
                if ($schedules) {
                    if (!array_key_exists('schedule', $routine_settings) || empty($routine_settings['schedule']) || !in_array($routine_settings['schedule'], array_keys($schedules))) {
                        $scheduled = 'daily';
                    } else {
                        $scheduled = $routine_settings['schedule'];
                    }
                    ?>

					<tr valign="top">
						<td scope="row" valign="top"><?php 
                    _e('Recurrence', ACI_PLUGIN_TEXTDOMAIN);
                    ?>
</td>
						<td>
							<select id="<?php 
                    echo $routine;
                    ?>
_schedule" name="<?php 
                    echo self::$_plugin_action_slug;
                    ?>
[<?php 
                    echo $routine;
                    ?>
][schedule]">
								<?php 
                    foreach (array_keys($schedules) as $schedule) {
                        ?>
									<option value="<?php 
                        echo $schedule;
                        ?>
"<?php 
                        echo $schedule == $scheduled ? " selected" : "";
                        ?>
><?php 
                        _e($schedules[$schedule]['display'], ACI_PLUGIN_TEXTDOMAIN);
                        ?>
</option>
								<?php 
                    }
                    ?>
							</select>
						</td>
					</tr>

				<?php 
                }
            }
            do_action($routine . '_settings_field', $routine_settings, $args);
        }
 public static function log_error()
 {
     $msg = isset($_GET["m"]) ? $_GET["m"] : "";
     $url = isset($_GET["u"]) ? $_GET["u"] : "";
     $line = isset($_GET["l"]) ? $_GET["l"] : "";
     $col = isset($_GET["c"]) ? $_GET["c"] : "";
     $r = isset($_GET["r"]) ? $_GET["r"] : "";
     $ua = isset($_GET["ua"]) ? $_GET["ua"] : "";
     $err = isset($_GET["e"]) ? $_GET["e"] : "";
     if (strpos($msg, ':') !== false) {
         $msg = trim(substr($msg, strpos($msg, ':') + 1));
     }
     $url = str_replace(home_url(), '', $url);
     $full_msg = "JS Error: " . $msg . " on " . $url;
     if (!empty($line)) {
         $full_msg .= ", line " . $line;
     }
     if (!empty($col)) {
         $full_msg .= ", column " . $col . ".";
     }
     if (!empty($r)) {
         $full_msg .= " | Requested URI: " . $r;
     }
     if (!empty($ua)) {
         $full_msg .= " | User Agent: " . $ua;
     }
     if (!empty($err)) {
         $full_msg .= " | Stacktrace: " . $err;
     }
     AC_Inspector::log($full_msg, __CLASS__);
 }
 public static function repair()
 {
     if (!aci_release_tier_aware()) {
         AC_Inspector::log('Unable to determine the appropriate site visibility setting, please define SITE_RELEASE_TIER in your wp-config.php.', __CLASS__, array('error' => true));
         return;
     }
     if (is_multisite() && is_plugin_active_for_network(ACI_PLUGIN_BASENAME)) {
         global $wpdb;
         $site_ids = $wpdb->get_col("SELECT blog_id FROM " . $wpdb->prefix . "blogs");
         if (is_array($site_ids)) {
             foreach ($site_ids as $site_id) {
                 if (intval($site_id) > 0) {
                     $visible = self::is_visible($site_id);
                     if (!$visible && true === self::should_be_visible($site_id) || $visible && false === self::should_be_visible($site_id)) {
                         $visible = $visible ? 0 : 1;
                         switch_to_blog($site_id);
                         update_option('blog_public', $visible);
                         restore_current_blog();
                         AC_Inspector::log('The site visibility setting for ' . get_blog_details($site_id, true)->blogname . ' is now ' . ($visible ? ' public' : ' private') . '.', __CLASS__, array('success' => true));
                     } else {
                         AC_Inspector::log('The site visibility setting for ' . get_blog_details($site_id, true)->blogname . ' seems correct, no action taken.', __CLASS__, array('log_level' => 'notice'));
                     }
                 }
             }
         }
     } else {
         $visible = self::is_visible();
         if (!$visible && true === self::should_be_visible() || $visible && false === self::should_be_visible()) {
             $visible = $visible ? 0 : 1;
             update_option('blog_public', $visible);
             AC_Inspector::log('The site visibility setting is now ' . ($visible ? ' public' : ' private') . '.', __CLASS__, array('success' => true));
         } else {
             AC_Inspector::log('The site visibility setting seems correct, no action taken.', __CLASS__, array('log_level' => 'notice'));
         }
     }
 }
 private function _get_log_path()
 {
     self::$log_path = self::get_option('ac_inspector_log_path');
     if (empty(self::$log_path)) {
         // For backwards compatibility with versions <= 0.1.1
         self::$log_path = self::get_option('log_path');
         if (!empty(self::$log_path)) {
             // Set new option variable name
             self::update_option('ac_inspector_log_path', self::$log_path);
         } else {
             self::$log_path = self::$_default_log_path;
             self::update_option('ac_inspector_log_path', self::$_default_log_path);
         }
     }
     self::$log_path = apply_filters('ac_inspector_log_path', self::$log_path);
 }
 private static function _log_super_user_cap_change($user_id)
 {
     $current_user = wp_get_current_user();
     $changed_user = get_user_by('id', $user_id);
     if (!is_array(self::$_super_user_cap_changes[$current_user->ID])) {
         self::$_super_user_cap_changes[$current_user->ID] = array();
     }
     if (!in_array($changed_user->ID, self::$_super_user_cap_changes[$current_user->ID])) {
         $message = "Meaningless change of capabilities on super user " . $changed_user->display_name . ' (' . $changed_user->user_login . ') by ' . $current_user->display_name . ' (' . $current_user->user_login . ')';
         AC_Inspector::log($message, __CLASS__);
         self::$_super_user_cap_changes[$current_user->ID][] = $changed_user->ID;
     }
 }
 public static function get_options($routine)
 {
     if (empty($routine)) {
         return false;
     }
     $options_key = self::routine_options_key($routine);
     $options = AC_Inspector::get_option($options_key);
     if (!empty($options['site_specific_settings']) && is_multisite() && is_plugin_active_for_network(ACI_PLUGIN_BASENAME)) {
         global $wpdb;
         $site_blog_ids = $wpdb->get_col("SELECT blog_id FROM " . $wpdb->prefix . "blogs");
         if (is_array($site_blog_ids)) {
             $global_opt_keys = array_keys($options);
             foreach ($site_blog_ids as $site_blog_id) {
                 if (!is_array($options[$site_blog_id])) {
                     $options[$site_blog_id] = array();
                 }
                 foreach ($global_opt_keys as $global_opt_key) {
                     if (!is_numeric($global_opt_key) && $global_opt_key != 'site_specific_settings' && !isset($options[$site_blog_id][$global_opt_key])) {
                         $options[$site_blog_id][$global_opt_key] = $options[$global_opt_key];
                     }
                 }
                 if (in_array($routine, self::$force_enabled) && $options[$site_blog_id]['log_level'] == 'ignore') {
                     $options[$site_blog_id]['log_level'] = 'notice';
                 }
             }
         }
     } else {
         if (in_array($routine, self::$force_enabled) && $options['log_level'] == 'ignore') {
             $options['log_level'] = 'notice';
         }
     }
     return apply_filters('ac_inspector_' . $routine . '_options', $options);
 }
 /**
  * Performs a full inspection and outputs the inspection log.
  *
  * ## OPTIONS
  *
  * [<routine>]
  * : The inspection routine to perform.
  *
  * ## EXAMPLES
  *
  *     wp angry-inspector inspect file-permissions
  *
  * @synopsis [--force] [<routine>] [<other-routine>]
  */
 function inspect($routines = array(), $assoc_args)
 {
     $all_routines = ACI_Routine_Handler::get_inspection_routines();
     $all_routine_slugs = array();
     $routine_repair_methods = array();
     $force_inspect = true;
     foreach ($all_routines as $key => $routine) {
         $all_routine_slugs[$key] = str_replace('_', '-', str_replace('aci_routine_', '', str_replace('aci_routine_check_', '', strtolower($routine))));
     }
     if (empty($routines) || !is_array($routines) || 0 == count($routines)) {
         $force_inspect = false;
         $routines = $all_routine_slugs;
     }
     if (array_key_exists('force', $assoc_args) && !empty($assoc_args['force'])) {
         $force_inspect = true;
     }
     foreach ($routines as $routine) {
         if (in_array($routine, $all_routine_slugs)) {
             $total_log_count = AC_Inspector::$log_count;
             $routine_key = array_search($routine, $all_routine_slugs);
             $routine_options = ACI_Routine_Handler::get_options($all_routines[$routine_key]);
             $inspection_method = ACI_Routine_Handler::get_inspection_method($all_routines[$routine_key], $routine_options);
             $enabled_routine = false;
             if ($force_inspect) {
                 $enabled_routine = true;
                 ACI_Routine_Handler::force_enable($all_routines[$routine_key]);
             } else {
                 if (!empty($routine_options['site_specific_settings']) && is_multisite() && is_plugin_active_for_network(ACI_PLUGIN_BASENAME)) {
                     $current_site_id = get_current_blog_id();
                     if ($routine_options[$current_site_id]['log_level'] != 'ignore') {
                         $enabled_routine = true;
                     }
                 } else {
                     if ($routine_options['log_level'] != 'ignore') {
                         $enabled_routine = true;
                     }
                 }
             }
             if (!$enabled_routine) {
                 echo "Skipping disabled routine {$routine}...\n\n";
                 continue;
             }
             if (empty($inspection_method)) {
                 WP_CLI::error("Failed to determine the inspection method for {$routine}.");
             }
             if (is_array($inspection_method)) {
                 if (class_exists($inspection_method[0]) && method_exists($inspection_method[0], $inspection_method[1])) {
                     echo "Calling inspection method {$routine}...\n";
                     call_user_func($inspection_method);
                 } else {
                     WP_CLI::error("Failed to load the inspection method for {$routine}.");
                 }
             } else {
                 if (function_exists($inspection_method)) {
                     echo "Calling inspection method {$routine}...\n";
                     call_user_func($inspection_method);
                 } else {
                     WP_CLI::error("Failed to load the inspection method for {$routine}.");
                     break;
                 }
             }
             if (AC_Inspector::$error_count) {
                 AC_Inspector::$error_count = 0;
                 continue;
             }
             $routine_log_count = AC_Inspector::$log_count - $total_log_count;
             WP_CLI::success("Inspected {$routine} with {$routine_log_count} remark(s).\n");
             if ($routine_log_count > 0) {
                 $repair_method = ACI_Routine_Handler::get_repair_method($all_routines[$routine_key], $routine_options);
                 if (!empty($repair_method)) {
                     $routine_repair_methods[$routine] = $repair_method;
                 }
             }
         } else {
             WP_CLI::error("Unrecognized inspection routine '{$routine}'.");
         }
     }
     if (count($routine_repair_methods) > 0) {
         WP_CLI::confirm("One or more of your inspection routines has a repair method that may or may not fix the problem(s) for you.\n" . "Have you made a backup of your website's entire source code, uploaded files and database and want me to\n" . "try and repair with the risk of me messing everything up?");
         foreach ($routine_repair_methods as $routine => $repair_method) {
             $total_log_count = AC_Inspector::$log_count;
             $total_error_count = AC_Inspector::$error_count;
             $total_success_count = AC_Inspector::$success_count;
             call_user_func($repair_method);
             $routine_log_count = AC_Inspector::$log_count - $total_log_count;
             $routine_error_count = AC_Inspector::$error_count - $total_error_count;
             $routine_success_count = AC_Inspector::$success_count - $total_success_count;
             if ($routine_error_count > 0) {
                 WP_CLI::error("Repair method for routine '{$routine}' yielded {$routine_error_count} error(s).\n");
             } else {
                 if ($routine_success_count > 0 || $routine_log_count > 0) {
                     WP_CLI::success("Successfully performed repair method for routine '{$routine}' with no errors.\n");
                 } else {
                     WP_CLI::success("Nothing seems broken. If it ain't broke, don't fix it.\n");
                 }
             }
         }
     }
 }
 public static function repair()
 {
     global $wpdb;
     $proper_db_collation = self::get_proper_db_collation();
     $default_db_collation = $wpdb->get_var("SELECT DEFAULT_COLLATION_NAME\n\t\t\t\t\t\t\t\t\t\t\t\t FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '" . DB_NAME . "'");
     list($proper_charset) = explode('_', $proper_db_collation);
     if ($proper_db_collation != $default_db_collation) {
         if ($wpdb->query($wpdb->prepare("ALTER DATABASE `" . DB_NAME . "` CHARACTER SET %s COLLATE %s", $proper_charset, $proper_db_collation))) {
             AC_Inspector::log("Converted default table collation from {$default_db_collation} to {$proper_db_collation}.", __CLASS__, array('success' => true));
         } else {
             AC_Inspector::log("Failed to convert default table collation from {$default_db_collation} to {$proper_db_collation}!", __CLASS__, array('error' => true));
         }
     }
     $tbl_collation_queries = self::get_table_collation_queries();
     if (is_array($tbl_collation_queries) && count($tbl_collation_queries) > 0) {
         foreach ($tbl_collation_queries as $tbl_collation_query) {
             $tbl_collation_data = $wpdb->get_row($tbl_collation_query);
             $tbl_name = $tbl_collation_data->TABLE_NAME;
             $tbl_collation = $tbl_collation_data->TABLE_COLLATION;
             if ($proper_db_collation != $tbl_collation) {
                 if ($wpdb->query($wpdb->prepare("ALTER TABLE `" . $tbl_name . "` CONVERT TO CHARACTER SET %s COLLATE %s", $proper_charset, $proper_db_collation))) {
                     AC_Inspector::log("Converted collation for {$tbl_name} from {$tbl_collation} to {$proper_db_collation}.", __CLASS__, array('success' => true));
                 } else {
                     AC_Inspector::log("Failed to convert collation for {$tbl_name} from {$tbl_collation} to {$proper_db_collation}.", __CLASS__, array('error' => true));
                 }
                 continue;
             }
             $tbl_columns = $wpdb->get_results("SHOW FULL COLUMNS FROM `{$tbl_name}`");
             if (!$tbl_columns) {
                 AC_Inspector::log("Unable to determine column collations for table {$tbl_name}.", __CLASS__, array('error' => true));
                 continue;
             }
             foreach ($tbl_columns as $column) {
                 if ($column->Collation) {
                     if ($proper_db_collation !== $column->Collation) {
                         if ($wpdb->query($wpdb->prepare("ALTER TABLE `" . $tbl_name . "` CONVERT TO CHARACTER SET %s COLLATE %s", $proper_charset, $proper_db_collation))) {
                             AC_Inspector::log("Converted collation for {$tbl_name} from {$tbl_collation} to {$proper_db_collation}.", __CLASS__, array('success' => true));
                         } else {
                             AC_Inspector::log("Failed to convert collation for {$tbl_name} from {$tbl_collation} to {$proper_db_collation}.", __CLASS__, array('error' => true));
                         }
                         break;
                     }
                 }
             }
         }
     }
     return;
 }
 public static function repair()
 {
     if (!function_exists('posix_geteuid')) {
         AC_Inspector::log('Repairing file permissions requires a POSIX-enabled PHP server.', __CLASS__, array('error' => true));
         return;
     }
     if (posix_geteuid() !== 0) {
         AC_Inspector::log('Repairing file permissions must be performed as root.', __CLASS__, array('error' => true));
         return;
     }
     $group = '';
     $owner = '';
     if (defined('HTTPD_USER')) {
         $group = HTTPD_USER;
     } else {
         AC_Inspector::log('Unable to determine the user your web server is running as, define HTTPD_USER in your wp-config.php to correct this.', __CLASS__, array('log_level' => 'warning'));
     }
     if (defined('FS_USER')) {
         $owner = FS_USER;
     } else {
         if (defined('FTP_USER')) {
             $owner = FTP_USER;
         } else {
             AC_Inspector::log('Unable to determine the appropriate file system owner, define FS_USER in your wp-config.php to correct this.', __CLASS__, array('log_level' => 'warning'));
         }
     }
     if (empty($group) && empty($owner)) {
         WP_CLI::confirm("Skip setting ownerships (chown) and attempt to repair file permissions (chmod) anyway?");
     } else {
         if (empty($group)) {
             WP_CLI::confirm("Skip setting group permissions and attempt to set just user permissions instead?");
         } else {
             if (empty($owner)) {
                 WP_CLI::confirm("Skip setting user permissions and attempt to set just group permissions instead?");
             }
         }
     }
     if (false === self::chown(self::$_real_abspath, $owner, $group, true, true)) {
         if (defined('WP_CLI') && WP_CLI) {
             WP_CLI::confirm("There where errors while trying to set file ownerships (chown), proceed with setting file permissions (chmod) anyway?");
         } else {
             return false;
         }
     }
     if (count(self::$_options['allowed_dirs']) != 1 || !in_array('/*', self::$_options['allowed_dirs'])) {
         self::chmod(self::$_real_abspath, 0644, 0755, true, true);
     }
     foreach (self::$_options['allowed_dirs'] as $folder) {
         $folder_base = trim(str_replace('/*', '', str_replace('//', '/', str_replace(self::$_real_abspath, '', $folder))), '/');
         if (!file_exists(self::$_real_abspath . '/' . $folder_base) && file_exists('/' . $folder_base)) {
             $folder_base = '/' . $folder_base;
             if (is_link($folder_base)) {
                 $resolved_folder_path = realpath(readlink($folder_base));
             } else {
                 $resolved_folder_path = $folder_base;
             }
         } else {
             if (is_link(self::$_real_abspath . '/' . $folder_base)) {
                 $resolved_folder_path = realpath(readlink(self::$_real_abspath . '/' . $folder_base));
             } else {
                 $resolved_folder_path = self::$_real_abspath . '/' . $folder_base;
             }
         }
         if (!self::$_force_default_allowed_dirs && !file_exists($resolved_folder_path)) {
             continue;
         }
         $recursive = substr($folder, -2) == "/*" ? true : false;
         self::chmod($resolved_folder_path, 0664, 0775, $recursive, true);
     }
     return "";
 }