-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.php
67 lines (59 loc) · 2.06 KB
/
Plugin.php
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
<?php
/**
* 一个基于 prism.js 的语法着色工具
*
* @package PrismSyntaxHighlighter
* @author guyanyijiu
* @version 1.0.0
* @link https://www.guyanyijiu.com
*/
class PrismSyntaxHighlighter_Plugin implements Typecho_Plugin_Interface {
private static $name = 'PrismSyntaxHighlighter';
public static function activate() {
Typecho_Plugin::factory('Widget_Archive')->header = [__CLASS__, 'addCss'];
Typecho_Plugin::factory('Widget_Archive')->footer = [__CLASS__, 'addJs'];
}
public static function deactivate() {
}
public static function config(Typecho_Widget_Helper_Form $form) {
$theme = new Typecho_Widget_Helper_Form_Element_Select('theme',
[
'default' => 'Default',
'dark' => 'Dark',
'funky' => 'Funky',
'okaidia' => 'Okaidia',
'twilight' => 'Twilight',
'coy' => 'Coy',
'solarizedlight' => 'Solarized Light',
'tomorrow' => 'Tomorrow Night',
'github' => 'Github',
'darcula' => 'IntelliJ Darcula',
'atom-dark' => 'Atom dark',
],
'default', _t('选择主题'), null);
$form->addInput($theme);
}
public static function personalConfig(Typecho_Widget_Helper_Form $form) {
}
/**
* 添加 css
*
* @throws Typecho_Plugin_Exception
*
* @author guyanyijiu
*/
public static function addCss() {
$settings = Helper::options()->plugin(self::$name);
$url = Helper::options()->pluginUrl . '/' . self::$name . '/css/prism-' . $settings->theme . '.css';
echo '<link href="' . $url . '" rel="stylesheet" />';
}
/**
* 添加 js
*
* @author guyanyijiu
*/
public static function addJs() {
$url = Helper::options()->pluginUrl . '/' . self::$name . '/js/prism.js';;
echo '<script type="text/javascript" src="' . $url . '"></script>';
}
}