| 1 |
<?php |
| 2 |
/** |
| 3 |
* The main loader class for ThemeIsle SDK |
| 4 |
* |
| 5 |
* @package ThemeIsleSDK |
| 6 |
* @subpackage Loader |
| 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_Loader' ) ) : |
| 16 |
/** |
| 17 |
* Singleton loader for ThemeIsle SDK. |
| 18 |
*/ |
| 19 |
final class ThemeIsle_SDK_Loader { |
| 20 |
/** |
| 21 |
* @var ThemeIsle_SDK_Loader instance The singleton instance |
| 22 |
*/ |
| 23 |
private static $instance; |
| 24 |
/** |
| 25 |
* @var string $version The class version. |
| 26 |
*/ |
| 27 |
private static $version = '1.0.0'; |
| 28 |
/** |
| 29 |
* @var array The products which use the SDK. |
| 30 |
*/ |
| 31 |
private static $products; |
| 32 |
|
| 33 |
/** |
| 34 |
* Register product into SDK. |
| 35 |
* |
| 36 |
* @param string $basefile The product basefile. |
| 37 |
* |
| 38 |
* @return ThemeIsle_SDK_Loader The singleton object. |
| 39 |
*/ |
| 40 |
public static function init_product( $basefile ) { |
| 41 |
|
| 42 |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof ThemeIsle_SDK_Loader ) ) { |
| 43 |
self::$instance = new ThemeIsle_SDK_Loader; |
| 44 |
|
| 45 |
} |
| 46 |
$product_object = new ThemeIsle_SDK_Product( $basefile ); |
| 47 |
self::$products[ $product_object->get_slug() ] = $product_object; |
| 48 |
|
| 49 |
$notifications = array(); |
| 50 |
// Based on the WordPress Available file header we enable the logger or not. |
| 51 |
if ( ! $product_object->is_wordpress_available() ) { |
| 52 |
$licenser = new ThemeIsle_SDK_Licenser( $product_object ); |
| 53 |
$licenser->enable(); |
| 54 |
} |
| 55 |
|
| 56 |
$logger = new ThemeIsle_SDK_Logger( $product_object ); |
| 57 |
if ( $product_object->is_logger_active() ) { |
| 58 |
$logger->enable(); |
| 59 |
} else { |
| 60 |
$notifications[] = $logger; |
| 61 |
} |
| 62 |
|
| 63 |
$feedback = new ThemeIsle_SDK_Feedback_Factory( $product_object, $product_object->get_feedback_types() ); |
| 64 |
|
| 65 |
$instances = $feedback->get_instances(); |
| 66 |
if ( array_key_exists( 'review', $instances ) ) { |
| 67 |
$notifications[] = $instances['review']; |
| 68 |
} |
| 69 |
if ( array_key_exists( 'translate', $instances ) ) { |
| 70 |
$notifications[] = $instances['translate']; |
| 71 |
} |
| 72 |
new ThemeIsle_SDK_Notification_Manager( $product_object, $notifications ); |
| 73 |
if ( ! $product_object->is_external_author() ) { |
| 74 |
new ThemeIsle_SDK_Widgets_Factory( $product_object, $product_object->get_widget_types() ); |
| 75 |
} |
| 76 |
if ( ! $product_object->is_external_author() ) { |
| 77 |
new ThemeIsle_SDK_Rollback( $product_object ); |
| 78 |
} |
| 79 |
return self::$instance; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Get all products using the SDK. |
| 84 |
* |
| 85 |
* @return array Products available. |
| 86 |
*/ |
| 87 |
public static function get_products() { |
| 88 |
return self::$products; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
} |
| 93 |
endif; |
| 94 |
|