| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn { |
| 4 |
if (!defined('ABSPATH')) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Class UIDashboard |
| 10 |
* |
| 11 |
* @package forge12\contactform7\CF7DoubleOptIn |
| 12 |
*/ |
| 13 |
class UIDashboard extends UIPage |
| 14 |
{ |
| 15 |
public function __construct($domain) |
| 16 |
{ |
| 17 |
parent::__construct($domain, 'f12-cf7-doubleoptin', 'Dashboard', 0); |
| 18 |
|
| 19 |
} |
| 20 |
|
| 21 |
public function getSettings($settings) |
| 22 |
{ |
| 23 |
return $settings; |
| 24 |
} |
| 25 |
|
| 26 |
protected function onSave($settings) |
| 27 |
{ |
| 28 |
return $settings; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Maybe delete an given entry. |
| 33 |
*/ |
| 34 |
private function maybeDelete() |
| 35 |
{ |
| 36 |
if (isset($_GET['option']) && $_GET['option'] == 'delete' && isset($_GET['hash']) && !empty($_GET['hash']) && current_user_can('manage_options')) { |
| 37 |
$hash = esc_attr($_GET['hash']); |
| 38 |
|
| 39 |
$CleanUp = new CleanUp(); |
| 40 |
|
| 41 |
if ($CleanUp->deleteByHash($hash)) { |
| 42 |
wp_redirect('admin.php?page=f12-cf7-doubleoptin&status=deleted'); |
| 43 |
wp_die(); |
| 44 |
} else { |
| 45 |
wp_redirect('admin.php?page=f12-cf7-doubleoptin&status=error'); |
| 46 |
wp_die(); |
| 47 |
} |
| 48 |
|
| 49 |
} else if (isset($_GET['status'])) { |
| 50 |
|
| 51 |
$status = $_GET['status']; |
| 52 |
if ($status == 'deleted') { |
| 53 |
Messages::getInstance()->add(__('The given DOI has been removed.', 'double-opt-in'), 'success'); |
| 54 |
} |
| 55 |
if ($status == 'error') { |
| 56 |
Messages::getInstance()->add(__('Couldn\'t delete the DOI, please try again later.', 'double-opt-in'), 'error'); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
public function theContent($slug, $page, $settings) |
| 62 |
{ |
| 63 |
// Check if there is a call to delete an specific entry |
| 64 |
$this->maybeDelete(); |
| 65 |
|
| 66 |
// Render the optins |
| 67 |
$this->renderLatestOptIns($slug, $page); |
| 68 |
} |
| 69 |
|
| 70 |
private function renderLatestOptins($slug, $page) |
| 71 |
{ |
| 72 |
$atts = array( |
| 73 |
'perPage' => 10, |
| 74 |
'page' => 1, |
| 75 |
'order' => 'DESC', |
| 76 |
'keyword' => '' |
| 77 |
); |
| 78 |
|
| 79 |
if(isset($_GET['perPage'])){ |
| 80 |
$atts['perPage'] = (int)$_GET['perPage']; |
| 81 |
} |
| 82 |
|
| 83 |
if (isset($_GET['pageNum'])) { |
| 84 |
$atts['page'] = (int)$_GET['pageNum']; |
| 85 |
} |
| 86 |
|
| 87 |
if(isset($_GET['keyword'])){ |
| 88 |
$atts['keyword'] = sanitize_text_field($_GET['keyword']); |
| 89 |
} |
| 90 |
|
| 91 |
if(isset($_GET['cf_form_id'])){ |
| 92 |
$atts['cf_form_id'] = (int)$_GET['cf_form_id']; |
| 93 |
} |
| 94 |
|
| 95 |
$numberOfPages = 0; |
| 96 |
$listOfOptIns = OptIn::get_list($atts, $numberOfPages); |
| 97 |
|
| 98 |
/* |
| 99 |
* Render the Template |
| 100 |
*/ |
| 101 |
?> |
| 102 |
<h1><?php _e('Latest Opt-ins', 'double-opt-in'); ?></h1> |
| 103 |
<?php |
| 104 |
|
| 105 |
CF7DoubleOptIn::getInstance()->renderTemplate('list-optins', array( |
| 106 |
'domain' => $this->domain, |
| 107 |
'listOfOptIns' => $listOfOptIns, |
| 108 |
'numberOfPages' => $numberOfPages, |
| 109 |
'currentPage' => $atts['page'], |
| 110 |
'slug' => $slug |
| 111 |
)); |
| 112 |
} |
| 113 |
|
| 114 |
public function theSidebar($slug, $page) |
| 115 |
{ |
| 116 |
?> |
| 117 |
<div class="box"> |
| 118 |
<h2> |
| 119 |
<?php _e('Hint:', 'double-opt-in'); ?> |
| 120 |
</h2> |
| 121 |
<p> |
| 122 |
<?php _e("In the table on the left side, you'll find an list containing all Opt-Ins and the required information from your customers. Click on the hash to open aditional informations about the form and the user data. All unconfirmed opt-ins will be deleted after 7 days.", 'double-opt-in'); ?> |
| 123 |
</p> |
| 124 |
</div> |
| 125 |
<div class="box"> |
| 126 |
<h2> |
| 127 |
<?php _e('Hooks:', 'double-opt-in'); ?> |
| 128 |
</h2> |
| 129 |
<p> |
| 130 |
<?php _e("You can use the following hooks to adjust the Opt-In to your requirements.", 'double-opt-in'); ?> |
| 131 |
</p> |
| 132 |
<p> |
| 133 |
<strong><?php _e("An Opt-in link has been called which is already confirmed or has been deleted.", 'double-opt-in'); ?></strong> |
| 134 |
</p> |
| 135 |
<div class="option"> |
| 136 |
<div class="input"> |
| 137 |
<p> |
| 138 |
add_action('f12_cf7_doubleoptin_already_confirmed', $hash, $OptIn) |
| 139 |
<br> |
| 140 |
</p> |
| 141 |
</div> |
| 142 |
</div> |
| 143 |
|
| 144 |
<p> |
| 145 |
<strong><?php _e("An Opt-in link has been called but not yet updated the database.", 'double-opt-in'); ?></strong> |
| 146 |
</p> |
| 147 |
<div class="option"> |
| 148 |
<div class="input"> |
| 149 |
<p> |
| 150 |
add_action('f12_cf7_doubleoptin_before_confirm', $hash, $OptIn) |
| 151 |
<br> |
| 152 |
</p> |
| 153 |
</div> |
| 154 |
</div> |
| 155 |
|
| 156 |
<p> |
| 157 |
<strong><?php _e("An Opt-in link has been called and the database has been updated already.", 'double-opt-in'); ?></strong> |
| 158 |
</p> |
| 159 |
<div class="option"> |
| 160 |
<div class="input"> |
| 161 |
<p> |
| 162 |
add_action('f12_cf7_doubleoptin_after_confirm', $hash, $OptIn) |
| 163 |
</p> |
| 164 |
</div> |
| 165 |
</div> |
| 166 |
|
| 167 |
</div> |
| 168 |
<?php |
| 169 |
} |
| 170 |
} |
| 171 |
} |