5
5
use lloc \Msls \ContentImport \Importers \ImportersFactory ;
6
6
use lloc \Msls \ContentImport \Importers \Map ;
7
7
use lloc \Msls \MslsBlogCollection ;
8
+ use lloc \Msls \MslsFields ;
8
9
use lloc \Msls \MslsOptionsPost ;
9
10
use lloc \Msls \MslsPlugin ;
10
11
use lloc \Msls \MslsRegistryInstance ;
12
+ use lloc \Msls \MslsRequest ;
11
13
12
14
class MetaBox extends MslsRegistryInstance {
13
- protected $ data = [] ;
15
+ protected $ data = array () ;
14
16
15
17
/**
16
18
* Renders the content import metabox.
@@ -21,23 +23,30 @@ public function render() {
21
23
$ languages = MslsOptionsPost::instance ()->get_available_languages ();
22
24
$ current = MslsBlogCollection::get_blog_language ( get_current_blog_id () );
23
25
$ languages = array_diff_key ( $ languages , array ( $ current => $ current ) );
24
- $ input_lang = isset ( $ _GET [ ' msls_lang ' ] ) ? $ _GET [ ' msls_lang ' ] : null ;
25
- $ input_id = isset ( $ _GET [ ' msls_id ' ] ) ? $ _GET [ ' msls_id ' ] : null ;
26
+ $ input_lang = MslsRequest:: get ( MslsFields:: FIELD_MSLS_LANG , null ) ;
27
+ $ input_id = MslsRequest:: get ( MslsFields:: FIELD_MSLS_ID , null ) ;
26
28
$ has_input = null !== $ input_lang && null !== $ input_id ;
27
29
$ blogs = msls_blog_collection ();
28
- $ available = array_filter ( array_map ( function ( $ lang ) use ( $ mydata ) {
29
- return $ mydata ->{$ lang };
30
- }, array_keys ( $ languages ) ) );
30
+ $ available = array_filter (
31
+ array_map (
32
+ function ( $ lang ) use ( $ mydata ) {
33
+ return $ mydata ->{$ lang };
34
+ },
35
+ array_keys ( $ languages )
36
+ )
37
+ );
31
38
$ has_translation = count ( $ available ) >= 1 ;
32
39
33
40
if ( $ has_input || $ has_translation ) {
34
41
add_thickbox ();
35
42
$ label_template = __ ( 'Import content from %s ' , 'multisite-language-switcher ' );
36
43
$ output = '<fieldset> ' ;
37
- $ output .= '<legend> '
38
- . esc_html__ ( 'Warning! This will override and replace all the post content with the content from the source post! ' ,
39
- 'multisite-language-switcher ' )
40
- . '</legend> ' ;
44
+ $ output .= '<legend> '
45
+ . esc_html__ (
46
+ 'Warning! This will override and replace all the post content with the content from the source post! ' ,
47
+ 'multisite-language-switcher '
48
+ )
49
+ . '</legend> ' ;
41
50
foreach ( $ languages as $ language => $ label ) {
42
51
$ id = $ mydata ->{$ language };
43
52
$ blog = $ blogs ->get_blog_id ( $ language );
@@ -47,10 +56,11 @@ public function render() {
47
56
$ blog = $ blogs ->get_blog_id ( $ language );
48
57
}
49
58
if ( null !== $ id ) {
50
- $ this ->data = [
59
+ $ this ->data = array (
51
60
'msls_import ' => "{$ blog }| {$ id }" ,
52
- ];
53
- $ output .= sprintf ( '<a class="button button-primary thickbox" href="%s" title="%s">%s</a> ' ,
61
+ );
62
+ $ output .= sprintf (
63
+ '<a class="button button-primary thickbox" href="%s" title="%s">%s</a> ' ,
54
64
$ this ->inline_thickbox_url ( $ this ->data ),
55
65
$ label ,
56
66
$ label
@@ -60,21 +70,26 @@ public function render() {
60
70
$ output .= '</fieldset> ' ;
61
71
} else {
62
72
$ output = '<p> ' .
63
- esc_html__ ( 'No translated versions linked to this post: import content functionality is disabled. ' ,
64
- 'multisite-language-switcher ' )
65
- . '</p> ' ;
73
+ esc_html__ (
74
+ 'No translated versions linked to this post: import content functionality is disabled. ' ,
75
+ 'multisite-language-switcher '
76
+ )
77
+ . '</p> ' ;
66
78
}
67
79
68
80
echo $ output ;
69
81
}
70
82
71
- protected function inline_thickbox_url ( array $ data = [] ) {
72
- $ args = array_merge ( [
73
- 'modal ' => true ,
74
- 'width ' => 770 , // meh, just a guess on *most* devices
75
- 'height ' => 770 ,
76
- 'inlineId ' => 'msls-import-dialog- ' . str_replace ( '| ' , '- ' , $ data ['msls_import ' ] ),
77
- ], $ data );
83
+ protected function inline_thickbox_url ( array $ data = array () ) {
84
+ $ args = array_merge (
85
+ array (
86
+ 'modal ' => true ,
87
+ 'width ' => 770 , // meh, just a guess on *most* devices
88
+ 'height ' => 770 ,
89
+ 'inlineId ' => 'msls-import-dialog- ' . str_replace ( '| ' , '- ' , $ data ['msls_import ' ] ),
90
+ ),
91
+ $ data
92
+ );
78
93
79
94
return esc_url (
80
95
'#TB_inline ' . add_query_arg ( $ args , '' )
@@ -85,7 +100,7 @@ public function print_modal_html() {
85
100
echo $ this ->inline_thickbox_html ( true , $ this ->data );
86
101
}
87
102
88
- protected function inline_thickbox_html ( $ echo = true , array $ data = [] ) {
103
+ protected function inline_thickbox_html ( $ echo = true , array $ data = array () ) {
89
104
if ( ! isset ( $ data ['msls_import ' ] ) ) {
90
105
return '' ;
91
106
}
@@ -94,84 +109,139 @@ protected function inline_thickbox_html( $echo = true, array $data = [] ) {
94
109
95
110
ob_start ();
96
111
?>
97
- <div style="display: none;" id="msls-import-dialog-<?php
98
- echo esc_attr ( $ slug ) ?> ">
99
- <h3><?php
100
- esc_html_e ( 'Select what should be imported and how ' , 'multisite-language-switcher ' ) ?> </h3>
101
-
102
- <form action="<?php
103
- echo add_query_arg ( [] ) ?> " method="post">
112
+ <div style="display: none;" id="msls-import-dialog-
113
+ <?php
114
+ echo esc_attr ( $ slug )
115
+ ?>
116
+ ">
117
+ <h3>
118
+ <?php
119
+ esc_html_e ( 'Select what should be imported and how ' , 'multisite-language-switcher ' )
120
+ ?>
121
+ </h3>
122
+
123
+ <form action="
124
+ <?php
125
+ echo add_query_arg ( array () )
126
+ ?>
127
+ " method="post">
104
128
105
129
<?php
106
- wp_nonce_field ( MslsPlugin::path (), 'msls_noncename ' ); ?>
130
+ wp_nonce_field ( MslsPlugin::path (), 'msls_noncename ' );
131
+ ?>
107
132
108
133
<?php
109
- foreach ( $ data as $ key => $ value ) : ?>
110
- <input type="hidden" name="<?php
111
- echo esc_attr ( $ key ) ?> " value="<?php
112
- echo esc_attr ( $ value ) ?> ">
113
- <?php
114
- endforeach ; ?>
134
+ foreach ( $ data as $ key => $ value ) :
135
+ ?>
136
+ <input type="hidden" name="
137
+ <?php
138
+ echo esc_attr ( $ key )
139
+ ?>
140
+ " value="
141
+ <?php
142
+ echo esc_attr ( $ value )
143
+ ?>
144
+ ">
145
+ <?php
146
+ endforeach ;
147
+ ?>
115
148
116
149
<?php
117
150
/** @var ImportersFactory $factory */
118
- foreach ( Map::instance ()->factories () as $ slug => $ factory ) : ?>
151
+ foreach ( Map::instance ()->factories () as $ slug => $ factory ) :
152
+ ?>
119
153
<?php
120
- $ details = $ factory ->details () ?>
121
- <h4> <?php
122
- echo esc_html ( $ details -> name ) ?> </ h4>
154
+ $ details = $ factory ->details ()
155
+ ?>
156
+ < h4>
123
157
<?php
124
- if ( empty ( $ details ->importers ) ) : ?>
125
- <p><?php
126
- esc_html_e ( 'No importers available for this type of content. ' ,
127
- 'multisite-language-switcher ' ) ?> </p>
158
+ echo esc_html ( $ details ->name )
159
+ ?>
160
+ </h4>
128
161
<?php
129
- else : ?>
130
- <ul>
131
- <li>
132
- <label>
133
- <input type="radio" name="msls_importers[<?php
134
- echo esc_attr ( $ details ->slug ) ?> ]">
162
+ if ( empty ( $ details ->importers ) ) :
163
+ ?>
164
+ <p>
165
+ <?php
166
+ esc_html_e (
167
+ 'No importers available for this type of content. ' ,
168
+ 'multisite-language-switcher '
169
+ )
170
+ ?>
171
+ </p>
172
+ <?php
173
+ else :
174
+ ?>
175
+ <ul>
176
+ <li>
177
+ <label>
178
+ <input type="radio" name="msls_importers[
135
179
<?php
136
- esc_html_e ( 'Off - Do not import this type of content in the destination post. ' ,
137
- 'multisite-language-switcher ' ) ?>
138
- </label>
139
- </li>
180
+ echo esc_attr ( $ details ->slug )
181
+ ?>
182
+ ]">
183
+ <?php
184
+ esc_html_e (
185
+ 'Off - Do not import this type of content in the destination post. ' ,
186
+ 'multisite-language-switcher '
187
+ )
188
+ ?>
189
+ </label>
190
+ </li>
140
191
<?php
141
- foreach ( $ details ->importers as $ importer_slug => $ importer_info ) : ?>
142
- <li>
143
- <label>
144
- <input type="radio" name="msls_importers[<?php
145
- echo esc_attr ( $ details ->slug ) ?> ]"
146
- value="<?php
147
- echo esc_attr ( $ importer_slug ) ?> "
192
+ foreach ( $ details ->importers as $ importer_slug => $ importer_info ) :
193
+ ?>
194
+ <li>
195
+ <label>
196
+ <input type="radio" name="msls_importers[
197
+ <?php
198
+ echo esc_attr ( $ details ->slug )
199
+ ?>
200
+ ]"
201
+ value="
202
+ <?php
203
+ echo esc_attr ( $ importer_slug )
204
+ ?>
205
+ "
148
206
<?php
149
- checked ( $ details ->selected , $ importer_slug ) ?>
150
- >
207
+ checked ( $ details ->selected , $ importer_slug )
208
+ ?>
209
+ >
151
210
<?php
152
- echo ( esc_html ( sprintf ( '%s - %s ' ,
153
- $ importer_info ->name ,
154
- $ importer_info ->description ) ) ) ?>
155
- </label>
156
- </li>
157
- <?php
158
- endforeach ; ?>
159
- </ul>
211
+ echo ( esc_html (
212
+ sprintf (
213
+ '%s - %s ' ,
214
+ $ importer_info ->name ,
215
+ $ importer_info ->description
216
+ )
217
+ ) )
218
+ ?>
219
+ </label>
220
+ </li>
221
+ <?php
222
+ endforeach ;
223
+ ?>
224
+ </ul>
225
+ <?php
226
+ endif ;
227
+ ?>
160
228
<?php
161
- endif ; ?>
162
- <?php
163
- endforeach ; ?>
164
-
165
- <div>
166
- <input
167
- type="submit"
168
- class="button button-primary"
169
- value="<?php
170
- esc_html_e ( 'Import Content ' , 'multisite-language-switcher ' ) ?> "
171
- >
172
- </div>
173
- </form>
174
- </div>
229
+ endforeach ;
230
+ ?>
231
+
232
+ <div>
233
+ <input
234
+ type="submit"
235
+ class="button button-primary"
236
+ value="
237
+ <?php
238
+ esc_html_e ( 'Import Content ' , 'multisite-language-switcher ' )
239
+ ?>
240
+ "
241
+ >
242
+ </div>
243
+ </form>
244
+ </div>
175
245
176
246
<?php
177
247
$ html = ob_get_clean ();
0 commit comments