Simple History - Version 2.7.3

Version Description

(June 2016) =

  • Removed the usage of the mb_* functions and mbstring is no longer a requirement.
  • Added a new debug tab to the settings page. On the debug page you can see stuff like how large your database is and how many rows that are stored in the database. Also, a list of all loggers are listed there together with some useful (for developers anyway) information.
Download this release

Release Info

Developer eskapism
Plugin Icon 128x128 Simple History
Version 2.7.3
Comparing to
See all releases

Code changes from version 2.7.2 to 2.7.3

dropins/SimpleHistorySettingsDebugDropin.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ Dropin Name: Settings debug
5
+ Dropin Description: Adds a tab with debug information
6
+ Dropin URI: http://simple-history.com/
7
+ Author: Pär Thernström
8
+ */
9
+
10
+ defined( 'ABSPATH' ) or die();
11
+
12
+ class SimpleHistorySettingsDebugDropin {
13
+
14
+ private $sh;
15
+
16
+ public function __construct( $sh ) {
17
+
18
+ $this->sh = $sh;
19
+
20
+ // How do we register this to the settings array?
21
+ $sh->registerSettingsTab( array(
22
+ "slug" => "debug",
23
+ "name" => __( "Debug", "simple-history" ),
24
+ "function" => array( $this, "output" )
25
+ ) );
26
+
27
+ // add_action( 'simple_history/enqueue_admin_scripts', array( $this, 'on_admin_enqueue_scripts' ) );
28
+
29
+ }
30
+
31
+ /*
32
+ public function on_admin_enqueue_scripts() {
33
+
34
+ $file_url = plugin_dir_url( __FILE__ );
35
+
36
+ wp_enqueue_script( "google-ajax-api", "https://www.google.com/jsapi" );
37
+ wp_enqueue_style( "simple_history_SettingsStatsDropin", $file_url . "SimpleHistorySettingsStatsDropin.css", null, SIMPLE_HISTORY_VERSION );
38
+
39
+ }
40
+ */
41
+
42
+ public function output() {
43
+
44
+ include SIMPLE_HISTORY_PATH . "templates/template-settings-tab-debug.php";
45
+
46
+ }
47
+
48
+ }
inc/SimpleHistory.php CHANGED
@@ -1025,6 +1025,7 @@ class SimpleHistory {
1025
  $dropinsDir . "SimpleHistoryRSSDropin.php",
1026
  $dropinsDir . "SimpleHistorySettingsLogtestDropin.php",
1027
  $dropinsDir . "SimpleHistorySettingsStatsDropin.php",
 
1028
  $dropinsDir . "SimpleHistorySidebarDropin.php",
1029
  $dropinsDir . "SimpleHistorySidebarStats.php",
1030
  );
1025
  $dropinsDir . "SimpleHistoryRSSDropin.php",
1026
  $dropinsDir . "SimpleHistorySettingsLogtestDropin.php",
1027
  $dropinsDir . "SimpleHistorySettingsStatsDropin.php",
1028
+ $dropinsDir . "SimpleHistorySettingsDebugDropin.php",
1029
  $dropinsDir . "SimpleHistorySidebarDropin.php",
1030
  $dropinsDir . "SimpleHistorySidebarStats.php",
1031
  );
index.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://simple-history.com
5
  Text Domain: simple-history
6
  Domain Path: /languages
7
  Description: Plugin that logs various things that occur in WordPress and then presents those events in a very nice GUI.
8
- Version: 2.7.2
9
  Author: Pär Thernström
10
  Author URI: http://simple-history.com/
11
  License: GPL2
@@ -32,7 +32,7 @@ if ( ! defined( 'WPINC' ) ) {
32
  die;
33
  }
34
 
35
- if ( version_compare( phpversion(), "5.3", ">=") && function_exists( "mb_strimwidth" ) ) {
36
 
37
  /**
38
  * Register function that is called when plugin is installed
@@ -42,7 +42,7 @@ if ( version_compare( phpversion(), "5.3", ">=") && function_exists( "mb_strimwi
42
  // register_activation_hook( trailingslashit(WP_PLUGIN_DIR) . trailingslashit( plugin_basename(__DIR__) ) . "index.php" , array("SimpleHistory", "on_plugin_activate" ) );
43
 
44
  if ( ! defined( 'SIMPLE_HISTORY_VERSION' ) ) {
45
- define( 'SIMPLE_HISTORY_VERSION', '2.7.2' );
46
  }
47
 
48
  if ( ! defined( 'SIMPLE_HISTORY_PATH' ) ) {
@@ -100,11 +100,6 @@ if ( version_compare( phpversion(), "5.3", ">=") && function_exists( "mb_strimwi
100
  phpversion()
101
  );
102
 
103
- if ( ! function_exists("mb_strimwidth") ) {
104
- echo "<br>";
105
- _e('You also need the mbstring extension to be enabled in PHP.', "simple-history");
106
- }
107
-
108
  ?></p>
109
  </div>
110
  <?php
5
  Text Domain: simple-history
6
  Domain Path: /languages
7
  Description: Plugin that logs various things that occur in WordPress and then presents those events in a very nice GUI.
8
+ Version: 2.7.3
9
  Author: Pär Thernström
10
  Author URI: http://simple-history.com/
11
  License: GPL2
32
  die;
33
  }
34
 
35
+ if ( version_compare( phpversion(), "5.3", ">=") ) {
36
 
37
  /**
38
  * Register function that is called when plugin is installed
42
  // register_activation_hook( trailingslashit(WP_PLUGIN_DIR) . trailingslashit( plugin_basename(__DIR__) ) . "index.php" , array("SimpleHistory", "on_plugin_activate" ) );
43
 
44
  if ( ! defined( 'SIMPLE_HISTORY_VERSION' ) ) {
45
+ define( 'SIMPLE_HISTORY_VERSION', '2.7.3' );
46
  }
47
 
48
  if ( ! defined( 'SIMPLE_HISTORY_PATH' ) ) {
100
  phpversion()
101
  );
102
 
 
 
 
 
 
103
  ?></p>
104
  </div>
105
  <?php
loggers/SimpleOptionsLogger.php CHANGED
@@ -12,12 +12,12 @@ class SimpleOptionsLogger extends SimpleLogger
12
 
13
  /**
14
  * Get array with information about this logger
15
- *
16
  * @return array
17
  */
18
  function getInfo() {
19
 
20
- $arr_info = array(
21
  "name" => "Options Logger",
22
  "description" => "Logs updates to WordPress settings",
23
  "capability" => "manage_options",
@@ -31,7 +31,7 @@ class SimpleOptionsLogger extends SimpleLogger
31
  Modified option "default_comment_status" on settings page "discussion"
32
 
33
  Edited settings page "discussion" and the "default_comment_status" options
34
-
35
  */
36
  ),
37
  "labels" => array(
@@ -40,12 +40,12 @@ class SimpleOptionsLogger extends SimpleLogger
40
  "options" => array(
41
  _x("Changed options", "Options logger: search", "simple-history") => array(
42
  "option_updated"
43
- ),
44
  )
45
  ) // end search array
46
  ) // end labels
47
  );
48
-
49
  return $arr_info;
50
 
51
  }
@@ -53,7 +53,7 @@ class SimpleOptionsLogger extends SimpleLogger
53
  function loaded() {
54
 
55
  add_action( 'updated_option', array($this, "on_updated_option"), 10, 3 );
56
-
57
  }
58
 
