| 1 |
<?php |
| 2 |
namespace MaxButtons; |
| 3 |
|
| 4 |
// main thing for the button editor |
| 5 |
class editorController extends MaxController |
| 6 |
{ |
| 7 |
protected $view_template = 'maxbuttons-button'; |
| 8 |
|
| 9 |
public function __construct() |
| 10 |
{ |
| 11 |
parent::__construct(); |
| 12 |
|
| 13 |
MB()->load_library('simple_template'); |
| 14 |
} |
| 15 |
|
| 16 |
public function view() |
| 17 |
{ |
| 18 |
if ($_POST) { |
| 19 |
$this->handlePost(); |
| 20 |
} |
| 21 |
$this->loadView(); |
| 22 |
|
| 23 |
parent::view(); |
| 24 |
} |
| 25 |
|
| 26 |
protected function loadView() |
| 27 |
{ |
| 28 |
$this->view->button = MB()->getClass('button'); // reset |
| 29 |
$this->view->button_id = 0; // always load. |
| 30 |
|
| 31 |
if (isset($_GET['id']) && $_GET['id'] != '') { |
| 32 |
//$button = |
| 33 |
$button_id = intval($_GET["id"]); |
| 34 |
$this->view->button_id = $button_id; |
| 35 |
|
| 36 |
if ($button_id == 0) |
| 37 |
|
| 38 |
{ |
| 39 |
$error = __("Maxbuttons button id is zero. Your data is not saved correctly! Please check your database.","maxbuttons"); |
| 40 |
MB()->add_notice('error', $error); |
| 41 |
} |
| 42 |
// returns bool |
| 43 |
$return = $this->view->button->set($button_id); |
| 44 |
if ($return === false) |
| 45 |
{ |
| 46 |
$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"); |
| 47 |
MB()->add_notice('error', $error); |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
protected function handlePost() |
| 53 |
{ |
| 54 |
if (! check_admin_referer("button-edit","maxbuttons_button")) |
| 55 |
{ |
| 56 |
exit("Request not valid"); |
| 57 |
} |
| 58 |
|
| 59 |
$button = MB()->getClass('button'); ; |
| 60 |
$button_id = intval($_POST["button_id"]); |
| 61 |
|
| 62 |
if ($button_id > 0) |
| 63 |
$button->set($button_id); |
| 64 |
$return = $button->save($_POST); |
| 65 |
if (is_int($return) && $button_id <= 0) |
| 66 |
$button_id = $return; |
| 67 |
|
| 68 |
if ($button_id === 0) |
| 69 |
{ |
| 70 |
error_log(__("Maxbuttons Error: Button id should never be zero","maxbuttons")); |
| 71 |
} |
| 72 |
|
| 73 |
$button->set($button_id); |
| 74 |
$url = $this->getButtonLink($button_id); |
| 75 |
wp_redirect($url); |
| 76 |
exit(); |
| 77 |
} // handlePost. |
| 78 |
|
| 79 |
} // Class editorController |
| 80 |
|