@@ -4,49 +4,49 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Date |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * [60, 1], |
|
| 9 | - * [60 * 100, 60], |
|
| 10 | - * [3600 * 70, 3600], |
|
| 11 | - * [3600 * 24 * 10, 3600 * 24], |
|
| 12 | - * [3600 * 24 * 30, 3600 * 24 * 7], |
|
| 13 | - * [3600 * 24 * 30 * 30, 3600 * 24 * 30], |
|
| 14 | - * [INF, 3600 * 24 * 265],. |
|
| 15 | - */ |
|
| 16 | - protected static $TIME_PERIODS = [ |
|
| 17 | - [60, 1], |
|
| 18 | - [6000, 60], |
|
| 19 | - [252000, 3600], |
|
| 20 | - [864000, 86400], |
|
| 21 | - [2592000, 604800], |
|
| 22 | - [77760000, 2592000], |
|
| 23 | - [INF, 22896000], |
|
| 24 | - ]; |
|
| 7 | + /** |
|
| 8 | + * [60, 1], |
|
| 9 | + * [60 * 100, 60], |
|
| 10 | + * [3600 * 70, 3600], |
|
| 11 | + * [3600 * 24 * 10, 3600 * 24], |
|
| 12 | + * [3600 * 24 * 30, 3600 * 24 * 7], |
|
| 13 | + * [3600 * 24 * 30 * 30, 3600 * 24 * 30], |
|
| 14 | + * [INF, 3600 * 24 * 265],. |
|
| 15 | + */ |
|
| 16 | + protected static $TIME_PERIODS = [ |
|
| 17 | + [60, 1], |
|
| 18 | + [6000, 60], |
|
| 19 | + [252000, 3600], |
|
| 20 | + [864000, 86400], |
|
| 21 | + [2592000, 604800], |
|
| 22 | + [77760000, 2592000], |
|
| 23 | + [INF, 22896000], |
|
| 24 | + ]; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function relative($date) |
|
| 30 | - { |
|
| 31 | - $diff = time() - strtotime($date); |
|
| 32 | - foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
| 33 | - if ($diff > $timePeriod[0]) { |
|
| 34 | - continue; |
|
| 35 | - } |
|
| 36 | - $unit = intval(floor($diff / $timePeriod[1])); |
|
| 37 | - $relativeDates = [ |
|
| 38 | - _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'), |
|
| 39 | - _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'), |
|
| 40 | - _n('an hour ago', '%s hours ago', $unit, 'site-reviews'), |
|
| 41 | - _n('yesterday', '%s days ago', $unit, 'site-reviews'), |
|
| 42 | - _n('a week ago', '%s weeks ago', $unit, 'site-reviews'), |
|
| 43 | - _n('%s month ago', '%s months ago', $unit, 'site-reviews'), |
|
| 44 | - _n('%s year ago', '%s years ago', $unit, 'site-reviews'), |
|
| 45 | - ]; |
|
| 46 | - $relativeDate = $relativeDates[$i]; |
|
| 47 | - return false !== strpos($relativeDate, '%s') |
|
| 48 | - ? sprintf($relativeDate, $unit) |
|
| 49 | - : $relativeDate; |
|
| 50 | - } |
|
| 51 | - } |
|
| 26 | + /** |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public function relative($date) |
|
| 30 | + { |
|
| 31 | + $diff = time() - strtotime($date); |
|
| 32 | + foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
| 33 | + if ($diff > $timePeriod[0]) { |
|
| 34 | + continue; |
|
| 35 | + } |
|
| 36 | + $unit = intval(floor($diff / $timePeriod[1])); |
|
| 37 | + $relativeDates = [ |
|
| 38 | + _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'), |
|
| 39 | + _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'), |
|
| 40 | + _n('an hour ago', '%s hours ago', $unit, 'site-reviews'), |
|
| 41 | + _n('yesterday', '%s days ago', $unit, 'site-reviews'), |
|
| 42 | + _n('a week ago', '%s weeks ago', $unit, 'site-reviews'), |
|
| 43 | + _n('%s month ago', '%s months ago', $unit, 'site-reviews'), |
|
| 44 | + _n('%s year ago', '%s years ago', $unit, 'site-reviews'), |
|
| 45 | + ]; |
|
| 46 | + $relativeDate = $relativeDates[$i]; |
|
| 47 | + return false !== strpos($relativeDate, '%s') |
|
| 48 | + ? sprintf($relativeDate, $unit) |
|
| 49 | + : $relativeDate; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -6,151 +6,151 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Translator |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @param string $translation |
|
| 11 | - * @param string $text |
|
| 12 | - * @param string $domain |
|
| 13 | - * @return string |
|
| 14 | - */ |
|
| 15 | - public function filterGettext($translation, $text, $domain) |
|
| 16 | - { |
|
| 17 | - return $this->translate($translation, $domain, [ |
|
| 18 | - 'single' => $text, |
|
| 19 | - ]); |
|
| 20 | - } |
|
| 9 | + /** |
|
| 10 | + * @param string $translation |
|
| 11 | + * @param string $text |
|
| 12 | + * @param string $domain |
|
| 13 | + * @return string |
|
| 14 | + */ |
|
| 15 | + public function filterGettext($translation, $text, $domain) |
|
| 16 | + { |
|
| 17 | + return $this->translate($translation, $domain, [ |
|
| 18 | + 'single' => $text, |
|
| 19 | + ]); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @param string $translation |
|
| 24 | - * @param string $text |
|
| 25 | - * @param string $context |
|
| 26 | - * @param string $domain |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function filterGettextWithContext($translation, $text, $context, $domain) |
|
| 30 | - { |
|
| 31 | - return $this->translate($translation, $domain, [ |
|
| 32 | - 'context' => $context, |
|
| 33 | - 'single' => $text, |
|
| 34 | - ]); |
|
| 35 | - } |
|
| 22 | + /** |
|
| 23 | + * @param string $translation |
|
| 24 | + * @param string $text |
|
| 25 | + * @param string $context |
|
| 26 | + * @param string $domain |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public function filterGettextWithContext($translation, $text, $context, $domain) |
|
| 30 | + { |
|
| 31 | + return $this->translate($translation, $domain, [ |
|
| 32 | + 'context' => $context, |
|
| 33 | + 'single' => $text, |
|
| 34 | + ]); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param string $translation |
|
| 39 | - * @param string $single |
|
| 40 | - * @param string $plural |
|
| 41 | - * @param int $number |
|
| 42 | - * @param string $domain |
|
| 43 | - * @return string |
|
| 44 | - */ |
|
| 45 | - public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
| 46 | - { |
|
| 47 | - return $this->translate($translation, $domain, [ |
|
| 48 | - 'number' => $number, |
|
| 49 | - 'plural' => $plural, |
|
| 50 | - 'single' => $single, |
|
| 51 | - ]); |
|
| 52 | - } |
|
| 37 | + /** |
|
| 38 | + * @param string $translation |
|
| 39 | + * @param string $single |
|
| 40 | + * @param string $plural |
|
| 41 | + * @param int $number |
|
| 42 | + * @param string $domain |
|
| 43 | + * @return string |
|
| 44 | + */ |
|
| 45 | + public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
| 46 | + { |
|
| 47 | + return $this->translate($translation, $domain, [ |
|
| 48 | + 'number' => $number, |
|
| 49 | + 'plural' => $plural, |
|
| 50 | + 'single' => $single, |
|
| 51 | + ]); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @param string $translation |
|
| 56 | - * @param string $single |
|
| 57 | - * @param string $plural |
|
| 58 | - * @param int $number |
|
| 59 | - * @param string $context |
|
| 60 | - * @param string $domain |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
| 64 | - { |
|
| 65 | - return $this->translate($translation, $domain, [ |
|
| 66 | - 'context' => $context, |
|
| 67 | - 'number' => $number, |
|
| 68 | - 'plural' => $plural, |
|
| 69 | - 'single' => $single, |
|
| 70 | - ]); |
|
| 71 | - } |
|
| 54 | + /** |
|
| 55 | + * @param string $translation |
|
| 56 | + * @param string $single |
|
| 57 | + * @param string $plural |
|
| 58 | + * @param int $number |
|
| 59 | + * @param string $context |
|
| 60 | + * @param string $domain |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
| 64 | + { |
|
| 65 | + return $this->translate($translation, $domain, [ |
|
| 66 | + 'context' => $context, |
|
| 67 | + 'number' => $number, |
|
| 68 | + 'plural' => $plural, |
|
| 69 | + 'single' => $single, |
|
| 70 | + ]); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @param string $original |
|
| 75 | - * @param string $domain |
|
| 76 | - * @return string |
|
| 77 | - */ |
|
| 78 | - public function translate($original, $domain, array $args) |
|
| 79 | - { |
|
| 80 | - $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
| 81 | - if (!in_array($domain, $domains)) { |
|
| 82 | - return $original; |
|
| 83 | - } |
|
| 84 | - $args = $this->normalizeTranslationArgs($args); |
|
| 85 | - $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
| 86 | - if (empty($strings)) { |
|
| 87 | - return $original; |
|
| 88 | - } |
|
| 89 | - $string = current($strings); |
|
| 90 | - return 'plural' == $string['type'] |
|
| 91 | - ? $this->translatePlural($domain, $string, $args) |
|
| 92 | - : $this->translateSingle($domain, $string, $args); |
|
| 93 | - } |
|
| 73 | + /** |
|
| 74 | + * @param string $original |
|
| 75 | + * @param string $domain |
|
| 76 | + * @return string |
|
| 77 | + */ |
|
| 78 | + public function translate($original, $domain, array $args) |
|
| 79 | + { |
|
| 80 | + $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
| 81 | + if (!in_array($domain, $domains)) { |
|
| 82 | + return $original; |
|
| 83 | + } |
|
| 84 | + $args = $this->normalizeTranslationArgs($args); |
|
| 85 | + $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
| 86 | + if (empty($strings)) { |
|
| 87 | + return $original; |
|
| 88 | + } |
|
| 89 | + $string = current($strings); |
|
| 90 | + return 'plural' == $string['type'] |
|
| 91 | + ? $this->translatePlural($domain, $string, $args) |
|
| 92 | + : $this->translateSingle($domain, $string, $args); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * @param string $single |
|
| 97 | - * @param string $plural |
|
| 98 | - * @return array |
|
| 99 | - */ |
|
| 100 | - protected function getTranslationStrings($single, $plural) |
|
| 101 | - { |
|
| 102 | - return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
| 103 | - return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
| 104 | - && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
| 105 | - }); |
|
| 106 | - } |
|
| 95 | + /** |
|
| 96 | + * @param string $single |
|
| 97 | + * @param string $plural |
|
| 98 | + * @return array |
|
| 99 | + */ |
|
| 100 | + protected function getTranslationStrings($single, $plural) |
|
| 101 | + { |
|
| 102 | + return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
| 103 | + return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
| 104 | + && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
| 105 | + }); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * @return array |
|
| 110 | - */ |
|
| 111 | - protected function normalizeTranslationArgs(array $args) |
|
| 112 | - { |
|
| 113 | - $defaults = [ |
|
| 114 | - 'context' => '', |
|
| 115 | - 'number' => 1, |
|
| 116 | - 'plural' => '', |
|
| 117 | - 'single' => '', |
|
| 118 | - ]; |
|
| 119 | - return shortcode_atts($defaults, $args); |
|
| 120 | - } |
|
| 108 | + /** |
|
| 109 | + * @return array |
|
| 110 | + */ |
|
| 111 | + protected function normalizeTranslationArgs(array $args) |
|
| 112 | + { |
|
| 113 | + $defaults = [ |
|
| 114 | + 'context' => '', |
|
| 115 | + 'number' => 1, |
|
| 116 | + 'plural' => '', |
|
| 117 | + 'single' => '', |
|
| 118 | + ]; |
|
| 119 | + return shortcode_atts($defaults, $args); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * @param string $domain |
|
| 124 | - * @return string |
|
| 125 | - */ |
|
| 126 | - protected function translatePlural($domain, array $string, array $args) |
|
| 127 | - { |
|
| 128 | - if (!empty($string['s2'])) { |
|
| 129 | - $args['single'] = $string['s2']; |
|
| 130 | - } |
|
| 131 | - if (!empty($string['p2'])) { |
|
| 132 | - $args['plural'] = $string['p2']; |
|
| 133 | - } |
|
| 134 | - return get_translations_for_domain($domain)->translate_plural( |
|
| 135 | - $args['single'], |
|
| 136 | - $args['plural'], |
|
| 137 | - $args['number'], |
|
| 138 | - $args['context'] |
|
| 139 | - ); |
|
| 140 | - } |
|
| 122 | + /** |
|
| 123 | + * @param string $domain |
|
| 124 | + * @return string |
|
| 125 | + */ |
|
| 126 | + protected function translatePlural($domain, array $string, array $args) |
|
| 127 | + { |
|
| 128 | + if (!empty($string['s2'])) { |
|
| 129 | + $args['single'] = $string['s2']; |
|
| 130 | + } |
|
| 131 | + if (!empty($string['p2'])) { |
|
| 132 | + $args['plural'] = $string['p2']; |
|
| 133 | + } |
|
| 134 | + return get_translations_for_domain($domain)->translate_plural( |
|
| 135 | + $args['single'], |
|
| 136 | + $args['plural'], |
|
| 137 | + $args['number'], |
|
| 138 | + $args['context'] |
|
| 139 | + ); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * @param string $domain |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - protected function translateSingle($domain, array $string, array $args) |
|
| 147 | - { |
|
| 148 | - if (!empty($string['s2'])) { |
|
| 149 | - $args['single'] = $string['s2']; |
|
| 150 | - } |
|
| 151 | - return get_translations_for_domain($domain)->translate( |
|
| 152 | - $args['single'], |
|
| 153 | - $args['context'] |
|
| 154 | - ); |
|
| 155 | - } |
|
| 142 | + /** |
|
| 143 | + * @param string $domain |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + protected function translateSingle($domain, array $string, array $args) |
|
| 147 | + { |
|
| 148 | + if (!empty($string['s2'])) { |
|
| 149 | + $args['single'] = $string['s2']; |
|
| 150 | + } |
|
| 151 | + return get_translations_for_domain($domain)->translate( |
|
| 152 | + $args['single'], |
|
| 153 | + $args['context'] |
|
| 154 | + ); |
|
| 155 | + } |
|
| 156 | 156 | } |
@@ -6,285 +6,285 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Attributes |
| 8 | 8 | { |
| 9 | - const ATTRIBUTES_A = [ |
|
| 10 | - 'download', 'href', 'hreflang', 'ping', 'referrerpolicy', 'rel', 'target', 'type', |
|
| 11 | - ]; |
|
| 9 | + const ATTRIBUTES_A = [ |
|
| 10 | + 'download', 'href', 'hreflang', 'ping', 'referrerpolicy', 'rel', 'target', 'type', |
|
| 11 | + ]; |
|
| 12 | 12 | |
| 13 | - const ATTRIBUTES_BUTTON = [ |
|
| 14 | - 'autofocus', 'disabled', 'form', 'formaction', 'formenctype', 'formmethod', |
|
| 15 | - 'formnovalidate', 'formtarget', 'name', 'type', 'value', |
|
| 16 | - ]; |
|
| 13 | + const ATTRIBUTES_BUTTON = [ |
|
| 14 | + 'autofocus', 'disabled', 'form', 'formaction', 'formenctype', 'formmethod', |
|
| 15 | + 'formnovalidate', 'formtarget', 'name', 'type', 'value', |
|
| 16 | + ]; |
|
| 17 | 17 | |
| 18 | - const ATTRIBUTES_FORM = [ |
|
| 19 | - 'accept', 'accept-charset', 'action', 'autocapitalize', 'autocomplete', 'enctype', 'method', |
|
| 20 | - 'name', 'novalidate', 'target', |
|
| 21 | - ]; |
|
| 18 | + const ATTRIBUTES_FORM = [ |
|
| 19 | + 'accept', 'accept-charset', 'action', 'autocapitalize', 'autocomplete', 'enctype', 'method', |
|
| 20 | + 'name', 'novalidate', 'target', |
|
| 21 | + ]; |
|
| 22 | 22 | |
| 23 | - const ATTRIBUTES_IMG = [ |
|
| 24 | - 'alt', 'crossorigin', 'decoding', 'height', 'ismap', 'referrerpolicy', 'sizes', 'src', |
|
| 25 | - 'srcset', 'width', 'usemap', |
|
| 26 | - ]; |
|
| 23 | + const ATTRIBUTES_IMG = [ |
|
| 24 | + 'alt', 'crossorigin', 'decoding', 'height', 'ismap', 'referrerpolicy', 'sizes', 'src', |
|
| 25 | + 'srcset', 'width', 'usemap', |
|
| 26 | + ]; |
|
| 27 | 27 | |
| 28 | - const ATTRIBUTES_INPUT = [ |
|
| 29 | - 'accept', 'autocomplete', 'autocorrect', 'autofocus', 'capture', 'checked', 'disabled', |
|
| 30 | - 'form', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'height', |
|
| 31 | - 'incremental', 'inputmode', 'list', 'max', 'maxlength', 'min', 'minlength', 'multiple', |
|
| 32 | - 'name', 'pattern', 'placeholder', 'readonly', 'results', 'required', 'selectionDirection', |
|
| 33 | - 'selectionEnd', 'selectionStart', 'size', 'spellcheck', 'src', 'step', 'tabindex', 'type', |
|
| 34 | - 'value', 'webkitdirectory', 'width', |
|
| 35 | - ]; |
|
| 28 | + const ATTRIBUTES_INPUT = [ |
|
| 29 | + 'accept', 'autocomplete', 'autocorrect', 'autofocus', 'capture', 'checked', 'disabled', |
|
| 30 | + 'form', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'height', |
|
| 31 | + 'incremental', 'inputmode', 'list', 'max', 'maxlength', 'min', 'minlength', 'multiple', |
|
| 32 | + 'name', 'pattern', 'placeholder', 'readonly', 'results', 'required', 'selectionDirection', |
|
| 33 | + 'selectionEnd', 'selectionStart', 'size', 'spellcheck', 'src', 'step', 'tabindex', 'type', |
|
| 34 | + 'value', 'webkitdirectory', 'width', |
|
| 35 | + ]; |
|
| 36 | 36 | |
| 37 | - const ATTRIBUTES_LABEL = [ |
|
| 38 | - 'for', |
|
| 39 | - ]; |
|
| 37 | + const ATTRIBUTES_LABEL = [ |
|
| 38 | + 'for', |
|
| 39 | + ]; |
|
| 40 | 40 | |
| 41 | - const ATTRIBUTES_OPTION = [ |
|
| 42 | - 'disabled', 'label', 'selected', 'value', |
|
| 43 | - ]; |
|
| 41 | + const ATTRIBUTES_OPTION = [ |
|
| 42 | + 'disabled', 'label', 'selected', 'value', |
|
| 43 | + ]; |
|
| 44 | 44 | |
| 45 | - const ATTRIBUTES_SELECT = [ |
|
| 46 | - 'autofocus', 'disabled', 'form', 'multiple', 'name', 'required', 'size', |
|
| 47 | - ]; |
|
| 45 | + const ATTRIBUTES_SELECT = [ |
|
| 46 | + 'autofocus', 'disabled', 'form', 'multiple', 'name', 'required', 'size', |
|
| 47 | + ]; |
|
| 48 | 48 | |
| 49 | - const ATTRIBUTES_TEXTAREA = [ |
|
| 50 | - 'autocapitalize', 'autocomplete', 'autofocus', 'cols', 'disabled', 'form', 'maxlength', |
|
| 51 | - 'minlength', 'name', 'placeholder', 'readonly', 'required', 'rows', 'spellcheck', 'wrap', |
|
| 52 | - ]; |
|
| 49 | + const ATTRIBUTES_TEXTAREA = [ |
|
| 50 | + 'autocapitalize', 'autocomplete', 'autofocus', 'cols', 'disabled', 'form', 'maxlength', |
|
| 51 | + 'minlength', 'name', 'placeholder', 'readonly', 'required', 'rows', 'spellcheck', 'wrap', |
|
| 52 | + ]; |
|
| 53 | 53 | |
| 54 | - const BOOLEAN_ATTRIBUTES = [ |
|
| 55 | - 'autofocus', 'capture', 'checked', 'disabled', 'draggable', 'formnovalidate', 'hidden', |
|
| 56 | - 'multiple', 'novalidate', 'readonly', 'required', 'selected', 'spellcheck', |
|
| 57 | - 'webkitdirectory', |
|
| 58 | - ]; |
|
| 54 | + const BOOLEAN_ATTRIBUTES = [ |
|
| 55 | + 'autofocus', 'capture', 'checked', 'disabled', 'draggable', 'formnovalidate', 'hidden', |
|
| 56 | + 'multiple', 'novalidate', 'readonly', 'required', 'selected', 'spellcheck', |
|
| 57 | + 'webkitdirectory', |
|
| 58 | + ]; |
|
| 59 | 59 | |
| 60 | - const GLOBAL_ATTRIBUTES = [ |
|
| 61 | - 'accesskey', 'class', 'contenteditable', 'contextmenu', 'dir', 'draggable', 'dropzone', |
|
| 62 | - 'hidden', 'id', 'lang', 'spellcheck', 'style', 'tabindex', 'title', |
|
| 63 | - ]; |
|
| 60 | + const GLOBAL_ATTRIBUTES = [ |
|
| 61 | + 'accesskey', 'class', 'contenteditable', 'contextmenu', 'dir', 'draggable', 'dropzone', |
|
| 62 | + 'hidden', 'id', 'lang', 'spellcheck', 'style', 'tabindex', 'title', |
|
| 63 | + ]; |
|
| 64 | 64 | |
| 65 | - const GLOBAL_WILDCARD_ATTRIBUTES = [ |
|
| 66 | - 'aria-', 'data-', 'item', 'on', |
|
| 67 | - ]; |
|
| 65 | + const GLOBAL_WILDCARD_ATTRIBUTES = [ |
|
| 66 | + 'aria-', 'data-', 'item', 'on', |
|
| 67 | + ]; |
|
| 68 | 68 | |
| 69 | - const INPUT_TYPES = [ |
|
| 70 | - 'button', 'checkbox', 'color', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', |
|
| 71 | - 'month', 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', |
|
| 72 | - 'time', 'url', 'week', |
|
| 73 | - ]; |
|
| 69 | + const INPUT_TYPES = [ |
|
| 70 | + 'button', 'checkbox', 'color', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', |
|
| 71 | + 'month', 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', |
|
| 72 | + 'time', 'url', 'week', |
|
| 73 | + ]; |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @var array |
|
| 77 | - */ |
|
| 78 | - protected $attributes = []; |
|
| 75 | + /** |
|
| 76 | + * @var array |
|
| 77 | + */ |
|
| 78 | + protected $attributes = []; |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @param string $method |
|
| 82 | - * @param array $args |
|
| 83 | - * @return static |
|
| 84 | - */ |
|
| 85 | - public function __call($method, $args) |
|
| 86 | - { |
|
| 87 | - $args += [[], false]; |
|
| 88 | - $constant = 'static::ATTRIBUTES_'.strtoupper($method); |
|
| 89 | - $allowedAttributeKeys = defined($constant) |
|
| 90 | - ? constant($constant) |
|
| 91 | - : []; |
|
| 92 | - $this->normalize((array) $args[0], $allowedAttributeKeys); |
|
| 93 | - $this->normalizeInputType($method); |
|
| 94 | - return $this; |
|
| 95 | - } |
|
| 80 | + /** |
|
| 81 | + * @param string $method |
|
| 82 | + * @param array $args |
|
| 83 | + * @return static |
|
| 84 | + */ |
|
| 85 | + public function __call($method, $args) |
|
| 86 | + { |
|
| 87 | + $args += [[], false]; |
|
| 88 | + $constant = 'static::ATTRIBUTES_'.strtoupper($method); |
|
| 89 | + $allowedAttributeKeys = defined($constant) |
|
| 90 | + ? constant($constant) |
|
| 91 | + : []; |
|
| 92 | + $this->normalize((array) $args[0], $allowedAttributeKeys); |
|
| 93 | + $this->normalizeInputType($method); |
|
| 94 | + return $this; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @return array |
|
| 99 | - */ |
|
| 100 | - public function toArray() |
|
| 101 | - { |
|
| 102 | - return $this->attributes; |
|
| 103 | - } |
|
| 97 | + /** |
|
| 98 | + * @return array |
|
| 99 | + */ |
|
| 100 | + public function toArray() |
|
| 101 | + { |
|
| 102 | + return $this->attributes; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * @return string |
|
| 107 | - */ |
|
| 108 | - public function toString() |
|
| 109 | - { |
|
| 110 | - $attributes = []; |
|
| 111 | - foreach ($this->attributes as $attribute => $value) { |
|
| 112 | - $quote = $this->getQuoteChar($attribute); |
|
| 113 | - $attributes[] = in_array($attribute, static::BOOLEAN_ATTRIBUTES) |
|
| 114 | - ? $attribute |
|
| 115 | - : $attribute.'='.$quote.implode(',', (array) $value).$quote; |
|
| 116 | - } |
|
| 117 | - return implode(' ', $attributes); |
|
| 118 | - } |
|
| 105 | + /** |
|
| 106 | + * @return string |
|
| 107 | + */ |
|
| 108 | + public function toString() |
|
| 109 | + { |
|
| 110 | + $attributes = []; |
|
| 111 | + foreach ($this->attributes as $attribute => $value) { |
|
| 112 | + $quote = $this->getQuoteChar($attribute); |
|
| 113 | + $attributes[] = in_array($attribute, static::BOOLEAN_ATTRIBUTES) |
|
| 114 | + ? $attribute |
|
| 115 | + : $attribute.'='.$quote.implode(',', (array) $value).$quote; |
|
| 116 | + } |
|
| 117 | + return implode(' ', $attributes); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * @return array |
|
| 122 | - */ |
|
| 123 | - protected function filterAttributes(array $allowedAttributeKeys) |
|
| 124 | - { |
|
| 125 | - return array_intersect_key($this->attributes, array_flip($allowedAttributeKeys)); |
|
| 126 | - } |
|
| 120 | + /** |
|
| 121 | + * @return array |
|
| 122 | + */ |
|
| 123 | + protected function filterAttributes(array $allowedAttributeKeys) |
|
| 124 | + { |
|
| 125 | + return array_intersect_key($this->attributes, array_flip($allowedAttributeKeys)); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * @return array |
|
| 130 | - */ |
|
| 131 | - protected function filterGlobalAttributes() |
|
| 132 | - { |
|
| 133 | - $globalAttributes = $this->filterAttributes(static::GLOBAL_ATTRIBUTES); |
|
| 134 | - $wildcards = []; |
|
| 135 | - foreach (static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) { |
|
| 136 | - $newWildcards = array_filter($this->attributes, function ($key) use ($wildcard) { |
|
| 137 | - return glsr(Helper::class)->startsWith($wildcard, $key); |
|
| 138 | - }, ARRAY_FILTER_USE_KEY); |
|
| 139 | - $wildcards = array_merge($wildcards, $newWildcards); |
|
| 140 | - } |
|
| 141 | - return array_merge($globalAttributes, $wildcards); |
|
| 142 | - } |
|
| 128 | + /** |
|
| 129 | + * @return array |
|
| 130 | + */ |
|
| 131 | + protected function filterGlobalAttributes() |
|
| 132 | + { |
|
| 133 | + $globalAttributes = $this->filterAttributes(static::GLOBAL_ATTRIBUTES); |
|
| 134 | + $wildcards = []; |
|
| 135 | + foreach (static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) { |
|
| 136 | + $newWildcards = array_filter($this->attributes, function ($key) use ($wildcard) { |
|
| 137 | + return glsr(Helper::class)->startsWith($wildcard, $key); |
|
| 138 | + }, ARRAY_FILTER_USE_KEY); |
|
| 139 | + $wildcards = array_merge($wildcards, $newWildcards); |
|
| 140 | + } |
|
| 141 | + return array_merge($globalAttributes, $wildcards); |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * @return array |
|
| 146 | - */ |
|
| 147 | - protected function getPermanentAttributes() |
|
| 148 | - { |
|
| 149 | - $permanentAttributes = []; |
|
| 150 | - if (array_key_exists('value', $this->attributes)) { |
|
| 151 | - $permanentAttributes['value'] = $this->attributes['value']; |
|
| 152 | - } |
|
| 153 | - return $permanentAttributes; |
|
| 154 | - } |
|
| 144 | + /** |
|
| 145 | + * @return array |
|
| 146 | + */ |
|
| 147 | + protected function getPermanentAttributes() |
|
| 148 | + { |
|
| 149 | + $permanentAttributes = []; |
|
| 150 | + if (array_key_exists('value', $this->attributes)) { |
|
| 151 | + $permanentAttributes['value'] = $this->attributes['value']; |
|
| 152 | + } |
|
| 153 | + return $permanentAttributes; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * @param string $attribute |
|
| 158 | - * @return string |
|
| 159 | - */ |
|
| 160 | - protected function getQuoteChar($attribute) |
|
| 161 | - { |
|
| 162 | - return glsr(Helper::class)->startsWith('data-', $attribute) |
|
| 163 | - ? '\'' |
|
| 164 | - : '"'; |
|
| 165 | - } |
|
| 156 | + /** |
|
| 157 | + * @param string $attribute |
|
| 158 | + * @return string |
|
| 159 | + */ |
|
| 160 | + protected function getQuoteChar($attribute) |
|
| 161 | + { |
|
| 162 | + return glsr(Helper::class)->startsWith('data-', $attribute) |
|
| 163 | + ? '\'' |
|
| 164 | + : '"'; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * @param string $key |
|
| 169 | - * @param mixed $value |
|
| 170 | - * @return bool |
|
| 171 | - */ |
|
| 172 | - protected function isAttributeKeyNumeric($key, $value) |
|
| 173 | - { |
|
| 174 | - return is_string($value) |
|
| 175 | - && is_numeric($key) |
|
| 176 | - && !array_key_exists($value, $this->attributes); |
|
| 177 | - } |
|
| 167 | + /** |
|
| 168 | + * @param string $key |
|
| 169 | + * @param mixed $value |
|
| 170 | + * @return bool |
|
| 171 | + */ |
|
| 172 | + protected function isAttributeKeyNumeric($key, $value) |
|
| 173 | + { |
|
| 174 | + return is_string($value) |
|
| 175 | + && is_numeric($key) |
|
| 176 | + && !array_key_exists($value, $this->attributes); |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * @return void |
|
| 181 | - */ |
|
| 182 | - protected function normalize(array $args, array $allowedAttributeKeys) |
|
| 183 | - { |
|
| 184 | - $this->attributes = array_change_key_case($args, CASE_LOWER); |
|
| 185 | - $this->normalizeBooleanAttributes(); |
|
| 186 | - $this->normalizeDataAttributes(); |
|
| 187 | - $this->normalizeStringAttributes(); |
|
| 188 | - $this->removeEmptyAttributes(); |
|
| 189 | - $this->removeIndexedAttributes(); |
|
| 190 | - $this->attributes = array_merge( |
|
| 191 | - $this->filterGlobalAttributes(), |
|
| 192 | - $this->filterAttributes($allowedAttributeKeys) |
|
| 193 | - ); |
|
| 194 | - } |
|
| 179 | + /** |
|
| 180 | + * @return void |
|
| 181 | + */ |
|
| 182 | + protected function normalize(array $args, array $allowedAttributeKeys) |
|
| 183 | + { |
|
| 184 | + $this->attributes = array_change_key_case($args, CASE_LOWER); |
|
| 185 | + $this->normalizeBooleanAttributes(); |
|
| 186 | + $this->normalizeDataAttributes(); |
|
| 187 | + $this->normalizeStringAttributes(); |
|
| 188 | + $this->removeEmptyAttributes(); |
|
| 189 | + $this->removeIndexedAttributes(); |
|
| 190 | + $this->attributes = array_merge( |
|
| 191 | + $this->filterGlobalAttributes(), |
|
| 192 | + $this->filterAttributes($allowedAttributeKeys) |
|
| 193 | + ); |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * @return void |
|
| 198 | - */ |
|
| 199 | - protected function normalizeBooleanAttributes() |
|
| 200 | - { |
|
| 201 | - foreach ($this->attributes as $key => $value) { |
|
| 202 | - if ($this->isAttributeKeyNumeric($key, $value)) { |
|
| 203 | - $key = $value; |
|
| 204 | - $value = true; |
|
| 205 | - } |
|
| 206 | - if (!in_array($key, static::BOOLEAN_ATTRIBUTES)) { |
|
| 207 | - continue; |
|
| 208 | - } |
|
| 209 | - $this->attributes[$key] = wp_validate_boolean($value); |
|
| 210 | - } |
|
| 211 | - } |
|
| 196 | + /** |
|
| 197 | + * @return void |
|
| 198 | + */ |
|
| 199 | + protected function normalizeBooleanAttributes() |
|
| 200 | + { |
|
| 201 | + foreach ($this->attributes as $key => $value) { |
|
| 202 | + if ($this->isAttributeKeyNumeric($key, $value)) { |
|
| 203 | + $key = $value; |
|
| 204 | + $value = true; |
|
| 205 | + } |
|
| 206 | + if (!in_array($key, static::BOOLEAN_ATTRIBUTES)) { |
|
| 207 | + continue; |
|
| 208 | + } |
|
| 209 | + $this->attributes[$key] = wp_validate_boolean($value); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - /** |
|
| 214 | - * @return void |
|
| 215 | - */ |
|
| 216 | - protected function normalizeDataAttributes() |
|
| 217 | - { |
|
| 218 | - foreach ($this->attributes as $key => $value) { |
|
| 219 | - if ($this->isAttributeKeyNumeric($key, $value)) { |
|
| 220 | - $key = $value; |
|
| 221 | - $value = ''; |
|
| 222 | - } |
|
| 223 | - if (!glsr(Helper::class)->startsWith('data-', $key)) { |
|
| 224 | - continue; |
|
| 225 | - } |
|
| 226 | - if (is_array($value)) { |
|
| 227 | - $value = json_encode($value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
| 228 | - } |
|
| 229 | - $this->attributes[$key] = $value; |
|
| 230 | - } |
|
| 231 | - } |
|
| 213 | + /** |
|
| 214 | + * @return void |
|
| 215 | + */ |
|
| 216 | + protected function normalizeDataAttributes() |
|
| 217 | + { |
|
| 218 | + foreach ($this->attributes as $key => $value) { |
|
| 219 | + if ($this->isAttributeKeyNumeric($key, $value)) { |
|
| 220 | + $key = $value; |
|
| 221 | + $value = ''; |
|
| 222 | + } |
|
| 223 | + if (!glsr(Helper::class)->startsWith('data-', $key)) { |
|
| 224 | + continue; |
|
| 225 | + } |
|
| 226 | + if (is_array($value)) { |
|
| 227 | + $value = json_encode($value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
| 228 | + } |
|
| 229 | + $this->attributes[$key] = $value; |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * @return void |
|
| 235 | - */ |
|
| 236 | - protected function normalizeStringAttributes() |
|
| 237 | - { |
|
| 238 | - foreach ($this->attributes as $key => $value) { |
|
| 239 | - if (!is_string($value)) { |
|
| 240 | - continue; |
|
| 241 | - } |
|
| 242 | - $this->attributes[$key] = trim($value); |
|
| 243 | - } |
|
| 244 | - } |
|
| 233 | + /** |
|
| 234 | + * @return void |
|
| 235 | + */ |
|
| 236 | + protected function normalizeStringAttributes() |
|
| 237 | + { |
|
| 238 | + foreach ($this->attributes as $key => $value) { |
|
| 239 | + if (!is_string($value)) { |
|
| 240 | + continue; |
|
| 241 | + } |
|
| 242 | + $this->attributes[$key] = trim($value); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - /** |
|
| 247 | - * @param string $method |
|
| 248 | - * @return void |
|
| 249 | - */ |
|
| 250 | - protected function normalizeInputType($method) |
|
| 251 | - { |
|
| 252 | - if ('input' != $method) { |
|
| 253 | - return; |
|
| 254 | - } |
|
| 255 | - $attributes = wp_parse_args($this->attributes, ['type' => '']); |
|
| 256 | - if (!in_array($attributes['type'], static::INPUT_TYPES)) { |
|
| 257 | - $this->attributes['type'] = 'text'; |
|
| 258 | - } |
|
| 259 | - } |
|
| 246 | + /** |
|
| 247 | + * @param string $method |
|
| 248 | + * @return void |
|
| 249 | + */ |
|
| 250 | + protected function normalizeInputType($method) |
|
| 251 | + { |
|
| 252 | + if ('input' != $method) { |
|
| 253 | + return; |
|
| 254 | + } |
|
| 255 | + $attributes = wp_parse_args($this->attributes, ['type' => '']); |
|
| 256 | + if (!in_array($attributes['type'], static::INPUT_TYPES)) { |
|
| 257 | + $this->attributes['type'] = 'text'; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * @return void |
|
| 263 | - */ |
|
| 264 | - protected function removeEmptyAttributes() |
|
| 265 | - { |
|
| 266 | - $attributes = $this->attributes; |
|
| 267 | - $permanentAttributes = $this->getPermanentAttributes(); |
|
| 268 | - foreach ($this->attributes as $key => $value) { |
|
| 269 | - if (in_array($key, static::BOOLEAN_ATTRIBUTES) && !$value) { |
|
| 270 | - unset($attributes[$key]); |
|
| 271 | - } |
|
| 272 | - if (glsr(Helper::class)->startsWith('data-', $key)) { |
|
| 273 | - $permanentAttributes[$key] = $value; |
|
| 274 | - unset($attributes[$key]); |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - $this->attributes = array_merge(array_filter($attributes), $permanentAttributes); |
|
| 278 | - } |
|
| 261 | + /** |
|
| 262 | + * @return void |
|
| 263 | + */ |
|
| 264 | + protected function removeEmptyAttributes() |
|
| 265 | + { |
|
| 266 | + $attributes = $this->attributes; |
|
| 267 | + $permanentAttributes = $this->getPermanentAttributes(); |
|
| 268 | + foreach ($this->attributes as $key => $value) { |
|
| 269 | + if (in_array($key, static::BOOLEAN_ATTRIBUTES) && !$value) { |
|
| 270 | + unset($attributes[$key]); |
|
| 271 | + } |
|
| 272 | + if (glsr(Helper::class)->startsWith('data-', $key)) { |
|
| 273 | + $permanentAttributes[$key] = $value; |
|
| 274 | + unset($attributes[$key]); |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + $this->attributes = array_merge(array_filter($attributes), $permanentAttributes); |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - /** |
|
| 281 | - * @return void |
|
| 282 | - */ |
|
| 283 | - protected function removeIndexedAttributes() |
|
| 284 | - { |
|
| 285 | - $this->attributes = array_diff_key( |
|
| 286 | - $this->attributes, |
|
| 287 | - array_filter($this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY) |
|
| 288 | - ); |
|
| 289 | - } |
|
| 280 | + /** |
|
| 281 | + * @return void |
|
| 282 | + */ |
|
| 283 | + protected function removeIndexedAttributes() |
|
| 284 | + { |
|
| 285 | + $this->attributes = array_diff_key( |
|
| 286 | + $this->attributes, |
|
| 287 | + array_filter($this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY) |
|
| 288 | + ); |
|
| 289 | + } |
|
| 290 | 290 | } |
@@ -9,239 +9,239 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Settings |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @var array |
|
| 14 | - */ |
|
| 15 | - public $settings; |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * @param string $id |
|
| 19 | - * @return string |
|
| 20 | - */ |
|
| 21 | - public function buildFields($id) |
|
| 22 | - { |
|
| 23 | - $this->settings = glsr(DefaultsManager::class)->settings(); |
|
| 24 | - $method = glsr(Helper::class)->buildMethodName($id, 'getTemplateDataFor'); |
|
| 25 | - $data = !method_exists($this, $method) |
|
| 26 | - ? $this->getTemplateData($id) |
|
| 27 | - : $this->$method($id); |
|
| 28 | - return glsr(Template::class)->build('pages/settings/'.$id, $data); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - protected function getFieldDefault(array $field) |
|
| 35 | - { |
|
| 36 | - return glsr_get($field, 'default'); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - protected function getFieldNameForDependsOn($path) |
|
| 43 | - { |
|
| 44 | - $fieldName = glsr(Helper::class)->convertPathToName($path, OptionManager::databaseKey()); |
|
| 45 | - return $this->isMultiDependency($path) |
|
| 46 | - ? $fieldName.'[]' |
|
| 47 | - : $fieldName; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @return array |
|
| 52 | - */ |
|
| 53 | - protected function getSettingFields($path) |
|
| 54 | - { |
|
| 55 | - return array_filter($this->settings, function ($key) use ($path) { |
|
| 56 | - return glsr(Helper::class)->startsWith($path, $key); |
|
| 57 | - }, ARRAY_FILTER_USE_KEY); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - protected function getSettingRows(array $fields) |
|
| 64 | - { |
|
| 65 | - $rows = ''; |
|
| 66 | - foreach ($fields as $name => $field) { |
|
| 67 | - $field = wp_parse_args($field, [ |
|
| 68 | - 'is_setting' => true, |
|
| 69 | - 'name' => $name, |
|
| 70 | - ]); |
|
| 71 | - $rows .= new Field($this->normalize($field)); |
|
| 72 | - } |
|
| 73 | - return $rows; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param string $id |
|
| 78 | - * @return array |
|
| 79 | - */ |
|
| 80 | - protected function getTemplateData($id) |
|
| 81 | - { |
|
| 82 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 83 | - return [ |
|
| 84 | - 'context' => [ |
|
| 85 | - 'rows' => $this->getSettingRows($fields), |
|
| 86 | - ], |
|
| 87 | - ]; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @param string $id |
|
| 92 | - * @return array |
|
| 93 | - */ |
|
| 94 | - protected function getTemplateDataForAddons($id) |
|
| 95 | - { |
|
| 96 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 97 | - $settings = glsr(Helper::class)->convertDotNotationArray($fields); |
|
| 98 | - $settingKeys = array_keys($settings['settings']['addons']); |
|
| 99 | - $results = []; |
|
| 100 | - foreach ($settingKeys as $key) { |
|
| 101 | - $addonFields = array_filter($fields, function ($path) use ($key) { |
|
| 102 | - return glsr(Helper::class)->startsWith('settings.addons.'.$key, $path); |
|
| 103 | - }, ARRAY_FILTER_USE_KEY); |
|
| 104 | - $results[$key] = $this->getSettingRows($addonFields); |
|
| 105 | - } |
|
| 106 | - ksort($results); |
|
| 107 | - return [ |
|
| 108 | - 'settings' => $results, |
|
| 109 | - ]; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @param string $id |
|
| 114 | - * @return array |
|
| 115 | - */ |
|
| 116 | - protected function getTemplateDataForLicenses($id) |
|
| 117 | - { |
|
| 118 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 119 | - ksort($fields); |
|
| 120 | - return [ |
|
| 121 | - 'context' => [ |
|
| 122 | - 'rows' => $this->getSettingRows($fields), |
|
| 123 | - ], |
|
| 124 | - ]; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @return array |
|
| 129 | - */ |
|
| 130 | - protected function getTemplateDataForTranslations() |
|
| 131 | - { |
|
| 132 | - $translations = glsr(Translation::class)->renderAll(); |
|
| 133 | - $class = empty($translations) |
|
| 134 | - ? 'glsr-hidden' |
|
| 135 | - : ''; |
|
| 136 | - return [ |
|
| 137 | - 'context' => [ |
|
| 138 | - 'class' => $class, |
|
| 139 | - 'database_key' => OptionManager::databaseKey(), |
|
| 140 | - 'translations' => $translations, |
|
| 141 | - ], |
|
| 142 | - ]; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * @param string $path |
|
| 147 | - * @param string|array $expectedValue |
|
| 148 | - * @return bool |
|
| 149 | - */ |
|
| 150 | - protected function isFieldHidden($path, $expectedValue) |
|
| 151 | - { |
|
| 152 | - $optionValue = glsr(OptionManager::class)->get( |
|
| 153 | - $path, |
|
| 154 | - glsr(Helper::class)->dataGet(glsr()->defaults, $path) |
|
| 155 | - ); |
|
| 156 | - if (is_array($expectedValue)) { |
|
| 157 | - return is_array($optionValue) |
|
| 158 | - ? 0 === count(array_intersect($optionValue, $expectedValue)) |
|
| 159 | - : !in_array($optionValue, $expectedValue); |
|
| 160 | - } |
|
| 161 | - return $optionValue != $expectedValue; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @return bool |
|
| 166 | - */ |
|
| 167 | - protected function isMultiDependency($path) |
|
| 168 | - { |
|
| 169 | - if (isset($this->settings[$path])) { |
|
| 170 | - $field = $this->settings[$path]; |
|
| 171 | - return ('checkbox' == $field['type'] && !empty($field['options'])) |
|
| 172 | - || !empty($field['multiple']); |
|
| 173 | - } |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @return array |
|
| 179 | - */ |
|
| 180 | - protected function normalize(array $field) |
|
| 181 | - { |
|
| 182 | - $field = $this->normalizeDependsOn($field); |
|
| 183 | - $field = $this->normalizeLabelAndLegend($field); |
|
| 184 | - $field = $this->normalizeValue($field); |
|
| 185 | - return $field; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * @return array |
|
| 190 | - */ |
|
| 191 | - protected function normalizeDependsOn(array $field) |
|
| 192 | - { |
|
| 193 | - if (!empty($field['depends_on']) && is_array($field['depends_on'])) { |
|
| 194 | - $isFieldHidden = false; |
|
| 195 | - $conditions = []; |
|
| 196 | - foreach ($field['depends_on'] as $path => $value) { |
|
| 197 | - $conditions[] = [ |
|
| 198 | - 'name' => $this->getFieldNameForDependsOn($path), |
|
| 199 | - 'value' => $value, |
|
| 200 | - ]; |
|
| 201 | - if ($this->isFieldHidden($path, $value)) { |
|
| 202 | - $isFieldHidden = true; |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT); |
|
| 206 | - $field['is_hidden'] = $isFieldHidden; |
|
| 207 | - } |
|
| 208 | - return $field; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @return array |
|
| 213 | - */ |
|
| 214 | - protected function normalizeLabelAndLegend(array $field) |
|
| 215 | - { |
|
| 216 | - if (!empty($field['label'])) { |
|
| 217 | - $field['legend'] = $field['label']; |
|
| 218 | - unset($field['label']); |
|
| 219 | - } else { |
|
| 220 | - $field['is_valid'] = false; |
|
| 221 | - glsr_log()->warning('Setting field is missing a label')->debug($field); |
|
| 222 | - } |
|
| 223 | - return $field; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @return array |
|
| 228 | - */ |
|
| 229 | - protected function normalizeValue(array $field) |
|
| 230 | - { |
|
| 231 | - if (!isset($field['value'])) { |
|
| 232 | - $field['value'] = glsr(OptionManager::class)->get( |
|
| 233 | - $field['name'], |
|
| 234 | - $this->getFieldDefault($field) |
|
| 235 | - ); |
|
| 236 | - } |
|
| 237 | - return $field; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @return string |
|
| 242 | - */ |
|
| 243 | - protected function normalizeSettingPath($path) |
|
| 244 | - { |
|
| 245 | - return glsr(Helper::class)->prefixString(rtrim($path, '.'), 'settings.'); |
|
| 246 | - } |
|
| 12 | + /** |
|
| 13 | + * @var array |
|
| 14 | + */ |
|
| 15 | + public $settings; |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * @param string $id |
|
| 19 | + * @return string |
|
| 20 | + */ |
|
| 21 | + public function buildFields($id) |
|
| 22 | + { |
|
| 23 | + $this->settings = glsr(DefaultsManager::class)->settings(); |
|
| 24 | + $method = glsr(Helper::class)->buildMethodName($id, 'getTemplateDataFor'); |
|
| 25 | + $data = !method_exists($this, $method) |
|
| 26 | + ? $this->getTemplateData($id) |
|
| 27 | + : $this->$method($id); |
|
| 28 | + return glsr(Template::class)->build('pages/settings/'.$id, $data); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + protected function getFieldDefault(array $field) |
|
| 35 | + { |
|
| 36 | + return glsr_get($field, 'default'); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + protected function getFieldNameForDependsOn($path) |
|
| 43 | + { |
|
| 44 | + $fieldName = glsr(Helper::class)->convertPathToName($path, OptionManager::databaseKey()); |
|
| 45 | + return $this->isMultiDependency($path) |
|
| 46 | + ? $fieldName.'[]' |
|
| 47 | + : $fieldName; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @return array |
|
| 52 | + */ |
|
| 53 | + protected function getSettingFields($path) |
|
| 54 | + { |
|
| 55 | + return array_filter($this->settings, function ($key) use ($path) { |
|
| 56 | + return glsr(Helper::class)->startsWith($path, $key); |
|
| 57 | + }, ARRAY_FILTER_USE_KEY); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + protected function getSettingRows(array $fields) |
|
| 64 | + { |
|
| 65 | + $rows = ''; |
|
| 66 | + foreach ($fields as $name => $field) { |
|
| 67 | + $field = wp_parse_args($field, [ |
|
| 68 | + 'is_setting' => true, |
|
| 69 | + 'name' => $name, |
|
| 70 | + ]); |
|
| 71 | + $rows .= new Field($this->normalize($field)); |
|
| 72 | + } |
|
| 73 | + return $rows; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param string $id |
|
| 78 | + * @return array |
|
| 79 | + */ |
|
| 80 | + protected function getTemplateData($id) |
|
| 81 | + { |
|
| 82 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 83 | + return [ |
|
| 84 | + 'context' => [ |
|
| 85 | + 'rows' => $this->getSettingRows($fields), |
|
| 86 | + ], |
|
| 87 | + ]; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param string $id |
|
| 92 | + * @return array |
|
| 93 | + */ |
|
| 94 | + protected function getTemplateDataForAddons($id) |
|
| 95 | + { |
|
| 96 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 97 | + $settings = glsr(Helper::class)->convertDotNotationArray($fields); |
|
| 98 | + $settingKeys = array_keys($settings['settings']['addons']); |
|
| 99 | + $results = []; |
|
| 100 | + foreach ($settingKeys as $key) { |
|
| 101 | + $addonFields = array_filter($fields, function ($path) use ($key) { |
|
| 102 | + return glsr(Helper::class)->startsWith('settings.addons.'.$key, $path); |
|
| 103 | + }, ARRAY_FILTER_USE_KEY); |
|
| 104 | + $results[$key] = $this->getSettingRows($addonFields); |
|
| 105 | + } |
|
| 106 | + ksort($results); |
|
| 107 | + return [ |
|
| 108 | + 'settings' => $results, |
|
| 109 | + ]; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @param string $id |
|
| 114 | + * @return array |
|
| 115 | + */ |
|
| 116 | + protected function getTemplateDataForLicenses($id) |
|
| 117 | + { |
|
| 118 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 119 | + ksort($fields); |
|
| 120 | + return [ |
|
| 121 | + 'context' => [ |
|
| 122 | + 'rows' => $this->getSettingRows($fields), |
|
| 123 | + ], |
|
| 124 | + ]; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @return array |
|
| 129 | + */ |
|
| 130 | + protected function getTemplateDataForTranslations() |
|
| 131 | + { |
|
| 132 | + $translations = glsr(Translation::class)->renderAll(); |
|
| 133 | + $class = empty($translations) |
|
| 134 | + ? 'glsr-hidden' |
|
| 135 | + : ''; |
|
| 136 | + return [ |
|
| 137 | + 'context' => [ |
|
| 138 | + 'class' => $class, |
|
| 139 | + 'database_key' => OptionManager::databaseKey(), |
|
| 140 | + 'translations' => $translations, |
|
| 141 | + ], |
|
| 142 | + ]; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * @param string $path |
|
| 147 | + * @param string|array $expectedValue |
|
| 148 | + * @return bool |
|
| 149 | + */ |
|
| 150 | + protected function isFieldHidden($path, $expectedValue) |
|
| 151 | + { |
|
| 152 | + $optionValue = glsr(OptionManager::class)->get( |
|
| 153 | + $path, |
|
| 154 | + glsr(Helper::class)->dataGet(glsr()->defaults, $path) |
|
| 155 | + ); |
|
| 156 | + if (is_array($expectedValue)) { |
|
| 157 | + return is_array($optionValue) |
|
| 158 | + ? 0 === count(array_intersect($optionValue, $expectedValue)) |
|
| 159 | + : !in_array($optionValue, $expectedValue); |
|
| 160 | + } |
|
| 161 | + return $optionValue != $expectedValue; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @return bool |
|
| 166 | + */ |
|
| 167 | + protected function isMultiDependency($path) |
|
| 168 | + { |
|
| 169 | + if (isset($this->settings[$path])) { |
|
| 170 | + $field = $this->settings[$path]; |
|
| 171 | + return ('checkbox' == $field['type'] && !empty($field['options'])) |
|
| 172 | + || !empty($field['multiple']); |
|
| 173 | + } |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @return array |
|
| 179 | + */ |
|
| 180 | + protected function normalize(array $field) |
|
| 181 | + { |
|
| 182 | + $field = $this->normalizeDependsOn($field); |
|
| 183 | + $field = $this->normalizeLabelAndLegend($field); |
|
| 184 | + $field = $this->normalizeValue($field); |
|
| 185 | + return $field; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * @return array |
|
| 190 | + */ |
|
| 191 | + protected function normalizeDependsOn(array $field) |
|
| 192 | + { |
|
| 193 | + if (!empty($field['depends_on']) && is_array($field['depends_on'])) { |
|
| 194 | + $isFieldHidden = false; |
|
| 195 | + $conditions = []; |
|
| 196 | + foreach ($field['depends_on'] as $path => $value) { |
|
| 197 | + $conditions[] = [ |
|
| 198 | + 'name' => $this->getFieldNameForDependsOn($path), |
|
| 199 | + 'value' => $value, |
|
| 200 | + ]; |
|
| 201 | + if ($this->isFieldHidden($path, $value)) { |
|
| 202 | + $isFieldHidden = true; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT); |
|
| 206 | + $field['is_hidden'] = $isFieldHidden; |
|
| 207 | + } |
|
| 208 | + return $field; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @return array |
|
| 213 | + */ |
|
| 214 | + protected function normalizeLabelAndLegend(array $field) |
|
| 215 | + { |
|
| 216 | + if (!empty($field['label'])) { |
|
| 217 | + $field['legend'] = $field['label']; |
|
| 218 | + unset($field['label']); |
|
| 219 | + } else { |
|
| 220 | + $field['is_valid'] = false; |
|
| 221 | + glsr_log()->warning('Setting field is missing a label')->debug($field); |
|
| 222 | + } |
|
| 223 | + return $field; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @return array |
|
| 228 | + */ |
|
| 229 | + protected function normalizeValue(array $field) |
|
| 230 | + { |
|
| 231 | + if (!isset($field['value'])) { |
|
| 232 | + $field['value'] = glsr(OptionManager::class)->get( |
|
| 233 | + $field['name'], |
|
| 234 | + $this->getFieldDefault($field) |
|
| 235 | + ); |
|
| 236 | + } |
|
| 237 | + return $field; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @return string |
|
| 242 | + */ |
|
| 243 | + protected function normalizeSettingPath($path) |
|
| 244 | + { |
|
| 245 | + return glsr(Helper::class)->prefixString(rtrim($path, '.'), 'settings.'); |
|
| 246 | + } |
|
| 247 | 247 | } |
@@ -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'] == $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 = glsr(Helper::class)->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'] == $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 = glsr(Helper::class)->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 | } |
@@ -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 Button extends Field |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @return array |
|
| 9 | - */ |
|
| 10 | - public static function defaults() |
|
| 11 | - { |
|
| 12 | - return [ |
|
| 13 | - 'class' => 'button glsr-button', |
|
| 14 | - ]; |
|
| 15 | - } |
|
| 7 | + /** |
|
| 8 | + * @return array |
|
| 9 | + */ |
|
| 10 | + public static function defaults() |
|
| 11 | + { |
|
| 12 | + return [ |
|
| 13 | + 'class' => 'button glsr-button', |
|
| 14 | + ]; |
|
| 15 | + } |
|
| 16 | 16 | } |
@@ -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 | } |