-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.php
More file actions
92 lines (83 loc) · 2.71 KB
/
Copy pathPlugin.php
File metadata and controls
92 lines (83 loc) · 2.71 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
<?php
/**
* LightPrismJs 代码高亮插件
*
* @package LightPrismJs
* @author Allan
* @version 1.0.0
* @link https://home.mydata.top:8683
*/
class LightPrismJs_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*/
public static function activate()
{
Typecho_Plugin::factory('Widget_Archive')->header = array('LightPrismJs_Plugin', 'header');
Typecho_Plugin::factory('Widget_Archive')->footer = array('LightPrismJs_Plugin', 'footer');
echo "success";
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*/
public static function deactivate(){}
/**
* 获取插件配置面板
*
* @param Form $form 配置面板
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
/** 分类名称 */
$themes = array_map(function ($item) {
$filename = basename($item);
return str_replace('.js', '', $filename);
}, glob(dirname(__FILE__) . '/prism/*.js'));
$themes = array_combine($themes, $themes);
$theme = new Typecho_Widget_Helper_Form_Element_Select('theme', $themes, 'default',
_t('代码配色样式'));
$form->addInput($theme->addRule('enum', _t('必须选择配色样式'), $themes));
}
/**
* 个人用户的配置面板
*
* @param Form $form
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
/**
* 输出头部css
*
* @access public
* @param unknown $header
* @return unknown
*/
public static function header() {
$cssUrl = Helper::options()->pluginUrl . '/LightPrismJs/prism/' . Helper::options()->plugin('LightPrismJs')->theme . ".css";
echo '<link rel="stylesheet" type="text/css" href="' . $cssUrl . '" />';
$cssUrl = Helper::options()->pluginUrl . '/LightPrismJs/res/style.css';
echo '<link rel="stylesheet" type="text/css" href="' . $cssUrl . '" />';
}
/**
* 输出尾部js
*
* @access public
* @param unknown $header
* @return unknown
*/
public static function footer() {
$jsUrl = Helper::options()->pluginUrl . '/LightPrismJs/prism/' . Helper::options()->plugin('LightPrismJs')->theme . ".js";
echo '<script type="text/javascript" src="'. $jsUrl .'"></script>';
echo <<<TXT
<script type="text/javascript">
(function(){
let pres = document.querySelectorAll('pre');
let lineNumberClassName = 'line-numbers';
pres.forEach(function (item, index) {
item.className = item.className == '' ? lineNumberClassName : item.className + ' ' + lineNumberClassName;
});
})();
</script>
TXT;
}
}