diff --git a/MultisiteLanguageSwitcher.php b/MultisiteLanguageSwitcher.php index c5668805..6652b030 100644 --- a/MultisiteLanguageSwitcher.php +++ b/MultisiteLanguageSwitcher.php @@ -76,6 +76,7 @@ function get_the_msls( $attr ): string { * @param string[] $arr */ function the_msls( array $arr = array() ): void { + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo get_the_msls( $arr ); } diff --git a/includes/Component/Wrapper.php b/includes/Component/Wrapper.php new file mode 100644 index 00000000..995a0f74 --- /dev/null +++ b/includes/Component/Wrapper.php @@ -0,0 +1,19 @@ +element = $element; + $this->content = $content; + } + + public function render(): string { + return sprintf( '<%1$s>%2$s', esc_html( $this->element ), wp_kses_post( $this->content ) ); + } +} diff --git a/includes/ContentImport/ContentImporter.php b/includes/ContentImport/ContentImporter.php index 34875490..00d0a512 100644 --- a/includes/ContentImport/ContentImporter.php +++ b/includes/ContentImport/ContentImporter.php @@ -9,6 +9,7 @@ use lloc\Msls\MslsMain; use lloc\Msls\MslsOptionsPost; use lloc\Msls\MslsRegistryInstance; +use lloc\Msls\MslsRequest; /** * Class ContentImporter @@ -166,11 +167,12 @@ protected function pre_flight_check( array $data = array() ) { * @return array|bool */ public function parse_sources() { - if ( ! isset( $_POST['msls_import'] ) ) { + if ( ! MslsRequest::has_var( 'msls_import' ) ) { return false; } - $import_data = array_filter( explode( '|', trim( $_POST['msls_import'] ) ), 'is_numeric' ); + $msls_import = MslsRequest::get_var( 'msls_import' ); + $import_data = array_filter( explode( '|', trim( $msls_import ) ), 'is_numeric' ); if ( count( $import_data ) !== 2 ) { return false; @@ -195,8 +197,9 @@ protected function get_the_blog_post_ID( $blog_id ) { return $id; } - if ( isset( $_REQUEST['post'] ) && filter_var( $_REQUEST['post'], FILTER_VALIDATE_INT ) ) { - return (int) $_REQUEST['post']; + $request = MslsRequest::get_request( array( 'post' ) ); + if ( ! empty( $request['post'] ) ) { + return (int) $request['post']; } $data = array( diff --git a/includes/ContentImport/Importers/WithRequestPostAttributes.php b/includes/ContentImport/Importers/WithRequestPostAttributes.php index 39f97ffa..c0f34250 100644 --- a/includes/ContentImport/Importers/WithRequestPostAttributes.php +++ b/includes/ContentImport/Importers/WithRequestPostAttributes.php @@ -10,6 +10,8 @@ namespace lloc\Msls\ContentImport\Importers; +use lloc\Msls\MslsRequest; + /** * Trait WithRequestPostAttributes * @@ -24,14 +26,11 @@ trait WithRequestPostAttributes { * @param string $default The default post type to return if none is specified in the `$_REQUEST` super-global. * * @return string Either the post type read from the `$_REQUEST` super-global, or the default value. - * @since TBD - * +\ * */ protected function read_post_type_from_request( $default = 'post' ) { - if ( ! isset( $_REQUEST['post_type'] ) ) { - return $default; - } + $request = MslsRequest::get_request( array( 'post_type' ), $default ); - return filter_var( $_REQUEST['post_type'], FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ?: 'post'; + return $request['post_type']; } } diff --git a/includes/ContentImport/LogWriters/AdminNoticeLogger.php b/includes/ContentImport/LogWriters/AdminNoticeLogger.php index 15966ee8..f760770e 100644 --- a/includes/ContentImport/LogWriters/AdminNoticeLogger.php +++ b/includes/ContentImport/LogWriters/AdminNoticeLogger.php @@ -141,7 +141,7 @@ public function show_last_log( $echo = true ): ?string { } if ( $echo ) { - echo $html; + echo wp_kses_post( $html ); } // we've shown it, no reason to keep it diff --git a/includes/ContentImport/MetaBox.php b/includes/ContentImport/MetaBox.php index 01791a19..10a25f08 100644 --- a/includes/ContentImport/MetaBox.php +++ b/includes/ContentImport/MetaBox.php @@ -2,7 +2,7 @@ namespace lloc\Msls\ContentImport; -use lloc\Msls\ContentImport\Importers\ImportersFactory; +use lloc\Msls\Component\Wrapper; use lloc\Msls\ContentImport\Importers\Map; use lloc\Msls\MslsBlogCollection; use lloc\Msls\MslsFields; @@ -43,26 +43,31 @@ function ( $lang ) use ( $mydata ) { /* translators: %s: language name */ $label_template = __( 'Import content from %s', 'multisite-language-switcher' ); - $output = '
'; - $output .= '' - . esc_html__( - 'Warning! This will override and replace all the post content with the content from the source post!', - 'multisite-language-switcher' - ) - . ''; + + $warning = esc_html__( + 'Warning! This will override and replace all the post content with the content from the source post!', + 'multisite-language-switcher' + ); + + $legend = ( new Wrapper( 'legend', $warning ) )->render(); + + $output = ''; foreach ( $languages as $language => $label ) { $id = $mydata->{$language}; $blog = $blogs->get_blog_id( $language ); $label = sprintf( $label_template, $label ); + if ( null === $id && $has_input && $input_lang === $language ) { $id = $input_id; $blog = $blogs->get_blog_id( $language ); } + if ( null !== $id ) { $this->data = array( 'msls_import' => "{$blog}|{$id}", ); - $output .= sprintf( + + $output .= sprintf( '%s', $this->inline_thickbox_url( $this->data ), $label, @@ -70,17 +75,18 @@ function ( $lang ) use ( $mydata ) { ); } } - $output .= '
'; + + $output = ( new Wrapper( 'fieldset', $legend . $output ) )->render(); } else { - $output = '

' . - esc_html__( - 'No translated versions linked to this post: import content functionality is disabled.', - 'multisite-language-switcher' - ) - . '

'; + $warning = esc_html__( + 'No translated versions linked to this post: import content functionality is disabled.', + 'multisite-language-switcher' + ); + + $output = ( new Wrapper( 'p', $warning ) )->render(); } - echo $output; + echo wp_kses_post( $output ); } protected function inline_thickbox_url( array $data = array() ): string { @@ -100,6 +106,7 @@ protected function inline_thickbox_url( array $data = array() ): string { } public function print_modal_html(): void { + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $this->inline_thickbox_html( true, $this->data ); } @@ -112,145 +119,60 @@ protected function inline_thickbox_html( $echo = true, array $data = array() ): ob_start(); ?> -