Plugin Directory

Changeset 2222202


Ignore:
Timestamp:
01/05/2020 04:42:14 AM (6 years ago)
Author:
sdffamt
Message:

1.3.5 fix send_through_proxy; add pre_http_request

Location:
wp-proxy/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-proxy/trunk/class-wp-proxy.php

    r2219135 r2222202  
    3737            $this->options = $options;
    3838            if ( $options['enable'] ) {
     39                add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 );
    3940                add_filter( 'pre_http_send_through_proxy', array( $this, 'send_through_proxy' ), 10, 4 );
    4041                defined( 'WP_PROXY_HOST' ) ? '' : define( 'WP_PROXY_HOST', $options['proxy_host'] );
     
    5051            add_option( 'wp_proxy_options', $this->defualt_options() );
    5152        }
    52         add_action( 'admin_menu', array( $this, 'options_page' ) );
    53         add_action( 'admin_init', array( $this, 'register_settings' ) );
    54         add_action( 'admin_init', array( $this, 'wp_proxy_enable_or_disable' ) );
    55         add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 1000 );
    56         add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
     53        if ( is_admin() ) {
     54            add_action( 'admin_menu', array( $this, 'options_page' ) );
     55            add_action( 'admin_init', array( $this, 'register_settings' ) );
     56            add_action( 'admin_init', array( $this, 'wp_proxy_enable_or_disable' ) );
     57            add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 1000 );
     58            add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
     59        }
    5760        add_filter( 'plugin_row_meta', array( $this, 'plugin_details_links' ), 10, 2 );
    5861    }
     
    232235
    233236    /**
     237     * Set request arg
     238     *
     239     * @param   bool   $false is pre.
     240     * @param   array  $parsed_args args.
     241     * @param   string $url url.
     242     */
     243    public function pre_http_request( $false, $parsed_args, $url ) {
     244        if ( $this->send_through_proxy( null, $url, $url, '' ) ) {
     245            $parsed_args['timeout'] = $parsed_args['timeout'] + 1200;
     246            @set_time_limit( $parsed_args['timeout'] + 60 );
     247        }
     248        return $parsed_args;
     249    }
     250
     251    /**
    234252     * Check URL
    235253     *
     
    241259     */
    242260    public function send_through_proxy( $null, $url, $check, $home ) {
    243         $rules = explode( '\n', $this->options['domains'] );
     261        $rules = explode( "\n", $this->options['domains'] );
    244262        $host  = false;
    245263        if ( ! is_array( $check ) ) {
     
    249267            $host = $check['host'];
    250268        }
     269        $regex = array();
    251270        foreach ( $rules as $rule ) {
    252             $rule = str_replace( '*.', '(.*)\.', $rule );
    253271            if ( $rule === $host ) {
    254272                return true;
    255             } elseif ( preg_match( '#' . $rule . '#i', $host ) ) {
    256                 return true;
    257             }
     273            } else {
     274                $regex[] = str_replace( '\*', '.+', preg_quote( $rule, '/' ) );
     275            }
     276        }
     277        if ( ! empty( $regex ) ) {
     278            $regex = '^(' . implode( '|', $regex ) . ')$';
     279            return preg_match( '#' . $regex . '#i', $host );
    258280        }
    259281        return false;
  • wp-proxy/trunk/readme.txt

    r2219135 r2222202  
    1 # WordPress 代理访问
     1# WP Proxy
    22Contributors: sdffamt
    33Donate link: https://xn--vkuk.org/blog/wp-proxy
     
    55Requires at least: 3.0.1
    66Tested up to: 5.3.2
    7 Stable tag: 1.3.4
     7Stable tag: 1.3.5
    88Requires PHP: 5.2.4
    99License: GPLv2 or later
  • wp-proxy/trunk/wp-proxy.php

    r2219135 r2222202  
    44 * Plugin URI: https://xn--vkuk.org/blog/wp-proxy
    55 * Description: manage proxy for WordPress
    6  * Version: 1.3.4
     6 * Version: 1.3.5
    77 * Author: sleepm
     8 * Author URI: https://xn--vkuk.org/blog/
    89 * Text Domain: wp-proxy
    910 * Domain Path: /languages
Note: See TracChangeset for help on using the changeset viewer.