1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-26 12:23:06 +08:00

Merge remote-tracking branch 'origin/demo' into demo

This commit is contained in:
xiaochong0302 2022-12-15 10:57:01 +08:00
commit 3b31294aee
14 changed files with 216 additions and 13 deletions

View File

@ -101,7 +101,6 @@ class Package extends Service
$data = [];
$data['title'] = $validator->checkTitle($post['title']);
$data['summary'] = $validator->checkSummary($post['summary']);
$package = new PackageModel();

View File

@ -12,12 +12,6 @@
<input class="layui-input" type="text" name="title" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">简介</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="summary"></textarea>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"></label>
<div class="layui-input-block">

View File

@ -32,6 +32,8 @@
</thead>
<tbody>
{% 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' %}
<tr>
<td>
<p class="layui-elip">课程:{{ item.course.title }}</p>
@ -41,8 +43,8 @@
<p>类型:{{ client_type_info(item.client_type) }}</p>
<p>地址:<a href="javascript:" class="kg-ip2region" title="查看位置" data-ip="{{ item.client_ip }}">{{ item.client_ip }}</a></p>
</td>
<td>{{ item.duration|duration }}</td>
<td>{{ date('Y-m-d H:i:s',item.active_time) }}</td>
<td>{{ duration }}</td>
<td>{{ active_time }}</td>
</tr>
{% endfor %}
</tbody>

View File

@ -0,0 +1,159 @@
<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
namespace App\Services;
use App\Library\Utils\FileInfo;
use App\Models\Upload as UploadModel;
use App\Repos\Upload as UploadRepo;
use Phalcon\Text;
class EditorStorage extends Storage
{
public function handle($content)
{
$content = $this->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('/<img src="(\S+)"/', $content, $matches);
if (count($matches[1]) > 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';
}
}

View File

@ -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);

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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;

View File

@ -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();
}