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