├── screenshot-1.png ├── screenshot-2.png ├── screenshot-3.png ├── assets └── icon-256x256.png ├── images └── random │ ├── article1.jpg │ ├── article2.jpg │ ├── article3.jpg │ ├── article4.jpg │ └── article5.jpg ├── trans ├── wechat-page-sharing-zh_CN.mo └── wechat-page-sharing-zh_CN.po ├── sharing-config.php ├── sharing-ajax.php ├── sharing.php ├── readme.txt ├── wechat.php ├── sharing-admin.php ├── sharing-page.php └── LICENSE /screenshot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosima/wechat-page-sharing/HEAD/screenshot-1.png -------------------------------------------------------------------------------- /screenshot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosima/wechat-page-sharing/HEAD/screenshot-2.png -------------------------------------------------------------------------------- /screenshot-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosima/wechat-page-sharing/HEAD/screenshot-3.png -------------------------------------------------------------------------------- /assets/icon-256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosima/wechat-page-sharing/HEAD/assets/icon-256x256.png -------------------------------------------------------------------------------- /images/random/article1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosima/wechat-page-sharing/HEAD/images/random/article1.jpg -------------------------------------------------------------------------------- /images/random/article2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosima/wechat-page-sharing/HEAD/images/random/article2.jpg -------------------------------------------------------------------------------- /images/random/article3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosima/wechat-page-sharing/HEAD/images/random/article3.jpg -------------------------------------------------------------------------------- /images/random/article4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosima/wechat-page-sharing/HEAD/images/random/article4.jpg -------------------------------------------------------------------------------- /images/random/article5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosima/wechat-page-sharing/HEAD/images/random/article5.jpg -------------------------------------------------------------------------------- /trans/wechat-page-sharing-zh_CN.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosima/wechat-page-sharing/HEAD/trans/wechat-page-sharing-zh_CN.mo -------------------------------------------------------------------------------- /sharing-config.php: -------------------------------------------------------------------------------- 1 | getSign($cur_url); 31 | 32 | wp_send_json($signPackage); 33 | } 34 | } -------------------------------------------------------------------------------- /sharing.php: -------------------------------------------------------------------------------- 1 | 请注意,0.2.x版本升级后需重新配置AppId和AppSecrect。 6 | Version: 0.3.4 7 | Author: 波斯码 8 | Author URI: http://blog.bossma.cn 9 | */ 10 | 11 | /* Copyright 2017 波斯码(bossma) (email : bossma@yeah.net) 12 | 13 | This program is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2 of the License, or 16 | (at your option) any later version. 17 | 18 | This program is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this program; if not, write to the Free Software 25 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | if (!defined('ABSPATH')) { 29 | exit(); 30 | } 31 | 32 | if (defined('WP_INSTALLING') && WP_INSTALLING) { 33 | return; 34 | } 35 | 36 | define('BOSIMA_WECHAT_PAGE_SHARING__PLUGIN_DIR', plugin_dir_path(__FILE__)); 37 | 38 | if (is_admin()) { 39 | require_once BOSIMA_WECHAT_PAGE_SHARING__PLUGIN_DIR.'sharing-admin.php'; 40 | 41 | function bosima_wps_plugin_action_links ( $links ) { 42 | $mylinks = array( 43 | ''.__("Settings").'', 44 | ); 45 | return array_merge( $links, $mylinks ); 46 | } 47 | 48 | add_action('init', array('Bosima_WeChat_Page_Sharing_Admin', 'init')); 49 | add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'bosima_wps_plugin_action_links' ); 50 | } 51 | 52 | require_once BOSIMA_WECHAT_PAGE_SHARING__PLUGIN_DIR.'sharing-page.php'; 53 | add_action('wp_footer', array('Bosima_WeChat_Page_Sharing_Page', 'render_ref_js'),1); 54 | add_action('wp_footer', array('Bosima_WeChat_Page_Sharing_Page', 'render_js'),100); 55 | 56 | Bosima_WeChat_Page_Sharing_Page::init(); -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Bosima WeChat Page Sharing === 2 | Contributors: bossma 3 | Donate link: http://blog.bossma.cn/ 4 | Tags: wechat, sharing, 微信, 分享 5 | Requires at least: 4.4 6 | Tested up to: 5.2.2 7 | Stable tag: 0.3.4 8 | License: GPLv2 or later 9 | License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 | 11 | 您可以控制Wordpress页面的分享内容,包括Url、标题、图片和描述,支持分享到微信朋友、微信朋友圈、QQ和QQ空间。 12 | 请注意,0.2.x版本升级后需重新配置AppId和AppSecrect。 13 | 14 | == Description == 15 | 16 | 本插件通过集成微信提供的JS-SDK,从而实现自定义网页分享的内容,包括Url、标题、图片和内容。 17 | 18 | 1、本插件简单灵活,分享的内容可全部从页面提取,也可在后台自定义。 19 | 2、目前已实现首页、分类页、文章页、标签页、搜索页、存档页以及单独页面的分享。 20 | 3、分享目标支持微信朋友、微信朋友圈、QQ、QQ空间。 21 | 4、分享标题、图片、描述等内容首先从自定义模板提取,如果未设置模板则从页面提取,如果页面上提取不到则根据当前页面内容自动生成。 22 | 5、从页面提取时,各个分享内容的来源:标题来源于html->head->title,描述从html->head->meta[name='description']提取,图片取正文中的第一张图。 23 | 6、分享url目前只能是当前url,未提供自定义设置功能。 24 | 25 | == Installation == 26 | 27 | 1、在您的Wordpress管理后台安装本插件或者通过上传文件夹到Wordpress插件目录的方式安装本插件; 28 | 2、启用插件; 29 | 3、注册一个微信公众号,访问地址:https://mp.weixin.qq.com; 30 | 4、在“Wordpress管理后台”-“设置”-“微信分享设置”中获取服务器出口IP,填写到“微信公众平台”-“安全中心”-“IP白名单”中; 31 | 5、在“微信公众平台”-“公众号设置”-“功能设置”-“JS接口安全域名”中填写您网站的域名; 32 | 6、在“Wordpress管理后台”-“设置”-“微信分享设置”中填写您微信公众号的AppID和AppSecrect(从“微信公众平台”-“基本配置”中获取)。 33 | 34 | 安装完毕。 35 | 36 | 特别说明: 37 | 由于0.2.0版本将微信的配置参数保存到了插件目录下(当然也不会被外部访问到),导致控制台升级后配置会丢失。 38 | 从0.2.1版本后配置参数保存位置进行了修改,防止升级导致丢失。 39 | 因此0.2.0版本升级后请重新设置微信的AppId和AppSecrect。 40 | 41 | == Frequently Asked Questions == 42 | 43 | = 微信IP白名单中需要的IP是域名解析到的IP吗? = 44 | 45 | 这两个IP可能是同一个,也可能不是。 46 | 微信IP白名单中的IP是网站所在服务器的外网出口IP,也就是服务器访问外部网络资源时暴漏的IP。 47 | 48 | = 如获取获取微信IP白名单中需要的IP? = 49 | 50 | 1、直接询问您的主机服务商服务器的外网出口IP; 51 | 2、在“Wordpress管理后台”-“设置”-“微信分享设置”中查看。 52 | 53 | = 微信公众号可以是个人账号吗? = 54 | 55 | 现在不可以,需要是认证过的企业账号。 56 | 如果你是很久之前注册的,有可能具备分享接口权限,请登陆微信公众号平台查看。 57 | 58 | = 这个插件和缓存插件冲突吗? = 59 | 60 | 没有冲突,对于启用缓存插件的WordPress,本插件将自动使用Ajax的方式实现页面分享。 61 | 62 | == Screenshots == 63 | 64 | 1. 使用说明、微信设置和模板设置 65 | 66 | 2、页面上生成的微信分享代码 67 | 68 | 3、分享到微信的效果 69 | 70 | == Changelog == 71 | 72 | = 0.3.4 = 73 | * 修改生成微信分享js的顺序,避免找不到jQuery的问题 74 | * 统一获取微信js签名的方式为ajax方式 75 | * 修改后台使用说明中的域名使用前端js获取 76 | 77 | = 0.3.3 = 78 | * 更改反向代理情况下获取分享链接域名的方法 79 | * 对分享标题和描述中的双引号进行转义 80 | * 修改从文章中提取图片的正则表达式 81 | * 在插件列表增加“设置”链接 82 | 83 | = 0.3.2 = 84 | * 增加插件截图 85 | * 在插件后台增加使用说明 86 | * 修正错误的作者url 87 | 88 | = 0.3.1 = 89 | * 增加了分享标题和描述的模板设置功能,让分享更个性化; 90 | * 增加了首页分享使用网站Icon的选择; 91 | * 增加了单篇文章分享使用特色图片的选择; 92 | * 更换了从正文提取图片url时调用的方法为当前类的静态方法; 93 | * 更换了通过ajax方式生成签名时检查url的函数为esc_url_raw; 94 | * 为后台管理界面编写了多语言文件; 95 | * 更新了判断https协议的方法; 96 | * 更换了获取服务器出口IP的方法。 97 | 98 | = 0.3.0 = 99 | * 解决了Url中含有中文时签名无效的问题; 100 | * 增加了首页、分类页、标签页、搜索页、存档页以及单独页面的分享。 101 | 102 | = 0.2.2 = 103 | * 修改Exit IP为Outbound IP; 104 | * 注释签名包中调试用的url和原始签名字符串,防止信息泄露。 105 | 106 | 107 | = 0.2.1 = 108 | * 增加显示服务器出口IP功能,方便在微信“安全中心”-“IP白名单”中进行配置。 109 | * 更改微信配置参数保存位置,防止控制台升级后丢失;但从0.2.0升级后仍会丢失,需重新配置。 110 | 111 | = 0.2.0 = 112 | * 第一个版本,仅支持文章分享给朋友和分享到朋友圈。 113 | 114 | 115 | == Upgrade Notice == 116 | 117 | = 0.3.4 = 118 | * 解决部分情况下因分享js脚本输出顺序导致分享失败的问题 119 | * 通过使用前端获取url的方式解决部分情况下签名url不正确的问题 120 | * 通过使用前端获取当前域名的方式解决部分情况下设置页面获取到的域名不正确的问题 121 | 122 | = 0.3.3 = 123 | * 修复某些部署情况下分享链接域名不正确的问题 124 | * 修复分享标题和描述中含有特殊字符导致分享失败的问题 125 | * 优化从文章中提取图片的正则表达式 126 | * 在插件列表增加“设置”链接,方便找到插件设置 127 | 128 | = 0.3.2 = 129 | * 增加插件截图,方便用户安装前了解插件功能 130 | * 在插件后台增加使用说明,方便用户尽快完成配置 131 | 132 | = 0.3.1 = 133 | * 增加了分享标题和描述的模板设置功能,让分享更个性化; 134 | * 增加了首页分享使用网站Icon的选择; 135 | * 增加了单篇文章分享使用特色图片的选择; 136 | * 解决了从正文提取图片url时调用了主题方法的bug; 137 | * 解决了搜索页分享时获取当前url不正确的bug; 138 | * 后台管理界面增加了对多语言的支持; 139 | * 增强了对https协议的支持; 140 | * 提升了获取服务器出口IP的速度。 141 | 142 | = 0.3.0 = 143 | * 解决了Url中含有中文时签名无效的问题; 144 | * 增加了首页、分类页、标签页、搜索页、存档页以及单独页面的分享。 145 | 146 | = 0.2.2 = 147 | * 修改Exit IP为Outbound IP; 148 | * 注释签名包中调试用的url和原始签名字符串,防止信息泄露。 149 | 150 | = 0.2.1 = 151 | * 增加显示服务器出口IP功能,方便在微信“安全中心”-“IP白名单”中进行配置。 152 | * 更改微信配置参数保存位置,防止控制台升级后丢失;但从0.2.0升级后仍会丢失,需重新配置。 153 | 154 | = 0.2.0 = 155 | * 第一个版本,仅支持文章分享给朋友和分享到朋友圈。 156 | 157 | 158 | == Dependency == 159 | 160 | = WeChat JS-SDK = 161 | https://res.wx.qq.com/open/js/jweixin-1.2.0.js 162 | This plugin depends on the WeChat JS-SDK, which is a remote JS file and provided by WeChat. 163 | It provides initialization method of WeChat services, and provide some functions, including share to friends, share to circle of friends. 164 | The JS-SDK is a service. 165 | 166 | = myip.fireflysoft.net = 167 | http://myip.fireflysoft.net 168 | This plugin depends on the myip.fireflysoft.net, which can return the outbound IP of the user server. 169 | The exit IP needs to be added to the WeChat IP whitelist. -------------------------------------------------------------------------------- /trans/wechat-page-sharing-zh_CN.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: wechat-page-sharing-lang\n" 4 | "POT-Creation-Date: 2018-08-26 22:59+0800\n" 5 | "PO-Revision-Date: 2018-08-26 23:06+0800\n" 6 | "Last-Translator: \n" 7 | "Language-Team: \n" 8 | "Language: zh-CN\n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "X-Generator: Poedit 1.5.7\n" 13 | "X-Poedit-KeywordsList: _e;__\n" 14 | "X-Poedit-Basepath: .\n" 15 | "X-Poedit-SourceCharset: UTF-8\n" 16 | "X-Poedit-SearchPath-0: ..\n" 17 | 18 | #: ../sharing-admin.php:26 19 | msgid "You do not have sufficient permissions to access this page." 20 | msgstr "您没有足够的权限访问此页面。" 21 | 22 | #: ../sharing-admin.php:82 23 | msgid "settings saved." 24 | msgstr "设置保存成功。" 25 | 26 | #: ../sharing-admin.php:109 27 | msgid "WeChat Page Sharing Plugin Settings" 28 | msgstr "微信分享设置" 29 | 30 | #: ../sharing-admin.php:115 31 | msgid "Plugin Instructions" 32 | msgstr "使用说明" 33 | 34 | #: ../sharing-admin.php:116 35 | msgid "Instructions Setp 1 Content" 36 | msgstr "首先要有微信公众号:认证过的或者具有JS分享接口权限的,这是硬条件" 37 | 38 | #: ../sharing-admin.php:117 39 | msgid "Instructions Setp 2 Content" 40 | msgstr "在“微信公众平台”-“安全中心”-“IP白名单”中增加您网站的出口IP:" 41 | 42 | #: ../sharing-admin.php:118 43 | msgid "Instructions Setp 3 Content" 44 | msgstr "" 45 | "在“微信公众平台”-“公众号设置”-“功能设置”-“JS接口安全域名”中增加您网站的域名:" 46 | 47 | #: ../sharing-admin.php:119 48 | msgid "Instructions Setp 4 Content" 49 | msgstr "" 50 | "在本页面“微信设置”中填写并保存您公众号的AppID和AppSecrect(从“微信公众平" 51 | "台”-“基本配置”中获取),完成这一步就可以用了" 52 | 53 | #: ../sharing-admin.php:120 54 | msgid "Instructions Setp 5 Content" 55 | msgstr "您还可以使用本插件的“模板设置”个性化您的分享内容" 56 | 57 | #: ../sharing-admin.php:121 58 | msgid "Have Fun" 59 | msgstr "祝您使用愉快!" 60 | 61 | #: ../sharing-admin.php:123 62 | msgid "WeChat Settings" 63 | msgstr "微信设置" 64 | 65 | #: ../sharing-admin.php:124 66 | msgid "WeChat AppId:" 67 | msgstr "微信AppId:" 68 | 69 | #: ../sharing-admin.php:127 70 | msgid "WeChat AppSecrect:" 71 | msgstr "微信AppSecrect:" 72 | 73 | #: ../sharing-admin.php:130 74 | msgid "Server Outbound IP:" 75 | msgstr "服务器出口IP:" 76 | 77 | #: ../sharing-admin.php:137 78 | msgid "Template Settings" 79 | msgstr "模板设置" 80 | 81 | #: ../sharing-admin.php:138 82 | msgid "Sharing Template Memo" 83 | msgstr "" 84 | "以下模板如果不设置,会使用默认标题和描述,默认标题为html->head->title中的内" 85 | "容,如果没有则使用本程序自定义的一句话;默认描述优先使用html->head->meta" 86 | "[name='description']的内容,如果没有则使用本程序自定义的一句话。" 87 | 88 | #: ../sharing-admin.php:139 89 | msgid "Sharing Home Title Template:" 90 | msgstr "首页分享标题模板:" 91 | 92 | #: ../sharing-admin.php:141 ../sharing-admin.php:145 ../sharing-admin.php:153 93 | #: ../sharing-admin.php:157 ../sharing-admin.php:161 ../sharing-admin.php:165 94 | #: ../sharing-admin.php:169 ../sharing-admin.php:173 ../sharing-admin.php:177 95 | #: ../sharing-admin.php:181 ../sharing-admin.php:185 ../sharing-admin.php:189 96 | #: ../sharing-admin.php:193 97 | msgid "Valid Variable Label:" 98 | msgstr "可用标签:" 99 | 100 | #: ../sharing-admin.php:143 101 | msgid "Sharing Home Description Template:" 102 | msgstr "首页分享描述模板:" 103 | 104 | #: ../sharing-admin.php:147 105 | msgid "Sharing Home Image Use Site Icon:" 106 | msgstr "首页分享图标使用网站图标:" 107 | 108 | #: ../sharing-admin.php:148 109 | msgid "Use" 110 | msgstr "使用" 111 | 112 | #: ../sharing-admin.php:149 113 | msgid "Not Use" 114 | msgstr "不使用" 115 | 116 | #: ../sharing-admin.php:151 117 | msgid "Sharing Category Title Template:" 118 | msgstr "分类页分享标题模板:" 119 | 120 | #: ../sharing-admin.php:155 121 | msgid "Sharing Single Title Template:" 122 | msgstr "文章页分享标题模板:" 123 | 124 | #: ../sharing-admin.php:159 125 | msgid "Sharing Single Description Template:" 126 | msgstr "文章页分享描述模板:" 127 | 128 | #: ../sharing-admin.php:163 129 | msgid "Sharing Page Title Template:" 130 | msgstr "页面分享标题模板:" 131 | 132 | #: ../sharing-admin.php:167 133 | msgid "Sharing Page Description Template:" 134 | msgstr "页面分享描述模板:" 135 | 136 | #: ../sharing-admin.php:171 137 | msgid "Sharing Tag Title Template:" 138 | msgstr "标签页分享标题模板:" 139 | 140 | #: ../sharing-admin.php:175 141 | msgid "Sharing Tag Description Template:" 142 | msgstr "标签页分享描述模板:" 143 | 144 | #: ../sharing-admin.php:179 145 | msgid "Sharing Archive Title Template:" 146 | msgstr "归档页分享标题模板:" 147 | 148 | #: ../sharing-admin.php:183 149 | msgid "Sharing Archive Description Template:" 150 | msgstr "归档页分享描述模板:" 151 | 152 | #: ../sharing-admin.php:187 153 | msgid "Sharing Search Title Template:" 154 | msgstr "搜索页分享标题模板:" 155 | 156 | #: ../sharing-admin.php:191 157 | msgid "Sharing Search Description Template:" 158 | msgstr "搜索页分享描述模板:" 159 | 160 | #: ../sharing-admin.php:195 161 | msgid "Sharing Image Option:" 162 | msgstr "分享图标使用的图片来源:" 163 | 164 | #: ../sharing-admin.php:196 165 | msgid "Post Featued Image" 166 | msgstr "文章特色图片" 167 | 168 | #: ../sharing-admin.php:197 169 | msgid "Post First Image" 170 | msgstr "文章首张图片" 171 | 172 | #: ../sharing-admin.php:198 173 | msgid "Sharing Image Option Memo:" 174 | msgstr "" 175 | "如果来源选择了“文章特色图片”,但是文章没有设置,会尝试“文章首张图片”,如果还" 176 | "找不到会随机给一张。" 177 | -------------------------------------------------------------------------------- /wechat.php: -------------------------------------------------------------------------------- 1 | initConfig(); 34 | } 35 | 36 | /** 37 | * 单例入口. 38 | */ 39 | public static function getInstance() 40 | { 41 | if (is_null(self::$instance) || !isset(self::$instance)) { 42 | self::$instance = new self(); 43 | } 44 | 45 | return self::$instance; 46 | } 47 | 48 | /** 49 | * 获取微信配置. 50 | */ 51 | public function getWeChatConfig() 52 | { 53 | return $this->config; 54 | } 55 | 56 | /** 57 | * 设置微信AppId. 58 | */ 59 | public function updateStaticConfig($appId, $appSecrect) 60 | { 61 | $this->config->appId = $appId; 62 | $this->config->appSecrect = $appSecrect; 63 | $this->updateConfigFile(); 64 | } 65 | 66 | /** 67 | * 设置微信AppId. 68 | */ 69 | public function updateAllConfig() 70 | { 71 | $this->updateConfigFile(); 72 | } 73 | 74 | /** 75 | * 获取JS用签名等相关信息. 76 | */ 77 | public function getSign($url) 78 | { 79 | $jsapiTicket = $this->getJsTicket(); 80 | $timestamp = time(); 81 | $nonceStr = $this->getNonceString(); 82 | 83 | // 这里参数的顺序要按照 key 值 ASCII 码升序排序 84 | $signStr = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url"; 85 | 86 | $signature = sha1($signStr); 87 | 88 | $signPackage = array( 89 | 'appId' => $this->config->appId, 90 | 'nonceStr' => $nonceStr, 91 | 'timestamp' => $timestamp, 92 | //'url' => $url, 93 | 'signature' => $signature, 94 | //'rawString' => $signStr, 95 | ); 96 | 97 | return $signPackage; 98 | } 99 | 100 | /** 101 | * 获取服务器出口IP. 102 | */ 103 | public static function getOutIp(){ 104 | $response = wp_remote_get("http://myip.fireflysoft.net/"); 105 | return wp_remote_retrieve_body($response); 106 | } 107 | 108 | /** 109 | * 从缓存获取配置信息. 110 | */ 111 | private function initConfig() 112 | { 113 | $this->config = new Bosima_WeChat_AccessConfig(); 114 | 115 | if (empty($this->config->appId)) { 116 | $this->initConfigFormFile(); 117 | } 118 | } 119 | 120 | /** 121 | * 从配置文件初始化配置信息. 122 | */ 123 | private function initConfigFormFile() 124 | { 125 | $configPath = BOSIMA_WECHAT_DATAPATH.'data.php'; 126 | if (file_exists($configPath)) { 127 | $configContent = trim(substr(file_get_contents($configPath), 15)); 128 | 129 | if ($configContent) { 130 | $this->config = json_decode($configContent); 131 | } 132 | 133 | if ($this->config->appId && $this->config->appSecrect) { 134 | $this->checkAccessToken(); 135 | $this->checkJsTicket(); 136 | } 137 | } 138 | } 139 | 140 | /** 141 | * 更新微信配置文件. 142 | */ 143 | private function updateConfigFile() 144 | { 145 | // 对于写文件进行加锁 146 | $lock = BOSIMA_WECHAT_DATAPATH.'config.lck'; 147 | 148 | try { 149 | while (true) { 150 | if (file_exists($lock)) { 151 | usleep(100); 152 | } else { 153 | touch($lock); 154 | $configPath = BOSIMA_WECHAT_DATAPATH.'data.php'; 155 | $content = json_encode($this->config); 156 | file_put_contents($configPath, ''.$content); 157 | 158 | if (file_exists($lock)) { 159 | unlink($lock); 160 | } 161 | 162 | break; 163 | } 164 | } 165 | } catch (Exception $ex) { 166 | if (file_exists($lock)) { 167 | unlink($lock); 168 | } 169 | } 170 | } 171 | 172 | /** 173 | * 获取随机数. 174 | */ 175 | private function getNonceString($length = 16) 176 | { 177 | $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; 178 | $str = ''; 179 | $len = strlen($chars); 180 | for ($i = 0; $i < $length; ++$i) { 181 | $str .= substr($chars, mt_rand(0, $len - 1), 1); 182 | } 183 | 184 | return $str; 185 | } 186 | 187 | /** 188 | * 获取微信接口AccessToken. 189 | */ 190 | private function getAccessToken() 191 | { 192 | $this->checkAccessToken(); 193 | 194 | return $this->config->accessToken; 195 | } 196 | 197 | /** 198 | * 获取微信接口JS Ticket. 199 | */ 200 | private function getJsTicket() 201 | { 202 | $this->checkJsTicket(); 203 | 204 | return $this->config->jsTicket; 205 | } 206 | 207 | /** 208 | * 检查Access Token,如果无效,则获取. 209 | */ 210 | private function checkAccessToken() 211 | { 212 | if (empty($this->config->accessToken) || $this->config->accessTokenDeadline < time()) { 213 | $this->setAccessTokenFromRemote(); 214 | } 215 | } 216 | 217 | /** 218 | * 检查JS Ticket,如果无效,则获取. 219 | */ 220 | private function checkJsTicket() 221 | { 222 | if (empty($this->config->jsTicket) || $this->config->jsTicketDeadline < time()) { 223 | $this->setJSTicketFromRemote(); 224 | } 225 | } 226 | 227 | /** 228 | * 通过远程接口设置Access Token. 229 | */ 230 | private function setAccessTokenFromRemote() 231 | { 232 | // 从远程接口获取 233 | $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&'. 234 | 'appid='.$this->config->appId. 235 | '&secret='.$this->config->appSecrect; 236 | 237 | $result = $this->doCurl($url); 238 | 239 | if ($result) { 240 | $j = json_decode($result); 241 | 242 | if (isset($j->access_token)) { 243 | // 设置到缓存 244 | $this->config->accessToken = $j->access_token; 245 | $this->config->accessTokenDeadline = time() + 7000; 246 | 247 | // 保存文件 248 | $this->updateConfigFile(); 249 | } 250 | } 251 | } 252 | 253 | /** 254 | * 通过远程接口设置JS Ticket. 255 | */ 256 | private function setJSTicketFromRemote() 257 | { 258 | $tmpToken = $this->getAccessToken(); 259 | 260 | // 从远程接口获取 261 | $url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token='.$tmpToken.'&type=jsapi'; 262 | 263 | $result = $this->doCurl($url); 264 | 265 | if ($result) { 266 | $j = json_decode($result); 267 | if (isset($j->errcode) && $j->errcode == '0') { 268 | // 设置到缓存 269 | $this->config->jsTicket = $j->ticket; 270 | $this->config->jsTicketDeadline = time() + 7000; 271 | 272 | // 保存文件 273 | $this->updateConfigFile(); 274 | } 275 | } 276 | } 277 | 278 | /** 279 | * curl get请求 280 | * 281 | * @param url 请求地址 282 | * 283 | * @return 请求响应数据 284 | */ 285 | private function doCurl($url) 286 | { 287 | $response = wp_remote_get($url); 288 | $body = wp_remote_retrieve_body($response); 289 | 290 | return $body; 291 | } 292 | } -------------------------------------------------------------------------------- /sharing-admin.php: -------------------------------------------------------------------------------- 1 | getWeChatConfig(); 51 | 52 | // See if the user has posted us some information 53 | // If they did, this hidden field will be set to 'Y' 54 | if (isset($_POST[$hidden_field_name]) && $_POST[$hidden_field_name] == 'Y') { 55 | 56 | check_admin_referer(self::NONCENAME); 57 | 58 | // Read their posted value 59 | $config->appId = sanitize_text_field($_POST[$appid_field_name]); 60 | $config->appSecrect = sanitize_text_field($_POST[$appsecrect_field_name]); 61 | $config->sharing_page_title=sanitize_text_field($_POST[$sharing_page_title_field_name]); 62 | $config->sharing_page_description=sanitize_text_field($_POST[$sharing_page_description_field_name]); 63 | $config->sharing_tag_title=sanitize_text_field($_POST[$sharing_tag_title_field_name]); 64 | $config->sharing_tag_description=sanitize_text_field($_POST[$sharing_tag_description_field_name]); 65 | $config->sharing_search_title=sanitize_text_field($_POST[$sharing_search_title_field_name]); 66 | $config->sharing_search_description=sanitize_text_field($_POST[$sharing_search_description_field_name]); 67 | $config->sharing_archive_title=sanitize_text_field($_POST[$sharing_archive_title_field_name]); 68 | $config->sharing_archive_description=sanitize_text_field($_POST[$sharing_archive_description_field_name]); 69 | $config->sharing_img_option=sanitize_text_field($_POST[$sharing_img_option_field_name]); 70 | $config->sharing_home_img_useicon=sanitize_text_field($_POST[$sharing_home_img_useicon_field_name]); 71 | $config->sharing_home_title=sanitize_text_field($_POST[$sharing_home_title_field_name]); 72 | $config->sharing_home_description=sanitize_text_field($_POST[$sharing_home_description_field_name]); 73 | $config->sharing_single_title=sanitize_text_field($_POST[$sharing_single_title_field_name]); 74 | $config->sharing_single_description=sanitize_text_field($_POST[$sharing_single_description_field_name]); 75 | $config->sharing_category_title=sanitize_text_field($_POST[$sharing_category_title_field_name]); 76 | 77 | // Save the posted value in the database 78 | $weChat->updateAllConfig(); 79 | 80 | // Put an settings updated message on the screen 81 | ?> 82 |

