MainWP Child - Version 4.0.5

Version Description

  • 12-9-19 =
  • Added: support for the Pro Reports extension
  • Fixed: MainWP Child Reports version 2 compatibility
Download this release

Release Info

Developer mainwp
Plugin Icon 128x128 MainWP Child
Version 4.0.5
Comparing to
See all releases

Code changes from version 4.0.4 to 4.0.5

class/class-mainwp-child-back-up-wordpress.php CHANGED
@@ -224,7 +224,7 @@ class MainWP_Child_Back_Up_Wordpress {
224
  if ( file_exists( $file ) ) {
225
  $date = @filemtime( $file );
226
  if ( !empty( $date ) ) {
227
- do_action( "backupwordpress_backup", $destination, $message, 'finished', $backup_type, $date );
228
  MainWP_Helper::update_lasttime_backup('backupwordpress', $date); // to support backup before update feature
229
  }
230
  }
224
  if ( file_exists( $file ) ) {
225
  $date = @filemtime( $file );
226
  if ( !empty( $date ) ) {
227
+ do_action( "mainwp_reports_backupwordpress_backup", $destination, $message, 'finished', $backup_type, $date );
228
  MainWP_Helper::update_lasttime_backup('backupwordpress', $date); // to support backup before update feature
229
  }
230
  }
class/class-mainwp-child-back-wp-up.php CHANGED
@@ -311,7 +311,7 @@ class MainWP_Child_Back_WP_Up {
311
  $backup_type = ltrim($backup_type, ' + ');
312
  }
313
  $message = 'BackWPup backup finished (' . $backup_type . ')';
314
- do_action( 'mainwp_backwpup_backup', $message, $backup_type, $backup_time );
315
 
316
  if ($new_lasttime_logged < $backup_time)
317
  $new_lasttime_logged = $backup_time;
311
  $backup_type = ltrim($backup_type, ' + ');
312
  }
313
  $message = 'BackWPup backup finished (' . $backup_type . ')';
314
+ do_action( 'mainwp_reports_backwpup_backup', $message, $backup_type, $backup_time );
315
 
316
  if ($new_lasttime_logged < $backup_time)
317
  $new_lasttime_logged = $backup_time;
class/class-mainwp-child-reports-connector-backups.php DELETED
@@ -1,76 +0,0 @@
1
- <?php
2
- if ( class_exists( 'MainWP_WP_Stream_Connector' ) ) {
3
- class MainWP_Child_Reports_Connector_Backups extends MainWP_WP_Stream_Connector {
4
-
5
- /**
6
- * Connector slug
7
- *
8
- * @var string
9
- */
10
- public static $name = 'mainwp_backups';
11
-
12
- /**
13
- * Actions registered for this connector
14
- *
15
- * @var array
16
- */
17
- public static $actions = array(
18
- 'mainwp_backup',
19
- );
20
-
21
- /**
22
- * Return translated connector label
23
- *
24
- * @return string Translated connector label
25
- */
26
- public static function get_label() {
27
- return __( 'MainWP Backups', 'default' );
28
- }
29
-
30
- /**
31
- * Return translated action labels
32
- *
33
- * @return array Action label translations
34
- */
35
- public static function get_action_labels() {
36
- return array(
37
- 'mainwp_backup' => __( 'MainWP Backup', 'default' ),
38
- );
39
- }
40
-
41
- /**
42
- * Return translated context labels
43
- *
44
- * @return array Context label translations
45
- */
46
- public static function get_context_labels() {
47
- return array(
48
- 'mainwp_backups' => __( 'MainWP Backups', 'mainwp-child' ),
49
- );
50
- }
51
-
52
- /**
53
- * Add action links to Stream drop row in admin list screen
54
- *
55
- * @filter wp_stream_action_links_{connector}
56
- *
57
- * @param array $links Previous links registered
58
- * @param int $record Stream record
59
- *
60
- * @return array Action links
61
- */
62
- public static function action_links( $links, $record ) {
63
- return $links;
64
- }
65
-
66
- public static function callback_mainwp_backup( $destination, $message, $size, $status, $type ) {
67
- self::log(
68
- $message,
69
- compact( 'destination', 'status', 'type', 'size' ),
70
- 0,
71
- array( 'mainwp_backups' => 'mainwp_backup' )
72
- );
73
- }
74
- }
75
- }
76
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
class/class-mainwp-child-reports-connector-sucuri.php DELETED
@@ -1,92 +0,0 @@
1
- <?php
2
- if ( class_exists( 'MainWP_WP_Stream_Connector' ) ) {
3
- class MainWP_Child_Reports_Connector_Sucuri extends MainWP_WP_Stream_Connector {
4
-
5
- /**
6
- * Connector slug
7
- *
8
- * @var string
9
- */
10
- public static $name = 'mainwp_sucuri';
11
-
12
- /**
13
- * Actions registered for this connector
14
- *
15
- * @var array
16
- */
17
- public static $actions = array(
18
- 'mainwp_sucuri_scan',
19
- );
20
-
21
- /**
22
- * Return translated connector label
23
- *
24
- * @return string Translated connector label
25
- */
26
- public static function get_label() {
27
- return __( 'MainWP Sucuri', 'default' );
28
- }
29
-
30
- /**
31
- * Return translated action labels
32
- *
33
- * @return array Action label translations
34
- */
35
- public static function get_action_labels() {
36
- return array(
37
- 'mainwp_sucuri_scan' => __( 'Scan', 'default' ),
38
- );
39
- }
40
-
41
- /**
42
- * Return translated context labels
43
- *
44
- * @return array Context label translations
45
- */
46
- public static function get_context_labels() {
47
- return array(
48
- 'mainwp_sucuri' => __( 'MainWP Sucuri', 'default' ),
49
- );
50
- }
51
-
52
- /**
53
- * Add action links to Stream drop row in admin list screen
54
- *
55
- * @filter wp_stream_action_links_{connector}
56
- *
57
- * @param array $links Previous links registered
58
- * @param int $record Stream record
59
- *
60
- * @return array Action links
61
- */
62
- public static function action_links( $links, $record ) {
63
- return $links;
64
- }
65
-
66
- public static function callback_mainwp_sucuri_scan( $data, $scan_status, $scan_data ) {
67
- $message = '';
68
- if ( 'success' === $scan_status ) {
69
- $message = __( 'Sucuri scan successful!', 'mainwp-child' );
70
- $scan_status = 'success';
71
- } else {
72
- $message = __( 'Sucuri scan failed!', 'mainwp-child' );
73
- $scan_status = 'failed';
74
- }
75
-
76
- $scan_result = maybe_unserialize( base64_decode( $data ) );
77
- $status = $webtrust = '';
78
- if ( is_array( $scan_result ) ) {
79
- $status = isset( $scan_result['status'] ) ? $scan_result['status'] : '';
80
- $webtrust = isset( $scan_result['webtrust'] ) ? $scan_result['webtrust'] : '';
81
- }
82
-
83
- self::log(
84
- $message,
85
- compact( 'scan_status', 'status', 'webtrust', 'scan_data' ),
86
- 0,
87
- array( 'mainwp_sucuri' => 'mainwp_sucuri_scan' )
88
- );
89
- }
90
- }
91
- }
92
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
class/class-mainwp-child-timecapsule.php CHANGED
@@ -741,7 +741,7 @@ function get_sibling_files_callback_wptc() {
741
  if (count($formatted_backups) > 0) {
742
  foreach($formatted_backups as $key => $value) {
743
  $backup_time = $key;
744
- do_action( 'mainwp_wptimecapsule_backup', $message, $backup_type, $backup_time );
745
  }
746
  }
747
  }