59
  function on_updated_option( $option, $old_value, $new_value ) {
@@ -75,7 +75,7 @@ class SimpleOptionsLogger extends SimpleLogger
75
  // Also only if "option_page" is set to one of these "built in" ones
76
  // We don't wanna start loging things from other plugins, like EDD
77
  $option_page = isset( $_REQUEST["option_page"] ) ? $_REQUEST["option_page"] : ""; // general | discussion | ...
78
-
79
  $arr_valid_option_pages = array(
80
  'general',
81
  'discussion',
@@ -134,7 +134,7 @@ class SimpleOptionsLogger extends SimpleLogger
134
  * Not doing anything at the moment, because it was really difficaly to give them meaningful text values
135
  */
136
  public function getLogRowPlainTextOutput( $row ) {
137
-
138
  $message = $row->message;
139
  $context = $row->context;
140
  $message_key = $context["_message_key"];
@@ -188,11 +188,11 @@ class SimpleOptionsLogger extends SimpleLogger
188
  * Get detailed output
189
  */
190
  function getLogRowDetailsOutput($row) {
191
-
192
  $context = $row->context;
193
  $message_key = $context["_message_key"];
194
  $output = "";
195
-
196
  $option = isset( $context["option"] ) ? $context["option"] : null;
197
  $option_page = isset( $context["option_page"] ) ? $context["option_page"] : null;
198
  $new_value = isset( $context["new_value"] ) ? $context["new_value"] : null;
@@ -206,16 +206,16 @@ class SimpleOptionsLogger extends SimpleLogger
206
  ';
207
 
208
  if ( "option_updated" == $message_key ) {
209
-
210
  //$message = 'Old value was {old_value} and new value is {new_value}';
211
  $output .= "<table class='SimpleHistoryLogitem__keyValueTable'>";
212
 
213
  // Output old and new values
214
  if ( $context["new_value"] || $context["old_value"] ) {
215
-
216
  $option_custom_output = "";
217
  $methodname = "get_details_output_for_option_{$option}";
218
-
219
  if ( method_exists( $this, $methodname ) ) {
220
  $option_custom_output = $this->$methodname( $context, $old_value, $new_value, $option, $option_page, $tmpl_row );
221
  }
@@ -223,20 +223,33 @@ class SimpleOptionsLogger extends SimpleLogger
223
  if ( empty( $option_custom_output ) ) {
224
 
225
  // all other options or fallback if custom output did not find all it's stuff
 
 
 
 
 
 
 
 
 
 
 
 
 
226
 
227
  $output .= sprintf(
228
  $tmpl_row,
229
  __("New value", "simple-history"),
230
- esc_html( mb_strimwidth( $new_value, 0, 250, "..." ) )
231
  );
232
 
233
  $output .= sprintf(
234
  $tmpl_row,
235
  __("Old value", "simple-history"),
236
- esc_html( mb_strimwidth( $old_value, 0, 250, "..." ) )
237
  );
238
-
239
-
240
  } else {
241
 
242
  $output .= $option_custom_output;
@@ -280,7 +293,7 @@ class SimpleOptionsLogger extends SimpleLogger
280
  );
281
 
282
  }
283
-
284
  $output .= "</table>";
285
 
286
  }
@@ -350,7 +363,7 @@ class SimpleOptionsLogger extends SimpleLogger
350
  if ( $new_value && ! empty( $context["new_post_title"] ) ) {
351
 
352
  $post_title_with_link = "";
353
-
354
  if ( get_post_status( $new_value ) ) {
355
  $post_title_with_link = sprintf('<a href="%1$s">%2$s</a>', get_edit_post_link( $new_value ), esc_html( $context["new_post_title"] ) );
356
  } else {
@@ -362,7 +375,7 @@ class SimpleOptionsLogger extends SimpleLogger
362
  __("New value", "simple-history"),
363
  sprintf( __('Page %1$s', "simple-history" ), $post_title_with_link)
364
  );
365
-
366
  }
367
  if ( intval( $new_value ) == 0 ) {
368
 
@@ -371,12 +384,12 @@ class SimpleOptionsLogger extends SimpleLogger
371
  __("New value", "simple-history"),
372
  __("Your latests posts", "simple-history")
373
  );
374
-
375
  }
376
 
377
  if ( $old_value && ! empty( $context["old_post_title"] ) ) {
378
  $post_title_with_link = "";
379
-
380
  if ( get_post_status( $old_value ) ) {
381
  $post_title_with_link = sprintf('<a href="%1$s">%2$s</a>', get_edit_post_link( $old_value ), esc_html( $context["old_post_title"] ) );
382
  } else {
@@ -398,16 +411,16 @@ class SimpleOptionsLogger extends SimpleLogger
398
  __("Old value", "simple-history"),
399
  __("Your latests posts", "simple-history")
400
  );
401
-
402
  }
403
-
404
  return $output;
405
 
406
  } // custom output page_on_front
407
 
408
 
409
  /**
410
- * "default_category" = Writing Settings » Default Post Category
411
  */
412
  function add_context_for_option_default_category( $context, $old_value, $new_value, $option, $option_page ) {
413
 
@@ -440,7 +453,7 @@ class SimpleOptionsLogger extends SimpleLogger
440
  }
441
 
442
  function add_context_for_option_default_email_category( $context, $old_value, $new_value, $option, $option_page ) {
443
-
444
  $context = call_user_func_array( array( $this, "add_context_for_option_default_category"), func_get_args() );
445
 
446
  return $context;
@@ -464,7 +477,7 @@ class SimpleOptionsLogger extends SimpleLogger
464
  $tmpl_row,
465
  __("Old value", "simple-history"),
466
  esc_html( $old_category_name )
467
- );
468
 
469
  }
470
 
@@ -474,7 +487,7 @@ class SimpleOptionsLogger extends SimpleLogger
474
  $tmpl_row,
475
  __("New value", "simple-history"),
476
  esc_html( $new_category_name )
477
- );
478
 
479
  }
480
 
@@ -482,9 +495,9 @@ class SimpleOptionsLogger extends SimpleLogger
482
 
483
  }
484
 
485
- function get_details_output_for_option_default_email_category( $context, $old_value, $new_value, $option, $option_page, $tmpl_row ) {
486
-
487
- $output = call_user_func_array( array( $this, "get_details_output_for_option_default_category"), func_get_args() );
488
 
489
  return $output;
490
 
12
 
13
  /**
14
  * Get array with information about this logger
15
+ *
16
  * @return array
17
  */
18
  function getInfo() {
19
 
20
+ $arr_info = array(
21
  "name" => "Options Logger",
22
  "description" => "Logs updates to WordPress settings",
23
  "capability" => "manage_options",
31
  Modified option "default_comment_status" on settings page "discussion"
32
 
33
  Edited settings page "discussion" and the "default_comment_status" options
34
+
35
  */
36
  ),
37
  "labels" => array(
40
  "options" => array(
41
  _x("Changed options", "Options logger: search", "simple-history") => array(
42
  "option_updated"
43
+ ),
44
  )
45
  ) // end search array
46
  ) // end labels
47
  );
48
+
49
  return $arr_info;
50
 
51
  }
53
  function loaded() {
54
 
55
  add_action( 'updated_option', array($this, "on_updated_option"), 10, 3 );
56
+
57
  }
58
 
59
  function on_updated_option( $option, $old_value, $new_value ) {
75
  // Also only if "option_page" is set to one of these "built in" ones
76
  // We don't wanna start loging things from other plugins, like EDD
77
  $option_page = isset( $_REQUEST["option_page"] ) ? $_REQUEST["option_page"] : ""; // general | discussion | ...
78
+
79
  $arr_valid_option_pages = array(
80
  'general',
81
  'discussion',
134
  * Not doing anything at the moment, because it was really difficaly to give them meaningful text values
135
  */
136
  public function getLogRowPlainTextOutput( $row ) {
137
+
138
  $message = $row->message;
139
  $context = $row->context;
140
  $message_key = $context["_message_key"];
188
  * Get detailed output
189
  */
190
  function getLogRowDetailsOutput($row) {
191
+
192
  $context = $row->context;
193
  $message_key = $context["_message_key"];
194
  $output = "";
195
+
196
  $option = isset( $context["option"] ) ? $context["option"] : null;
197
  $option_page = isset( $context["option_page"] ) ? $context["option_page"] : null;
198
  $new_value = isset( $context["new_value"] ) ? $context["new_value"] : null;
206
  ';
207
 
208
  if ( "option_updated" == $message_key ) {
209
+
210
  //$message = 'Old value was {old_value} and new value is {new_value}';
211
  $output .= "<table class='SimpleHistoryLogitem__keyValueTable'>";
212
 
213
  // Output old and new values
214
  if ( $context["new_value"] || $context["old_value"] ) {
215
+
216
  $option_custom_output = "";
217
  $methodname = "get_details_output_for_option_{$option}";
218
+
219
  if ( method_exists( $this, $methodname ) ) {
220
  $option_custom_output = $this->$methodname( $context, $old_value, $new_value, $option, $option_page, $tmpl_row );
221
  }
223
  if ( empty( $option_custom_output ) ) {
224
 
225
  // all other options or fallback if custom output did not find all it's stuff
226
+ $more = __( '&hellip;' );
227
+ $trim_length = 250;
228
+
229
+ $trimmed_new_value = substr( $new_value, 0, $trim_length );
230
+ $trimmed_old_value = substr( $old_value, 0, $trim_length );
231
+
232
+ if ( strlen( $new_value ) > $trim_length ) {
233
+ $trimmed_new_value .= $more;
234
+ }
235
+
236
+ if ( strlen( $old_value ) > $trim_length ) {
237
+ $trimmed_oldv_alue .= $more;
238
+ }
239
 
240
  $output .= sprintf(
241
  $tmpl_row,
242
  __("New value", "simple-history"),
243
+ esc_html( $trimmed_new_value )
244
  );
245
 
246
  $output .= sprintf(
247
  $tmpl_row,
248
  __("Old value", "simple-history"),
249
+ esc_html( $trimmed_old_value )
250
  );
251
+
252
+
253
  } else {
254
 
255
  $output .= $option_custom_output;
293
  );
294
 
295
  }
296
+
297
  $output .= "</table>";
298
 
299
  }
363
  if ( $new_value && ! empty( $context["new_post_title"] ) ) {
364
 
365
  $post_title_with_link = "";
366
+
367
  if ( get_post_status( $new_value ) ) {
368
  $post_title_with_link = sprintf('<a href="%1$s">%2$s</a>', get_edit_post_link( $new_value ), esc_html( $context["new_post_title"] ) );
369
  } else {
375
  __("New value", "simple-history"),
376
  sprintf( __('Page %1$s', "simple-history" ), $post_title_with_link)
377
  );
378
+
379
  }
380
  if ( intval( $new_value ) == 0 ) {
381
 
384
  __("New value", "simple-history"),
385
  __("Your latests posts", "simple-history")
386
  );
387
+
388
  }
389
 
390
  if ( $old_value && ! empty( $context["old_post_title"] ) ) {
391
  $post_title_with_link = "";
392
+
393
  if ( get_post_status( $old_value ) ) {
394
  $post_title_with_link = sprintf('<a href="%1$s">%2$s</a>', get_edit_post_link( $old_value ), esc_html( $context["old_post_title"] ) );
395
  } else {
411
  __("Old value", "simple-history"),
412
  __("Your latests posts", "simple-history")
413
  );
414
+
415
  }
416
+
417
  return $output;
418
 
419
  } // custom output page_on_front
420
 
421
 
422
  /**
423
+ * "default_category" = Writing Settings » Default Post Category
424
  */
425
  function add_context_for_option_default_category( $context, $old_value, $new_value, $option, $option_page ) {
426
 
453
  }
454
 
455
  function add_context_for_option_default_email_category( $context, $old_value, $new_value, $option, $option_page ) {
456
+
457
  $context = call_user_func_array( array( $this, "add_context_for_option_default_category"), func_get_args() );
458
 
459
  return $context;
477
  $tmpl_row,
478
  __("Old value", "simple-history"),
479
  esc_html( $old_category_name )
480
+ );
481
 
482
  }
483
 
487
  $tmpl_row,
488
  __("New value", "simple-history"),
489
  esc_html( $new_category_name )
490
+ );
491
 
