Repository navigation
Expand file tree
/
Copy pathPlugin.php
More file actions
95 lines (83 loc) · 2.42 KB
/
Copy pathPlugin.php
File metadata and controls
95 lines (83 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace TypechoPlugin\Spoiler;
use Typecho\Plugin\PluginInterface;
use Typecho\Widget\Helper\Form;
use Typecho\Widget\Helper\Form\Element\Radio;
use Widget\Archive;
if (!defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
/**
* 敏感内容遮罩,由后端直接渲染,不会短暂显示内容
*
* @package Spoiler
* @author Ect07
* @version 1.0.0
* @since 1.3.0
* @link https://ect.fyi/
*/
class Plugin implements PluginInterface
{
/**
* 激活插件方法
*/
public static function activate()
{
}
/**
* 禁用插件方法
*/
public static function deactivate()
{
}
/**
* 获取插件配置面板
*/
public static function config(Form $form)
{
$enableHtmlComments = new Radio('enableHtmlComments', array('0'=> '禁用', '1'=> '启用'), 1, 'HTML注释语法',
nl2br(htmlspecialchars("使用形如“
!!!
<!--SPOILER
本文章可能含有轻度的性暗示/血腥暴力/自伤自残等
使您感到轻微不适的内容。
请确定您的年龄与心智适宜阅读。
-->
!!!
”的语法创建一个遮罩。")));
$enableNoteTags = new Radio('enableNoteTags', array('0'=> '禁用', '1'=> '启用'), 1, '检测note标签',
nl2br(htmlspecialchars("检测页面的 [note type=\"warning\"] / [note type=\"danger\"] 来自动创建遮罩。
实际上它只检测HTML输出中同时含有 note 和 warning / danger 类的元素。Butterfly等主题会自动输出这些类。
在它们同时存在时,遮罩文案优先级为 SPOILER注释 > danger > warning 。")));
$form->addInput($enableHtmlComments);
$form->addInput($enableNoteTags);
}
/**
* 个人用户的配置面板
*/
public static function personalConfig(Form $form)
{
}
/**
* 根据上下文获取文章信息,渲染 Spoiler 遮罩
*/
public static function smartSpoiler()
{
$archive = Archive::alloc();
$archiveContent = $archive->content;
$archiveText = $archive->text;
include "smart-spoiler.php";
}
/**
* 手动传入 text 和 content,渲染 Spoiler 遮罩
*
* @param string $text 页面纯文本内容
* @param string $content 页面 HTML 内容
*/
public static function lessSmartSpoiler($text, $content)
{
$archiveContent = $content;
$archiveText = $text;
include "smart-spoiler.php";
}
}