Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.0.02 #12

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions db_dispose.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
public function dbCookie(): string|false
{
if (!isset($_COOKIE['UID'])) {
check();

Check failure on line 256 in db_dispose.php

View workflow job for this annotation

GitHub Actions / MegaLinter

Function check not found.

Check failure on line 256 in db_dispose.php

View workflow job for this annotation

GitHub Actions / MegaLinter

Function check not found.
}
$cookie = htmlspecialchars($_COOKIE['UID'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
// 查询 cookie.
Expand All @@ -271,10 +271,23 @@
// home_config 配置更新
public function dbUpdateHomeConfig(string $site_name, string $site_icon, string $home_theme, string $home_icon, array $label_id, array $home_label, bool $home_search, bool $home_login, string $home_content): void
{
$label_id_string = implode(", ",$label_id);
$home_label_string = implode(", ",$home_label);
$command = "UPDATE {$this->home_config} SET site_name = ? , site_icon = ? , home_theme = ? , home_icon = ? , label_id = ? , home_label = ? , home_search = ? , home_login = ? , home_content = ? ";
$this->dbUpdate($command, 'ssssssiis', [$site_name, $site_icon, $home_theme, $home_icon, $label_id_string, $home_label_string, $home_search, $home_login, $home_content], 'Update home_config failed');
try {
// 验证 ID 有效性
$data = $this->dbQueryHomeLabelAll();
$existing_ids = array_column($data, 'id');
if (!is_array($label_id) || array_diff(array_filter($label_id), $existing_ids)) {
echo "<script>alert('Label ID is invalid');</script>";
throw new Exception('ID does not exist');
}

$label_id_string = implode(", ",$label_id);
$home_label_string = implode(", ",$home_label);

$command = "UPDATE {$this->home_config} SET site_name = ? , site_icon = ? , home_theme = ? , home_icon = ? , label_id = ? , home_label = ? , home_search = ? , home_login = ? , home_content = ? ";
$this->dbUpdate($command, 'ssssssiis', [$site_name, $site_icon, $home_theme, $home_icon, $label_id_string, $home_label_string, $home_search, $home_login, $home_content], 'Update home_config failed');
} catch (Exception $e) {
throw new Exception('home_config update failed: ' . $e->getMessage());
}
}

// home_config 配置查询
Expand Down Expand Up @@ -312,7 +325,7 @@
&amp;lt;/a&amp;gt;
&amp;lt;/span&amp;gt;'],
['Dropdown', 'dropdown', '&amp;lt;a href=&amp;#039;https://github.com/DUQIA/Akylor&amp;#039; target=&amp;#039;_blank&amp;#039; rel=&amp;#039;nofollow noopener noreferrer&amp;#039;&amp;gt;Akylor&amp;lt;/a&amp;gt;'],
['Link', 'link', '&amp;lt;a href=&amp;#039;https://github.com/DUQIA&amp;#039; target=&amp;#039;_blank&amp;#039; rel=&amp;#039;nofollow noopener noreferrer&amp;#039;&amp;gt;Github&amp;lt;/a&amp;gt;']
['Link', 'link', '&amp;lt;a href=&amp;#039;https://blog.akylor.us.kg&amp;#039; target=&amp;#039;_blank&amp;#039; rel=&amp;#039;nofollow noopener noreferrer&amp;#039;&amp;gt;Blog&amp;lt;/a&amp;gt;']
];
$this->dbDeleteHomeLabelAll();
foreach ($default_labels_config as $label) {
Expand Down Expand Up @@ -389,16 +402,23 @@
// 开始事务
$this->beginTransaction();

$command = "SELECT * FROM {$this->home_labels}";
$data = $this->dbQueryAllLine($command, 'Query home_labels failed');
$data = $this->dbQueryHomeLabelAll();

// 首次创建数据
if (empty($data)) {
$this->dbCreateHomeLabel($home_label);
return $this->dbQueryHomeLabel($label_id, $home_label);
} else {
$existing_ids = array_column($data, 'id');
$existing_labels = array_column($data, 'label_name');

// 验证 ID 有效性
if (!is_array($label_id) || array_diff($label_id, $existing_ids)) {
// 回滚事务
$this->rollBack();
return $data;
}

$delete_ids = array_diff($existing_ids, $label_id); // 删除id
$Remaining_labels = array_diff_assoc($home_label, $existing_labels); // 剩余标签
$update_ids = array_intersect_key($label_id, $Remaining_labels); // 通过 id 更新标签
Expand All @@ -417,8 +437,7 @@

if (!empty($delete_ids) || !empty($update_ids) && !empty($update_laebels) || $create_labels) {
// 重新查询最新的 home_labels 数据
$command = "SELECT * FROM {$this->home_labels}";
$update_data = $this->dbQueryAllLine($command, 'Query home_labels failed');
$update_data = $this->dbQueryHomeLabelAll();
$update_ids = array_column($update_data, 'id');
// 更新 home_config 的id
$update_label_id = "UPDATE {$this->home_config} SET label_id = ?";
Expand Down Expand Up @@ -448,7 +467,7 @@
public function dbIp(): void
{
$ip = (filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP)) ?: 'invalid Ip'; // 获取当前ip地址
$response = new StatusCode();

Check failure on line 470 in db_dispose.php

View workflow job for this annotation

GitHub Actions / MegaLinter

Instantiated class StatusCode not found.

Check failure on line 470 in db_dispose.php

View workflow job for this annotation

GitHub Actions / MegaLinter

Instantiated class StatusCode not found.
$country = $response->getIp($ip); // 获取当前ip地址的详细信息

$timestamp = filter_var($_SERVER['REQUEST_TIME'], FILTER_VALIDATE_INT); // 时间戳
Expand Down
Loading