mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-24 04:01:31 +08:00
放弃部分地方缓存的使用
This commit is contained in:
parent
51428ac97a
commit
817b32b067
@ -27,10 +27,10 @@ class AppInfo extends Cache
|
||||
$appInfo = new \App\Library\AppInfo();
|
||||
|
||||
return [
|
||||
'name' => $appInfo->name,
|
||||
'alias' => $appInfo->alias,
|
||||
'link' => $appInfo->link,
|
||||
'version' => $appInfo->version,
|
||||
'name' => $appInfo->get('name'),
|
||||
'alias' => $appInfo->get('alias'),
|
||||
'link' => $appInfo->get('link'),
|
||||
'version' => $appInfo->get('version'),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -160,6 +160,10 @@ class Article extends Service
|
||||
$data['title'] = $validator->checkTitle($post['title']);
|
||||
}
|
||||
|
||||
if (isset($post['cover'])) {
|
||||
$data['cover'] = $validator->checkCover($post['cover']);
|
||||
}
|
||||
|
||||
if (isset($post['summary'])) {
|
||||
$data['summary'] = $validator->checkSummary($post['summary']);
|
||||
}
|
||||
|
@ -28,24 +28,28 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="layout-sidebar writer-sidebar wrap">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">文章分类</label>
|
||||
<div class="layui-input-block">
|
||||
<select name="category_id" lay-search="true" lay-verify="required">
|
||||
<option value="">请选择</option>
|
||||
{% for option in category_options %}
|
||||
{% set selected = article.category_id == option.id ? 'selected="selected"' : '' %}
|
||||
<option value="{{ option.id }}" {{ selected }}>{{ option.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% if category_options|length > 0 %}
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">文章分类</label>
|
||||
<div class="layui-input-block">
|
||||
<select name="category_id" lay-search="true" lay-verify="required">
|
||||
<option value="">请选择</option>
|
||||
{% for option in category_options %}
|
||||
{% set selected = article.category_id == option.id ? 'selected="selected"' : '' %}
|
||||
<option value="{{ option.id }}" {{ selected }}>{{ option.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">文章标签</label>
|
||||
<div class="layui-input-block">
|
||||
<div id="xm-tag-ids"></div>
|
||||
{% endif %}
|
||||
{% if xm_tags|length > 0 %}
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">文章标签</label>
|
||||
<div class="layui-input-block">
|
||||
<div id="xm-tag-ids"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">来源类型</label>
|
||||
<div class="layui-input-block">
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% set title = question.id > 0 ? '编辑问题' : '提问题' %}
|
||||
{% set title = question.id > 0 ? '编辑问题' : '发布问题' %}
|
||||
{% set action_url = question.id > 0 ? url({'for':'home.question.update','id':question.id}) : url({'for':'home.question.create'}) %}
|
||||
|
||||
<div class="breadcrumb">
|
||||
@ -27,24 +27,28 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="layout-sidebar writer-sidebar wrap">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">问题分类</label>
|
||||
<div class="layui-input-block">
|
||||
<select name="category_id" lay-search="true" lay-verify="required">
|
||||
<option value="">请选择</option>
|
||||
{% for option in category_options %}
|
||||
{% set selected = question.category_id == option.id ? 'selected="selected"' : '' %}
|
||||
<option value="{{ option.id }}" {{ selected }}>{{ option.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% if category_options|length > 0 %}
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">问题分类</label>
|
||||
<div class="layui-input-block">
|
||||
<select name="category_id" lay-search="true" lay-verify="required">
|
||||
<option value="">请选择</option>
|
||||
{% for option in category_options %}
|
||||
{% set selected = question.category_id == option.id ? 'selected="selected"' : '' %}
|
||||
<option value="{{ option.id }}" {{ selected }}>{{ option.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">问题标签</label>
|
||||
<div class="layui-input-block">
|
||||
<div id="xm-tag-ids"></div>
|
||||
{% endif %}
|
||||
{% if xm_tags|length > 0 %}
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">问题标签</label>
|
||||
<div class="layui-input-block">
|
||||
<div id="xm-tag-ids"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn layui-btn-fluid kg-submit" lay-submit="true" lay-filter="go">确认发布</button>
|
||||
|
@ -114,4 +114,13 @@ class Common
|
||||
return $str == $date;
|
||||
}
|
||||
|
||||
public static function image($path)
|
||||
{
|
||||
$exts = ['png', 'gif', 'jpg', 'jpeg', 'webp'];
|
||||
|
||||
$ext = pathinfo($path, PATHINFO_EXTENSION);
|
||||
|
||||
return in_array(strtolower($ext), $exts);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -249,9 +249,7 @@ class Article extends Model
|
||||
|
||||
public function beforeSave()
|
||||
{
|
||||
if (empty($this->cover)) {
|
||||
$this->cover = kg_default_article_cover_path();
|
||||
} elseif (Text::startsWith($this->cover, 'http')) {
|
||||
if (Text::startsWith($this->cover, 'http')) {
|
||||
$this->cover = self::getCoverPath($this->cover);
|
||||
}
|
||||
|
||||
@ -269,7 +267,7 @@ class Article extends Model
|
||||
|
||||
public function afterFetch()
|
||||
{
|
||||
if (!Text::startsWith($this->cover, 'http')) {
|
||||
if (!empty($this->cover) && !Text::startsWith($this->cover, 'http')) {
|
||||
$this->cover = kg_cos_article_cover_url($this->cover);
|
||||
}
|
||||
|
||||
|
@ -351,9 +351,7 @@ class Course extends Model
|
||||
|
||||
public function beforeSave()
|
||||
{
|
||||
if (empty($this->cover)) {
|
||||
$this->cover = kg_default_course_cover_path();
|
||||
} elseif (Text::startsWith($this->cover, 'http')) {
|
||||
if (Text::startsWith($this->cover, 'http')) {
|
||||
$this->cover = self::getCoverPath($this->cover);
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ use App\Caches\MaxQuestionId as MaxQuestionIdCache;
|
||||
use App\Services\Sync\QuestionIndex as QuestionIndexSync;
|
||||
use App\Services\Sync\QuestionScore as QuestionScoreSync;
|
||||
use Phalcon\Mvc\Model\Behavior\SoftDelete;
|
||||
use Phalcon\Text;
|
||||
|
||||
class Question extends Model
|
||||
{
|
||||
@ -269,6 +270,10 @@ class Question extends Model
|
||||
|
||||
public function beforeSave()
|
||||
{
|
||||
if (Text::startsWith($this->cover, 'http')) {
|
||||
$this->cover = self::getCoverPath($this->cover);
|
||||
}
|
||||
|
||||
if (is_array($this->tags) || is_object($this->tags)) {
|
||||
$this->tags = kg_json_encode($this->tags);
|
||||
}
|
||||
@ -283,11 +288,24 @@ class Question extends Model
|
||||
|
||||
public function afterFetch()
|
||||
{
|
||||
if (!empty($this->cover) && !Text::startsWith($this->cover, 'http')) {
|
||||
$this->cover = kg_cos_article_cover_url($this->cover);
|
||||
}
|
||||
|
||||
if (is_string($this->tags)) {
|
||||
$this->tags = json_decode($this->tags, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getCoverPath($url)
|
||||
{
|
||||
if (Text::startsWith($url, 'http')) {
|
||||
return parse_url($url, PHP_URL_PATH);
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public static function publishTypes()
|
||||
{
|
||||
return [
|
||||
|
@ -26,7 +26,7 @@ class ArticleInfo extends LogicService
|
||||
{
|
||||
$article = $this->checkArticle($id);
|
||||
|
||||
$user = $this->getCurrentUser(true);
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
$result = $this->handleArticle($article, $user);
|
||||
|
||||
|
@ -14,6 +14,7 @@ use App\Repos\Article as ArticleRepo;
|
||||
use App\Services\Category as CategoryService;
|
||||
use App\Services\Logic\Service as LogicService;
|
||||
use App\Validators\ArticleQuery as ArticleQueryValidator;
|
||||
use Phalcon\Text;
|
||||
|
||||
class ArticleList extends LogicService
|
||||
{
|
||||
@ -77,10 +78,20 @@ class ArticleList extends LogicService
|
||||
|
||||
$items = [];
|
||||
|
||||
$baseUrl = kg_cos_url();
|
||||
|
||||
foreach ($articles as $article) {
|
||||
|
||||
$article['tags'] = json_decode($article['tags'], true);
|
||||
|
||||
if (empty($article['cover'])) {
|
||||
$article['cover'] = kg_default_article_cover_path();
|
||||
}
|
||||
|
||||
if (!Text::startsWith($article['cover'], 'http')) {
|
||||
$article['cover'] = $baseUrl . $article['cover'];
|
||||
}
|
||||
|
||||
$category = $categories[$article['category_id']] ?? new \stdClass();
|
||||
|
||||
$owner = $users[$article['owner_id']] ?? new \stdClass();
|
||||
|
@ -25,7 +25,7 @@ class CommentInfo extends LogicService
|
||||
{
|
||||
$comment = $this->checkComment($id);
|
||||
|
||||
$user = $this->getCurrentUser(true);
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
return $this->handleComment($comment, $user);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class ConsultInfo extends LogicService
|
||||
{
|
||||
$consult = $this->checkConsult($id);
|
||||
|
||||
$user = $this->getCurrentUser(true);
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
return $this->handleConsult($consult, $user);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ class ResourceList extends LogicService
|
||||
{
|
||||
$course = $this->checkCourse($id);
|
||||
|
||||
$user = $this->getCurrentUser(true);
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
$this->setCourseUser($course, $user);
|
||||
|
||||
|
@ -25,7 +25,7 @@ class QuestionInfo extends LogicService
|
||||
|
||||
public function handle($id)
|
||||
{
|
||||
$user = $this->getCurrentUser(true);
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
$question = $this->checkQuestion($id);
|
||||
|
||||
|
@ -14,6 +14,7 @@ use App\Repos\Question as QuestionRepo;
|
||||
use App\Services\Category as CategoryService;
|
||||
use App\Services\Logic\Service as LogicService;
|
||||
use App\Validators\QuestionQuery as QuestionQueryValidator;
|
||||
use Phalcon\Text;
|
||||
|
||||
class QuestionList extends LogicService
|
||||
{
|
||||
@ -77,8 +78,14 @@ class QuestionList extends LogicService
|
||||
|
||||
$items = [];
|
||||
|
||||
$cosUrl = kg_cos_url();
|
||||
|
||||
foreach ($questions as $question) {
|
||||
|
||||
if (!empty($question['cover']) && !Text::startsWith($question['cover'], 'http')) {
|
||||
$question['cover'] = $cosUrl . $question['cover'];
|
||||
}
|
||||
|
||||
$question['tags'] = json_decode($question['tags'], true);
|
||||
|
||||
$category = $categories[$question['category_id']] ?? new \stdClass();
|
||||
|
@ -26,7 +26,7 @@ class TradeInfo extends LogicService
|
||||
{
|
||||
$trade = $this->checkTradeBySn($sn);
|
||||
|
||||
$user = $this->getCurrentUser(true);
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
return $this->handleTrade($trade, $user);
|
||||
}
|
||||
|
@ -90,6 +90,17 @@ class Article extends Validator
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function checkCover($cover)
|
||||
{
|
||||
$value = $this->filter->sanitize($cover, ['trim', 'string']);
|
||||
|
||||
if (!CommonValidator::image($value)) {
|
||||
throw new BadRequestException('article.invalid_cover');
|
||||
}
|
||||
|
||||
return kg_cos_img_style_trim($value);
|
||||
}
|
||||
|
||||
public function checkSummary($summary)
|
||||
{
|
||||
$value = $this->filter->sanitize($summary, ['trim', 'string']);
|
||||
|
@ -106,7 +106,7 @@ class Course extends Validator
|
||||
{
|
||||
$value = $this->filter->sanitize($cover, ['trim', 'string']);
|
||||
|
||||
if (!CommonValidator::url($value)) {
|
||||
if (!CommonValidator::image($value)) {
|
||||
throw new BadRequestException('course.invalid_cover');
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ class Package extends Validator
|
||||
{
|
||||
$value = $this->filter->sanitize($cover, ['trim', 'string']);
|
||||
|
||||
if (!CommonValidator::url($value)) {
|
||||
if (!CommonValidator::image($value)) {
|
||||
throw new BadRequestException('package.invalid_cover');
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ class PointGift extends Validator
|
||||
{
|
||||
$value = $this->filter->sanitize($cover, ['trim', 'string']);
|
||||
|
||||
if (!CommonValidator::url($value)) {
|
||||
if (!CommonValidator::image($value)) {
|
||||
throw new BadRequestException('point_gift.invalid_cover');
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ class Slide extends Validator
|
||||
{
|
||||
$value = $this->filter->sanitize($cover, ['trim', 'string']);
|
||||
|
||||
if (!CommonValidator::url($value)) {
|
||||
if (!CommonValidator::image($value)) {
|
||||
throw new BadRequestException('slide.invalid_cover');
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ class Topic extends Validator
|
||||
{
|
||||
$value = $this->filter->sanitize($cover, ['trim', 'string']);
|
||||
|
||||
if (!CommonValidator::url($value)) {
|
||||
if (!CommonValidator::image($value)) {
|
||||
throw new BadRequestException('topic.invalid_cover');
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ class Vip extends Validator
|
||||
{
|
||||
$value = $this->filter->sanitize($cover, ['trim', 'string']);
|
||||
|
||||
if (!CommonValidator::url($value)) {
|
||||
if (!CommonValidator::image($value)) {
|
||||
throw new BadRequestException('vip.invalid_cover');
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user