mirror of
https://github.com/yunluo/gdk.git
synced 2024-05-23 08:32:18 +02:00
增加一键更新安装插件功能
This commit is contained in:
parent
3168271cfe
commit
ffbd3af441
|
@ -50,7 +50,7 @@ function gdk_options_page()
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<h2>GDK选项 <input type="button" class="add-new-h2 get_new_version" value="检测更新"></h2>
|
<h2>GDK选项 <input type="button" class="add-new-h2 get_new_version" value="检测更新"><input type="button" data-url="" class="add-new-h2 install_new_version" value="安装更新"></h2>
|
||||||
<hr/>
|
<hr/>
|
||||||
<?php
|
<?php
|
||||||
if (isset($_GET['update'])) {
|
if (isset($_GET['update'])) {
|
||||||
|
@ -298,7 +298,7 @@ break;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
box-shadow: inset 0 0 0 2px #e14d43, 0 0 0 2px #e14d43;
|
box-shadow: inset 0 0 0 2px #e14d43, 0 0 0 2px #e14d43;
|
||||||
}
|
}
|
||||||
|
.install_new_version,
|
||||||
.wrap.searching .nav-tab-wrapper a,
|
.wrap.searching .nav-tab-wrapper a,
|
||||||
.wrap.searching .panel tr,
|
.wrap.searching .panel tr,
|
||||||
body.show-filters .wrap form {
|
body.show-filters .wrap form {
|
||||||
|
@ -321,6 +321,17 @@ body.show-filters .wrap form {
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
font-size: medium;
|
font-size: medium;
|
||||||
}
|
}
|
||||||
|
.g-load{
|
||||||
|
background: url(images/spinner.gif) no-repeat;
|
||||||
|
background-size: 20px 20px;
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: middle;
|
||||||
|
opacity: .7;
|
||||||
|
filter: alpha(opacity=70);
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
margin: 4px 10px 0;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<style id="theme-options-filter"></style>
|
<style id="theme-options-filter"></style>
|
||||||
<script>
|
<script>
|
||||||
|
@ -377,20 +388,35 @@ jQuery(function ($) {
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".get_new_version").click(function () {
|
$(".get_new_version").click(function () {
|
||||||
|
$(".get_new_version").after("<span class='g-load'></span>");
|
||||||
var ajax_data = { action: 'get_new_version' };
|
var ajax_data = { action: 'get_new_version' };
|
||||||
$.get(ajaxurl, ajax_data,
|
$.get(ajaxurl, ajax_data,
|
||||||
function(a) {
|
function(a) {
|
||||||
a = $.trim(a);
|
a = $.trim(a);
|
||||||
|
$(".g-load").hide();
|
||||||
if (a !== '400') {
|
if (a !== '400') {
|
||||||
|
if ($(".get_update_res").length > 0) return;
|
||||||
$(".get_new_version").after(a);
|
$(".get_new_version").after(a);
|
||||||
|
$(".install_new_version").show();
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
$(".get_new_version").after("检测失败,网络错误");
|
$(".get_new_version").after("检测失败,网络错误");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(".install_new_version").click(function () {
|
||||||
|
$(".install_new_version").after("<span class='g-load'></span>");
|
||||||
|
var ajax_data = { action: 'install_new_version' };
|
||||||
|
$.get(ajaxurl, ajax_data,
|
||||||
|
function() {
|
||||||
|
$(".g-load").hide();
|
||||||
|
window.location.reload();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
$(".feedback-btn").click(function() {
|
$(".feedback-btn").click(function() {
|
||||||
$(".feedback-btn").after(" <span class='feedback-load'>正在努力加载中.....</span>");
|
$(".feedback-btn").after("<span class='g-load'></span>");
|
||||||
$("<link>").attr({
|
$("<link>").attr({
|
||||||
rel: "stylesheet",
|
rel: "stylesheet",
|
||||||
type: "text/css",
|
type: "text/css",
|
||||||
|
@ -399,7 +425,7 @@ $(".feedback-btn").click(function() {
|
||||||
|
|
||||||
$.getScript("https://cdn.bootcss.com/fancybox/3.0.39/jquery.fancybox.min.js",
|
$.getScript("https://cdn.bootcss.com/fancybox/3.0.39/jquery.fancybox.min.js",
|
||||||
function() {
|
function() {
|
||||||
$(".feedback-load").hide();
|
$(".g-load").hide();
|
||||||
$.fancybox.open({
|
$.fancybox.open({
|
||||||
src: 'https://support.qq.com/products/51158/',
|
src: 'https://support.qq.com/products/51158/',
|
||||||
type: 'iframe',
|
type: 'iframe',
|
||||||
|
|
|
@ -33,7 +33,7 @@ function gdk_ajax_get_update()
|
||||||
$version = $plugin_info['version'];
|
$version = $plugin_info['version'];
|
||||||
|
|
||||||
if (version_compare($version, GDK_PLUGIN_VER, '>')) {
|
if (version_compare($version, GDK_PLUGIN_VER, '>')) {
|
||||||
exit('<span class="get_update_res">插件有更新,新版本:<span class="key_word">' . $version . '</span> <a class="feedback add-new-h2" href="' . $plugin_info['details_url'] . '" target="_blank">查看更新内容</a> <a class="feedback add-new-h2" href="' . $plugin_info['download_url'] . '" target="_blank">请点击下载</a></span>');
|
exit('<span class="get_update_res">插件有更新,新版本:<span class="key_word">' . $version . '</span> <a class="feedback add-new-h2" href="' . $plugin_info['details_url'] . '" target="_blank">查看更新内容</a></span>');
|
||||||
} else {
|
} else {
|
||||||
exit('<span class="get_update_res">你的插件目前已经是最新版了!</span>');
|
exit('<span class="get_update_res">你的插件目前已经是最新版了!</span>');
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,17 @@ function gdk_ajax_get_update()
|
||||||
add_action('wp_ajax_nopriv_get_new_version', 'gdk_ajax_get_update');
|
add_action('wp_ajax_nopriv_get_new_version', 'gdk_ajax_get_update');
|
||||||
add_action('wp_ajax_get_new_version', 'gdk_ajax_get_update');
|
add_action('wp_ajax_get_new_version', 'gdk_ajax_get_update');
|
||||||
|
|
||||||
|
//Ajax安装插件更新
|
||||||
|
function gdk_ajax_install_update()
|
||||||
|
{
|
||||||
|
$url = 'http://a.gitcafe.net/Git-alpha.zip';
|
||||||
|
unzip_url($url, ABSPATH . 'wp-content/plugins');
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
add_action('wp_ajax_nopriv_install_new_version', 'gdk_ajax_install_update');
|
||||||
|
add_action('wp_ajax_install_new_version', 'gdk_ajax_install_update');
|
||||||
|
|
||||||
//粘贴上传图片
|
//粘贴上传图片
|
||||||
function gdk_pasteup_imag()
|
function gdk_pasteup_imag()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1297,3 +1297,20 @@ function getQrcode($url)
|
||||||
header("content-type:application/json; charset=utf-8");
|
header("content-type:application/json; charset=utf-8");
|
||||||
return 'data:image/jpeg;base64,' . $imageString;
|
return 'data:image/jpeg;base64,' . $imageString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function unzip_url($url, $where)
|
||||||
|
{
|
||||||
|
$zippath = $where . '/' . (basename($url)) . '.zip';
|
||||||
|
wp_remote_get($url,
|
||||||
|
[
|
||||||
|
'timeout' => 300,
|
||||||
|
'stream' => true,
|
||||||
|
'filename' => $zippath,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||||
|
\WP_Filesystem();
|
||||||
|
\unzip_file($zippath, $where);
|
||||||
|
usleep(300000);
|
||||||
|
@unlink($zippath);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue