| 1 |
<?php |
| 2 |
/** |
| 3 |
* Add-Ons helper class. |
| 4 |
* |
| 5 |
* @package Formidable |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
die( 'You are not allowed to call this page directly.' ); |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Provides helper functions for managing add-ons in the admin area. |
| 14 |
* |
| 15 |
* @since 6.15 |
| 16 |
*/ |
| 17 |
class FrmAddonsHelper { |
| 18 |
/** |
| 19 |
* Stores the result of `FrmFormsHelper::get_plan_required`. |
| 20 |
* |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
private static $plan_required; |
| 24 |
|
| 25 |
/** |
| 26 |
* Show the CTA to upgrade or renew. |
| 27 |
* |
| 28 |
* @since 6.15 |
| 29 |
* @return void |
| 30 |
*/ |
| 31 |
public static function show_upgrade_renew_cta() { |
| 32 |
if ( FrmAddonsController::is_license_expired() ) { |
| 33 |
self::show_expired_cta(); |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
if ( ! FrmAppHelper::pro_is_connected() ) { |
| 38 |
self::show_lite_cta(); |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
if ( 'elite' !== FrmAddonsController::license_type() ) { |
| 43 |
self::show_elite_cta(); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Show 'Renew' banner for expired users. |
| 49 |
* |
| 50 |
* @since 6.15 |
| 51 |
* @return void |
| 52 |
*/ |
| 53 |
private static function show_expired_cta() { |
| 54 |
FrmTipsHelper::show_admin_cta( |
| 55 |
array( |
| 56 |
'title' => esc_html__( 'Unlock Add-on library', 'formidable' ), |
| 57 |
'description' => esc_html__( 'Renew your subscription today and access our library of add-ons to supercharge your forms.', 'formidable' ), |
| 58 |
'link_text' => esc_html__( 'Renew Now', 'formidable' ), |
| 59 |
'link_url' => FrmAddonsController::is_license_expired(), |
| 60 |
'id' => 'frm-renew-subscription-banner', |
| 61 |
) |
| 62 |
); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Show 'Upgrade to Pro' banner for users not connected to Pro. |
| 67 |
* |
| 68 |
* @since 6.15 |
| 69 |
* @return void |
| 70 |
*/ |
| 71 |
private static function show_lite_cta() { |
| 72 |
FrmTipsHelper::show_admin_cta( |
| 73 |
array( |
| 74 |
'title' => esc_html__( 'Unlock Add-on library', 'formidable' ), |
| 75 |
'description' => esc_html__( 'Upgrade to Pro and access our library of add-ons to supercharge your forms.', 'formidable' ), |
| 76 |
'link_text' => esc_html__( 'Upgrade to PRO', 'formidable' ), |
| 77 |
'link_url' => FrmAppHelper::admin_upgrade_link( |
| 78 |
array( |
| 79 |
'medium' => 'addons', |
| 80 |
'content' => 'upgrade-cta', |
| 81 |
) |
| 82 |
), |
| 83 |
'id' => 'frm-upgrade-banner', |
| 84 |
) |
| 85 |
); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Show 'Upgrade' banner for non-elite users. |
| 90 |
* |
| 91 |
* @since 6.15 |
| 92 |
* @return void |
| 93 |
*/ |
| 94 |
private static function show_elite_cta() { |
| 95 |
FrmTipsHelper::show_admin_cta( |
| 96 |
array( |
| 97 |
'title' => esc_html__( 'Unlock Even More Add-ons', 'formidable' ), |
| 98 |
'description' => sprintf( |
| 99 |
/* translators: %1$s: Open span tag, %2$s: Close span tag */ |
| 100 |
esc_html__( 'Your plan includes %1$s%2$s add-ons. Upgrade to take your forms even farther', 'formidable' ), |
| 101 |
'<span class="frm-addons-available-count">', |
| 102 |
'</span>' |
| 103 |
), |
| 104 |
'link_text' => esc_html__( 'Upgrade to PRO', 'formidable' ), |
| 105 |
'link_url' => FrmAppHelper::admin_upgrade_link( |
| 106 |
array( |
| 107 |
'medium' => 'addons', |
| 108 |
'content' => 'upgrade-cta', |
| 109 |
) |
| 110 |
), |
| 111 |
'id' => 'frm-upgrade-banner', |
| 112 |
) |
| 113 |
); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Displays a reconnect link for checking add-ons status. |
| 118 |
* |
| 119 |
* @since 6.15 |
| 120 |
* @return void |
| 121 |
*/ |
| 122 |
public static function get_reconnect_link() { |
| 123 |
if ( ! FrmAppHelper::pro_is_connected() ) { |
| 124 |
return; |
| 125 |
} |
| 126 |
?> |
| 127 |
<p class="frm-py-2xs"> |
| 128 |
<span class="frm-font-medium frm-text-grey-700"><?php esc_html_e( 'Missing add-ons?', 'formidable' ); ?></span> |
| 129 |
<a href="#" id="frm_reconnect_link" class="frm-show-authorized frm-font-semibold" data-refresh="1"> |
| 130 |
<?php esc_html_e( 'Check now for a recent upgrade or renewal', 'formidable' ); ?> |
| 131 |
</a> |
| 132 |
</p> |
| 133 |
<?php |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Get the icon for a specific addon. |
| 138 |
* |
| 139 |
* @since 6.15 |
| 140 |
* @param string $slug The slug of the addon. |
| 141 |
* @return void |
| 142 |
*/ |
| 143 |
public static function get_addon_icon( $slug ) { |
| 144 |
$icons_map = array( |
| 145 |
'acf-forms' => 'acfforms', |
| 146 |
'activecampaign-wordpress-plugin' => 'activecampaign', |
| 147 |
'ai' => 'ai-form', |
| 148 |
'authorize-net-aim' => 'authorize', |
| 149 |
'aweber' => 'aweber', |
| 150 |
'bootstrap' => 'bootstrap', |
| 151 |
'bootstrap-modal' => 'bootstrap', |
| 152 |
'campaign-monitor' => 'campaignmonitor', |
| 153 |
'constant-contact' => 'constant_contact', |
| 154 |
'getresponse-wordpress-plugin' => 'getresponse', |
| 155 |
'google-sheets' => 'googlesheets', |
| 156 |
'highrise' => 'highrise', |
| 157 |
'hubspot-wordpress' => 'hubspot', |
| 158 |
'mailchimp' => 'mailchimp', |
| 159 |
'mailpoet-newsletters' => 'mailpoet', |
| 160 |
'paypal-standard' => 'paypal', |
| 161 |
'polylang' => 'polylang', |
| 162 |
'salesforce' => 'salesforcealt', |
| 163 |
'stripe' => 'stripealt', |
| 164 |
'twilio' => 'twilio', |
| 165 |
'woocommerce' => 'woocommerce', |
| 166 |
'zapier' => 'zapier', |
| 167 |
); |
| 168 |
|
| 169 |
$icon = array_key_exists( $slug, $icons_map ) ? 'frm_' . $icons_map[ $slug ] . '_icon' : 'frm_logo_icon'; |
| 170 |
if ( 'ai' === $slug ) { |
| 171 |
$icon = str_replace( '_', '-', $icon ); |
| 172 |
} |
| 173 |
|
| 174 |
FrmAppHelper::icon_by_class( 'frmfont ' . $icon ); |
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* Echo attributes for a given addon. |
| 179 |
* |
| 180 |
* @since 6.15 |
| 181 |
* |
| 182 |
* @param array $addon |
| 183 |
* @return void |
| 184 |
*/ |
| 185 |
public static function add_addon_attributes( $addon ) { |
| 186 |
self::set_plan_required( $addon ); |
| 187 |
|
| 188 |
$attributes = array( |
| 189 |
'tabindex' => '0', |
| 190 |
'frm-search-text' => strtolower( $addon['title'] . ' ' . esc_html( $addon['excerpt'] ) ), |
| 191 |
); |
| 192 |
|
| 193 |
// Set 'data-slug' attribute. |
| 194 |
if ( ! empty( $addon['slug'] ) ) { |
| 195 |
$attributes['data-slug'] = $addon['slug']; |
| 196 |
} |
| 197 |
|
| 198 |
// Set 'data-categories' attribute. |
| 199 |
if ( ! empty( $addon['category-slugs'] ) ) { |
| 200 |
$attributes['data-categories'] = implode( ',', $addon['category-slugs'] ); |
| 201 |
} |
| 202 |
|
| 203 |
$attributes['class'] = self::prepare_single_addon_classes( $addon ); |
| 204 |
|
| 205 |
FrmAppHelper::array_to_html_params( $attributes, true ); |
| 206 |
} |
| 207 |
|
| 208 |
/** |
| 209 |
* Add classes for a given addon. |
| 210 |
* |
| 211 |
* @since 6.15 |
| 212 |
* |
| 213 |
* @param array $addon |
| 214 |
* @return string |
| 215 |
*/ |
| 216 |
private static function prepare_single_addon_classes( $addon ) { |
| 217 |
$class_names = array( 'frm-card-item frm-flex-col' ); |
| 218 |
$class_names[] = 'plugin-card-' . $addon['slug']; |
| 219 |
$class_names[] = 'frm-addon-' . $addon['status']['type']; |
| 220 |
|
| 221 |
if ( self::is_locked() ) { |
| 222 |
$class_names[] = 'frm-locked-item'; |
| 223 |
} |
| 224 |
|
| 225 |
return implode( ' ', $class_names ); |
| 226 |
} |
| 227 |
|
| 228 |
/** |
| 229 |
* Check if a given addon is locked. |
| 230 |
* |
| 231 |
* @return bool |
| 232 |
*/ |
| 233 |
public static function is_locked() { |
| 234 |
return self::$plan_required || ! FrmAppHelper::pro_is_installed(); |
| 235 |
} |
| 236 |
|
| 237 |
/** |
| 238 |
* Set the required plan for the given addon. |
| 239 |
* |
| 240 |
* @note |
| 241 |
* Because the `FrmFormsHelper::get_plan_required` changes $addon by reference, |
| 242 |
* we save the result inside a static field called `$plan_required`. |
| 243 |
* |
| 244 |
* @since 6.15 |
| 245 |
* |
| 246 |
* @param array $addon The addon array that will be modified by reference. |
| 247 |
* @return void |
| 248 |
*/ |
| 249 |
private static function set_plan_required( $addon ) { |
| 250 |
self::$plan_required = FrmFormsHelper::get_plan_required( $addon ); |
| 251 |
} |
| 252 |
|
| 253 |
/** |
| 254 |
* Get the required plan. |
| 255 |
* |
| 256 |
* @since 6.15 |
| 257 |
* |
| 258 |
* @return false|string |
| 259 |
*/ |
| 260 |
public static function get_plan() { |
| 261 |
return self::$plan_required; |
| 262 |
} |
| 263 |
} |
| 264 |
|