From a941d1129a00944ce0c895d61733ccc469e1e76b Mon Sep 17 00:00:00 2001 From: koogua Date: Wed, 2 Nov 2022 15:01:25 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=AF=8C=E6=96=87=E6=9C=AC=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8=E5=A2=9E=E5=8A=A0=E7=B2=98=E8=B4=B4=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=92=8C=E8=BF=9C=E7=A8=8B=E5=9B=BE=E7=89=87=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/EditorStorage.php | 159 +++++++++++++++++++++++++++++++++ app/Validators/Answer.php | 5 ++ app/Validators/Article.php | 5 ++ app/Validators/Course.php | 5 ++ app/Validators/Help.php | 5 ++ app/Validators/Page.php | 5 ++ app/Validators/PointGift.php | 5 ++ app/Validators/Question.php | 5 ++ 8 files changed, 194 insertions(+) create mode 100644 app/Services/EditorStorage.php diff --git a/app/Services/EditorStorage.php b/app/Services/EditorStorage.php new file mode 100644 index 00000000..10fb488d --- /dev/null +++ b/app/Services/EditorStorage.php @@ -0,0 +1,159 @@ +handleBase64Image($content); + $content = $this->handleRemoteImage($content); + + return trim($content); + } + + protected function handleBase64Image($content) + { + $content = preg_replace("/data-ke-src=\"(.*?)\"/", '', $content); + + preg_match_all('/src="(data:image\/(\S+);base64,(\S+))"/U', $content, $matches); + + if (count($matches[3]) > 0) { + foreach ($matches[3] as $key => $value) { + $imageUrl = $this->uploadBase64Image($matches[3][$key], $matches[2][$key]); + $content = str_replace($matches[1][$key], $imageUrl, $content); + } + } + + return $content; + } + + protected function handleRemoteImage($content) + { + $baseUrl = $this->getBaseUrl(); + + preg_match_all('/ 0) { + foreach ($matches[1] as $key => $value) { + if (!Text::startsWith($value, $baseUrl)) { + $imageUrl = $this->uploadRemoteImage($value); + $content = str_replace($value, $imageUrl, $content); + } + } + } + + return $content; + } + + protected function uploadBase64Image($encodeContent, $extension) + { + $keyName = $this->generateFileName($extension, '/img/content/'); + + $content = base64_decode($encodeContent); + + $md5 = md5($content); + + $uploadRepo = new UploadRepo(); + + $upload = $uploadRepo->findByMd5($md5); + + if (!$upload) { + + $uploadPath = $this->putString($keyName, $content); + + if ($uploadPath) { + + $upload = new UploadModel(); + + $upload->type = UploadModel::TYPE_CONTENT_IMG; + $upload->mime = FileInfo::getMimeTypeByExt($extension); + $upload->name = pathinfo($uploadPath, PATHINFO_BASENAME); + $upload->size = strlen($content); + $upload->path = $uploadPath; + $upload->md5 = $md5; + + $upload->create(); + } + + $imageUrl = $uploadPath ? $this->getImageUrl($uploadPath) : ''; + + } else { + + $imageUrl = $this->getImageUrl($upload->path); + } + + return $imageUrl; + } + + protected function uploadRemoteImage($remoteUrl) + { + $extension = $this->getImageExtension($remoteUrl); + + $content = file_get_contents($remoteUrl); + + if ($content === false) return $remoteUrl; + + $keyName = $this->generateFileName($extension, '/img/content/'); + + $md5 = md5($content); + + $uploadRepo = new UploadRepo(); + + $upload = $uploadRepo->findByMd5($md5); + + if (!$upload) { + + $uploadPath = $this->putString($keyName, $content); + + if ($uploadPath) { + + $upload = new UploadModel(); + + $upload->type = UploadModel::TYPE_CONTENT_IMG; + $upload->mime = FileInfo::getMimeTypeByExt($extension); + $upload->name = pathinfo($uploadPath, PATHINFO_BASENAME); + $upload->size = strlen($content); + $upload->path = $uploadPath; + $upload->md5 = $md5; + + $upload->create(); + } + + $imageUrl = $uploadPath ? $this->getImageUrl($uploadPath) : $remoteUrl; + + } else { + + $imageUrl = $this->getImageUrl($upload->path); + } + + return $imageUrl; + } + + /** + * 例如:https://abc.com/123.jpg!large,这类不规范地址,需要特殊处理 + * + * @param string $imageUrl + * @return string + */ + protected function getImageExtension($imageUrl) + { + $path = parse_url($imageUrl, PHP_URL_PATH); + + preg_match('/(\S+)\.(png|gif|jpg|jpeg)/i', $path, $matches); + + return $matches[2] ? strtolower($matches[2]) : 'jpg'; + } + +} \ No newline at end of file diff --git a/app/Validators/Answer.php b/app/Validators/Answer.php index 32a3fbe7..bb1099a4 100644 --- a/app/Validators/Answer.php +++ b/app/Validators/Answer.php @@ -15,6 +15,7 @@ use App\Models\Reason as ReasonModel; use App\Models\User as UserModel; use App\Repos\Answer as AnswerRepo; use App\Repos\Question as QuestionRepo; +use App\Services\EditorStorage as EditorStorageService; class Answer extends Validator { @@ -58,6 +59,10 @@ class Answer extends Validator { $value = $this->filter->sanitize($content, ['trim']); + $storage = new EditorStorageService(); + + $value = $storage->handle($value); + $length = kg_strlen($value); if ($length < 10) { diff --git a/app/Validators/Article.php b/app/Validators/Article.php index 9656b652..9987d097 100644 --- a/app/Validators/Article.php +++ b/app/Validators/Article.php @@ -14,6 +14,7 @@ use App\Library\Validators\Common as CommonValidator; use App\Models\Article as ArticleModel; use App\Models\Reason as ReasonModel; use App\Repos\Article as ArticleRepo; +use App\Services\EditorStorage as EditorStorageService; class Article extends Validator { @@ -94,6 +95,10 @@ class Article extends Validator { $value = $this->filter->sanitize($content, ['trim']); + $storage = new EditorStorageService(); + + $value = $storage->handle($value); + $length = kg_strlen($value); if ($length < 10) { diff --git a/app/Validators/Course.php b/app/Validators/Course.php index eda4d6ff..b562d98f 100644 --- a/app/Validators/Course.php +++ b/app/Validators/Course.php @@ -13,6 +13,7 @@ use App\Exceptions\BadRequest as BadRequestException; use App\Library\Validators\Common as CommonValidator; use App\Models\Course as CourseModel; use App\Repos\Course as CourseRepo; +use App\Services\EditorStorage as EditorStorageService; class Course extends Validator { @@ -119,6 +120,10 @@ class Course extends Validator { $value = $this->filter->sanitize($details, ['trim']); + $storage = new EditorStorageService(); + + $value = $storage->handle($value); + $length = kg_strlen($value); if ($length > 30000) { diff --git a/app/Validators/Help.php b/app/Validators/Help.php index 95d567ab..c5acab63 100644 --- a/app/Validators/Help.php +++ b/app/Validators/Help.php @@ -12,6 +12,7 @@ use App\Caches\MaxHelpId as MaxHelpIdCache; use App\Exceptions\BadRequest as BadRequestException; use App\Models\Help as HelpModel; use App\Repos\Help as HelpRepo; +use App\Services\EditorStorage as EditorStorageService; class Help extends Validator { @@ -90,6 +91,10 @@ class Help extends Validator { $value = $this->filter->sanitize($content, ['trim']); + $storage = new EditorStorageService(); + + $value = $storage->handle($value); + $length = kg_strlen($value); if ($length < 10) { diff --git a/app/Validators/Page.php b/app/Validators/Page.php index fa222509..2080d7a6 100644 --- a/app/Validators/Page.php +++ b/app/Validators/Page.php @@ -13,6 +13,7 @@ use App\Exceptions\BadRequest as BadRequestException; use App\Library\Validators\Common as CommonValidator; use App\Models\Page as PageModel; use App\Repos\Page as PageRepo; +use App\Services\EditorStorage as EditorStorageService; class Page extends Validator { @@ -124,6 +125,10 @@ class Page extends Validator { $value = $this->filter->sanitize($content, ['trim']); + $storage = new EditorStorageService(); + + $value = $storage->handle($value); + $length = kg_strlen($value); if ($length < 10) { diff --git a/app/Validators/PointGift.php b/app/Validators/PointGift.php index 5c1460ca..4f7e30b1 100644 --- a/app/Validators/PointGift.php +++ b/app/Validators/PointGift.php @@ -13,6 +13,7 @@ use App\Exceptions\BadRequest as BadRequestException; use App\Library\Validators\Common as CommonValidator; use App\Models\PointGift as PointGiftModel; use App\Repos\PointGift as PointGiftRepo; +use App\Services\EditorStorage as EditorStorageService; class PointGift extends Validator { @@ -86,6 +87,10 @@ class PointGift extends Validator { $value = $this->filter->sanitize($details, ['trim']); + $storage = new EditorStorageService(); + + $value = $storage->handle($value); + $length = kg_strlen($value); if ($length > 30000) { diff --git a/app/Validators/Question.php b/app/Validators/Question.php index 1481868c..84d1e98d 100644 --- a/app/Validators/Question.php +++ b/app/Validators/Question.php @@ -13,6 +13,7 @@ use App\Exceptions\BadRequest as BadRequestException; use App\Models\Question as QuestionModel; use App\Models\Reason as ReasonModel; use App\Repos\Question as QuestionRepo; +use App\Services\EditorStorage as EditorStorageService; class Question extends Validator { @@ -106,6 +107,10 @@ class Question extends Validator { $value = $this->filter->sanitize($content, ['trim']); + $storage = new EditorStorageService(); + + $value = $storage->handle($value); + $length = kg_strlen($value); if ($length > 30000) { From 7f9a63886fb11301f616723e43b1db820562b7fe Mon Sep 17 00:00:00 2001 From: koogua Date: Thu, 10 Nov 2022 12:08:46 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=A6=E5=91=98?= =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E8=AE=B0=E5=BD=95=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Admin/Views/student/learning.volt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Http/Admin/Views/student/learning.volt b/app/Http/Admin/Views/student/learning.volt index 620b6a27..314ef2c2 100644 --- a/app/Http/Admin/Views/student/learning.volt +++ b/app/Http/Admin/Views/student/learning.volt @@ -32,6 +32,8 @@ {% for item in pager.items %} + {% set duration = item.duration > 0 ? item.duration|duration : 'N/A' %} + {% set active_time = item.active_time > 0 ? date('Y-m-d H:i:s',item.active_time) : 'N/A' %}

课程:{{ item.course.title }}

@@ -41,8 +43,8 @@

类型:{{ client_type_info(item.client_type) }}

地址:{{ item.client_ip }}

- {{ item.duration|duration }} - {{ date('Y-m-d H:i:s',item.active_time) }} + {{ duration }} + {{ active_time }} {% endfor %} From 3d423890125cd713041ce3bb77b2bf3be44bb78f Mon Sep 17 00:00:00 2001 From: koogua Date: Thu, 17 Nov 2022 18:05:45 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=92=AD=E6=94=BE?= =?UTF-8?q?=E5=99=A8=E4=B8=AD=E5=A4=AE=E6=92=AD=E6=94=BE=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/static/home/js/chapter.live.player.js | 8 ++++++-- public/static/home/js/chapter.vod.player.js | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/public/static/home/js/chapter.live.player.js b/public/static/home/js/chapter.live.player.js index 4a0b7487..7c0285e8 100644 --- a/public/static/home/js/chapter.live.player.js +++ b/public/static/home/js/chapter.live.player.js @@ -56,14 +56,17 @@ layui.use(['jquery', 'helper'], function () { }); /** - * 播放器中央播放按钮点击事件 + * 播放器中央播放按钮 */ - $('#play-mask').on('click', function () { + var $playMask = $('#play-mask'); + + $playMask.on('click', function () { $(this).hide(); player.toggle(); }); function start() { + $playMask.hide(); if (interval != null) { clearInterval(interval); interval = null; @@ -72,6 +75,7 @@ layui.use(['jquery', 'helper'], function () { } function stop() { + $playMask.show(); if (interval != null) { clearInterval(interval); interval = null; diff --git a/public/static/home/js/chapter.vod.player.js b/public/static/home/js/chapter.vod.player.js index 3aaa7f69..9db67992 100644 --- a/public/static/home/js/chapter.vod.player.js +++ b/public/static/home/js/chapter.vod.player.js @@ -50,9 +50,11 @@ layui.use(['jquery', 'helper'], function () { }); /** - * 播放器中央播放按钮点击事件 + * 播放器中央播放按钮 */ - $('#play-mask').on('click', function () { + var $playMask = $('#play-mask'); + + $playMask.on('click', function () { $(this).hide(); player.toggle(); }); @@ -78,11 +80,13 @@ layui.use(['jquery', 'helper'], function () { } function play() { + $playMask.hide(); clearLearningInterval(); setLearningInterval(); } function pause() { + $playMask.show(); clearLearningInterval(); } From 214531691318f157f0fb092fcfc1c67b4af0f89b Mon Sep 17 00:00:00 2001 From: koogua Date: Mon, 12 Dec 2022 16:02:38 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A5=97=E9=A4=90?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=8E=BB=E9=99=A4summary=EF=BC=8C=E5=92=8C?= =?UTF-8?q?=E5=95=86=E4=B8=9A=E7=89=88=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Admin/Services/Package.php | 1 - app/Http/Admin/Views/package/add.volt | 6 ------ 2 files changed, 7 deletions(-) diff --git a/app/Http/Admin/Services/Package.php b/app/Http/Admin/Services/Package.php index c49ee55f..4cc1d666 100644 --- a/app/Http/Admin/Services/Package.php +++ b/app/Http/Admin/Services/Package.php @@ -101,7 +101,6 @@ class Package extends Service $data = []; $data['title'] = $validator->checkTitle($post['title']); - $data['summary'] = $validator->checkSummary($post['summary']); $package = new PackageModel(); diff --git a/app/Http/Admin/Views/package/add.volt b/app/Http/Admin/Views/package/add.volt index d8d8cc16..7a0a4163 100644 --- a/app/Http/Admin/Views/package/add.volt +++ b/app/Http/Admin/Views/package/add.volt @@ -12,12 +12,6 @@ -
- -
- -
-
From 1f996ab38437acbf2eba647b67ec600e03eb391e Mon Sep 17 00:00:00 2001 From: koogua Date: Mon, 12 Dec 2022 16:07:01 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=A0=87=E8=AE=B0=E4=B8=BA=E5=B7=B2=E8=AF=BB=EF=BC=8C=E8=AE=A1?= =?UTF-8?q?=E6=95=B0=E4=B8=8D=E5=BD=92=E9=9B=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/Logic/User/Console/NotificationRead.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Services/Logic/User/Console/NotificationRead.php b/app/Services/Logic/User/Console/NotificationRead.php index d33c5f20..5389db2a 100644 --- a/app/Services/Logic/User/Console/NotificationRead.php +++ b/app/Services/Logic/User/Console/NotificationRead.php @@ -17,6 +17,12 @@ class NotificationRead extends LogicService { $user = $this->getLoginUser(); + if ($user->notice_count == 0) return; + + $user->notice_count = 0; + + $user->update(); + $notifyRepo = new NotificationRepo(); $notifyRepo->markAllAsViewed($user->id); From 8b501d87574ec6dcb641ce99144ccc25893c7224 Mon Sep 17 00:00:00 2001 From: koogua Date: Mon, 12 Dec 2022 16:22:09 +0800 Subject: [PATCH 6/6] =?UTF-8?q?v1.6.1=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2046d530..1065dd5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +### [v1.6.1](https://gitee.com/koogua/course-tencent-cloud/releases/v1.6.1)(2022-12-12) + +- 富文本编辑器增加粘贴图片和远程图片本地化 +- 修正用户通知标记为已读,计数不归零问题 +- 修正播放器中央按钮显示问题 +- 优化腾讯云播放地址鉴权参数 +- 优化热门作者,答主和问题 +- 优化学员学习记录显示 +- 优化表单数据提交体验 +- 优化单章节层级显示 +- 优化ServerInfo类 + ### [v1.6.0](https://gitee.com/koogua/course-tencent-cloud/releases/v1.6.0)(2022-10-26) - 播放器中间增加大号播放按钮