forked from typecho/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.php
More file actions
78 lines (70 loc) · 2.13 KB
/
Plugin.php
File metadata and controls
78 lines (70 loc) · 2.13 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
<?php
/**
* 直接在在文章中插入[embed_snipt:{code_id}]({code_id}为snipt上面的id)就可引用http://snipt.org/上分享的代码
*
* @package ShareCode
* @author blankyao
* @version 1.0.0
* @link http://www.blankyao.cn
*/
class ShareCode_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
/** 前端输出处理接口 */
Typecho_Plugin::factory('Widget_Abstract_Contents')->content = array('ShareCode_Plugin', 'parse');
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerpt = array('ShareCode_Plugin', 'parse');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate(){}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form){}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
/**
* 解析内容
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function parse($value, $lastResult)
{
$value = empty($lastResult) ? $value : $lastResult;
$regex = '/\[embed_snipt:(.*?)]/i';
preg_match_all( $regex, $value, $matches);
$count = count($matches[0]);
for($i = 0;$i < $count;$i++) {
$url = $matches[1][$i];
$url = '<script type="text/javascript" src="http://embed.snipt.org/'. $url .'"></script>';
$value = str_replace($matches[0][$i], $url, $value);
}
return $value;
}
}