PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 2.1.9
Visualizer – Tables & Charts Manager with Built-in AI Generator v2.1.9
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 / class-themeisle-sdk-product.php

class-themeisle-sdk-product.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 2.1.9, at vendor/codeinwp/themeisle-sdk/class-themeisle-sdk-product.php

393 lines 9.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 // Exit if accessed directly.
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15 if ( ! class_exists( 'ThemeIsle_SDK_Product' ) ) :
16 /**
17 * Product model for ThemeIsle SDK.
18 */
19 class ThemeIsle_SDK_Product {
20 /**
21 * @var string $slug THe product slug.
22 */
23 private $slug;
24 /**
25 * @var string $basefile The file with headers.
26 */
27 private $basefile;
28 /**
29 * @var string $type The product type ( plugin | theme ).
30 */
31 private $type;
32 /**
33 * @var string $file The file name.
34 */
35 private $file;
36 /**
37 * @var string $name The product name.
38 */
39 private $name;
40 /**
41 * @var string $key The product ready key.
42 */
43 private $key;
44 /**
45 * @var string $author_url The url of the author.
46 */
47 private $author_url;
48 /**
49 * @var string $store_url The store url.
50 */
51 private $store_url;
52 /**
53 * @var int $install The date of install.
54 */
55 private $install;
56 /**
57 * @var string $store_name The store name.
58 */
59 private $store_name;
60 /**
61 * @var array $allowed_authors The allowed authors.
62 */
63 private $allowed_authors = array( 'proteusthemes.com' );
64 /**
65 * @var bool $requires_license Either user needs to activate it with license.
66 */
67 private $requires_license;
68 /**
69 * @var bool $wordpress_available Either is available on WordPress or not.
70 */
71 private $wordpress_available;
72 /**
73 * @var string $version The product version.
74 */
75 private $version;
76 /**
77 * @var string $logger_option Logger option key.
78 */
79 public $logger_option;
80 /**
81 * @var string $pro_slug Pro slug, if available.
82 */
83 public $pro_slug;
84 /**
85 * @var string $feedback_types All the feedback types the product supports
86 */
87 private $feedback_types = array();
88
89 /**
90 * @var string $widget_types All the widget types the product supports
91 */
92 private $widget_types = array( 'dashboard_blog' );
93
94 /**
95 * ThemeIsle_SDK_Product constructor.
96 *
97 * @param string $basefile Product basefile.
98 */
99 public function __construct( $basefile ) {
100 if ( ! empty( $basefile ) ) {
101 if ( is_readable( $basefile ) ) {
102 $this->basefile = $basefile;
103 $this->setup_from_path();
104 $this->setup_from_fileheaders();
105 }
106 }
107 $install = get_option( $this->get_key() . '_install', 0 );
108 if ( $install === 0 ) {
109 $install = time();
110 update_option( $this->get_key() . '_install', time() );
111 }
112 $this->install = $install;
113
114 $this->logger_option = $this->get_key() . '_logger_flag';
115
116 }
117
118 /**
119 * Setup props from fileheaders.
120 */
121 public function setup_from_fileheaders() {
122 $file_headers = array(
123 'Requires License' => 'Requires License',
124 'WordPress Available' => 'WordPress Available',
125 'Pro Slug' => 'Pro Slug',
126 'Version' => 'Version',
127 );
128 if ( $this->type == 'plugin' ) {
129 $file_headers['Name'] = 'Plugin Name';
130 $file_headers['AuthorName'] = 'Author';
131 $file_headers['AuthorURI'] = 'Author URI';
132 }
133 if ( $this->type == 'theme' ) {
134 $file_headers['Name'] = 'Theme Name';
135 $file_headers['AuthorName'] = 'Author';
136 $file_headers['AuthorURI'] = 'Author URI';
137 }
138 $file_headers = get_file_data( $this->basefile, $file_headers );
139
140 $this->name = $file_headers['Name'];
141 $this->store_name = $file_headers['AuthorName'];
142 $this->author_url = $file_headers['AuthorURI'];
143 $this->store_url = $file_headers['AuthorURI'];
144 if ( $this->is_external_author() ) {
145 $this->store_url = 'https://themeisle.com';
146 $this->store_name = 'ThemeIsle';
147 }
148 $this->requires_license = ( $file_headers['Requires License'] == 'yes' ) ? true : false;
149 $this->wordpress_available = ( $file_headers['WordPress Available'] == 'yes' ) ? true : false;
150 $this->pro_slug = ! empty( $file_headers['Pro Slug'] ) ? $file_headers['Pro Slug'] : '';
151 $this->version = $file_headers['Version'];
152 if ( $this->require_uninstall_feedback() ) {
153 $this->feedback_types[] = 'deactivate';
154 }
155 if ( $this->is_wordpress_available() ) {
156 $this->feedback_types[] = 'review';
157 }
158 }
159
160 /**
161 * Check if the product is by external author or not.
162 *
163 * @return bool Either is external author or no.
164 */
165 public function is_external_author() {
166 foreach ( $this->allowed_authors as $author ) {
167 if ( strpos( $this->author_url, $author ) !== false ) {
168 return true;
169 }
170 }
171
172 return false;
173 }
174
175 /**
176 * The magic var_dump info method.
177 *
178 * @return array Debug info.
179 */
180 public function __debugInfo() {
181 return array(
182 'name' => $this->name,
183 'slug' => $this->slug,
184 'version' => $this->version,
185 'basefile' => $this->basefile,
186 'key' => $this->key,
187 'type' => $this->type,
188 'store_name' => $this->store_name,
189 'store_url' => $this->store_url,
190 'wordpress_available' => $this->wordpress_available,
191 'requires_license' => $this->requires_license,
192 );
193
194 }
195
196 /**
197 * Setup props from path.
198 */
199 public function setup_from_path() {
200 $this->file = basename( $this->basefile );
201 $dir = dirname( $this->basefile );
202 $this->slug = basename( $dir );
203 $exts = explode( '.', $this->basefile );
204 $ext = $exts[ count( $exts ) - 1 ];
205 if ( $ext == 'css' ) {
206 $this->type = 'theme';
207 }
208 if ( $ext == 'php' ) {
209 $this->type = 'plugin';
210 }
211 $this->key = self::key_ready_name( $this->slug );
212 }
213
214 /**
215 * @param string $string the String to be normalized for cron handler.
216 *
217 * @return string $name The normalized string.
218 */
219 static function key_ready_name( $string ) {
220 return str_replace( '-', '_', strtolower( trim( $string ) ) );
221 }
222
223 /**
224 * Getter for product name.
225 *
226 * @return string The product name.
227 */
228 public function get_name() {
229 return $this->name;
230 }
231
232 /**
233 * Getter for product version.
234 *
235 * @return string The product version.
236 */
237 public function get_version() {
238 return $this->version;
239 }
240
241 /**
242 * If product is available on wordpress.org or not.
243 *
244 * @return bool Either is wp available or not.
245 */
246 public function is_wordpress_available() {
247 return $this->wordpress_available;
248 }
249
250 /**
251 * Return the product key.
252 *
253 * @return string The product key.
254 */
255 public function get_key() {
256 return $this->key;
257 }
258
259 /**
260 * Either the product requires license or not.
261 *
262 * @return bool Either requires license or not.
263 */
264 public function requires_license() {
265 return $this->requires_license;
266 }
267
268 /**
269 * Check if the product is either theme or plugin.
270 *
271 * @return string Product type.
272 */
273 public function get_type() {
274 return $this->type;
275 }
276
277 /**
278 * Returns the Store name.
279 *
280 * @return string Store name.
281 */
282 public function get_store_name() {
283 return $this->store_name;
284 }
285
286 /**
287 * Returns the store url.
288 *
289 * @return string The store url.
290 */
291 public function get_store_url() {
292 return $this->store_url;
293 }
294
295 /**
296 * Returns the product slug.
297 *
298 * @return string The product slug.
299 */
300 public function get_slug() {
301 return $this->slug;
302 }
303
304 /**
305 * Returns product basefile, which holds the metaheaders.
306 *
307 * @return string The product basefile.
308 */
309 public function get_basefile() {
310 return $this->basefile;
311 }
312
313 /**
314 * Returns product filename.
315 *
316 * @return string The product filename.
317 */
318 public function get_file() {
319 return $this->file;
320 }
321
322 /**
323 * Returns feedback types
324 *
325 * @return array The feedback types.
326 */
327 public function get_feedback_types() {
328 return apply_filters( $this->get_key() . '_feedback_types', $this->feedback_types );
329 }
330
331 /**
332 * Returns widget types
333 *
334 * @return array The widget types.
335 */
336 public function get_widget_types() {
337 return apply_filters( $this->get_key() . '_widget_types', $this->widget_types );
338 }
339
340 /**
341 * We log the user website and product version.
342 *
343 * @return bool Either we log the data or not.
344 */
345 public function is_logger_active() {
346 // If is not available on WordPress log this automatically.
347 if ( ! $this->is_wordpress_available() ) {
348 return true;
349 } else {
350 $pro_slug = $this->get_pro_slug();
351 if ( ! empty( $pro_slug ) ) {
352
353 $all_products = ThemeIsle_SDK_Loader::get_products();
354 if ( isset( $all_products[ $pro_slug ] ) ) {
355 return true;
356 }
357 }
358
359 return ( get_option( $this->get_key() . '_logger_flag', 'no' ) === 'yes' );
360
361 }
362 }
363
364 /**
365 * Returns the pro slug, if available.
366 *
367 * @return string The pro slug.
368 */
369 public function get_pro_slug() {
370 return $this->pro_slug;
371 }
372
373 /**
374 * Return the install timestamp.
375 *
376 * @return int The install timestamp.
377 */
378 public function get_install_time() {
379 return $this->install;
380 }
381
382 /**
383 * We require feedback on uninstall.
384 *
385 * @return bool Either we should require feedback on uninstall or not.
386 */
387 public function require_uninstall_feedback() {
388 return $this->get_type() === 'plugin';
389 }
390
391 }
392 endif;
393