PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.4.0
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.4.0
2.1.3 2.1.2 2.1.1 2.1.0 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 trunk 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 All 57 releases
darkify / src / Admin / appsero / Client.php

Client.php in Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) 1.4.0, at src/Admin/appsero/Client.php

202 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace DarkifyAppSero;
4
5 /**
6 * Appsero Client
7 *
8 * This class is necessary to set project data
9 */
10 class Client
11 {
12
13 /**
14 * The client version
15 *
16 * @var string
17 */
18 public $version = '1.2.0';
19
20 /**
21 * Hash identifier of the plugin
22 *
23 * @var string
24 */
25 public $hash;
26
27 /**
28 * Name of the plugin
29 *
30 * @var string
31 */
32 public $name;
33
34 /**
35 * The plugin/theme file path
36 * @example .../wp-content/plugins/test-slug/test-slug.php
37 *
38 * @var string
39 */
40 public $file;
41
42 /**
43 * Main plugin file
44 * @example test-slug/test-slug.php
45 *
46 * @var string
47 */
48 public $basename;
49
50 /**
51 * Slug of the plugin
52 * @example test-slug
53 *
54 * @var string
55 */
56 public $slug;
57
58 /**
59 * The project version
60 *
61 * @var string
62 */
63 public $project_version;
64
65 /**
66 * The project type
67 *
68 * @var string
69 */
70 public $type;
71
72 /**
73 * textdomain
74 *
75 * @var string
76 */
77 public $textdomain;
78
79 /**
80 * Initialize the class
81 *
82 * @param string $hash hash of the plugin
83 * @param string $name readable name of the plugin
84 * @param string $file main plugin file path
85 */
86 public function __construct($hash, $name, $file)
87 {
88 $this->hash = $hash;
89 $this->name = $name;
90 $this->file = $file;
91
92 $this->set_basename_and_slug();
93 }
94
95 /**
96 * Initialize insights class
97 *
98 * @return Appsero\Insights
99 */
100 public function insights()
101 {
102
103 if (!class_exists(__NAMESPACE__ . '\Insights')) {
104 require_once __DIR__ . '/Insights.php';
105 }
106
107 return new Insights($this);
108 }
109
110 /**
111 * API Endpoint
112 *
113 * @return string
114 */
115 public function endpoint()
116 {
117 $endpoint = apply_filters('appsero_endpoint', 'https://api.appsero.com');
118
119 return trailingslashit($endpoint);
120 }
121
122 /**
123 * Set project basename, slug and version
124 *
125 * @return void
126 */
127 protected function set_basename_and_slug()
128 {
129
130 // Removed checking for Theme slug
131
132 $this->basename = plugin_basename($this->file);
133
134 list($this->slug, $mainfile) = explode('/', $this->basename);
135
136 require_once ABSPATH . 'wp-admin/includes/plugin.php';
137
138 // $plugin_data = get_plugin_data($this->file);
139
140 $this->project_version = DARKIFY_VERSION;
141 $this->type = 'plugin';
142 $this->textdomain = $this->slug;
143 }
144
145 /**
146 * Send request to remote endpoint
147 *
148 * @param array $params
149 * @param string $route
150 *
151 * @return array|WP_Error Array of results including HTTP headers or WP_Error if the request failed.
152 */
153 public function send_request($params, $route, $blocking = false)
154 {
155 $url = $this->endpoint() . $route;
156
157 $headers = array(
158 'user-agent' => 'Appsero/' . md5(esc_url(home_url())) . ';',
159 'Accept' => 'application/json',
160 );
161
162 $response = wp_remote_post($url, array(
163 'method' => 'POST',
164 'timeout' => 30,
165 'redirection' => 5,
166 'httpversion' => '1.0',
167 'blocking' => $blocking,
168 'headers' => $headers,
169 'body' => array_merge($params, array('client' => $this->version)),
170 'cookies' => array()
171 ));
172
173 return $response;
174 }
175
176 /**
177 * Check if the current server is localhost
178 *
179 * @return boolean
180 */
181 public function is_local_server()
182 {
183 return in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'));
184 }
185
186 /**
187 * Translate function _e()
188 */
189 public function _etrans($text)
190 {
191 call_user_func('_e', $text, $this->textdomain);
192 }
193
194 /**
195 * Translate function __()
196 */
197 public function darkify_trans($text)
198 {
199 return call_user_func('__', $text, $this->textdomain);
200 }
201 }
202