update<first>
parent
4c5444b973
commit
2d1833a37a
@ -1,3 +1,11 @@
|
|||||||
# boheimg-wordpress-plugin
|
# boheimg-wordpress-plugin
|
||||||
|
|
||||||
薄荷图床的wordpress插件
|
薄荷图床的wordpress插件
|
||||||
|
|
||||||
|
# install
|
||||||
|
|
||||||
|
直接上传到wordpress的插件中
|
||||||
|
|
||||||
|
# use
|
||||||
|
|
||||||
|
进入插件设置页面正确配置你的相关信息
|
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
Plugin Name: 薄荷图床上传(Beta)
|
||||||
|
Plugin URI:
|
||||||
|
Description: 方便上传图片到薄荷图床,如有问题请点击反馈发送邮件
|
||||||
|
Version: 0.0.1
|
||||||
|
Author: 紗夕里
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
define('BohePro_WordPress_FILE', __FILE__);
|
||||||
|
define('BohePro_WordPress_DIRNAME', dirname(__FILE__));
|
||||||
|
define('BohePro_WordPress_Plugin', plugins_url('',__FILE__));
|
||||||
|
|
||||||
|
require BohePro_WordPress_DIRNAME . '/includes/bohe-config.php';
|
||||||
|
require BohePro_WordPress_DIRNAME . '/upload/bohe-img.php';
|
||||||
|
|
||||||
|
add_action( 'admin_init', 'bohe_upload_admin_init' );
|
||||||
|
function bohe_upload_admin_init() {
|
||||||
|
add_filter( 'plugin_action_links', 'bohe_upload_add_link', 10, 2 );
|
||||||
|
}
|
||||||
|
function bohe_upload_add_link( $actions, $plugin_file ) { //添加设置按钮
|
||||||
|
static $plugin;
|
||||||
|
if (!isset($plugin))
|
||||||
|
$plugin = plugin_basename(__FILE__);
|
||||||
|
if ($plugin == $plugin_file) {
|
||||||
|
$settings = array('settings' => '<a href="admin.php?page=boheupload_options">' . __('Settings') . '</a>');
|
||||||
|
$site_link = array('contact' => '<a href="mailto:mirai@lolicon.team" target="_blank">反馈</a>','bohe' => '<a href="https://lolicon.team/" target="_blank">博客</a>');
|
||||||
|
$actions = array_merge($settings, $actions);
|
||||||
|
$actions = array_merge($site_link, $actions);
|
||||||
|
}
|
||||||
|
return $actions;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,111 @@
|
|||||||
|
.com-hd {
|
||||||
|
margin: 20px 0 15px
|
||||||
|
}
|
||||||
|
|
||||||
|
.com-hd b {
|
||||||
|
font-size: 16px;
|
||||||
|
color: #333;
|
||||||
|
font-family: 'Microsoft Yahei'
|
||||||
|
}
|
||||||
|
|
||||||
|
.tb-set {
|
||||||
|
border-collapse: collapse
|
||||||
|
}
|
||||||
|
|
||||||
|
.tb-set tr td {
|
||||||
|
padding: 10px 5px;
|
||||||
|
border: 1px solid #e0e0e0
|
||||||
|
}
|
||||||
|
|
||||||
|
.actived {
|
||||||
|
color: red
|
||||||
|
}
|
||||||
|
|
||||||
|
.tb-set tr td input,
|
||||||
|
.tb-set tr td img {
|
||||||
|
margin: 0 auto;
|
||||||
|
vertical-align: middle
|
||||||
|
}
|
||||||
|
|
||||||
|
.tb-set tr td b {
|
||||||
|
color: #000
|
||||||
|
}
|
||||||
|
|
||||||
|
.tb-set tr td .sel {
|
||||||
|
height: 17px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 5px;
|
||||||
|
outline: 0;
|
||||||
|
color: #333;
|
||||||
|
padding: 3px 1px
|
||||||
|
}
|
||||||
|
|
||||||
|
.tb-set tr td .sel select {
|
||||||
|
border: 0;
|
||||||
|
outline: 0;
|
||||||
|
width: auto
|
||||||
|
}
|
||||||
|
|
||||||
|
.tb-set tr td .txt {
|
||||||
|
width: 80%;
|
||||||
|
height: 28px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
line-height: 20px;
|
||||||
|
outline: 0;
|
||||||
|
color: #333;
|
||||||
|
padding: 2px 0 2px 5px;
|
||||||
|
margin: -2px 0 0 5px
|
||||||
|
}
|
||||||
|
|
||||||
|
.tb-set tr td .sec {
|
||||||
|
width: 30px;
|
||||||
|
height: 20px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
line-height: 20px;
|
||||||
|
border-radius: 5px;
|
||||||
|
outline: 0;
|
||||||
|
color: #333;
|
||||||
|
padding: 2px 0 2px 5px;
|
||||||
|
margin: -2px 0 0 5px
|
||||||
|
}
|
||||||
|
|
||||||
|
.tb-set tr td .dy {
|
||||||
|
width: 15%;
|
||||||
|
height: 20px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
line-height: 20px;
|
||||||
|
border-radius: 5px;
|
||||||
|
outline: 0;
|
||||||
|
vertical-align: middle;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #0c0;
|
||||||
|
padding: 2px 0 2px 5px;
|
||||||
|
margin: -2px 0 0 5px
|
||||||
|
}
|
||||||
|
|
||||||
|
.tb-set tr td .txt-lar {
|
||||||
|
width: 450px;
|
||||||
|
height: 100px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
line-height: 15px
|
||||||
|
}
|
||||||
|
|
||||||
|
.tb-set tr td .txt-sho {
|
||||||
|
width: 150px
|
||||||
|
}
|
||||||
|
|
||||||
|
.message {
|
||||||
|
margin: 1em 0;
|
||||||
|
padding: .5em;
|
||||||
|
height: 30px;
|
||||||
|
line-height: 30px;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.success {
|
||||||
|
border-left: 3px solid #0c0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
border-left: 3px solid #c00;
|
||||||
|
}
|
@ -0,0 +1,97 @@
|
|||||||
|
.bohe-upload {
|
||||||
|
padding: 4px 10px;
|
||||||
|
height: 20px;
|
||||||
|
line-height: 20px;
|
||||||
|
position: relative;
|
||||||
|
cursor: pointer;
|
||||||
|
color: #888;
|
||||||
|
background: #fafafa;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
overflow: hidden;
|
||||||
|
display: inline-block;
|
||||||
|
zoom: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bohe-upload input {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
opacity: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bohe-upload:hover {
|
||||||
|
color: #444;
|
||||||
|
background: #eee;
|
||||||
|
border-color: #ccc;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#bohe-tip {
|
||||||
|
margin-left: 10px;
|
||||||
|
padding: 0 15px;
|
||||||
|
display: inline-block;
|
||||||
|
height: 30px;
|
||||||
|
position: absolute;
|
||||||
|
text-align: center;
|
||||||
|
line-height: 30px;
|
||||||
|
background: #fff;
|
||||||
|
color: #c00;
|
||||||
|
font-size: 12px;
|
||||||
|
border-radius: 6px;
|
||||||
|
box-shadow: 0px 0px 12px 4px rgba(0, 0, 0, .05);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#bohe-upload-box {
|
||||||
|
width: auto;
|
||||||
|
height: 100px;
|
||||||
|
border: 3px dashed silver;
|
||||||
|
line-height: 100px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 20px;
|
||||||
|
color: #d3d3d3;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#bohe-upload-box-input {
|
||||||
|
position: absolute;
|
||||||
|
display: block;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
bottom: 0;
|
||||||
|
right: 0;
|
||||||
|
opacity: 0;
|
||||||
|
-moz-opacity: 0;
|
||||||
|
filter: alpha(opacity=0);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#result {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 15px;
|
||||||
|
border-radius: 4px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 20px;
|
||||||
|
color: #d3d3d3;
|
||||||
|
}
|
||||||
|
|
||||||
|
#result input {
|
||||||
|
width: 100%;
|
||||||
|
height: 40px;
|
||||||
|
outline-style: none;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#result input:not(:last-child) {
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#result input:focus {
|
||||||
|
border: 1px solid #425AEF;
|
||||||
|
}
|
@ -0,0 +1,160 @@
|
|||||||
|
<?php
|
||||||
|
add_action('media_buttons', 'add_bohe_upload_button');
|
||||||
|
function add_bohe_upload_button() {
|
||||||
|
if(!empty(wp_get_current_user()->roles) && in_array('administrator', wp_get_current_user()->roles)){
|
||||||
|
$getdataDoMain = get_option('domain');
|
||||||
|
$getdataTokens = get_option('tokens');
|
||||||
|
$getdataProtocolType = get_option('protocol_type');
|
||||||
|
$getdataMode = get_option('mode');
|
||||||
|
$getdataUploadPath = get_option('uploadPath');
|
||||||
|
$getdataWatermark = get_option('watermark');
|
||||||
|
$getdataImageCompress = get_option('image_compress');
|
||||||
|
$getdataImageCompressLevel = get_option('image_compress_level');
|
||||||
|
}
|
||||||
|
else return 0;
|
||||||
|
?>
|
||||||
|
<link href="<?php echo plugin_dir_url(__FILE__ ); ?>assets/style.css" type="text/css" rel="stylesheet" />
|
||||||
|
<a href="javascript:;" class="bohe-upload"><input type="file" id="input-bohe-upload" multiple />上传图片</a>
|
||||||
|
<span id="tip">上传图片过程中请耐心等待!请勿刷新页面,如果等待时间过长没有上传成功可以刷新页面重试或检查插件设置</span>
|
||||||
|
<script src="//lib.baomitu.com/axios/0.27.2/axios.min.js"></script>
|
||||||
|
<script>
|
||||||
|
const bohe_upload = document.getElementById('input-bohe-upload');
|
||||||
|
bohe_upload.addEventListener("change", () => { //监听上传按钮
|
||||||
|
const getdataDoMain = "<?php echo get_option('domain'); ?>";
|
||||||
|
const getdataTokens = "<?php echo get_option('tokens'); ?>";
|
||||||
|
const getdataProtocolType = "<?php echo get_option('protocol_type'); ?>"; //协议类型
|
||||||
|
const getdataMode = "<?php echo get_option('mode'); ?>";
|
||||||
|
const getdataUploadPath = "<?php echo get_option('uploadPath'); ?>";
|
||||||
|
const getdataWatermark = "<?php echo get_option('watermark'); ?>";
|
||||||
|
const getdataImageCompress = "<?php echo get_option('image_compress'); ?>";
|
||||||
|
const getdataImageCompressLevel = "<?php echo get_option('image_compress_level'); ?>";
|
||||||
|
|
||||||
|
const files = bohe_upload.files;
|
||||||
|
for(let i = 0; i < files.length; i++) {
|
||||||
|
const file = files[i];
|
||||||
|
const formData = new FormData();
|
||||||
|
//输出调试信息
|
||||||
|
formData.append("api_token", getdataTokens);
|
||||||
|
formData.append('uploadedFile', file);
|
||||||
|
// 只在协议类型不为空时添加参数
|
||||||
|
if(getdataProtocolType !== ''){
|
||||||
|
formData.append('protocol_type', '<?php echo get_option('protocol_type'); ?>');
|
||||||
|
}
|
||||||
|
if(getdataMode !== ''){
|
||||||
|
formData.append('mode', getdataMode);
|
||||||
|
}
|
||||||
|
if(getdataImageCompress !== ''){
|
||||||
|
formData.append('image_compress', '1');
|
||||||
|
formData.append('image_compress_level', '<?php echo get_option('image_compress_level'); ?>');
|
||||||
|
}
|
||||||
|
formData.append('uploadPath', '<?php echo get_option('uploadPath'); ?>');
|
||||||
|
|
||||||
|
// 添加水印和压缩参数判断
|
||||||
|
if(getdataWatermark === '1'){
|
||||||
|
formData.append('watermark', '1');
|
||||||
|
}
|
||||||
|
document.getElementById('input-bohe-upload').disabled = true;
|
||||||
|
document.getElementById('tip').innerHTML = '正在上传中...';
|
||||||
|
axios.defaults.crossDomain = true;
|
||||||
|
axios({
|
||||||
|
method:'post',
|
||||||
|
url: '<?php echo get_option('domain'); ?>/api/upload/',
|
||||||
|
data:formData
|
||||||
|
}).then(response => {
|
||||||
|
const data = response.data;
|
||||||
|
if (data.status) {
|
||||||
|
const url = data.url;
|
||||||
|
const name = data.originFileName;
|
||||||
|
wp.media.editor.insert('<a href="'+ url +'"><img src="'+ url +'" alt="'+ name +'" /></a>');
|
||||||
|
document.getElementById('input-bohe-upload').disabled = false;
|
||||||
|
document.getElementById('tip').innerHTML = '上传图片过程中请耐心等待!请勿刷新页面,如果等待时间过长没有上传成功可以刷新页面重试或检查插件设置';
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
console.log(error);
|
||||||
|
document.getElementById('input-bohe-upload').disabled = false;
|
||||||
|
document.getElementById('tip').innerHTML = '上传图片过程中请耐心等待!请勿刷新页面,若等待时间过长可以尝试刷新页面重试或检查插件设置';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<?php }
|
||||||
|
add_action('add_meta_boxes', 'add_bohe_upload_box');
|
||||||
|
function add_bohe_upload_box() {
|
||||||
|
if(!empty(wp_get_current_user()->roles) && in_array('administrator', wp_get_current_user()->roles)){
|
||||||
|
add_meta_box('bohe_upload_box_tmp', '薄荷图床(BohePro)上传', 'bohe_upload_box', 'post', 'side', 'high');
|
||||||
|
}
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
function bohe_upload_box() {?>
|
||||||
|
<link href="<?php echo plugin_dir_url(__FILE__ ); ?>assets/style.css" type="text/css" rel="stylesheet" />
|
||||||
|
<div id="bohe-upload-box">点击此区域上传图片</div>
|
||||||
|
<input type="file" multiple id="bohe-upload-box-input" />
|
||||||
|
<div id="result"></div>
|
||||||
|
<script src="//lib.baomitu.com/axios/0.27.2/axios.min.js"></script>
|
||||||
|
<script>
|
||||||
|
const bohe_upload_input = document.getElementById('bohe-upload-box-input');
|
||||||
|
bohe_upload_input.addEventListener("change", () => {
|
||||||
|
const getdataDoMain = "<?php echo get_option('domain'); ?>";
|
||||||
|
const getdataTokens = "<?php echo get_option('tokens'); ?>";
|
||||||
|
const getdataProtocolType = "<?php echo get_option('protocol_type'); ?>"; //协议类型
|
||||||
|
const getdataMode = "<?php echo get_option('mode'); ?>";
|
||||||
|
const getdataUploadPath = "<?php echo get_option('uploadPath'); ?>";
|
||||||
|
const getdataWatermark = "<?php echo get_option('watermark'); ?>";
|
||||||
|
const getdataImageCompress = "<?php echo get_option('image_compress'); ?>";
|
||||||
|
const getdataImageCompressLevel = "<?php echo get_option('image_compress_level'); ?>";
|
||||||
|
const files = bohe_upload_input.files;
|
||||||
|
for(let i = 0; i < files.length; i++) {
|
||||||
|
const file = files[i];
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
formData.append("api_token", getdataTokens);
|
||||||
|
formData.append('uploadedFile', file);
|
||||||
|
// 只在协议类型不为空时添加参数
|
||||||
|
if(getdataProtocolType !== ''){
|
||||||
|
formData.append('protocol_type', '<?php echo get_option('protocol_type'); ?>');
|
||||||
|
}
|
||||||
|
if(getdataMode !== ''){
|
||||||
|
formData.append('mode', getdataMode);
|
||||||
|
}
|
||||||
|
if(getdataImageCompress !== ''){
|
||||||
|
formData.append('image_compress', '1');
|
||||||
|
formData.append('image_compress_level', '<?php echo get_option('image_compress_level'); ?>');
|
||||||
|
}
|
||||||
|
formData.append('uploadPath', '<?php echo get_option('uploadPath'); ?>');
|
||||||
|
// 添加水印和压缩参数判断
|
||||||
|
if(getdataWatermark === '1'){
|
||||||
|
formData.append('watermark', '1');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(formData);
|
||||||
|
document.getElementById('bohe-upload-box-input').disabled = true;
|
||||||
|
document.getElementById('bohe-upload-box').innerHTML = '正在上传中...';
|
||||||
|
axios({
|
||||||
|
method:'post',
|
||||||
|
url: '<?php echo get_option('domain'); ?>/api/upload/',
|
||||||
|
data:formData
|
||||||
|
}).then(response => {
|
||||||
|
const data = response.data;
|
||||||
|
if (data.status) {
|
||||||
|
const url = data.url;
|
||||||
|
const name = data.originFileName;
|
||||||
|
const input = document.createElement('input');
|
||||||
|
input.type = 'text';
|
||||||
|
input.value = url;
|
||||||
|
document.getElementById('result').appendChild(input);
|
||||||
|
input.addEventListener('click', function() {
|
||||||
|
input.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
});
|
||||||
|
document.getElementById('bohe-upload-box-input').disabled = false;
|
||||||
|
document.getElementById('bohe-upload-box').innerHTML = '点击此区域上传图片';
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
console.log(error);
|
||||||
|
document.getElementById('bohe-upload-box-input').disabled = false;
|
||||||
|
document.getElementById('bohe-upload-box').innerHTML = '点击此区域上传图片';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<?php } ?>
|
Loading…
Reference in New Issue