| 1 |
<?php |
| 2 |
|
| 3 |
namespace EmailKit\Promotional\Onboard\Classes; |
| 4 |
|
| 5 |
use EmailKit\Promotional\Onboard\Onboard; |
| 6 |
use EmailKit\Traits\Singleton; |
| 7 |
|
| 8 |
defined( 'ABSPATH' ) || exit; |
| 9 |
|
| 10 |
class PluginDataSender { |
| 11 |
|
| 12 |
use Singleton; |
| 13 |
|
| 14 |
private $installedPlugins = []; |
| 15 |
private $themes = []; |
| 16 |
private $activatedPlugins = []; |
| 17 |
|
| 18 |
public function __construct() { |
| 19 |
$this->set_activated_plugins(); |
| 20 |
$this->set_installed_plugins(); |
| 21 |
$this->setThemes(); |
| 22 |
} |
| 23 |
|
| 24 |
private function set_activated_plugins() { |
| 25 |
foreach ( apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) as $plugin ) { |
| 26 |
array_push( $this->activatedPlugins, $plugin ); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
private function set_installed_plugins() { |
| 31 |
foreach ( get_plugins() as $key => $plugin ) { |
| 32 |
$status = false; |
| 33 |
if ( in_array( $key, $this->activatedPlugins ) ) { |
| 34 |
$status = true; |
| 35 |
} |
| 36 |
array_push( $this->installedPlugins, [ |
| 37 |
'name' => $plugin['Name'], |
| 38 |
'version' => $plugin['Version'], |
| 39 |
'is_active' => $status, |
| 40 |
] ); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
private function setThemes() { |
| 45 |
$activeTheme = wp_get_theme()->get('Name') ; |
| 46 |
foreach (wp_get_themes() as $key => $theme) { |
| 47 |
array_push($this->themes, [ |
| 48 |
"name" => $theme->Name, |
| 49 |
"version" => $theme->Version, |
| 50 |
'is_active' => $activeTheme == $theme->Name, |
| 51 |
]); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
private function getUrl( $route ) { |
| 57 |
return 'https://account.wpmet.com/sync/api/' . $route; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
public function send( $route ) { |
| 62 |
return wp_remote_post( |
| 63 |
$this->getUrl($route) , |
| 64 |
[ |
| 65 |
'method' => 'POST', |
| 66 |
'data_format' => 'body', |
| 67 |
'headers' => [ |
| 68 |
'Content-Type' => 'application/json' |
| 69 |
], |
| 70 |
'body' => json_encode( $this->get_data() ) |
| 71 |
] |
| 72 |
); |
| 73 |
} |
| 74 |
|
| 75 |
public function sendAutomizyData( $route, $data ) { |
| 76 |
return wp_remote_post( |
| 77 |
$this->getUrl($route) , |
| 78 |
[ |
| 79 |
'method' => 'POST', |
| 80 |
'data_format' => 'body', |
| 81 |
'headers' => [ |
| 82 |
'Content-Type' => 'application/json' |
| 83 |
], |
| 84 |
'body' => json_encode( $data ) |
| 85 |
] |
| 86 |
); |
| 87 |
} |
| 88 |
|
| 89 |
public function get_data() { |
| 90 |
return [ |
| 91 |
'environment_id' => Onboard::ENVIRONMENT_ID, |
| 92 |
"domain" => get_site_url(), |
| 93 |
"total_user" => count_users()['total_users'], |
| 94 |
"themes" => $this->themes, |
| 95 |
"plugins" => $this->installedPlugins, |
| 96 |
"php_version" => phpversion(), |
| 97 |
"db_version" => mysqli_get_client_version(), //phpcs:ignore WordPress.DB.RestrictedFunctions |
| 98 |
"server_name" => isset($_SERVER['SERVER_SOFTWARE'])? explode( ' ', sanitize_text_field(wp_unslash($_SERVER['SERVER_SOFTWARE'])))[0] : '', |
| 99 |
"max_execution_time" => ini_get( 'max_execution_time' ), |
| 100 |
"php_memory_size" => ini_get( 'memory_limit' ), |
| 101 |
"language" => get_locale() |
| 102 |
]; |
| 103 |
} |
| 104 |
} |