Skip to content

Commit

Permalink
Fixed trim bug
Browse files Browse the repository at this point in the history
  • Loading branch information
juneszh committed Sep 21, 2022
1 parent 1abd3d2 commit 2a9989e
Show file tree
Hide file tree
Showing 7 changed files with 667 additions and 658 deletions.
1,131 changes: 570 additions & 561 deletions npm/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@tinymce/tinymce-react": "^4.2.0",
"antd": "^4.23.1",
"antd": "^4.23.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-resize-detector": "^7.1.2",
Expand Down
152 changes: 76 additions & 76 deletions src/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function url(string $url = '')
return $url;
} else {
$url = trim($url, '/');
return '/' . trim(AdminConfig::get('path'), '/') . ($url ? '/' . $url : '');
return '/' . AdminConfig::get('path') . ($url ? '/' . $url : '');
}
}

Expand Down Expand Up @@ -213,25 +213,25 @@ private static function createTable()
$db = Database::init();
$roleCreate = $db->create('admin_role', [
'id' => [
"TINYINT",
"UNSIGNED",
"NOT NULL",
"AUTO_INCREMENT",
'TINYINT',
'UNSIGNED',
'NOT NULL',
'AUTO_INCREMENT',
],
'name' => [
"VARCHAR(32)",
"NOT NULL",
"DEFAULT ''",
'VARCHAR(32)',
'NOT NULL',
'DEFAULT \'\'',
],
'create_time' => [
"TIMESTAMP",
"NOT NULL",
"DEFAULT CURRENT_TIMESTAMP",
'TIMESTAMP',
'NOT NULL',
'DEFAULT CURRENT_TIMESTAMP',
],
'PRIMARY KEY (<id>)',
], [
"ENGINE" => "InnoDB",
"DEFAULT CHARSET" => "utf8mb4",
'ENGINE' => 'InnoDB',
'DEFAULT CHARSET' => 'utf8mb4',
]);

if ($roleCreate) {
Expand All @@ -247,59 +247,59 @@ private static function createTable()

$userCreate = $db->create('admin_user', [
'id' => [
"SMALLINT",
"UNSIGNED",
"NOT NULL",
"AUTO_INCREMENT",
'SMALLINT',
'UNSIGNED',
'NOT NULL',
'AUTO_INCREMENT',
],
'account' => [
"VARCHAR(32)",
"NOT NULL",
"DEFAULT ''",
'VARCHAR(32)',
'NOT NULL',
'DEFAULT \'\'',
],
'password' => [
"VARCHAR(255)",
"NOT NULL",
"DEFAULT ''",
'VARCHAR(255)',
'NOT NULL',
'DEFAULT \'\'',
],
'name' => [
"VARCHAR(32)",
"NOT NULL",
"DEFAULT ''",
'VARCHAR(32)',
'NOT NULL',
'DEFAULT \'\'',
],
'email' => [
"VARCHAR(255)",
"NOT NULL",
"DEFAULT ''",
'VARCHAR(255)',
'NOT NULL',
'DEFAULT \'\'',
],
'role_id' => [
"TINYINT",
"UNSIGNED",
"NOT NULL",
"DEFAULT '0'",
'TINYINT',
'UNSIGNED',
'NOT NULL',
'DEFAULT \'0\'',
],
'status' => [
"TINYINT(1)",
"UNSIGNED",
"NOT NULL",
"DEFAULT '1'",
'TINYINT(1)',
'UNSIGNED',
'NOT NULL',
'DEFAULT \'1\'',
],
'auth_key' => [
"VARCHAR(32)",
"NOT NULL",
"DEFAULT ''",
'VARCHAR(32)',
'NOT NULL',
'DEFAULT \'\'',
],
'create_time' => [
"TIMESTAMP",
"NOT NULL",
"DEFAULT CURRENT_TIMESTAMP",
'TIMESTAMP',
'NOT NULL',
'DEFAULT CURRENT_TIMESTAMP',
],
'PRIMARY KEY (<id>)',
'UNIQUE INDEX <account> (<account>)',
'INDEX <auth_key> (<auth_key>)',
], [
"ENGINE" => "InnoDB",
"DEFAULT CHARSET" => "utf8mb4",
'ENGINE' => 'InnoDB',
'DEFAULT CHARSET' => 'utf8mb4',
]);

if ($userCreate) {
Expand All @@ -323,55 +323,55 @@ private static function createTable()

$db->create('admin_log', [
'id' => [
"INT",
"UNSIGNED",
"NOT NULL",
"AUTO_INCREMENT",
'INT',
'UNSIGNED',
'NOT NULL',
'AUTO_INCREMENT',
],
'user_id' => [
"SMALLINT",
"UNSIGNED",
"NOT NULL",
"DEFAULT '0'",
'SMALLINT',
'UNSIGNED',
'NOT NULL',
'DEFAULT \'0\'',
],
'date' => [
"DATE",
"NOT NULL",
"DEFAULT '2022-08-02'",
'DATE',
'NOT NULL',
'DEFAULT \'2022-08-02\'',
],
'hour' => [
"TINYINT",
"UNSIGNED",
"NOT NULL",
"DEFAULT '0'",
'TINYINT',
'UNSIGNED',
'NOT NULL',
'DEFAULT \'0\'',
],
'view' => [
"SMALLINT",
"UNSIGNED",
"NOT NULL",
"DEFAULT '0'",
'SMALLINT',
'UNSIGNED',
'NOT NULL',
'DEFAULT \'0\'',
],
'edit' => [
"SMALLINT",
"UNSIGNED",
"NOT NULL",
"DEFAULT '0'",
'SMALLINT',
'UNSIGNED',
'NOT NULL',
'DEFAULT \'0\'',
],
'ip' => [
"VARCHAR(45)",
"NOT NULL",
"DEFAULT ''",
'VARCHAR(45)',
'NOT NULL',
'DEFAULT \'\'',
],
'create_time' => [
"TIMESTAMP",
"NOT NULL",
"DEFAULT CURRENT_TIMESTAMP",
'TIMESTAMP',
'NOT NULL',
'DEFAULT CURRENT_TIMESTAMP',
],
'PRIMARY KEY (<id>)',
'UNIQUE INDEX <user_id_date_hour> (<user_id>, <date>, <hour>)',
], [
"ENGINE" => "InnoDB",
"DEFAULT CHARSET" => "utf8mb4",
'ENGINE' => 'InnoDB',
'DEFAULT CHARSET' => 'utf8mb4',
]);
}

Expand Down
20 changes: 10 additions & 10 deletions src/Admin/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public static function getUserId(): int
}