741
  if (count($formatted_backups) > 0) {
742
  foreach($formatted_backups as $key => $value) {
743
  $backup_time = $key;
744
+ do_action( 'mainwp_reports_wptimecapsule_backup', $message, $backup_type, $backup_time );
745
  }
746
  }
747
  }
class/class-mainwp-child.php CHANGED
@@ -115,7 +115,7 @@ if ( isset( $_GET['skeleton_keyuse_nonce_key'] ) && isset( $_GET['skeleton_keyus
115
  }
116
 
117
  class MainWP_Child {
118
- public static $version = '4.0.4';
119
  private $update_version = '1.5';
120
 
121
  private $callableFunctions = array(
@@ -498,7 +498,7 @@ class MainWP_Child {
498
  'show_support' => 'mainwp_branding_show_support',
499
  'disable_change' => 'mainwp_branding_disable_change',
500
  'disable_switching_theme' => 'mainwp_branding_disable_switching_theme',
501
- 'hide_child_reports' => 'mainwp_creport_branding_stream_hide',
502
  'branding_ext_enabled' => 'mainwp_branding_ext_enabled'
503
  );
504
 
@@ -3630,7 +3630,7 @@ class MainWP_Child {
3630
  $information['wpversion'] = $wp_version;
3631
  $information['siteurl'] = get_option( 'siteurl' );
3632
  $information['wpe'] = MainWP_Helper::is_wp_engine() ? 1 : 0;
3633
-
3634
  $information['site_info'] = array(
3635
  'wpversion' => $wp_version,
3636
  'debug_mode' => (defined('WP_DEBUG') && true === WP_DEBUG) ? true : false,
@@ -3638,6 +3638,7 @@ class MainWP_Child {
3638
  'child_version' => self::$version,
3639
  'memory_limit' => MainWP_Child_Server_Information::getPHPMemoryLimit(),
3640
  'mysql_version' => MainWP_Child_Server_Information::getMySQLVersion(),
 
3641
  'ip' => $_SERVER['SERVER_ADDR']
3642
  );
3643
 
@@ -5282,45 +5283,59 @@ class MainWP_Child {
5282
  $maint_options = array();
5283
  }
5284
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5285
  $performed_what = array();
5286
  if ( empty( $max_revisions ) ) {
5287
  $sql_clean = "DELETE FROM $wpdb->posts WHERE post_type = 'revision'";
5288
- $wpdb->query( $sql_clean );
5289
- $performed_what[] = 'Posts revisions deleted';
 
5290
  } else {
5291
  $results = MainWP_Helper::getRevisions( $max_revisions );
5292
  $count_deleted = MainWP_Helper::deleteRevisions( $results, $max_revisions );
5293
- $performed_what[] = 'Posts revisions deleted';
5294
  }
5295
 
5296
  if ( in_array( 'autodraft', $maint_options ) ) {
5297
  $sql_clean = "DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'";
5298
  $wpdb->query( $sql_clean );
5299
- $performed_what[] = 'Auto draft posts deleted';
5300
  }
5301
 
5302
  if ( in_array( 'trashpost', $maint_options ) ) {
5303
  $sql_clean = "DELETE FROM $wpdb->posts WHERE post_status = 'trash'";
5304
  $wpdb->query( $sql_clean );
5305
- $performed_what[] = 'Trash posts deleted';
5306
  }
5307
 
5308
  if ( in_array( 'spam', $maint_options ) ) {
5309
  $sql_clean = "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'";
5310
  $wpdb->query( $sql_clean );
5311
- $performed_what[] = 'Spam comments deleted';
5312
  }
5313
 
5314
  if ( in_array( 'pending', $maint_options ) ) {
5315
  $sql_clean = "DELETE FROM $wpdb->comments WHERE comment_approved = '0'";
5316
  $wpdb->query( $sql_clean );
5317
- $performed_what[] = 'Pending comments deleted';
5318
  }
5319
 
5320
  if ( in_array( 'trashcomment', $maint_options ) ) {
5321
  $sql_clean = "DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'";
5322
  $wpdb->query( $sql_clean );
5323
- $performed_what[] = 'Trash comments deleted';
5324
  }
5325
 
5326
  if ( in_array( 'tags', $maint_options ) ) {
@@ -5332,7 +5347,7 @@ class MainWP_Child {
5332
  }
5333
  }
5334
  }
5335
- $performed_what[] = 'Tags with 0 posts associated deleted';
5336
  }
5337
 
5338
  if ( in_array( 'categories', $maint_options ) ) {
@@ -5344,19 +5359,19 @@ class MainWP_Child {
5344
  }
5345
  }
5346
  }
5347
- $performed_what[] = 'Categories with 0 posts associated deleted';
5348
  }
5349
 
5350
  if ( in_array( 'optimize', $maint_options ) ) {
5351
  $this->maintenance_optimize();
5352
- $performed_what[] = 'Database optimized';
5353
  }
5354
  if ( ! isset( $information['status'] ) ) {
5355
  $information['status'] = 'SUCCESS';
5356
  }
5357
 
5358
  if ( !empty( $performed_what ) && has_action( 'mainwp_reports_maintenance' ) ) {
5359
- $details = implode( ', ', $performed_what );
5360
  $log_time = time();
5361
  $message = $result = "Maintenance Performed";
5362
  do_action( 'mainwp_reports_maintenance', $message, $log_time, $details, $result);
115
  }
116
 
117
  class MainWP_Child {
118
+ public static $version = '4.0.5';
119
  private $update_version = '1.5';
120
 
121
  private $callableFunctions = array(
498
  'show_support' => 'mainwp_branding_show_support',
499
  'disable_change' => 'mainwp_branding_disable_change',
500
  'disable_switching_theme' => 'mainwp_branding_disable_switching_theme',
501
+ //'hide_child_reports' => 'mainwp_creport_branding_stream_hide',
502
  'branding_ext_enabled' => 'mainwp_branding_ext_enabled'
503
  );
504
 
3630
  $information['wpversion'] = $wp_version;
3631
  $information['siteurl'] = get_option( 'siteurl' );
3632
  $information['wpe'] = MainWP_Helper::is_wp_engine() ? 1 : 0;
3633
+ $theme_name = wp_get_theme()->get( 'Name' );
3634
  $information['site_info'] = array(
3635
  'wpversion' => $wp_version,
3636
  'debug_mode' => (defined('WP_DEBUG') && true === WP_DEBUG) ? true : false,
3638
  'child_version' => self::$version,
3639
  'memory_limit' => MainWP_Child_Server_Information::getPHPMemoryLimit(),
3640
  'mysql_version' => MainWP_Child_Server_Information::getMySQLVersion(),
3641
+ 'themeactivated' => $theme_name,
3642
  'ip' => $_SERVER['SERVER_ADDR']
3643
  );
3644
 
5283
  $maint_options = array();
5284
  }
5285
 
5286
+
5287
+ // $this->options = array(
5288
+ // 'revisions' => __( 'Delete all post revisions', 'mainwp-maintenance-extension' ),
5289
+ // 'autodraft' => __( 'Delete all auto draft posts', 'mainwp-maintenance-extension' ),
5290
+ // 'trashpost' => __( 'Delete trash posts', 'mainwp-maintenance-extension' ),
5291
+ // 'spam' => __( 'Delete spam comments', 'mainwp-maintenance-extension' ),
5292
+ // 'pending' => __( 'Delete pending comments', 'mainwp-maintenance-extension' ),
5293
+ // 'trashcomment' => __( 'Delete trash comments', 'mainwp-maintenance-extension' ),
5294
+ // 'tags' => __( 'Delete tags with 0 posts associated', 'mainwp-maintenance-extension' ),
5295
+ // 'categories' => __( 'Delete categories with 0 posts associated', 'mainwp-maintenance-extension' ),
5296
+ // 'optimize' => __( 'Optimize database tables', 'mainwp-maintenance-extension' )
5297
+ // );
5298
+
5299
  $performed_what = array();
5300
  if ( empty( $max_revisions ) ) {
5301
  $sql_clean = "DELETE FROM $wpdb->posts WHERE post_type = 'revision'";
5302
+ $wpdb->query( $sql_clean );
5303
+ // to fix issue of meta_value short length
5304
+ $performed_what[] = 'revisions'; //'Posts revisions deleted';
5305
  } else {
5306
  $results = MainWP_Helper::getRevisions( $max_revisions );
5307
  $count_deleted = MainWP_Helper::deleteRevisions( $results, $max_revisions );
5308
+ $performed_what[] = 'revisions'; //'Posts revisions deleted';
5309
  }
5310
 
5311
  if ( in_array( 'autodraft', $maint_options ) ) {
5312
  $sql_clean = "DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'";
5313
  $wpdb->query( $sql_clean );
5314
+ $performed_what[] = 'autodraft'; //'Auto draft posts deleted';
5315
  }
5316
 
5317
  if ( in_array( 'trashpost', $maint_options ) ) {
5318
  $sql_clean = "DELETE FROM $wpdb->posts WHERE post_status = 'trash'";
5319
  $wpdb->query( $sql_clean );
5320
+ $performed_what[] = 'trashpost'; //'Trash posts deleted';
5321
  }
5322
 
5323
  if ( in_array( 'spam', $maint_options ) ) {
5324
  $sql_clean = "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'";
5325
  $wpdb->query( $sql_clean );
5326
+ $performed_what[] = 'spam'; //'Spam comments deleted';
5327
  }
5328
 
5329
  if ( in_array( 'pending', $maint_options ) ) {
5330
  $sql_clean = "DELETE FROM $wpdb->comments WHERE comment_approved = '0'";
5331
  $wpdb->query( $sql_clean );
5332
+ $performed_what[] = 'pending'; //'Pending comments deleted';
5333
  }
5334
 
5335
  if ( in_array( 'trashcomment', $maint_options ) ) {
5336
  $sql_clean = "DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'";
5337
  $wpdb->query( $sql_clean );
5338
+ $performed_what[] = 'trashcomment'; //'Trash comments deleted';
5339
  }
5340
 
5341
  if ( in_array( 'tags', $maint_options ) ) {
5347
  }
5348
  }
5349
  }
