ajax.php
7 months ago
plugin-data-sender.php
9 months ago
plugin-installer.php
7 months ago
plugin-skin.php
7 months ago
plugin-status.php
4 years ago
utils.php
3 years ago
plugin-data-sender.php
125 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP_Social\Lib\Onboard\Classes; |
| 4 | |
| 5 | use WP_Social\Lib\Onboard\Onboard; |
| 6 | use WP_Social\Plugin; |
| 7 | use WP_Social\Traits\Singleton; |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | class Plugin_Data_Sender { |
| 12 | |
| 13 | use Singleton; |
| 14 | |
| 15 | private $installedPlugins = []; |
| 16 | private $themes = []; |
| 17 | private $activatedPlugins = []; |
| 18 | |
| 19 | public function __construct() { |
| 20 | $this->set_activated_plugins(); |
| 21 | $this->set_installed_plugins(); |
| 22 | $this->setThemes(); |
| 23 | } |
| 24 | |
| 25 | private function set_activated_plugins() { |
| 26 | foreach ( apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) as $plugin ) { |
| 27 | array_push( $this->activatedPlugins, $plugin ); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | private function set_installed_plugins() { |
| 32 | foreach ( get_plugins() as $key => $plugin ) { |
| 33 | $status = false; |
| 34 | if ( in_array( $key, $this->activatedPlugins ) ) { |
| 35 | $status = true; |
| 36 | } |
| 37 | array_push( $this->installedPlugins, [ |
| 38 | 'name' => $plugin['Name'], |
| 39 | 'version' => $plugin['Version'], |
| 40 | 'is_active' => $status, |
| 41 | ] ); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | private function setThemes() { |
| 46 | $activeTheme = wp_get_theme()->get('Name') ; |
| 47 | foreach (wp_get_themes() as $key => $theme) { |
| 48 | array_push($this->themes, [ |
| 49 | "name" => $theme->Name, |
| 50 | "version" => $theme->Version, |
| 51 | 'is_active' => $activeTheme == $theme->Name, |
| 52 | ]); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | |
| 57 | private function getUrl( $route ) { |
| 58 | return Plugin::instance()->account_url(). '/sync/api/' . $route; |
| 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 | /** |
| 90 | * @param $route |
| 91 | * @param $data |
| 92 | */ |
| 93 | public function sendEmailSubscribeData( $route, $data ) |
| 94 | { |
| 95 | return wp_remote_post( |
| 96 | 'https://api.wpmet.com/public/' . $route, |
| 97 | [ |
| 98 | 'method' => 'POST', |
| 99 | 'data_format' => 'body', |
| 100 | 'headers' => [ |
| 101 | 'Accept' => '*/*', |
| 102 | 'Content-Type' => 'application/json' |
| 103 | ], |
| 104 | 'body' => json_encode($data) |
| 105 | ] |
| 106 | ); |
| 107 | } |
| 108 | |
| 109 | public function get_data() { |
| 110 | return [ |
| 111 | 'environment_id' => Onboard::ENVIRONMENT_ID, |
| 112 | "domain" => get_home_url(), |
| 113 | "total_user" => count_users()['total_users'], |
| 114 | "themes" => $this->themes, |
| 115 | "plugins" => $this->installedPlugins, |
| 116 | "php_version" => phpversion(), |
| 117 | "db_version" => mysqli_get_client_version(), |
| 118 | "server_name" => explode( ' ', sanitize_text_field( $_SERVER['SERVER_SOFTWARE'] ))[0], |
| 119 | "max_execution_time" => ini_get( 'max_execution_time' ), |
| 120 | "php_memory_size" => ini_get( 'memory_limit' ), |
| 121 | "language" => get_locale() |
| 122 | ]; |
| 123 | |
| 124 | } |
| 125 | } |