492
  }
493
 
495
 
496
  }
497
 
498
+ function get_details_output_for_option_default_email_category( $context, $old_value, $new_value, $option, $option_page, $tmpl_row ) {
499
+
500
+ $output = call_user_func_array( array( $this, "get_details_output_for_option_default_category"), func_get_args() );
501
 
502
  return $output;
503
 
loggers/SimplePluginLogger.php CHANGED
@@ -13,68 +13,68 @@ class SimplePluginLogger extends SimpleLogger
13
 
14
  /**
15
  * Get array with information about this logger
16
- *
17
  * @return array
18
  */
19
  function getInfo() {
20
 
21
- $arr_info = array(
22
  "name" => "Plugin Logger",
23
  "description" => "Logs plugin installs, uninstalls and updates",
24
- "capability" => "activate_plugins", // install_plugins, activate_plugins,
25
  "messages" => array(
26
 
27
  'plugin_activated' => _x(
28
- 'Activated plugin "{plugin_name}"',
29
  'Plugin was non-silently activated by a user',
30
  'simple-history'
31
  ),
32
 
33
  'plugin_deactivated' => _x(
34
- 'Deactivated plugin "{plugin_name}"',
35
  'Plugin was non-silently deactivated by a user',
36
  'simple-history'
37
  ),
38
 
39
  'plugin_installed' => _x(
40
- 'Installed plugin "{plugin_name}"',
41
  'Plugin was installed',
42
  'simple-history'
43
  ),
44
 
45
  'plugin_installed_failed' => _x(
46
- 'Failed to install plugin "{plugin_name}"',
47
  'Plugin failed to install',
48
  'simple-history'
49
  ),
50
 
51
  'plugin_updated' => _x(
52
- 'Updated plugin "{plugin_name}" to version {plugin_version} from {plugin_prev_version}',
53
  'Plugin was updated',
54
  'simple-history'
55
  ),
56
 
57
  'plugin_update_failed' => _x(
58
- 'Updated plugin "{plugin_name}"',
59
  'Plugin update failed',
60
  'simple-history'
61
  ),
62
 
63
  'plugin_file_edited' => _x(
64
- 'Edited plugin file "{plugin_edited_file}"',
65
  'Plugin file edited',
66
  'simple-history'
67
  ),
68
 
69
  'plugin_deleted' => _x(
70
- 'Deleted plugin "{plugin_name}"',
71
  'Plugin files was deleted',
72
  'simple-history'
73
  ),
74
 
75
  // bulk versions
76
  'plugin_bulk_updated' => _x(
77
- 'Updated plugin "{plugin_name}" to {plugin_version} from {plugin_prev_version}',
78
  'Plugin was updated in bulk',
79
  'simple-history'
80
  ),
@@ -113,7 +113,7 @@ class SimplePluginLogger extends SimpleLogger
113
  ) // search array
114
  ) // labels
115
  );
116
-
117
  return $arr_info;
118
 
119
  }
@@ -139,7 +139,7 @@ class SimplePluginLogger extends SimpleLogger
139
  // If a plugin is silently activated (such as during an update),
140
  // this hook does not fire.
141
  add_action( 'activated_plugin', array( $this, "on_activated_plugin" ), 10, 2 );
142
-
143
  // Fires after a plugin is deactivated.
144
  // If a plugin is silently deactivated (such as during an update),
145
  // this hook does not fire.
@@ -168,18 +168,18 @@ class SimplePluginLogger extends SimpleLogger
168
  } );
169
 
170
  }
171
-
172
  /**
173
  * Show readme from github in a modal win
174
  */
