@@ -2,7 +2,10 @@ |
||
2 | 2 | |
3 | 3 | namespace System\Utils { |
4 | 4 | |
5 | - use System\Utils\Messages, Explorer, Language, Request; |
|
5 | + use System\Utils\Messages; |
|
6 | + use Explorer; |
|
7 | + use Language; |
|
8 | + use Request; |
|
6 | 9 | |
7 | 10 | abstract class Uploader { |
8 | 11 |
@@ -10,19 +10,33 @@ discard block |
||
10 | 10 | |
11 | 11 | private static function translateError(int $error) { |
12 | 12 | |
13 | - if ($error === UPLOAD_ERR_INI_SIZE) return 'UPLOADER_ERROR_INI_SIZE'; |
|
13 | + if ($error === UPLOAD_ERR_INI_SIZE) { |
|
14 | + return 'UPLOADER_ERROR_INI_SIZE'; |
|
15 | + } |
|
14 | 16 | |
15 | - if ($error === UPLOAD_ERR_FORM_SIZE) return 'UPLOADER_ERROR_FORM_SIZE'; |
|
17 | + if ($error === UPLOAD_ERR_FORM_SIZE) { |
|
18 | + return 'UPLOADER_ERROR_FORM_SIZE'; |
|
19 | + } |
|
16 | 20 | |
17 | - if ($error === UPLOAD_ERR_PARTIAL) return 'UPLOADER_ERROR_PARTIAL'; |
|
21 | + if ($error === UPLOAD_ERR_PARTIAL) { |
|
22 | + return 'UPLOADER_ERROR_PARTIAL'; |
|
23 | + } |
|
18 | 24 | |
19 | - if ($error === UPLOAD_ERR_NO_FILE) return 'UPLOADER_ERROR_NO_FILE'; |
|
25 | + if ($error === UPLOAD_ERR_NO_FILE) { |
|
26 | + return 'UPLOADER_ERROR_NO_FILE'; |
|
27 | + } |
|
20 | 28 | |
21 | - if ($error === UPLOAD_ERR_NO_TMP_DIR) return 'UPLOADER_ERROR_NO_TMP_DIR'; |
|
29 | + if ($error === UPLOAD_ERR_NO_TMP_DIR) { |
|
30 | + return 'UPLOADER_ERROR_NO_TMP_DIR'; |
|
31 | + } |
|
22 | 32 | |
23 | - if ($error === UPLOAD_ERR_CANT_WRITE) return 'UPLOADER_ERROR_CANT_WRITE'; |
|
33 | + if ($error === UPLOAD_ERR_CANT_WRITE) { |
|
34 | + return 'UPLOADER_ERROR_CANT_WRITE'; |
|
35 | + } |
|
24 | 36 | |
25 | - if ($error === UPLOAD_ERR_EXTENSION) return 'UPLOADER_ERROR_EXTENSION'; |
|
37 | + if ($error === UPLOAD_ERR_EXTENSION) { |
|
38 | + return 'UPLOADER_ERROR_EXTENSION'; |
|
39 | + } |
|
26 | 40 | |
27 | 41 | # ------------------------ |
28 | 42 | |
@@ -33,35 +47,49 @@ discard block |
||
33 | 47 | |
34 | 48 | public static function save(string $name, string $dir_name) { |
35 | 49 | |
36 | - if ((false === ($file = Request::file($name))) || !is_uploaded_file($file['tmp_name'])) return false; |
|
50 | + if ((false === ($file = Request::file($name))) || !is_uploaded_file($file['tmp_name'])) { |
|
51 | + return false; |
|
52 | + } |
|
37 | 53 | |
38 | 54 | # Check for upload errors |
39 | 55 | |
40 | - if ($file['error'] !== UPLOAD_ERR_OK) return self::translateError($file['error']); |
|
56 | + if ($file['error'] !== UPLOAD_ERR_OK) { |
|
57 | + return self::translateError($file['error']); |
|
58 | + } |
|
41 | 59 | |
42 | 60 | # Check size |
43 | 61 | |
44 | - if ($file['size'] > CONFIG_UPLOADS_MAX_SIZE) return 'UPLOADER_ERROR_SIZE'; |
|
62 | + if ($file['size'] > CONFIG_UPLOADS_MAX_SIZE) { |
|
63 | + return 'UPLOADER_ERROR_SIZE'; |
|
64 | + } |
|
45 | 65 | |
46 | 66 | # Check file extension |
47 | 67 | |
48 | 68 | $extensions = ['php', 'phtml', 'php3', 'php4', 'php5', 'phps']; |
49 | 69 | |
50 | - if (in_array(Explorer::extension($file['name'], false), $extensions)) return 'UPLOADER_ERROR_TYPE'; |
|
70 | + if (in_array(Explorer::extension($file['name'], false), $extensions)) { |
|
71 | + return 'UPLOADER_ERROR_TYPE'; |
|
72 | + } |
|
51 | 73 | |
52 | 74 | # Check target directory |
53 | 75 | |
54 | - if (!Explorer::isDir($dir_name)) return 'UPLOADER_ERROR_DIR'; |
|
76 | + if (!Explorer::isDir($dir_name)) { |
|
77 | + return 'UPLOADER_ERROR_DIR'; |
|
78 | + } |
|
55 | 79 | |
56 | 80 | # Check target file |
57 | 81 | |
58 | 82 | $file_name = ($dir_name . '/' . basename($file['name'])); |
59 | 83 | |
60 | - if (Explorer::isDir($file_name) || Explorer::isFile($file_name)) return 'UPLOADER_ERROR_EXISTS'; |
|
84 | + if (Explorer::isDir($file_name) || Explorer::isFile($file_name)) { |
|
85 | + return 'UPLOADER_ERROR_EXISTS'; |
|
86 | + } |
|
61 | 87 | |
62 | 88 | # Save uploaded file |
63 | 89 | |
64 | - if (!@move_uploaded_file($file['tmp_name'], $file_name)) return 'UPLOADER_ERROR_SAVE'; |
|
90 | + if (!@move_uploaded_file($file['tmp_name'], $file_name)) { |
|
91 | + return 'UPLOADER_ERROR_SAVE'; |
|
92 | + } |
|
65 | 93 | |
66 | 94 | # ------------------------ |
67 | 95 |
@@ -10,10 +10,10 @@ |
||
10 | 10 | |
11 | 11 | # Define constants |
12 | 12 | |
13 | -define('DIR_ENGINE', (dirname(__FILE__) . '/')); |
|
13 | +define('DIR_ENGINE', (dirname(__FILE__) . '/')); |
|
14 | 14 | |
15 | -define('DIR_WWW', (DIR_ENGINE . '../')); |
|
16 | -define('DIR_UPLOADS', (DIR_ENGINE . '../uploads/')); |
|
15 | +define('DIR_WWW', (DIR_ENGINE . '../')); |
|
16 | +define('DIR_UPLOADS', (DIR_ENGINE . '../uploads/')); |
|
17 | 17 | |
18 | 18 | # Require framework main file |
19 | 19 |
@@ -2,7 +2,9 @@ discard block |
||
2 | 2 | |
3 | 3 | # Check PHP version |
4 | 4 | |
5 | -if (version_compare(PHP_VERSION, '7.0.0') < 0) exit('PHP version 7 or higher is required.'); |
|
5 | +if (version_compare(PHP_VERSION, '7.0.0') < 0) { |
|
6 | + exit('PHP version 7 or higher is required.'); |
|
7 | +} |
|
6 | 8 | |
7 | 9 | # Set error reporting |
8 | 10 | |
@@ -31,23 +33,31 @@ discard block |
||
31 | 33 | |
32 | 34 | # Determine class path |
33 | 35 | |
34 | - if ($path[0] === 'System') $path = (DIR_SYSTEM_CLASSES . implode('/', array_slice($path, 1))); |
|
35 | - |
|
36 | - else if ($path[0] === 'Plugins') $path = (DIR_SYSTEM_PLUGINS . implode('/', array_slice($path, 1))); |
|
37 | - |
|
38 | - else $path = (DIR_CLASSES . implode('/', $path)); |
|
36 | + if ($path[0] === 'System') { |
|
37 | + $path = (DIR_SYSTEM_CLASSES . implode('/', array_slice($path, 1))); |
|
38 | + } else if ($path[0] === 'Plugins') { |
|
39 | + $path = (DIR_SYSTEM_PLUGINS . implode('/', array_slice($path, 1))); |
|
40 | + } else { |
|
41 | + $path = (DIR_CLASSES . implode('/', $path)); |
|
42 | + } |
|
39 | 43 | |
40 | 44 | # Require class file |
41 | 45 | |
42 | - if (@file_exists($file_name = ($path . '.php')) && @is_file($file_name)) require_once $file_name; |
|
43 | - |
|
44 | - else if (@file_exists($file_name = ($path . '/' . $last . '.php')) && @is_file($file_name)) require_once $file_name; |
|
46 | + if (@file_exists($file_name = ($path . '.php')) && @is_file($file_name)) { |
|
47 | + require_once $file_name; |
|
48 | + } else if (@file_exists($file_name = ($path . '/' . $last . '.php')) && @is_file($file_name)) { |
|
49 | + require_once $file_name; |
|
50 | + } |
|
45 | 51 | |
46 | 52 | # Check if class exists |
47 | 53 | |
48 | - if (!class_exists($class_name) && !interface_exists($class_name) && !trait_exists($class_name)) throw new Exception\ClassLoad($class_name); |
|
54 | + if (!class_exists($class_name) && !interface_exists($class_name) && !trait_exists($class_name)) { |
|
55 | + throw new Exception\ClassLoad($class_name); |
|
56 | + } |
|
49 | 57 | |
50 | 58 | # Call autoload method |
51 | 59 | |
52 | - if (method_exists($class_name, '__autoload')) $class_name::__autoload(); |
|
53 | -}); |
|
60 | + if (method_exists($class_name, '__autoload')) { |
|
61 | + $class_name::__autoload(); |
|
62 | + } |
|
63 | + }); |
@@ -2,14 +2,14 @@ |
||
2 | 2 | |
3 | 3 | # Define constants |
4 | 4 | |
5 | -define('DIR_SYSTEM', (dirname(__FILE__) . '/')); |
|
6 | - |
|
7 | -define('DIR_SYSTEM_CLASSES', (DIR_SYSTEM . 'Classes/')); |
|
8 | -define('DIR_SYSTEM_DATA', (DIR_SYSTEM . 'Data/')); |
|
9 | -define('DIR_SYSTEM_INCLUDES', (DIR_SYSTEM . 'Includes/')); |
|
10 | -define('DIR_SYSTEM_LANGUAGES', (DIR_SYSTEM . 'Languages/')); |
|
11 | -define('DIR_SYSTEM_PLUGINS', (DIR_SYSTEM . 'Plugins/')); |
|
12 | -define('DIR_SYSTEM_TEMPLATES', (DIR_SYSTEM . 'Templates/')); |
|
5 | +define('DIR_SYSTEM', (dirname(__FILE__) . '/')); |
|
6 | + |
|
7 | +define('DIR_SYSTEM_CLASSES', (DIR_SYSTEM . 'Classes/')); |
|
8 | +define('DIR_SYSTEM_DATA', (DIR_SYSTEM . 'Data/')); |
|
9 | +define('DIR_SYSTEM_INCLUDES', (DIR_SYSTEM . 'Includes/')); |
|
10 | +define('DIR_SYSTEM_LANGUAGES', (DIR_SYSTEM . 'Languages/')); |
|
11 | +define('DIR_SYSTEM_PLUGINS', (DIR_SYSTEM . 'Plugins/')); |
|
12 | +define('DIR_SYSTEM_TEMPLATES', (DIR_SYSTEM . 'Templates/')); |
|
13 | 13 | |
14 | 14 | # Require classes |
15 | 15 |
@@ -46,7 +46,9 @@ |
||
46 | 46 | |
47 | 47 | $system_file = (DIR_SYSTEM_DATA . 'System.json'); |
48 | 48 | |
49 | - if (false !== ($data = Explorer::json($system_file))) $this->parse($data); |
|
49 | + if (false !== ($data = Explorer::json($system_file))) { |
|
50 | + $this->parse($data); |
|
51 | + } |
|
50 | 52 | } |
51 | 53 | } |
52 | 54 | } |
@@ -33,7 +33,7 @@ |
||
33 | 33 | |
34 | 34 | $condition = ("parent_id = " . $parent_id . " AND visibility = " . VISIBILITY_PUBLISHED . " ") . |
35 | 35 | |
36 | - ("AND access <= " . $access . " AND name = '" . addslashes($name) . "'"); |
|
36 | + ("AND access <= " . $access . " AND name = '" . addslashes($name) . "'"); |
|
37 | 37 | |
38 | 38 | if (!(DB::select(TABLE_PAGES, $selection, $condition, null, 1) && (DB::last()->rows === 1))) return false; |
39 | 39 |
@@ -35,7 +35,9 @@ discard block |
||
35 | 35 | |
36 | 36 | ("AND access <= " . $access . " AND name = '" . addslashes($name) . "'"); |
37 | 37 | |
38 | - if (!(DB::select(TABLE_PAGES, $selection, $condition, null, 1) && (DB::last()->rows === 1))) return false; |
|
38 | + if (!(DB::select(TABLE_PAGES, $selection, $condition, null, 1) && (DB::last()->rows === 1))) { |
|
39 | + return false; |
|
40 | + } |
|
39 | 41 | |
40 | 42 | $path[] = $page(...array_values(DB::last()->row())); |
41 | 43 | } |
@@ -53,9 +55,11 @@ discard block |
||
53 | 55 | |
54 | 56 | # Set breadcrumbs |
55 | 57 | |
56 | - if (count($this->path) <= 1) $contents->block('breadcrumbs')->disable(); |
|
57 | - |
|
58 | - else $contents->block('breadcrumbs')->path = $this->path; |
|
58 | + if (count($this->path) <= 1) { |
|
59 | + $contents->block('breadcrumbs')->disable(); |
|
60 | + } else { |
|
61 | + $contents->block('breadcrumbs')->path = $this->path; |
|
62 | + } |
|
59 | 63 | |
60 | 64 | # Set contents |
61 | 65 | |
@@ -70,7 +74,9 @@ discard block |
||
70 | 74 | |
71 | 75 | protected function handle() { |
72 | 76 | |
73 | - if (false === ($path = $this->getPath())) return false; |
|
77 | + if (false === ($path = $this->getPath())) { |
|
78 | + return false; |
|
79 | + } |
|
74 | 80 | |
75 | 81 | $this->path = $path; |
76 | 82 | |
@@ -78,11 +84,17 @@ discard block |
||
78 | 84 | |
79 | 85 | $this->page = Entitizer::get(ENTITY_TYPE_PAGE, ($this->path ? end($this->path)['id'] : 1)); |
80 | 86 | |
81 | - if (0 === $this->page->id) return false; |
|
87 | + if (0 === $this->page->id) { |
|
88 | + return false; |
|
89 | + } |
|
82 | 90 | |
83 | 91 | # Set data |
84 | 92 | |
85 | - if ($this->page->id !== 1) $this->title = $this->page->title; else $this->layout = 'Index'; |
|
93 | + if ($this->page->id !== 1) { |
|
94 | + $this->title = $this->page->title; |
|
95 | + } else { |
|
96 | + $this->layout = 'Index'; |
|
97 | + } |
|
86 | 98 | |
87 | 99 | $this->description = $this->page->description; |
88 | 100 | $this->keywords = $this->page->keywords; |
@@ -12,7 +12,9 @@ discard block |
||
12 | 12 | |
13 | 13 | $selection = 'MAX(time_modified) as last_modified'; |
14 | 14 | |
15 | - if (!(DB::select(TABLE_PAGES, $selection) && (DB::last()->rows === 1))) return 0; |
|
15 | + if (!(DB::select(TABLE_PAGES, $selection) && (DB::last()->rows === 1))) { |
|
16 | + return 0; |
|
17 | + } |
|
16 | 18 | |
17 | 19 | # ------------------------ |
18 | 20 | |
@@ -29,9 +31,13 @@ discard block |
||
29 | 31 | |
30 | 32 | $condition = ['visibility' => VISIBILITY_PUBLISHED, 'access' => ACCESS_PUBLIC]; |
31 | 33 | |
32 | - if (!(DB::select(TABLE_PAGES, 'id', $condition) && DB::last()->status)) return []; |
|
34 | + if (!(DB::select(TABLE_PAGES, 'id', $condition) && DB::last()->status)) { |
|
35 | + return []; |
|
36 | + } |
|
33 | 37 | |
34 | - while (null !== ($page = DB::last()->row())) $pages[] = $page['id']; |
|
38 | + while (null !== ($page = DB::last()->row())) { |
|
39 | + $pages[] = $page['id']; |
|
40 | + } |
|
35 | 41 | |
36 | 42 | # Init pages |
37 | 43 | |
@@ -59,7 +65,9 @@ discard block |
||
59 | 65 | |
60 | 66 | $last_modified = $this->getLastModified(); |
61 | 67 | |
62 | - if ($sitemap->load($last_modified)) return $sitemap; |
|
68 | + if ($sitemap->load($last_modified)) { |
|
69 | + return $sitemap; |
|
70 | + } |
|
63 | 71 | |
64 | 72 | # Fill sitemap |
65 | 73 |
@@ -16,7 +16,7 @@ |
||
16 | 16 | |
17 | 17 | # Connect to database |
18 | 18 | |
19 | - DB::connect ( |
|
19 | + DB::connect( |
|
20 | 20 | |
21 | 21 | $this->database['server'], $this->database['user'], |
22 | 22 |
@@ -12,7 +12,9 @@ |
||
12 | 12 | |
13 | 13 | # Check installation |
14 | 14 | |
15 | - if (!$this->installed) Request::redirect(INSTALL_PATH . '/install.php'); |
|
15 | + if (!$this->installed) { |
|
16 | + Request::redirect(INSTALL_PATH . '/install.php'); |
|
17 | + } |
|
16 | 18 | |
17 | 19 | # Connect to database |
18 | 20 |
@@ -14,7 +14,9 @@ discard block |
||
14 | 14 | |
15 | 15 | $extensions = ['mysqli', 'mbstring', 'gd', 'simplexml']; |
16 | 16 | |
17 | - foreach ($extensions as $name) self::$requirements[$name] = extension_loaded($name); |
|
17 | + foreach ($extensions as $name) { |
|
18 | + self::$requirements[$name] = extension_loaded($name); |
|
19 | + } |
|
18 | 20 | |
19 | 21 | # Check mod_rewrite |
20 | 22 | |
@@ -24,7 +26,9 @@ discard block |
||
24 | 26 | |
25 | 27 | $writables = ['data' => DIR_SYSTEM_DATA, 'uploads' => DIR_UPLOADS]; |
26 | 28 | |
27 | - foreach ($writables as $name => $dir) self::$requirements[$name] = is_writable($dir); |
|
29 | + foreach ($writables as $name => $dir) { |
|
30 | + self::$requirements[$name] = is_writable($dir); |
|
31 | + } |
|
28 | 32 | |
29 | 33 | # Set checking status |
30 | 34 |
@@ -20,21 +20,19 @@ discard block |
||
20 | 20 | |
21 | 21 | # Connect to DB |
22 | 22 | |
23 | - try { DB::connect($server, $user, $password, $name); } |
|
24 | - |
|
25 | - catch (Exception\DBConnect $error) { return 'INSTALL_ERROR_DATABASE_CONNECT'; } |
|
26 | - |
|
27 | - catch (Exception\DBSelect $error) { return 'INSTALL_ERROR_DATABASE_SELECT'; } |
|
28 | - |
|
29 | - catch (Exception\DBCharset $error) { return 'INSTALL_ERROR_DATABASE_CHARSET'; } |
|
23 | + try { DB::connect($server, $user, $password, $name); } catch (Exception\DBConnect $error) { return 'INSTALL_ERROR_DATABASE_CONNECT'; } catch (Exception\DBSelect $error) { return 'INSTALL_ERROR_DATABASE_SELECT'; } catch (Exception\DBCharset $error) { return 'INSTALL_ERROR_DATABASE_CHARSET'; } |
|
30 | 24 | |
31 | 25 | # Create tables |
32 | 26 | |
33 | - if (!Install\Utils\Tables::create()) return 'INSTALL_ERROR_DATABASE_TABLES_CREATE'; |
|
27 | + if (!Install\Utils\Tables::create()) { |
|
28 | + return 'INSTALL_ERROR_DATABASE_TABLES_CREATE'; |
|
29 | + } |
|
34 | 30 | |
35 | 31 | # Fill tables |
36 | 32 | |
37 | - if (!Install\Utils\Tables::fill()) return 'INSTALL_ERROR_DATABASE_TABLES_FILL'; |
|
33 | + if (!Install\Utils\Tables::fill()) { |
|
34 | + return 'INSTALL_ERROR_DATABASE_TABLES_FILL'; |
|
35 | + } |
|
38 | 36 | |
39 | 37 | # Save system file |
40 | 38 | |
@@ -49,7 +47,9 @@ discard block |
||
49 | 47 | |
50 | 48 | $system_file = (DIR_SYSTEM_DATA . 'System.json'); $system = json_encode($system, JSON_PRETTY_PRINT); |
51 | 49 | |
52 | - if (false === Explorer::save($system_file, $system, true)) return 'INSTALL_ERROR_SYSTEM'; |
|
50 | + if (false === Explorer::save($system_file, $system, true)) { |
|
51 | + return 'INSTALL_ERROR_SYSTEM'; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | # ------------------------ |
55 | 55 |