PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.11.14
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.11.14
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
← All changes | vendor/codeinwp/themeisle-sdk/src/Product.php +118 -4 3.1.33.11.14 View file →
@@ -70,8 +70,14 @@
70 70 * @var string $key The product ready key.
71 71 */
72 72 private $key;
73 73 /**
74 + * Author URL
75 + *
76 + * @var string $author_url The author url.
77 + */
78 + private $author_url;
79 + /**
74 80 * Product store url.
75 81 *
76 82 * @var string $store_url The store url.
77 83 */
@@ -105,8 +111,18 @@
105 111 *
106 112 * @var string $version The product version.
107 113 */
108 114 private $version;
115 + /**
116 + * Holds a map of loaded products objects.
117 + *
118 + * @var array Array of loaded products.
119 + */
120 + private static $cached_products = [];
121 + /**
122 + * Root api endpoint.
123 + */
124 + const API_URL = 'https://api.themeisle.com/';
109 125
110 126 /**
111 127 * ThemeIsle_SDK_Product constructor.
112 128 *
@@ -113,9 +129,9 @@
113 129 * @param string $basefile Product basefile.
114 130 */
115 131 public function __construct( $basefile ) {
116 132 if ( ! empty( $basefile ) ) {
117 - if ( is_readable( $basefile ) ) {
133 + if ( is_file( $basefile ) ) {
118 134 $this->basefile = $basefile;
119 135 $this->setup_from_path();
120 136 $this->setup_from_fileheaders();
121 137 }
@@ -122,15 +138,58 @@
122 138 }
123 139 $install = get_option( $this->get_key() . '_install', 0 );
124 140 if ( 0 === $install ) {
125 141 $install = time();
142 + /**
143 + * Action to be triggered when the product is first activated.
144 + *
145 + * @param string $basefile The basefile of the product.
146 + */
147 + do_action( 'themeisle_sdk_first_activation', $basefile );
148 +
126 149 update_option( $this->get_key() . '_install', time() );
127 150 }
128 - $this->install = $install;
151 + $this->install = $install;
152 + self::$cached_products[ crc32( $basefile ) ] = $this;
153 + $current_version = get_option( $this->slug . '_version', '' );
129 154
155 + if ( $current_version !== $this->version && wp_cache_get( "{$this->slug}_version_upgrade" ) === false ) {
156 + // Set the cache lock to avoid multiple calls.
157 + wp_cache_set( "{$this->slug}_version_upgrade", true, HOUR_IN_SECONDS );
158 + /**
159 + * Action to be triggered when the product is updated.
160 + *
161 + * @param string $current_version The current version of the product.
162 + * @param string $new_version The new version of the product.
163 + * @param string $basefile The basefile of the product.
164 + */
165 + do_action( "themeisle_sdk_update_{$this->slug}", $current_version, $this->version, $basefile );
166 +
167 + // Update the version of the product.
168 + update_option( "{$this->slug}_version", $this->version );
169 + // Delete the cache lock.
170 + wp_cache_delete( "{$this->slug}_version_upgrade" );
171 + }
130 172 }
131 173
132 174 /**
175 + * Return a product.
176 + *
177 + * @param string $basefile Product basefile.
178 + *
179 + * @return Product Product Object.
180 + */
181 + public static function get( $basefile ) {
182 + $key = crc32( $basefile );
183 + if ( isset( self::$cached_products[ $key ] ) ) {
184 + return self::$cached_products[ $key ];
185 + }
186 + self::$cached_products[ $key ] = new Product( $basefile );
187 +
188 + return self::$cached_products[ $key ];
189 + }
190 +
191 + /**
133 192 * Setup props from path.
134 193 */
135 194 public function setup_from_path() {
136 195 $this->file = basename( $this->basefile );
@@ -153,9 +212,9 @@
153 212 * @param string $string the String to be normalized for cron handler.
154 213 *
155 214 * @return string $name The normalized string.
156 215 */
157 - static function key_ready_name( $string ) {
216 + public static function key_ready_name( $string ) {
158 217 return str_replace( '-', '_', strtolower( trim( $string ) ) );
159 218 }
160 219
161 220 /**
@@ -199,8 +258,9 @@
199 258 */
200 259 public function get_key() {
201 260 return $this->key;
202 261 }
262 +
203 263 /**
204 264 * Check if the product is either theme or plugin.
205 265 *
206 266 * @return string Product type.
@@ -311,9 +371,19 @@
311 371 *
312 372 * @return string Friendly name.
313 373 */
314 374 public function get_friendly_name() {
315 - $name = apply_filters( $this->get_key() . '_friendly_name', trim( str_replace( 'Lite', '', $this->get_name() ) ) );
375 + $name = trim( str_replace( 'Lite', '', $this->get_name() ) );
376 + if ( defined( 'OTTER_BLOCKS_BASEFILE' ) && OTTER_BLOCKS_BASEFILE === $this->basefile ) {
377 + $name = 'Otter Blocks';
378 + }
379 + if ( defined( 'OPTML_BASEFILE' ) && OPTML_BASEFILE === $this->basefile ) {
380 + $name = 'Optimole';
381 + }
382 + if ( defined( 'WPMM_FILE' ) && WPMM_FILE === $this->basefile ) {
383 + $name = 'LightStart';
384 + }
385 + $name = apply_filters( $this->get_key() . '_friendly_name', $name );
316 386 $name = rtrim( $name, '- ()' );
317 387
318 388 return $name;
319 389 }
@@ -318,8 +388,17 @@
318 388 return $name;
319 389 }
320 390
321 391 /**
392 + * Return the product version cache key.
393 + *
394 + * @return string The product version cache key.
395 + */
396 + public function get_cache_key() {
397 + return $this->get_key() . '_' . preg_replace( '/[^0-9a-zA-Z ]/m', '', $this->get_version() ) . 'versions';
398 + }
399 +
400 + /**
322 401 * Getter for product name.
323 402 *
324 403 * @return string The product name.
325 404 */
@@ -341,8 +420,13 @@
341 420 *
342 421 * @return string The store url.
343 422 */
344 423 public function get_store_url() {
424 +
425 + if ( strpos( $this->store_url, '/themeisle.com' ) !== false ) {
426 + return 'https://store.themeisle.com/';
427 + }
428 +
345 429 return $this->store_url;
346 430 }
347 431
348 432 /**
@@ -354,8 +438,24 @@
354 438 return $this->basefile;
355 439 }
356 440
357 441 /**
442 + * Get changelog url.
443 + *
444 + * @return string Changelog url.
445 + */
446 + public function get_changelog() {
447 + return add_query_arg(
448 + [
449 + 'name' => rawurlencode( $this->get_name() ),
450 + 'edd_action' => 'view_changelog',
451 + 'locale' => get_user_locale(),
452 + ],
453 + $this->get_store_url()
454 + );
455 + }
456 +
457 + /**
358 458 * Returns product filename.
359 459 *
360 460 * @return string The product filename.
361 461 */
@@ -361,8 +461,9 @@
361 461 */
362 462 public function get_file() {
363 463 return $this->file;
364 464 }
465 +
365 466 /**
366 467 * Returns the pro slug, if available.
367 468 *
368 469 * @return string The pro slug.
@@ -377,7 +478,20 @@
377 478 * @return int The install timestamp.
378 479 */
379 480 public function get_install_time() {
380 481 return $this->install;
482 + }
483 +
484 + /**
485 + * Returns the URL of the product base file.
486 + *
487 + * @param string $path The path to the file.
488 + *
489 + * @return string The URL of the product base file.
490 + */
491 + public function get_base_url( $path = '/' ) {
492 + if ( $this->type ) {
493 + return plugins_url( $path, $this->basefile );
494 + }
381 495 }
382 496
383 497 }