| 1 |
<?php |
| 2 |
namespace MaxButtons; |
| 3 |
|
| 4 |
// controller for our views |
| 5 |
abstract class MaxController |
| 6 |
{ |
| 7 |
|
| 8 |
protected $view; // view data |
| 9 |
protected $page; |
| 10 |
protected $messages = array(); // messages to display to user. |
| 11 |
protected $view_template; |
| 12 |
|
| 13 |
public function __construct() |
| 14 |
{ |
| 15 |
$this->view = new \stdClass; |
| 16 |
} |
| 17 |
|
| 18 |
public function view() |
| 19 |
{ |
| 20 |
$view = $this->view; |
| 21 |
|
| 22 |
|
| 23 |
if (! is_null($this->view_template)) |
| 24 |
{ |
| 25 |
$path = MB()->get_plugin_path() . 'includes/' . $this->view_template . '.php'; |
| 26 |
if (file_exists($path)) |
| 27 |
include_once($path); |
| 28 |
else { |
| 29 |
exit('Template Not Found'); |
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
abstract protected function handlePost(); |
| 35 |
|
| 36 |
public function getButtonLink($button_id = 0, $args = array()) |
| 37 |
{ |
| 38 |
$link = admin_url() . 'admin.php?page=maxbuttons-controller&action=edit'; |
| 39 |
if ($button_id > 0) |
| 40 |
{ |
| 41 |
$link = add_query_arg('id', $button_id, $link); |
| 42 |
} |
| 43 |
$link = add_query_arg($args,$link); |
| 44 |
return $link; |
| 45 |
} |
| 46 |
|
| 47 |
public function getListLink($view = 'all', $args = array() ) |
| 48 |
{ |
| 49 |
$link = admin_url() . 'admin.php?page=maxbuttons-list&view=' . $view; |
| 50 |
$link = add_query_arg($args,$link); |
| 51 |
return $link; |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
// sets name of the requested page. can be used to load a specific template. |
| 56 |
public function setPage($page) |
| 57 |
{ |
| 58 |
$this->page = $page; |
| 59 |
} |
| 60 |
|
| 61 |
} |
| 62 |
|