| 1 |
<?php |
| 2 |
namespace MaxButtons; |
| 3 |
defined('ABSPATH') or die('No direct access permitted'); |
| 4 |
|
| 5 |
$button = MB()->getClass("button"); //new maxButton(); |
| 6 |
$button_id = 0; |
| 7 |
|
| 8 |
if ($_POST) { |
| 9 |
if (! check_admin_referer("button-edit","maxbuttons_button")) |
| 10 |
{ |
| 11 |
exit("Request not valid"); |
| 12 |
} |
| 13 |
|
| 14 |
$button_id = intval($_POST["button_id"]); |
| 15 |
|
| 16 |
if ($button_id > 0) |
| 17 |
$button->set($button_id); |
| 18 |
$return = $button->save($_POST); |
| 19 |
if (is_int($return) && $button_id <= 0) |
| 20 |
$button_id = $return; |
| 21 |
|
| 22 |
if ($button_id === 0) |
| 23 |
{ |
| 24 |
error_log(__("Maxbuttons Error: Button id should never be zero","maxbuttons")); |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
$button->set($button_id); |
| 29 |
wp_redirect(admin_url('admin.php?page=maxbuttons-controller&action=button&id=' . $button_id)); |
| 30 |
exit(); |
| 31 |
} |
| 32 |
|
| 33 |
if (isset($_GET['id']) && $_GET['id'] != '') { |
| 34 |
$button = MB()->getClass('button'); // reset |
| 35 |
$button_id = intval($_GET["id"]); |
| 36 |
if ($button_id == 0) |
| 37 |
{ |
| 38 |
$error = __("Maxbuttons button id is zero. Your data is not saved correctly! Please check your database.","maxbuttons"); |
| 39 |
MB()->add_notice('error', $error); |
| 40 |
} |
| 41 |
// returns bool |
| 42 |
$return = $button->set($button_id); |
| 43 |
if ($return === false) |
| 44 |
{ |
| 45 |
$error = __("MaxButtons could not find this button in the database. It might not be possible to save this button! Please check your database or contact support! ", "maxbuttons"); |
| 46 |
MB()->add_notice('error', $error); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
$admin = MB()->getClass('admin'); |
| 52 |
$page_title = __("Button editor","maxbuttons"); |
| 53 |
$action = "<a class='page-title-action add-new-h2' href='" . admin_url() . "admin.php?page=maxbuttons-controller&action=edit'>" . __('Add New', 'maxbuttons') . "</a>"; |
| 54 |
$admin->get_header(array("title" => $page_title, "title_action" => $action) ); |
| 55 |
?> |
| 56 |
<form id="new-button-form" action="<?php echo admin_url('admin.php?page=maxbuttons-controller&action=button&noheader=true'); ?>" method="post"> |
| 57 |
<input type="hidden" name="button_id" value="<?php echo $button_id ?>"> |
| 58 |
<?php wp_nonce_field("button-edit","maxbuttons_button") ?> |
| 59 |
<?php wp_nonce_field("button-copy","copy_nonce"); ?> |
| 60 |
<?php wp_nonce_field("button-delete","delete_nonce"); ?> |
| 61 |
<?php wp_nonce_field('button-trash', 'trash_nonce'); ?> |
| 62 |
|
| 63 |
<div class="form-actions"> |
| 64 |
<a class="button-primary button button-save" href='javascript:void(0);'><?php _e('Save', 'maxbuttons') ?></a> |
| 65 |
<?php if ($button_id > 0): ?> |
| 66 |
<a id="button-copy" class="maxmodal button" data-modal='copy-button' href="javascript:void(0)"><?php _e('Copy', 'maxbuttons') ?></a> |
| 67 |
<a id="button-trash" class="maxmodal button" data-modal = 'trash-button' href="javascript:void(0);"><?php _e('Move to Trash', 'maxbuttons') ?></a> |
| 68 |
<a class="button maxmodal" href="javascript:void(0);" data-modal='delete-button'><?php _e("Delete","maxbuttons"); ?> </a> |
| 69 |
<?php endif; // button_id > 0 ?> |
| 70 |
|
| 71 |
<?php do_action('mb/editor/form-actions', $button); ?> |
| 72 |
</div> |
| 73 |
|
| 74 |
<!-- delete modal --> |
| 75 |
<div class="maxmodal-data" id="delete-button"> |
| 76 |
<span class='title'><?php _e("Removing button","maxbuttons"); ?></span> |
| 77 |
<span class="content"><p><?php _e("You are about to permanently remove this button. Are you sure?", "maxbuttons"); ?></p></span> |
| 78 |
<div class='controls'> |
| 79 |
<button type="button" class='button-primary' data-buttonaction='delete' data-buttonid='<?php echo $button_id ?>'> |
| 80 |
<?php _e('Yes','maxbuttons'); ?></button> |
| 81 |
|
| 82 |
<a class="modal_close button-primary"><?php _e("No", "maxbuttons"); ?></a> |
| 83 |
|
| 84 |
</div> |
| 85 |
</div> |
| 86 |
|
| 87 |
<!-- trash modal --> |
| 88 |
<div class="maxmodal-data" id="trash-button"> |
| 89 |
<span class='title'><?php _e("Trash button","maxbuttons"); ?></span> |
| 90 |
<span class="content"><p><?php _e("The button will be moved to trash. It can be recovered from the trash bin later. Continue?", "maxbuttons"); ?></p></span> |
| 91 |
<div class='controls'> |
| 92 |
<button type="button" class='button-primary' data-buttonaction='trash' data-buttonid='<?php echo $button_id ?>'> |
| 93 |
<?php _e('Yes','maxbuttons'); ?></button> |
| 94 |
|
| 95 |
<a class="modal_close button-primary"><?php _e("No", "maxbuttons"); ?></a> |
| 96 |
|
| 97 |
</div> |
| 98 |
</div> |
| 99 |
|
| 100 |
<!-- copy modal --> |
| 101 |
<div class='maxmodal-data' id='copy-button' data-load='window.maxFoundry.maxadmin.checkCopyModal'> |
| 102 |
<span class='title'><?php _e("Copy this button","maxbuttons"); ?></span> |
| 103 |
<span class="content"> |
| 104 |
|
| 105 |
<div class='copy-warning'> |
| 106 |
<h3><?php _e('Probably you don\'t want to copy your button!', 'maxbuttons'); ?></h3> |
| 107 |
<p><?php _e( sprintf("Changing %sText%s and %sURL%s can be done with the same button. %s This will save you time in the near future", "<b>","</b>","<b>","</b>","<br>"),'maxbuttons'); ?> </p> |
| 108 |
|
| 109 |
<p class="example"> |
| 110 |
|
| 111 |
<strong><?php _e("Add the same button with different link","maxbuttons"); ?></strong><br> |
| 112 |
[maxbutton id="<?php echo $button_id ?>" url="http://yoururl"] |
| 113 |
</p> |
| 114 |
|
| 115 |
<p class="example"><strong><?php _e("Use the same button but change the text","maxbuttons"); ?> </strong><br /> |
| 116 |
[maxbutton id="<?php echo $button_id ?>" text="yourtext"] |
| 117 |
</p> |
| 118 |
|
| 119 |
<p class="example"><strong><?php _e("Both","maxbuttons"); ?> </strong><br /> |
| 120 |
[maxbutton id="<?php echo $button_id ?>" text="yourtext" url="http://yoururl"] |
| 121 |
</p> |
| 122 |
|
| 123 |
</div> |
| 124 |
|
| 125 |
|
| 126 |
<div class='mb-message mb-notice copy-notice hidden'><p><?php _e('Your button has not been saved. Any changes will be lost!','maxbuttons'); ?></p> |
| 127 |
</div> |
| 128 |
<p><?php _e("Do you want to copy this button to a new button?","maxbuttons"); ?></p> |
| 129 |
</span> |
| 130 |
<span class="controls"> |
| 131 |
<button type="button" class='button-primary' data-buttonaction='copy' data-buttonid='<?php echo $button_id ?>'> |
| 132 |
<?php _e('Copy','maxbuttons'); ?></button> |
| 133 |
|
| 134 |
<a class='button modal_close'><?php _e("Cancel",'maxbuttons'); ?></a> |
| 135 |
</span> |
| 136 |
</div> |
| 137 |
|
| 138 |
<?php |
| 139 |
/** Display admin notices [deprecated] |
| 140 |
* @ignore |
| 141 |
*/ |
| 142 |
|
| 143 |
|
| 144 |
/** Display admin notices |
| 145 |
* |
| 146 |
* Hook to display admin notices on error and other occurences in the editor. Follows WP guidelines on format. |
| 147 |
* @since 4.20 |
| 148 |
*/ |
| 149 |
do_action("mb/editor/display_notices"); |
| 150 |
?> |
| 151 |
|
| 152 |
<?php if ($button_id > 0): ?> |
| 153 |
<div class="mb-message shortcode"> |
| 154 |
<?php $button_name = $button->getName(); |
| 155 |
|
| 156 |
?> |
| 157 |
<?php _e('To use this button, place the following shortcode anywhere you want it to appear in your site content:', 'maxbuttons') ?> |
| 158 |
<strong>[maxbutton id="<?php echo $button_id ?>"]</strong> |
| 159 |
|
| 160 |
<p><?php _e("Shortcode options can make using MaxButtons much easier! Check all possible options", 'maxbuttons'); ?> </p> |
| 161 |
|
| 162 |
<span class='shortcode-expand closed'><?php _e("See more options","maxbuttons"); ?> |
| 163 |
<span class="dashicons-before dashicons-arrow-down"></span> |
| 164 |
</span> |
| 165 |
|
| 166 |
<div class="expanded"> |
| 167 |
<p class="example"> |
| 168 |
<strong><?php _e("Add a button by using the button name","maxbuttons"); ?></strong> |
| 169 |
[maxbutton name="<?php echo $button_name; ?>"] |
| 170 |
</p> |
| 171 |
<p class="example"> |
| 172 |
<strong><?php _e("Same button with different link","maxbuttons"); ?></strong> |
| 173 |
[maxbutton id="<?php echo $button_id ?>" url="http://yoururl"] |
| 174 |
</p> |
| 175 |
|
| 176 |
<p class="example"><strong><?php _e("Same button with diffent text","maxbuttons"); ?> </strong> |
| 177 |
[maxbutton id="<?php echo $button_id ?>" text="yourtext"] |
| 178 |
</p> |
| 179 |
<p class="example"><strong><?php _e("All possible shortcode options","maxbuttons"); ?></strong> |
| 180 |
[maxbutton id="<?php echo $button_id ?>" text="yourtext" url="http://yoururl" linktitle="tooltip" window="new" nofollow="true"] |
| 181 |
</p> |
| 182 |
|
| 183 |
<h4><?php _e("Some tips","maxbuttons"); ?></h4> |
| 184 |
<p><?php _e("If you use this button on a static page, on multiple pages, or upload your theme to another WordPress installation choose an unique name and use ", |
| 185 |
"maxbuttons"); ?> <strong>[maxbutton name='my-buy-button' url='http://yoururl']</strong>. |
| 186 |
|
| 187 |
|
| 188 |
<?php _e("By using this syntax when you edit and save your button it will be changed everywhere it is used on your site. If you delete the button and create a new one with the same name the new button will be used on your site.","maxbuttons"); ?> |
| 189 |
</p> |
| 190 |
|
| 191 |
</div> |
| 192 |
</div> |
| 193 |
<?php endif; ?> |
| 194 |
|
| 195 |
<div class="output"> |
| 196 |
<div class="header"><?php _e('Preview', 'maxbuttons') ?> |
| 197 |
<span class='preview-toggle dashicons dashicons-arrow-up'> </span> |
| 198 |
</div> |
| 199 |
<?php |
| 200 |
$border_box = get_option('maxbuttons_borderbox'); |
| 201 |
$boxclass = ''; |
| 202 |
if ($border_box == 1) // box-sizing option. |
| 203 |
$boxclass = 'preview-border-box'; |
| 204 |
?> |
| 205 |
<div class="inner"> |
| 206 |
|
| 207 |
<p><?php _e('The top is the normal button, the bottom one is the hover.', 'maxbuttons') ?></p> |
| 208 |
<div class="result <?php echo $boxclass ?>"> |
| 209 |
|
| 210 |
<?php $button->display(array("mode" => 'editor', "load_css" => "element")); ?> |
| 211 |
|
| 212 |
<p> </p> |
| 213 |
|
| 214 |
<?php $button->display(array("mode" => 'editor', "preview_part" => ":hover", "load_css" => "element")); ?> |
| 215 |
|
| 216 |
<?php $button->display_field_map(); ?> |
| 217 |
</div> |
| 218 |
|
| 219 |
<input type='hidden' id='colorpicker_current' value=''> |
| 220 |
|
| 221 |
<div class="input mbcolor preview nodrag"> |
| 222 |
<input type="text" name="button_preview" id="button_preview" class="color-field"> |
| 223 |
</div> |
| 224 |
|
| 225 |
<div class="note"><?php _e('Change this color to see your button on a different background.', 'maxbuttons') ?></div> |
| 226 |
<input type="hidden" id="button_preview" value='' /> |
| 227 |
<input style="display: none;" type="text" id="button_output" name="button_output" value="" /> |
| 228 |
|
| 229 |
<div class="clear"></div> |
| 230 |
</div> <!-- inner --> |
| 231 |
</div> <!-- output --> |
| 232 |
|
| 233 |
<?php #### STARTING FIELDS; |
| 234 |
|
| 235 |
|
| 236 |
$button->admin_fields(); |
| 237 |
|
| 238 |
?> |
| 239 |
|
| 240 |
<div class="form-actions"> |
| 241 |
<a href="#" class="button-primary button-save"><?php _e('Save', 'maxbuttons') ?></a> |
| 242 |
</div> |
| 243 |
</form> |
| 244 |
|
| 245 |
|
| 246 |
</div> |
| 247 |
<?php $admin->get_footer(); ?> |
| 248 |
|