PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.5.3
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.5.3
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.5.3, at src/Admin/appsero/Client.php

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