diff --git a/core/lib/Core/Helpers/Files.class.php b/core/lib/Core/Helpers/Files.class.php new file mode 100644 index 0000000..e4c6385 --- /dev/null +++ b/core/lib/Core/Helpers/Files.class.php @@ -0,0 +1,173 @@ + 0) { + ++$i; + $size /= 1024; + } + + $size = round($size, 1); + switch ($i) { + case 0: + return $size .= ' байт'; + case 1: + return $size .= ' КБ'; + case 2: + return $size .= ' МБ'; + case 3: + return $size .= ' ГБ'; + case 4: + return $size .= ' ТБ'; + } + } + + /** + * Получить расширение файла + * + * @param string $filename + * + * @return string + */ + public static function getExt($filename) + { + return mb_strtolower(mb_substr(mb_strrchr($filename, '.'), 1)); + } + + /** + * Получить список файлов директории в виде массива + * То же самое делает функция scandir(), разница в том что у scandir() в массиве будут «.» и «..» и есть возможность сортировки.. + * + * @param string $path + * + * @return string + */ + public static function listFiles($path) + { + if ($path[mb_strlen($path) - 1] != '/') { + $path .= '/'; + } + + $files = []; + $dh = opendir($path); + while (false !== ($file = readdir($dh))) { + if ($file != '.' && $file != '..' && !is_dir($path . $file) && $file[0] != '.') { + $files[] = $file; + } + } + + closedir($dh); + return $files; + } + + /** + * Безопасное сохранение файла + * Если дерикторя не существует - пытается её создать. + * Если файл существует - к концу файла приписывает префикс. + * + * @param string $filename + * + * @return string + */ + public static function safeFile($filename) + { + $dir = dirname($filename); + if (!is_dir($dir)) { + mkdir($dir, 0777, true); + } + + $info = pathinfo($filename); + $name = $dir . '/' . $info['filename']; + $prefix = ''; + $ext = (empty($info['extension'])) ? '' : '.' . $info['extension']; + + if (is_file($name . $ext)) { + $i = 1; + $prefix = '_' . $i; + while (is_file($name . $prefix . $ext)) { + $prefix = '_' . ++$i; + } + } + + return $name . $prefix . $ext; + } + + /** + * Удаление каталога со всем содержимым + * + * @param string $dir + * + * @return void + */ + public static function removeDir($dir) + { + if ($objs = glob($dir . '/*')) { + foreach ($objs as $obj) { + is_dir($obj) ? self::removeDir($obj) : unlink($obj); + } + } + rmdir($dir); + } + + /** + * Удаление содержимого каталога + * + * @param string $dir + * + * @return void + */ + public static function clearDir($dir) + { + if ($objs = glob($dir . '/*')) { + foreach ($objs as $obj) { + is_dir($obj) ? self::removeDir($obj) : unlink($obj); + } + } + } + + /** + * Копирование директории с ее содержимым + * + * @param string $src + * @param string $drc + * + * @return void + */ + public static function copyDir($src, $drc) + { + $dir = opendir($src); + + if (!is_dir($drc)) { + mkdir($drc, 0777, true); + } + + while (false !== ($file = readdir($dir))) { + if ($file != '.' && $file != '..') { + if (is_dir($src . '/' . $file)) { + self::copyDir($src . '/' . $file, $drc . '/' . $file); + } else { + copy($src . '/' . $file, $drc . '/' . $file); + } + } + } + + closedir($dir); + } + } \ No newline at end of file diff --git a/core/lib/Core/Helpers/SystemFunctions.class.php b/core/lib/Core/Helpers/SystemFunctions.class.php index e7bc632..1604623 100644 --- a/core/lib/Core/Helpers/SystemFunctions.class.php +++ b/core/lib/Core/Helpers/SystemFunctions.class.php @@ -335,7 +335,7 @@ $tableStyle = 'border: 1px solid #7b9ea3;border-collapse: collapse;'; $tdBoldStyle = 'padding: 10px;border: 1px solid #7b9ea3;background: powderblue;font-weight: bold; text-align: center;color: #226770;text-shadow: #7b9ea3 0px 0px 2px;'; $tdStyle = 'padding: 10px;border: 1px solid #7b9ea3;'; - $thStyle = 'background: #b0e0e6;font-size: 1.3em;padding: 10px;background: linear-gradient(0deg, #b0e0e6, #90c1c7);color: #226770;text-shadow: #7b9ea3 1px 1px 0px;'; + $thStyle = 'text-align: center;font-size: 1.3em;padding: 10px;background: linear-gradient(0deg, #b0e0e6, #90c1c7);color: #226770;text-shadow: #7b9ea3 1px 1px 0px;'; if (is_array($var)) { $table = ''; if ($title) { diff --git a/index.php b/index.php index e88e4dc..b1fc00a 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ use Core\CoreException; use Core\ExternalServices\Telegram; use Core\Models\{User, DB}; - use Core\Helpers\{SystemFunctions, Cache, Log, Mail, Zip, Pagination}; + use Core\Helpers\{SystemFunctions, Cache, Log, Mail, Zip, Pagination, Files}; require_once $_SERVER['DOCUMENT_ROOT'] . '/core/bootstrap.php'; ?> @@ -68,7 +68,7 @@ //echo str_replace('
query('select count(*) as count from d_posts where post_type="post" and post_status="publish"')[0]['count']; -Pagination::execute($_REQUEST['page'], $count, 3); +Pagination::execute($_REQUEST['page'], $count, 2); $limit = Pagination::getLimit(); $arPosts = (DB::getInstance())->query('select * from d_posts where post_type="post" and post_status="publish" order by id desc limit ' . $limit); @@ -90,7 +90,9 @@ echo ''; echo str_replace('
- + + +
FAQs -

© 2021 Company, Inc

+ Использовано ОЗУ: ' + . round(memory_get_usage() / 1024 / 1024, 2) + . ' МБ / БД: ' + . round(DB::$workingTime, 3) + . ' сек (' + . DB::$quantity + . ' шт.) / Кэш: ' + . Files::convertBytes($cacheSize) + . ' / Генерация: ' + . $delta + . ' сек

'; + + ?> +

© Delta Project