@@ -10,9 +10,13 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | private static function search(array &$list) { |
| 12 | 12 | |
| 13 | - if (empty($agent = getenv('HTTP_USER_AGENT'))) return false; |
|
| 13 | + if (empty($agent = getenv('HTTP_USER_AGENT'))) { |
|
| 14 | + return false; |
|
| 15 | + } |
|
| 14 | 16 | |
| 15 | - foreach ($list as $item) if (false !== stripos($agent, $item)) return true; |
|
| 17 | + foreach ($list as $item) { |
|
| 18 | + if (false !== stripos($agent, $item)) return true; |
|
| 19 | + } |
|
| 16 | 20 | |
| 17 | 21 | # ------------------------ |
| 18 | 22 | |
@@ -27,9 +31,13 @@ discard block |
||
| 27 | 31 | |
| 28 | 32 | $file_robots = (DIR_DATA . 'Agent/Robots.php'); |
| 29 | 33 | |
| 30 | - if (is_array($mobiles = Explorer::php($file_mobiles))) self::$mobiles = $mobiles; |
|
| 34 | + if (is_array($mobiles = Explorer::php($file_mobiles))) { |
|
| 35 | + self::$mobiles = $mobiles; |
|
| 36 | + } |
|
| 31 | 37 | |
| 32 | - if (is_array($robots = Explorer::php($file_robots))) self::$robots = $robots; |
|
| 38 | + if (is_array($robots = Explorer::php($file_robots))) { |
|
| 39 | + self::$robots = $robots; |
|
| 40 | + } |
|
| 33 | 41 | } |
| 34 | 42 | |
| 35 | 43 | # Check if user agent is mobile |
@@ -8,11 +8,17 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | public static function format($number, int $min = 0, int $max = 0) { |
| 10 | 10 | |
| 11 | - if (!is_numeric($number) || (($number = intval($number)) < 0)) $number = 0; |
|
| 11 | + if (!is_numeric($number) || (($number = intval($number)) < 0)) { |
|
| 12 | + $number = 0; |
|
| 13 | + } |
|
| 12 | 14 | |
| 13 | - if (($min > 0) && ($number < $min)) return $min; |
|
| 15 | + if (($min > 0) && ($number < $min)) { |
|
| 16 | + return $min; |
|
| 17 | + } |
|
| 14 | 18 | |
| 15 | - if (($max > 0) && ($number > $max)) return $max; |
|
| 19 | + if (($max > 0) && ($number > $max)) { |
|
| 20 | + return $max; |
|
| 21 | + } |
|
| 16 | 22 | |
| 17 | 23 | # ------------------------ |
| 18 | 24 | |
@@ -23,11 +29,17 @@ discard block |
||
| 23 | 29 | |
| 24 | 30 | public static function formatFloat($number, float $min = 0, float $max = 0, int $decimals = 0) { |
| 25 | 31 | |
| 26 | - if (!is_numeric($number) || (($number = floatval($number)) < 0)) $number = 0; |
|
| 32 | + if (!is_numeric($number) || (($number = floatval($number)) < 0)) { |
|
| 33 | + $number = 0; |
|
| 34 | + } |
|
| 27 | 35 | |
| 28 | - if (($min > 0) && ($number < $min)) $number = $min; |
|
| 36 | + if (($min > 0) && ($number < $min)) { |
|
| 37 | + $number = $min; |
|
| 38 | + } |
|
| 29 | 39 | |
| 30 | - if (($max > 0) && ($number > $max)) $number = $max; |
|
| 40 | + if (($max > 0) && ($number > $max)) { |
|
| 41 | + $number = $max; |
|
| 42 | + } |
|
| 31 | 43 | |
| 32 | 44 | $number = floatval(number_format($number, $decimals, '.', '')); |
| 33 | 45 | |
@@ -42,9 +54,11 @@ discard block |
||
| 42 | 54 | |
| 43 | 55 | $number = (($number >= 0) ? $number : 0); $exponents = [0 => 'Bytes', 'KB', 'MB', 'GB', 'TB']; |
| 44 | 56 | |
| 45 | - foreach ($exponents as $exponent => $text) if ($number < pow(1024, ($exponent + 1))) { |
|
| 57 | + foreach ($exponents as $exponent => $text) { |
|
| 58 | + if ($number < pow(1024, ($exponent + 1))) { |
|
| 46 | 59 | |
| 47 | 60 | $number = number_format(($number / pow(1024, $exponent)), (($exponent < 2) ? $exponent : 2)); |
| 61 | + } |
|
| 48 | 62 | |
| 49 | 63 | return (floatval($number) . ' ' . $text); |
| 50 | 64 | } |
@@ -62,13 +76,21 @@ discard block |
||
| 62 | 76 | |
| 63 | 77 | $last_1 = substr($number, ($length - 1), 1); $last_2 = substr($number, ($length - 2), 2); |
| 64 | 78 | |
| 65 | - if (($last_2 >= 11) && ($last_2 <= 20)) return $variant_5; |
|
| 79 | + if (($last_2 >= 11) && ($last_2 <= 20)) { |
|
| 80 | + return $variant_5; |
|
| 81 | + } |
|
| 66 | 82 | |
| 67 | - if ($last_1 == 1) return $variant_1; |
|
| 83 | + if ($last_1 == 1) { |
|
| 84 | + return $variant_1; |
|
| 85 | + } |
|
| 68 | 86 | |
| 69 | - if (($last_1 >= 2) && ($last_1 <= 4)) return $variant_3; |
|
| 87 | + if (($last_1 >= 2) && ($last_1 <= 4)) { |
|
| 88 | + return $variant_3; |
|
| 89 | + } |
|
| 70 | 90 | |
| 71 | - if (($last_1 >= 5) || ($last_1 == 0)) return $variant_5; |
|
| 91 | + if (($last_1 >= 5) || ($last_1 == 0)) { |
|
| 92 | + return $variant_5; |
|
| 93 | + } |
|
| 72 | 94 | } |
| 73 | 95 | } |
| 74 | 96 | } |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | private function addField(Form\Utils\Field $field) { |
| 12 | 12 | |
| 13 | - if ($this->posted || ('' === ($key = $field->key()))) return false; |
|
| 13 | + if ($this->posted || ('' === ($key = $field->key()))) { |
|
| 14 | + return false; |
|
| 15 | + } |
|
| 14 | 16 | |
| 15 | 17 | $this->fields[$key] = $field; |
| 16 | 18 | |
@@ -23,7 +25,9 @@ discard block |
||
| 23 | 25 | |
| 24 | 26 | public function __construct(string $name = '') { |
| 25 | 27 | |
| 26 | - if (preg_match(REGEX_FORM_NAME, $name)) $this->name = $name; |
|
| 28 | + if (preg_match(REGEX_FORM_NAME, $name)) { |
|
| 29 | + $this->name = $name; |
|
| 30 | + } |
|
| 27 | 31 | } |
| 28 | 32 | |
| 29 | 33 | # Add text field |
@@ -65,9 +69,15 @@ discard block |
||
| 65 | 69 | |
| 66 | 70 | foreach ($this->fields as $field) { |
| 67 | 71 | |
| 68 | - if (($field instanceof Form\Field\Checkbox) || $field->disabled()) continue; |
|
| 72 | + if (($field instanceof Form\Field\Checkbox) || $field->disabled()) { |
|
| 73 | + continue; |
|
| 74 | + } |
|
| 69 | 75 | |
| 70 | - if (false !== Request::post($field->name())) $check = true; else return false; |
|
| 76 | + if (false !== Request::post($field->name())) { |
|
| 77 | + $check = true; |
|
| 78 | + } else { |
|
| 79 | + return false; |
|
| 80 | + } |
|
| 71 | 81 | } |
| 72 | 82 | |
| 73 | 83 | # ------------------------ |
@@ -79,7 +89,9 @@ discard block |
||
| 79 | 89 | |
| 80 | 90 | public function post() { |
| 81 | 91 | |
| 82 | - if ($this->posted || !$this->check()) return false; |
|
| 92 | + if ($this->posted || !$this->check()) { |
|
| 93 | + return false; |
|
| 94 | + } |
|
| 83 | 95 | |
| 84 | 96 | $errors = false; $post = []; |
| 85 | 97 | |
@@ -87,7 +99,9 @@ discard block |
||
| 87 | 99 | |
| 88 | 100 | $field->post(); $post[$field->key()] = $field->value(); |
| 89 | 101 | |
| 90 | - if ($field->error()) $errors = true; |
|
| 102 | + if ($field->error()) { |
|
| 103 | + $errors = true; |
|
| 104 | + } |
|
| 91 | 105 | } |
| 92 | 106 | |
| 93 | 107 | $this->posted = true; $this->errors = $errors; |
@@ -44,7 +44,7 @@ |
||
| 44 | 44 | |
| 45 | 45 | public function __construct(Form $form, string $key, string $value = '', |
| 46 | 46 | |
| 47 | - array $options = [], string $default = null, array $config = []) { |
|
| 47 | + array $options = [], string $default = null, array $config = []) { |
|
| 48 | 48 | |
| 49 | 49 | # Init field |
| 50 | 50 | |
@@ -92,9 +92,13 @@ |
||
| 92 | 92 | |
| 93 | 93 | $tag = $this->getTag('select'); |
| 94 | 94 | |
| 95 | - if ($this->config['search']) $tag->set('data-search', 'search'); |
|
| 95 | + if ($this->config['search']) { |
|
| 96 | + $tag->set('data-search', 'search'); |
|
| 97 | + } |
|
| 96 | 98 | |
| 97 | - if ($this->config['auto']) $tag->set('data-auto', 'auto'); |
|
| 99 | + if ($this->config['auto']) { |
|
| 100 | + $tag->set('data-auto', 'auto'); |
|
| 101 | + } |
|
| 98 | 102 | |
| 99 | 103 | $tag->contents($this->getOptions()); |
| 100 | 104 | |
@@ -38,7 +38,9 @@ |
||
| 38 | 38 | |
| 39 | 39 | $tag->set('type', 'checkbox'); |
| 40 | 40 | |
| 41 | - if (false !== $this->value) $tag->set('checked', 'checked'); |
|
| 41 | + if (false !== $this->value) { |
|
| 42 | + $tag->set('checked', 'checked'); |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | # ------------------------ |
| 44 | 46 | |
@@ -105,7 +105,7 @@ |
||
| 105 | 105 | |
| 106 | 106 | public function __construct(Form $form, string $key, string $value = '', |
| 107 | 107 | |
| 108 | - string $type = FORM_FIELD_TEXT, int $maxlength = 0, array $config = []) { |
|
| 108 | + string $type = FORM_FIELD_TEXT, int $maxlength = 0, array $config = []) { |
|
| 109 | 109 | |
| 110 | 110 | # Init field |
| 111 | 111 | |
@@ -65,9 +65,13 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | $tag = $this->getTag('textarea', [], $this->value); |
| 67 | 67 | |
| 68 | - if ($this->config['rows'] > 0) $tag->set('rows', $this->config['rows']); |
|
| 68 | + if ($this->config['rows'] > 0) { |
|
| 69 | + $tag->set('rows', $this->config['rows']); |
|
| 70 | + } |
|
| 69 | 71 | |
| 70 | - if ($this->config['cols'] > 0) $tag->set('cols', $this->config['cols']); |
|
| 72 | + if ($this->config['cols'] > 0) { |
|
| 73 | + $tag->set('cols', $this->config['cols']); |
|
| 74 | + } |
|
| 71 | 75 | |
| 72 | 76 | # ------------------------ |
| 73 | 77 | |
@@ -78,27 +82,33 @@ discard block |
||
| 78 | 82 | |
| 79 | 83 | private function processSpaces() { |
| 80 | 84 | |
| 81 | - if ($this->config['spaces'] === 'strip') $this->value = Str::stripSpaces($this->value); |
|
| 82 | - |
|
| 83 | - else if ($this->config['spaces'] === 'single') $this->value = Str::singleSpaces($this->value); |
|
| 85 | + if ($this->config['spaces'] === 'strip') { |
|
| 86 | + $this->value = Str::stripSpaces($this->value); |
|
| 87 | + } else if ($this->config['spaces'] === 'single') { |
|
| 88 | + $this->value = Str::singleSpaces($this->value); |
|
| 89 | + } |
|
| 84 | 90 | } |
| 85 | 91 | |
| 86 | 92 | # Process convert |
| 87 | 93 | |
| 88 | 94 | private function processConvert() { |
| 89 | 95 | |
| 90 | - if ($this->config['convert'] === 'url') $this->value = Str::toUrl($this->value, $this->maxlength); |
|
| 91 | - |
|
| 92 | - else if ($this->config['convert'] === 'var') $this->value = Str::toVar($this->value, $this->maxlength); |
|
| 96 | + if ($this->config['convert'] === 'url') { |
|
| 97 | + $this->value = Str::toUrl($this->value, $this->maxlength); |
|
| 98 | + } else if ($this->config['convert'] === 'var') { |
|
| 99 | + $this->value = Str::toVar($this->value, $this->maxlength); |
|
| 100 | + } |
|
| 93 | 101 | } |
| 94 | 102 | |
| 95 | 103 | # Process transform |
| 96 | 104 | |
| 97 | 105 | private function processTransform() { |
| 98 | 106 | |
| 99 | - if ($this->config['transform'] === 'lower') $this->value = Str::toLower($this->value); |
|
| 100 | - |
|
| 101 | - else if ($this->config['transform'] === 'upper') $this->value = Str::toUpper($this->value); |
|
| 107 | + if ($this->config['transform'] === 'lower') { |
|
| 108 | + $this->value = Str::toLower($this->value); |
|
| 109 | + } else if ($this->config['transform'] === 'upper') { |
|
| 110 | + $this->value = Str::toUpper($this->value); |
|
| 111 | + } |
|
| 102 | 112 | } |
| 103 | 113 | |
| 104 | 114 | # Constructor |
@@ -164,7 +174,9 @@ discard block |
||
| 164 | 174 | |
| 165 | 175 | public function spaces(string $value) { |
| 166 | 176 | |
| 167 | - if (!in_array($value, ['strip', 'single'], true)) $value = ''; |
|
| 177 | + if (!in_array($value, ['strip', 'single'], true)) { |
|
| 178 | + $value = ''; |
|
| 179 | + } |
|
| 168 | 180 | |
| 169 | 181 | $this->config['spaces'] = $value; |
| 170 | 182 | } |
@@ -173,7 +185,9 @@ discard block |
||
| 173 | 185 | |
| 174 | 186 | public function convert(string $value) { |
| 175 | 187 | |
| 176 | - if (!in_array($value, ['url', 'var'], true)) $value = ''; |
|
| 188 | + if (!in_array($value, ['url', 'var'], true)) { |
|
| 189 | + $value = ''; |
|
| 190 | + } |
|
| 177 | 191 | |
| 178 | 192 | $this->config['convert'] = $value; |
| 179 | 193 | } |
@@ -182,7 +196,9 @@ discard block |
||
| 182 | 196 | |
| 183 | 197 | public function transform(string $value) { |
| 184 | 198 | |
| 185 | - if (!in_array($value, ['upper', 'lower'], true)) $value = ''; |
|
| 199 | + if (!in_array($value, ['upper', 'lower'], true)) { |
|
| 200 | + $value = ''; |
|
| 201 | + } |
|
| 186 | 202 | |
| 187 | 203 | $this->config['transform'] = $value; |
| 188 | 204 | } |
@@ -226,25 +242,35 @@ discard block |
||
| 226 | 242 | |
| 227 | 243 | public function block() { |
| 228 | 244 | |
| 229 | - if ($this->type === FORM_FIELD_HIDDEN) return $this->getHidden()->block(); |
|
| 230 | - |
|
| 231 | - else if ($this->type === FORM_FIELD_PASSWORD) $tag = $this->getPassword(); |
|
| 232 | - |
|
| 233 | - else if ($this->type === FORM_FIELD_CAPTCHA) $tag = $this->getCaptcha(); |
|
| 234 | - |
|
| 235 | - else if ($this->type === FORM_FIELD_TEXTAREA) $tag = $this->getTextarea(); |
|
| 236 | - |
|
| 237 | - else $tag = $this->getText(); |
|
| 245 | + if ($this->type === FORM_FIELD_HIDDEN) { |
|
| 246 | + return $this->getHidden()->block(); |
|
| 247 | + } else if ($this->type === FORM_FIELD_PASSWORD) { |
|
| 248 | + $tag = $this->getPassword(); |
|
| 249 | + } else if ($this->type === FORM_FIELD_CAPTCHA) { |
|
| 250 | + $tag = $this->getCaptcha(); |
|
| 251 | + } else if ($this->type === FORM_FIELD_TEXTAREA) { |
|
| 252 | + $tag = $this->getTextarea(); |
|
| 253 | + } else { |
|
| 254 | + $tag = $this->getText(); |
|
| 255 | + } |
|
| 238 | 256 | |
| 239 | 257 | # Set appearance |
| 240 | 258 | |
| 241 | - if ($this->maxlength > 0) $tag->set('maxlength', $this->maxlength); |
|
| 259 | + if ($this->maxlength > 0) { |
|
| 260 | + $tag->set('maxlength', $this->maxlength); |
|
| 261 | + } |
|
| 242 | 262 | |
| 243 | - if ('' !== $this->config['placeholder']) $tag->set('placeholder', $this->config['placeholder']); |
|
| 263 | + if ('' !== $this->config['placeholder']) { |
|
| 264 | + $tag->set('placeholder', $this->config['placeholder']); |
|
| 265 | + } |
|
| 244 | 266 | |
| 245 | - if ($this->config['readonly']) $tag->set('readonly', 'readonly'); |
|
| 267 | + if ($this->config['readonly']) { |
|
| 268 | + $tag->set('readonly', 'readonly'); |
|
| 269 | + } |
|
| 246 | 270 | |
| 247 | - if ($this->config['autofocus']) $tag->set('autofocus', 'autofocus'); |
|
| 271 | + if ($this->config['autofocus']) { |
|
| 272 | + $tag->set('autofocus', 'autofocus'); |
|
| 273 | + } |
|
| 248 | 274 | |
| 249 | 275 | # ------------------------ |
| 250 | 276 | |
@@ -24,11 +24,17 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | # Set config |
| 26 | 26 | |
| 27 | - if ($this->disabled) $tag->set('disabled', 'disabled'); |
|
| 27 | + if ($this->disabled) { |
|
| 28 | + $tag->set('disabled', 'disabled'); |
|
| 29 | + } |
|
| 28 | 30 | |
| 29 | - if ($this->required) $tag->set('data-required', 'required'); |
|
| 31 | + if ($this->required) { |
|
| 32 | + $tag->set('data-required', 'required'); |
|
| 33 | + } |
|
| 30 | 34 | |
| 31 | - if ($this->error) $tag->set('data-error', 'error'); |
|
| 35 | + if ($this->error) { |
|
| 36 | + $tag->set('data-error', 'error'); |
|
| 37 | + } |
|
| 32 | 38 | |
| 33 | 39 | # ------------------------ |
| 34 | 40 | |
@@ -54,11 +60,15 @@ discard block |
||
| 54 | 60 | |
| 55 | 61 | $params = array_merge(['disabled' => false, 'required' => false], $this->config); |
| 56 | 62 | |
| 57 | - foreach ($params as $name => $default) if (isset($config[$name])) { |
|
| 63 | + foreach ($params as $name => $default) { |
|
| 64 | + if (isset($config[$name])) { |
|
| 58 | 65 | |
| 59 | 66 | $checker = ((0 === $default) ? 'is_numeric' : 'is_scalar'); |
| 67 | + } |
|
| 60 | 68 | |
| 61 | - if ($checker($config[$name])) $this->$name($config[$name]); |
|
| 69 | + if ($checker($config[$name])) { |
|
| 70 | + $this->$name($config[$name]); |
|
| 71 | + } |
|
| 62 | 72 | } |
| 63 | 73 | } |
| 64 | 74 | |
@@ -66,7 +76,9 @@ discard block |
||
| 66 | 76 | |
| 67 | 77 | public function post() { |
| 68 | 78 | |
| 69 | - if ($this->posted || $this->disabled || ('' === $this->key)) return false; |
|
| 79 | + if ($this->posted || $this->disabled || ('' === $this->key)) { |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 70 | 82 | |
| 71 | 83 | $this->error = (!$this->set(Request::post($this->name)) && $this->required); |
| 72 | 84 | |
@@ -100,7 +112,9 @@ discard block |
||
| 100 | 112 | |
| 101 | 113 | public function disabled(bool $value = null) { |
| 102 | 114 | |
| 103 | - if (null === $value) return $this->disabled; |
|
| 115 | + if (null === $value) { |
|
| 116 | + return $this->disabled; |
|
| 117 | + } |
|
| 104 | 118 | |
| 105 | 119 | $this->disabled = $value; |
| 106 | 120 | } |
@@ -109,7 +123,9 @@ discard block |
||
| 109 | 123 | |
| 110 | 124 | public function required(bool $value = null) { |
| 111 | 125 | |
| 112 | - if (null === $value) return $this->required; |
|
| 126 | + if (null === $value) { |
|
| 127 | + return $this->required; |
|
| 128 | + } |
|
| 113 | 129 | |
| 114 | 130 | $this->required = $value; |
| 115 | 131 | } |
@@ -23,7 +23,9 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | $this->name = $name; |
| 25 | 25 | |
| 26 | - foreach ($attributes as $name => $value) $this->set($name, $value); |
|
| 26 | + foreach ($attributes as $name => $value) { |
|
| 27 | + $this->set($name, $value); |
|
| 28 | + } |
|
| 27 | 29 | |
| 28 | 30 | $this->contents($contents); |
| 29 | 31 | } |
@@ -41,9 +43,11 @@ discard block |
||
| 41 | 43 | |
| 42 | 44 | public function contents($contents) { |
| 43 | 45 | |
| 44 | - if ((null === $contents) || Template::isBlock($contents)) $this->contents = $contents; |
|
| 45 | - |
|
| 46 | - else if (is_scalar($contents)) $this->contents = Template::block('$contents$')->set('contents', $contents); |
|
| 46 | + if ((null === $contents) || Template::isBlock($contents)) { |
|
| 47 | + $this->contents = $contents; |
|
| 48 | + } else if (is_scalar($contents)) { |
|
| 49 | + $this->contents = Template::block('$contents$')->set('contents', $contents); |
|
| 50 | + } |
|
| 47 | 51 | |
| 48 | 52 | # ------------------------ |
| 49 | 53 | |
@@ -8,9 +8,13 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | public static function validate(string $date, string $format) { |
| 10 | 10 | |
| 11 | - if (false === ($date_object = date_create_from_format($format, $date))) return false; |
|
| 11 | + if (false === ($date_object = date_create_from_format($format, $date))) { |
|
| 12 | + return false; |
|
| 13 | + } |
|
| 12 | 14 | |
| 13 | - if (false === ($date_formatted = $date_object->format($format))) return false; |
|
| 15 | + if (false === ($date_formatted = $date_object->format($format))) { |
|
| 16 | + return false; |
|
| 17 | + } |
|
| 14 | 18 | |
| 15 | 19 | # ------------------------ |
| 16 | 20 | |
@@ -35,7 +39,9 @@ discard block |
||
| 35 | 39 | |
| 36 | 40 | public static function validateYear(int $year) { |
| 37 | 41 | |
| 38 | - if (false === ($year = self::validate($year, 'Y'))) return false; |
|
| 42 | + if (false === ($year = self::validate($year, 'Y'))) { |
|
| 43 | + return false; |
|
| 44 | + } |
|
| 39 | 45 | |
| 40 | 46 | return (($year > '1900') ? (($year > self::year()) ? self::year() : $year) : '1900'); |
| 41 | 47 | } |