PluginProbe
WPIDE – File Manager & Code Editor / 3.4.1
WPIDE – File Manager & Code Editor v3.4.1
3.5.9 3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 All 55 releases
wpide / App / Classes / Freemius.php

Freemius.php in WPIDE – File Manager & Code Editor 3.4.1, at App/Classes/Freemius.php

189 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPIDE\App\Classes;
4
5 use WPIDE\App\App ;
6 use const WPIDE\Constants\ASSETS_DIR ;
7 use const WPIDE\Constants\ASSETS_URL ;
8 use const WPIDE\Constants\AUTHOR ;
9 use const WPIDE\Constants\DIR ;
10 use const WPIDE\Constants\FS_ID ;
11 use const WPIDE\Constants\FS_KEY ;
12 use const WPIDE\Constants\GTM_ID ;
13 use const WPIDE\Constants\NAME ;
14 use const WPIDE\Constants\SLUG ;
15 use const WPIDE\Constants\VERSION ;
16 class Freemius
17 {
18 public static $fs ;
19 public static $loaded = false ;
20 /**
21 * @throws \Freemius_Exception
22 */
23 public static function init()
24 {
25
26 if ( !isset( self::$fs ) ) {
27 // Init Freemius SDK.
28 require_once DIR . 'freemius/start.php';
29 self::$fs = fs_dynamic_init( array(
30 'id' => FS_ID,
31 'slug' => SLUG,
32 'premium_slug' => SLUG . '-pro',
33 'type' => 'plugin',
34 'public_key' => FS_KEY,
35 'is_premium' => false,
36 'premium_suffix' => 'Pro',
37 'has_addons' => false,
38 'has_paid_plans' => true,
39 'trial' => array(
40 'days' => 14,
41 'is_require_payment' => true,
42 ),
43 'menu' => array(
44 'slug' => SLUG,
45 ),
46 'is_live' => true,
47 ) );
48 $GLOBALS['wpide_fs'] = self::$fs;
49 self::$fs->add_action( 'connect/before', [ __CLASS__, 'beforeConnectBox' ] );
50 self::$fs->add_action( 'connect/after', [ __CLASS__, 'afterConnectBox' ] );
51 self::$fs->add_filter( 'checkout/purchaseCompleted', [ __CLASS__, 'afterPurchaseJs' ] );
52 self::$fs->add_filter( 'templates/checkout.php', [ __CLASS__, 'checkoutGtmScript' ] );
53 self::$fs->add_filter( 'freemius_pricing_js_path', [ __CLASS__, 'pricingJsPath' ] );
54 self::$fs->add_filter( 'plugin_icon', [ __CLASS__, 'pluginIcon' ] );
55 self::$fs->add_filter( 'hide_account_tabs', '__return_true' );
56 self::$fs->add_filter( 'hide_freemius_powered_by', '__return_true' );
57 self::$fs->add_filter( 'hide_billing_and_payments_info', '__return_true' );
58 add_action( 'admin_enqueue_scripts', [ __CLASS__, 'admin_enqueue_scripts' ] );
59 self::$loaded = true;
60 // Signal that SDK was initiated.
61 do_action( 'wpide_fs_loaded' );
62 }
63
64 }
65
66 public static function admin_enqueue_scripts()
67 {
68 if ( App::instance()->isFreemiusScreen() ) {
69 self::freemius_custom_styles();
70 }
71 }
72
73 public static function freemius_custom_styles()
74 {
75 wp_enqueue_style(
76 SLUG . '-fs-connect',
77 ASSETS_URL . 'css/freemius/freemius.css',
78 [],
79 VERSION
80 );
81 }
82
83 public static function beforeConnectBox()
84 {
85 wp_enqueue_style(
86 SLUG . '-fs-connect',
87 ASSETS_URL . 'css/freemius/freemius.css',
88 [],
89 VERSION
90 );
91 echo '<div id="fs-connect-wrap">' ;
92 }
93
94 public static function afterConnectBox()
95 {
96 echo '</div>' ;
97 }
98
99 public static function afterPurchaseJs() : string
100 {
101 return 'function ( data ) {
102
103 /**
104 * Since the user just entered their personal & billing information, agreed to the TOS & privacy,
105 * know they are running within a secure iframe from an external domain, they implicitly permit tracking
106 * this purchase. So initializing GTM here (after the purchase), is legitimate.
107 */
108
109 var is_subscription = typeof(data.purchase.initial_amount) !== "undefined";
110 var is_trial = typeof(data.purchase.trial_ends) !== "undefined" && data.purchase.trial_ends !== null;
111 var total = is_subscription ? data.purchase.initial_amount : data.purchase.gross;
112 total = is_trial ? 0 : total;
113
114 var coupon = data && data.coupon ? data.coupon.code : "";
115 var currency = data && data.currency ? data.currency.toUpperCase() : "USD";
116
117 var item = {
118 item_name: "' . NAME . '",
119 item_id: ' . FS_ID . ',
120 item_brand: "' . AUTHOR . '",
121 affiliation: "' . AUTHOR . '",
122 price: data.total,
123 discount: 0,
124 currency: currency,
125 coupon: coupon,
126 index: 1,
127 quantity: 1
128 };
129
130 // Purchase Event
131 dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object.
132 dataLayer.push({
133 event: "purchase",
134 ecommerce: {
135 transaction_id: data.purchase.id,
136 affiliation: item.affiliation,
137 tax: 0,
138 shipping: 0,
139 items: [item],
140 currency: item.currency,
141 coupon: item.coupon,
142 value: total
143 }
144 });
145 }';
146 }
147
148 public static function checkoutGtmScript( $html ) : string
149 {
150 return "\n <script>window.dataLayer = window.dataLayer || [];</script>\n <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n })(window,document,'script','dataLayer', '" . GTM_ID . "');</script>\n " . $html;
151 }
152
153 public static function pricingJsPath() : string
154 {
155 return ASSETS_DIR . 'pricing/freemius-pricing.js';
156 }
157
158 public static function pluginIcon() : string
159 {
160 return ASSETS_DIR . 'img/icon.png';
161 }
162
163 /**
164 * Add license dialog boxes
165 *
166 * @since 1.0.0
167 */
168 public static function addLicenseActivationDialogBox()
169 {
170
171 if ( !did_action( SLUG . '_license_activation_dialog_added' ) && !App::instance()->isFreemiusScreen( 'account' ) ) {
172 self::sdk()->_add_license_activation_dialog_box();
173 fs_enqueue_local_style( 'fs_dialog_boxes', '/admin/dialog-boxes.css' );
174 do_action( SLUG . '_license_activation_dialog_added' );
175 }
176
177 }
178
179 public static function sdk()
180 {
181 return self::$fs;
182 }
183
184 public static function loaded()
185 {
186 return self::$loaded;
187 }
188
189 }