Skip to content

Commit

Permalink
Squashed 'WeChatShare/' changes from 920f48f..26414c3
Browse files Browse the repository at this point in the history
26414c3 Update README.md
115c64c Update README.md
f5d9336 Update README.md
dd00292 Update Action.php
3a1cde5 Update Plugin.php
dd44921 Update README.md

git-subtree-dir: WeChatShare
git-subtree-split: 26414c375433790b3672c3a700eebdd3a4a49f5c
  • Loading branch information
jzwalk committed May 15, 2020
1 parent fcbf03e commit 93d1288
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 204 deletions.
66 changes: 0 additions & 66 deletions Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,74 +15,8 @@ public function action()
$this->init();
$this->on($this->request->is('do=insert'))->insertWxShare();
$this->on($this->request->is('do=ajax-get'))->ajaxGetWxShare();
$this->on($this->request->is('do=update-plugin'))->updatePlugin();
}

/*
* 更新插件文件
*/
public function updatePlugin()
{
if($this->user->group != 'administrator') {
throw new Typecho_Plugin_Exception(_t('f**k,别瞎jb搞'));
}

$url = trim($_POST['zipball_url']);
$ch = curl_init();
//设置User-Agent, Github文档要求
$header = ['User-Agent: WeChatShare'];
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, $url);
//如果成功只将结果返回,不自动输出任何内容。
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//若给定url自动跳转到新的url,有了下面参数可自动获取新url内容:302跳转
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//设置cURL允许执行的最长秒数。
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_REFERER, $url);
$response = curl_exec($ch);
//获取请求返回码,请求成功返回200
$code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
if($code != '200') {
_e('在线更新失败,请手工下载更新。<br/><a href="'.$url.'" target="_blank">下载地址</a>');
exit;
}
$destination = __DIR__.'/wechatshare.zip';
$file = fopen($destination,"w+");
//写入文件
fputs($file,$response);
fclose($file);

