| 1 |
<?php |
| 2 |
/** |
| 3 |
* @var array $VARS |
| 4 |
* @var Freemius $fs |
| 5 |
*/ |
| 6 |
$fs = $VARS['parent_fs']; |
| 7 |
$addon_id = $VARS['addon_id']; |
| 8 |
$odd = $VARS['odd']; |
| 9 |
$slug = $fs->get_slug(); |
| 10 |
|
| 11 |
|
| 12 |
$addon = $fs->get_addon( $addon_id ); |
| 13 |
$is_addon_activated = $fs->is_addon_activated( $addon_id ); |
| 14 |
$is_addon_connected = $fs->is_addon_connected( $addon_id ); |
| 15 |
|
| 16 |
$fs_addon = $is_addon_connected ? |
| 17 |
freemius( $addon_id ) : |
| 18 |
false; |
| 19 |
|
| 20 |
// Aliases. |
| 21 |
$download_latest_text = fs_text_x_inline( 'Download Latest', 'as download latest version', 'download-latest', $slug ); |
| 22 |
$downgrade_x_confirm_text = fs_text_inline( 'Downgrading your plan will immediately stop all future recurring payments and your %s plan license will expire in %s.', 'downgrade-x-confirm', $slug ); |
| 23 |
$cancel_trial_confirm_text = fs_text_inline( 'Cancelling the trial will immediately block access to all premium features. Are you sure?', 'cancel-trial-confirm', $slug ); |
| 24 |
$after_downgrade_non_blocking_text = fs_text_inline( 'You can still enjoy all %s features but you will not have access to %s updates and support.', 'after-downgrade-non-blocking', $slug ); |
| 25 |
$after_downgrade_blocking_text = fs_text_inline( 'Once your license expires you can still use the Free version but you will NOT have access to the %s features.', 'after-downgrade-blocking', $slug ); |
| 26 |
/* translators: %s: Plan title (e.g. "Professional") */ |
| 27 |
$activate_plan_text = fs_text_inline( 'Activate %s Plan', 'activate-x-plan', $slug ); |
| 28 |
$version_text = fs_text_x_inline( 'Version', 'product version', 'version', $slug ); |
| 29 |
/* translators: %s: Time period (e.g. Auto renews in "2 months") */ |
| 30 |
$renews_in_text = fs_text_inline( 'Auto renews in %s', 'renews-in', $slug ); |
| 31 |
/* translators: %s: Time period (e.g. Expires in "2 months") */ |
| 32 |
$expires_in_text = fs_text_inline( 'Expires in %s', 'expires-in', $slug ); |
| 33 |
$sync_license_text = fs_text_x_inline( 'Sync License', 'as synchronize license', 'sync-license', $slug ); |
| 34 |
$cancel_trial_text = fs_text_inline( 'Cancel Trial', 'cancel-trial', $slug ); |
| 35 |
$change_plan_text = fs_text_inline( 'Change Plan', 'change-plan', $slug ); |
| 36 |
$upgrade_text = fs_text_x_inline( 'Upgrade', 'verb', 'upgrade', $slug ); |
| 37 |
$addons_text = fs_text_inline( 'Add-Ons', 'add-ons', $slug ); |
| 38 |
$downgrade_text = fs_text_x_inline( 'Downgrade', 'verb', 'downgrade', $slug ); |
| 39 |
$trial_text = fs_text_x_inline( 'Trial', 'trial period', 'trial', $slug ); |
| 40 |
$free_text = fs_text_inline( 'Free', 'free', $slug ); |
| 41 |
$activate_text = fs_text_inline( 'Activate', 'activate', $slug ); |
| 42 |
$plan_text = fs_text_x_inline( 'Plan', 'as product pricing plan', 'plan', $slug ); |
| 43 |
|
| 44 |
// Defaults. |
| 45 |
$plan = null; |
| 46 |
$is_paid_trial = false; |
| 47 |
$license = null; |
| 48 |
$site = null; |
| 49 |
$is_active_subscription = false; |
| 50 |
$subscription = null; |
| 51 |
$is_paying = false; |
| 52 |
|
| 53 |
if ( is_object( $fs_addon ) ) { |
| 54 |
$is_paying = $fs_addon->is_paying(); |
| 55 |
$user = $fs_addon->get_user(); |
| 56 |
$site = $fs_addon->get_site(); |
| 57 |
$license = $fs_addon->_get_license(); |
| 58 |
$subscription = ( is_object( $license ) ? |
| 59 |
$fs_addon->_get_subscription( $license->id ) : |
| 60 |
null ); |
| 61 |
$plan = $fs_addon->get_plan(); |
| 62 |
$is_active_subscription = ( is_object( $subscription ) && $subscription->is_active() ); |
| 63 |
$is_paid_trial = $fs_addon->is_paid_trial(); |
| 64 |
$show_upgrade = ( ! $is_paying && ! $is_paid_trial && ! $fs_addon->_has_premium_license() ); |
| 65 |
$is_current_license_expired = is_object( $license ) && $license->is_expired(); |
| 66 |
} |
| 67 |
?> |
| 68 |
<tr<?php if ( $odd ) { |
| 69 |
echo ' class="alternate"'; |
| 70 |
} ?>> |
| 71 |
<td> |
| 72 |
<!-- Title --> |
| 73 |
<?php echo $addon->title ?> |
| 74 |
</td> |
| 75 |
<?php if ( $is_addon_connected ) : ?> |
| 76 |
<!-- ID --> |
| 77 |
<td><?php echo $site->id ?></td> |
| 78 |
<!--/ ID --> |
| 79 |
|
| 80 |
<!-- Version --> |
| 81 |
<td><?php echo $fs_addon->get_plugin_version() ?></td> |
| 82 |
<!--/ Version --> |
| 83 |
|
| 84 |
<!-- Plan Title --> |
| 85 |
<td><?php echo strtoupper( is_string( $plan->name ) ? $plan->title : $free_text ) ?></td> |
| 86 |
<!--/ Plan Title --> |
| 87 |
|
| 88 |
<?php if ( $fs_addon->is_trial() || is_object( $license ) ) : ?> |
| 89 |
|
| 90 |
<!-- Expiration --> |
| 91 |
<td> |
| 92 |
<?php |
| 93 |
$tags = array(); |
| 94 |
|
| 95 |
if ( $fs_addon->is_trial() ) { |
| 96 |
$tags[] = array( 'label' => $trial_text, 'type' => 'success' ); |
| 97 |
|
| 98 |
$tags[] = array( |
| 99 |
'label' => sprintf( |
| 100 |
( $is_paid_trial ? |
| 101 |
$renews_in_text : |
| 102 |
$expires_in_text ), |
| 103 |
human_time_diff( time(), strtotime( $site->trial_ends ) ) |
| 104 |
), |
| 105 |
'type' => ( $is_paid_trial ? 'success' : 'warn' ) |
| 106 |
); |
| 107 |
} else { |
| 108 |
if ( is_object( $license ) ) { |
| 109 |
if ( $license->is_cancelled ) { |
| 110 |
$tags[] = array( |
| 111 |
'label' => fs_text_inline( 'Cancelled', 'cancelled', $slug ), |
| 112 |
'type' => 'error' |
| 113 |
); |
| 114 |
} else if ( $license->is_expired() ) { |
| 115 |
$tags[] = array( |
| 116 |
'label' => fs_text_inline( 'Expired', 'expired', $slug ), |
| 117 |
'type' => 'error' |
| 118 |
); |
| 119 |
} else if ( $license->is_lifetime() ) { |
| 120 |
$tags[] = array( |
| 121 |
'label' => fs_text_inline( 'No expiration', 'no-expiration', $slug ), |
| 122 |
'type' => 'success' |
| 123 |
); |
| 124 |
} else if ( ! $is_active_subscription && ! $license->is_first_payment_pending() ) { |
| 125 |
$tags[] = array( |
| 126 |
'label' => sprintf( $expires_in_text, human_time_diff( time(), strtotime( $license->expiration ) ) ), |
| 127 |
'type' => 'warn' |
| 128 |
); |
| 129 |
} else if ( $is_active_subscription && ! $subscription->is_first_payment_pending() ) { |
| 130 |
$tags[] = array( |
| 131 |
'label' => sprintf( $renews_in_text, human_time_diff( time(), strtotime( $subscription->next_payment ) ) ), |
| 132 |
'type' => 'success' |
| 133 |
); |
| 134 |
} |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
foreach ( $tags as $t ) { |
| 139 |
printf( '<label class="fs-tag fs-%s">%s</label>' . "\n", $t['type'], $t['label'] ); |
| 140 |
} |
| 141 |
?> |
| 142 |
</td> |
| 143 |
<!--/ Expiration --> |
| 144 |
|
| 145 |
<?php endif ?> |
| 146 |
|
| 147 |
<?php |
| 148 |
$buttons = array(); |
| 149 |
if ( $is_addon_activated ) { |
| 150 |
if ( $is_paying ) { |
| 151 |
$buttons[] = fs_ui_get_action_button( |
| 152 |
$fs->get_id(), |
| 153 |
'account', |
| 154 |
'deactivate_license', |
| 155 |
fs_text_inline( 'Deactivate License', 'deactivate-license', $slug ), |
| 156 |
'', |
| 157 |
array( 'plugin_id' => $addon_id ), |
| 158 |
false |
| 159 |
); |
| 160 |
|
| 161 |
$human_readable_license_expiration = human_time_diff( time(), strtotime( $license->expiration ) ); |
| 162 |
$downgrade_confirmation_message = sprintf( |
| 163 |
$downgrade_x_confirm_text, |
| 164 |
$plan->title, |
| 165 |
$human_readable_license_expiration |
| 166 |
); |
| 167 |
|
| 168 |
$after_downgrade_message = ! $license->is_block_features ? |
| 169 |
sprintf( $after_downgrade_non_blocking_text, $plan->title, $fs_addon->get_module_label( true ) ) : |
| 170 |
sprintf( $after_downgrade_blocking_text, $plan->title ); |
| 171 |
|
| 172 |
if ( ! $license->is_lifetime() && $is_active_subscription ) { |
| 173 |
$buttons[] = fs_ui_get_action_button( |
| 174 |
$fs->get_id(), |
| 175 |
'account', |
| 176 |
'downgrade_account', |
| 177 |
esc_html( $fs_addon->is_only_premium() ? fs_text_inline( 'Cancel Subscription', 'cancel-subscription', $slug ) : $downgrade_text ), |
| 178 |
'', |
| 179 |
array( 'plugin_id' => $addon_id ), |
| 180 |
false, |
| 181 |
false, |
| 182 |
false, |
| 183 |
( $downgrade_confirmation_message . ' ' . $after_downgrade_message ), |
| 184 |
'POST' |
| 185 |
); |
| 186 |
} |
| 187 |
} else if ( $is_paid_trial ) { |
| 188 |
$buttons[] = fs_ui_get_action_button( |
| 189 |
$fs->get_id(), |
| 190 |
'account', |
| 191 |
'cancel_trial', |
| 192 |
esc_html( $cancel_trial_text ), |
| 193 |
'', |
| 194 |
array( 'plugin_id' => $addon_id ), |
| 195 |
false, |
| 196 |
false, |
| 197 |
'dashicons dashicons-download', |
| 198 |
$cancel_trial_confirm_text, |
| 199 |
'POST' |
| 200 |
); |
| 201 |
} else { |
| 202 |
$premium_license = $fs_addon->_get_available_premium_license(); |
| 203 |
|
| 204 |
if ( is_object( $premium_license ) ) { |
| 205 |
$premium_plan = $fs_addon->_get_plan_by_id( $premium_license->plan_id ); |
| 206 |
$site = $fs_addon->get_site(); |
| 207 |
|
| 208 |
$buttons[] = fs_ui_get_action_button( |
| 209 |
$fs->get_id(), |
| 210 |
'account', |
| 211 |
'activate_license', |
| 212 |
esc_html( sprintf( $activate_plan_text, $premium_plan->title, ( $site->is_localhost() && $premium_license->is_free_localhost ) ? '[localhost]' : ( 1 < $premium_license->left() ? $premium_license->left() . ' left' : '' ) ) ), |
| 213 |
'', |
| 214 |
array( |
| 215 |
'plugin_id' => $addon_id, |
| 216 |
'license_id' => $premium_license->id, |
| 217 |
) |
| 218 |
); |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
if ( 0 == count( $buttons ) ) { |
| 223 |
$fs_addon->_add_license_activation_dialog_box(); |
| 224 |
|
| 225 |
$buttons[] = fs_ui_get_action_button( |
| 226 |
$fs->get_id(), |
| 227 |
'account', |
| 228 |
'activate_license', |
| 229 |
fs_esc_html_inline( 'Activate License', 'activate-license', $slug ), |
| 230 |
'activate-license-trigger ' . $fs_addon->get_unique_affix(), |
| 231 |
array( |
| 232 |
'plugin_id' => $addon_id, |
| 233 |
), |
| 234 |
false, |
| 235 |
true |
| 236 |
); |
| 237 |
|
| 238 |
// Add sync license only if non of the other CTAs are visible. |
| 239 |
$buttons[] = fs_ui_get_action_button( |
| 240 |
$fs->get_id(), |
| 241 |
'account', |
| 242 |
$fs->get_unique_affix() . '_sync_license', |
| 243 |
esc_html( $sync_license_text ), |
| 244 |
'', |
| 245 |
array( 'plugin_id' => $addon_id ), |
| 246 |
false, |
| 247 |
true |
| 248 |
); |
| 249 |
|
| 250 |
} |
| 251 |
} else if ( ! $show_upgrade ) { |
| 252 |
if ( $fs->is_addon_installed( $addon_id ) ) { |
| 253 |
$addon_file = $fs->get_addon_basename( $addon_id ); |
| 254 |
$buttons[] = sprintf( |
| 255 |
'<a class="button button-primary edit" href="%s" title="%s">%s</a>', |
| 256 |
wp_nonce_url( 'plugins.php?action=activate&plugin=' . $addon_file, 'activate-plugin_' . $addon_file ), |
| 257 |
fs_esc_attr_inline( 'Activate this add-on', 'activate-this-addon', $slug ), |
| 258 |
$activate_text |
| 259 |
); |
| 260 |
} else { |
| 261 |
if ( $fs->is_allowed_to_install() ) { |
| 262 |
$buttons[] = sprintf( |
| 263 |
'<a class="button button-primary edit" href="%s">%s</a>', |
| 264 |
wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $addon->slug ), 'install-plugin_' . $addon->slug ), |
| 265 |
fs_text_inline( 'Install Now', 'install-now', $slug ) |
| 266 |
); |
| 267 |
} else { |
| 268 |
$buttons[] = sprintf( |
| 269 |
'<a target="_blank" class="button button-primary edit" href="%s">%s</a>', |
| 270 |
$fs->_get_latest_download_local_url( $addon_id ), |
| 271 |
esc_html( $download_latest_text ) |
| 272 |
); |
| 273 |
} |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
if ( $show_upgrade ) { |
| 278 |
$buttons[] = sprintf( '<a href="%s" class="thickbox button button-small button-primary" aria-label="%s" data-title="%s"><i class="dashicons dashicons-cart"></i> %s</a>', |
| 279 |
esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&parent_plugin_id=' . $fs->get_id() . '&plugin=' . $addon->slug . |
| 280 |
'&TB_iframe=true&width=600&height=550' ) ), |
| 281 |
esc_attr( sprintf( fs_text_inline( 'More information about %s', 'more-information-about-x', $slug ), $addon->title ) ), |
| 282 |
esc_attr( $addon->title ), |
| 283 |
( $fs_addon->has_free_plan() ? |
| 284 |
$upgrade_text : |
| 285 |
fs_text_x_inline( 'Purchase', 'verb', 'purchase', $slug ) ) |
| 286 |
); |
| 287 |
} |
| 288 |
|
| 289 |
$buttons_count = count( $buttons ); |
| 290 |
?> |
| 291 |
|
| 292 |
<!-- Actions --> |
| 293 |
<td><?php if ( $buttons_count > 1 ) : ?> |
| 294 |
<div class="button-group"><?php endif ?> |
| 295 |
<?php foreach ( $buttons as $button ) { |
| 296 |
echo $button; |
| 297 |
} ?> |
| 298 |
<?php if ( $buttons_count > 1 ) : ?></div><?php endif ?></td> |
| 299 |
<!--/ Actions --> |
| 300 |
|
| 301 |
<?php else : ?> |
| 302 |
<?php // Add-on NOT Installed or was never connected. |
| 303 |
?> |
| 304 |
<!-- Action --> |
| 305 |
<td colspan="4"> |
| 306 |
<?php if ( $fs->is_addon_installed( $addon_id ) ) : ?> |
| 307 |
<?php $addon_file = $fs->get_addon_basename( $addon_id ) ?> |
| 308 |
<a class="button button-primary" |
| 309 |
href="<?php echo wp_nonce_url( 'plugins.php?action=activate&plugin=' . $addon_file, 'activate-plugin_' . $addon_file ) ?>" |
| 310 |
title="<?php fs_esc_attr_echo_inline( 'Activate this add-on', 'activate-this-addon', $slug ) ?>" |
| 311 |
class="edit"><?php echo esc_html( $activate_text ) ?></a> |
| 312 |
<?php else : ?> |
| 313 |
<?php if ( $fs->is_allowed_to_install() ) : ?> |
| 314 |
<a class="button button-primary" |
| 315 |
href="<?php echo wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $addon->slug ), 'install-plugin_' . $addon->slug ) ?>"><?php fs_esc_html_echo_inline( 'Install Now', 'install-now', $slug ) ?></a> |
| 316 |
<?php else : ?> |
| 317 |
<a target="_blank" class="button button-primary" |
| 318 |
href="<?php echo $fs->_get_latest_download_local_url( $addon_id ) ?>"><?php echo esc_html( $download_latest_text ) ?></a> |
| 319 |
<?php endif ?> |
| 320 |
<?php endif ?> |
| 321 |
</td> |
| 322 |
<!--/ Action --> |
| 323 |
<?php endif ?> |
| 324 |
<?php if ( ! $is_paying && WP_FS__DEV_MODE ) : ?> |
| 325 |
<!-- Optional Delete Action --> |
| 326 |
<td> |
| 327 |
<?php |
| 328 |
if ( $is_addon_activated ) { |
| 329 |
fs_ui_action_button( |
| 330 |
$fs->get_id(), 'account', |
| 331 |
'delete_account', |
| 332 |
fs_text_x_inline( 'Delete', 'verb', 'delete', $slug ), |
| 333 |
'', |
| 334 |
array( 'plugin_id' => $addon_id ), |
| 335 |
false, |
| 336 |
$show_upgrade |
| 337 |
); |
| 338 |
} |
| 339 |
?> |
| 340 |
</td> |
| 341 |
<!--/ Optional Delete Action --> |
| 342 |
<?php endif ?> |
| 343 |
</tr> |