@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -16,229 +16,229 @@ discard block |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var string $_tag |
|
| 21 | - */ |
|
| 22 | - protected $_tag = ''; |
|
| 19 | + /** |
|
| 20 | + * @var string $_tag |
|
| 21 | + */ |
|
| 22 | + protected $_tag = ''; |
|
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * returns HTML and javascript related to the displaying of this input |
|
| 30 | - * |
|
| 31 | - * @return string |
|
| 32 | - */ |
|
| 33 | - abstract public function display(); |
|
| 28 | + /** |
|
| 29 | + * returns HTML and javascript related to the displaying of this input |
|
| 30 | + * |
|
| 31 | + * @return string |
|
| 32 | + */ |
|
| 33 | + abstract public function display(); |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * _remove_chars - takes an incoming string, and removes the string $chars from the end of it, but only if $chars |
|
| 39 | - * is already there |
|
| 40 | - * |
|
| 41 | - * @param string $string - the string being processed |
|
| 42 | - * @param string $chars - exact string of characters to remove |
|
| 43 | - * @return string |
|
| 44 | - */ |
|
| 45 | - protected function _remove_chars($string = '', $chars = '-') |
|
| 46 | - { |
|
| 47 | - $char_length = strlen($chars) * -1; |
|
| 48 | - // if last three characters of string is " - ", then remove it |
|
| 49 | - return substr($string, $char_length) === $chars ? substr($string, 0, $char_length) : $string; |
|
| 50 | - } |
|
| 37 | + /** |
|
| 38 | + * _remove_chars - takes an incoming string, and removes the string $chars from the end of it, but only if $chars |
|
| 39 | + * is already there |
|
| 40 | + * |
|
| 41 | + * @param string $string - the string being processed |
|
| 42 | + * @param string $chars - exact string of characters to remove |
|
| 43 | + * @return string |
|
| 44 | + */ |
|
| 45 | + protected function _remove_chars($string = '', $chars = '-') |
|
| 46 | + { |
|
| 47 | + $char_length = strlen($chars) * -1; |
|
| 48 | + // if last three characters of string is " - ", then remove it |
|
| 49 | + return substr($string, $char_length) === $chars ? substr($string, 0, $char_length) : $string; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * _append_chars - takes an incoming string, and adds the string $chars to the end of it, but only if $chars is not |
|
| 56 | - * already there |
|
| 57 | - * |
|
| 58 | - * @param string $string - the string being processed |
|
| 59 | - * @param string $chars - exact string of characters to be added to end of string |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - protected function _append_chars($string = '', $chars = '-') |
|
| 63 | - { |
|
| 64 | - return $this->_remove_chars($string, $chars) . $chars; |
|
| 65 | - } |
|
| 54 | + /** |
|
| 55 | + * _append_chars - takes an incoming string, and adds the string $chars to the end of it, but only if $chars is not |
|
| 56 | + * already there |
|
| 57 | + * |
|
| 58 | + * @param string $string - the string being processed |
|
| 59 | + * @param string $chars - exact string of characters to be added to end of string |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + protected function _append_chars($string = '', $chars = '-') |
|
| 63 | + { |
|
| 64 | + return $this->_remove_chars($string, $chars) . $chars; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | |
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Gets the HTML IDs of all the inputs |
|
| 71 | - * |
|
| 72 | - * @param bool $add_pound_sign |
|
| 73 | - * @return array |
|
| 74 | - */ |
|
| 75 | - public function get_html_input_ids($add_pound_sign = false) |
|
| 76 | - { |
|
| 77 | - return array($this->get_input()->html_id($add_pound_sign)); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Adds js variables for localization to the $other_js_data. These should be put |
|
| 84 | - * in each form's "other_data" javascript object. |
|
| 85 | - * |
|
| 86 | - * @param array $other_js_data |
|
| 87 | - * @return array |
|
| 88 | - */ |
|
| 89 | - public function get_other_js_data($other_js_data = array()) |
|
| 90 | - { |
|
| 91 | - return $other_js_data; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Opportunity for this display strategy to call wp_enqueue_script and wp_enqueue_style. |
|
| 98 | - * This should be called during wp_enqueue_scripts |
|
| 99 | - */ |
|
| 100 | - public function enqueue_js() |
|
| 101 | - { |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * returns string like: '<tag' |
|
| 108 | - * |
|
| 109 | - * @param string $tag |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - protected function _opening_tag($tag) |
|
| 113 | - { |
|
| 114 | - $this->_tag = $tag; |
|
| 115 | - return "<{$this->_tag}"; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * returns string like: '</tag> |
|
| 122 | - * |
|
| 123 | - * @return string |
|
| 124 | - */ |
|
| 125 | - protected function _closing_tag() |
|
| 126 | - { |
|
| 127 | - return "</{$this->_tag}>"; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * returns string like: '/>' |
|
| 134 | - * |
|
| 135 | - * @return string |
|
| 136 | - */ |
|
| 137 | - protected function _close_tag() |
|
| 138 | - { |
|
| 139 | - return '/>'; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * returns an array of standard HTML attributes that get added to nearly all inputs, |
|
| 146 | - * where string keys represent named attributes like id, class, etc |
|
| 147 | - * and numeric keys represent single attributes like 'required'. |
|
| 148 | - * Note: this does not include "value" because many inputs (like dropdowns, textareas, and checkboxes) don't use |
|
| 149 | - * it. |
|
| 150 | - * |
|
| 151 | - * @return array |
|
| 152 | - */ |
|
| 153 | - protected function _standard_attributes_array() |
|
| 154 | - { |
|
| 155 | - return array( |
|
| 156 | - 'name' => $this->_input->html_name(), |
|
| 157 | - 'id' => $this->_input->html_id(), |
|
| 158 | - 'class' => $this->_input->html_class(true), |
|
| 159 | - 0 => array('required', $this->_input->required()), |
|
| 160 | - 1 => $this->_input->other_html_attributes(), |
|
| 161 | - 'style' => $this->_input->html_style(), |
|
| 162 | - ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * sets the attributes using the incoming array |
|
| 169 | - * and returns a string of all attributes rendered as valid HTML |
|
| 170 | - * |
|
| 171 | - * @param array $attributes |
|
| 172 | - * @return string |
|
| 173 | - */ |
|
| 174 | - protected function _attributes_string($attributes = array()) |
|
| 175 | - { |
|
| 176 | - $attributes = apply_filters( |
|
| 177 | - 'FHEE__EE_Display_Strategy_Base__attributes_string__attributes', |
|
| 178 | - $attributes, |
|
| 179 | - $this, |
|
| 180 | - $this->_input |
|
| 181 | - ); |
|
| 182 | - $attributes_string = ''; |
|
| 183 | - foreach ($attributes as $attribute => $value) { |
|
| 184 | - if (is_numeric($attribute)) { |
|
| 185 | - $add = true; |
|
| 186 | - if (is_array($value)) { |
|
| 187 | - $attribute = isset($value[0]) ? $value[0] : ''; |
|
| 188 | - $add = isset($value[1]) ? $value[1] : false; |
|
| 189 | - } else { |
|
| 190 | - $attribute = $value; |
|
| 191 | - } |
|
| 192 | - $attributes_string .= $this->_single_attribute($attribute, $add); |
|
| 193 | - } else { |
|
| 194 | - $attributes_string .= $this->_attribute($attribute, $value); |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - return $attributes_string; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * returns string like: ' attribute="value"' |
|
| 204 | - * returns an empty string if $value is null |
|
| 205 | - * |
|
| 206 | - * @param string $attribute |
|
| 207 | - * @param string $value |
|
| 208 | - * @return string |
|
| 209 | - */ |
|
| 210 | - protected function _attribute($attribute, $value = '') |
|
| 211 | - { |
|
| 212 | - return $value !== null ? " {$attribute}=\"{$value}\"" : ''; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * returns string like: ' data-attribute="value"' |
|
| 219 | - * returns an empty string if $value is null |
|
| 220 | - * |
|
| 221 | - * @param string $attribute |
|
| 222 | - * @param string $value |
|
| 223 | - * @return string |
|
| 224 | - */ |
|
| 225 | - protected function _data_attribute($attribute, $value = '') |
|
| 226 | - { |
|
| 227 | - return $value !== null ? " data-{$attribute}=\"{$value}\"" : ''; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * returns string like: ' attribute' if $add is true |
|
| 234 | - * |
|
| 235 | - * @param string $attribute |
|
| 236 | - * @param boolean $add |
|
| 237 | - * @return string |
|
| 238 | - */ |
|
| 239 | - protected function _single_attribute($attribute, $add = true) |
|
| 240 | - { |
|
| 241 | - return $add ? " {$attribute}" : ''; |
|
| 242 | - } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Gets the HTML IDs of all the inputs |
|
| 71 | + * |
|
| 72 | + * @param bool $add_pound_sign |
|
| 73 | + * @return array |
|
| 74 | + */ |
|
| 75 | + public function get_html_input_ids($add_pound_sign = false) |
|
| 76 | + { |
|
| 77 | + return array($this->get_input()->html_id($add_pound_sign)); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Adds js variables for localization to the $other_js_data. These should be put |
|
| 84 | + * in each form's "other_data" javascript object. |
|
| 85 | + * |
|
| 86 | + * @param array $other_js_data |
|
| 87 | + * @return array |
|
| 88 | + */ |
|
| 89 | + public function get_other_js_data($other_js_data = array()) |
|
| 90 | + { |
|
| 91 | + return $other_js_data; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Opportunity for this display strategy to call wp_enqueue_script and wp_enqueue_style. |
|
| 98 | + * This should be called during wp_enqueue_scripts |
|
| 99 | + */ |
|
| 100 | + public function enqueue_js() |
|
| 101 | + { |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * returns string like: '<tag' |
|
| 108 | + * |
|
| 109 | + * @param string $tag |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + protected function _opening_tag($tag) |
|
| 113 | + { |
|
| 114 | + $this->_tag = $tag; |
|
| 115 | + return "<{$this->_tag}"; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * returns string like: '</tag> |
|
| 122 | + * |
|
| 123 | + * @return string |
|
| 124 | + */ |
|
| 125 | + protected function _closing_tag() |
|
| 126 | + { |
|
| 127 | + return "</{$this->_tag}>"; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * returns string like: '/>' |
|
| 134 | + * |
|
| 135 | + * @return string |
|
| 136 | + */ |
|
| 137 | + protected function _close_tag() |
|
| 138 | + { |
|
| 139 | + return '/>'; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * returns an array of standard HTML attributes that get added to nearly all inputs, |
|
| 146 | + * where string keys represent named attributes like id, class, etc |
|
| 147 | + * and numeric keys represent single attributes like 'required'. |
|
| 148 | + * Note: this does not include "value" because many inputs (like dropdowns, textareas, and checkboxes) don't use |
|
| 149 | + * it. |
|
| 150 | + * |
|
| 151 | + * @return array |
|
| 152 | + */ |
|
| 153 | + protected function _standard_attributes_array() |
|
| 154 | + { |
|
| 155 | + return array( |
|
| 156 | + 'name' => $this->_input->html_name(), |
|
| 157 | + 'id' => $this->_input->html_id(), |
|
| 158 | + 'class' => $this->_input->html_class(true), |
|
| 159 | + 0 => array('required', $this->_input->required()), |
|
| 160 | + 1 => $this->_input->other_html_attributes(), |
|
| 161 | + 'style' => $this->_input->html_style(), |
|
| 162 | + ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * sets the attributes using the incoming array |
|
| 169 | + * and returns a string of all attributes rendered as valid HTML |
|
| 170 | + * |
|
| 171 | + * @param array $attributes |
|
| 172 | + * @return string |
|
| 173 | + */ |
|
| 174 | + protected function _attributes_string($attributes = array()) |
|
| 175 | + { |
|
| 176 | + $attributes = apply_filters( |
|
| 177 | + 'FHEE__EE_Display_Strategy_Base__attributes_string__attributes', |
|
| 178 | + $attributes, |
|
| 179 | + $this, |
|
| 180 | + $this->_input |
|
| 181 | + ); |
|
| 182 | + $attributes_string = ''; |
|
| 183 | + foreach ($attributes as $attribute => $value) { |
|
| 184 | + if (is_numeric($attribute)) { |
|
| 185 | + $add = true; |
|
| 186 | + if (is_array($value)) { |
|
| 187 | + $attribute = isset($value[0]) ? $value[0] : ''; |
|
| 188 | + $add = isset($value[1]) ? $value[1] : false; |
|
| 189 | + } else { |
|
| 190 | + $attribute = $value; |
|
| 191 | + } |
|
| 192 | + $attributes_string .= $this->_single_attribute($attribute, $add); |
|
| 193 | + } else { |
|
| 194 | + $attributes_string .= $this->_attribute($attribute, $value); |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + return $attributes_string; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * returns string like: ' attribute="value"' |
|
| 204 | + * returns an empty string if $value is null |
|
| 205 | + * |
|
| 206 | + * @param string $attribute |
|
| 207 | + * @param string $value |
|
| 208 | + * @return string |
|
| 209 | + */ |
|
| 210 | + protected function _attribute($attribute, $value = '') |
|
| 211 | + { |
|
| 212 | + return $value !== null ? " {$attribute}=\"{$value}\"" : ''; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * returns string like: ' data-attribute="value"' |
|
| 219 | + * returns an empty string if $value is null |
|
| 220 | + * |
|
| 221 | + * @param string $attribute |
|
| 222 | + * @param string $value |
|
| 223 | + * @return string |
|
| 224 | + */ |
|
| 225 | + protected function _data_attribute($attribute, $value = '') |
|
| 226 | + { |
|
| 227 | + return $value !== null ? " data-{$attribute}=\"{$value}\"" : ''; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * returns string like: ' attribute' if $add is true |
|
| 234 | + * |
|
| 235 | + * @param string $attribute |
|
| 236 | + * @param boolean $add |
|
| 237 | + * @return string |
|
| 238 | + */ |
|
| 239 | + protected function _single_attribute($attribute, $add = true) |
|
| 240 | + { |
|
| 241 | + return $add ? " {$attribute}" : ''; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | 244 | } |
| 245 | 245 | \ No newline at end of file |
@@ -14,56 +14,56 @@ |
||
| 14 | 14 | class EE_Number_Input_Display_Strategy extends EE_Display_Strategy_Base |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * minimum value for number field |
|
| 19 | - * |
|
| 20 | - * @var int|null $min |
|
| 21 | - */ |
|
| 22 | - protected $min; |
|
| 17 | + /** |
|
| 18 | + * minimum value for number field |
|
| 19 | + * |
|
| 20 | + * @var int|null $min |
|
| 21 | + */ |
|
| 22 | + protected $min; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * maximum value for number field |
|
| 26 | - * |
|
| 27 | - * @var int|null $max |
|
| 28 | - */ |
|
| 29 | - protected $max; |
|
| 24 | + /** |
|
| 25 | + * maximum value for number field |
|
| 26 | + * |
|
| 27 | + * @var int|null $max |
|
| 28 | + */ |
|
| 29 | + protected $max; |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * EE_Number_Input_Display_Strategy constructor. |
|
| 35 | - * |
|
| 36 | - * @param int $min |
|
| 37 | - * @param int $max |
|
| 38 | - */ |
|
| 39 | - public function __construct($min = null, $max = null) |
|
| 40 | - { |
|
| 41 | - $this->min = $min; |
|
| 42 | - $this->max = $max; |
|
| 43 | - } |
|
| 33 | + /** |
|
| 34 | + * EE_Number_Input_Display_Strategy constructor. |
|
| 35 | + * |
|
| 36 | + * @param int $min |
|
| 37 | + * @param int $max |
|
| 38 | + */ |
|
| 39 | + public function __construct($min = null, $max = null) |
|
| 40 | + { |
|
| 41 | + $this->min = $min; |
|
| 42 | + $this->max = $max; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @return string of html to display the field |
|
| 49 | - */ |
|
| 50 | - public function display() |
|
| 51 | - { |
|
| 52 | - $input = $this->_opening_tag('input'); |
|
| 53 | - $input .= $this->_attributes_string( |
|
| 54 | - array_merge( |
|
| 55 | - $this->_standard_attributes_array(), |
|
| 56 | - array( |
|
| 57 | - 'type' => 'number', |
|
| 58 | - 'min' => $this->min, |
|
| 59 | - 'max' => $this->max, |
|
| 60 | - 'value' => $this->_input->raw_value_in_form() |
|
| 61 | - ) |
|
| 62 | - ) |
|
| 63 | - ); |
|
| 64 | - $input .= $this->_close_tag(); |
|
| 65 | - return $input; |
|
| 66 | - } |
|
| 47 | + /** |
|
| 48 | + * @return string of html to display the field |
|
| 49 | + */ |
|
| 50 | + public function display() |
|
| 51 | + { |
|
| 52 | + $input = $this->_opening_tag('input'); |
|
| 53 | + $input .= $this->_attributes_string( |
|
| 54 | + array_merge( |
|
| 55 | + $this->_standard_attributes_array(), |
|
| 56 | + array( |
|
| 57 | + 'type' => 'number', |
|
| 58 | + 'min' => $this->min, |
|
| 59 | + 'max' => $this->max, |
|
| 60 | + 'value' => $this->_input->raw_value_in_form() |
|
| 61 | + ) |
|
| 62 | + ) |
|
| 63 | + ); |
|
| 64 | + $input .= $this->_close_tag(); |
|
| 65 | + return $input; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | } |
| 69 | 69 | // End of file EE_Number_Input_Display_Strategy.php |