@@ -19,7 +19,9 @@ |
||
| 19 | 19 | |
| 20 | 20 | protected static function init(string $file_name) { |
| 21 | 21 | |
| 22 | - if (is_array($range = Explorer::include($file_name))) static::$range = $range; |
|
| 22 | + if (is_array($range = Explorer::include($file_name))) { |
|
| 23 | + static::$range = $range; |
|
| 24 | + } |
|
| 23 | 25 | } |
| 24 | 26 | |
| 25 | 27 | /** |
@@ -30,7 +30,9 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | public static function stringify(SimpleXMLElement $xml) { |
| 32 | 32 | |
| 33 | - if (false === ($xml = dom_import_simplexml($xml))) return false; |
|
| 33 | + if (false === ($xml = dom_import_simplexml($xml))) { |
|
| 34 | + return false; |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | $dom = $xml->ownerDocument; $dom->formatOutput = true; |
| 36 | 38 | |
@@ -47,7 +49,9 @@ discard block |
||
| 47 | 49 | |
| 48 | 50 | public static function load(string $file_name) { |
| 49 | 51 | |
| 50 | - if (false === ($contents = Explorer::getContents($file_name))) return false; |
|
| 52 | + if (false === ($contents = Explorer::getContents($file_name))) { |
|
| 53 | + return false; |
|
| 54 | + } |
|
| 51 | 55 | |
| 52 | 56 | return self::parse($contents); |
| 53 | 57 | } |
@@ -60,7 +64,9 @@ discard block |
||
| 60 | 64 | |
| 61 | 65 | public static function save(string $file_name, SimpleXMLElement $xml) { |
| 62 | 66 | |
| 63 | - if (false === ($xml = self::stringify($xml))) return false; |
|
| 67 | + if (false === ($xml = self::stringify($xml))) { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 64 | 70 | |
| 65 | 71 | return Explorer::putContents($file_name, $xml); |
| 66 | 72 | } |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | |
| 30 | 30 | # Build query |
| 31 | 31 | |
| 32 | - $this->query = ('UPDATE ' . $table . ' SET ' . $set . ($condition ? (' WHERE (' . $condition . ')') : '')); |
|
| 32 | + $this->query = ('UPDATE '.$table.' SET '.$set.($condition ? (' WHERE ('.$condition.')') : '')); |
|
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | } |
@@ -95,7 +95,9 @@ |
||
| 95 | 95 | |
| 96 | 96 | public static function output(Template\Block $block, int $status = STATUS_CODE_200) { |
| 97 | 97 | |
| 98 | - if (!Headers::isStatusCode($status)) $status = STATUS_CODE_200; |
|
| 98 | + if (!Headers::isStatusCode($status)) { |
|
| 99 | + $status = STATUS_CODE_200; |
|
| 100 | + } |
|
| 99 | 101 | |
| 100 | 102 | Headers::sendNoCache(); Headers::sendStatus($status); Headers::sendContent(MIME_TYPE_HTML); |
| 101 | 103 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) continue; |
| 37 | 37 | |
| 38 | - $this->contents = str_replace($match, ('{ ' . $type . ':' . $name . ' / }'), $this->contents); |
|
| 38 | + $this->contents = str_replace($match, ('{ '.$type.':'.$name.' / }'), $this->contents); |
|
| 39 | 39 | |
| 40 | 40 | if ($type === 'block') $this->blocks[$name] = (new Block($contents))->$toggle(); |
| 41 | 41 | |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | private function parseElementaries() { |
| 53 | 53 | |
| 54 | - $variables = ['pattern' => REGEX_TEMPLATE_VARIABLE, 'stack' => &$this->variables ]; |
|
| 54 | + $variables = ['pattern' => REGEX_TEMPLATE_VARIABLE, 'stack' => &$this->variables]; |
|
| 55 | 55 | |
| 56 | - $phrases = ['pattern' => REGEX_TEMPLATE_PHRASE, 'stack' => &$this->phrases ]; |
|
| 56 | + $phrases = ['pattern' => REGEX_TEMPLATE_PHRASE, 'stack' => &$this->phrases]; |
|
| 57 | 57 | |
| 58 | 58 | foreach ([$variables, $phrases] as $elementaries) { |
| 59 | 59 | |
@@ -80,14 +80,14 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | foreach ($this->blocks as $name => $block) { |
| 82 | 82 | |
| 83 | - $insertions['{ block:' . $name . ' / }'] = $block->getContents(); |
|
| 83 | + $insertions['{ block:'.$name.' / }'] = $block->getContents(); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | # Process loops |
| 87 | 87 | |
| 88 | 88 | foreach ($this->loops as $name => $loop) { |
| 89 | 89 | |
| 90 | - $insertions['{ for:' . $name . ' / }'] = $loop->getContents(); |
|
| 90 | + $insertions['{ for:'.$name.' / }'] = $loop->getContents(); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | # Process widgets |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | $contents = ((false !== $widget) ? $widget->getContents() : ''); |
| 100 | 100 | |
| 101 | - $insertions['{ widget:' . $name . ' / }'] = $contents; |
|
| 101 | + $insertions['{ widget:'.$name.' / }'] = $contents; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | # Process variables |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | $value = ((false === $value) ? Template::getGlobal($name) : $value); |
| 109 | 109 | |
| 110 | - $insertions['$' . $name . '$'] = Str::formatOutput($value); |
|
| 110 | + $insertions['$'.$name.'$'] = Str::formatOutput($value); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | # Process phrases |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | $value = Language::get($name); |
| 118 | 118 | |
| 119 | - $insertions['%' . $name . '%'] = Str::formatOutput($value); |
|
| 119 | + $insertions['%'.$name.'%'] = Str::formatOutput($value); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | # Process insertions |
@@ -23,7 +23,9 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | private function registerWidget(string $name) { |
| 25 | 25 | |
| 26 | - if (false === Template::getWidget($name)) Template::setWidget($name, new Block); |
|
| 26 | + if (false === Template::getWidget($name)) { |
|
| 27 | + Template::setWidget($name, new Block); |
|
| 28 | + } |
|
| 27 | 29 | } |
| 28 | 30 | |
| 29 | 31 | /** |
@@ -40,15 +42,19 @@ discard block |
||
| 40 | 42 | |
| 41 | 43 | $type = $matches[2][$key]; $name = $matches[3][$key]; $contents = ($matches[4][$key] ?? ''); |
| 42 | 44 | |
| 43 | - if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) continue; |
|
| 45 | + if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) { |
|
| 46 | + continue; |
|
| 47 | + } |
|
| 44 | 48 | |
| 45 | 49 | $this->contents = str_replace($match, ('{ ' . $type . ':' . $name . ' / }'), $this->contents); |
| 46 | 50 | |
| 47 | - if ($type === 'block') $this->blocks[$name] = (new Block($contents))->$toggle(); |
|
| 48 | - |
|
| 49 | - else if ($type === 'for') $this->loops[$name] = new Loop($contents); |
|
| 50 | - |
|
| 51 | - else if ($type === 'widget') $this->registerWidget($this->widgets[] = $name); |
|
| 51 | + if ($type === 'block') { |
|
| 52 | + $this->blocks[$name] = (new Block($contents))->$toggle(); |
|
| 53 | + } else if ($type === 'for') { |
|
| 54 | + $this->loops[$name] = new Loop($contents); |
|
| 55 | + } else if ($type === 'widget') { |
|
| 56 | + $this->registerWidget($this->widgets[] = $name); |
|
| 57 | + } |
|
| 52 | 58 | } |
| 53 | 59 | } |
| 54 | 60 | |
@@ -68,7 +74,9 @@ discard block |
||
| 68 | 74 | |
| 69 | 75 | foreach ($matches[1] as $index => $name) { |
| 70 | 76 | |
| 71 | - if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) continue; |
|
| 77 | + if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) { |
|
| 78 | + continue; |
|
| 79 | + } |
|
| 72 | 80 | |
| 73 | 81 | $elementaries['stack'][$name] = false; |
| 74 | 82 | } |
@@ -152,11 +160,17 @@ discard block |
||
| 152 | 160 | |
| 153 | 161 | public function __clone() { |
| 154 | 162 | |
| 155 | - foreach ($this->blocks as $name => $block) $this->blocks[$name] = clone $block; |
|
| 163 | + foreach ($this->blocks as $name => $block) { |
|
| 164 | + $this->blocks[$name] = clone $block; |
|
| 165 | + } |
|
| 156 | 166 | |
| 157 | - foreach ($this->loops as $name => $loop) $this->loops[$name] = clone $loop; |
|
| 167 | + foreach ($this->loops as $name => $loop) { |
|
| 168 | + $this->loops[$name] = clone $loop; |
|
| 169 | + } |
|
| 158 | 170 | |
| 159 | - foreach ($this->items as $name => $item) $this->items[$name] = clone $item; |
|
| 171 | + foreach ($this->items as $name => $item) { |
|
| 172 | + $this->items[$name] = clone $item; |
|
| 173 | + } |
|
| 160 | 174 | } |
| 161 | 175 | |
| 162 | 176 | /** |
@@ -167,11 +181,13 @@ discard block |
||
| 167 | 181 | |
| 168 | 182 | public function set(string $name, $component) : Block { |
| 169 | 183 | |
| 170 | - if ($component instanceof Block) $this->setBlock($name, $component); |
|
| 171 | - |
|
| 172 | - else if (is_array($component)) $this->setLoop($name, $component); |
|
| 173 | - |
|
| 174 | - else if (is_scalar($component)) $this->setVar($name, $component); |
|
| 184 | + if ($component instanceof Block) { |
|
| 185 | + $this->setBlock($name, $component); |
|
| 186 | + } else if (is_array($component)) { |
|
| 187 | + $this->setLoop($name, $component); |
|
| 188 | + } else if (is_scalar($component)) { |
|
| 189 | + $this->setVar($name, $component); |
|
| 190 | + } |
|
| 175 | 191 | |
| 176 | 192 | # ------------------------ |
| 177 | 193 | |
@@ -186,7 +202,9 @@ discard block |
||
| 186 | 202 | |
| 187 | 203 | public function setArray(array $components) : Block { |
| 188 | 204 | |
| 189 | - foreach ($components as $name => $component) $this->set($name, $component); |
|
| 205 | + foreach ($components as $name => $component) { |
|
| 206 | + $this->set($name, $component); |
|
| 207 | + } |
|
| 190 | 208 | |
| 191 | 209 | return $this; |
| 192 | 210 | } |
@@ -199,7 +217,9 @@ discard block |
||
| 199 | 217 | |
| 200 | 218 | public function setBlock(string $name, Block $block) : Block { |
| 201 | 219 | |
| 202 | - if (isset($this->blocks[$name])) $this->blocks[$name] = $block; |
|
| 220 | + if (isset($this->blocks[$name])) { |
|
| 221 | + $this->blocks[$name] = $block; |
|
| 222 | + } |
|
| 203 | 223 | |
| 204 | 224 | return $this; |
| 205 | 225 | } |
@@ -212,7 +232,9 @@ discard block |
||
| 212 | 232 | |
| 213 | 233 | public function setLoop(string $name, array $items) : Block { |
| 214 | 234 | |
| 215 | - if (isset($this->loops[$name])) $this->loops[$name]->setItems($items); |
|
| 235 | + if (isset($this->loops[$name])) { |
|
| 236 | + $this->loops[$name]->setItems($items); |
|
| 237 | + } |
|
| 216 | 238 | |
| 217 | 239 | return $this; |
| 218 | 240 | } |
@@ -225,7 +247,9 @@ discard block |
||
| 225 | 247 | |
| 226 | 248 | public function setVar(string $name, string $value) : Block { |
| 227 | 249 | |
| 228 | - if (isset($this->variables[$name])) $this->variables[$name] = $value; |
|
| 250 | + if (isset($this->variables[$name])) { |
|
| 251 | + $this->variables[$name] = $value; |
|
| 252 | + } |
|
| 229 | 253 | |
| 230 | 254 | return $this; |
| 231 | 255 | } |
@@ -307,7 +331,9 @@ discard block |
||
| 307 | 331 | |
| 308 | 332 | public function getContents() : string { |
| 309 | 333 | |
| 310 | - if (!$this->enabled) return ''; |
|
| 334 | + if (!$this->enabled) { |
|
| 335 | + return ''; |
|
| 336 | + } |
|
| 311 | 337 | |
| 312 | 338 | # Lock the block |
| 313 | 339 | |
@@ -22,7 +22,12 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | $value = null; |
| 24 | 24 | |
| 25 | - foreach ($path as $item) if (isset($array[$item])) $value = ($array = $array[$item]); else return null; |
|
| 25 | + foreach ($path as $item) { |
|
| 26 | + if (isset($array[$item])) $value = ($array = $array[$item]); |
|
| 27 | + } |
|
| 28 | + else { |
|
| 29 | + return null; |
|
| 30 | + } |
|
| 26 | 31 | |
| 27 | 32 | # ------------------------ |
| 28 | 33 | |
@@ -38,7 +43,9 @@ discard block |
||
| 38 | 43 | |
| 39 | 44 | $selected = array_intersect_key($array, array_flip($keys)); |
| 40 | 45 | |
| 41 | - if (null !== $filter) $selected = array_filter($array, $filter); |
|
| 46 | + if (null !== $filter) { |
|
| 47 | + $selected = array_filter($array, $filter); |
|
| 48 | + } |
|
| 42 | 49 | |
| 43 | 50 | # ------------------------ |
| 44 | 51 | |
@@ -54,7 +61,9 @@ discard block |
||
| 54 | 61 | |
| 55 | 62 | $indexed = []; |
| 56 | 63 | |
| 57 | - foreach ($array as $key => $value) $indexed[] = [$key_name => $key, $value_name => $value]; |
|
| 64 | + foreach ($array as $key => $value) { |
|
| 65 | + $indexed[] = [$key_name => $key, $value_name => $value]; |
|
| 66 | + } |
|
| 58 | 67 | |
| 59 | 68 | # ------------------------ |
| 60 | 69 | |
@@ -71,9 +80,15 @@ discard block |
||
| 71 | 80 | |
| 72 | 81 | $sorted = []; $column = array_map($select_key, $array); |
| 73 | 82 | |
| 74 | - if (!$descending) asort($column); else arsort($column); |
|
| 83 | + if (!$descending) { |
|
| 84 | + asort($column); |
|
| 85 | + } else { |
|
| 86 | + arsort($column); |
|
| 87 | + } |
|
| 75 | 88 | |
| 76 | - foreach (array_keys($column) as $key) $sorted[$key] = $array[$key]; |
|
| 89 | + foreach (array_keys($column) as $key) { |
|
| 90 | + $sorted[$key] = $array[$key]; |
|
| 91 | + } |
|
| 77 | 92 | |
| 78 | 93 | # ------------------------ |
| 79 | 94 | |
@@ -67,7 +67,7 @@ |
||
| 67 | 67 | |
| 68 | 68 | public static function sortby(array $array, $sub_key, bool $descending = false) : array { |
| 69 | 69 | |
| 70 | - $select_key = function ($element) use ($sub_key) { return ($element[$sub_key] ?? false); }; |
|
| 70 | + $select_key = function($element) use ($sub_key) { return ($element[$sub_key] ?? false); }; |
|
| 71 | 71 | |
| 72 | 72 | $sorted = []; $column = array_map($select_key, $array); |
| 73 | 73 | |
@@ -19,9 +19,13 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | public static function validate(string $date, string $format) { |
| 21 | 21 | |
| 22 | - if (false === ($datetime = date_create_from_format($format, $date))) return false; |
|
| 22 | + if (false === ($datetime = date_create_from_format($format, $date))) { |
|
| 23 | + return false; |
|
| 24 | + } |
|
| 23 | 25 | |
| 24 | - if (false === ($formatted = $datetime->format($format))) return false; |
|
| 26 | + if (false === ($formatted = $datetime->format($format))) { |
|
| 27 | + return false; |
|
| 28 | + } |
|
| 25 | 29 | |
| 26 | 30 | # ------------------------ |
| 27 | 31 | |
@@ -58,7 +62,9 @@ discard block |
||
| 58 | 62 | |
| 59 | 63 | public static function validateYear(int $year) { |
| 60 | 64 | |
| 61 | - if (false === ($year = self::validate($year, 'Y'))) return false; |
|
| 65 | + if (false === ($year = self::validate($year, 'Y'))) { |
|
| 66 | + return false; |
|
| 67 | + } |
|
| 62 | 68 | |
| 63 | 69 | return (($year > '1900') ? (($year > self::getYear()) ? self::getYear() : $year) : '1900'); |
| 64 | 70 | } |
@@ -19,18 +19,24 @@ |
||
| 19 | 19 | |
| 20 | 20 | public function __construct(string $url = '') { |
| 21 | 21 | |
| 22 | - if (false === ($url = parse_url($url))) return; |
|
| 22 | + if (false === ($url = parse_url($url))) { |
|
| 23 | + return; |
|
| 24 | + } |
|
| 23 | 25 | |
| 24 | 26 | # Parse path |
| 25 | 27 | |
| 26 | - if (isset($url['path'])) foreach (explode('/', $url['path']) as $part) { |
|
| 28 | + if (isset($url['path'])) { |
|
| 29 | + foreach (explode('/', $url['path']) as $part) { |
|
| 27 | 30 | |
| 28 | 31 | if ('' !== $part) $this->path[] = urldecode($part); |
| 29 | 32 | } |
| 33 | + } |
|
| 30 | 34 | |
| 31 | 35 | # Parse query |
| 32 | 36 | |
| 33 | - if (isset($url['query'])) parse_str($url['query'], $this->query); |
|
| 37 | + if (isset($url['query'])) { |
|
| 38 | + parse_str($url['query'], $this->query); |
|
| 39 | + } |
|
| 34 | 40 | } |
| 35 | 41 | |
| 36 | 42 | /** |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | public function getPath() : string { |
| 74 | 74 | |
| 75 | - return ('/' . implode('/', array_map('urlencode', $this->path))); |
|
| 75 | + return ('/'.implode('/', array_map('urlencode', $this->path))); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | public function getQuery() : string { |
| 83 | 83 | |
| 84 | - return (($query = http_build_query($this->query)) ? ('?' . $query) : ''); |
|
| 84 | + return (($query = http_build_query($this->query)) ? ('?'.$query) : ''); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | public function getString(bool $include_query = true) : string { |
| 110 | 110 | |
| 111 | - return ($this->getPath() . ($include_query ? $this->getQuery() : '')); |
|
| 111 | + return ($this->getPath().($include_query ? $this->getQuery() : '')); |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -47,10 +47,10 @@ |
||
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | - * Get a query attribute |
|
| 51 | - * |
|
| 52 | - * @return string|false : the value or false if the attribute does not exist |
|
| 53 | - */ |
|
| 50 | + * Get a query attribute |
|
| 51 | + * |
|
| 52 | + * @return string|false : the value or false if the attribute does not exist |
|
| 53 | + */ |
|
| 54 | 54 | |
| 55 | 55 | public function getAttribute(string $name) { |
| 56 | 56 | |
@@ -181,7 +181,7 @@ |
||
| 181 | 181 | |
| 182 | 182 | foreach ($this->fields as $field) { |
| 183 | 183 | |
| 184 | - $block->setBlock(('field_' . $field->getName()), $field->getBlock()); |
|
| 184 | + $block->setBlock(('field_'.$field->getName()), $field->getBlock()); |
|
| 185 | 185 | } |
| 186 | 186 | } |
| 187 | 187 | } |
@@ -23,7 +23,9 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | private function addField(Form\Field $field) : bool { |
| 25 | 25 | |
| 26 | - if ($this->posted || ('' === ($key = $field->getKey()))) return false; |
|
| 26 | + if ($this->posted || ('' === ($key = $field->getKey()))) { |
|
| 27 | + return false; |
|
| 28 | + } |
|
| 27 | 29 | |
| 28 | 30 | $this->fields[$key] = $field; |
| 29 | 31 | |
@@ -38,7 +40,9 @@ discard block |
||
| 38 | 40 | |
| 39 | 41 | public function __construct(string $name = '') { |
| 40 | 42 | |
| 41 | - if (preg_match(REGEX_FORM_NAME, $name)) $this->name = $name; |
|
| 43 | + if (preg_match(REGEX_FORM_NAME, $name)) { |
|
| 44 | + $this->name = $name; |
|
| 45 | + } |
|
| 42 | 46 | } |
| 43 | 47 | |
| 44 | 48 | /** |
@@ -90,9 +94,15 @@ discard block |
||
| 90 | 94 | |
| 91 | 95 | foreach ($this->fields as $field) { |
| 92 | 96 | |
| 93 | - if (($field instanceof Form\Field\Checkbox) || $field->disabled) continue; |
|
| 97 | + if (($field instanceof Form\Field\Checkbox) || $field->disabled) { |
|
| 98 | + continue; |
|
| 99 | + } |
|
| 94 | 100 | |
| 95 | - if (false !== Request::post($field->getName())) $check = true; else return false; |
|
| 101 | + if (false !== Request::post($field->getName())) { |
|
| 102 | + $check = true; |
|
| 103 | + } else { |
|
| 104 | + return false; |
|
| 105 | + } |
|
| 96 | 106 | } |
| 97 | 107 | |
| 98 | 108 | # ------------------------ |
@@ -108,7 +118,9 @@ discard block |
||
| 108 | 118 | |
| 109 | 119 | public function post() { |
| 110 | 120 | |
| 111 | - if ($this->posted || !$this->check()) return false; |
|
| 121 | + if ($this->posted || !$this->check()) { |
|
| 122 | + return false; |
|
| 123 | + } |
|
| 112 | 124 | |
| 113 | 125 | $post = []; $errors = false; |
| 114 | 126 | |
@@ -116,7 +128,9 @@ discard block |
||
| 116 | 128 | |
| 117 | 129 | $field->post(); $post[$field->getKey()] = $field->getValue(); |
| 118 | 130 | |
| 119 | - if ($field->error) $errors = true; |
|
| 131 | + if ($field->error) { |
|
| 132 | + $errors = true; |
|
| 133 | + } |
|
| 120 | 134 | } |
| 121 | 135 | |
| 122 | 136 | $this->posted = true; $this->errors = $errors; |