| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn { |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Class UIOptinView |
| 10 |
* Show a specific OptIn |
| 11 |
* |
| 12 |
* @package forge12\contactform7\CF7DoubleOptIn |
| 13 |
*/ |
| 14 |
class UIOptinView extends UIPage { |
| 15 |
/** |
| 16 |
* Class constructor. |
| 17 |
* |
| 18 |
* @param TemplateHandler $templateHandler The template handler object. |
| 19 |
* @param string $domain The domain of the class. |
| 20 |
* |
| 21 |
* @return void |
| 22 |
*/ |
| 23 |
public function __construct( TemplateHandler $templateHandler, string $domain ) { |
| 24 |
parent::__construct( $templateHandler, $domain, 'optin_view', __( 'OptIn View', 'double-opt-in' ) ); |
| 25 |
|
| 26 |
if ( isset( $_GET['status'] ) ) { |
| 27 |
$status = sanitize_text_field( $_GET['status'] ); |
| 28 |
|
| 29 |
switch ( $status ) { |
| 30 |
case 'deleted': |
| 31 |
Messages::getInstance()->add( __( 'Opt-In deleted', 'double-opt-in' ), 'success' ); |
| 32 |
break; |
| 33 |
case 'not-deleted': |
| 34 |
Messages::getInstance()->add( __( 'Opt-In not-deleted', 'double-opt-in' ), 'error' ); |
| 35 |
break; |
| 36 |
default: |
| 37 |
break; |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Hide this page in the menu. |
| 44 |
* |
| 45 |
* @return bool |
| 46 |
*/ |
| 47 |
public function hideInMenu() { |
| 48 |
return true; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Render the license subpage content |
| 53 |
*/ |
| 54 |
protected function theContent( $slug, $page, $settings ) { |
| 55 |
/* |
| 56 |
* Ensure that the hash is given |
| 57 |
*/ |
| 58 |
if ( ! isset( $_GET['hash'] ) ) { |
| 59 |
wp_redirect( admin_url( 'admin.php' ) . '?page=f12-cf7-doubleoptin' ); |
| 60 |
} |
| 61 |
|
| 62 |
$this->maybeSave(); |
| 63 |
|
| 64 |
|
| 65 |
$hash = sanitize_text_field( $_GET['hash'] ); |
| 66 |
|
| 67 |
/* |
| 68 |
* Load the assigned Category |
| 69 |
*/ |
| 70 |
$Optin = Optin::get_by_hash( $hash ); |
| 71 |
|
| 72 |
if ( null === $Optin ) { |
| 73 |
wp_redirect( admin_url( 'admin.php' ) . '?page=f12-cf7-doubleoptin' ); |
| 74 |
} |
| 75 |
|
| 76 |
/* |
| 77 |
* Render the Template |
| 78 |
*/ |
| 79 |
?> |
| 80 |
<h2><?php _e( 'Opt-In: ', 'double-opt-in' ) . esc_attr_e( $Optin->get_hash() ); ?></h2> |
| 81 |
<?php |
| 82 |
$this->TemplateHandler->renderTemplate( 'view-optin', array( |
| 83 |
'domain' => $this->domain, |
| 84 |
'optin' => $Optin |
| 85 |
) ); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Update the Optin if the category has been submitted. |
| 90 |
* |
| 91 |
* @return void |
| 92 |
*/ |
| 93 |
private function maybeSave() { |
| 94 |
if ( ! isset( $_POST['hash'] ) || ! wp_verify_nonce( $_POST['doi_settings_nonce'], 'doi_settings_action' ) ) { |
| 95 |
return; |
| 96 |
} |
| 97 |
|
| 98 |
$category = (int) $_POST['category']; |
| 99 |
$hash = sanitize_text_field( $_POST['hash'] ); |
| 100 |
|
| 101 |
|
| 102 |
if ( ! $category ) { |
| 103 |
return; |
| 104 |
} |
| 105 |
|
| 106 |
$Optin = OptIn::get_by_hash( $hash ); |
| 107 |
$Optin->set_category( $category ); |
| 108 |
$Optin->save(); |
| 109 |
} |
| 110 |
|
| 111 |
protected function theSidebar( $slug, $page ) { |
| 112 |
/* |
| 113 |
* Ensure that the ID for the Categorie is set |
| 114 |
*/ |
| 115 |
if ( ! isset( $_GET['hash'] ) ) { |
| 116 |
wp_redirect( admin_url( 'admin.php' ) . '?page=f12-cf7-doubleoptin' ); |
| 117 |
} |
| 118 |
|
| 119 |
$hash = sanitize_text_field( $_GET['hash'] ); |
| 120 |
|
| 121 |
/* |
| 122 |
* Load the OptIn |
| 123 |
*/ |
| 124 |
$Optin = OptIn::get_by_hash( $hash ); |
| 125 |
|
| 126 |
if ( ! $Optin ) { |
| 127 |
wp_redirect( admin_url( 'admin.php' ) . '?page=f12-cf7-doubleoptin' ); |
| 128 |
} |
| 129 |
?> |
| 130 |
<div class="box"> |
| 131 |
<h2> |
| 132 |
<?php _e( 'Edit Opt-In:', 'double-opt-in' ); ?> |
| 133 |
</h2> |
| 134 |
|
| 135 |
<form action="" method="post"> |
| 136 |
<div class="option"> |
| 137 |
<div class="label"> |
| 138 |
<label for="category"><?php _e( 'Category:', 'double-opt-in' ); ?></label> |
| 139 |
</div> |
| 140 |
<input type="hidden" value="<?php esc_attr_e( $Optin->get_hash() ); ?>" name="hash"/> |
| 141 |
<div class="input"> |
| 142 |
<?php |
| 143 |
echo wp_kses( CategoryOptions::getInstance()->select_category( $Optin->get_category() ), array( |
| 144 |
'select' => array( 'name' => array() ), |
| 145 |
'option' => array( |
| 146 |
'value' => array(), |
| 147 |
'selected' => array() |
| 148 |
) |
| 149 |
) ); |
| 150 |
?> |
| 151 |
<p> |
| 152 |
<?php _e( 'Select the category to assign the Opt-In.', 'double-opt-in' ); ?> |
| 153 |
</p> |
| 154 |
</div> |
| 155 |
</div> |
| 156 |
<?php |
| 157 |
wp_nonce_field( 'doi_settings_action', 'doi_settings_nonce' ); |
| 158 |
?> |
| 159 |
|
| 160 |
<input type="submit" name="doubleoptin-settings-edit-submit" class="button" |
| 161 |
value=" <?php _e( 'Update', 'double-opt-in' ); ?>"/> |
| 162 |
</form> |
| 163 |
</div> |
| 164 |
|
| 165 |
<div class="box"> |
| 166 |
<h2> |
| 167 |
<?php _e( 'Opt-In:', 'double-opt-in' ); ?> |
| 168 |
</h2> |
| 169 |
|
| 170 |
<div class="option"> |
| 171 |
<div class="label"> |
| 172 |
<label for="category"><?php _e( 'Link:', 'double-opt-in' ); ?></label> |
| 173 |
</div> |
| 174 |
<div class="input copy-to-clipboard"> |
| 175 |
<?php |
| 176 |
echo $Optin->get_link_optin(); |
| 177 |
?> |
| 178 |
</div> |
| 179 |
</div> |
| 180 |
|
| 181 |
</div> |
| 182 |
|
| 183 |
|
| 184 |
<?php |
| 185 |
|
| 186 |
/** |
| 187 |
* Sidebar |
| 188 |
* |
| 189 |
* This Hook allows us to extend the sidebar for the pro version. |
| 190 |
* |
| 191 |
* @param OptIn $Optin |
| 192 |
* |
| 193 |
* @since 3.0.0 |
| 194 |
*/ |
| 195 |
do_action( 'f12_cf7_doubleoptin_ui_view_optin_sidebar', $Optin ); |
| 196 |
} |
| 197 |
|
| 198 |
public function getSettings( $settings ) { |
| 199 |
return $settings; |
| 200 |
} |
| 201 |
} |
| 202 |
} |