| 1 |
<?php |
| 2 |
/** |
| 3 |
* Deactivation feedback controller |
| 4 |
* |
| 5 |
* @package Formidable |
| 6 |
* @since 6.15 |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
die( 'You are not allowed to call this page directly.' ); |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Class FrmDeactivationFeedbackController |
| 15 |
*/ |
| 16 |
class FrmDeactivationFeedbackController { |
| 17 |
|
| 18 |
/** |
| 19 |
* Checks if is plugins page. |
| 20 |
* |
| 21 |
* @return bool |
| 22 |
*/ |
| 23 |
private static function is_plugins_page() { |
| 24 |
return 'plugins' === get_current_screen()->id; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Checks if feedback is expired. |
| 29 |
* |
| 30 |
* @return bool |
| 31 |
*/ |
| 32 |
private static function feedback_is_expired() { |
| 33 |
$feedback_expired = get_option( 'frm_feedback_expired' ); |
| 34 |
if ( ! $feedback_expired ) { |
| 35 |
return true; |
| 36 |
} |
| 37 |
|
| 38 |
$expired_date = strtotime( $feedback_expired ); |
| 39 |
if ( ! $expired_date ) { |
| 40 |
return true; |
| 41 |
} |
| 42 |
|
| 43 |
return $expired_date < time(); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Sets feedback expired date. |
| 48 |
* |
| 49 |
* @param string $plugin Path to the plugin file relative to the plugins directory. |
| 50 |
* |
| 51 |
* @return void |
| 52 |
*/ |
| 53 |
public static function set_feedback_expired_date( $plugin ) { |
| 54 |
if ( empty( $_GET['frm_feedback_submitted'] ) ) { |
| 55 |
return; |
| 56 |
} |
| 57 |
if ( ! strpos( $plugin, 'formidable.php' ) && ! strpos( $plugin, 'formidable-pro.php' ) ) { |
| 58 |
return; |
| 59 |
} |
| 60 |
update_option( 'frm_feedback_expired', gmdate( 'Y-m-d', strtotime( '+ 1 day' ) ) ); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Enqueues assets. |
| 65 |
* |
| 66 |
* @return void |
| 67 |
*/ |
| 68 |
public static function enqueue_assets() { |
| 69 |
if ( ! self::is_plugins_page() || ! self::feedback_is_expired() ) { |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
wp_enqueue_script( |
| 74 |
'frm-deactivation-feedback', |
| 75 |
FrmAppHelper::plugin_url() . '/js/admin/deactivation-feedback.js', |
| 76 |
array( 'formidable', 'formidable_dom', 'jquery' ), |
| 77 |
FrmAppHelper::plugin_version(), |
| 78 |
true |
| 79 |
); |
| 80 |
|
| 81 |
wp_enqueue_style( 'formidable-admin' ); |
| 82 |
|
| 83 |
wp_enqueue_style( |
| 84 |
'frm-deactivation-feedback', |
| 85 |
FrmAppHelper::plugin_url() . '/css/admin/deactivation-feedback.css', |
| 86 |
array( 'formidable-admin' ), |
| 87 |
FrmAppHelper::plugin_version() |
| 88 |
); |
| 89 |
|
| 90 |
FrmAppHelper::localize_script( 'front' ); |
| 91 |
|
| 92 |
wp_localize_script( |
| 93 |
'frm-deactivation-feedback', |
| 94 |
'FrmDeactivationFeedbackI18n', |
| 95 |
array( |
| 96 |
'skip_text' => __( 'Skip & Deactivate', 'formidable' ), |
| 97 |
) |
| 98 |
); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Prints footer HTML. |
| 103 |
* |
| 104 |
* @return void |
| 105 |
*/ |
| 106 |
public static function footer_html() { |
| 107 |
if ( ! self::is_plugins_page() || ! self::feedback_is_expired() ) { |
| 108 |
return; |
| 109 |
} |
| 110 |
?> |
| 111 |
<div id="frm-deactivation-modal" class=""> |
| 112 |
<div class="metabox-holder"> |
| 113 |
<div class="postbox"> |
| 114 |
<a class="frm-modal-close dismiss" title="<?php esc_attr_e( 'Close', 'formidable' ); ?>"> |
| 115 |
<svg class="frmsvg" id="frm_close_icon" viewBox="0 0 20 20" width="18px" height="18px" aria-label="<?php esc_attr_e( 'Close', 'formidable' ); ?>"> |
| 116 |
<path d="M16.8 4.5l-1.3-1.3L10 8.6 4.5 3.2 3.2 4.5 8.6 10l-5.4 5.5 1.3 1.3 5.5-5.4 5.5 5.4 1.3-1.3-5.4-5.5 5.4-5.5z"/> |
| 117 |
</svg> |
| 118 |
</a> |
| 119 |
|
| 120 |
<div class="inside"> |
| 121 |
<img id="frm-deactivation-modal-icon" class="frmsvg" src="<?php echo esc_url( FrmAppHelper::plugin_url() . '/images/logo.svg' ); ?>" alt="" /> |
| 122 |
<div id="frm-deactivation-form-wrapper" class="frmapi-form"> |
| 123 |
<span class="frm-wait frm_visible_spinner"></span> |
| 124 |
</div> |
| 125 |
</div> |
| 126 |
</div> |
| 127 |
</div> |
| 128 |
</div><!-- End #frm-deactivation-popup --> |
| 129 |
<?php |
| 130 |
} |
| 131 |
} |
| 132 |
|