前言
本文不涉及spimes主题文件的分享,只是提供了魔改后的functions.PHP | post.php | setjs.js
文件的下载,如有侵犯到作者的权益,请联系我删除本文。
增加了功能
-
设置外观里可以自定义Gravatar源,不用再去改代码了,推荐gravatar源:
https://cdn.zhuchunshu.com/avatar/ https://cdn.v2ex.com/gravatar/ https://gravatar.loli.net/avatar/8406d089bc81b664a2610b8d214c1428 https://secure.gravatar.com/avatar/
- 增加了文章内附件下载功能,可以选择链接(文件)类型为直链、百度网盘或是蓝奏云
可以设置文件下载权限为:所有人均可下载或者是登陆后下载
当链接类型为直链时会直接跳转到下载链接
当链接类型为百度网盘和蓝奏网盘时会弹出一个layer提示窗,询问下载
后续会写当文件类型为百度网盘时,弹窗提示显示文件大小并询问是否下载,蓝奏也一样
开始修改
打开主题functions.php文件,把代码:
$download = new typecho_Widget_Helper_Form_Element_Radio('download',
array(true => _t('启用'),
false => _t('关闭')),
false, _t('文件下载'), _t('默认关闭,启用则会在文章内文件下载按钮'));
$layout->addItem($download);
$downloads = new Typecho_Widget_Helper_Form_Element_Select('downloads',
array('link1'=>'直链',
'link2'=>'百度网盘',
'link3'=>'蓝奏网盘'),
'link1','链接(文件)类型','默认:文件直链,如果上面的文件下载选项为关闭则不用管这个');
$layout->addItem($downloads);
$downloadquanxian = new Typecho_Widget_Helper_Form_Element_Select('downloadquanxian',
array('1'=>'所有人',
'2'=>'登录后'),
'1','文件下载权限','默认:1,所有人都可以下载此文件');
$layout->addItem($downloadquanxian);
$downloadurl = new Typecho_Widget_Helper_Form_Element_Text('downloadurl', NULL, NULL, _t('文件下载链接'), _t('在这里填入一个文件 URL 地址, 如果不开启文件下载功能,则不用管这个'));
$downloadurl->input->setAttribute('class', 'w-100 setfb');
$layout->addItem($downloadurl);
$downloadpass = new Typecho_Widget_Helper_Form_Element_Text('downloadpass', NULL, NULL, _t('文件分享密码'), _t('在这里填入一个文件分享密码, 如果不开启文件下载功能,则不用管这个,如果文件没设置分享密码,也不用管这个'));
$downloadpass->input->setAttribute('class', 'w-100 setfb');
$layout->addItem($downloadpass);
插入到
$pdmapis = Helper::options()->pdmapi;
if ($pdmapis != '0'){
$dmlog = new Typecho_Widget_Helper_Form_Element_Radio('dmlog',
array('tepaly' => _t('主题播放器'),
'dmpaly' => _t('弹幕播放器')),
'tepaly', _t('主题播放器'), _t('默认为主题播放器,弹幕播放器则需要配置数据库系统文件后再使用'));
$layout->addItem($dmlog);
}
后面,也就是330行左右
再把代码:
$gv = new Typecho_Widget_Helper_Form_Element_Text('gravatar', NULL, 'https://cdn.zhuchunshu.com/avatar/', _t('Gravatar源'), _t('自定义Gravatar源,例如https://cdn.zhuchunshu.com/avatar/'));
$form->addInput($gv);
插入到
$favicon = new Typecho_Widget_Helper_Form_Element_Text('favicon', NULL, NULL, _t('favicon地址'), _t('一般为http://www.yourblog.com/image.png,支持 https:// 或 //,留空则不设置favicon'));
$form->addInput($favicon);
后面,也就是functions.php文件107行左右。
再找到functions.php文件502行左右的代码:
//获取Gravatar头像 QQ邮箱取用qq头像
function getGravatar($email, $s = 96, $d = 'mp', $r = 'g', $img = false, $atts = array())
{
preg_match_all('/((\d)*)@qq.com/', $email, $vai);
if (empty($vai['1']['0'])) {
$url = "https://cdn.v2ex.com/gravatar/"
$url .= md5(strtolower(trim($email)));
$url .= "?s=$s&d=$d&r=$r";
if ($img) {
$url = '<img src="' . $url . '"';
foreach ($atts as $key => $val)
$url .= ' ' . $key . '="' . $val . '"';
$url .= ' />';
}
}else{
$url = 'https://q2.qlogo.cn/headimg_dl?dst_uin='.$vai['1']['0'].'&spec=100';
}
return $url;
}
修改成:
//获取Gravatar头像 QQ邮箱取用qq头像
function getGravatar($email, $s = 96, $d = 'mp', $r = 'g', $img = false, $atts = array())
{
preg_match_all('/((\d)*)@qq.com/', $email, $vai);
if (empty($vai['1']['0'])) {
$url = Helper::options()->gravatar;
$url .= md5(strtolower(trim($email)));
$url .= "?s=$s&d=$d&r=$r";
if ($img) {
$url = '<img src="' . $url . '"';
foreach ($atts as $key => $val)
$url .= ' ' . $key . '="' . $val . '"';
$url .= ' />';
}
}else{
$url = 'https://q2.qlogo.cn/headimg_dl?dst_uin='.$vai['1']['0'].'&spec=100';
}
return $url;
}
保存即可,那么我们到现在已经完成了对functions.php文件的魔改
接下来修改主题的post.php
文件
打开post.php文件在62行
<div class="showall" >-- 展开阅读全文 --</div>
<?php endif; ?>
</div>
代码后面另起一行插入:
<?php if ($this->fields->download=="1"): ?>
<script src="https://www.layuicdn.com/layer/layer.js"></script>
<script src="https://cdn.bootcss.com/clipboard.js/2.0.6/clipboard.js"></script>
<link rel="stylesheet" type="text/css" href="https://assets.zhuchunshu.com/pan%2Fup1_zcs%2Fuploads%2F2020%2F06%2F22%2FuJz6nfRl_buttons.css">
<?php if ($this->fields->downloadquanxian=="1"): ?>
<center><p><a id="downloadbut" class="button button-primary button-rounded">下载本文附件</a></p></center>
<script type="text/JavaScript">
$(function(){
$("#downloadbut").click(function(){
var type = "<?php echo $this->fields->downloads; ?>";
var downloadurl = "<?php echo $this->fields->downloadurl; ?>";
var downloadpass = "<?php echo $this->fields->downloadpass; ?>";
var loginhas = "<?php echo $this->user->hasLogin(); ?>";
var quanxian = "<?php echo $this->fields->downloadquanxian; ?>";
if (downloadpass) {
var pass = "文件分享密码: "+downloadpass;
}else{
var pass ="此分享链接未设置密码访问";
}
switch (type) {
case 'link1':
location.href=downloadurl;
break;
case 'link2':
// 百度
layer.confirm('百度网盘下载链接:<br><a href="'+downloadurl+'"><font color="#46A3FF">'+downloadurl+'</font></a><br><br>'+pass, {
btn: ['下载','关闭'] //按钮
}, function(){
location.href=downloadurl;
}, function(){
});
break;
case 'link3':
//蓝奏
layer.confirm('蓝奏网盘下载链接:<br><a href="'+downloadurl+'"><font color="#46A3FF">'+downloadurl+'</font></a><br><br>'+pass, {
btn: ['下载','关闭'] //按钮
}, function(){
location.href=downloadurl;
}, function(){
});
break;
default:
alert("出错了");
break;
}
});
})
</script>
<?php else: ?>
<?php if ($this->fields->downloadquanxian=="2"): ?>
<?php if ($this->user->hasLogin()): ?>
<center><p><a id="downloadbut" class="button button-primary button-rounded">下载本文附件</a></p></center>
<script type="text/javascript">
$(function(){
$("#downloadbut").click(function(){
var type = "<?php echo $this->fields->downloads; ?>";
var downloadurl = "<?php echo $this->fields->downloadurl; ?>";
var downloadpass = "<?php echo $this->fields->downloadpass; ?>";
var loginhas = "<?php echo $this->user->hasLogin(); ?>";
var quanxian = "<?php echo $this->fields->downloadquanxian; ?>";
if (downloadpass) {
var pass = "文件分享密码: "+downloadpass;
}else{
var pass ="此分享链接未设置密码访问";
}
switch (type) {
case 'link1':
location.href=downloadurl;
break;
case 'link2':
// 百度
layer.confirm('百度网盘下载链接:<br><a href="'+downloadurl+'"><font color="#46A3FF">'+downloadurl+'</font></a><br><br>'+pass, {
btn: ['下载','关闭'] //按钮
}, function(){
location.href=downloadurl;
}, function(){
});
break;
case 'link3':
//蓝奏
layer.confirm('蓝奏网盘下载链接:<br><a href="'+downloadurl+'"><font color="#46A3FF">'+downloadurl+'</font></a><br><br>'+pass, {
btn: ['下载','关闭'] //按钮
}, function(){
location.href=downloadurl;
}, function(){
});
break;
default:
alert("出错了");
break;
}
});
})
</script>
<?php else: ?>
<center><p><a href="<?php $this->options->adminUrl('login.php'); ?>" class="button button-primary button-rounded">本文附件登陆后可下载</a></p></center>
<?php endif ?>
<?php endif ?>
<?php endif ?>
<?php endif ?>
保存后我们就完成了对post.php文件的魔改,最后打开usr/themes/spimes/assets/css/setjs.js
文件,
把第14行的文件删了,替换成
document.write('<li id="menu-item" class="item-0 "><a href="#div-10" class="link-0 ss"><span><i class="icon iconfont icon-anquan"></i> 保存设置 Save</span></a></li>');
保存后就大功告成了,此时你会发现头像图片加载不出来,到后台主题外观设置里添加上Gravatar源就好了
集成包
如果你觉得自己修改起来麻烦,那么没关系,我提供了被修改文件的下载,functions.php,post.php,setjs.php魔改后的文件
点击本文下方的下载本文附件即可下载这三个文件
Thank you great post. Hello Administ . Mng Nakliyat , Mng Evden Eve Nakliyat , mng evden eve nakliyat
It’s actually a great and helpful piece of info. I’m
satisfied that you just shared this useful info with us.
Please stay us informed like this. Thank you for sharing.
my web blog – tracfone coupon
Thanks for sharing your info. I truly appreciate your efforts and I am waiting for your
further write ups thanks once again.
Good article! We will be linking to this particularly great article on our
site. Keep up the great writing.
Thank you for the auspicious writeup. It in reality was a amusement account it.
Glance complicated to more added agreeable from you! However, how could we keep in touch?
Its such as you read my thoughts! You appear to understand a
lot approximately this, like you wrote the book in it or something.
I think that you simply can do with some p.c. to force the message home
a little bit, however other than that, that is fantastic blog.
An excellent read. I will certainly be back.
My site :: raycon
This site definitely has all the info I needed about this subject and didn’t
know who to ask.
Simply desire to say your article is as amazing. The clearness
on your post is just spectacular and i can assume you
are an expert on this subject. Well with your permission allow me to grab your RSS feed to keep up to date with approaching
post. Thank you a million and please continue the enjoyable work.
Aw, this was an exceptionally nice post.
Taking the time and actual effort to make a top notch article… but what can I say… I hesitate a whole lot and never seem to get anything done.
Great post. I was checking constantly this weblog and I’m inspired!
Very useful info specially the remaining part :
) I take care of such information a lot. I was looking for this
particular information for a long time. Thanks and best
of luck.
When someone writes an article he/she retains the plan of a user
in his/her brain that how a user can know it.
Therefore that’s why this paragraph is great. Thanks!
Greate pieces. Keep posting such kind of info on your page.
Im really impressed by your blog.
Hi there, You’ve done a fantastic job. I’ll certainly digg it and in my view suggest to my friends.
I am confident they’ll be benefited from this web site.