| 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 |
'class' => 'frm-gradient', |
| 57 |
'icon' => 'frmfont frm_speaker_icon', |
| 58 |
'title' => esc_html__( 'Unlock Add-on library', 'formidable' ), |
| 59 |
'description' => esc_html__( 'Renew your subscription today and access our library of add-ons to supercharge your forms.', 'formidable' ), |
| 60 |
'link_text' => esc_html__( 'Renew Now', 'formidable' ), |
| 61 |
'link_url' => FrmAddonsController::is_license_expired(), |
| 62 |
'id' => 'frm-renew-subscription-banner', |
| 63 |
) |
| 64 |
); |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Show 'Upgrade to Pro' banner for users not connected to Pro. |
| 69 |
* |
| 70 |
* @since 6.15 |
| 71 |
* @return void |
| 72 |
*/ |
| 73 |
private static function show_lite_cta() { |
| 74 |
FrmTipsHelper::show_admin_cta( |
| 75 |
array( |
| 76 |
'class' => 'frm-gradient', |
| 77 |
'icon' => 'frmfont frm_speaker_icon', |
| 78 |
'title' => esc_html__( 'Unlock Add-on library', 'formidable' ), |
| 79 |
'description' => esc_html__( 'Upgrade to Pro and access our library of add-ons to supercharge your forms.', 'formidable' ), |
| 80 |
'link_text' => esc_html__( 'Upgrade to PRO', 'formidable' ), |
| 81 |
'link_url' => FrmAppHelper::admin_upgrade_link( |
| 82 |
array( |
| 83 |
'medium' => 'addons', |
| 84 |
'content' => 'upgrade-cta', |
| 85 |
) |
| 86 |
), |
| 87 |
'id' => 'frm-upgrade-banner', |
| 88 |
) |
| 89 |
); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Show 'Upgrade' banner for non-elite users. |
| 94 |
* |
| 95 |
* @since 6.15 |
| 96 |
* @return void |
| 97 |
*/ |
| 98 |
private static function show_elite_cta() { |
| 99 |
FrmTipsHelper::show_admin_cta( |
| 100 |
array( |
| 101 |
'title' => esc_html__( 'Unlock Even More Add-ons', 'formidable' ), |
| 102 |
'description' => sprintf( |
| 103 |
/* translators: %1$s: Open span tag, %2$s: Close span tag */ |
| 104 |
esc_html__( 'Your plan includes %1$s%2$s add-ons. Upgrade to take your forms even farther', 'formidable' ), |
| 105 |
'<span class="frm-addons-available-count">', |
| 106 |
'</span>' |
| 107 |
), |
| 108 |
'link_text' => esc_html__( 'Upgrade to PRO', 'formidable' ), |
| 109 |
'link_url' => FrmAppHelper::admin_upgrade_link( |
| 110 |
array( |
| 111 |
'medium' => 'addons', |
| 112 |
'content' => 'upgrade-cta', |
| 113 |
) |
| 114 |
), |
| 115 |
'id' => 'frm-upgrade-banner', |
| 116 |
) |
| 117 |
); |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Displays a reconnect link for checking add-ons status. |
| 122 |
* |
| 123 |
* @since 6.15 |
| 124 |
* @return void |
| 125 |
*/ |
| 126 |
public static function get_reconnect_link() { |
| 127 |
if ( ! FrmAppHelper::pro_is_connected() ) { |
| 128 |
return; |
| 129 |
} |
| 130 |
?> |
| 131 |
<p class="frm-py-2xs"> |
| 132 |
<span class="frm-font-medium frm-text-grey-700"><?php esc_html_e( 'Missing add-ons?', 'formidable' ); ?></span> |
| 133 |
<a href="#" id="frm_reconnect_link" class="frm-show-authorized frm-font-semibold" data-refresh="1"> |
| 134 |
<?php esc_html_e( 'Check now for a recent upgrade or renewal', 'formidable' ); ?> |
| 135 |
</a> |
| 136 |
</p> |
| 137 |
<?php |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Get the icon for a specific addon. |
| 142 |
* |
| 143 |
* @since 6.15 |
| 144 |
* @param string $slug The slug of the addon. |
| 145 |
* @return void |
| 146 |
*/ |
| 147 |
public static function get_addon_icon( $slug ) { |
| 148 |
$icons_map = array( |
| 149 |
'acf-forms' => 'acfforms', |
| 150 |
'activecampaign-wordpress-plugin' => 'activecampaign', |
| 151 |
'ai' => 'ai-form', |
| 152 |
'authorize-net-aim' => 'authorize', |
| 153 |
'aweber' => 'aweber', |
| 154 |
'bootstrap' => 'bootstrap', |
| 155 |
'bootstrap-modal' => 'bootstrap', |
| 156 |
'campaign-monitor' => 'campaignmonitor', |
| 157 |
'constant-contact' => 'constant_contact', |
| 158 |
'getresponse-wordpress-plugin' => 'getresponse', |
| 159 |
'google-sheets' => 'googlesheets', |
| 160 |
'highrise' => 'highrise', |
| 161 |
'hubspot-wordpress' => 'hubspot', |
| 162 |
'mailchimp' => 'mailchimp', |
| 163 |
'mailpoet-newsletters' => 'mailpoet', |
| 164 |
'paypal-standard' => 'paypal', |
| 165 |
'polylang' => 'polylang', |
| 166 |
'salesforce' => 'salesforcealt', |
| 167 |
'stripe' => 'stripealt', |
| 168 |
'twilio' => 'twilio', |
| 169 |
'woocommerce' => 'woocommerce', |
| 170 |
'zapier' => 'zapier', |
| 171 |
'convertkit' => 'convertkit', |
| 172 |
); |
| 173 |
|
| 174 |
$icon = array_key_exists( $slug, $icons_map ) ? 'frm_' . $icons_map[ $slug ] . '_icon' : 'frm_logo_icon'; |
| 175 |
if ( 'ai' === $slug ) { |
| 176 |
$icon = str_replace( '_', '-', $icon ); |
| 177 |
} |
| 178 |
|
| 179 |
FrmAppHelper::icon_by_class( 'frmfont ' . $icon ); |
| 180 |
} |
| 181 |
|
| 182 |
/** |
| 183 |
* Echo attributes for a given addon. |
| 184 |
* |
| 185 |
* @since 6.15 |
| 186 |
* |
| 187 |
* @param array $addon |
| 188 |
* @return void |
| 189 |
*/ |
| 190 |
public static function add_addon_attributes( $addon ) { |
| 191 |
self::set_plan_required( $addon ); |
| 192 |
|
| 193 |
$attributes = array( |
| 194 |
'tabindex' => '0', |
| 195 |
'frm-search-text' => strtolower( $addon['title'] . ' ' . esc_html( $addon['excerpt'] ) ), |
| 196 |
); |
| 197 |
|
| 198 |
// Set 'data-slug' attribute. |
| 199 |
if ( ! empty( $addon['slug'] ) ) { |
| 200 |
$attributes['data-slug'] = $addon['slug']; |
| 201 |
} |
| 202 |
|
| 203 |
// Set 'data-categories' attribute. |
| 204 |
if ( ! empty( $addon['category-slugs'] ) ) { |
| 205 |
$attributes['data-categories'] = implode( ',', $addon['category-slugs'] ); |
| 206 |
} |
| 207 |
|
| 208 |
$attributes['class'] = self::prepare_single_addon_classes( $addon ); |
| 209 |
|
| 210 |
FrmAppHelper::array_to_html_params( $attributes, true ); |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* Add classes for a given addon. |
| 215 |
* |
| 216 |
* @since 6.15 |
| 217 |
* |
| 218 |
* @param array $addon |
| 219 |
* @return string |
| 220 |
*/ |
| 221 |
private static function prepare_single_addon_classes( $addon ) { |
| 222 |
$class_names = array( 'frm-card-item frm-flex-col' ); |
| 223 |
$class_names[] = 'plugin-card-' . $addon['slug']; |
| 224 |
$class_names[] = 'frm-addon-' . $addon['status']['type']; |
| 225 |
|
| 226 |
if ( self::is_locked() ) { |
| 227 |
$class_names[] = 'frm-locked-item'; |
| 228 |
} |
| 229 |
|
| 230 |
return implode( ' ', $class_names ); |
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* Check if a given addon is locked. |
| 235 |
* |
| 236 |
* @return bool |
| 237 |
*/ |
| 238 |
public static function is_locked() { |
| 239 |
return self::$plan_required || ! FrmAppHelper::pro_is_installed(); |
| 240 |
} |
| 241 |
|
| 242 |
/** |
| 243 |
* Set the required plan for the given addon. |
| 244 |
* |
| 245 |
* @note |
| 246 |
* Because the `FrmFormsHelper::get_plan_required` changes $addon by reference, |
| 247 |
* we save the result inside a static field called `$plan_required`. |
| 248 |
* |
| 249 |
* @since 6.15 |
| 250 |
* |
| 251 |
* @param array $addon The addon array that will be modified by reference. |
| 252 |
* @return void |
| 253 |
*/ |
| 254 |
private static function set_plan_required( $addon ) { |
| 255 |
self::$plan_required = FrmFormsHelper::get_plan_required( $addon ); |
| 256 |
} |
| 257 |
|
| 258 |
/** |
| 259 |
* Get the required plan. |
| 260 |
* |
| 261 |
* @since 6.15 |
| 262 |
* |
| 263 |
* @return false|string |
| 264 |
*/ |
| 265 |
public static function get_plan() { |
| 266 |
return self::$plan_required; |
| 267 |
} |
| 268 |
|
| 269 |
/** |
| 270 |
* Shows five star rating, used on Views page if only Lite plugins are installed. |
| 271 |
* |
| 272 |
* @since 6.17 |
| 273 |
* |
| 274 |
* @param string $color Star color. |
| 275 |
* @return void |
| 276 |
*/ |
| 277 |
public static function show_five_star_rating( $color = 'black' ) { |
| 278 |
$icon = file_get_contents( FrmAppHelper::plugin_path() . '/images/star.svg' ); |
| 279 |
?> |
| 280 |
<span style="color: <?php echo esc_attr( $color ); ?>;"> |
| 281 |
<?php |
| 282 |
for ( $i = 0; $i < 5; $i++ ) { |
| 283 |
echo $icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 284 |
} |
| 285 |
?> |
| 286 |
</span> |
| 287 |
<?php |
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* Shows the guarantee icon. |
| 292 |
* |
| 293 |
* @since 6.17 |
| 294 |
* |
| 295 |
* @return void |
| 296 |
*/ |
| 297 |
public static function guarantee_icon() { |
| 298 |
?> |
| 299 |
<img src="<?php echo esc_url( FrmAppHelper::plugin_url() . '/images/guarantee.svg' ); ?>" alt="" /> |
| 300 |
<?php |
| 301 |
} |
| 302 |
|
| 303 |
/** |
| 304 |
* Gets reviews text. |
| 305 |
* |
| 306 |
* @since 6.17 |
| 307 |
* |
| 308 |
* @param string $count Review count. |
| 309 |
* @param string $site Site name. |
| 310 |
* @return string |
| 311 |
*/ |
| 312 |
public static function get_reviews_text( $count, $site ) { |
| 313 |
return sprintf( |
| 314 |
// Translators: %1$s is the number of reviews, %2$s is the site name. |
| 315 |
__( 'Based on %1$s reviews on %2$s', 'formidable' ), |
| 316 |
$count, |
| 317 |
$site |
| 318 |
); |
| 319 |
} |
| 320 |
} |
| 321 |
|