1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-28 21:31:37 +08:00

修复编辑器图片上传,增加上传文件身份认证,markdown内容解析

This commit is contained in:
xiaochong0302 2020-11-26 21:45:52 +08:00
parent b716dcfa28
commit f980964ba8
19 changed files with 89 additions and 57 deletions

View File

@ -1,8 +1,15 @@
## 酷瓜云课堂 ## 酷瓜云课堂
![酷瓜云课堂](https://upload-images.jianshu.io/upload_images/326350-dd52d4e6ad576989.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
#### 项目介绍 #### 项目介绍
酷瓜云课堂依托腾讯云基础服务架构采用C扩展PHP框架Phalcon开发致力开源网课系统开源网校系统开源在线教育系统。 酷瓜云课堂依托腾讯云基础服务架构采用C扩展框架Phalcon开发GPL-2.0开源协议,致力开源网课系统,开源网校系统,开源在线教育系统。
![](https://img.shields.io/static/v1?label=release&message=1.2.0&color=blue)
![](https://img.shields.io/static/v1?label=stars&message=101&color=blue)
![](https://img.shields.io/static/v1?label=forks&message=40&color=blue)
![](https://img.shields.io/static/v1?label=license&message=GPL-2.0&color=blue)
#### 系统功能 #### 系统功能
@ -14,7 +21,9 @@
- 课程数据来源于网络(无实质内容),切莫购买 - 课程数据来源于网络(无实质内容),切莫购买
- 管理后台已禁止数据提交,私密配置已过滤 - 管理后台已禁止数据提交,私密配置已过滤
演示帐号100015@163.com / 123456 (前后台通用) 演示帐号:**13507083515 / 123456** (前后台通用)
桌面端演示:
- [前台演示](https://ctc.koogua.com) - [前台演示](https://ctc.koogua.com)
- [后台演示](https://ctc.koogua.com/admin) - [后台演示](https://ctc.koogua.com/admin)
@ -23,6 +32,14 @@
![移动端扫码演示](https://upload-images.jianshu.io/upload_images/326350-83444e0bbe14db9f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ![移动端扫码演示](https://upload-images.jianshu.io/upload_images/326350-83444e0bbe14db9f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
支付流程演示:
- [MySQL提升课程全面讲解MySQL架构设计0.01元)](https://ctc.koogua.com/order/confirm?item_id=1390&item_type=1)
- [Nginx入门到实践Nginx中间件0.01元)](https://ctc.koogua.com/order/confirm?item_id=1286&item_type=1)
- [数据库与中间件的基础必修课0.02元)](https://ctc.koogua.com/order/confirm?item_id=80&item_type=2)
Tips: 测试支付请用手机号注册一个新账户,以便接收订单通知,以及避免课程无法购买
#### 项目组件 #### 项目组件
- 后台框架:[phalcon 3.4.5](https://phalcon.io) - 后台框架:[phalcon 3.4.5](https://phalcon.io)
@ -45,8 +62,7 @@
#### 意见反馈 #### 意见反馈
- [在线反馈](https://gitee.com/koogua/course-tencent-cloud/issues)(推荐) - [在线反馈](https://gitee.com/koogua/course-tencent-cloud/issues)(推荐)
- QQ邮箱: 76632555@qq.com - QQ交流群: 787363898
- QQ群组: 787363898
#### 通过这个项目能学到什么? #### 通过这个项目能学到什么?

View File

@ -55,6 +55,10 @@
<td>cover_270</td> <td>cover_270</td>
<td>mageMogr2/thumbnail/270x/interlace/0</td> <td>mageMogr2/thumbnail/270x/interlace/0</td>
</tr> </tr>
<tr>
<td>content_800</td>
<td>mageMogr2/thumbnail/800x/interlace/0</td>
</tr>
<tr> <tr>
<td>slide_1100</td> <td>slide_1100</td>
<td>imageMogr2/thumbnail/1100x/interlace/0</td> <td>imageMogr2/thumbnail/1100x/interlace/0</td>

View File

@ -50,10 +50,6 @@ class Account extends Service
$user = $validator->checkUserLogin($post['account'], $post['password']); $user = $validator->checkUserLogin($post['account'], $post['password']);
//$validator = new CaptchaValidator();
//$validator->checkCode($post['ticket'], $post['rand']);
return $this->auth->saveAuthInfo($user); return $this->auth->saveAuthInfo($user);
} }

View File

@ -10,7 +10,6 @@ use App\Services\Pay\Wxpay as WxpayService;
use App\Services\Storage as StorageService; use App\Services\Storage as StorageService;
use App\Traits\Response as ResponseTrait; use App\Traits\Response as ResponseTrait;
use App\Traits\Security as SecurityTrait; use App\Traits\Security as SecurityTrait;
use Phalcon\Text;
use PHPQRCode\QRcode; use PHPQRCode\QRcode;
class PublicController extends \Phalcon\Mvc\Controller class PublicController extends \Phalcon\Mvc\Controller
@ -44,31 +43,6 @@ class PublicController extends \Phalcon\Mvc\Controller
} }
} }
/**
* @Get("/img/{id:[0-9]+}", name="home.img")
*/
public function imageAction($id)
{
$repo = new UploadRepo();
$file = $repo->findById($id);
if ($file && Text::startsWith($file->mime, 'image')) {
$service = new StorageService();
$location = $service->getImageUrl($file->path);
$this->response->redirect($location);
} else {
$this->response->setStatusCode(404);
return $this->response;
}
}
/** /**
* @Get("/qrcode", name="home.qrcode") * @Get("/qrcode", name="home.qrcode")
*/ */

View File

@ -1,9 +1,9 @@
<?php <?php
namespace App\Http\Home\Controllers; namespace App\Http\Home\Controllers;
use App\Services\MyStorage as StorageService; use App\Services\MyStorage as StorageService;
use App\Validators\Validator as AppValidator;
/** /**
* @RoutePrefix("/upload") * @RoutePrefix("/upload")
@ -11,6 +11,15 @@ use App\Services\MyStorage as StorageService;
class UploadController extends Controller class UploadController extends Controller
{ {
public function initialize()
{
$authUser = $this->getAuthUser();
$validator = new AppValidator();
$validator->checkAuthUser($authUser->id);
}
/** /**
* @Post("/avatar/img", name="home.upload.avatar_img") * @Post("/avatar/img", name="home.upload.avatar_img")
*/ */

View File

@ -8,7 +8,7 @@
{% set teacher.title = teacher.title ? teacher.title : '小小教书匠' %} {% set teacher.title = teacher.title ? teacher.title : '小小教书匠' %}
<div class="sidebar-teacher-card clearfix"> <div class="sidebar-teacher-card clearfix">
<div class="avatar"> <div class="avatar">
<img src="{{ teacher.avatar }}" alt="{{ teacher.name }}"> <img src="{{ teacher.avatar }}!avatar_160" alt="{{ teacher.name }}">
</div> </div>
<div class="info"> <div class="info">
<div class="name layui-elip"> <div class="name layui-elip">

View File

@ -25,7 +25,7 @@
<div class="user-profile wrap clearfix"> <div class="user-profile wrap clearfix">
{{ vip_info(user.vip) }} {{ vip_info(user.vip) }}
<div class="avatar"> <div class="avatar">
<img src="{{ user.avatar }}" alt="{{ user.name }}"> <img src="{{ user.avatar }}!avatar_160" alt="{{ user.name }}">
</div> </div>
<div class="info"> <div class="info">
<p><span class="name">{{ user.name }}</span><span>{{ gender_icon(user.gender) }}</span></p> <p><span class="name">{{ user.name }}</span><span>{{ gender_icon(user.gender) }}</span></p>

View File

@ -246,6 +246,42 @@ function kg_cos_cover_url($path, $style = null)
return kg_cos_img_url($path, $style); return kg_cos_img_url($path, $style);
} }
/**
* 获取幻灯片URL
*
* @param string $path
* @param string $style
* @return string
*/
function kg_cos_slide_url($path, $style = null)
{
return kg_cos_img_url($path, $style);
}
/**
* 清除存储图片处理样式
*
* @param $path
* @return string
*/
function kg_cos_img_style_trim($path)
{
return preg_replace('/!\w+/', '', $path);
}
/**
* 解析markdown内容
*
* @param $content
* @return string
*/
function kg_parse_markdown($content)
{
return preg_replace_callback('/\/img\/content\/(.*?)\)/', function ($matches) {
return '/img/content/' . trim($matches[1]) . '!content_800';
}, $content);
}
/** /**
* 隐藏部分字符 * 隐藏部分字符
* *

View File

@ -143,7 +143,7 @@ class Slide extends Model
public function afterFetch() public function afterFetch()
{ {
if (!Text::startsWith($this->cover, 'http')) { if (!Text::startsWith($this->cover, 'http')) {
$this->cover = kg_cos_cover_url($this->cover); $this->cover = kg_cos_slide_url($this->cover);
} }
} }

View File

@ -22,6 +22,8 @@ class BasicInfo extends Service
public function handleBasicInfo(CourseModel $course) public function handleBasicInfo(CourseModel $course)
{ {
$course->details = kg_parse_markdown($course->details);
$teachers = $this->handleTeachers($course); $teachers = $this->handleTeachers($course);
$ratings = $this->handleRatings($course); $ratings = $this->handleRatings($course);

View File

@ -20,10 +20,14 @@ class HelpInfo extends Service
protected function handleHelp(HelpModel $help) protected function handleHelp(HelpModel $help)
{ {
$help->content = kg_parse_markdown($help->content);
return [ return [
'id' => $help->id, 'id' => $help->id,
'title' => $help->title, 'title' => $help->title,
'content' => $help->content, 'content' => $help->content,
'create_time' => $help->create_time,
'update_time' => $help->update_time,
]; ];
} }

View File

@ -20,6 +20,8 @@ class PageInfo extends Service
protected function handlePage(PageModel $page) protected function handlePage(PageModel $page)
{ {
$page->content = kg_parse_markdown($page->content);
return [ return [
'id' => $page->id, 'id' => $page->id,
'title' => $page->title, 'title' => $page->title,

View File

@ -46,7 +46,7 @@ trait Auth
$validator = new AppValidator(); $validator = new AppValidator();
$validator->checkAuthUser($authUser); $validator->checkAuthUser($authUser['id']);
$userRepo = new UserRepo(); $userRepo = new UserRepo();

View File

@ -90,7 +90,7 @@ class Course extends Validator
throw new BadRequestException('course.invalid_cover'); throw new BadRequestException('course.invalid_cover');
} }
return $value; return kg_cos_img_style_trim($value);
} }
public function checkTitle($title) public function checkTitle($title)

View File

@ -98,7 +98,7 @@ class ImGroup extends Validator
throw new BadRequestException('im_group.invalid_avatar'); throw new BadRequestException('im_group.invalid_avatar');
} }
return $value; return kg_cos_img_style_trim($value);
} }
public function checkType($type) public function checkType($type)

View File

@ -64,18 +64,7 @@ class Slide extends Validator
throw new BadRequestException('slide.invalid_cover'); throw new BadRequestException('slide.invalid_cover');
} }
return $value; return kg_cos_img_style_trim($value);
}
public function checkBgColor($bgColor)
{
$value = $this->filter->sanitize($bgColor, ['trim', 'string']);
if (!preg_match('/^#[0-9a-fA-F]{6}$/', $bgColor)) {
throw new BadRequestException('slide.invalid_bg_color');
}
return $value;
} }
public function checkPlatform($platform) public function checkPlatform($platform)

View File

@ -137,7 +137,7 @@ class User extends Validator
throw new BadRequestException('user.invalid_avatar'); throw new BadRequestException('user.invalid_avatar');
} }
return $value; return kg_cos_img_style_trim($value);
} }
public function checkEduRole($value) public function checkEduRole($value)

View File

@ -9,9 +9,9 @@ use Phalcon\Mvc\User\Component;
class Validator extends Component class Validator extends Component
{ {
public function checkAuthUser($authInfo) public function checkAuthUser($userId)
{ {
if (empty($authInfo['id'])) { if (empty($userId)) {
throw new UnauthorizedException('sys.unauthorized'); throw new UnauthorizedException('sys.unauthorized');
} }
} }

View File

@ -24,7 +24,7 @@ layui.use(['jquery'], function () {
max: 30000 max: 30000
}, },
upload: { upload: {
url: '/admin/upload/img/editor', url: '/admin/upload/content/img',
max: 10 * 1024 * 1024, max: 10 * 1024 * 1024,
accept: 'image/*', accept: 'image/*',
headers: { headers: {