| 1 |
<?php |
| 2 |
$result = ''; |
| 3 |
$button = MB()->getClass("button"); |
| 4 |
$mbadmin = MB()->getClass("admin"); |
| 5 |
$collections = MB()->getClass('collections'); |
| 6 |
$collection = MB()->getClass('collection'); |
| 7 |
|
| 8 |
$view = (isset($_GET["view"])) ? sanitize_text_field($_GET["view"]) : "all"; |
| 9 |
|
| 10 |
// submit |
| 11 |
if (isset($_POST) && isset($_POST["mb-list-nonce"]) ) { |
| 12 |
$verify = wp_verify_nonce( $_POST['mb-list-nonce'], 'mb-list' ); |
| 13 |
if (! $verify ) echo " Nonce not verifed"; |
| 14 |
|
| 15 |
if ($verify && isset($_POST['button-id']) && isset($_POST['bulk-action-select'])) { |
| 16 |
if ($_POST['bulk-action-select'] == 'trash') { |
| 17 |
$count = 0; |
| 18 |
|
| 19 |
foreach ($_POST['button-id'] as $id) { |
| 20 |
$id = intval($id); |
| 21 |
$button->set($id); |
| 22 |
$button->setStatus('trash'); |
| 23 |
$count++; |
| 24 |
} |
| 25 |
|
| 26 |
if ($count == 1) { |
| 27 |
$result = __('Moved 1 button to the trash.', 'maxbuttons'); |
| 28 |
} |
| 29 |
|
| 30 |
if ($count > 1) { |
| 31 |
$result = __('Moved ', 'maxbuttons') . $count . __(' buttons to the trash.', 'maxbuttons'); |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
if ($verify && $_POST['bulk-action-select'] == 'restore') { |
| 36 |
$count = 0; |
| 37 |
|
| 38 |
foreach ($_POST['button-id'] as $id) { |
| 39 |
$id = intval($id); |
| 40 |
$set = $button->set($id,'','trash'); |
| 41 |
$button->setStatus('publish'); |
| 42 |
|
| 43 |
//maxbuttons_button_restore($id); |
| 44 |
$count++; |
| 45 |
} |
| 46 |
|
| 47 |
if ($count == 1) { |
| 48 |
$result = __('Restored 1 button.', 'maxbuttons'); |
| 49 |
} |
| 50 |
|
| 51 |
if ($count > 1) { |
| 52 |
$result = __('Restored ', 'maxbuttons') . $count . __(' buttons.', 'maxbuttons'); |
| 53 |
} |
| 54 |
$view = 'all'; // switch to normal list. |
| 55 |
} |
| 56 |
|
| 57 |
if ($verify && $_POST['bulk-action-select'] == 'delete') { |
| 58 |
$count = 0; |
| 59 |
|
| 60 |
foreach ($_POST['button-id'] as $id) { |
| 61 |
$id = intval($id); |
| 62 |
$button->delete($id); |
| 63 |
$count++; |
| 64 |
} |
| 65 |
|
| 66 |
if ($count == 1) { |
| 67 |
$result = __('Deleted 1 button.', 'maxbuttons'); |
| 68 |
} |
| 69 |
|
| 70 |
if ($count > 1) { |
| 71 |
$result = __('Deleted ', 'maxbuttons') . $count . __(' buttons.', 'maxbuttons'); |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
if (isset($_GET['message']) && $_GET['message'] == '1') { |
| 77 |
$result = __('Moved 1 button to the trash.', 'maxbuttons'); |
| 78 |
} |
| 79 |
|
| 80 |
if (isset($_GET['message']) && $_GET['message'] == '1restore') { |
| 81 |
$result = __('Restored 1 button.', 'maxbuttons'); |
| 82 |
} |
| 83 |
|
| 84 |
if (isset($_GET['message']) && $_GET['message'] == '1delete') { |
| 85 |
$result = __('Deleted 1 button.', 'maxbuttons'); |
| 86 |
} |
| 87 |
|
| 88 |
$args = array( |
| 89 |
"orderby" => "id", |
| 90 |
"order" => "DESC", |
| 91 |
|
| 92 |
); |
| 93 |
|
| 94 |
if (isset($_GET["orderby"])) |
| 95 |
$args["orderby"] = sanitize_text_field($_GET["orderby"]); |
| 96 |
if (isset($_GET["order"])) |
| 97 |
$args["order"] = sanitize_text_field($_GET["order"]); |
| 98 |
|
| 99 |
if (isset($_GET["paged"]) && $_GET["paged"] != '') |
| 100 |
{ |
| 101 |
$page = intval($_GET["paged"]); |
| 102 |
$args["paged"] = $page; |
| 103 |
} |
| 104 |
|
| 105 |
if ($view == 'trash') |
| 106 |
$args["status"] = "trash"; |
| 107 |
|
| 108 |
|
| 109 |
$published_buttons = $mbadmin->getButtons($args); |
| 110 |
|
| 111 |
$published_buttons_count = $mbadmin->getButtonCount(array()); |
| 112 |
$trashed_buttons_count = $mbadmin->getButtonCount(array("status" => "trash")); |
| 113 |
|
| 114 |
$args["view"] = $view; |
| 115 |
|
| 116 |
$page_args = $args; |
| 117 |
|
| 118 |
|
| 119 |
?> |
| 120 |
|
| 121 |
<script type="text/javascript"> |
| 122 |
jQuery(document).ready(function() { |
| 123 |
jQuery("#bulk-action-all").click(function() { |
| 124 |
jQuery("#maxbuttons input[name='button-id[]']").each(function() { |
| 125 |
if (jQuery("#bulk-action-all").is(":checked")) { |
| 126 |
jQuery(this).attr("checked", "checked"); |
| 127 |
} |
| 128 |
else { |
| 129 |
jQuery(this).removeAttr("checked"); |
| 130 |
} |
| 131 |
}); |
| 132 |
}); |
| 133 |
|
| 134 |
}); |
| 135 |
</script> |
| 136 |
|
| 137 |
<?php |
| 138 |
$page_title = __("Overview","maxbuttons"); |
| 139 |
$action = "<a class='page-title-action add-new-h2' href='" . admin_url() . "admin.php?page=maxbuttons-controller&action=edit'>" . __('Add New', 'maxbuttons') . "</a>"; |
| 140 |
$mbadmin->get_header(array("title" => $page_title, "title_action" => $action)); |
| 141 |
?> |
| 142 |
|
| 143 |
<div class="form-actions"> |
| 144 |
<a class="button-primary" href="<?php echo admin_url() ?>admin.php?page=maxbuttons-controller&action=edit"><?php _e('Add New', 'maxbuttons') ?></a> |
| 145 |
</div> |
| 146 |
|
| 147 |
<?php if ($result != '') { ?> |
| 148 |
<div class="mb-notice mb-message"><?php echo $result ?></div> |
| 149 |
<?php } |
| 150 |
|
| 151 |
do_action('mb-display-reviewoffer'); |
| 152 |
?> |
| 153 |
|
| 154 |
|
| 155 |
<p class="status"> |
| 156 |
<?php |
| 157 |
$url = admin_url() . "admin.php?page=maxbuttons-controller&action=list"; |
| 158 |
$trash_url = $url . "&view=trash"; |
| 159 |
|
| 160 |
if ($view == 'trash') |
| 161 |
{ |
| 162 |
$all_line = "<strong><a href='$url'>" . __('All', 'maxbuttons') . "</strong></a>"; |
| 163 |
$trash_line = __("Trash", "maxbuttons"); |
| 164 |
} |
| 165 |
else |
| 166 |
{ |
| 167 |
$all_line = __("All","maxbuttons"); |
| 168 |
$trash_line = "<a href='$trash_url'>" . __("Trash","maxbuttons") . "</strong></a>"; |
| 169 |
} |
| 170 |
?> |
| 171 |
<?php echo $all_line ?><span class="count"> (<?php echo $published_buttons_count ?>)</span> |
| 172 |
|
| 173 |
<?php if ($trashed_buttons_count > 0) { ?> |
| 174 |
<span class="separator">|</span> |
| 175 |
<?php echo $trash_line ?> <span class="count">(<?php echo $trashed_buttons_count ?>)</span> |
| 176 |
<?php } ?> |
| 177 |
</p> |
| 178 |
<?php |
| 179 |
do_action("mb-display-meta"); |
| 180 |
|
| 181 |
|
| 182 |
?> |
| 183 |
|
| 184 |
|
| 185 |
<form method="post"> |
| 186 |
<input type="hidden" name="view" value="<?php echo $view ?>" /> |
| 187 |
<?php wp_nonce_field("mb-list","mb-list-nonce"); ?> |
| 188 |
|
| 189 |
<select name="bulk-action-select" id="bulk-action-select"> |
| 190 |
<option value=""><?php _e('Bulk Actions', 'maxbuttons') ?></option> |
| 191 |
<?php if ($view == 'all'): ?> |
| 192 |
|
| 193 |
<option value="trash"><?php _e('Move to Trash', 'maxbuttons') ?></option> |
| 194 |
<?php endif; |
| 195 |
if ($view == 'trash'): ?> |
| 196 |
<option value="restore"><?php _e('Restore', 'maxbuttons') ?></option> |
| 197 |
<option value="delete"><?php _e('Delete Permanently', 'maxbuttons') ?></option> |
| 198 |
<?php endif; ?> |
| 199 |
</select> |
| 200 |
<input type="submit" class="button" value="<?php _e('Apply', 'maxbuttons') ?>" /> |
| 201 |
|
| 202 |
<div class='tablenav top'> |
| 203 |
<?php do_action("mb-display-pagination", $page_args); ?> |
| 204 |
</div> |
| 205 |
|
| 206 |
|
| 207 |
<?php // Sorting |
| 208 |
|
| 209 |
|
| 210 |
$link_order = (! isset($_GET["order"]) || $_GET["order"] == "DESC") ? "ASC" : 'DESC'; |
| 211 |
|
| 212 |
$name_sort_url = add_query_arg(array( |
| 213 |
"orderby" => "name", |
| 214 |
"order" => $link_order |
| 215 |
)); |
| 216 |
$id_sort_url = add_query_arg(array( |
| 217 |
"orderby" => "id", |
| 218 |
"order" => $link_order |
| 219 |
)); |
| 220 |
|
| 221 |
$sort_arrow = ( strtolower($args["order"]) == 'desc') ? 'dashicons-arrow-down' : 'dashicons-arrow-up' |
| 222 |
?> |
| 223 |
|
| 224 |
<div class="button-list preview-buttons"> |
| 225 |
|
| 226 |
<div class="heading"> |
| 227 |
<span class='col col_check'><input type="checkbox" name="bulk-action-all" id="bulk-action-all" /></span> |
| 228 |
<span class='col col_button'> |
| 229 |
<a href="<?php echo $id_sort_url ?>"> |
| 230 |
<?php _e('Button', 'maxbuttons') ?> |
| 231 |
<?php if ($args["orderby"] == 'id') |
| 232 |
echo "<span class='dashicons $sort_arrow'></span>"; |
| 233 |
?> |
| 234 |
</a> |
| 235 |
</span> |
| 236 |
<span class="col col_name manage-column column-name sortable <?php echo strtolower($link_order) ?>"> |
| 237 |
<a href="<?php echo $name_sort_url ?>"> |
| 238 |
<span><?php _e('Name and Description', 'maxbuttons') ?></span> |
| 239 |
<?php if ($args["orderby"] == 'name') |
| 240 |
echo "<span class='dashicons $sort_arrow'></span>"; |
| 241 |
?> |
| 242 |
|
| 243 |
</a> |
| 244 |
</span> |
| 245 |
<span class='col col_shortcode'><?php _e('Shortcode', 'maxbuttons') ?></span> |
| 246 |
</div> <!-- heading --> |
| 247 |
<?php foreach ($published_buttons as $b): |
| 248 |
$id = $b["id"]; |
| 249 |
if($view == 'trash') |
| 250 |
$button->set($id,'','trash'); |
| 251 |
else |
| 252 |
$button->set($id); |
| 253 |
|
| 254 |
$inCollections = $collections::isButtonInCollection($id); |
| 255 |
?> |
| 256 |
<div class='button-row'> |
| 257 |
<span class="col col_check"><input type="checkbox" name="button-id[]" id="button-id-<?php echo $id ?>" value="<?php echo $id ?>" /></span> |
| 258 |
<span class="col col_button"><div class="shortcode-container"> |
| 259 |
<?php |
| 260 |
//echo do_shortcode('[maxbutton id="' . $id . '" externalcss="false" ignorecontainer="true"]'); |
| 261 |
|
| 262 |
$button->display( array("mode" => "preview") ); |
| 263 |
?> |
| 264 |
</div> |
| 265 |
<div class="actions"> |
| 266 |
<?php if($view == 'all') : ?> |
| 267 |
<a href="<?php admin_url() ?>admin.php?page=maxbuttons-controller&action=button&id=<?php echo $id ?>"><?php _e('Edit', 'maxbuttons') ?></a> |
| 268 |
<span class="separator">|</span> |
| 269 |
<a href="<?php admin_url() ?>admin.php?page=maxbuttons-controller&action=copy&id=<?php echo $id ?>"><?php _e('Copy', 'maxbuttons') ?></a> |
| 270 |
<span class="separator">|</span> |
| 271 |
<a href="<?php admin_url() ?>admin.php?page=maxbuttons-controller&action=trash&id=<?php echo $id ?>"><?php _e('Move to Trash', 'maxbuttons') ?></a> |
| 272 |
<?php endif; |
| 273 |
if ($view == 'trash'): |
| 274 |
?> |
| 275 |
<a href="<?php admin_url() ?>admin.php?page=maxbuttons-controller&action=restore&id=<?php echo $id ?>"><?php _e('Restore', 'maxbuttons') ?></a> |
| 276 |
<span class="separator">|</span> |
| 277 |
<a href="<?php admin_url() ?>admin.php?page=maxbuttons-controller&action=delete&id=<?php echo $id ?>"><?php _e('Delete Permanently', 'maxbuttons') ?></a> |
| 278 |
<?php endif; ?> |
| 279 |
</div> |
| 280 |
|
| 281 |
<?php if ($inCollections): |
| 282 |
$number = count($inCollections); |
| 283 |
|
| 284 |
?> |
| 285 |
<div class='collection_notice'> |
| 286 |
<?php echo _n('In collection:', 'In collections:', $number,'maxbuttons') ?> |
| 287 |
<?php foreach($inCollections as $col_id) |
| 288 |
{ |
| 289 |
$meta = $collection->get_meta($col_id, 'collection_name'); |
| 290 |
$name = isset($meta['collection_name']) ? $meta['collection_name'] : false; |
| 291 |
if ($name) |
| 292 |
echo "<span class='name'>$name</span> "; |
| 293 |
} |
| 294 |
?> |
| 295 |
</div> |
| 296 |
|
| 297 |
<?php endif; |
| 298 |
?> |
| 299 |
</span> |
| 300 |
<span class="col col_name"><a class="button-name" href="<?php admin_url() ?>admin.php?page=maxbuttons-controller&action=button&id=<?php echo $id ?>"><?php echo $button->getName() ?></a> |
| 301 |
<br /> |
| 302 |
<p><?php echo $button->getDescription() ?></p> |
| 303 |
</span> |
| 304 |
<span class="col col_shortcode"> [maxbutton id="<?php echo $id ?>"]<br /> |
| 305 |
[maxbutton name="<?php echo $button->getName() ?>"]</span> |
| 306 |
</div> |
| 307 |
<?php endforeach; // buttons ?> |
| 308 |
|
| 309 |
|
| 310 |
</div> <!-- button-list --> |
| 311 |
</form> |
| 312 |
|
| 313 |
<div class="tablenav bottom"> |
| 314 |
<?php do_action("mb-display-pagination", $page_args); ?> |
| 315 |
</div> |
| 316 |
|
| 317 |
|
| 318 |
</div> |
| 319 |
<div class="ad-wrap"> |
| 320 |
<?php do_action("mb-display-ads"); ?> |
| 321 |
</div> |
| 322 |
|
| 323 |
<?php $mbadmin->get_footer(); ?> |
| 324 |
|