| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package Freemius |
| 4 | 4 | * @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 | - * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License | |
| 5 | + * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 | |
| 6 | 6 | * @since 1.0.3 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -11,16 +11,18 @@ | ||
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | wp_enqueue_script( 'jquery' ); |
| 14 | 14 | wp_enqueue_script( 'json2' ); |
| 15 | - fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' ); | |
| 15 | + fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.js' ); | |
| 16 | 16 | fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' ); |
| 17 | + fs_enqueue_local_style( 'fs_common', '/admin/common.css' ); | |
| 17 | 18 | |
| 18 | 19 | /** |
| 19 | - * @var array $VARS | |
| 20 | + * @var array $VARS | |
| 21 | + * @var Freemius $fs | |
| 20 | 22 | */ |
| 21 | - $slug = $VARS['slug']; | |
| 22 | - $fs = freemius( $slug ); | |
| 23 | + $fs = freemius( $VARS['id'] ); | |
| 24 | + $slug = $fs->get_slug(); | |
| 23 | 25 | $timestamp = time(); |
| 24 | 26 | |
| 25 | 27 | $context_params = array( |
| 26 | 28 | 'plugin_id' => $fs->get_id(), |
| @@ -27,8 +29,13 @@ | ||
| 27 | 29 | 'plugin_public_key' => $fs->get_public_key(), |
| 28 | 30 | 'plugin_version' => $fs->get_plugin_version(), |
| 29 | 31 | ); |
| 30 | 32 | |
| 33 | + $bundle_id = $fs->get_bundle_id(); | |
| 34 | + if ( ! is_null( $bundle_id ) ) { | |
| 35 | + $context_params['bundle_id'] = $bundle_id; | |
| 36 | + } | |
| 37 | + | |
| 31 | 38 | // Get site context secure params. |
| 32 | 39 | if ( $fs->is_registered() ) { |
| 33 | 40 | $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params( |
| 34 | 41 | $fs->get_site(), |
| @@ -48,75 +55,59 @@ | ||
| 48 | 55 | ); |
| 49 | 56 | } |
| 50 | 57 | |
| 51 | 58 | $query_params = array_merge( $context_params, $_GET, array( |
| 52 | - 'next' => $fs->_get_sync_license_url( false, false ), | |
| 53 | - 'plugin_version' => $fs->get_plugin_version(), | |
| 59 | + 'next' => $fs->_get_sync_license_url( false, false ), | |
| 60 | + 'plugin_version' => $fs->get_plugin_version(), | |
| 54 | 61 | // Billing cycle. |
| 55 | - 'billing_cycle' => fs_request_get( 'billing_cycle', WP_FS__PERIOD_ANNUALLY ), | |
| 62 | + 'billing_cycle' => fs_request_get( 'billing_cycle', WP_FS__PERIOD_ANNUALLY ), | |
| 63 | + 'is_network_admin' => fs_is_network_admin() ? 'true' : 'false', | |
| 64 | + 'currency' => $fs->apply_filters( 'default_currency', 'usd' ), | |
| 65 | + 'discounts_model' => $fs->apply_filters( 'pricing/discounts_model', 'absolute' ), | |
| 56 | 66 | ) ); |
| 57 | -?> | |
| 58 | - <?php if ( ! $fs->is_registered() ) { | |
| 59 | - $template_data = array( | |
| 60 | - 'slug' => $slug, | |
| 61 | - ); | |
| 62 | - fs_require_template( 'forms/trial-start.php', $template_data); | |
| 63 | - } ?> | |
| 64 | - <div id="fs_pricing" class="wrap" style="margin: 0 0 -65px -20px;"> | |
| 65 | - <div id="iframe"></div> | |
| 66 | - <form action="" method="POST"> | |
| 67 | - <input type="hidden" name="user_id"/> | |
| 68 | - <input type="hidden" name="user_email"/> | |
| 69 | - <input type="hidden" name="site_id"/> | |
| 70 | - <input type="hidden" name="public_key"/> | |
| 71 | - <input type="hidden" name="secret_key"/> | |
| 72 | - <input type="hidden" name="action" value="account"/> | |
| 73 | - </form> | |
| 74 | 67 | |
| 75 | - <script type="text/javascript"> | |
| 76 | - (function ($, undef) { | |
| 77 | - $(function () { | |
| 78 | - var | |
| 79 | - // Keep track of the iframe height. | |
| 80 | - iframe_height = 800, | |
| 81 | - base_url = '<?php echo WP_FS__ADDRESS ?>', | |
| 82 | - // Pass the parent page URL into the Iframe in a meaningful way (this URL could be | |
| 83 | - // passed via query string or hard coded into the child page, it depends on your needs). | |
| 84 | - src = base_url + '/pricing/?<?php echo http_build_query( $query_params ) ?>#' + encodeURIComponent(document.location.href), | |
| 68 | + $pricing_js_url = fs_asset_url( $fs->get_pricing_js_path() ); | |
| 85 | 69 | |
| 86 | - // Append the Iframe into the DOM. | |
| 87 | - iframe = $('<iframe " src="' + src + '" width="100%" height="' + iframe_height + 'px" scrolling="no" frameborder="0" style="background: transparent;"><\/iframe>') | |
| 88 | - .appendTo('#iframe'); | |
| 70 | + wp_enqueue_script( 'freemius-pricing', $pricing_js_url ); | |
| 89 | 71 | |
| 90 | - FS.PostMessage.init(base_url); | |
| 72 | + $pricing_css_path = $fs->apply_filters( 'pricing/css_path', null ); | |
| 73 | + if ( is_string( $pricing_css_path ) ) { | |
| 74 | + wp_enqueue_style( 'freemius-pricing', fs_asset_url( $pricing_css_path ) ); | |
| 75 | + } | |
| 91 | 76 | |
| 92 | - FS.PostMessage.receive('height', function (data) { | |
| 93 | - var h = data.height; | |
| 94 | - if (!isNaN(h) && h > 0 && h != iframe_height) { | |
| 95 | - iframe_height = h; | |
| 96 | - $("#iframe iframe").height(iframe_height + 'px'); | |
| 97 | - } | |
| 98 | - }); | |
| 77 | + $has_tabs = $fs->_add_tabs_before_content(); | |
| 99 | 78 | |
| 100 | - FS.PostMessage.receive('get_dimensions', function (data) { | |
| 101 | - FS.PostMessage.post('dimensions', { | |
| 102 | - height : $(document.body).height(), | |
| 103 | - scrollTop: $(document).scrollTop() | |
| 104 | - }, iframe[0]); | |
| 105 | - }); | |
| 79 | + if ( $has_tabs ) { | |
| 80 | + $query_params['tabs'] = 'true'; | |
| 81 | + } | |
| 82 | +?> | |
| 83 | + <div id="fs_pricing" class="wrap fs-section fs-full-size-wrapper"> | |
| 84 | + <div id="fs_pricing_wrapper" data-public-url="<?php echo trailingslashit( dirname( $pricing_js_url ) ) ?>"></div> | |
| 85 | + <?php | |
| 86 | + $pricing_config = array_merge( array( | |
| 87 | + 'contact_url' => $fs->contact_url(), | |
| 88 | + 'is_production' => ( defined( 'WP_FS__IS_PRODUCTION_MODE' ) ? WP_FS__IS_PRODUCTION_MODE : null ), | |
| 89 | + 'menu_slug' => $fs->get_menu_slug(), | |
| 90 | + 'mode' => 'dashboard', | |
| 91 | + 'fs_wp_endpoint_url' => WP_FS__ADDRESS, | |
| 92 | + 'request_handler_url' => admin_url( | |
| 93 | + 'admin-ajax.php?' . http_build_query( array( | |
| 94 | + 'module_id' => $fs->get_id(), | |
| 95 | + 'action' => $fs->get_ajax_action( 'pricing_ajax_action' ), | |
| 96 | + 'security' => $fs->get_ajax_security( 'pricing_ajax_action' ) | |
| 97 | + ) ) | |
| 98 | + ), | |
| 99 | + 'selector' => '#fs_pricing_wrapper', | |
| 100 | + 'unique_affix' => $fs->get_unique_affix(), | |
| 101 | + 'show_annual_in_monthly' => $fs->apply_filters( 'pricing/show_annual_in_monthly', true ), | |
| 102 | + 'license' => $fs->has_active_valid_license() ? $fs->_get_license() : null, | |
| 103 | + 'plugin_icon' => $fs->get_local_icon_url(), | |
| 104 | + 'disable_single_package' => $fs->apply_filters( 'pricing/disable_single_package', false ), | |
| 105 | + ), $query_params ); | |
| 106 | 106 | |
| 107 | - FS.PostMessage.receive('start_trial', function (data) { | |
| 108 | - openTrialConfirmationModal(data); | |
| 109 | - }); | |
| 110 | - }); | |
| 111 | - })(jQuery); | |
| 112 | - </script> | |
| 107 | + wp_add_inline_script( 'freemius-pricing', 'Freemius.pricing.new( ' . json_encode( $pricing_config ) . ' )' ); | |
| 108 | + ?> | |
| 113 | 109 | </div> |
| 114 | 110 | <?php |
| 115 | - $params = array( | |
| 116 | - 'page' => 'pricing', | |
| 117 | - 'module_id' => $fs->get_id(), | |
| 118 | - 'module_slug' => $slug, | |
| 119 | - 'module_version' => $fs->get_plugin_version(), | |
| 120 | - ); | |
| 121 | - fs_require_template( 'powered-by.php', $params ); | |
| 122 | -?> | |
| 111 | + if ( $has_tabs ) { | |
| 112 | + $fs->_add_tabs_after_content(); | |
| 113 | + } | |