PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.1.3
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.1.3
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.1.3, at vendor/codeinwp/themeisle-sdk/src/Product.php

384 lines 8.2 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_readable( $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 * Check if the product is either theme or plugin.
205 *
206 * @return string Product type.
207 */
208 public function get_type() {
209 return $this->type;
210 }
211
212 /**
213 * Return if the product is used as a plugin.
214 *
215 * @return bool Is plugin?
216 */
217 public function is_plugin() {
218 return self::PLUGIN_TYPE === $this->type;
219 }
220
221 /**
222 * Return if the product is used as a theme.
223 *
224 * @return bool Is theme ?
225 */
226 public function is_theme() {
227 return self::THEME_TYPE === $this->type;
228 }
229
230 /**
231 * Returns the product slug.
232 *
233 * @return string The product slug.
234 */
235 public function get_slug() {
236 return $this->slug;
237 }
238
239 /**
240 * The magic var_dump info method.
241 *
242 * @return array Debug info.
243 */
244 public function __debugInfo() {
245 return array(
246 'name' => $this->name,
247 'slug' => $this->slug,
248 'version' => $this->version,
249 'basefile' => $this->basefile,
250 'key' => $this->key,
251 'type' => $this->type,
252 'store_name' => $this->store_name,
253 'store_url' => $this->store_url,
254 'wordpress_available' => $this->wordpress_available,
255 'requires_license' => $this->requires_license,
256 );
257
258 }
259
260 /**
261 * Getter for product version.
262 *
263 * @return string The product version.
264 */
265 public function get_version() {
266 return $this->version;
267 }
268
269 /**
270 * Returns current product license, if available.
271 *
272 * @return string Return license key, if available.
273 */
274 public function get_license() {
275
276 if ( ! $this->requires_license() && ! $this->is_wordpress_available() ) {
277 return 'free';
278 }
279 $license_data = get_option( $this->get_key() . '_license_data', '' );
280
281 if ( empty( $license_data ) ) {
282 return get_option( $this->get_key() . '_license', '' );
283 }
284 if ( ! isset( $license_data->key ) ) {
285 return get_option( $this->get_key() . '_license', '' );
286 }
287
288 return $license_data->key;
289 }
290
291 /**
292 * Either the product requires license or not.
293 *
294 * @return bool Either requires license or not.
295 */
296 public function requires_license() {
297 return $this->requires_license;
298 }
299
300 /**
301 * If product is available on wordpress.org or not.
302 *
303 * @return bool Either is wp available or not.
304 */
305 public function is_wordpress_available() {
306 return $this->wordpress_available;
307 }
308
309 /**
310 * Return friendly name.
311 *
312 * @return string Friendly name.
313 */
314 public function get_friendly_name() {
315 $name = apply_filters( $this->get_key() . '_friendly_name', trim( str_replace( 'Lite', '', $this->get_name() ) ) );
316 $name = rtrim( $name, '- ()' );
317
318 return $name;
319 }
320
321 /**
322 * Getter for product name.
323 *
324 * @return string The product name.
325 */
326 public function get_name() {
327 return $this->name;
328 }
329
330 /**
331 * Returns the Store name.
332 *
333 * @return string Store name.
334 */
335 public function get_store_name() {
336 return $this->store_name;
337 }
338
339 /**
340 * Returns the store url.
341 *
342 * @return string The store url.
343 */
344 public function get_store_url() {
345 return $this->store_url;
346 }
347
348 /**
349 * Returns product basefile, which holds the metaheaders.
350 *
351 * @return string The product basefile.
352 */
353 public function get_basefile() {
354 return $this->basefile;
355 }
356
357 /**
358 * Returns product filename.
359 *
360 * @return string The product filename.
361 */
362 public function get_file() {
363 return $this->file;
364 }
365 /**
366 * Returns the pro slug, if available.
367 *
368 * @return string The pro slug.
369 */
370 public function get_pro_slug() {
371 return $this->pro_slug;
372 }
373
374 /**
375 * Return the install timestamp.
376 *
377 * @return int The install timestamp.
378 */
379 public function get_install_time() {
380 return $this->install;
381 }
382
383 }
384