Server : Apache System : Linux pod-100823:apache2_74:v0.5.7 5.4.0-1138-gcp #147~18.04.1-Ubuntu SMP Mon Oct 7 21:46:26 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33.7 Disable Function : apache_child_terminate,apache_get_modules,apache_get_version,apache_getenv,apache_note,apache_setenv,disk_free_space,disk_total_space,diskfreespace,dl,exec,fastcgi_finish_request,link,opcache_compile_file,opcache_get_configuration,opcache_invalidate,opcache_is_script_cached,opcache_reset,passthru,pclose,pcntl_exec,popen,posix_getpid,posix_getppid,posix_getpwuid,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_uname,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,realpath_cache_get,shell_exec,show_source,symlink,system Directory : /nas/content/live/attorneyexperi/wp-content/plugins/redirection/models/ |
<?php class Red_Http_Headers { private $headers = []; public function __construct( $options = [] ) { if ( is_array( $options ) ) { $this->headers = array_filter( array_map( [ $this, 'normalize' ], $options ) ); } } private function normalize( $header ) { $location = 'site'; if ( isset( $header['location'] ) && $header['location'] === 'redirect' ) { $location = 'redirect'; } $name = $this->sanitize( isset( $header['headerName'] ) ? sanitize_text_field( $header['headerName'] ) : '' ); $type = $this->sanitize( isset( $header['type'] ) ? sanitize_text_field( $header['type'] ) : '' ); $value = $this->sanitize( isset( $header['headerValue'] ) ? sanitize_text_field( $header['headerValue'] ) : '' ); $settings = []; if ( isset( $header['headerSettings'] ) && is_array( $header['headerSettings'] ) ) { foreach ( $header['headerSettings'] as $key => $setting_value ) { if ( is_array( $setting_value ) && isset( $setting_value['value'] ) ) { $settings[ $this->sanitize( sanitize_text_field( $key ) ) ] = $this->sanitize( $setting_value['value'] ); } else { $settings[ $this->sanitize( sanitize_text_field( $key ) ) ] = $this->sanitize( $setting_value ); } } } if ( strlen( $name ) > 0 && strlen( $type ) > 0 ) { return [ 'type' => $this->dash_case( $type ), 'headerName' => $this->dash_case( $name ), 'headerValue' => $value, 'location' => $location, 'headerSettings' => $settings, ]; } return null; } public function get_json() { return $this->headers; } private function dash_case( $name ) { $name = preg_replace( '/[^A-Za-z0-9]/', ' ', $name ); $name = preg_replace( '/\s{2,}/', ' ', $name ); $name = trim( $name, ' ' ); $name = ucwords( $name ); $name = str_replace( ' ', '-', $name ); return $name; } private function remove_dupes( $headers ) { $new_headers = []; foreach ( $headers as $header ) { $new_headers[ $header['headerName'] ] = $header; } return array_values( $new_headers ); } public function get_site_headers() { $headers = array_values( $this->remove_dupes( array_filter( $this->headers, [ $this, 'is_site_header' ] ) ) ); return apply_filters( 'redirection_headers_site', $headers ); } public function get_redirect_headers() { // Site ones first, then redirect - redirect will override any site ones $headers = $this->get_site_headers(); $headers = array_merge( $headers, array_values( array_filter( $this->headers, [ $this, 'is_redirect_header' ] ) ) ); $headers = array_values( $this->remove_dupes( $headers ) ); return apply_filters( 'redirection_headers_redirect', $headers ); } private function is_site_header( $header ) { return $header['location'] === 'site'; } private function is_redirect_header( $header ) { return $header['location'] === 'redirect'; } public function run( $headers ) { $done = []; foreach ( $headers as $header ) { if ( ! in_array( $header['headerName'], $done, true ) ) { $name = $this->sanitize( $this->dash_case( $header['headerName'] ) ); $value = $this->sanitize( $header['headerValue'] ); // Trigger some other action do_action( 'redirection_header', $name, $value ); header( sprintf( '%s: %s', $name, $value ) ); $done[] = $header['headerName']; } } } private function sanitize( $text ) { // No new lines $text = preg_replace( "/[\r\n\t].*?$/s", '', $text ); // Clean control codes $text = preg_replace( '/[^\PC\s]/u', '', $text ); // Try and remove bad decoding if ( function_exists( 'iconv' ) ) { $converted = @iconv( 'UTF-8', 'UTF-8//IGNORE', $text ); if ( $converted !== false ) { $text = $converted; } } return $text; } }