Skip to content

Commit 0d330b3

Browse files
committed
Merge commit '93d12880be03d731afaf29bf87b12366f21dec16'
2 parents 4902403 + 93d1288 commit 0d330b3

File tree

3 files changed

+27
-204
lines changed

3 files changed

+27
-204
lines changed

WeChatShare/Action.php

-66
Original file line numberDiff line numberDiff line change
@@ -15,74 +15,8 @@ public function action()
1515
$this->init();
1616
$this->on($this->request->is('do=insert'))->insertWxShare();
1717
$this->on($this->request->is('do=ajax-get'))->ajaxGetWxShare();
18-
$this->on($this->request->is('do=update-plugin'))->updatePlugin();
1918
}
20-
21-
/*
22-
* 更新插件文件
23-
*/
24-
public function updatePlugin()
25-
{
26-
if($this->user->group != 'administrator') {
27-
throw new Typecho_Plugin_Exception(_t('f**k,别瞎jb搞'));
28-
}
29-
30-
$url = trim($_POST['zipball_url']);
31-
$ch = curl_init();
32-
//设置User-Agent, Github文档要求
33-
$header = ['User-Agent: WeChatShare'];
34-
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
35-
curl_setopt($ch, CURLOPT_URL, $url);
36-
//如果成功只将结果返回,不自动输出任何内容。
37-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
38-
//若给定url自动跳转到新的url,有了下面参数可自动获取新url内容:302跳转
39-
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
40-
//设置cURL允许执行的最长秒数。
41-
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
42-
curl_setopt($ch, CURLOPT_REFERER, $url);
43-
$response = curl_exec($ch);
44-
//获取请求返回码,请求成功返回200
45-
$code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
46-
curl_close($ch);
47-
if($code != '200') {
48-
_e('在线更新失败,请手工下载更新。<br/><a href="'.$url.'" target="_blank">下载地址</a>');
49-
exit;
50-
}
51-
$destination = __DIR__.'/wechatshare.zip';
52-
$file = fopen($destination,"w+");
53-
//写入文件
54-
fputs($file,$response);
55-
fclose($file);
56-
57-
$zip = new ZipArchive;
58-
if ($zip->open($destination)) {
59-
60-
$dir_name = __DIR__.'/'.$zip->getNameIndex(0);
61-
62-
$zip->extractTo(__DIR__.'/');
6319

64-
for($i = 1; $i < $zip->numFiles; $i++) {
65-
66-
rename(__DIR__.'/'.$zip->getNameIndex($i),__DIR__.'/'.basename($zip->getNameIndex($i)));
67-
}
68-
if(!rmdir($dir_name)) {
69-
70-
_e('删除文件夹失败,请手工删除。');
71-
exit;
72-
}
73-
if(!unlink($destination)) {
74-
75-
_e('删除压缩包失败,请手工删除。');
76-
exit;
77-
}
78-
_e('更新成功!');
79-
80-
} else {
81-
82-
_e('在线更新失败,请手工下载更新。<br/><a href="'.$url.'" target="_blank">下载地址</a>');
83-
}
84-
return;
85-
}
8620
/*
8721
* 编辑或者新增文章的时候把微信分享的数据插入到wx_share表
8822
*/

WeChatShare/Plugin.php

