Skip to content

Commit

Permalink
global mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepm committed Dec 14, 2020
1 parent ca2e410 commit d19e7aa
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 344 deletions.
96 changes: 84 additions & 12 deletions class-wp-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct() {
$this->load_plugin_textdomain();
$options = get_option( 'wp_proxy_options' );
if ( $options ) {
$this->options = $options;
$this->options = wp_parse_args( $options, $this->defualt_options() );
if ( $options['enable'] ) {
add_filter( 'http_request_args', array( $this, 'http_request_args' ), 100, 2 );
add_filter( 'pre_http_send_through_proxy', array( $this, 'send_through_proxy' ), 10, 4 );
Expand Down Expand Up @@ -73,6 +73,15 @@ public static function instance() {
return self::$instance;
}

/**
* Magic call static
*
* @since 1.3.9
*/
public static function __callStatic ( $name, $args ) {
return call_user_func_array( array( new WP_Proxy, $name ), $args );
}

/**
* I18n
*
Expand All @@ -91,14 +100,15 @@ protected function load_plugin_textdomain() {
* @since 1.0
*/
protected function defualt_options() {
$options = array();
$options['domains'] = '*.wordpress.org';
$options['proxy_host'] = '127.0.0.1';
$options['proxy_port'] = '1080';
$options['username'] = '';
$options['password'] = '';
$options['type'] = '';
$options['enable'] = false;
$options = array();
$options['domains'] = '*.wordpress.org';
$options['proxy_host'] = '127.0.0.1';
$options['proxy_port'] = '1080';
$options['username'] = '';
$options['password'] = '';
$options['type'] = '';
$options['global_mode'] = false;
$options['enable'] = false;
return $options;
}

Expand Down Expand Up @@ -136,6 +146,13 @@ public function options_page() {
if ( isset( $_POST['domains'] ) ) {
$wp_proxy_options['domains'] = str_replace( ' ', "\n", sanitize_text_field( wp_unslash( $_POST['domains'] ) ) );
}
if ( isset( $_POST['global_mode'] ) ) {
if ( 'yes' === sanitize_text_field( wp_unslash( $_POST['global_mode'] ) ) ) {
$wp_proxy_options['global_mode'] = true;
} else {
$wp_proxy_options['global_mode'] = false;
}
}
if ( isset( $_POST['enable'] ) ) {
if ( 'yes' === sanitize_text_field( wp_unslash( $_POST['enable'] ) ) ) {
$wp_proxy_options['enable'] = true;
Expand All @@ -158,9 +175,16 @@ public function wp_proxy_enable_or_disable() {
// avoid invalid nonce.
if ( isset( $_GET['wp_proxy'] ) && check_admin_referer( 'wp-proxy-quick-set', 'wp-proxy-quick-set' ) ) {
$wp_proxy_options = $this->options;
if ( 'enable' === sanitize_text_field( wp_unslash( $_GET['wp_proxy'] ) ) ) {
$val = sanitize_text_field( wp_unslash( $_GET['wp_proxy'] ) );
if ( 'enable' === $val ) {
$wp_proxy_options['enable'] = true;
} else {
} else if( 'disable' === $val ) {
$wp_proxy_options['enable'] = false;
} else if( 'enable_in_global_mode' === $val ) {
$wp_proxy_options['global_mode'] = true;
$wp_proxy_options['enable'] = true;
} else if( 'disable_in_global_mode' === $val ) {
$wp_proxy_options['global_mode'] = false;
$wp_proxy_options['enable'] = false;
}
update_option( 'wp_proxy_options', $wp_proxy_options );
Expand Down Expand Up @@ -235,6 +259,25 @@ public function admin_bar_menu( $wp_admin_bar ) {
)
);
}
if ( $options['global_mode'] ) {
$wp_admin_bar->add_node(
array(
'id' => 'disable_wp_proxy_gloabl_mode',
'parent' => 'wp_proxy',
'title' => __( 'Disabled' ) . ' ' . esc_html__( 'Global mode', 'wp-proxy' ),
'href' => wp_nonce_url( add_query_arg( 'wp_proxy', 'disable_in_global_mode' ), 'wp-proxy-quick-set', 'wp-proxy-quick-set' ),
)
);
} else {
$wp_admin_bar->add_node(
array(
'id' => 'enable_wp_proxy_global_mode',
'parent' => 'wp_proxy',
'title' => __( 'Enabled' ) . ' ' . esc_html__( 'Global mode', 'wp-proxy' ),
'href' => wp_nonce_url( add_query_arg( 'wp_proxy', 'enable_in_global_mode' ), 'wp-proxy-quick-set', 'wp-proxy-quick-set' ),
)
);
}
}
}

Expand Down Expand Up @@ -282,6 +325,9 @@ public function curl_before_send( $handle, $request, $url ) {
* @since 1.0
*/
public function send_through_proxy( $null, $url, $check, $home ) {
if ( $this->options['global_mode'] ) {
return true;
}
$rules = explode( "\n", $this->options['domains'] );
$host = false;
if ( ! is_array( $check ) ) {
Expand Down Expand Up @@ -360,6 +406,13 @@ public function register_settings() {
'wp_proxy',
'wp_proxy_config'
);
add_settings_field(
'global_mode',
esc_html__( 'Global mode', 'wp-proxy' ),
array( $this, 'proxy_global_mode_callback' ),
'wp_proxy',
'wp_proxy_config'
);
add_settings_field(
'enable',
__( 'Enabled' ),
Expand Down Expand Up @@ -460,7 +513,26 @@ public function proxy_type_callback() {
*/
public function proxy_domains_callback() {
?>
<textarea name="domains" id="domains" cols="40" rows="5" autocomplete="off"><?php echo esc_attr( $this->options['domains'] ); ?></textarea>
<textarea name="domains" id="domains" cols="40" rows="5" autocomplete="off" <?php echo $this->options['global_mode'] ? 'disabled="disabled"' : '' ?>><?php echo esc_attr( $this->options['domains'] ); ?></textarea>
<?php
}

/**
* Show proxy global_mode field
*
* @since 1.3.9
*/
public function proxy_global_mode_callback() {
?>
<select name="global_mode" id="global_mode">
<?php if ( $this->options['global_mode'] ) { ?>
<option value="yes" selected="selected"><?php esc_html_e( 'Yes' ); ?></option>
<option value="no"><?php esc_html_e( 'No' ); ?></option>
<?php } else { ?>
<option value="yes"><?php esc_html_e( 'Yes' ); ?></option>
<option value="no" selected="selected"><?php esc_html_e( 'No' ); ?></option>
<?php } ?>
</select>
<?php
}

Expand Down
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// Silence is golden.
Binary file modified languages/wp-proxy-de_DE.mo
Binary file not shown.
71 changes: 16 additions & 55 deletions languages/wp-proxy-de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,82 +9,43 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2019-12-22T03:28:20+00:00\n"
"PO-Revision-Date: 2019-12-22 03:51+0000\n"
"PO-Revision-Date: 2020-12-14 16:17+0000\n"
"X-Generator: Loco https://localise.biz/\n"
"X-Domain: wp-proxy\n"
"Last-Translator: gt <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: de_DE\n"
"X-Loco-Version: 2.3.1; wp-5.3.2"

#. Plugin Name of the plugin
msgid "WordPress Proxy"
msgstr "WordPress Proxy"
#: class-wp-proxy.php:381
msgid "Global mode"
msgstr ""

#. Author URI of the plugin
msgid "https://xn--vkuk.org/blog/"
msgstr ""

#. Plugin URI of the plugin
#. URI of the plugin
msgid "https://xn--vkuk.org/blog/wp-proxy"
msgstr "https://xn--vkuk.org/blog/wp-proxy"

#. Description of the plugin
msgid "manage proxy for WordPress"
msgstr ""

#: class-wp-proxy.php:374
msgid "Proxy Domains"
msgstr ""

#. Author of the plugin
msgid "sleepm"
msgstr "sleepm"

#: class-wp-proxy.php:106 class-wp-proxy.php:234
#. Name of the plugin
#: class-wp-proxy.php:117 class-wp-proxy.php:404
msgid "WP Proxy"
msgstr "Proxy-Einstellungen"

#: class-wp-proxy.php:115
#: class-wp-proxy.php:127
msgid "Wrong port"
msgstr "Falsche Portnummer"

#: class-wp-proxy.php:183
msgid "Proxy Host"
msgstr ""

#: class-wp-proxy.php:190
msgid "Proxy Port"
msgstr ""

#: class-wp-proxy.php:197
msgid "Proxy Username"
msgstr "Benutzername"

#: class-wp-proxy.php:204
msgid "Proxy Password"
msgstr "Passwort"

#: class-wp-proxy.php:211
msgid "Proxy Domains"
msgstr ""

#: class-wp-proxy.php:218
msgid "Enable"
msgstr ""

#: class-wp-proxy.php:256
msgid "proxy host"
msgstr ""

#: class-wp-proxy.php:267
msgid "proxy port"
msgstr ""

#: class-wp-proxy.php:278
msgid "username"
msgstr ""

#: class-wp-proxy.php:289
msgid "password"
msgstr ""

#: class-wp-proxy.php:313 class-wp-proxy.php:316
msgid "yes"
msgstr "Ja"

#: class-wp-proxy.php:314 class-wp-proxy.php:317
msgid "no"
msgstr ""
Binary file modified languages/wp-proxy-ja_JP.mo
Binary file not shown.
71 changes: 16 additions & 55 deletions languages/wp-proxy-ja_JP.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,82 +9,43 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2019-12-22T03:28:20+00:00\n"
"PO-Revision-Date: 2019-12-22 03:53+0000\n"
"PO-Revision-Date: 2020-12-14 16:15+0000\n"
"X-Generator: Loco https://localise.biz/\n"
"X-Domain: wp-proxy\n"
"Last-Translator: gt <[email protected]>\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"Language: ja_JP\n"
"X-Loco-Version: 2.3.1; wp-5.3.2"

#. Plugin Name of the plugin
msgid "WordPress Proxy"
msgstr "WordPress Proxy"
#: class-wp-proxy.php:381
msgid "Global mode"
msgstr "グローバルモード"

#. Plugin URI of the plugin
#. Author URI of the plugin
msgid "https://xn--vkuk.org/blog/"
msgstr ""

#. URI of the plugin
msgid "https://xn--vkuk.org/blog/wp-proxy"
msgstr "https://xn--vkuk.org/blog/wp-proxy"

#. Description of the plugin
msgid "manage proxy for WordPress"
msgstr ""

#: class-wp-proxy.php:374
msgid "Proxy Domains"
msgstr ""

#. Author of the plugin
msgid "sleepm"
msgstr "sleepm"

#: class-wp-proxy.php:106 class-wp-proxy.php:234
#. Name of the plugin
#: class-wp-proxy.php:117 class-wp-proxy.php:404
msgid "WP Proxy"
msgstr "プロキシ設定"

#: class-wp-proxy.php:115
#: class-wp-proxy.php:127
msgid "Wrong port"
msgstr "間違ったポート番号"

#: class-wp-proxy.php:183
msgid "Proxy Host"
msgstr "プロキシホスト"

#: class-wp-proxy.php:190
msgid "Proxy Port"
msgstr "プロキシポート"

#: class-wp-proxy.php:197
msgid "Proxy Username"
msgstr "ユーザー名"

#: class-wp-proxy.php:204
msgid "Proxy Password"
msgstr "パスワード"

#: class-wp-proxy.php:211
msgid "Proxy Domains"
msgstr ""

#: class-wp-proxy.php:218
msgid "Enable"
msgstr "有効にする"

#: class-wp-proxy.php:256
msgid "proxy host"
msgstr ""

#: class-wp-proxy.php:267
msgid "proxy port"
msgstr ""

#: class-wp-proxy.php:278
msgid "username"
msgstr ""

#: class-wp-proxy.php:289
msgid "password"
msgstr ""

#: class-wp-proxy.php:313 class-wp-proxy.php:316
msgid "yes"
msgstr "はい"

#: class-wp-proxy.php:314 class-wp-proxy.php:317
msgid "no"
msgstr "いや"
Binary file modified languages/wp-proxy-ru_RU.mo
Binary file not shown.
Loading

0 comments on commit d19e7aa

Please sign in to comment.