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