+10-122
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,14 @@
55
*
66
* @package WeChatShare
77
* @author Fuzqing
8-
* @version 1.0.5
8+
* @version 1.0.6
99
* @link https://huangweitong.com
1010
*
1111
*
12-
* version 1.0.0 at 2018-6-14
13-
* 优化了代码
14-
* 更新了支持在线更新
15-
*
16-
* version 0.0.4 at 2018-4-30
17-
* 修复了某些bug,优化了代码逻辑
18-
* 把AccessToken、JsapiTicket写进配置里面,方便更新调用,之前版本是写到文件里面的
12+
* version 1.0.6 at 2018-12-19
13+
* 删除在线更新
14+
* 删除自定义字段
1915
*
20-
* version 0.0.3 at 2018-4-29
21-
* 更新支持pjax
22-
* 如果你启用了pjax,当切换页面时候,js不会重写绑定事件到新生成的节点上。
23-
* 你可以在pjax加载页面完成后重新加载js,以便将事件正确绑定ajax生成的DOM节点上。
24-
* 例如:$.getScript("/usr/plugins/WeChatShare/wx_share.js?ver="+Math.random());
25-
*
26-
* version 0.0.2 at 2018-4-27
27-
* 修复jssdk因为ssl判别证书的问题出现的notice
28-
*
29-
* version 0.0.1 at 2018-4-26
30-
* 实现分享博客文章到微信、朋友圈、QQ、QQ空间等
31-
* 包括: 自定义摘要 图标 标题
32-
* 本插件自带自定义摘要,如果填了摘要的话,也可以在前台调用
33-
* 调用字段<?php $description = $this->fields->description;?>
34-
* 具体其他使用方法,请查看官方文档:http://docs.typecho.org/help/custom-fields
3516
*/
3617
class WeChatShare_Plugin implements Typecho_Plugin_Interface
3718
{
@@ -40,7 +21,7 @@ class WeChatShare_Plugin implements Typecho_Plugin_Interface
4021
* 插件版本号
4122
* @var string
4223
*/
43-
const _VERSION = '1.0.5';
24+
const _VERSION = '1.0.6';
4425
/**
4526
* 激活插件方法,如果激活失败,直接抛出异常
4627
*
@@ -49,10 +30,6 @@ class WeChatShare_Plugin implements Typecho_Plugin_Interface
4930
*/
5031
public static Function activate()
5132
{
52-
// 检查curl
53-
if ( !function_exists('curl_init') ) {
54-
throw new Typecho_Plugin_Exception(_t('你好,使用本插件必须开启curl扩展'));
55-
}
5633
$info = WeChatShare_Plugin::wechatShareInstall();
5734
Helper::addAction('wx-share', 'WeChatShare_Action');
5835
Typecho_Plugin::factory('admin/write-post.php')->bottom = array('WeChatShare_Plugin', 'render');
@@ -86,62 +63,10 @@ public static function deactivate(){
8663
*/
8764
public static function config(Typecho_Widget_Helper_Form $form)
8865
{
89-
$options = Typecho_Widget::widget('Widget_Options');
90-
$up_action_url = Typecho_Common::url('/index.php/action/wx-share?do=update-plugin', $options->siteUrl);
91-
?>
92-
<style>
93-
#update_txt{font-size:1.2em;font-weight:700}#update_notice{display:block;text-align:center;margin:5px}#update_body{font-weight:700;color:#1abc9c}.message{padding:10px;background-color:#fff;box-shadow:2px 2px 5px #888;font-size:1pc;line-height:1.875rem}.bttn-default{color:#fff}.bttn,.bttn-md,.bttn-primary{color:#1d89ff}.bttn,.bttn-md{margin:0;padding:0;border-width:0;border-color:transparent;background:transparent;font-weight:400;cursor:pointer;position:relative}.bttn-md{padding:5px 9pt}.bttn-md,.bttn-slant{font-size:20px;font-family:inherit}.bttn-slant{margin:0;padding:0;border-width:0;border-color:transparent;font-weight:400;cursor:pointer;position:relative;padding:5px 9pt;z-index:0;border:none;border-radius:0;background:transparent;color:#1d89ff;-webkit-transition:color .3s cubic-bezier(0.02,0.01,0.47,1),-webkit-transform .3s cubic-bezier(0.02,0.01,0.47,1);transition:color .3s cubic-bezier(0.02,0.01,0.47,1),-webkit-transform .3s cubic-bezier(0.02,0.01,0.47,1);transition:color .3s cubic-bezier(0.02,0.01,0.47,1),transform .3s cubic-bezier(0.02,0.01,0.47,1);transition:color .3s cubic-bezier(0.02,0.01,0.47,1),transform .3s cubic-bezier(0.02,0.01,0.47,1),-webkit-transform .3s cubic-bezier(0.02,0.01,0.47,1)}.bttn-slant:before{width:100%;background:#fafafa;-webkit-transition:box-shadow .2s cubic-bezier(0.02,0.01,0.47,1);transition:box-shadow .2s cubic-bezier(0.02,0.01,0.47,1)}.bttn-slant:after,.bttn-slant:before{position:absolute;top:0;left:0;z-index:-1;height:100%;content:'';-webkit-transform:skewX(20deg);transform:skewX(20deg)}.bttn-slant:after{width:0;background:hsla(0,0%,98%,.3);opacity:0;-webkit-transition:opacity .2s cubic-bezier(0.02,0.01,0.47,1),width .15s cubic-bezier(0.02,0.01,0.47,1);transition:opacity .2s cubic-bezier(0.02,0.01,0.47,1),width .15s cubic-bezier(0.02,0.01,0.47,1)}.bttn-slant:focus,.bttn-slant:hover{-webkit-transform:translateX(5px);transform:translateX(5px)}.bttn-slant:focus:after,.bttn-slant:hover:after{width:5px;opacity:1}.bttn-slant:focus:before,.bttn-slant:hover:before{box-shadow:inset 0 -1px 0 #a7c3ff,inset 0 1px 0 #a7c3ff,inset -1px 0 0 #a7c3ff}.bttn-slant.bttn-md{font-size:20px;font-family:inherit;padding:5px 9pt}.bttn-slant.bttn-primary{color:#fff}.bttn-slant.bttn-primary:focus:before,.bttn-slant.bttn-primary:hover:before{box-shadow:inset 0 -1px 0 #006de3,inset 0 1px 0 #006de3,inset -1px 0 0 #006de3}.bttn-slant.bttn-primary:before{background:#1d89ff}.bttn-slant.bttn-primary:after{background:#006de3}
94-
</style>
95-
<div class="message">
96-
<div id="update_txt">当前版本: <?php _e(self::_VERSION); ?>,正在检测版本更新...</div>
97-
<div id="update_notice"></div>
98-
<div id="update_body"></div>
99-
</div>
100-
<script src="//cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
101-
<script src="//cdn.bootcss.com/marked/0.3.12/marked.min.js"></script>
102-
<script>
103-
$(function () {
104-
$.getJSON(
105-
'https://api.github.com/repos/fuzqing/WeChatShare/releases/latest',
106-
function (data) {
107-
if (checkUpdater('<?php _e(self::_VERSION);?>', data.tag_name)) {
108-
$('#update_txt').html('当前版本:<?php _e(self::_VERSION);?>,检测到有 v'+data.tag_name+' 最新版本,请更新!');
109-
$('#update_notice').html('<button class="bttn-slant bttn-md bttn-primary" zipball_url="' + data.zipball_url + '" onClick="updatePlugin();" id="update-plugin">立即更新</button><hr>');
110-
$('#update_body').html('<span style="font-size:1.3em">版本说明:</span>' + marked(data.body));
111-
} else {
112-
$('#update_txt').html('当前版本:<?php _e(self::_VERSION);?>,当前没有新版本');
113-
}
114-
}
115-
);
116-
});
117-
118-
// 版本比较
119-
function checkUpdater(currVer, remoteVer) {
120-
currVer = currVer || '0.0.0';
121-
remoteVer = remoteVer || '0.0.0';
122-
if (currVer == remoteVer) return false;
123-
var currVerAry = currVer.split('.');
124-
var remoteVerAry = remoteVer.split('.');
125-
var len = Math.max(currVerAry.length, remoteVerAry.length);
126-
for (var i = 0; i < len; i++) {
127-
if (~~remoteVerAry[i] > ~~currVerAry[i]) return true;
128-
}
129-
130-
return false;
131-
}
132-
133-
function updatePlugin() {
134-
var zipball_url = $("#update-plugin").attr('zipball_url');
135-
$.post("<?php echo $up_action_url;?>", {zipball_url:zipball_url} ,success,"");
136-
function success(data){
137-
$('#update_txt').html('');
138-
$('#update_notice').html('<span style="font-size:1.4em;color:#1d89f;font-weight:700;">'+data+'</span>');
139-
140-
}
141-
return false;
142-
}
143-
</script>
144-
<?php
66+
$options = Typecho_Widget::widget('Widget_Options');
67+
68+
$up_action_url = Typecho_Common::url('/index.php/action/wx-share?do=update-plugin', $options->siteUrl);
69+
14570
/** 公众号配置 */
14671
$wx_AppID = new Typecho_Widget_Helper_Form_Element_Text('wx_AppID', NULL, NULL, _t('APPID'),'请登录微信公众号获取');
14772

@@ -208,50 +133,13 @@ public static function render()
208133
$wx_image = $wx_share[0]['wx_image'];
209134
}
210135
}
211-
$str = '<tr><td><input type="hidden" name="fieldNames[]" my-description="my-description" value="description" id="fieldname"><label class="typecho-label" for="description">文章自定义摘要</label><input type="hidden" name="fieldTypes[]" value="str" id="fieldtype" class="text-s w-100"></td><td colspan="3"><textarea name="fieldValues[]" onfocus="get_describe(this);" id="fieldvalue" class="text-s w-100" rows="4">'.$description.'</textarea></td></tr>';
212-
136+
213137
$data = '<style>:-moz-placeholder {color: #E0E0E0; opacity:1;}::-moz-placeholder {color: #E0E0E0;opacity:1;}input:-ms-input-placeholder{color: #E0E0E0;opacity:1;}input::-webkit-input-placeholder{color: #E0E0E0;opacity:1;}</style><form id="wx_share" ><fieldset><legend>微信分享</legend><ol style="list-style-type:none;><li style="padding-bottom: 5px;"><label for="wx_title">标题:</label><input style="width: 80%" type="text" class="wx_title" value="'.$wx_title.'" name="wx_title" ></li><li style="padding-bottom: 5px;"><label for="wx_url">链接:</label><input type="text" style="width: 80%" value="'.$wx_url.'" name="wx_url"></li><li style="padding-bottom: 5px;display:block;"><span style="float:left" for="wx_describe">摘要:</span><textarea rows="4" class="wx_describe" name="wx_description" style="width: 80%" >'.$wx_description.'</textarea></li><li style="padding-bottom: 5px;"><label for="wx_image">图标:</label><input type="text" class="wx_image" value="'.$wx_image.'" style="width: 80%" name="wx_image"></li></ol></fieldset><input type="hidden" name="cid" value="'.$match['1'].'"></form>';
214138

215139
?>
216140

217141
<script>
218-
//监控摘要自定义字段的输入,同步更新微信摘要
219-
function get_describe(self){
220-
$(self).on('input propertychange', function(event) {
221-
var _val = $(self).val();
222-
var wx_describe = $(".wx_describe").val();
223-
if (wx_describe !== null || wx_describe !== undefined || wx_describe !== '') {
224-
225-
$(".wx_describe").val(_val);
226-
}
227-
228-
229-
});
230-
$(self).blur(function(){
231-
$(self).off('input propertychange');
232-
});
233-
}
234142
$(document).ready(function(){
235-
//添加description自定义字段
236-
$("#custom-field table tbody").prepend('<?php echo $str ?>');
237-
//自动打开自定义字段
238-
$(".i-caret-right").click();
239-
//多出来的一个自定义字段
240-
$("#custom-field table input").each(function () {
241-
if(!$(this).val()) {
242-
$("#custom-field table tr .btn-xs").parents('tr').fadeOut(function () {
243-
$(this).remove();
244-
});
245-
$("#custom-field table tr .btn-xs").parents('form').trigger('field');
246-
}
247-
if($(this).val() == 'description' && $(this).attr('my-description') == undefined) {
248-
$(this).parents('tr').fadeOut(function () {
249-
$(this).remove();
250-
});
251-
$(this).parents('form').trigger('field');
252-
}
253-
});
254-
255143

256144
//添加微信分享
257145
$("#custom-field").after('<?php echo $data ?>');

WeChatShare/README.md

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
# Typecho 微信分享插件 WeChatShare
22

3+
# 不再维护,谁愿意维护此插件的可以fork过去
4+
35
## 插件简介
46

5-
> 1. 使用此插件可方便地自定义微信和QQ分享链接中的标题、描述、小图标和URL,让你的分享链接不再单调;
6-
> 2. 建议使用1.2版本的Typecho
7+
使用此插件可方便地自定义微信和QQ分享链接中的标题、描述、小图标和URL,让你的分享链接不再单调;
78

89
## 本人博客环境
9-
> 1. 军哥的lnmp一键包,PHP7.1,开启了curl扩展
10-
> 2. Typecho 版本 1.2 (18.1.29)
10+
军哥的lnmp一键包,PHP7.1,开启了curl扩展
11+
Typecho 版本 1.2 (18.1.29)
1112

1213
## 安装方法
1314

14-
> 1.[releases](https://github.com/fuzqing/WeChatShare/releases)中下载最新版本插件;
15-
> 2. 将下载的压缩包进行解压,文件夹重命名为`WeChatShare`,上传至`Typecho`插件目录中;
16-
> 3. 检查`WeChatShare`插件目录文件是否有读写权限,如果没有请增加;
17-
> 4. 后台激活插件;
18-
> 5. 到插件配置页面填写插件配置信息。
15+
1.[releases](https://github.com/fuzqing/WeChatShare/releases)中下载最新版本插件;
16+
2. 将下载的压缩包进行解压,文件夹重命名为`WeChatShare`,上传至`Typecho`插件目录中;
17+
3. 检查`WeChatShare`插件目录文件是否有读写权限,如果没有请增加;
18+
4. 后台激活插件;
19+
5. 到插件配置页面填写插件配置信息。
1920

2021
## 注意:由于微信更新,如果你想要在微信中直接分享,请按以下步骤操作:
2122

22-
> 1. 公众号通过微信认证;
23-
> 2. 填写 AppID 和 AppSecret (开发 > 基本配置);
24-
> 3. 添加服务器IP 到 IP白名单中 (开发 > 基本配置 > IP白名单);
25-
> 4. 添加域名到 JS安全域名中(设置 > 公众号设置 > 功能设置 > JS接口安全域名)。
23+
1. 公众号通过微信认证;
24+
2. 填写 AppID 和 AppSecret (开发 > 基本配置);
25+
3. 添加服务器IP 到 IP白名单中 (开发 > 基本配置 > IP白名单);
26+
4. 添加域名到 JS安全域名中(设置 > 公众号设置 > 功能设置 > JS接口安全域名)。
2627

2728
## 更新日志
2829

29-
### 2018.6.16
30+
### 2018.12.19
3031

31-
> 1. 添加了版本更新检测;
32-
> 2. 后续版本支持在线更新!
32+
删除在线更新
33+
删除自定义字段

0 commit comments

Comments
 (0)