83 | appId); 88 | $wechat_appsecrect = esc_attr($config->appSecrect); 89 | $sharing_page_title = esc_attr($config->sharing_page_title); 90 | $sharing_page_description = esc_attr($config->sharing_page_description); 91 | $sharing_tag_title = esc_attr($config->sharing_tag_title); 92 | $sharing_tag_description = esc_attr($config->sharing_tag_description); 93 | $sharing_search_title = esc_attr($config->sharing_search_title); 94 | $sharing_search_description = esc_attr($config->sharing_search_description); 95 | $sharing_archive_title = esc_attr($config->sharing_archive_title); 96 | $sharing_archive_description = esc_attr($config->sharing_archive_description); 97 | $sharing_img_option = esc_attr($config->sharing_img_option); 98 | $sharing_home_title = esc_attr($config->sharing_home_title); 99 | $sharing_home_img_useicon = esc_attr($config->sharing_home_img_useicon); 100 | $sharing_home_description = esc_attr($config->sharing_home_description); 101 | $sharing_single_description = esc_attr($config->sharing_single_description); 102 | $sharing_single_title = esc_attr($config->sharing_single_title); 103 | $sharing_category_title = esc_attr($config->sharing_category_title); 104 | 105 | $out_ip = Bosima_WeChat::getOutIp(); 106 | 107 | echo '
'; 108 | echo '

