|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package WETU_Importer_Destination |
|
4
|
|
|
* @author LightSpeed |
|
5
|
|
|
* @license GPL-2.0+ |
|
6
|
|
|
* @link |
|
7
|
|
|
* @copyright 2016 LightSpeed |
|
8
|
|
|
**/ |
|
9
|
|
|
|
|
10
|
|
|
class WETU_Importer_Destination extends WETU_Importer { |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* The url to list items from WETU |
|
14
|
|
|
* |
|
15
|
|
|
* @since 0.0.1 |
|
16
|
|
|
* |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
public $tab_slug = 'destination'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The url to list items from WETU |
|
23
|
|
|
* |
|
24
|
|
|
* @since 0.0.1 |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
public $url = false; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The query string url to list items from WETU |
|
32
|
|
|
* |
|
33
|
|
|
* @since 0.0.1 |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
public $url_qs = false; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Options |
|
41
|
|
|
* |
|
42
|
|
|
* @since 0.0.1 |
|
43
|
|
|
* |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
public $options = false; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* The fields you wish to import |
|
50
|
|
|
* |
|
51
|
|
|
* @since 0.0.1 |
|
52
|
|
|
* |
|
53
|
|
|
* @var string |
|
54
|
|
|
*/ |
|
55
|
|
|
public $destination_options = false; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Initialize the plugin by setting localization, filters, and administration functions. |
|
59
|
|
|
* |
|
60
|
|
|
* @since 1.0.0 |
|
61
|
|
|
* |
|
62
|
|
|
* @access private |
|
63
|
|
|
*/ |
|
64
|
|
|
public function __construct() { |
|
65
|
|
|
$this->set_variables(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Sets the variables used throughout the plugin. |
|
70
|
|
|
*/ |
|
71
|
|
View Code Duplication |
public function set_variables() { |
|
|
|
|
|
|
72
|
|
|
parent::set_variables(); |
|
73
|
|
|
// ** This request only works with API KEY ** |
|
74
|
|
|
//if ( false !== $this->api_username && false !== $this->api_password ) { |
|
|
|
|
|
|
75
|
|
|
// $this->url = 'https://wetu.com/API/Pins/'; |
|
|
|
|
|
|
76
|
|
|
// $this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password; |
|
|
|
|
|
|
77
|
|
|
//} elseif ( false !== $this->api_key ) { |
|
|
|
|
|
|
78
|
|
|
$this->url = 'https://wetu.com/API/Pins/' . $this->api_key; |
|
79
|
|
|
$this->url_qs = ''; |
|
80
|
|
|
//} |
|
81
|
|
|
|
|
82
|
|
|
$temp_options = get_option( '_lsx-to_settings', false ); |
|
83
|
|
|
|
|
84
|
|
|
if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) { |
|
85
|
|
|
$this->options = $temp_options[ $this->plugin_slug ]; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$destination_options = get_option( 'wetu_importer_destination_settings', false ); |
|
89
|
|
|
|
|
90
|
|
|
if ( false !== $destination_options ) { |
|
91
|
|
|
$this->destination_options = $destination_options; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Display the importer administration screen |
|
97
|
|
|
*/ |
|
98
|
|
|
public function display_page() { |
|
99
|
|
|
?> |
|
100
|
|
|
<div class="wrap"> |
|
101
|
|
|
<?php $this->navigation( 'destination' ); ?> |
|
102
|
|
|
|
|
103
|
|
|
<?php $this->search_form(); ?> |
|
104
|
|
|
|
|
105
|
|
|
<form method="get" action="" id="posts-filter"> |
|
106
|
|
|
<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr( $this->tab_slug ); ?>"/> |
|
107
|
|
|
|
|
108
|
|
|
<p><input class="button button-primary add" type="button" |
|
109
|
|
|
value="<?php esc_html_e( 'Add to List', 'wetu-importer' ); ?>"/> |
|
110
|
|
|
<input class="button button-primary clear" type="button" |
|
111
|
|
|
value="<?php esc_html_e( 'Clear', 'wetu-importer' ); ?>"/> |
|
112
|
|
|
</p> |
|
113
|
|
|
|
|
114
|
|
|
<table class="wp-list-table widefat fixed posts"> |
|
115
|
|
|
<?php $this->table_header(); ?> |
|
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
<tbody id="the-list"> |
|
118
|
|
|
<tr class="post-0 type-tour status-none" id="post-0"> |
|
119
|
|
|
<th class="check-column" scope="row"> |
|
120
|
|
|
<label for="cb-select-0" |
|
121
|
|
|
class="screen-reader-text"><?php esc_html_e( 'Enter a title to search for and press enter', 'wetu-importer' ); ?></label> |
|
122
|
|
|
</th> |
|
123
|
|
|
<td class="post-title page-title column-title"> |
|
124
|
|
|
<strong> |
|
125
|
|
|
<?php esc_html_e( 'Enter a title to search for', 'wetu-importer' ); ?> |
|
126
|
|
|
</strong> |
|
127
|
|
|
</td> |
|
128
|
|
|
<td class="date column-date"> |
|
129
|
|
|
</td> |
|
130
|
|
|
<td class="ssid column-ssid"> |
|
131
|
|
|
</td> |
|
132
|
|
|
</tr> |
|
133
|
|
|
</tbody> |
|
134
|
|
|
|
|
135
|
|
|
<?php $this->table_footer(); ?> |
|
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
</table> |
|
138
|
|
|
|
|
139
|
|
|
<p><input class="button button-primary add" type="button" |
|
140
|
|
|
value="<?php esc_html_e( 'Add to List', 'wetu-importer' ); ?>"/> |
|
141
|
|
|
<input class="button button-primary clear" type="button" |
|
142
|
|
|
value="<?php esc_html_e( 'Clear', 'wetu-importer' ); ?>"/> |
|
143
|
|
|
</p> |
|
144
|
|
|
</form> |
|
145
|
|
|
|
|
146
|
|
|
<div style="display:none;" class="import-list-wrapper"> |
|
147
|
|
|
<br/> |
|
148
|
|
|
<form method="get" action="" id="import-list"> |
|
149
|
|
|
|
|
150
|
|
|
<div class="row"> |
|
151
|
|
|
<div class="settings-all" style="width:30%;display:block;float:left;"> |
|
152
|
|
|
<h3><?php esc_html_e( 'What content to Sync from WETU' ); ?></h3> |
|
153
|
|
|
<ul> |
|
154
|
|
|
<li> |
|
155
|
|
|
<input class="content select-all" <?php $this->checked( $this->destination_options, 'all' ); ?> |
|
|
|
|
|
|
156
|
|
|
type="checkbox" name="content[]" |
|
157
|
|
|
value="all"/> <?php esc_html_e( 'Select All', 'wetu-importer' ); ?></li> |
|
158
|
|
|
<?php if ( isset( $this->options ) && 'on' !== $this->options['disable_destination_descriptions'] ) { ?> |
|
159
|
|
|
<li> |
|
160
|
|
|
<input class="content" <?php $this->checked( $this->destination_options, 'description' ); ?> |
|
|
|
|
|
|
161
|
|
|
type="checkbox" name="content[]" |
|
162
|
|
|
value="description"/> <?php esc_html_e( 'Description', 'wetu-importer' ); ?></li> |
|
163
|
|
|
<?php } ?> |
|
164
|
|
|
|
|
165
|
|
|
<li> |
|
166
|
|
|
<input class="content" <?php $this->checked( $this->destination_options, 'gallery' ); ?> |
|
|
|
|
|
|
167
|
|
|
type="checkbox" name="content[]" |
|
168
|
|
|
value="gallery"/> <?php esc_html_e( 'Main Gallery', 'wetu-importer' ); ?></li> |
|
169
|
|
|
<?php if ( class_exists( 'LSX_TO_Maps' ) ) { ?> |
|
170
|
|
|
<li> |
|
171
|
|
|
<input class="content" <?php $this->checked( $this->destination_options, 'location' ); ?> |
|
|
|
|
|
|
172
|
|
|
type="checkbox" name="content[]" |
|
173
|
|
|
value="location"/> <?php esc_html_e( 'Location', 'wetu-importer' ); ?></li> |
|
174
|
|
|
<?php } ?> |
|
175
|
|
|
|
|
176
|
|
|
<?php if ( class_exists( 'LSX_TO_Videos' ) ) { ?> |
|
177
|
|
|
<li> |
|
178
|
|
|
<input class="content" <?php $this->checked( $this->destination_options, 'videos' ); ?> |
|
|
|
|
|
|
179
|
|
|
type="checkbox" name="content[]" |
|
180
|
|
|
value="videos"/> <?php esc_html_e( 'Videos', 'wetu-importer' ); ?></li> |
|
181
|
|
|
<?php } ?> |
|
182
|
|
|
|
|
183
|
|
|
</ul> |
|
184
|
|
|
<h4><?php esc_html_e( 'Additional Content' ); ?></h4> |
|
185
|
|
|
<ul> |
|
186
|
|
|
<li> |
|
187
|
|
|
<input class="content" <?php $this->checked( $this->destination_options, 'continent' ); ?> |
|
|
|
|
|
|
188
|
|
|
type="checkbox" name="content[]" |
|
189
|
|
|
value="continent"/> <?php esc_html_e( 'Set Continent', 'wetu-importer' ); ?></li> |
|
190
|
|
|
|
|
191
|
|
|
<li> |
|
192
|
|
|
<input class="content" <?php $this->checked( $this->destination_options, 'featured_image' ); ?> |
|
|
|
|
|
|
193
|
|
|
type="checkbox" name="content[]" |
|
194
|
|
|
value="featured_image"/> <?php esc_html_e( 'Set Featured Image', 'wetu-importer' ); ?> |
|
195
|
|
|
</li> |
|
196
|
|
|
<?php if ( class_exists( 'LSX_Banners' ) ) { ?> |
|
197
|
|
|
<li> |
|
198
|
|
|
<input class="content" <?php $this->checked( $this->destination_options, 'banner_image' ); ?> |
|
|
|
|
|
|
199
|
|
|
type="checkbox" name="content[]" |
|
200
|
|
|
value="banner_image"/> <?php esc_html_e( 'Set Banner Image', 'wetu-importer' ); ?> |
|
201
|
|
|
</li> |
|
202
|
|
|
<?php } ?> |
|
203
|
|
|
|
|
204
|
|
|
<li> |
|
205
|
|
|
<input class="content" <?php $this->checked( $this->destination_options, 'strip_tags' ); ?> |
|
|
|
|
|
|
206
|
|
|
type="checkbox" name="content[]" |
|
207
|
|
|
value="strip_tags"/> <?php esc_html_e( 'Strip HTML from the description', 'wetu-importer' ); ?></li> |
|
208
|
|
|
</ul> |
|
209
|
|
|
</div> |
|
210
|
|
|
<div class="settings-all" style="width:30%;display:block;float:left;"> |
|
211
|
|
|
<h3><?php esc_html_e( 'Travel Information' ); ?></h3> |
|
212
|
|
|
<ul> |
|
213
|
|
|
<li> |
|
214
|
|
|
<input class="content" <?php $this->checked( $this->destination_options, 'electricity' ); ?> |
|
|
|
|
|
|
215
|
|
|
type="checkbox" name="content[]" |
|
216
|
|
|
value="electricity"/> <?php esc_html_e( 'Electricity', 'wetu-importer' ); ?></li> |
|
217
|
|
|
<li> |
|
218
|
|
|
<input class="content" <?php $this->checked( $this->destination_options, 'banking' ); ?> |
|
|
|
|
|
|
219
|
|
|
type="checkbox" name="content[]" |
|
220
|
|
|
value="banking"/> <?php esc_html_e( 'Banking', 'wetu-importer' ); ?></li> |
|
221
|
|
|
<li> |
|
222
|
|
|
<input class="content" <?php $this->checked( $this->destination_options, 'cuisine' ); ?> |
|
|
|
|
|
|
223
|
|
|
type="checkbox" name="content[]" |
|
224
|
|
|
value="cuisine"/> <?php esc_html_e( 'Cuisine', 'wetu-importer' ); ?></li> |
|
225
|
|
|
<li> |
|
226
|
|
|
<input class="content" <?php $this->checked( $this->destination_options, 'climate' ); ?> |
|
|
|
|
|
|
227
|
|
|
type="checkbox" name="content[]" |
|
228
|
|
|
value="climate"/> <?php esc_html_e( 'Climate', 'wetu-importer' ); ?></li> |
|
229
|
|
|
<li> |
|
230
|
|
|
<input class="content" <?php $this->checked( $this->destination_options, 'transport' ); ?> |
|
|
|
|
|
|
231
|
|
|
type="checkbox" name="content[]" |
|
232
|
|
|
value="transport"/> <?php esc_html_e( 'Transport', 'wetu-importer' ); ?></li> |
|
233
|
|
|
<li><input class="content" <?php $this->checked( $this->destination_options, 'dress' ); ?> |
|
|
|
|
|
|
234
|
|
|
type="checkbox" name="content[]" |
|
235
|
|
|
value="dress"/> <?php esc_html_e( 'Dress', 'wetu-importer' ); ?></li> |
|
236
|
|
|
<li><input class="content" <?php $this->checked( $this->destination_options, 'health' ); ?> |
|
|
|
|
|
|
237
|
|
|
type="checkbox" name="content[]" |
|
238
|
|
|
value="health"/> <?php esc_html_e( 'Health', 'wetu-importer' ); ?></li> |
|
239
|
|
|
<li><input class="content" <?php $this->checked( $this->destination_options, 'safety' ); ?> |
|
|
|
|
|
|
240
|
|
|
type="checkbox" name="content[]" |
|
241
|
|
|
value="safety"/> <?php esc_html_e( 'Safety', 'wetu-importer' ); ?></li> |
|
242
|
|
|
<li><input class="content" <?php $this->checked( $this->destination_options, 'visa' ); ?> |
|
|
|
|
|
|
243
|
|
|
type="checkbox" name="content[]" |
|
244
|
|
|
value="visa"/> <?php esc_html_e( 'Visa', 'wetu-importer' ); ?></li> |
|
245
|
|
|
<li><input class="content" <?php $this->checked( $this->destination_options, 'additional_info' ); ?> |
|
|
|
|
|
|
246
|
|
|
type="checkbox" name="content[]" |
|
247
|
|
|
value="additional_info"/> <?php esc_html_e( 'General', 'wetu-importer' ); ?></li> |
|
248
|
|
|
</ul> |
|
249
|
|
|
</div> |
|
250
|
|
|
|
|
251
|
|
|
<?php if ( class_exists( 'LSX_TO_Team' ) ) { ?> |
|
252
|
|
|
<div style="width:30%;display:block;float:left;"> |
|
253
|
|
|
<h3><?php esc_html_e( 'Assign a Team Member' ); ?></h3> |
|
254
|
|
|
<?php $this->team_member_checkboxes( $this->destination_options ); ?> |
|
|
|
|
|
|
255
|
|
|
</div> |
|
256
|
|
|
<?php } ?> |
|
257
|
|
|
|
|
258
|
|
|
<br clear="both"/> |
|
259
|
|
|
</div> |
|
260
|
|
|
|
|
261
|
|
|
|
|
262
|
|
|
<h3><?php esc_html_e( 'Your List' ); ?></h3> |
|
263
|
|
|
<p><input class="button button-primary" type="submit" |
|
264
|
|
|
value="<?php esc_html_e( 'Sync', 'wetu-importer' ); ?>"/></p> |
|
265
|
|
|
<table class="wp-list-table widefat fixed posts"> |
|
266
|
|
|
<?php $this->table_header(); ?> |
|
|
|
|
|
|
267
|
|
|
|
|
268
|
|
|
<tbody> |
|
269
|
|
|
|
|
270
|
|
|
</tbody> |
|
271
|
|
|
|
|
272
|
|
|
<?php $this->table_footer(); ?> |
|
|
|
|
|
|
273
|
|
|
|
|
274
|
|
|
</table> |
|
275
|
|
|
|
|
276
|
|
|
<p><input class="button button-primary" type="submit" |
|
277
|
|
|
value="<?php esc_html_e( 'Sync', 'wetu-importer' ); ?>"/></p> |
|
278
|
|
|
</form> |
|
279
|
|
|
</div> |
|
280
|
|
|
|
|
281
|
|
|
<div style="display:none;" class="completed-list-wrapper"> |
|
282
|
|
|
<h3><?php esc_html_e( 'Completed' ); ?></h3> |
|
283
|
|
|
<ul> |
|
284
|
|
|
</ul> |
|
285
|
|
|
</div> |
|
286
|
|
|
</div> |
|
287
|
|
|
<?php |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* Grab all the current destination posts via the lsx_wetu_id field. |
|
292
|
|
|
*/ |
|
293
|
|
View Code Duplication |
public function find_current_destination( $post_type = 'destination' ) { |
|
|
|
|
|
|
294
|
|
|
global $wpdb; |
|
295
|
|
|
$return = array(); |
|
296
|
|
|
|
|
297
|
|
|
// @codingStandardsIgnoreStart |
|
298
|
|
|
$current_destination = $wpdb->get_results(" |
|
299
|
|
|
SELECT key1.post_id,key1.meta_value,key2.post_title as name,key2.post_date as last_modified |
|
300
|
|
|
FROM {$wpdb->postmeta} key1 |
|
301
|
|
|
|
|
302
|
|
|
INNER JOIN {$wpdb->posts} key2 |
|
303
|
|
|
ON key1.post_id = key2.ID |
|
304
|
|
|
|
|
305
|
|
|
WHERE key1.meta_key = 'lsx_wetu_id' |
|
306
|
|
|
AND key2.post_type = '{$post_type}' |
|
307
|
|
|
|
|
308
|
|
|
LIMIT 0,1000 |
|
309
|
|
|
"); |
|
310
|
|
|
// @codingStandardsIgnoreEnd |
|
311
|
|
|
|
|
312
|
|
|
if ( null !== $current_destination && ! empty( $current_destination ) ) { |
|
313
|
|
|
foreach ( $current_destination as $accom ) { |
|
314
|
|
|
$return[ $accom->meta_value ] = $accom; |
|
315
|
|
|
} |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
return $return; |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
/** |
|
322
|
|
|
* Run through the destination grabbed from the DB. |
|
323
|
|
|
*/ |
|
324
|
|
|
public function process_ajax_search() { |
|
325
|
|
|
$return = false; |
|
326
|
|
|
|
|
327
|
|
|
// @codingStandardsIgnoreLine |
|
328
|
|
|
if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_tour_importer' && isset( $_POST['type'] ) && $_POST['type'] === 'destination' ) { |
|
329
|
|
|
|
|
330
|
|
|
// @codingStandardsIgnoreLine |
|
331
|
|
|
if ( isset( $_POST['keyword'] ) ) { |
|
332
|
|
|
$searched_items = false; |
|
333
|
|
|
|
|
334
|
|
|
// @codingStandardsIgnoreLine |
|
335
|
|
View Code Duplication |
if ( isset( $_POST['keyword'] ) ) { |
|
|
|
|
|
|
336
|
|
|
// @codingStandardsIgnoreLine |
|
337
|
|
|
$keyphrases = $_POST['keyword']; |
|
338
|
|
|
} else { |
|
339
|
|
|
$keyphrases = array( 0 ); |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
if ( ! is_array( $keyphrases ) ) { |
|
343
|
|
|
$keyphrases = array( $keyphrases ); |
|
344
|
|
|
} |
|
345
|
|
|
foreach ( $keyphrases as &$keyword ) { |
|
346
|
|
|
$keyword = ltrim( rtrim( $keyword ) ); |
|
347
|
|
|
} |
|
348
|
|
|
|
|
349
|
|
|
$post_status = false; |
|
350
|
|
|
if ( in_array( 'publish', $keyphrases ) ) { |
|
351
|
|
|
$post_status = 'publish'; |
|
352
|
|
|
} |
|
353
|
|
|
if ( in_array( 'pending', $keyphrases ) ) { |
|
354
|
|
|
$post_status = 'pending'; |
|
355
|
|
|
} |
|
356
|
|
|
if ( in_array( 'draft', $keyphrases ) ) { |
|
357
|
|
|
$post_status = 'draft'; |
|
358
|
|
|
} |
|
359
|
|
|
if ( in_array( 'import', $keyphrases ) ) { |
|
360
|
|
|
$post_status = 'import'; |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
$destination = $this->find_current_destination(); |
|
364
|
|
|
|
|
365
|
|
|
if ( ! empty( $destination ) ) { |
|
366
|
|
|
|
|
367
|
|
|
foreach ( $destination as $row ) { |
|
368
|
|
|
|
|
369
|
|
|
//If we are searching for |
|
370
|
|
|
if ( 'import' === $post_status ) { |
|
371
|
|
|
if ( is_array( $this->queued_imports ) && in_array( $row->post_id,$this->queued_imports ) ) { |
|
372
|
|
|
$searched_items[ sanitize_title( $row->name ) . '-' . $row->meta_value ] = $this->format_row( $row ); |
|
373
|
|
|
} else { |
|
374
|
|
|
continue; |
|
375
|
|
|
} |
|
376
|
|
|
} else if ( false !== $post_status ) { |
|
377
|
|
|
|
|
378
|
|
|
$current_status = get_post_status( $row->post_id ); |
|
379
|
|
|
if ( $current_status !== $post_status ) { |
|
380
|
|
|
continue; |
|
381
|
|
|
} |
|
382
|
|
|
$searched_items[ sanitize_title( $row->name ) . '-' . $row->meta_value ] = $this->format_row( $row ); |
|
383
|
|
|
|
|
384
|
|
|
} else { |
|
385
|
|
|
//Search through each keyword. |
|
386
|
|
|
foreach ( $keyphrases as $keyphrase ) { |
|
387
|
|
|
|
|
388
|
|
|
//Make sure the keyphrase is turned into an array |
|
389
|
|
|
$keywords = explode( ' ', $keyphrase ); |
|
390
|
|
|
if ( ! is_array( $keywords ) ) { |
|
391
|
|
|
$keywords = array( $keywords ); |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
if ( $this->multineedle_stripos( ltrim( rtrim( $row->name ) ), $keywords ) !== false ) { |
|
395
|
|
|
$searched_items[ sanitize_title( $row->name ) . '-' . $row->meta_value ] = $this->format_row( $row ); |
|
396
|
|
|
} |
|
397
|
|
|
} |
|
398
|
|
|
} |
|
399
|
|
|
} |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
if ( false !== $searched_items ) { |
|
403
|
|
|
ksort( $searched_items ); |
|
404
|
|
|
$return = implode( $searched_items ); |
|
405
|
|
|
} |
|
406
|
|
|
} |
|
407
|
|
|
print_r( $return ); |
|
408
|
|
|
die(); |
|
409
|
|
|
} |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
/** |
|
413
|
|
|
* Formats the row for output on the screen. |
|
414
|
|
|
*/ |
|
415
|
|
|
public function format_row( $row = false ) { |
|
416
|
|
|
if ( false !== $row ) { |
|
417
|
|
|
|
|
418
|
|
|
$status = 'import'; |
|
419
|
|
|
if ( 0 !== $row->post_id ) { |
|
420
|
|
|
$status = '<a href="' . admin_url( '/post.php?post=' . $row->post_id . '&action=edit' ) . '" target="_blank">' . get_post_status( $row->post_id ) . '</a>'; |
|
421
|
|
|
} |
|
422
|
|
|
|
|
423
|
|
|
$row_html = ' |
|
424
|
|
|
<tr class="post-' . $row->post_id . ' type-tour" id="post-' . $row->post_id . '"> |
|
425
|
|
|
<th class="check-column" scope="row"> |
|
426
|
|
|
<label for="cb-select-' . $row->meta_value . '" class="screen-reader-text">' . $row->name . '</label> |
|
427
|
|
|
<input type="checkbox" data-identifier="' . $row->meta_value . '" value="' . $row->post_id . '" name="post[]" id="cb-select-' . $row->meta_value . '"> |
|
428
|
|
|
</th> |
|
429
|
|
|
<td class="post-title page-title column-title"> |
|
430
|
|
|
<strong>' . $row->name . '</strong> - ' . $status . ' |
|
431
|
|
|
</td> |
|
432
|
|
|
<td class="date column-date"> |
|
433
|
|
|
<abbr title="' . date( 'Y/m/d', strtotime( $row->last_modified ) ) . '">' . date( 'Y/m/d', strtotime( $row->last_modified ) ) . '</abbr><br>Last Modified |
|
434
|
|
|
</td> |
|
435
|
|
|
<td class="ssid column-ssid"> |
|
436
|
|
|
' . $row->meta_value . ' |
|
437
|
|
|
</td> |
|
438
|
|
|
</tr>'; |
|
439
|
|
|
return $row_html; |
|
440
|
|
|
} |
|
441
|
|
|
} |
|
442
|
|
|
|
|
443
|
|
|
/** |
|
444
|
|
|
* Connect to wetu |
|
445
|
|
|
*/ |
|
446
|
|
|
public function process_ajax_import() { |
|
447
|
|
|
$return = false; |
|
|
|
|
|
|
448
|
|
|
|
|
449
|
|
|
// @codingStandardsIgnoreLine |
|
450
|
|
|
if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_import_items' && isset( $_POST['type'] ) && $_POST['type'] === 'destination' && isset( $_POST['wetu_id'] ) ) { |
|
451
|
|
|
// @codingStandardsIgnoreLine |
|
452
|
|
|
$wetu_id = $_POST['wetu_id']; |
|
453
|
|
|
|
|
454
|
|
|
// @codingStandardsIgnoreLine |
|
455
|
|
|
if ( isset( $_POST['post_id'] ) ) { |
|
456
|
|
|
// @codingStandardsIgnoreLine |
|
457
|
|
|
$post_id = $_POST['post_id']; |
|
458
|
|
|
$this->current_post = get_post( $post_id ); |
|
459
|
|
|
} else { |
|
460
|
|
|
$post_id = 0; |
|
461
|
|
|
} |
|
462
|
|
|
|
|
463
|
|
|
// @codingStandardsIgnoreLine |
|
464
|
|
|
if ( isset( $_POST['team_members'] ) ) { |
|
465
|
|
|
// @codingStandardsIgnoreLine |
|
466
|
|
|
$team_members = $_POST['team_members']; |
|
467
|
|
|
} else { |
|
468
|
|
|
$team_members = false; |
|
469
|
|
|
} |
|
470
|
|
|
|
|
471
|
|
|
$safari_brands = false; |
|
472
|
|
|
|
|
473
|
|
|
delete_option( 'wetu_importer_destination_settings' ); |
|
474
|
|
|
|
|
475
|
|
|
// @codingStandardsIgnoreLine |
|
476
|
|
View Code Duplication |
if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) { |
|
|
|
|
|
|
477
|
|
|
// @codingStandardsIgnoreLine |
|
478
|
|
|
$content = $_POST['content']; |
|
479
|
|
|
add_option( 'wetu_importer_destination_settings', $content ); |
|
480
|
|
|
} else { |
|
481
|
|
|
$content = false; |
|
482
|
|
|
} |
|
483
|
|
|
|
|
484
|
|
|
$jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
485
|
|
|
|
|
486
|
|
View Code Duplication |
if ( $jdata ) { |
|
|
|
|
|
|
487
|
|
|
$adata = json_decode( $jdata, true ); |
|
488
|
|
|
|
|
489
|
|
|
if ( ! empty( $adata ) && ! isset( $adata['error'] ) ) { |
|
490
|
|
|
$return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands ); |
|
491
|
|
|
$this->remove_from_queue( $return ); |
|
492
|
|
|
$this->format_completed_row( $return ); |
|
493
|
|
|
} else { |
|
494
|
|
|
if ( isset( $adata['error'] ) ) { |
|
495
|
|
|
$this->format_error( $adata['error'] ); |
|
496
|
|
|
} else { |
|
497
|
|
|
$this->format_error( esc_html__( 'There was a problem importing your destination, please try refreshing the page.','wetu-importer' ) ); |
|
498
|
|
|
} |
|
499
|
|
|
} |
|
500
|
|
|
} |
|
501
|
|
|
} |
|
502
|
|
|
} |
|
503
|
|
|
|
|
504
|
|
|
/** |
|
505
|
|
|
* Saves the queue to the option. |
|
506
|
|
|
*/ |
|
507
|
|
View Code Duplication |
public function remove_from_queue( $id ) { |
|
|
|
|
|
|
508
|
|
|
if ( ! empty( $this->queued_imports ) ) { |
|
509
|
|
|
// @codingStandardsIgnoreLine |
|
510
|
|
|
if ( ( $key = array_search( $id, $this->queued_imports ) ) !== false ) { |
|
511
|
|
|
unset( $this->queued_imports[ $key ] ); |
|
512
|
|
|
|
|
513
|
|
|
delete_option( 'wetu_importer_que' ); |
|
514
|
|
|
update_option( 'wetu_importer_que',$this->queued_imports ); |
|
515
|
|
|
} |
|
516
|
|
|
} |
|
517
|
|
|
} |
|
518
|
|
|
|
|
519
|
|
|
/** |
|
520
|
|
|
* Connect to wetu |
|
521
|
|
|
*/ |
|
522
|
|
|
public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = false, $safari_brands = false ) { |
|
|
|
|
|
|
523
|
|
|
if ( 'Destination' === trim( $data[0]['type'] ) ) { |
|
524
|
|
|
$post_name = ''; |
|
525
|
|
|
$data_post_content = ''; |
|
|
|
|
|
|
526
|
|
|
$data_post_excerpt = ''; |
|
|
|
|
|
|
527
|
|
|
|
|
528
|
|
|
$post = array( |
|
529
|
|
|
'post_type' => 'destination', |
|
530
|
|
|
); |
|
531
|
|
|
|
|
532
|
|
|
//Set the post_content |
|
533
|
|
|
if ( false !== $importable_content && in_array( 'description', $importable_content ) ) { |
|
534
|
|
|
if ( isset( $data[0]['content']['general_description'] ) ) { |
|
535
|
|
|
|
|
536
|
|
|
if ( false !== $importable_content && in_array( 'strip_tags', $importable_content ) ) { |
|
537
|
|
|
$post['post_content'] = wp_strip_all_tags( $data[0]['content']['general_description'] ); |
|
538
|
|
|
} else { |
|
539
|
|
|
$post['post_content'] = $data[0]['content']['general_description']; |
|
540
|
|
|
} |
|
541
|
|
|
} |
|
542
|
|
|
} |
|
543
|
|
|
|
|
544
|
|
View Code Duplication |
if ( false !== $id && '0' !== $id ) { |
|
|
|
|
|
|
545
|
|
|
$post['ID'] = $id; |
|
546
|
|
|
|
|
547
|
|
|
if ( isset( $data[0]['name'] ) ) { |
|
548
|
|
|
$post['post_title'] = $data[0]['name']; |
|
549
|
|
|
$post['post_status'] = 'publish'; |
|
550
|
|
|
$post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 ); |
|
551
|
|
|
} |
|
552
|
|
|
|
|
553
|
|
|
$id = wp_update_post( $post ); |
|
554
|
|
|
$prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true ); |
|
555
|
|
|
update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date ); |
|
556
|
|
|
} else { |
|
557
|
|
|
//Set the name |
|
558
|
|
|
if ( isset( $data[0]['name'] ) ) { |
|
559
|
|
|
$post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 ); |
|
560
|
|
|
} |
|
561
|
|
|
|
|
562
|
|
|
$post['post_name'] = $post_name; |
|
563
|
|
|
$post['post_title'] = $data[0]['name']; |
|
564
|
|
|
$post['post_status'] = 'publish'; |
|
565
|
|
|
$id = wp_insert_post( $post ); |
|
566
|
|
|
|
|
567
|
|
|
//Save the WETU ID and the Last date it was modified. |
|
568
|
|
|
if ( false !== $id ) { |
|
569
|
|
|
add_post_meta( $id, 'lsx_wetu_id', $wetu_id ); |
|
570
|
|
|
add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) ); |
|
571
|
|
|
} |
|
572
|
|
|
} |
|
573
|
|
|
|
|
574
|
|
|
$this->find_attachments( $id ); |
|
575
|
|
|
|
|
576
|
|
|
//Set the team member if it is there |
|
577
|
|
View Code Duplication |
if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) { |
|
|
|
|
|
|
578
|
|
|
$this->set_team_member( $id, $team_members ); |
|
579
|
|
|
} |
|
580
|
|
|
|
|
581
|
|
|
if ( class_exists( 'LSX_TO_Maps' ) ) { |
|
582
|
|
|
$this->set_map_data( $data, $id, 9 ); |
|
583
|
|
|
} |
|
584
|
|
|
|
|
585
|
|
|
//Set the Room Data |
|
586
|
|
|
if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) { |
|
587
|
|
|
$this->set_video_data( $data, $id ); |
|
588
|
|
|
} |
|
589
|
|
|
|
|
590
|
|
|
//Set the Electricity |
|
591
|
|
|
if ( false !== $importable_content && in_array( 'electricity', $importable_content ) ) { |
|
592
|
|
|
$this->set_travel_info( $data, $id, 'electricity' ); |
|
593
|
|
|
} |
|
594
|
|
|
//Set the cuisine |
|
595
|
|
|
if ( false !== $importable_content && in_array( 'cuisine', $importable_content ) ) { |
|
596
|
|
|
$this->set_travel_info( $data, $id, 'cuisine' ); |
|
597
|
|
|
} |
|
598
|
|
|
//Set the banking |
|
599
|
|
|
if ( false !== $importable_content && in_array( 'banking', $importable_content ) ) { |
|
600
|
|
|
$this->set_travel_info( $data, $id, 'banking' ); |
|
601
|
|
|
} |
|
602
|
|
|
//Set the transport |
|
603
|
|
|
if ( false !== $importable_content && in_array( 'transport', $importable_content ) ) { |
|
604
|
|
|
$this->set_travel_info( $data, $id, 'transport' ); |
|
605
|
|
|
} |
|
606
|
|
|
//Set the dress |
|
607
|
|
|
if ( false !== $importable_content && in_array( 'dress', $importable_content ) ) { |
|
608
|
|
|
$this->set_travel_info( $data, $id, 'dress' ); |
|
609
|
|
|
} |
|
610
|
|
|
//Set the climate |
|
611
|
|
|
if ( false !== $importable_content && in_array( 'climate', $importable_content ) ) { |
|
612
|
|
|
$this->set_travel_info( $data, $id, 'climate' ); |
|
613
|
|
|
} |
|
614
|
|
|
//Set the Health |
|
615
|
|
|
if ( false !== $importable_content && in_array( 'health', $importable_content ) ) { |
|
616
|
|
|
$this->set_travel_info( $data, $id, 'health' ); |
|
617
|
|
|
} |
|
618
|
|
|
//Set the Safety |
|
619
|
|
|
if ( false !== $importable_content && in_array( 'safety', $importable_content ) ) { |
|
620
|
|
|
$this->set_travel_info( $data, $id, 'safety' ); |
|
621
|
|
|
} |
|
622
|
|
|
//Set the Visa |
|
623
|
|
|
if ( false !== $importable_content && in_array( 'visa', $importable_content ) ) { |
|
624
|
|
|
$this->set_travel_info( $data, $id, 'visa' ); |
|
625
|
|
|
} |
|
626
|
|
|
//Set the General |
|
627
|
|
|
if ( false !== $importable_content && in_array( 'additional_info', $importable_content ) ) { |
|
628
|
|
|
$this->set_travel_info( $data, $id, 'additional_info' ); |
|
629
|
|
|
} |
|
630
|
|
|
|
|
631
|
|
|
//Setup some default for use in the import |
|
632
|
|
|
if ( false !== $importable_content && (in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content )) ) { |
|
633
|
|
|
$this->find_attachments( $id ); |
|
634
|
|
|
|
|
635
|
|
|
//Set the featured image |
|
636
|
|
|
if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) { |
|
637
|
|
|
$this->set_featured_image( $data, $id ); |
|
638
|
|
|
} |
|
639
|
|
|
if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) { |
|
640
|
|
|
$this->set_banner_image( $data, $id ); |
|
641
|
|
|
} |
|
642
|
|
|
//Import the main gallery |
|
643
|
|
|
if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) { |
|
644
|
|
|
$this->create_main_gallery( $data, $id ); |
|
645
|
|
|
} |
|
646
|
|
|
} |
|
647
|
|
|
|
|
648
|
|
|
//Set the continent |
|
649
|
|
|
if ( false !== $importable_content && in_array( 'continent', $importable_content ) ) { |
|
650
|
|
|
$this->set_continent( $data, $id ); |
|
651
|
|
|
} |
|
652
|
|
|
} |
|
653
|
|
|
|
|
654
|
|
|
return $id; |
|
655
|
|
|
} |
|
656
|
|
|
|
|
657
|
|
|
/** |
|
658
|
|
|
* Set the team memberon each item. |
|
659
|
|
|
*/ |
|
660
|
|
View Code Duplication |
public function set_team_member( $id, $team_members ) { |
|
|
|
|
|
|
661
|
|
|
delete_post_meta( $id, 'team_to_' . $this->tab_slug ); |
|
662
|
|
|
|
|
663
|
|
|
foreach ( $team_members as $team ) { |
|
664
|
|
|
add_post_meta( $id, 'team_to_' . $this->tab_slug, $team ); |
|
665
|
|
|
} |
|
666
|
|
|
} |
|
667
|
|
|
|
|
668
|
|
|
/** |
|
669
|
|
|
* Saves the room data |
|
670
|
|
|
*/ |
|
671
|
|
|
public function set_travel_info( $data, $id, $meta_key ) { |
|
672
|
|
|
if ( ! empty( $data[0]['travel_information'] ) && isset( $data[0]['travel_information'][ $meta_key ] ) ) { |
|
673
|
|
|
$content = $data[0]['travel_information'][ $meta_key ]; |
|
674
|
|
|
$this->save_custom_field( $content, $meta_key, $id ); |
|
675
|
|
|
} |
|
676
|
|
|
} |
|
677
|
|
|
|
|
678
|
|
|
/** |
|
679
|
|
|
* Set the Travel Style |
|
680
|
|
|
*/ |
|
681
|
|
|
public function set_continent( $data, $id ) { |
|
682
|
|
|
if ( isset( $data[0]['position']['country'] ) ) { |
|
683
|
|
|
//get the continent code. |
|
684
|
|
|
$continent_code = to_continent_label( to_continent_code( to_country_data( $data[0]['position']['country'], false ) ) ); |
|
685
|
|
|
|
|
686
|
|
|
if ( '' !== $continent_code ) { |
|
687
|
|
|
// @codingStandardsIgnoreLine |
|
688
|
|
|
if ( ! $term = term_exists( trim( $continent_code ), 'continent' ) ) { |
|
689
|
|
|
$term = wp_insert_term( trim( $continent_code ), 'continent' ); |
|
690
|
|
|
|
|
691
|
|
|
if ( is_wp_error( $term ) ) { |
|
692
|
|
|
// @codingStandardsIgnoreLine |
|
693
|
|
|
echo $term->get_error_message(); |
|
694
|
|
|
} |
|
695
|
|
|
} else { |
|
696
|
|
|
wp_set_object_terms( $id, intval( $term['term_id'] ), 'continent', true ); |
|
697
|
|
|
} |
|
698
|
|
|
} else { |
|
699
|
|
|
wp_set_object_terms( $id, intval( $term['term_id'] ), 'continent', true ); |
|
|
|
|
|
|
700
|
|
|
} |
|
701
|
|
|
} |
|
702
|
|
|
} |
|
703
|
|
|
} |
|
704
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.