forked from chakhsu/lpisme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
106 lines (94 loc) · 4.56 KB
/
functions.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
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
96
97
98
99
100
101
102
103
104
105
106
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
function themeConfig($form) {
$slogan = new Typecho_Widget_Helper_Form_Element_Text('slogan', NULL, NULL, _t('logo旁边的标语'), _t('在这里输入标语'));
$form->addInput($slogan);
//社交链接
$socialweibo = new Typecho_Widget_Helper_Form_Element_Text('socialweibo', NULL, NULL, _t('输入微博链接'), _t('在这里输入微博链接,带http://'));
$form->addInput($socialweibo);
$socialgithub = new Typecho_Widget_Helper_Form_Element_Text('socialgithub', NULL, NULL, _t('输入GitHub链接'), _t('输入GitHub链接,带http://'));
$form->addInput($socialgithub);
$socialtwitter = new Typecho_Widget_Helper_Form_Element_Text('socialtwitter', NULL, NULL, _t('输入Twitter链接'), _t('在这里输入twitter链接,带http://'));
$form->addInput($socialtwitter);
$socialgoogle = new Typecho_Widget_Helper_Form_Element_Text('socialgoogle', NULL, NULL, _t('输入Google +链接'), _t('在这里输入Google +链接,带http://'));
$form->addInput($socialgoogle);
//附件源地址
$src_address = new Typecho_Widget_Helper_Form_Element_Text('src_add', NULL, NULL, _t('替换前地址'), _t('即你的附件存放链接,如http://www.yourblog.com/usr/uploads/'));
$form->addInput($src_address);
//替换后地址
$cdn_address = new Typecho_Widget_Helper_Form_Element_Text('cdn_add', NULL, NULL, _t('替换后'), _t('即你的七牛云存储域名,如http://yourblog.qiniudn.com/'));
$form->addInput($cdn_address);
//默认缩略图
$default = new Typecho_Widget_Helper_Form_Element_Text('default_thumb', NULL, '', _t('默认缩略图'),_t('文章没有图片时显示的默认缩略图,为空时表示不显示,如http://www.yourblog.com/image.png'));
$form->addInput($default);
//默认宽度
$width = new Typecho_Widget_Helper_Form_Element_Text('thumb_width', NULL, '600', _t('缩略图默认宽度'));
$form->addInput($width);
//默认高度
$height = new Typecho_Widget_Helper_Form_Element_Text('thumb_height', NULL, '100%', _t('缩略图默认高度'));
$form->addInput($height);
}
function showThumb($obj,$size=null,$link=false,$pattern='<div class="post-thumb"><a class="thumb" href="{permalink}" title="{title}" style="background-image:url({thumb})"></a></div>'){
preg_match_all( "/<[img|IMG].*?src=[\'|\"](.*?)[\'|\"].*?[\/]?>/", $obj->content, $matches );
$thumb = '';
$options = Typecho_Widget::widget('Widget_Options');
$attach = $obj->attachments(1)->attachment;
if (isset($attach->isImage)){
$thumb = $attach->url;
if(!empty($options->src_add) && !empty($options->cdn_add)){
$thumb = str_ireplace($options->src_add,$options->cdn_add,$thumb);
}
if($size!='full'){
$thumb_width = $options->thumb_width;
$thumb_height = $options->thumb_height;
if($size!=null){
$size = explode('x', $size);
if(!empty($size[0]) && !empty($size[1])){
list($thumb_width,$thumb_height) = $size;
}
}
$thumb .= '?imageView2/4/w/'.$thumb_width.'/h/'.$thumb_height;
}
}elseif(isset($matches[1][0])){
$thumb = $matches[1][0];
if(!empty($options->src_add) && !empty($options->cdn_add)){
$thumb = str_ireplace($options->src_add,$options->cdn_add,$thumb);
}
if($size!='full'){
$thumb_width = $options->thumb_width;
$thumb_height = $options->thumb_height;
if($size!=null){
$size = explode('x', $size);
if(!empty($size[0]) && !empty($size[1])){
list($thumb_width,$thumb_height) = $size;
}
}
$thumb .= '?imageView2/4/w/'.$thumb_width.'/h/'.$thumb_height;
}
}
if(empty($thumb) && empty($options->default_thumb)){
return '';
}else{
$thumb = empty($thumb) ? $options->default_thumb : $thumb;
}
if($link){
return $thumb;
}
echo str_replace(
array('{title}','{thumb}','{permalink}'),
array($obj->title,$thumb,$obj->permalink),
$pattern);
}
/**
* 解析内容以实现附件加速
* @access public
* @param string $content 文章正文
* @param Widget_Abstract_Contents $obj
*/
function parseContent($obj){
$options = Typecho_Widget::widget('Widget_Options');
if(!empty($options->src_add) && !empty($options->cdn_add)){
$obj->content = str_ireplace($options->src_add,$options->cdn_add,$obj->content);
}
echo trim($obj->content);
}