@@ -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 | } |
@@ -21,19 +21,29 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | # Establish connection |
| 23 | 23 | |
| 24 | - if (false === ($link = mysqli_connect($server, $user, $password))) throw new Exception\DBConnect(); |
|
| 24 | + if (false === ($link = mysqli_connect($server, $user, $password))) { |
|
| 25 | + throw new Exception\DBConnect(); |
|
| 26 | + } |
|
| 25 | 27 | |
| 26 | 28 | # Select database |
| 27 | 29 | |
| 28 | - if (!mysqli_select_db($link, $name)) throw new Exception\DBSelect(); |
|
| 30 | + if (!mysqli_select_db($link, $name)) { |
|
| 31 | + throw new Exception\DBSelect(); |
|
| 32 | + } |
|
| 29 | 33 | |
| 30 | 34 | # Set encoding |
| 31 | 35 | |
| 32 | - if (!mysqli_query($link, "SET character_set_client = 'utf8'")) throw new Exception\DBCharset(); |
|
| 36 | + if (!mysqli_query($link, "SET character_set_client = 'utf8'")) { |
|
| 37 | + throw new Exception\DBCharset(); |
|
| 38 | + } |
|
| 33 | 39 | |
| 34 | - if (!mysqli_query($link, "SET character_set_results = 'utf8'")) throw new Exception\DBCharset(); |
|
| 40 | + if (!mysqli_query($link, "SET character_set_results = 'utf8'")) { |
|
| 41 | + throw new Exception\DBCharset(); |
|
| 42 | + } |
|
| 35 | 43 | |
| 36 | - if (!mysqli_query($link, "SET collation_connection = 'utf8_general_ci'")) throw new Exception\DBCharset(); |
|
| 44 | + if (!mysqli_query($link, "SET collation_connection = 'utf8_general_ci'")) { |
|
| 45 | + throw new Exception\DBCharset(); |
|
| 46 | + } |
|
| 37 | 47 | |
| 38 | 48 | # ------------------------ |
| 39 | 49 | |
@@ -48,7 +58,9 @@ discard block |
||
| 48 | 58 | |
| 49 | 59 | public static function send(string $query) { |
| 50 | 60 | |
| 51 | - if (null === self::$link) return (self::$last = false); |
|
| 61 | + if (null === self::$link) { |
|
| 62 | + return (self::$last = false); |
|
| 63 | + } |
|
| 52 | 64 | |
| 53 | 65 | $time = microtime(true); $result = mysqli_query(self::$link, $query); $time = (microtime(true) - $time); |
| 54 | 66 | |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | |
| 18 | 18 | protected function getValue(string $value) { |
| 19 | 19 | |
| 20 | - return ('\'' . addslashes($value) . '\''); |
|
| 20 | + return ('\''.addslashes($value).'\''); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | # Get field sort |
@@ -31,7 +31,9 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | protected function getString($source = null, string $pattern = '', string $separator = '') { |
| 33 | 33 | |
| 34 | - if (!is_array($source)) return (is_scalar($source) ? strval($source) : ''); |
|
| 34 | + if (!is_array($source)) { |
|
| 35 | + return (is_scalar($source) ? strval($source) : ''); |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | $regexs = ['key' => '/\^([a-z]+)/', 'value' => '/\$([a-z]+)/']; $matches = ['key' => [], 'value' => []]; |
| 37 | 39 | |
@@ -39,18 +41,25 @@ discard block |
||
| 39 | 41 | |
| 40 | 42 | # Parse pattern |
| 41 | 43 | |
| 42 | - foreach ($regexs as $name => $regex) preg_match($regex, $pattern, $matches[$name]); |
|
| 44 | + foreach ($regexs as $name => $regex) { |
|
| 45 | + preg_match($regex, $pattern, $matches[$name]); |
|
| 46 | + } |
|
| 43 | 47 | |
| 44 | 48 | # Process replacements |
| 45 | 49 | |
| 46 | - foreach ($source as $key => $value) if (is_scalar($value)) { |
|
| 50 | + foreach ($source as $key => $value) { |
|
| 51 | + if (is_scalar($value)) { |
|
| 47 | 52 | |
| 48 | - $output[$count] = $pattern; $item = &$output[$count++]; |
|
| 53 | + $output[$count] = $pattern; |
|
| 54 | + } |
|
| 55 | + $item = &$output[$count++]; |
|
| 49 | 56 | |
| 50 | - foreach ($matches as $name => $match) if (isset($match[1]) && isset($parsers[$match[1]])) { |
|
| 57 | + foreach ($matches as $name => $match) { |
|
| 58 | + if (isset($match[1]) && isset($parsers[$match[1]])) { |
|
| 51 | 59 | |
| 52 | 60 | $item = str_replace($match[0], [$this, $parsers[$match[1]]]($$name), $item); |
| 53 | 61 | } |
| 62 | + } |
|
| 54 | 63 | }; |
| 55 | 64 | |
| 56 | 65 | # ------------------------ |
@@ -56,7 +56,9 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | public function getRow() { |
| 58 | 58 | |
| 59 | - if (!is_object($this->result)) return null; |
|
| 59 | + if (!is_object($this->result)) { |
|
| 60 | + return null; |
|
| 61 | + } |
|
| 60 | 62 | |
| 61 | 63 | return mysqli_fetch_assoc($this->result); |
| 62 | 64 | } |
@@ -67,9 +69,13 @@ discard block |
||
| 67 | 69 | |
| 68 | 70 | public function getRows() { |
| 69 | 71 | |
| 70 | - if (!is_object($this->result)) return []; |
|
| 72 | + if (!is_object($this->result)) { |
|
| 73 | + return []; |
|
| 74 | + } |
|
| 71 | 75 | |
| 72 | - $rows = []; while (null !== ($row = $this->getRow())) $rows[] = $row; |
|
| 76 | + $rows = []; while (null !== ($row = $this->getRow())) { |
|
| 77 | + $rows[] = $row; |
|
| 78 | + } |
|
| 73 | 79 | |
| 74 | 80 | # ------------------------ |
| 75 | 81 | |
@@ -36,7 +36,9 @@ |
||
| 36 | 36 | |
| 37 | 37 | public function addItems(array $items) { |
| 38 | 38 | |
| 39 | - foreach ($items as $item) if (is_array($item)) $this->addItem($item); |
|
| 39 | + foreach ($items as $item) { |
|
| 40 | + if (is_array($item)) $this->addItem($item); |
|
| 41 | + } |
|
| 40 | 42 | |
| 41 | 43 | return $this; |
| 42 | 44 | } |
@@ -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 |
@@ -31,15 +31,19 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | $type = $matches[2][$key]; $name = $matches[3][$key]; $contents = ($matches[4][$key] ?? ''); |
| 33 | 33 | |
| 34 | - if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) continue; |
|
| 34 | + if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) { |
|
| 35 | + continue; |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | $this->contents = str_replace($match, ('{ ' . $type . ':' . $name . ' / }'), $this->contents); |
| 37 | 39 | |
| 38 | - if ($type === 'block') $this->blocks[$name] = (new Block($contents))->$toggle(); |
|
| 39 | - |
|
| 40 | - else if ($type === 'for') $this->loops[$name] = new Loop($contents); |
|
| 41 | - |
|
| 42 | - else if ($type === 'widget') $this->widgets[] = $name; |
|
| 40 | + if ($type === 'block') { |
|
| 41 | + $this->blocks[$name] = (new Block($contents))->$toggle(); |
|
| 42 | + } else if ($type === 'for') { |
|
| 43 | + $this->loops[$name] = new Loop($contents); |
|
| 44 | + } else if ($type === 'widget') { |
|
| 45 | + $this->widgets[] = $name; |
|
| 46 | + } |
|
| 43 | 47 | } |
| 44 | 48 | } |
| 45 | 49 | |
@@ -59,7 +63,9 @@ discard block |
||
| 59 | 63 | |
| 60 | 64 | foreach ($matches[1] as $index => $name) { |
| 61 | 65 | |
| 62 | - if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) continue; |
|
| 66 | + if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) { |
|
| 67 | + continue; |
|
| 68 | + } |
|
| 63 | 69 | |
| 64 | 70 | $elementaries['stack'][$name] = false; |
| 65 | 71 | } |
@@ -143,11 +149,17 @@ discard block |
||
| 143 | 149 | |
| 144 | 150 | public function __clone() { |
| 145 | 151 | |
| 146 | - foreach ($this->blocks as $name => $block) $this->blocks[$name] = clone $block; |
|
| 152 | + foreach ($this->blocks as $name => $block) { |
|
| 153 | + $this->blocks[$name] = clone $block; |
|
| 154 | + } |
|
| 147 | 155 | |
| 148 | - foreach ($this->loops as $name => $loop) $this->loops[$name] = clone $loop; |
|
| 156 | + foreach ($this->loops as $name => $loop) { |
|
| 157 | + $this->loops[$name] = clone $loop; |
|
| 158 | + } |
|
| 149 | 159 | |
| 150 | - foreach ($this->items as $name => $item) $this->items[$name] = clone $item; |
|
| 160 | + foreach ($this->items as $name => $item) { |
|
| 161 | + $this->items[$name] = clone $item; |
|
| 162 | + } |
|
| 151 | 163 | } |
| 152 | 164 | |
| 153 | 165 | /** |
@@ -158,11 +170,13 @@ discard block |
||
| 158 | 170 | |
| 159 | 171 | public function set(string $name, $value) : Block { |
| 160 | 172 | |
| 161 | - if ($value instanceof Block) $this->setBlock($name, $value); |
|
| 162 | - |
|
| 163 | - else if (is_array($value)) $this->setLoop($name, $value); |
|
| 164 | - |
|
| 165 | - else if (is_scalar($value)) $this->setVar($name, $value); |
|
| 173 | + if ($value instanceof Block) { |
|
| 174 | + $this->setBlock($name, $value); |
|
| 175 | + } else if (is_array($value)) { |
|
| 176 | + $this->setLoop($name, $value); |
|
| 177 | + } else if (is_scalar($value)) { |
|
| 178 | + $this->setVar($name, $value); |
|
| 179 | + } |
|
| 166 | 180 | |
| 167 | 181 | # ------------------------ |
| 168 | 182 | |
@@ -177,7 +191,9 @@ discard block |
||
| 177 | 191 | |
| 178 | 192 | public function setArray(array $components) : Block { |
| 179 | 193 | |
| 180 | - foreach ($components as $name => $component) $this->set($name, $component); |
|
| 194 | + foreach ($components as $name => $component) { |
|
| 195 | + $this->set($name, $component); |
|
| 196 | + } |
|
| 181 | 197 | |
| 182 | 198 | return $this; |
| 183 | 199 | } |
@@ -190,7 +206,9 @@ discard block |
||
| 190 | 206 | |
| 191 | 207 | public function setBlock(string $name, Block $block) : Block { |
| 192 | 208 | |
| 193 | - if (isset($this->blocks[$name])) $this->blocks[$name] = $block; |
|
| 209 | + if (isset($this->blocks[$name])) { |
|
| 210 | + $this->blocks[$name] = $block; |
|
| 211 | + } |
|
| 194 | 212 | |
| 195 | 213 | return $this; |
| 196 | 214 | } |
@@ -203,7 +221,9 @@ discard block |
||
| 203 | 221 | |
| 204 | 222 | public function setLoop(string $name, array $items) : Block { |
| 205 | 223 | |
| 206 | - if (isset($this->loops[$name])) $this->loops[$name]->setItems($items); |
|
| 224 | + if (isset($this->loops[$name])) { |
|
| 225 | + $this->loops[$name]->setItems($items); |
|
| 226 | + } |
|
| 207 | 227 | |
| 208 | 228 | return $this; |
| 209 | 229 | } |
@@ -216,7 +236,9 @@ discard block |
||
| 216 | 236 | |
| 217 | 237 | public function setVar(string $name, string $value) : Block { |
| 218 | 238 | |
| 219 | - if (isset($this->variables[$name])) $this->variables[$name] = $value; |
|
| 239 | + if (isset($this->variables[$name])) { |
|
| 240 | + $this->variables[$name] = $value; |
|
| 241 | + } |
|
| 220 | 242 | |
| 221 | 243 | return $this; |
| 222 | 244 | } |
@@ -298,7 +320,9 @@ discard block |
||
| 298 | 320 | |
| 299 | 321 | public function getContents() : string { |
| 300 | 322 | |
| 301 | - if (!$this->enabled) return ''; |
|
| 323 | + if (!$this->enabled) { |
|
| 324 | + return ''; |
|
| 325 | + } |
|
| 302 | 326 | |
| 303 | 327 | # Lock the block |
| 304 | 328 | |
@@ -9,7 +9,9 @@ |
||
| 9 | 9 | |
| 10 | 10 | namespace Template { |
| 11 | 11 | |
| 12 | - use Language, Str, Template; |
|
| 12 | + use Language; |
|
| 13 | + use Str; |
|
| 14 | + use Template; |
|
| 13 | 15 | |
| 14 | 16 | class Block extends Group { |
| 15 | 17 | |
@@ -19,7 +19,9 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | public static function start(string $name, int $lifetime) { |
| 21 | 21 | |
| 22 | - if (session_id()) return true; |
|
| 22 | + if (session_id()) { |
|
| 23 | + return true; |
|
| 24 | + } |
|
| 23 | 25 | |
| 24 | 26 | ini_set('session.gc_maxlifetime', $lifetime); |
| 25 | 27 | |
@@ -47,7 +49,9 @@ discard block |
||
| 47 | 49 | |
| 48 | 50 | public static function set(string $name, $value) { |
| 49 | 51 | |
| 50 | - if (session_id()) $_SESSION[$name] = $value; |
|
| 52 | + if (session_id()) { |
|
| 53 | + $_SESSION[$name] = $value; |
|
| 54 | + } |
|
| 51 | 55 | } |
| 52 | 56 | |
| 53 | 57 | /** |
@@ -76,7 +80,9 @@ discard block |
||
| 76 | 80 | |
| 77 | 81 | public static function delete(string $name) { |
| 78 | 82 | |
| 79 | - if (isset($_SESSION[$name])) unset($_SESSION[$name]); |
|
| 83 | + if (isset($_SESSION[$name])) { |
|
| 84 | + unset($_SESSION[$name]); |
|
| 85 | + } |
|
| 80 | 86 | } |
| 81 | 87 | } |
| 82 | 88 | } |
@@ -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 | |