if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
$auth = trim(strip_tags($_SERVER['PHP_AUTH_USER']));
$session = trim(strip_tags($_SERVER['PHP_AUTH_PW']));
$auth = $_SERVER['PHP_AUTH_USER'];
$session = $_SERVER['PHP_AUTH_PW'];
} else {
$auth = trim(strip_tags($_COOKIE['admin_auth'] ?? ''));
$session = trim(strip_tags($_COOKIE['admin_session'] ?? ''));
$auth = $_COOKIE['admin_auth'] ?? '';
$session = $_COOKIE['admin_session'] ?? '';
}

if ($auth && $session) {
Expand Down Expand Up @@ -105,8 +105,8 @@ public static function getUserId(): int
public static function store(int $userId, bool $renew = false)
{
if ($renew) {
$auth = trim(strip_tags($_COOKIE['admin_auth'] ?? ''));
$session = trim(strip_tags($_COOKIE['admin_session'] ?? ''));
$auth = $_COOKIE['admin_auth'] ?? '';
$session = $_COOKIE['admin_session'] ?? '';
} else {
$userInfo = Model::getUserInfo($userId);
$auth = $userInfo['auth_key'];
Expand All @@ -122,8 +122,8 @@ public static function store(int $userId, bool $renew = false)
$cacheTime = Config::get('remember');
$cache->set($cacheKey, $authInfo, $cacheTime);

setcookie('admin_auth', $auth, time() + $cacheTime, '/' . trim(Config::get('path'), '/'), '.' . Request::host());
setcookie('admin_session', $session, time() + $cacheTime, '/' . trim(Config::get('path'), '/'), '.' . Request::host());
setcookie('admin_auth', $auth, time() + $cacheTime, '/' . Config::get('path'), '.' . Request::host());
setcookie('admin_session', $session, time() + $cacheTime, '/' . Config::get('path'), '.' . Request::host());
}

/**
Expand All @@ -143,8 +143,8 @@ public static function clear(int $userId)
$cache->delete($cacheKey);
}

setcookie('admin_auth', '', 0, '/' . trim(Config::get('path'), '/'), '.' . Request::host());
setcookie('admin_session', '', 0, '/' . trim(Config::get('path'), '/'), '.' . Request::host());
setcookie('admin_auth', '', 0, '/' . Config::get('path'), '.' . Request::host());
setcookie('admin_session', '', 0, '/' . Config::get('path'), '.' . Request::host());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Admin/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static function login()
$cacheKey = 'admin_captcha_' . $captchaHash;
$captchaCodeCache = $cache->get($cacheKey);
$cache->delete($cacheKey);
setcookie('admin_captcha', '', 0, '/' . trim(Config::get('path'), '/'), '.' . Request::host());
setcookie('admin_captcha', '', 0, '/' . Config::get('path'), '.' . Request::host());

if (!$captchaCodeCache || $captchaCode != $captchaCodeCache) {
Response::api(1002, ':invalid_captcha');
Expand Down Expand Up @@ -208,7 +208,7 @@ public static function captcha()
$cache = Cache::init();
$cache->set('admin_captcha_' . $captchaHash, $code, 300);

setcookie('admin_captcha', $captchaHash, time() + 300, '/' . trim(Config::get('path'), '/'), '.' . Request::host());
setcookie('admin_captcha', $captchaHash, time() + 300, '/' . Config::get('path'), '.' . Request::host());

header('Content-type: image/jpeg');
$builder->output();
Expand Down Expand Up @@ -356,15 +356,15 @@ public static function userForm()
*/
public static function upload()
{
$path = trim(Request::$data['path'] ?? '');
$path = trim((string) Request::$data['path'] ?? '', '/');
$local = (int) (Request::$data['local'] ?? 0);
$keepName = (int) (Request::$data['keep'] ?? 0);
$tinymce = (int) (Request::$data['tinymce'] ?? 0);
$file = $_FILES['file'] ?? null;

$fileName = '';
$now = time();
$filePath = 'upload/' . (trim($path, '/') ? trim($path, '/') : 'file') . '/' . date('ym', $now) . '/' . date('d', $now);
$filePath = 'upload/' . ($path ?: 'file') . '/' . date('ym', $now) . '/' . date('d', $now);
$localPath = App::root('public' . '/' . $filePath);
if (!is_dir($localPath)) {
mkdir($localPath, 0775, true);
Expand Down
6 changes: 3 additions & 3 deletions src/Admin/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public static function field(string $key): FormField
public static function render(string $table, ?callable $middleware = null)
{
Request::$data['_id'] = (int) (Request::$data['_id'] ?? 0);
Request::$data['_form'] = trim(Request::$data['_form'] ?? '');
Request::$data['_title'] = trim(Request::$data['_title'] ?? '');
Request::$data['_form'] = Request::$data['_form'] ?? '';
Request::$data['_title'] = Request::$data['_title'] ?? '';

$separator = (string) Config::get('join');
if (isset(Request::$data['_ids'])) {
Expand Down Expand Up @@ -189,7 +189,7 @@ private static function dataFilter(array $field, array $data): array
} elseif (is_array($data[$k])) {
$return[$k] = join($separator, $data[$k]);
} else {
$return[$k] = isset($v['raw']) ? $data[$k] : trim($data[$k]);
$return[$k] = isset($v['raw']) ? $data[$k] : trim((string) $data[$k]);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Admin/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public static function render(string $table, ?callable $middleware = null)
$page = (int) (Request::$data['current'] ?? 1);
$limit = (int) (Request::$data['pageSize'] ?? 20);
$limit = $limit < 100 ? $limit : 100;
$order = trim(Request::$data['_order'] ?? '') ?: 'id';
$sort = trim(Request::$data['_sort'] ?? '') ?: 'asc';
$order = (Request::$data['_order'] ?? '') ?: 'id';
$sort = (Request::$data['_sort'] ?? '') ?: 'asc';

$sortLimit = ['ascend' => 'asc', 'descend' => 'desc'];
$sort = $sortLimit[$sort] ?? 'asc';
Expand Down Expand Up @@ -242,7 +242,7 @@ private static function searchFilter(array $column, array $data): array
if ($column) {
foreach ($column as $k => $v) {
if ($v['database'] && isset($v['search']) && isset($data[$k])) {
$_v = isset($v['searchRaw']) ? $data[$k] : trim($data[$k]);
$_v = isset($v['searchRaw']) ? $data[$k] : trim((string) $data[$k]);
if ($_v || is_numeric($_v)) {
if ($v['search'] === 'text[~]') {
$return[$k . '[~]'] = $_v;
Expand Down

0 comments on commit 2a9989e

Please sign in to comment.