diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
new file mode 100644
index 0000000..660f23d
--- /dev/null
+++ b/.idea/dataSources.xml
@@ -0,0 +1,12 @@
+
+
+
+
+ mysql.8
+ true
+ com.mysql.cj.jdbc.Driver
+ jdbc:mysql://its-dev.site:3306/delta_core
+ $ProjectFileDir$
+
+
+
\ No newline at end of file
diff --git a/.idea/delta-project.iml b/.idea/delta-project.iml
new file mode 100644
index 0000000..c956989
--- /dev/null
+++ b/.idea/delta-project.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/deployment.xml b/.idea/deployment.xml
new file mode 100644
index 0000000..c6bcd82
--- /dev/null
+++ b/.idea/deployment.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..af519c4
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/php.xml b/.idea/php.xml
new file mode 100644
index 0000000..7341688
--- /dev/null
+++ b/.idea/php.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml
new file mode 100644
index 0000000..40faa6d
--- /dev/null
+++ b/.idea/sqldialects.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/webServers.xml b/.idea/webServers.xml
new file mode 100644
index 0000000..7bb19cc
--- /dev/null
+++ b/.idea/webServers.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/core/SQL_DUMPS/users.sql b/core/SQL_DUMPS/users.sql
new file mode 100644
index 0000000..bc29f75
--- /dev/null
+++ b/core/SQL_DUMPS/users.sql
@@ -0,0 +1,24 @@
+CREATE TABLE `users` (
+ `id` int(11) NOT NULL,
+ `login` varchar(100) NOT NULL,
+ `password` varchar(100) NOT NULL,
+ `access_level` varchar(100) NOT NULL,
+ `name` varchar(150) NOT NULL,
+ `email` text,
+ `image` varchar(255) NOT NULL,
+ `token` text,
+ `last_active` varchar(100) NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
+INSERT INTO `users` (`id`, `login`, `password`, `access_level`, `name`, `email`, `image`, `token`, `last_active`)
+VALUES
+ (1, 'admin', '5321ef98bd96cccf03f50979fdd8c893', 'admin', 'Роман Гринько', 'rsgrinko@yandex.ru', 'https://avatars.githubusercontent.com/u/38320330?s=150', 'RG17DE-1000-26FC-837F-8F9C47E643960', '1649970260'),
+ (2, 'a.kirilcev', 'c7e82c3d2bed998ea1f4c1aca09c282b', 'admin', 'Александр Кирильцев', 'a.kirilcev@it-tula.ru', 'https://i.pinimg.com/736x/36/3a/65/363a65ba6f997b11904654d0531a8166.jpg', 'RG17DE-1000-26FC-837F-8F9C47E643970', '1649505403'),
+ (3, 'system', '', 'admin', 'Система', 'info@it-stories.ru', '/uploads/users/system.jpg', 'RG17DE-1000-2702-816F-97E3877DD6650', '1');
+
+ALTER TABLE `users`
+ ADD PRIMARY KEY (`id`);
+
+ALTER TABLE `users`
+ MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=25;
+COMMIT;
\ No newline at end of file
diff --git a/core/bootstrap.php b/core/bootstrap.php
index 37a80f8..b230840 100644
--- a/core/bootstrap.php
+++ b/core/bootstrap.php
@@ -1,4 +1,14 @@
0) {
+ ++$i;
+ $size /= 1024;
+ }
+
+ $size = str_replace('.', ',', round($size, 1));
+ switch ($i) {
+ case 0:
+ return $size .= ' байт';
+ case 1:
+ return $size .= ' КБ';
+ case 2:
+ return $size .= ' МБ';
+ }
+ return '';
+ }
+
+
+ /**
+ * Получение ОС клиента
+ *
+ * @return string
+ */
+ public static function getOS(): string
+ {
+ $userAgent = $_SERVER['HTTP_USER_AGENT'];
+ $oses = [
+ 'iOS' => '/(iPhone)|(iPad)/i',
+ 'Windows 3.11' => '/Win16/i',
+ 'Windows 95' => '/(Windows 95)|(Win95)|(Windows_95)/i',
+ 'Windows 98' => '/(Windows 98)|(Win98)/i',
+ 'Windows 2000' => '/(Windows NT 5.0)|(Windows 2000)/i',
+ 'Windows XP' => '/(Windows NT 5.1)|(Windows XP)/i',
+ 'Windows 2003' => '/(Windows NT 5.2)/i',
+ 'Windows Vista' => '/(Windows NT 6.0)|(Windows Vista)/i',
+ 'Windows 7' => '/(Windows NT 6.1)|(Windows 7)/i',
+ 'Windows 8' => '/(Windows NT 6.2)|(Windows 8)/i',
+ 'Windows 8.1' => '/(Windows NT 6.3)|(Windows 8.1)/i',
+ 'Windows 10' => '/(Windows NT 10.0)|(Windows 10)/i',
+ 'Windows NT 4.0' => '/(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)/i',
+ 'Windows ME' => '/Windows ME/i',
+ 'Open BSD' => '/OpenBSD/i',
+ 'Sun OS' => '/SunOS/i',
+ 'Android' => '/Android/i',
+ 'Linux' => '/(Linux)|(X11)/i',
+ 'Macintosh' => '/(Mac_PowerPC)|(Macintosh)/i',
+ 'QNX' => '/QNX/i',
+ 'BeOS' => '/BeOS/i',
+ 'OS/2' => '/OS/2/i',
+ 'Search Bot' => '/(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp/cat)|(msnbot)|(ia_archiver)/i',
+ ];
+
+ foreach ($oses as $os => $pattern) {
+ if (preg_match($pattern, $userAgent)) {
+ return $os;
+ }
+ }
+ return 'Unknown OS';
+ }
+
+ /**
+ * Генерация GUID
+ */
+ public static function generateGUID(): string
+ {
+ $uid = dechex(microtime(true) * 1000) . bin2hex(random_bytes(8));
+ $guid = vsprintf('DLT%s-1000-%s-8%.3s-%s%s%s0', str_split($uid, 4));
+ return strtoupper($guid);
+ }
+
+ /**
+ * Генерация пароля
+ *
+ * @param int $number Количество символов в пароле
+ * @param bool $useSpecialChars Использовать ли спецсимволы
+ *
+ * @return string
+ */
+ public static function generatePassword(int $number = 10, bool $useSpecialChars = true): string
+ {
+ $number = ($number > 0) ? $number : 1;
+
+ $arChars = [
+ 'a', 'b', 'c', 'd', 'e', 'f',
+ 'g', 'h', 'i', 'j', 'k', 'l',
+ 'm', 'n', 'o', 'p', 'r', 's',
+ 't', 'u', 'v', 'x', 'y', 'z',
+ 'A', 'B', 'C', 'D', 'E', 'F',
+ 'G', 'H', 'I', 'J', 'K', 'L',
+ 'M', 'N', 'O', 'P', 'R', 'S',
+ 'T', 'U', 'V', 'X', 'Y', 'Z',
+ '1', '2', '3', '4', '5', '6',
+ '7', '8', '9', '0'];
+ $arSpecialChars = [
+ '(', ')', '[', ']', '!', '?',
+ '&', '^', '%', '@', '*', '$',
+ '<', '>', '/', '|', '+', '-',
+ '{', '}', '~'];
+
+ if ($useSpecialChars) {
+ $arChars = array_merge($arChars, $arSpecialChars);
+ }
+
+ $pass = '';
+ for ($i = 0; $i < $number; $i++) {
+ $index = rand(0, count($arChars) - 1);
+ $pass .= $arChars[$index];
+ }
+ return $pass;
+ }
+
+
+ /**
+ * Проверка UserAgent на бота
+ *
+ * @param string|null $userAgent User agent
+ * @return string|null
+ */
+ public static function isSearchBot(?string $userAgent): ?string
+ {
+ if (empty($userAgent)) {
+ return null;
+ }
+
+ $bots = [
+ // Yandex
+ 'YandexBot', 'YandexAccessibilityBot', 'YandexMobileBot', 'YandexDirectDyn', 'YandexScreenshotBot',
+ 'YandexImages', 'YandexVideo', 'YandexVideoParser', 'YandexMedia', 'YandexBlogs', 'YandexFavicons',
+ 'YandexWebmaster', 'YandexPagechecker', 'YandexImageResizer', 'YandexAdNet', 'YandexDirect',
+ 'YaDirectFetcher', 'YandexCalendar', 'YandexSitelinks', 'YandexMetrika', 'YandexNews',
+ 'YandexNewslinks', 'YandexCatalog', 'YandexAntivirus', 'YandexMarket', 'YandexVertis',
+ 'YandexForDomain', 'YandexSpravBot', 'YandexSearchShop', 'YandexMedianaBot', 'YandexOntoDB',
+ 'YandexOntoDBAPI', 'YandexTurbo', 'YandexVerticals',
+
+ // Google
+ 'Googlebot', 'Googlebot-Image', 'Mediapartners-Google', 'AdsBot-Google', 'APIs-Google',
+ 'AdsBot-Google-Mobile', 'AdsBot-Google-Mobile', 'Googlebot-News', 'Googlebot-Video',
+ 'AdsBot-Google-Mobile-Apps',
+
+ // Other
+ 'Mail.RU_Bot', 'bingbot', 'Accoona', 'ia_archiver', 'Ask Jeeves', 'OmniExplorer_Bot', 'W3C_Validator',
+ 'WebAlta', 'YahooFeedSeeker', 'Yahoo!', 'Ezooms', 'Tourlentabot', 'MJ12bot', 'AhrefsBot',
+ 'SearchBot', 'SiteStatus', 'Nigma.ru', 'Baiduspider', 'Statsbot', 'SISTRIX', 'AcoonBot', 'findlinks',
+ 'proximic', 'OpenindexSpider', 'statdom.ru', 'Exabot', 'Spider', 'SeznamBot', 'oBot', 'C-T bot',
+ 'Updownerbot', 'Snoopy', 'heritrix', 'Yeti', 'DomainVader', 'DCPbot', 'PaperLiBot', 'StackRambler',
+ 'msnbot', 'msnbot-media', 'msnbot-news',
+ ];
+
+ foreach ($bots as $bot) {
+ if (stripos($userAgent, $bot) !== false) {
+ return $bot;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Метод для склонения слов в зависимости от числа
+ * Пример: numWord($secs, array('секунда', 'секунды', 'секунд'))
+ *
+ * @param int $value Число
+ * @param array $words Массив слов
+ * @return string
+ */
+ public static function numWord(int $value, array $words): string
+ {
+ $num = $value % 100;
+ if ($num > 19) {
+ $num = $num % 10;
+ }
+
+ switch ($num) {
+ case 1:
+ $out = $words[0];
+ break;
+ case 2:
+ case 3:
+ case 4:
+ $out = $words[1];
+ break;
+ default:
+ $out = $words[2];
+ break;
+ }
+
+ return $out;
+ }
+
+
+ /**
+ * Преобразование количества секунд в строку с разбиением на дни, часы, минуты и секунды
+ *
+ * @param int $secs Секунды
+ * @return string
+ */
+ public static function secToString(int $secs): string
+ {
+ $res = '';
+
+ $days = floor($secs / 86400);
+ $secs = $secs % 86400;
+ if ($days > 0) {
+ $res .= $days . ' ' . self::numWord($days, ['день', 'дня', 'дней']) . ', ';
+ }
+
+ $hours = floor($secs / 3600);
+ $secs = $secs % 3600;
+ if ($hours > 0) {
+ $res .= $hours . ' ' . self::numWord($hours, ['час', 'часа', 'часов']) . ', ';
+ }
+
+ $minutes = floor($secs / 60);
+ $secs = $secs % 60;
+ if ($minutes > 0) {
+ $res .= $minutes . ' ' . self::numWord($minutes, ['минута', 'минуты', 'минут']) . ', ';
+ }
+
+ $res .= $secs . ' ' . self::numWord($secs, ['секунда', 'секунды', 'секунд']);
+
+ return $res;
+ }
+
+ /**
+ * Удаление GET параметров из строки URL
+ * @param string|null $url URL
+ * @return string|string[]|null
+ */
+ public static function getBaseUrl(?string $url = null): ?string
+ {
+ return !empty($url) ? preg_replace('/^([^?]+)(\?.*?)?(#.*)?$/', '$1$3', $url) : null;
+ }
+
+ /**
+ * Транслитерация строки
+ *
+ * @param string|null $text Строка для преобразования
+ * @param bool $noUseSpace Использование режима "для ЧПУ"
+ *
+ * @return string|null
+ */
+ public static function transliterate(?string $text, bool $noUseSpace = false): ?string
+ {
+ if (empty($text)) {
+ return null;
+ }
+
+ $converter = [
+ 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd',
+ 'е' => 'e', 'ё' => 'e', 'ж' => 'zh', 'з' => 'z', 'и' => 'i',
+ 'й' => 'y', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n',
+ 'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't',
+ 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c', 'ч' => 'ch',
+ 'ш' => 'sh', 'щ' => 'sch', 'ь' => '', 'ы' => 'y', 'ъ' => '',
+ 'э' => 'e', 'ю' => 'yu', 'я' => 'ya',
+
+ 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D',
+ 'Е' => 'E', 'Ё' => 'E', 'Ж' => 'Zh', 'З' => 'Z', 'И' => 'I',
+ 'Й' => 'Y', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N',
+ 'О' => 'O', 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T',
+ 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', 'Ч' => 'Ch',
+ 'Ш' => 'Sh', 'Щ' => 'Sch', 'Ь' => '', 'Ы' => 'Y', 'Ъ' => '',
+ 'Э' => 'E', 'Ю' => 'Yu', 'Я' => 'Ya',
+ ];
+
+ $result = strtr($text, $converter);
+
+ if ($noUseSpace) {
+ $result = mb_strtolower($result);
+ $result = mb_ereg_replace('[^-0-9a-z]', '-', $result);
+ $result = mb_ereg_replace('[-]+', '-', $result);
+ $result = trim($result, '-');
+ }
+ return $result;
+ }
+
+
+ /**
+ * Построение структурной таблицы из массива
+ *
+ * @param array|string|null $var Массив
+ * @param string $title Заголовок
+ *
+ * @return string|null
+ */
+ public static function arrayToTable($var, string $title = ''): ?string
+ {
+ if (is_array($var)) {
+ $table = '
';
+ if ($title) {
+ $table .= '| ' . $title . ' |
';
+ }
+ foreach ($var as $k => $v) {
+ $table .= '';
+ $table .= '| ' . htmlspecialchars($k) . ' | ';
+ $table .= '';
+ if (is_array($v)) {
+ $table .= self::arrayToTable($v);
+ } else {
+ $table .= htmlspecialchars($v);
+ }
+ $table .= ' | ';
+ $table .= '
';
+ }
+ $table .= '
';
+ } else {
+ $table = $var;
+ }
+ return $table;
+ }
+ }
\ No newline at end of file
diff --git a/core/lib/Core/Models/DB.class.php b/core/lib/Core/Models/DB.class.php
index f4da58c..4b852ae 100644
--- a/core/lib/Core/Models/DB.class.php
+++ b/core/lib/Core/Models/DB.class.php
@@ -2,6 +2,7 @@
namespace Core\Models;
+
/**
* Класс для работы с базой данных
*
diff --git a/core/lib/Core/Models/User.class.php b/core/lib/Core/Models/User.class.php
index 1883cac..6d1aafb 100644
--- a/core/lib/Core/Models/User.class.php
+++ b/core/lib/Core/Models/User.class.php
@@ -4,7 +4,10 @@
*
* @author Roman Grinko
*/
-use Core\Models\DB;
+
+ namespace Core\Models;
+
+ use Core\Models\DB;
class User
{
@@ -33,7 +36,7 @@ use Core\Models\DB;
*
* @param string $table
*/
- public static function init( string $table = TABLE_PREFIX . 'users'): void
+ public static function init(string $table = TABLE_PREFIX . 'users'): void
{
self::$table = $table;
if (isset($_SESSION['authorize']) and $_SESSION['authorize'] == 'Y') {
@@ -181,18 +184,16 @@ use Core\Models\DB;
*/
public static function registration($login, $password, $email, $level = 'user', $name = '', $image = ''): void
{
- (DB::getInstance())->addItem(self::$table,
- [
- 'login' => $login,
- 'password' => md5(self::$cryptoSalt . $password),
- 'access_level' => $level,
- 'name' => $name,
- 'image' => $image,
- 'token' => '',
- 'email' => $email,
- 'last_active' => time(),
- ]
- );
+ (DB::getInstance())->addItem(self::$table, [
+ 'login' => $login,
+ 'password' => md5(self::$cryptoSalt . $password),
+ 'access_level' => $level,
+ 'name' => $name,
+ 'image' => $image,
+ 'token' => '',
+ 'email' => $email,
+ 'last_active' => time(),
+ ]);
$result = (DB::getInstance())->getItem(self::$table, ['login' => $login, 'password' => $password]);
self::$id = $result['id'];
diff --git a/index.php b/index.php
index 00e9aa6..cfae448 100644
--- a/index.php
+++ b/index.php
@@ -1,7 +1,12 @@