PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.4
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.4
9.1.2 9.1.1 9.1.0 9.0.3 9.0.2 9.0.1 9.0.0 8.5.79 8.5.78 8.5.77 8.5.76 8.5.75 8.5.74 8.5.73 8.5.72 8.5.71 8.5.70 8.5.69 8.5.68 8.5.35 8.5.36 8.5.37 8.5.38 8.5.39 8.5.4 All 221 releases
wpvr / appsero / src / Client.php

Client.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 8.5.4, at appsero/src/Client.php

281 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Appsero;
3
4 /**
5 * Appsero Client
6 *
7 * This class is necessary to set project data
8 */
9 class Client {
10
11 /**
12 * The client version
13 *
14 * @var string
15 */
16 public $version = '1.2.0';
17
18 /**
19 * Hash identifier of the plugin
20 *
21 * @var string
22 */
23 public $hash;
24
25 /**
26 * Name of the plugin
27 *
28 * @var string
29 */
30 public $name;
31
32 /**
33 * The plugin/theme file path
34 * @example .../wp-content/plugins/test-slug/test-slug.php
35 *
36 * @var string
37 */
38 public $file;
39
40 /**
41 * Main plugin file
42 * @example test-slug/test-slug.php
43 *
44 * @var string
45 */
46 public $basename;
47
48 /**
49 * Slug of the plugin
50 * @example test-slug
51 *
52 * @var string
53 */
54 public $slug;
55
56 /**
57 * The project version
58 *
59 * @var string
60 */
61 public $project_version;
62
63 /**
64 * The project type
65 *
66 * @var string
67 */
68 public $type;
69
70 /**
71 * textdomain
72 *
73 * @var string
74 */
75 public $textdomain;
76
77 /**
78 * The Object of Insights Class
79 *
80 * @var object
81 */
82 private $insights;
83
84 /**
85 * The Object of Updater Class
86 *
87 * @var object
88 */
89 private $updater;
90
91 /**
92 * The Object of License Class
93 *
94 * @var object
95 */
96 private $license;
97
98 /**
99 * Initialize the class
100 *
101 * @param string $hash hash of the plugin
102 * @param string $name readable name of the plugin
103 * @param string $file main plugin file path
104 */
105 public function __construct( $hash, $name, $file ) {
106 $this->hash = $hash;
107 $this->name = $name;
108 $this->file = $file;
109
110 $this->set_basename_and_slug();
111 }
112
113 /**
114 * Initialize insights class
115 *
116 * @return Appsero\Insights
117 */
118 public function insights() {
119
120 if ( ! class_exists( __NAMESPACE__ . '\Insights') ) {
121 require_once __DIR__ . '/Insights.php';
122 }
123
124 // if already instantiated, return the cached one
125 if ( $this->insights ) {
126 return $this->insights;
127 }
128
129 $this->insights = new Insights( $this );
130
131 return $this->insights;
132 }
133
134 /**
135 * Initialize plugin/theme updater
136 *
137 * @return Appsero\Updater
138 */
139 public function updater() {
140
141 if ( ! class_exists( __NAMESPACE__ . '\Updater') ) {
142 require_once __DIR__ . '/Updater.php';
143 }
144
145 // if already instantiated, return the cached one
146 if ( $this->updater ) {
147 return $this->updater;
148 }
149
150 $this->updater = new Updater( $this );
151
152 return $this->updater;
153 }
154
155 /**
156 * Initialize license checker
157 *
158 * @return Appsero\License
159 */
160 public function license() {
161
162 if ( ! class_exists( __NAMESPACE__ . '\License') ) {
163 require_once __DIR__ . '/License.php';
164 }
165
166 // if already instantiated, return the cached one
167 if ( $this->license ) {
168 return $this->license;
169 }
170
171 $this->license = new License( $this );
172
173 return $this->license;
174 }
175
176 /**
177 * API Endpoint
178 *
179 * @return string
180 */
181 public function endpoint() {
182 $endpoint = apply_filters( 'appsero_endpoint', 'https://api.appsero.com' );
183
184 return trailingslashit( $endpoint );
185 }
186
187 /**
188 * Set project basename, slug and version
189 *
190 * @return void
191 */
192 protected function set_basename_and_slug() {
193
194 if ( strpos( $this->file, WP_CONTENT_DIR . '/themes/' ) === false ) {
195 $this->basename = plugin_basename( $this->file );
196
197 list( $this->slug, $mainfile) = explode( '/', $this->basename );
198
199 require_once ABSPATH . 'wp-admin/includes/plugin.php';
200
201 $plugin_data = get_plugin_data( $this->file );
202
203 $this->project_version = $plugin_data['Version'];
204 $this->type = 'plugin';
205 } else {
206 $this->basename = str_replace( WP_CONTENT_DIR . '/themes/', '', $this->file );
207
208 list( $this->slug, $mainfile) = explode( '/', $this->basename );
209
210 $theme = wp_get_theme( $this->slug );
211
212 $this->project_version = $theme->version;
213 $this->type = 'theme';
214 }
215
216 $this->textdomain = $this->slug;
217 }
218
219 /**
220 * Send request to remote endpoint
221 *
222 * @param array $params
223 * @param string $route
224 *
225 * @return array|WP_Error Array of results including HTTP headers or WP_Error if the request failed.
226 */
227 public function send_request( $params, $route, $blocking = false ) {
228 $url = $this->endpoint() . $route;
229
230 $headers = array(
231 'user-agent' => 'Appsero/' . md5( esc_url( home_url() ) ) . ';',
232 'Accept' => 'application/json',
233 );
234
235 $response = wp_remote_post( $url, array(
236 'method' => 'POST',
237 'timeout' => 30,
238 'redirection' => 5,
239 'httpversion' => '1.0',
240 'blocking' => $blocking,
241 'headers' => $headers,
242 'body' => array_merge( $params, array( 'client' => $this->version ) ),
243 'cookies' => array()
244 ) );
245
246 return $response;
247 }
248
249 /**
250 * Check if the current server is localhost
251 *
252 * @return boolean
253 */
254 public function is_local_server() {
255 $is_local = in_array( $_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '::1' ) );
256
257 return apply_filters( 'appsero_is_local', $is_local );
258 }
259
260 /**
261 * Translate function _e()
262 */
263 public function _etrans( $text ) {
264 call_user_func( '_e', $text, $this->textdomain );
265 }
266
267 /**
268 * Translate function __()
269 */
270 public function __trans( $text ) {
271 return call_user_func( '__', $text, $this->textdomain );
272 }
273
274 /**
275 * Set project textdomain
276 */
277 public function set_textdomain( $textdomain ) {
278 $this->textdomain = $textdomain;
279 }
280 }
281