2
2
3
3
namespace lloc \Msls \ContentImport ;
4
4
5
- use lloc \Msls \ContentImport \ Importers \ ImportersFactory ;
5
+ use lloc \Msls \Component \ Wrapper ;
6
6
use lloc \Msls \ContentImport \Importers \Map ;
7
7
use lloc \Msls \MslsBlogCollection ;
8
8
use lloc \Msls \MslsFields ;
@@ -43,44 +43,50 @@ function ( $lang ) use ( $mydata ) {
43
43
44
44
/* translators: %s: language name */
45
45
$ label_template = __ ( 'Import content from %s ' , 'multisite-language-switcher ' );
46
- $ output = '<fieldset> ' ;
47
- $ output .= '<legend> '
48
- . esc_html__ (
49
- 'Warning! This will override and replace all the post content with the content from the source post! ' ,
50
- 'multisite-language-switcher '
51
- )
52
- . '</legend> ' ;
46
+
47
+ $ warning = esc_html__ (
48
+ 'Warning! This will override and replace all the post content with the content from the source post! ' ,
49
+ 'multisite-language-switcher '
50
+ );
51
+
52
+ $ legend = ( new Wrapper ( 'legend ' , $ warning ) )->render ();
53
+
54
+ $ output = '' ;
53
55
foreach ( $ languages as $ language => $ label ) {
54
56
$ id = $ mydata ->{$ language };
55
57
$ blog = $ blogs ->get_blog_id ( $ language );
56
58
$ label = sprintf ( $ label_template , $ label );
59
+
57
60
if ( null === $ id && $ has_input && $ input_lang === $ language ) {
58
61
$ id = $ input_id ;
59
62
$ blog = $ blogs ->get_blog_id ( $ language );
60
63
}
64
+
61
65
if ( null !== $ id ) {
62
66
$ this ->data = array (
63
67
'msls_import ' => "{$ blog }| {$ id }" ,
64
68
);
65
- $ output .= sprintf (
69
+
70
+ $ output .= sprintf (
66
71
'<a class="button button-primary thickbox" href="%s" title="%s">%s</a> ' ,
67
72
$ this ->inline_thickbox_url ( $ this ->data ),
68
73
$ label ,
69
74
$ label
70
75
);
71
76
}
72
77
}
73
- $ output .= '</fieldset> ' ;
78
+
79
+ $ output = ( new Wrapper ( 'fieldset ' , $ legend . $ output ) )->render ();
74
80
} else {
75
- $ output = ' <p> ' .
76
- esc_html__ (
77
- ' No translated versions linked to this post: import content functionality is disabled. ' ,
78
- ' multisite-language-switcher '
79
- )
80
- . ' </p> ' ;
81
+ $ warning = esc_html__ (
82
+ ' No translated versions linked to this post: import content functionality is disabled. ' ,
83
+ ' multisite-language-switcher '
84
+ );
85
+
86
+ $ output = ( new Wrapper ( ' p ' , $ warning ) )-> render () ;
81
87
}
82
88
83
- echo $ output ;
89
+ echo wp_kses_post ( $ output ) ;
84
90
}
85
91
86
92
protected function inline_thickbox_url ( array $ data = array () ): string {
@@ -100,6 +106,7 @@ protected function inline_thickbox_url( array $data = array() ): string {
100
106
}
101
107
102
108
public function print_modal_html (): void {
109
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
103
110
echo $ this ->inline_thickbox_html ( true , $ this ->data );
104
111
}
105
112
@@ -112,145 +119,60 @@ protected function inline_thickbox_html( $echo = true, array $data = array() ):
112
119
113
120
ob_start ();
114
121
?>
115
- <div style="display: none;" id="msls-import-dialog-
116
- <?php
117
- echo esc_attr ( $ slug )
118
- ?>
119
- ">
120
- <h3>
121
- <?php
122
- esc_html_e ( 'Select what should be imported and how ' , 'multisite-language-switcher ' )
123
- ?>
124
- </h3>
125
-
126
- <form action="
127
- <?php
128
- echo add_query_arg ( array () )
129
- ?>
130
- " method="post">
131
-
132
- <?php
133
- wp_nonce_field ( MslsPlugin::path (), 'msls_noncename ' );
134
- ?>
135
-
136
- <?php
137
- foreach ( $ data as $ key => $ value ) :
138
- ?>
139
- <input type="hidden" name="
140
- <?php
141
- echo esc_attr ( $ key )
142
- ?>
143
- " value="
144
- <?php
145
- echo esc_attr ( $ value )
146
- ?>
147
- ">
148
- <?php
149
- endforeach ;
150
- ?>
151
-
152
- <?php
153
- /** @var ImportersFactory $factory */
154
- foreach ( Map::instance ()->factories () as $ slug => $ factory ) :
155
- ?>
156
- <?php
157
- $ details = $ factory ->details ()
158
- ?>
159
- <h4>
160
- <?php
161
- echo esc_html ( $ details ->name )
162
- ?>
163
- </h4>
164
- <?php
165
- if ( empty ( $ details ->importers ) ) :
166
- ?>
122
+ <div style="display: none;" id="msls-import-dialog-<?php echo esc_attr ( $ slug ); ?> ">
123
+ <h3><?php esc_html_e ( 'Select what should be imported and how ' , 'multisite-language-switcher ' ); ?> </h3>
124
+ <form action="<?php echo esc_url ( add_query_arg ( array () ) ); ?> " method="post">
125
+ <?php wp_nonce_field ( MslsPlugin::path (), 'msls_noncename ' ); ?>
126
+ <?php foreach ( $ data as $ key => $ value ) : ?>
127
+ <input type="hidden" name="<?php echo esc_attr ( $ key ); ?> " value="<?php echo esc_attr ( $ value ); ?> ">
128
+ <?php endforeach ; ?>
129
+ <?php foreach ( Map::instance ()->factories () as $ slug => $ factory ) : ?>
130
+ <?php $ details = $ factory ->details (); ?>
131
+ <h4><?php echo esc_html ( $ details ->name ); ?> </h4>
132
+ <?php if ( empty ( $ details ->importers ) ) : ?>
167
133
<p>
168
134
<?php
169
135
esc_html_e (
170
136
'No importers available for this type of content. ' ,
171
137
'multisite-language-switcher '
172
- )
138
+ );
173
139
?>
174
- </p>
175
- <?php
176
- else :
177
- ?>
178
- <ul>
179
- <li>
180
- <label>
181
- <input type="radio" name="msls_importers[
182
- <?php
183
- echo esc_attr ( $ details ->slug )
184
- ?>
185
- ]">
186
- <?php
187
- esc_html_e (
188
- 'Off - Do not import this type of content in the destination post. ' ,
189
- 'multisite-language-switcher '
190
- )
191
- ?>
192
- </label>
193
- </li>
194
- <?php
195
- foreach ( $ details ->importers as $ importer_slug => $ importer_info ) :
196
- ?>
197
- <li>
198
- <label>
199
- <input type="radio" name="msls_importers[
200
- <?php
201
- echo esc_attr ( $ details ->slug )
202
- ?>
203
- ]"
204
- value="
205
- <?php
206
- echo esc_attr ( $ importer_slug )
207
- ?>
208
- "
209
- <?php
210
- checked ( $ details ->selected , $ importer_slug )
211
- ?>
212
- >
213
- <?php
214
- echo ( esc_html (
215
- sprintf (
216
- '%s - %s ' ,
217
- $ importer_info ->name ,
218
- $ importer_info ->description
219
- )
220
- ) )
221
- ?>
222
- </label>
223
- </li>
140
+ </p>
141
+ <?php else : ?>
142
+ <ul>
143
+ <li>
144
+ <label>
145
+ <input type="radio" name="msls_importers[<?php echo esc_attr ( $ details ->slug ); ?> ]">
224
146
<?php
225
- endforeach ;
226
- ?>
227
- </ul>
228
- <?php
229
- endif ;
230
- ?>
231
- <?php
232
- endforeach ;
233
- ?>
234
-
147
+ esc_html_e (
148
+ 'Off - Do not import this type of content in the destination post. ' ,
149
+ 'multisite-language-switcher '
150
+ );
151
+ ?>
152
+ </label>
153
+ </li>
154
+ <?php foreach ( $ details ->importers as $ importer_slug => $ importer_info ) : ?>
155
+ <li>
156
+ <label>
157
+ <input type="radio" name="msls_importers[<?php echo esc_attr ( $ details ->slug ); ?> ]" value="<?php echo esc_attr ( $ importer_slug ); ?> " <?php checked ( $ details ->selected , $ importer_slug ); ?> >
158
+ <?php echo ( esc_html ( sprintf ( '%s - %s ' , $ importer_info ->name , $ importer_info ->description ) ) ); ?>
159
+ </label>
160
+ </li>
161
+ <?php endforeach ; ?>
162
+ </ul>
163
+ <?php endif ; ?>
164
+ <?php endforeach ; ?>
235
165
<div>
236
- <input
237
- type="submit"
238
- class="button button-primary"
239
- value="
240
- <?php
241
- esc_html_e ( 'Import Content ' , 'multisite-language-switcher ' )
242
- ?>
243
- "
244
- >
166
+ <input type="submit" class="button button-primary" value="<?php esc_html_e ( 'Import Content ' , 'multisite-language-switcher ' ); ?> ">
245
167
</div>
246
168
</form>
247
169
</div>
248
-
249
170
<?php
171
+
250
172
$ html = ob_get_clean ();
251
173
252
174
if ( $ echo ) {
253
- echo $ html ;
175
+ echo wp_kses_post ( $ html ) ;
254
176
}
255
177
256
178
return $ html ;
0 commit comments