| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn { |
| 4 |
if (!defined('ABSPATH')) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Class UICategories |
| 10 |
* Show the Category and Assigned DOIs |
| 11 |
* |
| 12 |
* @package forge12\contactform7\CF7DoubleOptIn |
| 13 |
*/ |
| 14 |
class UICategoriesView extends UIPage |
| 15 |
{ |
| 16 |
public function __construct($domain) |
| 17 |
{ |
| 18 |
parent::__construct($domain, 'categories_view', 'Category View'); |
| 19 |
|
| 20 |
add_action('admin_init', array($this, 'maybeUpdateCategory')); |
| 21 |
} |
| 22 |
|
| 23 |
public function maybeUpdateCategory(){ |
| 24 |
if(isset($_POST['doi_settings_nonce']) && !wp_verify_nonce($_POST['doi_settings_nonce'],'doi_settings_action')){ |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
if(!isset($_POST['doubleoptin-settings-edit-submit'])){ |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
if(!isset($_POST['category_id'])){ |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
$category_id = (int)$_POST['category_id']; |
| 37 |
|
| 38 |
$Category = Category::get_by_id($category_id); |
| 39 |
|
| 40 |
if(null === $Category){ |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
$name = sanitize_text_field($_POST['categorie_name']); |
| 45 |
|
| 46 |
if(empty($name)){ |
| 47 |
return false; |
| 48 |
} |
| 49 |
|
| 50 |
$Category->set_name($name); |
| 51 |
|
| 52 |
if($Category->save()){ |
| 53 |
Messages::getInstance()->add(__('Category updated', 'double-opt-in'), 'success'); |
| 54 |
}else{ |
| 55 |
Messages::getInstance()->add(__('Category update failed', 'double-opt-in'), 'error'); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Hide this page in the menu. |
| 61 |
* @return bool |
| 62 |
*/ |
| 63 |
public function hideInMenu() |
| 64 |
{ |
| 65 |
return true; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Render the license subpage content |
| 70 |
*/ |
| 71 |
protected function theContent($slug, $page, $settings) |
| 72 |
{ |
| 73 |
/* |
| 74 |
* Ensure that the ID for the Categorie is set |
| 75 |
*/ |
| 76 |
if(!isset($_GET['id'])){ |
| 77 |
wp_redirect(admin_url('admin.php').'?page=f12-cf7-doubleoptin'); |
| 78 |
} |
| 79 |
|
| 80 |
$id = (int)$_GET['id']; |
| 81 |
|
| 82 |
/* |
| 83 |
* Load the assigned Category |
| 84 |
*/ |
| 85 |
$Category = Category::get_by_id($id); |
| 86 |
|
| 87 |
if(null === $Category){ |
| 88 |
wp_redirect(admin_url('admin.php').'?page=f12-cf7-doubleoptin'); |
| 89 |
} |
| 90 |
|
| 91 |
$atts = array( |
| 92 |
'perPage' => 10, |
| 93 |
'page' => 1, |
| 94 |
'order' => 'DESC', |
| 95 |
); |
| 96 |
|
| 97 |
if (isset($_GET['pageNum'])) { |
| 98 |
$atts['page'] = (int)$_GET['pageNum']; |
| 99 |
} |
| 100 |
|
| 101 |
if(isset($_GET['perPage'])){ |
| 102 |
$atts['perPage'] = (int)$_GET['perPage']; |
| 103 |
} |
| 104 |
|
| 105 |
if(isset($_GET['keyword'])){ |
| 106 |
$atts['keyword'] = sanitize_text_field($_GET['keyword']); |
| 107 |
} |
| 108 |
|
| 109 |
$numberOfPages = 0; |
| 110 |
$listOfOptIns = OptIn::get_list_by_category_id($Category->get_id(), $atts, $numberOfPages); |
| 111 |
|
| 112 |
/* |
| 113 |
* Render the Template |
| 114 |
*/ |
| 115 |
?> |
| 116 |
<h1><?php _e('Category: ', 'double-opt-in').esc_attr_e($Category->get_name()); ?></h1> |
| 117 |
<?php |
| 118 |
|
| 119 |
CF7DoubleOptIn::getInstance()->renderTemplate('list-optins', array( |
| 120 |
'domain' => $this->domain, |
| 121 |
'listOfOptIns' => $listOfOptIns, |
| 122 |
'numberOfPages' => $numberOfPages, |
| 123 |
'currentPage' => $atts['page'], |
| 124 |
'slug' => $slug |
| 125 |
)); |
| 126 |
} |
| 127 |
|
| 128 |
protected function theSidebar($slug, $page) |
| 129 |
{ |
| 130 |
/* |
| 131 |
* Ensure that the ID for the Categorie is set |
| 132 |
*/ |
| 133 |
if(!isset($_GET['id'])){ |
| 134 |
wp_redirect(admin_url('admin.php').'?page=f12-cf7-doubleoptin'); |
| 135 |
} |
| 136 |
|
| 137 |
$id = (int)$_GET['id']; |
| 138 |
|
| 139 |
/* |
| 140 |
* Load the assigned Category |
| 141 |
*/ |
| 142 |
$Category = Category::get_by_id($id); |
| 143 |
|
| 144 |
?> |
| 145 |
<div class="box"> |
| 146 |
<h2> |
| 147 |
<?php _e('Edit Category:', 'double-opt-in'); ?> |
| 148 |
</h2> |
| 149 |
|
| 150 |
<form action="" method="post"> |
| 151 |
<div class="option"> |
| 152 |
<input type="hidden" value="<?php esc_attr_e($_GET['id']);?>" name="category_id" /> |
| 153 |
<div class="input"> |
| 154 |
<input type="text" name="categorie_name" value="<?php esc_attr_e($Category->get_name());?>" placeholder="<?php _e('Please enter the Name of the Categorie', 'double-opt-in'); ?>"/> |
| 155 |
<p> |
| 156 |
<?php _e('Enter the name of the Categorie and submit.', 'double-opt-in'); ?> |
| 157 |
</p> |
| 158 |
</div> |
| 159 |
</div> |
| 160 |
<?php |
| 161 |
wp_nonce_field('doi_settings_action', 'doi_settings_nonce'); |
| 162 |
?> |
| 163 |
|
| 164 |
<input type="submit" name="doubleoptin-settings-edit-submit" class="button" |
| 165 |
value=" <?php _e('Update', 'double-opt-in'); ?>"/> |
| 166 |
</form> |
| 167 |
</div> |
| 168 |
<?php |
| 169 |
} |
| 170 |
|
| 171 |
public function getSettings($settings) |
| 172 |
{ |
| 173 |
return $settings; |
| 174 |
} |
| 175 |
} |
| 176 |
} |