5350
+ $performed_what[] = 'tags'; //'Tags with 0 posts associated deleted';
5351
  }
5352
 
5353
  if ( in_array( 'categories', $maint_options ) ) {
5359
  }
5360
  }
5361
  }
5362
+ $performed_what[] = 'categories'; //'Categories with 0 posts associated deleted';
5363
  }
5364
 
5365
  if ( in_array( 'optimize', $maint_options ) ) {
5366
  $this->maintenance_optimize();
5367
+ $performed_what[] = 'optimize'; //'Database optimized';
5368
  }
5369
  if ( ! isset( $information['status'] ) ) {
5370
  $information['status'] = 'SUCCESS';
5371
  }
5372
 
5373
  if ( !empty( $performed_what ) && has_action( 'mainwp_reports_maintenance' ) ) {
5374
+ $details = implode( ',', $performed_what );
5375
  $log_time = time();
5376
  $message = $result = "Maintenance Performed";
5377
  do_action( 'mainwp_reports_maintenance', $message, $log_time, $details, $result);
class/class-mainwp-client-report.php CHANGED
@@ -1,8 +1,9 @@
1
  <?php
2
 
3
  class MainWP_Client_Report {
4
- public static $instance = null;
5
-
 
6
  static function Instance() {
7
  if ( null === MainWP_Client_Report::$instance ) {
8
  MainWP_Client_Report::$instance = new MainWP_Client_Report();
@@ -10,15 +11,23 @@ class MainWP_Client_Report {
10
 
11
  return MainWP_Client_Report::$instance;
12
  }
13
-
 
 
 
 
14
  public function init() {
15
- add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
16
- //add_filter( 'wp_stream_connectors', array( 'MainWP_Client_Report', 'init_stream_connectors' ), 10, 1 );
17
- add_filter( 'mainwp_client_reports_connectors', array( 'MainWP_Client_Report', 'init_report_connectors' ), 10, 1 );
18
  add_action( 'mainwp_child_log', array( 'MainWP_Client_Report', 'do_reports_log' ) );
19
  }
20
 
21
- // ok
 
 
 
 
 
 
22
  public function syncOthersData( $information, $data = array() ) {
23
  if ( isset( $data['syncClientReportData'] ) && $data['syncClientReportData'] ) {
24
  $creport_sync_data = array();
@@ -32,48 +41,6 @@ class MainWP_Client_Report {
32
  return $information;
33
  }
34
 
35
-
36
- // not used
37
- public static function init_stream_connectors( $classes ) {
38
- $connectors = array(
39
- 'Backups',
40
- 'Sucuri',
41
- );
42
-
43
- foreach ( $connectors as $connector ) {
44
- $class_name = "MainWP_Child_Reports_Connector_$connector";
45
- if ( ! class_exists( $class_name ) ) {
46
- continue;
47
- }
48
- $class = new $class_name();
49
- if ( ! method_exists( $class, 'is_dependency_satisfied' ) ) {
50
- continue;
51
- }
52
- if ( $class->is_dependency_satisfied() ) {
53
- $classes[] = $class;
54
- }
55
- }
56
-
57
- return $classes;
58
- }
59
-
60
- public static function init_report_connectors( $classes ) {
61
- $connectors = array(
62
- 'Backups',
63
- 'Sucuri'
64
- );
65
-
66
- foreach ( $connectors as $connector ) {
67
- $class = "MainWP_Child_Reports_Connector_$connector";
68
- if ( ! class_exists( $class ) ) {
69
- continue;
70
- }
71
- $classes[] = $class;
72
- }
73
-
74
- return $classes;
75
- }
76
-
77
  public static function do_reports_log( $ext = '' ) {
78
  switch( $ext ) {
79
  case 'backupbuddy':
@@ -98,8 +65,8 @@ class MainWP_Client_Report {
98
 
99
  $information = array();
100
 
101
- if ( !function_exists( 'mainwp_wp_stream_query' ) || !class_exists( 'MainWP_WP_Stream' ) ) {
102
- $information['error'] = 'NO_CREPORT';
103
  MainWP_Helper::write( $information );
104
  }
105
 
@@ -122,10 +89,9 @@ class MainWP_Client_Report {
122
  MainWP_Helper::write( $information );
123
  }
124
 
125
- public function save_sucuri_stream() {
126
- $scan_data = isset($_POST['scan_data']) ? $_POST['scan_data'] : '';
127
- do_action( 'mainwp_sucuri_scan', $_POST['result'], $_POST['scan_status'], $scan_data );
128
-
129
  return true;
130
  }
131
 
@@ -134,7 +100,102 @@ class MainWP_Client_Report {
134
 
135
  return true;
136
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  public function get_stream() {
139
  // Filters
140
  $allowed_params = array(
@@ -170,7 +231,7 @@ class MainWP_Client_Report {
170
 
171
  $args = array();
172
  foreach ( $allowed_params as $param ) {
173
- $paramval = mainwp_wp_stream_filter_input( INPUT_POST, $param );
174
  if ( $paramval || '0' === $paramval ) {
175
  $args[ $param ] = $paramval;
176
  }
@@ -248,13 +309,14 @@ class MainWP_Client_Report {
248
 
249
  $args['action__not_in'] = array( 'login' );
250
 
251
- $args['fields'] = 'with-meta';
 
252
  if ( isset( $args['date_from'] ) ) {
253
- $args['date_from'] = date( 'Y-m-d H:i:s', $args['date_from'] );
254
  }
255
 
256
  if ( isset( $args['date_to'] ) ) {
257
- $args['date_to'] = date( 'Y-m-d H:i:s', $args['date_to'] );
258
  }
259
 
260
  if ( MainWP_Child_Branding::Instance()->is_branding() ) {
@@ -263,15 +325,13 @@ class MainWP_Client_Report {
263
 
264
  $args['records_per_page'] = 9999;
265
 
266
- $records = mainwp_wp_stream_query( $args );
267
-
 
268
  if ( ! is_array( $records ) ) {
269
  $records = array();
270
  }
271
 
272
- //return $records;
273
- //$other_tokens_data = $this->get_other_tokens_data($records, $other_tokens);
274
-
275
  // to fix invalid data
276
  $skip_records = array();
277
  if ( isset( $other_tokens['header'] ) && is_array( $other_tokens['header'] ) ) {
@@ -317,37 +377,6 @@ class MainWP_Client_Report {
317
 
318
  function get_other_tokens_data( $records, $tokens, &$skip_records ) {
319
 
320
- // convert context name of tokens to context name saved in child report
321
- // some context are not difference
322
- $convert_context_name = array(
323
- 'comment' => 'comments',
324
- 'plugin' => 'plugins',
325
- 'profile' => 'profiles',
326
- 'session' => 'sessions',
327
- 'setting' => 'settings',
328
- 'setting' => 'settings',
329
- 'theme' => 'themes',
330
- 'posts' => 'post',
331
- 'pages' => 'page',
332
- 'user' => 'users',
333
- 'widget' => 'widgets',
334
- 'menu' => 'menus',
335
- 'backups' => 'mainwp_backups',
336
- 'backup' => 'mainwp_backups',
337
- 'sucuri' => 'mainwp_sucuri',
338
- );
339
-
340
- $convert_action_name = array(
341
- 'restored' => 'untrashed',
342
- 'spam' => 'spammed',
343
- 'backups' => 'mainwp_backup',
344
- 'backup' => 'mainwp_backup',
345
- );
346
-
347
- $allowed_data = array(
348
- 'count'
349
- );
350
-
351
  $token_values = array();
352
 
353
  if ( ! is_array( $tokens ) ) {
@@ -357,7 +386,7 @@ class MainWP_Client_Report {
357
  $backups_created_time_to_fix = array();
358
  foreach ( $tokens as $token ) {
359
 
360
- if (isset($token_values[ $token ]))
361
  continue;
362
 
363
  $str_tmp = str_replace( array( '[', ']' ), '', $token );
@@ -371,71 +400,81 @@ class MainWP_Client_Report {
371
  list( $context, $action, $data ) = $array_tmp;
372
  }
373
 
374
- $context = isset( $convert_context_name[ $context ] ) ? $convert_context_name[ $context ] : $context;
375
- if ( isset( $convert_action_name[ $action ] ) ) {
376
- $action = $convert_action_name[ $action ];
 
 
 
 
 
 
 
 
 
 
377
  }
 
 
378
  switch ( $data ) {
379
  case 'count':
 
380
  $count = 0;
381
  foreach ( $records as $record ) {
382
- if ( 'themes' === $context && 'edited' === $action ) {
383
- if ( $record->action !== 'updated' || $record->connector !== 'editor' ) {
384
- continue;
385
- }
386
- } else if ( 'users' === $context && 'updated' === $action ) {
387
- if ( $record->context !== 'profiles' || $record->connector !== 'users' ) {
 
 
 
 
 
 
 
388
  continue;
389
  }
390
- } else if ( 'mainwp_backups' === $context ) {
391
- if ( $record->context !== 'mainwp_backups' && $record->context !== 'backwpup_backups' && $record->context !== 'updraftplus_backups' && $record->context !== 'backupwordpress_backups' && $record->context !== 'backupbuddy_backups' && $record->context !== 'wptimecapsule_backups') {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
392
  continue;
393
  }
394
-
395
  $created = strtotime( $record->created );
396
  if ( in_array( $created, $backups_created_time_to_fix ) ) {
397
- if ( !in_array($record->ID, $skip_records) ) {
398
  $skip_records[] = $record->ID;
399
  }
400
  continue;
401
  } else {
402
  $backups_created_time_to_fix[] = $created;
403
  }
404
-
405
- } else if ( 'mainwp_sucuri' === $context ) {
406
- if ( $record->context !== 'mainwp_sucuri' ) {
407
- continue;
408
- }
409
- } else if ( 'wordfence' === $context ) {
410
- if ( $record->context !== 'wordfence_scans' ) {
411
- continue;
412
- }
413
- } else if ( 'maintenance' === $context ) {
414
- if ( $record->context !== 'mainwp_maintenances' ) {
415
- continue;
416
- }
417
- } else {
418
  if ( $action !== $record->action ) {
419
  continue;
420
  }
421
 
422
- if ( 'comments' === $context && 'comments' !== $record->connector ) {
423
- continue;
424
- } else if ( 'media' === $context && 'media' !== $record->connector ) {
425
- continue;
426
- } else if ( 'widgets' === $context && 'widgets' !== $record->connector ) {
427
- continue;
428
- } else if ( 'menus' === $context && 'menus' !== $record->connector ) {
429
- continue;
430
- }
431
-
432
- if ( 'comments' !== $context && 'media' !== $context &&
433
- 'widgets' !== $context && 'menus' !== $context &&
434
- $record->context !== $context
435
- ) {
436
- continue;
437
- }
438
-
439
  if ( 'updated' === $action && ( 'post' === $context || 'page' === $context ) ) {
440
  $new_status = $this->get_stream_meta_data( $record, 'new_status' );
441
  if ( 'draft' === $new_status ) { // avoid auto save post
@@ -457,21 +496,7 @@ class MainWP_Client_Report {
457
  }
458
  }
459
  }
460
-
461
- // to avoid WC order_note, action_log
462
- if ( 'comments' === $context ) {
463
- if ( isset( $record->meta ) ) {
464
- if ( isset( $record->meta[ 'comment_type' ] ) && is_array($record->meta[ 'comment_type' ])) {
465
- $cmtype = current($record->meta[ 'comment_type' ]);
466
- if ( $cmtype == 'order_note' || $cmtype == 'action_log') {
467
- continue;
468
- }
469
- }
470
- }
471
- }
472
-
473
  }
474
-
475
  $count ++;
476
  }
477
  $token_values[ $token ] = $count;
@@ -485,43 +510,22 @@ class MainWP_Client_Report {
485
 
486
  function get_section_loop_data( $records, $tokens, $section, $skip_records = array() ) {
487
 
488
- $convert_context_name = array(
489
- 'comment' => 'comments',
490
- 'plugin' => 'plugins',
491
- 'profile' => 'profiles',
492
- 'session' => 'sessions',
493
- 'setting' => 'settings',
494
- 'theme' => 'themes',
495
- 'posts' => 'post',
496
- 'pages' => 'page',
497
- 'widget' => 'widgets',
498
- 'menu' => 'menus',
499
- 'backups' => 'mainwp_backups',
500
- 'backup' => 'mainwp_backups',
501
- 'sucuri' => 'mainwp_sucuri',
502
- );
503
-
504
- $convert_action_name = array(
505
- 'restored' => 'untrashed',
506
- 'spam' => 'spammed',
507
- 'backup' => 'mainwp_backup',
508
  );
509
-
510
- // $some_allowed_data = array(
511
- // 'ID',
512
- // 'name',
513
- // 'title',
514
- // 'oldversion',
515
- // 'currentversion',
516
- // 'date',
517
- // 'time',
518
- // 'count',
519
- // 'author',
520
- // 'old.version',
521
- // 'current.version',
522
- // );
523
-
524
- $context = $action = '';
525
  $str_tmp = str_replace( array( '[', ']' ), '', $section );
526
  $array_tmp = explode( '.', $str_tmp );
527
  if ( is_array( $array_tmp ) ) {
@@ -531,97 +535,86 @@ class MainWP_Client_Report {
531
  list( $str1, $context, $action ) = $array_tmp;
532
  }
533
  }
534
-
535
- $context = isset( $convert_context_name[ $context ] ) ? $convert_context_name[ $context ] : $context;
536
- $action = isset( $convert_action_name[ $action ] ) ? $convert_action_name[ $action ] : $action;
537
-
 
 
 
 
 
 
 
 
 
 
 
 
538
  $loops = array();
539
  $loop_count = 0;
540
 
541
  foreach ( $records as $record ) {
 
542
  if (in_array($record->ID, $skip_records)) {
543
  continue;
544
  }
545
-
546
- $theme_edited = $users_updated = $plugin_edited = false;
547
-
548
- if ( $plugin_edited ) {
549
- // ok next
550
- } else if ( 'themes' === $context && 'edited' === $action ) {
551
- if ( $record->action !== 'updated' || $record->connector !== 'editor' ) {
552
- continue;
553
- } else {
554
- $theme_edited = true;
555
- }
556
- } else if ( 'users' === $context && 'updated' === $action ) {
557
- if ( $record->context !== 'profiles' || $record->connector !== 'users' ) {
558
- continue;
559
- } else {
560
- $users_updated = true;
561
- }
562
- } else if ( 'mainwp_backups' === $context ) {
563
- if ( $record->context !== 'mainwp_backups' && $record->context !== 'backwpup_backups' && $record->context !== 'updraftplus_backups' && $record->context !== 'backupwordpress_backups' && $record->context !== 'backupbuddy_backups' && $record->context !== 'wptimecapsule_backups') {
564
- continue;
565
- }
566
- } else if ( 'mainwp_sucuri' === $context ) {
567
- if ( $record->context !== 'mainwp_sucuri' ) {
568
- continue;
569
- }
570
- } else if ( 'wordfence' === $context ) {
571
- if ( $record->context !== 'wordfence_scans' ) {
572
- continue;
573
- }
574
- } else if ( 'maintenance' === $context ) {
575
- if ( $record->context !== 'mainwp_maintenances' ) {
576
- continue;
577
- }
578
- } else {
579
- if ( $action !== $record->action ) {
580
- continue;
581
- }
582
-
583
- if ( 'comments' === $context && 'comments' !== $record->connector ) {
584
- continue;
585
- } else if ( 'media' === $context && 'media' !== $record->connector ) {
586
- continue;
587
- } else if ( 'widgets' === $context && 'widgets' !== $record->connector ) {
588
  continue;
589
- } else if ( 'menus' === $context && 'menus' !== $record->connector ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
590
  continue;
591
  }
592
- // else if ($context === "themes" && $record->connector !== "themes")
593
- // continue;
 
594
 
595
- if ( 'comments' !== $context && 'media' !== $context &&
596
- 'widgets' !== $context && 'menus' !== $context &&
597
- $record->context !== $context
598
- ) {
599
  continue;
600
  }
601
-
602
- if ( 'updated' === $action && ( 'post' === $context || 'page' === $context ) ) {
603
- $new_status = $this->get_stream_meta_data( $record, 'new_status' );
604
- if ( 'draft' === $new_status ) { // avoid auto save post
605
- continue;
606
- }
607
- }
608
- }
609
-
610
- // to avoid WC order_note, action_log
611
- if ( 'comments' === $context ) {
612
- if ( isset( $record->meta ) ) {
613
- if ( isset( $record->meta[ 'comment_type' ] ) && is_array($record->meta[ 'comment_type' ])) {
614
- $cmtype = current($record->meta[ 'comment_type' ]);
615
- if ( $cmtype == 'order_note' || $cmtype == 'action_log') {
616
- continue;
617
- }
618
- }
619
- }
620
- }
621
-
622
  $token_values = array();
623
 
624
- foreach ( $tokens as $token ) {
 
625
  $data = '';
626
  $token_name = str_replace( array( '[', ']' ), '', $token );
627
  $array_tmp = explode( '.', $token_name );
@@ -670,27 +663,11 @@ class MainWP_Client_Report {
670
  case 'new_version':
671
  case 'display_name':
672
  case 'roles':
673
- if ( 'name' === $data ) {
674
- if ( $theme_edited ) {
675
- $data = 'theme_name';
676
- } else if ( $plugin_edited ) {
677
- $data = 'plugin_name';
678
- } else if ( $users_updated ) {
679
- $data = 'display_name';
680
- }
681
- }
682
-
683
- if ( 'roles' === $data && $users_updated ) {
684
- $user_info = get_userdata( $record->object_id );
685
- if ( ! ( is_object( $user_info ) && $user_info instanceof WP_User ) ) {
686
- $roles = '';
687
- } else {
688
- $roles = implode( ', ', $user_info->roles );
689
- }
690
- $token_values[ $token ] = $roles;
691
- } else {
692
- $token_values[ $token ] = $this->get_stream_meta_data( $record, $data );
693
- }
694
  break;
695
  case 'title':
696
  if ( 'comments' === $context ) {
@@ -704,8 +681,13 @@ class MainWP_Client_Report {
704
  $token_values[ $token ] = $this->get_stream_meta_data( $record, $data );
705
  }
706
  break;
707
- case 'author':
708
- $data = 'author_meta';
 
 
 
 
 
709
  $value = $this->get_stream_meta_data( $record, $data );
710
  if ( empty( $value ) && 'comments' === $context ) {
711
  $value = __( 'Guest', 'mainwp-child-reports' );
@@ -714,8 +696,7 @@ class MainWP_Client_Report {
714
  break;
715
  case 'status': // sucuri cases
716
  case 'webtrust':
717
- if ( 'mainwp_sucuri' === $context ) {
718
-
719
  $scan_data = $this->get_stream_meta_data( $record, 'scan_data' );
720
  if (!empty($scan_data)) {
721
  $scan_data = maybe_unserialize( base64_decode( $scan_data ) );
@@ -746,7 +727,24 @@ class MainWP_Client_Report {
746
  break;
747
  case 'details':
748
  case 'result':
749
- if ( 'wordfence' === $context || 'maintenance' === $context ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
750
  $meta_value = $this->get_stream_meta_data( $record, $data );
751
  // to fix
752
  if ('wordfence' === $context && $data == 'result') {
@@ -763,9 +761,9 @@ class MainWP_Client_Report {
763
  $token_values[ $token ] = $meta_value;
764
  }
765
  break;
766
- case 'destination': // backup cases
767
- case 'type':
768
- if ( 'mainwp_backups' === $context ) {
769
  $token_values[ $token ] = $this->get_stream_meta_data( $record, $data );
770
  } else {
771
  $token_values[ $token ] = $token;
@@ -797,28 +795,30 @@ class MainWP_Client_Report {
797
 
798
  if ( isset( $record->meta ) ) {
799
  $meta = $record->meta;
800
- if ( isset( $meta[ $meta_key ] ) ) {
 
801
  $value = $meta[ $meta_key ];
802
- $value = current( $value );
803
- if ( 'author_meta' === $meta_key || 'user_meta' === $meta_key ) {
804
- $value = maybe_unserialize( $value );
805
- $value = $value['display_name'];
806
-
807
- if ( 'author_meta' === $meta_key && $value == '' && $context == 'comments') {
808
- $value = __( 'Guest', 'mainwp-child-reports' );
809
- }
810
- // to fix empty author value
811
- if ( empty($value) ) {
812
- if (isset($value['agent']) && !empty($value['agent'])) {
813
- $value = $value['agent'];
814
- }
815
- }
816
-
817
- if (!is_string($value)) {
818
- $value = '';
819
- }
820
- }
821
- }
 
822
  }
823
 
824
  return $value;
@@ -827,7 +827,7 @@ class MainWP_Client_Report {
827
  function set_showhide() {
828
  $hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
829
  MainWP_Child_Branding::Instance()->save_branding_options('hide_child_reports', $hide);
830
- MainWP_Helper::update_option( 'mainwp_creport_branding_stream_hide', $hide, 'yes' ); // to compatible with old child reports
831
  $information['result'] = 'SUCCESS';
832
 
833
  return $information;
1
  <?php
2
 
3
  class MainWP_Client_Report {
4
+
5
+ public static $instance = null;
6
+
7
  static function Instance() {
8
  if ( null === MainWP_Client_Report::$instance ) {
9
  MainWP_Client_Report::$instance = new MainWP_Client_Report();
11
 
12
  return MainWP_Client_Report::$instance;
13
  }
14
+
15
+ public function __construct() {
16
+ add_filter( 'wp_mainwp_stream_current_agent', array($this, 'current_agent' ), 10, 1 );
17
+ }
18
+
19
  public function init() {
20
+ add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
 
 
21
  add_action( 'mainwp_child_log', array( 'MainWP_Client_Report', 'do_reports_log' ) );
22
  }
23
 
24
+ public function current_agent( $agent ) {
25
+ if ( isset( $_POST['function'] ) && isset( $_POST['mainwpsignature'] ) )
26
+ $agent = '';
27
+ return $agent;
28
+ }
29
+
30
+ // ok
31
  public function syncOthersData( $information, $data = array() ) {
32
  if ( isset( $data['syncClientReportData'] ) && $data['syncClientReportData'] ) {
33
  $creport_sync_data = array();
41
  return $information;
42
  }
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  public static function do_reports_log( $ext = '' ) {
45
  switch( $ext ) {
46
  case 'backupbuddy':
65
 
66
  $information = array();
67
 
68
+ if ( !function_exists( 'wp_mainwp_stream_get_instance' ) ) {
69
+ $information['error'] = __( 'Error: No MainWP Client Reports plugin installed.' );
70
  MainWP_Helper::write( $information );
71
  }
72
 
89
  MainWP_Helper::write( $information );
90
  }
91
 
92
+ public function save_sucuri_stream() {
93
+ $scan_data = isset($_POST['scan_data']) ? $_POST['scan_data'] : '';
94
+ do_action( 'mainwp_reports_sucuri_scan', $_POST['result'], $_POST['scan_status'], $scan_data, isset($_POST['scan_time']) ? $_POST['scan_time'] : 0 );
 
95
  return true;
96
  }
97
 
100
 
101
  return true;
102
  }
103
+
104
+ public function is_backup_action( $action ) {
105
+ if ( in_array( $action, array( 'mainwp_backup', 'backupbuddy_backup', 'backupwordpress_backup', 'backwpup_backup', 'updraftplus_backup', 'wptimecapsule_backup' ) ) )
106
+ return true;
107
+ return false;
108
+ }
109
+
110
+ public function get_compatible_context( $context ) {
111
+ // convert context name of tokens to context name saved in child report
112
+ // some context are not difference
113
+ $mapping_contexts = array(
114
+ 'comment' => 'comments', // actual context values: post,page
115
+ 'plugin' => 'plugins',
116
+ 'users' => 'profiles',
117
+ 'user' => 'profiles',
118
+ 'session' => 'sessions',
119
+ 'setting' => 'settings',
120
+ 'theme' => 'themes',
121
+ 'posts' => 'post',
122
+ 'pages' => 'page',
123
+ 'widgets' => 'widgets',
124
+ 'widget' => 'widgets',
125
+ 'menu' => 'menus',
126
+ 'backups' => 'backups',
127
+ 'backup' => 'backups',
128
+ 'sucuri' => 'sucuri_scan',
129
+ 'maintenance' => 'mainwp_maintenance',
130
+ 'wordfence' => 'wordfence_scan',
131
+ 'backups' => 'backups',
132
+ 'backup' => 'backups',
133
+ 'media' => 'media'
134
+ );
135
+
136
+ return isset( $mapping_contexts[ $context ] ) ? $mapping_contexts[ $context ] : $context;
137
+ }
138
+
139
+
140
+ public function get_connector_by_compatible_context( $context ) {
141
+
142
+ $connector = "";
143
+ if ( $context == "plugins" || $context == "themes" ) {
144
+ $connector = "installer";
145
+ } else if ( $context == 'profiles' ) {
146
+ $connector = "users";
147
+ } else if ( $context == 'comments' ) { // multi values
148
+ $connector = "comments";
149
+ }
150
+ // else if ( $context == 'sessions' ) {
151
+ // $connector = "users";
152
+ // }
153
+ else if ( $context == 'settings' ) {
154
+ $connector = "settings";
155
+ } else if ( $context == 'post' || $context == 'page') {
156
+ $connector = "posts";
157
+ } else if ( $context == 'widgets' ) {
158
+ $connector = "widgets";
159
+ } else if ( $context == 'menus' ) {
160
+ $connector = "menus";
161
+ } else if ( $context == 'backups' ) {
162
+ $connector = "mainwp_backups";
163
+ } else if ( $context == 'sucuri_scan' ) {
164
+ $connector = "mainwp_sucuri";
165
+ } else if ( $context == 'mainwp_maintenance' ) {
166
+ $connector = "mainwp_maintenance";
167
+ } else if ( $context == 'wordfence_scan' ) {
168
+ $connector = "mainwp_wordfence";
169
+ } else if ( $context == 'media' ) {
170
+ $connector = "media";
171
+ }
172
+
173
+ return $connector;
174
+ }
175
 
176
+ public function get_compatible_action( $action, $context = '' ) {
177
+
178
+ $mapping_actions = array(
179
+ 'restored' => 'untrashed',
180
+ 'spam' => 'spammed',
181
+ );
182
+
183
+ if (isset($mapping_actions[ $action ]))
184
+ return $mapping_actions[ $action ];
185
+
186
+ if ( $context == 'mainwp_maintenance' ) {
187
+ if ( $action == 'process')
188
+ $action = 'maintenance';
189
+ } else if ( $context == 'sucuri_scan' ) {
190
+ if ( $action == 'checks')
191
+ $action = 'sucuri_scan';
192
+ } else if ($context == 'wordfence_scan') {
193
+ if ( $action == 'scan')
194
+ $action = 'wordfence_scan';
195
+ }
196
+ return $action;
197
+ }
198
+
199
  public function get_stream() {
200
  // Filters
201
  $allowed_params = array(
231
 
232
  $args = array();
233
  foreach ( $allowed_params as $param ) {
234
+ $paramval = wp_mainwp_stream_filter_input( INPUT_POST, $param );
235
  if ( $paramval || '0' === $paramval ) {
236
  $args[ $param ] = $paramval;
237
  }
309
 
310
  $args['action__not_in'] = array( 'login' );
311
 
312
+ $args['with-meta'] = 1;
313
+
314
  if ( isset( $args['date_from'] ) ) {
315
+ $args['date_from'] = date( 'Y-m-d', $args['date_from'] );
316
  }
317
 
318
  if ( isset( $args['date_to'] ) ) {
319
+ $args['date_to'] = date( 'Y-m-d', $args['date_to'] );
320
  }
321
 
322
  if ( MainWP_Child_Branding::Instance()->is_branding() ) {
325
 
326
  $args['records_per_page'] = 9999;
327
 
328
+ // $records = mainwp_wp_stream_query( $args );
329
+ $records = wp_mainwp_stream_get_instance()->db->query( $args );
330
+
331
  if ( ! is_array( $records ) ) {
332
  $records = array();
333
  }
334
 
 
 
 
335
  // to fix invalid data
336
  $skip_records = array();
337
  if ( isset( $other_tokens['header'] ) && is_array( $other_tokens['header'] ) ) {
377
 
378
  function get_other_tokens_data( $records, $tokens, &$skip_records ) {
379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
  $token_values = array();
381
 
382
  if ( ! is_array( $tokens ) ) {
386
  $backups_created_time_to_fix = array();
387
  foreach ( $tokens as $token ) {
388
 
389
+ if ( isset( $token_values[ $token ] ) )
390
  continue;
391
 
392
  $str_tmp = str_replace( array( '[', ']' ), '', $token );
400
  list( $context, $action, $data ) = $array_tmp;
401
  }
402
 
403
+ $context = $this->get_compatible_context( $context );
404
+
405
+ // to compatible with new version of child report
406
+ // to check condition for grabbing report data
407
+ $connector = $this->get_connector_by_compatible_context( $context );
408
+
409
+ $action = $this->get_compatible_action( $action, $context );
410
+
411
+ // custom values
412
+ if ( $context == 'profiles' ) {
413
+ if ( $action == 'created' || $action == 'deleted' ) {
414
+ $context = 'users'; // see class-connector-user.php
415
+ }
416
  }
417
+ ////
418
+
419
  switch ( $data ) {
420
  case 'count':
421
+
422
  $count = 0;
423
  foreach ( $records as $record ) {
424
+
425
+ // check connector
426
+ if ( $record->connector == 'editor' ) {
427
+ if ( !in_array( $context, array('plugins', 'themes') ) || $action !== 'updated' )
428
+ continue;
429
+ } else if ( $connector !== $record->connector ) {
430
+ continue;
431
+ }
432
+
433
+ // check context
434
+ if ( $context == 'comments' ) { // multi values
435
+ $comment_contexts = array( 'post', 'page' );
436
+ if ( ! in_array( $record->context, $comment_contexts ) ) {
437
  continue;
438
  }
439
+ } else if ( $context == "menus") {
440
+ // ok, pass, don't check context
441
+ } else if ( $record->connector == 'editor' ) {
442
+ // ok, pass, checked above
443
+ } else if ( $connector == 'media' && $record->connector == 'media' ) {
444
+ // ok, pass, do not check context
445
+ } else if ( $connector == "widgets" && $record->connector == 'widgets') {
446
+ // ok, pass, don't check context
447
+ } else if ( $context !== $record->context) {
448
+ continue;
449
+ }
450
+
451
+ // custom action value
452
+ if ( $connector == "widgets" ) {
453
+ if ( $action == "deleted" ) {
454
+ $action = "removed"; // action saved in database
455
+ }
456
+ }
457
+ ////
458
+
459
+ // check action
460
+ if ( 'backups' === $context ) {
461
+ if ( ! $this->is_backup_action($record->action) ) {
462
  continue;
463
  }
 
464
  $created = strtotime( $record->created );
465
  if ( in_array( $created, $backups_created_time_to_fix ) ) {
466
+ if ( ! in_array($record->ID, $skip_records) ) {
467
  $skip_records[] = $record->ID;
468
  }
469
  continue;
470
  } else {
471
  $backups_created_time_to_fix[] = $created;
472
  }
473
+ } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
474
  if ( $action !== $record->action ) {
475
  continue;
476
  }
477
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478
  if ( 'updated' === $action && ( 'post' === $context || 'page' === $context ) ) {
479
  $new_status = $this->get_stream_meta_data( $record, 'new_status' );
480
  if ( 'draft' === $new_status ) { // avoid auto save post
496
  }
497
  }
498
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
499
  }
 
500
  $count ++;
501
  }
502
  $token_values[ $token ] = $count;
510
 
511
  function get_section_loop_data( $records, $tokens, $section, $skip_records = array() ) {
512
 
513
+
514
+ $maintenance_details = array(
515
+ 'revisions' => __( 'Delete all post revisions', 'mainwp-child' ),
516
+ 'autodraft' => __( 'Delete all auto draft posts', 'mainwp-child' ),
517
+ 'trashpost' => __( 'Delete trash posts', 'mainwp-child' ),
518
+ 'spam' => __( 'Delete spam comments', 'mainwp-child' ),
519
+ 'pending' => __( 'Delete pending comments', 'mainwp-child' ),
520
+ 'trashcomment' => __( 'Delete trash comments', 'mainwp-child' ),
521
+ 'tags' => __( 'Delete tags with 0 posts associated', 'mainwp-child' ),
522
+ 'categories' => __( 'Delete categories with 0 posts associated', 'mainwp-child' ),
523
+ 'optimize' => __( 'Optimize database tables', 'mainwp-child' )
 
 
 
 
 
 
 
 
 
524
  );
525
+
526
+ $context = $action = '';
527
+
528
+ // parse $context, $action values from section tokens
 
 
 
 
 
 
 
 
 
 
 
 
529
  $str_tmp = str_replace( array( '[', ']' ), '', $section );
530
  $array_tmp = explode( '.', $str_tmp );
531
  if ( is_array( $array_tmp ) ) {
535
  list( $str1, $context, $action ) = $array_tmp;
536
  }
537
  }
538
+ // end
539
+
540
+ // get db $context value by mapping
541
+ $context = $this->get_compatible_context( $context );
542
+ // to compatible with new version of child report
543
+ // to check condition for grabbing report data
544
+ $connector = $this->get_connector_by_compatible_context( $context );
545
+
546
+ $action = $this->get_compatible_action( $action, $context );
547
+
548
+ if ( $context == 'profiles' ) {
549
+ if ( $action == 'created' || $action == 'deleted' ) {
550
+ $context = 'users'; // see class-connector-user.php
551
+ }
552
+ }
553
+
554
  $loops = array();
555
  $loop_count = 0;
556
 
557
  foreach ( $records as $record ) {
558
+
559
  if (in_array($record->ID, $skip_records)) {
560
  continue;
561
  }
562
+
563
+ // check connector
564
+ if ( $record->connector == 'editor' ) {
565
+ if ( !in_array( $context, array('plugins', 'themes') ) || $action !== 'updated' )
566
+ continue;
567
+ } else if ( $connector !== $record->connector ) {
568
+ continue;
569
+ }
570
+
571
+ // check context
572
+ if ( $context == "comments" ) { // multi values
573
+ $comment_contexts = array('post', 'page');
574
+ if ( ! in_array( $record->context, $comment_contexts ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
575
  continue;
576
+ }
577
+ } else if ( $context == "menus") {
578
+ // ok, pass, don't check context
579
+ } else if ( $record->connector == 'editor' ) {
580
+ // ok, pass, checked above
581
+ } else if ( $connector == 'media' && $record->connector == 'media' ) {
582
+ // ok, pass, do not check context
583
+ } else if ( $connector == "widgets" && $record->connector == 'widgets') {
584
+ // ok, pass, don't check context
585
+ //
586
+ } else if ( $context !== $record->context ) {
587
+ continue;
588
+ }
589
+
590
+ // custom action value
591
+ if ( $connector == "widgets" ) {
592
+ if ( $action == "deleted" ) {
593
+ $action = "removed"; // action saved in database
594
+ }
595
+ }
596
+ ////
597
+
598
+ // check action
599
+ if ( $context == 'backups' ) {
600
+ if ( ! $this->is_backup_action($record->action) ) {
601
  continue;
602
  }
603
+ } else if ( $action !== $record->action ) {
604
+ continue;
605
+ }
606
 
607
+ if ( 'updated' === $action && ( 'post' === $context || 'page' === $context ) ) {
608
+ $new_status = $this->get_stream_meta_data( $record, 'new_status' );
609
+ if ( 'draft' === $new_status ) { // avoid auto save post
 
610
  continue;
611
  }
612
+ }
613
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
614
  $token_values = array();
615
 
616
+ foreach ( $tokens as $token ) {
617
+ // parse $data value from tokens in sections
618
  $data = '';
619
  $token_name = str_replace( array( '[', ']' ), '', $token );
620
  $array_tmp = explode( '.', $token_name );
663
  case 'new_version':
664
  case 'display_name':
665
  case 'roles':
666
+ if ( $data == 'name' ) {
667
+ if ( $context == 'profiles' )
668
+ $data = 'display_name';
669
+ }
670
+ $token_values[ $token ] = $this->get_stream_meta_data( $record, $data );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
671
  break;
672
  case 'title':
673
  if ( 'comments' === $context ) {
681
  $token_values[ $token ] = $this->get_stream_meta_data( $record, $data );
682
  }
683
  break;
684
+ case 'author':
685
+ if ( $connector == "comment" ) {
686
+ $data = 'user_name';
687
+ } else {
688
+ $data = 'user_meta';
689
+ }
690
+
691
  $value = $this->get_stream_meta_data( $record, $data );
692
  if ( empty( $value ) && 'comments' === $context ) {
693
  $value = __( 'Guest', 'mainwp-child-reports' );
696
  break;
697
  case 'status': // sucuri cases
698
  case 'webtrust':
699
+ if ( 'sucuri_scan' === $context ) {
 
700
  $scan_data = $this->get_stream_meta_data( $record, 'scan_data' );
701
  if (!empty($scan_data)) {
702
  $scan_data = maybe_unserialize( base64_decode( $scan_data ) );
727
  break;
728
  case 'details':
729
  case 'result':
730
+
731
+ if ('mainwp_maintenance' === $context && 'details' == $data) {
732
+
733
+ $meta_value = $this->get_stream_meta_data( $record, $data );
734
+ $meta_value = explode(",", $meta_value);
735
+
736
+ $details = array();
737
+
738
+ if ( is_array( $meta_value) ) {
739
+ foreach($meta_value as $mt) {
740
+ if ( isset($maintenance_details[$mt]) ) {
741
+ $details[] = $maintenance_details[$mt];
742
+ }
743
+ }
744
+ }
745
+ $token_values[ $token ] = implode(", ", $details);
746
+
747
+ } else if ( 'wordfence_scan' === $context || 'mainwp_maintenance' === $context ) {
748
  $meta_value = $this->get_stream_meta_data( $record, $data );
749
  // to fix
750
  if ('wordfence' === $context && $data == 'result') {
761
  $token_values[ $token ] = $meta_value;
762
  }
763
  break;
764
+ //case 'destination': // for backup tokens
765
+ case 'type':
766
+ if ( 'backups' === $context ) {
767
  $token_values[ $token ] = $this->get_stream_meta_data( $record, $data );
768
  } else {
769
  $token_values[ $token ] = $token;
795
 
796
  if ( isset( $record->meta ) ) {
797
  $meta = $record->meta;
798
+
799
+ if ( isset( $meta[ $meta_key ] ) ) {
800
  $value = $meta[ $meta_key ];
801
+ $value = current( $value );
802
+
803
+ // if ( 'author_meta' === $meta_key || 'user_meta' === $meta_key ) {
804
+ // $value = maybe_unserialize( $value );
805
+ // $value = $value['display_name'];
806
+ //
807
+ // if ( 'author_meta' === $meta_key && $value == '' && $context == 'comments') {
808
+ // $value = __( 'Guest', 'mainwp-child-reports' );
809
+ // }
810
+ // // to fix empty author value
811
+ // if ( empty($value) ) {
812
+ // if (isset($value['agent']) && !empty($value['agent'])) {
813
+ // $value = $value['agent'];
814
+ // }
815
+ // }
816
+ //
817
+ // if (!is_string($value)) {
818
+ // $value = '';
819
+ // }
820
+ // }
821
+ }
822
  }
823
 
824
  return $value;
827
  function set_showhide() {
828
  $hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
829
  MainWP_Child_Branding::Instance()->save_branding_options('hide_child_reports', $hide);
830
+ //MainWP_Helper::update_option( 'mainwp_creport_branding_stream_hide', $hide, 'yes' ); // to compatible with old child reports
831
  $information['result'] = 'SUCCESS';
832
 
833
  return $information;
mainwp-child.php CHANGED
@@ -6,7 +6,7 @@
6
  Author: MainWP
7
  Author URI: https://mainwp.com
8
  Text Domain: mainwp-child
9
- Version: 4.0.4
10
  */
11
  include_once( ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'version.php' ); //Version information from wordpress
12
 
6
  Author: MainWP
7
  Author URI: https://mainwp.com
8
  Text Domain: mainwp-child
9
+ Version: 4.0.5
10
  */
11
  include_once( ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'version.php' ); //Version information from wordpress
12
 
readme.txt CHANGED
@@ -7,7 +7,7 @@ Plugin URI: https://mainwp.com
7
  Requires at least: 3.6
8
  Tested up to: 5.3
9
  Requires PHP: 5.6
10
- Stable tag: 4.0.4
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
 
@@ -71,6 +71,10 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
71
 
72
  == Changelog ==
73
 
 
 
 
 
74
  = 4.0.4 - 11-11-19 =
75
  * Fixed: WordPress 5.3 compatibility problems
76
  * Fixed: an issue with managing BackWPup backups
7
  Requires at least: 3.6
8
  Tested up to: 5.3
9
  Requires PHP: 5.6
10
+ Stable tag: 4.0.5
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
 
71
 
72
  == Changelog ==
73
 
74
+ = 4.0.5 - 12-9-19 =
75
+ * Added: support for the Pro Reports extension
76
+ * Fixed: MainWP Child Reports version 2 compatibility
77
+
78
  = 4.0.4 - 11-11-19 =
79
  * Fixed: WordPress 5.3 compatibility problems
80
  * Fixed: an issue with managing BackWPup backups