mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-03-03 16:24:28 +08:00
完成防采集版权声明;
This commit is contained in:
45
app/common/tools/PostShow.php
Normal file
45
app/common/tools/PostShow.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\tools;
|
||||
|
||||
use phpQuery;
|
||||
|
||||
class PostShow
|
||||
{
|
||||
public static function handleCopyright($content)
|
||||
{
|
||||
|
||||
// 防采集版权声明,被采集了会在其他网站显示
|
||||
// 可以被选中复制,可以被采集,在网页中不会显示,但是在别的网站中可以显示
|
||||
$content_copyright = '<blockquote class="post-content-inner-copyright"> 版权声明:' . get_system_config('post_copyright') . '</blockquote>';
|
||||
|
||||
// 防采集版权声明,被采集了也不会在其他网站显示
|
||||
// 可以被选中复制,可以被采集,在网页中不会显示,在别的网站中也不会显示
|
||||
$content_copyright_hide = '<p style="height:0;line-height: 0;margin:0;padding:0;overflow: hidden;margin-block-start:0;margin-block-end:0;position: absolute;">版权声明:' . get_system_config('post_copyright') . '</p>';
|
||||
|
||||
$dom_copyright = phpQuery::newDocumentHTML($content_copyright);
|
||||
|
||||
$dom_copyright_hide = phpQuery::newDocumentHTML($content_copyright_hide);
|
||||
|
||||
$dom_content = phpQuery::newDocumentHTML($content);
|
||||
|
||||
// 找到子元素p
|
||||
$p_list = $dom_content->children('p');
|
||||
|
||||
foreach ($p_list as $index_p => $dom_p) {
|
||||
|
||||
if ($index_p != 0 && $index_p % 8 == 0) {
|
||||
|
||||
// $dom_copyright->clone()->children()->insertAfter($dom_p);
|
||||
}
|
||||
if ($index_p != 0 && $index_p % 6 == 0) {
|
||||
|
||||
$dom_copyright_hide->clone()->children()->insertAfter($dom_p);
|
||||
}
|
||||
}
|
||||
|
||||
$content = $dom_content->html();
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace app\model;
|
||||
|
||||
use app\common\model\Base;
|
||||
use app\common\tools\PostShow;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Request;
|
||||
use think\Model;
|
||||
@@ -151,6 +152,14 @@ class Post extends Base
|
||||
return trim($value);
|
||||
}
|
||||
|
||||
public function getContentHtmlShowAttr()
|
||||
{
|
||||
|
||||
$content = $this->getAttr('content_html');
|
||||
|
||||
return PostShow::handleCopyright($content);
|
||||
}
|
||||
|
||||
public function getContentAttr($value)
|
||||
{
|
||||
return json_decode($value, true);
|
||||
|
||||
@@ -27,7 +27,9 @@
|
||||
"topthink/think-captcha": "^3.0",
|
||||
"topthink/think-multi-app": "^1.0",
|
||||
"ulthon/user_hub_client": "^1.0",
|
||||
"thepixeldeveloper/sitemap": "^5.1"
|
||||
"thepixeldeveloper/sitemap": "^5.1",
|
||||
"jaeger/querylist": "^4.2",
|
||||
"jaeger/phpquery-single": "^1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/var-dumper": "^4.2"
|
||||
|
||||
@@ -385,4 +385,15 @@ a.post-item:visited {
|
||||
|
||||
.post-event-body img {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.post-content-inner-copyright {
|
||||
height : 0;
|
||||
line-height : 0;
|
||||
margin : 0;
|
||||
padding : 0;
|
||||
overflow : hidden;
|
||||
margin-block-start: 0;
|
||||
margin-block-end : 0;
|
||||
position : absolute;
|
||||
}
|
||||
@@ -125,7 +125,7 @@
|
||||
{/if}
|
||||
<div class="">
|
||||
<article class="ul-content entry heti heti--classic">
|
||||
{$post->content_html|raw}
|
||||
{$post->content_html_show|raw}
|
||||
|
||||
{:\\app\\common\\tools\\PostBlock::copyright($post)}
|
||||
</article>
|
||||
|
||||
Reference in New Issue
Block a user