PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.3.2
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.3.2
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
visualizer / vendor / codeinwp / themeisle-sdk / src / Product.php

Product.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.3.2, at vendor/codeinwp/themeisle-sdk/src/Product.php

419 lines 8.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The product model class for ThemeIsle SDK
4 *
5 * @package ThemeIsleSDK
6 * @subpackage Product
7 * @copyright Copyright (c) 2017, Marius Cristea
8 * @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
9 * @since 1.0.0
10 */
11
12 namespace ThemeisleSDK;
13
14 // Exit if accessed directly.
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 /**
20 * Product model for ThemeIsle SDK.
21 */
22 class Product {
23 /**
24 * Define plugin type string.
25 */
26 const PLUGIN_TYPE = 'plugin';
27 /**
28 * Define theme type string.
29 */
30 const THEME_TYPE = 'theme';
31 /**
32 * If the product has a pro version, contains the pro slug.
33 *
34 * @var string $pro_slug Pro slug, if available.
35 */
36 public $pro_slug;
37 /**
38 * Current product slug.
39 *
40 * @var string $slug THe product slug.
41 */
42 private $slug;
43 /**
44 * Product basefile, with the proper metadata.
45 *
46 * @var string $basefile The file with headers.
47 */
48 private $basefile;
49 /**
50 * Type of the product.
51 *
52 * @var string $type The product type ( plugin | theme ).
53 */
54 private $type;
55 /**
56 * The file name.
57 *
58 * @var string $file The file name.
59 */
60 private $file;
61 /**
62 * Product name, fetched from the file headers.
63 *
64 * @var string $name The product name.
65 */
66 private $name;
67 /**
68 * Product normalized key.
69 *
70 * @var string $key The product ready key.
71 */
72 private $key;
73 /**
74 * Product store url.
75 *
76 * @var string $store_url The store url.
77 */
78 private $store_url;
79 /**
80 * Product install timestamp.
81 *
82 * @var int $install The date of install.
83 */
84 private $install;
85 /**
86 * Product store/author name.
87 *
88 * @var string $store_name The store name.
89 */
90 private $store_name;
91 /**
92 * Does the product requires license.
93 *
94 * @var bool $requires_license Either user needs to activate it with license.
95 */
96 private $requires_license;
97 /**
98 * Is the product available on wordpress.org
99 *
100 * @var bool $wordpress_available Either is available on WordPress or not.
101 */
102 private $wordpress_available;
103 /**
104 * Current version of the product.
105 *
106 * @var string $version The product version.
107 */
108 private $version;
109
110 /**
111 * ThemeIsle_SDK_Product constructor.
112 *
113 * @param string $basefile Product basefile.
114 */
115 public function __construct( $basefile ) {
116 if ( ! empty( $basefile ) ) {
117 if ( is_file( $basefile ) ) {
118 $this->basefile = $basefile;
119 $this->setup_from_path();
120 $this->setup_from_fileheaders();
121 }
122 }
123 $install = get_option( $this->get_key() . '_install', 0 );
124 if ( 0 === $install ) {
125 $install = time();
126 update_option( $this->get_key() . '_install', time() );
127 }
128 $this->install = $install;
129
130 }
131
132 /**
133 * Setup props from path.
134 */
135 public function setup_from_path() {
136 $this->file = basename( $this->basefile );
137 $dir = dirname( $this->basefile );
138 $this->slug = basename( $dir );
139 $exts = explode( '.', $this->basefile );
140 $ext = $exts[ count( $exts ) - 1 ];
141 if ( 'css' === $ext ) {
142 $this->type = 'theme';
143 }
144 if ( 'php' === $ext ) {
145 $this->type = 'plugin';
146 }
147 $this->key = self::key_ready_name( $this->slug );
148 }
149
150 /**
151 * Normalize string.
152 *
153 * @param string $string the String to be normalized for cron handler.
154 *
155 * @return string $name The normalized string.
156 */
157 static function key_ready_name( $string ) {
158 return str_replace( '-', '_', strtolower( trim( $string ) ) );
159 }
160
161 /**
162 * Setup props from fileheaders.
163 */
164 public function setup_from_fileheaders() {
165 $file_headers = array(
166 'Requires License' => 'Requires License',
167 'WordPress Available' => 'WordPress Available',
168 'Pro Slug' => 'Pro Slug',
169 'Version' => 'Version',
170 );
171 if ( 'plugin' === $this->type ) {
172 $file_headers['Name'] = 'Plugin Name';
173 $file_headers['AuthorName'] = 'Author';
174 $file_headers['AuthorURI'] = 'Author URI';
175 }
176 if ( 'theme' === $this->type ) {
177 $file_headers['Name'] = 'Theme Name';
178 $file_headers['AuthorName'] = 'Author';
179 $file_headers['AuthorURI'] = 'Author URI';
180 }
181 $file_headers = get_file_data( $this->basefile, $file_headers );
182
183 $this->name = $file_headers['Name'];
184 $this->store_name = $file_headers['AuthorName'];
185 $this->author_url = $file_headers['AuthorURI'];
186 $this->store_url = $file_headers['AuthorURI'];
187
188 $this->requires_license = ( 'yes' === $file_headers['Requires License'] ) ? true : false;
189 $this->wordpress_available = ( 'yes' === $file_headers['WordPress Available'] ) ? true : false;
190 $this->pro_slug = ! empty( $file_headers['Pro Slug'] ) ? $file_headers['Pro Slug'] : '';
191 $this->version = $file_headers['Version'];
192
193 }
194
195 /**
196 * Return the product key.
197 *
198 * @return string The product key.
199 */
200 public function get_key() {
201 return $this->key;
202 }
203
204 /**
205 * Check if the product is either theme or plugin.
206 *
207 * @return string Product type.
208 */
209 public function get_type() {
210 return $this->type;
211 }
212
213 /**
214 * Return if the product is used as a plugin.
215 *
216 * @return bool Is plugin?
217 */
218 public function is_plugin() {
219 return self::PLUGIN_TYPE === $this->type;
220 }
221
222 /**
223 * Return if the product is used as a theme.
224 *
225 * @return bool Is theme ?
226 */
227 public function is_theme() {
228 return self::THEME_TYPE === $this->type;
229 }
230
231 /**
232 * Returns the product slug.
233 *
234 * @return string The product slug.
235 */
236 public function get_slug() {
237 return $this->slug;
238 }
239
240 /**
241 * The magic var_dump info method.
242 *
243 * @return array Debug info.
244 */
245 public function __debugInfo() {
246 return array(
247 'name' => $this->name,
248 'slug' => $this->slug,
249 'version' => $this->version,
250 'basefile' => $this->basefile,
251 'key' => $this->key,
252 'type' => $this->type,
253 'store_name' => $this->store_name,
254 'store_url' => $this->store_url,
255 'wordpress_available' => $this->wordpress_available,
256 'requires_license' => $this->requires_license,
257 );
258
259 }
260
261 /**
262 * Getter for product version.
263 *
264 * @return string The product version.
265 */
266 public function get_version() {
267 return $this->version;
268 }
269
270 /**
271 * Returns current product license, if available.
272 *
273 * @return string Return license key, if available.
274 */
275 public function get_license() {
276
277 if ( ! $this->requires_license() && ! $this->is_wordpress_available() ) {
278 return 'free';
279 }
280 $license_data = get_option( $this->get_key() . '_license_data', '' );
281
282 if ( empty( $license_data ) ) {
283 return get_option( $this->get_key() . '_license', '' );
284 }
285 if ( ! isset( $license_data->key ) ) {
286 return get_option( $this->get_key() . '_license', '' );
287 }
288
289 return $license_data->key;
290 }
291
292 /**
293 * Either the product requires license or not.
294 *
295 * @return bool Either requires license or not.
296 */
297 public function requires_license() {
298 return $this->requires_license;
299 }
300
301 /**
302 * If product is available on wordpress.org or not.
303 *
304 * @return bool Either is wp available or not.
305 */
306 public function is_wordpress_available() {
307 return $this->wordpress_available;
308 }
309
310 /**
311 * Return friendly name.
312 *
313 * @return string Friendly name.
314 */
315 public function get_friendly_name() {
316 $name = apply_filters( $this->get_key() . '_friendly_name', trim( str_replace( 'Lite', '', $this->get_name() ) ) );
317 $name = rtrim( $name, '- ()' );
318
319 return $name;
320 }
321
322 /**
323 * Getter for product name.
324 *
325 * @return string The product name.
326 */
327 public function get_name() {
328 return $this->name;
329 }
330
331 /**
332 * Returns the Store name.
333 *
334 * @return string Store name.
335 */
336 public function get_store_name() {
337 return $this->store_name;
338 }
339
340 /**
341 * Returns the store url.
342 *
343 * @return string The store url.
344 */
345 public function get_store_url() {
346
347 if ( strpos( $this->store_url, '/themeisle.com' ) !== false ) {
348 return 'https://store.themeisle.com/';
349 }
350
351 return $this->store_url;
352 }
353
354 /**
355 * Returns product basefile, which holds the metaheaders.
356 *
357 * @return string The product basefile.
358 */
359 public function get_basefile() {
360 return $this->basefile;
361 }
362
363 /**
364 * Get changelog url.
365 *
366 * @return string Changelog url.
367 */
368 public function get_changelog() {
369 return add_query_arg(
370 [
371 'name' => rawurlencode( $this->get_name() ),
372 'edd_action' => 'view_changelog',
373 ],
374 $this->get_store_url()
375 );
376 }
377
378 /**
379 * Returns product filename.
380 *
381 * @return string The product filename.
382 */
383 public function get_file() {
384 return $this->file;
385 }
386
387 /**
388 * Returns the pro slug, if available.
389 *
390 * @return string The pro slug.
391 */
392 public function get_pro_slug() {
393 return $this->pro_slug;
394 }
395
396 /**
397 * Return the install timestamp.
398 *
399 * @return int The install timestamp.
400 */
401 public function get_install_time() {
402 return $this->install;
403 }
404
405 /**
406 * Returns the URL of the product base file.
407 *
408 * @param string $path The path to the file.
409 *
410 * @return string The URL of the product base file.
411 */
412 public function get_base_url( $path = '/' ) {
413 if ( $this->type ) {
414 return plugins_url( $path, $this->basefile );
415 }
416 }
417
418 }
419