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