WP Security Audit Log - Version 0.4

Version Description

  • New WordPress Security Alerts for Custom Post Types

    • Alert 2029: New post with custom post type created and saved as draft
    • Alert 2030: Post with custom post type is publishes
    • Alert 2031: A published post with custom post type is modified
    • Alert 2032: A draft post with custom post type is modified
    • Alert 2033: A post with custom post type was permanently deleted
    • Alert 2034: A post with custom post type was moved to trash
    • Alert 2035: A post with custom post type was restored from trash
    • Alert 2036: The category of a post with custom post type was changed
    • Alert 2037: The URL of a post with custom post type was changed
    • Alert 2038: The author of a post with custom post type was changed
    • Alert 2039: The status of a post with custom post type was changed
    • Alert 2040: The visibility of a post with custom post type was changed
    • Alert 2041: The date of a post with custom post type was changed
  • New Plugin Features

    • Enable/Disable Alerts node that allows WordPress administrators to switch on or off specific WordPress security alerts
    • Dashboard widget that shows the latest 5 WordPress security alerts (widget can be switched on or off from the plugin settings)
    • Plugin is now language aware and we can accept translations
  • Plugin Improvements

    • Updated settings page to have the same look and feel of WordPress
    • Improved the upgrade procedure of the plugin
    • Updated the Audit Log Viewer display to support more resultions such as those of tables and smartphones
Download this release

Release Info

Developer WPWhiteSecurity
Plugin Icon 128x128 WP Security Audit Log
Version 0.4
Comparing to
See all releases

Code changes from version 0.3 to 0.4

inc/WPPH.php CHANGED
@@ -41,26 +41,36 @@ class WPPH
41
 
42
  add_menu_page('WP Security Audit Log', 'WP Security Audit Log', $reqCap, $baseMenuSlug, 'WPPH::pageMain', WPPH_PLUGIN_URL.'res/img/logo-main-menu.png');
43
  add_submenu_page($baseMenuSlug, 'Audit Log Viewer', 'Audit Log Viewer', $reqCap, $baseMenuSlug, 'WPPH::pageMain');
44
- add_submenu_page($baseMenuSlug, 'Settings', __('Settings'), $reqCap, $baseMenuSlug.'settings', 'WPPH::pageSettings');
45
- add_submenu_page($baseMenuSlug, 'About', __('About'), $reqCap, $baseMenuSlug.'about', 'WPPH::pageAbout');
46
- add_submenu_page($baseMenuSlug, 'Support', __('Support'), $reqCap, $baseMenuSlug.'support', 'WPPH::pageSupport');
 
47
  }
48
  }
49
 
50
  public static function pageMain() { include(WPPH_PLUGIN_DIR.'pages/dashboard.php'); }
51
  public static function pageSettings() { include(WPPH_PLUGIN_DIR.'pages/settings.php'); }
 
 
 
 
 
 
52
  public static function pageAbout() { include(WPPH_PLUGIN_DIR.'pages/about.php'); }
53
  public static function pageSupport() { include(WPPH_PLUGIN_DIR.'pages/support.php'); }
54
 
55
  public static function createPluginDefaultSettings()
56
  {
 
57
  $settings = new stdClass();
58
  $settings->daysToKeep = 0;
59
- $settings->eventsToKeep = 10000;
60
  $settings->showEventsViewList = 50; // how many items to show in the event viewer by default
61
  $settings->lastCleanup = time();
62
  $settings->cleanupRan = 0;
63
- add_option(WPPH_PLUGIN_SETTING_NAME, $settings);
 
 
64
  wpphLog('Settings added.');
65
  }
66
  public static function getPluginSettings()
@@ -105,88 +115,109 @@ class WPPH
105
  wpphLog('Settings saved.', $settings);
106
  }
107
 
108
- public static function optionExists($optionName) { return (false === get_option($optionName, false) ? false : true); }
109
-
110
  public static function onPluginActivate()
111
  {
112
- wpphLog(__FUNCTION__.'() triggered. Checking if the plugin needs to be updated.');
113
 
114
- $optErrorData = array();
115
  $canContinue = true;
116
 
117
  // Check: MySQL, PHP - without these there's not much left for this plugin to do
118
  if(! self::checkMySQL()){
119
- $optErrorData = self::__addError($optErrorData, 'e400');
120
- update_option(WPPH_PLUGIN_ERROR_OPTION_NAME, $optErrorData);
121
  $canContinue = false;
122
  }
123
  if(! self::checkPHP()){
124
- $optErrorData = self::__addError($optErrorData, 'e300');
125
- update_option(WPPH_PLUGIN_ERROR_OPTION_NAME, $optErrorData);
126
  $canContinue = false;
127
  }
128
  // no need for further checks, the plugin cannot run on this server...
129
  if(! $canContinue){
130
- $optErrorData = self::__addError($optErrorData, 'e500');
131
- update_option(WPPH_PLUGIN_ERROR_OPTION_NAME, $optErrorData);
132
  $GLOBALS['WPPH_CAN_RUN'] = false;
 
133
  return false;
134
  }
135
 
136
- $triggerInstall = false;
 
 
 
 
 
 
 
137
 
138
- // check to see whether or not an upgrade is necessary
139
- $v = get_option(WPPH_PLUGIN_VERSION_OPTION_NAME,false);
140
- if($v != false)
 
 
 
 
 
 
 
 
141
  {
142
- $v = (float)$v;
143
- $cv = (float)WPPH_PLUGIN_VERSION;
144
- //#! no need for upgrade
145
- if($v == $cv){
146
- delete_option(WPPH_PLUGIN_ERROR_OPTION_NAME);
147
- update_option(WPPH_PLUGIN_VERSION_OPTION_NAME, WPPH_PLUGIN_VERSION);
148
- WPPHEvent::hookWatchPluginActivity(); //#! log self installation
149
  return true;
150
  }
151
- }
152
- else { $triggerInstall = true; }
153
-
154
- // check to see whether or not the tables exist - if true, it means the installed version is 0.1
155
- // and we need to clear the tables before upgrading them
156
- if(WPPHDatabase::tablesExist()){
157
- $triggerInstall = false;
158
- if(!empty($v) && version_compare($v, '0.2', '<')){
159
- wpphLog('Version 0.1 detected. Cleaning out the tables.');
160
- if(! WPPHDatabase::v2Cleanup()){
161
- $optErrorData = self::__addError($optErrorData, 'e600');
162
- update_option(WPPH_PLUGIN_ERROR_OPTION_NAME, $optErrorData);
163
- return false;
164
- }
165
  }
166
- }
167
 
168
- //#! run the upgrade / update
169
- if(($result = self::wpphDoUpdate()) != true){
170
- $optErrorData = self::__addError($optErrorData, 'e'.$result);
171
  }
172
-
173
- if(empty($optErrorData)){
174
- delete_option(WPPH_PLUGIN_ERROR_OPTION_NAME);
175
- update_option(WPPH_PLUGIN_VERSION_OPTION_NAME, WPPH_PLUGIN_VERSION);
176
-
177
- if($triggerInstall){
178
- define('WPPH_PLUGIN_INSTALLED_OK',true);
179
- $current_user = wp_get_current_user();
180
- WPPHEvent::_addLogEvent(5000,$current_user->ID, WPPHUtil::getIP(), array(WPPH_PLUGIN_NAME));
181
- wpphLog('Plugin installed.', array('plugin'=>WPPH_PLUGIN_NAME));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  }
183
-
184
- WPPHEvent::hookWatchPluginActivity(); //#! log self installation
185
- return true;
186
  }
187
-
188
- update_option(WPPH_PLUGIN_ERROR_OPTION_NAME, $optErrorData);
189
- $GLOBALS['WPPH_CAN_RUN'] = false;
190
  return false;
191
  }
192
 
@@ -196,17 +227,40 @@ class WPPH
196
  public static function onPluginDeactivate()
197
  {
198
  wp_clear_scheduled_hook(WPPH_PLUGIN_DEL_EVENTS_CRON_TASK_NAME);
199
- if(self::optionExists(WPPH_PLUGIN_ERROR_OPTION_NAME)){ delete_option(WPPH_PLUGIN_ERROR_OPTION_NAME); }
200
- if(self::optionExists(WPPH_PLUGIN_SETTING_NAME)){ delete_option(WPPH_PLUGIN_SETTING_NAME); }
201
  wpphLog('__FUNCTION__.() triggered.');
202
  }
203
 
204
-
205
- public static function __addError(array $errorData, $errorCode, $arg=''){
206
- $errorData["$errorCode"] = base64_encode($arg);
207
- return $errorData;
 
 
 
 
208
  }