175
  function ajax_GetGitHubPluginInfo() {
176
-
177
  if ( ! current_user_can("install_plugins") ) {
178
  wp_die( __("You don't have access to this page.", "simple-history" ));
179
  }
180
-
181
  $repo = isset( $_GET["repo"] ) ? (string) $_GET["repo"] : "";
182
-
183
  if ( ! $repo ) {
184
  wp_die( __("Could not find GitHub repository.", "simple-history" ));
185
  }
@@ -196,7 +196,7 @@ class SimplePluginLogger extends SimpleLogger
196
  // https://api.github.com/repos/<username>/<repo>/readme
197
  $api_url = sprintf('https://api.github.com/repos/%1$s/%2$s/readme', urlencode( $repo_username ), urlencode( $repo_repo ));
198
 
199
- // Get file. Use accept-header to get file as HTML instead of JSON
200
  $response = wp_remote_get( $api_url, array(
201
  "headers" => array(
202
  "accept" => "application/vnd.github.VERSION.html"
@@ -210,7 +210,7 @@ class SimplePluginLogger extends SimpleLogger
210
  esc_url( $repo ),
211
  esc_html( $repo )
212
  );
213
-
214
  $github_markdown_css_path = SIMPLE_HISTORY_PATH . "/css/github-markdown.css";
215
 
216
  printf(
@@ -235,17 +235,17 @@ class SimplePluginLogger extends SimpleLogger
235
  margin: 0 auto;
236
  padding: 30px;
237
  }
238
-
239
  @import url("%3$s");
240
-
241
  </style>
242
-
243
  <base href="%4$s/raw/master/">
244
-
245
  <header class="repo-info">
246
  %1$s
247
  </header>
248
-
249
  <div class="markdown-body readme-contents">
250
  %2$s
251
  </div>
@@ -255,9 +255,9 @@ class SimplePluginLogger extends SimpleLogger
255
  $github_markdown_css_path,
256
  esc_url( $repo ) // 4
257
  );
258
-
259
  #echo($response_body);
260
-
261
  exit;
262
 
263
  }
@@ -268,7 +268,7 @@ class SimplePluginLogger extends SimpleLogger
268
  * So before a plugin is deleted we save all needed info in a transient
269
  */
270
  function on_action_delete_selected() {
271
-
272
  // Same as in plugins.php
273
  if ( ! current_user_can('delete_plugins') ) {
274
  wp_die(__('You do not have sufficient permissions to delete plugins for this site.'));
@@ -312,9 +312,9 @@ class SimplePluginLogger extends SimpleLogger
312
  * set_transient('plugins_delete_result_' . $user_ID, $delete_result);
313
  *
314
  * We detect when that transient is set and then we have all info needed to log the plugin delete
315
- *
316
  */
317
- public function on_setted_transient_for_remove_files( $transient = "", $value = "" ) {
318
 
319
  if ( ! $user_id = get_current_user_id() ) {
320
  return;
@@ -326,7 +326,7 @@ class SimplePluginLogger extends SimpleLogger
326
  }
327
 
328
  // We found the transient we were looking for
329
- if (
330
  isset( $_POST["action"] )
331
  && "delete-selected" == $_POST["action"]
332
  && isset( $_POST["checked"] )
@@ -344,7 +344,7 @@ class SimplePluginLogger extends SimpleLogger
344
  $plugins_before_update = json_decode( get_option( $this->slug . "_plugin_info_before_update", false ), true );
345
 
346
  foreach ( $plugins_deleted as $plugin ) {
347
-
348
  $context = array(
349
  "plugin" => $plugin // plugin-name-folder/plugin-main-file.php
350
  );
@@ -366,7 +366,7 @@ class SimplePluginLogger extends SimpleLogger
366
  }
367
 
368
  }
369
-
370
  $this->remove_saved_versions();
371
 
372
  }
@@ -376,29 +376,29 @@ class SimplePluginLogger extends SimpleLogger
376
  * This way we can know both the old (pre updated/removed) and the current version of the plugin
377
  */
378
  /*public function save_versions_before_update() {
379
-
380
  $current_screen = get_current_screen();
381
  $request_uri = $_SERVER["SCRIPT_NAME"];
382
 
383
  // Only add option on pages where needed
384
  $do_store = false;
385
 
386
- if (
387
  SimpleHistory::ends_with( $request_uri, "/wp-admin/update.php" )
388
- && isset( $current_screen->base )
389
- && "update" == $current_screen->base
390
  ) {
391
-
392
  // Plugin update screen
393
  $do_store = true;
394
 
395
- } else if (
396
  SimpleHistory::ends_with( $request_uri, "/wp-admin/plugins.php" )
397
- && isset( $current_screen->base )
398
  && "plugins" == $current_screen->base
399
  && ( isset( $_POST["action"] ) && "delete-selected" == $_POST["action"] )
400
  ) {
401
-
402
  // Plugin delete screen, during delete
403
  $do_store = true;
404
 
@@ -419,7 +419,7 @@ class SimplePluginLogger extends SimpleLogger
419
  * delete_site_transient_update_plugins
420
  */
421
  public function remove_saved_versions() {
422
-
423
  delete_option( $this->slug . "_plugin_info_before_update" );
424
 
425
  }
@@ -428,14 +428,14 @@ class SimplePluginLogger extends SimpleLogger
428
 
429
  // Var is string with length 113: /wp-admin/plugin-editor.php?file=my-plugin%2Fviews%2Fplugin-file.php
430
  $referer = wp_get_referer();
431
-
432
  // contains key "path" with value like "/wp-admin/plugin-editor.php"
433
  $referer_info = parse_url($referer);
434
 
435
  if ( "/wp-admin/plugin-editor.php" === $referer_info["path"] ) {
436
 
437
  // We are in plugin editor
438
- // Check for plugin edit saved
439
  if ( isset( $_POST["newcontent"] ) && isset( $_POST["action"] ) && "update" == $_POST["action"] && isset( $_POST["file"] ) && ! empty( $_POST["file"] ) ) {
440
 
441
  // A file was edited
@@ -443,7 +443,7 @@ class SimplePluginLogger extends SimpleLogger
443
 
444
  // $plugins = get_plugins();
445
  // http://codex.wordpress.org/Function_Reference/wp_text_diff
446
-
447
  // Generate a diff of changes
448
  if ( ! class_exists( 'WP_Text_Diff_Renderer_Table' ) ) {
449
  require_once( ABSPATH . WPINC . '/wp-diff.php' );
@@ -499,10 +499,10 @@ class SimplePluginLogger extends SimpleLogger
499
 
500
  */
501
 
502
- /*
503
 
504
  # WordPress core update
505
-
506
  $arr_data:
507
  Array
508
  (
@@ -510,9 +510,9 @@ class SimplePluginLogger extends SimpleLogger
510
  [type] => core
511
  )
512
 
513
-
514
  # Plugin install
515
-
516
  $arr_data:
517
  Array
518
  (
@@ -522,7 +522,7 @@ class SimplePluginLogger extends SimpleLogger
522
 
523
 
524
  # Plugin update
525
-
526
  $arr_data:
527
  Array
528
  (
@@ -570,7 +570,7 @@ class SimplePluginLogger extends SimpleLogger
570
  "plugin_downloaded" => isset( $upgrader_skin_api->downloaded ) ? $upgrader_skin_api->downloaded : "",
571
  "plugin_added" => isset( $upgrader_skin_api->added ) ? $upgrader_skin_api->added : "",
572
  "plugin_source_files" => $this->simpleHistory->json_encode( $plugin_upgrader_instance->result["source_files"] ),
573
-
574
  // To debug comment out these:
575
  // "debug_skin_options" => $this->simpleHistory->json_encode( $upgrader_skin_options ),
576
  // "debug_skin_result" => $this->simpleHistory->json_encode( $upgrader_skin_result ),
@@ -608,7 +608,7 @@ class SimplePluginLogger extends SimpleLogger
608
  }
609
  }
610
  */
611
-
612
  if ( isset( $_FILES["pluginzip"]["name"] ) ) {
613
  $plugin_upload_name = $_FILES["pluginzip"]["name"];
614
  $context["plugin_upload_name"] = $plugin_upload_name;
@@ -630,14 +630,14 @@ class SimplePluginLogger extends SimpleLogger
630
  );
631
 
632
  $did_log = true;
633
-
634
  } else {
635
 
636
  // Plugin was successfully installed
637
  // Try to grab more info from the readme
638
  // Would be nice to grab a screenshot, but that is difficult since they often are stored remotely
639
  $plugin_destination = isset( $plugin_upgrader_instance->result["destination"] ) ? $plugin_upgrader_instance->result["destination"] : null;
640
-
641
  if ( $plugin_destination ) {
642
 
643
  $plugin_info = $plugin_upgrader_instance->plugin_info();
@@ -652,15 +652,15 @@ class SimplePluginLogger extends SimpleLogger
652
  $context["plugin_url"] = isset( $plugin_data["PluginURI"] ) ? $plugin_data["PluginURI"] : "";
653
  $context["plugin_version"] = isset( $plugin_data["Version"] ) ? $plugin_data["Version"] : "";
654
  $context["plugin_author"] = isset( $plugin_data["AuthorName"] ) ? $plugin_data["AuthorName"] : "";
655
-
656
  // Comment out these to debug plugin installs
657
  #$context["debug_plugin_data"] = $this->simpleHistory->json_encode( $plugin_data );
658
  #$context["debug_plugin_info"] = $this->simpleHistory->json_encode( $plugin_info );
659
-
660
  if ( ! empty( $plugin_data["GitHub Plugin URI"] ) ) {
661
  $context["plugin_github_url"] = $plugin_data["GitHub Plugin URI"];
662
  }
663
-
664
  }
665
 
666
  $this->infoMessage(
@@ -703,7 +703,7 @@ class SimplePluginLogger extends SimpleLogger
703
  // use transient to get url and package
704
  $update_plugins = get_site_transient( 'update_plugins' );
705
  if ( $update_plugins && isset( $update_plugins->response[ $arr_data["plugin"] ] ) ) {
706
-
707
  /*
708
  $update_plugins[plugin_path/slug]:
709
  {
@@ -753,7 +753,7 @@ class SimplePluginLogger extends SimpleLogger
753
  );
754
 
755
  $did_log = true;
756
-
757
  } else {
758
 
759
  $this->infoMessage(
@@ -770,7 +770,7 @@ class SimplePluginLogger extends SimpleLogger
770
  }
771
 
772
  } // update single
773
-
774
 
775
  /**
776
  * For bulk updates $arr_data looks like:
@@ -795,7 +795,7 @@ class SimplePluginLogger extends SimpleLogger
795
  $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_name );
796
 
797
  $plugin_slug = dirname( $plugin_name );
798
-
799
  $context = array(
800
  "plugin_slug" => $plugin_slug,
801
  "plugin_name" => $plugin_data["Name"],
@@ -809,7 +809,7 @@ class SimplePluginLogger extends SimpleLogger
809
  // get url and package
810
  $update_plugins = get_site_transient( 'update_plugins' );
811
  if ( $update_plugins && isset( $update_plugins->response[ $plugin_name ] ) ) {
812
-
813
  /*
814
  $update_plugins[plugin_path/slug]:
815
  {
@@ -854,7 +854,7 @@ class SimplePluginLogger extends SimpleLogger
854
 
855
  } // bulk update
856
 
857
-
858
  } // if plugin
859
 
860
  if ( ! $did_log ) {
@@ -867,7 +867,7 @@ class SimplePluginLogger extends SimpleLogger
867
  }
868
 
869
  /*
870
- * Called from filter 'upgrader_post_install'.
871
  *
872
  * Used to log bulk plugin installs and updates
873
  *
@@ -880,10 +880,10 @@ class SimplePluginLogger extends SimpleLogger
880
  * @param array $result Installation result data.
881
  */
882
  public function on_upgrader_post_install( $response, $hook_extra, $result ) {
883
-
884
  #echo "on_upgrader_post_install";
885
  /*
886
-
887
  # Plugin update:
888
  $hook_extra
889
  Array
@@ -907,10 +907,10 @@ class SimplePluginLogger extends SimpleLogger
907
 
908
  // It's a plugin install
909
  #error_log("plugin install");
910
-
911
 
912
  } else if ( isset( $hook_extra["action"] ) && $hook_extra["action"] == "update" && isset( $hook_extra["type"] ) && $hook_extra["type"] == "plugin" ) {
913
-
914
  // It's a plugin upgrade
915
  #echo "plugin update!";
916
  //error_log("plugin update");
@@ -993,7 +993,7 @@ class SimplePluginLogger extends SimpleLogger
993
  'Network' - Boolean. Whether the plugin can only be activated network wide.
994
  */
995
  $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_name );
996
-
997
  $plugin_slug = dirname( $plugin_name );
998
 
999
  $context = array(
@@ -1011,7 +1011,7 @@ class SimplePluginLogger extends SimpleLogger
1011
  }
1012
 
1013
  $this->infoMessage( 'plugin_activated', $context );
1014
-
1015
  }
1016
 
1017
  /**
@@ -1022,7 +1022,7 @@ class SimplePluginLogger extends SimpleLogger
1022
 
1023
  $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_name );
1024
  $plugin_slug = dirname( $plugin_name );
1025
-
1026
  $context = array(
1027
  "plugin_name" => $plugin_data["Name"],
1028
  "plugin_slug" => $plugin_slug,
@@ -1053,17 +1053,17 @@ class SimplePluginLogger extends SimpleLogger
1053
 
1054
  // When a plugin is installed we show a bit more information
1055
  // We do it only on install because we don't want to clutter to log,
1056
- // and when something is installed the description is most useul for other
1057
  // admins on the site
1058
  if ( "plugin_installed" === $message_key ) {
1059
-
1060
- if ( isset($context["plugin_description"]) ) {
1061
 
1062
  // Description includes a link to author, remove that, i.e. all text after and including <cite>
1063
  $plugin_description = $context["plugin_description"];
1064
- $cite_pos = mb_strpos($plugin_description, "<cite>");
1065
  if ($cite_pos) {
1066
- $plugin_description = mb_strcut( $plugin_description, 0, $cite_pos );
1067
  }
1068
 
1069
  // Keys to show
@@ -1086,7 +1086,7 @@ class SimplePluginLogger extends SimpleLogger
1086
  $output .= "<table class='SimpleHistoryLogitem__keyValueTable'>";
1087
 
1088
  foreach ( $arr_plugin_keys as $key => $desc ) {
1089
-
1090
  $desc_output = "";
1091
 
1092
  switch ( $key ) {
@@ -1103,7 +1103,7 @@ class SimplePluginLogger extends SimpleLogger
1103
  // URL needs a link
1104
  case "plugin_url":
1105
  $desc_output = sprintf('<a href="%1$s">%2$s</a>', esc_attr( $context["plugin_url"] ), esc_html( $context["plugin_url"] ));
1106
- break;
1107
 
1108
  case "plugin_description":
1109
  $desc_output = $plugin_description;
@@ -1172,7 +1172,7 @@ class SimplePluginLogger extends SimpleLogger
1172
 
1173
  // Slug + web as install source = show link to wordpress.org
1174
  if ( $plugin_slug && isset( $context["plugin_install_source"] ) && $context["plugin_install_source"] == "web" ) {
1175
-
1176
  $output .= sprintf(
1177
  '
1178
  <tr>
@@ -1184,10 +1184,10 @@ class SimplePluginLogger extends SimpleLogger
1184
  esc_html_x("View plugin info", "plugin logger: plugin info thickbox title view all info", "simple-history")
1185
  );
1186
 
1187
- }
1188
  // GitHub plugin url set = show link to github repo
1189
  else if ( isset( $context["plugin_install_source"] ) && $context["plugin_install_source"] == "upload" && ! empty( $context["plugin_github_url"] ) ) {
1190
-
1191
  // Can't embed iframe
1192
  // Must use API instead
1193
  // https://api.github.com/repos/<username>/<repo>/readme?callback=<callbackname>
@@ -1203,7 +1203,7 @@ class SimplePluginLogger extends SimpleLogger
1203
  esc_html_x("View plugin info", "plugin logger: plugin info thickbox title view all info", "simple-history")
1204
  );
1205
 
1206
- }
1207
 
1208
  $output .= "</table>";
1209
 
@@ -1214,23 +1214,23 @@ class SimplePluginLogger extends SimpleLogger
1214
  $plugin_slug = ! empty( $context["plugin_slug"] ) ? $context["plugin_slug"] : "";
1215
 
1216
  if ( $plugin_slug && empty( $context["plugin_github_url"] ) ) {
1217
-
1218
  $link_title = esc_html_x("View plugin info", "plugin logger: plugin info thickbox title", "simple-history");
1219
  $url = admin_url( "plugin-install.php?tab=plugin-information&amp;plugin={$plugin_slug}&amp;section=&amp;TB_iframe=true&amp;width=640&amp;height=550" );
1220
-
1221
  if ( "plugin_updated" == $message_key || "plugin_bulk_updated" == $message_key ) {
1222
  $link_title = esc_html_x("View changelog", "plugin logger: plugin info thickbox title", "simple-history");
1223
  $url = admin_url( "plugin-install.php?tab=plugin-information&amp;plugin={$plugin_slug}&amp;section=changelog&amp;TB_iframe=true&amp;width=772&amp;height=550" );
1224
  }
1225
-
1226
  $output .= sprintf(
1227
  '<p><a title="%2$s" class="thickbox" href="%1$s">%2$s</a></p>',
1228
  $url,
1229
- $link_title
1230
  );
1231
 
1232
  } else if ( ! empty( $context["plugin_github_url"] ) ) {
1233
-
1234
  $output .= sprintf(
1235
  '
1236
  <tr>
@@ -1242,7 +1242,7 @@ class SimplePluginLogger extends SimpleLogger
1242
  esc_html_x("View plugin info", "plugin logger: plugin info thickbox title view all info", "simple-history")
1243
  );
1244
 
1245
- }
1246
 
1247
 
1248
  } // if plugin_updated
13
 
14
  /**
15
  * Get array with information about this logger
16
+ *
17
  * @return array
18
  */
19
  function getInfo() {
20
 
21
+ $arr_info = array(
22
  "name" => "Plugin Logger",
23
  "description" => "Logs plugin installs, uninstalls and updates",
24
+ "capability" => "activate_plugins", // install_plugins, activate_plugins,
25
  "messages" => array(
26
 
27
  'plugin_activated' => _x(
28
+ 'Activated plugin "{plugin_name}"',
29
  'Plugin was non-silently activated by a user',
30
  'simple-history'
31
  ),
32
 
33
  'plugin_deactivated' => _x(
34
+ 'Deactivated plugin "{plugin_name}"',
35
  'Plugin was non-silently deactivated by a user',
36
  'simple-history'
37
  ),
38
 
39
  'plugin_installed' => _x(
40
+ 'Installed plugin "{plugin_name}"',
41
  'Plugin was installed',
42
  'simple-history'
43
  ),
44
 
45
  'plugin_installed_failed' => _x(
46
+ 'Failed to install plugin "{plugin_name}"',
47
  'Plugin failed to install',
48
  'simple-history'
49
  ),
50
 
51
  'plugin_updated' => _x(
52
+ 'Updated plugin "{plugin_name}" to version {plugin_version} from {plugin_prev_version}',
53
  'Plugin was updated',
54
  'simple-history'
55
  ),
56
 
57
  'plugin_update_failed' => _x(
58
+ 'Updated plugin "{plugin_name}"',
59
  'Plugin update failed',
60
  'simple-history'
61
  ),
62
 
63
  'plugin_file_edited' => _x(
64
+ 'Edited plugin file "{plugin_edited_file}"',
65
  'Plugin file edited',
66
  'simple-history'
67
  ),
68
 
69
  'plugin_deleted' => _x(
70
+ 'Deleted plugin "{plugin_name}"',
71
  'Plugin files was deleted',
72
  'simple-history'
73
  ),
74
 
75
  // bulk versions
76
  'plugin_bulk_updated' => _x(
77
+ 'Updated plugin "{plugin_name}" to {plugin_version} from {plugin_prev_version}',
78
  'Plugin was updated in bulk',
79
  'simple-history'
80
  ),
113
  ) // search array
114
  ) // labels
115
  );
116
+
117
  return $arr_info;
118
 
119
  }
139
  // If a plugin is silently activated (such as during an update),
140
  // this hook does not fire.
141
  add_action( 'activated_plugin', array( $this, "on_activated_plugin" ), 10, 2 );
142
+
143
  // Fires after a plugin is deactivated.
144
  // If a plugin is silently deactivated (such as during an update),
145
  // this hook does not fire.
168
  } );
169
 
170
  }
171
+
172
  /**
173
  * Show readme from github in a modal win
174
  */
175
  function ajax_GetGitHubPluginInfo() {
176
+
177
  if ( ! current_user_can("install_plugins") ) {
178
  wp_die( __("You don't have access to this page.", "simple-history" ));
179
  }
180
+
181
  $repo = isset( $_GET["repo"] ) ? (string) $_GET["repo"] : "";
182
+
183
  if ( ! $repo ) {
184
  wp_die( __("Could not find GitHub repository.", "simple-history" ));
185
  }
196
  // https://api.github.com/repos/<username>/<repo>/readme
197
  $api_url = sprintf('https://api.github.com/repos/%1$s/%2$s/readme', urlencode( $repo_username ), urlencode( $repo_repo ));
198
 
199
+ // Get file. Use accept-header to get file as HTML instead of JSON
200
  $response = wp_remote_get( $api_url, array(
201
  "headers" => array(
202
  "accept" => "application/vnd.github.VERSION.html"
210
  esc_url( $repo ),
211
  esc_html( $repo )
212
  );
213
+
214
  $github_markdown_css_path = SIMPLE_HISTORY_PATH . "/css/github-markdown.css";
215
 
216
  printf(
235
  margin: 0 auto;
236
  padding: 30px;
237
  }
238
+
239
  @import url("%3$s");
240
+
241
  </style>
242
+
243
  <base href="%4$s/raw/master/">
244
+
245
  <header class="repo-info">
246
  %1$s
247
  </header>
248
+
249
  <div class="markdown-body readme-contents">
250
  %2$s
251
  </div>
255
  $github_markdown_css_path,
256
  esc_url( $repo ) // 4
257
  );
258
+
259
  #echo($response_body);
260
+
261
  exit;
262
 
263
  }
268
  * So before a plugin is deleted we save all needed info in a transient
269
  */
270
  function on_action_delete_selected() {
271
+
272
  // Same as in plugins.php
273
  if ( ! current_user_can('delete_plugins') ) {
274
  wp_die(__('You do not have sufficient permissions to delete plugins for this site.'));
312
  * set_transient('plugins_delete_result_' . $user_ID, $delete_result);
313
  *
314
  * We detect when that transient is set and then we have all info needed to log the plugin delete
315
+ *
316
  */
317
+ public function on_setted_transient_for_remove_files( $transient = "", $value = "" ) {
318
 
319
  if ( ! $user_id = get_current_user_id() ) {
320
  return;
326
  }
327
 
328
  // We found the transient we were looking for
329
+ if (
330
  isset( $_POST["action"] )
331
  && "delete-selected" == $_POST["action"]
332
  && isset( $_POST["checked"] )
344
  $plugins_before_update = json_decode( get_option( $this->slug . "_plugin_info_before_update", false ), true );
345
 
346
  foreach ( $plugins_deleted as $plugin ) {
347
+
348
  $context = array(
349
  "plugin" => $plugin // plugin-name-folder/plugin-main-file.php
350
  );
366
  }
367
 
368
  }
369
+
370
  $this->remove_saved_versions();
371
 
372
  }
376
  * This way we can know both the old (pre updated/removed) and the current version of the plugin
377
  */
378
  /*public function save_versions_before_update() {
379
+
380
  $current_screen = get_current_screen();
381
  $request_uri = $_SERVER["SCRIPT_NAME"];
382
 
383
  // Only add option on pages where needed
384
  $do_store = false;
385
 
386
+ if (
387
  SimpleHistory::ends_with( $request_uri, "/wp-admin/update.php" )
388
+ && isset( $current_screen->base )
389
+ && "update" == $current_screen->base
390
  ) {
391
+
392
  // Plugin update screen
393
  $do_store = true;
394
 
395
+ } else if (
396
  SimpleHistory::ends_with( $request_uri, "/wp-admin/plugins.php" )
397
+ && isset( $current_screen->base )
398
  && "plugins" == $current_screen->base
399
  && ( isset( $_POST["action"] ) && "delete-selected" == $_POST["action"] )
400
  ) {
401
+
402
  // Plugin delete screen, during delete
403
  $do_store = true;
404
 
419
  * delete_site_transient_update_plugins
420
  */
421
  public function remove_saved_versions() {
422
+
423
  delete_option( $this->slug . "_plugin_info_before_update" );
424
 
425
  }
428
 
429
  // Var is string with length 113: /wp-admin/plugin-editor.php?file=my-plugin%2Fviews%2Fplugin-file.php
430
  $referer = wp_get_referer();
431
+
432
  // contains key "path" with value like "/wp-admin/plugin-editor.php"
433
  $referer_info = parse_url($referer);
434
 
435
  if ( "/wp-admin/plugin-editor.php" === $referer_info["path"] ) {
436
 
437
  // We are in plugin editor
438
+ // Check for plugin edit saved
439
  if ( isset( $_POST["newcontent"] ) && isset( $_POST["action"] ) && "update" == $_POST["action"] && isset( $_POST["file"] ) && ! empty( $_POST["file"] ) ) {
440
 
441
  // A file was edited
443
 
444
  // $plugins = get_plugins();
445
  // http://codex.wordpress.org/Function_Reference/wp_text_diff
446
+
447
  // Generate a diff of changes
448
  if ( ! class_exists( 'WP_Text_Diff_Renderer_Table' ) ) {
449
  require_once( ABSPATH . WPINC . '/wp-diff.php' );
499
 
500
  */
501
 
502
+ /*
503
 
504
  # WordPress core update
505
+
506
  $arr_data:
507
  Array
508
  (
510
  [type] => core
511
  )
512
 
513
+
514
  # Plugin install
515
+
516
  $arr_data:
517
  Array
518
  (
522
 
523
 
524
  # Plugin update
525
+
526
  $arr_data:
527
  Array
528
  (
570
  "plugin_downloaded" => isset( $upgrader_skin_api->downloaded ) ? $upgrader_skin_api->downloaded : "",
571
  "plugin_added" => isset( $upgrader_skin_api->added ) ? $upgrader_skin_api->added : "",
572
  "plugin_source_files" => $this->simpleHistory->json_encode( $plugin_upgrader_instance->result["source_files"] ),
573
+
574
  // To debug comment out these:
575
  // "debug_skin_options" => $this->simpleHistory->json_encode( $upgrader_skin_options ),
576
  // "debug_skin_result" => $this->simpleHistory->json_encode( $upgrader_skin_result ),
608
  }
609
  }
610
  */
611
+
612
  if ( isset( $_FILES["pluginzip"]["name"] ) ) {
613
  $plugin_upload_name = $_FILES["pluginzip"]["name"];
614
  $context["plugin_upload_name"] = $plugin_upload_name;
630
  );
631
 
632
  $did_log = true;
633
+
634
  } else {
635
 
636
  // Plugin was successfully installed
637
  // Try to grab more info from the readme
638
  // Would be nice to grab a screenshot, but that is difficult since they often are stored remotely
639
  $plugin_destination = isset( $plugin_upgrader_instance->result["destination"] ) ? $plugin_upgrader_instance->result["destination"] : null;
640
+
641
  if ( $plugin_destination ) {
642
 
643
  $plugin_info = $plugin_upgrader_instance->plugin_info();
652
  $context["plugin_url"] = isset( $plugin_data["PluginURI"] ) ? $plugin_data["PluginURI"] : "";
653
  $context["plugin_version"] = isset( $plugin_data["Version"] ) ? $plugin_data["Version"] : "";
654
  $context["plugin_author"] = isset( $plugin_data["AuthorName"] ) ? $plugin_data["AuthorName"] : "";
655
+
656
  // Comment out these to debug plugin installs
657
  #$context["debug_plugin_data"] = $this->simpleHistory->json_encode( $plugin_data );
658
  #$context["debug_plugin_info"] = $this->simpleHistory->json_encode( $plugin_info );
659
+
660
  if ( ! empty( $plugin_data["GitHub Plugin URI"] ) ) {
661
  $context["plugin_github_url"] = $plugin_data["GitHub Plugin URI"];
662
  }
663
+
664
  }
665
 
666
  $this->infoMessage(
703
  // use transient to get url and package
704
  $update_plugins = get_site_transient( 'update_plugins' );
705
  if ( $update_plugins && isset( $update_plugins->response[ $arr_data["plugin"] ] ) ) {
706
+
707
  /*
708
  $update_plugins[plugin_path/slug]:
709
  {
753
  );
754
 
755
  $did_log = true;
756
+
757
  } else {
758
 
759
  $this->infoMessage(
770
  }
771
 
772
  } // update single
773
+
774
 
775
  /**
776
  * For bulk updates $arr_data looks like:
795
  $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_name );
796
 
797
  $plugin_slug = dirname( $plugin_name );
798
+
799
  $context = array(
800
  "plugin_slug" => $plugin_slug,
801
  "plugin_name" => $plugin_data["Name"],
809
  // get url and package
810
  $update_plugins = get_site_transient( 'update_plugins' );
811
  if ( $update_plugins && isset( $update_plugins->response[ $plugin_name ] ) ) {
812
+
813
  /*
814
  $update_plugins[plugin_path/slug]:
815
  {
854
 
855
  } // bulk update
856
 
857
+
858
  } // if plugin
859
 
860
  if ( ! $did_log ) {
867
  }
868
 
869
  /*
870
+ * Called from filter 'upgrader_post_install'.
871
  *
872
  * Used to log bulk plugin installs and updates
873
  *
880
  * @param array $result Installation result data.
881
  */
882
  public function on_upgrader_post_install( $response, $hook_extra, $result ) {
883
+
884
  #echo "on_upgrader_post_install";
885
  /*
886
+
887
  # Plugin update:
888
  $hook_extra
889
  Array
907
 
908
  // It's a plugin install
909
  #error_log("plugin install");
910
+
911
 
912
  } else if ( isset( $hook_extra["action"] ) && $hook_extra["action"] == "update" && isset( $hook_extra["type"] ) && $hook_extra["type"] == "plugin" ) {
913
+
914
  // It's a plugin upgrade
915
  #echo "plugin update!";
916
  //error_log("plugin update");
993
  'Network' - Boolean. Whether the plugin can only be activated network wide.
994
  */
995
  $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_name );
996
+
997
  $plugin_slug = dirname( $plugin_name );
998
 
999
  $context = array(
1011
  }
1012
 
1013
  $this->infoMessage( 'plugin_activated', $context );
1014
+
1015
  }
1016
 
1017
  /**
1022
 
1023
  $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_name );
1024
  $plugin_slug = dirname( $plugin_name );
1025
+
1026
  $context = array(
1027
  "plugin_name" => $plugin_data["Name"],
1028
  "plugin_slug" => $plugin_slug,
1053
 
1054
  // When a plugin is installed we show a bit more information
1055
  // We do it only on install because we don't want to clutter to log,
1056
+ // and when something is installed the description is most useul for other
1057
  // admins on the site
1058
  if ( "plugin_installed" === $message_key ) {
1059
+
1060
+ if ( isset( $context["plugin_description"] ) ) {
1061
 
1062
  // Description includes a link to author, remove that, i.e. all text after and including <cite>
1063
  $plugin_description = $context["plugin_description"];
1064
+ $cite_pos = strpos( $plugin_description, "<cite>" );
1065
  if ($cite_pos) {
1066
+ $plugin_description = substr( $plugin_description, 0, $cite_pos );
1067
  }
1068
 
1069
  // Keys to show
1086
  $output .= "<table class='SimpleHistoryLogitem__keyValueTable'>";
1087
 
1088
  foreach ( $arr_plugin_keys as $key => $desc ) {
1089
+
1090
  $desc_output = "";
1091
 
1092
  switch ( $key ) {
1103
  // URL needs a link
1104
  case "plugin_url":
1105
  $desc_output = sprintf('<a href="%1$s">%2$s</a>', esc_attr( $context["plugin_url"] ), esc_html( $context["plugin_url"] ));
1106
+ break;
1107
 
1108
  case "plugin_description":
1109
  $desc_output = $plugin_description;
1172
 
1173
  // Slug + web as install source = show link to wordpress.org
1174
  if ( $plugin_slug && isset( $context["plugin_install_source"] ) && $context["plugin_install_source"] == "web" ) {
1175
+
1176
  $output .= sprintf(
1177
  '
1178
  <tr>
1184
  esc_html_x("View plugin info", "plugin logger: plugin info thickbox title view all info", "simple-history")
1185
  );
1186
 
1187
+ }
1188
  // GitHub plugin url set = show link to github repo
1189
  else if ( isset( $context["plugin_install_source"] ) && $context["plugin_install_source"] == "upload" && ! empty( $context["plugin_github_url"] ) ) {
1190
+
1191
  // Can't embed iframe
1192
  // Must use API instead
1193
  // https://api.github.com/repos/<username>/<repo>/readme?callback=<callbackname>
1203
  esc_html_x("View plugin info", "plugin logger: plugin info thickbox title view all info", "simple-history")
1204
  );
1205
 
1206
+ }
1207
 
1208
  $output .= "</table>";
1209
 
1214
  $plugin_slug = ! empty( $context["plugin_slug"] ) ? $context["plugin_slug"] : "";
1215
 
1216
  if ( $plugin_slug && empty( $context["plugin_github_url"] ) ) {
1217
+
1218
  $link_title = esc_html_x("View plugin info", "plugin logger: plugin info thickbox title", "simple-history");
1219
  $url = admin_url( "plugin-install.php?tab=plugin-information&amp;plugin={$plugin_slug}&amp;section=&amp;TB_iframe=true&amp;width=640&amp;height=550" );
1220
+
1221
  if ( "plugin_updated" == $message_key || "plugin_bulk_updated" == $message_key ) {
1222
  $link_title = esc_html_x("View changelog", "plugin logger: plugin info thickbox title", "simple-history");
1223
  $url = admin_url( "plugin-install.php?tab=plugin-information&amp;plugin={$plugin_slug}&amp;section=changelog&amp;TB_iframe=true&amp;width=772&amp;height=550" );
1224
  }
1225
+
1226
  $output .= sprintf(
1227
  '<p><a title="%2$s" class="thickbox" href="%1$s">%2$s</a></p>',
1228
  $url,
1229
+ $link_title
1230
  );
1231
 
1232
  } else if ( ! empty( $context["plugin_github_url"] ) ) {
1233
+
1234
  $output .= sprintf(
1235
  '
1236
  <tr>
1242
  esc_html_x("View plugin info", "plugin logger: plugin info thickbox title view all info", "simple-history")
1243
  );
1244
 
1245
+ }
1246
 
1247
 
1248
  } // if plugin_updated
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://eskapism.se/sida/donate/
4
  Tags: history, log, changes, changelog, audit, trail, pages, attachments, users, cms, dashboard, admin, syslog, feed, activity, stream, audit trail, brute-force
5
  Requires at least: 4.5.1
6
  Tested up to: 4.5.2
7
- Stable tag: 2.7.2
8
 
9
  View changes made by users within WordPress. See who created a page, uploaded an attachment or approved an comment, and more.
10
 
@@ -132,7 +132,7 @@ initiated by a specific user.
132
 
133
  2. The __Post Quick Diff__ feature will make it quick and easy for a user of a site to see what updates other users have done to posts and pages.
134
 
135
- 3. Events with different severity Simple History uses the log levels specified in the PHP PSR-3 standard.
136
 
137
  4. Events have context with extra details - Each logged event can include useful rich formatted extra information. For example: a plugin install can contain author info and a the url to the plugin, and an uploaded image can contain a thumbnail of the image.
138
 
@@ -143,12 +143,15 @@ initiated by a specific user.
143
  7. A chart with some quick statistics is available, so you can see the number of events that has been logged each day.
144
  A simple way to see any uncommon activity, for example an increased number of logins or similar.
145
 
146
- 8. When users are created or changed you can see details on what have changed.
147
-
148
  == Changelog ==
149
 
150
  ## Changelog
151
 
 
 
 
 
 
152
  = 2.7.2 (June 2016) =
153
 
154
  - Fixed message about mbstring required not being echo'ed.
4
  Tags: history, log, changes, changelog, audit, trail, pages, attachments, users, cms, dashboard, admin, syslog, feed, activity, stream, audit trail, brute-force
5
  Requires at least: 4.5.1
6
  Tested up to: 4.5.2
7
+ Stable tag: 2.7.3
8
 
9
  View changes made by users within WordPress. See who created a page, uploaded an attachment or approved an comment, and more.
10
 
132
 
133
  2. The __Post Quick Diff__ feature will make it quick and easy for a user of a site to see what updates other users have done to posts and pages.
134
 
135
+ 3. When users are created or changed you can see details on what have changed.
136
 
137
  4. Events have context with extra details - Each logged event can include useful rich formatted extra information. For example: a plugin install can contain author info and a the url to the plugin, and an uploaded image can contain a thumbnail of the image.
138
 
143
  7. A chart with some quick statistics is available, so you can see the number of events that has been logged each day.
144
  A simple way to see any uncommon activity, for example an increased number of logins or similar.
145
 
 
 
146
  == Changelog ==
147
 
148
  ## Changelog
149
 
150
+ = 2.7.3 (June 2016) =
151
+
152
+ - Removed the usage of the mb_* functions and mbstring is no longer a requirement.
153
+ - Added a new debug tab to the settings page. On the debug page you can see stuff like how large your database is and how many rows that are stored in the database. Also, a list of all loggers are listed there together with some useful (for developers anyway) information.
154
+
155
  = 2.7.2 (June 2016) =
156
 
157
  - Fixed message about mbstring required not being echo'ed.
templates/template-settings-tab-debug.php ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ defined( 'ABSPATH' ) or die();
4
+
5
+ global $wpdb;
6
+
7
+ $table_name = $wpdb->prefix . SimpleHistory::DBTABLE;
8
+ $table_name_contexts = $wpdb->prefix . SimpleHistory::DBTABLE_CONTEXTS;
9
+
10
+ $period_days = (int) 14;
11
+ $period_start_date = DateTime::createFromFormat( 'U', strtotime( "-$period_days days" ) );
12
+ $period_end_date = DateTime::createFromFormat( 'U', time() );
13
+
14
+ /**
15
+ * Size of database in both number or rows and table size
16
+ */
17
+
18
+ echo "<h3>Database size</h3>";
19
+
20
+ // Get table sizes in mb
21
+ $sql_table_size = sprintf( '
22
+ SELECT table_name AS "table_name",
23
+ round(((data_length + index_length) / 1024 / 1024), 2) "size_in_mb"
24
+ FROM information_schema.TABLES
25
+ WHERE table_schema = "%1$s"
26
+ AND table_name IN ("%2$s", "%3$s");
27
+ ',
28
+ DB_NAME, // 1
29
+ $table_name, // 2
30
+ $table_name_contexts
31
+ );
32
+
33
+ $table_size_result = $wpdb->get_results( $sql_table_size );
34
+
35
+ // Get num of rows for each table
36
+ $total_num_rows_table = (int) $wpdb->get_var( "select count(*) FROM {$table_name}" );
37
+ $total_num_rows_table_contexts = (int) $wpdb->get_var( "select count(*) FROM {$table_name_contexts}" );
38
+
39
+ $table_size_result[0]->num_rows = $total_num_rows_table;
40
+ $table_size_result[1]->num_rows = $total_num_rows_table_contexts;
41
+
42
+ echo "<table class='widefat'>";
43
+ printf(
44
+ '<thead>
45
+ <tr>
46
+ <th>%1$s</th>
47
+ <th>%2$s</th>
48
+ <th>%3$s</th>
49
+ </tr>
50
+ </thead>
51
+ ',
52
+ _x("Table name", "debug dropin", "simple-history"),
53
+ _x("Size", "debug dropin", "simple-history"),
54
+ _x("Rows", "debug dropin", "simple-history")
55
+ );
56
+
57
+ $loopnum = 0;
58
+ foreach ( $table_size_result as $one_table ) {
59
+
60
+ $size = sprintf(
61
+ _x('%s MB', "debug dropin", "simple-history"),
62
+ $one_table->size_in_mb
63
+ );
64
+
65
+ $rows = sprintf(
66
+ _x('%s rows', "debug dropin", "simple-history"),
67
+ number_format_i18n( $one_table->num_rows, 0 )
68
+ );
69
+
70
+ printf( '<tr class="%4$s">
71
+ <td>%1$s</td>
72
+ <td>%2$s</td>
73
+ <td>%3$s</td>
74
+ </tr>',
75
+ $one_table->table_name,
76
+ $size,
77
+ $rows,
78
+ $loopnum % 2 ? " alt " : ""
79
+ );
80
+
81
+ $loopnum++;
82
+ }
83
+
84
+ echo "</table>";
85
+
86
+ $logQuery = new SimpleHistoryLogQuery();
87
+ $rows = $logQuery->query( array(
88
+ "posts_per_page" => 1,
89
+ ) );
90
+
91
+ // This is the number of rows with occasions taken into consideration
92
+ $total_accassions_rows_count = $rows["total_row_count"];
93
+
94
+ echo "<p>";
95
+ printf(
96
+ _x('Total %s rows, when grouped by occasion id.', "debug dropin", "simple-history" ),
97
+ $total_accassions_rows_count
98
+ );
99
+ echo "</p>";
100
+
101
+
102
+ // echo "<h4>Clear history interval</h4>";
103
+ // echo "<p>" . $this->sh->get_clear_history_interval() . "</p>";
104
+
105
+
106
+ /**
107
+ * Output a list of all active loggers, including name, slug, comment, message, capability and number of rows
108
+ * Retrieve them in order by the number of rows they have in the db
109
+ * Loggers with 0 rows in the db will not be included in the array, so we need to find those
110
+ * and add them manually last
111
+ */
112
+
113
+ $arr_logger_slugs = array();
114
+
115
+ foreach ( $this->sh->getInstantiatedLoggers() as $oneLogger ) {
116
+ $arr_logger_slugs[] = $oneLogger["instance"]->slug;
117
+ }
118
+
119
+ $sql_logger_counts = sprintf( '
120
+ SELECT logger, count(id) as count
121
+ FROM %1$s
122
+ WHERE logger IN ("%2$s")
123
+ GROUP BY logger
124
+ ORDER BY count DESC
125
+ ', $table_name, join( $arr_logger_slugs, '","' ) );
126
+
127
+ $logger_rows_count = $wpdb->get_results( $sql_logger_counts, OBJECT_K );
128
+
129
+ // Find loggers with no rows in db and append to array
130
+ $missing_logger_slugs = array_diff( $arr_logger_slugs, array_keys( $logger_rows_count ) );
131
+
132
+ foreach ( $missing_logger_slugs as $one_missing_logger_slug ) {
133
+
134
+ $logger_rows_count[$one_missing_logger_slug] = (object) array(
135
+ "logger" => $one_missing_logger_slug,
136
+ "count" => 0
137
+ );
138
+
139
+ }
140
+
141
+ echo "<h3>";
142
+ _ex("Loggers", "debug dropin", "simple-history");
143
+ echo "</h3>";
144
+
145
+ echo "<p>";
146
+ printf(
147
+ _x('Listing %1$d loggers, ordered by rows count in database.', "debug dropin", "simple-history"),
148
+ sizeof( $arr_logger_slugs ) // 1
149
+ );
150
+ echo "</p>";
151
+
152
+ echo "<table class='widefat fixed' cellpadding=2>";
153
+ printf(
154
+ '
155
+ <thead>
156
+ <tr>
157
+ <th>%1$s</th>
158
+ <th>%2$s</th>
159
+ <th>%3$s</th>
160
+ <th>%4$s</th>
161
+ <th>%5$s</th>
162
+ <th>%6$s</th>
163
+ </tr>
164
+ </thead>
165
+ ',
166
+ _x("Logger name", "debug dropin", "simple-history"),
167
+ _x("Slug", "debug dropin", "simple-history"),
168
+ _x("Description", "debug dropin", "simple-history"),
169
+ _x("Messages", "debug dropin", "simple-history"),
170
+ _x("Capability", "debug dropin", "simple-history"),
171
+ _x("Rows count", "debug dropin", "simple-history")
172
+ );
173
+
174
+ $loopnum = 0;
175
+
176
+ foreach ( $logger_rows_count as $one_logger_slug => $one_logger_val ) {
177
+
178
+ $logger = $this->sh->getInstantiatedLoggerBySlug( $one_logger_slug );
179
+
180
+ if ( ! $logger ) {
181
+ continue;
182
+ }
183
+
184
+ if ( isset( $logger_rows_count[ $one_logger_slug ] ) ) {
185
+ $one_logger_count = $logger_rows_count[ $one_logger_slug ];
186
+ } else {
187
+ // logger was not is sql result, so fake result
188
+ $one_logger_count = new stdclass;
189
+ $one_logger_count->count = 0;
190
+ }
191
+
192
+ $logger_info = $logger->getInfo();
193
+ $logger_messages = isset( $logger_info["messages"] ) ? (array) $logger_info["messages"] : array();
194
+
195
+ $html_logger_messages = "";
196
+
197
+ foreach ( $logger_messages as $message_key => $message ) {
198
+ $html_logger_messages .= sprintf( '<li>%1$s</li>', esc_html( $message ) );
199
+ }
200
+
201
+ if ( $html_logger_messages ) {
202
+
203
+ $str_num_message_strings = sprintf(
204
+ _x('%1$s message strings', "debug dropin", "simple-history"),
205
+ sizeof( $logger_messages )
206
+ );
207
+
208
+ $html_logger_messages = sprintf( '
209
+ <p>%1$s</p>
210
+ <ul class="hide-if-js">
211
+ %2$s
212
+ </ul>
213
+ ',
214
+ $str_num_message_strings, // 1
215
+ $html_logger_messages // 2
216
+ );
217
+
218
+ } else {
219
+ $html_logger_messages = "<p>No message strings</p>";
220
+ }
221
+
222
+ printf(
223
+ '
224
+ <tr class="%6$s">
225
+ <td>
226
+ <p><strong>%3$s</strong>
227
+ </td>
228
+ <td>
229
+ <p><code>%2$s</code></p>
230
+ </td>
231
+ <td>
232
+ <p>%4$s</p>
233
+ </td>
234
+ <td>
235
+ %7$s
236
+ </td>
237
+ <td>
238
+ <p>%5$s</p>
239
+ </td>
240
+ <td>
241
+ <p>%1$s</p>
242
+ </td>
243
+ </tr>
244
+ ',
245
+ number_format_i18n( $one_logger_count->count ),
246
+ esc_html( $one_logger_slug ), // 2
247
+ esc_html( $logger_info["name"] ),
248
+ esc_html( $logger_info["description"] ), // 4
249
+ esc_html( $logger->getCapability() ), // 5
250
+ $loopnum % 2 ? " alt " : "", // 6
251
+ $html_logger_messages // 7
252
+ );
253
+
254
+ $loopnum++;
255
+
256
+ }
257
+
258
+ echo "</table>";
tests/test-simplehistory.php CHANGED
@@ -97,7 +97,8 @@ class SimpleHistoryTest extends WP_UnitTestCase {
97
  $settings_tabs = $sh->getSettingsTabs();
98
  $arr_default_settings = array(
99
  "settings",
100
- "export"
 
101
  );
102
 
103
  $loaded_settings_slugs = wp_list_pluck( $settings_tabs, "slug" );
@@ -275,7 +276,7 @@ class SimpleHistoryTest extends WP_UnitTestCase {
275
  $this->assertArrayHasKey( "description", $info );
276
  $this->assertArrayHasKey( "capability", $info );
277
  $this->assertArrayHasKey( "messages", $info );
278
-
279
  $this->assertTrue( is_array( $info["messages"] ) );
280
  $this->assertTrue( is_array( $info["labels"] ) );
281
  $this->assertTrue( is_array( $info["labels"]["search"] ) );
@@ -285,4 +286,3 @@ class SimpleHistoryTest extends WP_UnitTestCase {
285
 
286
 
287
  }
288
-
97
  $settings_tabs = $sh->getSettingsTabs();
98
  $arr_default_settings = array(
99
  "settings",
100
+ "export",
101
+ "debug"
102
  );
103
 
104
  $loaded_settings_slugs = wp_list_pluck( $settings_tabs, "slug" );
276
  $this->assertArrayHasKey( "description", $info );
277
  $this->assertArrayHasKey( "capability", $info );
278
  $this->assertArrayHasKey( "messages", $info );
279
+
280
  $this->assertTrue( is_array( $info["messages"] ) );
281
  $this->assertTrue( is_array( $info["labels"] ) );
282
  $this->assertTrue( is_array( $info["labels"]["search"] ) );
286
 
287
 
288
  }