PluginProbe
Easy Hotel – Powerful Hotel Booking / 2.0.2
Easy Hotel – Powerful Hotel Booking v2.0.2
2.0.8 2.0.7 2.0.6 2.0.5 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.9.9 1.9.8 1.9.7 1.9.6 1.9.5 1.9.4 1.9.3 1.9.2 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 All 110 releases
easy-hotel / admin / includes / opt-in / Client.php

Client.php in Easy Hotel – Powerful Hotel Booking 2.0.2, at admin/includes/opt-in/Client.php

252 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Appsero;
3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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 = '2.0.4';
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 *
35 * @example .../wp-content/plugins/test-slug/test-slug.php
36 *
37 * @var string
38 */
39 public $file;
40
41 /**
42 * Main plugin file
43 *
44 * @example test-slug/test-slug.php
45 *
46 * @var string
47 */
48 public $basename;
49
50 /**
51 * Slug of the plugin
52 *
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 * The Object of Insights Class
82 *
83 * @var object
84 */
85 private $insights;
86
87 /**
88 * Initialize the class
89 *
90 * @param string $hash hash of the plugin
91 * @param string $name readable name of the plugin
92 * @param string $file main plugin file path
93 */
94 public function __construct( $hash, $name, $file ) {
95 $this->hash = $hash;
96 $this->name = $name;
97 $this->file = $file;
98
99 $this->set_basename_and_slug();
100 }
101
102 /**
103 * Initialize insights class
104 *
105 * @return Appsero\Insights
106 */
107 public function insights() {
108 if ( ! class_exists( __NAMESPACE__ . '\Insights' ) ) {
109 require_once __DIR__ . '/Insights.php';
110 }
111
112 // if already instantiated, return the cached one
113 if ( $this->insights ) {
114 return $this->insights;
115 }
116
117 $this->insights = new Insights( $this );
118
119 return $this->insights;
120 }
121
122 /**
123 * Initialize plugin/theme updater
124 *
125 * @return void
126 */
127 public function updater() {
128 // do not show update notice on ajax request and rest api request
129 if ( wp_doing_ajax() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
130 return;
131 }
132
133 // show deprecated notice
134 _deprecated_function( __CLASS__ . '::updater', '2.0', '\Appsero\Updater::init($client);, for more details please visit: https://appsero.com/docs/appsero-developers-guide/appsero-client/appsero-sdk-updater-changes/' );
135
136 // initialize the new updater
137 if ( method_exists( '\Appsero\Updater', 'init' ) ) {
138 \Appsero\Updater::init( $this );
139 }
140 }
141
142
143 /**
144 * API Endpoint
145 *
146 * @return string
147 */
148 public function endpoint() {
149 $endpoint = apply_filters( 'appsero_endpoint', 'https://api.appsero.com' );
150
151 return trailingslashit( $endpoint );
152 }
153
154 /**
155 * Set project basename, slug and version
156 *
157 * @return void
158 */
159 protected function set_basename_and_slug() {
160 if ( strpos( $this->file, WP_CONTENT_DIR . '/themes/' ) === false ) {
161 $this->basename = plugin_basename( $this->file );
162
163 list( $this->slug, $mainfile ) = explode( '/', $this->basename );
164
165 require_once ABSPATH . 'wp-admin/includes/plugin.php';
166
167 $plugin_data = get_plugin_data( $this->file, false, false );
168
169 $this->project_version = $plugin_data['Version'];
170 $this->type = 'plugin';
171 } else {
172 $this->basename = str_replace( WP_CONTENT_DIR . '/themes/', '', $this->file );
173
174 list( $this->slug, $mainfile ) = explode( '/', $this->basename );
175
176 $theme = wp_get_theme( $this->slug );
177
178 $this->project_version = $theme->version;
179 $this->type = 'theme';
180 }
181
182 $this->textdomain = $this->slug;
183 }
184
185 /**
186 * Send request to remote endpoint
187 *
188 * @param array $params
189 * @param string $route
190 *
191 * @return array|WP_Error array of results including HTTP headers or WP_Error if the request failed
192 */
193 public function send_request( $params, $route, $blocking = false ) {
194 $url = $this->endpoint() . $route;
195
196 $headers = [
197 'user-agent' => 'Appsero/' . md5( esc_url( home_url() ) ) . ';',
198 'Accept' => 'application/json',
199 ];
200
201 $response = wp_remote_post(
202 $url,
203 [
204 'method' => 'POST',
205 'timeout' => 30,
206 'redirection' => 5,
207 'httpversion' => '1.0',
208 'blocking' => $blocking,
209 'headers' => $headers,
210 'body' => array_merge( $params, [ 'client' => $this->version ] ),
211 'cookies' => [],
212 ]
213 );
214
215 return $response;
216 }
217
218 /**
219 * Check if the current server is localhost
220 *
221 * @return bool
222 */
223 public function is_local_server() {
224 $is_local = isset( $_SERVER['REMOTE_ADDR'] ) && in_array( $_SERVER['REMOTE_ADDR'], [ '127.0.0.1', '::1' ], true );
225
226 return apply_filters( 'appsero_is_local', $is_local );
227 }
228
229 /**
230 * Translate function _e()
231 */
232 // phpcs:ignore
233 public function _etrans( $text ) {
234 call_user_func( '_e', $text, $this->textdomain );
235 }
236
237 /**
238 * Translate function __()
239 */
240 // phpcs:ignore
241 public function __trans( $text ) {
242 return call_user_func( '__', $text, $this->textdomain );
243 }
244
245 /**
246 * Set project textdomain
247 */
248 public function set_textdomain( $textdomain ) {
249 $this->textdomain = $textdomain;
250 }
251 }
252