array( 'rooster_lms_rsvp', 'aieo_cart', 'aieo_offer', 'aieo_fulfillment_pdf', 'aieo_withdraw_confirm', 'aieo_wd_k', 'aieo_rsvp_token', 'token', 'vt', 'key', 'code', 'state', 'password', 'pass', 'pwd', '_wpnonce', 'nonce', ), 'paths' => array( '#(/rooster-lms/rsvp/)[^/?\#&]+#i', '#(/event-rsvp/)[^/?\#&]+#i', ), 'with' => array( 'aieo_unsub' => array( 'e', 's' ), ), ); $rules = apply_filters( 'aieo_url_redactions', $rules ); $rules = is_array( $rules ) ? $rules : array(); return array( 'args' => array_values( array_map( 'strtolower', array_map( 'strval', (array) ( $rules['args'] ?? array() ) ) ) ), 'paths' => array_values( array_filter( array_map( 'strval', (array) ( $rules['paths'] ?? array() ) ) ) ), 'with' => is_array( $rules['with'] ?? null ) ? $rules['with'] : array(), ); } public static function clean( $url, $depth = 0 ) { $url = (string) $url; if ( '' === $url ) { return ''; } $rules = self::rules(); $frag = ''; $hash = strpos( $url, '#' ); if ( false !== $hash ) { $frag = substr( $url, $hash + 1 ); $url = substr( $url, 0, $hash ); } $query = ''; $q = strpos( $url, '?' ); if ( false !== $q ) { $query = substr( $url, $q + 1 ); $url = substr( $url, 0, $q ); } foreach ( $rules['paths'] as $re ) { $out = @preg_replace( $re, '$1' . self::MASK, $url ); if ( is_string( $out ) ) { $url = $out; } } if ( '' !== $query ) { $query = self::clean_query( $query, $rules, $depth ); } if ( '' !== $frag && false !== strpos( $frag, '=' ) ) { $frag = self::clean_query( $frag, $rules, $depth ); } return $url . ( false !== $q ? '?' . $query : '' ) . ( false !== $hash ? '#' . $frag : '' ); } private static function clean_query( $query, array $rules, $depth ) { $pairs = explode( '&', $query ); $names = array(); foreach ( $pairs as $pair ) { $names[] = strtolower( rawurldecode( (string) strtok( $pair, '=' ) ) ); } $mask = $rules['args']; foreach ( $rules['with'] as $flag => $also ) { if ( in_array( strtolower( (string) $flag ), $names, true ) ) { $mask = array_merge( $mask, array_map( 'strtolower', (array) $also ) ); } } foreach ( $pairs as $i => $pair ) { $eq = strpos( $pair, '=' ); if ( false === $eq ) { continue; } $name = substr( $pair, 0, $eq ); $value = substr( $pair, $eq + 1 ); if ( in_array( $names[ $i ], $mask, true ) ) { $pairs[ $i ] = $name . '=' . self::MASK; continue; } if ( $depth < 2 && '' !== $value ) { $decoded = rawurldecode( str_replace( '+', ' ', $value ) ); if ( false !== strpos( $decoded, '://' ) || 0 === strpos( $decoded, '/' ) ) { $clean = self::clean( $decoded, $depth + 1 ); if ( $clean !== $decoded ) { $pairs[ $i ] = $name . '=' . rawurlencode( $clean ); } } } } return implode( '&', $pairs ); } public static function clean_deep( $value, $depth = 0 ) { if ( $depth > 6 ) { return $value; } if ( is_array( $value ) ) { foreach ( $value as $k => $v ) { $value[ $k ] = self::clean_deep( $v, $depth + 1 ); } return $value; } if ( is_object( $value ) ) { foreach ( get_object_vars( $value ) as $k => $v ) { $value->$k = self::clean_deep( $v, $depth + 1 ); } return $value; } if ( is_string( $value ) && ( false !== strpos( $value, '://' ) || ( 0 === strpos( $value, '/' ) && false === strpos( $value, ' ' ) ) ) ) { return self::clean( $value ); } return $value; } } }