@@ -328,7 +328,8 @@ |
||
| 328 | 328 | } |
| 329 | 329 | if (is_array($params[0])) { |
| 330 | 330 | $this->args += $params[0]; |
| 331 | - } elseif (is_array($params[1])) { |
|
| 331 | + } |
|
| 332 | + elseif (is_array($params[1])) { |
|
| 332 | 333 | $this->args += $params[1]; |
| 333 | 334 | } |
| 334 | 335 | if (!isset($this->args['is_public'])) { |
@@ -18,346 +18,346 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Builder |
| 20 | 20 | { |
| 21 | - const INPUT_TYPES = [ |
|
| 22 | - 'checkbox', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month', |
|
| 23 | - 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time', |
|
| 24 | - 'url', 'week', |
|
| 25 | - ]; |
|
| 26 | - |
|
| 27 | - const TAGS_FORM = [ |
|
| 28 | - 'input', 'select', 'textarea', |
|
| 29 | - ]; |
|
| 30 | - |
|
| 31 | - const TAGS_SINGLE = [ |
|
| 32 | - 'img', |
|
| 33 | - ]; |
|
| 34 | - |
|
| 35 | - const TAGS_STRUCTURE = [ |
|
| 36 | - 'div', 'form', 'nav', 'ol', 'section', 'ul', |
|
| 37 | - ]; |
|
| 38 | - |
|
| 39 | - const TAGS_TEXT = [ |
|
| 40 | - 'a', 'button', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'label', 'li', 'option', 'p', 'pre', |
|
| 41 | - 'small', 'span', |
|
| 42 | - ]; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - public $args = []; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var bool |
|
| 51 | - */ |
|
| 52 | - public $render = false; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var string |
|
| 56 | - */ |
|
| 57 | - public $tag; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @param string $method |
|
| 61 | - * @param array $args |
|
| 62 | - * @return string|void |
|
| 63 | - */ |
|
| 64 | - public function __call($method, $args) |
|
| 65 | - { |
|
| 66 | - $instance = new static(); |
|
| 67 | - $instance->setTagFromMethod($method); |
|
| 68 | - call_user_func_array([$instance, 'normalize'], $args += ['', '']); |
|
| 69 | - $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT); |
|
| 70 | - do_action_ref_array('site-reviews/builder', [$instance]); |
|
| 71 | - $generatedTag = in_array($instance->tag, $tags) |
|
| 72 | - ? $instance->buildTag() |
|
| 73 | - : $instance->buildCustomField(); |
|
| 74 | - $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance); |
|
| 75 | - if (!$this->render) { |
|
| 76 | - return $generatedTag; |
|
| 77 | - } |
|
| 78 | - echo $generatedTag; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @param string $property |
|
| 83 | - * @param mixed $value |
|
| 84 | - * @return void |
|
| 85 | - */ |
|
| 86 | - public function __set($property, $value) |
|
| 87 | - { |
|
| 88 | - $properties = [ |
|
| 89 | - 'args' => 'is_array', |
|
| 90 | - 'render' => 'is_bool', |
|
| 91 | - 'tag' => 'is_string', |
|
| 92 | - ]; |
|
| 93 | - if (!isset($properties[$property]) |
|
| 94 | - || empty(array_filter([$value], $properties[$property])) |
|
| 95 | - ) { |
|
| 96 | - return; |
|
| 97 | - } |
|
| 98 | - $this->$property = $value; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @return void|string |
|
| 103 | - */ |
|
| 104 | - public function getClosingTag() |
|
| 105 | - { |
|
| 106 | - if (empty($this->tag)) { |
|
| 107 | - return; |
|
| 108 | - } |
|
| 109 | - return '</'.$this->tag.'>'; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @return void|string |
|
| 114 | - */ |
|
| 115 | - public function getOpeningTag() |
|
| 116 | - { |
|
| 117 | - if (empty($this->tag)) { |
|
| 118 | - return; |
|
| 119 | - } |
|
| 120 | - $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString(); |
|
| 121 | - return '<'.trim($this->tag.' '.$attributes).'>'; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @return void|string |
|
| 126 | - */ |
|
| 127 | - public function getTag() |
|
| 128 | - { |
|
| 129 | - if (in_array($this->tag, static::TAGS_SINGLE)) { |
|
| 130 | - return $this->getOpeningTag(); |
|
| 131 | - } |
|
| 132 | - if (!in_array($this->tag, static::TAGS_FORM)) { |
|
| 133 | - return $this->buildDefaultTag(); |
|
| 134 | - } |
|
| 135 | - return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription(); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @return string |
|
| 140 | - */ |
|
| 141 | - public function raw(array $field) |
|
| 142 | - { |
|
| 143 | - unset($field['label']); |
|
| 144 | - return $this->{$field['type']}($field); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @return string|void |
|
| 149 | - */ |
|
| 150 | - protected function buildCustomField() |
|
| 151 | - { |
|
| 152 | - $className = $this->getCustomFieldClassName(); |
|
| 153 | - if (class_exists($className)) { |
|
| 154 | - return (new $className($this))->build(); |
|
| 155 | - } |
|
| 156 | - glsr_log()->error('Field missing: '.$className); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @return string|void |
|
| 161 | - */ |
|
| 162 | - protected function buildDefaultTag($text = '') |
|
| 163 | - { |
|
| 164 | - if (empty($text)) { |
|
| 165 | - $text = $this->args['text']; |
|
| 166 | - } |
|
| 167 | - return $this->getOpeningTag().$text.$this->getClosingTag(); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @return string|void |
|
| 172 | - */ |
|
| 173 | - protected function buildFieldDescription() |
|
| 174 | - { |
|
| 175 | - if (empty($this->args['description'])) { |
|
| 176 | - return; |
|
| 177 | - } |
|
| 178 | - if ($this->args['is_widget']) { |
|
| 179 | - return $this->small($this->args['description']); |
|
| 180 | - } |
|
| 181 | - return $this->p($this->args['description'], ['class' => 'description']); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @return string|void |
|
| 186 | - */ |
|
| 187 | - protected function buildFormInput() |
|
| 188 | - { |
|
| 189 | - if (!in_array($this->args['type'], ['checkbox', 'radio'])) { |
|
| 190 | - if (isset($this->args['multiple'])) { |
|
| 191 | - $this->args['name'].= '[]'; |
|
| 192 | - } |
|
| 193 | - return $this->buildFormLabel().$this->getOpeningTag(); |
|
| 194 | - } |
|
| 195 | - return empty($this->args['options']) |
|
| 196 | - ? $this->buildFormInputChoice() |
|
| 197 | - : $this->buildFormInputMultiChoice(); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * @return string|void |
|
| 202 | - */ |
|
| 203 | - protected function buildFormInputChoice() |
|
| 204 | - { |
|
| 205 | - if (!empty($this->args['text'])) { |
|
| 206 | - $this->args['label'] = $this->args['text']; |
|
| 207 | - } |
|
| 208 | - if (!$this->args['is_public']) { |
|
| 209 | - return $this->buildFormLabel([ |
|
| 210 | - 'class' => 'glsr-'.$this->args['type'].'-label', |
|
| 211 | - 'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>', |
|
| 212 | - ]); |
|
| 213 | - } |
|
| 214 | - return $this->getOpeningTag().$this->buildFormLabel([ |
|
| 215 | - 'class' => 'glsr-'.$this->args['type'].'-label', |
|
| 216 | - 'text' => $this->args['label'].'<span></span>', |
|
| 217 | - ]); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * @return string|void |
|
| 222 | - */ |
|
| 223 | - protected function buildFormInputMultiChoice() |
|
| 224 | - { |
|
| 225 | - if ('checkbox' == $this->args['type']) { |
|
| 226 | - $this->args['name'].= '[]'; |
|
| 227 | - } |
|
| 228 | - $index = 0; |
|
| 229 | - $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) { |
|
| 230 | - return $carry.$this->li($this->{$this->args['type']}([ |
|
| 231 | - 'checked' => in_array($key, (array) $this->args['value']), |
|
| 232 | - 'id' => $this->args['id'].'-'.$index++, |
|
| 233 | - 'name' => $this->args['name'], |
|
| 234 | - 'text' => $this->args['options'][$key], |
|
| 235 | - 'value' => $key, |
|
| 236 | - ])); |
|
| 237 | - }); |
|
| 238 | - return $this->ul($options, [ |
|
| 239 | - 'class' => $this->args['class'], |
|
| 240 | - 'id' => $this->args['id'], |
|
| 241 | - ]); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * @return void|string |
|
| 246 | - */ |
|
| 247 | - protected function buildFormLabel(array $customArgs = []) |
|
| 248 | - { |
|
| 249 | - if (empty($this->args['label']) || 'hidden' == $this->args['type']) { |
|
| 250 | - return; |
|
| 251 | - } |
|
| 252 | - return $this->label(wp_parse_args($customArgs, [ |
|
| 253 | - 'for' => $this->args['id'], |
|
| 254 | - 'is_public' => $this->args['is_public'], |
|
| 255 | - 'text' => $this->args['label'], |
|
| 256 | - 'type' => $this->args['type'], |
|
| 257 | - ])); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * @return string|void |
|
| 262 | - */ |
|
| 263 | - protected function buildFormSelect() |
|
| 264 | - { |
|
| 265 | - return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions()); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * @return string|void |
|
| 270 | - */ |
|
| 271 | - protected function buildFormSelectOptions() |
|
| 272 | - { |
|
| 273 | - return array_reduce(array_keys($this->args['options']), function ($carry, $key) { |
|
| 274 | - return $carry.$this->option([ |
|
| 275 | - 'selected' => $this->args['value'] === (string) $key, |
|
| 276 | - 'text' => $this->args['options'][$key], |
|
| 277 | - 'value' => $key, |
|
| 278 | - ]); |
|
| 279 | - }); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * @return string|void |
|
| 284 | - */ |
|
| 285 | - protected function buildFormTextarea() |
|
| 286 | - { |
|
| 287 | - return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * @return string|void |
|
| 292 | - */ |
|
| 293 | - protected function buildTag() |
|
| 294 | - { |
|
| 295 | - $this->mergeArgsWithRequiredDefaults(); |
|
| 296 | - return $this->getTag(); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * @return string |
|
| 301 | - */ |
|
| 302 | - protected function getCustomFieldClassName() |
|
| 303 | - { |
|
| 304 | - $classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields'); |
|
| 305 | - return apply_filters('site-reviews/builder/field/'.$this->tag, $classname); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * @return void |
|
| 310 | - */ |
|
| 311 | - protected function mergeArgsWithRequiredDefaults() |
|
| 312 | - { |
|
| 313 | - $className = $this->getCustomFieldClassName(); |
|
| 314 | - if (class_exists($className)) { |
|
| 315 | - $this->args = $className::merge($this->args); |
|
| 316 | - } |
|
| 317 | - $this->args = glsr(BuilderDefaults::class)->merge($this->args); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * @param string|array ...$params |
|
| 322 | - * @return void |
|
| 323 | - */ |
|
| 324 | - protected function normalize(...$params) |
|
| 325 | - { |
|
| 326 | - if (is_string($params[0]) || is_numeric($params[0])) { |
|
| 327 | - $this->setNameOrTextAttributeForTag($params[0]); |
|
| 328 | - } |
|
| 329 | - if (is_array($params[0])) { |
|
| 330 | - $this->args += $params[0]; |
|
| 331 | - } elseif (is_array($params[1])) { |
|
| 332 | - $this->args += $params[1]; |
|
| 333 | - } |
|
| 334 | - if (!isset($this->args['is_public'])) { |
|
| 335 | - $this->args['is_public'] = false; |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * @param string $value |
|
| 341 | - * @return void |
|
| 342 | - */ |
|
| 343 | - protected function setNameOrTextAttributeForTag($value) |
|
| 344 | - { |
|
| 345 | - $attribute = in_array($this->tag, static::TAGS_FORM) |
|
| 346 | - ? 'name' |
|
| 347 | - : 'text'; |
|
| 348 | - $this->args[$attribute] = $value; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * @param string $method |
|
| 353 | - * @return void |
|
| 354 | - */ |
|
| 355 | - protected function setTagFromMethod($method) |
|
| 356 | - { |
|
| 357 | - $this->tag = strtolower($method); |
|
| 358 | - if (in_array($this->tag, static::INPUT_TYPES)) { |
|
| 359 | - $this->args['type'] = $this->tag; |
|
| 360 | - $this->tag = 'input'; |
|
| 361 | - } |
|
| 362 | - } |
|
| 21 | + const INPUT_TYPES = [ |
|
| 22 | + 'checkbox', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month', |
|
| 23 | + 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time', |
|
| 24 | + 'url', 'week', |
|
| 25 | + ]; |
|
| 26 | + |
|
| 27 | + const TAGS_FORM = [ |
|
| 28 | + 'input', 'select', 'textarea', |
|
| 29 | + ]; |
|
| 30 | + |
|
| 31 | + const TAGS_SINGLE = [ |
|
| 32 | + 'img', |
|
| 33 | + ]; |
|
| 34 | + |
|
| 35 | + const TAGS_STRUCTURE = [ |
|
| 36 | + 'div', 'form', 'nav', 'ol', 'section', 'ul', |
|
| 37 | + ]; |
|
| 38 | + |
|
| 39 | + const TAGS_TEXT = [ |
|
| 40 | + 'a', 'button', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'label', 'li', 'option', 'p', 'pre', |
|
| 41 | + 'small', 'span', |
|
| 42 | + ]; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + public $args = []; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var bool |
|
| 51 | + */ |
|
| 52 | + public $render = false; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var string |
|
| 56 | + */ |
|
| 57 | + public $tag; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @param string $method |
|
| 61 | + * @param array $args |
|
| 62 | + * @return string|void |
|
| 63 | + */ |
|
| 64 | + public function __call($method, $args) |
|
| 65 | + { |
|
| 66 | + $instance = new static(); |
|
| 67 | + $instance->setTagFromMethod($method); |
|
| 68 | + call_user_func_array([$instance, 'normalize'], $args += ['', '']); |
|
| 69 | + $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT); |
|
| 70 | + do_action_ref_array('site-reviews/builder', [$instance]); |
|
| 71 | + $generatedTag = in_array($instance->tag, $tags) |
|
| 72 | + ? $instance->buildTag() |
|
| 73 | + : $instance->buildCustomField(); |
|
| 74 | + $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance); |
|
| 75 | + if (!$this->render) { |
|
| 76 | + return $generatedTag; |
|
| 77 | + } |
|
| 78 | + echo $generatedTag; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @param string $property |
|
| 83 | + * @param mixed $value |
|
| 84 | + * @return void |
|
| 85 | + */ |
|
| 86 | + public function __set($property, $value) |
|
| 87 | + { |
|
| 88 | + $properties = [ |
|
| 89 | + 'args' => 'is_array', |
|
| 90 | + 'render' => 'is_bool', |
|
| 91 | + 'tag' => 'is_string', |
|
| 92 | + ]; |
|
| 93 | + if (!isset($properties[$property]) |
|
| 94 | + || empty(array_filter([$value], $properties[$property])) |
|
| 95 | + ) { |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + $this->$property = $value; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @return void|string |
|
| 103 | + */ |
|
| 104 | + public function getClosingTag() |
|
| 105 | + { |
|
| 106 | + if (empty($this->tag)) { |
|
| 107 | + return; |
|
| 108 | + } |
|
| 109 | + return '</'.$this->tag.'>'; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @return void|string |
|
| 114 | + */ |
|
| 115 | + public function getOpeningTag() |
|
| 116 | + { |
|
| 117 | + if (empty($this->tag)) { |
|
| 118 | + return; |
|
| 119 | + } |
|
| 120 | + $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString(); |
|
| 121 | + return '<'.trim($this->tag.' '.$attributes).'>'; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @return void|string |
|
| 126 | + */ |
|
| 127 | + public function getTag() |
|
| 128 | + { |
|
| 129 | + if (in_array($this->tag, static::TAGS_SINGLE)) { |
|
| 130 | + return $this->getOpeningTag(); |
|
| 131 | + } |
|
| 132 | + if (!in_array($this->tag, static::TAGS_FORM)) { |
|
| 133 | + return $this->buildDefaultTag(); |
|
| 134 | + } |
|
| 135 | + return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription(); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @return string |
|
| 140 | + */ |
|
| 141 | + public function raw(array $field) |
|
| 142 | + { |
|
| 143 | + unset($field['label']); |
|
| 144 | + return $this->{$field['type']}($field); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @return string|void |
|
| 149 | + */ |
|
| 150 | + protected function buildCustomField() |
|
| 151 | + { |
|
| 152 | + $className = $this->getCustomFieldClassName(); |
|
| 153 | + if (class_exists($className)) { |
|
| 154 | + return (new $className($this))->build(); |
|
| 155 | + } |
|
| 156 | + glsr_log()->error('Field missing: '.$className); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @return string|void |
|
| 161 | + */ |
|
| 162 | + protected function buildDefaultTag($text = '') |
|
| 163 | + { |
|
| 164 | + if (empty($text)) { |
|
| 165 | + $text = $this->args['text']; |
|
| 166 | + } |
|
| 167 | + return $this->getOpeningTag().$text.$this->getClosingTag(); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @return string|void |
|
| 172 | + */ |
|
| 173 | + protected function buildFieldDescription() |
|
| 174 | + { |
|
| 175 | + if (empty($this->args['description'])) { |
|
| 176 | + return; |
|
| 177 | + } |
|
| 178 | + if ($this->args['is_widget']) { |
|
| 179 | + return $this->small($this->args['description']); |
|
| 180 | + } |
|
| 181 | + return $this->p($this->args['description'], ['class' => 'description']); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @return string|void |
|
| 186 | + */ |
|
| 187 | + protected function buildFormInput() |
|
| 188 | + { |
|
| 189 | + if (!in_array($this->args['type'], ['checkbox', 'radio'])) { |
|
| 190 | + if (isset($this->args['multiple'])) { |
|
| 191 | + $this->args['name'].= '[]'; |
|
| 192 | + } |
|
| 193 | + return $this->buildFormLabel().$this->getOpeningTag(); |
|
| 194 | + } |
|
| 195 | + return empty($this->args['options']) |
|
| 196 | + ? $this->buildFormInputChoice() |
|
| 197 | + : $this->buildFormInputMultiChoice(); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * @return string|void |
|
| 202 | + */ |
|
| 203 | + protected function buildFormInputChoice() |
|
| 204 | + { |
|
| 205 | + if (!empty($this->args['text'])) { |
|
| 206 | + $this->args['label'] = $this->args['text']; |
|
| 207 | + } |
|
| 208 | + if (!$this->args['is_public']) { |
|
| 209 | + return $this->buildFormLabel([ |
|
| 210 | + 'class' => 'glsr-'.$this->args['type'].'-label', |
|
| 211 | + 'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>', |
|
| 212 | + ]); |
|
| 213 | + } |
|
| 214 | + return $this->getOpeningTag().$this->buildFormLabel([ |
|
| 215 | + 'class' => 'glsr-'.$this->args['type'].'-label', |
|
| 216 | + 'text' => $this->args['label'].'<span></span>', |
|
| 217 | + ]); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * @return string|void |
|
| 222 | + */ |
|
| 223 | + protected function buildFormInputMultiChoice() |
|
| 224 | + { |
|
| 225 | + if ('checkbox' == $this->args['type']) { |
|
| 226 | + $this->args['name'].= '[]'; |
|
| 227 | + } |
|
| 228 | + $index = 0; |
|
| 229 | + $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) { |
|
| 230 | + return $carry.$this->li($this->{$this->args['type']}([ |
|
| 231 | + 'checked' => in_array($key, (array) $this->args['value']), |
|
| 232 | + 'id' => $this->args['id'].'-'.$index++, |
|
| 233 | + 'name' => $this->args['name'], |
|
| 234 | + 'text' => $this->args['options'][$key], |
|
| 235 | + 'value' => $key, |
|
| 236 | + ])); |
|
| 237 | + }); |
|
| 238 | + return $this->ul($options, [ |
|
| 239 | + 'class' => $this->args['class'], |
|
| 240 | + 'id' => $this->args['id'], |
|
| 241 | + ]); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * @return void|string |
|
| 246 | + */ |
|
| 247 | + protected function buildFormLabel(array $customArgs = []) |
|
| 248 | + { |
|
| 249 | + if (empty($this->args['label']) || 'hidden' == $this->args['type']) { |
|
| 250 | + return; |
|
| 251 | + } |
|
| 252 | + return $this->label(wp_parse_args($customArgs, [ |
|
| 253 | + 'for' => $this->args['id'], |
|
| 254 | + 'is_public' => $this->args['is_public'], |
|
| 255 | + 'text' => $this->args['label'], |
|
| 256 | + 'type' => $this->args['type'], |
|
| 257 | + ])); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * @return string|void |
|
| 262 | + */ |
|
| 263 | + protected function buildFormSelect() |
|
| 264 | + { |
|
| 265 | + return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions()); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * @return string|void |
|
| 270 | + */ |
|
| 271 | + protected function buildFormSelectOptions() |
|
| 272 | + { |
|
| 273 | + return array_reduce(array_keys($this->args['options']), function ($carry, $key) { |
|
| 274 | + return $carry.$this->option([ |
|
| 275 | + 'selected' => $this->args['value'] === (string) $key, |
|
| 276 | + 'text' => $this->args['options'][$key], |
|
| 277 | + 'value' => $key, |
|
| 278 | + ]); |
|
| 279 | + }); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * @return string|void |
|
| 284 | + */ |
|
| 285 | + protected function buildFormTextarea() |
|
| 286 | + { |
|
| 287 | + return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * @return string|void |
|
| 292 | + */ |
|
| 293 | + protected function buildTag() |
|
| 294 | + { |
|
| 295 | + $this->mergeArgsWithRequiredDefaults(); |
|
| 296 | + return $this->getTag(); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * @return string |
|
| 301 | + */ |
|
| 302 | + protected function getCustomFieldClassName() |
|
| 303 | + { |
|
| 304 | + $classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields'); |
|
| 305 | + return apply_filters('site-reviews/builder/field/'.$this->tag, $classname); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * @return void |
|
| 310 | + */ |
|
| 311 | + protected function mergeArgsWithRequiredDefaults() |
|
| 312 | + { |
|
| 313 | + $className = $this->getCustomFieldClassName(); |
|
| 314 | + if (class_exists($className)) { |
|
| 315 | + $this->args = $className::merge($this->args); |
|
| 316 | + } |
|
| 317 | + $this->args = glsr(BuilderDefaults::class)->merge($this->args); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * @param string|array ...$params |
|
| 322 | + * @return void |
|
| 323 | + */ |
|
| 324 | + protected function normalize(...$params) |
|
| 325 | + { |
|
| 326 | + if (is_string($params[0]) || is_numeric($params[0])) { |
|
| 327 | + $this->setNameOrTextAttributeForTag($params[0]); |
|
| 328 | + } |
|
| 329 | + if (is_array($params[0])) { |
|
| 330 | + $this->args += $params[0]; |
|
| 331 | + } elseif (is_array($params[1])) { |
|
| 332 | + $this->args += $params[1]; |
|
| 333 | + } |
|
| 334 | + if (!isset($this->args['is_public'])) { |
|
| 335 | + $this->args['is_public'] = false; |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * @param string $value |
|
| 341 | + * @return void |
|
| 342 | + */ |
|
| 343 | + protected function setNameOrTextAttributeForTag($value) |
|
| 344 | + { |
|
| 345 | + $attribute = in_array($this->tag, static::TAGS_FORM) |
|
| 346 | + ? 'name' |
|
| 347 | + : 'text'; |
|
| 348 | + $this->args[$attribute] = $value; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * @param string $method |
|
| 353 | + * @return void |
|
| 354 | + */ |
|
| 355 | + protected function setTagFromMethod($method) |
|
| 356 | + { |
|
| 357 | + $this->tag = strtolower($method); |
|
| 358 | + if (in_array($this->tag, static::INPUT_TYPES)) { |
|
| 359 | + $this->args['type'] = $this->tag; |
|
| 360 | + $this->tag = 'input'; |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | 363 | } |
@@ -61,18 +61,18 @@ discard block |
||
| 61 | 61 | * @param array $args |
| 62 | 62 | * @return string|void |
| 63 | 63 | */ |
| 64 | - public function __call($method, $args) |
|
| 64 | + public function __call( $method, $args ) |
|
| 65 | 65 | { |
| 66 | 66 | $instance = new static(); |
| 67 | - $instance->setTagFromMethod($method); |
|
| 68 | - call_user_func_array([$instance, 'normalize'], $args += ['', '']); |
|
| 69 | - $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT); |
|
| 70 | - do_action_ref_array('site-reviews/builder', [$instance]); |
|
| 71 | - $generatedTag = in_array($instance->tag, $tags) |
|
| 67 | + $instance->setTagFromMethod( $method ); |
|
| 68 | + call_user_func_array( [$instance, 'normalize'], $args += ['', ''] ); |
|
| 69 | + $tags = array_merge( static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT ); |
|
| 70 | + do_action_ref_array( 'site-reviews/builder', [$instance] ); |
|
| 71 | + $generatedTag = in_array( $instance->tag, $tags ) |
|
| 72 | 72 | ? $instance->buildTag() |
| 73 | 73 | : $instance->buildCustomField(); |
| 74 | - $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance); |
|
| 75 | - if (!$this->render) { |
|
| 74 | + $generatedTag = apply_filters( 'site-reviews/builder/result', $generatedTag, $instance ); |
|
| 75 | + if( !$this->render ) { |
|
| 76 | 76 | return $generatedTag; |
| 77 | 77 | } |
| 78 | 78 | echo $generatedTag; |
@@ -83,15 +83,15 @@ discard block |
||
| 83 | 83 | * @param mixed $value |
| 84 | 84 | * @return void |
| 85 | 85 | */ |
| 86 | - public function __set($property, $value) |
|
| 86 | + public function __set( $property, $value ) |
|
| 87 | 87 | { |
| 88 | 88 | $properties = [ |
| 89 | 89 | 'args' => 'is_array', |
| 90 | 90 | 'render' => 'is_bool', |
| 91 | 91 | 'tag' => 'is_string', |
| 92 | 92 | ]; |
| 93 | - if (!isset($properties[$property]) |
|
| 94 | - || empty(array_filter([$value], $properties[$property])) |
|
| 93 | + if( !isset($properties[$property]) |
|
| 94 | + || empty(array_filter( [$value], $properties[$property] )) |
|
| 95 | 95 | ) { |
| 96 | 96 | return; |
| 97 | 97 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function getClosingTag() |
| 105 | 105 | { |
| 106 | - if (empty($this->tag)) { |
|
| 106 | + if( empty($this->tag) ) { |
|
| 107 | 107 | return; |
| 108 | 108 | } |
| 109 | 109 | return '</'.$this->tag.'>'; |
@@ -114,11 +114,11 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | public function getOpeningTag() |
| 116 | 116 | { |
| 117 | - if (empty($this->tag)) { |
|
| 117 | + if( empty($this->tag) ) { |
|
| 118 | 118 | return; |
| 119 | 119 | } |
| 120 | - $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString(); |
|
| 121 | - return '<'.trim($this->tag.' '.$attributes).'>'; |
|
| 120 | + $attributes = glsr( Attributes::class )->{$this->tag}($this->args)->toString(); |
|
| 121 | + return '<'.trim( $this->tag.' '.$attributes ).'>'; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -126,19 +126,19 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function getTag() |
| 128 | 128 | { |
| 129 | - if (in_array($this->tag, static::TAGS_SINGLE)) { |
|
| 129 | + if( in_array( $this->tag, static::TAGS_SINGLE ) ) { |
|
| 130 | 130 | return $this->getOpeningTag(); |
| 131 | 131 | } |
| 132 | - if (!in_array($this->tag, static::TAGS_FORM)) { |
|
| 132 | + if( !in_array( $this->tag, static::TAGS_FORM ) ) { |
|
| 133 | 133 | return $this->buildDefaultTag(); |
| 134 | 134 | } |
| 135 | - return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription(); |
|
| 135 | + return call_user_func( [$this, 'buildForm'.ucfirst( $this->tag )] ).$this->buildFieldDescription(); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
| 139 | 139 | * @return string |
| 140 | 140 | */ |
| 141 | - public function raw(array $field) |
|
| 141 | + public function raw( array $field ) |
|
| 142 | 142 | { |
| 143 | 143 | unset($field['label']); |
| 144 | 144 | return $this->{$field['type']}($field); |
@@ -150,18 +150,18 @@ discard block |
||
| 150 | 150 | protected function buildCustomField() |
| 151 | 151 | { |
| 152 | 152 | $className = $this->getCustomFieldClassName(); |
| 153 | - if (class_exists($className)) { |
|
| 154 | - return (new $className($this))->build(); |
|
| 153 | + if( class_exists( $className ) ) { |
|
| 154 | + return (new $className( $this ))->build(); |
|
| 155 | 155 | } |
| 156 | - glsr_log()->error('Field missing: '.$className); |
|
| 156 | + glsr_log()->error( 'Field missing: '.$className ); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
| 160 | 160 | * @return string|void |
| 161 | 161 | */ |
| 162 | - protected function buildDefaultTag($text = '') |
|
| 162 | + protected function buildDefaultTag( $text = '' ) |
|
| 163 | 163 | { |
| 164 | - if (empty($text)) { |
|
| 164 | + if( empty($text) ) { |
|
| 165 | 165 | $text = $this->args['text']; |
| 166 | 166 | } |
| 167 | 167 | return $this->getOpeningTag().$text.$this->getClosingTag(); |
@@ -172,13 +172,13 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | protected function buildFieldDescription() |
| 174 | 174 | { |
| 175 | - if (empty($this->args['description'])) { |
|
| 175 | + if( empty($this->args['description']) ) { |
|
| 176 | 176 | return; |
| 177 | 177 | } |
| 178 | - if ($this->args['is_widget']) { |
|
| 179 | - return $this->small($this->args['description']); |
|
| 178 | + if( $this->args['is_widget'] ) { |
|
| 179 | + return $this->small( $this->args['description'] ); |
|
| 180 | 180 | } |
| 181 | - return $this->p($this->args['description'], ['class' => 'description']); |
|
| 181 | + return $this->p( $this->args['description'], ['class' => 'description'] ); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -186,9 +186,9 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | protected function buildFormInput() |
| 188 | 188 | { |
| 189 | - if (!in_array($this->args['type'], ['checkbox', 'radio'])) { |
|
| 190 | - if (isset($this->args['multiple'])) { |
|
| 191 | - $this->args['name'].= '[]'; |
|
| 189 | + if( !in_array( $this->args['type'], ['checkbox', 'radio'] ) ) { |
|
| 190 | + if( isset($this->args['multiple']) ) { |
|
| 191 | + $this->args['name'] .= '[]'; |
|
| 192 | 192 | } |
| 193 | 193 | return $this->buildFormLabel().$this->getOpeningTag(); |
| 194 | 194 | } |
@@ -202,19 +202,19 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | protected function buildFormInputChoice() |
| 204 | 204 | { |
| 205 | - if (!empty($this->args['text'])) { |
|
| 205 | + if( !empty($this->args['text']) ) { |
|
| 206 | 206 | $this->args['label'] = $this->args['text']; |
| 207 | 207 | } |
| 208 | - if (!$this->args['is_public']) { |
|
| 209 | - return $this->buildFormLabel([ |
|
| 208 | + if( !$this->args['is_public'] ) { |
|
| 209 | + return $this->buildFormLabel( [ |
|
| 210 | 210 | 'class' => 'glsr-'.$this->args['type'].'-label', |
| 211 | 211 | 'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>', |
| 212 | - ]); |
|
| 212 | + ] ); |
|
| 213 | 213 | } |
| 214 | - return $this->getOpeningTag().$this->buildFormLabel([ |
|
| 214 | + return $this->getOpeningTag().$this->buildFormLabel( [ |
|
| 215 | 215 | 'class' => 'glsr-'.$this->args['type'].'-label', |
| 216 | 216 | 'text' => $this->args['label'].'<span></span>', |
| 217 | - ]); |
|
| 217 | + ] ); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -222,39 +222,39 @@ discard block |
||
| 222 | 222 | */ |
| 223 | 223 | protected function buildFormInputMultiChoice() |
| 224 | 224 | { |
| 225 | - if ('checkbox' == $this->args['type']) { |
|
| 226 | - $this->args['name'].= '[]'; |
|
| 225 | + if( 'checkbox' == $this->args['type'] ) { |
|
| 226 | + $this->args['name'] .= '[]'; |
|
| 227 | 227 | } |
| 228 | 228 | $index = 0; |
| 229 | - $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) { |
|
| 230 | - return $carry.$this->li($this->{$this->args['type']}([ |
|
| 231 | - 'checked' => in_array($key, (array) $this->args['value']), |
|
| 229 | + $options = array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) use (&$index) { |
|
| 230 | + return $carry.$this->li( $this->{$this->args['type']}([ |
|
| 231 | + 'checked' => in_array( $key, (array)$this->args['value'] ), |
|
| 232 | 232 | 'id' => $this->args['id'].'-'.$index++, |
| 233 | 233 | 'name' => $this->args['name'], |
| 234 | 234 | 'text' => $this->args['options'][$key], |
| 235 | 235 | 'value' => $key, |
| 236 | - ])); |
|
| 236 | + ]) ); |
|
| 237 | 237 | }); |
| 238 | - return $this->ul($options, [ |
|
| 238 | + return $this->ul( $options, [ |
|
| 239 | 239 | 'class' => $this->args['class'], |
| 240 | 240 | 'id' => $this->args['id'], |
| 241 | - ]); |
|
| 241 | + ] ); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
| 245 | 245 | * @return void|string |
| 246 | 246 | */ |
| 247 | - protected function buildFormLabel(array $customArgs = []) |
|
| 247 | + protected function buildFormLabel( array $customArgs = [] ) |
|
| 248 | 248 | { |
| 249 | - if (empty($this->args['label']) || 'hidden' == $this->args['type']) { |
|
| 249 | + if( empty($this->args['label']) || 'hidden' == $this->args['type'] ) { |
|
| 250 | 250 | return; |
| 251 | 251 | } |
| 252 | - return $this->label(wp_parse_args($customArgs, [ |
|
| 252 | + return $this->label( wp_parse_args( $customArgs, [ |
|
| 253 | 253 | 'for' => $this->args['id'], |
| 254 | 254 | 'is_public' => $this->args['is_public'], |
| 255 | 255 | 'text' => $this->args['label'], |
| 256 | 256 | 'type' => $this->args['type'], |
| 257 | - ])); |
|
| 257 | + ] ) ); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | protected function buildFormSelect() |
| 264 | 264 | { |
| 265 | - return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions()); |
|
| 265 | + return $this->buildFormLabel().$this->buildDefaultTag( $this->buildFormSelectOptions() ); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -270,12 +270,12 @@ discard block |
||
| 270 | 270 | */ |
| 271 | 271 | protected function buildFormSelectOptions() |
| 272 | 272 | { |
| 273 | - return array_reduce(array_keys($this->args['options']), function ($carry, $key) { |
|
| 274 | - return $carry.$this->option([ |
|
| 275 | - 'selected' => $this->args['value'] === (string) $key, |
|
| 273 | + return array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) { |
|
| 274 | + return $carry.$this->option( [ |
|
| 275 | + 'selected' => $this->args['value'] === (string)$key, |
|
| 276 | 276 | 'text' => $this->args['options'][$key], |
| 277 | 277 | 'value' => $key, |
| 278 | - ]); |
|
| 278 | + ] ); |
|
| 279 | 279 | }); |
| 280 | 280 | } |
| 281 | 281 | |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | */ |
| 285 | 285 | protected function buildFormTextarea() |
| 286 | 286 | { |
| 287 | - return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']); |
|
| 287 | + return $this->buildFormLabel().$this->buildDefaultTag( $this->args['value'] ); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -301,8 +301,8 @@ discard block |
||
| 301 | 301 | */ |
| 302 | 302 | protected function getCustomFieldClassName() |
| 303 | 303 | { |
| 304 | - $classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields'); |
|
| 305 | - return apply_filters('site-reviews/builder/field/'.$this->tag, $classname); |
|
| 304 | + $classname = Helper::buildClassName( $this->tag, __NAMESPACE__.'\Fields' ); |
|
| 305 | + return apply_filters( 'site-reviews/builder/field/'.$this->tag, $classname ); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -311,27 +311,27 @@ discard block |
||
| 311 | 311 | protected function mergeArgsWithRequiredDefaults() |
| 312 | 312 | { |
| 313 | 313 | $className = $this->getCustomFieldClassName(); |
| 314 | - if (class_exists($className)) { |
|
| 315 | - $this->args = $className::merge($this->args); |
|
| 314 | + if( class_exists( $className ) ) { |
|
| 315 | + $this->args = $className::merge( $this->args ); |
|
| 316 | 316 | } |
| 317 | - $this->args = glsr(BuilderDefaults::class)->merge($this->args); |
|
| 317 | + $this->args = glsr( BuilderDefaults::class )->merge( $this->args ); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | /** |
| 321 | 321 | * @param string|array ...$params |
| 322 | 322 | * @return void |
| 323 | 323 | */ |
| 324 | - protected function normalize(...$params) |
|
| 324 | + protected function normalize( ...$params ) |
|
| 325 | 325 | { |
| 326 | - if (is_string($params[0]) || is_numeric($params[0])) { |
|
| 327 | - $this->setNameOrTextAttributeForTag($params[0]); |
|
| 326 | + if( is_string( $params[0] ) || is_numeric( $params[0] ) ) { |
|
| 327 | + $this->setNameOrTextAttributeForTag( $params[0] ); |
|
| 328 | 328 | } |
| 329 | - if (is_array($params[0])) { |
|
| 329 | + if( is_array( $params[0] ) ) { |
|
| 330 | 330 | $this->args += $params[0]; |
| 331 | - } elseif (is_array($params[1])) { |
|
| 331 | + } elseif( is_array( $params[1] ) ) { |
|
| 332 | 332 | $this->args += $params[1]; |
| 333 | 333 | } |
| 334 | - if (!isset($this->args['is_public'])) { |
|
| 334 | + if( !isset($this->args['is_public']) ) { |
|
| 335 | 335 | $this->args['is_public'] = false; |
| 336 | 336 | } |
| 337 | 337 | } |
@@ -340,9 +340,9 @@ discard block |
||
| 340 | 340 | * @param string $value |
| 341 | 341 | * @return void |
| 342 | 342 | */ |
| 343 | - protected function setNameOrTextAttributeForTag($value) |
|
| 343 | + protected function setNameOrTextAttributeForTag( $value ) |
|
| 344 | 344 | { |
| 345 | - $attribute = in_array($this->tag, static::TAGS_FORM) |
|
| 345 | + $attribute = in_array( $this->tag, static::TAGS_FORM ) |
|
| 346 | 346 | ? 'name' |
| 347 | 347 | : 'text'; |
| 348 | 348 | $this->args[$attribute] = $value; |
@@ -352,10 +352,10 @@ discard block |
||
| 352 | 352 | * @param string $method |
| 353 | 353 | * @return void |
| 354 | 354 | */ |
| 355 | - protected function setTagFromMethod($method) |
|
| 355 | + protected function setTagFromMethod( $method ) |
|
| 356 | 356 | { |
| 357 | - $this->tag = strtolower($method); |
|
| 358 | - if (in_array($this->tag, static::INPUT_TYPES)) { |
|
| 357 | + $this->tag = strtolower( $method ); |
|
| 358 | + if( in_array( $this->tag, static::INPUT_TYPES ) ) { |
|
| 359 | 359 | $this->args['type'] = $this->tag; |
| 360 | 360 | $this->tag = 'input'; |
| 361 | 361 | } |
@@ -4,13 +4,13 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Hidden extends Field |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @return array |
|
| 9 | - */ |
|
| 10 | - public static function required() |
|
| 11 | - { |
|
| 12 | - return [ |
|
| 13 | - 'is_raw' => true, |
|
| 14 | - ]; |
|
| 15 | - } |
|
| 7 | + /** |
|
| 8 | + * @return array |
|
| 9 | + */ |
|
| 10 | + public static function required() |
|
| 11 | + { |
|
| 12 | + return [ |
|
| 13 | + 'is_raw' => true, |
|
| 14 | + ]; |
|
| 15 | + } |
|
| 16 | 16 | } |
@@ -4,33 +4,33 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Code extends Field |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @return string|void |
|
| 9 | - */ |
|
| 10 | - public function build() |
|
| 11 | - { |
|
| 12 | - $this->builder->tag = 'textarea'; |
|
| 13 | - $this->mergeFieldArgs(); |
|
| 14 | - return $this->builder->getTag(); |
|
| 15 | - } |
|
| 7 | + /** |
|
| 8 | + * @return string|void |
|
| 9 | + */ |
|
| 10 | + public function build() |
|
| 11 | + { |
|
| 12 | + $this->builder->tag = 'textarea'; |
|
| 13 | + $this->mergeFieldArgs(); |
|
| 14 | + return $this->builder->getTag(); |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @return array |
|
| 19 | - */ |
|
| 20 | - public static function defaults() |
|
| 21 | - { |
|
| 22 | - return [ |
|
| 23 | - 'class' => 'large-text code', |
|
| 24 | - ]; |
|
| 25 | - } |
|
| 17 | + /** |
|
| 18 | + * @return array |
|
| 19 | + */ |
|
| 20 | + public static function defaults() |
|
| 21 | + { |
|
| 22 | + return [ |
|
| 23 | + 'class' => 'large-text code', |
|
| 24 | + ]; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @return array |
|
| 29 | - */ |
|
| 30 | - public static function required() |
|
| 31 | - { |
|
| 32 | - return [ |
|
| 33 | - 'type' => 'textarea', |
|
| 34 | - ]; |
|
| 35 | - } |
|
| 27 | + /** |
|
| 28 | + * @return array |
|
| 29 | + */ |
|
| 30 | + public static function required() |
|
| 31 | + { |
|
| 32 | + return [ |
|
| 33 | + 'type' => 'textarea', |
|
| 34 | + ]; |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -4,13 +4,13 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Text extends Field |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @return array |
|
| 9 | - */ |
|
| 10 | - public static function defaults() |
|
| 11 | - { |
|
| 12 | - return [ |
|
| 13 | - 'class' => 'regular-text', |
|
| 14 | - ]; |
|
| 15 | - } |
|
| 7 | + /** |
|
| 8 | + * @return array |
|
| 9 | + */ |
|
| 10 | + public static function defaults() |
|
| 11 | + { |
|
| 12 | + return [ |
|
| 13 | + 'class' => 'regular-text', |
|
| 14 | + ]; |
|
| 15 | + } |
|
| 16 | 16 | } |
@@ -4,30 +4,30 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Honeypot extends Field |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @return string|void |
|
| 9 | - */ |
|
| 10 | - public function build() |
|
| 11 | - { |
|
| 12 | - $this->builder->args = wp_parse_args($this->builder->args, [ |
|
| 13 | - 'name' => $this->builder->args['text'], |
|
| 14 | - ]); |
|
| 15 | - $this->builder->tag = 'input'; |
|
| 16 | - $this->mergeFieldArgs(); |
|
| 17 | - return $this->builder->getOpeningTag(); |
|
| 18 | - } |
|
| 7 | + /** |
|
| 8 | + * @return string|void |
|
| 9 | + */ |
|
| 10 | + public function build() |
|
| 11 | + { |
|
| 12 | + $this->builder->args = wp_parse_args($this->builder->args, [ |
|
| 13 | + 'name' => $this->builder->args['text'], |
|
| 14 | + ]); |
|
| 15 | + $this->builder->tag = 'input'; |
|
| 16 | + $this->mergeFieldArgs(); |
|
| 17 | + return $this->builder->getOpeningTag(); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @return array |
|
| 22 | - */ |
|
| 23 | - public static function required() |
|
| 24 | - { |
|
| 25 | - return [ |
|
| 26 | - 'autocomplete' => 'off', |
|
| 27 | - 'is_raw' => true, |
|
| 28 | - 'style' => 'display:none!important', |
|
| 29 | - 'tabindex' => '-1', |
|
| 30 | - 'type' => 'text', |
|
| 31 | - ]; |
|
| 32 | - } |
|
| 20 | + /** |
|
| 21 | + * @return array |
|
| 22 | + */ |
|
| 23 | + public static function required() |
|
| 24 | + { |
|
| 25 | + return [ |
|
| 26 | + 'autocomplete' => 'off', |
|
| 27 | + 'is_raw' => true, |
|
| 28 | + 'style' => 'display:none!important', |
|
| 29 | + 'tabindex' => '-1', |
|
| 30 | + 'type' => 'text', |
|
| 31 | + ]; |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -9,9 +9,9 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | public function build() |
| 11 | 11 | { |
| 12 | - $this->builder->args = wp_parse_args($this->builder->args, [ |
|
| 12 | + $this->builder->args = wp_parse_args( $this->builder->args, [ |
|
| 13 | 13 | 'name' => $this->builder->args['text'], |
| 14 | - ]); |
|
| 14 | + ] ); |
|
| 15 | 15 | $this->builder->tag = 'input'; |
| 16 | 16 | $this->mergeFieldArgs(); |
| 17 | 17 | return $this->builder->getOpeningTag(); |
@@ -4,38 +4,38 @@ |
||
| 4 | 4 | |
| 5 | 5 | class YesNo extends Field |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @return string|void |
|
| 9 | - */ |
|
| 10 | - public function build() |
|
| 11 | - { |
|
| 12 | - $this->builder->tag = 'input'; |
|
| 13 | - $this->mergeFieldArgs(); |
|
| 14 | - return $this->builder->getTag(); |
|
| 15 | - } |
|
| 7 | + /** |
|
| 8 | + * @return string|void |
|
| 9 | + */ |
|
| 10 | + public function build() |
|
| 11 | + { |
|
| 12 | + $this->builder->tag = 'input'; |
|
| 13 | + $this->mergeFieldArgs(); |
|
| 14 | + return $this->builder->getTag(); |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @return array |
|
| 19 | - */ |
|
| 20 | - public static function defaults() |
|
| 21 | - { |
|
| 22 | - return [ |
|
| 23 | - 'class' => 'inline', |
|
| 24 | - ]; |
|
| 25 | - } |
|
| 17 | + /** |
|
| 18 | + * @return array |
|
| 19 | + */ |
|
| 20 | + public static function defaults() |
|
| 21 | + { |
|
| 22 | + return [ |
|
| 23 | + 'class' => 'inline', |
|
| 24 | + ]; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @return array |
|
| 29 | - */ |
|
| 30 | - public static function required() |
|
| 31 | - { |
|
| 32 | - return [ |
|
| 33 | - 'is_multi' => true, |
|
| 34 | - 'options' => [ |
|
| 35 | - 'no' => __('No', 'site-reviews'), |
|
| 36 | - 'yes' => __('Yes', 'site-reviews'), |
|
| 37 | - ], |
|
| 38 | - 'type' => 'radio', |
|
| 39 | - ]; |
|
| 40 | - } |
|
| 27 | + /** |
|
| 28 | + * @return array |
|
| 29 | + */ |
|
| 30 | + public static function required() |
|
| 31 | + { |
|
| 32 | + return [ |
|
| 33 | + 'is_multi' => true, |
|
| 34 | + 'options' => [ |
|
| 35 | + 'no' => __('No', 'site-reviews'), |
|
| 36 | + 'yes' => __('Yes', 'site-reviews'), |
|
| 37 | + ], |
|
| 38 | + 'type' => 'radio', |
|
| 39 | + ]; |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -32,8 +32,8 @@ |
||
| 32 | 32 | return [ |
| 33 | 33 | 'is_multi' => true, |
| 34 | 34 | 'options' => [ |
| 35 | - 'no' => __('No', 'site-reviews'), |
|
| 36 | - 'yes' => __('Yes', 'site-reviews'), |
|
| 35 | + 'no' => __( 'No', 'site-reviews' ), |
|
| 36 | + 'yes' => __( 'Yes', 'site-reviews' ), |
|
| 37 | 37 | ], |
| 38 | 38 | 'type' => 'radio', |
| 39 | 39 | ]; |
@@ -4,13 +4,13 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Number extends Field |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @return array |
|
| 9 | - */ |
|
| 10 | - public static function defaults() |
|
| 11 | - { |
|
| 12 | - return [ |
|
| 13 | - 'class' => 'small-text', |
|
| 14 | - ]; |
|
| 15 | - } |
|
| 7 | + /** |
|
| 8 | + * @return array |
|
| 9 | + */ |
|
| 10 | + public static function defaults() |
|
| 11 | + { |
|
| 12 | + return [ |
|
| 13 | + 'class' => 'small-text', |
|
| 14 | + ]; |
|
| 15 | + } |
|
| 16 | 16 | } |
@@ -4,23 +4,23 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Checkbox extends Field |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @return array |
|
| 9 | - */ |
|
| 10 | - public static function defaults() |
|
| 11 | - { |
|
| 12 | - return [ |
|
| 13 | - 'value' => 1, |
|
| 14 | - ]; |
|
| 15 | - } |
|
| 7 | + /** |
|
| 8 | + * @return array |
|
| 9 | + */ |
|
| 10 | + public static function defaults() |
|
| 11 | + { |
|
| 12 | + return [ |
|
| 13 | + 'value' => 1, |
|
| 14 | + ]; |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @return array |
|
| 19 | - */ |
|
| 20 | - public static function required() |
|
| 21 | - { |
|
| 22 | - return [ |
|
| 23 | - 'is_multi' => true, |
|
| 24 | - ]; |
|
| 25 | - } |
|
| 17 | + /** |
|
| 18 | + * @return array |
|
| 19 | + */ |
|
| 20 | + public static function required() |
|
| 21 | + { |
|
| 22 | + return [ |
|
| 23 | + 'is_multi' => true, |
|
| 24 | + ]; |
|
| 25 | + } |
|
| 26 | 26 | } |
@@ -6,29 +6,29 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Rating extends Field |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @return string|void |
|
| 11 | - */ |
|
| 12 | - public function build() |
|
| 13 | - { |
|
| 14 | - $this->builder->tag = 'select'; |
|
| 15 | - $this->mergeFieldArgs(); |
|
| 16 | - return $this->builder->getTag(); |
|
| 17 | - } |
|
| 9 | + /** |
|
| 10 | + * @return string|void |
|
| 11 | + */ |
|
| 12 | + public function build() |
|
| 13 | + { |
|
| 14 | + $this->builder->tag = 'select'; |
|
| 15 | + $this->mergeFieldArgs(); |
|
| 16 | + return $this->builder->getTag(); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @return array |
|
| 21 | - */ |
|
| 22 | - public static function required() |
|
| 23 | - { |
|
| 24 | - $options = ['' => __('Select a Rating', 'site-reviews')]; |
|
| 25 | - foreach (range(glsr()->constant('MAX_RATING', RatingModule::class), 1) as $rating) { |
|
| 26 | - $options[$rating] = sprintf(_n('%s Star', '%s Stars', $rating, 'site-reviews'), $rating); |
|
| 27 | - } |
|
| 28 | - return [ |
|
| 29 | - 'class' => 'glsr-star-rating', |
|
| 30 | - 'options' => $options, |
|
| 31 | - 'type' => 'select', |
|
| 32 | - ]; |
|
| 33 | - } |
|
| 19 | + /** |
|
| 20 | + * @return array |
|
| 21 | + */ |
|
| 22 | + public static function required() |
|
| 23 | + { |
|
| 24 | + $options = ['' => __('Select a Rating', 'site-reviews')]; |
|
| 25 | + foreach (range(glsr()->constant('MAX_RATING', RatingModule::class), 1) as $rating) { |
|
| 26 | + $options[$rating] = sprintf(_n('%s Star', '%s Stars', $rating, 'site-reviews'), $rating); |
|
| 27 | + } |
|
| 28 | + return [ |
|
| 29 | + 'class' => 'glsr-star-rating', |
|
| 30 | + 'options' => $options, |
|
| 31 | + 'type' => 'select', |
|
| 32 | + ]; |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -21,9 +21,9 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | public static function required() |
| 23 | 23 | { |
| 24 | - $options = ['' => __('Select a Rating', 'site-reviews')]; |
|
| 25 | - foreach (range(glsr()->constant('MAX_RATING', RatingModule::class), 1) as $rating) { |
|
| 26 | - $options[$rating] = sprintf(_n('%s Star', '%s Stars', $rating, 'site-reviews'), $rating); |
|
| 24 | + $options = ['' => __( 'Select a Rating', 'site-reviews' )]; |
|
| 25 | + foreach( range( glsr()->constant( 'MAX_RATING', RatingModule::class ), 1 ) as $rating ) { |
|
| 26 | + $options[$rating] = sprintf( _n( '%s Star', '%s Stars', $rating, 'site-reviews' ), $rating ); |
|
| 27 | 27 | } |
| 28 | 28 | return [ |
| 29 | 29 | 'class' => 'glsr-star-rating', |