Skip to content

Commit

Permalink
更新日志
Browse files Browse the repository at this point in the history
  • Loading branch information
friend-nicen committed Aug 30, 2022
1 parent f3b23fd commit f1826aa
Show file tree
Hide file tree
Showing 10 changed files with 351 additions and 312 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: nicen-localize-image
Plugin URI:https://nicen.cn/2893.html
Description: 用于本地化文章的外部图片的插件,支持文章发布前通过编辑器插件本地化、文章发布时自动本地化、定时发布文章时自动本地化、已发布的文章批量本地化。
Version: 1.3.1
Version: 1.3.3
Author: 友人a丶
Author URI: https://nicen.cn
Text Domain: nicen-localize-image
Expand All @@ -22,6 +22,12 @@ nicen-localize-image,是一款用于本地化文章的外部图片的插件,

# 更新日志:

## v1.3.3

1. 修改代码适配wordpress插件商店规范;
2. 图片压缩完成后自动刷新显示的目录;
3. 修改网络请求超时时间为120s;

## v1.3.1 beta

1. 新增批量本地化时,可以指定文章分类,指定文章发布时间范围;
Expand Down
2 changes: 1 addition & 1 deletion admin/preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}


const NICEN_VERSION='1.3.2'; //插件版本
const NICEN_VERSION='1.3.3'; //插件版本
/*
* 定时任务接口
* */
Expand Down
76 changes: 40 additions & 36 deletions admin/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,35 @@
/*
* 输出本地化日志
* */
function nicen_plugin_local_log() {
function nicen_plugin_local_log()
{

$logs = ( ( Nicen_log::getInstance() )->get_logs() );
$logs = ((Nicen_log::getInstance())->get_logs());

echo '<a-form-item label="相关操作">';
echo '<a-button type="primary" @click="clearLogs">清空插件日志</a-button>';
echo '</a-form-item>';
echo '<a-form-item label="相关操作">';
echo '<a-button type="primary" @click="clearLogs">清空插件日志</a-button>';
echo '</a-form-item>';

echo '
echo '
<a-form-item label="详细日志">
<a-textarea
value="' . ( empty( $logs ) ? '暂无日志' : $logs ) . '"
value="' . (empty($logs) ? '暂无日志' : $logs) . '"
:auto-size="{minRows: 5,maxRows:15}"
read-only/>
';
echo '</a-form-item>';
echo '</a-form-item>';


}


/*
/**
* 插件升级
* */
function nicen_plugin_update() {
*/
function nicen_plugin_update()
{

echo '
echo '
<a-form-item label="版本信息">
当前版本(' . NICEN_VERSION . ')/ 最新版本({{version}})
</a-form-item>
Expand Down Expand Up @@ -94,22 +96,23 @@ function nicen_plugin_update() {

}

/*
/**
* 文章批量本地化
* */
function Nicen_form_batch() {
*/
function Nicen_form_batch()
{

$count = wp_count_posts();//文章总数
$last = get_option( 'nicen_last_batch' ); //上次本地化的ID
$count = wp_count_posts();//文章总数
$last = get_option('nicen_last_batch'); //上次本地化的ID

/*
* 获取上次的ID
* */
if ( ! empty( $last ) ) {
$last = '上次批量本地化的文章ID为:' . $last . '';
}
/*
* 获取上次的ID
* */
if (!empty($last)) {
$last = '上次批量本地化的文章ID为:' . $last . '';
}

echo ' <a-form-item label="功能说明">
echo ' <a-form-item label="功能说明">
<div style="line-height: 1.8; width: 150%; overflow-wrap: break-word; word-spacing: normal; word-break: break-all;">
按照指定的文章ID范围批量进行图片本地化,点击开始后任务自动运行,运行过程中可以随时暂停,关闭网页表示强制暂停!运行过程中将会展示实时日志!
<br/><br/>
Expand All @@ -127,15 +130,15 @@ function Nicen_form_batch() {
</a-input-number>
</a-form-item>';

echo '<a-form-item label="文章创建时间范围">
echo '<a-form-item label="文章创建时间范围">
<a-range-picker @change="selectRange" allow-clear></a-range-picker>
</a-form-item>';


echo "
echo "
<a-form-item label='选择指定分类'>
<a-select
:options='" . json_encode( nicen_plugin_getAllCat() ) . "'
:options='" . json_encode(nicen_plugin_getAllCat()) . "'
style='width: 100%'
show-arrow
mode='multiple'
Expand All @@ -145,32 +148,33 @@ function Nicen_form_batch() {
</a-select>
</a-form-item>";

echo '<a-form-item label="相关操作">';
echo '<a-space>
echo '<a-form-item label="相关操作">';
echo '<a-space>
<a-button type="primary" :loading="batch.loading" @click="getBatch">{{batch.loading?"正在运行,点击取消运行...":"开始运行"}}</a-button>
<a-button type="primary" v-if="batch.loading" @click="getBatch">取消运行</a-button>
</a-space>';
echo '</a-form-item>';
echo '</a-form-item>';

}


/*
* 文章批量本地化
* */
function Nicen_form_compress() {
function Nicen_form_compress()
{

echo '<a-form-item label="功能说明">选择指定的目录或者图片进行压缩,默认根目录为 /wp-content/uploads,压缩前请先点击加载图片目录,然后再选中目录或图片进行压缩 </a-form-item>';
echo '<a-form-item label="功能说明">选择指定的目录或者图片进行压缩,默认根目录为 wordpress媒体文件存放目录,压缩前请先点击加载图片目录,然后再选中目录或图片进行压缩 </a-form-item>';

echo '<a-form-item label="相关操作">';
echo '<a-space>
echo '<a-form-item label="相关操作">';
echo '<a-space>
<a-button type="primary" :loading="tree.loading" @click="compress">{{tree.loading?"正在压缩第"+tree.count+"张图片,点击取消压缩...":"开始压缩"}}</a-button>
<a-button type="primary" v-if="tree.loading" @click="compress">取消压缩</a-button>
<a-button type="primary" @click="loadFiles">加载图片目录</a-button>
</a-space>';
echo '</a-form-item>';
echo '</a-form-item>';

echo "<a-form-item label='选择指定文件或目录'>
echo "<a-form-item label='选择指定文件或目录'>
<a-tree
checkable
v-model='tree.selected'
Expand Down
1 change: 1 addition & 0 deletions assets/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ jQuery(function () {

that.tree.loading = false; //批量结束
that.tree.flag = false; //标记结束
that.loadFiles(); //重新加载文件目录
load.loaded();

},
Expand Down
6 changes: 4 additions & 2 deletions class/compress.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ function get( $url ) {
* */
$res = wp_remote_get( $url, [
'headers' => $headers,
'sslverify' => false
'sslverify' => false,
'timeout' => 120,
] );

return wp_remote_retrieve_body( $res );
Expand All @@ -137,7 +138,7 @@ function post( $file ) {
'files' => new \CURLFile( $file )
];

$Http = new WP_Http_Curl;
$Http = new WP_Http_Curl();

/*
* 修改请求配置
Expand All @@ -146,6 +147,7 @@ function post( $file ) {
'method' => 'POST',
'sslverify' => false,
'body' => $post_data,
'timeout' => 120,
'httpversion' => '1.1'
);

Expand Down
6 changes: 4 additions & 2 deletions class/local.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public static function getInstance() {
* */
function getHttpcode( $url ) {
$response = wp_remote_get( $url, [
'sslverify' => false
'sslverify' => false,
'timeout' => 60,
] );
$http_code = wp_remote_retrieve_response_code( $response );

Expand Down Expand Up @@ -69,7 +70,8 @@ function getImage( $url ) {
* */
$res = wp_remote_get( $url, [
'headers' => $headers,
'sslverify' => false
'sslverify' => false,
'timeout' => 120,
] );

return wp_remote_retrieve_body( $res );
Expand Down
2 changes: 1 addition & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
'nicen_make_plugin_save_result' => '', //临时保存本地化结果
'nicen_make_plugin_alt' => '1', //自动新增alt
'nicen_make_plugin_alt_type' => '1', //alt增加的类型
'nicen_make_plugin_path' => '/wp-content/uploads/replace', //资源保存的路径
'nicen_make_plugin_path' => NICEN_SITE_ROOT.'/uploads/replace', //资源保存的路径
'nicen_make_plugin_add_domain' => '0', //链接是否增加域名
'nicen_make_save_type'=>'png',

Expand Down
45 changes: 28 additions & 17 deletions nicen-localize-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,47 @@
* Plugin Name: nicen-localize-image
* Plugin URI:https://nicen.cn/2893.html
* Description: 用于本地化文章的外部图片的插件,支持文章发布前通过编辑器插件本地化、文章发布时自动本地化、定时发布文章时自动本地化、已发布的文章批量本地化。
* Version: 1.3.2
* Version: 1.3.3
* Author: 友人a丶
* Author URI: https://nicen.cn
* Text Domain: nicen-localize-image
* License: GPLv2 or later
*/



define( 'nicen_make_PATH', plugin_dir_path( __FILE__ ) ); //插件目录
define( 'nicen_make_URL', plugin_dir_url( __FILE__ ) ); //插件URL
define('nicen_make_PATH', plugin_dir_path(__FILE__)); //插件目录
define('nicen_make_URL', plugin_dir_url(__FILE__)); //插件URL

//this is the root of website's path. call $_SERVER['DOCUMENT_ROOT'],I think it's safe;
//Think's
define( 'NICEN_ROOT', $_SERVER['DOCUMENT_ROOT'] );

var_dump(realpath(WP_CONTENT_DIR));
var_dump(DIRECTORY_SEPARATOR);
var_dump(NICEN_ROOT);
exit();
/*文件系统根目录*/
define('NICEN_ROOT', $_SERVER['DOCUMENT_ROOT']);

/*站点根目录*/
define('NICEN_SITE_ROOT',
str_replace(
str_replace(
'\\',
'/',
$_SERVER['DOCUMENT_ROOT']),
"",
str_replace(
'\\',
'/',
WP_CONTENT_DIR)
));


date_default_timezone_set( get_option( 'timezone_string' ) ); //设置时区
date_default_timezone_set(get_option('timezone_string')); //设置时区

include_once nicen_make_PATH . '/admin/preload.php'; //加载插件配置
include_once nicen_make_PATH . '/config.php'; //加载插件配置
include_once nicen_make_PATH . '/admin/install.php'; //安装时触发


register_activation_hook( __FILE__, "nicen_make_install" );//初始化插件
register_deactivation_hook( __FILE__, 'nicen_make_end' ); //卸载插件
register_activation_hook(__FILE__, "nicen_make_install");//初始化插件
register_deactivation_hook(__FILE__, 'nicen_make_end'); //卸载插件

/*导入类库*/
include_once nicen_make_PATH . '/class/log.php'; //错误日志封装类
Expand All @@ -49,11 +60,11 @@
/*
* 只在后台才触发
* */
if ( is_admin() ) {
include_once nicen_make_PATH . '/admin/load.php'; //加载后台插件资源
include_once nicen_make_PATH . '/admin/form.php'; //加载后台设置表单
include_once nicen_make_PATH . '/admin/setting.php';//渲染表单
include_once nicen_make_PATH . '/admin/initialize.php'; //初始化插件功能
if (is_admin()) {
include_once nicen_make_PATH . '/admin/load.php'; //加载后台插件资源
include_once nicen_make_PATH . '/admin/form.php'; //加载后台设置表单
include_once nicen_make_PATH . '/admin/setting.php';//渲染表单
include_once nicen_make_PATH . '/admin/initialize.php'; //初始化插件功能
}


9 changes: 8 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Donate link: https://nicen.cn/donate
Requires at least: 5.6
Tested up to: 6.0.1
Requires PHP: 7.3
Stable tag: 1.3.2
Stable tag: 1.3.3
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -27,6 +27,13 @@ Github:https://github.com/friend-nicen/nicen-localize-image
Gitee:https://gitee.com/friend-nicen/nicen-localize-image

== Changelog ==

v1.3.3

1. 修改代码适配wordpress插件商店规范;
2. 图片压缩完成后自动刷新显示的目录;
3. 修改网络请求超时时间为120s;

v1.3.1 beta

1. 新增批量本地化时,可以指定文章分类,指定文章发布时间范围;
Expand Down
Loading

0 comments on commit f1826aa

Please sign in to comment.