'.__('WeChat Page Sharing Plugin Settings', 'wechat-page-sharing').'

'; ?> 109 |
110 | 111 | 112 | 113 | 114 |

115 |

1.

116 |

2.

117 |

3.

118 |

4.

119 |

5.

120 |

121 |
122 | 123 |

124 |

125 | 126 |

127 |

128 | 129 |

130 | 136 |
137 |

138 | 139 |

140 | 141 | {blog_name} {blog_sub_name} 142 |

143 |

144 | 145 | {blog_name} {blog_sub_name} 146 |

147 |

148 | > 149 | > 150 |

151 |

152 | 153 | {blog_name} {blog_sub_name} {category_name} 154 |

155 |

156 | 157 | {blog_name} {blog_sub_name} {post_title} 158 |

159 |

160 | 161 | {blog_name} {blog_sub_name} {post_title} {post_excerpt} 162 |

163 |

164 | 165 | {blog_name} {blog_sub_name} {post_title} 166 |

167 |

168 | 169 | {blog_name} {blog_sub_name} {post_title} 170 |

171 |

172 | 173 | {blog_name} {blog_sub_name} {tag_con} 174 |

175 |

176 | 177 | {blog_name} {blog_sub_name} {tag_con} 178 |

179 |

180 | 181 | {blog_name} {blog_sub_name} {archive_date} 182 |

