Changeset 539134
- Timestamp:
- 05/02/2012 06:57:16 PM (14 years ago)
- Location:
- wordpress-file-monitor-plus/trunk
- Files:
-
- 1 deleted
- 3 edited
-
classes/wpfmp.class.php (deleted)
-
classes/wpfmp.settings.class.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
wordpress-file-monitor-plus.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wordpress-file-monitor-plus/trunk/classes/wpfmp.settings.class.php
r539101 r539134 17 17 */ 18 18 19 // Not a WordPress context? Stop. 20 ! defined( 'ABSPATH' ) and exit; 21 22 // Only load class if it hasn't already been loaded 23 if ( ! class_exists( 'sc_WordPressFileMonitorPlusSettings' ) ) 24 { 25 class sc_WordPressFileMonitorPlusSettings 26 { 27 static public function init() 19 class sc_WordPressFileMonitorPlusSettings extends sc_WordPressFileMonitorPlus { 20 21 protected static $frequency_intervals = array("hourly", "twicedaily", "daily", "manual"); 22 23 24 public function __construct() { 25 $this->settingsUpToDate(); // Check settings are up to date 26 add_action('admin_menu', array(__CLASS__, 'admin_settings_menu')); // Add admin settings menu 27 add_action('admin_init', array(__CLASS__, 'admin_settings_init')); // Add admin init functions 28 add_filter('plugin_action_links', array(__CLASS__, 'plugin_action_links'), 10, 2); // Add settings link to plugin in plugin list 29 } 30 31 32 /** 33 * Check if this plugin settings are up to date. Firstly check the version in 34 * the DB. If they don't match then load in defaults but don't override values 35 * already set. Also this will remove obsolete settings that are not needed. 36 * 37 * @return void 38 */ 39 protected function settingsUpToDate() { 40 $current_ver = get_option(parent::$settings_option_field_ver); // Get current plugin version 41 if(parent::$settings_option_field_current_ver != $current_ver) { // is the version the same as this plugin? 42 $options = (array) maybe_unserialize(get_option(parent::$settings_option_field)); // get current settings from DB 43 if( isset( $current_ver ) && ( $current_ver <= 1.3 ) ) 44 $options = self::update_settings_pre_1_4_to_1_4($options); // Convert old settings to new setup 45 $defaults = array( // Here are the default values 46 'cron_method' => 'wordpress', // Cron method to be used for scheduling scans 47 'file_check_interval' => 'daily', // How often should the cron run 48 'notify_by_email' => 1, // Do we want to be notified by email when there is a file change? 49 'data_save' => 'database', // Where to save scan data and admin alert message 50 'from_address' => get_option('admin_email'), // Email address the notification comes from 51 'notify_address' => get_option('admin_email'), // Email address the notification is sent to 52 'site_root' => realpath(ABSPATH), // The file check path to start checking files from 53 'exclude_paths_files' => array(), // What files and dirs should we ignore? 54 'file_check_method' => array( 55 'size' => 1, // Should we log the filesize of files? 56 'modified' => 1, // Should we log the modified date of files? 57 'md5' => 1 // Should we log the hash of files using md5_file()? 58 ), 59 'display_admin_alert' => 1, // Do we allow the plugin to notify us when there is a change in the admin area? 60 'is_admin_alert' => 0, // Is there a live admin alert? 61 'security_key' => sha1(microtime(true).mt_rand(10000,90000)), // Generate a random key to be used for Other Cron Method 62 // The security key is only shown to the admin and has to be used for triggering a manual scan via an external cron. 63 // This is to stop non admin users from being able to trigger the cron and potentially abuse server resources. 64 'file_extension_mode' => 0, // 0 = Disabled, 1 = ignore below extensions, 2 = only scan below extensions. 65 'file_extensions' => array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico') // List of extensions separated by pipe. 66 ); 67 // Intersect current options with defaults. Basically removing settings that are obsolete 68 $options = array_intersect_key($options, $defaults); 69 // Merge current settings with defaults. Basically adding any new settings with defaults that we dont have. 70 $options = array_merge($defaults, $options); 71 update_option(parent::$settings_option_field, $options); // update settings 72 update_option(parent::$settings_option_field_ver, parent::$settings_option_field_current_ver); // update settings version 73 } 74 } 75 76 77 /** 78 * Upgrades settings from pre version 1.4 to version 1.4 79 * 80 * Now combined all excluding of files and dirs into one 81 * setting that now uses fnmatch(). Because of this the old 82 * settings need copying over to the new setting as well as 83 * converting to an fnmatch() compatible format. 84 * 85 * @param array $options 86 * @return array $options 87 */ 88 private function update_settings_pre_1_4_to_1_4($options) { 89 $options['exclude_paths_files'] = array(); 90 if( isset( $options['exclude_paths'] ) ) { 91 foreach( $options['exclude_paths'] as $exclude) { 92 $options['exclude_paths_files'][] = rtrim($exclude, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR."*"; 93 } 94 } 95 if( isset( $options['exclude_files'] ) ) { 96 foreach( $options['exclude_files'] as $exclude) { 97 $options['exclude_paths_files'][] = $exclude; 98 } 99 } 100 if( isset( $options['exclude_paths_wild'] ) ) { 101 foreach( $options['exclude_paths_wild'] as $exclude) { 102 $options['exclude_paths_files'][] = "*".DIRECTORY_SEPARATOR.trim($exclude, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR."*"; 103 } 104 } 105 if( isset( $options['exclude_files_wild'] ) ) { 106 foreach( $options['exclude_files_wild'] as $exclude) { 107 $options['exclude_paths_files'][] = "*".DIRECTORY_SEPARATOR.ltrim($exclude, DIRECTORY_SEPARATOR); 108 } 109 } 110 return $options; 111 } 112 113 /** 114 * Adds settings link on plugin list 115 * 116 * @param array $links 117 * @param string $file 118 * @return array $links 119 */ 120 public function plugin_action_links($links, $file) { 121 static $this_plugin; 122 if (!$this_plugin) { $this_plugin = "wordpress-file-monitor-plus/wordpress-file-monitor-plus.php"; } 123 if ($this_plugin == $file){ 124 $settings_link = '<a href="'.admin_url("options-general.php?page=wordpress-file-monitor-plus").'">'.__("Settings", "wordpress-file-monitor-plus").'</a>'; 125 array_unshift($links, $settings_link); 126 $settings_link = '<a href="'.admin_url("options-general.php?page=wordpress-file-monitor-plus&sc_wpfmp_action=sc_wpfmp_scan").'">'.__("Manual Scan", "wordpress-file-monitor-plus").'</a>'; 127 array_unshift($links, $settings_link); 128 } 129 return $links; 130 } 131 132 133 /* 134 * EVERYTHING SETTINGS 135 * 136 * I'm not going to comment any of this as its all pretty 137 * much straight forward use of the WordPress Settings API. 138 */ 139 public function admin_settings_menu() { 140 $options = get_option(parent::$settings_option_field); // get settings 141 if( isset($_GET['sc_wpfmp_action']) 142 && isset($_GET['page']) 143 && current_user_can(SC_WPFMP_ADMIN_ALERT_PERMISSION) 144 && "wordpress-file-monitor-plus" == $_GET['page'] ) 28 145 { 29 add_action( 'init', array( __CLASS__, 'settings_up_to_date' ), 9 ); 30 add_action( 'admin_menu', array( __CLASS__, 'admin_settings_menu' ) ); // Add admin settings menu 31 add_action( 'admin_init', array( __CLASS__, 'admin_settings_init' ) ); // Add admin init functions 32 add_filter( 'plugin_action_links', array( __CLASS__, 'plugin_action_links' ), 10, 2 ); // Add settings link to plugin in plugin list 33 } 34 35 36 /** 37 * Check if this plugin settings are up to date. Firstly check the version in 38 * the DB. If they don't match then load in defaults but don't override values 39 * already set. Also this will remove obsolete settings that are not needed. 40 * 41 * @return void 42 */ 43 static public function settings_up_to_date() 44 { 45 // Get current plugin version 46 $current_ver = get_option( sc_WordPressFileMonitorPlus::$settings_option_field_ver ); 47 48 // Does the current version number in DB store match the current version 49 if( sc_WordPressFileMonitorPlus::$settings_option_field_current_ver == $current_ver ) 50 return; 51 52 // Get existing options 53 $options = (array) maybe_unserialize( get_option( sc_WordPressFileMonitorPlus::$settings_option_field ) ); 54 55 // Are we before 1.3? If so we need to do a conversion process to 1.4 56 if( isset( $current_ver ) && ( $current_ver <= 1.3 ) ) 57 $options = self::update_settings_pre_1_4_to_1_4( $options ); 58 59 // Default setting values for WPFMP 60 $defaults = array( 61 'cron_method' => 'wordpress', // Cron method to be used for scheduling scans 62 'file_check_interval' => 'daily', // How often should the cron run 63 'notify_by_email' => 1, // Do we want to be notified by email when there is a file change? 64 'data_save' => 'database', // Where to save scan data and admin alert message 65 'from_address' => get_option( 'admin_email' ), // Email address the notification comes from 66 'notify_address' => get_option( 'admin_email' ), // Email address the notification is sent to 67 'site_root' => realpath( ABSPATH ), // The file check path to start checking files from 68 'exclude_paths_files' => array(), // What files and dirs should we ignore? 69 'file_check_method' => array( 70 'size' => 1, // Should we log the filesize of files? 71 'modified' => 1, // Should we log the modified date of files? 72 'md5' => 1 // Should we log the hash of files using md5_file()? 73 ), 74 'display_admin_alert' => 1, // Do we allow the plugin to notify us when there is a change in the admin area? 75 'is_admin_alert' => 0, // Is there a live admin alert? 76 'security_key' => sha1( microtime( true ) . mt_rand( 10000,90000 ) ), // Generate a random key to be used for Other Cron Method 77 // The security key is only shown to the admin and has to be used for triggering a manual scan via an external cron. 78 // This is to stop non admin users from being able to trigger the cron and potentially abuse server resources. 79 'file_extension_mode' => 0, // 0 = Disabled, 1 = ignore below extensions, 2 = only scan below extensions. 80 'file_extensions' => array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico') // List of extensions separated by pipe. 81 ); 82 83 // Intersect current options with defaults. Basically removing settings that are obsolete 84 $options = array_intersect_key( $options, $defaults ); 85 86 // Merge current settings with defaults. Basically adding any new settings with defaults that we don't have. 87 $options = array_merge( $defaults, $options ); 88 89 // Update settings and version number 90 update_option( sc_WordPressFileMonitorPlus::$settings_option_field, $options ); // update settings 91 update_option( sc_WordPressFileMonitorPlus::$settings_option_field_ver, sc_WordPressFileMonitorPlus::$settings_option_field_current_ver ); // update settings version 92 } 93 94 95 /** 96 * Upgrades settings from pre version 1.4 to version 1.4 97 * 98 * Now combined all excluding of files and dirs into one 99 * setting that now uses fnmatch(). Because of this the old 100 * settings need copying over to the new setting as well as 101 * converting to an fnmatch() compatible format. 102 * 103 * @param array $options 104 * @return array $options 105 */ 106 private function update_settings_pre_1_4_to_1_4( $options ) 107 { 108 $options['exclude_paths_files'] = array(); 109 110 if( isset( $options['exclude_paths'] ) ) 111 { 112 foreach( $options['exclude_paths'] as $exclude ) 113 $options['exclude_paths_files'][] = rtrim( $exclude, DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . "*"; 146 switch($_GET['sc_wpfmp_action']) { 147 case "sc_wpfmp_scan" : 148 do_action(parent::$cron_name); 149 add_settings_error("sc_wpfmp_settings_main", "sc_wpfmp_settings_main_error", __("Manual scan completed", "wordpress-file-monitor-plus"), "updated"); 150 break; 151 case "sc_wpfmp_reset_settings" : 152 delete_option(parent::$settings_option_field); 153 delete_option(parent::$settings_option_field_ver); 154 self::settingsUpToDate(); 155 add_settings_error("sc_wpfmp_settings_main", "sc_wpfmp_settings_main_error", __("Settings reset", "wordpress-file-monitor-plus"), "updated"); 156 break; 157 case "sc_wpfmp_clear_admin_alert" : 158 $options['is_admin_alert'] = 0; 159 update_option(parent::$settings_option_field, $options); 160 add_settings_error("sc_wpfmp_settings_main", "sc_wpfmp_settings_main_error", __("Admin alert cleared", "wordpress-file-monitor-plus"), "updated"); 161 break; 162 case "sc_wpfmp_view_alert" : 163 $alert_content = parent::getPutAlertContent("get"); 164 echo $alert_content; 165 exit; 166 break; 167 default: 168 add_settings_error("sc_wpfmp_settings_main", "sc_wpfmp_settings_main_error", __("Invalid action encountered", "wordpress-file-monitor-plus"), "error"); 169 break; 114 170 } 115 116 if( isset( $options['exclude_files'] ) ) 117 { 118 foreach( $options['exclude_files'] as $exclude ) 119 $options['exclude_paths_files'][] = $exclude; 120 } 121 122 if( isset( $options['exclude_paths_wild'] ) ) 123 { 124 foreach( $options['exclude_paths_wild'] as $exclude ) 125 $options['exclude_paths_files'][] = "*" . DIRECTORY_SEPARATOR . trim( $exclude, DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . "*"; 126 } 127 128 if( isset( $options['exclude_files_wild'] ) ) 129 { 130 foreach( $options['exclude_files_wild'] as $exclude ) 131 $options['exclude_paths_files'][] = "*" . DIRECTORY_SEPARATOR . ltrim( $exclude, DIRECTORY_SEPARATOR ); 132 } 133 134 return $options; 135 } 136 137 /** 138 * Adds settings link on plugin list 139 * 140 * @param array $links 141 * @param string $file 142 * @return array $links 143 */ 144 public function plugin_action_links( $links, $file ) 145 { 146 static $this_plugin; 147 148 if ( ! $this_plugin ) 149 $this_plugin = "wordpress-file-monitor-plus/wordpress-file-monitor-plus.php"; 150 151 if ( $this_plugin == $file ) 152 { 153 $settings_link = '<a href="' . admin_url( "options-general.php?page=wordpress-file-monitor-plus" ) . '">' . __( "Settings", "wordpress-file-monitor-plus" ) . '</a>'; 154 array_unshift( $links, $settings_link ); 155 $settings_link = '<a href="' . admin_url( "options-general.php?page=wordpress-file-monitor-plus&sc_wpfmp_action=sc_wpfmp_scan" ) . '">' . __( "Manual Scan", "wordpress-file-monitor-plus" ) . '</a>'; 156 array_unshift($links, $settings_link); 157 } 158 159 return $links; 160 } 161 162 163 /* 164 * EVERYTHING SETTINGS 165 * 166 * I'm not going to comment any of this as its all pretty 167 * much straight forward use of the WordPress Settings API. 168 */ 169 public function admin_settings_menu() { 170 $options = get_option(sc_WordPressFileMonitorPlus::$settings_option_field); // get settings 171 if( isset($_GET['sc_wpfmp_action']) 172 && isset($_GET['page']) 173 && current_user_can(SC_WPFMP_ADMIN_ALERT_PERMISSION) 174 && "wordpress-file-monitor-plus" == $_GET['page'] ) 175 { 176 switch($_GET['sc_wpfmp_action']) { 177 case "sc_wpfmp_scan" : 178 do_action(sc_WordPressFileMonitorPlus::$cron_name); 179 add_settings_error("sc_wpfmp_settings_main", "sc_wpfmp_settings_main_error", __("Manual scan completed", "wordpress-file-monitor-plus"), "updated"); 180 break; 181 case "sc_wpfmp_reset_settings" : 182 delete_option(sc_WordPressFileMonitorPlus::$settings_option_field); 183 delete_option(sc_WordPressFileMonitorPlus::$settings_option_field_ver); 184 self::settingsUpToDate(); 185 add_settings_error("sc_wpfmp_settings_main", "sc_wpfmp_settings_main_error", __("Settings reset", "wordpress-file-monitor-plus"), "updated"); 186 break; 187 case "sc_wpfmp_clear_admin_alert" : 188 $options['is_admin_alert'] = 0; 189 update_option(sc_WordPressFileMonitorPlus::$settings_option_field, $options); 190 add_settings_error("sc_wpfmp_settings_main", "sc_wpfmp_settings_main_error", __("Admin alert cleared", "wordpress-file-monitor-plus"), "updated"); 191 break; 192 case "sc_wpfmp_view_alert" : 193 $alert_content = sc_WordPressFileMonitorPlus::getPutAlertContent("get"); 194 echo $alert_content; 195 exit; 196 break; 197 default: 198 add_settings_error("sc_wpfmp_settings_main", "sc_wpfmp_settings_main_error", __("Invalid action encountered", "wordpress-file-monitor-plus"), "error"); 199 break; 200 } 201 } 202 $page = add_options_page('WordPress File Monitor Plus', 'WordPress File Monitor Plus', 'manage_options', 'wordpress-file-monitor-plus', array(__CLASS__, 'settings_page')); 203 add_action("admin_print_scripts-$page", array(__CLASS__, 'create_admin_pages_scripts')); // Add js to my settings page 204 if(1 == $options['is_admin_alert'] && 1 == $options['display_admin_alert'] && current_user_can(SC_WPFMP_ADMIN_ALERT_PERMISSION)) { // is there an admin display? 205 add_action("admin_print_scripts", array(__CLASS__, 'create_admin_pages_tbscripts')); // load thickbox js 206 add_action("admin_print_styles", array(__CLASS__, 'create_admin_pages_tbstyles')); // load thickbox css 207 } 208 } 209 public function settings_page() { 210 ?> 211 <div class="wrap"> 212 <?php screen_icon(); ?> 213 <h2><?php _e("WordPress File Monitor Plus", "wordpress-file-monitor-plus"); ?></h2> 214 <form action="options.php" method="post"> 215 <?php 216 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'sc_wpfmp_action', 'sc_wpfmp_scan', 'sc_wpfmp_reset_settings', 'sc_wpfmp_clear_admin_alert', 'sc_wpfmp_clear_admin_alert' ) ); 217 settings_fields("sc_wpfmp_settings"); 218 do_settings_sections("wordpress-file-monitor-plus"); 219 ?> 220 <p class="submit"> 221 <?php submit_button(__("Save changes", "wordpress-file-monitor-plus"), "primary", "submit", false); ?> 222 <a class="button-secondary" href="<?php echo admin_url("options-general.php?page=wordpress-file-monitor-plus&sc_wpfmp_action=sc_wpfmp_scan"); ?>"><?php _e("Manual scan", "wordpress-file-monitor-plus"); ?></a> 223 <a class="button-secondary" href="<?php echo admin_url("options-general.php?page=wordpress-file-monitor-plus&sc_wpfmp_action=sc_wpfmp_reset_settings"); ?>"><?php _e("Reset settings to defaults", "wordpress-file-monitor-plus"); ?></a> 224 </p> 225 </form> 226 </div> 227 <?php 228 } 229 public function admin_settings_init() { 230 register_setting(sc_WordPressFileMonitorPlus::$settings_option_field, sc_WordPressFileMonitorPlus::$settings_option_field, array(__CLASS__, "sc_wpfmp_settings_validate")); // Register Main Settings 231 add_settings_section("sc_wpfmp_settings_main", __("Settings", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_text"), "wordpress-file-monitor-plus"); // Make settings main section 232 add_settings_field("sc_wpfmp_settings_main_cron_method", __("Cron Method", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_cron_method"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 233 add_settings_field("sc_wpfmp_settings_main_file_check_interval", __("File Check Interval", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_file_check_interval"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 234 add_settings_field("sc_wpfmp_settings_main_data_save", __("Data Save Method", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_data_save"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 235 add_settings_field("sc_wpfmp_settings_main_notify_by_email", __("Notify By Email", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_notify_by_email"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 236 add_settings_field("sc_wpfmp_settings_main_from_address", __("From Email Address", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_from_address"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 237 add_settings_field("sc_wpfmp_settings_main_notify_address", __("Notify Email Address", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_notify_address"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 238 add_settings_field("sc_wpfmp_settings_main_display_admin_alert", __("Admin Alert", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_display_admin_alert"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 239 add_settings_field("sc_wpfmp_settings_main_file_check_method", __("File Check Method", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_file_check_method"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 240 add_settings_field("sc_wpfmp_settings_main_site_root", __("File Check Root", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_site_root"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 241 add_settings_field("sc_wpfmp_settings_main_exclude_paths_files", __("Dirs/Files To Ignore", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_exclude_paths_files"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 242 add_settings_field("sc_wpfmp_settings_main_file_extension_mode", __("File Extensions Scan", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_file_extension_mode"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 243 add_settings_field("sc_wpfmp_settings_main_file_extensions", __("File Extensions", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_file_extensions"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 244 } 245 public function sc_wpfmp_settings_validate($input) { 246 $valid = get_option(sc_WordPressFileMonitorPlus::$settings_option_field); 247 if(in_array($input['cron_method'], array("wordpress", "other"))) { 248 $valid['cron_method'] = $input['cron_method']; 249 } else { 250 add_settings_error("sc_wpfmp_settings_main_cron_method", "sc_wpfmp_settings_main_cron_method_error", __("Invalid cron method selected", "wordpress-file-monitor-plus"), "error"); 251 } 252 if("other" == $valid['cron_method']) { // If cron method is other 253 $input['file_check_interval'] = "manual"; // then force scan interval to manual 254 } 255 if(in_array($input['file_check_interval'], self::$frequency_intervals)) { 256 $valid['file_check_interval'] = $input['file_check_interval']; 257 sc_WordPressFileMonitorPlus::enable_cron($input['file_check_interval']); 258 } else { 259 add_settings_error("sc_wpfmp_settings_main_file_check_interval", "sc_wpfmp_settings_main_file_check_interval_error", __("Invalid file check interval selected", "wordpress-file-monitor-plus"), "error"); 260 } 261 if(in_array($input['data_save'], array("database", "file"))) { 262 $valid['data_save'] = $input['data_save']; 263 } else { 264 add_settings_error("sc_wpfmp_settings_main_data_save", "sc_wpfmp_settings_main_data_save_error", __("Invalid data save method selected", "wordpress-file-monitor-plus"), "error"); 265 } 266 $sanitized_notify_by_email = absint($input['notify_by_email']); 267 if(1 === $sanitized_notify_by_email || 0 === $sanitized_notify_by_email) { 268 $valid['notify_by_email'] = $sanitized_notify_by_email; 269 } else { 270 add_settings_error("sc_wpfmp_settings_main_notify_by_email", "sc_wpfmp_settings_main_notify_by_email_error", __("Invalid notify by email selected", "wordpress-file-monitor-plus"), "error"); 271 } 272 $sanitized_email_from = sanitize_email($input['from_address']); 273 if(is_email($sanitized_email_from)) { 274 $valid['from_address'] = $sanitized_email_from; 275 } else { 276 add_settings_error("sc_wpfmp_settings_main_from_address", "sc_wpfmp_settings_main_from_address_error", __("Invalid from email address entered", "wordpress-file-monitor-plus"), "error"); 277 } 278 $sanitized_email_to = sanitize_email($input['notify_address']); 279 if(is_email($sanitized_email_to)) { 280 $valid['notify_address'] = $sanitized_email_to; 281 } else { 282 add_settings_error("sc_wpfmp_settings_main_notify_address", "sc_wpfmp_settings_main_notify_address_error", __("Invalid notify email address entered", "wordpress-file-monitor-plus"), "error"); 283 } 284 $sanitized_display_admin_alert = absint($input['display_admin_alert']); 285 if(1 === $sanitized_display_admin_alert || 0 === $sanitized_display_admin_alert) { 286 $valid['display_admin_alert'] = $sanitized_display_admin_alert; 287 } else { 288 add_settings_error("sc_wpfmp_settings_main_display_admin_alert", "sc_wpfmp_settings_main_display_admin_alert_error", __("Invalid display admin alert selected", "wordpress-file-monitor-plus"), "error"); 289 } 290 $valid['file_check_method'] = array_map(array(__CLASS__, 'file_check_method_func'), $input['file_check_method']); 291 $sanitized_site_root = realpath($input['site_root']); 292 if(is_dir($sanitized_site_root) && is_readable($sanitized_site_root)) { 293 $valid['site_root'] = $sanitized_site_root; 294 } else { 295 add_settings_error("sc_wpfmp_settings_main_site_root", "sc_wpfmp_settings_main_site_root_error", __("File check root is not valid. Make sure that PHP has read permissions of the entered file check root", "wordpress-file-monitor-plus"), "error"); 296 } 297 $valid['exclude_paths_files'] = self::textarea_newlines_to_array($input['exclude_paths_files']); 298 $sanitized_file_extension_mode = absint($input['file_extension_mode']); 299 if(2 === $sanitized_file_extension_mode || 1 === $sanitized_file_extension_mode || 0 === $sanitized_file_extension_mode) { 300 $valid['file_extension_mode'] = $sanitized_file_extension_mode; 301 } else { 302 add_settings_error("sc_wpfmp_settings_main_file_extension_mode", "sc_wpfmp_settings_main_file_extension_mode_error", __("Invalid file extension mode selected", "wordpress-file-monitor-plus"), "error"); 303 } 304 $valid['file_extensions'] = self::file_extensions_to_array($input['file_extensions']); 305 return $valid; 306 } 307 public function sc_wpfmp_settings_main_text() {} 308 public function sc_wpfmp_settings_main_field_cron_method() { 309 $options = get_option(sc_WordPressFileMonitorPlus::$settings_option_field); 310 ?> 311 <select name="<?php echo sc_WordPressFileMonitorPlus::$settings_option_field ?>[cron_method]"> 312 <option value="wordpress" <?php selected( $options['cron_method'], "wordpress" ); ?>><?php _e("WordPress Cron", "wordpress-file-monitor-plus"); ?></option> 313 <option value="other" <?php selected( $options['cron_method'], "other" ); ?>><?php _e("Other Cron", "wordpress-file-monitor-plus"); ?></option> 314 </select> 315 <div> 316 <br /> 317 <span class="description"><?php _e("Cron Command: ", "wordpress-file-monitor-plus"); ?></span> 318 <pre>wget -q "<?php echo site_url(); ?>/index.php?sc_wpfmp_scan=1&sc_wpfmp_key=<?php echo $options['security_key']; ?>" -O /dev/null >/dev/null 2>&1</pre> 319 </div> 320 <?php 321 } 322 public function sc_wpfmp_settings_main_field_file_check_interval() { 323 $options = get_option(sc_WordPressFileMonitorPlus::$settings_option_field); 324 ?> 325 <select name="<?php echo sc_WordPressFileMonitorPlus::$settings_option_field ?>[file_check_interval]"> 326 <option value="<?php echo self::$frequency_intervals[0]; ?>" <?php selected( $options['file_check_interval'], self::$frequency_intervals[0] ); ?>><?php _e("Hourly", "wordpress-file-monitor-plus"); ?></option> 327 <option value="<?php echo self::$frequency_intervals[1]; ?>" <?php selected( $options['file_check_interval'], self::$frequency_intervals[1] ); ?>><?php _e("Twice Daily", "wordpress-file-monitor-plus"); ?></option> 328 <option value="<?php echo self::$frequency_intervals[2]; ?>" <?php selected( $options['file_check_interval'], self::$frequency_intervals[2] ); ?>><?php _e("Daily", "wordpress-file-monitor-plus"); ?></option> 329 <option value="<?php echo self::$frequency_intervals[3]; ?>" <?php selected( $options['file_check_interval'], self::$frequency_intervals[3] ); ?>><?php _e("Manual", "wordpress-file-monitor-plus"); ?></option> 330 </select> 331 <?php 332 } 333 public function sc_wpfmp_settings_main_field_data_save() { 334 $options = get_option(sc_WordPressFileMonitorPlus::$settings_option_field); 335 ?> 336 <select name="<?php echo sc_WordPressFileMonitorPlus::$settings_option_field ?>[data_save]"> 337 <option value="database" <?php selected( $options['data_save'], "database" ); ?>><?php _e("Database", "wordpress-file-monitor-plus"); ?></option> 338 <option value="file" <?php selected( $options['data_save'], "file" ); ?>><?php _e("File", "wordpress-file-monitor-plus"); ?></option> 339 </select> 340 <?php 341 } 342 public function sc_wpfmp_settings_main_field_notify_by_email() { 343 $options = get_option(sc_WordPressFileMonitorPlus::$settings_option_field); 344 ?> 345 <select name="<?php echo sc_WordPressFileMonitorPlus::$settings_option_field ?>[notify_by_email]"> 346 <option value="1" <?php selected( $options['notify_by_email'], 1 ); ?>><?php _e("Yes", "wordpress-file-monitor-plus"); ?></option> 347 <option value="0" <?php selected( $options['notify_by_email'], 0 ); ?>><?php _e("No", "wordpress-file-monitor-plus"); ?></option> 348 </select> 349 <?php 350 } 351 public function sc_wpfmp_settings_main_field_from_address() { 352 $options = get_option(sc_WordPressFileMonitorPlus::$settings_option_field); 353 ?><input class="regular-text" name="<?php echo sc_WordPressFileMonitorPlus::$settings_option_field ?>[from_address]" value="<?php echo $options['from_address']; ?>" /><?php 354 } 355 public function sc_wpfmp_settings_main_field_notify_address() { 356 $options = get_option(sc_WordPressFileMonitorPlus::$settings_option_field); 357 ?><input class="regular-text" name="<?php echo sc_WordPressFileMonitorPlus::$settings_option_field ?>[notify_address]" value="<?php echo $options['notify_address']; ?>" /><?php 358 } 359 public function sc_wpfmp_settings_main_field_display_admin_alert() { 360 $options = get_option(sc_WordPressFileMonitorPlus::$settings_option_field); 361 ?> 362 <select name="<?php echo sc_WordPressFileMonitorPlus::$settings_option_field ?>[display_admin_alert]"> 363 <option value="1" <?php selected( $options['display_admin_alert'], 1 ); ?>><?php _e("Yes", "wordpress-file-monitor-plus"); ?></option> 364 <option value="0" <?php selected( $options['display_admin_alert'], 0 ); ?>><?php _e("No", "wordpress-file-monitor-plus"); ?></option> 365 </select> 366 <?php 367 } 368 public function sc_wpfmp_settings_main_field_file_check_method() { 369 $options = get_option(sc_WordPressFileMonitorPlus::$settings_option_field); 370 ?> 371 <input name="<?php echo sc_WordPressFileMonitorPlus::$settings_option_field ?>[file_check_method][size]" type="checkbox" value="1" <?php checked( $options['file_check_method']['size'], 1 ); ?> /><?php _e(" File Size", "wordpress-file-monitor-plus"); ?><br /> 372 <input name="<?php echo sc_WordPressFileMonitorPlus::$settings_option_field ?>[file_check_method][modified]" type="checkbox" value="1" <?php checked( $options['file_check_method']['modified'], 1 ); ?> /><?php _e(" Date Modified", "wordpress-file-monitor-plus"); ?><br /> 373 <input name="<?php echo sc_WordPressFileMonitorPlus::$settings_option_field ?>[file_check_method][md5]" type="checkbox" value="1" <?php checked( $options['file_check_method']['md5'], 1 ); ?> /><?php _e(" File Hash", "wordpress-file-monitor-plus"); ?> 374 <?php 375 } 376 public function sc_wpfmp_settings_main_field_site_root() { 377 $options = get_option(sc_WordPressFileMonitorPlus::$settings_option_field); 378 ?><input name="<?php echo sc_WordPressFileMonitorPlus::$settings_option_field ?>[site_root]" value="<?php echo $options['site_root']; ?>" /> <span class="description"><?php printf(__("Default: %s", "wordpress-file-monitor-plus"), realpath(ABSPATH)); ?></span><?php 379 } 380 public function sc_wpfmp_settings_main_exclude_paths_files() { 381 $options = get_option(sc_WordPressFileMonitorPlus::$settings_option_field); 382 ?><textarea name="<?php echo sc_WordPressFileMonitorPlus::$settings_option_field ?>[exclude_paths_files]" cols="60" rows="8"><?php echo implode("\n", $options['exclude_paths_files']); ?></textarea><?php 383 } 384 public function sc_wpfmp_settings_main_field_file_extension_mode() { 385 $options = get_option(sc_WordPressFileMonitorPlus::$settings_option_field); 386 ?> 387 <select name="<?php echo sc_WordPressFileMonitorPlus::$settings_option_field ?>[file_extension_mode]"> 388 <option value="0" <?php selected( $options['file_extension_mode'], 0 ); ?>><?php _e("Disabled", "wordpress-file-monitor-plus"); ?></option> 389 <option value="1" <?php selected( $options['file_extension_mode'], 1 ); ?>><?php _e("Exclude files that have an extension listed below", "wordpress-file-monitor-plus"); ?></option> 390 <option value="2" <?php selected( $options['file_extension_mode'], 2 ); ?>><?php _e("Only scan files that have an extension listed below", "wordpress-file-monitor-plus"); ?></option> 391 </select> 392 <?php 393 } 394 public function sc_wpfmp_settings_main_field_file_extensions() { 395 $options = get_option(sc_WordPressFileMonitorPlus::$settings_option_field); 396 ?><input class="regular-text" name="<?php echo sc_WordPressFileMonitorPlus::$settings_option_field ?>[file_extensions]" value="<?php echo implode($options['file_extensions'], "|"); ?>" /> <span class="description"><?php _e("Separate extensions with | character.", "wordpress-file-monitor-plus"); ?></span><?php 397 } 398 public function create_admin_pages_scripts() { 399 wp_enqueue_script('wordpress_file_monitor_plus_js_function', plugins_url('js/function.js', "wordpress-file-monitor-plus/wordpress-file-monitor-plus.php"), array('jquery'), '1.2', true); 400 } 401 public function create_admin_pages_tbscripts() { 402 wp_enqueue_script('thickbox'); 403 } 404 public function create_admin_pages_tbstyles() { 405 wp_enqueue_style('thickbox'); 406 } 407 protected function file_check_method_func($n) { 408 $n = absint($n); 409 if(1 !== $n) { $n = 0; } 410 return $n; 411 } 412 413 414 /** 415 * Takes multiline input from textarea and splits newlines into an array. 416 * 417 * @param string $input Text from textarea 418 * @return array $output 419 */ 420 protected function textarea_newlines_to_array($input) { 421 $output = (array) explode("\n", $input); // Split textarea input by new lines 422 $output = array_map('trim', $output); // trim whitespace off end of line. 423 $output = array_filter($output); // remove empty lines from array 424 return $output; // return array. 425 } 426 427 428 /** 429 * Takes extension list "foo|bar|foo|bar" and converts into array. 430 * 431 * @param string $input Extension list from settings page input 432 * @return array $output 433 */ 434 protected function file_extensions_to_array($input) { 435 $output = strtolower($input); // set all to lower case 436 $output = preg_replace("/[^a-z0-9|]+/", "", $output); // strip characters that cannot make up valid extension 437 $output = (array) explode("|", $output); // Split into array 438 $output = array_filter($output); // remove empty entries from array 439 return $output; 440 } 171 } 172 $page = add_options_page('WordPress File Monitor Plus', 'WordPress File Monitor Plus', 'manage_options', 'wordpress-file-monitor-plus', array(__CLASS__, 'settings_page')); 173 add_action("admin_print_scripts-$page", array(__CLASS__, 'create_admin_pages_scripts')); // Add js to my settings page 174 if(1 == $options['is_admin_alert'] && 1 == $options['display_admin_alert'] && current_user_can(SC_WPFMP_ADMIN_ALERT_PERMISSION)) { // is there an admin display? 175 add_action("admin_print_scripts", array(__CLASS__, 'create_admin_pages_tbscripts')); // load thickbox js 176 add_action("admin_print_styles", array(__CLASS__, 'create_admin_pages_tbstyles')); // load thickbox css 177 } 178 } 179 public function settings_page() { 180 ?> 181 <div class="wrap"> 182 <?php screen_icon(); ?> 183 <h2><?php _e("WordPress File Monitor Plus", "wordpress-file-monitor-plus"); ?></h2> 184 <form action="options.php" method="post"> 185 <?php 186 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'sc_wpfmp_action', 'sc_wpfmp_scan', 'sc_wpfmp_reset_settings', 'sc_wpfmp_clear_admin_alert', 'sc_wpfmp_clear_admin_alert' ) ); 187 settings_fields("sc_wpfmp_settings"); 188 do_settings_sections("wordpress-file-monitor-plus"); 189 ?> 190 <p class="submit"> 191 <?php submit_button(__("Save changes", "wordpress-file-monitor-plus"), "primary", "submit", false); ?> 192 <a class="button-secondary" href="<?php echo admin_url("options-general.php?page=wordpress-file-monitor-plus&sc_wpfmp_action=sc_wpfmp_scan"); ?>"><?php _e("Manual scan", "wordpress-file-monitor-plus"); ?></a> 193 <a class="button-secondary" href="<?php echo admin_url("options-general.php?page=wordpress-file-monitor-plus&sc_wpfmp_action=sc_wpfmp_reset_settings"); ?>"><?php _e("Reset settings to defaults", "wordpress-file-monitor-plus"); ?></a> 194 </p> 195 </form> 196 </div> 197 <?php 198 } 199 public function admin_settings_init() { 200 register_setting(parent::$settings_option_field, parent::$settings_option_field, array(__CLASS__, "sc_wpfmp_settings_validate")); // Register Main Settings 201 add_settings_section("sc_wpfmp_settings_main", __("Settings", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_text"), "wordpress-file-monitor-plus"); // Make settings main section 202 add_settings_field("sc_wpfmp_settings_main_cron_method", __("Cron Method", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_cron_method"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 203 add_settings_field("sc_wpfmp_settings_main_file_check_interval", __("File Check Interval", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_file_check_interval"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 204 add_settings_field("sc_wpfmp_settings_main_data_save", __("Data Save Method", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_data_save"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 205 add_settings_field("sc_wpfmp_settings_main_notify_by_email", __("Notify By Email", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_notify_by_email"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 206 add_settings_field("sc_wpfmp_settings_main_from_address", __("From Email Address", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_from_address"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 207 add_settings_field("sc_wpfmp_settings_main_notify_address", __("Notify Email Address", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_notify_address"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 208 add_settings_field("sc_wpfmp_settings_main_display_admin_alert", __("Admin Alert", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_display_admin_alert"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 209 add_settings_field("sc_wpfmp_settings_main_file_check_method", __("File Check Method", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_file_check_method"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 210 add_settings_field("sc_wpfmp_settings_main_site_root", __("File Check Root", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_site_root"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 211 add_settings_field("sc_wpfmp_settings_main_exclude_paths_files", __("Dirs/Files To Ignore", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_exclude_paths_files"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 212 add_settings_field("sc_wpfmp_settings_main_file_extension_mode", __("File Extensions Scan", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_file_extension_mode"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 213 add_settings_field("sc_wpfmp_settings_main_file_extensions", __("File Extensions", "wordpress-file-monitor-plus"), array(__CLASS__, "sc_wpfmp_settings_main_field_file_extensions"), "wordpress-file-monitor-plus", "sc_wpfmp_settings_main"); 214 } 215 public function sc_wpfmp_settings_validate($input) { 216 $valid = get_option(parent::$settings_option_field); 217 if(in_array($input['cron_method'], array("wordpress", "other"))) { 218 $valid['cron_method'] = $input['cron_method']; 219 } else { 220 add_settings_error("sc_wpfmp_settings_main_cron_method", "sc_wpfmp_settings_main_cron_method_error", __("Invalid cron method selected", "wordpress-file-monitor-plus"), "error"); 221 } 222 if("other" == $valid['cron_method']) { // If cron method is other 223 $input['file_check_interval'] = "manual"; // then force scan interval to manual 224 } 225 if(in_array($input['file_check_interval'], self::$frequency_intervals)) { 226 $valid['file_check_interval'] = $input['file_check_interval']; 227 parent::enable_cron($input['file_check_interval']); 228 } else { 229 add_settings_error("sc_wpfmp_settings_main_file_check_interval", "sc_wpfmp_settings_main_file_check_interval_error", __("Invalid file check interval selected", "wordpress-file-monitor-plus"), "error"); 230 } 231 if(in_array($input['data_save'], array("database", "file"))) { 232 $valid['data_save'] = $input['data_save']; 233 } else { 234 add_settings_error("sc_wpfmp_settings_main_data_save", "sc_wpfmp_settings_main_data_save_error", __("Invalid data save method selected", "wordpress-file-monitor-plus"), "error"); 235 } 236 $sanitized_notify_by_email = absint($input['notify_by_email']); 237 if(1 === $sanitized_notify_by_email || 0 === $sanitized_notify_by_email) { 238 $valid['notify_by_email'] = $sanitized_notify_by_email; 239 } else { 240 add_settings_error("sc_wpfmp_settings_main_notify_by_email", "sc_wpfmp_settings_main_notify_by_email_error", __("Invalid notify by email selected", "wordpress-file-monitor-plus"), "error"); 241 } 242 $sanitized_email_from = sanitize_email($input['from_address']); 243 if(is_email($sanitized_email_from)) { 244 $valid['from_address'] = $sanitized_email_from; 245 } else { 246 add_settings_error("sc_wpfmp_settings_main_from_address", "sc_wpfmp_settings_main_from_address_error", __("Invalid from email address entered", "wordpress-file-monitor-plus"), "error"); 247 } 248 $sanitized_email_to = sanitize_email($input['notify_address']); 249 if(is_email($sanitized_email_to)) { 250 $valid['notify_address'] = $sanitized_email_to; 251 } else { 252 add_settings_error("sc_wpfmp_settings_main_notify_address", "sc_wpfmp_settings_main_notify_address_error", __("Invalid notify email address entered", "wordpress-file-monitor-plus"), "error"); 253 } 254 $sanitized_display_admin_alert = absint($input['display_admin_alert']); 255 if(1 === $sanitized_display_admin_alert || 0 === $sanitized_display_admin_alert) { 256 $valid['display_admin_alert'] = $sanitized_display_admin_alert; 257 } else { 258 add_settings_error("sc_wpfmp_settings_main_display_admin_alert", "sc_wpfmp_settings_main_display_admin_alert_error", __("Invalid display admin alert selected", "wordpress-file-monitor-plus"), "error"); 259 } 260 $valid['file_check_method'] = array_map(array(__CLASS__, 'file_check_method_func'), $input['file_check_method']); 261 $sanitized_site_root = realpath($input['site_root']); 262 if(is_dir($sanitized_site_root) && is_readable($sanitized_site_root)) { 263 $valid['site_root'] = $sanitized_site_root; 264 } else { 265 add_settings_error("sc_wpfmp_settings_main_site_root", "sc_wpfmp_settings_main_site_root_error", __("File check root is not valid. Make sure that PHP has read permissions of the entered file check root", "wordpress-file-monitor-plus"), "error"); 266 } 267 $valid['exclude_paths_files'] = self::textarea_newlines_to_array($input['exclude_paths_files']); 268 $sanitized_file_extension_mode = absint($input['file_extension_mode']); 269 if(2 === $sanitized_file_extension_mode || 1 === $sanitized_file_extension_mode || 0 === $sanitized_file_extension_mode) { 270 $valid['file_extension_mode'] = $sanitized_file_extension_mode; 271 } else { 272 add_settings_error("sc_wpfmp_settings_main_file_extension_mode", "sc_wpfmp_settings_main_file_extension_mode_error", __("Invalid file extension mode selected", "wordpress-file-monitor-plus"), "error"); 273 } 274 $valid['file_extensions'] = self::file_extensions_to_array($input['file_extensions']); 275 return $valid; 276 } 277 public function sc_wpfmp_settings_main_text() {} 278 public function sc_wpfmp_settings_main_field_cron_method() { 279 $options = get_option(parent::$settings_option_field); 280 ?> 281 <select name="<?php echo parent::$settings_option_field ?>[cron_method]"> 282 <option value="wordpress" <?php selected( $options['cron_method'], "wordpress" ); ?>><?php _e("WordPress Cron", "wordpress-file-monitor-plus"); ?></option> 283 <option value="other" <?php selected( $options['cron_method'], "other" ); ?>><?php _e("Other Cron", "wordpress-file-monitor-plus"); ?></option> 284 </select> 285 <div> 286 <br /> 287 <span class="description"><?php _e("Cron Command: ", "wordpress-file-monitor-plus"); ?></span> 288 <pre>wget -q "<?php echo site_url(); ?>/index.php?sc_wpfmp_scan=1&sc_wpfmp_key=<?php echo $options['security_key']; ?>" -O /dev/null >/dev/null 2>&1</pre> 289 </div> 290 <?php 291 } 292 public function sc_wpfmp_settings_main_field_file_check_interval() { 293 $options = get_option(parent::$settings_option_field); 294 ?> 295 <select name="<?php echo parent::$settings_option_field ?>[file_check_interval]"> 296 <option value="<?php echo self::$frequency_intervals[0]; ?>" <?php selected( $options['file_check_interval'], self::$frequency_intervals[0] ); ?>><?php _e("Hourly", "wordpress-file-monitor-plus"); ?></option> 297 <option value="<?php echo self::$frequency_intervals[1]; ?>" <?php selected( $options['file_check_interval'], self::$frequency_intervals[1] ); ?>><?php _e("Twice Daily", "wordpress-file-monitor-plus"); ?></option> 298 <option value="<?php echo self::$frequency_intervals[2]; ?>" <?php selected( $options['file_check_interval'], self::$frequency_intervals[2] ); ?>><?php _e("Daily", "wordpress-file-monitor-plus"); ?></option> 299 <option value="<?php echo self::$frequency_intervals[3]; ?>" <?php selected( $options['file_check_interval'], self::$frequency_intervals[3] ); ?>><?php _e("Manual", "wordpress-file-monitor-plus"); ?></option> 300 </select> 301 <?php 302 } 303 public function sc_wpfmp_settings_main_field_data_save() { 304 $options = get_option(parent::$settings_option_field); 305 ?> 306 <select name="<?php echo parent::$settings_option_field ?>[data_save]"> 307 <option value="database" <?php selected( $options['data_save'], "database" ); ?>><?php _e("Database", "wordpress-file-monitor-plus"); ?></option> 308 <option value="file" <?php selected( $options['data_save'], "file" ); ?>><?php _e("File", "wordpress-file-monitor-plus"); ?></option> 309 </select> 310 <?php 311 } 312 public function sc_wpfmp_settings_main_field_notify_by_email() { 313 $options = get_option(parent::$settings_option_field); 314 ?> 315 <select name="<?php echo parent::$settings_option_field ?>[notify_by_email]"> 316 <option value="1" <?php selected( $options['notify_by_email'], 1 ); ?>><?php _e("Yes", "wordpress-file-monitor-plus"); ?></option> 317 <option value="0" <?php selected( $options['notify_by_email'], 0 ); ?>><?php _e("No", "wordpress-file-monitor-plus"); ?></option> 318 </select> 319 <?php 320 } 321 public function sc_wpfmp_settings_main_field_from_address() { 322 $options = get_option(parent::$settings_option_field); 323 ?><input class="regular-text" name="<?php echo parent::$settings_option_field ?>[from_address]" value="<?php echo $options['from_address']; ?>" /><?php 324 } 325 public function sc_wpfmp_settings_main_field_notify_address() { 326 $options = get_option(parent::$settings_option_field); 327 ?><input class="regular-text" name="<?php echo parent::$settings_option_field ?>[notify_address]" value="<?php echo $options['notify_address']; ?>" /><?php 328 } 329 public function sc_wpfmp_settings_main_field_display_admin_alert() { 330 $options = get_option(parent::$settings_option_field); 331 ?> 332 <select name="<?php echo parent::$settings_option_field ?>[display_admin_alert]"> 333 <option value="1" <?php selected( $options['display_admin_alert'], 1 ); ?>><?php _e("Yes", "wordpress-file-monitor-plus"); ?></option> 334 <option value="0" <?php selected( $options['display_admin_alert'], 0 ); ?>><?php _e("No", "wordpress-file-monitor-plus"); ?></option> 335 </select> 336 <?php 337 } 338 public function sc_wpfmp_settings_main_field_file_check_method() { 339 $options = get_option(parent::$settings_option_field); 340 ?> 341 <input name="<?php echo parent::$settings_option_field ?>[file_check_method][size]" type="checkbox" value="1" <?php checked( $options['file_check_method']['size'], 1 ); ?> /><?php _e(" File Size", "wordpress-file-monitor-plus"); ?><br /> 342 <input name="<?php echo parent::$settings_option_field ?>[file_check_method][modified]" type="checkbox" value="1" <?php checked( $options['file_check_method']['modified'], 1 ); ?> /><?php _e(" Date Modified", "wordpress-file-monitor-plus"); ?><br /> 343 <input name="<?php echo parent::$settings_option_field ?>[file_check_method][md5]" type="checkbox" value="1" <?php checked( $options['file_check_method']['md5'], 1 ); ?> /><?php _e(" File Hash", "wordpress-file-monitor-plus"); ?> 344 <?php 345 } 346 public function sc_wpfmp_settings_main_field_site_root() { 347 $options = get_option(parent::$settings_option_field); 348 ?><input name="<?php echo parent::$settings_option_field ?>[site_root]" value="<?php echo $options['site_root']; ?>" /> <span class="description"><?php printf(__("Default: %s", "wordpress-file-monitor-plus"), realpath(ABSPATH)); ?></span><?php 349 } 350 public function sc_wpfmp_settings_main_exclude_paths_files() { 351 $options = get_option(parent::$settings_option_field); 352 ?><textarea name="<?php echo parent::$settings_option_field ?>[exclude_paths_files]" cols="60" rows="8"><?php echo implode("\n", $options['exclude_paths_files']); ?></textarea><?php 353 } 354 public function sc_wpfmp_settings_main_field_file_extension_mode() { 355 $options = get_option(parent::$settings_option_field); 356 ?> 357 <select name="<?php echo parent::$settings_option_field ?>[file_extension_mode]"> 358 <option value="0" <?php selected( $options['file_extension_mode'], 0 ); ?>><?php _e("Disabled", "wordpress-file-monitor-plus"); ?></option> 359 <option value="1" <?php selected( $options['file_extension_mode'], 1 ); ?>><?php _e("Exclude files that have an extension listed below", "wordpress-file-monitor-plus"); ?></option> 360 <option value="2" <?php selected( $options['file_extension_mode'], 2 ); ?>><?php _e("Only scan files that have an extension listed below", "wordpress-file-monitor-plus"); ?></option> 361 </select> 362 <?php 363 } 364 public function sc_wpfmp_settings_main_field_file_extensions() { 365 $options = get_option(parent::$settings_option_field); 366 ?><input class="regular-text" name="<?php echo parent::$settings_option_field ?>[file_extensions]" value="<?php echo implode($options['file_extensions'], "|"); ?>" /> <span class="description"><?php _e("Separate extensions with | character.", "wordpress-file-monitor-plus"); ?></span><?php 367 } 368 public function create_admin_pages_scripts() { 369 wp_enqueue_script('wordpress_file_monitor_plus_js_function', plugins_url('js/function.js', "wordpress-file-monitor-plus/wordpress-file-monitor-plus.php"), array('jquery'), '1.2', true); 370 } 371 public function create_admin_pages_tbscripts() { 372 wp_enqueue_script('thickbox'); 373 } 374 public function create_admin_pages_tbstyles() { 375 wp_enqueue_style('thickbox'); 376 } 377 protected function file_check_method_func($n) { 378 $n = absint($n); 379 if(1 !== $n) { $n = 0; } 380 return $n; 381 } 382 383 384 /** 385 * Takes multiline input from textarea and splits newlines into an array. 386 * 387 * @param string $input Text from textarea 388 * @return array $output 389 */ 390 protected function textarea_newlines_to_array($input) { 391 $output = (array) explode("\n", $input); // Split textarea input by new lines 392 $output = array_map('trim', $output); // trim whitespace off end of line. 393 $output = array_filter($output); // remove empty lines from array 394 return $output; // return array. 395 } 396 397 398 /** 399 * Takes extension list "foo|bar|foo|bar" and converts into array. 400 * 401 * @param string $input Extension list from settings page input 402 * @return array $output 403 */ 404 protected function file_extensions_to_array($input) { 405 $output = strtolower($input); // set all to lower case 406 $output = preg_replace("/[^a-z0-9|]+/", "", $output); // strip characters that cannot make up valid extension 407 $output = (array) explode("|", $output); // Split into array 408 $output = array_filter($output); // remove empty entries from array 409 return $output; 441 410 } 442 411 } -
wordpress-file-monitor-plus/trunk/readme.txt
r539102 r539134 5 5 Requires at least: 3.1 6 6 Tested up to: 3.3.2 7 Stable tag: 2.07 Stable tag: 1.4.1 8 8 9 9 Monitor files under your WP installation for changes. When a change occurs, be notified via email. This plugin is a fork of WordPress File Monitor. … … 99 99 == Changelog == 100 100 101 = 2.0 =102 * Full refactor of code, optimizing, documenting and overall tidy.103 * Proper multi-site support.104 105 101 = 1.4.1 = 106 102 * fnmatch() wasn't working on Windows. Added `FNM_NOESCAPE` to fnmatch and changed code for fnmatch compatability function to allow `FNM_NOESCAPE`. -
wordpress-file-monitor-plus/trunk/wordpress-file-monitor-plus.php
r539101 r539134 5 5 Description: Monitor your website for added/changed/deleted files 6 6 Author: Scott Cariss 7 Version: 2.07 Version: 1.4.1 8 8 Author URI: http://l3rady.com/ 9 9 Text Domain: wordpress-file-monitor-plus … … 28 28 */ 29 29 30 // Not a WordPress context? Stop. 31 ! defined( 'ABSPATH' ) and exit; 32 33 define( 'SC_WPFMP_PLUGIN_FILE', __FILE__ ); 34 define( 'SC_WPFMP_PLUGIN_FOLDER', dirname( SC_WPFMP_PLUGIN_FILE ) ); 35 define( 'SC_WPFMP_CLASSES_FOLDER', SC_WPFMP_PLUGIN_FOLDER . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR ); 36 define( 'SC_WPFMP_DATA_FOLDER', SC_WPFMP_PLUGIN_FOLDER . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR ); 37 define( 'SC_WPFMP_FUNCTIONS_FOLDER', SC_WPFMP_PLUGIN_FOLDER . DIRECTORY_SEPARATOR . 'functions' . DIRECTORY_SEPARATOR ); 38 39 define( 'SC_WPFMP_FILE_SCAN_DATA', SC_WPFMP_DATA_FOLDER . '.sc_wpfmp_scan_data' ); 40 define( 'SC_WPFMP_FILE_ALERT_CONTENT', SC_WPFMP_DATA_FOLDER . '.sc_wpfmp_admin_alert_content' ); 41 42 require SC_WPFMP_CLASSES_FOLDER . 'wpfmp.class.php'; 43 require SC_WPFMP_CLASSES_FOLDER . 'wpfmp.settings.class.php'; 44 45 require SC_WPFMP_FUNCTIONS_FOLDER . 'compatability.php'; 46 47 sc_WordPressFileMonitorPlus::init(); 48 sc_WordPressFileMonitorPlusSettings::init(); 30 // Only load class if it hasn't already been loaded 31 if (!class_exists('sc_WordPressFileMonitorPlus')) { 32 33 // Wordpress File Monitor Plus Class - All the magic happens here! 34 class sc_WordPressFileMonitorPlus { 35 36 protected static $settings_option_field = "sc_wpfmp_settings"; // Option name for settings 37 protected static $settings_option_field_ver = "sc_wpfmp_settings_ver"; // Option name for settings version 38 protected static $settings_option_field_current_ver = "1.4"; // Current settings version 39 protected static $cron_name = "sc_wpfmp_scan"; // Name of cron 40 protected static $frequency_intervals = array("hourly", "twicedaily", "daily", "manual"); // What cron schedules are available 41 42 public function __construct() { 43 load_plugin_textdomain('wordpress-file-monitor-plus', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/'); // Internationalization 44 if(!defined('SC_WPFMP_ADMIN_ALERT_PERMISSION')) {define('SC_WPFMP_ADMIN_ALERT_PERMISSION', 'manage_options');} // Define the permission to see/read/remove admin alert if not already set in config 45 register_activation_hook(__FILE__, array(__CLASS__, 'activate')); // plugin activate 46 register_deactivation_hook(__FILE__, array(__CLASS__, 'deactive')); // plugin deactivate 47 add_filter('sc_wpfmp_format_file_modified_time', array(__CLASS__, 'format_file_modified_time'), 10, 2); // Create filter for formating the file modified time 48 add_action('init', array(__CLASS__, 'things_to_do')); // Check for things to do when needed 49 add_action('admin_notices', array(__CLASS__, 'admin_alert')); // Admin alert show in dashboard 50 add_action(self::$cron_name, array(__CLASS__, 'scan')); // Create a hook for scanning 51 add_action('sc_wpfmp_enable_wp_cron', array(__CLASS__, 'enable_cron')); // Create a hook for enabling WPFMP cron 52 add_action('sc_wpfmp_disable_wp_cron', array(__CLASS__, 'disable_cron')); // Create a hook for disabling WPFMP cron 53 add_action('sc_wpfmp_send_notify_email', array(__CLASS__, 'send_notify_email')); // Create a hook for sending alert email 54 } 55 56 57 /** 58 * What to do when plugin is activated 59 * 60 * @return void 61 */ 62 public function activate() { 63 do_action("sc_wpfmp_enable_wp_cron"); // Go enable cron 64 } 65 66 67 /** 68 * What to do when plugin is deactivated 69 * 70 * @return void 71 */ 72 public function deactive() { 73 do_action("sc_wpfmp_disable_wp_cron"); // Go disable cron 74 } 75 76 77 /** 78 * Check for form submission, external or manual scan and show alert details 79 * 80 * @return void 81 */ 82 function things_to_do() { 83 $options = get_option(self::$settings_option_field); // get settings 84 if( isset($_GET['sc_wpfmp_scan']) 85 && isset($_GET['sc_wpfmp_key']) 86 && (1 == $_GET['sc_wpfmp_scan']) 87 && ($options['security_key'] == $_GET['sc_wpfmp_key']) 88 && ("other" == $options['cron_method'])) 89 { // Check if a scan is being requested external and that the correct security key is provided and the that the settings allow an external cron 90 do_action('sc_wpfmp_scan'); // Go run file check scan. 91 _e("Scan Successful", "wordpress-file-monitor-plus"); // Simple message to say the cron ran :) 92 exit; // No point showing any other content as this is and external cron running this. 93 } 94 } 95 96 97 /** 98 * Scan files and compare new scan data against old 99 * 100 * @return void 101 */ 102 public function scan() { 103 $options = get_option(self::$settings_option_field); // Get settings 104 $oldScanData = self::getPutScanData("get"); // Get old data 105 $newScanData = (array) self::scan_dirs(); // Get new data 106 ksort($newScanData);// Lets make sure that the new data is always sorted 107 self::getPutScanData("put", $newScanData); // Save newScanData back to database or file 108 if(is_array($oldScanData)) { // Only do checks for file ammends/aditions/removals if we have some old 109 $files_added = array_diff_assoc($newScanData, $oldScanData); // See which files have been added since last scan 110 $files_removed = array_diff_assoc($oldScanData, $newScanData); // See which files have been removed since last scan 111 $comp_newdata = array_diff_key($newScanData, $files_added); // remove added files 112 $comp_olddata = array_diff_key($oldScanData, $files_removed); // remove removed files 113 $changed_files = self::array_compare($comp_newdata, $comp_olddata); // Compare old scan to new scan 114 $count_files_changed = count($changed_files[0]); // number of files changed 115 $count_files_addedd = count($files_added); // number of files added 116 $count_files_removed = count($files_removed); // number of files removed 117 if((1 <= $count_files_changed) || (1 <= $count_files_addedd) || (1 <= $count_files_removed)) { // Any file changes? 118 $alertMessage = self::format_alert($files_added, $files_removed, $changed_files, $oldScanData, $newScanData); // get html alert 119 self::getPutAlertContent("put", $alertMessage); // save html into DB or file to be shown later 120 $options["is_admin_alert"] = 1; // yes there is an admin alert 121 update_option(self::$settings_option_field, $options); // Save settings to save admin alert flag. 122 if(1 == $options['notify_by_email']) { // Are we to notify by email? then do it. 123 do_action("sc_wpfmp_send_notify_email", $alertMessage); // go alert 124 } 125 } 126 } 127 } 128 129 130 /** 131 * Recursivly scan directories 132 * 133 * @param string $path full path to scan 134 * @return array $dirs holds array of all captured files and their details. 135 */ 136 protected function scan_dirs($path = "") { 137 static $options; // Set settings as static so not to repeat get options as we recurse. 138 if(!$options) { // Are settings set? 139 $options = get_option(self::$settings_option_field); // Get settings 140 if("file" == $options['data_save']) { // are we saving to file? 141 $options['exclude_paths_files'][] = dirname(__FILE__).DIRECTORY_SEPARATOR."data".DIRECTORY_SEPARATOR.".sc_wpfmp_scan_data"; // add file to ignore 142 $options['exclude_paths_files'][] = dirname(__FILE__).DIRECTORY_SEPARATOR."data".DIRECTORY_SEPARATOR.".sc_wpfmp_admin_alert_content"; // add file to ignore 143 } 144 if(1 == $options['file_extension_mode']) { 145 $options['file_extensions'] = apply_filters("sc_wpfmp_filter_ignore_extensions", $options['file_extensions']); // Allow other plugins to add remove extensions 146 } elseif(2 == $options['file_extension_mode']) { 147 $options['file_extensions'] = apply_filters("sc_wpfmp_filter_scan_extensions", $options['file_extensions']); // Allow other plugins to add remove extensions 148 } 149 $options['exclude_paths_files'] = apply_filters("sc_wpfmp_filter_exclude_paths_files", $options['exclude_paths_files']); 150 } 151 152 $dirs = array(); 153 154 if ($handle = opendir($options['site_root'].$path)) { // Open dir 155 while (false !== ($file = readdir($handle))) { // loop through dirs 156 if ("." != $file && ".." != $file) { // ignore . and .. 157 $full_file_name = $path.DIRECTORY_SEPARATOR.$file; 158 $full_dir_file_name = $options['site_root'].$full_file_name; 159 if( isset( $options['exclude_paths_files'] ) ) { // have we got any dirs/files to exclude 160 foreach( $options['exclude_paths_files'] as $exclude ) { // loop through dirs/folders to exclude 161 if(fnmatch($exclude, $full_dir_file_name, FNM_NOESCAPE)) { // Any matches? 162 continue 2; // yes lets break from this foreach and skip below code in while loop 163 } 164 } 165 } 166 if('dir' === filetype($full_dir_file_name)) { // is this a directory? 167 $dirs = array_merge((array) $dirs, (array) self::scan_dirs($full_file_name)); // We are all good lets continue down the rabbit hole. 168 } else { // is must be a file if not a directory 169 if( (0 == $options['file_extension_mode']) 170 || ( (1 == $options['file_extension_mode'] ) 171 && ! in_array( strtolower( pathinfo( $file, PATHINFO_EXTENSION ) ), $options['file_extensions'] ) ) 172 || ( (2 == $options['file_extension_mode']) 173 && in_array( strtolower( pathinfo( $file, PATHINFO_EXTENSION ) ), $options['file_extensions'] ) ) ) 174 { 175 $dirs[$full_file_name] = array(); // We are all good lets get the data of the the file. 176 if(1 == $options['file_check_method']['size']) { // are we to check its filesize? 177 $dirs[$full_file_name]["size"] = filesize($options['site_root'].$full_file_name); 178 } 179 if(1 == $options['file_check_method']['modified']) { // are we to check its modified date? 180 $dirs[$full_file_name]["modified"] = filemtime($options['site_root'].$full_file_name); 181 } 182 if(1 == $options['file_check_method']['md5']) { // are we to check its file hash? 183 $dirs[$full_file_name]["md5"] = md5_file($options['site_root'].$full_file_name); 184 } 185 } 186 } 187 } 188 } 189 closedir($handle); // close directory 190 } 191 return $dirs; // return the files we found in this dir 192 } 193 194 195 /** 196 * Creates HTML for email and admin alert 197 * 198 * @param array $files_added Array holding any files that have been added 199 * @param array $files_removed Array holding any files that have been removed 200 * @param array $changed_files Array holding any files that have been changed 201 * @param array $oldScanData Array holding all files in old scan data 202 * @param array $newScanData Array holding all files in new scan data 203 * @return string $alertMessage return formatted HTML 204 */ 205 protected function format_alert($files_added, $files_removed, $changed_files, $oldScanData, $newScanData) { 206 $options = get_option(self::$settings_option_field); // Get settings 207 $alertMessage = ""; 208 if(1 == $options['display_admin_alert']) { 209 $alertMessage .= "<a class='button-secondary' href='".admin_url("options-general.php?page=wordpress-file-monitor-plus&sc_wpfmp_action=sc_wpfmp_clear_admin_alert")."'>".__("Clear admin alert", "wordpress-file-monitor-plus")."</a><br /><br />"; 210 } 211 $alertMessage .= sprintf(__("Files Changed: %d", "wordpress-file-monitor-plus"), count($changed_files[0]))."<br />"; 212 $alertMessage .= sprintf(__("Files Added: %d", "wordpress-file-monitor-plus"), count($files_added))."<br />"; 213 $alertMessage .= sprintf(__("Files Removed: %d", "wordpress-file-monitor-plus"), count($files_removed))."<br />"; 214 $alertMessage .= "<br />"; 215 if(count($changed_files[0]) >= 1) { // Only do this if some changed files 216 $alertMessage .= "<strong>".__("Files Changed:", "wordpress-file-monitor-plus")."</strong>"; 217 $alertMessage .= "<table class='widefat' width='100%' border='1' cellspacing='0' cellpadding='2'>"; 218 $alertMessage .= " <thead>"; 219 $alertMessage .= " <tr>"; 220 $alertMessage .= " <th width='100%'>".__("File", "wordpress-file-monitor-plus")."</th>"; 221 if(1 == $options['file_check_method']['size']) { 222 $alertMessage .= " <th nowrap='nowrap'>".__("New Filesize", "wordpress-file-monitor-plus")."</th>"; 223 $alertMessage .= " <th nowrap='nowrap'>".__("Old Filesize", "wordpress-file-monitor-plus")."</th>"; 224 } 225 if(1 == $options['file_check_method']['modified']) { 226 $alertMessage .= " <th nowrap='nowrap'>".__("New Modified", "wordpress-file-monitor-plus")."</th>"; 227 $alertMessage .= " <th nowrap='nowrap'>".__("Old Modified", "wordpress-file-monitor-plus")."</th>"; 228 } 229 if(1 == $options['file_check_method']['md5']) { 230 $alertMessage .= " <th nowrap='nowrap'>".__("New Hash", "wordpress-file-monitor-plus")."</th>"; 231 $alertMessage .= " <th nowrap='nowrap'>".__("Old Hash", "wordpress-file-monitor-plus")."</th>"; 232 } 233 $alertMessage .= " </tr>"; 234 $alertMessage .= " </thead>"; 235 $alertMessage .= " <tbody>"; 236 foreach($changed_files[0] as $key => $data) { 237 $alertMessage .= " <tr>"; 238 $alertMessage .= " <td>".$key."</td>"; 239 if(1 == $options['file_check_method']['size']) { 240 $alertMessage .= " <td nowrap='nowrap'>".size_format($newScanData[$key]["size"])."</td>"; 241 $alertMessage .= " <td nowrap='nowrap'>".size_format($oldScanData[$key]["size"])."</td>"; 242 } 243 if(1 == $options['file_check_method']['modified']) { 244 $alertMessage .= " <td nowrap='nowrap'>".apply_filters("sc_wpfmp_format_file_modified_time", NULL, $newScanData[$key]["modified"])."</td>"; 245 $alertMessage .= " <td nowrap='nowrap'>".apply_filters("sc_wpfmp_format_file_modified_time", NULL, $oldScanData[$key]["modified"])."</td>"; 246 } 247 if(1 == $options['file_check_method']['md5']) { 248 $alertMessage .= " <td nowrap='nowrap'>".$newScanData[$key]["md5"]."</td>"; 249 $alertMessage .= " <td nowrap='nowrap'>".$oldScanData[$key]["md5"]."</td>"; 250 } 251 $alertMessage .= " </tr>"; 252 } 253 $alertMessage .= " </tbody>"; 254 $alertMessage .= "</table>"; 255 $alertMessage .= "<br /><br />"; 256 } 257 if(count($files_added) >= 1) {// Only do this if added files 258 $alertMessage .= "<strong>".__("Files Added:", "wordpress-file-monitor-plus")."</strong>"; 259 $alertMessage .= "<table class='widefat' width='100%' border='1' cellspacing='0' cellpadding='2'>"; 260 $alertMessage .= " <thead>"; 261 $alertMessage .= " <tr>"; 262 $alertMessage .= " <th width='100%'>".__("File", "wordpress-file-monitor-plus")."</th>"; 263 if(1 == $options['file_check_method']['size']) { 264 $alertMessage .= " <th nowrap='nowrap'>".__("New Filesize", "wordpress-file-monitor-plus")."</th>"; 265 } 266 if(1 == $options['file_check_method']['modified']) { 267 $alertMessage .= " <th nowrap='nowrap'>".__("New Modified", "wordpress-file-monitor-plus")."</th>"; 268 } 269 if(1 == $options['file_check_method']['md5']) { 270 $alertMessage .= " <th nowrap='nowrap'>".__("New Hash", "wordpress-file-monitor-plus")."</th>"; 271 } 272 $alertMessage .= " </tr>"; 273 $alertMessage .= " </thead>"; 274 $alertMessage .= " <tbody>"; 275 foreach($files_added as $key => $data) { 276 $alertMessage .= " <tr>"; 277 $alertMessage .= " <td>".$key."</td>"; 278 if(1 == $options['file_check_method']['size']) { 279 $alertMessage .= " <td nowrap='nowrap'>".size_format($newScanData[$key]["size"])."</td>"; 280 } 281 if(1 == $options['file_check_method']['modified']) { 282 $alertMessage .= " <td nowrap='nowrap'>".apply_filters("sc_wpfmp_format_file_modified_time", NULL, $newScanData[$key]["modified"])."</td>"; 283 } 284 if(1 == $options['file_check_method']['md5']) { 285 $alertMessage .= " <td nowrap='nowrap'>".$newScanData[$key]["md5"]."</td>"; 286 } 287 $alertMessage .= " </tr>"; 288 } 289 $alertMessage .= " </tbody>"; 290 $alertMessage .= "</table>"; 291 $alertMessage .= "<br /><br />"; 292 } 293 if(count($files_removed) >= 1) {// Only do this if removed files 294 $alertMessage .= "<strong>".__("Files Removed:", "wordpress-file-monitor-plus")."</strong>"; 295 $alertMessage .= "<table class='widefat' width='100%' border='1' cellspacing='0' cellpadding='2'>"; 296 $alertMessage .= " <thead>"; 297 $alertMessage .= " <tr>"; 298 $alertMessage .= " <th width='100%'>".__("File", "wordpress-file-monitor-plus")."</th>"; 299 if(1 == $options['file_check_method']['size']) { 300 $alertMessage .= " <th nowrap='nowrap'>".__("Old Filesize", "wordpress-file-monitor-plus")."</th>"; 301 } 302 if(1 == $options['file_check_method']['modified']) { 303 $alertMessage .= " <th nowrap='nowrap'>".__("Old Modified", "wordpress-file-monitor-plus")."</th>"; 304 } 305 if(1 == $options['file_check_method']['md5']) { 306 $alertMessage .= " <th nowrap='nowrap'>".__("Old Hash", "wordpress-file-monitor-plus")."</th>"; 307 } 308 $alertMessage .= " </tr>"; 309 $alertMessage .= " </thead>"; 310 $alertMessage .= " <tbody>"; 311 foreach($files_removed as $key => $data) { 312 $alertMessage .= " <tr>"; 313 $alertMessage .= " <td>".$key."</td>"; 314 if(1 == $options['file_check_method']['size']) { 315 $alertMessage .= " <td nowrap='nowrap'>".size_format($oldScanData[$key]["size"])."</td>"; 316 } 317 if(1 == $options['file_check_method']['modified']) { 318 $alertMessage .= " <td nowrap='nowrap'>".apply_filters("sc_wpfmp_format_file_modified_time", NULL, $oldScanData[$key]["modified"])."</td>"; 319 } 320 if(1 == $options['file_check_method']['md5']) { 321 $alertMessage .= " <td nowrap='nowrap'>".$oldScanData[$key]["md5"]."</td>"; 322 } 323 $alertMessage .= " </tr>"; 324 } 325 $alertMessage .= " </tbody>"; 326 $alertMessage .= "</table>"; 327 $alertMessage .= "<br /><br />"; 328 } 329 if(1 == $options['display_admin_alert']) { 330 $alertMessage .= "<a class='button-secondary' href='".admin_url("options-general.php?page=wordpress-file-monitor-plus&sc_wpfmp_action=sc_wpfmp_clear_admin_alert")."'>".__("Clear admin alert", "wordpress-file-monitor-plus")."</a><br /><br />"; 331 } 332 return $alertMessage; 333 } 334 335 336 /** 337 * Sends admin alert email 338 * 339 * @param $alertMessage string 340 * @return void 341 */ 342 public function send_notify_email($alertMessage) { 343 $options = get_option(self::$settings_option_field); // Get settings 344 $subject = sprintf(__("WordPress File Monitor Plus: Alert (%s)", "wordpress-file-monitor-plus"), site_url()); // build subject 345 $subject = apply_filters("sc_wpfmp_format_email_subject", $subject); // allow filter to alter subject 346 add_filter('wp_mail_from', array(__CLASS__, 'sc_wpfmp_wp_mail_from')); // add filter to modify the mail from 347 add_filter('wp_mail_from_name', array(__CLASS__, 'sc_wpfmp_wp_mail_from_name')); // add filter to modify the mail from name 348 add_filter('wp_mail_content_type', array(__CLASS__, 'sc_wpfmp_wp_mail_content_type')); // add filter to modify the mail content type 349 wp_mail($options['notify_address'], $subject, $alertMessage); // send mail 350 remove_filter('wp_mail_from', array(__CLASS__, 'sc_wpfmp_wp_mail_from')); // remove applied filter 351 remove_filter('wp_mail_from_name', array(__CLASS__, 'sc_wpfmp_wp_mail_from_name')); // remove applied filter 352 remove_filter('wp_mail_content_type', array(__CLASS__, 'sc_wpfmp_wp_mail_content_type')); // remove applied filter 353 } 354 355 356 /** 357 * Set from address for email notification 358 * 359 * @return void 360 */ 361 public function sc_wpfmp_wp_mail_from() { 362 $options = get_option(self::$settings_option_field); // Get settings 363 return $options['from_address']; // Return the from address 364 } 365 366 367 /** 368 * Set from name for email notification 369 * 370 * @return string $from_name 371 */ 372 public function sc_wpfmp_wp_mail_from_name() { 373 $from_name = __("WordPress File Monitor Plus", "wordpress-file-monitor-plus"); 374 $from_name = apply_filters("sc_wpfmp_format_email_from_name", $from_name); // allow filter to alter the from name 375 return $from_name; // return from name 376 } 377 378 379 /** 380 * Set content type for email notification 381 * 382 * @return string 383 */ 384 public function sc_wpfmp_wp_mail_content_type() { return "text/html"; } 385 386 387 /** 388 * Function deals with getting and putting scan data to and from DB or FILE 389 * 390 * @param string $getorput "get" to get data "put" to put data 391 * @param array $data if putting data this should contain array of new scan data 392 * @return array $data if getting data this should contain array of old scan data 393 */ 394 protected function getPutScanData($getorput, $data = NULL) { 395 $options = get_option(self::$settings_option_field); // Get settings 396 if("file" == $options['data_save']) { // Check how data is to be saved 397 $scandatafile = dirname(__FILE__)."/data/.sc_wpfmp_scan_data"; 398 if("get" == $getorput) { // Are we getting or putting data 399 if(file_exists($scandatafile)) { // Check if file exists. No point reading from file if it doesnt exist yet 400 $data = maybe_unserialize(file_get_contents($scandatafile)); 401 return $data; 402 } else { 403 return NULL; 404 } 405 } else { 406 file_put_contents($scandatafile, maybe_serialize($data)); // Save contents to file 407 } 408 } else { 409 if("get" == $getorput) { // Are we getting or putting data 410 $data = maybe_unserialize(get_option('sc_wpfmp_scan_data')); 411 return $data; 412 } else { 413 update_option('sc_wpfmp_scan_data', maybe_serialize($data)); 414 } 415 } 416 } 417 418 419 /** 420 * Function deals with getting and putting Admin Alert Content to and from DB or FILE 421 * 422 * @param string $getorput "get" to get data "put" to put data 423 * @param string $data if putting data this should contain alert data 424 * @return string $data if getting data this should contain alert data 425 */ 426 protected function getPutAlertContent($getorput, $data = NULL) { 427 $options = get_option(self::$settings_option_field); // Get settings 428 if("file" == $options['data_save']) { // Check how data is to be saved 429 $scandatafile = dirname(__FILE__)."/data/.sc_wpfmp_admin_alert_content"; 430 if("get" == $getorput) {// Are we getting or putting data 431 if(file_exists($scandatafile)) { // Check if file exists. No point reading from file if it doesnt exist yet 432 $data = file_get_contents($scandatafile); 433 return $data; 434 } else { 435 return NULL; 436 } 437 } else { 438 file_put_contents($scandatafile, $data); // Save contents to file 439 } 440 } else { 441 if("get" == $getorput) { // Are we getting or putting data 442 $data = get_option('sc_wpfmp_admin_alert_content'); 443 return $data; 444 } else { 445 update_option('sc_wpfmp_admin_alert_content', $data); 446 } 447 } 448 } 449 450 451 /** 452 * Admin notice 453 * 454 * @return void 455 */ 456 public function admin_alert() { 457 $options = get_option(self::$settings_option_field); // Get settings 458 if (1 == $options['is_admin_alert'] && 1 == $options['display_admin_alert'] && current_user_can(SC_WPFMP_ADMIN_ALERT_PERMISSION)) : ?> 459 <div class="error"> 460 <p> 461 <?php _e("<strong>Warning!</strong> WordPress File Monitor Plus has detected a change in the files on your site.", "wordpress-file-monitor-plus"); ?> 462 <br/><br/> 463 <a class="button-secondary thickbox" href="<?php echo admin_url("options-general.php?page=wordpress-file-monitor-plus&sc_wpfmp_action=sc_wpfmp_view_alert"); ?>" title="<?php _e("View file changes and clear this alert", "wordpress-file-monitor-plus"); ?>"><?php _e("View file changes and clear this alert", "wordpress-file-monitor-plus"); ?></a> 464 </p> 465 </div> 466 <?php endif; 467 } 468 469 470 /** 471 * Sets up cron schedule in WP if needed. 472 * 473 * @param bool|string $manual_interval 474 * @return void 475 */ 476 public function enable_cron($manual_interval = false) { 477 $options = get_option(self::$settings_option_field); // Get settings 478 $currentSchedule = wp_get_schedule(self::$cron_name); // find if a schedule already exists 479 if(!empty($manual_interval)) {$options['file_check_interval'] = $manual_interval;} // if a manual cron interval is set, use this 480 if("manual" == $options['file_check_interval']) { 481 do_action("sc_wpfmp_disable_wp_cron"); // Make sure no cron is setup as we are manual 482 } else { 483 if($currentSchedule != $options['file_check_interval']) { // check if the current schedule matches the one set in settings 484 if(in_array($options['file_check_interval'], self::$frequency_intervals)) { // check the cron setting is valid 485 do_action("sc_wpfmp_disable_wp_cron"); // remove any crons for this plugin first so we don't end up with multiple crons doing the same thing. 486 wp_schedule_event(time(), $options['file_check_interval'], self::$cron_name); // schedule cron for this plugin. 487 } 488 } 489 } 490 } 491 492 493 /** 494 * Remove any WordPress cron our plugin may have created 495 * 496 * @return void 497 */ 498 public function disable_cron() { 499 wp_clear_scheduled_hook(self::$cron_name); 500 } 501 502 503 /** 504 * Compares two arrays and returns the difference 505 * 506 * This is a function I picked up from PHP.net some time ago 507 * and can no longer find the author so unable to give credit. 508 * 509 * @param array $array1 510 * @param array $array2 511 * @return array $diff 512 */ 513 public function array_compare($array1, $array2) { 514 $diff = false; 515 foreach ($array1 as $key => $value) { 516 if (!array_key_exists($key,$array2)) { 517 $diff[0][$key] = $value; 518 } elseif (is_array($value)) { 519 if (!is_array($array2[$key])) { 520 $diff[0][$key] = $value; 521 $diff[1][$key] = $array2[$key]; 522 } else { 523 $new = self::array_compare($value, $array2[$key]); 524 if ($new !== false) { 525 if (isset($new[0])) { 526 $diff[0][$key] = $new[0]; 527 } 528 if (isset($new[1])) { 529 $diff[1][$key] = $new[1]; 530 } 531 } 532 } 533 } elseif ($array2[$key] !== $value) { 534 $diff[0][$key] = $value; 535 $diff[1][$key] = $array2[$key]; 536 } 537 } 538 foreach ($array2 as $key => $value) { 539 if (!array_key_exists($key,$array1)) { 540 $diff[1][$key] = $value; 541 } 542 } 543 return $diff; 544 } 545 546 547 /** 548 * Filter for formatting the file modified time 549 * 550 * @param string $formatted 551 * @param int $timestamp unix timestamp 552 * @return string 553 */ 554 public function format_file_modified_time($formatted = NULL, $timestamp) { 555 $date_format = get_option( 'date_format' ); // Get wordpress date format 556 $time_format = get_option( 'time_format' ); // Get wordpress time format 557 $gmt_offset = get_option( 'gmt_offset' ); // Get wordpress gmt offset 558 $formatted = gmdate($date_format." @ ".$time_format, ($timestamp + ($gmt_offset * 3600))); 559 return $formatted; 560 } 561 562 } 563 564 } 565 566 // Include Compatability Functions 567 require_once("functions/compatability.php"); 568 // Include Settings Class 569 require_once("classes/wpfmp.settings.class.php"); 570 571 572 // Create instance of plugin classes 573 $sc_wpfmp = new sc_WordPressFileMonitorPlus(); 574 $sc_wpfmp_settings = new sc_WordPressFileMonitorPlusSettings(); 49 575 ?>
Note: See TracChangeset
for help on using the changeset viewer.