PluginProbe
InfiniteWP Client / trunk
InfiniteWP Client vtrunk
1.13.10 1.13.7 trunk 0.1.4 0.1.5 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.11.0 1.11.1 1.12.1 1.12.3 All 92 releases
iwp-client / activities_log.class.php

activities_log.class.php in InfiniteWP Client trunk, at activities_log.class.php

887 lines 33.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /************************************************************
3 * This plugin was modified by Revmakx *
4 * Copyright (c) 2012 Revmakx *
5 * www.revmakx.com *
6 * *
7 ************************************************************/
8 /*************************************************************
9 *
10 * activities_log.class.php
11 *
12 * Utility functions
13 *
14 *
15 * Copyright (c) 2011 Prelovac Media
16 * www.prelovac.com
17 **************************************************************/
18 if ( ! defined('ABSPATH') )
19 die();
20 class IWP_MMB_Activities_log {
21
22 function __construct() {
23 if(function_exists('add_action')) {
24 add_action('core_upgrade_preamble',array( &$this, 'iwp_mmb_core_upgrade_preamble'));
25 add_action('_core_updated_successfully',array( &$this, 'iwp_mmb_core_updated_successfully'), 1, 1); // It will call after "wordpress core updates via wp-admin or wp-cron" completed. It is available from wordpress 3.3.
26 add_action('upgrader_process_complete', array( &$this, 'iwp_mmb_upgrader_process_complete'), 1, 2); // It is available from wordpress 3.7. It is for plugins upgrade, themes upgrade, plugins install and themes install.
27 add_action('automatic_updates_complete', array( &$this, 'iwp_mmb_automatic_updates_complete'), 10, 1); // It is available since wordpress 3.8. It is for automatic translation updates.
28 add_action('updated_option', array( &$this, 'iwp_mmb_check_and_update_all_plugins_themes_history'), 10, 3);
29 add_action( 'init', array( &$this, 'iwp_mmb_register_custom_post_type' ),10,1,1 );
30 // add_action('sucuriscan_scheduled_scan', array( &$this, 'iwp_mmb_save_sucuri_activity_log'),99999); // We can use this action if sucuri implement schedule remote scan
31
32 }
33
34 if(function_exists('add_filter')) {
35
36 add_filter('update_theme_complete_actions', array( &$this, 'iwp_mmb_update_theme_complete_actions'), 1, 2); // It is available from wordpress 2.7 to 3.6.
37 add_filter('update_bulk_theme_complete_actions', array( &$this, 'iwp_mmb_update_bulk_theme_complete_actions'), 1, 2); // It is available from wordpress 2.7 to 3.6.
38
39 add_filter('async_update_translation', array( &$this, 'iwp_mmb_async_update_translation'), 1, 2); // why we added this hook? Because, whenever we tried to update the core, plugins and themes, translation updates automatically trigger. To prevent it, we added this line. It is available since wordpress 4.0.
40
41 add_filter('update_translations_complete_actions', array( &$this, 'iwp_mmb_update_translations_complete_actions'), 10, 1); // It is available since wordpress 3.7.
42 add_filter('upgrader_post_install', array( &$this, 'iwp_mmb_upgrader_post_install'), 10, 3);
43 // We couldn't get the error for failure translations updates (in wordpress 3.7 DE) when individual plugin updates happened. But the above line solved it.
44 // Activities log for automatic translation updates wont work in wordpress 3.7. Because, wordpress 3.7 hasnt given any option to achieve it. But the above line solved it.
45
46 }
47 }
48
49 // whenever iwp client plugin updated also, it will call the following function for creating options like iwp_client_all_plugins_history, iwp_client_all_themes_history and iwp_client_wp_version_old.
50 function iwp_mmb_save_options_for_activity_log($activity = '') {
51 global $wp_version;
52
53 // The following three lines are used for Client Reporting (Beta) - activities log.
54 if(!get_option('iwp_client_all_plugins_history') || in_array($activity, array('update_client_plugin', 'install'))) {
55 $this->iwp_mmb_update_all_plugins_history();
56 }
57 if(!get_option('iwp_client_all_themes_history') || in_array($activity, array('update_client_plugin', 'install'))) {
58 $this->iwp_mmb_update_all_themes_history();
59 }
60
61 if(!get_option('iwp_client_wp_version_old') || in_array($activity, array('update_client_plugin', 'install'))) {
62 update_option('iwp_client_wp_version_old',$wp_version); // It is mainly used when wp core auto updates happened.
63 }
64 }
65
66 function iwp_mmb_collect_backup_details($params) {
67 global $iwp_activities_log_post_type;
68
69 $user = get_user_by( 'login', $params['username'] );
70 $userid = $user->data->ID;
71
72 $details = array();
73 $details['backup_name'] = isset($params['args']['backup_name']) ? $params['args']['backup_name'] : '';
74 $details['limit'] = isset($params['args']['limit']) ? $params['args']['limit'] : '';
75 $details['disable_comp'] = isset($params['args']['disable_comp']) ? $params['args']['disable_comp'] : '';
76 $details['optimize_tables'] = isset($params['args']['optimize_tables']) ? $params['args']['optimize_tables'] : '';
77 $details['what'] = isset($params['args']['what']) ? $params['args']['what'] : '';
78 $details['exclude'] = isset($params['args']['exclude']) ? $params['args']['exclude'] : '';
79 $details['exclude_extensions'] = isset($params['args']['exclude_extensions']) ? $params['args']['exclude_extensions'] : '';
80 $details['exclude_file_size'] = isset($params['args']['exclude_file_size']) ? $params['args']['exclude_file_size'] : '';
81 $details['include'] = isset($params['args']['include']) ? $params['args']['include'] : '';
82 $details['mechanism'] = isset($params['mechanism']) ? $params['mechanism'] : '';
83 $details['fail_safe_files'] = isset($params['args']['fail_safe_files']) ? $params['args']['fail_safe_files'] : '';
84 $details['fail_safe_db'] = isset($params['args']['fail_safe_db']) ? $params['args']['fail_safe_db'] : '';
85 $details['del_host_file'] = isset($params['args']['del_host_file']) ? $params['args']['del_host_file'] : '';
86 $details['backup_repo_type'] = isset($params['args']['backup_repo_type']) ? $params['args']['backup_repo_type'] : '';
87 $details['when'] = isset($params['args']['when']) ? $params['args']['when'] : '';
88 $details['at'] = isset($params['args']['at']) ? $params['args']['at'] : '';
89
90 $this->iwp_mmb_save_iwp_activities(isset($params['args']['type'])?$params['args']['type']:'backup', isset($params['args']['action'])?$params['args']['action']:'now', $iwp_activities_log_post_type, (object)$details, $userid);
91
92 unset($details);
93 }
94
95 function iwp_is_wptc_white_label_enabled(){
96 if (iwp_mmb_is_WPTC() == false) {
97 return false;
98 }
99 try{
100 global $wpdb;
101
102 $table_name = $wpdb->base_prefix . 'wptc_options';
103 $white_lable_details = $wpdb->get_var("SELECT `value` from `$table_name` WHERE `name`='white_lable_details'");
104
105 if(!empty($white_lable_details)){
106 $white_lable_details = unserialize($white_lable_details);
107
108 if(!empty($white_lable_details) && !empty($white_lable_details->wl_select_action) && $white_lable_details->wl_select_action != 'normal'){
109
110 return true;
111 }
112 }
113
114 return false;
115 } catch(Exception $e){
116
117 return false;
118 }
119 }
120
121 function iwp_mmb_save_iwp_activities($iwp_type, $iwp_action, $activities_type, $params, $userid) {
122 global $wpdb,$iwp_activities_log_post_type, $wpdb;
123 if(!$this->iwp_mmb_get_is_save_activity_log()) {
124 return false;
125 }
126
127 $is_wptc_white_label_enabled = $this->iwp_is_wptc_white_label_enabled();
128
129 if($is_wptc_white_label_enabled && $iwp_action == 'update' && $iwp_type == 'plugins' && $params->slug == 'wp-time-capsule'){
130
131 return false;
132 }
133
134 $iwp_activities = array(
135 'post_title' => uniqid( $iwp_activities_log_post_type.'_' ),
136 'post_author' => $userid,
137 'post_status' => 'publish',
138 'post_type' => $iwp_activities_log_post_type
139 );
140
141 if(!empty($GLOBALS['activities_log_datetime'])) {
142 $iwp_activities['post_date'] = $iwp_activities['post_date_gmt'] = $iwp_activities['post_modified'] = $iwp_activities['post_modified_gmt'] = wp_resolve_post_date();
143 }
144 if (is_multisite() && in_array($iwp_action, array('now', 'schedule','multiCallNow'))) {
145 $wpdb->set_blog_id(1);
146 }
147 $post_id = wp_insert_post( $iwp_activities );
148
149 unset($iwp_activities);
150
151 /*
152 meta keys
153 ==========
154 iwp_log_type
155 iwp_log_action
156 iwp_log_activities_type - i. iwp_activities_log ii. direct iii. automatic
157 iwp_log_details
158 iwp_log_actions - i. core-updated ii. plugins-updated iii. themes-updated iv. translations-updated
159 */
160
161 $details = array();
162 $actions = '';
163 switch($iwp_action) {
164 case 'update':
165 switch($iwp_type) {
166 case 'core':
167 $details['old_version'] = $params->current_version;
168 $details['updated_version'] = $params->current;
169 update_option('iwp_client_wp_version_old',$params->current);
170 break;
171 case 'plugins':
172 case 'themes':
173 $details['name'] = $params->name;
174 $details['slug'] = $params->slug;
175 $details['old_version'] = $params->old_version;
176 $details['updated_version'] = $params->updated_version;
177 break;
178 case 'translations':
179 break;
180 }
181 $actions = $iwp_type.'-updated';
182 break;
183 case 'now':
184 case 'schedule':
185 case 'multiCallNow':
186 switch($iwp_type) {
187 case 'backup':
188 case 'scheduleBackup':
189 $details = (array) $params;
190 break;
191 }
192 $actions = 'backups';
193 break;
194 case 'scan':
195 $actions = 'sucuri';
196 $details = serialize($params);
197 break;
198 }
199
200 if(!function_exists('update_post_meta')) {
201 require_once(ABSPATH.'wp-includes/post.php');
202 }
203
204 update_post_meta($post_id,$iwp_activities_log_post_type.'_type',$iwp_type);
205 update_post_meta($post_id,$iwp_activities_log_post_type.'_action',$iwp_action);
206 update_post_meta($post_id,$iwp_activities_log_post_type.'_activities_type',$activities_type);
207 update_post_meta($post_id,$iwp_activities_log_post_type.'_actions',$actions);
208 update_post_meta($post_id,$iwp_activities_log_post_type.'_details',$details);
209
210 unset($details);
211 }
212
213 function iwp_mmb_get_is_save_activity_log() {
214 return get_option('is_save_activity_log');
215 }
216
217 function iwp_mmb_core_upgrade_preamble() {
218
219 }
220
221 function iwp_mmb_core_updated_successfully($new_version) {
222 global $pagenow;
223
224 $current = array();
225 $current['current_version'] = get_option('iwp_client_wp_version_old');
226 $current['current'] = $new_version;
227 $activities_type = ('update-core.php' !== $pagenow)?'automatic':'direct';
228
229 $userid = $this->iwp_mmb_get_current_user_id();
230
231 $this->iwp_mmb_save_iwp_activities('core', 'update', $activities_type, (object)$current, $userid);
232 }
233
234 function iwp_mmb_get_current_user_id() {
235 if(!function_exists('get_current_user_id')) {
236 include_once (ABSPATH . 'wp-admin/includes/user.php');
237 }
238 return get_current_user_id();
239 }
240
241 function iwp_mmb_upgrader_process_complete($upgrader, $extra) {
242 global $pagenow,$wp_version;
243
244 if(version_compare($wp_version,'3.6','<=')) {
245 return false;
246 }
247
248 $success = ! is_wp_error( $upgrader->skin->result );
249 $error = null;
250
251 if ( ! $success ) {
252 $errors = $upgrader->skin->result->errors;
253
254 list( $error ) = reset( $errors );
255 }
256
257 // This would have failed down the road anyway
258 if ( ! isset( $extra['type'] ) ) {
259 return false;
260 }
261
262 $type = $extra['type'];
263 $action = $extra['action'];
264
265 if ( ! in_array( $type, array( 'plugin', 'theme' ) ) ) {
266 return false;
267 }
268
269 if ( 'install' === $action ) {
270 if ( 'plugin' === $type ) {
271 } else { // theme
272 }
273 } elseif ( 'update' === $action ) {
274 if(
275 (
276 'theme' === $type
277 )
278 || (
279 'plugin' === $type
280 && version_compare($wp_version,'3.7','>=')
281 && version_compare($wp_version,'3.8','<')
282 && isset( $extra['bulk'] )
283 && true === $extra['bulk']
284 && isset($extra['themes'])
285 && is_array($extra['themes'])
286 && count($extra['themes'])
287 ) // In wordpress 3.7, it is behaving differently. Thats why, we have written this "or" condition.
288 ) { // theme
289 if(isset($extra['theme']) && $extra['theme']) { // It is mainly used when wp cron themes updates happened.
290 $slugs = array( $extra['theme'] );
291 } else if ( isset( $extra['bulk'] ) && true === $extra['bulk'] ) {
292 $slugs = $extra['themes'];
293 } else {
294 $slugs = array( $upgrader->skin->theme );
295 }
296
297 foreach ( $slugs as $slug ) {
298 $this->iwp_mmb_collect_theme_details($slug);
299 }
300 } else if ( 'plugin' === $type ) {
301 if(isset($extra['plugin']) && $extra['plugin']) { // It is mainly used when wp cron plugins updates happened.
302 $slugs = array( $extra['plugin'] );
303 } else if ( isset( $extra['bulk'] ) && true === $extra['bulk'] ) {
304 $slugs = $extra['plugins'];
305 } else {
306 $slugs = array( $upgrader->skin->plugin );
307 }
308
309 $slugs_to_exclude = [
310 'iwp-client/init.php',
311 'wp-time-capsule/wp-time-capsule.php',
312 ];
313
314 foreach ( $slugs as $slug ) {
315 if(!in_array($slug, $slugs_to_exclude)) {
316 $this->iwp_mmb_collect_plugin_details($slug);
317 }
318 }
319 }
320 unset($current);
321 } else {
322 return false;
323 }
324 }
325
326 function iwp_mmb_collect_theme_details($theme_slug) {
327 global $pagenow;
328
329 $activities_type = (!in_array($pagenow,array('update.php','admin-ajax.php')))?'automatic':'direct';
330
331 $theme = $this->iwp_mmb_get_theme_details($theme_slug);
332
333 if(empty($theme) || !is_array($theme)) {
334 return false;
335 }
336
337 $userid = $this->iwp_mmb_get_current_user_id();
338
339 $current = array();
340
341 $stylesheet = $theme['Stylesheet Dir'] . '/style.css';
342
343 if(!function_exists('get_file_data')) {
344 require_once(ABSPATH.'wp-includes/functions.php');
345 }
346
347 $theme_data = get_file_data( $stylesheet, array( 'Version' => 'Version' ) );
348 $current['name'] = $theme['Name']; // slug is used to get short description. Here theme name as slug.
349 $current['slug'] = $theme_slug;
350 $current['updated_version'] = $theme_data['Version'];
351 $current['old_version'] = $theme['Version'];
352
353 $all_themes_history = get_option('iwp_client_all_themes_history');
354
355 if(empty($current['name'])) {
356 return false;
357 }
358
359 if(!empty($current['updated_version']) && !empty($current['old_version']) && version_compare($current['updated_version'],$current['old_version'],'==') && isset($all_themes_history) && isset($all_themes_history[$theme_slug]) && $all_themes_history[$theme_slug]) {
360 $current['old_version'] = $all_themes_history[$theme_slug];
361 $all_themes_history[$theme_slug] = $current['updated_version'];
362 update_option('iwp_client_all_themes_history',$all_themes_history);
363 }
364
365 if(!empty($current['updated_version']) && !empty($current['old_version']) && version_compare($current['updated_version'],$current['old_version'],'==')) {
366 return false;
367 } // From wordpress 3.6 to lower versions, even though we got errors when we tried to update the themes, wordpress wont inform us about error via hooks. Thats why we have written this "if".
368
369 $this->iwp_mmb_save_iwp_activities('themes','update',$activities_type,(object)$current,$userid);
370 unset($current);
371 return true;
372 }
373
374 function iwp_mmb_get_theme_details($theme_slug) {
375 if(!function_exists('wp_get_theme')) {
376 require_once(ABSPATH.'wp-includes/theme.php');
377 }
378 if(function_exists('wp_get_theme')) {
379 $theme = wp_get_theme( $theme_slug );
380 } else if(function_exists('get_theme_data') && file_exists(ABSPATH . 'wp-content/themes/'. $theme_slug . '/style.css')) {
381 $theme = get_theme_data( ABSPATH . 'wp-content/themes/'. $theme_slug . '/style.css');
382 } else {
383 $theme = array();
384 }
385
386 return $theme;
387 }
388
389 function iwp_mmb_collect_plugin_details($plugin_file) {
390 global $pagenow;
391
392 $activities_type = (!in_array($pagenow,array('update.php','admin-ajax.php')))?'automatic':'direct';
393
394 $userid = $this->iwp_mmb_get_current_user_id();
395
396 $current = array();
397
398 $_plugins = $this->iwp_mmb_get_all_plugin_details();
399
400 if(!count($_plugins)) {
401 return false;
402 }
403
404 $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_file );
405 $current['name'] = isset($plugin_data['Name'])?$plugin_data['Name']:'';
406 $current['slug'] = $plugin_file;
407 $current['updated_version'] = isset($plugin_data['Version'])?$plugin_data['Version']:'';
408 $current['old_version'] = isset($_plugins[ $plugin_file ]['Version'])?$_plugins[ $plugin_file ]['Version']:'';
409
410 $all_plugins_history = get_option('iwp_client_all_plugins_history');
411
412 if(!empty($current['updated_version']) && !empty($current['old_version']) && version_compare($current['updated_version'],$current['old_version'],'==') && isset($all_plugins_history) && isset($all_plugins_history[$plugin_file]) && $all_plugins_history[$plugin_file]) {
413 $current['old_version'] = $all_plugins_history[$plugin_file];
414 $all_plugins_history[$plugin_file] = $current['updated_version'];
415 update_option('iwp_client_all_plugins_history',$all_plugins_history);
416 }
417
418 if(!empty($current['updated_version']) && !empty($current['old_version']) && version_compare($current['updated_version'],$current['old_version'],'==')) {
419 return false;
420 } // From wordpress 3.6 to lower versions, even though we got errors when we tried to update the plugins, wordpress wont inform us about error via hooks. Thats why we have written this "if".
421
422 $this->iwp_mmb_save_iwp_activities('plugins','update',$activities_type,(object)$current,$userid);
423 unset($current);
424 return true;
425 }
426
427 function iwp_mmb_get_all_plugin_details() {
428
429 if ( ! function_exists( 'get_plugins' ) ) {
430 require_once ABSPATH . 'wp-admin/includes/plugin.php';
431 }
432 $_plugins = get_plugins();
433 if (empty($_plugins) || !is_array($_plugins)) {
434 return array();
435 }
436 return $_plugins;
437 }
438
439 function iwp_mmb_automatic_updates_complete($update_results) {
440 if(empty($update_results['translation'])) {
441 return false;
442 }
443 return $this->iwp_mmb_post_update_translations_complete_actions(array());
444 }
445
446 function iwp_mmb_post_update_translations_complete_actions($update_actions) {
447 global $pagenow,$iwp_client_plugin_translations,$iwp_client_plugin_ptc_updates,$wp_version,$iwp_activities_log_post_type;
448
449 $activities_type = (!in_array($pagenow,array('update.php','update-core.php')))?'automatic':'direct';
450
451 if(
452 isset($iwp_client_plugin_ptc_updates)
453 && $iwp_client_plugin_ptc_updates==1
454 ) {
455 $activities_type = $iwp_activities_log_post_type;
456 }
457
458 $userid = $this->iwp_mmb_get_current_user_id();
459
460 $details = array();
461 $this->iwp_mmb_save_iwp_activities('translations', 'update', $activities_type, (object)$details, $userid);
462 return $update_actions;
463 }
464
465 function iwp_mmb_check_and_update_all_plugins_themes_history($option, $old_value, $value) {
466 if(in_array($option,array('_site_transient_update_plugins','_site_transient_update_themes'))) {
467
468 $this->iwp_mmb_update_all_plugins_history();
469 $this->iwp_mmb_update_all_themes_history();
470 }
471 }
472
473 function iwp_mmb_update_all_plugins_history() {
474 $all_plugins = $this->get_all_plugins();
475
476 unset($all_plugins['iwp-client/init.php']);
477 unset($all_plugins['wp-time-capsule/wp-time-capsule.php']);
478
479 $all_plugins_history = array();
480 foreach($all_plugins as $key=>$plugin) {
481 $all_plugins_history[$key] = $plugin['Version'];
482 }
483
484 update_option('iwp_client_all_plugins_history',$all_plugins_history);
485 unset($all_plugins,$all_plugins_history);
486 }
487
488 function iwp_mmb_update_all_themes_history() {
489 $all_themes = $this->get_all_themes();
490 $all_themes_history = array();
491 $theme_details = array();
492 foreach($all_themes as $key=>$theme) {
493 $theme_details = $this->iwp_mmb_get_theme_details($key);
494 $all_themes_history[$key] = $theme_details->Version;
495 }
496
497 update_option('iwp_client_all_themes_history',$all_themes_history);
498 unset($all_themes,$all_themes_history,$theme_details);
499 }
500
501 function get_all_plugins() {
502 if (!function_exists('get_plugins')) {
503 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
504 }
505 $all_plugins = get_plugins();
506 return $all_plugins;
507 }
508
509 function get_all_themes() {
510 if (!function_exists('wp_get_themes')) {
511 include_once(ABSPATH . WPINC . '/theme.php');
512 }
513 if(function_exists('wp_get_themes')){
514 $all_themes = wp_get_themes();
515 }else{
516 $all_themes = get_themes();
517 }
518 return $all_themes;
519 }
520
521 function iwp_mmb_update_theme_complete_actions($update_actions, $theme_slug) {
522 global $wp_version;
523
524 if(version_compare($wp_version,'3.7','>=') or empty($theme_slug)) {
525 return $update_actions;
526 }
527
528 $this->iwp_mmb_collect_theme_details($theme_slug);
529
530 return $update_actions;
531 }
532
533 function iwp_mmb_update_bulk_theme_complete_actions($update_actions, $theme_info) {
534 global $wp_version,$iwp_client_plugin_ptc_updates;
535
536 if(
537 (
538 version_compare($wp_version,'3.7','>=')
539 )
540 or (
541 isset($iwp_client_plugin_ptc_updates)
542 && $iwp_client_plugin_ptc_updates==1
543 )
544 ) {
545 return $update_actions;
546 }
547
548 $theme_info = (array) $theme_info;
549 $theme_slug = '';
550
551 foreach($theme_info as $key=>$value) {
552 if(isset($value['TextDomain']) && $value['TextDomain']) {
553 $theme_slug = $value['TextDomain'];
554 break;
555 } else if(strstr($key,'stylesheet') || strstr($key,'template')) {
556 $theme_slug = $value;
557 break;
558 } else if($key=='Name') {
559 $theme_slug = str_replace(array(' '),array(''),strtolower($value));
560 break;
561 }
562 }
563
564 if($theme_slug=='') {
565 return $update_actions;
566 }
567
568 $this->iwp_mmb_collect_theme_details($theme_slug);
569
570 return $update_actions;
571 }
572
573 function iwp_mmb_async_update_translation($update, $language_update) {
574 return false;
575 }
576
577 function iwp_mmb_update_translations_complete_actions($update_actions) {
578 global $pagenow,$iwp_client_plugin_translations,$iwp_client_plugin_ptc_updates,$wp_version;
579
580 if(
581 (
582 isset($iwp_client_plugin_translations)
583 && $iwp_client_plugin_translations==1
584 )
585 or (
586 version_compare($wp_version,'4.0','<')
587 )
588 ) {
589 return $update_actions;
590 }
591
592 return $this->iwp_mmb_post_update_translations_complete_actions($update_actions);
593 }
594
595 function iwp_mmb_upgrader_post_install($response, $hook_extra, $result) {
596 global $wp_version;
597
598 if(
599 isset($hook_extra['language_update_type'])
600 && isset($hook_extra['language_update'])
601 && is_object($hook_extra['language_update'])
602 ) {
603 remove_filter('update_translations_complete_actions', array(&$this,'iwp_mmb_update_translations_complete_actions'));
604 $this->iwp_mmb_post_update_translations_complete_actions(array());
605 return $response;
606 }
607
608 if(
609 version_compare($wp_version,'3.6','<=')
610 && isset($hook_extra['plugin'])
611 && $hook_extra['plugin']
612 && strstr($hook_extra['plugin'],'.zip')===false
613 ) {
614 $this->iwp_mmb_collect_plugin_details($hook_extra['plugin']);
615 }
616
617 return $response;
618 }
619
620 function iwp_mmb_update_is_save_activity_log($is_save_activity_log) {
621 if(isset($is_save_activity_log)) {
622 update_option('is_save_activity_log', $is_save_activity_log);
623 }
624 }
625
626 function iwp_mmb_process_and_fetch_activities_log($params) {
627 global $wpdb,$iwp_activities_log_post_type;
628
629 $updated_key = 'updated';
630 $backups_key = 'backups';
631 $count_key = 'count';
632 $name_key = 'name';
633 $date_key = 'date';
634 $time_key = 'time';
635 $type_key = 'type';
636 $from_key = 'from';
637 $to_key = 'to';
638 $translations_updated = 'translations-updated';
639 $sucuri = 'sucuri';
640 $ithemesec = 'ithemesec';
641 $wordfence = 'wordfence';
642 $slug = 'slug';
643
644 if(
645 !is_array($params['originalActions'])
646 || !is_array($params['actions'])
647 || !count($params['originalActions'])
648 || !count($params['actions'])
649 || empty($params['fromDate'])
650 || empty($params['toDate'])
651 ) {
652 iwp_mmb_response(array('error' => 'Invalid request', 'error_code' => 'invalid_request'), false);
653 }
654
655 $params['fromDate'] = (int)$params['fromDate'];
656 $params['toDate'] = (int)$params['toDate'];
657
658 $escaped_actions = array_map('esc_sql', $params['actions']);
659 $iwp_action = implode("','", $escaped_actions);
660
661 $query = $wpdb->prepare("
662 select
663 p.ID as post_id,
664 p.post_date as date,
665 pm.meta_value as actions
666 from
667 {$wpdb->prefix}posts as p
668 left join {$wpdb->prefix}postmeta as pm on pm.post_id = p.ID
669 where
670 p.post_type = %s
671 and unix_timestamp(p.post_date)>=%d
672 and unix_timestamp(p.post_date)<=%d
673 and pm.meta_key in ('".$iwp_activities_log_post_type."_actions')
674 and pm.meta_value in ('".$iwp_action."')
675 order by p.post_date asc
676 ", $iwp_activities_log_post_type, $params['fromDate'], $params['toDate']);
677
678 $activities_log_result = $wpdb->get_results($query,ARRAY_A);
679 $return = array();
680 $return['detailed'] = $params['detailed'];
681 $return[$count_key] = array_map('iwp_make_values_as_zero',array_flip($params['actions']));
682
683 foreach($activities_log_result as $key=>$activities_log) {
684
685 $date = date('M d, y',strtotime($activities_log['date']));
686 $time = date('g',strtotime($activities_log['date'])).':'.date('i',strtotime($activities_log['date'])).' '.date('a',strtotime($activities_log['date']));
687
688 $detailed_array = array(
689 $date_key => $date,
690 $time_key => $time
691 );
692
693 $activities_log_details = get_post_meta($activities_log['post_id'],$iwp_activities_log_post_type.'_details',true);
694
695 // The following lines are for CR New
696 if($activities_log['actions']==$backups_key) {
697 $return['detailed'][$activities_log['actions']]['details'][$return['detailed'][$activities_log['actions']][$count_key]] = $detailed_array;
698 if($activities_log_details['what']=='full') {
699 $backup_what_type = 'Files & DB';
700 } else if($activities_log_details['what']=='files') {
701 $backup_what_type = 'Files';
702 } else {
703 $backup_what_type = 'DB';
704 }
705 $return['detailed'][$activities_log['actions']]['details'][$return['detailed'][$activities_log['actions']][$count_key]][$type_key] = $backup_what_type;
706 $return['detailed'][$activities_log['actions']][$count_key]++;
707 } elseif($activities_log['actions']==$sucuri){
708 $return['detailed'][$sucuri][$count_key]++;
709 $return['detailed'][$sucuri]['details'][]=$activities_log_details;
710 }else {
711
712 $return['detailed'][$updated_key][$count_key]++;
713
714 $return['detailed'][$updated_key][$activities_log['actions']]['details'][$return['detailed'][$updated_key][$activities_log['actions']][$count_key]] = $detailed_array;
715
716 if($activities_log['actions']!=$translations_updated) {
717
718 $name = str_replace(array($translations_updated,'s-updated','core-updated'),array(''),$activities_log['actions']);
719 $what_updated = isset($activities_log_details['name'])?$activities_log_details['name']:'Wordpress Core Updates';
720
721 $return['detailed'][$updated_key][$activities_log['actions']]['details'][$return['detailed'][$updated_key][$activities_log['actions']][$count_key]][$name.$name_key] = $what_updated;
722 $return['detailed'][$updated_key][$activities_log['actions']]['details'][$return['detailed'][$updated_key][$activities_log['actions']][$count_key]][$from_key] = $activities_log_details['old_version'];
723 $return['detailed'][$updated_key][$activities_log['actions']]['details'][$return['detailed'][$updated_key][$activities_log['actions']][$count_key]][$to_key] = $activities_log_details['updated_version'];
724 $return['detailed'][$updated_key][$activities_log['actions']]['details'][$return['detailed'][$updated_key][$activities_log['actions']][$count_key]][$slug] = $activities_log_details['slug'];
725 }
726 $return['detailed'][$updated_key][$activities_log['actions']][$count_key]++;
727 }
728 // The above lines are for CR New
729 $return[$count_key][$activities_log['actions']]++; // This line is for CR Old
730 }
731 foreach($return[$count_key] as $key => &$value) {
732 if($value==0) {
733 unset($return[$count_key][$key]);
734 }
735 }
736 foreach($return['detailed'] as $key => &$mainActionArray) {
737 if(!$mainActionArray[$count_key]) {
738 unset($return['detailed'][$key]);
739 } else if(!array_key_exists('details',$mainActionArray)) {
740 foreach($mainActionArray as $key_inner => &$subActionsArray) {
741 if(empty($subActionsArray[$count_key]) && $key_inner!=$count_key) {
742 unset($mainActionArray[$key_inner]);
743 }
744 }
745 }
746 }
747 if (in_array($ithemesec, $params['actions']) && iwp_mmb_ithemes_security_check()) {
748 global $iwp_mmb_core;
749 $ithemessec_instance = $iwp_mmb_core->get_ithemessec_instance();
750 $logCounts = $ithemessec_instance->getLogCounts($params['fromDate'], $params['toDate']);
751 $return['detailed'][$ithemesec]['details'] = $logCounts;
752 }
753
754 if (in_array($wordfence, $params['actions']) && iwp_mmb_is_wordfence()) {
755 global $iwp_mmb_core;
756 require_once($GLOBALS['iwp_mmb_plugin_dir'] . "/addons/wordfence/wordfence.class.php");
757 $wordfence_instance = $iwp_mmb_core->get_wordfence_instance();
758 $logCounts = $wordfence_instance->getLogCounts($params['fromDate'], $params['toDate']);
759 $return['detailed'][$wordfence]['details'] = $logCounts;
760 }
761 if (in_array($backups_key, $params['actions']) && iwp_mmb_is_WPTC()) {
762 $query = $wpdb->prepare("SELECT backup_id from ".$wpdb->base_prefix."wptc_backups WHERE backup_id >= %d AND backup_id <= %d", $params['fromDate'], $params['toDate']);
763 $wptc_backup_counts = 0;
764 $wptc_backups = $wpdb->get_results($query,ARRAY_A);
765 if (!empty($wptc_backups)) {
766 $wptc_backups_details = array();
767 foreach ($wptc_backups as $key => $backup) {
768 $wptc_backup_counts ++;
769 $details = array();
770 $date = date('M d, y',$backup['backup_id']);
771 $time = date('g',$backup['backup_id']).':'.date('i',$backup['backup_id']).' '.date('a',$backup['backup_id']);
772 $details['time'] = $time;
773 $details['date'] = $date;
774 $details['type'] = 'Files & DB';
775 $wptc_backups_details[] = $details;
776 }
777 $parentDetails = $return['detailed']['backups']['details'];
778 if (empty($parentDetails)) {
779 $parentDetails = array();
780 }
781 $parentDetails = array_merge($parentDetails,$wptc_backups_details);
782 $return['detailed']['backups']['count']+=$wptc_backup_counts;
783 $return['detailed']['backups']['details']= $parentDetails;
784 $return['count']['backups']+=$wptc_backup_counts;
785 }
786 }
787 iwp_mmb_response($return, true);
788 }
789
790 function iwp_mmb_do_remove_upgrader_process_complete_action() {
791 remove_action('upgrader_process_complete', array( &$this, 'iwp_mmb_upgrader_process_complete'), 1);
792 }
793
794 function iwp_mmb_do_remove_theme_filters() {
795 remove_filter('update_theme_complete_actions', array( &$this, 'iwp_mmb_update_theme_complete_actions')); // It is available from wordpress 2.7 to 3.6.
796 remove_filter('update_bulk_theme_complete_actions', array( &$this, 'iwp_mmb_update_bulk_theme_complete_actions')); // It is available from wordpress 2.7 to 3.6.
797 }
798
799 function iwp_mmb_do_remove_upgrader_post_install_filter() {
800 remove_filter('upgrader_post_install', array( &$this, 'iwp_mmb_upgrader_post_install'));
801 }
802
803 function iwp_mmb_do_remove_core_updated_successfully() {
804 remove_action('_core_updated_successfully', array( &$this, 'iwp_mmb_core_updated_successfully'),1);
805 }
806
807 function iwp_mmb_register_custom_post_type(){
808 register_post_type('iwp_log', array('label' => 'IWP Log'));
809 }
810 function iwp_mmb_save_sucuri_activity_log(){
811 $object = new IWP_MMB_Sucuri();
812 $details = $object->getScannedCacheResult(1);
813 if (!empty($details)) {
814 $info = $details['info'];
815 $userid = $this->iwp_mmb_get_current_user_id();
816 $this->iwp_mmb_save_iwp_activities('sucuri', 'scan', 'automatic',$info, $userid);
817 }
818 }
819
820 function iwp_mmb_backup_complete(){
821 return true;
822 }
823
824 function iwp_client_report_delete_log($params){
825 $older_than_no_of_days = $params['days'];
826 if (defined('IWP_CLIENT_REPORT_AUTO_DELETE_POST_LIMIT')) {
827 $delete_post_limit = (int)IWP_CLIENT_REPORT_AUTO_DELETE_POST_LIMIT;
828 }else {
829 $delete_post_limit = (int)$params['delete_post_limit'];
830 }
831
832 $days = $older_than_no_of_days * 86400; // 30 * 86400 = 30days
833 $now = time(); // today
834 $till_date = date('Y-m-d', $now - $days); // 30days before
835 $before_log_count = $this->iwp_client_report_get_log_count($till_date);
836 if ($before_log_count == 0) {
837 return array('status' => 'not_found', 'remaining_log_count' => $before_log_count);
838 }
839 global $wpdb;
840 $delete_query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_date <= %s AND post_type= 'iwp_log' LIMIT %d ", $till_date, $delete_post_limit);
841 $result = $wpdb->get_results($delete_query, ARRAY_A);
842
843 if (empty($result)) {
844 return array('status' => 'result_not_found', 'remaining_log_count' => $this->iwp_client_report_get_log_count($till_date));
845 }
846 $before_delete_time = microtime(true);
847 foreach ($result as $log) {
848 $post_id = (int)$log['ID'];
849 wp_delete_post($post_id, true);
850 }
851 $after_delete_time = microtime(true);
852 $after_log_count = $this->iwp_client_report_get_log_count($till_date);
853 $response = array();
854 if ($after_log_count > 0) {
855 $response['status'] = 'partially_completed';
856 }else{
857 $response['status'] = 'completed';
858 }
859 $response['before_log_count'] = $before_log_count;
860 $response['remaining_log_count'] = $after_log_count;
861 $response['before_delete_time'] = $before_delete_time;
862 $response['after_delete_time'] = $after_delete_time;
863 $response['time_diff'] = $after_delete_time - $before_delete_time;
864
865 return $response;
866 }
867
868 function iwp_client_report_get_log_count( $till_date ) {
869 global $wpdb;
870 $prepared_query = $wpdb->prepare("SELECT count(ID) FROM $wpdb->posts WHERE post_date <= %s AND post_type= 'iwp_log' ", $till_date);
871 $result = $wpdb->get_var($prepared_query);
872 return $result;
873 }
874 }
875
876 if(!function_exists('iwp_make_values_as_zero')) {
877 function iwp_make_values_as_zero($value) {
878 return 0;
879 }
880 }
881 if( !function_exists ( 'iwp_mmb_fetch_activities_log' )) {
882 function iwp_mmb_fetch_activities_log($params) {
883 global $iwp_mmb_activities_log;
884
885 $iwp_mmb_activities_log->iwp_mmb_process_and_fetch_activities_log($params);
886 }
887 }