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