PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.9.2
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.9.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
← All changes | vendor/codeinwp/themeisle-sdk/src/Product.php +74 -3 3.1.33.9.2 View file →
@@ -105,8 +105,18 @@
105 105 *
106 106 * @var string $version The product version.
107 107 */
108 108 private $version;
109 + /**
110 + * Holds a map of loaded products objects.
111 + *
112 + * @var array Array of loaded products.
113 + */
114 + private static $cached_products = [];
115 + /**
116 + * Root api endpoint.
117 + */
118 + const API_URL = 'https://api.themeisle.com/';
109 119
110 120 /**
111 121 * ThemeIsle_SDK_Product constructor.
112 122 *
@@ -113,9 +123,9 @@
113 123 * @param string $basefile Product basefile.
114 124 */
115 125 public function __construct( $basefile ) {
116 126 if ( ! empty( $basefile ) ) {
117 - if ( is_readable( $basefile ) ) {
127 + if ( is_file( $basefile ) ) {
118 128 $this->basefile = $basefile;
119 129 $this->setup_from_path();
120 130 $this->setup_from_fileheaders();
121 131 }
@@ -124,10 +134,27 @@
124 134 if ( 0 === $install ) {
125 135 $install = time();
126 136 update_option( $this->get_key() . '_install', time() );
127 137 }
128 - $this->install = $install;
138 + $this->install = $install;
139 + self::$cached_products[ crc32( $basefile ) ] = $this;
140 + }
129 141
142 + /**
143 + * Return a product.
144 + *
145 + * @param string $basefile Product basefile.
146 + *
147 + * @return Product Product Object.
148 + */
149 + public static function get( $basefile ) {
150 + $key = crc32( $basefile );
151 + if ( isset( self::$cached_products[ $key ] ) ) {
152 + return self::$cached_products[ $key ];
153 + }
154 + self::$cached_products[ $key ] = new Product( $basefile );
155 +
156 + return self::$cached_products[ $key ];
130 157 }
131 158
132 159 /**
133 160 * Setup props from path.
@@ -153,9 +180,9 @@
153 180 * @param string $string the String to be normalized for cron handler.
154 181 *
155 182 * @return string $name The normalized string.
156 183 */
157 - static function key_ready_name( $string ) {
184 + public static function key_ready_name( $string ) {
158 185 return str_replace( '-', '_', strtolower( trim( $string ) ) );
159 186 }
160 187
161 188 /**
@@ -199,8 +226,9 @@
199 226 */
200 227 public function get_key() {
201 228 return $this->key;
202 229 }
230 +
203 231 /**
204 232 * Check if the product is either theme or plugin.
205 233 *
206 234 * @return string Product type.
@@ -318,8 +346,17 @@
318 346 return $name;
319 347 }
320 348
321 349 /**
350 + * Return the product version cache key.
351 + *
352 + * @return string The product version cache key.
353 + */
354 + public function get_cache_key() {
355 + return $this->get_key() . '_' . preg_replace( '/[^0-9a-zA-Z ]/m', '', $this->get_version() ) . 'versions';
356 + }
357 +
358 + /**
322 359 * Getter for product name.
323 360 *
324 361 * @return string The product name.
325 362 */
@@ -341,8 +378,13 @@
341 378 *
342 379 * @return string The store url.
343 380 */
344 381 public function get_store_url() {
382 +
383 + if ( strpos( $this->store_url, '/themeisle.com' ) !== false ) {
384 + return 'https://store.themeisle.com/';
385 + }
386 +
345 387 return $this->store_url;
346 388 }
347 389
348 390 /**
@@ -354,8 +396,23 @@
354 396 return $this->basefile;
355 397 }
356 398
357 399 /**
400 + * Get changelog url.
401 + *
402 + * @return string Changelog url.
403 + */
404 + public function get_changelog() {
405 + return add_query_arg(
406 + [
407 + 'name' => rawurlencode( $this->get_name() ),
408 + 'edd_action' => 'view_changelog',
409 + ],
410 + $this->get_store_url()
411 + );
412 + }
413 +
414 + /**
358 415 * Returns product filename.
359 416 *
360 417 * @return string The product filename.
361 418 */
@@ -361,8 +418,9 @@
361 418 */
362 419 public function get_file() {
363 420 return $this->file;
364 421 }
422 +
365 423 /**
366 424 * Returns the pro slug, if available.
367 425 *
368 426 * @return string The pro slug.
@@ -377,7 +435,20 @@
377 435 * @return int The install timestamp.
378 436 */
379 437 public function get_install_time() {
380 438 return $this->install;
439 + }
440 +
441 + /**
442 + * Returns the URL of the product base file.
443 + *
444 + * @param string $path The path to the file.
445 + *
446 + * @return string The URL of the product base file.
447 + */
448 + public function get_base_url( $path = '/' ) {
449 + if ( $this->type ) {
450 + return plugins_url( $path, $this->basefile );
451 + }
381 452 }
382 453
383 454 }