| @@ -8,11 +8,8 @@ | ||
| 8 | 8 | public static $actlog_table = 'activities_store'; |
| 9 | 9 | public $db; |
| 10 | 10 | public $settings; |
| 11 | 11 | public $bvinfo; |
| 12 | - public $request_id; | |
| 13 | - public $ip_header; | |
| 14 | - public $ignored_events; | |
| 15 | 12 | |
| 16 | 13 | public function __construct($db, $settings, $info, $config) { |
| 17 | 14 | $this->db = $db; |
| 18 | 15 | $this->settings = $settings; |
| @@ -18,9 +15,8 @@ | ||
| 18 | 15 | $this->settings = $settings; |
| 19 | 16 | $this->bvinfo = $info; |
| 20 | 17 | $this->request_id = WPRInfo::getRequestID(); |
| 21 | 18 | $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 | 19 | } |
| 24 | 20 | |
| 25 | 21 | function init() { |
| 26 | 22 | $this->add_actions_and_listeners(); |
| @@ -65,9 +61,8 @@ | ||
| 65 | 61 | $data = array('id' => $user_id); |
| 66 | 62 | if (!empty($user)) { |
| 67 | 63 | $data['username'] = $user->user_login; |
| 68 | 64 | $data['email'] = $user->user_email; |
| 69 | - $data['role'] = $user->roles; | |
| 70 | 65 | } |
| 71 | 66 | return $data; |
| 72 | 67 | } |
| 73 | 68 | |
| @@ -109,21 +104,21 @@ | ||
| 109 | 104 | function get_ip($ipHeader) { |
| 110 | 105 | $ip = '127.0.0.1'; |
| 111 | 106 | if ($ipHeader && is_array($ipHeader)) { |
| 112 | 107 | if (array_key_exists($ipHeader['hdr'], $_SERVER)) { |
| 113 | - $_ips = preg_split("/(,| |\t)/", WPRHelper::getRawParam('SERVER', $ipHeader['hdr'])); | |
| 108 | + $_ips = preg_split("/(,| |\t)/", $_SERVER[$ipHeader['hdr']]); | |
| 114 | 109 | if (array_key_exists(intval($ipHeader['pos']), $_ips)) { |
| 115 | 110 | $ip = $_ips[intval($ipHeader['pos'])]; |
| 116 | 111 | } |
| 117 | 112 | } |
| 118 | 113 | } else if (array_key_exists('REMOTE_ADDR', $_SERVER)) { |
| 119 | - $ip = WPRHelper::getRawParam('SERVER', 'REMOTE_ADDR'); | |
| 114 | + $ip = $_SERVER['REMOTE_ADDR']; | |
| 120 | 115 | } |
| 121 | 116 | |
| 122 | 117 | $ip = trim($ip); |
| 123 | - if (WPRHelper::safePregMatch('/^\[([0-9a-fA-F:]+)\](:[0-9]+)$/', $ip, $matches)) { | |
| 118 | + if (preg_match('/^\[([0-9a-fA-F:]+)\](:[0-9]+)$/', $ip, $matches)) { | |
| 124 | 119 | $ip = $matches[1]; |
| 125 | - } elseif (WPRHelper::safePregMatch('/^([0-9.]+)(:[0-9]+)$/', $ip, $matches)) { | |
| 120 | + } elseif (preg_match('/^([0-9.]+)(:[0-9]+)$/', $ip, $matches)) { | |
| 126 | 121 | $ip = $matches[1]; |
| 127 | 122 | } |
| 128 | 123 | |
| 129 | 124 | return $ip; |
| @@ -148,27 +143,8 @@ | ||
| 148 | 143 | $values["time"] = time(); |
| 149 | 144 | $this->db->replaceIntoBVTable(BVWPActLog::$actlog_table, $values); |
| 150 | 145 | } |
| 151 | 146 | |
| 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 | 147 | function user_login_handler($user_login, $user) { |
| 172 | 148 | $event_data = array("user" => $this->get_user($user->ID)); |
| 173 | 149 | $this->add_activity($event_data); |
| 174 | 150 | } |
| @@ -208,14 +184,10 @@ | ||
| 208 | 184 | } |
| 209 | 185 | |
| 210 | 186 | function post_handler($post_id) { |
| 211 | 187 | $post = $this->get_post($post_id); |
| 212 | - if ($this->is_key_ignored($this->ignored_events, $post["type"])) | |
| 213 | - return; | |
| 214 | 188 | $event_data = array(); |
| 215 | - if (!isset($post["type"])) { | |
| 216 | - $event_data["post"] = $post; | |
| 217 | - } elseif ($post["type"] === "product") { | |
| 189 | + if ($post["type"] === "product") { | |
| 218 | 190 | $event_data["product"] = $post; |
| 219 | 191 | } elseif ($post["type"] === "shop_order") { |
| 220 | 192 | $event_data["order"] = $post; |
| 221 | 193 | } else { |
| @@ -225,14 +197,10 @@ | ||
| 225 | 197 | } |
| 226 | 198 | |
| 227 | 199 | function post_saved_handler($post_id, $post, $update) { |
| 228 | 200 | $post = $this->get_post($post_id); |
| 229 | - if ($this->is_key_ignored($this->ignored_events, $post["type"])) | |
| 230 | - return; | |
| 231 | 201 | $event_data = array(); |
| 232 | - if (!isset($post["type"])) { | |
| 233 | - $event_data["post"] = $post; | |
| 234 | - } elseif ($post["type"] === "product") { | |
| 202 | + if ($post["type"] === "product") { | |
| 235 | 203 | $event_data["product"] = $post; |
| 236 | 204 | } elseif ($post["type"] === "shop_order") { |
| 237 | 205 | $event_data["order"] = $post; |
| 238 | 206 | } else { |
| @@ -369,11 +337,9 @@ | ||
| 369 | 337 | $data = array(); |
| 370 | 338 | if (!empty($plugins) && defined('WP_PLUGIN_DIR')) { |
| 371 | 339 | foreach ($plugins as $plugin) { |
| 372 | 340 | $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); | |
| 341 | + $install_data = array('title' => $plugin_data['Name'], 'version' => $plugin_data['Version']); | |
| 376 | 342 | array_push($data, $install_data); |
| 377 | 343 | } |
| 378 | 344 | } |
| 379 | 345 | return $data; |
| @@ -383,11 +349,9 @@ | ||
| 383 | 349 | $data = array(); |
| 384 | 350 | if (!empty($themes)) { |
| 385 | 351 | foreach ($themes as $theme) { |
| 386 | 352 | $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); | |
| 353 | + $install_data = array('title' => $theme_data['Name'], 'version' => $theme_data['Version']); | |
| 390 | 354 | array_push($data, $install_data); |
| 391 | 355 | } |
| 392 | 356 | } |
| 393 | 357 | return $data; |
| @@ -396,11 +360,9 @@ | ||
| 396 | 360 | function get_plugin_install_data($upgrader) { |
| 397 | 361 | $data = array(); |
| 398 | 362 | if ($upgrader->bulk != "1") { |
| 399 | 363 | $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); | |
| 364 | + $install_data = array('title' => $plugin_data['Name'], 'version' => $plugin_data['Version']); | |
| 403 | 365 | array_push($data, $install_data); |
| 404 | 366 | } |
| 405 | 367 | return $data; |
| 406 | 368 | } |
| @@ -407,33 +369,28 @@ | ||
| 407 | 369 | |
| 408 | 370 | function get_theme_install_data($upgrader) { |
| 409 | 371 | $data = array(); |
| 410 | 372 | $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); | |
| 373 | + $install_data = array('title' => $theme_data['Name'], 'version' => $theme_data['Version']); | |
| 414 | 374 | array_push($data, $install_data); |
| 415 | 375 | return $data; |
| 416 | 376 | } |
| 417 | 377 | |
| 418 | 378 | function get_update_data($options) { |
| 379 | + global $wp_version; | |
| 419 | 380 | $event_data = array('action' => 'update'); |
| 420 | 381 | if ($options['type'] === 'plugin') { |
| 421 | 382 | $event_data['type'] = 'plugin'; |
| 422 | - if (array_key_exists("plugin", $options)) { | |
| 423 | - $options['plugins'] = array($options['plugin']); | |
| 424 | - unset($options['plugin']); | |
| 425 | - } | |
| 426 | 383 | $event_data['plugins'] = $this->get_plugin_update_data($options['plugins']); |
| 427 | 384 | } |
| 428 | 385 | else if ($options['type'] === 'theme') { |
| 429 | 386 | $event_data['type'] = 'theme'; |
| 430 | - if (array_key_exists("theme", $options)) { | |
| 431 | - $options['themes'] = array($options['theme']); | |
| 432 | - unset($options['theme']); | |
| 433 | - } | |
| 434 | 387 | $event_data['themes'] = $this->get_theme_update_data($options['themes']); |
| 435 | 388 | } |
| 389 | + else if ($options['type'] === 'core') { | |
| 390 | + $event_data['type'] = 'core'; | |
| 391 | + $event_data['wp_core'] = array('prev_version' => $wp_version); | |
| 392 | + } | |
| 436 | 393 | return $event_data; |
| 437 | 394 | } |
| 438 | 395 | |
| 439 | 396 | function get_install_data($upgrader, $options) { |
| @@ -450,29 +407,16 @@ | ||
| 450 | 407 | } |
| 451 | 408 | |
| 452 | 409 | function upgrade_handler($upgrader, $data) { |
| 453 | 410 | $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 | - } | |
| 411 | + if ($data['action'] === 'update') { | |
| 412 | + $event_data = $this->get_update_data($data); | |
| 413 | + } else if ($data['action'] === 'install') { | |
| 414 | + $event_data = $this->get_install_data($upgrader, $data); | |
| 463 | 415 | } |
| 464 | 416 | $this->add_activity($event_data); |
| 465 | 417 | } |
| 466 | 418 | |
| 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 | 419 | /* ADDING ACTION AND LISTENERS FOR SENSING EVENTS. */ |
| 476 | 420 | public function add_actions_and_listeners() { |
| 477 | 421 | /* SENSORS FOR POST AND PAGE CHANGES */ |
| 478 | 422 | add_action('pre_post_update', array($this, 'post_handler')); |
| @@ -518,9 +462,8 @@ | ||
| 518 | 462 | add_action('password_reset', array( $this, 'password_reset_handler'), 10, 2); |
| 519 | 463 | |
| 520 | 464 | /* SENSOR FOR PLUGIN, THEME, WPCORE UPGRADES */ |
| 521 | 465 | 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 | 466 | |
| 524 | 467 | /* SENSORS FOR WOOCOMMERCE EVENTS */ |
| 525 | 468 | add_action('woocommerce_attribute_added', array($this, 'woocommerce_attribute_created_handler'), 10, 2); |
| 526 | 469 | add_action('woocommerce_attribute_updated', array($this, 'woocommerce_attribute_handler'), 10, 1); |