From 7416631e6278cb4038e770ad0766660e7dfe3847 Mon Sep 17 00:00:00 2001 From: sleepm <1520667045@qq.com> Date: Sun, 5 Jan 2020 12:46:58 +0800 Subject: [PATCH] 1.3.5 fix send_through_proxy; add pre_http_request --- class-wp-proxy.php | 40 +++++++++++++++++++++++++++++++--------- readme.txt | 4 ++-- wp-proxy.php | 3 ++- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/class-wp-proxy.php b/class-wp-proxy.php index af8d131..4cda82b 100644 --- a/class-wp-proxy.php +++ b/class-wp-proxy.php @@ -36,6 +36,7 @@ public function __construct() { if ( $options ) { $this->options = $options; if ( $options['enable'] ) { + add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 ); add_filter( 'pre_http_send_through_proxy', array( $this, 'send_through_proxy' ), 10, 4 ); defined( 'WP_PROXY_HOST' ) ? '' : define( 'WP_PROXY_HOST', $options['proxy_host'] ); defined( 'WP_PROXY_PORT' ) ? '' : define( 'WP_PROXY_PORT', $options['proxy_port'] ); @@ -49,11 +50,13 @@ public function __construct() { } else { add_option( 'wp_proxy_options', $this->defualt_options() ); } - add_action( 'admin_menu', array( $this, 'options_page' ) ); - add_action( 'admin_init', array( $this, 'register_settings' ) ); - add_action( 'admin_init', array( $this, 'wp_proxy_enable_or_disable' ) ); - add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 1000 ); - add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 ); + if ( is_admin() ) { + add_action( 'admin_menu', array( $this, 'options_page' ) ); + add_action( 'admin_init', array( $this, 'register_settings' ) ); + add_action( 'admin_init', array( $this, 'wp_proxy_enable_or_disable' ) ); + add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 1000 ); + add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 ); + } add_filter( 'plugin_row_meta', array( $this, 'plugin_details_links' ), 10, 2 ); } @@ -230,6 +233,21 @@ public function admin_bar_menu( $wp_admin_bar ) { } } + /** + * Set request arg + * + * @param bool $false is pre. + * @param array $parsed_args args. + * @param string $url url. + */ + public function pre_http_request( $false, $parsed_args, $url ) { + if ( $this->send_through_proxy( null, $url, $url, '' ) ) { + $parsed_args['timeout'] = $parsed_args['timeout'] + 1200; + @set_time_limit( $parsed_args['timeout'] + 60 ); + } + return $parsed_args; + } + /** * Check URL * @@ -240,7 +258,7 @@ public function admin_bar_menu( $wp_admin_bar ) { * @since 1.0 */ public function send_through_proxy( $null, $url, $check, $home ) { - $rules = explode( '\n', $this->options['domains'] ); + $rules = explode( "\n", $this->options['domains'] ); $host = false; if ( ! is_array( $check ) ) { $check = wp_parse_url( $check ); @@ -248,14 +266,18 @@ public function send_through_proxy( $null, $url, $check, $home ) { if ( isset( $check['host'] ) ) { $host = $check['host']; } + $regex = array(); foreach ( $rules as $rule ) { - $rule = str_replace( '*.', '(.*)\.', $rule ); if ( $rule === $host ) { return true; - } elseif ( preg_match( '#' . $rule . '#i', $host ) ) { - return true; + } else { + $regex[] = str_replace( '\*', '.+', preg_quote( $rule, '/' ) ); } } + if ( ! empty( $regex ) ) { + $regex = '^(' . implode( '|', $regex ) . ')$'; + return preg_match( '#' . $regex . '#i', $host ); + } return false; } diff --git a/readme.txt b/readme.txt index 0e24e9c..d0fa456 100644 --- a/readme.txt +++ b/readme.txt @@ -1,10 +1,10 @@ -# WordPress 代理访问 +# WP Proxy Contributors: sdffamt Donate link: https://xn--vkuk.org/blog/wp-proxy Tags: proxy Requires at least: 3.0.1 Tested up to: 5.3.2 -Stable tag: 1.3.4 +Stable tag: 1.3.5 Requires PHP: 5.2.4 License: GPLv2 or later diff --git a/wp-proxy.php b/wp-proxy.php index dba329d..3d43085 100644 --- a/wp-proxy.php +++ b/wp-proxy.php @@ -3,8 +3,9 @@ * Plugin Name: WP Proxy * Plugin URI: https://xn--vkuk.org/blog/wp-proxy * Description: manage proxy for WordPress - * Version: 1.3.4 + * Version: 1.3.5 * Author: sleepm + * Author URI: https://xn--vkuk.org/blog/ * Text Domain: wp-proxy * Domain Path: /languages * License: GPLv2 or later