@@ -23,15 +23,23 @@ discard block |
||
23 | 23 | |
24 | 24 | // Ignore error to avoid warning when trying to connect to unavailable host |
25 | 25 | |
26 | - if (false === ($link = @mysqli_connect($server, $user, $password))) throw new Exception\DBConnect; |
|
26 | + if (false === ($link = @mysqli_connect($server, $user, $password))) { |
|
27 | + throw new Exception\DBConnect; |
|
28 | + } |
|
27 | 29 | |
28 | 30 | # Set encoding |
29 | 31 | |
30 | - if (!mysqli_query($link, "SET character_set_client = 'utf8'")) throw new Exception\DBCharset; |
|
32 | + if (!mysqli_query($link, "SET character_set_client = 'utf8'")) { |
|
33 | + throw new Exception\DBCharset; |
|
34 | + } |
|
31 | 35 | |
32 | - if (!mysqli_query($link, "SET character_set_results = 'utf8'")) throw new Exception\DBCharset; |
|
36 | + if (!mysqli_query($link, "SET character_set_results = 'utf8'")) { |
|
37 | + throw new Exception\DBCharset; |
|
38 | + } |
|
33 | 39 | |
34 | - if (!mysqli_query($link, "SET collation_connection = 'utf8_general_ci'")) throw new Exception\DBCharset; |
|
40 | + if (!mysqli_query($link, "SET collation_connection = 'utf8_general_ci'")) { |
|
41 | + throw new Exception\DBCharset; |
|
42 | + } |
|
35 | 43 | |
36 | 44 | # ------------------------ |
37 | 45 | |
@@ -44,7 +52,9 @@ discard block |
||
44 | 52 | |
45 | 53 | public static function name(string $name) { |
46 | 54 | |
47 | - if (!mysqli_select_db(self::$link, $name)) throw new Exception\DBSelect; |
|
55 | + if (!mysqli_select_db(self::$link, $name)) { |
|
56 | + throw new Exception\DBSelect; |
|
57 | + } |
|
48 | 58 | } |
49 | 59 | |
50 | 60 | /** |
@@ -55,7 +65,9 @@ discard block |
||
55 | 65 | |
56 | 66 | public static function send(string $query) { |
57 | 67 | |
58 | - if (null === self::$link) return (self::$last = false); |
|
68 | + if (null === self::$link) { |
|
69 | + return (self::$last = false); |
|
70 | + } |
|
59 | 71 | |
60 | 72 | $time = microtime(true); $result = mysqli_query(self::$link, $query); $time = (microtime(true) - $time); |
61 | 73 |
@@ -10,13 +10,13 @@ discard block |
||
10 | 10 | |
11 | 11 | private static function parseContents(string $contents, Throwable $exc) : string { |
12 | 12 | |
13 | - $contents = str_replace('$message$', $exc->getMessage(), $contents); |
|
13 | + $contents = str_replace('$message$', $exc->getMessage(), $contents); |
|
14 | 14 | |
15 | - $contents = str_replace('$file$', $exc->getFile(), $contents); |
|
15 | + $contents = str_replace('$file$', $exc->getFile(), $contents); |
|
16 | 16 | |
17 | - $contents = str_replace('$line$', $exc->getLine(), $contents); |
|
17 | + $contents = str_replace('$line$', $exc->getLine(), $contents); |
|
18 | 18 | |
19 | - $contents = str_replace('$trace$', nl2br($exc->getTraceAsString()), $contents); |
|
19 | + $contents = str_replace('$trace$', nl2br($exc->getTraceAsString()), $contents); |
|
20 | 20 | |
21 | 21 | # ------------------------ |
22 | 22 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | # Load template |
56 | 56 | |
57 | - $file_name = (DIR_TEMPLATES . 'Exception.tpl'); |
|
57 | + $file_name = (DIR_TEMPLATES.'Exception.tpl'); |
|
58 | 58 | |
59 | 59 | if (false === ($contents = @file_get_contents($file_name))) $output = nl2br($exc); |
60 | 60 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | |
71 | 71 | header('Pragma: no-cache'); |
72 | 72 | |
73 | - header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500); |
|
73 | + header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error', true, 500); |
|
74 | 74 | |
75 | 75 | header('Content-type: text/html; charset=UTF-8'); |
76 | 76 |
@@ -29,17 +29,29 @@ discard block |
||
29 | 29 | |
30 | 30 | public static function getIP() : string { |
31 | 31 | |
32 | - if (!empty($_SERVER['HTTP_CLIENT_IP'])) return $_SERVER['HTTP_CLIENT_IP']; |
|
32 | + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { |
|
33 | + return $_SERVER['HTTP_CLIENT_IP']; |
|
34 | + } |
|
33 | 35 | |
34 | - if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) return $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
36 | + if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
37 | + return $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
38 | + } |
|
35 | 39 | |
36 | - if (!empty($_SERVER['HTTP_X_FORWARDED'])) return $_SERVER['HTTP_X_FORWARDED']; |
|
40 | + if (!empty($_SERVER['HTTP_X_FORWARDED'])) { |
|
41 | + return $_SERVER['HTTP_X_FORWARDED']; |
|
42 | + } |
|
37 | 43 | |
38 | - if (!empty($_SERVER['HTTP_FORWARDED_FOR'])) return $_SERVER['HTTP_FORWARDED_FOR']; |
|
44 | + if (!empty($_SERVER['HTTP_FORWARDED_FOR'])) { |
|
45 | + return $_SERVER['HTTP_FORWARDED_FOR']; |
|
46 | + } |
|
39 | 47 | |
40 | - if (!empty($_SERVER['HTTP_FORWARDED'])) return $_SERVER['HTTP_FORWARDED']; |
|
48 | + if (!empty($_SERVER['HTTP_FORWARDED'])) { |
|
49 | + return $_SERVER['HTTP_FORWARDED']; |
|
50 | + } |
|
41 | 51 | |
42 | - if (!empty($_SERVER['REMOTE_ADDR'])) return $_SERVER['REMOTE_ADDR']; |
|
52 | + if (!empty($_SERVER['REMOTE_ADDR'])) { |
|
53 | + return $_SERVER['REMOTE_ADDR']; |
|
54 | + } |
|
43 | 55 | |
44 | 56 | # ------------------------ |
45 | 57 | |
@@ -56,9 +68,11 @@ discard block |
||
56 | 68 | |
57 | 69 | $file_name = (DIR_TEMPLATES . 'Exception.tpl'); |
58 | 70 | |
59 | - if (false === ($contents = @file_get_contents($file_name))) $output = nl2br($exc); |
|
60 | - |
|
61 | - else $output = self::parseContents($contents, $exc); |
|
71 | + if (false === ($contents = @file_get_contents($file_name))) { |
|
72 | + $output = nl2br($exc); |
|
73 | + } else { |
|
74 | + $output = self::parseContents($contents, $exc); |
|
75 | + } |
|
62 | 76 | |
63 | 77 | # Set headers |
64 | 78 |
@@ -63,7 +63,7 @@ |
||
63 | 63 | |
64 | 64 | # Check target file |
65 | 65 | |
66 | - $base_name = basename($file['name']); $file_name = ($dir_name . '/' . $base_name); |
|
66 | + $base_name = basename($file['name']); $file_name = ($dir_name.'/'.$base_name); |
|
67 | 67 | |
68 | 68 | if (Explorer::isDir($file_name) || Explorer::isFile($file_name)) return 'UPLOADER_ERROR_EXISTS'; |
69 | 69 |
@@ -12,19 +12,33 @@ discard block |
||
12 | 12 | |
13 | 13 | private static function translateError(int $error) { |
14 | 14 | |
15 | - if ($error === UPLOAD_ERR_INI_SIZE) return 'UPLOADER_ERROR_INI_SIZE'; |
|
15 | + if ($error === UPLOAD_ERR_INI_SIZE) { |
|
16 | + return 'UPLOADER_ERROR_INI_SIZE'; |
|
17 | + } |
|
16 | 18 | |
17 | - if ($error === UPLOAD_ERR_FORM_SIZE) return 'UPLOADER_ERROR_FORM_SIZE'; |
|
19 | + if ($error === UPLOAD_ERR_FORM_SIZE) { |
|
20 | + return 'UPLOADER_ERROR_FORM_SIZE'; |
|
21 | + } |
|
18 | 22 | |
19 | - if ($error === UPLOAD_ERR_PARTIAL) return 'UPLOADER_ERROR_PARTIAL'; |
|
23 | + if ($error === UPLOAD_ERR_PARTIAL) { |
|
24 | + return 'UPLOADER_ERROR_PARTIAL'; |
|
25 | + } |
|
20 | 26 | |
21 | - if ($error === UPLOAD_ERR_NO_FILE) return 'UPLOADER_ERROR_NO_FILE'; |
|
27 | + if ($error === UPLOAD_ERR_NO_FILE) { |
|
28 | + return 'UPLOADER_ERROR_NO_FILE'; |
|
29 | + } |
|
22 | 30 | |
23 | - if ($error === UPLOAD_ERR_NO_TMP_DIR) return 'UPLOADER_ERROR_NO_TMP_DIR'; |
|
31 | + if ($error === UPLOAD_ERR_NO_TMP_DIR) { |
|
32 | + return 'UPLOADER_ERROR_NO_TMP_DIR'; |
|
33 | + } |
|
24 | 34 | |
25 | - if ($error === UPLOAD_ERR_CANT_WRITE) return 'UPLOADER_ERROR_CANT_WRITE'; |
|
35 | + if ($error === UPLOAD_ERR_CANT_WRITE) { |
|
36 | + return 'UPLOADER_ERROR_CANT_WRITE'; |
|
37 | + } |
|
26 | 38 | |
27 | - if ($error === UPLOAD_ERR_EXTENSION) return 'UPLOADER_ERROR_EXTENSION'; |
|
39 | + if ($error === UPLOAD_ERR_EXTENSION) { |
|
40 | + return 'UPLOADER_ERROR_EXTENSION'; |
|
41 | + } |
|
28 | 42 | |
29 | 43 | # ------------------------ |
30 | 44 | |
@@ -35,19 +49,27 @@ discard block |
||
35 | 49 | |
36 | 50 | public static function save(string $name, string $dir_name) { |
37 | 51 | |
38 | - if (false === ($file = Request::file($name))) return false; |
|
52 | + if (false === ($file = Request::file($name))) { |
|
53 | + return false; |
|
54 | + } |
|
39 | 55 | |
40 | 56 | # Check for upload errors |
41 | 57 | |
42 | - if ($file['error'] !== UPLOAD_ERR_OK) return self::translateError($file['error']); |
|
58 | + if ($file['error'] !== UPLOAD_ERR_OK) { |
|
59 | + return self::translateError($file['error']); |
|
60 | + } |
|
43 | 61 | |
44 | 62 | # Check for secure upload |
45 | 63 | |
46 | - if (!is_uploaded_file($file['tmp_name'])) return 'UPLOADER_ERROR_SECURITY'; |
|
64 | + if (!is_uploaded_file($file['tmp_name'])) { |
|
65 | + return 'UPLOADER_ERROR_SECURITY'; |
|
66 | + } |
|
47 | 67 | |
48 | 68 | # Check size |
49 | 69 | |
50 | - if ($file['size'] > CONFIG_UPLOADS_MAX_SIZE) return 'UPLOADER_ERROR_SIZE'; |
|
70 | + if ($file['size'] > CONFIG_UPLOADS_MAX_SIZE) { |
|
71 | + return 'UPLOADER_ERROR_SIZE'; |
|
72 | + } |
|
51 | 73 | |
52 | 74 | # Check file extension |
53 | 75 | |
@@ -55,21 +77,29 @@ discard block |
||
55 | 77 | |
56 | 78 | $extension = strtolower(Explorer::getExtension($file['name'], false)); |
57 | 79 | |
58 | - if (in_array($extension, $extensions, true)) return 'UPLOADER_ERROR_TYPE'; |
|
80 | + if (in_array($extension, $extensions, true)) { |
|
81 | + return 'UPLOADER_ERROR_TYPE'; |
|
82 | + } |
|
59 | 83 | |
60 | 84 | # Check target directory |
61 | 85 | |
62 | - if (!Explorer::isDir($dir_name) && !Explorer::createDir($dir_name)) return 'UPLOADER_ERROR_DIR'; |
|
86 | + if (!Explorer::isDir($dir_name) && !Explorer::createDir($dir_name)) { |
|
87 | + return 'UPLOADER_ERROR_DIR'; |
|
88 | + } |
|
63 | 89 | |
64 | 90 | # Check target file |
65 | 91 | |
66 | 92 | $base_name = basename($file['name']); $file_name = ($dir_name . '/' . $base_name); |
67 | 93 | |
68 | - if (Explorer::isDir($file_name) || Explorer::isFile($file_name)) return 'UPLOADER_ERROR_EXISTS'; |
|
94 | + if (Explorer::isDir($file_name) || Explorer::isFile($file_name)) { |
|
95 | + return 'UPLOADER_ERROR_EXISTS'; |
|
96 | + } |
|
69 | 97 | |
70 | 98 | # Save uploaded file |
71 | 99 | |
72 | - if (!@move_uploaded_file($file['tmp_name'], $file_name)) return 'UPLOADER_ERROR_SAVE'; |
|
100 | + if (!@move_uploaded_file($file['tmp_name'], $file_name)) { |
|
101 | + return 'UPLOADER_ERROR_SAVE'; |
|
102 | + } |
|
73 | 103 | |
74 | 104 | # Set upload data |
75 | 105 |
@@ -10,7 +10,9 @@ |
||
10 | 10 | |
11 | 11 | protected function handle() { |
12 | 12 | |
13 | - if (!Request::isAjax()) return false; |
|
13 | + if (!Request::isAjax()) { |
|
14 | + return false; |
|
15 | + } |
|
14 | 16 | |
15 | 17 | # Create response |
16 | 18 |
@@ -22,9 +22,9 @@ |
||
22 | 22 | |
23 | 23 | # Save uploaded file |
24 | 24 | |
25 | - if (true === ($upload = (Uploader::save('upload', (DIR_UPLOADS . $target_dir))))) { |
|
25 | + if (true === ($upload = (Uploader::save('upload', (DIR_UPLOADS.$target_dir))))) { |
|
26 | 26 | |
27 | - $name = Uploader::baseName(); $url = (INSTALL_PATH . '/uploads/' . $target_dir . $name); |
|
27 | + $name = Uploader::baseName(); $url = (INSTALL_PATH.'/uploads/'.$target_dir.$name); |
|
28 | 28 | |
29 | 29 | $ajax->set('name', $name)->set('url', $url); |
30 | 30 |
@@ -30,7 +30,9 @@ discard block |
||
30 | 30 | |
31 | 31 | public function set(string $name, $value) : Response { |
32 | 32 | |
33 | - if (!in_array($name, ['error', 'status'], true)) $this->data[$name] = $value; |
|
33 | + if (!in_array($name, ['error', 'status'], true)) { |
|
34 | + $this->data[$name] = $value; |
|
35 | + } |
|
34 | 36 | |
35 | 37 | return $this; |
36 | 38 | } |
@@ -43,7 +45,9 @@ discard block |
||
43 | 45 | |
44 | 46 | public function setArray(array $data) : Response { |
45 | 47 | |
46 | - foreach ($data as $name => $value) $this->set($name, $value); |
|
48 | + foreach ($data as $name => $value) { |
|
49 | + $this->set($name, $value); |
|
50 | + } |
|
47 | 51 | |
48 | 52 | return $this; |
49 | 53 | } |
@@ -104,7 +108,9 @@ discard block |
||
104 | 108 | |
105 | 109 | $data = ['status' => $this->status]; |
106 | 110 | |
107 | - if (null !== $this->error) $data['error'] = $this->error; |
|
111 | + if (null !== $this->error) { |
|
112 | + $data['error'] = $this->error; |
|
113 | + } |
|
108 | 114 | |
109 | 115 | # ------------------------ |
110 | 116 |
@@ -19,32 +19,32 @@ |
||
19 | 19 | |
20 | 20 | # Check basic types |
21 | 21 | |
22 | - if (is_string ($default)) return function (string $value) { return $value; }; |
|
22 | + if (is_string($default)) return function(string $value) { return $value; }; |
|
23 | 23 | |
24 | - if (is_bool ($default)) return function (bool $value) { return $value; }; |
|
24 | + if (is_bool($default)) return function(bool $value) { return $value; }; |
|
25 | 25 | |
26 | - if (is_int ($default)) return function (int $value) { return $value; }; |
|
26 | + if (is_int($default)) return function(int $value) { return $value; }; |
|
27 | 27 | |
28 | - if (is_float ($default)) return function (float $value) { return $value; }; |
|
28 | + if (is_float($default)) return function(float $value) { return $value; }; |
|
29 | 29 | |
30 | - if (is_array ($default)) return function (array $value) { return $value; }; |
|
30 | + if (is_array($default)) return function(array $value) { return $value; }; |
|
31 | 31 | |
32 | - if (is_callable ($default)) return function (callable $value) { return $value; }; |
|
32 | + if (is_callable($default)) return function(callable $value) { return $value; }; |
|
33 | 33 | |
34 | 34 | # Check object type |
35 | 35 | |
36 | - if (is_object($default)) return function ($value) use ($default) { |
|
36 | + if (is_object($default)) return function($value) use ($default) { |
|
37 | 37 | |
38 | 38 | return (is_a($value, get_class($default)) ? $value : null); |
39 | 39 | }; |
40 | 40 | |
41 | 41 | # Check resource type |
42 | 42 | |
43 | - if (is_resource($default)) return function ($value) { return (is_resource($value) ? $value : null); }; |
|
43 | + if (is_resource($default)) return function($value) { return (is_resource($value) ? $value : null); }; |
|
44 | 44 | |
45 | 45 | # ------------------------ |
46 | 46 | |
47 | - return function () { return null; }; |
|
47 | + return function() { return null; }; |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | } |
@@ -19,28 +19,51 @@ |
||
19 | 19 | |
20 | 20 | # Check basic types |
21 | 21 | |
22 | - if (is_string ($default)) return function (string $value) { return $value; }; |
|
22 | + if (is_string ($default)) { |
|
23 | + return function (string $value) { return $value; |
|
24 | + } |
|
25 | + }; |
|
23 | 26 | |
24 | - if (is_bool ($default)) return function (bool $value) { return $value; }; |
|
27 | + if (is_bool ($default)) { |
|
28 | + return function (bool $value) { return $value; |
|
29 | + } |
|
30 | + }; |
|
25 | 31 | |
26 | - if (is_int ($default)) return function (int $value) { return $value; }; |
|
32 | + if (is_int ($default)) { |
|
33 | + return function (int $value) { return $value; |
|
34 | + } |
|
35 | + }; |
|
27 | 36 | |
28 | - if (is_float ($default)) return function (float $value) { return $value; }; |
|
37 | + if (is_float ($default)) { |
|
38 | + return function (float $value) { return $value; |
|
39 | + } |
|
40 | + }; |
|
29 | 41 | |
30 | - if (is_array ($default)) return function (array $value) { return $value; }; |
|
42 | + if (is_array ($default)) { |
|
43 | + return function (array $value) { return $value; |
|
44 | + } |
|
45 | + }; |
|
31 | 46 | |
32 | - if (is_callable ($default)) return function (callable $value) { return $value; }; |
|
47 | + if (is_callable ($default)) { |
|
48 | + return function (callable $value) { return $value; |
|
49 | + } |
|
50 | + }; |
|
33 | 51 | |
34 | 52 | # Check object type |
35 | 53 | |
36 | - if (is_object($default)) return function ($value) use ($default) { |
|
54 | + if (is_object($default)) { |
|
55 | + return function ($value) use ($default) { |
|
37 | 56 | |
38 | 57 | return (is_a($value, get_class($default)) ? $value : null); |
58 | + } |
|
39 | 59 | }; |
40 | 60 | |
41 | 61 | # Check resource type |
42 | 62 | |
43 | - if (is_resource($default)) return function ($value) { return (is_resource($value) ? $value : null); }; |
|
63 | + if (is_resource($default)) { |
|
64 | + return function ($value) { return (is_resource($value) ? $value : null); |
|
65 | + } |
|
66 | + }; |
|
44 | 67 | |
45 | 68 | # ------------------------ |
46 | 69 |
@@ -10,7 +10,7 @@ |
||
10 | 10 | |
11 | 11 | protected static $loader_class = 'Modules\Extend\Loader\Templates', $exception_class = 'Exception\Template'; |
12 | 12 | |
13 | - protected static $root_dir = [SECTION_SITE => DIR_SYSTEM_TEMPLATES . 'Site/', SECTION_ADMIN => DIR_SYSTEM_TEMPLATES . 'Admin/']; |
|
13 | + protected static $root_dir = [SECTION_SITE => DIR_SYSTEM_TEMPLATES.'Site/', SECTION_ADMIN => DIR_SYSTEM_TEMPLATES.'Admin/']; |
|
14 | 14 | |
15 | 15 | protected static $schema_prototype = 'Prototype\Template', $regex_name = REGEX_TEMPLATE_NAME; |
16 | 16 |
@@ -32,9 +32,13 @@ discard block |
||
32 | 32 | |
33 | 33 | $param = static::$param[$this->loader->section()]; $name = Request::post('name'); |
34 | 34 | |
35 | - if (false === Settings::set($param, $name)) return $ajax->setError(Language::get(static::$error_activate)); |
|
35 | + if (false === Settings::set($param, $name)) { |
|
36 | + return $ajax->setError(Language::get(static::$error_activate)); |
|
37 | + } |
|
36 | 38 | |
37 | - if (false === Settings::save()) return $ajax->setError(Language::get(static::$error_save)); |
|
39 | + if (false === Settings::save()) { |
|
40 | + return $ajax->setError(Language::get(static::$error_save)); |
|
41 | + } |
|
38 | 42 | |
39 | 43 | } else if (Request::post('action') === 'list') { |
40 | 44 | |
@@ -52,7 +56,9 @@ discard block |
||
52 | 56 | |
53 | 57 | $this->loader = new static::$loader_class(Request::get('list')); |
54 | 58 | |
55 | - if ($ajax) return $this->handleAjax(); |
|
59 | + if ($ajax) { |
|
60 | + return $this->handleAjax(); |
|
61 | + } |
|
56 | 62 | |
57 | 63 | # ------------------------ |
58 | 64 |
@@ -35,13 +35,17 @@ discard block |
||
35 | 35 | |
36 | 36 | $name = Request::post('name'); |
37 | 37 | |
38 | - if (!$this->loader->install($name, true)) return $ajax->setError(Language::get(static::$error_install)); |
|
38 | + if (!$this->loader->install($name, true)) { |
|
39 | + return $ajax->setError(Language::get(static::$error_install)); |
|
40 | + } |
|
39 | 41 | |
40 | 42 | } else if (Request::post('action') === 'uninstall') { |
41 | 43 | |
42 | 44 | $name = Request::post('name'); |
43 | 45 | |
44 | - if (!$this->loader->install($name, false)) return $ajax->setError(Language::get(static::$error_uninstall)); |
|
46 | + if (!$this->loader->install($name, false)) { |
|
47 | + return $ajax->setError(Language::get(static::$error_uninstall)); |
|
48 | + } |
|
45 | 49 | } |
46 | 50 | |
47 | 51 | # ------------------------ |
@@ -55,7 +59,9 @@ discard block |
||
55 | 59 | |
56 | 60 | $this->loader = new static::$loader_class; |
57 | 61 | |
58 | - if ($ajax) return $this->handleAjax(); |
|
62 | + if ($ajax) { |
|
63 | + return $this->handleAjax(); |
|
64 | + } |
|
59 | 65 | |
60 | 66 | # ------------------------ |
61 | 67 |