get_excluded_domains(); foreach ($excluded as $domain) { $domain = strtolower(trim($domain)); if ($domain && (strtolower($url_host) === $domain || substr(strtolower($url_host), -strlen($domain) - 1) === '.' . $domain)) { return false; } } return true; } /** * Generate signed go link with time-limited nonce */ public function create_go_link(string $url): string { $token = wp_create_nonce('aksrt_go_' . $url); return add_query_arg([ 'url' => rawurlencode($url), 'token' => $token, ], home_url('/go/')); } /** * Handle the /go/ confirmation page */ public function handle_go_page(): void { if (!get_query_var('aksrt_go_redirect')) return; $url = isset($_GET['url']) ? wp_unslash(rawurldecode($_GET['url'])) : ''; $token = isset($_GET['token']) ? sanitize_text_field(wp_unslash($_GET['token'])) : ''; if (empty($url) || empty($token)) { wp_die( esc_html__('无效的跳转链接。', 'aksrt'), esc_html__('跳转错误', 'aksrt'), ['response' => 400] ); } // Validate nonce (gated by seo_go_link_nonce schema setting) $require_nonce = class_exists('AKSRT_Settings') ? !empty(AKSRT_Settings::get_value('seo_go_link_nonce', true)) : true; if ($require_nonce && !wp_verify_nonce($token, 'aksrt_go_' . $url)) { wp_die( esc_html__('链接已过期或无效,请返回原页面重新点击。', 'aksrt'), esc_html__('链接过期', 'aksrt'), ['response' => 403] ); } // Validate URL $url = esc_url_raw($url); if (empty($url) || !wp_http_validate_url($url)) { wp_die( esc_html__('无效的目标地址。', 'aksrt'), esc_html__('跳转错误', 'aksrt'), ['response' => 400] ); } // Security: must be external if (!$this->is_external($url)) { wp_redirect($url); exit; } // Render confirmation page $this->render_go_page($url); } /** * Render the go confirmation page */ private function render_go_page(string $url): void { $domain = wp_parse_url($url, PHP_URL_HOST) ?: $url; $protocol = wp_parse_url($url, PHP_URL_SCHEME) ?: 'https'; set_query_var('aksrt_go_target_url', esc_url($url)); set_query_var('aksrt_go_target_domain', (string) $domain); set_query_var('aksrt_go_target_protocol', (string) $protocol); $template = locate_template('go.php', false, false); if ($template) { status_header(200); nocache_headers(); include $template; exit; } $safe_url = esc_url($url); $safe_domain = esc_html($domain); $safe_protocol = esc_html($protocol); wp_head(); ?> >