| 1 |
<?php |
| 2 |
namespace MaxButtons; |
| 3 |
defined('ABSPATH') or die('No direct access permitted'); |
| 4 |
|
| 5 |
class maxField |
| 6 |
{ |
| 7 |
|
| 8 |
/* Static class variables */ |
| 9 |
static $templates = ''; |
| 10 |
static $position = 0; |
| 11 |
|
| 12 |
/* Field data */ |
| 13 |
public $id; |
| 14 |
public $name; |
| 15 |
public $value = ''; |
| 16 |
|
| 17 |
/* Layout options */ |
| 18 |
public $note; |
| 19 |
public $label; |
| 20 |
public $title; |
| 21 |
public $default; |
| 22 |
|
| 23 |
// Specific options */ |
| 24 |
public $placeholder = ''; // text / textarea |
| 25 |
public $icon; // checkbox-icon |
| 26 |
public $checked = ''; // checkbox / radio |
| 27 |
public $input_class = ''; // inputs |
| 28 |
public $before_input; // text |
| 29 |
public $content = ''; // generic / spacer |
| 30 |
public $min; // number |
| 31 |
|
| 32 |
/* Border radius */ |
| 33 |
public $radius_tl; |
| 34 |
public $radius_tr; |
| 35 |
public $radius_bl, $radius_br; |
| 36 |
|
| 37 |
// conditionals |
| 38 |
public $start_conditional; // conditional defined in start.tpl / row start |
| 39 |
public $start_cond_type = 'show'; // show / has conditional |
| 40 |
public $conditional; |
| 41 |
|
| 42 |
//public |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
/* Template */ |
| 47 |
public $template; |
| 48 |
public $main_class = 'option'; // row class - start template |
| 49 |
public $esc_function = 'esc_attr'; |
| 50 |
|
| 51 |
/* Publish brake */ |
| 52 |
public $publish = true; |
| 53 |
public $output = ''; |
| 54 |
|
| 55 |
public function __construct($template = 'text', $args = array() ) |
| 56 |
{ |
| 57 |
self::$position++; |
| 58 |
$this->template = $template; |
| 59 |
|
| 60 |
foreach($args as $item => $value) |
| 61 |
{ |
| 62 |
$this->{$item} = $value; |
| 63 |
|
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
static function setTemplates($templates) |
| 68 |
{ |
| 69 |
self::$templates = apply_filters('mb/editor/templates', $templates); |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
public function setDefault($default) |
| 75 |
{ |
| 76 |
$this->default = __('Default:','maxbuttons') . ' ' . $default; |
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
/** Output field interface |
| 81 |
* |
| 82 |
* @param $start_tpl Prepend a template before this field ( e.g. row defition ) |
| 83 |
* @param $end_tpl Append a template after this field |
| 84 |
*/ |
| 85 |
|
| 86 |
public function output($start_tpl = '', $end_tpl = '') |
| 87 |
{ |
| 88 |
if ($this->esc_function) |
| 89 |
{ |
| 90 |
$this->value = call_user_func($this->esc_function, $this->value); |
| 91 |
} |
| 92 |
|
| 93 |
$output = ''; |
| 94 |
if ($start_tpl != '') |
| 95 |
{ |
| 96 |
$start_tpl = self::$templates[$start_tpl]; |
| 97 |
$output .= simpleTemplate::parse($start_tpl['path'], $this); |
| 98 |
} |
| 99 |
|
| 100 |
$template = self::$templates[$this->template]; // template name; |
| 101 |
do_action('mb/editor/before-field-' . $this->id, $this); |
| 102 |
|
| 103 |
$output .= simpleTemplate::parse($template['path'], $this); |
| 104 |
|
| 105 |
|
| 106 |
if ($end_tpl != '') |
| 107 |
{ |
| 108 |
if (! is_array($end_tpl)) |
| 109 |
$end_tpl = array($end_tpl); |
| 110 |
|
| 111 |
foreach($end_tpl as $tpl) |
| 112 |
{ |
| 113 |
$tpl = self::$templates[$tpl]; |
| 114 |
$output .= simpleTemplate::parse($tpl['path'], $this); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
if ($this->publish) |
| 119 |
echo $output; |
| 120 |
do_action('mb/editor/after-field-'. $this->id); // hook for extra fields. |
| 121 |
|
| 122 |
$this->output = $output; |
| 123 |
return $output; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
} |
| 128 |
|