| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Freemius |
| 4 |
* @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 6 |
* @since 1.0.3 |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* @var array $VARS |
| 15 |
*/ |
| 16 |
$slug = $VARS['slug']; |
| 17 |
/** |
| 18 |
* @var Freemius |
| 19 |
*/ |
| 20 |
$fs = freemius( $slug ); |
| 21 |
|
| 22 |
$open_addon_slug = fs_request_get( 'slug' ); |
| 23 |
|
| 24 |
$open_addon = false; |
| 25 |
|
| 26 |
/** |
| 27 |
* @var FS_Plugin[] |
| 28 |
*/ |
| 29 |
$addons = $fs->get_addons(); |
| 30 |
|
| 31 |
$has_addons = ( is_array( $addons ) && 0 < count( $addons ) ); |
| 32 |
?> |
| 33 |
<div id="fs_addons" class="wrap"> |
| 34 |
<h2><?php printf( fs_text( 'add-ons-for-x', $slug ), $fs->get_plugin_name() ) ?></h2> |
| 35 |
|
| 36 |
<div id="poststuff"> |
| 37 |
<?php if ( ! $has_addons ) : ?> |
| 38 |
<h3><?php printf( |
| 39 |
'%s... %s', |
| 40 |
fs_text( 'oops', $slug ), |
| 41 |
fs_text( 'add-ons-missing', $slug ) |
| 42 |
) ?></h3> |
| 43 |
<?php endif ?> |
| 44 |
<ul class="fs-cards-list"> |
| 45 |
<?php if ( $has_addons ) : ?> |
| 46 |
<?php foreach ( $addons as $addon ) : ?> |
| 47 |
<?php |
| 48 |
$open_addon = ( $open_addon || ( $open_addon_slug === $addon->slug ) ); |
| 49 |
|
| 50 |
$price = 0; |
| 51 |
$plan = null; |
| 52 |
$plans_result = $fs->get_api_site_or_plugin_scope()->get( "/addons/{$addon->id}/plans.json" ); |
| 53 |
if ( ! isset( $plans_result->error ) ) { |
| 54 |
$plans = $plans_result->plans; |
| 55 |
if ( is_array( $plans ) && 0 < count( $plans ) ) { |
| 56 |
$plan = new FS_Plugin_Plan( $plans[0] ); |
| 57 |
$pricing_result = $fs->get_api_site_or_plugin_scope()->get( "/addons/{$addon->id}/plans/{$plan->id}/pricing.json" ); |
| 58 |
if ( ! isset( $pricing_result->error ) ) { |
| 59 |
// Update plan's pricing. |
| 60 |
$plan->pricing = $pricing_result->pricing; |
| 61 |
|
| 62 |
if ( is_array( $plan->pricing ) && 0 < count( $plan->pricing ) ) { |
| 63 |
$min_price = 999999; |
| 64 |
foreach ( $plan->pricing as $pricing ) { |
| 65 |
if ( ! is_null( $pricing->annual_price ) && $pricing->annual_price > 0 ) { |
| 66 |
$min_price = min( $min_price, $pricing->annual_price ); |
| 67 |
} else if ( ! is_null( $pricing->monthly_price ) && $pricing->monthly_price > 0 ) { |
| 68 |
$min_price = min( $min_price, 12 * $pricing->monthly_price ); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
if ( $min_price < 999999 ) { |
| 73 |
$price = $min_price; |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
?> |
| 80 |
<li class="fs-card fs-addon" data-slug="<?php echo $addon->slug ?>"> |
| 81 |
<?php |
| 82 |
echo sprintf( '<a href="%s" class="thickbox fs-overlay" aria-label="%s" data-title="%s"></a>', |
| 83 |
esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&parent_plugin_id=' . $fs->get_id() . '&plugin=' . $addon->slug . |
| 84 |
'&TB_iframe=true&width=600&height=550' ) ), |
| 85 |
esc_attr( sprintf( fs_text( 'more-information-about-x', $slug ), $addon->title ) ), |
| 86 |
esc_attr( $addon->title ) |
| 87 |
); |
| 88 |
?> |
| 89 |
<?php |
| 90 |
if ( is_null( $addon->info ) ) { |
| 91 |
$addon->info = new stdClass(); |
| 92 |
} |
| 93 |
if ( ! isset( $addon->info->card_banner_url ) ) { |
| 94 |
$addon->info->card_banner_url = '//dashboard.freemius.com/assets/img/marketing/blueprint-300x100.jpg'; |
| 95 |
} |
| 96 |
if ( ! isset( $addon->info->short_description ) ) { |
| 97 |
$addon->info->short_description = 'What\'s the one thing your add-on does really, really well?'; |
| 98 |
} |
| 99 |
?> |
| 100 |
<div class="fs-inner"> |
| 101 |
<ul> |
| 102 |
<li class="fs-card-banner" |
| 103 |
style="background-image: url('<?php echo $addon->info->card_banner_url ?>');"></li> |
| 104 |
<!-- <li class="fs-tag"></li>--> |
| 105 |
<li class="fs-title"><?php echo $addon->title ?></li> |
| 106 |
<li class="fs-offer"> |
| 107 |
<span |
| 108 |
class="fs-price"><?php echo ( 0 == $price ) ? fs_text( 'free', $slug ) : ('$' . number_format( $price, 2 ) . ($plan->has_trial() ? ' - ' . fs_text('trial', $slug) : '')) ?></span> |
| 109 |
</li> |
| 110 |
<li class="fs-description"><?php echo ! empty( $addon->info->short_description ) ? $addon->info->short_description : 'SHORT DESCRIPTION' ?></li> |
| 111 |
<li class="fs-cta"><a class="button"><?php fs_echo( 'view-details', $slug ) ?></a></li> |
| 112 |
</ul> |
| 113 |
</div> |
| 114 |
</li> |
| 115 |
<?php endforeach ?> |
| 116 |
<?php endif ?> |
| 117 |
</ul> |
| 118 |
</div> |
| 119 |
</div> |
| 120 |
<script type="text/javascript"> |
| 121 |
(function ($) { |
| 122 |
<?php if ( $open_addon ) : ?> |
| 123 |
|
| 124 |
var interval = setInterval(function () { |
| 125 |
// Open add-on information page. |
| 126 |
<?php |
| 127 |
/** |
| 128 |
* @author Vova Feldman |
| 129 |
* |
| 130 |
* This code does NOT expose an XSS vulnerability because: |
| 131 |
* 1. This page only renders for admins, so if an attacker manage to get |
| 132 |
* admin access, they can do more harm. |
| 133 |
* 2. This code won't be rendered unless $open_addon_slug matches any of |
| 134 |
* the plugin's add-ons slugs. |
| 135 |
*/ |
| 136 |
?> |
| 137 |
$('.fs-card[data-slug=<?php echo $open_addon_slug ?>] a').click(); |
| 138 |
if ($('#TB_iframeContent').length > 0) { |
| 139 |
clearInterval(interval); |
| 140 |
interval = null; |
| 141 |
} |
| 142 |
}, 200); |
| 143 |
|
| 144 |
<?php else : ?> |
| 145 |
|
| 146 |
|
| 147 |
$('.fs-card.fs-addon') |
| 148 |
.mouseover(function () { |
| 149 |
$(this).find('.fs-cta .button').addClass('button-primary'); |
| 150 |
}).mouseout(function () { |
| 151 |
$(this).find('.fs-cta .button').removeClass('button-primary'); |
| 152 |
}); |
| 153 |
|
| 154 |
<?php endif ?> |
| 155 |
})(jQuery); |
| 156 |
</script> |
| 157 |
<?php |
| 158 |
$params = array( |
| 159 |
'page' => 'addons', |
| 160 |
'module_id' => $fs->get_id(), |
| 161 |
'module_slug' => $slug, |
| 162 |
'module_version' => $fs->get_plugin_version(), |
| 163 |
); |
| 164 |
fs_require_template( 'powered-by.php', $params ); |
| 165 |
?> |