完成显示水印功能;

This commit is contained in:
2024-02-18 15:41:14 +08:00
parent a59b124e70
commit aa9ae7f30b
8 changed files with 150 additions and 32 deletions

View File

@@ -5,36 +5,45 @@ declare(strict_types=1);
namespace app\model;
use app\common\model\Base;
use app\common\tools\Image;
/**
* @mixin think\Model
*/
class Nav extends Base
{
public static $autoClearCache = [
[
'type' => 'key',
'name' => 'type_list',
'field' => 'type'
'field' => 'type',
],
[
'type' => 'tag',
'name' => 'page_cache'
'name' => 'page_cache',
],
];
public static $statusName = [
0 => '不显示',
1 => '显示'
1 => '显示',
];
//
public function getImgAttr($value)
{
return get_source_link($value);
}
public function getImgShowAttr()
{
$src = $this->getData('img');
$watermarked_file_save_name = Image::handelWatermarkSave($src);
return $watermarked_file_save_name;
}
public function getStatusNameAttr()
{
return self::$statusName[$this->getData('status')];

View File

@@ -5,15 +5,14 @@ declare(strict_types=1);
namespace app\model;
use app\common\model\Base;
use app\common\tools\Image;
use app\common\tools\PostBlock;
use app\common\tools\PostShow;
use League\HTMLToMarkdown\Converter\TableConverter;
use League\HTMLToMarkdown\HtmlConverter;
use think\facade\Cache;
use think\facade\Request;
use think\Model;
use think\model\concern\SoftDelete;
use think\Paginator;
/**
* @mixin think\Model
@@ -23,7 +22,6 @@ class Post extends Base
use SoftDelete;
//
public const CACHE_KEY_HITS = 'cache_hits_';
public static $autoClearCache = [
@@ -32,7 +30,7 @@ class Post extends Base
public static $stausNameList = [
0 => '不发布',
1 => '发布'
1 => '发布',
];
protected $defaultSoftDelete = 0;
@@ -52,7 +50,6 @@ class Post extends Base
return $this->hasMany(PostComment::class, 'post_id');
}
public function getCommentCountAttr()
{
return PostComment::getPostCommentsCount($this->getData('id'));
@@ -62,16 +59,18 @@ class Post extends Base
{
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);
}
@@ -97,8 +96,7 @@ class Post extends Base
public function getDescAttr($value)
{
if(empty($value)) {
if (empty($value)) {
}
return $value;
@@ -157,11 +155,9 @@ class Post extends Base
{
$content_html = $this->getAttr('content_html');
$content_html .= PostBlock::copyright($this);
$converter = new HtmlConverter(array('strip_tags' => true));
$converter = new HtmlConverter(['strip_tags' => true]);
$converter->getEnvironment()->addConverter(new TableConverter());
@@ -172,9 +168,10 @@ class Post extends Base
public function getContentHtmlShowAttr()
{
$content = $this->getAttr('content_html');
$content = PostShow::handleImage($content);
return PostShow::handleCopyright($content);
}
@@ -187,6 +184,15 @@ class Post extends Base
return get_source_link($value);
}
public function getPosterShowAttr()
{
$poster = $this->getAttr('poster');
$watermarked_file_save_name = Image::handelWatermarkSave($poster);
return $watermarked_file_save_name;
}
public function getReadUrlAttr()
{
$path = '/index/a' . $this->getData('uid') . '.html';
@@ -211,7 +217,7 @@ class Post extends Base
$list_post_category_id = $this->getAttr('categorys')->column('category_id');
$list_start_post = Post::where('category_id', 'in', $list_post_category_id)->where('type', 'category-start')->cacheAlways(600)->where('status', 1)->select();
$list_start_post = self::where('category_id', 'in', $list_post_category_id)->where('type', 'category-start')->cacheAlways(600)->where('status', 1)->select();
foreach ($list_start_post as $k_start_post => $v_start_post) {
$start_content .= $v_start_post->content_html;
@@ -224,20 +230,21 @@ class Post extends Base
{
$end_content = '';
$list_post_category_id = $this->getAttr('categorys')->column('category_id');
$list_end_post = Post::where('category_id', 'in', $list_post_category_id)->where('type', 'category-end')->cacheAlways(600)->where('status', 1)->select();
$list_end_post = self::where('category_id', 'in', $list_post_category_id)->where('type', 'category-end')->cacheAlways(600)->where('status', 1)->select();
foreach ($list_end_post as $k_end_post => $v_end_post) {
$end_content.= $v_end_post->content_html;
$end_content .= $v_end_post->content_html;
}
return $end_content;
}
public function getHitsTitleAttr()
{
$cache_key = static::CACHE_KEY_HITS.$this->getAttr('id');
$cache_key = static::CACHE_KEY_HITS . $this->getAttr('id');
$value = Cache::get($cache_key);
if(!is_null($value)) {
if (!is_null($value)) {
return $value;
}
@@ -250,7 +257,7 @@ class Post extends Base
public function setHitsAttr($value)
{
$cache_key = static::CACHE_KEY_HITS.$this->getAttr('id');
$cache_key = static::CACHE_KEY_HITS . $this->getAttr('id');
$this->getAttr('hits_title');
Cache::inc($cache_key);