| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn { |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Class Ajax |
| 10 |
* Responsible to handle the admin settings for the double opt-in field |
| 11 |
* |
| 12 |
* @package forge12\contactform7\CF7OptIn |
| 13 |
*/ |
| 14 |
class Ajax { |
| 15 |
/** |
| 16 |
* Admin constructor. |
| 17 |
*/ |
| 18 |
public function __construct() { |
| 19 |
add_action( 'wp_ajax_f12_doi_details', array( $this, 'getDetails' ) ); |
| 20 |
add_action( 'wp_ajax_f12_doi_templateloader', array( $this, 'getTemplate' ) ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Load and get the template we need. |
| 25 |
*/ |
| 26 |
public function getTemplate() { |
| 27 |
$content = ''; |
| 28 |
if ( isset( $_POST['template'] ) && wp_verify_nonce( $_POST['nonce'], 'f12_doi_templateloader' ) ) { |
| 29 |
$template_path = plugin_dir_path( dirname( __FILE__ ) ) . 'mails/' . esc_attr( sanitize_text_field( $_POST['template'] ) ) . '.html'; |
| 30 |
|
| 31 |
if ( file_exists( $template_path ) ) { |
| 32 |
$content = file_get_contents( $template_path ); |
| 33 |
} |
| 34 |
|
| 35 |
} |
| 36 |
echo wp_json_encode( [ 'status' => 200, 'content' => $content ] ); |
| 37 |
wp_die(); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Return the Popup for the HASH DOI |
| 42 |
*/ |
| 43 |
public function getDetails() { |
| 44 |
if ( isset( $_POST['hash'] ) && wp_verify_nonce( $_POST['nonce'], 'f12_doi_details' ) ) { |
| 45 |
global $wpdb; |
| 46 |
$tableName = $wpdb->prefix . 'f12_cf7_doubleoptin'; |
| 47 |
$hash = sanitize_text_field( $_POST['hash'] ); |
| 48 |
|
| 49 |
$OptIn = OptIn::get_by_hash( $hash ); |
| 50 |
|
| 51 |
if ( null == $OptIn ) { |
| 52 |
ob_start(); |
| 53 |
?> |
| 54 |
<h2><?php _e( 'Ooops!', 'double-opt-in' ); ?></h2> |
| 55 |
<p> |
| 56 |
<?php _e( 'Something went wrong. The given DOI wasn\'t found. Maybe it got removed?', 'double-opt-in' ); ?> |
| 57 |
</p> |
| 58 |
<?php |
| 59 |
$content = ob_get_contents(); |
| 60 |
ob_end_clean(); |
| 61 |
echo wp_json_encode( [ 'status' => 200, 'content' => $content ] ); |
| 62 |
wp_die(); |
| 63 |
} |
| 64 |
|
| 65 |
$formfields = maybe_unserialize( $OptIn->get_content() ); |
| 66 |
ob_start(); |
| 67 |
?> |
| 68 |
<h2><?php echo esc_html( $OptIn->get_hash() ); ?></h2> |
| 69 |
<?php if ( current_user_can( 'manage_options' ) ): ?> |
| 70 |
<div class="options"> |
| 71 |
<?php |
| 72 |
/** |
| 73 |
* Opt-in View Options |
| 74 |
* |
| 75 |
* This action is used to extend the options for the pro version. |
| 76 |
* |
| 77 |
* @param \forge12\contactform7\CF7DoubleOptIn\OptIn $OptIn |
| 78 |
* |
| 79 |
* @since 3.0.0 |
| 80 |
*/ |
| 81 |
do_action( 'f12_cf7_doubleoptin_ui_view_optin_options', $OptIn ); |
| 82 |
?> |
| 83 |
<a class="button" |
| 84 |
href="<?php echo esc_url( $OptIn->get_link_delete() ); ?>"><?php _e( 'Delete DOI', 'double-opt-in' ); ?></a> |
| 85 |
<a class="button" |
| 86 |
href="<?php echo esc_url( $OptIn->get_link_ui() ); ?>"><?php _e( 'Details', 'double-opt-in' ); ?></a> |
| 87 |
</div> |
| 88 |
<?php endif; ?> |
| 89 |
<table> |
| 90 |
<tr> |
| 91 |
<td><?php _e( 'Key', 'double-opt-in' ); ?></td> |
| 92 |
<td><?php _e( 'Value', 'double-opt-in' ); ?></td> |
| 93 |
</tr> |
| 94 |
<tr> |
| 95 |
<td> |
| 96 |
<?php _e( 'ID', 'f12-cf7-doupleoptin' ); ?> |
| 97 |
</td> |
| 98 |
<td> |
| 99 |
<?php echo esc_html( $OptIn->get_id() ); ?> |
| 100 |
</td> |
| 101 |
</tr> |
| 102 |
<tr> |
| 103 |
<td> |
| 104 |
<?php _e( 'CF7 Form ID', 'double-opt-in' ); ?> |
| 105 |
</td> |
| 106 |
<td> |
| 107 |
<?php echo esc_html( $OptIn->get_cf_form_id() ); ?> |
| 108 |
</td> |
| 109 |
</tr> |
| 110 |
<tr> |
| 111 |
<td> |
| 112 |
<?php _e( 'Registration Date', 'double-opt-in' ); ?> |
| 113 |
</td> |
| 114 |
<td> |
| 115 |
<?php |
| 116 |
echo esc_html( $OptIn->get_createtime( 'formatted' ) ); |
| 117 |
?> |
| 118 |
</td> |
| 119 |
</tr> |
| 120 |
<tr> |
| 121 |
<td> |
| 122 |
<?php _e( 'Registration IP', 'double-opt-in' ); ?> |
| 123 |
</td> |
| 124 |
<td> |
| 125 |
<?php echo esc_html( $OptIn->get_ipaddr_register() ); ?> |
| 126 |
</td> |
| 127 |
</tr> |
| 128 |
<tr> |
| 129 |
<td> |
| 130 |
<?php _e( 'Confirmation Date', 'double-opt-in' ); ?> |
| 131 |
</td> |
| 132 |
<td> |
| 133 |
<?php |
| 134 |
if ( $OptIn->is_confirmed() ) { |
| 135 |
echo esc_html( $OptIn->get_updatetime( 'formatted' ) ); |
| 136 |
} |
| 137 |
?> |
| 138 |
</td> |
| 139 |
</tr> |
| 140 |
<tr> |
| 141 |
<td> |
| 142 |
<?php _e( 'Confirmation IP', 'double-opt-in' ); ?> |
| 143 |
</td> |
| 144 |
<td> |
| 145 |
<?php |
| 146 |
echo esc_html( $OptIn->get_ipaddr_confirmation() ); |
| 147 |
?> |
| 148 |
</td> |
| 149 |
</tr> |
| 150 |
</table> |
| 151 |
|
| 152 |
<h3><?php _e( 'Form Fields', 'double-opt-in' ); ?></h3> |
| 153 |
<table> |
| 154 |
<tr> |
| 155 |
<td><?php _e( 'Key', 'double-opt-in' ); ?></td> |
| 156 |
<td><?php _e( 'Value', 'double-opt-in' ); ?></td> |
| 157 |
</tr> |
| 158 |
<?php if ( isset( $formfields['fields'] ) ): ?> |
| 159 |
<?php foreach ( $formfields['fields'] as $key => $value ): ?> |
| 160 |
<tr> |
| 161 |
<td> |
| 162 |
<?php esc_attr_e( $key ); ?> |
| 163 |
</td> |
| 164 |
<td> |
| 165 |
<?php if ( is_array( $value ) ) { |
| 166 |
echo esc_html( implode( ',', $value ) ); |
| 167 |
} else { |
| 168 |
echo esc_html( $value ); |
| 169 |
} |
| 170 |
?> |
| 171 |
</td> |
| 172 |
</tr> |
| 173 |
<?php endforeach; ?> |
| 174 |
<?php else: ?> |
| 175 |
<?php foreach ( $formfields as $key => $value ): ?> |
| 176 |
<tr> |
| 177 |
<td> |
| 178 |
<?php esc_attr_e( $key ); ?> |
| 179 |
</td> |
| 180 |
<td> |
| 181 |
<?php if ( is_array( $value ) ) { |
| 182 |
echo esc_html( implode( ',', $value ) ); |
| 183 |
} else { |
| 184 |
echo esc_html( $value ); |
| 185 |
} |
| 186 |
?> |
| 187 |
</td> |
| 188 |
</tr> |
| 189 |
<?php endforeach; ?> |
| 190 |
<?php endif; ?> |
| 191 |
</table> |
| 192 |
<?php |
| 193 |
$content = ob_get_contents(); |
| 194 |
ob_end_clean(); |
| 195 |
echo wp_json_encode( [ 'status' => 200, 'content' => $content ] ); |
| 196 |
exit; |
| 197 |
} |
| 198 |
wp_die( 0 ); |
| 199 |
} |
| 200 |
|
| 201 |
/** |
| 202 |
* Add the styles for the form |
| 203 |
*/ |
| 204 |
public function addStyles( $hook ) { |
| 205 |
if ( $hook == 'tools_page_f12doubleoptin' ) { |
| 206 |
wp_enqueue_style( 'f12-cf7-doubleoptin-admin', plugins_url( 'assets/admin-style.css', __FILE__ ) ); |
| 207 |
wp_enqueue_script( 'f12-cf7-doubleoptin-admin', plugins_url( 'assets/f12-cf7-popup.js', __FILE__ ), array( 'jquery' ) ); |
| 208 |
} |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
new Ajax(); |
| 213 |
} |