183 |

184 | 185 | {blog_name} {blog_sub_name} {archive_date} 186 |

187 |

188 | 189 | {blog_name} {blog_sub_name} {search_con} 190 |

191 |

192 | 193 | {blog_name} {blog_sub_name} {search_con} 194 |

195 |

196 | > 197 | > 198 | 199 |

200 |
201 | 202 |

203 | 204 |

205 |
206 |
207 | sharing_img_option)) { 28 | $config->sharing_img_option = "0"; 29 | } 30 | 31 | if ($config->sharing_img_option == "1" && has_post_thumbnail()) { 32 | $post_thumbnail = get_the_post_thumbnail_url(null, 'thumbnail'); 33 | } 34 | 35 | if ($config->sharing_img_option == "0" || empty($post_thumbnail)) { 36 | $output = preg_match_all('/]+?src=[\'"]([^\'"]+)[\'"].*>/i', $post_content, $matches); 37 | if (isset($matches[1][0]) && !empty($matches[1][0])) { 38 | $post_thumbnail = $matches[1][0]; 39 | } 40 | } 41 | 42 | if (empty($post_thumbnail)) { 43 | $post_thumbnail = plugins_url('', __FILE__) . '/images/random/article' . rand(1, 5) . '.jpg'; 44 | } 45 | 46 | return $post_thumbnail; 47 | } 48 | 49 | /** 50 | * 判断字符串结尾 51 | */ 52 | public static function endWith($haystack, $needle) 53 | { 54 | $length = strlen($needle); 55 | if ($length == 0) { 56 | return true; 57 | } 58 | return (substr($haystack, -$length) === $needle); 59 | } 60 | 61 | /** 62 | * 获取当前页面Url 63 | */ 64 | private static function curPageURL() 65 | { 66 | $current_url = 'http://'; 67 | $current_port = ''; 68 | if ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) { 69 | $current_url = 'https://'; 70 | if ($_SERVER['SERVER_PORT'] != '443') { 71 | $current_port = $_SERVER['SERVER_PORT']; 72 | } 73 | } 74 | 75 | if ($current_url == 'http://' && $_SERVER['SERVER_PORT'] != '80') { 76 | $current_port = $_SERVER['SERVER_PORT']; 77 | } 78 | 79 | $host = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''); 80 | $current_url .= $host. $_SERVER['REQUEST_URI']; 81 | 82 | return $current_url; 83 | } 84 | 85 | /** 86 | * 输出微信分享配置JS 87 | */ 88 | public static function render_config_js($config) 89 | { 90 | global $post, $posts; 91 | global $wp; 92 | 93 | $share_title = ''; 94 | $default_share_title = get_bloginfo('name'); 95 | $share_img_url = ''; 96 | $share_desc = ''; 97 | $default_share_desc = "想知道【" . get_bloginfo('name') . "】的更多内容吗?现在就点我吧。"; 98 | $default_img_url = plugins_url('', __FILE__) . '/images/random/article' . rand(1, 5) . '.jpg'; 99 | $use_icon_as_share_img = '0'; 100 | $site_lang = explode('_', get_locale())[0]; 101 | 102 | if (is_single()) { 103 | $default_share_title = $post->post_title; 104 | $share_img_url = Bosima_WeChat_Page_Sharing_Page::get_post_img_url($post->post_content, $config); 105 | $default_share_desc = wp_strip_all_tags($post->post_excerpt); 106 | $description_template_vars = array( 107 | '{blog_name}' => get_bloginfo('name'), 108 | '{blog_sub_name}' => get_bloginfo('description'), 109 | '{post_title}' => $post->post_title, 110 | '{post_excerpt}' => $default_share_desc 111 | ); 112 | if (!empty($config->sharing_single_description)) { 113 | $share_desc = strtr($config->sharing_single_description, $description_template_vars); 114 | } 115 | $title_template_vars = array( 116 | '{blog_name}' => get_bloginfo('name'), 117 | '{blog_sub_name}' => get_bloginfo('description'), 118 | '{post_title}' => $post->post_title, 119 | ); 120 | if (!empty($config->sharing_single_title)) { 121 | $share_title = strtr($config->sharing_single_title, $title_template_vars); 122 | } 123 | } elseif (is_page()) { 124 | $template_vars = array( 125 | '{blog_name}' => get_bloginfo('name'), 126 | '{blog_sub_name}' => get_bloginfo('description'), 127 | '{post_title}' => $post->post_title 128 | ); 129 | $share_img_url = Bosima_WeChat_Page_Sharing_Page::get_post_img_url($post->post_content, $config); 130 | $default_share_title = $post->post_title . ' | ' . get_bloginfo('name'); 131 | $default_share_desc = "想知道【" . $post->post_title . "】的更多内容吗?现在就点我吧。"; 132 | if (!empty($config->sharing_page_description)) { 133 | $share_desc = strtr($config->sharing_page_description, $template_vars); 134 | } 135 | if (!empty($config->sharing_page_title)) { 136 | $share_title = strtr($config->sharing_page_title, $template_vars); 137 | } 138 | } elseif (is_home() || is_front_page()) { 139 | $template_vars = array( 140 | '{blog_name}' => get_bloginfo('name'), 141 | '{blog_sub_name}' => get_bloginfo('description') 142 | ); 143 | $default_share_desc = "这是【" . get_bloginfo('name') . "】的官方网站,请注意收藏。"; 144 | 145 | $default_share_title = get_bloginfo('name') . ' | ' . get_bloginfo('description'); 146 | if (!empty($config->sharing_home_title)) { 147 | $share_title = strtr($config->sharing_home_title, $template_vars); 148 | } 149 | if (!empty($config->sharing_home_description)) { 150 | $share_desc = strtr($config->sharing_home_description, $template_vars); 151 | } 152 | if (!empty($config->sharing_home_img_useicon)) { 153 | $use_icon_as_share_img = $config->sharing_home_img_useicon; 154 | } 155 | } elseif (is_category()) { 156 | $cate_name = single_cat_title('', false); 157 | $template_vars = array( 158 | '{blog_name}' => get_bloginfo('name'), 159 | '{blog_sub_name}' => get_bloginfo('description'), 160 | '{category_name}' => $cate_name 161 | ); 162 | $default_share_desc = "想知道【" . $cate_name . "】的更多内容吗?现在就点我吧。"; 163 | $default_share_title = $cate_name . ' | ' . get_bloginfo('name'); 164 | $category_description = wp_strip_all_tags(category_description()); 165 | if (!empty($category_description)) { 166 | $share_desc = $category_description; 167 | } 168 | 169 | if (!empty($config->sharing_category_title)) { 170 | $share_title = strtr($config->sharing_category_title, $template_vars); 171 | } 172 | } elseif (is_tag()) { 173 | $tag_con = single_term_title('', false); 174 | $tag_con = htmlspecialchars($tag_con); 175 | $template_vars = array( 176 | '{blog_name}' => get_bloginfo('name'), 177 | '{blog_sub_name}' => get_bloginfo('description'), 178 | '{tag_con}' => $tag_con 179 | ); 180 | $default_share_title = $tag_con . ' | ' . get_bloginfo('name'); 181 | $default_share_desc = "想知道【" . $tag_con . "】的更多内容吗?现在就点我吧。"; 182 | if (!empty($config->sharing_tag_description)) { 183 | $share_desc = strtr($config->sharing_tag_description, $template_vars); 184 | } 185 | if (!empty($config->sharing_tag_title)) { 186 | $share_title = strtr($config->sharing_tag_title, $template_vars); 187 | } 188 | } elseif (is_archive()) { 189 | $m = get_query_var('m'); 190 | $year = get_query_var('year'); 191 | $monthnum = get_query_var('monthnum'); 192 | $day = get_query_var('day'); 193 | $archive_date = ''; 194 | 195 | if (!empty($m)) { 196 | $my_year = substr($m, 0, 4); 197 | $my_month = $wp_locale->get_month(substr($m, 4, 2)); 198 | $my_day = intval(substr($m, 6, 2)); 199 | if ($site_lang == "zh") { 200 | $archive_date = $my_year . '年' . ($my_month ? $my_month . '月' : '') . ($my_day ? $my_day . '日' : ''); 201 | } else { 202 | $archive_date = $my_year . '/' . ($my_month ? $my_month . '/' : '') . ($my_day ? $my_day : ''); 203 | } 204 | } 205 | 206 | if (!empty($year)) { 207 | $archive_date = $year . '年'; 208 | if ($site_lang != "zh") { 209 | $archive_date = $year; 210 | } 211 | if (!empty($monthnum)) { 212 | if ($site_lang != "zh") { 213 | $archive_date .= '/' . $monthnum; 214 | } else { 215 | $archive_date .= $monthnum . '月'; 216 | } 217 | } 218 | 219 | if (!empty($day)) { 220 | if ($site_lang != "zh") { 221 | $archive_date .= '/' . zeroise($day, 2); 222 | } else { 223 | $archive_date .= zeroise($day, 2) . '日'; 224 | } 225 | } 226 | } 227 | 228 | $template_vars = array( 229 | '{blog_name}' => get_bloginfo('name'), 230 | '{blog_sub_name}' => get_bloginfo('description'), 231 | '{archive_date}' => $archive_date 232 | ); 233 | $default_share_title = $archive_date . ' | ' . get_bloginfo('name'); 234 | $default_share_desc = "想知道" . $archive_date . "都有什么吗?现在就点我吧。"; 235 | if (!empty($config->sharing_archive_description)) { 236 | $share_desc = strtr($config->sharing_archive_description, $template_vars); 237 | } 238 | if (!empty($config->sharing_archive_title)) { 239 | $share_title = strtr($config->sharing_archive_title, $template_vars); 240 | } 241 | } elseif (is_search()) { 242 | $search = get_query_var('s'); 243 | $search_con = strip_tags($search); 244 | $template_vars = array( 245 | '{blog_name}' => get_bloginfo('name'), 246 | '{blog_sub_name}' => get_bloginfo('description'), 247 | '{search_con}' => $search_con 248 | ); 249 | $default_share_title = $search_con . ' | ' . get_bloginfo('name'); 250 | $default_share_desc = "想知道【" . $search_con . "】的更多内容吗?点我开始搜索吧。"; 251 | if (!empty($config->sharing_search_description)) { 252 | $share_desc = strtr($config->sharing_search_description, $template_vars); 253 | } 254 | if (!empty($config->sharing_search_title)) { 255 | $share_title = strtr($config->sharing_search_title, $template_vars); 256 | } 257 | } 258 | 259 | // todo:support custom post type 260 | // https://codex.wordpress.org/Post_Types#Custom_Post_Types 261 | 262 | ?> 263 | var use_icon_as_share_img = ""; 264 | var default_img_url=''; 265 | var share_img_url=''; 266 | var share_desc=""; 267 | var default_share_desc=""; 268 | var share_title=""; 269 | var default_share_title=""; 270 | var current_url=location.href.split('#')[0]; 271 | 272 | if(share_title==""){ 273 | share_title=jQuery("head title").text(); 274 | } 275 | if(share_title==""){ 276 | share_title=default_share_title; 277 | } 278 | 279 | if(use_icon_as_share_img=="1"){ 280 | var icons = jQuery("head link[rel='shortcut icon']"); 281 | if(icons!=null&&icons.length>0){ 282 | share_img_url=jQuery(icons[0]).attr('href'); 283 | } 284 | } 285 | 286 | if(share_img_url==''){ 287 | var imgs = document.getElementsByTagName("img"); 288 | for(var i=0;i=100&&imgs[i].height>=100){ 290 | share_img_url=imgs[i].src; 291 | break; 292 | } 293 | } 294 | 295 | if(share_img_url==''){ 296 | share_img_url=default_img_url; 297 | } 298 | } 299 | 300 | if(share_desc==''){ 301 | var meta = document.getElementsByTagName('meta'); 302 | for(i in meta){ 303 | if(typeof meta[i].name!="undefined" && meta[i].name.toLowerCase()=="description"){ 304 | share_desc = meta[i].content; 305 | break; 306 | } 307 | } 308 | } 309 | 310 | if(share_desc==''){ 311 | share_desc=default_share_desc; 312 | } 313 | 314 | wx.config({ 315 | debug: false, 316 | appId: weChatJsSign.appId, 317 | timestamp: weChatJsSign.timestamp, 318 | nonceStr: weChatJsSign.nonceStr, 319 | signature: weChatJsSign.signature, 320 | jsApiList: [ 321 | 'updateAppMessageShareData', 322 | 'updateTimelineShareData', 323 | 'onMenuShareWeibo' 324 | ] 325 | }); 326 | 327 | wx.ready(function () { 328 | wx.updateTimelineShareData({ 329 | title: share_title, 330 | link: current_url, 331 | imgUrl: share_img_url 332 | }); 333 | 334 | wx.updateAppMessageShareData({ 335 | title: share_title, 336 | desc: share_desc, 337 | link: current_url, 338 | imgUrl: share_img_url 339 | }); 340 | 341 | wx.onMenuShareWeibo({ 342 | title: share_title, 343 | desc: share_desc, 344 | link: current_url, 345 | imgUrl: share_img_url 346 | }); 347 | }); 348 | getWeChatConfig(); 367 | ?> 368 | 386 | 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------