PluginProbe
The WP Remote WordPress Plugin / 6.47
The WP Remote WordPress Plugin v6.47
6.72 6.69 6.65 6.62 6.48 6.47 4.87 4.97 5.05 5.09 5.16 5.22 5.24 5.25 5.38 5.41 5.42 5.45 5.47 5.53 5.56 5.65 5.68 5.72 5.73 All 53 releases
wpremote / wp_actlog.php

wp_actlog.php in The WP Remote WordPress Plugin 6.47, at wp_actlog.php

542 lines 17.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('BVWPActLog')) :
5
6 class BVWPActLog {
7
8 public static $actlog_table = 'activities_store';
9 public $db;
10 public $settings;
11 public $bvinfo;
12 public $request_id;
13 public $ip_header;
14 public $ignored_events;
15
16 public function __construct($db, $settings, $info, $config) {
17 $this->db = $db;
18 $this->settings = $settings;
19 $this->bvinfo = $info;
20 $this->request_id = WPRInfo::getRequestID();
21 $this->ip_header = array_key_exists('ip_header', $config) ? $config['ip_header'] : false;
22 $this->ignored_events = array_key_exists('ignored_events', $config) ? $config['ignored_events'] : array();
23 }
24
25 function init() {
26 $this->add_actions_and_listeners();
27 }
28
29 function get_post($post_id) {
30 $post = get_post($post_id);
31 $data = array('id' => $post_id);
32 if (!empty($post)) {
33 $data['title'] = $post->post_title;
34 $data['status'] = $post->post_status;
35 $data['type'] = $post->post_type;
36 $data['url'] = get_permalink($post_id);
37 $data['date'] = $post->post_date;
38 }
39 return $data;
40 }
41
42 function get_comment($comment_id) {
43 $comment = get_comment($comment_id);
44 $data = array('id' => $comment_id);
45 if (!empty($comment)) {
46 $data['author'] = $comment->comment_author;
47 $data['post_id'] = $comment->comment_post_ID;
48 }
49 return $data;
50 }
51
52 function get_term($term_id) {
53 $term = get_term($term_id);
54 $data = array('id' => $term_id);
55 if (!empty($term)) {
56 $data['name'] = $term->name;
57 $data['slug'] = $term->slug;
58 $data['taxonomy'] = $term->taxonomy;
59 }
60 return $data;
61 }
62
63 function get_user($user_id) {
64 $user = get_userdata($user_id);
65 $data = array('id' => $user_id);
66 if (!empty($user)) {
67 $data['username'] = $user->user_login;
68 $data['email'] = $user->user_email;
69 $data['role'] = $user->roles;
70 }
71 return $data;
72 }
73
74 function get_blog($blog_id) {
75 $blog = get_blog_details($blog_id);
76 $data = array('id' => $blog_id);
77 if (!empty($blog)) {
78 $data['name'] = $blog->blogname;
79 $data['url'] = $blog->path;
80 }
81 return $data;
82 }
83
84 function wc_get_attribute($attribute_id, $attribute_data = null) {
85 $data = array('id' => $attribute_id);
86 if (!is_null($attribute_data) && is_array($attribute_data)) {
87 $data['name'] = $attribute_data['attribute_label'];
88 $data['slug'] = $attribute_data['attribute_name'];
89 } else {
90 $attribute = wc_get_attribute($attribute_id);
91 if (!empty($attribute)) {
92 $data['name'] = $attribute->name;
93 $data['slug'] = substr($attribute->slug, 3);
94 }
95 }
96 return $data;
97 }
98
99 function wc_get_tax_rate($tax_rate_id, $tax_rate) {
100 $data = array('id' => $tax_rate_id);
101 if (!empty($tax_rate)) {
102 $data['name'] = array_key_exists('tax_rate_name', $tax_rate) ? $tax_rate['tax_rate_name'] : '';
103 $data['country'] = array_key_exists('tax_rate_country', $tax_rate) ? $tax_rate['tax_rate_country'] : '';
104 $data['rate'] = array_key_exists('tax_rate', $tax_rate) ? $tax_rate['tax_rate'] : '';
105 }
106 return $data;
107 }
108
109 function get_ip($ipHeader) {
110 $ip = '127.0.0.1';
111 if ($ipHeader && is_array($ipHeader)) {
112 if (array_key_exists($ipHeader['hdr'], $_SERVER)) {
113 $_ips = preg_split("/(,| |\t)/", WPRHelper::getRawParam('SERVER', $ipHeader['hdr']));
114 if (array_key_exists(intval($ipHeader['pos']), $_ips)) {
115 $ip = $_ips[intval($ipHeader['pos'])];
116 }
117 }
118 } else if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
119 $ip = WPRHelper::getRawParam('SERVER', 'REMOTE_ADDR');
120 }
121
122 $ip = trim($ip);
123 if (WPRHelper::safePregMatch('/^\[([0-9a-fA-F:]+)\](:[0-9]+)$/', $ip, $matches)) {
124 $ip = $matches[1];
125 } elseif (WPRHelper::safePregMatch('/^([0-9.]+)(:[0-9]+)$/', $ip, $matches)) {
126 $ip = $matches[1];
127 }
128
129 return $ip;
130 }
131
132 function add_activity($event_data) {
133 if (!function_exists('wp_get_current_user')) {
134 @include_once(ABSPATH . "wp-includes/pluggable.php");
135 }
136
137 $user = wp_get_current_user();
138 $values = array();
139 if (!empty($user)) {
140 $values["user_id"] = $user->ID;
141 $values["username"] = $user->user_login;
142 }
143 $values["request_id"] = $this->request_id;
144 $values["site_id"] = get_current_blog_id();
145 $values["ip"] = $this->get_ip($this->ip_header);
146 $values["event_type"] = current_filter();
147 $values["event_data"] = maybe_serialize($event_data);
148 $values["time"] = time();
149 $this->db->replaceIntoBVTable(BVWPActLog::$actlog_table, $values);
150 }
151
152 function is_key_ignored($ignored_keys, $value) {
153 $is_ignored = false;
154 if (array_key_exists("post_types_regex", $ignored_keys)) {
155 foreach ($ignored_keys['post_types_regex'] as $val) {
156 if (WPRHelper::safePregMatch($val, $value)) {
157 return true;
158 }
159 }
160 }
161 if (array_key_exists("post_types", $ignored_keys)) {
162 foreach ($ignored_keys['post_types'] as $val) {
163 if ($val == $value) {
164 return true;
165 }
166 }
167 }
168 return $is_ignored;
169 }
170
171 function user_login_handler($user_login, $user) {
172 $event_data = array("user" => $this->get_user($user->ID));
173 $this->add_activity($event_data);
174 }
175
176 function user_logout_handler($user_id) {
177 $user = $this->get_user($user_id);
178 $event_data = array("user" => $user);
179 $this->add_activity($event_data);
180 }
181
182 function password_reset_handler($user, $new_pass) {
183 if (!empty($user)) {
184 $event_data = array("user" => $this->get_user($user->ID));
185 $this->add_activity($event_data);
186 }
187 }
188
189 function comment_handler($comment_id) {
190 $comment = $this->get_comment($comment_id);
191 $post = $this->get_post($comment['post_id']);
192 $event_data = array(
193 "comment" => $comment,
194 "post" => $post
195 );
196 $this->add_activity($event_data);
197 }
198
199 function comment_status_changed_handler($new_status, $old_status, $comment) {
200 $post = $this->get_post($comment->comment_post_ID);
201 $event_data = array(
202 "comment" => $this->get_comment($comment->comment_ID),
203 "post" => $post,
204 "old_status" => $old_status,
205 "new_status" => $new_status
206 );
207 $this->add_activity($event_data);
208 }
209
210 function post_handler($post_id) {
211 $post = $this->get_post($post_id);
212 if ($this->is_key_ignored($this->ignored_events, $post["type"]))
213 return;
214 $event_data = array();
215 if (!isset($post["type"])) {
216 $event_data["post"] = $post;
217 } elseif ($post["type"] === "product") {
218 $event_data["product"] = $post;
219 } elseif ($post["type"] === "shop_order") {
220 $event_data["order"] = $post;
221 } else {
222 $event_data["post"] = $post;
223 }
224 $this->add_activity($event_data);
225 }
226
227 function post_saved_handler($post_id, $post, $update) {
228 $post = $this->get_post($post_id);
229 if ($this->is_key_ignored($this->ignored_events, $post["type"]))
230 return;
231 $event_data = array();
232 if (!isset($post["type"])) {
233 $event_data["post"] = $post;
234 } elseif ($post["type"] === "product") {
235 $event_data["product"] = $post;
236 } elseif ($post["type"] === "shop_order") {
237 $event_data["order"] = $post;
238 } else {
239 $event_data["post"] = $post;
240 }
241 $event_data["updated"] = $update;
242 $this->add_activity($event_data);
243 }
244
245 function term_handler($term_id) {
246 $term = $this->get_term($term_id);
247 $event_data = array(
248 "term" => $term,
249 );
250 $this->add_activity($event_data);
251 }
252
253 function term_updation_handler($data, $term_id) {
254 $term = $this->get_term($term_id);
255 $event_data = array(
256 "term" => $term,
257 "new_term" => $data
258 );
259 $this->add_activity($event_data);
260 return $data;
261 }
262
263 function term_deletion_handler($term_id) {
264 $event_data = array(
265 "term" => array("id" => $term_id)
266 );
267 $this->add_activity($event_data);
268 }
269
270 function user_handler($user_id) {
271 $user = $this->get_user($user_id);
272 $event_data = array(
273 "user" => $user,
274 );
275 $this->add_activity($event_data);
276 }
277
278 function user_update_handler($user_id, $old_userdata) {
279 $new_userdata = $this->get_user($user_id);
280 $event_data = array(
281 "old_user" => $this->get_user($old_userdata->ID),
282 "user" => $new_userdata,
283 );
284 $this->add_activity($event_data);
285 }
286
287 function plugin_action_handler($plugin) {
288 $event_data = array("plugin" => $plugin);
289 $this->add_activity($event_data);
290 }
291
292 function theme_action_handler($theme_name) {
293 $event_data = array("theme" => $theme_name);
294 $this->add_activity($event_data);
295 }
296
297 function mu_handler($blog_id) {
298 $blog = $this->get_blog($blog_id);
299 $event_data = array(
300 "blog" => $blog
301 );
302 $this->add_activity($event_data);
303 }
304
305 function mu_site_handler($blog) {
306 $event_data = array(
307 "blog" => $this->get_blog($blog->blog_id)
308 );
309 $this->add_activity($event_data);
310 }
311
312 function woocommerce_attribute_created_handler($attribute_id, $attribute_data) {
313 $event_data = array(
314 "attribute" => $this->wc_get_attribute($attribute_id, $attribute_data)
315 );
316 $this->add_activity($event_data);
317 }
318
319 function woocommerce_attribute_handler($attribute_id) {
320 $event_data = array(
321 "attribute" => $this->wc_get_attribute($attribute_id)
322 );
323 $this->add_activity($event_data);
324 }
325
326 function woocommerce_tax_rate_handler($tax_rate_id, $tax_rate) {
327 $event_data = array(
328 "tax_rate" => $this->wc_get_tax_rate($tax_rate_id, $tax_rate)
329 );
330 $this->add_activity($event_data);
331 }
332
333 function woocommerce_tax_rate_deleted_handler($tax_rate_id) {
334 $event_data = array(
335 "tax_rate" => array("id" => $tax_rate_id)
336 );
337 $this->add_activity($event_data);
338 }
339
340 function woocommerce_grant_product_download_access_handler($data) {
341 $event_data = array(
342 "download_id" => $data['download_id'],
343 "user_id" => $data['user_id'],
344 "order_id" => $data['order_id'],
345 "product_id" => $data['product_id']
346 );
347 $this->add_activity($event_data);
348 }
349
350 function woocommerce_revoke_access_to_product_download_handler($download_id, $product_id, $order_id) {
351 $event_data = array(
352 "download_id" => $download_id,
353 "product_id" => $product_id,
354 "order_id" => $order_id
355 );
356 $this->add_activity($event_data);
357 }
358
359 function woocommerce_shipping_zone_method_handler($instance_id, $method_id, $zone_id) {
360 $event_data = array(
361 "instance_id" => absint ($instance_id),
362 "method_id" => $method_id,
363 "zone_id" => $zone_id
364 );
365 $this->add_activity($event_data);
366 }
367
368 function get_plugin_update_data($plugins) {
369 $data = array();
370 if (!empty($plugins) && defined('WP_PLUGIN_DIR')) {
371 foreach ($plugins as $plugin) {
372 $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin);
373 $title = isset($plugin_data['Name']) ? $plugin_data['Name'] : '';
374 $version = isset($plugin_data['Version']) ? $plugin_data['Version'] : '';
375 $install_data = array('title' => $title, 'version' => $version);
376 array_push($data, $install_data);
377 }
378 }
379 return $data;
380 }
381
382 function get_theme_update_data($themes) {
383 $data = array();
384 if (!empty($themes)) {
385 foreach ($themes as $theme) {
386 $theme_data = wp_get_theme($theme);
387 $title = isset($theme_data['Name']) ? $theme_data['Name'] : '';
388 $version = isset($theme_data['Version']) ? $theme_data['Version'] : '';
389 $install_data = array('title' => $title, 'version' => $version);
390 array_push($data, $install_data);
391 }
392 }
393 return $data;
394 }
395
396 function get_plugin_install_data($upgrader) {
397 $data = array();
398 if ($upgrader->bulk != "1") {
399 $plugin_data = $upgrader->new_plugin_data;
400 $title = isset($plugin_data['Name']) ? $plugin_data['Name'] : '';
401 $version = isset($plugin_data['Version']) ? $plugin_data['Version'] : '';
402 $install_data = array('title' => $title, 'version' => $version);
403 array_push($data, $install_data);
404 }
405 return $data;
406 }
407
408 function get_theme_install_data($upgrader) {
409 $data = array();
410 $theme_data = $upgrader->new_theme_data;
411 $title = isset($theme_data['Name']) ? $theme_data['Name'] : '';
412 $version = isset($theme_data['Version']) ? $theme_data['Version'] : '';
413 $install_data = array('title' => $title, 'version' => $version);
414 array_push($data, $install_data);
415 return $data;
416 }
417
418 function get_update_data($options) {
419 $event_data = array('action' => 'update');
420 if ($options['type'] === 'plugin') {
421 $event_data['type'] = 'plugin';
422 if (array_key_exists("plugin", $options)) {
423 $options['plugins'] = array($options['plugin']);
424 unset($options['plugin']);
425 }
426 $event_data['plugins'] = $this->get_plugin_update_data($options['plugins']);
427 }
428 else if ($options['type'] === 'theme') {
429 $event_data['type'] = 'theme';
430 if (array_key_exists("theme", $options)) {
431 $options['themes'] = array($options['theme']);
432 unset($options['theme']);
433 }
434 $event_data['themes'] = $this->get_theme_update_data($options['themes']);
435 }
436 return $event_data;
437 }
438
439 function get_install_data($upgrader, $options) {
440 $event_data = array('action' => 'install');
441 if ($options['type'] === 'plugin') {
442 $event_data['type'] = 'plugin';
443 $event_data['plugins'] = $this->get_plugin_install_data($upgrader);
444 }
445 else if ($options['type'] === 'theme') {
446 $event_data['type'] = 'theme';
447 $event_data['themes'] = $this->get_theme_install_data($upgrader);
448 }
449 return $event_data;
450 }
451
452 function upgrade_handler($upgrader, $data) {
453 $event_data = array();
454 if (isset($data['action'])) {
455 if ($data['action'] === 'update') {
456 if ('core' === $data['type']) {
457 return;
458 }
459 $event_data = $this->get_update_data($data);
460 } else if ($data['action'] === 'install') {
461 $event_data = $this->get_install_data($upgrader, $data);
462 }
463 }
464 $this->add_activity($event_data);
465 }
466
467 function core_upgrade_handler($new_wp_version) {
468 global $wp_version;
469 $event_data = array();
470 $event_data['type'] = 'core';
471 $event_data['wp_core'] = array('prev_version' => $wp_version, 'new_version' => $new_wp_version);
472 $this->add_activity($event_data);
473 }
474
475 /* ADDING ACTION AND LISTENERS FOR SENSING EVENTS. */
476 public function add_actions_and_listeners() {
477 /* SENSORS FOR POST AND PAGE CHANGES */
478 add_action('pre_post_update', array($this, 'post_handler'));
479 add_action('save_post', array($this, 'post_saved_handler'), 10, 3);
480 add_action('post_stuck', array($this, 'post_handler'));
481 add_action('post_unstuck', array($this, 'post_handler'));
482 add_action('delete_post', array($this, 'post_handler'));
483
484 /* SENSORS FOR COMMENTS */
485 add_action('comment_post', array($this, 'comment_handler'));
486 add_action('edit_comment', array($this, 'comment_handler'));
487 add_action('transition_comment_status', array($this, 'comment_status_changed_handler'), 10, 3);
488
489 /* SENSORS FOR TAG AND CATEGORY CHANGES */
490 add_action('create_term', array($this, 'term_handler'));
491 add_action('pre_delete_term', array($this, 'term_handler'));
492 add_action('delete_term', array($this, 'term_deletion_handler'));
493 add_filter('wp_update_term_data', array($this, 'term_updation_handler'), 10, 2);
494
495 /* SENSORS FOR USER CHANGES*/
496 add_action('user_register', array($this, 'user_handler'));
497 add_action('wpmu_new_user', array($this, 'user_handler'));
498 add_action('profile_update', array($this, 'user_update_handler'), 10, 2);
499 add_action('delete_user', array($this, 'user_handler'));
500 add_action('wpmu_delete_user', array($this, 'user_handler'));
501
502 /* SENSORS FOR PLUGIN AND THEME*/
503 add_action('activate_plugin', array($this, 'plugin_action_handler'));
504 add_action('deactivate_plugin', array($this, 'plugin_action_handler'));
505 add_action('switch_theme', array($this, 'theme_action_handler'));
506
507 /* SENSORS FOR MULTISITE CHANGES */
508 add_action('wp_insert_site', array($this, 'mu_site_handler'));
509 add_action('archive_blog', array($this, 'mu_handler'));
510 add_action('unarchive_blog', array( $this, 'mu_handler'));
511 add_action('activate_blog', array($this, 'mu_handler'));
512 add_action('deactivate_blog', array($this, 'mu_handler'));
513 add_action('wp_delete_site', array($this, 'mu_site_handler'));
514
515 /* SENSORS USER ACTIONS AT FRONTEND */
516 add_action('wp_login', array($this, 'user_login_handler'), 10, 2);
517 add_action('wp_logout', array( $this, 'user_logout_handler'), 5, 1);
518 add_action('password_reset', array( $this, 'password_reset_handler'), 10, 2);
519
520 /* SENSOR FOR PLUGIN, THEME, WPCORE UPGRADES */
521 add_action('upgrader_process_complete', array($this, 'upgrade_handler'), 10, 2);
522 add_action('_core_updated_successfully', array($this, 'core_upgrade_handler'), 10, 1);
523
524 /* SENSORS FOR WOOCOMMERCE EVENTS */
525 add_action('woocommerce_attribute_added', array($this, 'woocommerce_attribute_created_handler'), 10, 2);
526 add_action('woocommerce_attribute_updated', array($this, 'woocommerce_attribute_handler'), 10, 1);
527 add_action('woocommerce_before_attribute_delete', array($this, 'woocommerce_attribute_handler'), 10, 1);
528 add_action('woocommerce_attribute_deleted', array($this, 'woocommerce_attribute_handler'), 10, 1);
529
530 add_action('woocommerce_tax_rate_added', array($this, 'woocommerce_tax_rate_handler'), 10, 2);
531 add_action('woocommerce_tax_rate_deleted', array($this, 'woocommerce_tax_rate_deleted_handler'), 10, 1);
532 add_action('woocommerce_tax_rate_updated', array($this, 'woocommerce_tax_rate_handler'), 10, 2);
533
534 add_action('woocommerce_grant_product_download_access', array($this, 'woocommerce_grant_product_download_access_handler'), 10, 1);
535 add_action('woocommerce_ajax_revoke_access_to_product_download', array($this, 'woocommerce_revoke_access_to_product_download_handler'), 10, 3);
536
537 add_action('woocommerce_shipping_zone_method_added', array($this, 'woocommerce_shipping_zone_method_handler'), 10, 3);
538 add_action('woocommerce_shipping_zone_method_status_toggled', array($this, 'woocommerce_shipping_zone_method_handler'), 10, 3);
539 add_action('woocommerce_shipping_zone_method_deleted', array($this, 'woocommerce_shipping_zone_method_handler'), 10, 3);
540 }
541 }
542 endif;