diff --git a/db/app_uoj233.sql b/db/app_uoj233.sql index bb96614..8d743d4 100644 --- a/db/app_uoj233.sql +++ b/db/app_uoj233.sql @@ -847,7 +847,7 @@ CREATE TABLE `users_images` ( `hash` varchar(70) NOT NULL, PRIMARY KEY (`id`), KEY `uploader` (`uploader`), - KET `path` (`path`), + KEY `path` (`path`), KEY `upload_time` (`upload_time`), KEY `size` (`size`), KEY `hash` (`hash`) diff --git a/web/app/controllers/image_hosting/index.php b/web/app/controllers/image_hosting/index.php index 35d678c..3aef020 100644 --- a/web/app/controllers/image_hosting/index.php +++ b/web/app/controllers/image_hosting/index.php @@ -58,10 +58,10 @@ $watermark_text = UOJConfig::$data['profile']['oj-name-short']; if (isSuperUser($myUser) && $_POST['watermark'] == 'no_watermark') { $watermark_text = ""; - $hash += "__no"; + $hash .= "__no"; } elseif ($_POST['watermark'] == 'site_shortname_and_username') { $watermark_text .= ' @'.Auth::id(); - $hash += "__id"; + $hash .= "__id"; } $existing_image = DB::selectFirst("SELECT * FROM users_images WHERE `hash` = '$hash'"); @@ -71,11 +71,13 @@ } $img = imagecreatefromstring(file_get_contents($_FILES["image_upload_file"]["tmp_name"])); - $white = imagecolorallocate($img, 255, 255, 255); - $black = imagecolorallocate($img, 150, 150, 150); + $white = imagecolorallocatealpha($img, 255, 255, 255, 30); + $black = imagecolorallocatealpha($img, 50, 50, 50, 70); + $scale = ceil($width / 750.0); - imagettftext($img, '16', 0, 10 + 1, max(0, $height - 20) + 1, $black, UOJContext::documentRoot().'/fonts/roboto-mono/RobotoMono-Bold.ttf', $watermark_text); - imagettftext($img, '16', 0, 10, max(0, $height - 20), $white, UOJContext::documentRoot().'/fonts/roboto-mono/RobotoMono-Bold.ttf', $watermark_text); + imagettftext($img, strval($scale * 16), 0, ($scale * 16) + $scale, max(0, $height - ($scale * 16) + 5) + $scale, $black, UOJContext::documentRoot().'/fonts/roboto-mono/RobotoMono-Bold.ttf', $watermark_text); + imagefilter($img, IMG_FILTER_GAUSSIAN_BLUR); + imagettftext($img, strval($scale * 16), 0, ($scale * 16), max(0, $height - ($scale * 16) + 5), $white, UOJContext::documentRoot().'/fonts/roboto-mono/RobotoMono-Bold.ttf', $watermark_text); imagepng($img, $_FILES["image_upload_file"]["tmp_name"]); imagedestroy($img); @@ -87,6 +89,24 @@ DB::insert("INSERT INTO users_images (`path`, uploader, width, height, upload_time, size, `hash`) VALUES ('$filename', '{$myUser['username']}', $width, $height, now(), {$_FILES["image_upload_file"]["size"]}, '$hash')"); die(json_encode(['status' => 'success', 'path' => $filename])); + } elseif ($_POST['image_delete_submit'] == 'submit') { + crsf_defend(); + + $id = $_POST['image_delete_id']; + if (!validateUInt($id)) { + becomeMsgPage('ID 不合法。返回'); + } else { + $result = DB::selectFirst("SELECT * from users_images WHERE id = $id"); + if (!$result) { + becomeMsgPage('图片不存在。返回'); + } else { + unlink(UOJContext::storagePath().$result['path']); + DB::delete("DELETE FROM users_images WHERE id = $id"); + + header("Location: ". UOJContext::requestURI()); + die(); + } + } } ?> @@ -260,6 +280,9 @@ $('#image-upload-form').submit(function(event) { } } }, + error: function() { + $('#modal-help-message').html('上传失败,请刷新页面重试。').addClass('text-danger').show(); + } }); return false; @@ -304,4 +327,94 @@ $('#image_upload_file').change(function() { }); + 40, + 'col_names' => ['*'], + 'table_name' => 'users_images', + 'cond' => "uploader = '{$myUser['username']}'", + 'tail' => 'order by upload_time desc', +]; +$pag = new Paginator($pag_config); +?> + +

+ 我的图片 +

+ +
+ get() as $idx => $row): ?> +
+
+ + +
+
+ +
+ +
+ pagination() ?> +
+ +
+ +
+ + +