| @@ -1,0 +1,203 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Extension Factory | |
| 4 | + * | |
| 5 | + * @package NotificationX\Extensions | |
| 6 | + */ | |
| 7 | + | |
| 8 | +namespace NotificationX\Extensions; | |
| 9 | + | |
| 10 | +use Exception; | |
| 11 | +use NotificationX\Core\Database; | |
| 12 | +use NotificationX\GetInstance; | |
| 13 | +use NotificationX\Core\Modules; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * ExtensionFactory Class | |
| 17 | + * | |
| 18 | + * @method static ExtensionFactory get_instance($args = null) | |
| 19 | + */ | |
| 20 | +class ExtensionFactory { | |
| 21 | + /** | |
| 22 | + * Instance of Admin | |
| 23 | + * | |
| 24 | + * @var Admin | |
| 25 | + */ | |
| 26 | + use GetInstance; | |
| 27 | + | |
| 28 | + public $active_items; | |
| 29 | + public $types = []; | |
| 30 | + public $extensions = []; | |
| 31 | + public $extension_classes = [ | |
| 32 | + 'woo_inline' => 'NotificationX\Extensions\WooCommerce\WooInline', | |
| 33 | + 'edd_inline' => 'NotificationX\Extensions\EDD\EDDInline', | |
| 34 | + 'tutor_inline' => 'NotificationX\Extensions\Tutor\TutorInline', | |
| 35 | + 'learndash_inline' => 'NotificationX\Extensions\LearnDash\LearnDashInline', | |
| 36 | + 'learnpress_inline' => 'NotificationX\Extensions\LearnPress\LearnPressInline', | |
| 37 | + 'cf7' => 'NotificationX\Extensions\CF7\CF7', | |
| 38 | + 'convertkit' => 'NotificationX\Extensions\ConvertKit\ConvertKit', | |
| 39 | + 'custom_notification' => 'NotificationX\Extensions\CustomNotification\CustomNotification', | |
| 40 | + 'custom_notification_conversions' => 'NotificationX\Extensions\CustomNotification\CustomNotificationConversions', | |
| 41 | + 'announcements' => 'NotificationX\Extensions\OfferAnnouncement\Announcements', | |
| 42 | + 'edd' => 'NotificationX\Extensions\EDD\EDD', | |
| 43 | + 'envato' => 'NotificationX\Extensions\Envato\Envato', | |
| 44 | + 'freemius_conversions' => 'NotificationX\Extensions\Freemius\FreemiusConversions', | |
| 45 | + 'freemius_reviews' => 'NotificationX\Extensions\Freemius\FreemiusReviews', | |
| 46 | + 'freemius_stats' => 'NotificationX\Extensions\Freemius\FreemiusStats', | |
| 47 | + 'grvf' => 'NotificationX\Extensions\GRVF\GravityForms', | |
| 48 | + 'give' => 'NotificationX\Extensions\Give\Give', | |
| 49 | + 'google' => 'NotificationX\Extensions\Google_Analytics\Google_Analytics', | |
| 50 | + 'google_reviews' => 'NotificationX\Extensions\Google\GoogleReviews', | |
| 51 | + 'learndash' => 'NotificationX\Extensions\LearnDash\LearnDash', | |
| 52 | + 'learnpress' => 'NotificationX\Extensions\LearnPress\LearnPress', | |
| 53 | + 'mailchimp' => 'NotificationX\Extensions\MailChimp\MailChimp', | |
| 54 | + 'njf' => 'NotificationX\Extensions\NJF\NinjaForms', | |
| 55 | + 'press_bar' => 'NotificationX\Extensions\PressBar\PressBar', | |
| 56 | + 'tutor' => 'NotificationX\Extensions\Tutor\Tutor', | |
| 57 | + 'wpf' => 'NotificationX\Extensions\WPF\WPForms', | |
| 58 | + 'reviewx' => 'NotificationX\Extensions\ReviewX\ReviewX', | |
| 59 | + 'woocommerce' => 'NotificationX\Extensions\WooCommerce\WooCommerce', | |
| 60 | + 'woocommerce_sales' => 'NotificationX\Extensions\WooCommerce\WooCommerceSales', | |
| 61 | + 'woocommerce_cart_peek' => 'NotificationX\Extensions\WooCommerce\WooCommerceCartPeek', | |
| 62 | + 'woocommerce_sales_reviews' => 'NotificationX\Extensions\WooCommerce\WooCommerceSalesReviews', | |
| 63 | + 'woocommerce_sales_inline' => 'NotificationX\Extensions\WooCommerce\WooCommerceSalesInline', | |
| 64 | + 'woo_reviews' => 'NotificationX\Extensions\WooCommerce\WooReviews', | |
| 65 | + 'wp_comments' => 'NotificationX\Extensions\WordPress\WPComments', | |
| 66 | + 'wp_reviews' => 'NotificationX\Extensions\WordPress\WPOrgReview', | |
| 67 | + 'wp_stats' => 'NotificationX\Extensions\WordPress\WPOrgStats', | |
| 68 | + 'zapier_conversions' => 'NotificationX\Extensions\Zapier\ZapierConversions', | |
| 69 | + 'zapier_email_subscription' => 'NotificationX\Extensions\Zapier\ZapierEmailSubscription', | |
| 70 | + 'zapier_reviews' => 'NotificationX\Extensions\Zapier\ZapierReviews', | |
| 71 | + 'exit_intent_custom' => 'NotificationX\Extensions\ExitIntent\ExitIntentNotification', | |
| 72 | + 'elementor_form' => 'NotificationX\Extensions\Elementor\From', | |
| 73 | + 'flashing_tab' => 'NotificationX\Extensions\FlashingTab\FlashingTab', | |
| 74 | + 'fluentform' => 'NotificationX\Extensions\FluentForm\FluentForm', | |
| 75 | + 'youtube' => 'NotificationX\Extensions\Google\YouTube', | |
| 76 | + 'vimeo' => 'NotificationX\Extensions\Vimeo\Vimeo', | |
| 77 | + 'wistia' => 'NotificationX\Extensions\Wistia\Wistia', | |
| 78 | + 'surecart' => 'NotificationX\Extensions\SureCart\SureCart', | |
| 79 | + 'ActiveCampaign' => 'NotificationX\Extensions\ActiveCampaign\ActiveCampaign', | |
| 80 | + 'brevo' => 'NotificationX\Extensions\Brevo\Brevo', | |
| 81 | + 'popup_notification' => 'NotificationX\Extensions\Popup\PopupNotification', | |
| 82 | + 'fluentcart' => 'NotificationX\Extensions\FluentCart\FluentCart', | |
| 83 | + 'fluentcart_inline' => 'NotificationX\Extensions\FluentCart\FluentCartInline', | |
| 84 | + 'gdpr_notification' => 'NotificationX\Extensions\GDPR\GDPR_Notification', | |
| 85 | + 'ccpa_notification' => 'NotificationX\Extensions\CCPA\CCPA_Notification', | |
| 86 | + 'bitintegrations_conversions' => 'NotificationX\Extensions\BitIntegrations\BitIntegrationsConversions', | |
| 87 | + 'bitintegrations_email_subscription' => 'NotificationX\Extensions\BitIntegrations\BitIntegrationsEmailSubscription', | |
| 88 | + 'bitintegrations_reviews' => 'NotificationX\Extensions\BitIntegrations\BitIntegrtionsReviews', | |
| 89 | + ]; | |
| 90 | + | |
| 91 | + /** | |
| 92 | + * Initially Invoked when initialized. | |
| 93 | + */ | |
| 94 | + public function __construct(){ | |
| 95 | + // GlobalFields::get_instance(); | |
| 96 | + $this->register_extensions(); | |
| 97 | + } | |
| 98 | + | |
| 99 | + public function register_extensions(){ | |
| 100 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Reviewed for the NotificationX codebase: acceptable in this context. | |
| 101 | + $this->extension_classes = apply_filters( 'nx_extension_classes', $this->extension_classes ); | |
| 102 | + foreach ($this->extension_classes as $extension) { | |
| 103 | + // initializing extension. | |
| 104 | + if(class_exists($extension)){ | |
| 105 | + $obj = $extension::get_instance(); | |
| 106 | + if(Modules::get_instance()->is_enabled($obj->module)){ | |
| 107 | + $this->add($obj); | |
| 108 | + } | |
| 109 | + } | |
| 110 | + } | |
| 111 | + } | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * This function is responsible for adding an extension to the extensions array! | |
| 115 | + * | |
| 116 | + * @param array $extensions | |
| 117 | + * @param string $classname | |
| 118 | + * @return void | |
| 119 | + */ | |
| 120 | + protected function add( $extension) { | |
| 121 | + $this->extensions[ $extension->id ] = $extension; | |
| 122 | + $this->types[$extension->types][ $extension->id ] = $extension; | |
| 123 | + return $this->extensions; | |
| 124 | + } | |
| 125 | + | |
| 126 | + /** | |
| 127 | + * Get Extensions data | |
| 128 | + * | |
| 129 | + * @param Extension $extension The notifications type. | |
| 130 | + * @param array $args Settings arguments for notificationx. | |
| 131 | + * @return array | |
| 132 | + */ | |
| 133 | + public static function getExtension( Extension $extension, $args = array() ){ | |
| 134 | + return $extension->get_data( $args ); | |
| 135 | + } | |
| 136 | + | |
| 137 | + /** | |
| 138 | + * This function is responsible for getting the extension from loaded extension. | |
| 139 | + * | |
| 140 | + * @param string $key | |
| 141 | + * @return Extension | |
| 142 | + */ | |
| 143 | + public function get( $key ){ | |
| 144 | + if( empty( $key ) ) { | |
| 145 | + return false; | |
| 146 | + } | |
| 147 | + try { | |
| 148 | + $class = $this->extension_classes[$key]; | |
| 149 | + if(class_exists($class)){ | |
| 150 | + return $class::get_instance(); | |
| 151 | + } | |
| 152 | + } | |
| 153 | + catch (\Exception $e) { | |
| 154 | + | |
| 155 | + } | |
| 156 | + return isset( $this->extensions[ $key ] ) ? $this->extensions[ $key ] : false; | |
| 157 | + } | |
| 158 | + | |
| 159 | + /** | |
| 160 | + * This function is responsible for getting the extension from loaded extension. | |
| 161 | + * | |
| 162 | + * @param string $key | |
| 163 | + * @return array|bool | |
| 164 | + */ | |
| 165 | + public function get_type( $type ){ | |
| 166 | + if( empty( $type ) ) { | |
| 167 | + return false; | |
| 168 | + } | |
| 169 | + return isset( $this->types[ $type ] ) ? $this->types[ $type ] : false; | |
| 170 | + } | |
| 171 | + | |
| 172 | + /** | |
| 173 | + * This function is responsible for getting the extension from loaded extension. | |
| 174 | + * | |
| 175 | + * @param string $key | |
| 176 | + * @return array | |
| 177 | + */ | |
| 178 | + public function get_themes_for_type( $type ){ | |
| 179 | + $themes = []; | |
| 180 | + | |
| 181 | + $extensions = $this->get_type($type); | |
| 182 | + | |
| 183 | + if(is_array($extensions)){ | |
| 184 | + foreach($extensions as $extension){ | |
| 185 | + if(!$extension->exclude_custom_themes){ | |
| 186 | + $themes = array_merge($themes, $extension->get_themes_name()); | |
| 187 | + } | |
| 188 | + } | |
| 189 | + } | |
| 190 | + | |
| 191 | + return array_unique($themes); | |
| 192 | + } | |
| 193 | + | |
| 194 | + /** | |
| 195 | + * This function is responsible for getting the extension from loaded extension. | |
| 196 | + * | |
| 197 | + * @param string $key | |
| 198 | + * @return bool|void | |
| 199 | + */ | |
| 200 | + public function get_all(){ | |
| 201 | + return $this->extensions; | |
| 202 | + } | |
| 203 | +} | |