PluginProbe
BlockSpare – Gutenberg Blocks, AI Content Generator & Site Builder for News, Magazine & Blogs / 2.6.6
BlockSpare – Gutenberg Blocks, AI Content Generator & Site Builder for News, Magazine & Blogs v2.6.6
5.0.1 4.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.1.2 2.5.0 2.5.3 All 39 releases
← All changes | freemius/templates/checkout.php +326 -15 5.0.1 → 2.6.6 View file →
@@ -1,29 +1,340 @@
1 1 <?php
2 2 /**
3 3 * @package Freemius
4 - * @copyright Copyright (c) 2024, Freemius, Inc.
4 + * @copyright Copyright (c) 2015, Freemius, Inc.
5 5 * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6 - * @since 2.9.0
6 + * @since 1.0.3
7 7 */
8 - if ( ! defined( 'ABSPATH' ) ) {
9 - exit;
10 - }
8 +
11 9 /**
10 + * Note for WordPress.org Theme/Plugin reviewer:
11 + * Freemius is an SDK for plugin and theme developers. Since the core
12 + * of the SDK is relevant both for plugins and themes, for obvious reasons,
13 + * we only develop and maintain one code base.
14 + *
15 + * This code (and page) will not run for wp.org themes (only plugins).
16 + *
17 + * In addition, this page loads an i-frame. We intentionally named it 'frame'
18 + * so it will pass the "Theme Check" that is looking for the string "i" . "frame".
19 + *
20 + * UPDATE:
21 + * After ongoing conversations with the WordPress.org TRT we received
22 + * an official approval for including i-frames in the theme's WP Admin setting's
23 + * page tab (the SDK will never add any i-frames on the sitefront). i-frames
24 + * were never against the guidelines, but we wanted to get the team's blessings
25 + * before we move forward. For the record, I got the final approval from
26 + * Ulrich Pogson (@grapplerulrich), a team lead at the TRT during WordCamp
27 + * Europe 2017 (June 16th, 2017).
28 + *
29 + * If you have any questions or need clarifications, please don't hesitate
30 + * pinging me on slack, my username is @svovaf.
31 + *
32 + * @author Vova Feldman (@svovaf)
33 + * @since 1.2.2
34 + */
35 +
36 + if ( ! defined( 'ABSPATH' ) ) {
37 + exit;
38 + }
39 +
40 + wp_enqueue_script( 'jquery' );
41 + wp_enqueue_script( 'json2' );
42 + fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
43 + fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
44 + fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
45 +
46 + fs_enqueue_local_style( 'fs_checkout', '/admin/checkout.css' );
47 +
48 + /**
12 49 * @var array $VARS
13 50 * @var Freemius $fs
14 51 */
15 - $fs = freemius( $VARS['id'] );
52 + $fs = freemius( $VARS['id'] );
53 + $slug = $fs->get_slug();
16 54
17 - if ( fs_request_get_bool( 'redirect' ) ) {
18 - fs_require_template( 'checkout/redirect.php', $VARS );
19 - } else if ( fs_request_get_bool( 'process_redirect' ) ) {
20 - fs_require_template( 'checkout/process-redirect.php', $VARS );
55 + $timestamp = time();
56 +
57 + $context_params = array(
58 + 'plugin_id' => $fs->get_id(),
59 + 'public_key' => $fs->get_public_key(),
60 + 'plugin_version' => $fs->get_plugin_version(),
61 + 'mode' => 'dashboard',
62 + 'trial' => fs_request_get_bool( 'trial' ),
63 + 'is_ms' => ( fs_is_network_admin() && $fs->is_network_active() ),
64 + );
65 +
66 + $plan_id = fs_request_get( 'plan_id' );
67 + if ( FS_Plugin_Plan::is_valid_id( $plan_id ) ) {
68 + $context_params['plan_id'] = $plan_id;
69 + }
70 +
71 + $licenses = fs_request_get( 'licenses' );
72 + if ( $licenses === strval( intval( $licenses ) ) && $licenses > 0 ) {
73 + $context_params['licenses'] = $licenses;
74 + }
75 +
76 + $plugin_id = fs_request_get( 'plugin_id' );
77 + if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
78 + $plugin_id = $fs->get_id();
79 + }
80 +
81 + if ( $plugin_id == $fs->get_id() ) {
82 + $is_premium = $fs->is_premium();
83 +
84 + $bundle_id = $fs->get_bundle_id();
85 + if ( ! is_null( $bundle_id ) ) {
86 + $context_params['bundle_id'] = $bundle_id;
87 + }
88 + } else {
89 + // Identify the module code version of the checkout context module.
90 + if ( $fs->is_addon_activated( $plugin_id ) ) {
91 + $fs_addon = Freemius::get_instance_by_id( $plugin_id );
92 + $is_premium = $fs_addon->is_premium();
93 + } else {
94 + // If add-on isn't activated assume the premium version isn't installed.
95 + $is_premium = false;
96 + }
97 + }
98 +
99 + // Get site context secure params.
100 + if ( $fs->is_registered() ) {
101 + $site = $fs->get_site();
102 +
103 + if ( $plugin_id != $fs->get_id() ) {
104 + if ( $fs->is_addon_activated( $plugin_id ) ) {
105 + $fs_addon = Freemius::get_instance_by_id( $plugin_id );
106 + $addon_site = $fs_addon->get_site();
107 + if ( is_object( $addon_site ) ) {
108 + $site = $addon_site;
109 + }
110 + }
111 + }
112 +
113 + $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
114 + $site,
115 + $timestamp,
116 + 'checkout'
117 + ) );
21 118 } else {
22 - $fs = freemius( $VARS['id'] );
119 + $current_user = Freemius::_get_current_wp_user();
23 120
24 - if ( $fs->is_premium() ) {
25 - fs_require_template( 'checkout/frame.php', $VARS );
26 - } else {
27 - fs_require_template( 'checkout/redirect.php', $VARS );
121 + // Add site and user info to the request, this information
122 + // is NOT being stored unless the user complete the purchase
123 + // and agrees to the TOS.
124 + $context_params = array_merge( $context_params, array(
125 + 'user_firstname' => $current_user->user_firstname,
126 + 'user_lastname' => $current_user->user_lastname,
127 + 'user_email' => $current_user->user_email,
128 + 'home_url' => home_url(),
129 + ) );
130 +
131 + $fs_user = Freemius::_get_user_by_email( $current_user->user_email );
132 +
133 + if ( is_object( $fs_user ) && $fs_user->is_verified() ) {
134 + $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
135 + $fs_user,
136 + $timestamp,
137 + 'checkout'
138 + ) );
28 139 }
29 140 }
141 +
142 + if ( $fs->is_payments_sandbox() ) {
143 + // Append plugin secure token for sandbox mode authentication.
144 + $context_params['sandbox'] = FS_Security::instance()->get_secure_token(
145 + $fs->get_plugin(),
146 + $timestamp,
147 + 'checkout'
148 + );
149 +
150 + /**
151 + * @since 1.1.7.3 Add security timestamp for sandbox even for anonymous user.
152 + */
153 + if ( empty( $context_params['s_ctx_ts'] ) ) {
154 + $context_params['s_ctx_ts'] = $timestamp;
155 + }
156 + }
157 +
158 + $return_url = $fs->_get_sync_license_url( $plugin_id );
159 +
160 + $can_user_install = (
161 + ( $fs->is_plugin() && current_user_can( 'install_plugins' ) ) ||
162 + ( $fs->is_theme() && current_user_can( 'install_themes' ) )
163 + );
164 +
165 + $query_params = array_merge( $context_params, $_GET, array(
166 + // Current plugin version.
167 + 'plugin_version' => $fs->get_plugin_version(),
168 + 'sdk_version' => WP_FS__SDK_VERSION,
169 + 'is_premium' => $is_premium ? 'true' : 'false',
170 + 'can_install' => $can_user_install ? 'true' : 'false',
171 + 'return_url' => $return_url,
172 + ) );
173 +
174 + $xdebug_session = fs_request_get( 'XDEBUG_SESSION' );
175 + if ( false !== $xdebug_session ) {
176 + $query_params['XDEBUG_SESSION'] = $xdebug_session;
177 + }
178 +
179 + $view_params = array(
180 + 'id' => $VARS['id'],
181 + 'page' => strtolower( $fs->get_text_inline( 'Checkout', 'checkout' ) ) . ' ' . $fs->get_text_inline( 'PCI compliant', 'pci-compliant' ),
182 + );
183 + fs_require_once_template('secure-https-header.php', $view_params);
184 +?>
185 + <div id="fs_checkout" class="wrap fs-section fs-full-size-wrapper">
186 + <div id="fs_frame"></div>
187 + <script type="text/javascript">
188 + // http://stackoverflow.com/questions/4583703/jquery-post-request-not-ajax
189 + jQuery(function ($) {
190 + $.extend({
191 + form: function (url, data, method) {
192 + if (method == null) method = 'POST';
193 + if (data == null) data = {};
194 +
195 + var form = $('<form>').attr({
196 + method: method,
197 + action: url
198 + }).css({
199 + display: 'none'
200 + });
201 +
202 + var addData = function (name, data) {
203 + if ($.isArray(data)) {
204 + for (var i = 0; i < data.length; i++) {
205 + var value = data[i];
206 + addData(name + '[]', value);
207 + }
208 + } else if (typeof data === 'object') {
209 + for (var key in data) {
210 + if (data.hasOwnProperty(key)) {
211 + addData(name + '[' + key + ']', data[key]);
212 + }
213 + }
214 + } else if (data != null) {
215 + form.append($('<input>').attr({
216 + type : 'hidden',
217 + name : String(name),
218 + value: String(data)
219 + }));
220 + }
221 + };
222 +
223 + for (var key in data) {
224 + if (data.hasOwnProperty(key)) {
225 + addData(key, data[key]);
226 + }
227 + }
228 +
229 + return form.appendTo('body');
230 + }
231 + });
232 + });
233 +
234 + (function ($) {
235 + $(function () {
236 +
237 + var
238 + // Keep track of the i-frame height.
239 + frame_height = 800,
240 + base_url = '<?php echo FS_CHECKOUT__ADDRESS ?>',
241 + // Pass the parent page URL into the i-frame in a meaningful way (this URL could be
242 + // passed via query string or hard coded into the child page, it depends on your needs).
243 + src = base_url + '/?<?php echo http_build_query( $query_params ) ?>#' + encodeURIComponent(document.location.href),
244 + // Append the i-frame into the DOM.
245 + frame = $('<i' + 'frame " src="' + src + '" width="100%" height="' + frame_height + 'px" scrolling="no" frameborder="0" style="background: transparent; width: 1px; min-width: 100%;"><\/i' + 'frame>')
246 + .appendTo('#fs_frame');
247 +
248 + FS.PostMessage.init(base_url, [frame[0]]);
249 + FS.PostMessage.receiveOnce('height', function (data) {
250 + var h = data.height;
251 + if (!isNaN(h) && h > 0 && h != frame_height) {
252 + frame_height = h;
253 + frame.height(frame_height + 'px');
254 +
255 + FS.PostMessage.postScroll(frame[0]);
256 + }
257 + });
258 +
259 + FS.PostMessage.receiveOnce('install', function (data) {
260 + var requestData = {
261 + user_id : data.user.id,
262 + user_secret_key : data.user.secret_key,
263 + user_public_key : data.user.public_key,
264 + install_id : data.install.id,
265 + install_secret_key: data.install.secret_key,
266 + install_public_key: data.install.public_key
267 + };
268 +
269 + if (true === data.auto_install)
270 + requestData.auto_install = true;
271 +
272 + // Post data to activation URL.
273 + $.form('<?php echo fs_nonce_url( $fs->_get_admin_page_url( 'account', array(
274 + 'fs_action' => $fs->get_unique_affix() . '_activate_new',
275 + 'plugin_id' => $plugin_id
276 + ) ), $fs->get_unique_affix() . '_activate_new' ) ?>', requestData).submit();
277 + });
278 +
279 + FS.PostMessage.receiveOnce('pending_activation', function (data) {
280 + var requestData = {
281 + user_email : data.user_email,
282 + support_email_address: data.support_email_address
283 + };
284 +
285 + if (true === data.auto_install)
286 + requestData.auto_install = true;
287 +
288 + $.form('<?php echo fs_nonce_url( $fs->_get_admin_page_url( 'account', array(
289 + 'fs_action' => $fs->get_unique_affix() . '_activate_new',
290 + 'plugin_id' => $plugin_id,
291 + 'pending_activation' => true,
292 + 'has_upgrade_context' => true,
293 + ) ), $fs->get_unique_affix() . '_activate_new' ) ?>', requestData).submit();
294 + });
295 +
296 + FS.PostMessage.receiveOnce('get_context', function () {
297 + console.debug('receiveOnce', 'get_context');
298 +
299 + // If the user didn't connect his account with Freemius,
300 + // once he accepts the Terms of Service and Privacy Policy,
301 + // and then click the purchase button, the context information
302 + // of the user will be shared with Freemius in order to complete the
303 + // purchase workflow and activate the license for the right user.
304 + <?php $install_data = array_merge( $fs->get_opt_in_params(),
305 + array(
306 + 'activation_url' => fs_nonce_url( $fs->_get_admin_page_url( '',
307 + array(
308 + 'fs_action' => $fs->get_unique_affix() . '_activate_new',
309 + 'plugin_id' => $plugin_id,
310 +
311 + ) ),
312 + $fs->get_unique_affix() . '_activate_new' )
313 + ) ) ?>
314 + FS.PostMessage.post('context', <?php echo json_encode( $install_data ) ?>, frame[0]);
315 + });
316 +
317 + FS.PostMessage.receiveOnce('purchaseCompleted', <?php echo $fs->apply_filters('checkout/purchaseCompleted', 'function (data) {
318 + console.log("checkout", "purchaseCompleted");
319 + }') ?>);
320 +
321 + FS.PostMessage.receiveOnce('get_dimensions', function (data) {
322 + console.debug('receiveOnce', 'get_dimensions');
323 +
324 + FS.PostMessage.post('dimensions', {
325 + height : $(document.body).height(),
326 + scrollTop: $(document).scrollTop()
327 + }, frame[0]);
328 + });
329 +
330 + var updateHeight = function () {
331 + frame.css('min-height', $(document.body).height() + 'px');
332 + };
333 +
334 + $(document).ready(updateHeight);
335 +
336 + $(window).resize(updateHeight);
337 + });
338 + })(jQuery);
339 + </script>
340 + </div>