209
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  /**
211
  * @internal
212
  * @static
@@ -226,19 +280,7 @@ class WPPH
226
  return false;
227
  }
228
 
229
- public static function isInstalled() { return self::optionExists(WPPH_PLUGIN_DB_UPDATED); }
230
-
231
- public static function getPluginErrors() { return get_option(WPPH_PLUGIN_ERROR_OPTION_NAME,null); }
232
-
233
- public static function wpphDoUpdate()
234
- {
235
- wpphLog(__FUNCTION__.'() triggered. Running the update.');
236
- if(($result = WPPHDatabase::handleTables()) !== true)
237
- {
238
- return $result;
239
- }
240
- return true;
241
- }
242
 
243
  public static function checkMySQL(){
244
  global $wpdb;
41
 
42
  add_menu_page('WP Security Audit Log', 'WP Security Audit Log', $reqCap, $baseMenuSlug, 'WPPH::pageMain', WPPH_PLUGIN_URL.'res/img/logo-main-menu.png');
43
  add_submenu_page($baseMenuSlug, 'Audit Log Viewer', 'Audit Log Viewer', $reqCap, $baseMenuSlug, 'WPPH::pageMain');
44
+ add_submenu_page($baseMenuSlug, __('Settings',WPPH_PLUGIN_TEXT_DOMAIN), __('Settings',WPPH_PLUGIN_TEXT_DOMAIN), $reqCap, $baseMenuSlug.'settings', 'WPPH::pageSettings');
45
+ add_submenu_page($baseMenuSlug, __('Enable/Disable Alerts',WPPH_PLUGIN_TEXT_DOMAIN), __('Enable/Disable Alerts',WPPH_PLUGIN_TEXT_DOMAIN), $reqCap, $baseMenuSlug.'alerts', 'WPPH::pageAlerts');
46
+ add_submenu_page($baseMenuSlug, __('About',WPPH_PLUGIN_TEXT_DOMAIN), __('About',WPPH_PLUGIN_TEXT_DOMAIN), $reqCap, $baseMenuSlug.'about', 'WPPH::pageAbout');
47
+ add_submenu_page($baseMenuSlug, __('Support',WPPH_PLUGIN_TEXT_DOMAIN), __('Support',WPPH_PLUGIN_TEXT_DOMAIN), $reqCap, $baseMenuSlug.'support', 'WPPH::pageSupport');
48
  }
49
  }
50
 
51
  public static function pageMain() { include(WPPH_PLUGIN_DIR.'pages/dashboard.php'); }
52
  public static function pageSettings() { include(WPPH_PLUGIN_DIR.'pages/settings.php'); }
53
+ public static function pageAlerts() {
54
+ wp_enqueue_style('jquery-smoothness-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/themes/smoothness/jquery-ui.css');
55
+ wp_enqueue_script('jquery-ui-core');
56
+ wp_enqueue_script('jquery-ui-tabs');
57
+ include(WPPH_PLUGIN_DIR.'pages/alerts.php');
58
+ }
59
  public static function pageAbout() { include(WPPH_PLUGIN_DIR.'pages/about.php'); }
60
  public static function pageSupport() { include(WPPH_PLUGIN_DIR.'pages/support.php'); }
61
 
62
  public static function createPluginDefaultSettings()
63
  {
64
+ global $wpphEvents;
65
  $settings = new stdClass();
66
  $settings->daysToKeep = 0;
67
+ $settings->eventsToKeep = WPPH_KEEP_MAX_EVENTS; // default delete option
68
  $settings->showEventsViewList = 50; // how many items to show in the event viewer by default
69
  $settings->lastCleanup = time();
70
  $settings->cleanupRan = 0;
71
+ $settings->logEvents = $wpphEvents; // holds the list of events that will be triggered
72
+ $settings->showDW = 1; // whether or not to show the dashboard widget. @since v0.4
73
+ update_option(WPPH_PLUGIN_SETTING_NAME, $settings);
74
  wpphLog('Settings added.');
75
  }
76
  public static function getPluginSettings()
115
  wpphLog('Settings saved.', $settings);
116
  }
117
 
 
 
118
  public static function onPluginActivate()
119
  {
120
+ wpphLog(__METHOD__.'() triggered.');
121
 
 
122
  $canContinue = true;
123
 
124
  // Check: MySQL, PHP - without these there's not much left for this plugin to do
125
  if(! self::checkMySQL()){
126
+ self::__addPluginError(__("Plugin could not be properly installed. The MySQL version installed on this server is less than 5.",WPPH_PLUGIN_TEXT_DOMAIN));
 
127
  $canContinue = false;
128
  }
129
  if(! self::checkPHP()){
130
+ self::__addPluginError(__("Plugin could not be properly installed. The PHP version installed on this server is less than 5.",WPPH_PLUGIN_TEXT_DOMAIN));
 
131
  $canContinue = false;
132
  }
133
  // no need for further checks, the plugin cannot run on this server...
134
  if(! $canContinue){
 
 
135
  $GLOBALS['WPPH_CAN_RUN'] = false;
136
+ self::__addPluginError(__("Plugin could not be properly installed because the server does not meet our requirements: MySQL and PHP version >= 5.",WPPH_PLUGIN_TEXT_DOMAIN));
137
  return false;
138
  }
139
 
140
+ // check to see whether or not an upgrade is necessary
141
+ global $wpdb;
142
+ $dbUpdated = get_option(WPPH_PLUGIN_DB_UPDATED);
143
+ $tablesExist = false;
144
+ $triggerInstallEvent = false; // whether or not the plugin is installed
145
+ $pluginDbVersion = get_option(WPPH_PLUGIN_VERSION_OPTION_NAME);
146
+
147
+ delete_option(WPPH_PLUGIN_ERROR_OPTION_NAME);
148
 
149
+ // first install?
150
+ if($pluginDbVersion === false){
151
+ // Check tables
152
+ if(WPPHDatabase::tableExists($wpdb, WPPHDatabase::getFullTableName('MAIN')) || WPPHDatabase::tableExists($wpdb, WPPHDatabase::getFullTableName('EVENTS'))){
153
+ $tablesExist = true;
154
+ }
155
+ else { $triggerInstallEvent = true; }
156
+ }
157
+
158
+ // if we need to install
159
+ if($triggerInstallEvent)
160
  {
161
+ if($dbUpdated){ delete_option(WPPH_PLUGIN_DB_UPDATED); }
162
+ if(WPPHDatabase::handleDatabase()){
163
+ self::__handlePluginActivation(true);
 
 
 
 
164
  return true;
165
  }
166
+ else {
167
+ self::__addPluginError(__("Plugin could not be properly installed because we have encountered errors during the database update.",WPPH_PLUGIN_TEXT_DOMAIN));
168
+ return false;
 
 
 
 
 
 
 
 
 
 
 
169
  }
 
170
 
 
 
 
171
  }
172
+ // plugin already installed
173
+ else
174
+ {
175
+ // if tables exist - do update database
176
+ if($tablesExist)
177
+ {
178
+ // check plugin version
179
+ if(empty($pluginDbVersion))
180
+ {
181
+ if($dbUpdated){ delete_option(WPPH_PLUGIN_DB_UPDATED); }
182
+ // maybe version 0.1 ? empty tables
183
+ if(! WPPHDatabase::v2Cleanup()){
184
+ self::__addPluginError(__("Plugin could not be properly installed because we have encountered errors during the database update.",WPPH_PLUGIN_TEXT_DOMAIN));
185
+ return false;
186
+ }
187
+ // update database
188
+ if(WPPHDatabase::handleDatabase()){
189
+ self::__handlePluginActivation();
190
+ return true;
191
+ }
192
+ else {
193
+ self::__addPluginError(__("Plugin could not be properly installed because we have encountered errors during the database update.",WPPH_PLUGIN_TEXT_DOMAIN));
194
+ return false;
195
+ }
196
+ }
197
+ else {
198
+ $pluginDbVersion = (float)$pluginDbVersion;
199
+ $currentVersion = (float)WPPH_PLUGIN_VERSION;
200
+ // no need for upgrade
201
+ if(version_compare($pluginDbVersion, $currentVersion, '==')){
202
+ self::__handlePluginActivation();
203
+ return true;
204
+ }
205
+ }
206
+ }
207
+ // tables not found
208
+ else {
209
+ if($dbUpdated){ delete_option(WPPH_PLUGIN_DB_UPDATED); }
210
+ // create them
211
+ if(WPPHDatabase::handleDatabase()){
212
+ self::__handlePluginActivation();
213
+ return true;
214
+ }
215
+ else {
216
+ self::__addPluginError(__("Plugin could not be properly installed because we have encountered errors during the database update.",WPPH_PLUGIN_TEXT_DOMAIN));
217
+ return false;
218
+ }
219
  }
 
 
 
220
  }
 
 
 
221
  return false;
222
  }
223
 
227
  public static function onPluginDeactivate()
228
  {
229
  wp_clear_scheduled_hook(WPPH_PLUGIN_DEL_EVENTS_CRON_TASK_NAME);
230
+ delete_option(WPPH_PLUGIN_ERROR_OPTION_NAME);
231
+ delete_option(WPPH_PLUGIN_SETTING_NAME);
232
  wpphLog('__FUNCTION__.() triggered.');
233
  }
234
 
235
+ public static function __addPluginError($error){
236
+ $data = get_option(WPPH_PLUGIN_ERROR_OPTION_NAME);
237
+ if(empty($data)){
238
+ $data = array();
239
+ }
240
+ $data[] = base64_encode($error);
241
+ update_option(WPPH_PLUGIN_ERROR_OPTION_NAME, $data);
242
+ return true;
243
  }
244
 
245
+ private static function __handlePluginActivation($triggerInstallEvent = false)
246
+ {
247
+ self::getPluginSettings();
248
+
249
+ $GLOBALS['WPPH_CAN_RUN'] = true;
250
+ update_option(WPPH_PLUGIN_DB_UPDATED,1);
251
+ delete_option(WPPH_PLUGIN_ERROR_OPTION_NAME);
252
+ update_option(WPPH_PLUGIN_VERSION_OPTION_NAME, WPPH_PLUGIN_VERSION);
253
+ if($triggerInstallEvent)
254
+ {
255
+ define('WPPH_PLUGIN_INSTALLED_OK',true);
256
+ $current_user = wp_get_current_user();
257
+ // log plugin installation
258
+ WPPHEvent::_addLogEvent(5000,$current_user->ID, WPPHUtil::getIP(), array(WPPH_PLUGIN_NAME));
259
+ wpphLog('Plugin installed.', array('plugin'=>WPPH_PLUGIN_NAME));
260
+ }
261
+ // log plugin activation
262
+ WPPHEvent::hookWatchPluginActivity();
263
+ }
264
  /**
265
  * @internal
266
  * @static
280
  return false;
281
  }
282
 
283
+ public static function getPluginErrors() { return get_option(WPPH_PLUGIN_ERROR_OPTION_NAME); }
 
 
 
 
 
 
 
 
 
 
 
 
284
 
285
  public static function checkMySQL(){
286
  global $wpdb;
inc/WPPHAdminNotices.php DELETED
@@ -1,127 +0,0 @@
1
- <?php
2
- /**
3
- * Class WPPHAdminNotices
4
- */
5
- class WPPHAdminNotices
6
- {
7
- public static function show($errorCode)
8
- {
9
- $f = "e".$errorCode;
10
- if(is_callable(array(__CLASS__,$f))){ add_action('admin_notices',array(__CLASS__,$f)); }
11
- }
12
-
13
- public static function e0()
14
- {
15
- $tableName = WPPHDatabase::getFullTableName('events');
16
- $query = '<pre><code>'.WPPHDatabase::getCreateQueryEventsDetailsTable().'</code></pre>';
17
- $m = sprintf(
18
- __('The table <strong>%s</strong> was not found nor it could be created.<br/>Please run this query manually and reactivate the plugin: %s')
19
- , $tableName, $query);
20
- echo '<div class="error"><p><strong>'.WPPH_PLUGIN_NAME.' '.__('Error').':</strong> '.$m.'</p></div>';
21
- }
22
-
23
- public static function e1()
24
- {
25
- $tableName = WPPHDatabase::getFullTableName('events');
26
- $queryUpdate = '<pre><code>';
27
- foreach(WPPHDatabase::getUpdateQueryEventsDetailsTable() as $query){
28
- $queryUpdate .= $query.'<br/>';
29
- }
30
- $queryUpdate .= '</code></pre>';
31
- $m = sprintf(__('We have encountered an error while trying to update the table: <strong>%s</strong>
32
- <br/>Please run the following queries manually then reload this page: %s')
33
- ,$tableName, $queryUpdate);
34
- echo '<div class="error"><p><strong>'.WPPH_PLUGIN_NAME.' '.__('Error').':</strong> '.$m.'</p></div>';
35
- }
36
-
37
- public static function e2()
38
- {
39
- $tableName = WPPHDatabase::getFullTableName('events');
40
- $queries = WPPHDatabase::getUpgradeQueryEventsDetailsTable();
41
- $out = '<pre>';
42
- foreach($queries as $query){
43
- $out .= "<code>{$query}</code><br/>";
44
- }
45
- $out .= '</pre>';
46
- $m = sprintf(
47
- __('The table <strong>%s</strong> could not be updated.<br/>Please run the following queries manually and reactivate the plugin: %s')
48
- , $tableName, $out);
49
- echo '<div class="error"><p><strong>'.WPPH_PLUGIN_NAME.' '.__('Error').':</strong> '.$m.'</p></div>';
50
- }
51
-
52
- public static function e3()
53
- {
54
- $tableName = WPPHDatabase::getFullTableName('main');
55
- $query = '<pre><code>'.WPPHDatabase::getCreateQueryLogsTable().'</code></pre>';
56
- $m = sprintf(
57
- __('The table <strong>%s</strong> was not found nor it could be created.<br/>Please run this query manually and reactivate the plugin: %s')
58
- , $tableName, $query);
59
- echo '<div class="error"><p><strong>'.WPPH_PLUGIN_NAME.' '.__('Error').':</strong> '.$m.'</p></div>';
60
- }
61
-
62
- public static function e4()
63
- {
64
- $tableName = WPPHDatabase::getFullTableName('main');
65
- $query = '<pre><code>'.WPPHDatabase::getUpdateQueryLogsTable().'</code></pre>';
66
- $m = sprintf(
67
- __('The table <strong>%s</strong> could not be updated.<br/>Please run this query manually and reactivate the plugin: %s')
68
- , $tableName, $query);
69
- echo '<div class="error"><p><strong>'.WPPH_PLUGIN_NAME.' '.__('Error').':</strong> '.$m.'</p></div>';
70
- }
71
-
72
- public static function e5()
73
- {
74
- $tableName = WPPHDatabase::getFullTableName('main');
75
- $queries = WPPHDatabase::getUpgradeQueryLogsTable();
76
- $out = '<pre>';
77
- foreach($queries as $query){
78
- $out .= "<code>{$query}</code><br/>";
79
- }
80
- $out .= '</pre>';
81
- $m = sprintf(
82
- __('The table <strong>%s</strong> could not be updated.<br/>Please run the following queries manually and reactivate the plugin: %s')
83
- , $tableName, $out);
84
- echo '<div class="error"><p><strong>'.WPPH_PLUGIN_NAME.' '.__('Error').':</strong> '.$m.'</p></div>';
85
- }
86
-
87
- // MySQL < 5
88
- public static function e6(){
89
- echo '<div class="error"><p><strong>'.WPPH_PLUGIN_NAME.' '.__('Error').':</strong> Plugin could not be properly installed. MySQL version detected is lower than 5.</p></div>';
90
- }
91
- // PHP < 5
92
- public static function e7(){
93
- echo '<div class="error"><p><strong>'.WPPH_PLUGIN_NAME.' '.__('Error').':</strong> Plugin could not be properly installed. PHP version detected is lower than 5.</p></div>';
94
- }
95
-
96
-
97
- public static function e100(){
98
- $m = __('Plugin cannot create tables in the WordPress database to store security audit logs. Allow write access to the WordPress database user temporarily to activate this plugin.
99
- For more information contact us on support@wpprohelp.com.');
100
- echo '<div class="error"><p><strong>'.WPPH_PLUGIN_NAME.' '.__('Error').':</strong> '.$m.'</p></div>';
101
- }
102
- public static function e200($missingRights=''){
103
- if(! empty($missingRights)){
104
- $missingRights = base64_decode($missingRights);
105
- }
106
- echo '<div class="error"><p><strong>'.WPPH_PLUGIN_NAME.' '.__('Error').':</strong> Plugin could not be properly installed.
107
- The db user used to connect to the WordPress database is missing the following rights: '.$missingRights.'.</p></div>';
108
- }
109
- public static function e300(){
110
- echo '<div class="error"><p><strong>'.WPPH_PLUGIN_NAME.' '.__('Error').':</strong> Plugin could not be properly installed.
111
- The PHP version installed on this server is less than 5.</p></div>';
112
- }
113
- public static function e400(){
114
- echo '<div class="error"><p><strong>'.WPPH_PLUGIN_NAME.' '.__('Error').':</strong> Plugin could not be properly installed.
115
- The MySQL version installed on this server is less than 5.</p></div>';
116
- }
117
- public static function e500(){
118
- echo '<div class="error"><p><strong>'.WPPH_PLUGIN_NAME.' '.__('Fatal Error').':</strong> Plugin could not be properly installed because the server does not meet our requirements:
119
- MySQL and PHP version >= 5.</p></div>';
120
- }
121
- public static function e600(){
122
- echo '<div class="error"><p><strong>'.WPPH_PLUGIN_NAME.' '.__('Fatal Error').':</strong> Plugin could not be properly upgraded because we could not empty the content of the following tables: ';
123
- echo '<br/><strong>'.WPPHDatabase::getFullTableName('main').'</strong>';
124
- echo '<br/><strong>'.WPPHDatabase::getFullTableName('events').'</strong>';
125
- echo '</p></div>';
126
- }
127
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/WPPHDatabase.php CHANGED
@@ -35,138 +35,66 @@ class WPPHDatabase
35
 
36
  //================================================================================================================
37
 
38
- /**
39
- * @internal
40
- * Prepares the tables for future upgrades from v0.1
41
- */
42
- public static function v2Cleanup()
43
- {
44
- global $wpdb;
45
-
46
- // empty table 1
47
- if(self::_eventLogsTableExists())
48
- {
49
- $query = "TRUNCATE ".$wpdb->prefix.self::$_eventsLogTableBaseName;
50
-
51
- if(false === $wpdb->query($query)){
52
- self::$_canUpgrade = false;
53
- }
54
- else { self::$_canUpgrade = true; }
55
- }
56
- else { self::$_canUpgrade = true; }
57
-
58
- // empty table 2
59
- if(self::_eventDetailsTableExists())
60
- {
61
- $query = "TRUNCATE ".$wpdb->prefix.self::$_eventsDetailsTableBaseName;
62
-
63
- if(false === $wpdb->query($query)){
64
- self::$_canUpgrade = false;
65
- }
66
- else { self::$_canUpgrade = true; }
67
- }
68
- else { self::$_canUpgrade = true; }
69
-
70
- return self::$_canUpgrade;
71
- }
72
-
73
-
74
- public static function handleTables()
75
  {
76
- if(! self::tablesExist())
77
- {
78
- $result = WPPHDatabase::createTables();
79
- if($result !== true){
80
- return $result;
81
- }
82
- }
83
-
84
- $result = self::upgradeTables();
85
- if($result !== true){
86
- return $result;
87
- }
88
-
89
- $result = self::updateTables();
90
- if($result !== true){
91
- return $result;
92
- }
93
-
94
- update_option(WPPH_PLUGIN_DB_UPDATED,1);
95
- return true;
96
- }
97
-
98
- // check to see whether or not the tables exist in the database
99
- public static function tablesExist()
100
- {
101
- global $wpdb;
102
- $tables = $wpdb->get_results("SHOW TABLES;",ARRAY_N);
103
- $t1 = self::getFullTableName('main');
104
- $t2 = self::getFullTableName('events');
105
- $r1 = $r2 = false;
106
- foreach($tables as $table){
107
- if(strcasecmp($t1, $table[0])==0){ $r1 = true; }
108
- elseif(strcasecmp($t2, $table[0])==0){ $r2 = true; }
109
- }
110
- if($r1 == true && $r2 == true){
111
  self::$_tablesCreated = true;
 
 
 
112
  return true;
113
  }
114
- return false;
115
- }
116
 
117
- public static function createTables()
118
- {
119
  global $wpdb;
120
- if(! self::_eventDetailsTableExists()) {
121
- $query = self::getCreateQueryEventsDetailsTable();
122
- if (false === @$wpdb->query($query)){ return 0; }
123
- }
124
- if(! self::_eventLogsTableExists()){
125
- $query = self::getCreateQueryLogsTable();
126
- if(false === @$wpdb->query($query)){return 3;}
 
 
 
127
  }
128
- return true;
129
- }
130
-
131
- public static function upgradeTables()
132
- {
133
- wpphLog(__FUNCTION__.'() triggered.');
134
- $optData = get_option(WPPH_PLUGIN_DB_UPDATED);
135
- if($optData !== false){
136
- wpphLog('Database is already updated.');
137
- if($optData == 1){ return true; }
138
  }
139
-
140
- if(! @self::_upgradeEventDetailsTable()){
141
- return 2;
142
  }
143
- if(! @self::_upgradeEventLogsTable()){
144
- return 5;
145
  }
146
- self::$_tablesUpgraded = true;
147
- return true;
148
- }
149
-
150
- public static function updateTables()
151
- {
152
- if(! @self::_updateEventsDetailsTable()){
153
- return 1;
154
  }
155
- if(! @self::_updateEventLogsTable()){
156
- return 4;
 
157
  }
 
 
158
  self::$_tablesUpdated = true;
 
159
  return true;
160
  }
161
 
162
- public static function canRun() {
163
- if(self::$_tablesCreated && self::$_tablesUpgraded && self::$_tablesUpdated){
164
- self::$_canRun = true;
165
- }
166
- return self::$_canRun;
167
  }
168
 
169
-
170
  /**
171
  * Returns the full table name db_prefix + base_table_name for the requested table
172
  * @param string $what the table identifier. Possible values:
@@ -174,7 +102,7 @@ class WPPHDatabase
174
  * events -> to retrieve: db_prefix + self::$_eventsDetailsTableBaseName
175
  * @return string
176
  */
177
- public static function getFullTableName($what = 'main')
178
  {
179
  global $wpdb;
180
  if(strcasecmp($what, 'MAIN') == 0){
@@ -186,45 +114,47 @@ class WPPHDatabase
186
  return '';
187
  }
188
 
189
- public static function getCreateQueryEventsDetailsTable()
 
 
 
 
 
 
190
  {
191
  global $wpdb;
192
- $tableName = self::getFullTableName('events');
193
- return "CREATE TABLE IF NOT EXISTS `$tableName` (
194
- `EventID` int(8) NOT NULL,
195
- `EventType` varchar(10) DEFAULT 'NOTICE',
196
- `EventDescription` text NOT NULL,
197
- PRIMARY KEY (`EventID`),
198
- UNIQUE KEY `EventID` (`EventID`)
199
- );";
200
- }
201
 
202
- public static function getUpdateQueryEventsDetailsTable()
203
- {
204
- $out = array();
205
- $entries = WPPHEvent::listEvents();
206
- if(empty($entries)){ return $out; }
207
 
208
- foreach($entries as $entry)
209
- {
210
- $q = sprintf("INSERT INTO ".self::getFullTableName('events')." (`EventID`,`EventType`,`EventDescription`) VALUES(%d,'%s','%s')", $entry['id'], $entry['category'], $entry['text']);
211
- $out["{$entry['id']}"] = $q;
 
 
 
 
212
  }
213
- return $out;
214
- }
215
 
216
- //@todo: UPDATE AS NECESSARY
217
- public static function getUpgradeQueryEventsDetailsTable()
218
- {
219
- return array();
 
 
 
 
 
 
 
220
  }
221
 
222
 
223
- public static function getCreateQueryLogsTable()
224
  {
225
- global $wpdb;
226
- $t1 = $wpdb->prefix.self::$_eventsLogTableBaseName;
227
- return "CREATE TABLE IF NOT EXISTS `$t1` (
228
  `EventNumber` bigint(40) NOT NULL AUTO_INCREMENT,
229
  `EventID` int(8) NOT NULL,
230
  `EventDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -234,113 +164,107 @@ class WPPHDatabase
234
  PRIMARY KEY (`EventNumber`),
235
  UNIQUE KEY `EventNumber` (`EventNumber`)
236
  );";
 
 
237
  }
238
- // todo: add more events to db here
239
- public static function getUpdateQueryLogsTable()
240
  {
241
- return '';
 
 
 
 
 
 
 
 
242
  }
243
- public static function getUpgradeQueryLogsTable()
244
  {
245
- return array(
246
- "ALTER TABLE ".self::getFullTableName('main')." ADD COLUMN `EventCount` INT NOT NULL DEFAULT 1 AFTER `EventData`;",
247
- "ALTER TABLE ".self::getFullTableName('main')." ADD COLUMN `UserName` VARCHAR(125) NOT NULL DEFAULT '' AFTER `EventCount`;",
248
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  }
250
-
251
-
252
- private static function _createEventDetailsTable()
253
  {
254
- if(self::_eventDetailsTableExists()) { return true; }
255
- global $wpdb;
256
- $query = self::getCreateQueryEventsDetailsTable();
257
- if (false === @$wpdb->query($query)){ return false; }
258
  return true;
259
  }
260
-
261
  /**
262
  * This function will insert the default rows in the events details table
263
  */
264
- private static function _updateEventsDetailsTable()
265
  {
266
- global $wpdb;
 
 
267
 
268
- $queries = self::getUpdateQueryEventsDetailsTable();
269
- if(empty($queries)){
 
 
 
 
270
  return true;
271
  }
272
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
  foreach($queries as $id => $query){
274
  if(! empty($query)){
275
- $var = @$wpdb->get_var("SELECT EventID FROM ".self::getFullTableName('events')." WHERE EventID = $id");
276
- if(empty($var)){
277
- if(false === @$wpdb->query($query)){
278
- wpphLog('QUERY FAILED TO RUN: ',$query);
279
- return false;
280
- }
 
 
281
  }
282
  }
283
  }
284
  return true;
285
  }
286
 
287
- //TODO: UPDATE AS NECESSARY
288
- private static function _upgradeEventDetailsTable()
289
  {
290
- //EXECUTE THE QUERY FROM self::getUpgradeQueryEventsDetailsTable();
291
- $queries = self::getUpgradeQueryEventsDetailsTable();
292
- if(empty($queries)){ return true; }
293
-
294
- global $wpdb;
295
- foreach($queries as $query){
296
- if(false === @$wpdb->query($query)){return false;}
297
- }
298
  return true;
299
  }
300
-
301
-
302
- private static function _createEventLogsTable()
303
- {
304
- if(self::_eventLogsTableExists()){ return true;}
305
- global $wpdb;
306
- $query = self::getCreateQueryLogsTable();
307
- if(false === @$wpdb->query($query)){return false;}
308
- return true;
309
- }
310
-
311
- private static function _updateEventLogsTable()
312
- {
313
- return true;
314
- }
315
-
316
- //TODO: UPDATE AS NECESSARY
317
- private static function _upgradeEventLogsTable()
318
- {
319
- //EXECUTE THE QUERY FROM self::getUpgradeQueryLogsTable();
320
- $queries = self::getUpgradeQueryLogsTable();
321
- if(empty($queries)){ return true;}
322
- global $wpdb;
323
-
324
- foreach($queries as $query){
325
- if(false === @$wpdb->query($query)){return false;}
326
- }
327
- return true;
328
- }
329
-
330
- private static function _eventLogsTableExists()
331
- {
332
- global $wpdb;
333
- $result = @$wpdb->get_var('SELECT EventNumber FROM '.self::getFullTableName('main'));
334
- return (is_null($result) ? false : true);
335
-
336
- }
337
- private static function _eventDetailsTableExists()
338
- {
339
- global $wpdb;
340
- $result = @$wpdb->get_var('SELECT EventID FROM '.self::getFullTableName('events'));
341
- return (is_null($result) ? false : true);
342
- }
343
-
344
  }
345
 
346
  /**
@@ -352,7 +276,7 @@ class WPPHDB extends WPPHDatabase
352
  /**
353
  * @return string The current logged in user's role
354
  */
355
- public static function getCurrentUserRole()
356
  {
357
  global $current_user;
358
  get_currentuserinfo();
@@ -361,7 +285,7 @@ class WPPHDB extends WPPHDatabase
361
  return $user_role;
362
  }
363
  // returns array(userName, userRole)
364
- public static function getUserInfo($userID)
365
  {
366
  global $wpdb;
367
 
@@ -381,11 +305,9 @@ class WPPHDB extends WPPHDatabase
381
  * Retrieve the total number of events from db
382
  * @return int
383
  */
384
- public static function getEventsCount()
385
  {
386
  global $wpdb;
387
  return $wpdb->get_var("SELECT COUNT(EventNumber) FROM ".self::getFullTableName('main'));
388
  }
389
-
390
- }
391
-
35
 
36
  //================================================================================================================
37
 
38
+ static function handleDatabase()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  {
40
+ // Check database
41
+ $dbUpdated = get_option(WPPH_PLUGIN_DB_UPDATED);
42
+ if(false !== $dbUpdated){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  self::$_tablesCreated = true;
44
+ self::$_tablesUpgraded = true;
45
+ self::$_tablesUpdated = true;
46
+ self::$_canRun = true;
47
  return true;
48
  }
 
 
49
 
 
 
50
  global $wpdb;
51
+ $tableMain = self::getFullTableName('MAIN');
52
+ $tableEvents = self::getFullTableName('EVENTS');
53
+
54
+ // Check if tables exist
55
+ if(! self::tableExists($wpdb, $tableMain)){
56
+ if(! self::_createEventLogsTable($wpdb, $tableMain)){
57
+ WPPH::__addPluginError(__("Plugin cannot create tables in the WordPress database to store security audit logs. Allow write access to the WordPress database user temporarily to activate this plugin.
58
+ For more information contact us on support@wpprohelp.com.",WPPH_PLUGIN_TEXT_DOMAIN));
59
+ return false;
60
+ }
61
  }
62
+ if(! self::tableExists($wpdb, $tableEvents)){
63
+ if(! self::_createEventDetailsTable($wpdb, $tableEvents)){
64
+ WPPH::__addPluginError(__("Plugin cannot create tables in the WordPress database to store security audit logs. Allow write access to the WordPress database user temporarily to activate this plugin.
65
+ For more information contact us on support@wpprohelp.com.",WPPH_PLUGIN_TEXT_DOMAIN));
66
+ return false;
67
+ }
 
 
 
 
68
  }
69
+ // Check if tables need to be upgraded
70
+ if(! self::_upgradeEventLogsTable($wpdb, $tableMain)){
71
+ return false;
72
  }
73
+ if(! self::_upgradeEventDetailsTable($wpdb, $tableEvents)){
74
+ return false;
75
  }
76
+ // Check if tables need to be updated
77
+ if(! self::_updateEventsDetailsTable($wpdb, $tableEvents)){
78
+ WPPH::__addPluginError(sprintf(__("Error updating table <strong>%s</strong>.",WPPH_PLUGIN_TEXT_DOMAIN), $tableEvents));
79
+ return false;
 
 
 
 
80
  }
81
+ if(! self::_updateEventLogsTable($wpdb, $tableMain)){
82
+ WPPH::__addPluginError(sprintf(__("Error updating table <strong>%s</strong>.",WPPH_PLUGIN_TEXT_DOMAIN), $tableMain));
83
+ return false;
84
  }
85
+ self::$_tablesCreated = true;
86
+ self::$_tablesUpgraded = true;
87
  self::$_tablesUpdated = true;
88
+ self::$_canRun = true;
89
  return true;
90
  }
91
 
92
+ static function tableExists($wpdb, $tableFullName)
93
+ {
94
+ $result = $wpdb->get_var("SHOW TABLES LIKE '$tableFullName'");
95
+ return (is_null($result) ? false : true);
 
96
  }
97
 
 
98
  /**
99
  * Returns the full table name db_prefix + base_table_name for the requested table
100
  * @param string $what the table identifier. Possible values:
102
  * events -> to retrieve: db_prefix + self::$_eventsDetailsTableBaseName
103
  * @return string
104
  */
105
+ static function getFullTableName($what = 'main')
106
  {
107
  global $wpdb;
108
  if(strcasecmp($what, 'MAIN') == 0){
114
  return '';
115
  }
116
 
117
+ static function canRun() { return self::$_canRun; }
118
+
119
+ /**
120
+ * @internal
121
+ * Prepares the tables for future upgrades from v0.1
122
+ */
123
+ static function v2Cleanup()
124
  {
125
  global $wpdb;
 
 
 
 
 
 
 
 
 
126
 
127
+ $t1 = self::getFullTableName('MAIN');
128
+ $t2 = self::getFullTableName('EVENTS');
 
 
 
129
 
130
+ // empty table 1
131
+ $query = "TRUNCATE ". $wpdb->prefix.self::$_eventsLogTableBaseName;
132
+ if(false === $wpdb->query($query)){
133
+ WPPH::__addPluginError(
134
+ sprintf(
135
+ __("Plugin could not be properly upgraded because we could not empty the content of the following table: <strong>%s</strong>",WPPH_PLUGIN_TEXT_DOMAIN),$t1)
136
+ );
137
+ self::$_canUpgrade = false;
138
  }
139
+ else { self::$_canUpgrade = true; }
 
140
 
141
+ // empty table 2
142
+ $query = "TRUNCATE ".$wpdb->prefix.self::$_eventsDetailsTableBaseName;
143
+ if(false === $wpdb->query($query)){
144
+ WPPH::__addPluginError(
145
+ sprintf(__("Plugin could not be properly upgraded because we could not empty the content of the following table: <strong>%s</strong>",WPPH_PLUGIN_TEXT_DOMAIN),$t2)
146
+ );
147
+ self::$_canUpgrade = false;
148
+ }
149
+ else { self::$_canUpgrade = true; }
150
+
151
+ return self::$_canUpgrade;
152
  }
153
 
154
 
155
+ private static function _createEventLogsTable($wpdb, $tableFullName)
156
  {
157
+ $query = "CREATE TABLE IF NOT EXISTS `$tableFullName` (
 
 
158
  `EventNumber` bigint(40) NOT NULL AUTO_INCREMENT,
159
  `EventID` int(8) NOT NULL,
160
  `EventDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
164
  PRIMARY KEY (`EventNumber`),
165
  UNIQUE KEY `EventNumber` (`EventNumber`)
166
  );";
167
+ if(false === @$wpdb->query($query)){return false;}
168
+ return true;
169
  }
170
+ private static function _createEventDetailsTable($wpdb, $tableFullName)
 
171
  {
172
+ $query = "CREATE TABLE IF NOT EXISTS `$tableFullName` (
173
+ `EventID` int(8) NOT NULL,
174
+ `EventType` varchar(10) DEFAULT 'NOTICE',
175
+ `EventDescription` text NOT NULL,
176
+ PRIMARY KEY (`EventID`),
177
+ UNIQUE KEY `EventID` (`EventID`)
178
+ );";
179
+ if (false === @$wpdb->query($query)){ return false; }
180
+ return true;
181
  }
182
+ private static function _upgradeEventLogsTable($wpdb, $tableFullName)
183
  {
184
+ $q = "SHOW COLUMNS FROM $tableFullName LIKE 'EventCount';";
185
+ $rowData = $wpdb->get_row($q, ARRAY_A);
186
+ if(empty($rowData['Field']))
187
+ {
188
+ $q = "ALTER TABLE $tableFullName ADD COLUMN `EventCount` INT NOT NULL DEFAULT 1 AFTER `EventData`;";
189
+ $result = @$wpdb->query($q);
190
+ if($result === false){
191
+ WPPH::__addPluginError(
192
+ sprintf(__("Plugin could not be properly installed. The db user used to connect to the WordPress database is missing the <strong>ALTER</strong> right for query: <strong>%s</strong>",WPPH_PLUGIN_TEXT_DOMAIN),$q)
193
+ );
194
+ return false;
195
+ }
196
+ $q = "ALTER TABLE $tableFullName ADD COLUMN `UserName` VARCHAR(125) NOT NULL DEFAULT '' AFTER `EventCount`;";
197
+ $result = @$wpdb->query($q);
198
+ if($result === false){
199
+ WPPH::__addPluginError(
200
+ sprintf(__("Plugin could not be properly installed. The db user used to connect to the WordPress database is missing the <strong>ALTER</strong> right for query: <strong>%s</strong>",WPPH_PLUGIN_TEXT_DOMAIN),$q)
201
+ );
202
+ return false;
203
+ }
204
+ }
205
+ return true;
206
  }
207
+ private static function _upgradeEventDetailsTable($wpdb, $tableFullName)
 
 
208
  {
 
 
 
 
209
  return true;
210
  }
 
211
  /**
212
  * This function will insert the default rows in the events details table
213
  */
214
+ private static function _updateEventsDetailsTable($wpdb, $tableFullName)
215
  {
216
+ $queries = array();
217
+ $events = WPPHEvent::listEvents();
218
+ if(empty($events)){ return true; }
219
 
220
+ // check for differences
221
+ $numFileEvents = count($events);
222
+ $numDbEvents = (int)$wpdb->get_var("SELECT COUNT(EventID) FROM $tableFullName;");
223
+
224
+ // no update necessary
225
+ if($numFileEvents == $numDbEvents){
226
  return true;
227
  }
228
 
229
+ foreach($events as $entry)
230
+ {
231
+ $q = sprintf("INSERT INTO $tableFullName (`EventID`,`EventType`,`EventDescription`) VALUES(%d,'%s','%s')", $entry['id'], $entry['category'], $entry['text']);
232
+ $queries["{$entry['id']}"] = $q;
233
+ }
234
+
235
+ // Clear table
236
+ if($numDbEvents > 0){
237
+ $result = @$wpdb->query("TRUNCATE $tableFullName");
238
+ if($result === false){
239
+ WPPH::__addPluginError(
240
+ sprintf(
241
+ __("Could not empty table <strong>%s</strong>. Please run the following query manually: <strong>TRUNCATE %s</strong>",WPPH_PLUGIN_TEXT_DOMAIN)
242
+ ,$tableFullName, $tableFullName)
243
+ );
244
+ return false;
245
+ }
246
+ }
247
+ // Insert data
248
  foreach($queries as $id => $query){
249
  if(! empty($query)){
250
+ if(false === @$wpdb->query($query)){
251
+ wpphLog('QUERY FAILED TO RUN: ',$query);
252
+ WPPH::__addPluginError(
253
+ sprintf(
254
+ __("Error updating table <strong>%s</strong> using query: <strong>%s</strong>",WPPH_PLUGIN_TEXT_DOMAIN)
255
+ ,$tableFullName, $query)
256
+ );
257
+ return false;
258
  }
259
  }
260
  }
261
  return true;
262
  }
263
 
264
+ private static function _updateEventLogsTable($wpdb, $tableFullName)
 
265
  {
 
 
 
 
 
 
 
 
266
  return true;
267
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
  }
269
 
270
  /**
276
  /**
277
  * @return string The current logged in user's role
278
  */
279
+ static function getCurrentUserRole()
280
  {
281
  global $current_user;
282
  get_currentuserinfo();
285
  return $user_role;
286
  }
287
  // returns array(userName, userRole)
288
+ static function getUserInfo($userID)
289
  {
290
  global $wpdb;
291
 
305
  * Retrieve the total number of events from db
306
  * @return int
307
  */
308
+ static function getEventsCount()
309
  {
310
  global $wpdb;
311
  return $wpdb->get_var("SELECT COUNT(EventNumber) FROM ".self::getFullTableName('main'));
312
  }
313
+ }
 
 
inc/WPPHEvent.php CHANGED
@@ -8,114 +8,142 @@ class WPPHEvent
8
  * Retrieve the list of events
9
  * @return array
10
  */
11
- public static function listEvents()
12
  {
13
  return array(
14
  // 1xxx - Login/Logout events
15
- array( 'id' => 1000, 'category' => 'NOTICE', 'text' => __('Successfully logged in.') ),
16
- array( 'id' => 1001, 'category' => 'NOTICE', 'text' => __('Successfully logged out.') ),
17
- array( 'id' => 1002, 'category' => 'WARNING', 'text' => __('Failed login detected using <strong>%s</strong> as username.') ),
18
 
19
  // 2xxx - User activity events
20
  // Created a new blog post called %Post Title%. Blog post ID is %ID%
21
- array( 'id' => 2000, 'category' => 'NOTICE', 'text' => __('Created a new draft blog post called <strong>%s</strong>. Blog post ID is <strong>%d</strong>.') ),
22
  // Published a blog post called %Post_Title%. Blog post URL is %Post_URL%
23
- array( 'id' => 2001, 'category' => 'NOTICE', 'text' => __('Published a blog post called <strong>%s</strong>. Blog post URL is <strong>%s</strong>.') ),
24
  // Modified the published blog post %post_title%. Blog post URL is %post_URL%
25
- array( 'id' => 2002, 'category' => 'NOTICE', 'text' => __('Modified the published blog post <strong>%s</strong>. Blog post URL is <strong>%s</strong>.') ),
26
  // Modified the draft blog post %post_title%. Blog post ID is %ID%
27
- array( 'id' => 2003, 'category' => 'NOTICE', 'text' => __('Modified the draft blog post <strong>%s</strong>. Blog post ID is <strong>%d</strong>.') ),
28
 
29
  // Created a new page called %page_title%. Page ID is %ID%
30
- array( 'id' => 2004, 'category' => 'NOTICE', 'text' => __('Created a new draft page called <strong>%s</strong>. Page ID is <strong>%d</strong>.') ),
31
  // Published a page called %page_title%. Page URL is %URL%
32
- array( 'id' => 2005, 'category' => 'NOTICE', 'text' => __('Published a page called <strong>%s</strong>. Page URL is <strong>%s</strong>.') ),
33
  // Modified the published page %page_title%. Page URL is %URL%
34
- array( 'id' => 2006, 'category' => 'NOTICE', 'text' => __('Modified the published page <strong>%s</strong>. Page URL is <strong>%s</strong>.') ),
35
  // Modified the draft page %page_title%. Page ID is %ID%
36
- array( 'id' => 2007, 'category' => 'NOTICE', 'text' => __('Modified the draft page <strong>%s</strong>. Page ID is <strong>%d</strong>.') ),
37
  // Deleted the post %Title%. Blog post ID is %ID%
38
- array( 'id' => 2008, 'category' => 'HIGH', 'text' => __('Deleted the post <strong>%s</strong>. Blog post ID is <strong>%d</strong>.') ),
39
  // Deleted the page %Title%. Page ID is %ID%
40
- array( 'id' => 2009, 'category' => 'HIGH', 'text' => __('Deleted the page <strong>%s</strong>. Page ID is <strong>%d</strong>.') ),
41
 
42
  // Uploaded the file %file name$ in %file location%
43
- array( 'id' => 2010, 'category' => 'NOTICE', 'text' => __('Uploaded the file <strong>%s</strong> in <strong>%s</strong>/.') ),
44
  // Deleted file %file name$ from %file_location%
45
- array( 'id' => 2011, 'category' => 'HIGH', 'text' => __('Deleted the file <strong>%s</strong> from <strong>%s</strong>/.') ),
46
  // 2012 - trashed draft post
47
- array( 'id' => 2012, 'category' => 'HIGH', 'text' => __('Moved the post <strong>%s</strong> to trash.') ),
48
  // 2013 - trashed published post
49
- array( 'id' => 2013, 'category' => 'HIGH', 'text' => __('Moved the page <strong>%s</strong> to trash.') ),
50
  // 2014 - untrashed post
51
- array( 'id' => 2014, 'category' => 'HIGH', 'text' => __('Post <strong>%s</strong> has been restored from trash.') ),
52
  // 2015 - untrashed page
53
- array( 'id' => 2015, 'category' => 'HIGH', 'text' => __('Page <strong>%s</strong> has been restored from trash.') ),
54
  // 2016 - Post category changed
55
- array( 'id' => 2016, 'category' => 'NOTICE', 'text' => __('Changed the category(ies) of the post <strong>%s</strong> from <strong>%s</strong> to <strong>%s</strong>.') ),
56
  // 2017 - Changed the URL of the post %post_name% from %old_url% to %new_url%
57
- array( 'id' => 2017, 'category' => 'NOTICE', 'text' => __('Changed the URL of the post <strong>%s</strong> from <strong>%s</strong> to <strong>%s</strong>.') ),
58
  // 2018 - Changed the URL of the page %page_name% from %old_url% to %new_url%
59
- array( 'id' => 2018, 'category' => 'NOTICE', 'text' => __('Changed the URL of the page <strong>%s</strong> from <strong>%s</strong> to <strong>%s</strong>.') ),
60
  // 2019 - Changed the author of %post_name% post from %old_author% to %new_author%
61
- array( 'id' => 2019, 'category' => 'NOTICE', 'text' => __('Changed the author of <strong>%s</strong> from <strong>%s</strong> to <strong>%s</strong>.') ),
62
  // 2020 - Changed the author of %page_name% page from %old_author% to %new_author%
63
- array( 'id' => 2020, 'category' => 'NOTICE', 'text' => __('Changed the author of <strong>%s</strong> page from <strong>%s</strong> to <strong>%s</strong>.') ),
64
  // 2021 - %postName% from %oldStatus% to %newStatus%
65
- array( 'id' => 2021, 'category' => 'NOTICE', 'text' => __('Changed the status of <strong>%s</strong> post from <strong>%s</strong> to <strong>%s</strong>.') ),
66
  // 2022 - page from published to draft
67
- array( 'id' => 2022, 'category' => 'NOTICE', 'text' => __('Changed the status of <strong>%s</strong> page from <strong>%s</strong> to <strong>%s</strong>.') ),
68
  // 2023 - added new category
69
- array( 'id' => 2023, 'category' => 'NOTICE', 'text' => __('Created a new category called <strong>%s</strong>.') ),
70
  // 2024 - deleted category
71
- array( 'id' => 2024, 'category' => 'WARNING', 'text' => __('Deleted the <strong>%s</strong> category.') ),
72
  // 2025 - Changed the visibility of %post_name% blog post from %old_visibility% to %new_visibility%
73
- array( 'id' => 2025, 'category' => 'WARNING', 'text' => __('Changed the visibility of <strong>%s</strong> blog post from <strong>%s</strong> to <strong>%s</strong>.') ),
74
  // 2026 - Changed the visibility of %page_name% page from %old_visibility% to %new_visibility%
75
- array( 'id' => 2026, 'category' => 'WARNING', 'text' => __('Changed the visibility of <strong>%s</strong> page from <strong>%s</strong> to <strong>%s</strong>.') ),
76
  // 2027 - Changed the date of %post_name% blog post from %old_date% to %new_date%
77
- array( 'id' => 2027, 'category' => 'NOTICE', 'text' => __('Changed the date of <strong>%s</strong> blog post from <strong>%s</strong> to <strong>%s</strong>.') ),
78
  // 2028 - Changed the date of %post_name% page from %old_date% to %new_date%
79
- array( 'id' => 2028, 'category' => 'NOTICE', 'text' => __('Changed the date of <strong>%s</strong> page from <strong>%s</strong> to <strong>%s</strong>.') ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  // 3xxx - Themes management
82
  // Activated the theme %themeName%
83
- array( 'id' => 3000, 'category' => 'NOTICE', 'text' => __('Activated the theme <strong>%s</strong>.') ),
84
 
85
  // 4xxx - User profile events
86
- array( 'id' => 4000, 'category' => 'HIGH', 'text' => __('A new user with the username <strong>%s</strong> has registered with the role of <strong>%s</strong>.') ),
87
- array( 'id' => 4001, 'category' => 'HIGH', 'text' => __('<strong>%s</strong> created a new user <strong>%s</strong> with the role of <strong>%s</strong>.') ),
88
- array( 'id' => 4002, 'category' => 'HIGH', 'text' => __('The role of user <strong>%s</strong> was changed from <strong>%s</strong> to <strong>%s</strong> by <strong>%s</strong>.') ),
89
- array( 'id' => 4003, 'category' => 'HIGH', 'text' => __('Changed the account password.') ),
90
- array( 'id' => 4004, 'category' => 'HIGH', 'text' => __('<strong>%s</strong> changed the password for user <strong>%s</strong> with the role of <strong>%s</strong>.') ),
91
  // Changed the email address from %old_email% to %new_email%
92
- array( 'id' => 4005, 'category' => 'NOTICE', 'text' => __('Changed the email address from <strong>%s</strong> to <strong>%s</strong>.') ),
93
  // %user_making_change% changed the email address of user %user% from %old_email% to %new_email%
94
- array( 'id' => 4006, 'category' => 'NOTICE', 'text' => __('<strong>%s</strong> changed the email address of user <strong>%s</strong> from <strong>%s</strong> to <strong>%s</strong>.') ),
95
  // User %user% with the role of %role% was deleted by %user_deleting%
96
- array( 'id' => 4007, 'category' => 'HIGH', 'text' => __('User <strong>%s</strong> with the role of <strong>%s</strong> was deleted by <strong>%s</strong>.') ),
97
 
98
  // 5xxx - Plugin management
99
  // # 5000 Installed the plugin %name%.
100
- array( 'id' => 5000, 'category' => 'HIGH', 'text' => __('Installed the plugin <strong>%s</strong>.') ),
101
  // Activated the plugin %plugin_name% installed in %plugin_directory%
102
- array( 'id' => 5001, 'category' => 'HIGH', 'text' => __('Activated the plugin <strong>%s</strong> installed in /<strong>%s</strong>.') ),
103
  // Deactivated the plugin %plugin_name% installed in %plugin_directory%
104
- array( 'id' => 5002, 'category' => 'HIGH', 'text' => __('Deactivated the plugin <strong>%s</strong> installed in /<strong>%s</strong>.') ),
105
  // # 5003 Uninstalled the plugin %plugin_name% which was installed in %path%
106
- array( 'id' => 5003, 'category' => 'HIGH', 'text' => __('Uninstalled the plugin <strong>%s</strong> which was installed in /<strong>%s</strong>.') ),
107
  // # 5004 Upgraded the plugin %name% installed in %path%
108
- array( 'id' => 5004, 'category' => 'WARNING', 'text' => __('Upgraded the plugin <strong>%s</strong> installed in /<strong>%s</strong>.') ),
109
 
110
  // 6xxx - System events
111
  // #6000 Events automatically deleted by system.
112
- array( 'id' => 6000, 'category' => 'NOTICE', 'text' => __('Events automatically deleted by system.') ),
113
  // #6001 - <strong>%s</strong> the option Anyone can register
114
- array( 'id' => 6001, 'category' => 'HIGH', 'text' => __('<strong>%s</strong> the option Anyone can register') ),
115
  // #6002 - Changed the New User Default Role from <strong>%s</strong> to <strong>%s</strong>
116
- array( 'id' => 6002, 'category' => 'HIGH', 'text' => __('Changed the New User Default Role from <strong>%s</strong> to <strong>%s</strong>') ),
117
  // #6003 - Changed the WordPress administrator notifications email address from %old_email% to %new_mail%
118
- array( 'id' => 6003, 'category' => 'HIGH', 'text' => __('Changed the WordPress administrator notifications email address from <strong>%s</strong> to <strong>%s</strong>') ),
119
  );
120
  }
121
 
@@ -123,47 +151,47 @@ class WPPHEvent
123
  // 1xxx - Login/Logout events
124
 
125
  // 1000
126
- public static function hookLoginEvent() { add_action('wp_login', array('WPPHEventWatcher', 'watchEventLogin'), 10, 2); }
127
  // 1001
128
- public static function hookLogoutEvent() { add_action('wp_logout', array('WPPHEventWatcher', 'watchEventLogout')); }
129
  // 1002
130
- public static function hookLoginFailure() { add_action('wp_login_failed', array('WPPHEventWatcher', 'watchLoginFailure')); }
131
 
132
 
133
  // 2xxx - User activity events
134
 
135
  // 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2021, 2022
136
- public static function hookWatchBlogActivity() { add_action('transition_post_status', array('WPPHEventWatcher', 'watchBlogActivity'), 10, 3); }
137
  // 2008, 2009
138
- public static function hookFileDeletion() { add_action('delete_post', array('WPPHEventWatcher', 'watchTrash'), 10, 1); }
139
  // 2010
140
- public static function hookFileUploaded() { add_action('add_attachment', array('WPPHEventWatcher', 'watchFileUploaded')); }
141
  // 2011
142
- public static function hookFileUploadedDeleted() { add_action('delete_attachment', array('WPPHEventWatcher', 'watchFileUploadedDeleted')); }
143
  // 2012
144
- public static function hookTrashPost() {
145
  if(defined('EMPTY_TRASH_DAYS') && (EMPTY_TRASH_DAYS == 0)){
146
  add_action('delete_post', array('WPPHEventWatcher', 'watchTrash'), 10, 1);
147
  }
148
- else { add_action('trash_post', array('WPPHEventWatcher', 'watchFileDeletion')); }
149
  }
150
  // 2013
151
- public static function hookTrashPage() {
152
  if(defined('EMPTY_TRASH_DAYS') && (EMPTY_TRASH_DAYS == 0)){
153
  add_action('delete_post', array('WPPHEventWatcher', 'watchTrash'), 10, 1);
154
  }
155
- else { add_action('trash_page', array('WPPHEventWatcher', 'watchFileDeletion')); }
156
  }
157
  //2014
158
- public static function hookUntrashedPosts() { add_action('untrash_post', array('WPPHEventWatcher', 'watchTrashUndo')); }
159
  // 2015
160
- public static function hookUntrashedPages() { add_action('untrash_page', array('WPPHEventWatcher', 'watchTrashUndo')); }
161
  // 2016, 2017
162
- public static function hookWatchPostStateBefore()
163
  {
164
- if(! isset($_POST)){ return; }
165
- if(! is_admin()){ return; }
166
- if(isset($_POST['action']) && $_POST['action'] == 'autosave') { return; }
167
 
168
  if(isset($GLOBALS['WPPH_DEFAULT_EDITOR_ENABLED']) || isset($GLOBALS['WPPH_SCREEN_EDITOR_ENABLED']))
169
  {
@@ -172,51 +200,55 @@ class WPPHEvent
172
  global $wpdb;
173
  $pid = $_POST['post_ID'];
174
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  /*
176
  * CHECK IF POST/PAGE AUTHOR UPDATED; 2019
177
  * ## step 1: this is where we check if author has been changed
178
- * ## step 2: @see wpph_managePostAuthorUpdateQuickEditForm()
179
  */
180
  if(! empty($_POST['post_author']))
181
  {
182
  $GLOBALS['WPPH_POST_AUTHOR_UPDATED_ID'] = intval($_POST['post_author']);
183
  if(isset($GLOBALS['WPPH_SCREEN_EDITOR_ENABLED'])){
184
  // trigger hook manually
185
- add_filter( 'wp_insert_post_data', 'wpph_managePostAuthorUpdateQuickEditForm', '1', 2 );
186
- // $GLOBALS['WPPH_POST_AUTHOR_UPDATED'] = true;
187
- // $GLOBALS['WPPH_PAGE_AUTHOR_UPDATED'] = true;
188
  }
189
  }
190
 
191
- // check if post exists
192
- $query = "SELECT ID FROM ".$wpdb->posts." WHERE ID = ".$pid;
193
- $postExists = $wpdb->get_var($query);
194
- $GLOBALS['WPPH_POST_EXISTS'] = (empty($postExists) ? false : true);
195
-
196
- // get aggregated data
197
- $result = $wpdb->get_row("SELECT post_name, post_password, post_date FROM ".$wpdb->posts." WHERE ID = $pid");
198
 
199
  // if blog post
200
- if($_POST['post_type'] == 'post')
201
  {
202
  // before further checks, we have to make sure this post isn't new
203
- if(empty($GLOBALS['WPPH_POST_EXISTS'])){
204
  return;
205
  }
206
 
207
- if(! is_null($result))
208
- {
209
- // retrieve the old post pwd to help us detect the posts' visibility transition state
210
- $GLOBALS['WPPH_OLD_POST_PASSWORD'] = $result->post_password;
211
- // check if post date has been changed
212
- $GLOBALS['WPPH_POST_OLD_DATE'] = $result->post_date;
213
- // Get the post name so we'll know if URL was updated
214
- $GLOBALS['WPPH_POST_OLD_NAME'] = $result->post_name;
215
- }
216
-
217
  // CHECK IF POST CATEGORY UPDATED; 2016
218
  $GLOBALS['WPPH_POST_OLD_CATEGORIES'] = wp_get_post_categories($pid);
219
-
220
  /*
221
  * CHECK IF POST URL UPDATED; 2017
222
  * ## step 1: this is where we retrieve the new URL
@@ -225,9 +257,9 @@ class WPPHEvent
225
  $GLOBALS['WPPH_POST_NEW_URL'] = get_permalink($pid);
226
  }
227
  // if page
228
- elseif($_POST['post_type'] == 'page')
229
  {
230
- if(! is_null($result))
231
  {
232
  // get the page's password if any (to trigger the 2026 event)
233
  // retrieve the old post pwd to help us detect the posts' visibility transition state
@@ -235,58 +267,57 @@ class WPPHEvent
235
  // check if post date has been changed
236
  $GLOBALS['WPPH_POST_OLD_DATE'] = $result->post_date;
237
  // Get the post name so we'll know if URL was updated
238
- $GLOBALS['WPPH_POST_OLD_NAME'] = $result->post_name;
239
  }
240
 
241
-
242
  /*
243
- * CHECK IF PAGE URL UPDATED; 2018
244
- * ## step 1: this is where we retrieve the new URL
245
- * ## step 2: @see WPPHEventWatcher::watchBlogActivity()
246
- */
247
  $GLOBALS['WPPH_POST_NEW_URL'] = get_permalink($pid);
248
  }
249
  }
250
  }
251
 
252
  // 2023
253
- public static function hookWatchCategoryAdd() { WPPHEventWatcher::watchCategoryAdd($_POST); }
254
  // 2024
255
- public static function hookWatchCategoryDelete() { WPPHEventWatcher::watchCategoryDelete($_POST); }
256
 
257
  // 3xxx - Themes management
258
 
259
  // 3000
260
- public static function hookThemeChange() { add_action('switch_theme', array('WPPHEventWatcher', 'watchThemeChange'));}
261
 
262
 
263
  // 4xxx - User profile events
264
 
265
  // 4000, 4001
266
- public static function hookUserRegisterEvent() { add_action('user_register', array('WPPHEventWatcher', 'watchEventUserRegister')); }
267
  // 4002
268
- public static function hookUserRoleUpdated() {
269
  add_action('edit_user_profile_update', array('WPPHEventWatcher', 'watchUserInfoUpdated'));
270
  add_action('personal_options_update', array('WPPHEventWatcher', 'watchUserInfoUpdated'));
271
  }
272
  // 4003, 4004
273
- public static function hookUserPasswordUpdated() {
274
  add_action('edit_user_profile_update', array('WPPHEventWatcher', 'watchUserInfoUpdated'));
275
  add_action('personal_options_update', array('WPPHEventWatcher', 'watchUserInfoUpdated'));
276
  }
277
  // 4005, 4006
278
- public static function hookUserEmailUpdated() {
279
  add_action('edit_user_profile_update', array('WPPHEventWatcher', 'watchUserInfoUpdated'));
280
  add_action('personal_options_update', array('WPPHEventWatcher', 'watchUserInfoUpdated'));
281
  }
282
  // 4007
283
- public static function hookUserDeletion() { add_action( 'delete_user', array('WPPHEventWatcher', 'watchUserDeletion') ); }
284
 
285
 
286
  // 5xxx - Plugin management
287
 
288
  // 5000, 5001, 5002, 5003, 5004
289
- public static function hookWatchPluginActivity() {
290
  @include_once(ABSPATH.'wp-admin/includes/plugin.php');
291
  WPPHEventWatcher::watchPluginInstall(); // 5000
292
  WPPHEventWatcher::watchPluginActivate(); // 5001
@@ -299,10 +330,10 @@ class WPPHEvent
299
  // 6xxx - System events
300
 
301
  // 6000
302
- public static function hookEventsDeletion() { add_action('init', array('WPPHEventWatcher', 'watchDeleteEvents')); }
303
 
304
  // 6001, 6002
305
- public static function hookCheckWpGeneralSettings(){
306
  if(isset($_POST))
307
  {
308
  $wpphOptData = get_option(WPPH_USERS_CAN_REGISTER_OPT_NAME);
@@ -313,14 +344,14 @@ class WPPHEvent
313
  if(isset($_POST['users_can_register'])){
314
  // on
315
  if(false === $wpphOptData || 0 == $wpphOptData){
316
- self::_addLogEvent(6001, wp_get_current_user()->ID, WPPHUtil::getIP(), array('Enabled'));
317
  update_option(WPPH_USERS_CAN_REGISTER_OPT_NAME,1);
318
  }
319
  }
320
  else {
321
  // off
322
  if(false === $wpphOptData || 1 == $wpphOptData){
323
- self::_addLogEvent(6001, wp_get_current_user()->ID, WPPHUtil::getIP(), array('Disabled'));
324
  update_option('wpph_users_can_register',0);
325
  }
326
  }
@@ -367,8 +398,13 @@ class WPPHEvent
367
  * @param string $failedLoginUserName The name of the user used for the failed login
368
  * @return bool
369
  */
370
- public static function _addLogEvent($eventID = 1000, $userID = 0, $userIP = '', $eventData = array(), $failedLoginUserName='')
371
  {
 
 
 
 
 
372
  if(empty($userIP)){ $userIP = WPPHUtil::getIP(); }
373
  $tableName = WPPHDB::getFullTableName('MAIN');
374
  $eventData = base64_encode(serialize($eventData));
@@ -398,7 +434,7 @@ class WPPHEvent
398
  * ============================================
399
  */
400
 
401
- public static function getEventDetailsData($eventID)
402
  {
403
  global $wpdb;
404
  $table = WPPHDatabase::getFullTableName('events');
@@ -412,7 +448,7 @@ class WPPHEvent
412
  * @param string $sort ASC or DESC
413
  * @return mixed
414
  */
415
- public static function getEvents($orderBy='EventNumber', $sort = 'DESC', $limit = array(0,0))
416
  {
417
  $validArgsSort = array('ASC', 'DESC');
418
  $validCnTableLogDetails = array('EventID', 'EventType');
@@ -469,7 +505,7 @@ class WPPHEventWatcher extends WPPHEvent
469
  * @param $user_login
470
  * @param WP_User $user
471
  */
472
- public static function watchEventLogin($user_login, $user)
473
  {
474
  wpphLog(__METHOD__.'() triggered by hook.');
475
  self::_addLogEvent(1000, $user->ID);
@@ -478,7 +514,7 @@ class WPPHEventWatcher extends WPPHEvent
478
  * @internal
479
  * Hooks to the logout event
480
  */
481
- public static function watchEventLogout()
482
  {
483
  wpphLog(__METHOD__.'() triggered by hook.');
484
  self::_addLogEvent(1001, wp_get_current_user()->ID);
@@ -488,7 +524,7 @@ class WPPHEventWatcher extends WPPHEvent
488
  * @internal
489
  * Hooks to the user register event
490
  */
491
- public static function watchEventUserRegister($user_id)
492
  {
493
  wpphLog(__METHOD__.'() triggered by hook.');
494
 
@@ -500,9 +536,6 @@ class WPPHEventWatcher extends WPPHEvent
500
  $nu = $uInfo['userName'];
501
  $nur = ucfirst($uInfo['userRole']);
502
 
503
- // %s created new user %s with role %s
504
- $eventData = array($un, $nu, $nur);
505
-
506
  if($un == 'System')
507
  {
508
  // A new user with the username %username% has registered with the role of %user_role%
@@ -517,11 +550,11 @@ class WPPHEventWatcher extends WPPHEvent
517
  }
518
 
519
  /**
520
- * #! 6000
521
  * @internal
522
  * Hooks to the events deletion event
523
  */
524
- public static function watchDeleteEvents()
525
  {
526
  wpphLog(__METHOD__.'() triggered by hook.');
527
 
@@ -532,7 +565,7 @@ class WPPHEventWatcher extends WPPHEvent
532
  }
533
  else{
534
  add_action(WPPH_PLUGIN_DEL_EVENTS_CRON_TASK_NAME, array('WPPHEventWatcher','__deleteEvents'));
535
- if ( ! wp_next_scheduled(WPPH_PLUGIN_DEL_EVENTS_CRON_TASK_NAME) ) {
536
  wp_schedule_event( time(), 'daily', WPPH_PLUGIN_DEL_EVENTS_CRON_TASK_NAME );
537
  wpphLog(__METHOD__.'() scheduled by wp-cron.');
538
  }
@@ -540,7 +573,7 @@ class WPPHEventWatcher extends WPPHEvent
540
  }
541
 
542
  //@internal
543
- public static function __deleteEvents()
544
  {
545
  // check settings and delete the events (if any)
546
  $settings = WPPH::getPluginSettings();
@@ -598,15 +631,15 @@ class WPPHEventWatcher extends WPPHEvent
598
  }
599
  //@internal
600
  // delete by number
601
- private static function _deleteEventsGreaterThan($number = 10000)
602
  {
603
- if($number > 10000){ $number = 10000; }
604
  global $wpdb;
605
  $tableName = WPPHDatabase::getFullTableName('main');
606
  $count = $wpdb->get_var("SELECT COUNT(0) FROM $tableName");
607
  if(empty($count)){
608
  wpphLog(__METHOD__.'('.$number.') called. Ignored, there are no events in the database');
609
- return;
610
  }
611
  $keep = $number;
612
  if($count > $keep)
@@ -621,7 +654,7 @@ class WPPHEventWatcher extends WPPHEvent
621
  }
622
  else {
623
  wpphLog(__METHOD__.'('.$number.') called. Ignored, there are not enough events to trigger this action.');
624
- return;
625
  }
626
  }
627
 
@@ -629,13 +662,13 @@ class WPPHEventWatcher extends WPPHEvent
629
  * @internal
630
  * Fired on login failure
631
  */
632
- public static function watchLoginFailure($username='')
633
  {
634
  wpphLog(__METHOD__.'() triggered by hook.', array('username'=>$username));
635
  self::_addLogEvent(1002,0,WPPHUtil::getIP(),array($username), base64_encode($username));
636
  }
637
 
638
- public static function watchUserInfoUpdated($userID)
639
  {
640
  wpphLog(__METHOD__.'() triggered by hook.');
641
 
@@ -691,7 +724,6 @@ class WPPHEventWatcher extends WPPHEvent
691
  {
692
  wpphLog(__METHOD__.'() triggered by hook.');
693
 
694
- //$updatedRole = trim($_POST['role']);
695
  if(strcasecmp($initialUserRole, $updatedRole)==0){
696
  wpphLog(__METHOD__.'() Ignored. Role did not change.');
697
  return false;
@@ -773,7 +805,7 @@ class WPPHEventWatcher extends WPPHEvent
773
  * @param $userID the id of the user being deleted
774
  * Triggered when a user is deleted
775
  */
776
- public static function watchUserDeletion($userID)
777
  {
778
  wpphLog(__METHOD__.'() triggered by hook.');
779
 
@@ -795,7 +827,7 @@ class WPPHEventWatcher extends WPPHEvent
795
  }
796
 
797
  // # 5001
798
- public static function watchPluginActivate()
799
  {
800
  wpphLog(__METHOD__.'() triggered by hook.');
801
 
@@ -839,7 +871,7 @@ class WPPHEventWatcher extends WPPHEvent
839
  }
840
  }
841
  // # 5002
842
- public static function watchPluginDeactivate()
843
  {
844
  wpphLog(__METHOD__.'() triggered by hook.');
845
 
@@ -883,7 +915,7 @@ class WPPHEventWatcher extends WPPHEvent
883
  }
884
  }
885
  // # 5000
886
- public static function watchPluginInstall()
887
  {
888
  if(defined('WPPH_PLUGIN_INSTALLED_OK')){ return; }
889
  if(empty($_GET)) { return; }
@@ -913,7 +945,7 @@ class WPPHEventWatcher extends WPPHEvent
913
  }
914
  }
915
  // # 5003
916
- public static function watchPluginUninstall()
917
  {
918
  if(empty($_POST)) { return; }
919
  if(! isset($_POST['verify-delete'])) { return; }
@@ -937,18 +969,13 @@ class WPPHEventWatcher extends WPPHEvent
937
  }
938
  }
939
  // # 5004
940
- public static function watchPluginUpgrade()
941
  {
942
- wpphLog(__METHOD__.'() triggered by hook.',array(
943
- 'get' => $_GET,
944
- 'post' => $_POST
945
- ));
946
-
947
  $current_user = wp_get_current_user();
948
  $userID = $current_user->ID;
949
  $ip = WPPHUtil::getIP();
950
 
951
- //#! One by link
952
  if(!empty($_GET))
953
  {
954
  if(isset($_GET['action']) && !empty($_GET['action']))
@@ -999,21 +1026,28 @@ class WPPHEventWatcher extends WPPHEvent
999
  }
1000
 
1001
 
1002
- public static function watchBlogActivity($newStatus, $oldStatus, $post)
1003
  {
1004
- wpphLog(__FUNCTION__.'() triggered.');
1005
 
1006
-
1007
- wpphLog(__FUNCTION__.'. POST STATUS DATA', array(
1008
  '$oldStatus' => $oldStatus,
1009
  '$newStatus' => $newStatus,
1010
  '$post' => $post
1011
  ));
1012
 
1013
  // IGNORE STATES - so we skip generating multiple events
1014
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; }
1015
- if($post->post_type == 'revision') {return;}
1016
- if($newStatus == 'auto-draft' || ($oldStatus == 'new' && $newStatus=='auto-draft')) { return; }
 
 
 
 
 
 
 
 
1017
 
1018
  $postID = $post->ID;
1019
  $postTitle = $post->post_title;
@@ -1037,49 +1071,67 @@ class WPPHEventWatcher extends WPPHEvent
1037
  }
1038
 
1039
  if(empty($originalPostStatus)){
1040
- wpphLog('$_POST["_status"] not found. $originalPostStatus is EMPTY - nothing to do here.');
 
1041
  return;
1042
  }
1043
 
1044
- $postTypePost = $postTypePage = false;
1045
 
1046
  if($post->post_type == 'post'){ $postTypePost = true;}
1047
  elseif($post->post_type == 'page'){ $postTypePage = true;}
 
1048
 
1049
- if(!$postTypePost && !$postTypePage){
1050
- wpphLog('Ignored. Invalid post type');
1051
  return;
1052
  }
1053
 
 
 
 
1054
  global $wpdb;
1055
- //===============================================
1056
 
1057
- //## 2025 & 2026
1058
- self::watchPostVisibilityChange($oldStatus, $newStatus, $userID, $postTitle, $post, ($postTypePost) ? 2025 : 2026);
 
1059
 
1060
- //## 2027 & 2028
1061
  if(! in_array($oldStatus, array('new', 'auto-draft'))){
1062
- self::watchPostDateChange($userID, $postTitle, $post->post_date, ($postTypePost) ? 2027 : 2028);
 
1063
  }
1064
 
1065
- //## 2016
1066
- if($postTypePost){ self::watchPostCategoriesChange($post, $wpdb, $postTitle); }
 
1067
 
1068
- //## 2019 & 2020
1069
  $authorChanged = false;
1070
  if(isset($GLOBALS['WPPH_POST_AUTHOR_UPDATED_ID']))
1071
  {
1072
- if(wpph_postAuthorChanged((int)$GLOBALS['WPPH_POST_AUTHOR_UPDATED_ID'], $postID, $userID, $postTitle, ($postTypePost) ? 2019 : 2020)){
1073
- unset($GLOBALS['WPPH_POST_AUTHOR_UPDATED_ID']);
1074
- $GLOBALS['WPPH_POST_AUTHOR_UPDATED'] = true;
1075
- $authorChanged = true;
 
 
 
 
 
 
 
 
 
1076
  }
1077
  }
1078
 
 
1079
  if($newStatus != 'publish'){
1080
  if($originalPostStatus == 'auto-draft' || ($oldStatus=='new' && $newStatus=='inherit' && $postStatus=='inherit'))
1081
  {
1082
- wpph_newPostAsDraft($userID, $postID, $postTitle, ($postTypePost) ? 2000 : 2004);
 
1083
  }
1084
  }
1085
 
@@ -1087,17 +1139,18 @@ class WPPHEventWatcher extends WPPHEvent
1087
  $postModified = self::watchPostChanged($wpdb, $postID);
1088
  wpphLog('POST MODIFIED',array('modified'=> $postModified ? 'true' : 'false'));
1089
 
1090
- //## 2000 & 2003 & 2004 & 2007
1091
  if(($oldStatus == 'draft') && ($newStatus == 'draft' && $postStatus == 'draft'))
1092
  {
1093
  if($originalPostStatus == 'draft')
1094
  {
1095
  //## 2003 - draft post updated
1096
- if($postTypePost){
1097
  // only if 2016 || 2017 || 2019 were not triggered
1098
  if(isset($GLOBALS['WPPH_POST_CATEGORIES_UPDATED']) || isset($GLOBALS['WPPH_POST_URL_UPDATED']) || isset($GLOBALS['WPPH_POST_AUTHOR_UPDATED'])){}
1099
  else {
1100
- wpph_draftPostUpdated($userID, $postID, $postTitle, 2003);
 
1101
  $postModified = false;
1102
  }
1103
  }
@@ -1106,61 +1159,95 @@ class WPPHEventWatcher extends WPPHEvent
1106
  // only if 2018 || 2020 were not triggered
1107
  if(isset($GLOBALS['WPPH_PAGE_URL_UPDATED']) || isset($GLOBALS['WPPH_PAGE_AUTHOR_UPDATED'])){}
1108
  else {
1109
- wpph_draftPostUpdated($userID, $postID, $postTitle, 2007);
1110
  $postModified = false;
1111
  }
1112
  }
1113
  }
1114
  }
1115
 
1116
- //## 2001 & 2005 - new post/page published
1117
  elseif(in_array($oldStatus, array('draft','auto-draft','pending')) && $newStatus == 'publish' && $postStatus == 'publish')
1118
  {
1119
- wpph_newPostPublished($userID, $postTitle, $postUrl, ($postTypePost) ? 2001 : 2005);
1120
- return; // no need to process further
 
 
 
 
 
 
1121
  }
1122
 
1123
- //## 2021 & 2022 : published -> pending
1124
  elseif($oldStatus == 'publish' && $newStatus == 'pending' && $postStatus == 'pending')
1125
  {
1126
- wpph_postStatusChanged($postTitle, 'Published', 'Pending Review', $userID, ($postTypePost) ? 2021 : 2022);
 
 
 
 
 
 
1127
  }
1128
 
1129
- //## 2021 & 2022 : pending -> draft
1130
  elseif($oldStatus == 'pending' && $newStatus == 'draft' && $postStatus == 'draft')
1131
  {
1132
- wpph_postStatusChanged($postTitle, 'Pending Review', 'Draft', $userID, ($postTypePost) ? 2021 : 2022);
 
 
 
 
 
 
1133
  }
1134
 
1135
- //## 2021 & 2022 : draft -> pending
1136
  elseif($oldStatus == 'draft' && $newStatus == 'pending' && $postStatus == 'pending')
1137
  {
1138
- wpph_postStatusChanged($postTitle, 'Draft', 'Pending Review', $userID, ($postTypePost) ? 2021 : 2022);
 
 
 
 
 
 
1139
  }
1140
 
1141
- //## 2021 & 2022 : published -> draft
1142
  elseif($oldStatus == 'publish' && $newStatus == 'draft' && $postStatus == 'draft')
1143
  {
1144
- wpph_postStatusChanged($postTitle, 'Published', 'Draft', $userID, ($postTypePost) ? 2021 : 2022);
 
 
 
 
 
 
1145
  }
1146
 
1147
- //## 2002 & 2006 : published post/page updated
1148
  elseif($oldStatus == 'publish' && $newStatus == 'publish' && $postStatus == 'publish')
1149
  {
1150
- // CHECK IF POST URL MODIFIED
1151
- // ## step 1: see self::hookWatchPostStateBefore()
1152
- // ## step 2: trigger event
1153
- // trigger: 2017 - Changed the URL of the post %post_name% from %old_url% to %new_url%
1154
  if(isset($GLOBALS['WPPH_POST_NEW_URL']) || $postModified)
1155
  {
1156
- if(wpph_postUrlUpdated($GLOBALS['WPPH_POST_NEW_URL'], get_permalink($postID), $userID, $postTitle, ($postTypePost) ? 2017 : 2018))
1157
- {
1158
- unset($GLOBALS['WPPH_POST_NEW_URL']);
1159
- $GLOBALS['WPPH_POST_URL_UPDATED'] = $postTypePost;
1160
- $GLOBALS['WPPH_PAGE_URL_UPDATED'] = $postTypePage;
 
 
 
 
 
 
1161
  }
1162
  }
1163
- if($postTypePost)
 
1164
  {
1165
  if(isset($GLOBALS['WPPH_POST_CATEGORIES_UPDATED']) || isset($GLOBALS['WPPH_POST_URL_UPDATED'])
1166
  || isset($GLOBALS['WPPH_POST_AUTHOR_UPDATED']) || isset($GLOBALS['WPPH_POST_PROTECTED_TRANSITION'])
@@ -1168,7 +1255,7 @@ class WPPHEventWatcher extends WPPHEvent
1168
  // Modified the published blog post %post_title%. Blog post URL is %post_URL%
1169
  else {
1170
  if(! $authorChanged){
1171
- wpph_publishedPostUpdated($userID, $postTitle, $postUrl, 2002);
1172
  }
1173
  }
1174
  }
@@ -1180,49 +1267,64 @@ class WPPHEventWatcher extends WPPHEvent
1180
  // Modified the published page %page_title%. Page URL is %URL%
1181
  else {
1182
  if(! $authorChanged){
1183
- wpph_publishedPostUpdated($userID, $postTitle, $postUrl, 2006);
1184
  }
1185
  }
1186
  }
 
1187
  return;
1188
  }
1189
 
1190
  // if post name changed - we probably have a URL change here
 
1191
  if($postModified){
1192
  if( isset($GLOBALS['WPPH_PAGE_AUTHOR_UPDATED']) || isset($GLOBALS['WPPH_PAGE_AUTHOR_UPDATED'])
1193
  || isset($GLOBALS['WPPH_POST_CATEGORIES_UPDATED'])|| isset($GLOBALS['WPPH_POST_DATE_CHANGED'])){}
1194
  else {
1195
- wpph_draftPostUpdated($userID, $postID, $postTitle, ($postTypePost) ? 2003 : 2007);
 
 
 
 
 
 
1196
  }
1197
  }
1198
  }
1199
 
1200
- public static function watchTrash($postID)
1201
  {
1202
  wpphLog(__METHOD__.'() triggered by hook.');
1203
- $hPid = md5($postID);
1204
  // get info for the currently logged in user
1205
  $current_user = wp_get_current_user();
1206
  global $wpdb;
1207
  $postInfo = $wpdb->get_row("SELECT post_title, post_type FROM ".$wpdb->posts." WHERE ID = ".$postID);
1208
  $postTitle = $postInfo->post_title;
1209
  $postType = $postInfo->post_type;
1210
- if($postType == 'post')
1211
- {
1212
- // Deleted the blog post %Title%. Blog post ID is %ID%
1213
- self::_addLogEvent(2008, $current_user->ID, WPPHUtil::getIP(), array($postTitle,$postID));
1214
- wpphLog('Blog post deleted.', array('title'=>$postTitle, 'id'=>$postID));
 
 
1215
  }
1216
- elseif($postType == 'page')
1217
- {
1218
- // Deleted the page %Title%. Page ID is %ID%
1219
- self::_addLogEvent(2009, $current_user->ID, WPPHUtil::getIP(), array($postTitle,$postID));
1220
- wpphLog('Page deleted.', array('title'=>$postTitle, 'id'=>$postID));
 
 
 
 
 
 
1221
  }
1222
  }
1223
 
1224
  // 2010
1225
- public static function watchFileUploaded($attachmentID)
1226
  {
1227
  global $wpdb;
1228
  // get info for the currently logged in user
@@ -1236,7 +1338,7 @@ class WPPHEventWatcher extends WPPHEvent
1236
  $GLOBALS['WPPH_PLUGIN_FILE_UPLOADED_IGNORE_DELETE'] = true;
1237
  }
1238
  // 2011
1239
- public static function watchFileUploadedDeleted($attachmentID)
1240
  {
1241
  if(isset($GLOBALS['WPPH_PLUGIN_FILE_UPLOADED_IGNORE_DELETE'])){
1242
  // return, because if this variable is set this means this action is
@@ -1252,50 +1354,66 @@ class WPPHEventWatcher extends WPPHEvent
1252
  wpphLog('File deleted.', array('title'=>$rowData->post_title, 'url'=>dirname($rowData->guid)));
1253
  }
1254
 
1255
- // 2012, 2013
1256
- public static function watchFileDeletion($postID)
1257
  {
1258
  global $wpdb;
 
1259
  $postInfo = $wpdb->get_row("SELECT post_title, post_type FROM ".$wpdb->posts." WHERE ID = ".$postID);
1260
  $postTitle = $postInfo->post_title;
1261
  $postType = $postInfo->post_type;
1262
- // get info for the currently logged in user
1263
- $userID = wp_get_current_user()->ID;
1264
- if('post' == $postType)
1265
- {
1266
- self::_addLogEvent(2012, $userID, WPPHUtil::getIP(), array($postTitle));
1267
- wpphLog('Post trashed.', array('name'=>$postTitle));
 
1268
  }
1269
- elseif ('page' == $postType)
1270
- {
1271
- self::_addLogEvent(2013, $userID, WPPHUtil::getIP(), array($postTitle));
1272
- wpphLog('Page trashed.', array('name'=>$postTitle));
 
 
 
 
 
 
1273
  }
1274
  }
1275
 
1276
- // 2014, 2015
1277
- public static function watchTrashUndo($postID)
1278
  {
1279
  global $wpdb;
 
1280
  $postInfo = $wpdb->get_row("SELECT post_title, post_type FROM ".$wpdb->posts." WHERE ID = ".$postID);
1281
  $postTitle = $postInfo->post_title;
1282
  $postType = $postInfo->post_type;
1283
- // get info for the currently logged in user
1284
- $userID = wp_get_current_user()->ID;
1285
- if('post' == $postType)
1286
- {
1287
- self::_addLogEvent(2014, $userID, WPPHUtil::getIP(), array($postTitle));
1288
- wpphLog('Post restored from trash.', array('name'=>$postTitle));
 
1289
  }
1290
- elseif ('page' == $postType)
1291
- {
1292
- self::_addLogEvent(2015, $userID, WPPHUtil::getIP(), array($postTitle));
1293
- wpphLog('Page restored from trash.', array('name'=>$postTitle));
 
 
 
 
 
 
1294
  }
1295
  }
1296
 
1297
  // 3000 - Theme activated
1298
- public static function watchThemeChange($themeName)
1299
  {
1300
  // get info for the currently logged in user
1301
  $current_user = wp_get_current_user();
@@ -1305,7 +1423,7 @@ class WPPHEventWatcher extends WPPHEvent
1305
  }
1306
 
1307
  // 2023 - category created
1308
- public static function watchCategoryAdd(array $postData)
1309
  {
1310
  wpphLog(__METHOD__.'() triggered by hook.');
1311
 
@@ -1336,7 +1454,7 @@ class WPPHEventWatcher extends WPPHEvent
1336
  }
1337
 
1338
  // 2024 - category deleted
1339
- public static function watchCategoryDelete(array $postData)
1340
  {
1341
  wpphLog(__METHOD__.'() triggered by hook.');
1342
 
@@ -1375,10 +1493,10 @@ class WPPHEventWatcher extends WPPHEvent
1375
  }
1376
  }
1377
 
1378
- // #! 2025, 2026
1379
- public static function watchPostVisibilityChange($oldStatus, $newStatus, $userID, $postTitle, $post, $event)
1380
  {
1381
- wpphLog(__FUNCTION__.'() triggered.');
1382
 
1383
  global $wpdb;
1384
 
@@ -1391,16 +1509,22 @@ class WPPHEventWatcher extends WPPHEvent
1391
  // pwd protected -> public
1392
  if($oldStatus == 'publish' && $newStatus == 'publish')
1393
  {
 
 
 
 
 
 
1394
  // pwd protected -> public
1395
  if(empty($crtPostPassword) && !empty($oldPostPassword)){
1396
- $from = 'Password Protected';
1397
- $to = 'Public';
1398
  }
1399
  // public -> pwd protected
1400
  else {
1401
  if(! empty($crtPostPassword)){
1402
- $from = 'Public';
1403
- $to = 'Password Protected';
1404
  }
1405
  }
1406
  }
@@ -1410,14 +1534,14 @@ class WPPHEventWatcher extends WPPHEvent
1410
  {
1411
  // public -> private
1412
  if(empty($crtPostPassword) && empty($oldPostPassword)){
1413
- $from = 'Public';
1414
- $to = 'Private';
1415
  }
1416
  // pwd protected -> private
1417
  else {
1418
  if(!empty($oldPostPassword)){
1419
- $from = 'Password Protected';
1420
- $to = 'Private';
1421
  }
1422
  }
1423
  }
@@ -1427,14 +1551,14 @@ class WPPHEventWatcher extends WPPHEvent
1427
  {
1428
  // private -> public
1429
  if(empty($oldPostPassword) && empty($crtPostPassword)){
1430
- $from = 'Private';
1431
- $to = 'Public';
1432
  }
1433
  // private -> pwd protected
1434
  else {
1435
  if(empty($oldPostPassword) && !empty($crtPostPassword)){
1436
- $from = 'Private';
1437
- $to = 'Password Protected';
1438
  }
1439
  }
1440
  }
@@ -1444,18 +1568,22 @@ class WPPHEventWatcher extends WPPHEvent
1444
  }
1445
 
1446
  $GLOBALS['WPPH_PREVENT_BUBBLE'] = true;
1447
- wpph_postVisibilityChanged($userID, $postTitle, $from, $to, $event);
1448
  }
1449
 
1450
- //#! 2027 & 2028
1451
- public static function watchPostDateChange($userID, $postTitle, $postCurrentDate, $event)
1452
  {
1453
- wpphLog(__FUNCTION__.'() triggered.');
1454
 
1455
  if($GLOBALS['WPPH_POST_IS_NEW']){
1456
  wpphLog('Nothing to do. The post is brand new.');
1457
  return;
1458
  }
 
 
 
 
1459
 
1460
  $t1 = strtotime($GLOBALS['WPPH_POST_OLD_DATE']);
1461
  $t2 = strtotime($postCurrentDate);
@@ -1464,6 +1592,10 @@ class WPPHEventWatcher extends WPPHEvent
1464
  wpphLog('No change.');
1465
  return;
1466
  }
 
 
 
 
1467
 
1468
  $format = get_option('date_format');
1469
  $from = date($format, $t1);
@@ -1476,12 +1608,12 @@ class WPPHEventWatcher extends WPPHEvent
1476
  'from' => $from . '('.$t1.')',
1477
  'to' => $to . '('.$t2.')'
1478
  ));
1479
- wpph_postDateChanged($userID, $postTitle, $from, $to, $event);
1480
  }
1481
 
1482
- public static function watchPostCategoriesChange($post, $wpdb, $postTitle)
1483
  {
1484
- wpphLog(__FUNCTION__.'() triggered.');
1485
 
1486
  if(isset($GLOBALS['WPPH_POST_OLD_CATEGORIES']))
1487
  {
@@ -1526,14 +1658,14 @@ class WPPHEventWatcher extends WPPHEvent
1526
  else {
1527
  $c1 = implode(', ', $categories_1);
1528
  $c2 = implode(', ', $categories_2);
1529
- wpph_postCategoriesUpdated(wp_get_current_user()->ID, $postTitle, $c1, $c2);
1530
  $GLOBALS['WPPH_POST_CATEGORIES_UPDATED'] = true;
1531
  }
1532
  }
1533
  else {
1534
  $c1 = implode(', ', $categories_1);
1535
  $c2 = implode(', ', $categories_2);
1536
- wpph_postCategoriesUpdated(wp_get_current_user()->ID, $postTitle, $c1, $c2);
1537
  $GLOBALS['WPPH_POST_CATEGORIES_UPDATED'] = true;
1538
  }
1539
  }
@@ -1542,16 +1674,16 @@ class WPPHEventWatcher extends WPPHEvent
1542
 
1543
  // 2017 & 2018 - Post/page modified
1544
  // convenience method to trigger a post/page modified event
1545
- public static function watchPostChanged($wpdb, $postID)
1546
  {
1547
- wpphLog(__FUNCTION__.'() triggered.');
1548
 
1549
  if(isset($GLOBALS['WPPH_POST_OLD_NAME'])){
1550
  // get the current post name and compare
1551
- $post_name = $wpdb->get_var("SELECT post_name, post_password, post_date FROM ".$wpdb->posts." WHERE ID = $postID");
1552
- if($GLOBALS['WPPH_POST_OLD_NAME'] != $post_name){
1553
- return true;
1554
- }
1555
  }
1556
  return false;
1557
  }
8
  * Retrieve the list of events
9
  * @return array
10
  */
11
+ static function listEvents()
12
  {
13
  return array(
14
  // 1xxx - Login/Logout events
15
+ array( 'id' => 1000, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Successfully logged in.',WPPH_PLUGIN_TEXT_DOMAIN)),
16
+ array( 'id' => 1001, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Successfully logged out.',WPPH_PLUGIN_TEXT_DOMAIN)),
17
+ array( 'id' => 1002, 'category' => WPPH_E_WARNING_TEXT, 'text' => __('Failed login detected using <strong>%s</strong> as username.',WPPH_PLUGIN_TEXT_DOMAIN)),
18
 
19
  // 2xxx - User activity events
20
  // Created a new blog post called %Post Title%. Blog post ID is %ID%
21
+ array( 'id' => 2000, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Created a new draft blog post called <strong>%s</strong>. Blog post ID is <strong>%d</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
22
  // Published a blog post called %Post_Title%. Blog post URL is %Post_URL%
23
+ array( 'id' => 2001, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Published a blog post called <strong>%s</strong>. Blog post URL is <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
24
  // Modified the published blog post %post_title%. Blog post URL is %post_URL%
25
+ array( 'id' => 2002, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Modified the published blog post <strong>%s</strong>. Blog post URL is <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
26
  // Modified the draft blog post %post_title%. Blog post ID is %ID%
27
+ array( 'id' => 2003, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Modified the draft blog post <strong>%s</strong>. Blog post ID is <strong>%d</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
28
 
29
  // Created a new page called %page_title%. Page ID is %ID%
30
+ array( 'id' => 2004, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Created a new draft page called <strong>%s</strong>. Page ID is <strong>%d</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
31
  // Published a page called %page_title%. Page URL is %URL%
32
+ array( 'id' => 2005, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Published a page called <strong>%s</strong>. Page URL is <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
33
  // Modified the published page %page_title%. Page URL is %URL%
34
+ array( 'id' => 2006, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Modified the published page <strong>%s</strong>. Page URL is <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
35
  // Modified the draft page %page_title%. Page ID is %ID%
36
+ array( 'id' => 2007, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Modified the draft page <strong>%s</strong>. Page ID is <strong>%d</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
37
  // Deleted the post %Title%. Blog post ID is %ID%
38
+ array( 'id' => 2008, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('Deleted the post <strong>%s</strong>. Blog post ID is <strong>%d</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
39
  // Deleted the page %Title%. Page ID is %ID%
40
+ array( 'id' => 2009, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('Deleted the page <strong>%s</strong>. Page ID is <strong>%d</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
41
 
42
  // Uploaded the file %file name$ in %file location%
43
+ array( 'id' => 2010, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Uploaded the file <strong>%s</strong> in <strong>%s</strong>/.',WPPH_PLUGIN_TEXT_DOMAIN)),
44
  // Deleted file %file name$ from %file_location%
45
+ array( 'id' => 2011, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('Deleted the file <strong>%s</strong> from <strong>%s</strong>/.',WPPH_PLUGIN_TEXT_DOMAIN)),
46
  // 2012 - trashed draft post
47
+ array( 'id' => 2012, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('Moved the post <strong>%s</strong> to trash.',WPPH_PLUGIN_TEXT_DOMAIN)),
48
  // 2013 - trashed published post
49
+ array( 'id' => 2013, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('Moved the page <strong>%s</strong> to trash.',WPPH_PLUGIN_TEXT_DOMAIN)),
50
  // 2014 - untrashed post
51
+ array( 'id' => 2014, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('Post <strong>%s</strong> has been restored from trash.',WPPH_PLUGIN_TEXT_DOMAIN)),
52
  // 2015 - untrashed page
53
+ array( 'id' => 2015, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('Page <strong>%s</strong> has been restored from trash.',WPPH_PLUGIN_TEXT_DOMAIN)),
54
  // 2016 - Post category changed
55
+ array( 'id' => 2016, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Changed the category(ies) of the post <strong>%s</strong> from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
56
  // 2017 - Changed the URL of the post %post_name% from %old_url% to %new_url%
57
+ array( 'id' => 2017, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Changed the URL of the post <strong>%s</strong> from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
58
  // 2018 - Changed the URL of the page %page_name% from %old_url% to %new_url%
59
+ array( 'id' => 2018, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Changed the URL of the page <strong>%s</strong> from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
60
  // 2019 - Changed the author of %post_name% post from %old_author% to %new_author%
61
+ array( 'id' => 2019, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Changed the author of <strong>%s</strong> post from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
62
  // 2020 - Changed the author of %page_name% page from %old_author% to %new_author%
63
+ array( 'id' => 2020, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Changed the author of <strong>%s</strong> page from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
64
  // 2021 - %postName% from %oldStatus% to %newStatus%
65
+ array( 'id' => 2021, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Changed the status of <strong>%s</strong> post from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
66
  // 2022 - page from published to draft
67
+ array( 'id' => 2022, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Changed the status of <strong>%s</strong> page from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
68
  // 2023 - added new category
69
+ array( 'id' => 2023, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Created a new category called <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
70
  // 2024 - deleted category
71
+ array( 'id' => 2024, 'category' => WPPH_E_WARNING_TEXT, 'text' => __('Deleted the <strong>%s</strong> category.',WPPH_PLUGIN_TEXT_DOMAIN)),
72
  // 2025 - Changed the visibility of %post_name% blog post from %old_visibility% to %new_visibility%
73
+ array( 'id' => 2025, 'category' => WPPH_E_WARNING_TEXT, 'text' => __('Changed the visibility of <strong>%s</strong> blog post from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
74
  // 2026 - Changed the visibility of %page_name% page from %old_visibility% to %new_visibility%
75
+ array( 'id' => 2026, 'category' => WPPH_E_WARNING_TEXT, 'text' => __('Changed the visibility of <strong>%s</strong> page from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
76
  // 2027 - Changed the date of %post_name% blog post from %old_date% to %new_date%
77
+ array( 'id' => 2027, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Changed the date of <strong>%s</strong> blog post from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
78
  // 2028 - Changed the date of %post_name% page from %old_date% to %new_date%
79
+ array( 'id' => 2028, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Changed the date of <strong>%s</strong> page from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
80
+
81
+ //[[ Custom Post Types
82
+ // 2029 Created a new custom post called %Post Title%. Post ID is %ID%
83
+ array( 'id' => 2029, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Created a new draft custom post <strong>%s</strong> of type <strong>%s</strong>. Post ID is <strong>%d</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
84
+ // 2030 Published a custom post called %Post_Title%. Post URL is %Post_URL%
85
+ array( 'id' => 2030, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Published a custom post <strong>%s</strong> of type <strong>%s</strong>. Post URL is <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
86
+ // 2031 Modified the published custom post %post_title%. Post URL is %post_URL%
87
+ array( 'id' => 2031, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Modified the custom post <strong>%s</strong> of type <strong>%s</strong>. Post URL is <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
88
+ // 2032 Modified the draft custom post %post_title%. Post ID is %ID%
89
+ array( 'id' => 2032, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Modified the draft custom post <strong>%s</strong> of type <strong>%s</strong>. Post ID is <strong>%d</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
90
+ // 2033 Deleted the custom post %Title%. Post ID is %ID%
91
+ array( 'id' => 2033, 'category' => WPPH_E_WARNING_TEXT, 'text' => __('Deleted custom post <strong>%s</strong> of type <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
92
+ // 2034 - trashed draft custom post
93
+ array( 'id' => 2034, 'category' => WPPH_E_WARNING_TEXT, 'text' => __('Moved the custom post <strong>%s</strong> to trash. Post type is <strong>%s</strong>',WPPH_PLUGIN_TEXT_DOMAIN)),
94
+ // 2035 - untrashed custom post
95
+ array( 'id' => 2035, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('Custom post <strong>%s</strong> of type <strong>%s</strong> has been restored from trash.',WPPH_PLUGIN_TEXT_DOMAIN)),
96
+ // 2036 - Custom post category changed
97
+ array( 'id' => 2036, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Changed the category(ies) of custom post <strong>%s</strong> of type <strong>%s</strong> from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
98
+ // 2037 - Changed the URL of the custom post %post_name% from %old_url% to %new_url%
99
+ array( 'id' => 2037, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Changed the URL of the custom post <strong>%s</strong> of type <strong>%s</strong> from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
100
+ // 2038 - Changed the author of %post_name% custom post from %old_author% to %new_author%
101
+ array( 'id' => 2038, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Changed the author of custom post <strong>%s</strong> of type <strong>%s</strong> from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
102
+ // 2039 - Changed the status of %postName% custom post from %oldStatus% to %newStatus%
103
+ array( 'id' => 2039, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Changed the status of custom post <strong>%s</strong> of type <strong>%s</strong> from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
104
+ // 2040 - Changed the visibility of %post_name% custom post from %old_visibility% to %new_visibility%
105
+ array( 'id' => 2040, 'category' => WPPH_E_WARNING_TEXT, 'text' => __('Changed the visibility of custom post <strong>%s</strong> of type <strong>%s</strong> from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
106
+ // 2041 - Changed the date of %post_name% custom post from %old_date% to %new_date%
107
+ array( 'id' => 2041, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Changed the date of custom post <strong>%s</strong> of type <strong>%s</strong> from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
108
 
109
  // 3xxx - Themes management
110
  // Activated the theme %themeName%
111
+ array( 'id' => 3000, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Activated the theme <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
112
 
113
  // 4xxx - User profile events
114
+ array( 'id' => 4000, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('A new user with the username <strong>%s</strong> has registered with the role of <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
115
+ array( 'id' => 4001, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('<strong>%s</strong> created a new user <strong>%s</strong> with the role of <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
116
+ array( 'id' => 4002, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('The role of user <strong>%s</strong> was changed from <strong>%s</strong> to <strong>%s</strong> by <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
117
+ array( 'id' => 4003, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('Changed the account password.',WPPH_PLUGIN_TEXT_DOMAIN)),
118
+ array( 'id' => 4004, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('<strong>%s</strong> changed the password for user <strong>%s</strong> with the role of <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
119
  // Changed the email address from %old_email% to %new_email%
120
+ array( 'id' => 4005, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Changed the email address from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
121
  // %user_making_change% changed the email address of user %user% from %old_email% to %new_email%
122
+ array( 'id' => 4006, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('<strong>%s</strong> changed the email address of user <strong>%s</strong> from <strong>%s</strong> to <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
123
  // User %user% with the role of %role% was deleted by %user_deleting%
124
+ array( 'id' => 4007, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('User <strong>%s</strong> with the role of <strong>%s</strong> was deleted by <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
125
 
126
  // 5xxx - Plugin management
127
  // # 5000 Installed the plugin %name%.
128
+ array( 'id' => 5000, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('Installed the plugin <strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
129
  // Activated the plugin %plugin_name% installed in %plugin_directory%
130
+ array( 'id' => 5001, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('Activated the plugin <strong>%s</strong> installed in /<strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
131
  // Deactivated the plugin %plugin_name% installed in %plugin_directory%
132
+ array( 'id' => 5002, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('Deactivated the plugin <strong>%s</strong> installed in /<strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
133
  // # 5003 Uninstalled the plugin %plugin_name% which was installed in %path%
134
+ array( 'id' => 5003, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('Uninstalled the plugin <strong>%s</strong> which was installed in /<strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
135
  // # 5004 Upgraded the plugin %name% installed in %path%
136
+ array( 'id' => 5004, 'category' => WPPH_E_WARNING_TEXT, 'text' => __('Upgraded the plugin <strong>%s</strong> installed in /<strong>%s</strong>.',WPPH_PLUGIN_TEXT_DOMAIN)),
137
 
138
  // 6xxx - System events
139
  // #6000 Events automatically deleted by system.
140
+ array( 'id' => 6000, 'category' => WPPH_E_NOTICE_TEXT, 'text' => __('Events automatically deleted by system.',WPPH_PLUGIN_TEXT_DOMAIN)),
141
  // #6001 - <strong>%s</strong> the option Anyone can register
142
+ array( 'id' => 6001, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('<strong>%s</strong> the option Anyone can register',WPPH_PLUGIN_TEXT_DOMAIN)),
143
  // #6002 - Changed the New User Default Role from <strong>%s</strong> to <strong>%s</strong>
144
+ array( 'id' => 6002, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('Changed the New User Default Role from <strong>%s</strong> to <strong>%s</strong>',WPPH_PLUGIN_TEXT_DOMAIN)),
145
  // #6003 - Changed the WordPress administrator notifications email address from %old_email% to %new_mail%
146
+ array( 'id' => 6003, 'category' => WPPH_E_HIGH_TEXT, 'text' => __('Changed the WordPress administrator notifications email address from <strong>%s</strong> to <strong>%s</strong>',WPPH_PLUGIN_TEXT_DOMAIN)),
147
  );
148
  }
149
 
151
  // 1xxx - Login/Logout events
152
 
153
  // 1000
154
+ static function hookLoginEvent() { add_action('wp_login', array('WPPHEventWatcher', 'watchEventLogin'), 10, 2); }
155
  // 1001
156
+ static function hookLogoutEvent() { add_action('wp_logout', array('WPPHEventWatcher', 'watchEventLogout')); }
157
  // 1002
158
+ static function hookLoginFailure() { add_action('wp_login_failed', array('WPPHEventWatcher', 'watchLoginFailure')); }
159
 
160
 
161
  // 2xxx - User activity events
162
 
163
  // 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2021, 2022
164
+ static function hookWatchBlogActivity() { add_action('transition_post_status', array('WPPHEventWatcher', 'watchBlogActivity'), 10, 3); }
165
  // 2008, 2009
166
+ static function hookFileDeletion() { add_action('delete_post', array('WPPHEventWatcher', 'watchTrash'), 10, 1); }
167
  // 2010
168
+ static function hookFileUploaded() { add_action('add_attachment', array('WPPHEventWatcher', 'watchFileUploaded')); }
169
  // 2011
170
+ static function hookFileUploadedDeleted() { add_action('delete_attachment', array('WPPHEventWatcher', 'watchFileUploadedDeleted')); }
171
  // 2012
172
+ static function hookTrashPost() {
173
  if(defined('EMPTY_TRASH_DAYS') && (EMPTY_TRASH_DAYS == 0)){
174
  add_action('delete_post', array('WPPHEventWatcher', 'watchTrash'), 10, 1);
175
  }
176
+ else { add_action('wp_trash_post', array('WPPHEventWatcher', 'watchFileDeletion')); }
177
  }
178
  // 2013
179
+ static function hookTrashPage() {
180
  if(defined('EMPTY_TRASH_DAYS') && (EMPTY_TRASH_DAYS == 0)){
181
  add_action('delete_post', array('WPPHEventWatcher', 'watchTrash'), 10, 1);
182
  }
183
+ else { add_action('wp_trash_page', array('WPPHEventWatcher', 'watchFileDeletion')); }
184
  }
185
  //2014
186
+ static function hookUntrashedPosts() { add_action('untrash_post', array('WPPHEventWatcher', 'watchTrashUndo')); }
187
  // 2015
188
+ static function hookUntrashedPages() { add_action('untrash_page', array('WPPHEventWatcher', 'watchTrashUndo')); }
189
  // 2016, 2017
190
+ static function hookWatchPostStateBefore()
191
  {
192
+ if(! isset($_POST)){ wpphLog(__METHOD__.' not $_POST method'); return; }
193
+ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { wpphLog(__METHOD__.' doing autosave'); return; }
194
+ if(isset($_POST['action']) && $_POST['action'] == 'autosave') { wpphLog(__METHOD__.' $_POST action == autosave'); return; }
195
 
196
  if(isset($GLOBALS['WPPH_DEFAULT_EDITOR_ENABLED']) || isset($GLOBALS['WPPH_SCREEN_EDITOR_ENABLED']))
197
  {
200
  global $wpdb;
201
  $pid = $_POST['post_ID'];
202
 
203
+ $postType = (empty($_POST['post_type']) ? '' : $_POST['post_type']);
204
+ if(! WPPHPost::validatePostType($postType)){
205
+ wpphLog('Invalid post type.', array('post-type'=>$postType));
206
+ return;
207
+ }
208
+
209
+ $_postType = $postType;
210
+ if(! in_array($postType, array('post','page'))){
211
+ $_postType = 'custom';
212
+ }
213
+ do_action('wpph_set_post_type',$postType);
214
+
215
  /*
216
  * CHECK IF POST/PAGE AUTHOR UPDATED; 2019
217
  * ## step 1: this is where we check if author has been changed
218
+ * ## step 2: @see WPPHPost::managePostAuthorUpdateQuickEditForm()
219
  */
220
  if(! empty($_POST['post_author']))
221
  {
222
  $GLOBALS['WPPH_POST_AUTHOR_UPDATED_ID'] = intval($_POST['post_author']);
223
  if(isset($GLOBALS['WPPH_SCREEN_EDITOR_ENABLED'])){
224
  // trigger hook manually
225
+ add_filter('wp_insert_post_data', array('WPPHPost','managePostAuthorUpdateQuickEditForm'), '1', 2);
 
 
226
  }
227
  }
228
 
229
+ // check if post exists & get aggregated data
230
+ $query = "SELECT ID, post_title, post_name, post_password, post_date FROM ".$wpdb->posts." WHERE ID = ".$pid;
231
+ $result = $wpdb->get_row($query);
232
+ $postExists = (empty($result->ID) ? false : true);
233
+ $GLOBALS['WPPH_POST_EXISTS'] = $postExists;
234
+ $GLOBALS['WPPH_POST_PWD_PROTECTED'] = (empty($result->post_password) ? false : true);
 
235
 
236
  // if blog post
237
+ if($postType == 'post' || $_postType == 'custom')
238
  {
239
  // before further checks, we have to make sure this post isn't new
240
+ if(! $postExists){
241
  return;
242
  }
243
 
244
+ // retrieve the old post pwd to help us detect the posts' visibility transition state
245
+ $GLOBALS['WPPH_OLD_POST_PASSWORD'] = $result->post_password;
246
+ // check if post date has been changed
247
+ $GLOBALS['WPPH_POST_OLD_DATE'] = $result->post_date;
248
+ // Get the post name so we'll know if URL was updated
249
+ $GLOBALS['WPPH_POST_OLD_NAME'] = (empty($result->post_name) ? $result->post_title : $result->post_name);
 
 
 
 
250
  // CHECK IF POST CATEGORY UPDATED; 2016
251
  $GLOBALS['WPPH_POST_OLD_CATEGORIES'] = wp_get_post_categories($pid);
 
252
  /*
253
  * CHECK IF POST URL UPDATED; 2017
254
  * ## step 1: this is where we retrieve the new URL
257
  $GLOBALS['WPPH_POST_NEW_URL'] = get_permalink($pid);
258
  }
259
  // if page
260
+ elseif($postType == 'page')
261
  {
262
+ if($postExists)
263
  {
264
  // get the page's password if any (to trigger the 2026 event)
265
  // retrieve the old post pwd to help us detect the posts' visibility transition state
267
  // check if post date has been changed
268
  $GLOBALS['WPPH_POST_OLD_DATE'] = $result->post_date;
269
  // Get the post name so we'll know if URL was updated
270
+ $GLOBALS['WPPH_POST_OLD_NAME'] = (empty($result->post_name) ? $result->post_title : $result->post_name);
271
  }
272
 
 
273
  /*
274
+ * CHECK IF PAGE URL UPDATED; 2018
275
+ * ## step 1: this is where we retrieve the new URL
276
+ * ## step 2: @see WPPHEventWatcher::watchBlogActivity()
277
+ */
278
  $GLOBALS['WPPH_POST_NEW_URL'] = get_permalink($pid);
279
  }
280
  }
281
  }
282
 
283
  // 2023
284
+ static function hookWatchCategoryAdd() { WPPHEventWatcher::watchCategoryAdd($_POST); }
285
  // 2024
286
+ static function hookWatchCategoryDelete() { WPPHEventWatcher::watchCategoryDelete($_POST); }
287
 
288
  // 3xxx - Themes management
289
 
290
  // 3000
291
+ static function hookThemeChange() { add_action('switch_theme', array('WPPHEventWatcher', 'watchThemeChange'));}
292
 
293
 
294
  // 4xxx - User profile events
295
 
296
  // 4000, 4001
297
+ static function hookUserRegisterEvent() { add_action('user_register', array('WPPHEventWatcher', 'watchEventUserRegister')); }
298
  // 4002
299
+ static function hookUserRoleUpdated() {
300
  add_action('edit_user_profile_update', array('WPPHEventWatcher', 'watchUserInfoUpdated'));
301
  add_action('personal_options_update', array('WPPHEventWatcher', 'watchUserInfoUpdated'));
302
  }
303
  // 4003, 4004
304
+ static function hookUserPasswordUpdated() {
305
  add_action('edit_user_profile_update', array('WPPHEventWatcher', 'watchUserInfoUpdated'));
306
  add_action('personal_options_update', array('WPPHEventWatcher', 'watchUserInfoUpdated'));
307
  }
308
  // 4005, 4006
309
+ static function hookUserEmailUpdated() {
310
  add_action('edit_user_profile_update', array('WPPHEventWatcher', 'watchUserInfoUpdated'));
311
  add_action('personal_options_update', array('WPPHEventWatcher', 'watchUserInfoUpdated'));
312
  }
313
  // 4007
314
+ static function hookUserDeletion() { add_action( 'delete_user', array('WPPHEventWatcher', 'watchUserDeletion') ); }
315
 
316
 
317
  // 5xxx - Plugin management
318
 
319
  // 5000, 5001, 5002, 5003, 5004
320
+ static function hookWatchPluginActivity() {
321
  @include_once(ABSPATH.'wp-admin/includes/plugin.php');
322
  WPPHEventWatcher::watchPluginInstall(); // 5000
323
  WPPHEventWatcher::watchPluginActivate(); // 5001
330
  // 6xxx - System events
331
 
332
  // 6000
333
+ static function hookEventsDeletion() { add_action('init', array('WPPHEventWatcher', 'watchDeleteEvents')); }
334
 
335
  // 6001, 6002
336
+ static function hookCheckWpGeneralSettings(){
337
  if(isset($_POST))
338
  {
339
  $wpphOptData = get_option(WPPH_USERS_CAN_REGISTER_OPT_NAME);
344
  if(isset($_POST['users_can_register'])){
345
  // on
346
  if(false === $wpphOptData || 0 == $wpphOptData){
347
+ self::_addLogEvent(6001, wp_get_current_user()->ID, WPPHUtil::getIP(), array(__('Enabled')));
348
  update_option(WPPH_USERS_CAN_REGISTER_OPT_NAME,1);
349
  }
350
  }
351
  else {
352
  // off
353
  if(false === $wpphOptData || 1 == $wpphOptData){
354
+ self::_addLogEvent(6001, wp_get_current_user()->ID, WPPHUtil::getIP(), array(__('Disabled')));
355
  update_option('wpph_users_can_register',0);
356
  }
357
  }
398
  * @param string $failedLoginUserName The name of the user used for the failed login
399
  * @return bool
400
  */
401
+ static function _addLogEvent($eventID = 1000, $userID = 0, $userIP = '', $eventData = array(), $failedLoginUserName='')
402
  {
403
+ if(! wpph_isEventEnabled($eventID)){
404
+ wpphLog('Event '.$eventID.' is not enabled. Ignoring request.');
405
+ return true;
406
+ }
407
+
408
  if(empty($userIP)){ $userIP = WPPHUtil::getIP(); }
409
  $tableName = WPPHDB::getFullTableName('MAIN');
410
  $eventData = base64_encode(serialize($eventData));
434
  * ============================================
435
  */
436
 
437
+ static function getEventDetailsData($eventID)
438
  {
439
  global $wpdb;
440
  $table = WPPHDatabase::getFullTableName('events');
448
  * @param string $sort ASC or DESC
449
  * @return mixed
450
  */
451
+ static function getEvents($orderBy='EventNumber', $sort = 'DESC', $limit = array(0,0))
452
  {
453
  $validArgsSort = array('ASC', 'DESC');
454
  $validCnTableLogDetails = array('EventID', 'EventType');
505
  * @param $user_login
506
  * @param WP_User $user
507
  */
508
+ static function watchEventLogin($user_login, $user)
509
  {
510
  wpphLog(__METHOD__.'() triggered by hook.');
511
  self::_addLogEvent(1000, $user->ID);
514
  * @internal
515
  * Hooks to the logout event
516
  */
517
+ static function watchEventLogout()
518
  {
519
  wpphLog(__METHOD__.'() triggered by hook.');
520
  self::_addLogEvent(1001, wp_get_current_user()->ID);
524
  * @internal
525
  * Hooks to the user register event
526
  */
527
+ static function watchEventUserRegister($user_id)
528
  {
529
  wpphLog(__METHOD__.'() triggered by hook.');
530
 
536
  $nu = $uInfo['userName'];
537
  $nur = ucfirst($uInfo['userRole']);
538
 
 
 
 
539
  if($un == 'System')
540
  {
541
  // A new user with the username %username% has registered with the role of %user_role%
550
  }
551
 
552
  /**
553
+ * 6000
554
  * @internal
555
  * Hooks to the events deletion event
556
  */
557
+ static function watchDeleteEvents()
558
  {
559
  wpphLog(__METHOD__.'() triggered by hook.');
560
 
565
  }
566
  else{
567
  add_action(WPPH_PLUGIN_DEL_EVENTS_CRON_TASK_NAME, array('WPPHEventWatcher','__deleteEvents'));
568
+ if ( ! wp_next_scheduled(WPPH_PLUGIN_DEL_EVENTS_CRON_TASK_NAME)) {
569
  wp_schedule_event( time(), 'daily', WPPH_PLUGIN_DEL_EVENTS_CRON_TASK_NAME );
570
  wpphLog(__METHOD__.'() scheduled by wp-cron.');
571
  }
573
  }
574
 
575
  //@internal
576
+ static function __deleteEvents()
577
  {
578
  // check settings and delete the events (if any)
579
  $settings = WPPH::getPluginSettings();
631
  }
632
  //@internal
633
  // delete by number
634
+ private static function _deleteEventsGreaterThan($number = WPPH_KEEP_MAX_EVENTS)
635
  {
636
+ if($number > WPPH_KEEP_MAX_EVENTS){ $number = WPPH_KEEP_MAX_EVENTS; }
637
  global $wpdb;
638
  $tableName = WPPHDatabase::getFullTableName('main');
639
  $count = $wpdb->get_var("SELECT COUNT(0) FROM $tableName");
640
  if(empty($count)){
641
  wpphLog(__METHOD__.'('.$number.') called. Ignored, there are no events in the database');
642
+ return true;
643
  }
644
  $keep = $number;
645
  if($count > $keep)
654
  }
655
  else {
656
  wpphLog(__METHOD__.'('.$number.') called. Ignored, there are not enough events to trigger this action.');
657
+ return true;
658
  }
659
  }
660
 
662
  * @internal
663
  * Fired on login failure
664
  */
665
+ static function watchLoginFailure($username='')
666
  {
667
  wpphLog(__METHOD__.'() triggered by hook.', array('username'=>$username));
668
  self::_addLogEvent(1002,0,WPPHUtil::getIP(),array($username), base64_encode($username));
669
  }
670
 
671
+ static function watchUserInfoUpdated($userID)
672
  {
673
  wpphLog(__METHOD__.'() triggered by hook.');
674
 
724
  {
725
  wpphLog(__METHOD__.'() triggered by hook.');
726
 
 
727
  if(strcasecmp($initialUserRole, $updatedRole)==0){
728
  wpphLog(__METHOD__.'() Ignored. Role did not change.');
729
  return false;
805
  * @param $userID the id of the user being deleted
806
  * Triggered when a user is deleted
807
  */
808
+ static function watchUserDeletion($userID)
809
  {
810
  wpphLog(__METHOD__.'() triggered by hook.');
811
 
827
  }
828
 
829
  // # 5001
830
+ static function watchPluginActivate()
831
  {
832
  wpphLog(__METHOD__.'() triggered by hook.');
833
 
871
  }
872
  }
873
  // # 5002
874
+ static function watchPluginDeactivate()
875
  {
876
  wpphLog(__METHOD__.'() triggered by hook.');
877
 
915
  }
916
  }
917
  // # 5000
918
+ static function watchPluginInstall()
919
  {
920
  if(defined('WPPH_PLUGIN_INSTALLED_OK')){ return; }
921
  if(empty($_GET)) { return; }
945
  }
946
  }
947
  // # 5003
948
+ static function watchPluginUninstall()
949
  {
950
  if(empty($_POST)) { return; }
951
  if(! isset($_POST['verify-delete'])) { return; }
969
  }
970
  }
971
  // # 5004
972
+ static function watchPluginUpgrade()
973
  {
 
 
 
 
 
974
  $current_user = wp_get_current_user();
975
  $userID = $current_user->ID;
976
  $ip = WPPHUtil::getIP();
977
 
978
+ // One by link
979
  if(!empty($_GET))
980
  {
981
  if(isset($_GET['action']) && !empty($_GET['action']))
1026
  }
1027
 
1028
 
1029
+ static function watchBlogActivity($newStatus, $oldStatus, $post)
1030
  {
1031
+ wpphLog(__METHOD__.'() triggered.');
1032
 
1033
+ wpphLog(__METHOD__.'. POST STATUS DATA', array(
 
1034
  '$oldStatus' => $oldStatus,
1035
  '$newStatus' => $newStatus,
1036
  '$post' => $post
1037
  ));
1038
 
1039
  // IGNORE STATES - so we skip generating multiple events
1040
+ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { wpphLog('Doing autosave'); return; }
1041
+ if(empty($post->post_type)){ wpphLog('Empty post->post_type'); return; }
1042
+ if($post->post_type == 'revision') { wpphLog('Post type == revision.'); return; }
1043
+ if($newStatus == 'auto-draft' || ($oldStatus == 'new' && $newStatus=='auto-draft')) { wpphLog('Doing draft autosave'); return; }
1044
+
1045
+ $types = WPPHPost::getPostTypes();
1046
+ if(! in_array($post->post_type, $types)){
1047
+ wpphLog('Invalid post type.', array('post-type'=>$post->post_type));
1048
+ return;
1049
+ }
1050
+ do_action('wpph_set_post_type','custom');
1051
 
1052
  $postID = $post->ID;
1053
  $postTitle = $post->post_title;
1071
  }
1072
 
1073
  if(empty($originalPostStatus)){
1074
+ // wpphLog(__METHOD__.' $_POST["_status"] not found. $originalPostStatus is EMPTY - nothing to do here.');
1075
+ // wpphLog(__METHOD__.' POST DATA',$_POST);
1076
  return;
1077
  }
1078
 
1079
+ $postTypePost = $postTypePage = $customPostType = false;
1080
 
1081
  if($post->post_type == 'post'){ $postTypePost = true;}
1082
  elseif($post->post_type == 'page'){ $postTypePage = true;}
1083
+ else { $customPostType = true; }
1084
 
1085
+ if(!$postTypePost && !$postTypePage && !$customPostType){
1086
+ wpphLog('Ignored. Invalid post type', array('postType'=>$post->post_type));
1087
  return;
1088
  }
1089
 
1090
+ WPPHPost::$currentPostType = $post->post_type;
1091
+
1092
+
1093
  global $wpdb;
 
1094
 
1095
+ //## 2025 & 2026 & 2040
1096
+ if($customPostType){ self::watchPostVisibilityChange($oldStatus, $newStatus, $userID, $postTitle, $post, 2040); }
1097
+ else { self::watchPostVisibilityChange($oldStatus, $newStatus, $userID, $postTitle, $post, ($postTypePost) ? 2025 : 2026); }
1098
 
1099
+ //## 2027 & 2028 & 2041
1100
  if(! in_array($oldStatus, array('new', 'auto-draft'))){
1101
+ if($customPostType){ self::watchPostDateChange($userID, $postTitle, $post->post_date, 2041);}
1102
+ else { self::watchPostDateChange($userID, $postTitle, $post->post_date, ($postTypePost) ? 2027 : 2028); }
1103
  }
1104
 
1105
+ //## 2016 & 2036
1106
+ if($postTypePost){ self::watchPostCategoriesChange($post, $wpdb, $postTitle, 2016); }
1107
+ elseif($customPostType){ self::watchPostCategoriesChange($post, $wpdb, $postTitle, 2036); }
1108
 
1109
+ //## 2019 & 2020 & 2038
1110
  $authorChanged = false;
1111
  if(isset($GLOBALS['WPPH_POST_AUTHOR_UPDATED_ID']))
1112
  {
1113
+ if($customPostType){
1114
+ if(WPPHPost::postAuthorChanged((int)$GLOBALS['WPPH_POST_AUTHOR_UPDATED_ID'], $postID, $userID, $postTitle, 2038)){
1115
+ unset($GLOBALS['WPPH_POST_AUTHOR_UPDATED_ID']);
1116
+ $GLOBALS['WPPH_POST_AUTHOR_UPDATED'] = true;
1117
+ $authorChanged = true;
1118
+ }
1119
+ }
1120
+ else {
1121
+ if(WPPHPost::postAuthorChanged((int)$GLOBALS['WPPH_POST_AUTHOR_UPDATED_ID'], $postID, $userID, $postTitle, ($postTypePost) ? 2019 : 2020)){
1122
+ unset($GLOBALS['WPPH_POST_AUTHOR_UPDATED_ID']);
1123
+ $GLOBALS['WPPH_POST_AUTHOR_UPDATED'] = true;
1124
+ $authorChanged = true;
1125
+ }
1126
  }
1127
  }
1128
 
1129
+ // 2000 & 2004 & 2029
1130
  if($newStatus != 'publish'){
1131
  if($originalPostStatus == 'auto-draft' || ($oldStatus=='new' && $newStatus=='inherit' && $postStatus=='inherit'))
1132
  {
1133
+ if($customPostType){ WPPHPost::newPostAsDraft($userID, $postID, $postTitle, 2029); }
1134
+ else { WPPHPost::newPostAsDraft($userID, $postID, $postTitle, ($postTypePost) ? 2000 : 2004); }
1135
  }
1136
  }
1137
 
1139
  $postModified = self::watchPostChanged($wpdb, $postID);
1140
  wpphLog('POST MODIFIED',array('modified'=> $postModified ? 'true' : 'false'));
1141
 
1142
+ //## 2000 & 2003 & 2004 & 2007 & 2032
1143
  if(($oldStatus == 'draft') && ($newStatus == 'draft' && $postStatus == 'draft'))
1144
  {
1145
  if($originalPostStatus == 'draft')
1146
  {
1147
  //## 2003 - draft post updated
1148
+ if($postTypePost || $customPostType){
1149
  // only if 2016 || 2017 || 2019 were not triggered
1150
  if(isset($GLOBALS['WPPH_POST_CATEGORIES_UPDATED']) || isset($GLOBALS['WPPH_POST_URL_UPDATED']) || isset($GLOBALS['WPPH_POST_AUTHOR_UPDATED'])){}
1151
  else {
1152
+ $event = ($customPostType ? 2032 : 2003);
1153
+ WPPHPost::draftPostUpdated($userID, $postID, $postTitle, $event);
1154
  $postModified = false;
1155
  }
1156
  }
1159
  // only if 2018 || 2020 were not triggered
1160
  if(isset($GLOBALS['WPPH_PAGE_URL_UPDATED']) || isset($GLOBALS['WPPH_PAGE_AUTHOR_UPDATED'])){}
1161
  else {
1162
+ WPPHPost::draftPostUpdated($userID, $postID, $postTitle, 2007);
1163
  $postModified = false;
1164
  }
1165
  }
1166
  }
1167
  }
1168
 
1169
+ //## 2001 & 2005 & 2030 - new post/page published
1170
  elseif(in_array($oldStatus, array('draft','auto-draft','pending')) && $newStatus == 'publish' && $postStatus == 'publish')
1171
  {
1172
+ $event = 0;
1173
+ if($customPostType) { $event = 2030;}
1174
+ elseif($postTypePost) { $event = 2001; }
1175
+ elseif($postTypePage) { $event = 2005; }
1176
+ if(! empty($event)){
1177
+ WPPHPost::newPostPublished($userID, $postTitle, $postUrl, $event);
1178
+ return; // no need to process further
1179
+ }
1180
  }
1181
 
1182
+ //## 2021 & 2022 & 2039 : published -> pending
1183
  elseif($oldStatus == 'publish' && $newStatus == 'pending' && $postStatus == 'pending')
1184
  {
1185
+ $event = 0;
1186
+ if($customPostType) { $event = 2039;}
1187
+ elseif($postTypePost) { $event = 2021; }
1188
+ elseif($postTypePage) { $event = 2022; }
1189
+ if(! empty($event)){
1190
+ WPPHPost::postStatusChanged($postTitle, __('Published'), __('Pending Review'), $userID, $event);
1191
+ }
1192
  }
1193
 
1194
+ //## 2021 & 2022 & 2039 : pending -> draft
1195
  elseif($oldStatus == 'pending' && $newStatus == 'draft' && $postStatus == 'draft')
1196
  {
1197
+ $event = 0;
1198
+ if($customPostType) { $event = 2039;}
1199
+ elseif($postTypePost) { $event = 2021; }
1200
+ elseif($postTypePage) { $event = 2022; }
1201
+ if(! empty($event)){
1202
+ WPPHPost::postStatusChanged($postTitle, __('Pending Review'), __('Draft'), $userID, $event);
1203
+ }
1204
  }
1205
 
1206
+ //## 2021 & 2022 & 2039 : draft -> pending
1207
  elseif($oldStatus == 'draft' && $newStatus == 'pending' && $postStatus == 'pending')
1208
  {
1209
+ $event = 0;
1210
+ if($customPostType) { $event = 2039;}
1211
+ elseif($postTypePost) { $event = 2021; }
1212
+ elseif($postTypePage) { $event = 2022; }
1213
+ if(! empty($event)){
1214
+ WPPHPost::postStatusChanged($postTitle, __('Draft'), __('Pending Review'), $userID, $event);
1215
+ }
1216
  }
1217
 
1218
+ //## 2021 & 2022 & 2039 : published -> draft
1219
  elseif($oldStatus == 'publish' && $newStatus == 'draft' && $postStatus == 'draft')
1220
  {
1221
+ $event = 0;
1222
+ if($customPostType) { $event = 2039;}
1223
+ elseif($postTypePost) { $event = 2001; }
1224
+ elseif($postTypePage) { $event = 2005; }
1225
+ if(! empty($event)){
1226
+ WPPHPost::postStatusChanged($postTitle, __('Published'), __('Draft'), $userID, $event);
1227
+ }
1228
  }
1229
 
1230
+ //## 2002 & 2006 & 2017 & 2018 & 2031 & 2037 : published post/page updated
1231
  elseif($oldStatus == 'publish' && $newStatus == 'publish' && $postStatus == 'publish')
1232
  {
1233
+ // trigger: 2017 & 2018 & 2037 - Changed the URL of the post %post_name% from %old_url% to %new_url%
 
 
 
1234
  if(isset($GLOBALS['WPPH_POST_NEW_URL']) || $postModified)
1235
  {
1236
+ $event = 0;
1237
+ if($customPostType) { $event = 2037;}
1238
+ elseif($postTypePost) { $event = 2017; }
1239
+ elseif($postTypePage) { $event = 2018; }
1240
+ if(! empty($event)){
1241
+ if(WPPHPost::postUrlUpdated($GLOBALS['WPPH_POST_NEW_URL'], get_permalink($postID), $userID, $postTitle, $event))
1242
+ {
1243
+ unset($GLOBALS['WPPH_POST_NEW_URL']);
1244
+ $GLOBALS['WPPH_POST_URL_UPDATED'] = $postTypePost;
1245
+ $GLOBALS['WPPH_PAGE_URL_UPDATED'] = $postTypePage;
1246
+ }
1247
  }
1248
  }
1249
+ // 2002 & 2031
1250
+ if($postTypePost || $customPostType)
1251
  {
1252
  if(isset($GLOBALS['WPPH_POST_CATEGORIES_UPDATED']) || isset($GLOBALS['WPPH_POST_URL_UPDATED'])
1253
  || isset($GLOBALS['WPPH_POST_AUTHOR_UPDATED']) || isset($GLOBALS['WPPH_POST_PROTECTED_TRANSITION'])
1255
  // Modified the published blog post %post_title%. Blog post URL is %post_URL%
1256
  else {
1257
  if(! $authorChanged){
1258
+ WPPHPost::publishedPostUpdated($userID, $postTitle, $postUrl, ($postTypePost) ? 2002 : 2031);
1259
  }
1260
  }
1261
  }
1267
  // Modified the published page %page_title%. Page URL is %URL%
1268
  else {
1269
  if(! $authorChanged){
1270
+ WPPHPost::publishedPostUpdated($userID, $postTitle, $postUrl, 2006);
1271
  }
1272
  }
1273
  }
1274
+ // no need to process further
1275
  return;
1276
  }
1277
 
1278
  // if post name changed - we probably have a URL change here
1279
+ // 2003 & 2007 & 2032
1280
  if($postModified){
1281
  if( isset($GLOBALS['WPPH_PAGE_AUTHOR_UPDATED']) || isset($GLOBALS['WPPH_PAGE_AUTHOR_UPDATED'])
1282
  || isset($GLOBALS['WPPH_POST_CATEGORIES_UPDATED'])|| isset($GLOBALS['WPPH_POST_DATE_CHANGED'])){}
1283
  else {
1284
+ $event = 0;
1285
+ if($customPostType) { $event = 2032;}
1286
+ elseif($postTypePost) { $event = 2003; }
1287
+ elseif($postTypePage) { $event = 2007; }
1288
+ if(! empty($event)){
1289
+ WPPHPost::draftPostUpdated($userID, $postID, $postTitle, $event);
1290
+ }
1291
  }
1292
  }
1293
  }
1294
 
1295
+ static function watchTrash($postID)
1296
  {
1297
  wpphLog(__METHOD__.'() triggered by hook.');
 
1298
  // get info for the currently logged in user
1299
  $current_user = wp_get_current_user();
1300
  global $wpdb;
1301
  $postInfo = $wpdb->get_row("SELECT post_title, post_type FROM ".$wpdb->posts." WHERE ID = ".$postID);
1302
  $postTitle = $postInfo->post_title;
1303
  $postType = $postInfo->post_type;
1304
+ $customPostType = false;
1305
+ $postTypePost = (($postType == 'post') ? true : false);
1306
+ $postTypePage = (($postType == 'page') ? true : false);
1307
+ if(!$postTypePost && !$postTypePage){
1308
+ if(WPPHPost::validatePostType($postType)){
1309
+ $customPostType = true;
1310
+ }
1311
  }
1312
+ $event = 0;
1313
+ if($customPostType) { $event = 2033;}
1314
+ elseif($postTypePost) { $event = 2008; }
1315
+ elseif($postTypePage) { $event = 2009; }
1316
+ if(! empty($event)){
1317
+ if($event == 2033){
1318
+ self::_addLogEvent($event, $current_user->ID, WPPHUtil::getIP(), array($postTitle, ucfirst($postType), $postID));
1319
+ }
1320
+ else { self::_addLogEvent($event, $current_user->ID, WPPHUtil::getIP(), array($postTitle,$postID)); }
1321
+
1322
+ wpphLog('Post/Page deleted.', array('title'=>$postTitle, 'id'=>$postID));
1323
  }
1324
  }
1325
 
1326
  // 2010
1327
+ static function watchFileUploaded($attachmentID)
1328
  {
1329
  global $wpdb;
1330
  // get info for the currently logged in user
1338
  $GLOBALS['WPPH_PLUGIN_FILE_UPLOADED_IGNORE_DELETE'] = true;
1339
  }
1340
  // 2011
1341
+ static function watchFileUploadedDeleted($attachmentID)
1342
  {
1343
  if(isset($GLOBALS['WPPH_PLUGIN_FILE_UPLOADED_IGNORE_DELETE'])){
1344
  // return, because if this variable is set this means this action is
1354
  wpphLog('File deleted.', array('title'=>$rowData->post_title, 'url'=>dirname($rowData->guid)));
1355
  }
1356
 
1357
+ // 2012, 2013, 2034
1358
+ static function watchFileDeletion($postID)
1359
  {
1360
  global $wpdb;
1361
+ $userID = wp_get_current_user()->ID;
1362
  $postInfo = $wpdb->get_row("SELECT post_title, post_type FROM ".$wpdb->posts." WHERE ID = ".$postID);
1363
  $postTitle = $postInfo->post_title;
1364
  $postType = $postInfo->post_type;
1365
+ $customPostType = false;
1366
+ $postTypePost = (($postType == 'post') ? true : false);
1367
+ $postTypePage = (($postType == 'page') ? true : false);
1368
+ if(!$postTypePost && !$postTypePage){
1369
+ if(WPPHPost::validatePostType($postType)){
1370
+ $customPostType = true;
1371
+ }
1372
  }
1373
+ $event = 0;
1374
+ if($customPostType) { $event = 2034;}
1375
+ elseif($postTypePost) { $event = 2012; }
1376
+ elseif($postTypePage) { $event = 2013; }
1377
+ if(! empty($event)){
1378
+ if($event == 2034){
1379
+ self::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle, ucfirst($postType)));
1380
+ }
1381
+ else { self::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle)); }
1382
+ wpphLog('Post/Page trashed.', array('name'=>$postTitle));
1383
  }
1384
  }
1385
 
1386
+ // 2014, 2015, 2035
1387
+ static function watchTrashUndo($postID)
1388
  {
1389
  global $wpdb;
1390
+ $userID = wp_get_current_user()->ID;
1391
  $postInfo = $wpdb->get_row("SELECT post_title, post_type FROM ".$wpdb->posts." WHERE ID = ".$postID);
1392
  $postTitle = $postInfo->post_title;
1393
  $postType = $postInfo->post_type;
1394
+ $customPostType = false;
1395
+ $postTypePost = (($postType == 'post') ? true : false);
1396
+ $postTypePage = (($postType == 'page') ? true : false);
1397
+ if(!$postTypePost && !$postTypePage){
1398
+ if(WPPHPost::validatePostType($postType)){
1399
+ $customPostType = true;
1400
+ }
1401
  }
1402
+ $event = 0;
1403
+ if($customPostType) { $event = 2035;}
1404
+ elseif($postTypePost) { $event = 2014; }
1405
+ elseif($postTypePage) { $event = 2015; }
1406
+ if(! empty($event)){
1407
+ if($event == 2035){
1408
+ self::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle, ucfirst($postType)));
1409
+ }
1410
+ else { self::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle)); }
1411
+ wpphLog('Post/Page restored from trash.', array('name'=>$postTitle));
1412
  }
1413
  }
1414
 
1415
  // 3000 - Theme activated
1416
+ static function watchThemeChange($themeName)
1417
  {
1418
  // get info for the currently logged in user
1419
  $current_user = wp_get_current_user();
1423
  }
1424
 
1425
  // 2023 - category created
1426
+ static function watchCategoryAdd(array $postData)
1427
  {
1428
  wpphLog(__METHOD__.'() triggered by hook.');
1429
 
1454
  }
1455
 
1456
  // 2024 - category deleted
1457
+ static function watchCategoryDelete(array $postData)
1458
  {
1459
  wpphLog(__METHOD__.'() triggered by hook.');
1460
 
1493
  }
1494
  }
1495
 
1496
+ // 2025, 2026
1497
+ static function watchPostVisibilityChange($oldStatus, $newStatus, $userID, $postTitle, $post, $event)
1498
  {
1499
+ wpphLog(__METHOD__.'() triggered.');
1500
 
1501
  global $wpdb;
1502
 
1509
  // pwd protected -> public
1510
  if($oldStatus == 'publish' && $newStatus == 'publish')
1511
  {
1512
+ // if post is already pwd protected and there is no change, it will still be issued an event: public to pwd protected
1513
+ if(isset($GLOBALS['WPPH_POST_PWD_PROTECTED']) && $GLOBALS['WPPH_POST_PWD_PROTECTED']){
1514
+ $GLOBALS['WPPH_PREVENT_BUBBLE'] = true;
1515
+ wpphLog(__METHOD__.'() No change.');
1516
+ return;
1517
+ }
1518
  // pwd protected -> public
1519
  if(empty($crtPostPassword) && !empty($oldPostPassword)){
1520
+ $from = __('Password Protected');
1521
+ $to = __('Public');
1522
  }
1523
  // public -> pwd protected
1524
  else {
1525
  if(! empty($crtPostPassword)){
1526
+ $from = __('Public');
1527
+ $to = __('Password Protected');
1528
  }
1529
  }
1530
  }
1534
  {
1535
  // public -> private
1536
  if(empty($crtPostPassword) && empty($oldPostPassword)){
1537
+ $from = __('Public');
1538
+ $to = __('Private');
1539
  }
1540
  // pwd protected -> private
1541
  else {
1542
  if(!empty($oldPostPassword)){
1543
+ $from = __('Password Protected');
1544
+ $to = __('Private');
1545
  }
1546
  }
1547
  }
1551
  {
1552
  // private -> public
1553
  if(empty($oldPostPassword) && empty($crtPostPassword)){
1554
+ $from = __('Private');
1555
+ $to = __('Public');
1556
  }
1557
  // private -> pwd protected
1558
  else {
1559
  if(empty($oldPostPassword) && !empty($crtPostPassword)){
1560
+ $from = __('Private');
1561
+ $to = __('Password Protected');
1562
  }
1563
  }
1564
  }
1568
  }
1569
 
1570
  $GLOBALS['WPPH_PREVENT_BUBBLE'] = true;
1571
+ WPPHPost::postVisibilityChanged($userID, $postTitle, $from, $to, $event);
1572
  }
1573
 
1574
+ // 2027 & 2028
1575
+ static function watchPostDateChange($userID, $postTitle, $postCurrentDate, $event)
1576
  {
1577
+ wpphLog(__METHOD__.'() triggered.');
1578
 
1579
  if($GLOBALS['WPPH_POST_IS_NEW']){
1580
  wpphLog('Nothing to do. The post is brand new.');
1581
  return;
1582
  }
1583
+ if(empty($GLOBALS['WPPH_POST_OLD_DATE'])){
1584
+ wpphLog('Empty global WPPH_POST_OLD_DATE, nothing to do.');
1585
+ return;
1586
+ }
1587
 
1588
  $t1 = strtotime($GLOBALS['WPPH_POST_OLD_DATE']);
1589
  $t2 = strtotime($postCurrentDate);
1592
  wpphLog('No change.');
1593
  return;
1594
  }
1595
+ if(empty($t1) || empty($postCurrentDate)){
1596
+ wpphLog('Empty $t1 or $postCurrentDate. Nothing to do.');
1597
+ return;
1598
+ }
1599
 
1600
  $format = get_option('date_format');
1601
  $from = date($format, $t1);
1608
  'from' => $from . '('.$t1.')',
1609
  'to' => $to . '('.$t2.')'
1610
  ));
1611
+ WPPHPost::postDateChanged($userID, $postTitle, $from, $to, $event);
1612
  }
1613
 
1614
+ static function watchPostCategoriesChange($post, $wpdb, $postTitle, $event)
1615
  {
1616
+ wpphLog(__METHOD__.'() triggered.');
1617
 
1618
  if(isset($GLOBALS['WPPH_POST_OLD_CATEGORIES']))
1619
  {
1658
  else {
1659
  $c1 = implode(', ', $categories_1);
1660
  $c2 = implode(', ', $categories_2);
1661
+ WPPHPost::postCategoriesUpdated(wp_get_current_user()->ID, $postTitle, $c1, $c2, $event);
1662
  $GLOBALS['WPPH_POST_CATEGORIES_UPDATED'] = true;
1663
  }
1664
  }
1665
  else {
1666
  $c1 = implode(', ', $categories_1);
1667
  $c2 = implode(', ', $categories_2);
1668
+ WPPHPost::postCategoriesUpdated(wp_get_current_user()->ID, $postTitle, $c1, $c2, $event);
1669
  $GLOBALS['WPPH_POST_CATEGORIES_UPDATED'] = true;
1670
  }
1671
  }
1674
 
1675
  // 2017 & 2018 - Post/page modified
1676
  // convenience method to trigger a post/page modified event
1677
+ static function watchPostChanged($wpdb, $postID)
1678
  {
1679
+ wpphLog(__METHOD__.'() triggered.');
1680
 
1681
  if(isset($GLOBALS['WPPH_POST_OLD_NAME'])){
1682
  // get the current post name and compare
1683
+ $result = $wpdb->get_row("SELECT post_title, post_name, post_password, post_date FROM ".$wpdb->posts." WHERE ID = $postID");
1684
+ if(empty($result)){ return false; }
1685
+ $postName = (empty($result->post_name) ? $result->post_title : $result->post_name);
1686
+ return($GLOBALS['WPPH_POST_OLD_NAME'] != $postName);
1687
  }
1688
  return false;
1689
  }
inc/WPPHPost.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class WPPHPost
4
+ {
5
+ public static $currentPostType = '';
6
+
7
+ static function getPostTypes()
8
+ {
9
+ $args = array('public' => true,'_builtin' => false);
10
+ $output = 'names'; // names or objects, note names is the default
11
+ $operator = 'and'; // 'and' or 'or'
12
+
13
+ $result = get_post_types( $args, $output, $operator );
14
+ if(! isset($result['post'])){ $result['post'] = 'post'; }
15
+ if(! isset($result['page'])){ $result['page'] = 'page'; }
16
+ return $result;
17
+ }
18
+
19
+ static function validatePostType($postType)
20
+ {
21
+ if(empty($postType)){
22
+ return false;
23
+ }
24
+ $types = self::getPostTypes();
25
+ wpphLog('POST TYPES',$types);
26
+ return (in_array($postType, $types) ? true : false);
27
+ }
28
+
29
+ // 2019 & 2020 & 2038
30
+ static function managePostAuthorUpdateQuickEditForm($data, $postArray)
31
+ {
32
+ if($data['post_type'] == 'post'){
33
+ if(self::postAuthorChanged($GLOBALS['WPPH_POST_AUTHOR_UPDATED_ID'], $postArray['ID'], wp_get_current_user()->ID, $data['post_title'], 2019, true)){
34
+ $GLOBALS['WPPH_POST_AUTHOR_UPDATED'] = true;
35
+ }
36
+ }
37
+ elseif($data['post_type'] == 'page'){
38
+ if(self::postAuthorChanged($GLOBALS['WPPH_POST_AUTHOR_UPDATED_ID'], $postArray['ID'], wp_get_current_user()->ID, $data['post_title'], 2020, true)){
39
+ $GLOBALS['WPPH_PAGE_AUTHOR_UPDATED'] = true;
40
+ }
41
+ }
42
+ // custom post type
43
+ else {
44
+ self::$currentPostType = $data['post_type'];
45
+ wpphLog('================================== CURRENT POST TYPE: '.self::$currentPostType);
46
+ if(self::postAuthorChanged($GLOBALS['WPPH_POST_AUTHOR_UPDATED_ID'], $postArray['ID'], wp_get_current_user()->ID, $data['post_title'], 2038, true)){
47
+ $GLOBALS['WPPH_POST_AUTHOR_UPDATED'] = true;
48
+ }
49
+ }
50
+ return $data;
51
+ }
52
+
53
+ // 2019 & 2020 & 2038
54
+ static function postAuthorChanged($newAuthorID, $postID, $userID, $postTitle, $event, $quickFormEnabled = false)
55
+ {
56
+ global $wpdb;
57
+ $oldAuthorID = $wpdb->get_var("SELECT post_author FROM ".$wpdb->posts." WHERE ID = ".$postID);
58
+
59
+ wpphLog(__METHOD__.'() ',array(
60
+ 'oldAuthorID' => $oldAuthorID,
61
+ 'newAuthorID' => $newAuthorID
62
+ ));
63
+
64
+ if($newAuthorID <> $oldAuthorID)
65
+ {
66
+ $n = $wpdb->get_var("SELECT user_login FROM ".$wpdb->users." WHERE ID = ".$newAuthorID);
67
+ $o = $wpdb->get_var("SELECT user_login FROM ".$wpdb->users." WHERE ID = ".$oldAuthorID);
68
+
69
+ if($quickFormEnabled){
70
+ // in quick edit form the authors get switched whereas in the default post editor they don't :/
71
+ $t = $n;
72
+ $n = $o;
73
+ $o = $t;
74
+ }
75
+ if(self::isCustomPost()){
76
+ WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle,ucfirst(self::$currentPostType),$n,$o));
77
+ }
78
+ else { WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle,$n,$o)); }
79
+ wpphLog(__METHOD__.' : Author updated.', array('from'=>$o, 'to'=>$n));
80
+ return true;
81
+ }
82
+ return false;
83
+ }
84
+
85
+ // 2001 & 2005 & 2030
86
+ static function newPostPublished($userID, $postTitle, $postUrl, $event)
87
+ {
88
+ if(self::isCustomPost()){
89
+ WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle, ucfirst(self::$currentPostType), $postUrl));
90
+ }
91
+ else { WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle,$postUrl)); }
92
+ wpphLog(__METHOD__.'() : Post/Page published.', array('title'=>$postTitle));
93
+ }
94
+
95
+ // 2003 & 2007 & 2032
96
+ static function draftPostUpdated($userID, $postID, $postTitle, $event)
97
+ {
98
+ if(self::isCustomPost()){
99
+ WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle, ucfirst(self::$currentPostType), $postID));
100
+ }
101
+ else { WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle,$postID)); }
102
+ wpphLog(__METHOD__.'() : Draft post/page updated.', array('title'=>$postTitle));
103
+ }
104
+
105
+ // 2000 & 2004 & 2029
106
+ static function newPostAsDraft($userID, $postID, $postTitle, $event)
107
+ {
108
+ if(self::isCustomPost()){
109
+ WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle, ucfirst(self::$currentPostType), $postID));
110
+ }
111
+ else { WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle, $postID)); }
112
+ wpphLog(__METHOD__.'() : New post/page saved as draft.', array('title'=>$postTitle));
113
+ }
114
+
115
+ // 2017 & 2018
116
+ static function postUrlUpdated($oldUrl, $newUrl, $userID, $postTitle, $event)
117
+ {
118
+ if($oldUrl == $newUrl) { return false; }
119
+ if(self::isCustomPost()){
120
+ WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle, ucfirst(self::$currentPostType), $oldUrl, $newUrl));
121
+ }
122
+ else { WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle, $oldUrl, $newUrl)); }
123
+ wpphLog(__METHOD__.'() : Post/Page URL updated.', array('from' => $oldUrl,'to' => $newUrl));
124
+ return true;
125
+ }
126
+
127
+ // 2002 & 2006 & 2031
128
+ static function publishedPostUpdated($userID, $postTitle, $postUrl, $event)
129
+ {
130
+ if(self::isCustomPost()){
131
+ WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle, ucfirst(self::$currentPostType), $postUrl));
132
+ }
133
+ else { WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle,$postUrl)); }
134
+ wpphLog(__METHOD__.'() : Published post/page updated.', array('title'=>$postTitle));
135
+ }
136
+
137
+ static function postVisibilityChanged($userID, $postTitle, $fromVisibility, $toVisibility, $event)
138
+ {
139
+ if(self::isCustomPost()){
140
+ WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle,ucfirst(self::$currentPostType),$fromVisibility,$toVisibility));
141
+ }
142
+ else { WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle,$fromVisibility,$toVisibility)); }
143
+ wpphLog('Post visibility changed.', array('from' => $fromVisibility, 'to' => $toVisibility));
144
+ }
145
+
146
+ static function postDateChanged($userID, $postTitle, $fromDate, $toDate, $event)
147
+ {
148
+ $GLOBALS['WPPH_POST_DATE_CHANGED'] = true; // so we won't trigger the "modified post/page" event alongside the current event
149
+ if(self::isCustomPost()){
150
+ WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle,ucfirst(self::$currentPostType),$fromDate,$toDate));
151
+ }
152
+ else { WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle,$fromDate,$toDate)); }
153
+ wpphLog('Post date changed.', array('from' => $fromDate . ' ('.strtotime($fromDate).')', 'to' => $toDate . ' ('.strtotime($toDate).')'));
154
+ }
155
+
156
+ static function postStatusChanged($postTitle, $fromStatus, $toStatus, $userID, $event)
157
+ {
158
+ if(self::isCustomPost()){
159
+ WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle, ucfirst(self::$currentPostType), $fromStatus, $toStatus));
160
+ }
161
+ else { WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle, $fromStatus, $toStatus)); }
162
+ wpphLog(__METHOD__.'() : Post status updated.', array('title'=>$postTitle, 'from' => $fromStatus, 'to' => $toStatus));
163
+ }
164
+
165
+ // 2016
166
+ static function postCategoriesUpdated($userID, $postTitle, $fromCategories, $toCategories, $event)
167
+ {
168
+ if(self::isCustomPost()){
169
+ WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle, ucfirst(self::$currentPostType), $fromCategories, $toCategories));
170
+ }
171
+ else { WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle, $fromCategories, $toCategories)); }
172
+ wpphLog(__METHOD__.' : Post categories updated.', array('from'=>$fromCategories, 'to'=>$toCategories));
173
+ }
174
+
175
+ static function isCustomPost(){
176
+ if(in_array(self::$currentPostType, array('post','page'))){ return false; }
177
+ return self::validatePostType(self::$currentPostType);
178
+ }
179
+ }
inc/WPPHUtil.php CHANGED
@@ -1,28 +1,28 @@
1
  <?php
2
  class WPPHUtil
3
  {
4
- public static function loadPluggable(){
5
  if(! function_exists('user_can')){
6
  @include_once(ABSPATH.'wp-includes/pluggable.php');
7
  }
8
  }
9
 
10
- public static function getIP() { return(!empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0'); }
11
 
12
  /**
13
  * Check to see whether or not the current user is an administrator
14
  * @return bool
15
  */
16
- public static function isAdministrator(){ return user_can(wp_get_current_user(),'update_core'); }
17
 
18
- /*
19
- * Will respond to the ajax requests getting the events
20
- */
21
- public static function get_events_html()
22
  {
23
- //#! VALIDATE REQUEST
24
  $rm = strtoupper($_SERVER['REQUEST_METHOD']);
25
- if($rm != 'POST'){ exit('<tr><td colspan="7"><span>'.__('Error: Invalid request').'</span></td></tr>'); }
26
 
27
  // set defaults
28
  $orderBy = 'EventNumber';
@@ -50,13 +50,13 @@ class WPPHUtil
50
  $eventsNum = count($events);
51
 
52
  if($eventsNum == 0){
53
- exit( __formatJsonOutput(array(),__('There are no events to display.')) );
54
  }
55
 
56
  $out = array();
57
  $out['events'] = array();
58
 
59
- //#! prepare output
60
  foreach($events as $entry)
61
  {
62
  $entry = (object)$entry;
@@ -83,7 +83,8 @@ class WPPHUtil
83
 
84
  // format event description message
85
  if($eventCount >=2 && $EventID == 1002){
86
- $evm = sprintf(__('<strong>%d</strong> failed login attempts from <strong>%s</strong> using <strong>%s</strong> as username.'), $eventCount, $userIP, base64_decode($entry->UserName));
 
87
  }
88
  else {
89
  if(empty($eventData)) { $evm = $eventDetails->EventDescription; }
@@ -106,4 +107,63 @@ class WPPHUtil
106
  exit(__formatJsonOutput($out));
107
  }
108
 
109
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
  class WPPHUtil
3
  {
4
+ static function loadPluggable(){
5
  if(! function_exists('user_can')){
6
  @include_once(ABSPATH.'wp-includes/pluggable.php');
7
  }
8
  }
9
 
10
+ static function getIP() { return(!empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0'); }
11
 
12
  /**
13
  * Check to see whether or not the current user is an administrator
14
  * @return bool
15
  */
16
+ static function isAdministrator(){ return user_can(wp_get_current_user(),'update_core'); }
17
 
18
+ /**
19
+ * Will respond to the ajax requests getting the events
20
+ */
21
+ static function get_events_html()
22
  {
23
+ // VALIDATE REQUEST
24
  $rm = strtoupper($_SERVER['REQUEST_METHOD']);
25
+ if($rm != 'POST'){ exit('<tr><td colspan="7"><span>'.__('Error: Invalid request',WPPH_PLUGIN_TEXT_DOMAIN).'</span></td></tr>'); }
26
 
27
  // set defaults
28
  $orderBy = 'EventNumber';
50
  $eventsNum = count($events);
51
 
52
  if($eventsNum == 0){
53
+ exit( __formatJsonOutput(array(),__('There are no events to display.',WPPH_PLUGIN_TEXT_DOMAIN)) );
54
  }
55
 
56
  $out = array();
57
  $out['events'] = array();
58
 
59
+ // prepare output
60
  foreach($events as $entry)
61
  {
62
  $entry = (object)$entry;
83
 
84
  // format event description message
85
  if($eventCount >=2 && $EventID == 1002){
86
+ $evm = sprintf(__('<strong>%d</strong> failed login attempts from <strong>%s</strong> using <strong>%s</strong> as username.',WPPH_PLUGIN_TEXT_DOMAIN)
87
+ , $eventCount, $userIP, base64_decode($entry->UserName));
88
  }
89
  else {
90
  if(empty($eventData)) { $evm = $eventDetails->EventDescription; }
107
  exit(__formatJsonOutput($out));
108
  }
109
 
110
+ static function addDashboardWidget()
111
+ {
112
+ $settings = WPPH::getPluginSettings();
113
+ if(! empty($settings->showDW)){
114
+ wp_add_dashboard_widget('wpphPluginDashboardWidget', __('Latest WordPress Security Alerts').' | WP Security Audit Log', array(get_class(),'createDashboardWidget'));
115
+ }
116
+ }
117
+ static function createDashboardWidget()
118
+ {
119
+ // get and display data
120
+ $results = $events = WPPHEvent::getEvents('EventNumber', 'DESC', array(0,5));
121
+ echo '<div>';
122
+ if(empty($results))
123
+ {
124
+ echo '<p>'.__('',WPPH_PLUGIN_TEXT_DOMAIN).'</p>';
125
+ }
126
+ else {
127
+ echo '<table class="wp-list-table widefat" cellspacing="0" cellpadding="0">';
128
+ echo '<thead>';
129
+ echo '<th class="manage-column" style="width: 15%;" scope="col">'.__('User',WPPH_PLUGIN_TEXT_DOMAIN).'</th>';
130
+ echo '<th class="manage-column" style="width: 85%;" scope="col">'.__('Description',WPPH_PLUGIN_TEXT_DOMAIN).'</th>';
131
+ echo '</thead>';
132
+ echo '<tbody>';
133
+ foreach($results as $entry)
134
+ {
135
+ $entry = (object)$entry;
136
+ $eventID = $entry->EventID;
137
+ $userID = $entry->UserID;
138
+ $eventData = ((!empty($entry->EventData)) ? unserialize(base64_decode($entry->EventData)) : ''); //<< values to use for event description
139
+ $eventCount = intval($entry->EventCount);
140
+ $userIP = $entry->UserIP;
141
+ // get User Info
142
+ if($userID == 0){ $username = 'System'; }
143
+ else {
144
+ $user_info = get_userdata($userID);
145
+ $username = $user_info->user_login;
146
+ }
147
+ // format event description message
148
+ if($eventCount >=2 && $eventID == 1002){
149
+ $evm = sprintf(__('<strong>%d</strong> failed login attempts from <strong>%s</strong> using <strong>%s</strong> as username.',WPPH_PLUGIN_TEXT_DOMAIN)
150
+ , $eventCount, $userIP, base64_decode($entry->UserName));
151
+ }
152
+ else {
153
+ $eventDetails = WPPHEvent::getEventDetailsData($eventID);
154
+ if(empty($eventData)) { $evm = $eventDetails->EventDescription; }
155
+ else { $evm = vsprintf($eventDetails->EventDescription, $eventData); }
156
+ }
157
+
158
+ echo '<tr>';
159
+ echo '<td>'.$username.'</td>';
160
+ echo '<td><a href="admin.php?page='.WPPH_PLUGIN_PREFIX.'">'.$evm.'</a></td>';
161
+ echo '</tr>';
162
+ }
163
+ echo '</tbody>';
164
+ echo '</table>';
165
+ }
166
+ echo '</div>';
167
+ }
168
+
169
+ }
inc/wpphFunctions.php CHANGED
@@ -1,112 +1,139 @@
1
- <?php
2
-
3
- //#! 2001 & 2005
4
- function wpph_newPostPublished($userID, $postTitle, $postUrl, $event)
5
- {
6
- WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle,$postUrl));
7
- wpphLog(__FUNCTION__.'() : Post/Page published.', array('title'=>$postTitle));
8
- }
9
-
10
- // 2003 & 2007
11
- function wpph_draftPostUpdated($userID, $postID, $postTitle, $event)
12
- {
13
- WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle,$postID));
14
- wpphLog(__FUNCTION__.'() : Draft post/page updated.', array('title'=>$postTitle));
15
  }
16
 
17
- // 2000 & 2004
18
- function wpph_newPostAsDraft($userID, $postID, $postTitle, $event)
19
- {
20
- WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle,$postID));
21
- wpphLog(__FUNCTION__.'() : New post/page saved as draft.', array('title'=>$postTitle));
22
- }
23
 
24
- // 2017 & 2018
25
- function wpph_postUrlUpdated($oldUrl, $newUrl, $userID, $postTitle, $event)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  {
27
- if($oldUrl == $newUrl) { return false; }
28
-
29
- WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle, $oldUrl, $newUrl));
30
- wpphLog(__FUNCTION__.'() : Post/Page URL updated.', array('from' => $oldUrl,'to' => $newUrl));
31
- return true;
32
- }
33
-
34
- // 2002 & 2006
35
- function wpph_publishedPostUpdated($userID, $postTitle, $postUrl, $event)
36
- {
37
- WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle,$postUrl));
38
- wpphLog(__FUNCTION__.'() : Published post/page updated.', array('title'=>$postTitle));
39
- }
40
-
41
- function wpph_postVisibilityChanged($userID, $postTitle, $fromVisibility, $toVisibility, $event)
42
- {
43
- wpphLog(__FUNCTION__.'() triggered.');
44
- wpphLog('Post visibility changed.', array('from' => $fromVisibility, 'to' => $toVisibility));
45
- WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle,$fromVisibility,$toVisibility));
46
- }
47
-
48
- function wpph_postDateChanged($userID, $postTitle, $fromDate, $toDate, $event)
49
- {
50
- wpphLog(__FUNCTION__.'() triggered.');
51
- wpphLog('Post date changed.', array('from' => $fromDate . ' ('.strtotime($fromDate).')', 'to' => $toDate . ' ('.strtotime($toDate).')'));
52
- $GLOBALS['WPPH_POST_DATE_CHANGED'] = true; // so we won't trigger the "modified post/page" event alongside the current event
53
- WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle,$fromDate,$toDate));
54
- }
55
-
56
- function wpph_postStatusChanged($postTitle, $fromStatus, $toStatus, $userID, $event)
57
- {
58
- WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle, $fromStatus, $toStatus));
59
- wpphLog(__FUNCTION__.'() : Post status updated.', array('title'=>$postTitle, 'from' => $fromStatus, 'to' => $toStatus));
60
- }
61
-
62
- // 2016
63
- function wpph_postCategoriesUpdated($userID, $postTitle, $fromCategories, $toCategories)
64
- {
65
- WPPHEvent::_addLogEvent(2016, $userID, WPPHUtil::getIP(), array($postTitle, $fromCategories, $toCategories));
66
- wpphLog(__FUNCTION__.' : Blog post categories updated.', array('from'=>$fromCategories, 'to'=>$toCategories));
67
- }
68
-
69
- // 2019 & 2020
70
- function wpph_postAuthorChanged($newAuthorID, $postID, $userID, $postTitle, $event, $quickFormEnabled = false)
71
- {
72
- global $wpdb;
73
- $oldAuthorID = $wpdb->get_var("SELECT post_author FROM ".$wpdb->posts." WHERE ID = ".$postID);
74
-
75
- wpphLog(__FUNCTION__.'() ',array(
76
- 'oldAuthorID' => $oldAuthorID,
77
- 'newAuthorID' => $newAuthorID
78
- ));
79
-
80
- if($newAuthorID <> $oldAuthorID){
81
- $n = $wpdb->get_var("SELECT user_login FROM ".$wpdb->users." WHERE ID = ".$newAuthorID);
82
- $o = $wpdb->get_var("SELECT user_login FROM ".$wpdb->users." WHERE ID = ".$oldAuthorID);
83
-
84
- if($quickFormEnabled){
85
- // in quick edit form the authors get switched whereas in the default post editor they don't :/
86
- $t = $n;
87
- $n = $o;
88
- $o = $t;
89
  }
90
-
91
- WPPHEvent::_addLogEvent($event, $userID, WPPHUtil::getIP(), array($postTitle,$n,$o));
92
- wpphLog(__FUNCTION__.' : Post/Page author updated.', array('from'=>$o, 'to'=>$n));
93
- return true;
94
  }
95
  return false;
96
  }
97
 
98
- // handle author change in quick edit form
99
- function wpph_managePostAuthorUpdateQuickEditForm($data, $postArray)
100
- {
101
- if($data['post_type'] == 'post'){
102
- if(wpph_postAuthorChanged($GLOBALS['WPPH_POST_AUTHOR_UPDATED_ID'], $postArray['ID'], wp_get_current_user()->ID, $data['post_title'], 2019, true)){
103
- $GLOBALS['WPPH_POST_AUTHOR_UPDATED'] = true;
104
- }
105
- }
106
- elseif($data['post_type'] == 'page'){
107
- if(wpph_postAuthorChanged($GLOBALS['WPPH_POST_AUTHOR_UPDATED_ID'], $postArray['ID'], wp_get_current_user()->ID, $data['post_title'], 2020, true)){
108
- $GLOBALS['WPPH_PAGE_AUTHOR_UPDATED'] = true;
109
- }
110
- }
111
- return $data;
112
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if(! defined('WPPH_PLUGIN_NAME')) return;
2
+
3
+ /**
4
+ * @param string $error The error to display in the admin notice
5
+ * This function can be used to generate an admin notice error
6
+ */
7
+ function wpph_adminNotice($error) { echo '<div id="errMessage" class="error"><p><strong>'.WPPH_PLUGIN_NAME.' '.__('Error',WPPH_PLUGIN_TEXT_DOMAIN).':</strong> '.$error.'</p></div>'; }
8
+ function wpph_adminUpdate($message) { echo '<div id="errMessage" class="updated"><p><strong>'.$message.'</strong></p></div>'; }
9
+
10
+ add_action('wpph_set_post_type', 'wpph_setPostType', 1, 1);
11
+ function wpph_setPostType($postType){
12
+ WPPHPost::$currentPostType = $postType;
13
+ wpphLog(__FUNCTION__.' triggered', array('postType'=>$postType));
 
14
  }
15
 
 
 
 
 
 
 
16
 
17
+ /**
18
+ * Retrieve the custom post type from the given base post type
19
+ * @since v0.4
20
+ * @param string $baseType The post's base type from which to extract the custom type
21
+ * @return string The custom post type
22
+ */
23
+ function wpph_extractCustomPostType($baseType) { return substr($baseType, strpos($baseType,'-')+1); }
24
+
25
+ /**
26
+ * Check to see whether or not the provided event is enabled
27
+ * @since v0.4
28
+ * @param integer $event the event to search for
29
+ * @param array $events Optional. The list of events where to search for $event to see if it's enabled or not
30
+ * @return bool
31
+ */
32
+ function wpph_isEventEnabled($event, array $events = array())
33
  {
34
+ if(empty($event)){ return false; }
35
+ if(empty($events)){
36
+ $temp = WPPH::getPluginSettings();
37
+ $events = $temp->logEvents;
38
+ }
39
+ foreach($events as $k=>$entries){
40
+ foreach($entries as $_event => $enabled){
41
+ if(($event == $_event) && $enabled){
42
+ return true;
43
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  }
 
 
 
 
45
  }
46
  return false;
47
  }
48
 
49
+ // Add custom links on plugins page
50
+ function wpphCustomLinks($links) { return array_merge(array('<a href="admin.php?page=wpph_">Audit Log Viewer </a>', '<a href="admin.php?page=wpph_settings">'.__('Settings',WPPH_PLUGIN_TEXT_DOMAIN).'</a>'), $links); }
51
+ // Load text domain
52
+ function wpphLoadTextDomain() { load_plugin_textdomain(WPPH_PLUGIN_TEXT_DOMAIN, false, 'wp-security-audit-log/languages/'); }
53
+
54
+
55
+ //@see: http://codex.wordpress.org/Function_Reference/register_activation_hook#A_Note_on_Variable_Scope
56
+ global $wpphEvents;
57
+ /**
58
+ * @array
59
+ * @since v0.4
60
+ * Holds the list of all events
61
+ */
62
+ $wpphEvents = array(
63
+ 'Login_Logout' => array(
64
+ 1000 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User logs in',WPPH_PLUGIN_TEXT_DOMAIN)),
65
+ 1001 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User Logs out',WPPH_PLUGIN_TEXT_DOMAIN)),
66
+ 1002 => array('type' => WPPH_E_WARNING_TEXT, 'text' => __('Failed login detected',WPPH_PLUGIN_TEXT_DOMAIN)),
67
+ ),
68
+ 'Pages' => array(
69
+ 2004 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User created a new WordPress page and saved it as draft',WPPH_PLUGIN_TEXT_DOMAIN)),
70
+ 2005 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User published a WorPress page',WPPH_PLUGIN_TEXT_DOMAIN)),
71
+ 2006 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User modified a published WordPress page',WPPH_PLUGIN_TEXT_DOMAIN)),
72
+ 2007 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User modified a draft WordPress page',WPPH_PLUGIN_TEXT_DOMAIN)),
73
+ 2009 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User permanently deleted a page from the trash',WPPH_PLUGIN_TEXT_DOMAIN)),
74
+ 2013 => array('type' => WPPH_E_WARNING_TEXT, 'text' => __('User moved WordPress page to the trash',WPPH_PLUGIN_TEXT_DOMAIN)),
75
+ 2015 => array('type' => WPPH_E_HIGH_TEXT, 'text' => __('User restored a WordPress page from trash',WPPH_PLUGIN_TEXT_DOMAIN)),
76
+ 2018 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User changed page URL',WPPH_PLUGIN_TEXT_DOMAIN)),
77
+ 2020 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User changed page author',WPPH_PLUGIN_TEXT_DOMAIN)),
78
+ 2022 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User changed page status',WPPH_PLUGIN_TEXT_DOMAIN)),
79
+ 2026 => array('type' => WPPH_E_WARNING_TEXT, 'text' => __('User changed the visibility of a page',WPPH_PLUGIN_TEXT_DOMAIN)),
80
+ 2028 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User changed the date of a page post',WPPH_PLUGIN_TEXT_DOMAIN)),
81
+ ),
82
+ 'Blog_Posts' => array(
83
+ 2000 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User created a new blog post and saved it as draft',WPPH_PLUGIN_TEXT_DOMAIN)),
84
+ 2001 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User published a blog post',WPPH_PLUGIN_TEXT_DOMAIN)),
85
+ 2002 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User modified a published blog post',WPPH_PLUGIN_TEXT_DOMAIN)),
86
+ 2003 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User modified a draft blog post',WPPH_PLUGIN_TEXT_DOMAIN)),
87
+ 2008 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User permanently deleted a blog post from the trash',WPPH_PLUGIN_TEXT_DOMAIN)),
88
+ 2010 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User uploaded a file to the uploads directory',WPPH_PLUGIN_TEXT_DOMAIN)),
89
+ 2011 => array('type' => WPPH_E_WARNING_TEXT, 'text' => __('User deleted a file from the uploads directory',WPPH_PLUGIN_TEXT_DOMAIN)),
90
+ 2012 => array('type' => WPPH_E_WARNING_TEXT, 'text' => __('User moved a blog post to the trash',WPPH_PLUGIN_TEXT_DOMAIN)),
91
+ 2014 => array('type' => WPPH_E_HIGH_TEXT, 'text' => __('User restored a blog post from trash',WPPH_PLUGIN_TEXT_DOMAIN)),
92
+ 2016 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User changed blog post category',WPPH_PLUGIN_TEXT_DOMAIN)),
93
+ 2017 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User changed blog post URL',WPPH_PLUGIN_TEXT_DOMAIN)),
94
+ 2019 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User changed blog post author',WPPH_PLUGIN_TEXT_DOMAIN)),
95
+ 2021 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User changed blog post status',WPPH_PLUGIN_TEXT_DOMAIN)),
96
+ 2023 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User created new category',WPPH_PLUGIN_TEXT_DOMAIN)),
97
+ 2024 => array('type' => WPPH_E_WARNING_TEXT, 'text' => __('User deleted a category',WPPH_PLUGIN_TEXT_DOMAIN)),
98
+ 2025 => array('type' => WPPH_E_WARNING_TEXT, 'text' => __('User changed the visibility of a blog post',WPPH_PLUGIN_TEXT_DOMAIN)),
99
+ 2027 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User changed the date of a blog post',WPPH_PLUGIN_TEXT_DOMAIN)),
100
+ ),
101
+ 'Custom_Posts' => array(
102
+ 2029 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User created a new custom blog post and saved it as draft',WPPH_PLUGIN_TEXT_DOMAIN)),
103
+ 2030 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User published a custom blog post',WPPH_PLUGIN_TEXT_DOMAIN)),
104
+ 2031 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User modified a published custom blog post',WPPH_PLUGIN_TEXT_DOMAIN)),
105
+ 2032 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User modified a draft custom blog post',WPPH_PLUGIN_TEXT_DOMAIN)),
106
+ 2033 => array('type' => WPPH_E_WARNING_TEXT, 'text' => __('User permanently deleted a custom blog post from the trash',WPPH_PLUGIN_TEXT_DOMAIN)),
107
+ 2034 => array('type' => WPPH_E_WARNING_TEXT, 'text' => __('User moved a custom blog post to the trash',WPPH_PLUGIN_TEXT_DOMAIN)),
108
+ 2035 => array('type' => WPPH_E_HIGH_TEXT, 'text' => __('User restored a custom blog post from trash',WPPH_PLUGIN_TEXT_DOMAIN)),
109
+ 2036 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User changed custom blog post category',WPPH_PLUGIN_TEXT_DOMAIN)),
110
+ 2037 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User changed custom blog post URL',WPPH_PLUGIN_TEXT_DOMAIN)),
111
+ 2038 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User changed custom blog post author',WPPH_PLUGIN_TEXT_DOMAIN)),
112
+ 2039 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User changed custom blog post status',WPPH_PLUGIN_TEXT_DOMAIN)),
113
+ 2040 => array('type' => WPPH_E_WARNING_TEXT, 'text' => __('User changed the visibility of a custom blog post',WPPH_PLUGIN_TEXT_DOMAIN)),
114
+ 2041 => array('type' => WPPH_E_NOTICE_TEXT, 'text' => __('User changed the date of a custom blog post',WPPH_PLUGIN_TEXT_DOMAIN)),
115
+ ),
116
+ 'Users_Profiles' => array(
117
+ 4000 => array('type' => WPPH_E_HIGH_TEXT, 'text' => __('A new user was created on WordPress',WPPH_PLUGIN_TEXT_DOMAIN)),
118
+ 4001 => array('type' => WPPH_E_HIGH_TEXT, 'text' => __('A user created another WordPress user',WPPH_PLUGIN_TEXT_DOMAIN)),
119
+ 4002 => array('type' => WPPH_E_HIGH_TEXT, 'text' => __('The role of a user was changed by another WordPress user',WPPH_PLUGIN_TEXT_DOMAIN)),
120
+ 4003 => array('type' => WPPH_E_HIGH_TEXT, 'text' => __('User has changed his or her password',WPPH_PLUGIN_TEXT_DOMAIN)),
121
+ 4004 => array('type' => WPPH_E_HIGH_TEXT, 'text' => __('A user changed another user\'s password',WPPH_PLUGIN_TEXT_DOMAIN)),
122
+ 4005 => array('type' => WPPH_E_NOTICE_TEXT,'text' => __('User changed his or her email address',WPPH_PLUGIN_TEXT_DOMAIN)),
123
+ 4006 => array('type' => WPPH_E_NOTICE_TEXT,'text' => __('A user changed another user\'s email address',WPPH_PLUGIN_TEXT_DOMAIN)),
124
+ 4007 => array('type' => WPPH_E_HIGH_TEXT, 'text' => __('A user was deleted by another user',WPPH_PLUGIN_TEXT_DOMAIN)),
125
+ ),
126
+ 'Plugins' => array(
127
+ 5000 => array('type' => WPPH_E_HIGH_TEXT, 'text' => __('User installed a plugin',WPPH_PLUGIN_TEXT_DOMAIN)),
128
+ 5001 => array('type' => WPPH_E_HIGH_TEXT, 'text' => __('User activated a WordPress plugin',WPPH_PLUGIN_TEXT_DOMAIN)),
129
+ 5002 => array('type' => WPPH_E_HIGH_TEXT, 'text' => __('User deactivated a WordPress plugin',WPPH_PLUGIN_TEXT_DOMAIN)),
130
+ 5003 => array('type' => WPPH_E_HIGH_TEXT, 'text' => __('User uninstalled a plugin',WPPH_PLUGIN_TEXT_DOMAIN)),
131
+ 5004 => array('type' => WPPH_E_WARNING_TEXT, 'text' => __('User upgraded a plugin',WPPH_PLUGIN_TEXT_DOMAIN)),
132
+ ),
133
+ 'Settings_And_System_Activity' => array(
134
+ 6000 => array('type' => WPPH_E_NOTICE_TEXT,'text' => __('Events automatically pruned by system',WPPH_PLUGIN_TEXT_DOMAIN)),
135
+ 6001 => array('type' => WPPH_E_HIGH_TEXT, 'text' => __('Option Anyone Can Register in WordPress settings changed',WPPH_PLUGIN_TEXT_DOMAIN)),
136
+ 6002 => array('type' => WPPH_E_HIGH_TEXT, 'text' => __('New User Default Role changed',WPPH_PLUGIN_TEXT_DOMAIN)),
137
+ 6003 => array('type' => WPPH_E_HIGH_TEXT, 'text' => __('WordPress Administrator Notification email changed',WPPH_PLUGIN_TEXT_DOMAIN))
138
+ ),
139
+ );
inc/wpphSettings.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ define('WPPH_PLUGIN_VERSION_OPTION_NAME','WPPH_PLUGIN_VERSION');
3
+ define('WPPH_PLUGIN_ERROR_OPTION_NAME','WPPH_PLUGIN_ERROR');
4
+ define('WPPH_PLUGIN_SETTING_NAME', 'wpph_plugin_settings');
5
+
6
+ define('WPPH_PLUGIN_DB_UPDATED', 'WPPH_PLUGIN_DB_UPDATED');
7
+ define('WPPH_PLUGIN_DEL_EVENTS_CRON_TASK_NAME', 'wpph_plugin_delete_events_cron');
8
+ /** @since v0.3 */
9
+ define('WPPH_USERS_CAN_REGISTER_OPT_NAME', 'wpph_users_can_register');
10
+ /**
11
+ * @since v0.3
12
+ * @see WPPH::onPluginActivate()
13
+ */
14
+ $GLOBALS['WPPH_CAN_RUN'] = true;
15
+ /**@since 0.4*/
16
+ define('WPPH_PLUGIN_TEXT_DOMAIN', 'wp-security-audit-log');
17
+ /**@since 0.4*/
18
+ define('WPPH_E_NOTICE_TEXT', __('NOTICE',WPPH_PLUGIN_TEXT_DOMAIN));
19
+ /**@since 0.4*/
20
+ define('WPPH_E_HIGH_TEXT', __('HIGH',WPPH_PLUGIN_TEXT_DOMAIN));
21
+ /**@since 0.4*/
22
+ define('WPPH_E_WARNING_TEXT', __('WARNING',WPPH_PLUGIN_TEXT_DOMAIN));
23
+
24
+ /**@since 0.4*/
25
+ define('WPPH_KEEP_MAX_EVENTS', 5000);
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
pages/about.php CHANGED
@@ -2,21 +2,20 @@
2
  <?php
3
  if(! WPPH::ready())
4
  {
5
- $errors = WPPH::getPLuginErrors();
6
- foreach($errors as $k =>$v) { call_user_func(array('WPPHAdminNotices',$k),$v); }
7
-
 
8
  echo '<div id="wpph-pageWrapper" class="wrap">';
9
- echo '<p>We have encountered some errors during the installation of the plugin which you can find above.</p>';
10
- echo '<p>Please try to correct them and then reactivate the plugin.</p>';
11
  echo '</div>';
12
  return;
13
  }
14
  ?>
15
  <div id="wpph-pageWrapper" class="wrap">
16
- <h2 class="pageTitle pageTitle-about"><?php echo __('About us');?></h2>
17
  <div>
18
- <p><?php echo sprintf(
19
- __('WP Security Audit Log is a WordPress security plugin developed by %s.'),
20
- '<a href="http://www.wpwhitesecurity.com">WP White Security</a>');?></p>
21
  </div>
22
- </div>
2
  <?php
3
  if(! WPPH::ready())
4
  {
5
+ $errors = WPPH::getPluginErrors();
6
+ foreach($errors as $error) {
7
+ wpph_adminNotice($error);
8
+ }
9
  echo '<div id="wpph-pageWrapper" class="wrap">';
10
+ echo '<p>'.__('We have encountered some errors during the installation of the plugin which you can find above.',WPPH_PLUGIN_TEXT_DOMAIN).'</p>';
11
+ echo '<p>'.__('Please try to correct them and then reactivate the plugin.',WPPH_PLUGIN_TEXT_DOMAIN).'</p>';
12
  echo '</div>';
13
  return;
14
  }
15
  ?>
16
  <div id="wpph-pageWrapper" class="wrap">
17
+ <h2 class="pageTitle pageTitle-about"><?php echo __('About us',WPPH_PLUGIN_TEXT_DOMAIN);?></h2>
18
  <div>
19
+ <p><?php echo sprintf(__('WP Security Audit Log is a WordPress security plugin developed by %s.',WPPH_PLUGIN_TEXT_DOMAIN), '<a href="http://www.wpwhitesecurity.com">WP White Security</a>');?></p>
 
 
20
  </div>
21
+ </div>
pages/alerts.php ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if(! WPPH::canRun()){ return; } ?>
2
+ <?php
3
+ if(! WPPH::ready())
4
+ {
5
+ $errors = WPPH::getPluginErrors();
6
+ foreach($errors as $error) {
7
+ wpph_adminNotice($error);
8
+ }
9
+ echo '<div id="wpph-pageWrapper" class="wrap">';
10
+ echo '<p>'.__('We have encountered some errors during the installation of the plugin which you can find above.',WPPH_PLUGIN_TEXT_DOMAIN).'</p>';
11
+ echo '<p>'.__('Please try to correct them and then reactivate the plugin.',WPPH_PLUGIN_TEXT_DOMAIN).'</p>';
12
+ echo '</div>';
13
+ return;
14
+ }
15
+ ?>
16
+ <?php
17
+ // defaults
18
+ $opt = WPPH::getPluginSettings();
19
+ $logEvents = $opt->logEvents;
20
+ $validationMessage = array();
21
+ $sectionNames = array_keys($logEvents);
22
+ $activeTab = 0;
23
+ $rm = strtoupper($_SERVER['REQUEST_METHOD']);
24
+ if('POST' == $rm)
25
+ {
26
+ // Check nonce
27
+ if(isset($_POST['wpph_update_settings_field_nonce'])){
28
+ if(!wp_verify_nonce($_POST['wpph_update_settings_field_nonce'],'wpph_update_settings')){
29
+ wp_die('Invalid request');
30
+ }
31
+ }
32
+ else {wp_die('Invalid request');}
33
+
34
+ $hasErrors = false;
35
+ $activeTab = intval($_POST['activeTab']);
36
+ $inputEvents = $_POST['inputEvents'];
37
+ $inputEvents = str_replace("\\", "",$inputEvents);
38
+ $inputEvents = json_decode($inputEvents, true);
39
+ if(is_null($inputEvents)){
40
+ $validationMessage['error'] = __('JSON Decode Error: ',WPPH_PLUGIN_TEXT_DOMAIN).json_last_error();
41
+ $hasErrors = true;
42
+ }
43
+
44
+ // save options
45
+ if(!$hasErrors)
46
+ {
47
+ $logEvents = array();
48
+ global $wpphEvents;
49
+ foreach($wpphEvents as $category=>$entries){
50
+ $logEvents[$category] = array();
51
+ foreach($entries as $event=>$entry){
52
+ $logEvents[$category][$event] = 1;
53
+ }
54
+ }
55
+ foreach($inputEvents as $category=>$entries){
56
+ foreach($entries as $entry){
57
+ $event = (int)$entry['e'];
58
+ // validate event before insert
59
+ if(isset($wpphEvents[$category][$event])){
60
+ $logEvents[$category][$event] = 0;
61
+ }
62
+ }
63
+ }
64
+ $opt->logEvents = $logEvents;
65
+ $opt->cleanupRan = 0;
66
+ WPPH::updatePluginSettings($opt,null,null,true);
67
+ $validationMessage['success'] = __('Your settings have been saved.',WPPH_PLUGIN_TEXT_DOMAIN);
68
+ }
69
+ }
70
+ // end $post
71
+ ?>
72
+ <div id="wpph-pageWrapper" class="wrap">
73
+ <h2 class="pageTitle pageTitle-settings"><?php echo __('Enable/Disable Alerts',WPPH_PLUGIN_TEXT_DOMAIN);?></h2>
74
+
75
+ <div id="optionsDescription">
76
+ <p id="description">
77
+ <?php
78
+ echo __('From this page you can enable or disable WordPress security alerts. If a security alert is disabled, an alert will not be generated in the Audit Log Viewer once such action happens.',WPPH_PLUGIN_TEXT_DOMAIN);
79
+ echo '<br/>'.__('To disable a security alert, select the category tab and untick the alert. Click Save Settings when ready.',WPPH_PLUGIN_TEXT_DOMAIN);
80
+ ?>
81
+ </p>
82
+ </div>
83
+
84
+ <?php if(! empty($validationMessage)) : ?>
85
+ <?php
86
+ if(!empty($validationMessage['error'])){ wpph_adminNotice($validationMessage['error']); }
87
+ else { wpph_adminUpdate($validationMessage['success']); }
88
+ ?>
89
+ <?php endif;?>
90
+
91
+ <div id="logEventsTabControl" style="margin: 20px 0;">
92
+ <form id="updateSettingsForm" method="post">
93
+ <?php wp_nonce_field('wpph_update_settings','wpph_update_settings_field_nonce'); ?>
94
+ <?php
95
+ $sectionNames = array_keys($logEvents);
96
+ echo '<ul id="tabControlNavBar">';
97
+ foreach($sectionNames as $item){
98
+ if($item == 'Login_Logout'){
99
+ echo '<li data-id="'.$item.'"><a href="#'.$item.'"/>Login / Logout</a></li>';
100
+ }
101
+ else { echo '<li data-id="'.$item.'"><a href="#'.$item.'"/>'.str_replace('_',' ', $item).'</a></li>'; }
102
+ }
103
+ echo '</ul>';
104
+
105
+ global $wpphEvents;
106
+ foreach($logEvents as $sectionName => $items){
107
+ echo '<div id="'.$sectionName.'">';
108
+ echo '<table class="wp-list-table widefat" cellspacing="0" cellpadding="0">';
109
+ echo '<thead>';
110
+ echo '<th class="manage-column column-cb check-column item-cb" scope="col"><input type="checkbox" class="js-select-all"/></th>';
111
+ echo '<th class="manage-column column-cb check-column item-event" scope="col">'.__('Event',WPPH_PLUGIN_TEXT_DOMAIN).'</th>';
112
+ echo '<th class="manage-column column-cb check-column item-type" scope="col">'.__('Type',WPPH_PLUGIN_TEXT_DOMAIN).'</th>';
113
+ echo '<th class="manage-column column-cb check-column item-description" scope="col">'.__('Description',WPPH_PLUGIN_TEXT_DOMAIN).'</th>';
114
+ echo '</thead>';
115
+ echo '<tbody>';
116
+ foreach($items as $item => $enabled){
117
+ echo '<tr class="row">';
118
+ echo '<th class="manage-column column-cb check-column" scope="row"><input class="item_cb" type="checkbox" '.($enabled ? 'checked="checked"' : '').' value="'.$item.'"/></th>';
119
+ echo '<td>'.$item.'</td>';
120
+ echo '<td>'.$wpphEvents[$sectionName][$item]['type'].'</td>';
121
+ echo '<td>'.$wpphEvents[$sectionName][$item]['text'].'</td>';
122
+ echo '</tr>';
123
+ }
124
+ echo '</tbody>';
125
+ echo '</table>';
126
+ echo '</div>';
127
+ }
128
+ // Events deletion tab
129
+ ?>
130
+ <input type="submit" id="submitButton" class="button button-primary" value="<?php echo __('Save settings',WPPH_PLUGIN_TEXT_DOMAIN);?>"/>
131
+ <input type="hidden" id="inputEvents" name="inputEvents" value=""/>
132
+ <input type="hidden" id="activeTab" name="activeTab" value=""/>
133
+ </form>
134
+ </div>
135
+ </div>
136
+ <br class="clear"/>
137
+
138
+ <script type="text/javascript">
139
+ jQuery(document).ready(function($){
140
+ var tabControl = $('#logEventsTabControl');
141
+ var activeTab = $('#activeTab');
142
+ tabControl.tabs();
143
+ tabControl.tabs("option", "active", <?php echo $activeTab;?>);
144
+ // update select all checkbox
145
+ $('#tabControlNavBar li').each(function(){
146
+ var sectionName = $(this).data('id');
147
+ if(sectionName.length > 0){
148
+ $('#'+sectionName+' input:checkbox.item_cb').each(function() {
149
+ var self = $(this);
150
+ if (self.prop('checked')) {
151
+ $('#'+sectionName+' input:checkbox.js-select-all').attr('checked','checked');
152
+ }
153
+ });
154
+ }
155
+ });
156
+ //
157
+ // form submit
158
+ $('#submitButton').on('click',function()
159
+ {
160
+ activeTab.val(tabControl.tabs("option","active"));
161
+ // build options
162
+ var e = $('#inputEvents')
163
+ ,catList = $('#tabControlNavBar li')
164
+ ,outData = {};
165
+ catList.each(function(){
166
+ var sectionName = $(this).data('id');
167
+ if(sectionName.length > 0){
168
+ outData[sectionName] = [];
169
+ $('#'+sectionName+' input:checkbox.item_cb').each(function() {
170
+ var self = $(this);
171
+ if (!self.prop('checked')) {
172
+ outData[sectionName].push({"e": self.val()});
173
+ }
174
+ });
175
+ }
176
+ });
177
+ e.val(JSON.stringify(outData));
178
+ });
179
+ });
180
+ </script>
pages/dashboard.php CHANGED
@@ -1,32 +1,33 @@
1
- <?php if(! WPPH::canRun()){ return; } ?>
2
  <?php
3
  if(! WPPH::ready())
4
  {
5
- $errors = WPPH::getPLuginErrors();
6
- foreach($errors as $k =>$v) { call_user_func(array('WPPHAdminNotices',$k),$v); }
7
-
 
8
  echo '<div id="wpph-pageWrapper" class="wrap">';
9
- echo '<p>We have encountered some errors during the installation of the plugin which you can find above.</p>';
10
- echo '<p>Please try to correct them and then reactivate the plugin.</p>';
11
  echo '</div>';
12
  return;
13
  }
14
  ?>
15
 
16
  <div id="wpph-pageWrapper" class="wrap">
17
- <h2 class="pageTitle pageTitle-eventViewer"><?php echo __('Audit Log Viewer');?></h2>
18
  <div id="EventViewerWrapper">
19
  <div style="overflow: hidden; display: block; clear: both;">
20
  <div class="tablenav top" style="overflow: hidden; padding: 4px 0;">
21
  <div class="alignleft">
22
  <div style="overflow: hidden;">
23
- <input type="button" class="buttonRefreshEventsList button" value="<?php echo __('Refresh Events List');?>"
24
  style="float: left; display: block;" data-bind="disable: loading, click: cleanRefresh"/>
25
  <span class="ajaxLoaderWrapper" style="float: left; display: block; width: 20px; height: 20px; padding: 7px 7px;"><img/></span>
26
  </div>
27
  </div>
28
  <div class="alignleft actions" style="overflow: hidden;">
29
- <label class="alignleft" style="margin: 5px 5px 0 0;"><?php echo __('Number of events per page:');?></label>
30
  <select name="actionLimit1" class="actionLimit" data-bind="options: availablePageSize, value: selectedPageSize"></select>
31
  <input type="button" value="Apply" class="button action" data-bind="disable: loading, click: applyPageSize">
32
  </div>
@@ -69,7 +70,7 @@ if(! WPPH::ready())
69
  </tr>
70
  </tfoot>
71
  <tbody id="the-list">
72
- <tr data-bind="if: events().length == 0"><td style="padding: 4px !important;" colspan="7"><?php echo __('No events');?></td></tr>
73
  <!-- ko foreach: events -->
74
  <tr data-bind="css: {'row-0': ($index() % 2) == 0, 'row-1': ($index() % 2) != 0}">
75
  <td class="column-event_number"><span data-bind="text: eventNumber"></span></td>
@@ -87,13 +88,13 @@ if(! WPPH::ready())
87
  <div class="tablenav top" style="overflow: hidden; padding: 4px 0;">
88
  <div class="alignleft">
89
  <div style="overflow: hidden;">
90
- <input type="button" class="buttonRefreshEventsList button" value="<?php echo __('Refresh Events List');?>"
91
  style="float: left; display: block;" data-bind="disable: loading, click: cleanRefresh"/>
92
  <span class="ajaxLoaderWrapper" style="float: left; display: block; width: 20px; height: 20px; padding: 7px 7px;"><img/></span>
93
  </div>
94
  </div>
95
  <div class="alignleft actions" style="overflow: hidden;">
96
- <label class="alignleft" style="margin: 5px 5px 0 0;"><?php echo __('Number of events per page:');?></label>
97
  <select name="actionLimit1" class="actionLimit" data-bind="options: availablePageSize, value: selectedPageSize"></select>
98
  <input type="button" value="Apply" class="button action" data-bind="disable: loading, click: applyPageSize">
99
  </div>
1
+ <?php //if(! WPPH::canRun()){ return; } ?>
2
  <?php
3
  if(! WPPH::ready())
4
  {
5
+ $errors = WPPH::getPluginErrors();
6
+ foreach($errors as $error) {
7
+ wpph_adminNotice($error);
8
+ }
9
  echo '<div id="wpph-pageWrapper" class="wrap">';
10
+ echo '<p>'.__('We have encountered some errors during the installation of the plugin which you can find above.',WPPH_PLUGIN_TEXT_DOMAIN).'</p>';
11
+ echo '<p>'.__('Please try to correct them and then reactivate the plugin.',WPPH_PLUGIN_TEXT_DOMAIN).'</p>';
12
  echo '</div>';
13
  return;
14
  }
15
  ?>
16
 
17
  <div id="wpph-pageWrapper" class="wrap">
18
+ <h2 class="pageTitle pageTitle-eventViewer">Audit Log Viewer</h2>
19
  <div id="EventViewerWrapper">
20
  <div style="overflow: hidden; display: block; clear: both;">
21
  <div class="tablenav top" style="overflow: hidden; padding: 4px 0;">
22
  <div class="alignleft">
23
  <div style="overflow: hidden;">
24
+ <input type="button" class="buttonRefreshEventsList button" value="<?php echo __('Refresh Events List',WPPH_PLUGIN_TEXT_DOMAIN);?>"
25
  style="float: left; display: block;" data-bind="disable: loading, click: cleanRefresh"/>
26
  <span class="ajaxLoaderWrapper" style="float: left; display: block; width: 20px; height: 20px; padding: 7px 7px;"><img/></span>
27
  </div>
28
  </div>
29
  <div class="alignleft actions" style="overflow: hidden;">
30
+ <label class="alignleft" style="margin: 5px 5px 0 0;"><?php echo __('Number of events per page:',WPPH_PLUGIN_TEXT_DOMAIN);?></label>
31
  <select name="actionLimit1" class="actionLimit" data-bind="options: availablePageSize, value: selectedPageSize"></select>
32
  <input type="button" value="Apply" class="button action" data-bind="disable: loading, click: applyPageSize">
33
  </div>
70
  </tr>
71
  </tfoot>
72
  <tbody id="the-list">
73
+ <tr data-bind="if: events().length == 0"><td style="padding: 4px !important;" colspan="7"><?php echo __('No events',WPPH_PLUGIN_TEXT_DOMAIN);?></td></tr>
74
  <!-- ko foreach: events -->
75
  <tr data-bind="css: {'row-0': ($index() % 2) == 0, 'row-1': ($index() % 2) != 0}">
76
  <td class="column-event_number"><span data-bind="text: eventNumber"></span></td>
88
  <div class="tablenav top" style="overflow: hidden; padding: 4px 0;">
89
  <div class="alignleft">
90
  <div style="overflow: hidden;">
91
+ <input type="button" class="buttonRefreshEventsList button" value="<?php echo __('Refresh Events List',WPPH_PLUGIN_TEXT_DOMAIN);?>"
92
  style="float: left; display: block;" data-bind="disable: loading, click: cleanRefresh"/>
93
  <span class="ajaxLoaderWrapper" style="float: left; display: block; width: 20px; height: 20px; padding: 7px 7px;"><img/></span>
94
  </div>
95
  </div>
96
  <div class="alignleft actions" style="overflow: hidden;">
97
+ <label class="alignleft" style="margin: 5px 5px 0 0;"><?php echo __('Number of events per page:',WPPH_PLUGIN_TEXT_DOMAIN);?></label>
98
  <select name="actionLimit1" class="actionLimit" data-bind="options: availablePageSize, value: selectedPageSize"></select>
99
  <input type="button" value="Apply" class="button action" data-bind="disable: loading, click: applyPageSize">
100
  </div>
pages/settings.php CHANGED
@@ -2,269 +2,319 @@
2
  <?php
3
  if(! WPPH::ready())
4
  {
5
- $errors = WPPH::getPLuginErrors();
6
- foreach($errors as $k =>$v) { call_user_func(array('WPPHAdminNotices',$k),$v); }
7
-
 
8
  echo '<div id="wpph-pageWrapper" class="wrap">';
9
- echo '<p>We have encountered some errors during the installation of the plugin which you can find above.</p>';
10
- echo '<p>Please try to correct them and then reactivate the plugin.</p>';
11
  echo '</div>';
12
  return;
13
  }
14
  ?>
15
  <?php
16
-
17
- //#! defaults
18
  $opt = WPPH::getPluginSettings();
19
  $daysInput = 0;
20
  $eventsNumber = 0;
21
- $showEventsViewList = 50;
22
-
23
- if(!empty($opt->daysToKeep)){
24
- $daysInput = $opt->daysToKeep;
25
- }
26
- if(! empty($opt->eventsToKeep)){
27
- $eventsNumber = $opt->eventsToKeep;
28
- }
29
- if(! empty($opt->showEventsViewList)){
30
- $showEventsViewList = $opt->showEventsViewList;
31
- }
32
-
33
- //#! end defaults
34
-
35
  $validationMessage = array();
36
- //#! If post : section #1
37
- if ( !empty($_POST['wpph_update_settings_field']) )
 
 
 
 
 
 
 
38
  {
39
- if(isset($_POST['wpph_update_settings_field'])){
40
- if(!wp_verify_nonce($_POST['wpph_update_settings_field'],'wpph_update_settings')){
41
- wp_die(__('Invalid request.'));
 
42
  }
43
  }
44
- else {wp_die(__('Invalid request.'));}
45
 
46
- // validate fields
47
- $section = intval($_POST['sectionInputField']);
48
- if(! in_array($section, array(1,2))){
49
- $validationMessage['error'] = __('Error: Invalid form. Please try again.');
50
- }
 
51
 
52
- //#! get settings
53
- $daysInput = $eventsNumber = 0;
54
- $eventsNumber = 10000; // default
55
- $opt = WPPH::getPluginSettings();
56
- if($section == 1)
57
  {
58
- if(empty($_POST['daysInput'])){
59
- $validationMessage['error'] = __('Error: Invalid form. Please try again.');
 
 
 
 
60
  $hasErrors = true;
61
  }
62
- else
63
- {
64
- $daysInput = intval($_POST['daysInput']);
65
-
66
- if($daysInput == 0){
67
- $validationMessage['error'] = __('Please input the number of days.');
68
- $hasErrors = true;
69
- }
70
- elseif($daysInput > 365){
71
- $validationMessage['error'] = __('Incorrect number of days. Please specify a value between 1 and 365.');
72
- $hasErrors = true;
73
- }
74
-
75
- if(! $hasErrors)
76
- {
77
  // reset events number
78
  if(isset($opt->eventsToKeep)){
79
  $opt->eventsToKeep = 0;
80
  }
81
- $opt->daysToKeep = $daysInput;
82
  }
83
  }
84
  }
85
- elseif($section == 2)
86
  {
87
- if(empty($_POST['eventsNumberInput'])){
88
- $validationMessage['error'] = __('Error: Invalid form. Please try again.');
 
 
 
 
89
  $hasErrors = true;
90
  }
91
- else
92
- {
93
- $eventsNumber = intval($_POST['eventsNumberInput']);
94
-
95
- if($eventsNumber == 0){
96
- $validationMessage['error'] = __('Please input the number of events to keep.');
97
- $hasErrors = true;
98
- }
99
- elseif($eventsNumber > 10000){
100
- $validationMessage['error'] = __('Incorrect number of events. Please specify a value between 1 and 10,000.');
101
- $hasErrors = true;
102
- }
103
-
104
- if(! $hasErrors)
105
- {
106
- // reset days
107
- if(isset($opt->daysToKeep)){
108
- $opt->daysToKeep = 0;
109
- }
110
- $opt->eventsToKeep = $eventsNumber;
111
  }
 
112
  }
113
  }
114
- else { $validationMessage['error'] = __('Error: Invalid form. Please try again.'); }
115
 
 
 
 
 
116
 
117
- if(! $hasErrors)
 
118
  {
 
119
  $opt->cleanupRan = 0;
120
  WPPH::updatePluginSettings($opt,null,null,true);
121
- $validationMessage['success'] = __('Your settings have been saved.');
122
-
123
- //#! get updated settings
124
- $opt = WPPH::getPluginSettings();
125
- $daysInput = $opt->daysToKeep;
126
- $eventsNumber = $opt->eventsToKeep;
127
  }
128
  }
129
- //#! end $post
130
  ?>
131
  <div id="wpph-pageWrapper" class="wrap">
132
- <h2 class="pageTitle pageTitle-settings"><?php echo __('Settings');?></h2>
133
 
134
- <div style="width:48%; margin: 30px 0 0 0; float: left;" class="inner-sidebar1 postbox">
135
- <h3 class="hndle" style="padding: 5px 5px; font-size: 15px;"><span><strong><?php echo __('Events Auto Deletion');?></strong></span></h3>
136
- <div class="inside">
137
- <?php if(! empty($validationMessage)) : ?>
138
- <?php
139
- if(!empty($validationMessage['error'])){
140
- echo '<div id="errMessage" class="error-info-icon" style="display: block;">'.$validationMessage['error'].'</div>';
141
- }
142
- else { echo '<div id="errMessage" class="success-info-icon" style="display: block;">'.$validationMessage['success'].'</div>'; }
143
- ?>
144
- <?php else : ?>
145
- <div id="errMessage" class="error-info-icon" style="display: none;"></div>
146
- <?php endif;?>
147
- <div style="margin: 5px 10px 0 10px; background: #fafafa; padding: 1px 10px;">
148
- <p><?php echo __('From this section you can configure the retention of the WordPress event logs. If no option is configured, all the event logs will be kept.');?></p>
149
- </div>
150
- <div style="padding: 10px 10px">
151
- <form id="updateOptionsForm" method="post">
152
- <?php wp_nonce_field('wpph_update_settings','wpph_update_settings_field'); ?>
153
- <div id="section1" class="form-section">
154
- <input type="radio" id="option1" class="radioInput" name="options[]" value="e1" style="margin-top: 0;" checked="checked"/>
155
- <label for="option1"><?php echo __('Delete events older than');?></label>
156
- <input type="text" id="daysInput" name="daysInput" maxlength="3"
157
- placeholder="<?php echo __('(1 to 365)');?>"
158
- value="<?php if(! empty($daysInput)) { echo $daysInput; } ;?>"/>
159
- <span> <?php echo __('(1 to 365 days)');?></span>
160
- </div>
161
- <div id="section2" class="form-section">
162
- <input type="radio" id="option2" class="radioInput" name="options[]" value="e2" style="margin-top: 0;"/>
163
- <label for="option2"><?php echo __('Keep up to');?></label>
164
- <input type="text" id="eventsNumberInput" name="eventsNumberInput" maxlength="6"
165
- placeholder="<?php echo __('1 to 10,000');?>"
166
- value="<?php if(! empty($eventsNumber)) { echo $eventsNumber; } ;?>"/>
167
- <span> <?php echo __('(1 to 10,000 events)');?></span>
168
- </div>
169
- <div class="form-section"><input type="submit" id="submitButton" class="button" value="<?php echo __('Save settings');?>"/></div>
170
- <input type="hidden" id="sectionInputField1" name="sectionInputField"/>
171
- </form>
172
- </div>
173
- </div>
174
- <script type="text/javascript">
175
- jQuery(document).ready(function($){
176
- var showErrorMessage = function(msg){
177
- var errWrapper = $('#errMessage');
178
- errWrapper.html("Error: "+msg).show();
179
- };
180
- var hideErrorMessage = function(){ $('#errMessage').hide(); };
181
- var setFocusOn = function($e){
182
- $e.focus();
183
- $e.select();
184
- };
185
 
186
- $('#updateOptionsForm :input').click(function(){ hideErrorMessage(); });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
 
188
- //#! select the radio input to check
189
- <?php if(! empty($daysInput)){ ?>
190
- $('#option1').attr('checked', 'checked');
191
- <?php } elseif(! empty($eventsNumber)){ ?>
192
- $('#option2').attr('checked', 'checked');
193
- <?php };?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
 
195
- // select radio on input click
196
- $('#daysInput').click(function(){ $('#option1').attr('checked', 'checked'); });
197
- $('#eventsNumberInput').click(function(){ $('#option2').attr('checked', 'checked'); });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
 
199
- $('#updateOptionsForm').submit(function()
200
- {
201
- var section = 0;
202
- if ($('#option1').attr('checked') == 'checked'){section = 1;}
203
- else { section = 2; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
 
205
- // validate fields
206
- if(section == 1)
207
- {
208
- var $daysInput = $('#daysInput'),
209
- daysInputVal = $daysInput.val();
 
 
 
 
 
 
 
 
 
210
 
211
- if(daysInputVal.length == 0){
212
- showErrorMessage("<?php echo __('Please input the number of days.');?>");
213
- setFocusOn($daysInput);
214
- return false;
215
- }
216
- if(daysInputVal == 0){
217
- showErrorMessage("<?php echo __('Please input a number greater than 0.');?>");
218
- setFocusOn($daysInput);
219
- return false;
220
- }
221
- if(!/^\d+$/.test(daysInputVal)){
222
- showErrorMessage("<?php echo __('Only numbers greater than 0 allowed.');?>");
223
- setFocusOn($daysInput);
224
- return false;
225
- }
226
- if(daysInputVal > 365){
227
- showErrorMessage("<?php echo __('Incorrect number of days. Please specify a value between 1 and 365.');?>");
228
- setFocusOn($daysInput);
229
- return false;
230
- }
231
- }
232
- else if(section == 2)
233
- {
234
- var $eventsNumberInput = $('#eventsNumberInput'),
235
- eniVal = $eventsNumberInput.val();
236
 
237
- if(eniVal.length == 0){
238
- showErrorMessage("<?php echo __('Please input the number of events.');?>");
239
- setFocusOn($eventsNumberInput);
240
- return false;
241
- }
242
- if(eniVal == 0){
243
- showErrorMessage("<?php echo __('Please input a number greater than 0.');?>");
244
- setFocusOn($eventsNumberInput);
245
- return false;
246
- }
247
- if(!/^\d+$/.test(eniVal)){
248
- showErrorMessage("<?php echo __('Only numbers greater than 0 allowed.');?>");
249
- setFocusOn($eventsNumberInput);
250
- return false;
251
- }
252
- if(eniVal > 500000){
253
- showErrorMessage("<?php echo __('Incorrect number of events. Please specify a value between 1 and 10,000.');?>");
254
- setFocusOn($eventsNumberInput);
255
- return false;
256
- }
257
- }
258
- $('#sectionInputField1').val(section);
259
 
260
- //#! clear the other section
261
- if(section == 1){ $('#eventsNumberInput').val(''); }
262
- else if(section == 2){ $('#daysInput').val(''); }
 
 
 
263
 
264
- return true;
265
- });
266
- });
267
- </script>
268
- </div>
269
- <br class="clear"/>
270
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  <?php
3
  if(! WPPH::ready())
4
  {
5
+ $errors = WPPH::getPluginErrors();
6
+ foreach($errors as $error) {
7
+ wpph_adminNotice($error);
8
+ }
9
  echo '<div id="wpph-pageWrapper" class="wrap">';
10
+ echo '<p>'.__('We have encountered some errors during the installation of the plugin which you can find above.',WPPH_PLUGIN_TEXT_DOMAIN).'</p>';
11
+ echo '<p>'.__('Please try to correct them and then reactivate the plugin.',WPPH_PLUGIN_TEXT_DOMAIN).'</p>';
12
  echo '</div>';
13
  return;
14
  }
15
  ?>
16
  <?php
17
+ // defaults
 
18
  $opt = WPPH::getPluginSettings();
19
  $daysInput = 0;
20
  $eventsNumber = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  $validationMessage = array();
22
+ $hasErrors = false;
23
+ $showDW = (empty($opt->showDW) ? false : true);
24
+ // active delete option for events
25
+ if(!empty($opt->daysToKeep)){ $daysInput = $opt->daysToKeep; $activeOption = 1; }
26
+ if(! empty($opt->eventsToKeep)){ $eventsNumber = $opt->eventsToKeep; $activeOption = 2; }
27
+ // end defaults
28
+
29
+ $rm = strtoupper($_SERVER['REQUEST_METHOD']);
30
+ if('POST' == $rm)
31
  {
32
+ // Check nonce
33
+ if(isset($_POST['wpph_update_settings_field_nonce'])){
34
+ if(!wp_verify_nonce($_POST['wpph_update_settings_field_nonce'],'wpph_update_settings')){
35
+ wp_die('Invalid request');
36
  }
37
  }
38
+ else {wp_die('Invalid request');}
39
 
40
+ // method to use
41
+ if(! isset($_POST['deleteEventsBy'])){ wp_die('Invalid request'); }
42
+ // value to use
43
+ if(! isset($_POST['deleteEventsValue'])){ wp_die('Invalid request'); }
44
+ $deleteEventsBy = intval($_POST['deleteEventsBy']);
45
+ $deleteEventsValue = intval($_POST['deleteEventsValue']);
46
 
47
+ // if Delete events older than ... days
48
+ if($deleteEventsBy == 1)
 
 
 
49
  {
50
+ $activeOption = 1;
51
+ $daysInput = $deleteEventsValue;
52
+
53
+ // Validate
54
+ if(!preg_match('/^\d+$/',$deleteEventsValue)){
55
+ $validationMessage['error'] = __('Incorrect number of days. Please specify a value between 1 and 365.',WPPH_PLUGIN_TEXT_DOMAIN);
56
  $hasErrors = true;
57
  }
58
+ elseif($deleteEventsValue < 1 || $deleteEventsValue > 365){
59
+ $validationMessage['error'] = __('Incorrect number of days. Please specify a value between 1 and 365.',WPPH_PLUGIN_TEXT_DOMAIN);
60
+ $hasErrors = true;
61
+ }
62
+ else {
63
+ if(! $hasErrors){
 
 
 
 
 
 
 
 
 
64
  // reset events number
65
  if(isset($opt->eventsToKeep)){
66
  $opt->eventsToKeep = 0;
67
  }
68
+ $opt->daysToKeep = $deleteEventsValue;
69
  }
70
  }
71
  }
72
+ elseif($deleteEventsBy == 2)
73
  {
74
+ $activeOption = 2;
75
+ $eventsNumber = $deleteEventsValue;
76
+
77
+ // Validate
78
+ if(!preg_match('/^\d+$/',$deleteEventsValue)){
79
+ $validationMessage['error'] = sprintf(__('Incorrect number of events. Please specify a value between 1 and %d.',WPPH_PLUGIN_TEXT_DOMAIN), WPPH_KEEP_MAX_EVENTS);
80
  $hasErrors = true;
81
  }
82
+ elseif($deleteEventsValue < 1 || $deleteEventsValue > WPPH_KEEP_MAX_EVENTS){
83
+ $validationMessage['error'] = sprintf(__('Incorrect number of events. Please specify a value between 1 and %d.',WPPH_PLUGIN_TEXT_DOMAIN), WPPH_KEEP_MAX_EVENTS);
84
+ $hasErrors = true;
85
+ }
86
+ else {
87
+ // reset days
88
+ if(isset($opt->daysToKeep)){
89
+ $opt->daysToKeep = 0;
 
 
 
 
 
 
 
 
 
 
 
 
90
  }
91
+ $opt->eventsToKeep = $deleteEventsValue;
92
  }
93
  }
 
94
 
95
+ // dashboard widget
96
+ if(isset($_POST['optionDW'])){
97
+ $showDW = intval($_POST['optionDW']);
98
+ }
99
 
100
+ // save options
101
+ if(!$hasErrors)
102
  {
103
+ $opt->showDW = (empty($showDW) ? 0 : 1);
104
  $opt->cleanupRan = 0;
105
  WPPH::updatePluginSettings($opt,null,null,true);
106
+ $validationMessage['success'] = __('Your settings have been saved.',WPPH_PLUGIN_TEXT_DOMAIN);
 
 
 
 
 
107
  }
108
  }
109
+ // end $post
110
  ?>
111
  <div id="wpph-pageWrapper" class="wrap">
112
+ <h2 class="pageTitle pageTitle-settings"><?php echo __('WP Security Audit Log Settings',WPPH_PLUGIN_TEXT_DOMAIN);?></h2>
113
 
114
+ <?php if(! empty($validationMessage)) : ?>
115
+ <?php
116
+ if(!empty($validationMessage['error'])){ wpph_adminNotice($validationMessage['error']); }
117
+ else { wpph_adminUpdate($validationMessage['success']); }
118
+ ?>
119
+ <?php else : ?>
120
+ <div id="errMessage" style="display: none;"></div>
121
+ <?php endif;?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
+ <div style="margin: 20px 0;">
124
+ <form id="updateSettingsForm" method="post">
125
+ <?php wp_nonce_field('wpph_update_settings','wpph_update_settings_field_nonce'); ?>
126
+ <div id="eventsDeletion">
127
+ <div id="section-holder">
128
+ <table cellspacing="0" cellpadding="0" class="form-table">
129
+ <tbody>
130
+ <tr valign="top">
131
+ <td rowspan="4" class="section-left">
132
+ <label style="display:block;margin: 30px 0 0 0;"><?php echo __('Security Alerts Pruning',WPPH_PLUGIN_TEXT_DOMAIN);?></label>
133
+ </td>
134
+ </tr>
135
+ <tr>
136
+ <td class="section-right">
137
+ <p>
138
+ <input type="radio" id="option1" class="radioInput" style="margin-top: 2px;"/>
139
+ <label for="option1"><?php echo __('Delete alerts older than',WPPH_PLUGIN_TEXT_DOMAIN);?></label>
140
+ <input type="text" id="daysInput" maxlength="3"
141
+ placeholder="<?php echo __('(1 to 365)',WPPH_PLUGIN_TEXT_DOMAIN);?>"
142
+ value="<?php if(! empty($daysInput)) { echo $daysInput; } ;?>"/>
143
+ <span> <?php echo __('(1 to 365 days)',WPPH_PLUGIN_TEXT_DOMAIN);?></span>
144
+ </p>
145
+ </td>
146
+ </tr>
147
+ <tr>
148
+ <td class="section-right">
149
+ <p>
150
+ <?php $wpph_t1 = sprintf(__('(1 to %d alerts)',WPPH_PLUGIN_TEXT_DOMAIN),WPPH_KEEP_MAX_EVENTS); ?>
151
+ <input type="radio" id="option2" class="radioInput" style="margin-top: 2px;"/>
152
+ <label for="option2"><?php echo __('Keep up to',WPPH_PLUGIN_TEXT_DOMAIN);?></label>
153
+ <input type="text" id="eventsNumberInput" maxlength="6"
154
+ placeholder="<?php echo $wpph_t1;?>"
155
+ value="<?php if(! empty($eventsNumber)) { echo $eventsNumber; } ;?>"/>
156
+ <span> <?php echo $wpph_t1;?></span>
157
+ </p>
158
+ </td>
159
+ </tr>
160
+ <tr>
161
+ <td class="section-right"><p class="description"><?php echo sprintf(__('By default %s will keep up to %d WordPress Security Events.',WPPH_PLUGIN_TEXT_DOMAIN),WPPH_PLUGIN_NAME, WPPH_KEEP_MAX_EVENTS);?></p></td>
162
+ </tr>
163
+ <tr><td style="height: 10px;"></td></tr>
164
+ <tr>
165
+ <td rowspan="2" class="section-left"><label><?php echo __('Security Alerts Dashboard Widget',WPPH_PLUGIN_TEXT_DOMAIN);?></label></td>
166
+ </tr>
167
+ <tr>
168
+ <td class="section-right">
169
+ <input type="radio" id="optionDW_on" class="radioInput" style="margin-top: 2px;"/><label for="optionDW_on" style="padding-top: 5px; padding-left: 3px;"><?php echo __('On',WPPH_PLUGIN_TEXT_DOMAIN);?></label>
170
+ <input type="radio" id="optionDW_off" class="radioInput" style="margin-top: 2px;"/><label for="optionDW_off" style="padding-top: 5px; padding-left: 3px;"><?php echo __('Off',WPPH_PLUGIN_TEXT_DOMAIN);?></label>
171
+ </td>
172
+ </tr>
173
+ </tbody>
174
+ </table>
175
+ </div>
176
+ </div>
177
+ <p style="margin-top: 40px;">
178
+ <input type="submit" id="submitButton" class="button button-primary" value="<?php echo __('Save settings',WPPH_PLUGIN_TEXT_DOMAIN);?>"/>
179
+ </p>
180
+ <input type="hidden" id="deleteEventsBy" name="deleteEventsBy" value=""/>
181
+ <input type="hidden" id="deleteEventsValue" name="deleteEventsValue" value=""/>
182
+ <input type="hidden" id="optionDW" name="optionDW" value=""/>
183
+ </form>
184
+ </div>
185
+ </div>
186
+ <br class="clear"/>
187
 
188
+ <script type="text/javascript">
189
+ jQuery(document).ready(function($){
190
+ var showErrorMessage = function(msg){
191
+ $('#errMessage').removeClass('updated').addClass('error').html("<p>Error: "+msg+"</p>").show();
192
+ };
193
+ var setFocusOn = function($e){
194
+ $e.focus();
195
+ $e.select();
196
+ };
197
+ var validateDeleteOptions = function(section, $daysInput, $eventsNumberInput)
198
+ {
199
+ if(section == 0){
200
+ showErrorMessage("<?php echo __('Invalid form. Please reload the page and try again.',WPPH_PLUGIN_TEXT_DOMAIN);?>");
201
+ setFocusOn($daysInput);
202
+ return false;
203
+ }
204
+ // validate fields
205
+ if(section == 1)
206
+ {
207
+ var daysInputVal = $daysInput.val();
208
 
209
+ if(daysInputVal.length == 0){
210
+ showErrorMessage("<?php echo __('Please input the number of days.',WPPH_PLUGIN_TEXT_DOMAIN);?>");
211
+ setFocusOn($daysInput);
212
+ return false;
213
+ }
214
+ if(daysInputVal == 0){
215
+ showErrorMessage("<?php echo __('Please input a number greater than 0.',WPPH_PLUGIN_TEXT_DOMAIN);?>");
216
+ setFocusOn($daysInput);
217
+ return false;
218
+ }
219
+ if(!/^\d+$/.test(daysInputVal)){
220
+ showErrorMessage("<?php echo __('Only numbers greater than 0 allowed.',WPPH_PLUGIN_TEXT_DOMAIN);?>");
221
+ setFocusOn($daysInput);
222
+ return false;
223
+ }
224
+ if(daysInputVal > 365){
225
+ showErrorMessage("<?php echo __('Incorrect number of days. Please specify a value between 1 and 365.',WPPH_PLUGIN_TEXT_DOMAIN);?>");
226
+ setFocusOn($daysInput);
227
+ return false;
228
+ }
229
+ }
230
+ else if(section == 2)
231
+ {
232
+ var eniVal = $eventsNumberInput.val();
233
 
234
+ if(eniVal.length == 0){
235
+ showErrorMessage("<?php echo __('Please input the number of alerts.',WPPH_PLUGIN_TEXT_DOMAIN);?>");
236
+ setFocusOn($eventsNumberInput);
237
+ return false;
238
+ }
239
+ if(eniVal == 0){
240
+ showErrorMessage("<?php echo __('Please input a number greater than 0.',WPPH_PLUGIN_TEXT_DOMAIN);?>");
241
+ setFocusOn($eventsNumberInput);
242
+ return false;
243
+ }
244
+ if(!/^\d+$/.test(eniVal)){
245
+ showErrorMessage("<?php echo __('Only numbers greater than 0 allowed.',WPPH_PLUGIN_TEXT_DOMAIN);?>");
246
+ setFocusOn($eventsNumberInput);
247
+ return false;
248
+ }
249
+ if(eniVal > <?php echo WPPH_KEEP_MAX_EVENTS;?>){
250
+ showErrorMessage("<?php echo sprintf(__('Incorrect number of alerts. Please specify a value between 1 and %d.',WPPH_PLUGIN_TEXT_DOMAIN),WPPH_KEEP_MAX_EVENTS);?>");
251
+ setFocusOn($eventsNumberInput);
252
+ return false;
253
+ }
254
+ }
255
+ return true;
256
+ };
257
 
258
+ var deb = $('#deleteEventsBy')
259
+ ,debv = $('#deleteEventsValue')
260
+ ,option1 = $('#option1')
261
+ ,option2 = $('#option2')
262
+ ,daysInput = $('#daysInput')
263
+ ,eventsNumber = $('#eventsNumberInput')
264
+ ,showDW = $('#optionDW_on')
265
+ ,hideDW = $('#optionDW_off');
266
+ option1.on('click', function(){ option2.removeAttr('checked'); $(this).attr('checked','checked'); setFocusOn(daysInput); });
267
+ option2.on('click', function(){ option1.removeAttr('checked'); $(this).attr('checked','checked'); setFocusOn(eventsNumber); });
268
+ daysInput.on('click', function(){ option2.removeAttr('checked'); option1.attr('checked','checked'); });
269
+ eventsNumber.on('click', function(){ option1.removeAttr('checked'); option2.attr('checked','checked'); });
270
+ showDW.on('click', function(){ hideDW.removeAttr('checked'); $(this).attr('checked','checked'); setFocusOn($(this)); });
271
+ hideDW.on('click', function(){ showDW.removeAttr('checked'); $(this).attr('checked','checked'); setFocusOn($(this)); });
272
 
273
+ // select delete option
274
+ <?php if($activeOption == 1):?>
275
+ option1.attr('checked','checked');
276
+ eventsNumber.val("");
277
+ <?php else :?>
278
+ option2.attr('checked','checked');
279
+ daysInput.val("");
280
+ <?php endif; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
 
282
+ //select DW
283
+ <?php if($showDW):?>
284
+ showDW.attr('checked','checked');
285
+ <?php else :?>
286
+ hideDW.attr('checked','checked');
287
+ <?php endif;?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
 
289
+ // form submit
290
+ $('#submitButton').on('click',function()
291
+ {
292
+ var section = 0;
293
+ if ($('#option1').prop('checked')){section = 1;}
294
+ else { section = 2; }
295
 
296
+ if(section < 1){
297
+ alert("<?php echo __('Invalid form. Please refresh the page and try again.',WPPH_PLUGIN_TEXT_DOMAIN);?>");
298
+ return false;
299
+ }
300
+ if(! validateDeleteOptions(section, daysInput, eventsNumber)){
301
+ return false;
302
+ }
303
+ // alerts pruning
304
+ if(section == 1){
305
+ deb.val(1);
306
+ debv.val(daysInput.val());
307
+ }
308
+ else if(section ==2){
309
+ deb.val(2);
310
+ debv.val(eventsNumber.val());
311
+ }
312
+ // dashboard widget
313
+ if(showDW.prop('checked')){
314
+ $('#optionDW').val('1');
315
+ }
316
+ else { $('#optionDW').val('0') }
317
+ return true;
318
+ });
319
+ });
320
+ </script>
pages/support.php CHANGED
@@ -3,21 +3,22 @@
3
  <?php
4
  if(! WPPH::ready())
5
  {
6
- $errors = WPPH::getPLuginErrors();
7
- foreach($errors as $k =>$v) { call_user_func(array('WPPHAdminNotices',$k),$v); }
8
-
 
9
  echo '<div id="wpph-pageWrapper" class="wrap">';
10
- echo '<p>We have encountered some errors during the installation of the plugin which you can find above.</p>';
11
- echo '<p>Please try to correct them and then reactivate the plugin.</p>';
12
  echo '</div>';
13
  return;
14
  }
15
  ?>
16
  <div id="wpph-pageWrapper" class="wrap">
17
- <h2 class="pageTitle pageTitle-support"><?php echo __('Support');?></h2>
18
  <div>
19
  <p><?php echo
20
- sprintf(__('Thank you for showing interest and using our plugin. If you encounter any issues running this plugin, or have suggestions or queries, please get in touch with us on %s.'),
21
  '<a href="mailto:plugins@wpwhitesecurity.com">plugins@wpwhitesecurity.com</a>');?></p>
22
  </div>
23
  </div>
3
  <?php
4
  if(! WPPH::ready())
5
  {
6
+ $errors = WPPH::getPluginErrors();
7
+ foreach($errors as $error) {
8
+ wpph_adminNotice($error);
9
+ }
10
  echo '<div id="wpph-pageWrapper" class="wrap">';
11
+ echo '<p>'.__('We have encountered some errors during the installation of the plugin which you can find above.',WPPH_PLUGIN_TEXT_DOMAIN).'</p>';
12
+ echo '<p>'.__('Please try to correct them and then reactivate the plugin.',WPPH_PLUGIN_TEXT_DOMAIN).'</p>';
13
  echo '</div>';
14
  return;
15
  }
16
  ?>
17
  <div id="wpph-pageWrapper" class="wrap">
18
+ <h2 class="pageTitle pageTitle-support"><?php echo __('Support',WPPH_PLUGIN_TEXT_DOMAIN);?></h2>
19
  <div>
20
  <p><?php echo
21
+ sprintf(__('Thank you for showing interest and using our plugin. If you encounter any issues running this plugin, or have suggestions or queries, please get in touch with us on %s.',WPPH_PLUGIN_TEXT_DOMAIN),
22
  '<a href="mailto:plugins@wpwhitesecurity.com">plugins@wpwhitesecurity.com</a>');?></p>
23
  </div>
24
  </div>
readme.txt CHANGED
@@ -5,7 +5,7 @@ License URI: http://www.gnu.org/licenses/gpl.html
5
  Tags: wordpress security plugin, wordpress security audit log, audit log, event log wordpress, wordpress user tracking, wordpress activity log, wordpress audit, security event log, audit trail, security audit trail, wordpress security alerts, wordpress monitor, wordpress security monitor
6
  Requires at least: 3.0
7
  Tested up to: 3.6.1
8
- Stable tag: 0.3
9
 
10
  Identify WordPress security issues before they become a problem. Keep an audit log of everything that happens on WordPress including WordPress user activity.
11
 
@@ -62,18 +62,50 @@ For more information and to get started with WordPress Security, check out the f
62
 
63
  = How can I prune WordPress security events? =
64
 
65
- By default the plugin will keep up to 10,000 events. When this limit is reached, older events are deleted to make place for the new ones. You can configure the plugin to keep more events from the settings page. You can also configure the plugin to delete events which are older than a number of days.
66
 
67
  = Is there a complete list of all WordPress security audit events? =
68
  Yes. A complete list can be found [here](http://www.wpwhitesecurity.com/wordpress-security-plugins/wp-security-audit-log/security-audit-event-logs/)
69
 
 
 
 
 
70
  == Screenshots ==
71
 
72
  1. The Audit Log Viewer from where the WordPress administrator can see all the security events generated by WP Security Audit Log WordPress plugin.
73
- 2. The Auto Prune Security Events settings which the WordPress administrator can configure the auto deletion of security events.
 
74
 
75
  == Changelog ==
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  = 0.3 =
78
 
79
  * New WordPress Security Alerts
@@ -92,7 +124,7 @@ Yes. A complete list can be found [here](http://www.wpwhitesecurity.com/wordpres
92
  * Bug Fixes
93
  * Fixed: Incorrect alerts generated when author of page was changed from quick edit mode
94
  * Fixed: Conflict with WP Mandrill and other plugins using pluggable.php
95
- * Fixed: Incorrect alerts generated when plugin is installed via a zip file / upload method
96
 
97
  = 0.2 =
98
 
5
  Tags: wordpress security plugin, wordpress security audit log, audit log, event log wordpress, wordpress user tracking, wordpress activity log, wordpress audit, security event log, audit trail, security audit trail, wordpress security alerts, wordpress monitor, wordpress security monitor
6
  Requires at least: 3.0
7
  Tested up to: 3.6.1
8
+ Stable tag: 0.4
9
 
10
  Identify WordPress security issues before they become a problem. Keep an audit log of everything that happens on WordPress including WordPress user activity.
11
 
62
 
63
  = How can I prune WordPress security events? =
64
 
65
+ By default the plugin will keep 5,000 events. When this limit is reached, older events are deleted to make place for the new ones. You can configure the plugin to keep more events from the settings page. You can also configure the plugin to delete events which are older than a number of days.
66
 
67
  = Is there a complete list of all WordPress security audit events? =
68
  Yes. A complete list can be found [here](http://www.wpwhitesecurity.com/wordpress-security-plugins/wp-security-audit-log/security-audit-event-logs/)
69
 
70
+ = Can I disable some WordPress security alerts? =
71
+
72
+ Yes it is possible to disable (and re-enable later) specific WordPress security alerts. To do so navigate to the Enable/Disable Alerts node in the plugin, select the category tab and untick the WordPress security alert. Tick back the alert to re-enable it.
73
+
74
  == Screenshots ==
75
 
76
  1. The Audit Log Viewer from where the WordPress administrator can see all the security events generated by WP Security Audit Log WordPress plugin.
77
+ 2. The WP Security Audit Log plugin options from where WordPress administrator can configure the auto pruning of security alerts.
78
+ 3. The Enable/Disable Alerts settings node from where Administrators can disable or enable WordPress security alerts.
79
 
80
  == Changelog ==
81
 
82
+
83
+ = 0.4 =
84
+ * New WordPress Security Alerts for Custom Post Types
85
+ * Alert 2029: New post with custom post type created and saved as draft
86
+ * Alert 2030: Post with custom post type is publishes
87
+ * Alert 2031: A published post with custom post type is modified
88
+ * Alert 2032: A draft post with custom post type is modified
89
+ * Alert 2033: A post with custom post type was permanently deleted
90
+ * Alert 2034: A post with custom post type was moved to trash
91
+ * Alert 2035: A post with custom post type was restored from trash
92
+ * Alert 2036: The category of a post with custom post type was changed
93
+ * Alert 2037: The URL of a post with custom post type was changed
94
+ * Alert 2038: The author of a post with custom post type was changed
95
+ * Alert 2039: The status of a post with custom post type was changed
96
+ * Alert 2040: The visibility of a post with custom post type was changed
97
+ * Alert 2041: The date of a post with custom post type was changed
98
+
99
+ * New Plugin Features
100
+ * Enable/Disable Alerts node that allows WordPress administrators to switch on or off specific WordPress security alerts
101
+ * Dashboard widget that shows the latest 5 WordPress security alerts (widget can be switched on or off from the plugin settings)
102
+ * Plugin is now language aware and we can accept translations
103
+
104
+ * Plugin Improvements
105
+ * Updated settings page to have the same look and feel of WordPress
106
+ * Improved the upgrade procedure of the plugin
107
+ * Updated the Audit Log Viewer display to support more resultions such as those of tables and smartphones
108
+
109
  = 0.3 =
110
 
111
  * New WordPress Security Alerts
124
  * Bug Fixes
125
  * Fixed: Incorrect alerts generated when author of page was changed from quick edit mode
126
  * Fixed: Conflict with WP Mandrill and other plugins using pluggable.php
127
+ * Fixed: Incorrect alerts generated when plugin is installed via a zip file / upload method
128
 
129
  = 0.2 =
130
 
res/css/styles.base.css CHANGED
@@ -10,9 +10,8 @@ h2.pageTitle-about { background: url("../img/page-about-logo.png") no-repeat lef
10
  #wpph-pageWrapper .buttonRefreshEventsList { margin-top: 3px;}
11
 
12
 
13
-
14
  /*
15
- * #! Page: Event Viewer
16
  */
17
  .column-left-align { text-align: left; }
18
  .column-center-align { text-align: center; }
@@ -25,7 +24,7 @@ h2.pageTitle-about { background: url("../img/page-about-logo.png") no-repeat lef
25
  #the-list span { padding: 5px 5px; line-height: normal !important; display: block; }
26
 
27
  /*
28
- * #! Page: Settings
29
  */
30
  .error-info-icon {
31
  padding: 5px 7px 5px 20px;
@@ -34,17 +33,39 @@ h2.pageTitle-about { background: url("../img/page-about-logo.png") no-repeat lef
34
  background: url("../img/error-icon.png") no-repeat left center;
35
  }
36
  .success-info-icon {
37
- padding: 5px 7px 5px 20px;
38
  margin-left: 8px;
39
  color: #000000;
40
  background: url("../img/success-icon.png") no-repeat left center;
41
  }
42
 
43
- .form-section { margin: 7px 0; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
 
 
 
 
45
 
46
  /*
47
- * #! Page: Events :: pagination
48
  */
49
  .paginationWrapper{
50
  overflow: hidden;
10
  #wpph-pageWrapper .buttonRefreshEventsList { margin-top: 3px;}
11
 
12
 
 
13
  /*
14
+ * Page: Event Viewer
15
  */
16
  .column-left-align { text-align: left; }
17
  .column-center-align { text-align: center; }
24
  #the-list span { padding: 5px 5px; line-height: normal !important; display: block; }
25
 
26
  /*
27
+ * Page: Settings, Alerts
28
  */
29
  .error-info-icon {
30
  padding: 5px 7px 5px 20px;
33
  background: url("../img/error-icon.png") no-repeat left center;
34
  }
35
  .success-info-icon {
36
+ padding: 5px 7px 5px 20px !important;
37
  margin-left: 8px;
38
  color: #000000;
39
  background: url("../img/success-icon.png") no-repeat left center;
40
  }
41
 
42
+ #section-holder { overflow: hidden; }
43
+ #section-holder p { margin: 15px 0; overflow: hidden; }
44
+ #section-holder p input[type="radio"] { float: left; margin-top: 5px !important; }
45
+ #section-holder p label, #section-holder p span { float: left; margin-top: 4px !important; margin-left: 10px !important; font-size: 12px !important; }
46
+ #section-holder p input[type="text"] { float: left; margin-left: 10px !important; }
47
+
48
+ .form-table td { line-height: normal !important;; }
49
+ .form-table td.section-left { width: 190px; padding: 0 30px 0 0; }
50
+ .form-table td.section-right p { padding: 0 0 !important; margin: 0 0 !important; }
51
+ .form-table td #optionDW_off { margin-left: 10px; }
52
+
53
+ #errMessage { margin: 20px 0; }
54
+ #eventsDeletion #description,
55
+ #optionsDescription #description {
56
+ background: none repeat scroll 0 0 #EEEEEE;
57
+ margin: 0 0 20px 0;
58
+ padding: 10px;
59
+ }
60
+ #optionsDescription #description { margin: 20px 0; }
61
 
62
+ .widefat .item-cb { width: 50px !important; }
63
+ .widefat .item-event { width: 100px !important; text-align: left; padding: 8px 7px 2px 7px !important; }
64
+ .widefat .item-type { width: 100px !important; text-align: left; padding: 8px 7px 2px 7px !important; }
65
+ .widefat .item-description { width: auto !important; text-align: left; padding: 8px 7px 2px 7px !important; }
66
 
67
  /*
68
+ * Page: Events :: pagination
69
  */
70
  .paginationWrapper{
71
  overflow: hidden;
res/js/audit-view-model.js CHANGED
@@ -55,12 +55,12 @@ var AuditLogViewModel = (function($) {
55
  function AuditLogViewModel()
56
  {
57
  this.columns = ko.observableArray([
58
- {columnHeader: 'Event', columnName: 'EventNumber', sortable: true, columnWidth: '80px', sorted: ko.observable(false), sortedDescending: ko.observable(false)},
59
- {columnHeader: 'ID', columnName: 'EventID', sortable: true, columnWidth: '80px', sorted: ko.observable(false), sortedDescending: ko.observable(false)},
60
- {columnHeader: 'Date', columnName: 'EventDate', sortable: true, columnWidth: '170px', sorted: ko.observable(false), sortedDescending: ko.observable(false)},
61
- {columnHeader: 'Type', columnName: 'EventType', sortable: true, columnWidth: '100px', sorted: ko.observable(false), sortedDescending: ko.observable(false)},
62
- {columnHeader: 'IP Address', columnName: 'UserIP', sortable: true, columnWidth: '130px', sorted: ko.observable(false), sortedDescending: ko.observable(false)},
63
- {columnHeader: 'User', columnName: 'UserID', sortable: true, columnWidth: '240px', sorted: ko.observable(false), sortedDescending: ko.observable(false)},
64
  {columnHeader: 'Description', columnName: 'EventDescription', sortable: false, columnWidth: 'auto', sorted: ko.observable(false), sortedDescending: ko.observable(false)}]);
65
 
66
  this.loading = ko.observable(false);
55
  function AuditLogViewModel()
56
  {
57
  this.columns = ko.observableArray([
58
+ {columnHeader: 'Event', columnName: 'EventNumber', sortable: true, columnWidth: '5%', sorted: ko.observable(false), sortedDescending: ko.observable(false)},
59
+ {columnHeader: 'ID', columnName: 'EventID', sortable: true, columnWidth: '5%', sorted: ko.observable(false), sortedDescending: ko.observable(false)},
60
+ {columnHeader: 'Date', columnName: 'EventDate', sortable: true, columnWidth: '11%', sorted: ko.observable(false), sortedDescending: ko.observable(false)},
61
+ {columnHeader: 'Type', columnName: 'EventType', sortable: true, columnWidth: '6%', sorted: ko.observable(false), sortedDescending: ko.observable(false)},
62
+ {columnHeader: 'IP Address', columnName: 'UserIP', sortable: true, columnWidth: '9%', sorted: ko.observable(false), sortedDescending: ko.observable(false)},
63
+ {columnHeader: 'User', columnName: 'UserID', sortable: true, columnWidth: '10%', sorted: ko.observable(false), sortedDescending: ko.observable(false)},
64
  {columnHeader: 'Description', columnName: 'EventDescription', sortable: false, columnWidth: 'auto', sorted: ko.observable(false), sortedDescending: ko.observable(false)}]);
65
 
66
  this.loading = ko.observable(false);
wp-security-audit-log.php CHANGED
@@ -4,9 +4,11 @@ Plugin Name: WP Security Audit Log
4
  Plugin URI: http://www.wpwhitesecurity.com/wordpress-security-plugins/wp-security-audit-log/
5
  Description: Identify WordPress security issues before they become a problem and keep track of everything happening on your WordPress, including WordPress users activity. Similar to Windows Event Log and Linux Syslog, WP Security Audit Log will generate a security alert for everything that happens on your WordPress blog or website. Use the Audit Log Viewer included in the plugin to see all the security alerts.
6
  Author: WP White Security
7
- Version: 0.3
8
  Author URI: http://www.wpwhitesecurity.com/
9
  License: GPL2
 
 
10
 
11
  WP Security Audit Log
12
  Copyright(c) 2013 Robert Abela (email : robert@wpwhitesecurity.com)
@@ -24,39 +26,26 @@ License: GPL2
24
  along with this program; if not, write to the Free Software
25
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
  */
27
- //#! Holds the plugin option name
28
- define('WPPH_PLUGIN_VERSION','0.3');
29
- define('WPPH_PLUGIN_VERSION_OPTION_NAME','WPPH_PLUGIN_VERSION');
30
- define('WPPH_PLUGIN_ERROR_OPTION_NAME','WPPH_PLUGIN_ERROR');
31
- define('WPPH_PLUGIN_SETTING_NAME', 'wpph_plugin_settings');
32
  define('WPPH_PLUGIN_PREFIX', 'wpph_');
33
  define('WPPH_PLUGIN_NAME', 'WP Security Audit Log');
34
  define('WPPH_PLUGIN_URL', trailingslashit(plugins_url('', __FILE__)));
35
  define('WPPH_PLUGIN_DIR', trailingslashit(plugin_dir_path(__FILE__)));
36
  if(defined('__DIR__')) { define('WPPH_PLUGIN_BASE_NAME', basename(__DIR__)); }
37
  else { define('WPPH_PLUGIN_BASE_NAME', basename(dirname(__FILE__))); }
38
- define('WPPH_PLUGIN_DB_UPDATED', 'WPPH_PLUGIN_DB_UPDATED');
39
- define('WPPH_PLUGIN_DEL_EVENTS_CRON_TASK_NAME', 'wpph_plugin_delete_events_cron');
40
- /** @since v0.3 */
41
- define('WPPH_USERS_CAN_REGISTER_OPT_NAME', 'wpph_users_can_register');
42
- /**
43
- * @since v0.3
44
- * @see WPPH::onPluginActivate()
45
- */
46
- $GLOBALS['WPPH_CAN_RUN'] = true;
47
-
48
 
49
- //#! Load required files
 
50
  require('inc/WPPHLogger.php');
51
  require('inc/WPPHUtil.php');
52
- require('inc/WPPHAdminNotices.php');
53
  require('inc/WPPHDatabase.php');
54
  require('inc/WPPHEvent.php');
 
55
  require('inc/WPPH.php');
56
  require('inc/wpphFunctions.php');
57
 
58
-
59
- //#! 2000
60
  $GLOBALS['WPPH_POST_IS_NEW'] = false;
61
  add_action('wp_insert_post', 'wpphPostDetectNew', 1, 2);
62
  function wpphPostDetectNew($post, $wp_error = false){
@@ -72,39 +61,38 @@ function wpphPostDetectNew($post, $wp_error = false){
72
  */
73
  function onPluginUninstall()
74
  {
75
- if(WPPH::optionExists(WPPH_PLUGIN_DB_UPDATED)){ delete_option(WPPH_PLUGIN_DB_UPDATED); }
76
- if(WPPH::optionExists(WPPH_PLUGIN_VERSION_OPTION_NAME)){ delete_option(WPPH_PLUGIN_VERSION_OPTION_NAME); }
77
- if(WPPH::optionExists(WPPH_USERS_CAN_REGISTER_OPT_NAME)){ delete_option(WPPH_USERS_CAN_REGISTER_OPT_NAME); }
78
  global $wpdb;
 
 
 
79
  $wpdb->query("DROP TABLE IF EXISTS ".WPPHDatabase::getFullTableName('main'));
80
  $wpdb->query("DROP TABLE IF EXISTS ".WPPHDatabase::getFullTableName('events'));
81
  }
82
- //#! register callbacks
83
  register_activation_hook( __FILE__, array('WPPH', 'onPluginActivate') );
84
  register_deactivation_hook( __FILE__, array('WPPH', 'onPluginDeactivate') );
85
  register_uninstall_hook( __FILE__, 'onPluginUninstall' );
86
 
87
  // Add custom links on plugins page
88
- function wpphCustomLinks($links) {
89
- return array_merge(array('<a href="admin.php?page=wpph_">Audit Log Viewer </a>', '<a href="admin.php?page=wpph_settings">'.__('Settings').'</a>'), $links);
90
- }
91
  add_filter("plugin_action_links_".plugin_basename(__FILE__), 'wpphCustomLinks' );
 
 
 
 
 
92
 
93
  // $GLOBALS['WPPH_CAN_RUN']
94
  // @since v0.3
95
  // @see WPPH::onPluginActivate()
96
  if($GLOBALS['WPPH_CAN_RUN'])
97
  {
98
- //#! Load the pluggable.php file if needed
99
  add_action('admin_init', array('WPPHUtil','loadPluggable'));
100
-
101
- //#! Load resources
102
  add_action('admin_init', array('WPPH', 'loadBaseResources'));
103
-
104
- //#! Add the sidebar menu
105
  add_action('admin_menu', array('WPPH', 'createPluginWpSidebar'));
106
-
107
- //#! Plugin init
108
  add_action('init', 'wpphPluginInit');
109
  function wpphPluginInit()
110
  {
@@ -113,8 +101,25 @@ if($GLOBALS['WPPH_CAN_RUN'])
113
  if(isset($_POST)){
114
  //# 6001, 6002, 6003
115
  WPPHEvent::hookCheckWpGeneralSettings();
116
- if(isset($_POST['action']) && $_POST['action'] == 'editpost'){ $GLOBALS['WPPH_DEFAULT_EDITOR_ENABLED'] = true; }
117
- elseif(isset($_POST['screen']) && ($_POST['screen'] == 'edit-post' || $_POST['screen'] == 'edit-page') ){ $GLOBALS['WPPH_SCREEN_EDITOR_ENABLED'] = true; wpphLog('WPPH_SCREEN_EDITOR_ENABLED');}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  }
119
  WPPHEvent::hookWatchPostStateBefore();
120
  WPPHEvent::hookWatchBlogActivity();
@@ -143,4 +148,4 @@ if($GLOBALS['WPPH_CAN_RUN'])
143
  WPPHEvent::hookUserRegisterEvent();
144
  }
145
  }
146
- //#! End wp-security-audit-log
4
  Plugin URI: http://www.wpwhitesecurity.com/wordpress-security-plugins/wp-security-audit-log/
5
  Description: Identify WordPress security issues before they become a problem and keep track of everything happening on your WordPress, including WordPress users activity. Similar to Windows Event Log and Linux Syslog, WP Security Audit Log will generate a security alert for everything that happens on your WordPress blog or website. Use the Audit Log Viewer included in the plugin to see all the security alerts.
6
  Author: WP White Security
7
+ Version: 0.4
8
  Author URI: http://www.wpwhitesecurity.com/
9
  License: GPL2
10
+ Text Domain: wp-security-audit-log
11
+ Domain Path: languages/
12
 
13
  WP Security Audit Log
14
  Copyright(c) 2013 Robert Abela (email : robert@wpwhitesecurity.com)
26
  along with this program; if not, write to the Free Software
27
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
  */
29
+ // Holds the plugin option name
30
+ define('WPPH_PLUGIN_VERSION','0.4');
 
 
 
31
  define('WPPH_PLUGIN_PREFIX', 'wpph_');
32
  define('WPPH_PLUGIN_NAME', 'WP Security Audit Log');
33
  define('WPPH_PLUGIN_URL', trailingslashit(plugins_url('', __FILE__)));
34
  define('WPPH_PLUGIN_DIR', trailingslashit(plugin_dir_path(__FILE__)));
35
  if(defined('__DIR__')) { define('WPPH_PLUGIN_BASE_NAME', basename(__DIR__)); }
36
  else { define('WPPH_PLUGIN_BASE_NAME', basename(dirname(__FILE__))); }
 
 
 
 
 
 
 
 
 
 
37
 
38
+ // Load required files
39
+ require('inc/wpphSettings.php');
40
  require('inc/WPPHLogger.php');
41
  require('inc/WPPHUtil.php');
 
42
  require('inc/WPPHDatabase.php');
43
  require('inc/WPPHEvent.php');
44
+ require('inc/WPPHPost.php');
45
  require('inc/WPPH.php');
46
  require('inc/wpphFunctions.php');
47
 
48
+ // 2000
 
49
  $GLOBALS['WPPH_POST_IS_NEW'] = false;
50
  add_action('wp_insert_post', 'wpphPostDetectNew', 1, 2);
51
  function wpphPostDetectNew($post, $wp_error = false){
61
  */
62
  function onPluginUninstall()
63
  {
 
 
 
64
  global $wpdb;
65
+ delete_option(WPPH_PLUGIN_DB_UPDATED);
66
+ delete_option(WPPH_PLUGIN_VERSION_OPTION_NAME);
67
+ delete_option(WPPH_USERS_CAN_REGISTER_OPT_NAME);
68
  $wpdb->query("DROP TABLE IF EXISTS ".WPPHDatabase::getFullTableName('main'));
69
  $wpdb->query("DROP TABLE IF EXISTS ".WPPHDatabase::getFullTableName('events'));
70
  }
71
+ // register callbacks
72
  register_activation_hook( __FILE__, array('WPPH', 'onPluginActivate') );
73
  register_deactivation_hook( __FILE__, array('WPPH', 'onPluginDeactivate') );
74
  register_uninstall_hook( __FILE__, 'onPluginUninstall' );
75
 
76
  // Add custom links on plugins page
 
 
 
77
  add_filter("plugin_action_links_".plugin_basename(__FILE__), 'wpphCustomLinks' );
78
+ // Load text domain
79
+ add_action('plugins_loaded', 'wpphLoadTextDomain');
80
+ // create dashboard widget
81
+ add_action('wp_dashboard_setup', array('WPPHUtil','addDashboardWidget'));
82
+
83
 
84
  // $GLOBALS['WPPH_CAN_RUN']
85
  // @since v0.3
86
  // @see WPPH::onPluginActivate()
87
  if($GLOBALS['WPPH_CAN_RUN'])
88
  {
89
+ // Load the pluggable.php file if needed
90
  add_action('admin_init', array('WPPHUtil','loadPluggable'));
91
+ // Load resources
 
92
  add_action('admin_init', array('WPPH', 'loadBaseResources'));
93
+ // Add the sidebar menu
 
94
  add_action('admin_menu', array('WPPH', 'createPluginWpSidebar'));
95
+ // Plugin init
 
96
  add_action('init', 'wpphPluginInit');
97
  function wpphPluginInit()
98
  {
101
  if(isset($_POST)){
102
  //# 6001, 6002, 6003
103
  WPPHEvent::hookCheckWpGeneralSettings();
104
+ if(isset($_POST)){
105
+ if(isset($_POST['action']) && $_POST['action'] == 'editpost'){
106
+ wpphLog('WPPH_DEFAULT_EDITOR_ENABLED');
107
+ $GLOBALS['WPPH_DEFAULT_EDITOR_ENABLED'] = true;
108
+ }
109
+ elseif(isset($_POST['screen'])){
110
+ if($_POST['screen'] == 'edit-post' || $_POST['screen'] == 'edit-page'){
111
+ wpphLog('WPPH_SCREEN_EDITOR_ENABLED');
112
+ $GLOBALS['WPPH_SCREEN_EDITOR_ENABLED'] = true;
113
+ }
114
+ else {// Custom Post type screen
115
+ $type = wpph_extractCustomPostType($_POST['screen']);
116
+ if(WPPHPost::validatePostType($type)){
117
+ wpphLog('WPPH_SCREEN_EDITOR_ENABLED');
118
+ $GLOBALS['WPPH_SCREEN_EDITOR_ENABLED'] = true;
119
+ }
120
+ }
121
+ }
122
+ }
123
  }
124
  WPPHEvent::hookWatchPostStateBefore();
125
  WPPHEvent::hookWatchBlogActivity();
148
  WPPHEvent::hookUserRegisterEvent();
149
  }
150
  }
151
+ // End wp-security-audit-log