PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 2.1.6
Visualizer – Tables & Charts Manager with Built-in AI Generator v2.1.6
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.6, at vendor/codeinwp/themeisle-sdk/class-themeisle-sdk-product.php

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