$zip = new ZipArchive;
if ($zip->open($destination)) {

$dir_name = __DIR__.'/'.$zip->getNameIndex(0);

$zip->extractTo(__DIR__.'/');

for($i = 1; $i < $zip->numFiles; $i++) {

rename(__DIR__.'/'.$zip->getNameIndex($i),__DIR__.'/'.basename($zip->getNameIndex($i)));
}
if(!rmdir($dir_name)) {

_e('删除文件夹失败,请手工删除。');
exit;
}
if(!unlink($destination)) {

_e('删除压缩包失败,请手工删除。');
exit;
}
_e('更新成功!');

} else {

_e('在线更新失败,请手工下载更新。<br/><a href="'.$url.'" target="_blank">下载地址</a>');
}
return;
}
/*
* 编辑或者新增文章的时候把微信分享的数据插入到wx_share表
*/
Expand Down
132 changes: 10 additions & 122 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,14 @@
*
* @package WeChatShare
* @author Fuzqing
* @version 1.0.5
* @version 1.0.6
* @link https://huangweitong.com
*
*
* version 1.0.0 at 2018-6-14
* 优化了代码
* 更新了支持在线更新
*
* version 0.0.4 at 2018-4-30
* 修复了某些bug,优化了代码逻辑
* 把AccessToken、JsapiTicket写进配置里面,方便更新调用,之前版本是写到文件里面的
* version 1.0.6 at 2018-12-19
* 删除在线更新
* 删除自定义字段
*
* version 0.0.3 at 2018-4-29
* 更新支持pjax
* 如果你启用了pjax,当切换页面时候,js不会重写绑定事件到新生成的节点上。
* 你可以在pjax加载页面完成后重新加载js,以便将事件正确绑定ajax生成的DOM节点上。
* 例如:$.getScript("/usr/plugins/WeChatShare/wx_share.js?ver="+Math.random());
*
* version 0.0.2 at 2018-4-27
* 修复jssdk因为ssl判别证书的问题出现的notice
*
* version 0.0.1 at 2018-4-26
* 实现分享博客文章到微信、朋友圈、QQ、QQ空间等
* 包括: 自定义摘要 图标 标题
* 本插件自带自定义摘要,如果填了摘要的话,也可以在前台调用
* 调用字段<?php $description = $this->fields->description;?>
* 具体其他使用方法,请查看官方文档:http://docs.typecho.org/help/custom-fields
*/
class WeChatShare_Plugin implements Typecho_Plugin_Interface
{
Expand All @@ -40,7 +21,7 @@ class WeChatShare_Plugin implements Typecho_Plugin_Interface
* 插件版本号
* @var string
*/
const _VERSION = '1.0.5';
const _VERSION = '1.0.6';
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
Expand All @@ -49,10 +30,6 @@ class WeChatShare_Plugin implements Typecho_Plugin_Interface
*/
public static Function activate()
{
// 检查curl
if ( !function_exists('curl_init') ) {
throw new Typecho_Plugin_Exception(_t('你好,使用本插件必须开启curl扩展'));
}
$info = WeChatShare_Plugin::wechatShareInstall();
Helper::addAction('wx-share', 'WeChatShare_Action');
Typecho_Plugin::factory('admin/write-post.php')->bottom = array('WeChatShare_Plugin', 'render');
Expand Down Expand Up @@ -86,62 +63,10 @@ public static function deactivate(){
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
$options = Typecho_Widget::widget('Widget_Options');
$up_action_url = Typecho_Common::url('/index.php/action/wx-share?do=update-plugin', $options->siteUrl);
?>
<style>
#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}
</style>
<div class="message">
<div id="update_txt">当前版本: <?php _e(self::_VERSION); ?>,正在检测版本更新...</div>
<div id="update_notice"></div>
<div id="update_body"></div>
</div>
<script src="//cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="//cdn.bootcss.com/marked/0.3.12/marked.min.js"></script>
<script>
$(function () {
$.getJSON(
'https://api.github.com/repos/fuzqing/WeChatShare/releases/latest',
function (data) {
if (checkUpdater('<?php _e(self::_VERSION);?>', data.tag_name)) {
$('#update_txt').html('当前版本:<?php _e(self::_VERSION);?>,检测到有 v'+data.tag_name+' 最新版本,请更新!');
$('#update_notice').html('<button class="bttn-slant bttn-md bttn-primary" zipball_url="' + data.zipball_url + '" onClick="updatePlugin();" id="update-plugin">立即更新</button><hr>');
$('#update_body').html('<span style="font-size:1.3em">版本说明:</span>' + marked(data.body));
} else {
$('#update_txt').html('当前版本:<?php _e(self::_VERSION);?>,当前没有新版本');
}
}
);
});

// 版本比较
function checkUpdater(currVer, remoteVer) {
currVer = currVer || '0.0.0';
remoteVer = remoteVer || '0.0.0';
if (currVer == remoteVer) return false;
var currVerAry = currVer.split('.');
var remoteVerAry = remoteVer.split('.');
var len = Math.max(currVerAry.length, remoteVerAry.length);
for (var i = 0; i < len; i++) {
if (~~remoteVerAry[i] > ~~currVerAry[i]) return true;
}

return false;
}

function updatePlugin() {
var zipball_url = $("#update-plugin").attr('zipball_url');
$.post("<?php echo $up_action_url;?>", {zipball_url:zipball_url} ,success,"");
function success(data){
$('#update_txt').html('');
$('#update_notice').html('<span style="font-size:1.4em;color:#1d89f;font-weight:700;">'+data+'</span>');

}
return false;
}
</script>
<?php
$options = Typecho_Widget::widget('Widget_Options');

$up_action_url = Typecho_Common::url('/index.php/action/wx-share?do=update-plugin', $options->siteUrl);

/** 公众号配置 */
$wx_AppID = new Typecho_Widget_Helper_Form_Element_Text('wx_AppID', NULL, NULL, _t('APPID'),'请登录微信公众号获取');

Expand Down Expand Up @@ -208,50 +133,13 @@ public static function render()
$wx_image = $wx_share[0]['wx_image'];
}
}
$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>';


$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>';

?>

<script>
//监控摘要自定义字段的输入,同步更新微信摘要
function get_describe(self){
$(self).on('input propertychange', function(event) {
var _val = $(self).val();
var wx_describe = $(".wx_describe").val();
if (wx_describe !== null || wx_describe !== undefined || wx_describe !== '') {

$(".wx_describe").val(_val);
}


});
$(self).blur(function(){
$(self).off('input propertychange');
});
}
$(document).ready(function(){
//添加description自定义字段
$("#custom-field table tbody").prepend('<?php echo $str ?>');
//自动打开自定义字段
$(".i-caret-right").click();
//多出来的一个自定义字段
$("#custom-field table input").each(function () {
if(!$(this).val()) {
$("#custom-field table tr .btn-xs").parents('tr').fadeOut(function () {
$(this).remove();
});
$("#custom-field table tr .btn-xs").parents('form').trigger('field');
}
if($(this).val() == 'description' && $(this).attr('my-description') == undefined) {
$(this).parents('tr').fadeOut(function () {
$(this).remove();
});
$(this).parents('form').trigger('field');
}
});


//添加微信分享
$("#custom-field").after('<?php echo $data ?>');
Expand Down
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
# Typecho 微信分享插件 WeChatShare

# 不再维护,谁愿意维护此插件的可以fork过去

## 插件简介

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

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

## 安装方法

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

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

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

## 更新日志

### 2018.6.16
### 2018.12.19

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

0 comments on commit 93d1288

Please sign in to comment.