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 function validate_options($input = array()) { if ($_REQUEST['download_log_file']) { $this->download_log_file(); exit; } if (empty($input) && $_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST[self::$_plugin_action_slug])) { $input = $_POST[self::$_plugin_action_slug]; } $saved_option = parent::get_option('ac_inspector_log_path'); if (!empty($input['log_path'])) { if ($saved_option === FALSE) { parent::add_option('ac_inspector_log_path', $input['log_path']); } else { parent::update_option('ac_inspector_log_path', $input['log_path']); } parent::$log_path = $input['log_path']; } $routines = (array) ACI_Routine_Handler::get_all(); foreach (array_keys($routines) as $routine) { $routine_settings = ACI_Routine_Handler::get_options($routine); if (!empty($input[$routine]) && is_array($input[$routine])) { $new_routine_settings = $input[$routine]; } else { $new_routine_settings = array(); } foreach ($new_routine_settings as $opt => $val) { $routine_settings[$opt] = $new_routine_settings[$opt]; } $routine_settings = apply_filters($routine . '_settings', $routine_settings); ACI_Routine_Handler::set_options($routine, $routine_settings); } if (is_multisite() && is_plugin_active_for_network(ACI_PLUGIN_BASENAME)) { // redirect to settings page in network wp_redirect(add_query_arg(array('page' => ACI_PLUGIN_SLUG, 'updated' => 'true'), network_admin_url('settings.php'))); exit; } return $input; }