mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-03-03 16:24:28 +08:00
优化网站性能;
This commit is contained in:
@@ -20,7 +20,11 @@ class Category extends Base
|
||||
[
|
||||
'name' => 'category_type_list',
|
||||
'field' => 'type'
|
||||
]
|
||||
],
|
||||
[
|
||||
'type' => 'tag',
|
||||
'name' => 'page_cache'
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,11 @@ class Nav extends Base
|
||||
'type' => 'key',
|
||||
'name' => 'type_list',
|
||||
'field' => 'type'
|
||||
]
|
||||
],
|
||||
[
|
||||
'type' => 'tag',
|
||||
'name' => 'page_cache'
|
||||
],
|
||||
];
|
||||
|
||||
public static $statusName = [
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use app\common\model\Base;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Request;
|
||||
use think\Model;
|
||||
@@ -13,161 +14,171 @@ use think\Paginator;
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class Post extends Model
|
||||
class Post extends Base
|
||||
{
|
||||
//
|
||||
//
|
||||
|
||||
public static $stausNameList = [
|
||||
0 => '不发布',
|
||||
1 => '发布'
|
||||
];
|
||||
public static $autoClearCache = [
|
||||
[
|
||||
'name' => 'top_post'
|
||||
],
|
||||
[
|
||||
'type' => 'tag',
|
||||
'name' => 'page_cache'
|
||||
],
|
||||
];
|
||||
|
||||
use SoftDelete;
|
||||
public static $stausNameList = [
|
||||
0 => '不发布',
|
||||
1 => '发布'
|
||||
];
|
||||
|
||||
protected $defaultSoftDelete = 0;
|
||||
use SoftDelete;
|
||||
|
||||
public function categorys()
|
||||
{
|
||||
return $this->hasMany(PostCategory::class, 'post_id');
|
||||
}
|
||||
protected $defaultSoftDelete = 0;
|
||||
|
||||
public function tags()
|
||||
{
|
||||
return $this->hasMany(PostTag::class, 'post_id');
|
||||
}
|
||||
|
||||
public function comments()
|
||||
{
|
||||
return $this->hasMany(PostComment::class,'post_id');
|
||||
}
|
||||
|
||||
|
||||
public function getCommentCountAttr()
|
||||
{
|
||||
|
||||
|
||||
|
||||
return PostComment::getPostCommentsCount($this->getData('id'));
|
||||
}
|
||||
|
||||
public function setPublishTimeAttr($value)
|
||||
{
|
||||
return strtotime($value);
|
||||
}
|
||||
public function getPublishTimeTextAttr()
|
||||
{
|
||||
|
||||
$value = $this->getData('publish_time');
|
||||
return date('Y-m-d', $value);
|
||||
}
|
||||
public function getPublishTimeDatetimeAttr()
|
||||
{
|
||||
|
||||
$value = $this->getData('publish_time');
|
||||
return date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
|
||||
public function getCategorysListAttr()
|
||||
{
|
||||
$list_post_categorys = $this->getAttr('categorys');
|
||||
|
||||
$list = array_column($list_post_categorys->append(['category'])->toArray(), 'category');
|
||||
|
||||
$list = array2level($list, 0, 0);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getTagsListAttr()
|
||||
{
|
||||
$list_post_tags = $this->getAttr('tags');
|
||||
|
||||
$list = array_column($list_post_tags->append(['tag'])->toArray(), 'tag');
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getDescShortAttr()
|
||||
{
|
||||
$desc = $this->getData('desc');
|
||||
|
||||
if (strlen($desc) > 100) {
|
||||
$desc = mb_substr($desc, 0, 100) . '...';
|
||||
public function categorys()
|
||||
{
|
||||
return $this->hasMany(PostCategory::class, 'post_id');
|
||||
}
|
||||
|
||||
return $desc;
|
||||
}
|
||||
|
||||
public function getDescListAttr()
|
||||
{
|
||||
$desc = $this->getData('desc');
|
||||
|
||||
if (empty($desc)) {
|
||||
return '';
|
||||
}
|
||||
$list = explode("\n", $desc);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getDescHtmlAttr()
|
||||
{
|
||||
$desc = $this->getData('desc');
|
||||
|
||||
if (empty($desc)) {
|
||||
return '';
|
||||
public function tags()
|
||||
{
|
||||
return $this->hasMany(PostTag::class, 'post_id');
|
||||
}
|
||||
|
||||
return str_replace("\n", '<br>', $desc);
|
||||
}
|
||||
|
||||
public function getStatusNameAttr()
|
||||
{
|
||||
return self::$stausNameList[$this->getData('status')];
|
||||
}
|
||||
|
||||
public function setPubishTimeAttr($value)
|
||||
{
|
||||
return strtotime($value);
|
||||
}
|
||||
|
||||
public function setContentAttr($value)
|
||||
{
|
||||
return json_encode($value);
|
||||
}
|
||||
public function setContentHtmlAttr($value)
|
||||
{
|
||||
return trim($value);
|
||||
}
|
||||
|
||||
public function getContentAttr($value)
|
||||
{
|
||||
return json_decode($value, true);
|
||||
}
|
||||
|
||||
public function getPosterAttr($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
$value = '/static/images/avatar.jpeg';
|
||||
public function comments()
|
||||
{
|
||||
return $this->hasMany(PostComment::class, 'post_id');
|
||||
}
|
||||
|
||||
return get_source_link($value);
|
||||
}
|
||||
|
||||
public function getReadUrlAttr()
|
||||
{
|
||||
public function getCommentCountAttr()
|
||||
{
|
||||
|
||||
return Request::domain() . '/index/a' . $this->getData('uid') . '.html';
|
||||
}
|
||||
|
||||
public function getShareTextAttr()
|
||||
{
|
||||
$share_text = get_system_config('post_share_text_tpl');
|
||||
|
||||
$share_text = str_replace('%post_title%', $this->getAttr('title'), $share_text);
|
||||
$share_text = str_replace('%post_desc%', $this->getAttr('desc'), $share_text);
|
||||
$share_text = str_replace('%post_url%', $this->getAttr('read_url'), $share_text);
|
||||
return PostComment::getPostCommentsCount($this->getData('id'));
|
||||
}
|
||||
|
||||
return $share_text;
|
||||
}
|
||||
public function setPublishTimeAttr($value)
|
||||
{
|
||||
return strtotime($value);
|
||||
}
|
||||
public function getPublishTimeTextAttr()
|
||||
{
|
||||
|
||||
$value = $this->getData('publish_time');
|
||||
return date('Y-m-d', $value);
|
||||
}
|
||||
public function getPublishTimeDatetimeAttr()
|
||||
{
|
||||
|
||||
$value = $this->getData('publish_time');
|
||||
return date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
|
||||
public function getCategorysListAttr()
|
||||
{
|
||||
$list_post_categorys = $this->getAttr('categorys');
|
||||
|
||||
$list = array_column($list_post_categorys->append(['category'])->toArray(), 'category');
|
||||
|
||||
$list = array2level($list, 0, 0);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getTagsListAttr()
|
||||
{
|
||||
$list_post_tags = $this->getAttr('tags');
|
||||
|
||||
$list = array_column($list_post_tags->append(['tag'])->toArray(), 'tag');
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getDescShortAttr()
|
||||
{
|
||||
$desc = $this->getData('desc');
|
||||
|
||||
if (strlen($desc) > 100) {
|
||||
$desc = mb_substr($desc, 0, 100) . '...';
|
||||
}
|
||||
|
||||
return $desc;
|
||||
}
|
||||
|
||||
public function getDescListAttr()
|
||||
{
|
||||
$desc = $this->getData('desc');
|
||||
|
||||
if (empty($desc)) {
|
||||
return '';
|
||||
}
|
||||
$list = explode("\n", $desc);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getDescHtmlAttr()
|
||||
{
|
||||
$desc = $this->getData('desc');
|
||||
|
||||
if (empty($desc)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return str_replace("\n", '<br>', $desc);
|
||||
}
|
||||
|
||||
public function getStatusNameAttr()
|
||||
{
|
||||
return self::$stausNameList[$this->getData('status')];
|
||||
}
|
||||
|
||||
public function setPubishTimeAttr($value)
|
||||
{
|
||||
return strtotime($value);
|
||||
}
|
||||
|
||||
public function setContentAttr($value)
|
||||
{
|
||||
return json_encode($value);
|
||||
}
|
||||
public function setContentHtmlAttr($value)
|
||||
{
|
||||
return trim($value);
|
||||
}
|
||||
|
||||
public function getContentAttr($value)
|
||||
{
|
||||
return json_decode($value, true);
|
||||
}
|
||||
|
||||
public function getPosterAttr($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
$value = '/static/images/avatar.jpeg';
|
||||
}
|
||||
|
||||
return get_source_link($value);
|
||||
}
|
||||
|
||||
public function getReadUrlAttr()
|
||||
{
|
||||
|
||||
return Request::domain() . '/index/a' . $this->getData('uid') . '.html';
|
||||
}
|
||||
|
||||
public function getShareTextAttr()
|
||||
{
|
||||
$share_text = get_system_config('post_share_text_tpl');
|
||||
|
||||
$share_text = str_replace('%post_title%', $this->getAttr('title'), $share_text);
|
||||
$share_text = str_replace('%post_desc%', $this->getAttr('desc'), $share_text);
|
||||
$share_text = str_replace('%post_url%', $this->getAttr('read_url'), $share_text);
|
||||
|
||||
return $share_text;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user