@@ -9,95 +9,95 @@ discard block |
||
9 | 9 | |
10 | 10 | class LSX_WETU_Importer_Accommodation extends LSX_WETU_Importer { |
11 | 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 = 'accommodation'; |
|
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 $accommodation_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 | - public function set_variables() { |
|
72 | - parent::set_variables(); |
|
73 | - |
|
74 | - // ** This request only works with API KEY ** |
|
75 | - // if ( false !== $this->api_username && false !== $this->api_password ) { |
|
76 | - // $this->url = 'https://wetu.com/API/Pins/'; |
|
77 | - // $this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password; |
|
78 | - // } elseif ( false !== $this->api_key ) { |
|
79 | - $this->url = 'https://wetu.com/API/Pins/' . $this->api_key; |
|
80 | - $this->url_qs = 'all=include'; |
|
81 | - // } |
|
82 | - |
|
83 | - $temp_options = get_option( '_lsx-to_settings', false ); |
|
84 | - |
|
85 | - if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) { |
|
86 | - $this->options = $temp_options[ $this->plugin_slug ]; |
|
87 | - } |
|
88 | - |
|
89 | - $accommodation_options = get_option( 'lsx_wetu_importer_accommodation_settings', false ); |
|
90 | - |
|
91 | - if ( false !== $accommodation_options ) { |
|
92 | - $this->accommodation_options = $accommodation_options; |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Display the importer administration screen |
|
98 | - */ |
|
99 | - public function display_page() { |
|
100 | - ?> |
|
12 | + /** |
|
13 | + * The url to list items from WETU |
|
14 | + * |
|
15 | + * @since 0.0.1 |
|
16 | + * |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + public $tab_slug = 'accommodation'; |
|
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 $accommodation_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 | + public function set_variables() { |
|
72 | + parent::set_variables(); |
|
73 | + |
|
74 | + // ** This request only works with API KEY ** |
|
75 | + // if ( false !== $this->api_username && false !== $this->api_password ) { |
|
76 | + // $this->url = 'https://wetu.com/API/Pins/'; |
|
77 | + // $this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password; |
|
78 | + // } elseif ( false !== $this->api_key ) { |
|
79 | + $this->url = 'https://wetu.com/API/Pins/' . $this->api_key; |
|
80 | + $this->url_qs = 'all=include'; |
|
81 | + // } |
|
82 | + |
|
83 | + $temp_options = get_option( '_lsx-to_settings', false ); |
|
84 | + |
|
85 | + if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) { |
|
86 | + $this->options = $temp_options[ $this->plugin_slug ]; |
|
87 | + } |
|
88 | + |
|
89 | + $accommodation_options = get_option( 'lsx_wetu_importer_accommodation_settings', false ); |
|
90 | + |
|
91 | + if ( false !== $accommodation_options ) { |
|
92 | + $this->accommodation_options = $accommodation_options; |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Display the importer administration screen |
|
98 | + */ |
|
99 | + public function display_page() { |
|
100 | + ?> |
|
101 | 101 | <div class="wrap"> |
102 | 102 | |
103 | 103 | <div class="tablenav top"> |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | <div style="width:30%;display:block;float:left;"> |
188 | 188 | <h3><?php esc_html_e( 'Assign a Safari Brand' ); ?></h3> |
189 | 189 | <?php |
190 | - echo wp_kses_post( $this->taxonomy_checkboxes( 'accommodation-brand', $this->accommodation_options ) ); |
|
191 | - ?> |
|
190 | + echo wp_kses_post( $this->taxonomy_checkboxes( 'accommodation-brand', $this->accommodation_options ) ); |
|
191 | + ?> |
|
192 | 192 | </div> |
193 | 193 | |
194 | 194 | <br clear="both" /> |
@@ -218,142 +218,142 @@ discard block |
||
218 | 218 | </div> |
219 | 219 | </div> |
220 | 220 | <?php |
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Run through the accommodation grabbed from the DB. |
|
225 | - */ |
|
226 | - public function process_ajax_search() { |
|
227 | - $return = false; |
|
228 | - check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
229 | - if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && 'accommodation' === $_POST['type'] ) { |
|
230 | - |
|
231 | - $searched_items = false; |
|
232 | - if ( isset( $_POST['keyword'] ) ) { |
|
233 | - $keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) ); |
|
234 | - } else { |
|
235 | - $keyphrases = array( 0 ); |
|
236 | - } |
|
237 | - |
|
238 | - if ( ! is_array( $keyphrases ) ) { |
|
239 | - $keyphrases = array( $keyphrases ); |
|
240 | - } |
|
241 | - foreach ( $keyphrases as &$keyword ) { |
|
242 | - $keyword = ltrim( rtrim( $keyword ) ); |
|
243 | - } |
|
244 | - |
|
245 | - $post_status = false; |
|
246 | - |
|
247 | - if ( in_array( 'publish', $keyphrases ) ) { |
|
248 | - $post_status = 'publish'; |
|
249 | - } |
|
250 | - if ( in_array( 'pending', $keyphrases ) ) { |
|
251 | - $post_status = 'pending'; |
|
252 | - } |
|
253 | - if ( in_array( 'draft', $keyphrases ) ) { |
|
254 | - $post_status = 'draft'; |
|
255 | - } |
|
256 | - if ( in_array( 'import', $keyphrases ) ) { |
|
257 | - $post_status = 'import'; |
|
258 | - } |
|
259 | - |
|
260 | - // If there is a post status use it. |
|
261 | - if ( false !== $post_status ) { |
|
262 | - |
|
263 | - $accommodation = array(); |
|
264 | - $current_accommodation = $this->find_current_accommodation(); |
|
265 | - if ( ! empty( $current_accommodation ) ) { |
|
266 | - foreach ( $current_accommodation as $cs_key => $ccs_id ) { |
|
267 | - $accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id ); |
|
268 | - } |
|
269 | - } |
|
270 | - |
|
271 | - // Run through each accommodation and use it. |
|
272 | - if ( ! empty( $accommodation ) ) { |
|
273 | - foreach ( $accommodation as $row_key => $row ) { |
|
274 | - $row['post_title'] = $row['name']; |
|
275 | - if ( 'import' === $post_status ) { |
|
276 | - if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) { |
|
277 | - $current_status = get_post_status( $row['post_id'] ); |
|
278 | - if ( 'draft' === $current_status ) { |
|
279 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row ); |
|
280 | - } |
|
281 | - } else { |
|
282 | - continue; |
|
283 | - } |
|
284 | - } else { |
|
285 | - if ( 0 === $row['post_id'] ) { |
|
286 | - continue; |
|
287 | - } else { |
|
288 | - $current_status = get_post_status( $row['post_id'] ); |
|
289 | - if ( $current_status !== $post_status ) { |
|
290 | - continue; |
|
291 | - } |
|
292 | - } |
|
293 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key ); |
|
294 | - } |
|
295 | - } |
|
296 | - } |
|
297 | - } else { |
|
298 | - $key_string_search = implode( '+', $keyphrases ); |
|
299 | - $search_data = wp_remote_get( $this->url . '/Search/' . $key_string_search ); |
|
300 | - if ( ! empty( $search_data ) && isset( $search_data['response'] ) && isset( $search_data['response']['code'] ) && 200 === $search_data['response']['code'] ) { |
|
301 | - |
|
302 | - $search_data = json_decode( $search_data['body'], true ); |
|
303 | - foreach ( $search_data as $sdata_key => $sdata ) { |
|
304 | - |
|
305 | - if ( 'Destination' === trim( $sdata['type'] ) || 'Activity' === trim( $sdata['type'] ) || 'Restaurant' === trim( $sdata['type'] ) || 'None' === trim( $sdata['type'] ) || 'Site / Attraction' === trim( $sdata['type'] ) || '' === trim( $sdata['type'] ) ) { |
|
306 | - continue; |
|
307 | - } |
|
308 | - |
|
309 | - $temp_id = $this->get_post_id_by_key_value( $sdata['id'] ); |
|
310 | - if ( false === $temp_id ) { |
|
311 | - $sdata['post_id'] = 0; |
|
312 | - $sdata['post_title'] = $sdata['name']; |
|
313 | - } else { |
|
314 | - $sdata['post_id'] = $temp_id; |
|
315 | - $sdata['post_title'] = get_the_title( $temp_id ); |
|
316 | - } |
|
317 | - $searched_items[ sanitize_title( $sdata['name'] ) . '-' . $sdata['id'] ] = $this->format_row( $sdata, $sdata_key ); |
|
318 | - } |
|
319 | - } |
|
320 | - } |
|
321 | - |
|
322 | - if ( false !== $searched_items ) { |
|
323 | - $return = implode( $searched_items ); |
|
324 | - } |
|
325 | - print_r( $return ); |
|
326 | - } |
|
327 | - |
|
328 | - die(); |
|
329 | - } |
|
330 | - |
|
331 | - public function prepare_row_attributes( $cs_key, $ccs_id ) { |
|
332 | - $row_item = array( |
|
333 | - 'id' => $cs_key, |
|
334 | - 'type' => 'Accommodation', |
|
335 | - 'name' => get_the_title( $ccs_id ), |
|
336 | - 'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ), |
|
337 | - 'post_id' => $ccs_id, |
|
338 | - ); |
|
339 | - return $row_item; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Formats the row for output on the screen. |
|
344 | - * |
|
345 | - * @param boolean $row the current row to format. |
|
346 | - * @return void |
|
347 | - */ |
|
348 | - public function format_row( $row = false, $row_key = '' ) { |
|
349 | - if ( false !== $row ) { |
|
350 | - |
|
351 | - $status = 'import'; |
|
352 | - if ( 0 !== $row['post_id'] ) { |
|
353 | - $status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>'; |
|
354 | - } |
|
355 | - |
|
356 | - $row_html = ' |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Run through the accommodation grabbed from the DB. |
|
225 | + */ |
|
226 | + public function process_ajax_search() { |
|
227 | + $return = false; |
|
228 | + check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
229 | + if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && 'accommodation' === $_POST['type'] ) { |
|
230 | + |
|
231 | + $searched_items = false; |
|
232 | + if ( isset( $_POST['keyword'] ) ) { |
|
233 | + $keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) ); |
|
234 | + } else { |
|
235 | + $keyphrases = array( 0 ); |
|
236 | + } |
|
237 | + |
|
238 | + if ( ! is_array( $keyphrases ) ) { |
|
239 | + $keyphrases = array( $keyphrases ); |
|
240 | + } |
|
241 | + foreach ( $keyphrases as &$keyword ) { |
|
242 | + $keyword = ltrim( rtrim( $keyword ) ); |
|
243 | + } |
|
244 | + |
|
245 | + $post_status = false; |
|
246 | + |
|
247 | + if ( in_array( 'publish', $keyphrases ) ) { |
|
248 | + $post_status = 'publish'; |
|
249 | + } |
|
250 | + if ( in_array( 'pending', $keyphrases ) ) { |
|
251 | + $post_status = 'pending'; |
|
252 | + } |
|
253 | + if ( in_array( 'draft', $keyphrases ) ) { |
|
254 | + $post_status = 'draft'; |
|
255 | + } |
|
256 | + if ( in_array( 'import', $keyphrases ) ) { |
|
257 | + $post_status = 'import'; |
|
258 | + } |
|
259 | + |
|
260 | + // If there is a post status use it. |
|
261 | + if ( false !== $post_status ) { |
|
262 | + |
|
263 | + $accommodation = array(); |
|
264 | + $current_accommodation = $this->find_current_accommodation(); |
|
265 | + if ( ! empty( $current_accommodation ) ) { |
|
266 | + foreach ( $current_accommodation as $cs_key => $ccs_id ) { |
|
267 | + $accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id ); |
|
268 | + } |
|
269 | + } |
|
270 | + |
|
271 | + // Run through each accommodation and use it. |
|
272 | + if ( ! empty( $accommodation ) ) { |
|
273 | + foreach ( $accommodation as $row_key => $row ) { |
|
274 | + $row['post_title'] = $row['name']; |
|
275 | + if ( 'import' === $post_status ) { |
|
276 | + if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) { |
|
277 | + $current_status = get_post_status( $row['post_id'] ); |
|
278 | + if ( 'draft' === $current_status ) { |
|
279 | + $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row ); |
|
280 | + } |
|
281 | + } else { |
|
282 | + continue; |
|
283 | + } |
|
284 | + } else { |
|
285 | + if ( 0 === $row['post_id'] ) { |
|
286 | + continue; |
|
287 | + } else { |
|
288 | + $current_status = get_post_status( $row['post_id'] ); |
|
289 | + if ( $current_status !== $post_status ) { |
|
290 | + continue; |
|
291 | + } |
|
292 | + } |
|
293 | + $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key ); |
|
294 | + } |
|
295 | + } |
|
296 | + } |
|
297 | + } else { |
|
298 | + $key_string_search = implode( '+', $keyphrases ); |
|
299 | + $search_data = wp_remote_get( $this->url . '/Search/' . $key_string_search ); |
|
300 | + if ( ! empty( $search_data ) && isset( $search_data['response'] ) && isset( $search_data['response']['code'] ) && 200 === $search_data['response']['code'] ) { |
|
301 | + |
|
302 | + $search_data = json_decode( $search_data['body'], true ); |
|
303 | + foreach ( $search_data as $sdata_key => $sdata ) { |
|
304 | + |
|
305 | + if ( 'Destination' === trim( $sdata['type'] ) || 'Activity' === trim( $sdata['type'] ) || 'Restaurant' === trim( $sdata['type'] ) || 'None' === trim( $sdata['type'] ) || 'Site / Attraction' === trim( $sdata['type'] ) || '' === trim( $sdata['type'] ) ) { |
|
306 | + continue; |
|
307 | + } |
|
308 | + |
|
309 | + $temp_id = $this->get_post_id_by_key_value( $sdata['id'] ); |
|
310 | + if ( false === $temp_id ) { |
|
311 | + $sdata['post_id'] = 0; |
|
312 | + $sdata['post_title'] = $sdata['name']; |
|
313 | + } else { |
|
314 | + $sdata['post_id'] = $temp_id; |
|
315 | + $sdata['post_title'] = get_the_title( $temp_id ); |
|
316 | + } |
|
317 | + $searched_items[ sanitize_title( $sdata['name'] ) . '-' . $sdata['id'] ] = $this->format_row( $sdata, $sdata_key ); |
|
318 | + } |
|
319 | + } |
|
320 | + } |
|
321 | + |
|
322 | + if ( false !== $searched_items ) { |
|
323 | + $return = implode( $searched_items ); |
|
324 | + } |
|
325 | + print_r( $return ); |
|
326 | + } |
|
327 | + |
|
328 | + die(); |
|
329 | + } |
|
330 | + |
|
331 | + public function prepare_row_attributes( $cs_key, $ccs_id ) { |
|
332 | + $row_item = array( |
|
333 | + 'id' => $cs_key, |
|
334 | + 'type' => 'Accommodation', |
|
335 | + 'name' => get_the_title( $ccs_id ), |
|
336 | + 'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ), |
|
337 | + 'post_id' => $ccs_id, |
|
338 | + ); |
|
339 | + return $row_item; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Formats the row for output on the screen. |
|
344 | + * |
|
345 | + * @param boolean $row the current row to format. |
|
346 | + * @return void |
|
347 | + */ |
|
348 | + public function format_row( $row = false, $row_key = '' ) { |
|
349 | + if ( false !== $row ) { |
|
350 | + |
|
351 | + $status = 'import'; |
|
352 | + if ( 0 !== $row['post_id'] ) { |
|
353 | + $status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>'; |
|
354 | + } |
|
355 | + |
|
356 | + $row_html = ' |
|
357 | 357 | <tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '"> |
358 | 358 | <th class="check-column" scope="row"> |
359 | 359 | <label for="cb-select-' . $row['id'] . '" class="screen-reader-text">' . $row['name'] . '</label> |
@@ -372,457 +372,457 @@ discard block |
||
372 | 372 | ' . $row['id'] . ' |
373 | 373 | </td> |
374 | 374 | </tr>'; |
375 | - return $row_html; |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * Saves the queue to the option. |
|
381 | - */ |
|
382 | - public function remove_from_queue( $id ) { |
|
383 | - if ( ! empty( $this->queued_imports ) ) { |
|
384 | - $key = array_search( $id, $this->queued_imports ); |
|
385 | - if ( false !== $key ) { |
|
386 | - unset( $this->queued_imports[ $key ] ); |
|
387 | - |
|
388 | - delete_option( 'lsx_wetu_importer_que' ); |
|
389 | - update_option( 'lsx_wetu_importer_que', $this->queued_imports ); |
|
390 | - } |
|
391 | - } |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Connect to wetu |
|
396 | - */ |
|
397 | - public function process_ajax_import() { |
|
398 | - $return = false; |
|
399 | - check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
400 | - |
|
401 | - if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && 'accommodation' === $_POST['type'] && isset( $_POST['wetu_id'] ) ) { |
|
402 | - |
|
403 | - $wetu_id = sanitize_text_field( $_POST['wetu_id'] ); |
|
404 | - if ( isset( $_POST['post_id'] ) ) { |
|
405 | - $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
406 | - } else { |
|
407 | - $post_id = 0; |
|
408 | - } |
|
409 | - |
|
410 | - if ( isset( $_POST['team_members'] ) ) { |
|
411 | - $team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) ); |
|
412 | - } else { |
|
413 | - $team_members = false; |
|
414 | - } |
|
415 | - |
|
416 | - if ( isset( $_POST['safari_brands'] ) ) { |
|
417 | - $safari_brands = array_map( 'sanitize_text_field', wp_unslash( $_POST['safari_brands'] ) ); |
|
418 | - } else { |
|
419 | - $safari_brands = false; |
|
420 | - } |
|
421 | - delete_option( 'lsx_wetu_importer_accommodation_settings' ); |
|
422 | - |
|
423 | - if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) { |
|
424 | - $content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) ); |
|
425 | - add_option( 'lsx_wetu_importer_accommodation_settings', $content ); |
|
426 | - } else { |
|
427 | - $content = false; |
|
428 | - } |
|
429 | - |
|
430 | - $jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
431 | - |
|
432 | - if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) { |
|
433 | - $adata = json_decode( $jdata['body'], true ); |
|
434 | - $return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands ); |
|
435 | - $this->format_completed_row( $return ); |
|
436 | - $this->remove_from_queue( $return ); |
|
437 | - $this->cleanup_posts(); |
|
438 | - } else { |
|
439 | - $this->format_error( esc_html__( 'There was a problem importing your accommodation, please try refreshing the page.', 'lsx-wetu-importer' ) ); |
|
440 | - } |
|
441 | - } |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * Connect to wetu |
|
446 | - */ |
|
447 | - public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false ) { |
|
448 | - $post_name = ''; |
|
449 | - $data_post_content = ''; |
|
450 | - $data_post_excerpt = ''; |
|
451 | - |
|
452 | - $post = array( |
|
453 | - 'post_type' => 'accommodation', |
|
454 | - ); |
|
455 | - $content_used_general_description = false; |
|
456 | - |
|
457 | - // Set the post_content. |
|
458 | - if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) { |
|
459 | - if ( isset( $data[0]['content']['extended_description'] ) ) { |
|
460 | - $data_post_content = $data[0]['content']['extended_description']; |
|
461 | - } elseif ( isset( $data[0]['content']['general_description'] ) ) { |
|
462 | - $data_post_content = $data[0]['content']['general_description']; |
|
463 | - $content_used_general_description = true; |
|
464 | - } elseif ( isset( $data[0]['content']['teaser_description'] ) ) { |
|
465 | - $data_post_content = $data[0]['content']['teaser_description']; |
|
466 | - } |
|
467 | - |
|
468 | - if ( isset( $this->options['disable_accommodation_filtering'] ) && 'on' === $this->options['disable_accommodation_filtering'] ) { |
|
469 | - $post['post_content'] = $data_post_content; |
|
470 | - } else { |
|
471 | - $post['post_content'] = wp_strip_all_tags( $data_post_content ); |
|
472 | - } |
|
473 | - } |
|
474 | - |
|
475 | - // set the post_excerpt. |
|
476 | - if ( ! empty( $importable_content ) && in_array( 'excerpt', $importable_content ) ) { |
|
477 | - if ( isset( $data[0]['content']['teaser_description'] ) ) { |
|
478 | - $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
479 | - } elseif ( isset( $data[0]['content']['general_description'] ) && false === $content_used_general_description ) { |
|
480 | - $data_post_excerpt = $data[0]['content']['general_description']; |
|
481 | - } |
|
482 | - |
|
483 | - $post['post_excerpt'] = $data_post_excerpt; |
|
484 | - } |
|
485 | - |
|
486 | - if ( false !== $id && '0' !== $id ) { |
|
487 | - $post['ID'] = $id; |
|
488 | - |
|
489 | - if ( isset( $this->options ) && 'on' !== $this->options['disable_accommodation_title'] && isset( $data[0]['name'] ) ) { |
|
490 | - $post['post_title'] = $data[0]['name']; |
|
491 | - $post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'accommodation', 0 ); |
|
492 | - } |
|
493 | - |
|
494 | - $post['post_status'] = 'publish'; |
|
495 | - |
|
496 | - $id = wp_update_post( $post ); |
|
497 | - $prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true ); |
|
498 | - update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date ); |
|
499 | - } else { |
|
500 | - // Set the name. |
|
501 | - if ( isset( $data[0]['name'] ) ) { |
|
502 | - $post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'accommodation', 0 ); |
|
503 | - } |
|
504 | - |
|
505 | - $post['post_name'] = $post_name; |
|
506 | - $post['post_title'] = $data[0]['name']; |
|
507 | - $post['post_status'] = 'publish'; |
|
508 | - $id = wp_insert_post( $post ); |
|
509 | - |
|
510 | - // Save the WETU ID and the Last date it was modified. |
|
511 | - if ( false !== $id ) { |
|
512 | - add_post_meta( $id, 'lsx_wetu_id', $wetu_id ); |
|
513 | - add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) ); |
|
514 | - } |
|
515 | - } |
|
516 | - |
|
517 | - // Setup some default for use in the import. |
|
518 | - if ( false !== $importable_content && ( in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content ) ) ) { |
|
519 | - $this->find_attachments( $id ); |
|
520 | - } |
|
521 | - |
|
522 | - // Set the team member if it is there. |
|
523 | - if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) { |
|
524 | - $this->set_team_member( $id, $team_members ); |
|
525 | - } |
|
526 | - |
|
527 | - // Set the safari brand. |
|
528 | - if ( false !== $safari_brands && '' !== $safari_brands ) { |
|
529 | - $this->set_safari_brands( $id, $safari_brands ); |
|
530 | - } |
|
531 | - |
|
532 | - $this->set_map_data( $data, $id, 9 ); |
|
533 | - |
|
534 | - if ( post_type_exists( 'destination' ) && false !== $importable_content && in_array( 'destination', $importable_content ) ) { |
|
535 | - $this->connect_destinations( $data, $id ); |
|
536 | - } |
|
537 | - |
|
538 | - if ( false !== $importable_content && in_array( 'category', $importable_content ) ) { |
|
539 | - $this->set_taxonomy_style( $data, $id ); |
|
540 | - } |
|
541 | - |
|
542 | - // Set the Room Data. |
|
543 | - if ( false !== $importable_content && in_array( 'rooms', $importable_content ) ) { |
|
544 | - $this->set_room_data( $data, $id ); |
|
545 | - } |
|
546 | - |
|
547 | - // Set the rating. |
|
548 | - if ( false !== $importable_content && in_array( 'rating', $importable_content ) ) { |
|
549 | - $this->set_rating( $data, $id ); |
|
550 | - } |
|
551 | - |
|
552 | - // Set the checkin checkout data. |
|
553 | - if ( false !== $importable_content && in_array( 'checkin', $importable_content ) ) { |
|
554 | - $this->set_checkin_checkout( $data, $id ); |
|
555 | - } |
|
556 | - |
|
557 | - // Set the Spoken Languages. |
|
558 | - if ( false !== $importable_content && in_array( 'spoken_languages', $importable_content ) ) { |
|
559 | - $this->set_spoken_languages( $data, $id ); |
|
560 | - } |
|
561 | - |
|
562 | - // Set the friendly options. |
|
563 | - if ( false !== $importable_content && in_array( 'friendly', $importable_content ) ) { |
|
564 | - $this->set_friendly( $data, $id ); |
|
565 | - } |
|
566 | - |
|
567 | - // Set the special_interests. |
|
568 | - if ( false !== $importable_content && in_array( 'special_interests', $importable_content ) ) { |
|
569 | - $this->set_special_interests( $data, $id ); |
|
570 | - } |
|
571 | - |
|
572 | - // Import the videos. |
|
573 | - if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) { |
|
574 | - $this->set_video_data( $data, $id ); |
|
575 | - } |
|
576 | - |
|
577 | - // Import the facilities. |
|
578 | - if ( false !== $importable_content && in_array( 'facilities', $importable_content ) ) { |
|
579 | - $this->set_facilities( $data, $id ); |
|
580 | - } |
|
581 | - |
|
582 | - // Set the featured image. |
|
583 | - if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) { |
|
584 | - $this->set_featured_image( $data, $id ); |
|
585 | - } |
|
586 | - |
|
587 | - if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) { |
|
588 | - $this->set_banner_image( $data, $id ); |
|
589 | - } |
|
590 | - |
|
591 | - // Import the main gallery. |
|
592 | - if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) { |
|
593 | - $this->create_main_gallery( $data, $id ); |
|
594 | - } |
|
595 | - |
|
596 | - return $id; |
|
597 | - } |
|
598 | - |
|
599 | - /** |
|
600 | - * Set the safari brand |
|
601 | - */ |
|
602 | - public function set_safari_brands( $id, $safari_brands ) { |
|
603 | - foreach ( $safari_brands as $safari_brand ) { |
|
604 | - wp_set_object_terms( $id, intval( $safari_brand ), 'accommodation-brand', true ); |
|
605 | - } |
|
606 | - } |
|
607 | - |
|
608 | - /** |
|
609 | - * Connects the destinations post type |
|
610 | - */ |
|
611 | - public function connect_destinations( $data, $id ) { |
|
612 | - if ( isset( $data[0]['position'] ) ) { |
|
613 | - $destinations = false; |
|
614 | - |
|
615 | - if ( isset( $data[0]['position']['country'] ) ) { |
|
616 | - $destinations['country'] = $data[0]['position']['country']; |
|
617 | - } |
|
618 | - |
|
619 | - if ( isset( $data[0]['position']['destination'] ) ) { |
|
620 | - $destinations['destination'] = $data[0]['position']['destination']; |
|
621 | - } |
|
622 | - |
|
623 | - if ( false !== $destinations ) { |
|
624 | - $prev_values = get_post_meta( $id, 'destination_to_accommodation', false ); |
|
625 | - |
|
626 | - if ( false === $prev_values || ! is_array( $prev_values ) ) { |
|
627 | - $prev_values = array(); |
|
628 | - } |
|
629 | - |
|
630 | - delete_post_meta( $id, 'destination_to_accommodation', $prev_values ); |
|
631 | - $destinations = array_unique( $destinations ); |
|
632 | - |
|
633 | - foreach ( $destinations as $key => $value ) { |
|
634 | - $destination = get_page_by_title( ltrim( rtrim( $value ) ), 'OBJECT', 'destination' ); |
|
635 | - if ( null !== $destination ) { |
|
636 | - if ( ! in_array( $destination->ID, $prev_values ) ) { |
|
637 | - add_post_meta( $id, 'destination_to_accommodation', $destination->ID, false ); |
|
638 | - add_post_meta( $destination->ID, 'accommodation_to_destination', $id, false ); |
|
639 | - $this->cleanup_posts[ $destination->ID ] = 'accommodation_to_destination'; |
|
640 | - } |
|
641 | - } |
|
642 | - } |
|
643 | - } |
|
644 | - } |
|
645 | - } |
|
646 | - |
|
647 | - /** |
|
648 | - * Set the Travel Style |
|
649 | - */ |
|
650 | - public function set_taxonomy_style( $data, $id ) { |
|
651 | - $terms = false; |
|
652 | - |
|
653 | - if ( isset( $data[0]['category'] ) ) { |
|
654 | - $term = term_exists( trim( $data[0]['category'] ), 'accommodation-type' ); |
|
655 | - if ( ! $term ) { |
|
656 | - $term = wp_insert_term( trim( $data[0]['category'] ), 'accommodation-type' ); |
|
657 | - |
|
658 | - if ( is_wp_error( $term ) ) { |
|
659 | - echo wp_kses_post( $term->get_error_message() ); |
|
660 | - } |
|
661 | - } else { |
|
662 | - wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type', true ); |
|
663 | - } |
|
664 | - } else { |
|
665 | - wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type', true ); |
|
666 | - } |
|
667 | - } |
|
668 | - |
|
669 | - /** |
|
670 | - * Saves the room data |
|
671 | - */ |
|
672 | - public function set_room_data( $data, $id ) { |
|
673 | - if ( ! empty( $data[0]['rooms'] ) && is_array( $data[0]['rooms'] ) ) { |
|
674 | - $rooms = false; |
|
675 | - |
|
676 | - foreach ( $data[0]['rooms'] as $room ) { |
|
677 | - $temp_room = array(); |
|
678 | - |
|
679 | - if ( isset( $room['name'] ) ) { |
|
680 | - $temp_room['title'] = $room['name']; |
|
681 | - } |
|
682 | - |
|
683 | - if ( isset( $room['description'] ) ) { |
|
684 | - $temp_room['description'] = strip_tags( $room['description'] ); |
|
685 | - } |
|
686 | - |
|
687 | - $temp_room['price'] = 0; |
|
688 | - $temp_room['type'] = 'room'; |
|
689 | - |
|
690 | - if ( ! empty( $room['images'] ) && is_array( $room['images'] ) ) { |
|
691 | - $temp_room['gallery'] = array(); |
|
692 | - $temp_room['gallery'][] = $this->attach_image( $room['images'][0], $id ); |
|
693 | - } |
|
694 | - $rooms[] = $temp_room; |
|
695 | - } |
|
696 | - |
|
697 | - if ( false !== $id && '0' !== $id ) { |
|
698 | - delete_post_meta( $id, 'units' ); |
|
699 | - } |
|
700 | - |
|
701 | - foreach ( $rooms as $room ) { |
|
702 | - add_post_meta( $id, 'units', $room, false ); |
|
703 | - } |
|
704 | - |
|
705 | - if ( isset( $data[0]['features'] ) && isset( $data[0]['features']['rooms'] ) ) { |
|
706 | - $room_count = $data[0]['features']['rooms']; |
|
707 | - } else { |
|
708 | - $room_count = count( $data[0]['rooms'] ); |
|
709 | - } |
|
710 | - |
|
711 | - if ( false !== $id && '0' !== $id ) { |
|
712 | - $prev_rooms = get_post_meta( $id, 'number_of_rooms', true ); |
|
713 | - update_post_meta( $id, 'number_of_rooms', $room_count, $prev_rooms ); |
|
714 | - } else { |
|
715 | - add_post_meta( $id, 'number_of_rooms', $room_count, true ); |
|
716 | - } |
|
717 | - } |
|
718 | - } |
|
719 | - |
|
720 | - /** |
|
721 | - * Set the ratings |
|
722 | - */ |
|
723 | - public function set_rating( $data, $id ) { |
|
724 | - if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['star_authority'] ) ) { |
|
725 | - $rating_type = $data[0]['features']['star_authority']; |
|
726 | - } else { |
|
727 | - $rating_type = 'Unspecified2'; |
|
728 | - } |
|
729 | - |
|
730 | - $this->save_custom_field( $rating_type, 'rating_type', $id ); |
|
731 | - |
|
732 | - if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['stars'] ) ) { |
|
733 | - $this->save_custom_field( $data[0]['features']['stars'], 'rating', $id, true ); |
|
734 | - } |
|
735 | - } |
|
736 | - |
|
737 | - /** |
|
738 | - * Set the spoken_languages |
|
739 | - */ |
|
740 | - public function set_spoken_languages( $data, $id ) { |
|
741 | - if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['spoken_languages'] ) && ! empty( $data[0]['features']['spoken_languages'] ) ) { |
|
742 | - $languages = false; |
|
743 | - |
|
744 | - foreach ( $data[0]['features']['spoken_languages'] as $spoken_language ) { |
|
745 | - $languages[] = sanitize_title( $spoken_language ); |
|
746 | - } |
|
747 | - |
|
748 | - if ( false !== $languages ) { |
|
749 | - $this->save_custom_field( $languages, 'spoken_languages', $id ); |
|
750 | - } |
|
751 | - } |
|
752 | - } |
|
753 | - |
|
754 | - /** |
|
755 | - * Set the friendly |
|
756 | - */ |
|
757 | - public function set_friendly( $data, $id ) { |
|
758 | - if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['suggested_visitor_types'] ) && ! empty( $data[0]['features']['suggested_visitor_types'] ) ) { |
|
759 | - $friendly_options = false; |
|
760 | - |
|
761 | - foreach ( $data[0]['features']['suggested_visitor_types'] as $visitor_type ) { |
|
762 | - $friendly_options[] = sanitize_title( $visitor_type ); |
|
763 | - } |
|
764 | - |
|
765 | - if ( false !== $friendly_options ) { |
|
766 | - $this->save_custom_field( $friendly_options, 'suggested_visitor_types', $id ); |
|
767 | - } |
|
768 | - } |
|
769 | - } |
|
770 | - |
|
771 | - /** |
|
772 | - * Set the special interests |
|
773 | - */ |
|
774 | - public function set_special_interests( $data, $id ) { |
|
775 | - if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['special_interests'] ) && ! empty( $data[0]['features']['special_interests'] ) ) { |
|
776 | - $interests = false; |
|
777 | - |
|
778 | - foreach ( $data[0]['features']['special_interests'] as $special_interest ) { |
|
779 | - $interests[] = sanitize_title( $special_interest ); |
|
780 | - } |
|
781 | - |
|
782 | - if ( false !== $interests ) { |
|
783 | - $this->save_custom_field( $interests, 'special_interests', $id ); |
|
784 | - } |
|
785 | - } |
|
786 | - } |
|
787 | - |
|
788 | - /** |
|
789 | - * Set the Check in and Check out Date |
|
790 | - */ |
|
791 | - public function set_checkin_checkout( $data, $id ) { |
|
792 | - if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_in_time'] ) ) { |
|
793 | - $time = str_replace( 'h', ':', $data[0]['features']['check_in_time'] ); |
|
794 | - $time = date( 'h:ia', strtotime( $time ) ); |
|
795 | - $this->save_custom_field( $time, 'checkin_time', $id ); |
|
796 | - } |
|
797 | - |
|
798 | - if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_out_time'] ) ) { |
|
799 | - $time = str_replace( 'h', ':', $data[0]['features']['check_out_time'] ); |
|
800 | - $time = date( 'h:ia', strtotime( $time ) ); |
|
801 | - $this->save_custom_field( $time, 'checkout_time', $id ); |
|
802 | - } |
|
803 | - } |
|
804 | - |
|
805 | - /** |
|
806 | - * Set the Facilities |
|
807 | - */ |
|
808 | - public function set_facilities( $data, $id ) { |
|
809 | - $parent_facilities = array( |
|
810 | - 'available_services' => 'Available Services', |
|
811 | - 'property_facilities' => 'Property Facilities', |
|
812 | - 'room_facilities' => 'Room Facilities', |
|
813 | - 'activities_on_site' => 'Activities on Site', |
|
814 | - ); |
|
815 | - |
|
816 | - foreach ( $parent_facilities as $key => $label ) { |
|
817 | - $terms = false; |
|
818 | - |
|
819 | - if ( isset( $data[0]['features'] ) && isset( $data[0]['features'][ $key ] ) ) { |
|
820 | - $parent_id = $this->set_term( $id, $label, 'facility' ); |
|
821 | - } |
|
822 | - |
|
823 | - foreach ( $data[0]['features'][ $key ] as $child_facility ) { |
|
824 | - $this->set_term( $id, $child_facility, 'facility', $parent_id ); |
|
825 | - } |
|
826 | - } |
|
827 | - } |
|
375 | + return $row_html; |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Saves the queue to the option. |
|
381 | + */ |
|
382 | + public function remove_from_queue( $id ) { |
|
383 | + if ( ! empty( $this->queued_imports ) ) { |
|
384 | + $key = array_search( $id, $this->queued_imports ); |
|
385 | + if ( false !== $key ) { |
|
386 | + unset( $this->queued_imports[ $key ] ); |
|
387 | + |
|
388 | + delete_option( 'lsx_wetu_importer_que' ); |
|
389 | + update_option( 'lsx_wetu_importer_que', $this->queued_imports ); |
|
390 | + } |
|
391 | + } |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * Connect to wetu |
|
396 | + */ |
|
397 | + public function process_ajax_import() { |
|
398 | + $return = false; |
|
399 | + check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
400 | + |
|
401 | + if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && 'accommodation' === $_POST['type'] && isset( $_POST['wetu_id'] ) ) { |
|
402 | + |
|
403 | + $wetu_id = sanitize_text_field( $_POST['wetu_id'] ); |
|
404 | + if ( isset( $_POST['post_id'] ) ) { |
|
405 | + $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
406 | + } else { |
|
407 | + $post_id = 0; |
|
408 | + } |
|
409 | + |
|
410 | + if ( isset( $_POST['team_members'] ) ) { |
|
411 | + $team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) ); |
|
412 | + } else { |
|
413 | + $team_members = false; |
|
414 | + } |
|
415 | + |
|
416 | + if ( isset( $_POST['safari_brands'] ) ) { |
|
417 | + $safari_brands = array_map( 'sanitize_text_field', wp_unslash( $_POST['safari_brands'] ) ); |
|
418 | + } else { |
|
419 | + $safari_brands = false; |
|
420 | + } |
|
421 | + delete_option( 'lsx_wetu_importer_accommodation_settings' ); |
|
422 | + |
|
423 | + if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) { |
|
424 | + $content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) ); |
|
425 | + add_option( 'lsx_wetu_importer_accommodation_settings', $content ); |
|
426 | + } else { |
|
427 | + $content = false; |
|
428 | + } |
|
429 | + |
|
430 | + $jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
431 | + |
|
432 | + if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) { |
|
433 | + $adata = json_decode( $jdata['body'], true ); |
|
434 | + $return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands ); |
|
435 | + $this->format_completed_row( $return ); |
|
436 | + $this->remove_from_queue( $return ); |
|
437 | + $this->cleanup_posts(); |
|
438 | + } else { |
|
439 | + $this->format_error( esc_html__( 'There was a problem importing your accommodation, please try refreshing the page.', 'lsx-wetu-importer' ) ); |
|
440 | + } |
|
441 | + } |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * Connect to wetu |
|
446 | + */ |
|
447 | + public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false ) { |
|
448 | + $post_name = ''; |
|
449 | + $data_post_content = ''; |
|
450 | + $data_post_excerpt = ''; |
|
451 | + |
|
452 | + $post = array( |
|
453 | + 'post_type' => 'accommodation', |
|
454 | + ); |
|
455 | + $content_used_general_description = false; |
|
456 | + |
|
457 | + // Set the post_content. |
|
458 | + if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) { |
|
459 | + if ( isset( $data[0]['content']['extended_description'] ) ) { |
|
460 | + $data_post_content = $data[0]['content']['extended_description']; |
|
461 | + } elseif ( isset( $data[0]['content']['general_description'] ) ) { |
|
462 | + $data_post_content = $data[0]['content']['general_description']; |
|
463 | + $content_used_general_description = true; |
|
464 | + } elseif ( isset( $data[0]['content']['teaser_description'] ) ) { |
|
465 | + $data_post_content = $data[0]['content']['teaser_description']; |
|
466 | + } |
|
467 | + |
|
468 | + if ( isset( $this->options['disable_accommodation_filtering'] ) && 'on' === $this->options['disable_accommodation_filtering'] ) { |
|
469 | + $post['post_content'] = $data_post_content; |
|
470 | + } else { |
|
471 | + $post['post_content'] = wp_strip_all_tags( $data_post_content ); |
|
472 | + } |
|
473 | + } |
|
474 | + |
|
475 | + // set the post_excerpt. |
|
476 | + if ( ! empty( $importable_content ) && in_array( 'excerpt', $importable_content ) ) { |
|
477 | + if ( isset( $data[0]['content']['teaser_description'] ) ) { |
|
478 | + $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
479 | + } elseif ( isset( $data[0]['content']['general_description'] ) && false === $content_used_general_description ) { |
|
480 | + $data_post_excerpt = $data[0]['content']['general_description']; |
|
481 | + } |
|
482 | + |
|
483 | + $post['post_excerpt'] = $data_post_excerpt; |
|
484 | + } |
|
485 | + |
|
486 | + if ( false !== $id && '0' !== $id ) { |
|
487 | + $post['ID'] = $id; |
|
488 | + |
|
489 | + if ( isset( $this->options ) && 'on' !== $this->options['disable_accommodation_title'] && isset( $data[0]['name'] ) ) { |
|
490 | + $post['post_title'] = $data[0]['name']; |
|
491 | + $post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'accommodation', 0 ); |
|
492 | + } |
|
493 | + |
|
494 | + $post['post_status'] = 'publish'; |
|
495 | + |
|
496 | + $id = wp_update_post( $post ); |
|
497 | + $prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true ); |
|
498 | + update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date ); |
|
499 | + } else { |
|
500 | + // Set the name. |
|
501 | + if ( isset( $data[0]['name'] ) ) { |
|
502 | + $post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'accommodation', 0 ); |
|
503 | + } |
|
504 | + |
|
505 | + $post['post_name'] = $post_name; |
|
506 | + $post['post_title'] = $data[0]['name']; |
|
507 | + $post['post_status'] = 'publish'; |
|
508 | + $id = wp_insert_post( $post ); |
|
509 | + |
|
510 | + // Save the WETU ID and the Last date it was modified. |
|
511 | + if ( false !== $id ) { |
|
512 | + add_post_meta( $id, 'lsx_wetu_id', $wetu_id ); |
|
513 | + add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) ); |
|
514 | + } |
|
515 | + } |
|
516 | + |
|
517 | + // Setup some default for use in the import. |
|
518 | + if ( false !== $importable_content && ( in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content ) ) ) { |
|
519 | + $this->find_attachments( $id ); |
|
520 | + } |
|
521 | + |
|
522 | + // Set the team member if it is there. |
|
523 | + if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) { |
|
524 | + $this->set_team_member( $id, $team_members ); |
|
525 | + } |
|
526 | + |
|
527 | + // Set the safari brand. |
|
528 | + if ( false !== $safari_brands && '' !== $safari_brands ) { |
|
529 | + $this->set_safari_brands( $id, $safari_brands ); |
|
530 | + } |
|
531 | + |
|
532 | + $this->set_map_data( $data, $id, 9 ); |
|
533 | + |
|
534 | + if ( post_type_exists( 'destination' ) && false !== $importable_content && in_array( 'destination', $importable_content ) ) { |
|
535 | + $this->connect_destinations( $data, $id ); |
|
536 | + } |
|
537 | + |
|
538 | + if ( false !== $importable_content && in_array( 'category', $importable_content ) ) { |
|
539 | + $this->set_taxonomy_style( $data, $id ); |
|
540 | + } |
|
541 | + |
|
542 | + // Set the Room Data. |
|
543 | + if ( false !== $importable_content && in_array( 'rooms', $importable_content ) ) { |
|
544 | + $this->set_room_data( $data, $id ); |
|
545 | + } |
|
546 | + |
|
547 | + // Set the rating. |
|
548 | + if ( false !== $importable_content && in_array( 'rating', $importable_content ) ) { |
|
549 | + $this->set_rating( $data, $id ); |
|
550 | + } |
|
551 | + |
|
552 | + // Set the checkin checkout data. |
|
553 | + if ( false !== $importable_content && in_array( 'checkin', $importable_content ) ) { |
|
554 | + $this->set_checkin_checkout( $data, $id ); |
|
555 | + } |
|
556 | + |
|
557 | + // Set the Spoken Languages. |
|
558 | + if ( false !== $importable_content && in_array( 'spoken_languages', $importable_content ) ) { |
|
559 | + $this->set_spoken_languages( $data, $id ); |
|
560 | + } |
|
561 | + |
|
562 | + // Set the friendly options. |
|
563 | + if ( false !== $importable_content && in_array( 'friendly', $importable_content ) ) { |
|
564 | + $this->set_friendly( $data, $id ); |
|
565 | + } |
|
566 | + |
|
567 | + // Set the special_interests. |
|
568 | + if ( false !== $importable_content && in_array( 'special_interests', $importable_content ) ) { |
|
569 | + $this->set_special_interests( $data, $id ); |
|
570 | + } |
|
571 | + |
|
572 | + // Import the videos. |
|
573 | + if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) { |
|
574 | + $this->set_video_data( $data, $id ); |
|
575 | + } |
|
576 | + |
|
577 | + // Import the facilities. |
|
578 | + if ( false !== $importable_content && in_array( 'facilities', $importable_content ) ) { |
|
579 | + $this->set_facilities( $data, $id ); |
|
580 | + } |
|
581 | + |
|
582 | + // Set the featured image. |
|
583 | + if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) { |
|
584 | + $this->set_featured_image( $data, $id ); |
|
585 | + } |
|
586 | + |
|
587 | + if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) { |
|
588 | + $this->set_banner_image( $data, $id ); |
|
589 | + } |
|
590 | + |
|
591 | + // Import the main gallery. |
|
592 | + if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) { |
|
593 | + $this->create_main_gallery( $data, $id ); |
|
594 | + } |
|
595 | + |
|
596 | + return $id; |
|
597 | + } |
|
598 | + |
|
599 | + /** |
|
600 | + * Set the safari brand |
|
601 | + */ |
|
602 | + public function set_safari_brands( $id, $safari_brands ) { |
|
603 | + foreach ( $safari_brands as $safari_brand ) { |
|
604 | + wp_set_object_terms( $id, intval( $safari_brand ), 'accommodation-brand', true ); |
|
605 | + } |
|
606 | + } |
|
607 | + |
|
608 | + /** |
|
609 | + * Connects the destinations post type |
|
610 | + */ |
|
611 | + public function connect_destinations( $data, $id ) { |
|
612 | + if ( isset( $data[0]['position'] ) ) { |
|
613 | + $destinations = false; |
|
614 | + |
|
615 | + if ( isset( $data[0]['position']['country'] ) ) { |
|
616 | + $destinations['country'] = $data[0]['position']['country']; |
|
617 | + } |
|
618 | + |
|
619 | + if ( isset( $data[0]['position']['destination'] ) ) { |
|
620 | + $destinations['destination'] = $data[0]['position']['destination']; |
|
621 | + } |
|
622 | + |
|
623 | + if ( false !== $destinations ) { |
|
624 | + $prev_values = get_post_meta( $id, 'destination_to_accommodation', false ); |
|
625 | + |
|
626 | + if ( false === $prev_values || ! is_array( $prev_values ) ) { |
|
627 | + $prev_values = array(); |
|
628 | + } |
|
629 | + |
|
630 | + delete_post_meta( $id, 'destination_to_accommodation', $prev_values ); |
|
631 | + $destinations = array_unique( $destinations ); |
|
632 | + |
|
633 | + foreach ( $destinations as $key => $value ) { |
|
634 | + $destination = get_page_by_title( ltrim( rtrim( $value ) ), 'OBJECT', 'destination' ); |
|
635 | + if ( null !== $destination ) { |
|
636 | + if ( ! in_array( $destination->ID, $prev_values ) ) { |
|
637 | + add_post_meta( $id, 'destination_to_accommodation', $destination->ID, false ); |
|
638 | + add_post_meta( $destination->ID, 'accommodation_to_destination', $id, false ); |
|
639 | + $this->cleanup_posts[ $destination->ID ] = 'accommodation_to_destination'; |
|
640 | + } |
|
641 | + } |
|
642 | + } |
|
643 | + } |
|
644 | + } |
|
645 | + } |
|
646 | + |
|
647 | + /** |
|
648 | + * Set the Travel Style |
|
649 | + */ |
|
650 | + public function set_taxonomy_style( $data, $id ) { |
|
651 | + $terms = false; |
|
652 | + |
|
653 | + if ( isset( $data[0]['category'] ) ) { |
|
654 | + $term = term_exists( trim( $data[0]['category'] ), 'accommodation-type' ); |
|
655 | + if ( ! $term ) { |
|
656 | + $term = wp_insert_term( trim( $data[0]['category'] ), 'accommodation-type' ); |
|
657 | + |
|
658 | + if ( is_wp_error( $term ) ) { |
|
659 | + echo wp_kses_post( $term->get_error_message() ); |
|
660 | + } |
|
661 | + } else { |
|
662 | + wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type', true ); |
|
663 | + } |
|
664 | + } else { |
|
665 | + wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type', true ); |
|
666 | + } |
|
667 | + } |
|
668 | + |
|
669 | + /** |
|
670 | + * Saves the room data |
|
671 | + */ |
|
672 | + public function set_room_data( $data, $id ) { |
|
673 | + if ( ! empty( $data[0]['rooms'] ) && is_array( $data[0]['rooms'] ) ) { |
|
674 | + $rooms = false; |
|
675 | + |
|
676 | + foreach ( $data[0]['rooms'] as $room ) { |
|
677 | + $temp_room = array(); |
|
678 | + |
|
679 | + if ( isset( $room['name'] ) ) { |
|
680 | + $temp_room['title'] = $room['name']; |
|
681 | + } |
|
682 | + |
|
683 | + if ( isset( $room['description'] ) ) { |
|
684 | + $temp_room['description'] = strip_tags( $room['description'] ); |
|
685 | + } |
|
686 | + |
|
687 | + $temp_room['price'] = 0; |
|
688 | + $temp_room['type'] = 'room'; |
|
689 | + |
|
690 | + if ( ! empty( $room['images'] ) && is_array( $room['images'] ) ) { |
|
691 | + $temp_room['gallery'] = array(); |
|
692 | + $temp_room['gallery'][] = $this->attach_image( $room['images'][0], $id ); |
|
693 | + } |
|
694 | + $rooms[] = $temp_room; |
|
695 | + } |
|
696 | + |
|
697 | + if ( false !== $id && '0' !== $id ) { |
|
698 | + delete_post_meta( $id, 'units' ); |
|
699 | + } |
|
700 | + |
|
701 | + foreach ( $rooms as $room ) { |
|
702 | + add_post_meta( $id, 'units', $room, false ); |
|
703 | + } |
|
704 | + |
|
705 | + if ( isset( $data[0]['features'] ) && isset( $data[0]['features']['rooms'] ) ) { |
|
706 | + $room_count = $data[0]['features']['rooms']; |
|
707 | + } else { |
|
708 | + $room_count = count( $data[0]['rooms'] ); |
|
709 | + } |
|
710 | + |
|
711 | + if ( false !== $id && '0' !== $id ) { |
|
712 | + $prev_rooms = get_post_meta( $id, 'number_of_rooms', true ); |
|
713 | + update_post_meta( $id, 'number_of_rooms', $room_count, $prev_rooms ); |
|
714 | + } else { |
|
715 | + add_post_meta( $id, 'number_of_rooms', $room_count, true ); |
|
716 | + } |
|
717 | + } |
|
718 | + } |
|
719 | + |
|
720 | + /** |
|
721 | + * Set the ratings |
|
722 | + */ |
|
723 | + public function set_rating( $data, $id ) { |
|
724 | + if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['star_authority'] ) ) { |
|
725 | + $rating_type = $data[0]['features']['star_authority']; |
|
726 | + } else { |
|
727 | + $rating_type = 'Unspecified2'; |
|
728 | + } |
|
729 | + |
|
730 | + $this->save_custom_field( $rating_type, 'rating_type', $id ); |
|
731 | + |
|
732 | + if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['stars'] ) ) { |
|
733 | + $this->save_custom_field( $data[0]['features']['stars'], 'rating', $id, true ); |
|
734 | + } |
|
735 | + } |
|
736 | + |
|
737 | + /** |
|
738 | + * Set the spoken_languages |
|
739 | + */ |
|
740 | + public function set_spoken_languages( $data, $id ) { |
|
741 | + if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['spoken_languages'] ) && ! empty( $data[0]['features']['spoken_languages'] ) ) { |
|
742 | + $languages = false; |
|
743 | + |
|
744 | + foreach ( $data[0]['features']['spoken_languages'] as $spoken_language ) { |
|
745 | + $languages[] = sanitize_title( $spoken_language ); |
|
746 | + } |
|
747 | + |
|
748 | + if ( false !== $languages ) { |
|
749 | + $this->save_custom_field( $languages, 'spoken_languages', $id ); |
|
750 | + } |
|
751 | + } |
|
752 | + } |
|
753 | + |
|
754 | + /** |
|
755 | + * Set the friendly |
|
756 | + */ |
|
757 | + public function set_friendly( $data, $id ) { |
|
758 | + if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['suggested_visitor_types'] ) && ! empty( $data[0]['features']['suggested_visitor_types'] ) ) { |
|
759 | + $friendly_options = false; |
|
760 | + |
|
761 | + foreach ( $data[0]['features']['suggested_visitor_types'] as $visitor_type ) { |
|
762 | + $friendly_options[] = sanitize_title( $visitor_type ); |
|
763 | + } |
|
764 | + |
|
765 | + if ( false !== $friendly_options ) { |
|
766 | + $this->save_custom_field( $friendly_options, 'suggested_visitor_types', $id ); |
|
767 | + } |
|
768 | + } |
|
769 | + } |
|
770 | + |
|
771 | + /** |
|
772 | + * Set the special interests |
|
773 | + */ |
|
774 | + public function set_special_interests( $data, $id ) { |
|
775 | + if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['special_interests'] ) && ! empty( $data[0]['features']['special_interests'] ) ) { |
|
776 | + $interests = false; |
|
777 | + |
|
778 | + foreach ( $data[0]['features']['special_interests'] as $special_interest ) { |
|
779 | + $interests[] = sanitize_title( $special_interest ); |
|
780 | + } |
|
781 | + |
|
782 | + if ( false !== $interests ) { |
|
783 | + $this->save_custom_field( $interests, 'special_interests', $id ); |
|
784 | + } |
|
785 | + } |
|
786 | + } |
|
787 | + |
|
788 | + /** |
|
789 | + * Set the Check in and Check out Date |
|
790 | + */ |
|
791 | + public function set_checkin_checkout( $data, $id ) { |
|
792 | + if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_in_time'] ) ) { |
|
793 | + $time = str_replace( 'h', ':', $data[0]['features']['check_in_time'] ); |
|
794 | + $time = date( 'h:ia', strtotime( $time ) ); |
|
795 | + $this->save_custom_field( $time, 'checkin_time', $id ); |
|
796 | + } |
|
797 | + |
|
798 | + if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_out_time'] ) ) { |
|
799 | + $time = str_replace( 'h', ':', $data[0]['features']['check_out_time'] ); |
|
800 | + $time = date( 'h:ia', strtotime( $time ) ); |
|
801 | + $this->save_custom_field( $time, 'checkout_time', $id ); |
|
802 | + } |
|
803 | + } |
|
804 | + |
|
805 | + /** |
|
806 | + * Set the Facilities |
|
807 | + */ |
|
808 | + public function set_facilities( $data, $id ) { |
|
809 | + $parent_facilities = array( |
|
810 | + 'available_services' => 'Available Services', |
|
811 | + 'property_facilities' => 'Property Facilities', |
|
812 | + 'room_facilities' => 'Room Facilities', |
|
813 | + 'activities_on_site' => 'Activities on Site', |
|
814 | + ); |
|
815 | + |
|
816 | + foreach ( $parent_facilities as $key => $label ) { |
|
817 | + $terms = false; |
|
818 | + |
|
819 | + if ( isset( $data[0]['features'] ) && isset( $data[0]['features'][ $key ] ) ) { |
|
820 | + $parent_id = $this->set_term( $id, $label, 'facility' ); |
|
821 | + } |
|
822 | + |
|
823 | + foreach ( $data[0]['features'][ $key ] as $child_facility ) { |
|
824 | + $this->set_term( $id, $child_facility, 'facility', $parent_id ); |
|
825 | + } |
|
826 | + } |
|
827 | + } |
|
828 | 828 | } |
@@ -9,51 +9,51 @@ discard block |
||
9 | 9 | |
10 | 10 | class LSX_WETU_Importer_Connect_Accommodation extends LSX_WETU_Importer_Admin { |
11 | 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 = 'connect_accommodation'; |
|
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 | - * Initialize the plugin by setting localization, filters, and administration functions. |
|
32 | - * |
|
33 | - * @since 1.0.0 |
|
34 | - * |
|
35 | - * @access private |
|
36 | - */ |
|
37 | - public function __construct() { |
|
38 | - $temp_options = get_option( '_lsx-to_settings', false ); |
|
39 | - |
|
40 | - if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) { |
|
41 | - $this->options = $temp_options[ $this->plugin_slug ]; |
|
42 | - } |
|
43 | - |
|
44 | - $this->url = 'http://wetu.com/API/Pins/' . $this->options['api_key'] . '/List'; |
|
45 | - |
|
46 | - add_action( 'lsx_tour_importer_admin_tab_' . $this->tab_slug, array( $this, 'display_page' ) ); |
|
47 | - add_action( 'wp_ajax_lsx_import_connect_accommodation', array( $this, 'process_connection' ) ); |
|
48 | - add_action( 'wp_ajax_nopriv_lsx_import_connect_accommodation', array( $this, 'process_connection' ) ); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Display the importer administration screen |
|
53 | - */ |
|
54 | - public function display_page() { |
|
55 | - global $post; |
|
56 | - ?> |
|
12 | + /** |
|
13 | + * The url to list items from WETU |
|
14 | + * |
|
15 | + * @since 0.0.1 |
|
16 | + * |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + public $tab_slug = 'connect_accommodation'; |
|
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 | + * Initialize the plugin by setting localization, filters, and administration functions. |
|
32 | + * |
|
33 | + * @since 1.0.0 |
|
34 | + * |
|
35 | + * @access private |
|
36 | + */ |
|
37 | + public function __construct() { |
|
38 | + $temp_options = get_option( '_lsx-to_settings', false ); |
|
39 | + |
|
40 | + if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) { |
|
41 | + $this->options = $temp_options[ $this->plugin_slug ]; |
|
42 | + } |
|
43 | + |
|
44 | + $this->url = 'http://wetu.com/API/Pins/' . $this->options['api_key'] . '/List'; |
|
45 | + |
|
46 | + add_action( 'lsx_tour_importer_admin_tab_' . $this->tab_slug, array( $this, 'display_page' ) ); |
|
47 | + add_action( 'wp_ajax_lsx_import_connect_accommodation', array( $this, 'process_connection' ) ); |
|
48 | + add_action( 'wp_ajax_nopriv_lsx_import_connect_accommodation', array( $this, 'process_connection' ) ); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Display the importer administration screen |
|
53 | + */ |
|
54 | + public function display_page() { |
|
55 | + global $post; |
|
56 | + ?> |
|
57 | 57 | <div class="wrap"> |
58 | 58 | <h3><span class="dashicons dashicons-admin-multisite"></span> <?php esc_html_e( 'Connect your Accommodation', 'lsx-wetu-importer' ); ?></h3> |
59 | 59 | |
@@ -67,38 +67,38 @@ discard block |
||
67 | 67 | </div> |
68 | 68 | |
69 | 69 | <?php |
70 | - $loose_accommodation = $this->find_current_accommodation(); |
|
71 | - ?> |
|
70 | + $loose_accommodation = $this->find_current_accommodation(); |
|
71 | + ?> |
|
72 | 72 | <p><input class="button button-primary connect" type="button" value="<?php esc_html_e( 'Connect', 'lsx-wetu-importer' ); ?>" /></p> |
73 | 73 | <table class="wp-list-table widefat fixed posts"> |
74 | 74 | <?php $this->table_header(); ?> |
75 | 75 | |
76 | 76 | <tbody> |
77 | 77 | <?php |
78 | - if ( false !== $loose_accommodation ) { |
|
79 | - |
|
80 | - $loose_args = array( |
|
81 | - 'post_type' => 'accommodation', |
|
82 | - 'post_status' => array( 'publish', 'pending' ), |
|
83 | - 'nopagin' => true, |
|
84 | - 'post__in' => $loose_accommodation, |
|
85 | - ); |
|
86 | - $loose_accommodation_query = new WP_Query( $loose_args ); |
|
87 | - $accommodation = get_transient( 'lsx_ti_accommodation' ); |
|
88 | - $identifier = ''; |
|
89 | - |
|
90 | - if ( $loose_accommodation_query->have_posts() && false !== $accommodation ) { |
|
91 | - while ( $loose_accommodation_query->have_posts() ) { |
|
92 | - $loose_accommodation_query->the_post(); |
|
93 | - |
|
94 | - foreach ( $accommodation as $row_key => $row ) { |
|
95 | - if ( stripos( ltrim( rtrim( $row->name ) ), $post->post_title ) !== false ) { |
|
96 | - $identifier = $row->id; |
|
97 | - } else { |
|
98 | - continue; |
|
99 | - } |
|
100 | - } |
|
101 | - ?> |
|
78 | + if ( false !== $loose_accommodation ) { |
|
79 | + |
|
80 | + $loose_args = array( |
|
81 | + 'post_type' => 'accommodation', |
|
82 | + 'post_status' => array( 'publish', 'pending' ), |
|
83 | + 'nopagin' => true, |
|
84 | + 'post__in' => $loose_accommodation, |
|
85 | + ); |
|
86 | + $loose_accommodation_query = new WP_Query( $loose_args ); |
|
87 | + $accommodation = get_transient( 'lsx_ti_accommodation' ); |
|
88 | + $identifier = ''; |
|
89 | + |
|
90 | + if ( $loose_accommodation_query->have_posts() && false !== $accommodation ) { |
|
91 | + while ( $loose_accommodation_query->have_posts() ) { |
|
92 | + $loose_accommodation_query->the_post(); |
|
93 | + |
|
94 | + foreach ( $accommodation as $row_key => $row ) { |
|
95 | + if ( stripos( ltrim( rtrim( $row->name ) ), $post->post_title ) !== false ) { |
|
96 | + $identifier = $row->id; |
|
97 | + } else { |
|
98 | + continue; |
|
99 | + } |
|
100 | + } |
|
101 | + ?> |
|
102 | 102 | <tr class="post-<?php the_ID(); ?> type-accommodation status-none" id="post-<?php the_ID(); ?>"> |
103 | 103 | <th class="check-column" scope="row"> |
104 | 104 | <label for="cb-select-<?php the_ID(); ?>" class="screen-reader-text"><?php the_title(); ?></label> |
@@ -109,15 +109,15 @@ discard block |
||
109 | 109 | </td> |
110 | 110 | <td class="excerpt column-excerpt"> |
111 | 111 | <?php |
112 | - echo wp_kses_post( strip_tags( get_the_excerpt() ) ); |
|
113 | - ?> |
|
112 | + echo wp_kses_post( strip_tags( get_the_excerpt() ) ); |
|
113 | + ?> |
|
114 | 114 | </td> |
115 | 115 | </tr> |
116 | 116 | <?php |
117 | - } |
|
118 | - } |
|
119 | - } |
|
120 | - ?> |
|
117 | + } |
|
118 | + } |
|
119 | + } |
|
120 | + ?> |
|
121 | 121 | </tbody> |
122 | 122 | |
123 | 123 | <?php $this->table_footer(); ?> |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | </div> |
136 | 136 | </div> |
137 | 137 | <?php |
138 | - } |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * The header of the item list |
|
142 | - */ |
|
143 | - public function table_header() { |
|
144 | - ?> |
|
140 | + /** |
|
141 | + * The header of the item list |
|
142 | + */ |
|
143 | + public function table_header() { |
|
144 | + ?> |
|
145 | 145 | <thead> |
146 | 146 | <tr> |
147 | 147 | <th style="" class="manage-column column-cb check-column" id="cb" scope="col"> |
@@ -153,13 +153,13 @@ discard block |
||
153 | 153 | </tr> |
154 | 154 | </thead> |
155 | 155 | <?php |
156 | - } |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * The footer of the item list |
|
160 | - */ |
|
161 | - public function table_footer() { |
|
162 | - ?> |
|
158 | + /** |
|
159 | + * The footer of the item list |
|
160 | + */ |
|
161 | + public function table_footer() { |
|
162 | + ?> |
|
163 | 163 | <tfoot> |
164 | 164 | <tr> |
165 | 165 | <th style="" class="manage-column column-cb check-column" id="cb" scope="col"> |
@@ -171,27 +171,27 @@ discard block |
||
171 | 171 | </tr> |
172 | 172 | </tfoot> |
173 | 173 | <?php |
174 | - } |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * Grab all the current accommodation posts via the lsx_wetu_id field. |
|
178 | - */ |
|
179 | - public function find_current_accommodation() { |
|
180 | - global $wpdb; |
|
181 | - $return = false; |
|
176 | + /** |
|
177 | + * Grab all the current accommodation posts via the lsx_wetu_id field. |
|
178 | + */ |
|
179 | + public function find_current_accommodation() { |
|
180 | + global $wpdb; |
|
181 | + $return = false; |
|
182 | 182 | |
183 | - $all_accommodation = $wpdb->get_results( |
|
184 | - " |
|
183 | + $all_accommodation = $wpdb->get_results( |
|
184 | + " |
|
185 | 185 | SELECT ID |
186 | 186 | FROM {$wpdb->posts} |
187 | 187 | WHERE post_type = 'accommodation' |
188 | 188 | LIMIT 0,500 |
189 | 189 | ", |
190 | - ARRAY_A |
|
191 | - ); |
|
190 | + ARRAY_A |
|
191 | + ); |
|
192 | 192 | |
193 | - $current_accommodation = $wpdb->get_results( |
|
194 | - " |
|
193 | + $current_accommodation = $wpdb->get_results( |
|
194 | + " |
|
195 | 195 | SELECT key1.post_id |
196 | 196 | FROM {$wpdb->postmeta} key1 |
197 | 197 | |
@@ -203,55 +203,55 @@ discard block |
||
203 | 203 | |
204 | 204 | LIMIT 0,500 |
205 | 205 | ", |
206 | - ARRAY_A |
|
207 | - ); |
|
208 | - |
|
209 | - if ( null !== $all_accommodation && ! empty( $all_accommodation ) ) { |
|
210 | - // remove the extra accommodation |
|
211 | - if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) { |
|
212 | - $all_accommodation = array_diff( $this->format_array( $all_accommodation, 'ID' ), $this->format_array( $current_accommodation, 'post_id' ) ); |
|
213 | - } elseif ( null !== $current_accommodation && empty( $current_accommodation ) ) { |
|
214 | - $all_accommodation = $this->format_array( $current_accommodation, 'post_id' ); |
|
215 | - } |
|
216 | - |
|
217 | - $return = $all_accommodation; |
|
218 | - } |
|
219 | - |
|
220 | - return $return; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * format the array |
|
225 | - */ |
|
226 | - public function format_array( $array, $key ) { |
|
227 | - $new_array = array(); |
|
228 | - |
|
229 | - foreach ( $array as $value ) { |
|
230 | - $new_array[] = $value[ $key ]; |
|
231 | - } |
|
232 | - |
|
233 | - return $new_array; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Run through the accommodation an connect them. |
|
238 | - */ |
|
239 | - public function process_connection() { |
|
240 | - $return = false; |
|
241 | - check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
242 | - if ( isset( $_POST['action'] ) && 'lsx_import_connect_accommodation' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug && isset( $_POST['post_id'] ) && isset( $_POST['wetu_id'] ) ) { |
|
243 | - $post_id = false; |
|
244 | - $matching_id = false; |
|
245 | - $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
246 | - $matching_id = sanitize_text_field( $_POST['wetu_id'] ); |
|
247 | - |
|
248 | - add_post_meta( $post_id, 'lsx_wetu_id', $matching_id ); |
|
249 | - $return = '<li class="post-' . $post_id . '"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="' . get_permalink( $post_id ) . '">' . get_the_title( $post_id ) . '</a></li>'; |
|
250 | - } |
|
251 | - |
|
252 | - print_r( $return ); |
|
253 | - die(); |
|
254 | - } |
|
206 | + ARRAY_A |
|
207 | + ); |
|
208 | + |
|
209 | + if ( null !== $all_accommodation && ! empty( $all_accommodation ) ) { |
|
210 | + // remove the extra accommodation |
|
211 | + if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) { |
|
212 | + $all_accommodation = array_diff( $this->format_array( $all_accommodation, 'ID' ), $this->format_array( $current_accommodation, 'post_id' ) ); |
|
213 | + } elseif ( null !== $current_accommodation && empty( $current_accommodation ) ) { |
|
214 | + $all_accommodation = $this->format_array( $current_accommodation, 'post_id' ); |
|
215 | + } |
|
216 | + |
|
217 | + $return = $all_accommodation; |
|
218 | + } |
|
219 | + |
|
220 | + return $return; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * format the array |
|
225 | + */ |
|
226 | + public function format_array( $array, $key ) { |
|
227 | + $new_array = array(); |
|
228 | + |
|
229 | + foreach ( $array as $value ) { |
|
230 | + $new_array[] = $value[ $key ]; |
|
231 | + } |
|
232 | + |
|
233 | + return $new_array; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Run through the accommodation an connect them. |
|
238 | + */ |
|
239 | + public function process_connection() { |
|
240 | + $return = false; |
|
241 | + check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
242 | + if ( isset( $_POST['action'] ) && 'lsx_import_connect_accommodation' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug && isset( $_POST['post_id'] ) && isset( $_POST['wetu_id'] ) ) { |
|
243 | + $post_id = false; |
|
244 | + $matching_id = false; |
|
245 | + $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
246 | + $matching_id = sanitize_text_field( $_POST['wetu_id'] ); |
|
247 | + |
|
248 | + add_post_meta( $post_id, 'lsx_wetu_id', $matching_id ); |
|
249 | + $return = '<li class="post-' . $post_id . '"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="' . get_permalink( $post_id ) . '">' . get_the_title( $post_id ) . '</a></li>'; |
|
250 | + } |
|
251 | + |
|
252 | + print_r( $return ); |
|
253 | + die(); |
|
254 | + } |
|
255 | 255 | |
256 | 256 | } |
257 | 257 |
@@ -14,109 +14,109 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class LSX_WETU_Importer_Post_Columns { |
16 | 16 | |
17 | - /** |
|
18 | - * Holds instance of the class |
|
19 | - * |
|
20 | - * @var object |
|
21 | - */ |
|
22 | - private static $instance; |
|
17 | + /** |
|
18 | + * Holds instance of the class |
|
19 | + * |
|
20 | + * @var object |
|
21 | + */ |
|
22 | + private static $instance; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Initialize the plugin by setting localization, filters, and administration functions. |
|
26 | - * |
|
27 | - * @since 1.0.0 |
|
28 | - * |
|
29 | - * @access private |
|
30 | - */ |
|
31 | - public function __construct() { |
|
32 | - add_filter( 'manage_tour_posts_columns', array( $this, 'register_tour_columns' ) ); |
|
33 | - add_action( 'manage_tour_posts_custom_column', array( $this, 'output_tour_ref_column' ), 10, 2 ); |
|
24 | + /** |
|
25 | + * Initialize the plugin by setting localization, filters, and administration functions. |
|
26 | + * |
|
27 | + * @since 1.0.0 |
|
28 | + * |
|
29 | + * @access private |
|
30 | + */ |
|
31 | + public function __construct() { |
|
32 | + add_filter( 'manage_tour_posts_columns', array( $this, 'register_tour_columns' ) ); |
|
33 | + add_action( 'manage_tour_posts_custom_column', array( $this, 'output_tour_ref_column' ), 10, 2 ); |
|
34 | 34 | |
35 | - // Sortables Columns, sorting needs to be fixed |
|
36 | - // add_filter( 'manage_edit-tour_sortable_columns', array( $this, 'register_sortable_columns' ) ); |
|
37 | - // add_action( 'pre_get_posts', array( $this, 'columns_posts_orderby' ) ); |
|
38 | - } |
|
35 | + // Sortables Columns, sorting needs to be fixed |
|
36 | + // add_filter( 'manage_edit-tour_sortable_columns', array( $this, 'register_sortable_columns' ) ); |
|
37 | + // add_action( 'pre_get_posts', array( $this, 'columns_posts_orderby' ) ); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Return an instance of this class. |
|
42 | - * |
|
43 | - * @return object |
|
44 | - */ |
|
45 | - public static function get_instance() { |
|
46 | - // If the single instance hasn't been set, set it now. |
|
47 | - if ( ! isset( self::$instance ) ) { |
|
48 | - self::$instance = new self(); |
|
49 | - } |
|
50 | - return self::$instance; |
|
51 | - } |
|
40 | + /** |
|
41 | + * Return an instance of this class. |
|
42 | + * |
|
43 | + * @return object |
|
44 | + */ |
|
45 | + public static function get_instance() { |
|
46 | + // If the single instance hasn't been set, set it now. |
|
47 | + if ( ! isset( self::$instance ) ) { |
|
48 | + self::$instance = new self(); |
|
49 | + } |
|
50 | + return self::$instance; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Display the importer welcome screen |
|
55 | - */ |
|
56 | - public function display_page() { |
|
53 | + /** |
|
54 | + * Display the importer welcome screen |
|
55 | + */ |
|
56 | + public function display_page() { |
|
57 | 57 | |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Registers the tour ref column |
|
62 | - * |
|
63 | - * @param array $columns |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public function register_tour_columns( $columns ) { |
|
67 | - $new_columns = array( |
|
68 | - 'cb' => $columns['cb'], |
|
69 | - 'title' => $columns['title'], |
|
70 | - 'wetu_ref' => __( 'Ref', 'lsx-wetu-importer' ), |
|
71 | - ); |
|
72 | - unset( $columns['cb'] ); |
|
73 | - unset( $columns['title'] ); |
|
74 | - foreach ( $columns as $column_key => $column_label ) { |
|
75 | - $new_columns[ $column_key ] = $column_label; |
|
76 | - } |
|
77 | - $columns = $new_columns; |
|
78 | - return $columns; |
|
79 | - } |
|
60 | + /** |
|
61 | + * Registers the tour ref column |
|
62 | + * |
|
63 | + * @param array $columns |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public function register_tour_columns( $columns ) { |
|
67 | + $new_columns = array( |
|
68 | + 'cb' => $columns['cb'], |
|
69 | + 'title' => $columns['title'], |
|
70 | + 'wetu_ref' => __( 'Ref', 'lsx-wetu-importer' ), |
|
71 | + ); |
|
72 | + unset( $columns['cb'] ); |
|
73 | + unset( $columns['title'] ); |
|
74 | + foreach ( $columns as $column_key => $column_label ) { |
|
75 | + $new_columns[ $column_key ] = $column_label; |
|
76 | + } |
|
77 | + $columns = $new_columns; |
|
78 | + return $columns; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Outputs the tour reference column |
|
83 | - * |
|
84 | - * @param string $column |
|
85 | - * @param string $post_id |
|
86 | - * @return void |
|
87 | - */ |
|
88 | - public function output_tour_ref_column( $column, $post_id ) { |
|
89 | - if ( 'wetu_ref' === $column ) { |
|
90 | - echo esc_attr( get_post_meta( $post_id, 'lsx_wetu_ref', true ) ); |
|
91 | - } |
|
92 | - } |
|
81 | + /** |
|
82 | + * Outputs the tour reference column |
|
83 | + * |
|
84 | + * @param string $column |
|
85 | + * @param string $post_id |
|
86 | + * @return void |
|
87 | + */ |
|
88 | + public function output_tour_ref_column( $column, $post_id ) { |
|
89 | + if ( 'wetu_ref' === $column ) { |
|
90 | + echo esc_attr( get_post_meta( $post_id, 'lsx_wetu_ref', true ) ); |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Register the columns that will be sortable |
|
96 | - * |
|
97 | - * @param array $columns |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - public function register_sortable_columns( $columns = array() ) { |
|
101 | - $columns['wetu_ref'] = 'price_per_month'; |
|
102 | - return $columns; |
|
103 | - } |
|
94 | + /** |
|
95 | + * Register the columns that will be sortable |
|
96 | + * |
|
97 | + * @param array $columns |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + public function register_sortable_columns( $columns = array() ) { |
|
101 | + $columns['wetu_ref'] = 'price_per_month'; |
|
102 | + return $columns; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Sort the columns |
|
107 | - * |
|
108 | - * @param object $query WP_Query() |
|
109 | - * @return void |
|
110 | - */ |
|
111 | - public function columns_posts_orderby( $query ) { |
|
112 | - if ( ! is_admin() || ! $query->is_main_query() ) { |
|
113 | - return; |
|
114 | - } |
|
115 | - if ( 'wetu_ref' === $query->get( 'orderby' ) ) { |
|
116 | - $query->set( 'orderby', 'meta_value' ); |
|
117 | - $query->set( 'meta_key', 'lsx_wetu_reference' ); |
|
118 | - } |
|
119 | - /* |
|
105 | + /** |
|
106 | + * Sort the columns |
|
107 | + * |
|
108 | + * @param object $query WP_Query() |
|
109 | + * @return void |
|
110 | + */ |
|
111 | + public function columns_posts_orderby( $query ) { |
|
112 | + if ( ! is_admin() || ! $query->is_main_query() ) { |
|
113 | + return; |
|
114 | + } |
|
115 | + if ( 'wetu_ref' === $query->get( 'orderby' ) ) { |
|
116 | + $query->set( 'orderby', 'meta_value' ); |
|
117 | + $query->set( 'meta_key', 'lsx_wetu_reference' ); |
|
118 | + } |
|
119 | + /* |
|
120 | 120 | if ( $query->is_search() && 'tour' === $query->get( 'post_type' ) ) { |
121 | 121 | $meta_query = array( |
122 | 122 | 'relation' => 'OR', |
@@ -128,5 +128,5 @@ discard block |
||
128 | 128 | ); |
129 | 129 | $query->set( 'meta_query', $meta_query ); |
130 | 130 | }*/ |
131 | - } |
|
131 | + } |
|
132 | 132 | } |
@@ -13,465 +13,465 @@ discard block |
||
13 | 13 | */ |
14 | 14 | class LSX_WETU_Importer { |
15 | 15 | |
16 | - /** |
|
17 | - * Holds class instance |
|
18 | - * |
|
19 | - * @since 1.0.0 |
|
20 | - * |
|
21 | - * @var object|Module_Template |
|
22 | - */ |
|
23 | - protected static $instance = null; |
|
24 | - |
|
25 | - /** |
|
26 | - * The slug for this plugin |
|
27 | - * |
|
28 | - * @since 0.0.1 |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - public $plugin_slug = 'lsx-wetu-importer'; |
|
33 | - |
|
34 | - /** |
|
35 | - * The url to list items from WETU |
|
36 | - * |
|
37 | - * @since 0.0.1 |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - public $tab_slug = 'default'; |
|
42 | - |
|
43 | - /** |
|
44 | - * The options for the plugin |
|
45 | - * |
|
46 | - * @since 0.0.1 |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - public $options = false; |
|
51 | - |
|
52 | - /** |
|
53 | - * The url to import images from WETU |
|
54 | - * |
|
55 | - * @since 0.0.1 |
|
56 | - * |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - public $import_scaling_url = false; |
|
60 | - |
|
61 | - /** |
|
62 | - * scale the images on import or not |
|
63 | - * |
|
64 | - * @since 0.0.1 |
|
65 | - * |
|
66 | - * @var boolean |
|
67 | - */ |
|
68 | - public $scale_images = false; |
|
69 | - |
|
70 | - /** |
|
71 | - * The WETU API Key |
|
72 | - */ |
|
73 | - public $api_key = false; |
|
74 | - |
|
75 | - /** |
|
76 | - * The post types this works with. |
|
77 | - */ |
|
78 | - public $post_types = array(); |
|
79 | - |
|
80 | - /** |
|
81 | - * The previously attached images |
|
82 | - * |
|
83 | - * @var array() |
|
84 | - */ |
|
85 | - public $found_attachments = array(); |
|
86 | - |
|
87 | - /** |
|
88 | - * The gallery ids for the found attachements |
|
89 | - * |
|
90 | - * @var array() |
|
91 | - */ |
|
92 | - public $gallery_meta = array(); |
|
93 | - |
|
94 | - /** |
|
95 | - * The post ids to clean up (make sure the connected items are only singular) |
|
96 | - * |
|
97 | - * @var array() |
|
98 | - */ |
|
99 | - public $cleanup_posts = array(); |
|
100 | - |
|
101 | - /** |
|
102 | - * A post => parent relationship array. |
|
103 | - * |
|
104 | - * @var array() |
|
105 | - */ |
|
106 | - public $relation_meta = array(); |
|
107 | - |
|
108 | - /** |
|
109 | - * Image Limit |
|
110 | - * |
|
111 | - * @var int |
|
112 | - */ |
|
113 | - public $image_limit = false; |
|
114 | - |
|
115 | - /** |
|
116 | - * the featured image id |
|
117 | - * |
|
118 | - * @var int |
|
119 | - */ |
|
120 | - public $featured_image = false; |
|
121 | - |
|
122 | - /** |
|
123 | - * the banner image |
|
124 | - * |
|
125 | - * @var int |
|
126 | - */ |
|
127 | - public $banner_image = false; |
|
128 | - |
|
129 | - /** |
|
130 | - * Holds the current import to display |
|
131 | - * |
|
132 | - * @var int |
|
133 | - */ |
|
134 | - public $current_importer = false; |
|
135 | - |
|
136 | - /** |
|
137 | - * if you ran a tour import then you will have accommodation and destination queued to sync as well. |
|
138 | - * |
|
139 | - * @var int |
|
140 | - */ |
|
141 | - public $queued_imports = array(); |
|
142 | - |
|
143 | - /** |
|
144 | - * An Array to hold the items to queue |
|
145 | - * |
|
146 | - * @var int |
|
147 | - */ |
|
148 | - public $import_queue = array(); |
|
149 | - |
|
150 | - /** |
|
151 | - * Holds the current post that is being imported. Use to check the content and excerpt. |
|
152 | - * |
|
153 | - * @var int |
|
154 | - */ |
|
155 | - public $current_post = false; |
|
156 | - |
|
157 | - /** |
|
158 | - * Holds the accommodation settings |
|
159 | - * |
|
160 | - * @var int |
|
161 | - */ |
|
162 | - public $accommodation_settings = false; |
|
163 | - |
|
164 | - /** |
|
165 | - * Holds the tour settings |
|
166 | - * |
|
167 | - * @var int |
|
168 | - */ |
|
169 | - public $tour_settings = false; |
|
170 | - |
|
171 | - /** |
|
172 | - * Holds the destination settings |
|
173 | - * |
|
174 | - * @var int |
|
175 | - */ |
|
176 | - public $destination_settings = false; |
|
177 | - |
|
178 | - /** |
|
179 | - * Hold the flag to let you know if the debug is enabled or not. |
|
180 | - * |
|
181 | - * @var int |
|
182 | - */ |
|
183 | - public $debug_enabled = false; |
|
184 | - |
|
185 | - /** |
|
186 | - * Hold the post columns object |
|
187 | - * |
|
188 | - * @var object LSX_WETU_Importer_Post_Columns() |
|
189 | - */ |
|
190 | - public $post_columns = false; |
|
191 | - |
|
192 | - /** |
|
193 | - * Initialize the plugin by setting localization, filters, and administration functions. |
|
194 | - * |
|
195 | - * @since 1.0.0 |
|
196 | - * |
|
197 | - * @access private |
|
198 | - */ |
|
199 | - public function __construct() { |
|
200 | - add_action( 'admin_init', array( $this, 'compatible_version_check' ) ); |
|
201 | - require_once LSX_WETU_IMPORTER_PATH . 'includes/helpers.php'; |
|
202 | - |
|
203 | - // Don't run anything else in the plugin, if we're on an incompatible PHP version. |
|
204 | - if ( ! self::compatible_version() ) { |
|
205 | - return; |
|
206 | - } |
|
207 | - |
|
208 | - $this->set_variables(); |
|
209 | - |
|
210 | - add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); |
|
211 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 11 ); |
|
212 | - add_action( 'admin_menu', array( $this, 'register_importer_page' ), 20 ); |
|
213 | - |
|
214 | - require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-welcome.php'; |
|
215 | - require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-accommodation.php'; |
|
216 | - require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-destination.php'; |
|
217 | - require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-tours.php'; |
|
218 | - require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-settings.php'; |
|
219 | - require_once LSX_WETU_IMPORTER_PATH . 'classes/class-cron.php'; |
|
220 | - |
|
221 | - if ( isset( $this->options ) && isset( $this->options['enable_tour_ref_column'] ) && '' !== $this->options['enable_tour_ref_column'] ) { |
|
222 | - require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-post-columns.php'; |
|
223 | - $this->post_columns = LSX_WETU_Importer_Post_Columns::get_instance(); |
|
224 | - } |
|
225 | - |
|
226 | - add_action( 'init', array( $this, 'load_class' ) ); |
|
227 | - |
|
228 | - if ( 'default' !== $this->tab_slug ) { |
|
229 | - add_action( 'wp_ajax_lsx_tour_importer', array( $this, 'process_ajax_search' ) ); |
|
230 | - add_action( 'wp_ajax_nopriv_lsx_tour_importer', array( $this, 'process_ajax_search' ) ); |
|
231 | - |
|
232 | - add_action( 'wp_ajax_lsx_import_items', array( $this, 'process_ajax_import' ) ); |
|
233 | - add_action( 'wp_ajax_nopriv_lsx_import_items', array( $this, 'process_ajax_import' ) ); |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Load the plugin text domain for translation. |
|
239 | - * |
|
240 | - * @since 1.0.0 |
|
241 | - */ |
|
242 | - public function load_plugin_textdomain() { |
|
243 | - load_plugin_textdomain( 'lsx-wetu-importer', false, basename( LSX_WETU_IMPORTER_PATH ) . '/languages' ); |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Sets the variables used throughout the plugin. |
|
248 | - */ |
|
249 | - public function set_variables() { |
|
250 | - $this->post_types = array( 'accommodation', 'destination', 'tour' ); |
|
251 | - $options = lsx_wetu_get_options(); |
|
252 | - |
|
253 | - // Set the options. |
|
254 | - $this->options = $options; |
|
255 | - |
|
256 | - $temp_options = get_option( '_lsx-to_settings', false ); |
|
257 | - if ( false !== $temp_options ) { |
|
258 | - $this->accommodation_settings = $temp_options['accommodation']; |
|
259 | - $this->tour_settings = $temp_options['tour']; |
|
260 | - $this->destination_settings = $temp_options['destination']; |
|
261 | - } |
|
262 | - |
|
263 | - $this->api_key = false; |
|
264 | - |
|
265 | - if ( ! defined( 'WETU_API_KEY' ) ) { |
|
266 | - if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) { |
|
267 | - $this->api_key = $options['api_key']; |
|
268 | - } |
|
269 | - } else { |
|
270 | - $this->api_key = WETU_API_KEY; |
|
271 | - } |
|
272 | - |
|
273 | - // Set the tab slug. |
|
274 | - // @codingStandardsIgnoreLine |
|
275 | - if ( isset( $_GET['tab'] ) || ( defined( 'DOING_AJAX' ) && isset( $_POST['type'] ) ) ) { |
|
276 | - if ( isset( $_GET['tab'] ) ) { |
|
277 | - $this->tab_slug = sanitize_text_field( $_GET['tab'] ); |
|
278 | - } else { |
|
279 | - // @codingStandardsIgnoreLine |
|
280 | - $this->tab_slug = sanitize_text_field( $_POST['type'] ); |
|
281 | - } |
|
282 | - } |
|
283 | - |
|
284 | - // If any tours were queued. |
|
285 | - $this->queued_imports = get_option( 'lsx_wetu_importer_que', array() ); |
|
286 | - |
|
287 | - // Set the scaling options. |
|
288 | - if ( isset( $this->options ) && isset( $this->options['image_scaling'] ) ) { |
|
289 | - $this->scale_images = true; |
|
290 | - |
|
291 | - $width = '1024'; |
|
292 | - if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) { |
|
293 | - $width = $this->options['width']; |
|
294 | - } |
|
295 | - |
|
296 | - $height = '768'; |
|
297 | - if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) { |
|
298 | - $height = $this->options['height']; |
|
299 | - } |
|
300 | - |
|
301 | - $cropping = 'w'; |
|
302 | - if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) { |
|
303 | - $cropping = $this->options['cropping']; |
|
304 | - } |
|
305 | - |
|
306 | - $this->image_scaling_url = 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/'; |
|
307 | - } |
|
308 | - |
|
309 | - if ( isset( $this->options ) && isset( $this->options['image_limit'] ) && '' !== $this->options['image_limit'] ) { |
|
310 | - $this->image_limit = $this->options['image_limit']; |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - // COMPATABILITY FUNCTIONS. |
|
315 | - |
|
316 | - /** |
|
317 | - * On plugin activation |
|
318 | - * |
|
319 | - * @since 1.0.0 |
|
320 | - */ |
|
321 | - public static function register_activation_hook() { |
|
322 | - self::compatible_version_check_on_activation(); |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Check if the PHP version is compatible. |
|
327 | - * |
|
328 | - * @since 1.0.0 |
|
329 | - */ |
|
330 | - public static function compatible_version() { |
|
331 | - if ( version_compare( PHP_VERSION, '5.6', '<' ) ) { |
|
332 | - return false; |
|
333 | - } |
|
334 | - |
|
335 | - return true; |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * The backup sanity check, in case the plugin is activated in a weird way, |
|
340 | - * or the versions change after activation. |
|
341 | - * |
|
342 | - * @since 1.0.0 |
|
343 | - */ |
|
344 | - public function compatible_version_check() { |
|
345 | - if ( ! self::compatible_version() ) { |
|
346 | - if ( is_plugin_active( plugin_basename( LSX_WETU_IMPORTER_CORE ) ) ) { |
|
347 | - deactivate_plugins( plugin_basename( LSX_WETU_IMPORTER_CORE ) ); |
|
348 | - add_action( 'admin_notices', array( $this, 'compatible_version_notice' ) ); |
|
349 | - |
|
350 | - if ( isset( $_GET['activate'] ) ) { |
|
351 | - unset( $_GET['activate'] ); |
|
352 | - } |
|
353 | - } |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Display the notice related with the older version from PHP. |
|
359 | - * |
|
360 | - * @since 1.0.0 |
|
361 | - */ |
|
362 | - public function compatible_version_notice() { |
|
363 | - $class = 'notice notice-error'; |
|
364 | - $message = esc_html__( 'LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer' ); |
|
365 | - printf( '<div class="%1$s"><p>%2$s</p></div>', esc_html( $class ), esc_html( $message ) ); |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * The primary sanity check, automatically disable the plugin on activation if it doesn't |
|
370 | - * meet minimum requirements. |
|
371 | - * |
|
372 | - * @since 1.0.0 |
|
373 | - */ |
|
374 | - public static function compatible_version_check_on_activation() { |
|
375 | - if ( ! self::compatible_version() ) { |
|
376 | - deactivate_plugins( plugin_basename( LSX_WETU_IMPORTER_CORE ) ); |
|
377 | - wp_die( esc_html__( 'LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer' ) ); |
|
378 | - } |
|
379 | - } |
|
380 | - |
|
381 | - // DISPLAY FUNCTIONS. |
|
382 | - |
|
383 | - /** |
|
384 | - * Load the importer class you want to use |
|
385 | - */ |
|
386 | - public function load_class() { |
|
387 | - switch ( $this->tab_slug ) { |
|
388 | - case 'accommodation': |
|
389 | - $this->current_importer = new LSX_WETU_Importer_Accommodation(); |
|
390 | - break; |
|
391 | - |
|
392 | - case 'destination': |
|
393 | - $this->current_importer = new LSX_WETU_Importer_Destination(); |
|
394 | - break; |
|
395 | - |
|
396 | - case 'tour': |
|
397 | - $this->current_importer = new LSX_WETU_Importer_Tours(); |
|
398 | - break; |
|
399 | - |
|
400 | - case 'settings': |
|
401 | - $this->current_importer = LSX_WETU_Importer_Settings::get_instance(); |
|
402 | - break; |
|
403 | - |
|
404 | - default: |
|
405 | - $this->current_importer = LSX_WETU_Importer_Welcome::get_instance(); |
|
406 | - break; |
|
407 | - } |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Registers the admin page which will house the importer form. |
|
412 | - */ |
|
413 | - public function register_importer_page() { |
|
414 | - add_submenu_page( 'tour-operator', esc_html__( 'Importer', 'tour-operator' ), esc_html__( 'Importer', 'tour-operator' ), 'manage_options', 'lsx-wetu-importer', array( $this, 'display_page' ) ); |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * Enqueue the JS needed to contact wetu and return your result. |
|
419 | - */ |
|
420 | - public function admin_scripts() { |
|
421 | - if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) { |
|
422 | - $min = ''; |
|
423 | - } else { |
|
424 | - $min = '.min'; |
|
425 | - } |
|
426 | - |
|
427 | - $min = ''; |
|
428 | - |
|
429 | - if ( is_admin() && isset( $_GET['page'] ) && $this->plugin_slug === $_GET['page'] ) { |
|
430 | - |
|
431 | - // wp_enqueue_style( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/css/datatables' . $min . '.css', LSX_WETU_IMPORTER_VER, true ); |
|
432 | - wp_enqueue_style( 'lsx-wetu-importer-style', LSX_WETU_IMPORTER_URL . 'assets/css/lsx-wetu-importer.css', LSX_WETU_IMPORTER_VER, true ); |
|
433 | - |
|
434 | - if ( isset( $_GET['tab'] ) ) { |
|
435 | - wp_enqueue_script( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/js/datatables' . $min . '.js', array( 'jquery' ), LSX_WETU_IMPORTER_VER, true ); |
|
436 | - wp_enqueue_script( 'lsx-wetu-importers-script', LSX_WETU_IMPORTER_URL . 'assets/js/lsx-wetu-importer' . $min . '.js', array( 'jquery', 'datatables' ), LSX_WETU_IMPORTER_VER, true ); |
|
437 | - |
|
438 | - wp_localize_script( |
|
439 | - 'lsx-wetu-importers-script', |
|
440 | - 'lsx_tour_importer_params', |
|
441 | - array( |
|
442 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
443 | - 'ajax_nonce' => wp_create_nonce( 'lsx_wetu_ajax_action' ), |
|
444 | - ) |
|
445 | - ); |
|
446 | - } |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * Display the importer administration screen |
|
452 | - */ |
|
453 | - public function display_page() { |
|
454 | - ?> |
|
16 | + /** |
|
17 | + * Holds class instance |
|
18 | + * |
|
19 | + * @since 1.0.0 |
|
20 | + * |
|
21 | + * @var object|Module_Template |
|
22 | + */ |
|
23 | + protected static $instance = null; |
|
24 | + |
|
25 | + /** |
|
26 | + * The slug for this plugin |
|
27 | + * |
|
28 | + * @since 0.0.1 |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + public $plugin_slug = 'lsx-wetu-importer'; |
|
33 | + |
|
34 | + /** |
|
35 | + * The url to list items from WETU |
|
36 | + * |
|
37 | + * @since 0.0.1 |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + public $tab_slug = 'default'; |
|
42 | + |
|
43 | + /** |
|
44 | + * The options for the plugin |
|
45 | + * |
|
46 | + * @since 0.0.1 |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + public $options = false; |
|
51 | + |
|
52 | + /** |
|
53 | + * The url to import images from WETU |
|
54 | + * |
|
55 | + * @since 0.0.1 |
|
56 | + * |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + public $import_scaling_url = false; |
|
60 | + |
|
61 | + /** |
|
62 | + * scale the images on import or not |
|
63 | + * |
|
64 | + * @since 0.0.1 |
|
65 | + * |
|
66 | + * @var boolean |
|
67 | + */ |
|
68 | + public $scale_images = false; |
|
69 | + |
|
70 | + /** |
|
71 | + * The WETU API Key |
|
72 | + */ |
|
73 | + public $api_key = false; |
|
74 | + |
|
75 | + /** |
|
76 | + * The post types this works with. |
|
77 | + */ |
|
78 | + public $post_types = array(); |
|
79 | + |
|
80 | + /** |
|
81 | + * The previously attached images |
|
82 | + * |
|
83 | + * @var array() |
|
84 | + */ |
|
85 | + public $found_attachments = array(); |
|
86 | + |
|
87 | + /** |
|
88 | + * The gallery ids for the found attachements |
|
89 | + * |
|
90 | + * @var array() |
|
91 | + */ |
|
92 | + public $gallery_meta = array(); |
|
93 | + |
|
94 | + /** |
|
95 | + * The post ids to clean up (make sure the connected items are only singular) |
|
96 | + * |
|
97 | + * @var array() |
|
98 | + */ |
|
99 | + public $cleanup_posts = array(); |
|
100 | + |
|
101 | + /** |
|
102 | + * A post => parent relationship array. |
|
103 | + * |
|
104 | + * @var array() |
|
105 | + */ |
|
106 | + public $relation_meta = array(); |
|
107 | + |
|
108 | + /** |
|
109 | + * Image Limit |
|
110 | + * |
|
111 | + * @var int |
|
112 | + */ |
|
113 | + public $image_limit = false; |
|
114 | + |
|
115 | + /** |
|
116 | + * the featured image id |
|
117 | + * |
|
118 | + * @var int |
|
119 | + */ |
|
120 | + public $featured_image = false; |
|
121 | + |
|
122 | + /** |
|
123 | + * the banner image |
|
124 | + * |
|
125 | + * @var int |
|
126 | + */ |
|
127 | + public $banner_image = false; |
|
128 | + |
|
129 | + /** |
|
130 | + * Holds the current import to display |
|
131 | + * |
|
132 | + * @var int |
|
133 | + */ |
|
134 | + public $current_importer = false; |
|
135 | + |
|
136 | + /** |
|
137 | + * if you ran a tour import then you will have accommodation and destination queued to sync as well. |
|
138 | + * |
|
139 | + * @var int |
|
140 | + */ |
|
141 | + public $queued_imports = array(); |
|
142 | + |
|
143 | + /** |
|
144 | + * An Array to hold the items to queue |
|
145 | + * |
|
146 | + * @var int |
|
147 | + */ |
|
148 | + public $import_queue = array(); |
|
149 | + |
|
150 | + /** |
|
151 | + * Holds the current post that is being imported. Use to check the content and excerpt. |
|
152 | + * |
|
153 | + * @var int |
|
154 | + */ |
|
155 | + public $current_post = false; |
|
156 | + |
|
157 | + /** |
|
158 | + * Holds the accommodation settings |
|
159 | + * |
|
160 | + * @var int |
|
161 | + */ |
|
162 | + public $accommodation_settings = false; |
|
163 | + |
|
164 | + /** |
|
165 | + * Holds the tour settings |
|
166 | + * |
|
167 | + * @var int |
|
168 | + */ |
|
169 | + public $tour_settings = false; |
|
170 | + |
|
171 | + /** |
|
172 | + * Holds the destination settings |
|
173 | + * |
|
174 | + * @var int |
|
175 | + */ |
|
176 | + public $destination_settings = false; |
|
177 | + |
|
178 | + /** |
|
179 | + * Hold the flag to let you know if the debug is enabled or not. |
|
180 | + * |
|
181 | + * @var int |
|
182 | + */ |
|
183 | + public $debug_enabled = false; |
|
184 | + |
|
185 | + /** |
|
186 | + * Hold the post columns object |
|
187 | + * |
|
188 | + * @var object LSX_WETU_Importer_Post_Columns() |
|
189 | + */ |
|
190 | + public $post_columns = false; |
|
191 | + |
|
192 | + /** |
|
193 | + * Initialize the plugin by setting localization, filters, and administration functions. |
|
194 | + * |
|
195 | + * @since 1.0.0 |
|
196 | + * |
|
197 | + * @access private |
|
198 | + */ |
|
199 | + public function __construct() { |
|
200 | + add_action( 'admin_init', array( $this, 'compatible_version_check' ) ); |
|
201 | + require_once LSX_WETU_IMPORTER_PATH . 'includes/helpers.php'; |
|
202 | + |
|
203 | + // Don't run anything else in the plugin, if we're on an incompatible PHP version. |
|
204 | + if ( ! self::compatible_version() ) { |
|
205 | + return; |
|
206 | + } |
|
207 | + |
|
208 | + $this->set_variables(); |
|
209 | + |
|
210 | + add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); |
|
211 | + add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 11 ); |
|
212 | + add_action( 'admin_menu', array( $this, 'register_importer_page' ), 20 ); |
|
213 | + |
|
214 | + require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-welcome.php'; |
|
215 | + require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-accommodation.php'; |
|
216 | + require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-destination.php'; |
|
217 | + require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-tours.php'; |
|
218 | + require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-settings.php'; |
|
219 | + require_once LSX_WETU_IMPORTER_PATH . 'classes/class-cron.php'; |
|
220 | + |
|
221 | + if ( isset( $this->options ) && isset( $this->options['enable_tour_ref_column'] ) && '' !== $this->options['enable_tour_ref_column'] ) { |
|
222 | + require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-post-columns.php'; |
|
223 | + $this->post_columns = LSX_WETU_Importer_Post_Columns::get_instance(); |
|
224 | + } |
|
225 | + |
|
226 | + add_action( 'init', array( $this, 'load_class' ) ); |
|
227 | + |
|
228 | + if ( 'default' !== $this->tab_slug ) { |
|
229 | + add_action( 'wp_ajax_lsx_tour_importer', array( $this, 'process_ajax_search' ) ); |
|
230 | + add_action( 'wp_ajax_nopriv_lsx_tour_importer', array( $this, 'process_ajax_search' ) ); |
|
231 | + |
|
232 | + add_action( 'wp_ajax_lsx_import_items', array( $this, 'process_ajax_import' ) ); |
|
233 | + add_action( 'wp_ajax_nopriv_lsx_import_items', array( $this, 'process_ajax_import' ) ); |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Load the plugin text domain for translation. |
|
239 | + * |
|
240 | + * @since 1.0.0 |
|
241 | + */ |
|
242 | + public function load_plugin_textdomain() { |
|
243 | + load_plugin_textdomain( 'lsx-wetu-importer', false, basename( LSX_WETU_IMPORTER_PATH ) . '/languages' ); |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Sets the variables used throughout the plugin. |
|
248 | + */ |
|
249 | + public function set_variables() { |
|
250 | + $this->post_types = array( 'accommodation', 'destination', 'tour' ); |
|
251 | + $options = lsx_wetu_get_options(); |
|
252 | + |
|
253 | + // Set the options. |
|
254 | + $this->options = $options; |
|
255 | + |
|
256 | + $temp_options = get_option( '_lsx-to_settings', false ); |
|
257 | + if ( false !== $temp_options ) { |
|
258 | + $this->accommodation_settings = $temp_options['accommodation']; |
|
259 | + $this->tour_settings = $temp_options['tour']; |
|
260 | + $this->destination_settings = $temp_options['destination']; |
|
261 | + } |
|
262 | + |
|
263 | + $this->api_key = false; |
|
264 | + |
|
265 | + if ( ! defined( 'WETU_API_KEY' ) ) { |
|
266 | + if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) { |
|
267 | + $this->api_key = $options['api_key']; |
|
268 | + } |
|
269 | + } else { |
|
270 | + $this->api_key = WETU_API_KEY; |
|
271 | + } |
|
272 | + |
|
273 | + // Set the tab slug. |
|
274 | + // @codingStandardsIgnoreLine |
|
275 | + if ( isset( $_GET['tab'] ) || ( defined( 'DOING_AJAX' ) && isset( $_POST['type'] ) ) ) { |
|
276 | + if ( isset( $_GET['tab'] ) ) { |
|
277 | + $this->tab_slug = sanitize_text_field( $_GET['tab'] ); |
|
278 | + } else { |
|
279 | + // @codingStandardsIgnoreLine |
|
280 | + $this->tab_slug = sanitize_text_field( $_POST['type'] ); |
|
281 | + } |
|
282 | + } |
|
283 | + |
|
284 | + // If any tours were queued. |
|
285 | + $this->queued_imports = get_option( 'lsx_wetu_importer_que', array() ); |
|
286 | + |
|
287 | + // Set the scaling options. |
|
288 | + if ( isset( $this->options ) && isset( $this->options['image_scaling'] ) ) { |
|
289 | + $this->scale_images = true; |
|
290 | + |
|
291 | + $width = '1024'; |
|
292 | + if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) { |
|
293 | + $width = $this->options['width']; |
|
294 | + } |
|
295 | + |
|
296 | + $height = '768'; |
|
297 | + if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) { |
|
298 | + $height = $this->options['height']; |
|
299 | + } |
|
300 | + |
|
301 | + $cropping = 'w'; |
|
302 | + if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) { |
|
303 | + $cropping = $this->options['cropping']; |
|
304 | + } |
|
305 | + |
|
306 | + $this->image_scaling_url = 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/'; |
|
307 | + } |
|
308 | + |
|
309 | + if ( isset( $this->options ) && isset( $this->options['image_limit'] ) && '' !== $this->options['image_limit'] ) { |
|
310 | + $this->image_limit = $this->options['image_limit']; |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + // COMPATABILITY FUNCTIONS. |
|
315 | + |
|
316 | + /** |
|
317 | + * On plugin activation |
|
318 | + * |
|
319 | + * @since 1.0.0 |
|
320 | + */ |
|
321 | + public static function register_activation_hook() { |
|
322 | + self::compatible_version_check_on_activation(); |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Check if the PHP version is compatible. |
|
327 | + * |
|
328 | + * @since 1.0.0 |
|
329 | + */ |
|
330 | + public static function compatible_version() { |
|
331 | + if ( version_compare( PHP_VERSION, '5.6', '<' ) ) { |
|
332 | + return false; |
|
333 | + } |
|
334 | + |
|
335 | + return true; |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * The backup sanity check, in case the plugin is activated in a weird way, |
|
340 | + * or the versions change after activation. |
|
341 | + * |
|
342 | + * @since 1.0.0 |
|
343 | + */ |
|
344 | + public function compatible_version_check() { |
|
345 | + if ( ! self::compatible_version() ) { |
|
346 | + if ( is_plugin_active( plugin_basename( LSX_WETU_IMPORTER_CORE ) ) ) { |
|
347 | + deactivate_plugins( plugin_basename( LSX_WETU_IMPORTER_CORE ) ); |
|
348 | + add_action( 'admin_notices', array( $this, 'compatible_version_notice' ) ); |
|
349 | + |
|
350 | + if ( isset( $_GET['activate'] ) ) { |
|
351 | + unset( $_GET['activate'] ); |
|
352 | + } |
|
353 | + } |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Display the notice related with the older version from PHP. |
|
359 | + * |
|
360 | + * @since 1.0.0 |
|
361 | + */ |
|
362 | + public function compatible_version_notice() { |
|
363 | + $class = 'notice notice-error'; |
|
364 | + $message = esc_html__( 'LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer' ); |
|
365 | + printf( '<div class="%1$s"><p>%2$s</p></div>', esc_html( $class ), esc_html( $message ) ); |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * The primary sanity check, automatically disable the plugin on activation if it doesn't |
|
370 | + * meet minimum requirements. |
|
371 | + * |
|
372 | + * @since 1.0.0 |
|
373 | + */ |
|
374 | + public static function compatible_version_check_on_activation() { |
|
375 | + if ( ! self::compatible_version() ) { |
|
376 | + deactivate_plugins( plugin_basename( LSX_WETU_IMPORTER_CORE ) ); |
|
377 | + wp_die( esc_html__( 'LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer' ) ); |
|
378 | + } |
|
379 | + } |
|
380 | + |
|
381 | + // DISPLAY FUNCTIONS. |
|
382 | + |
|
383 | + /** |
|
384 | + * Load the importer class you want to use |
|
385 | + */ |
|
386 | + public function load_class() { |
|
387 | + switch ( $this->tab_slug ) { |
|
388 | + case 'accommodation': |
|
389 | + $this->current_importer = new LSX_WETU_Importer_Accommodation(); |
|
390 | + break; |
|
391 | + |
|
392 | + case 'destination': |
|
393 | + $this->current_importer = new LSX_WETU_Importer_Destination(); |
|
394 | + break; |
|
395 | + |
|
396 | + case 'tour': |
|
397 | + $this->current_importer = new LSX_WETU_Importer_Tours(); |
|
398 | + break; |
|
399 | + |
|
400 | + case 'settings': |
|
401 | + $this->current_importer = LSX_WETU_Importer_Settings::get_instance(); |
|
402 | + break; |
|
403 | + |
|
404 | + default: |
|
405 | + $this->current_importer = LSX_WETU_Importer_Welcome::get_instance(); |
|
406 | + break; |
|
407 | + } |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Registers the admin page which will house the importer form. |
|
412 | + */ |
|
413 | + public function register_importer_page() { |
|
414 | + add_submenu_page( 'tour-operator', esc_html__( 'Importer', 'tour-operator' ), esc_html__( 'Importer', 'tour-operator' ), 'manage_options', 'lsx-wetu-importer', array( $this, 'display_page' ) ); |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * Enqueue the JS needed to contact wetu and return your result. |
|
419 | + */ |
|
420 | + public function admin_scripts() { |
|
421 | + if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) { |
|
422 | + $min = ''; |
|
423 | + } else { |
|
424 | + $min = '.min'; |
|
425 | + } |
|
426 | + |
|
427 | + $min = ''; |
|
428 | + |
|
429 | + if ( is_admin() && isset( $_GET['page'] ) && $this->plugin_slug === $_GET['page'] ) { |
|
430 | + |
|
431 | + // wp_enqueue_style( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/css/datatables' . $min . '.css', LSX_WETU_IMPORTER_VER, true ); |
|
432 | + wp_enqueue_style( 'lsx-wetu-importer-style', LSX_WETU_IMPORTER_URL . 'assets/css/lsx-wetu-importer.css', LSX_WETU_IMPORTER_VER, true ); |
|
433 | + |
|
434 | + if ( isset( $_GET['tab'] ) ) { |
|
435 | + wp_enqueue_script( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/js/datatables' . $min . '.js', array( 'jquery' ), LSX_WETU_IMPORTER_VER, true ); |
|
436 | + wp_enqueue_script( 'lsx-wetu-importers-script', LSX_WETU_IMPORTER_URL . 'assets/js/lsx-wetu-importer' . $min . '.js', array( 'jquery', 'datatables' ), LSX_WETU_IMPORTER_VER, true ); |
|
437 | + |
|
438 | + wp_localize_script( |
|
439 | + 'lsx-wetu-importers-script', |
|
440 | + 'lsx_tour_importer_params', |
|
441 | + array( |
|
442 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
443 | + 'ajax_nonce' => wp_create_nonce( 'lsx_wetu_ajax_action' ), |
|
444 | + ) |
|
445 | + ); |
|
446 | + } |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * Display the importer administration screen |
|
452 | + */ |
|
453 | + public function display_page() { |
|
454 | + ?> |
|
455 | 455 | <div class="wrap"> |
456 | 456 | <?php |
457 | - $this->navigation( $this->tab_slug ); |
|
458 | - if ( 'default' !== $this->tab_slug && 'settings' !== $this->tab_slug ) { |
|
459 | - $this->wetu_status(); |
|
460 | - $this->post_status_navigation(); |
|
461 | - } |
|
462 | - $this->current_importer->display_page(); |
|
463 | - ?> |
|
457 | + $this->navigation( $this->tab_slug ); |
|
458 | + if ( 'default' !== $this->tab_slug && 'settings' !== $this->tab_slug ) { |
|
459 | + $this->wetu_status(); |
|
460 | + $this->post_status_navigation(); |
|
461 | + } |
|
462 | + $this->current_importer->display_page(); |
|
463 | + ?> |
|
464 | 464 | </div> |
465 | 465 | <?php |
466 | - } |
|
467 | - |
|
468 | - /** |
|
469 | - * Outputs the post status navigation |
|
470 | - * |
|
471 | - * @return void |
|
472 | - */ |
|
473 | - public function post_status_navigation() { |
|
474 | - ?> |
|
466 | + } |
|
467 | + |
|
468 | + /** |
|
469 | + * Outputs the post status navigation |
|
470 | + * |
|
471 | + * @return void |
|
472 | + */ |
|
473 | + public function post_status_navigation() { |
|
474 | + ?> |
|
475 | 475 | <ul class="subsubsub"> |
476 | 476 | <li class="searchform"><a class="current" href="#search"><?php esc_attr_e( 'Search', 'lsx-wetu-importer' ); ?></a> | </li> |
477 | 477 | <li class="publish"><a href="#publish"><?php esc_attr_e( 'Published', 'lsx-wetu-importer' ); ?> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_post_count( $this->tab_slug, 'publish ' ) ); ?>)</span></a> | </li> |
@@ -486,13 +486,13 @@ discard block |
||
486 | 486 | </ul> |
487 | 487 | <a class="documentation" target="_blank"href="https://tour-operator.lsdev.biz/documentation/extension/wetu-importer/"><?php esc_attr_e( 'Documentation', 'lsx-wetu-importer' ); ?></a> |
488 | 488 | <?php |
489 | - } |
|
489 | + } |
|
490 | 490 | |
491 | - /** |
|
492 | - * Search Form |
|
493 | - */ |
|
494 | - public function search_form() { |
|
495 | - ?> |
|
491 | + /** |
|
492 | + * Search Form |
|
493 | + */ |
|
494 | + public function search_form() { |
|
495 | + ?> |
|
496 | 496 | <form class="ajax-form" id="<?php echo esc_attr( $this->plugin_slug ); ?>-search-form" method="get" action="tools.php" data-type="<?php echo esc_attr( $this->tab_slug ); ?>"> |
497 | 497 | <input type="hidden" name="page" value="<?php echo esc_attr( $this->tab_slug ); ?>" /> |
498 | 498 | |
@@ -518,13 +518,13 @@ discard block |
||
518 | 518 | <a class="button advanced-search-toggle" href="#"><?php esc_html_e( 'Bulk Search', 'lsx-wetu-importer' ); ?></a> |
519 | 519 | </form> |
520 | 520 | <?php |
521 | - } |
|
521 | + } |
|
522 | 522 | |
523 | - /** |
|
524 | - * The header of the item list |
|
525 | - */ |
|
526 | - public function table_header() { |
|
527 | - ?> |
|
523 | + /** |
|
524 | + * The header of the item list |
|
525 | + */ |
|
526 | + public function table_header() { |
|
527 | + ?> |
|
528 | 528 | <thead> |
529 | 529 | <tr> |
530 | 530 | <th style="" class="manage-column column-cb check-column no-sort" id="cb" scope="col"> |
@@ -538,13 +538,13 @@ discard block |
||
538 | 538 | </tr> |
539 | 539 | </thead> |
540 | 540 | <?php |
541 | - } |
|
541 | + } |
|
542 | 542 | |
543 | - /** |
|
544 | - * The footer of the item list |
|
545 | - */ |
|
546 | - public function table_footer() { |
|
547 | - ?> |
|
543 | + /** |
|
544 | + * The footer of the item list |
|
545 | + */ |
|
546 | + public function table_footer() { |
|
547 | + ?> |
|
548 | 548 | <tfoot> |
549 | 549 | <tr> |
550 | 550 | <th style="" class="manage-column column-cb check-column" id="cb" scope="col"> |
@@ -558,724 +558,724 @@ discard block |
||
558 | 558 | </tr> |
559 | 559 | </tfoot> |
560 | 560 | <?php |
561 | - } |
|
562 | - |
|
563 | - /** |
|
564 | - * Displays the importers navigation. |
|
565 | - * |
|
566 | - * @param $tab string |
|
567 | - */ |
|
568 | - public function navigation( $tab = '' ) { |
|
569 | - $post_types = array( |
|
570 | - 'tour' => esc_attr( 'Tours', 'lsx-wetu-importer' ), |
|
571 | - 'accommodation' => esc_attr( 'Accommodation', 'lsx-wetu-importer' ), |
|
572 | - 'destination' => esc_attr( 'Destinations', 'lsx-wetu-importer' ), |
|
573 | - ); |
|
574 | - |
|
575 | - echo wp_kses_post( '<div class="wp-filter">' ); |
|
576 | - echo wp_kses_post( '<ul class="filter-links">' ); |
|
577 | - echo wp_kses_post( '<li><a class="' . $this->itemd( $tab, 'default', 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '">' . esc_attr__( 'Home', 'lsx-wetu-importer' ) . '</a></li>' ); |
|
578 | - |
|
579 | - foreach ( $post_types as $post_type => $label ) { |
|
580 | - echo wp_kses_post( ' | <li><a class="' . $this->itemd( $tab, $post_type, 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '&tab=' . $post_type . '">' . $label . '</a></li>' ); |
|
581 | - } |
|
582 | - |
|
583 | - echo wp_kses_post( ' | <li><a class="' . $this->itemd( $tab, 'settings', 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '&tab=settings">' . esc_attr__( 'Settings', 'lsx-wetu-importer' ) . '</a></li>' ); |
|
584 | - echo wp_kses_post( '</ul> </div>' ); |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Wetu Status Bar. |
|
589 | - */ |
|
590 | - public function wetu_status() { |
|
591 | - $tours = get_transient( 'lsx_ti_tours' ); |
|
592 | - echo '<div class="wetu-status tour-wetu-status"><h3>' . esc_html__( 'Wetu Status', 'lsx-wetu-importer' ) . ' - '; |
|
593 | - |
|
594 | - if ( '' === $tours || false === $tours || isset( $_GET['refresh_tours'] ) ) { |
|
595 | - $result = $this->update_options(); |
|
596 | - if ( true === $result ) { |
|
597 | - echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span>'; |
|
598 | - echo ' - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>'; |
|
599 | - } else { |
|
600 | - echo '<span style="color:red;">' . wp_kses_post( $result ) . '</span>'; |
|
601 | - } |
|
602 | - } else { |
|
603 | - echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span> - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>'; |
|
604 | - } |
|
605 | - echo '</h3>'; |
|
606 | - echo '</div>'; |
|
607 | - } |
|
608 | - |
|
609 | - /** |
|
610 | - * Set_taxonomy with some terms |
|
611 | - */ |
|
612 | - public function team_member_checkboxes( $selected = array() ) { |
|
613 | - if ( post_type_exists( 'team' ) ) { |
|
614 | - ?> |
|
561 | + } |
|
562 | + |
|
563 | + /** |
|
564 | + * Displays the importers navigation. |
|
565 | + * |
|
566 | + * @param $tab string |
|
567 | + */ |
|
568 | + public function navigation( $tab = '' ) { |
|
569 | + $post_types = array( |
|
570 | + 'tour' => esc_attr( 'Tours', 'lsx-wetu-importer' ), |
|
571 | + 'accommodation' => esc_attr( 'Accommodation', 'lsx-wetu-importer' ), |
|
572 | + 'destination' => esc_attr( 'Destinations', 'lsx-wetu-importer' ), |
|
573 | + ); |
|
574 | + |
|
575 | + echo wp_kses_post( '<div class="wp-filter">' ); |
|
576 | + echo wp_kses_post( '<ul class="filter-links">' ); |
|
577 | + echo wp_kses_post( '<li><a class="' . $this->itemd( $tab, 'default', 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '">' . esc_attr__( 'Home', 'lsx-wetu-importer' ) . '</a></li>' ); |
|
578 | + |
|
579 | + foreach ( $post_types as $post_type => $label ) { |
|
580 | + echo wp_kses_post( ' | <li><a class="' . $this->itemd( $tab, $post_type, 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '&tab=' . $post_type . '">' . $label . '</a></li>' ); |
|
581 | + } |
|
582 | + |
|
583 | + echo wp_kses_post( ' | <li><a class="' . $this->itemd( $tab, 'settings', 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '&tab=settings">' . esc_attr__( 'Settings', 'lsx-wetu-importer' ) . '</a></li>' ); |
|
584 | + echo wp_kses_post( '</ul> </div>' ); |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Wetu Status Bar. |
|
589 | + */ |
|
590 | + public function wetu_status() { |
|
591 | + $tours = get_transient( 'lsx_ti_tours' ); |
|
592 | + echo '<div class="wetu-status tour-wetu-status"><h3>' . esc_html__( 'Wetu Status', 'lsx-wetu-importer' ) . ' - '; |
|
593 | + |
|
594 | + if ( '' === $tours || false === $tours || isset( $_GET['refresh_tours'] ) ) { |
|
595 | + $result = $this->update_options(); |
|
596 | + if ( true === $result ) { |
|
597 | + echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span>'; |
|
598 | + echo ' - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>'; |
|
599 | + } else { |
|
600 | + echo '<span style="color:red;">' . wp_kses_post( $result ) . '</span>'; |
|
601 | + } |
|
602 | + } else { |
|
603 | + echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span> - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>'; |
|
604 | + } |
|
605 | + echo '</h3>'; |
|
606 | + echo '</div>'; |
|
607 | + } |
|
608 | + |
|
609 | + /** |
|
610 | + * Set_taxonomy with some terms |
|
611 | + */ |
|
612 | + public function team_member_checkboxes( $selected = array() ) { |
|
613 | + if ( post_type_exists( 'team' ) ) { |
|
614 | + ?> |
|
615 | 615 | <ul> |
616 | 616 | <?php |
617 | - $team_args = array( |
|
618 | - 'post_type' => 'team', |
|
619 | - 'post_status' => 'publish', |
|
620 | - 'nopagin' => true, |
|
621 | - 'fields' => 'ids', |
|
622 | - ); |
|
623 | - |
|
624 | - $team_members = new WP_Query( $team_args ); |
|
625 | - |
|
626 | - if ( $team_members->have_posts() ) { |
|
627 | - foreach ( $team_members->posts as $member ) { |
|
628 | - ?> |
|
617 | + $team_args = array( |
|
618 | + 'post_type' => 'team', |
|
619 | + 'post_status' => 'publish', |
|
620 | + 'nopagin' => true, |
|
621 | + 'fields' => 'ids', |
|
622 | + ); |
|
623 | + |
|
624 | + $team_members = new WP_Query( $team_args ); |
|
625 | + |
|
626 | + if ( $team_members->have_posts() ) { |
|
627 | + foreach ( $team_members->posts as $member ) { |
|
628 | + ?> |
|
629 | 629 | <li><input class="team" <?php $this->checked( $selected, $member ); ?> type="checkbox" value="<?php echo esc_attr( $member ); ?>" /> <?php echo wp_kses_post( get_the_title( $member ) ); ?></li> |
630 | 630 | <?php |
631 | - } |
|
632 | - } else { |
|
633 | - ?> |
|
631 | + } |
|
632 | + } else { |
|
633 | + ?> |
|
634 | 634 | <li><input class="team" type="checkbox" value="0" /> <?php esc_html_e( 'None', 'lsx-wetu-importer' ); ?></li> |
635 | 635 | <?php |
636 | - } |
|
637 | - ?> |
|
636 | + } |
|
637 | + ?> |
|
638 | 638 | </ul> |
639 | 639 | <?php |
640 | - } |
|
641 | - } |
|
642 | - |
|
643 | - |
|
644 | - // GENERAL FUNCTIONS. |
|
645 | - |
|
646 | - /** |
|
647 | - * Checks to see if an item is checked. |
|
648 | - * |
|
649 | - * @param $haystack array|string |
|
650 | - * @param $needle string |
|
651 | - * @param $echo bool |
|
652 | - */ |
|
653 | - public function checked( $haystack = false, $needle = '', $echo = true ) { |
|
654 | - $return = $this->itemd( $haystack, $needle, 'checked', false ); |
|
655 | - |
|
656 | - if ( '' !== $return ) { |
|
657 | - if ( true === $echo ) { |
|
658 | - echo wp_kses_post( $return ); |
|
659 | - } else { |
|
660 | - return $return; |
|
661 | - } |
|
662 | - } |
|
663 | - } |
|
664 | - |
|
665 | - /** |
|
666 | - * Checks to see if an item is checked. |
|
667 | - * |
|
668 | - * @param $haystack array|string |
|
669 | - * @param $needle string |
|
670 | - * @param $echo bool |
|
671 | - */ |
|
672 | - public function selected( $haystack = false, $needle = '', $echo = true ) { |
|
673 | - $return = $this->itemd( $haystack, $needle, 'selected' ); |
|
674 | - |
|
675 | - if ( '' !== $return ) { |
|
676 | - if ( true === $echo ) { |
|
677 | - echo wp_kses_post( $return ); |
|
678 | - } else { |
|
679 | - return $return; |
|
680 | - } |
|
681 | - } |
|
682 | - } |
|
683 | - |
|
684 | - /** |
|
685 | - * Checks to see if an item is selected. If $echo is false, it will return the $type if conditions are true. |
|
686 | - * |
|
687 | - * @param $haystack array|string |
|
688 | - * @param $needle string |
|
689 | - * @param $type string |
|
690 | - * @param $wrap bool |
|
691 | - * @return $html string |
|
692 | - */ |
|
693 | - public function itemd( $haystack = false, $needle = '', $type = '', $wrap = true ) { |
|
694 | - $html = ''; |
|
695 | - |
|
696 | - if ( '' !== $type ) { |
|
697 | - if ( ! is_array( $haystack ) ) { |
|
698 | - $haystack = array( $haystack ); |
|
699 | - } |
|
700 | - if ( in_array( $needle, $haystack ) ) { |
|
701 | - if ( true === $wrap || 'true' === $wrap ) { |
|
702 | - $html = $type . '="' . $type . '"'; |
|
703 | - } else { |
|
704 | - $html = $type; |
|
705 | - } |
|
706 | - } |
|
707 | - } |
|
708 | - |
|
709 | - return $html; |
|
710 | - } |
|
711 | - |
|
712 | - /** |
|
713 | - * Grabs any attachments for the current item |
|
714 | - */ |
|
715 | - public function find_attachments( $id = false ) { |
|
716 | - if ( false !== $id ) { |
|
717 | - if ( empty( $this->found_attachments ) ) { |
|
718 | - $attachments_args = array( |
|
719 | - 'post_parent' => $id, |
|
720 | - 'post_status' => 'inherit', |
|
721 | - 'post_type' => 'attachment', |
|
722 | - 'order' => 'ASC', |
|
723 | - 'nopagin' => 'true', |
|
724 | - 'posts_per_page' => '-1', |
|
725 | - ); |
|
726 | - |
|
727 | - $attachments = new WP_Query( $attachments_args ); |
|
728 | - |
|
729 | - if ( $attachments->have_posts() ) { |
|
730 | - foreach ( $attachments->posts as $attachment ) { |
|
731 | - $this->found_attachments[ $attachment->ID ] = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $attachment->post_title ); |
|
732 | - } |
|
733 | - } |
|
734 | - } |
|
735 | - } |
|
736 | - } |
|
737 | - |
|
738 | - // CUSTOM FIELD FUNCTIONS. |
|
739 | - |
|
740 | - /** |
|
741 | - * Saves the room data |
|
742 | - */ |
|
743 | - public function save_custom_field( $value = false, $meta_key, $id, $decrease = false, $unique = true ) { |
|
744 | - if ( false !== $value ) { |
|
745 | - if ( false !== $decrease ) { |
|
746 | - $value = intval( $value ); |
|
747 | - $value--; |
|
748 | - } |
|
749 | - |
|
750 | - $prev = get_post_meta( $id, $meta_key, true ); |
|
751 | - |
|
752 | - if ( false !== $id && '0' !== $id && false !== $prev && true === $unique ) { |
|
753 | - update_post_meta( $id, $meta_key, $value, $prev ); |
|
754 | - } else { |
|
755 | - add_post_meta( $id, $meta_key, $value, $unique ); |
|
756 | - } |
|
757 | - } |
|
758 | - } |
|
759 | - |
|
760 | - /** |
|
761 | - * Grabs the custom fields, and resaves an array of unique items. |
|
762 | - */ |
|
763 | - public function cleanup_posts() { |
|
764 | - if ( ! empty( $this->cleanup_posts ) ) { |
|
765 | - |
|
766 | - foreach ( $this->cleanup_posts as $id => $key ) { |
|
767 | - $prev_items = get_post_meta( $id, $key, false ); |
|
768 | - $new_items = array_unique( $prev_items ); |
|
769 | - delete_post_meta( $id, $key ); |
|
770 | - |
|
771 | - foreach ( $new_items as $new_item ) { |
|
772 | - add_post_meta( $id, $key, $new_item, false ); |
|
773 | - } |
|
774 | - } |
|
775 | - } |
|
776 | - } |
|
777 | - |
|
778 | - // TAXONOMY FUNCTIONS. |
|
779 | - |
|
780 | - /** |
|
781 | - * Set_taxonomy with some terms |
|
782 | - */ |
|
783 | - public function set_taxonomy( $taxonomy, $terms, $id ) { |
|
784 | - $result = array(); |
|
785 | - |
|
786 | - if ( ! empty( $data ) ) { |
|
787 | - foreach ( $data as $k ) { |
|
788 | - if ( $id ) { |
|
789 | - $term = term_exists( trim( $k ), $tax ); |
|
790 | - if ( ! $term ) { |
|
791 | - $term = wp_insert_term( trim( $k ), $tax ); |
|
792 | - |
|
793 | - if ( is_wp_error( $term ) ) { |
|
794 | - echo wp_kses_post( $term->get_error_message() ); |
|
795 | - } else { |
|
796 | - wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
797 | - } |
|
798 | - } else { |
|
799 | - wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
800 | - } |
|
801 | - } else { |
|
802 | - $result[] = trim( $k ); |
|
803 | - } |
|
804 | - } |
|
805 | - } |
|
806 | - return $result; |
|
807 | - } |
|
808 | - |
|
809 | - /** |
|
810 | - * Sets the terms of the current post |
|
811 | - * |
|
812 | - * @param boolean $id |
|
813 | - * @param boolean $name |
|
814 | - * @param boolean $taxonomy |
|
815 | - * @param boolean $parent |
|
816 | - * @return void |
|
817 | - */ |
|
818 | - public function set_term( $id = false, $name = false, $taxonomy = false, $parent = false ) { |
|
819 | - $term = term_exists( $name, $taxonomy ); |
|
820 | - if ( ! $term ) { |
|
821 | - if ( false !== $parent ) { |
|
822 | - $parent = array( |
|
823 | - 'parent' => $parent, |
|
824 | - ); |
|
825 | - } |
|
826 | - $term = wp_insert_term( trim( $name ), $taxonomy, $parent ); |
|
827 | - |
|
828 | - if ( is_wp_error( $term ) ) { |
|
829 | - echo wp_kses_post( $term->get_error_message() ); |
|
830 | - } else { |
|
831 | - wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
832 | - } |
|
833 | - } else { |
|
834 | - wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
835 | - } |
|
836 | - |
|
837 | - return $term['term_id']; |
|
838 | - } |
|
839 | - |
|
840 | - /** |
|
841 | - * set_taxonomy with some terms |
|
842 | - */ |
|
843 | - public function taxonomy_checkboxes( $taxonomy = false, $selected = array() ) { |
|
844 | - $return = ''; |
|
845 | - |
|
846 | - if ( false !== $taxonomy ) { |
|
847 | - $return .= '<ul>'; |
|
848 | - $terms = get_terms( |
|
849 | - array( |
|
850 | - 'taxonomy' => $taxonomy, |
|
851 | - 'hide_empty' => false, |
|
852 | - ) |
|
853 | - ); |
|
854 | - |
|
855 | - if ( ! is_wp_error( $terms ) ) { |
|
856 | - foreach ( $terms as $term ) { |
|
857 | - $return .= '<li><input class="' . $taxonomy . '" ' . $this->checked( $selected, $term->term_id, false ) . ' type="checkbox" value="' . $term->term_id . '" /> ' . $term->name . '</li>'; |
|
858 | - } |
|
859 | - } else { |
|
860 | - $return .= '<li><input type="checkbox" value="" /> ' . __( 'None', 'lsx-wetu-importer' ) . '</li>'; |
|
861 | - } |
|
862 | - |
|
863 | - $return .= '</ul>'; |
|
864 | - } |
|
865 | - |
|
866 | - return $return; |
|
867 | - } |
|
868 | - |
|
869 | - // MAP FUNCTIONS |
|
870 | - |
|
871 | - /** |
|
872 | - * Saves the longitude and lattitude, as well as sets the map marker. |
|
873 | - */ |
|
874 | - public function set_map_data( $data, $id, $zoom = '10' ) { |
|
875 | - $longitude = false; |
|
876 | - $latitude = false; |
|
877 | - $address = false; |
|
878 | - |
|
879 | - if ( isset( $data[0]['position'] ) ) { |
|
880 | - if ( isset( $data[0]['position']['driving_latitude'] ) ) { |
|
881 | - $latitude = $data[0]['position']['driving_latitude']; |
|
882 | - } elseif ( isset( $data[0]['position']['latitude'] ) ) { |
|
883 | - $latitude = $data[0]['position']['latitude']; |
|
884 | - } |
|
885 | - |
|
886 | - if ( isset( $data[0]['position']['driving_longitude'] ) ) { |
|
887 | - $longitude = $data[0]['position']['driving_longitude']; |
|
888 | - } elseif ( isset( $data[0]['position']['longitude'] ) ) { |
|
889 | - $longitude = $data[0]['position']['longitude']; |
|
890 | - } |
|
891 | - } |
|
892 | - |
|
893 | - if ( isset( $data[0]['content'] ) && isset( $data[0]['content']['contact_information'] ) ) { |
|
894 | - if ( isset( $data[0]['content']['contact_information']['address'] ) ) { |
|
895 | - $address = strip_tags( $data[0]['content']['contact_information']['address'] ); |
|
896 | - $address = explode( "\n", $address ); |
|
897 | - |
|
898 | - foreach ( $address as $bitkey => $bit ) { |
|
899 | - $bit = ltrim( rtrim( $bit ) ); |
|
900 | - |
|
901 | - if ( false === $bit || '' === $bit || null === $bit || empty( $bit ) ) { |
|
902 | - unset( $address[ $bitkey ] ); |
|
903 | - } |
|
904 | - } |
|
905 | - |
|
906 | - $address = implode( ', ', $address ); |
|
907 | - $address = str_replace( ', , ', ', ', $address ); |
|
908 | - } |
|
909 | - } |
|
910 | - |
|
911 | - if ( false !== $longitude ) { |
|
912 | - $location_data = array( |
|
913 | - 'address' => (string) $address, |
|
914 | - 'lat' => (string) $latitude, |
|
915 | - 'long' => (string) $longitude, |
|
916 | - 'zoom' => (string) $zoom, |
|
917 | - 'elevation' => '', |
|
918 | - ); |
|
919 | - |
|
920 | - if ( false !== $id && '0' !== $id ) { |
|
921 | - $prev = get_post_meta( $id, 'location', true ); |
|
922 | - update_post_meta( $id, 'location', $location_data, $prev ); |
|
923 | - } else { |
|
924 | - add_post_meta( $id, 'location', $location_data, true ); |
|
925 | - } |
|
926 | - } |
|
927 | - } |
|
928 | - |
|
929 | - // IMAGE FUNCTIONS |
|
930 | - |
|
931 | - /** |
|
932 | - * Creates the main gallery data |
|
933 | - */ |
|
934 | - public function set_featured_image( $data, $id ) { |
|
935 | - if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
936 | - $this->featured_image = $this->attach_image( |
|
937 | - $data[0]['content']['images'][0], |
|
938 | - $id, |
|
939 | - array( |
|
940 | - 'width' => '800', |
|
941 | - 'height' => '600', |
|
942 | - 'cropping' => 'h', |
|
943 | - ) |
|
944 | - ); |
|
945 | - |
|
946 | - if ( false !== $this->featured_image ) { |
|
947 | - delete_post_meta( $id, '_thumbnail_id' ); |
|
948 | - add_post_meta( $id, '_thumbnail_id', $this->featured_image, true ); |
|
949 | - } |
|
950 | - } |
|
951 | - } |
|
952 | - |
|
953 | - /** |
|
954 | - * Sets a banner image |
|
955 | - */ |
|
956 | - public function set_banner_image( $data, $id, $content = array( 'none' ) ) { |
|
957 | - if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
958 | - if ( in_array( 'unique_banner_image', $content ) && isset( $data[0]['destination_image'] ) && is_array( $data[0]['destination_image'] ) ) { |
|
959 | - $temp_banner = $this->attach_image( |
|
960 | - $data[0]['destination_image'], |
|
961 | - $id, |
|
962 | - array( |
|
963 | - 'width' => '1920', |
|
964 | - 'height' => '600', |
|
965 | - 'cropping' => 'c', |
|
966 | - ) |
|
967 | - ); |
|
968 | - } else { |
|
969 | - $temp_banner = $this->attach_image( |
|
970 | - $data[0]['content']['images'][1], |
|
971 | - $id, |
|
972 | - array( |
|
973 | - 'width' => '1920', |
|
974 | - 'height' => '600', |
|
975 | - 'cropping' => 'c', |
|
976 | - ) |
|
977 | - ); |
|
978 | - } |
|
979 | - |
|
980 | - if ( false !== $temp_banner ) { |
|
981 | - $this->banner_image = $temp_banner; |
|
982 | - |
|
983 | - delete_post_meta( $id, 'image_group' ); |
|
984 | - |
|
985 | - $new_banner = array( |
|
986 | - 'banner_image' => array( |
|
987 | - 'cmb-field-0' => $this->banner_image, |
|
988 | - ), |
|
989 | - ); |
|
990 | - |
|
991 | - add_post_meta( $id, 'image_group', $new_banner, true ); |
|
992 | - } |
|
993 | - } |
|
994 | - } |
|
995 | - |
|
996 | - /** |
|
997 | - * Checks if the current image is being used as a thumbnail somewhere else. |
|
998 | - */ |
|
999 | - public function is_image_being_used( $image_id = '', $post_id = '' ) { |
|
1000 | - global $wpdb; |
|
1001 | - $being_used = false; |
|
1002 | - if ( '' !== $image_id ) { |
|
1003 | - $sql = "SELECT * FROM `{$wpdb->postmeta}` WHERE `post_id` != {$post_id} AND `meta_key` LIKE '_thumbnail_id' AND `meta_value` LIKE '{$image_id}'"; |
|
1004 | - $results = $wpdb->query( $sql ); |
|
1005 | - if ( false !== $results && ! empty( $results ) ) { |
|
1006 | - $being_used = true; |
|
1007 | - } |
|
1008 | - } |
|
1009 | - return $being_used; |
|
1010 | - } |
|
1011 | - |
|
1012 | - /** |
|
1013 | - * Creates the main gallery data |
|
1014 | - */ |
|
1015 | - public function create_main_gallery( $data, $id ) { |
|
1016 | - if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
1017 | - if ( isset( $this->options['image_replacing'] ) && 'on' === $this->options['image_replacing'] ) { |
|
1018 | - $current_gallery = get_post_meta( $id, 'gallery', false ); |
|
1019 | - |
|
1020 | - if ( false !== $current_gallery && ! empty( $current_gallery ) ) { |
|
1021 | - foreach ( $current_gallery as $g ) { |
|
1022 | - delete_post_meta( $id, 'gallery', $g ); |
|
1023 | - |
|
1024 | - if ( 'attachment' === get_post_type( $g ) && false === $this->is_image_being_used( $g, $id ) ) { |
|
1025 | - wp_delete_attachment( $g, true ); |
|
1026 | - } |
|
1027 | - } |
|
1028 | - } |
|
1029 | - } |
|
1030 | - |
|
1031 | - $counter = 0; |
|
1032 | - |
|
1033 | - foreach ( $data[0]['content']['images'] as $image_data ) { |
|
1034 | - if ( ( 0 === $counter && false !== $this->featured_image ) || ( 1 === $counter && false !== $this->banner_image ) ) { |
|
1035 | - $counter++; |
|
1036 | - |
|
1037 | - if ( false !== $this->image_limit && false !== $this->image_limit ) { |
|
1038 | - $this->image_limit++; |
|
1039 | - } |
|
1040 | - |
|
1041 | - continue; |
|
1042 | - } |
|
1043 | - |
|
1044 | - if ( false !== $this->image_limit && $counter >= $this->image_limit ) { |
|
1045 | - continue; |
|
1046 | - } |
|
1047 | - |
|
1048 | - $this->gallery_meta[] = $this->attach_image( $image_data, $id ); |
|
1049 | - $counter++; |
|
1050 | - } |
|
1051 | - |
|
1052 | - if ( ! empty( $this->gallery_meta ) ) { |
|
1053 | - delete_post_meta( $id, 'gallery' ); |
|
1054 | - $this->gallery_meta = array_unique( $this->gallery_meta ); |
|
1055 | - |
|
1056 | - foreach ( $this->gallery_meta as $gallery_id ) { |
|
1057 | - if ( false !== $gallery_id && '' !== $gallery_id && ! is_array( $gallery_id ) ) { |
|
1058 | - add_post_meta( $id, 'gallery', $gallery_id, false ); |
|
1059 | - } |
|
1060 | - } |
|
1061 | - } |
|
1062 | - } |
|
1063 | - } |
|
1064 | - |
|
1065 | - /** |
|
1066 | - * search_form |
|
1067 | - */ |
|
1068 | - public function get_scaling_url( $args = array() ) { |
|
1069 | - $defaults = array( |
|
1070 | - 'width' => '1024', |
|
1071 | - 'height' => '768', |
|
1072 | - // 'cropping' => 'w', |
|
1073 | - 'cropping' => 'h', |
|
1074 | - ); |
|
1075 | - |
|
1076 | - if ( false !== $this->options ) { |
|
1077 | - if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) { |
|
1078 | - $defaults['width'] = $this->options['width']; |
|
1079 | - } |
|
1080 | - |
|
1081 | - if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) { |
|
1082 | - $defaults['height'] = $this->options['height']; |
|
1083 | - } |
|
1084 | - |
|
1085 | - if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) { |
|
1086 | - $defaults['cropping'] = $this->options['cropping']; |
|
1087 | - } |
|
1088 | - } |
|
1089 | - |
|
1090 | - $args = wp_parse_args( $args, $defaults ); |
|
1091 | - $cropping = $args['cropping']; |
|
1092 | - $width = $args['width']; |
|
1093 | - $height = $args['height']; |
|
1094 | - |
|
1095 | - return 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/'; |
|
1096 | - } |
|
1097 | - |
|
1098 | - /** |
|
1099 | - * Attaches 1 image |
|
1100 | - */ |
|
1101 | - public function attach_image( $v = false, $parent_id, $image_sizes = false, $banner = false ) { |
|
1102 | - if ( false !== $v ) { |
|
1103 | - $temp_fragment = explode( '/', $v['url_fragment'] ); |
|
1104 | - $url_filename = $temp_fragment[ count( $temp_fragment ) - 1 ]; |
|
1105 | - $url_filename = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $url_filename ); |
|
1106 | - $url_filename = trim( $url_filename ); |
|
1107 | - $title = $url_filename; |
|
1108 | - $url_filename = str_replace( ' ', '_', $url_filename ); |
|
1109 | - |
|
1110 | - if ( ! isset( $this->options['image_replacing'] ) && in_array( $url_filename, $this->found_attachments ) ) { |
|
1111 | - return array_search( $url_filename, $this->found_attachments ); |
|
1112 | - } |
|
1113 | - |
|
1114 | - $postdata = array(); |
|
1115 | - |
|
1116 | - if ( empty( $v['label'] ) ) { |
|
1117 | - $v['label'] = ''; |
|
1118 | - } |
|
1119 | - |
|
1120 | - if ( ! empty( $v['description'] ) ) { |
|
1121 | - $desc = wp_strip_all_tags( $v['description'] ); |
|
1122 | - $posdata = array( |
|
1123 | - 'post_excerpt' => $desc, |
|
1124 | - ); |
|
1125 | - } |
|
1126 | - |
|
1127 | - if ( ! empty( $v['section'] ) ) { |
|
1128 | - $desc = wp_strip_all_tags( $v['section'] ); |
|
1129 | - $posdata = array( |
|
1130 | - 'post_excerpt' => $desc, |
|
1131 | - ); |
|
1132 | - } |
|
1133 | - |
|
1134 | - $attach_id = null; |
|
1135 | - // Resizor - add option to setting if required. |
|
1136 | - $fragment = str_replace( ' ', '%20', $v['url_fragment'] ); |
|
1137 | - $url = $this->get_scaling_url( $image_sizes ) . $fragment; |
|
1138 | - $attach_id = $this->attach_external_image2( $url, $parent_id, '', $v['label'], $postdata ); |
|
1139 | - if ( ! empty( $attach_id ) ) { |
|
1140 | - $this->found_attachments[ $attach_id ] = $url_filename; |
|
1141 | - add_post_meta( $attach_id, 'lsx_wetu_id', $v['url_fragment'], true ); |
|
1142 | - return $attach_id; |
|
1143 | - } |
|
1144 | - } |
|
1145 | - return false; |
|
1146 | - } |
|
1147 | - |
|
1148 | - public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
|
1149 | - if ( ! $url || ! $post_id ) { |
|
1150 | - return new WP_Error( 'missing', 'Need a valid URL and post ID...' ); } |
|
1151 | - $att_id = false; |
|
1152 | - |
|
1153 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
1154 | - require_once ABSPATH . 'wp-admin/includes/media.php'; |
|
1155 | - require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
1156 | - // Download file to temp location, returns full server path to temp file. |
|
1157 | - |
|
1158 | - $tmp = tempnam( '/tmp', 'FOO' ); |
|
1159 | - $image = wp_remote_get( $url ); |
|
1160 | - if ( ! is_wp_error( $image ) && ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) { |
|
1161 | - file_put_contents( $tmp, $image['body'] ); |
|
1162 | - chmod( $tmp, '777' ); |
|
1163 | - |
|
1164 | - preg_match( '/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches ); // fix file filename for query strings |
|
1165 | - $url_filename = basename( $matches[0] ); |
|
1166 | - $url_filename = str_replace( '%20', '_', $url_filename ); |
|
1167 | - // extract filename from url for title |
|
1168 | - $url_type = wp_check_filetype( $url_filename ); // determine file type (ext and mime/type) |
|
1169 | - |
|
1170 | - // override filename if given, reconstruct server path. |
|
1171 | - if ( ! empty( $filename ) && ' ' != $filename ) { |
|
1172 | - $filename = sanitize_file_name( $filename ); |
|
1173 | - $tmppath = pathinfo( $tmp ); |
|
1174 | - |
|
1175 | - $extension = ''; |
|
1176 | - if ( isset( $tmppath['extension'] ) ) { |
|
1177 | - $extension = $tmppath['extension']; |
|
1178 | - } |
|
1179 | - |
|
1180 | - $new = $tmppath['dirname'] . '/' . $filename . '.' . $extension; |
|
1181 | - rename( $tmp, $new ); // renames temp file on server |
|
1182 | - $tmp = $new; // push new filename (in path) to be used in file array later |
|
1183 | - } |
|
1184 | - |
|
1185 | - // assemble file data (should be built like $_FILES since wp_handle_sideload() will be using). |
|
1186 | - $file_array['tmp_name'] = $tmp; // full server path to temp file |
|
1187 | - |
|
1188 | - if ( ! empty( $filename ) && ' ' != $filename ) { |
|
1189 | - $file_array['name'] = $filename . '.' . $url_type['ext']; // user given filename for title, add original URL extension |
|
1190 | - } else { |
|
1191 | - $file_array['name'] = $url_filename; // just use original URL filename |
|
1192 | - } |
|
1193 | - |
|
1194 | - // set additional wp_posts columns. |
|
1195 | - if ( empty( $post_data['post_title'] ) ) { |
|
1196 | - |
|
1197 | - $url_filename = str_replace( '%20', ' ', $url_filename ); |
|
1198 | - |
|
1199 | - $post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] ); // just use the original filename (no extension) |
|
1200 | - } |
|
1201 | - |
|
1202 | - // make sure gets tied to parent. |
|
1203 | - if ( empty( $post_data['post_parent'] ) ) { |
|
1204 | - $post_data['post_parent'] = $post_id; |
|
1205 | - } |
|
1206 | - |
|
1207 | - // do the validation and storage stuff. |
|
1208 | - $att_id = media_handle_sideload( $file_array, $post_id, null, $post_data ); // $post_data can override the items saved to wp_posts table, like post_mime_type, guid, post_parent, post_title, post_content, post_status |
|
1209 | - |
|
1210 | - // If error storing permanently, unlink. |
|
1211 | - if ( is_wp_error( $att_id ) ) { |
|
1212 | - unlink( $file_array['tmp_name'] ); |
|
1213 | - return false; |
|
1214 | - } |
|
1215 | - } |
|
1216 | - return $att_id; |
|
1217 | - } |
|
1218 | - |
|
1219 | - // AJAX FUNCTIONS |
|
1220 | - /** |
|
1221 | - * Run through the accommodation grabbed from the DB. |
|
1222 | - */ |
|
1223 | - public function process_ajax_search() { |
|
1224 | - $this->current_importer->process_ajax_search(); |
|
1225 | - die(); |
|
1226 | - } |
|
1227 | - |
|
1228 | - /** |
|
1229 | - * Connect to wetu |
|
1230 | - */ |
|
1231 | - public function process_ajax_import() { |
|
1232 | - $this->current_importer->process_ajax_import(); |
|
1233 | - die(); |
|
1234 | - } |
|
1235 | - |
|
1236 | - /** |
|
1237 | - * Formats the row for the completed list. |
|
1238 | - */ |
|
1239 | - public function format_completed_row( $response ) { |
|
1240 | - echo wp_kses_post( '<li class="post-' . $response . '"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="' . get_permalink( $response ) . '">' . get_the_title( $response ) . '</a></li>' ); |
|
1241 | - } |
|
1242 | - |
|
1243 | - /** |
|
1244 | - * Formats the error. |
|
1245 | - */ |
|
1246 | - public function format_error( $response ) { |
|
1247 | - echo wp_kses_post( '<li class="post-error"><span class="dashicons dashicons-no"></span>' . $response . '</li>' ); |
|
1248 | - } |
|
1249 | - |
|
1250 | - /** |
|
1251 | - * Does a multine search |
|
1252 | - */ |
|
1253 | - public function multineedle_stripos( $haystack, $needles, $offset = 0 ) { |
|
1254 | - $found = false; |
|
1255 | - $needle_count = count( $needles ); |
|
1256 | - |
|
1257 | - foreach ( $needles as $needle ) { |
|
1258 | - if ( false !== stripos( $haystack, $needle, $offset ) ) { |
|
1259 | - $found[] = true; |
|
1260 | - } |
|
1261 | - } |
|
1262 | - |
|
1263 | - if ( false !== $found && count( $found ) === $needle_count ) { |
|
1264 | - return true; |
|
1265 | - } else { |
|
1266 | - return false; |
|
1267 | - } |
|
1268 | - } |
|
1269 | - |
|
1270 | - /** |
|
1271 | - * Grab all the current accommodation posts via the lsx_wetu_id field. |
|
1272 | - */ |
|
1273 | - public function find_current_accommodation( $post_type = 'accommodation' ) { |
|
1274 | - global $wpdb; |
|
1275 | - $return = array(); |
|
1276 | - |
|
1277 | - // @codingStandardsIgnoreStart |
|
1278 | - $current_accommodation = $wpdb->get_results(" |
|
640 | + } |
|
641 | + } |
|
642 | + |
|
643 | + |
|
644 | + // GENERAL FUNCTIONS. |
|
645 | + |
|
646 | + /** |
|
647 | + * Checks to see if an item is checked. |
|
648 | + * |
|
649 | + * @param $haystack array|string |
|
650 | + * @param $needle string |
|
651 | + * @param $echo bool |
|
652 | + */ |
|
653 | + public function checked( $haystack = false, $needle = '', $echo = true ) { |
|
654 | + $return = $this->itemd( $haystack, $needle, 'checked', false ); |
|
655 | + |
|
656 | + if ( '' !== $return ) { |
|
657 | + if ( true === $echo ) { |
|
658 | + echo wp_kses_post( $return ); |
|
659 | + } else { |
|
660 | + return $return; |
|
661 | + } |
|
662 | + } |
|
663 | + } |
|
664 | + |
|
665 | + /** |
|
666 | + * Checks to see if an item is checked. |
|
667 | + * |
|
668 | + * @param $haystack array|string |
|
669 | + * @param $needle string |
|
670 | + * @param $echo bool |
|
671 | + */ |
|
672 | + public function selected( $haystack = false, $needle = '', $echo = true ) { |
|
673 | + $return = $this->itemd( $haystack, $needle, 'selected' ); |
|
674 | + |
|
675 | + if ( '' !== $return ) { |
|
676 | + if ( true === $echo ) { |
|
677 | + echo wp_kses_post( $return ); |
|
678 | + } else { |
|
679 | + return $return; |
|
680 | + } |
|
681 | + } |
|
682 | + } |
|
683 | + |
|
684 | + /** |
|
685 | + * Checks to see if an item is selected. If $echo is false, it will return the $type if conditions are true. |
|
686 | + * |
|
687 | + * @param $haystack array|string |
|
688 | + * @param $needle string |
|
689 | + * @param $type string |
|
690 | + * @param $wrap bool |
|
691 | + * @return $html string |
|
692 | + */ |
|
693 | + public function itemd( $haystack = false, $needle = '', $type = '', $wrap = true ) { |
|
694 | + $html = ''; |
|
695 | + |
|
696 | + if ( '' !== $type ) { |
|
697 | + if ( ! is_array( $haystack ) ) { |
|
698 | + $haystack = array( $haystack ); |
|
699 | + } |
|
700 | + if ( in_array( $needle, $haystack ) ) { |
|
701 | + if ( true === $wrap || 'true' === $wrap ) { |
|
702 | + $html = $type . '="' . $type . '"'; |
|
703 | + } else { |
|
704 | + $html = $type; |
|
705 | + } |
|
706 | + } |
|
707 | + } |
|
708 | + |
|
709 | + return $html; |
|
710 | + } |
|
711 | + |
|
712 | + /** |
|
713 | + * Grabs any attachments for the current item |
|
714 | + */ |
|
715 | + public function find_attachments( $id = false ) { |
|
716 | + if ( false !== $id ) { |
|
717 | + if ( empty( $this->found_attachments ) ) { |
|
718 | + $attachments_args = array( |
|
719 | + 'post_parent' => $id, |
|
720 | + 'post_status' => 'inherit', |
|
721 | + 'post_type' => 'attachment', |
|
722 | + 'order' => 'ASC', |
|
723 | + 'nopagin' => 'true', |
|
724 | + 'posts_per_page' => '-1', |
|
725 | + ); |
|
726 | + |
|
727 | + $attachments = new WP_Query( $attachments_args ); |
|
728 | + |
|
729 | + if ( $attachments->have_posts() ) { |
|
730 | + foreach ( $attachments->posts as $attachment ) { |
|
731 | + $this->found_attachments[ $attachment->ID ] = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $attachment->post_title ); |
|
732 | + } |
|
733 | + } |
|
734 | + } |
|
735 | + } |
|
736 | + } |
|
737 | + |
|
738 | + // CUSTOM FIELD FUNCTIONS. |
|
739 | + |
|
740 | + /** |
|
741 | + * Saves the room data |
|
742 | + */ |
|
743 | + public function save_custom_field( $value = false, $meta_key, $id, $decrease = false, $unique = true ) { |
|
744 | + if ( false !== $value ) { |
|
745 | + if ( false !== $decrease ) { |
|
746 | + $value = intval( $value ); |
|
747 | + $value--; |
|
748 | + } |
|
749 | + |
|
750 | + $prev = get_post_meta( $id, $meta_key, true ); |
|
751 | + |
|
752 | + if ( false !== $id && '0' !== $id && false !== $prev && true === $unique ) { |
|
753 | + update_post_meta( $id, $meta_key, $value, $prev ); |
|
754 | + } else { |
|
755 | + add_post_meta( $id, $meta_key, $value, $unique ); |
|
756 | + } |
|
757 | + } |
|
758 | + } |
|
759 | + |
|
760 | + /** |
|
761 | + * Grabs the custom fields, and resaves an array of unique items. |
|
762 | + */ |
|
763 | + public function cleanup_posts() { |
|
764 | + if ( ! empty( $this->cleanup_posts ) ) { |
|
765 | + |
|
766 | + foreach ( $this->cleanup_posts as $id => $key ) { |
|
767 | + $prev_items = get_post_meta( $id, $key, false ); |
|
768 | + $new_items = array_unique( $prev_items ); |
|
769 | + delete_post_meta( $id, $key ); |
|
770 | + |
|
771 | + foreach ( $new_items as $new_item ) { |
|
772 | + add_post_meta( $id, $key, $new_item, false ); |
|
773 | + } |
|
774 | + } |
|
775 | + } |
|
776 | + } |
|
777 | + |
|
778 | + // TAXONOMY FUNCTIONS. |
|
779 | + |
|
780 | + /** |
|
781 | + * Set_taxonomy with some terms |
|
782 | + */ |
|
783 | + public function set_taxonomy( $taxonomy, $terms, $id ) { |
|
784 | + $result = array(); |
|
785 | + |
|
786 | + if ( ! empty( $data ) ) { |
|
787 | + foreach ( $data as $k ) { |
|
788 | + if ( $id ) { |
|
789 | + $term = term_exists( trim( $k ), $tax ); |
|
790 | + if ( ! $term ) { |
|
791 | + $term = wp_insert_term( trim( $k ), $tax ); |
|
792 | + |
|
793 | + if ( is_wp_error( $term ) ) { |
|
794 | + echo wp_kses_post( $term->get_error_message() ); |
|
795 | + } else { |
|
796 | + wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
797 | + } |
|
798 | + } else { |
|
799 | + wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
800 | + } |
|
801 | + } else { |
|
802 | + $result[] = trim( $k ); |
|
803 | + } |
|
804 | + } |
|
805 | + } |
|
806 | + return $result; |
|
807 | + } |
|
808 | + |
|
809 | + /** |
|
810 | + * Sets the terms of the current post |
|
811 | + * |
|
812 | + * @param boolean $id |
|
813 | + * @param boolean $name |
|
814 | + * @param boolean $taxonomy |
|
815 | + * @param boolean $parent |
|
816 | + * @return void |
|
817 | + */ |
|
818 | + public function set_term( $id = false, $name = false, $taxonomy = false, $parent = false ) { |
|
819 | + $term = term_exists( $name, $taxonomy ); |
|
820 | + if ( ! $term ) { |
|
821 | + if ( false !== $parent ) { |
|
822 | + $parent = array( |
|
823 | + 'parent' => $parent, |
|
824 | + ); |
|
825 | + } |
|
826 | + $term = wp_insert_term( trim( $name ), $taxonomy, $parent ); |
|
827 | + |
|
828 | + if ( is_wp_error( $term ) ) { |
|
829 | + echo wp_kses_post( $term->get_error_message() ); |
|
830 | + } else { |
|
831 | + wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
832 | + } |
|
833 | + } else { |
|
834 | + wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
835 | + } |
|
836 | + |
|
837 | + return $term['term_id']; |
|
838 | + } |
|
839 | + |
|
840 | + /** |
|
841 | + * set_taxonomy with some terms |
|
842 | + */ |
|
843 | + public function taxonomy_checkboxes( $taxonomy = false, $selected = array() ) { |
|
844 | + $return = ''; |
|
845 | + |
|
846 | + if ( false !== $taxonomy ) { |
|
847 | + $return .= '<ul>'; |
|
848 | + $terms = get_terms( |
|
849 | + array( |
|
850 | + 'taxonomy' => $taxonomy, |
|
851 | + 'hide_empty' => false, |
|
852 | + ) |
|
853 | + ); |
|
854 | + |
|
855 | + if ( ! is_wp_error( $terms ) ) { |
|
856 | + foreach ( $terms as $term ) { |
|
857 | + $return .= '<li><input class="' . $taxonomy . '" ' . $this->checked( $selected, $term->term_id, false ) . ' type="checkbox" value="' . $term->term_id . '" /> ' . $term->name . '</li>'; |
|
858 | + } |
|
859 | + } else { |
|
860 | + $return .= '<li><input type="checkbox" value="" /> ' . __( 'None', 'lsx-wetu-importer' ) . '</li>'; |
|
861 | + } |
|
862 | + |
|
863 | + $return .= '</ul>'; |
|
864 | + } |
|
865 | + |
|
866 | + return $return; |
|
867 | + } |
|
868 | + |
|
869 | + // MAP FUNCTIONS |
|
870 | + |
|
871 | + /** |
|
872 | + * Saves the longitude and lattitude, as well as sets the map marker. |
|
873 | + */ |
|
874 | + public function set_map_data( $data, $id, $zoom = '10' ) { |
|
875 | + $longitude = false; |
|
876 | + $latitude = false; |
|
877 | + $address = false; |
|
878 | + |
|
879 | + if ( isset( $data[0]['position'] ) ) { |
|
880 | + if ( isset( $data[0]['position']['driving_latitude'] ) ) { |
|
881 | + $latitude = $data[0]['position']['driving_latitude']; |
|
882 | + } elseif ( isset( $data[0]['position']['latitude'] ) ) { |
|
883 | + $latitude = $data[0]['position']['latitude']; |
|
884 | + } |
|
885 | + |
|
886 | + if ( isset( $data[0]['position']['driving_longitude'] ) ) { |
|
887 | + $longitude = $data[0]['position']['driving_longitude']; |
|
888 | + } elseif ( isset( $data[0]['position']['longitude'] ) ) { |
|
889 | + $longitude = $data[0]['position']['longitude']; |
|
890 | + } |
|
891 | + } |
|
892 | + |
|
893 | + if ( isset( $data[0]['content'] ) && isset( $data[0]['content']['contact_information'] ) ) { |
|
894 | + if ( isset( $data[0]['content']['contact_information']['address'] ) ) { |
|
895 | + $address = strip_tags( $data[0]['content']['contact_information']['address'] ); |
|
896 | + $address = explode( "\n", $address ); |
|
897 | + |
|
898 | + foreach ( $address as $bitkey => $bit ) { |
|
899 | + $bit = ltrim( rtrim( $bit ) ); |
|
900 | + |
|
901 | + if ( false === $bit || '' === $bit || null === $bit || empty( $bit ) ) { |
|
902 | + unset( $address[ $bitkey ] ); |
|
903 | + } |
|
904 | + } |
|
905 | + |
|
906 | + $address = implode( ', ', $address ); |
|
907 | + $address = str_replace( ', , ', ', ', $address ); |
|
908 | + } |
|
909 | + } |
|
910 | + |
|
911 | + if ( false !== $longitude ) { |
|
912 | + $location_data = array( |
|
913 | + 'address' => (string) $address, |
|
914 | + 'lat' => (string) $latitude, |
|
915 | + 'long' => (string) $longitude, |
|
916 | + 'zoom' => (string) $zoom, |
|
917 | + 'elevation' => '', |
|
918 | + ); |
|
919 | + |
|
920 | + if ( false !== $id && '0' !== $id ) { |
|
921 | + $prev = get_post_meta( $id, 'location', true ); |
|
922 | + update_post_meta( $id, 'location', $location_data, $prev ); |
|
923 | + } else { |
|
924 | + add_post_meta( $id, 'location', $location_data, true ); |
|
925 | + } |
|
926 | + } |
|
927 | + } |
|
928 | + |
|
929 | + // IMAGE FUNCTIONS |
|
930 | + |
|
931 | + /** |
|
932 | + * Creates the main gallery data |
|
933 | + */ |
|
934 | + public function set_featured_image( $data, $id ) { |
|
935 | + if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
936 | + $this->featured_image = $this->attach_image( |
|
937 | + $data[0]['content']['images'][0], |
|
938 | + $id, |
|
939 | + array( |
|
940 | + 'width' => '800', |
|
941 | + 'height' => '600', |
|
942 | + 'cropping' => 'h', |
|
943 | + ) |
|
944 | + ); |
|
945 | + |
|
946 | + if ( false !== $this->featured_image ) { |
|
947 | + delete_post_meta( $id, '_thumbnail_id' ); |
|
948 | + add_post_meta( $id, '_thumbnail_id', $this->featured_image, true ); |
|
949 | + } |
|
950 | + } |
|
951 | + } |
|
952 | + |
|
953 | + /** |
|
954 | + * Sets a banner image |
|
955 | + */ |
|
956 | + public function set_banner_image( $data, $id, $content = array( 'none' ) ) { |
|
957 | + if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
958 | + if ( in_array( 'unique_banner_image', $content ) && isset( $data[0]['destination_image'] ) && is_array( $data[0]['destination_image'] ) ) { |
|
959 | + $temp_banner = $this->attach_image( |
|
960 | + $data[0]['destination_image'], |
|
961 | + $id, |
|
962 | + array( |
|
963 | + 'width' => '1920', |
|
964 | + 'height' => '600', |
|
965 | + 'cropping' => 'c', |
|
966 | + ) |
|
967 | + ); |
|
968 | + } else { |
|
969 | + $temp_banner = $this->attach_image( |
|
970 | + $data[0]['content']['images'][1], |
|
971 | + $id, |
|
972 | + array( |
|
973 | + 'width' => '1920', |
|
974 | + 'height' => '600', |
|
975 | + 'cropping' => 'c', |
|
976 | + ) |
|
977 | + ); |
|
978 | + } |
|
979 | + |
|
980 | + if ( false !== $temp_banner ) { |
|
981 | + $this->banner_image = $temp_banner; |
|
982 | + |
|
983 | + delete_post_meta( $id, 'image_group' ); |
|
984 | + |
|
985 | + $new_banner = array( |
|
986 | + 'banner_image' => array( |
|
987 | + 'cmb-field-0' => $this->banner_image, |
|
988 | + ), |
|
989 | + ); |
|
990 | + |
|
991 | + add_post_meta( $id, 'image_group', $new_banner, true ); |
|
992 | + } |
|
993 | + } |
|
994 | + } |
|
995 | + |
|
996 | + /** |
|
997 | + * Checks if the current image is being used as a thumbnail somewhere else. |
|
998 | + */ |
|
999 | + public function is_image_being_used( $image_id = '', $post_id = '' ) { |
|
1000 | + global $wpdb; |
|
1001 | + $being_used = false; |
|
1002 | + if ( '' !== $image_id ) { |
|
1003 | + $sql = "SELECT * FROM `{$wpdb->postmeta}` WHERE `post_id` != {$post_id} AND `meta_key` LIKE '_thumbnail_id' AND `meta_value` LIKE '{$image_id}'"; |
|
1004 | + $results = $wpdb->query( $sql ); |
|
1005 | + if ( false !== $results && ! empty( $results ) ) { |
|
1006 | + $being_used = true; |
|
1007 | + } |
|
1008 | + } |
|
1009 | + return $being_used; |
|
1010 | + } |
|
1011 | + |
|
1012 | + /** |
|
1013 | + * Creates the main gallery data |
|
1014 | + */ |
|
1015 | + public function create_main_gallery( $data, $id ) { |
|
1016 | + if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
1017 | + if ( isset( $this->options['image_replacing'] ) && 'on' === $this->options['image_replacing'] ) { |
|
1018 | + $current_gallery = get_post_meta( $id, 'gallery', false ); |
|
1019 | + |
|
1020 | + if ( false !== $current_gallery && ! empty( $current_gallery ) ) { |
|
1021 | + foreach ( $current_gallery as $g ) { |
|
1022 | + delete_post_meta( $id, 'gallery', $g ); |
|
1023 | + |
|
1024 | + if ( 'attachment' === get_post_type( $g ) && false === $this->is_image_being_used( $g, $id ) ) { |
|
1025 | + wp_delete_attachment( $g, true ); |
|
1026 | + } |
|
1027 | + } |
|
1028 | + } |
|
1029 | + } |
|
1030 | + |
|
1031 | + $counter = 0; |
|
1032 | + |
|
1033 | + foreach ( $data[0]['content']['images'] as $image_data ) { |
|
1034 | + if ( ( 0 === $counter && false !== $this->featured_image ) || ( 1 === $counter && false !== $this->banner_image ) ) { |
|
1035 | + $counter++; |
|
1036 | + |
|
1037 | + if ( false !== $this->image_limit && false !== $this->image_limit ) { |
|
1038 | + $this->image_limit++; |
|
1039 | + } |
|
1040 | + |
|
1041 | + continue; |
|
1042 | + } |
|
1043 | + |
|
1044 | + if ( false !== $this->image_limit && $counter >= $this->image_limit ) { |
|
1045 | + continue; |
|
1046 | + } |
|
1047 | + |
|
1048 | + $this->gallery_meta[] = $this->attach_image( $image_data, $id ); |
|
1049 | + $counter++; |
|
1050 | + } |
|
1051 | + |
|
1052 | + if ( ! empty( $this->gallery_meta ) ) { |
|
1053 | + delete_post_meta( $id, 'gallery' ); |
|
1054 | + $this->gallery_meta = array_unique( $this->gallery_meta ); |
|
1055 | + |
|
1056 | + foreach ( $this->gallery_meta as $gallery_id ) { |
|
1057 | + if ( false !== $gallery_id && '' !== $gallery_id && ! is_array( $gallery_id ) ) { |
|
1058 | + add_post_meta( $id, 'gallery', $gallery_id, false ); |
|
1059 | + } |
|
1060 | + } |
|
1061 | + } |
|
1062 | + } |
|
1063 | + } |
|
1064 | + |
|
1065 | + /** |
|
1066 | + * search_form |
|
1067 | + */ |
|
1068 | + public function get_scaling_url( $args = array() ) { |
|
1069 | + $defaults = array( |
|
1070 | + 'width' => '1024', |
|
1071 | + 'height' => '768', |
|
1072 | + // 'cropping' => 'w', |
|
1073 | + 'cropping' => 'h', |
|
1074 | + ); |
|
1075 | + |
|
1076 | + if ( false !== $this->options ) { |
|
1077 | + if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) { |
|
1078 | + $defaults['width'] = $this->options['width']; |
|
1079 | + } |
|
1080 | + |
|
1081 | + if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) { |
|
1082 | + $defaults['height'] = $this->options['height']; |
|
1083 | + } |
|
1084 | + |
|
1085 | + if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) { |
|
1086 | + $defaults['cropping'] = $this->options['cropping']; |
|
1087 | + } |
|
1088 | + } |
|
1089 | + |
|
1090 | + $args = wp_parse_args( $args, $defaults ); |
|
1091 | + $cropping = $args['cropping']; |
|
1092 | + $width = $args['width']; |
|
1093 | + $height = $args['height']; |
|
1094 | + |
|
1095 | + return 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/'; |
|
1096 | + } |
|
1097 | + |
|
1098 | + /** |
|
1099 | + * Attaches 1 image |
|
1100 | + */ |
|
1101 | + public function attach_image( $v = false, $parent_id, $image_sizes = false, $banner = false ) { |
|
1102 | + if ( false !== $v ) { |
|
1103 | + $temp_fragment = explode( '/', $v['url_fragment'] ); |
|
1104 | + $url_filename = $temp_fragment[ count( $temp_fragment ) - 1 ]; |
|
1105 | + $url_filename = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $url_filename ); |
|
1106 | + $url_filename = trim( $url_filename ); |
|
1107 | + $title = $url_filename; |
|
1108 | + $url_filename = str_replace( ' ', '_', $url_filename ); |
|
1109 | + |
|
1110 | + if ( ! isset( $this->options['image_replacing'] ) && in_array( $url_filename, $this->found_attachments ) ) { |
|
1111 | + return array_search( $url_filename, $this->found_attachments ); |
|
1112 | + } |
|
1113 | + |
|
1114 | + $postdata = array(); |
|
1115 | + |
|
1116 | + if ( empty( $v['label'] ) ) { |
|
1117 | + $v['label'] = ''; |
|
1118 | + } |
|
1119 | + |
|
1120 | + if ( ! empty( $v['description'] ) ) { |
|
1121 | + $desc = wp_strip_all_tags( $v['description'] ); |
|
1122 | + $posdata = array( |
|
1123 | + 'post_excerpt' => $desc, |
|
1124 | + ); |
|
1125 | + } |
|
1126 | + |
|
1127 | + if ( ! empty( $v['section'] ) ) { |
|
1128 | + $desc = wp_strip_all_tags( $v['section'] ); |
|
1129 | + $posdata = array( |
|
1130 | + 'post_excerpt' => $desc, |
|
1131 | + ); |
|
1132 | + } |
|
1133 | + |
|
1134 | + $attach_id = null; |
|
1135 | + // Resizor - add option to setting if required. |
|
1136 | + $fragment = str_replace( ' ', '%20', $v['url_fragment'] ); |
|
1137 | + $url = $this->get_scaling_url( $image_sizes ) . $fragment; |
|
1138 | + $attach_id = $this->attach_external_image2( $url, $parent_id, '', $v['label'], $postdata ); |
|
1139 | + if ( ! empty( $attach_id ) ) { |
|
1140 | + $this->found_attachments[ $attach_id ] = $url_filename; |
|
1141 | + add_post_meta( $attach_id, 'lsx_wetu_id', $v['url_fragment'], true ); |
|
1142 | + return $attach_id; |
|
1143 | + } |
|
1144 | + } |
|
1145 | + return false; |
|
1146 | + } |
|
1147 | + |
|
1148 | + public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
|
1149 | + if ( ! $url || ! $post_id ) { |
|
1150 | + return new WP_Error( 'missing', 'Need a valid URL and post ID...' ); } |
|
1151 | + $att_id = false; |
|
1152 | + |
|
1153 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
1154 | + require_once ABSPATH . 'wp-admin/includes/media.php'; |
|
1155 | + require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
1156 | + // Download file to temp location, returns full server path to temp file. |
|
1157 | + |
|
1158 | + $tmp = tempnam( '/tmp', 'FOO' ); |
|
1159 | + $image = wp_remote_get( $url ); |
|
1160 | + if ( ! is_wp_error( $image ) && ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) { |
|
1161 | + file_put_contents( $tmp, $image['body'] ); |
|
1162 | + chmod( $tmp, '777' ); |
|
1163 | + |
|
1164 | + preg_match( '/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches ); // fix file filename for query strings |
|
1165 | + $url_filename = basename( $matches[0] ); |
|
1166 | + $url_filename = str_replace( '%20', '_', $url_filename ); |
|
1167 | + // extract filename from url for title |
|
1168 | + $url_type = wp_check_filetype( $url_filename ); // determine file type (ext and mime/type) |
|
1169 | + |
|
1170 | + // override filename if given, reconstruct server path. |
|
1171 | + if ( ! empty( $filename ) && ' ' != $filename ) { |
|
1172 | + $filename = sanitize_file_name( $filename ); |
|
1173 | + $tmppath = pathinfo( $tmp ); |
|
1174 | + |
|
1175 | + $extension = ''; |
|
1176 | + if ( isset( $tmppath['extension'] ) ) { |
|
1177 | + $extension = $tmppath['extension']; |
|
1178 | + } |
|
1179 | + |
|
1180 | + $new = $tmppath['dirname'] . '/' . $filename . '.' . $extension; |
|
1181 | + rename( $tmp, $new ); // renames temp file on server |
|
1182 | + $tmp = $new; // push new filename (in path) to be used in file array later |
|
1183 | + } |
|
1184 | + |
|
1185 | + // assemble file data (should be built like $_FILES since wp_handle_sideload() will be using). |
|
1186 | + $file_array['tmp_name'] = $tmp; // full server path to temp file |
|
1187 | + |
|
1188 | + if ( ! empty( $filename ) && ' ' != $filename ) { |
|
1189 | + $file_array['name'] = $filename . '.' . $url_type['ext']; // user given filename for title, add original URL extension |
|
1190 | + } else { |
|
1191 | + $file_array['name'] = $url_filename; // just use original URL filename |
|
1192 | + } |
|
1193 | + |
|
1194 | + // set additional wp_posts columns. |
|
1195 | + if ( empty( $post_data['post_title'] ) ) { |
|
1196 | + |
|
1197 | + $url_filename = str_replace( '%20', ' ', $url_filename ); |
|
1198 | + |
|
1199 | + $post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] ); // just use the original filename (no extension) |
|
1200 | + } |
|
1201 | + |
|
1202 | + // make sure gets tied to parent. |
|
1203 | + if ( empty( $post_data['post_parent'] ) ) { |
|
1204 | + $post_data['post_parent'] = $post_id; |
|
1205 | + } |
|
1206 | + |
|
1207 | + // do the validation and storage stuff. |
|
1208 | + $att_id = media_handle_sideload( $file_array, $post_id, null, $post_data ); // $post_data can override the items saved to wp_posts table, like post_mime_type, guid, post_parent, post_title, post_content, post_status |
|
1209 | + |
|
1210 | + // If error storing permanently, unlink. |
|
1211 | + if ( is_wp_error( $att_id ) ) { |
|
1212 | + unlink( $file_array['tmp_name'] ); |
|
1213 | + return false; |
|
1214 | + } |
|
1215 | + } |
|
1216 | + return $att_id; |
|
1217 | + } |
|
1218 | + |
|
1219 | + // AJAX FUNCTIONS |
|
1220 | + /** |
|
1221 | + * Run through the accommodation grabbed from the DB. |
|
1222 | + */ |
|
1223 | + public function process_ajax_search() { |
|
1224 | + $this->current_importer->process_ajax_search(); |
|
1225 | + die(); |
|
1226 | + } |
|
1227 | + |
|
1228 | + /** |
|
1229 | + * Connect to wetu |
|
1230 | + */ |
|
1231 | + public function process_ajax_import() { |
|
1232 | + $this->current_importer->process_ajax_import(); |
|
1233 | + die(); |
|
1234 | + } |
|
1235 | + |
|
1236 | + /** |
|
1237 | + * Formats the row for the completed list. |
|
1238 | + */ |
|
1239 | + public function format_completed_row( $response ) { |
|
1240 | + echo wp_kses_post( '<li class="post-' . $response . '"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="' . get_permalink( $response ) . '">' . get_the_title( $response ) . '</a></li>' ); |
|
1241 | + } |
|
1242 | + |
|
1243 | + /** |
|
1244 | + * Formats the error. |
|
1245 | + */ |
|
1246 | + public function format_error( $response ) { |
|
1247 | + echo wp_kses_post( '<li class="post-error"><span class="dashicons dashicons-no"></span>' . $response . '</li>' ); |
|
1248 | + } |
|
1249 | + |
|
1250 | + /** |
|
1251 | + * Does a multine search |
|
1252 | + */ |
|
1253 | + public function multineedle_stripos( $haystack, $needles, $offset = 0 ) { |
|
1254 | + $found = false; |
|
1255 | + $needle_count = count( $needles ); |
|
1256 | + |
|
1257 | + foreach ( $needles as $needle ) { |
|
1258 | + if ( false !== stripos( $haystack, $needle, $offset ) ) { |
|
1259 | + $found[] = true; |
|
1260 | + } |
|
1261 | + } |
|
1262 | + |
|
1263 | + if ( false !== $found && count( $found ) === $needle_count ) { |
|
1264 | + return true; |
|
1265 | + } else { |
|
1266 | + return false; |
|
1267 | + } |
|
1268 | + } |
|
1269 | + |
|
1270 | + /** |
|
1271 | + * Grab all the current accommodation posts via the lsx_wetu_id field. |
|
1272 | + */ |
|
1273 | + public function find_current_accommodation( $post_type = 'accommodation' ) { |
|
1274 | + global $wpdb; |
|
1275 | + $return = array(); |
|
1276 | + |
|
1277 | + // @codingStandardsIgnoreStart |
|
1278 | + $current_accommodation = $wpdb->get_results(" |
|
1279 | 1279 | SELECT key1.post_id,key1.meta_value |
1280 | 1280 | FROM {$wpdb->postmeta} key1 |
1281 | 1281 | |
@@ -1287,128 +1287,128 @@ discard block |
||
1287 | 1287 | |
1288 | 1288 | LIMIT 0,5000 |
1289 | 1289 | "); |
1290 | - // @codingStandardsIgnoreEnd |
|
1291 | - |
|
1292 | - if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) { |
|
1293 | - foreach ( $current_accommodation as $accom ) { |
|
1294 | - $return[ $accom->meta_value ] = $accom; |
|
1295 | - } |
|
1296 | - } |
|
1297 | - |
|
1298 | - return $return; |
|
1299 | - } |
|
1300 | - |
|
1301 | - /** |
|
1302 | - * Set the Video date |
|
1303 | - */ |
|
1304 | - public function set_video_data( $data, $id ) { |
|
1305 | - if ( ! empty( $data[0]['content']['youtube_videos'] ) && is_array( $data[0]['content']['youtube_videos'] ) ) { |
|
1306 | - $videos = false; |
|
1307 | - |
|
1308 | - foreach ( $data[0]['content']['youtube_videos'] as $video ) { |
|
1309 | - $temp_video = array(); |
|
1310 | - |
|
1311 | - if ( isset( $video['label'] ) ) { |
|
1312 | - $temp_video['title'] = $video['label']; |
|
1313 | - } |
|
1314 | - if ( isset( $video['description'] ) ) { |
|
1315 | - $temp_video['description'] = strip_tags( $video['description'] ); |
|
1316 | - } |
|
1317 | - if ( isset( $video['url'] ) ) { |
|
1318 | - $temp_video['url'] = $video['url']; |
|
1319 | - } |
|
1320 | - |
|
1321 | - $temp_video['thumbnail'] = ''; |
|
1322 | - $videos[] = $temp_video; |
|
1323 | - } |
|
1324 | - |
|
1325 | - if ( false !== $id && '0' !== $id ) { |
|
1326 | - delete_post_meta( $id, 'videos' ); |
|
1327 | - } |
|
1328 | - |
|
1329 | - foreach ( $videos as $video ) { |
|
1330 | - add_post_meta( $id, 'videos', $video, false ); |
|
1331 | - } |
|
1332 | - } |
|
1333 | - } |
|
1334 | - |
|
1335 | - public function shuffle_assoc( &$array ) { |
|
1336 | - $new = array(); |
|
1337 | - $keys = array_keys( $array ); |
|
1338 | - |
|
1339 | - shuffle( $keys ); |
|
1340 | - |
|
1341 | - foreach ( $keys as $key ) { |
|
1342 | - $new[ $key ] = $array[ $key ]; |
|
1343 | - } |
|
1344 | - |
|
1345 | - $array = $new; |
|
1346 | - |
|
1347 | - return true; |
|
1348 | - } |
|
1349 | - |
|
1350 | - /** |
|
1351 | - * Save the list of Tours into an option |
|
1352 | - */ |
|
1353 | - public function update_options() { |
|
1354 | - $own = ''; |
|
1355 | - $options = array(); |
|
1356 | - delete_option( 'lsx_ti_tours_api_options' ); |
|
1357 | - |
|
1358 | - if ( isset( $_GET['own'] ) ) { |
|
1359 | - $this->current_importer->url_qs .= '&own=true'; |
|
1360 | - $options[] = 'own'; |
|
1361 | - } |
|
1362 | - |
|
1363 | - if ( isset( $_GET['type'] ) && 'allitineraries' !== $_GET['type'] ) { |
|
1364 | - $this->current_importer->url_qs .= '&type=' . $_GET['type']; |
|
1365 | - $options[] = $_GET['type']; |
|
1366 | - } else { |
|
1367 | - $options[] = 'sample'; |
|
1368 | - $this->current_importer->url_qs .= '&type=sample'; |
|
1369 | - } |
|
1370 | - |
|
1371 | - $url = str_replace( 'Pins', 'Itinerary', $this->current_importer->url . '/V8/List?' . $this->current_importer->url_qs ); |
|
1372 | - $url .= '&results=2000'; |
|
1373 | - add_option( 'lsx_ti_tours_api_options', $options ); |
|
1374 | - $data = wp_remote_get( $url ); |
|
1375 | - $tours = json_decode( wp_remote_retrieve_body( $data ), true ); |
|
1376 | - |
|
1377 | - if ( isset( $tours['error'] ) ) { |
|
1378 | - return $tours['error']; |
|
1379 | - } elseif ( isset( $tours['itineraries'] ) && ! empty( $tours['itineraries'] ) ) { |
|
1380 | - set_transient( 'lsx_ti_tours', $tours['itineraries'], 60 * 60 * 4 ); |
|
1381 | - return true; |
|
1382 | - } |
|
1383 | - } |
|
1384 | - |
|
1385 | - /** |
|
1386 | - * Gets the post_id from the key |
|
1387 | - * |
|
1388 | - * @param boolean $wetu_id |
|
1389 | - * @return string |
|
1390 | - */ |
|
1391 | - public function get_post_id_by_key_value( $wetu_id = false ) { |
|
1392 | - global $wpdb; |
|
1393 | - $id = false; |
|
1394 | - if ( false !== $wetu_id && '' !== $wetu_id ) { |
|
1395 | - $result = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM `$wpdb->postmeta` WHERE `meta_key` = 'lsx_wetu_id' AND `meta_value` = '%s'", array( $wetu_id ) ) ); |
|
1396 | - if ( false !== $result && ! empty( $result ) ) { |
|
1397 | - $id = $result; |
|
1398 | - } |
|
1399 | - } |
|
1400 | - return $id; |
|
1401 | - } |
|
1402 | - /** |
|
1403 | - * Set the team memberon each item. |
|
1404 | - */ |
|
1405 | - public function set_team_member( $id, $team_members ) { |
|
1406 | - delete_post_meta( $id, 'team_to_' . $this->tab_slug ); |
|
1407 | - |
|
1408 | - foreach ( $team_members as $team ) { |
|
1409 | - add_post_meta( $id, 'team_to_' . $this->tab_slug, $team ); |
|
1410 | - } |
|
1411 | - } |
|
1290 | + // @codingStandardsIgnoreEnd |
|
1291 | + |
|
1292 | + if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) { |
|
1293 | + foreach ( $current_accommodation as $accom ) { |
|
1294 | + $return[ $accom->meta_value ] = $accom; |
|
1295 | + } |
|
1296 | + } |
|
1297 | + |
|
1298 | + return $return; |
|
1299 | + } |
|
1300 | + |
|
1301 | + /** |
|
1302 | + * Set the Video date |
|
1303 | + */ |
|
1304 | + public function set_video_data( $data, $id ) { |
|
1305 | + if ( ! empty( $data[0]['content']['youtube_videos'] ) && is_array( $data[0]['content']['youtube_videos'] ) ) { |
|
1306 | + $videos = false; |
|
1307 | + |
|
1308 | + foreach ( $data[0]['content']['youtube_videos'] as $video ) { |
|
1309 | + $temp_video = array(); |
|
1310 | + |
|
1311 | + if ( isset( $video['label'] ) ) { |
|
1312 | + $temp_video['title'] = $video['label']; |
|
1313 | + } |
|
1314 | + if ( isset( $video['description'] ) ) { |
|
1315 | + $temp_video['description'] = strip_tags( $video['description'] ); |
|
1316 | + } |
|
1317 | + if ( isset( $video['url'] ) ) { |
|
1318 | + $temp_video['url'] = $video['url']; |
|
1319 | + } |
|
1320 | + |
|
1321 | + $temp_video['thumbnail'] = ''; |
|
1322 | + $videos[] = $temp_video; |
|
1323 | + } |
|
1324 | + |
|
1325 | + if ( false !== $id && '0' !== $id ) { |
|
1326 | + delete_post_meta( $id, 'videos' ); |
|
1327 | + } |
|
1328 | + |
|
1329 | + foreach ( $videos as $video ) { |
|
1330 | + add_post_meta( $id, 'videos', $video, false ); |
|
1331 | + } |
|
1332 | + } |
|
1333 | + } |
|
1334 | + |
|
1335 | + public function shuffle_assoc( &$array ) { |
|
1336 | + $new = array(); |
|
1337 | + $keys = array_keys( $array ); |
|
1338 | + |
|
1339 | + shuffle( $keys ); |
|
1340 | + |
|
1341 | + foreach ( $keys as $key ) { |
|
1342 | + $new[ $key ] = $array[ $key ]; |
|
1343 | + } |
|
1344 | + |
|
1345 | + $array = $new; |
|
1346 | + |
|
1347 | + return true; |
|
1348 | + } |
|
1349 | + |
|
1350 | + /** |
|
1351 | + * Save the list of Tours into an option |
|
1352 | + */ |
|
1353 | + public function update_options() { |
|
1354 | + $own = ''; |
|
1355 | + $options = array(); |
|
1356 | + delete_option( 'lsx_ti_tours_api_options' ); |
|
1357 | + |
|
1358 | + if ( isset( $_GET['own'] ) ) { |
|
1359 | + $this->current_importer->url_qs .= '&own=true'; |
|
1360 | + $options[] = 'own'; |
|
1361 | + } |
|
1362 | + |
|
1363 | + if ( isset( $_GET['type'] ) && 'allitineraries' !== $_GET['type'] ) { |
|
1364 | + $this->current_importer->url_qs .= '&type=' . $_GET['type']; |
|
1365 | + $options[] = $_GET['type']; |
|
1366 | + } else { |
|
1367 | + $options[] = 'sample'; |
|
1368 | + $this->current_importer->url_qs .= '&type=sample'; |
|
1369 | + } |
|
1370 | + |
|
1371 | + $url = str_replace( 'Pins', 'Itinerary', $this->current_importer->url . '/V8/List?' . $this->current_importer->url_qs ); |
|
1372 | + $url .= '&results=2000'; |
|
1373 | + add_option( 'lsx_ti_tours_api_options', $options ); |
|
1374 | + $data = wp_remote_get( $url ); |
|
1375 | + $tours = json_decode( wp_remote_retrieve_body( $data ), true ); |
|
1376 | + |
|
1377 | + if ( isset( $tours['error'] ) ) { |
|
1378 | + return $tours['error']; |
|
1379 | + } elseif ( isset( $tours['itineraries'] ) && ! empty( $tours['itineraries'] ) ) { |
|
1380 | + set_transient( 'lsx_ti_tours', $tours['itineraries'], 60 * 60 * 4 ); |
|
1381 | + return true; |
|
1382 | + } |
|
1383 | + } |
|
1384 | + |
|
1385 | + /** |
|
1386 | + * Gets the post_id from the key |
|
1387 | + * |
|
1388 | + * @param boolean $wetu_id |
|
1389 | + * @return string |
|
1390 | + */ |
|
1391 | + public function get_post_id_by_key_value( $wetu_id = false ) { |
|
1392 | + global $wpdb; |
|
1393 | + $id = false; |
|
1394 | + if ( false !== $wetu_id && '' !== $wetu_id ) { |
|
1395 | + $result = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM `$wpdb->postmeta` WHERE `meta_key` = 'lsx_wetu_id' AND `meta_value` = '%s'", array( $wetu_id ) ) ); |
|
1396 | + if ( false !== $result && ! empty( $result ) ) { |
|
1397 | + $id = $result; |
|
1398 | + } |
|
1399 | + } |
|
1400 | + return $id; |
|
1401 | + } |
|
1402 | + /** |
|
1403 | + * Set the team memberon each item. |
|
1404 | + */ |
|
1405 | + public function set_team_member( $id, $team_members ) { |
|
1406 | + delete_post_meta( $id, 'team_to_' . $this->tab_slug ); |
|
1407 | + |
|
1408 | + foreach ( $team_members as $team ) { |
|
1409 | + add_post_meta( $id, 'team_to_' . $this->tab_slug, $team ); |
|
1410 | + } |
|
1411 | + } |
|
1412 | 1412 | } |
1413 | 1413 | |
1414 | 1414 | $lsx_wetu_importer = new LSX_WETU_Importer(); |
@@ -9,109 +9,109 @@ discard block |
||
9 | 9 | |
10 | 10 | class LSX_WETU_Importer_Tours extends LSX_WETU_Importer { |
11 | 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 = 'tour'; |
|
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 | - * Holds a list of any current accommodation |
|
41 | - * |
|
42 | - * @since 0.0.1 |
|
43 | - * |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - public $current_accommodation = false; |
|
47 | - |
|
48 | - /** |
|
49 | - * Holds a list of any current destinations |
|
50 | - * |
|
51 | - * @since 0.0.1 |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - public $current_destinations = false; |
|
56 | - |
|
57 | - /** |
|
58 | - * Holds a list of the destination and the image it needs to grab. |
|
59 | - * |
|
60 | - * @since 0.0.1 |
|
61 | - * |
|
62 | - * @var string |
|
63 | - */ |
|
64 | - public $destination_images = false; |
|
65 | - |
|
66 | - /** |
|
67 | - * Options |
|
68 | - * |
|
69 | - * @since 0.0.1 |
|
70 | - * |
|
71 | - * @var string |
|
72 | - */ |
|
73 | - public $options = false; |
|
74 | - |
|
75 | - /** |
|
76 | - * The fields you wish to import |
|
77 | - * |
|
78 | - * @since 0.0.1 |
|
79 | - * |
|
80 | - * @var string |
|
81 | - */ |
|
82 | - public $tour_options = false; |
|
83 | - |
|
84 | - /** |
|
85 | - * Initialize the plugin by setting localization, filters, and administration functions. |
|
86 | - * |
|
87 | - * @since 1.0.0 |
|
88 | - * |
|
89 | - * @access private |
|
90 | - */ |
|
91 | - public function __construct() { |
|
92 | - $this->set_variables(); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Sets the variables used throughout the plugin. |
|
97 | - */ |
|
98 | - public function set_variables() { |
|
99 | - parent::set_variables(); |
|
100 | - if ( false !== $this->api_key ) { |
|
101 | - $this->url = 'https://wetu.com/API/Itinerary/' . $this->api_key; |
|
102 | - $this->url_qs = ''; |
|
103 | - } |
|
104 | - $tour_options = get_option( 'lsx_wetu_importer_tour_settings', false ); |
|
105 | - if ( false !== $tour_options ) { |
|
106 | - $this->tour_options = $tour_options; |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Display the importer administration screen |
|
112 | - */ |
|
113 | - public function display_page() { |
|
114 | - ?> |
|
12 | + /** |
|
13 | + * The url to list items from WETU |
|
14 | + * |
|
15 | + * @since 0.0.1 |
|
16 | + * |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + public $tab_slug = 'tour'; |
|
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 | + * Holds a list of any current accommodation |
|
41 | + * |
|
42 | + * @since 0.0.1 |
|
43 | + * |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + public $current_accommodation = false; |
|
47 | + |
|
48 | + /** |
|
49 | + * Holds a list of any current destinations |
|
50 | + * |
|
51 | + * @since 0.0.1 |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + public $current_destinations = false; |
|
56 | + |
|
57 | + /** |
|
58 | + * Holds a list of the destination and the image it needs to grab. |
|
59 | + * |
|
60 | + * @since 0.0.1 |
|
61 | + * |
|
62 | + * @var string |
|
63 | + */ |
|
64 | + public $destination_images = false; |
|
65 | + |
|
66 | + /** |
|
67 | + * Options |
|
68 | + * |
|
69 | + * @since 0.0.1 |
|
70 | + * |
|
71 | + * @var string |
|
72 | + */ |
|
73 | + public $options = false; |
|
74 | + |
|
75 | + /** |
|
76 | + * The fields you wish to import |
|
77 | + * |
|
78 | + * @since 0.0.1 |
|
79 | + * |
|
80 | + * @var string |
|
81 | + */ |
|
82 | + public $tour_options = false; |
|
83 | + |
|
84 | + /** |
|
85 | + * Initialize the plugin by setting localization, filters, and administration functions. |
|
86 | + * |
|
87 | + * @since 1.0.0 |
|
88 | + * |
|
89 | + * @access private |
|
90 | + */ |
|
91 | + public function __construct() { |
|
92 | + $this->set_variables(); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Sets the variables used throughout the plugin. |
|
97 | + */ |
|
98 | + public function set_variables() { |
|
99 | + parent::set_variables(); |
|
100 | + if ( false !== $this->api_key ) { |
|
101 | + $this->url = 'https://wetu.com/API/Itinerary/' . $this->api_key; |
|
102 | + $this->url_qs = ''; |
|
103 | + } |
|
104 | + $tour_options = get_option( 'lsx_wetu_importer_tour_settings', false ); |
|
105 | + if ( false !== $tour_options ) { |
|
106 | + $this->tour_options = $tour_options; |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Display the importer administration screen |
|
112 | + */ |
|
113 | + public function display_page() { |
|
114 | + ?> |
|
115 | 115 | <div class="wrap"> |
116 | 116 | |
117 | 117 | <div class="tablenav top"> |
@@ -225,19 +225,19 @@ discard block |
||
225 | 225 | </div> |
226 | 226 | </div> |
227 | 227 | <?php |
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Displays the options for the form. |
|
232 | - * |
|
233 | - * @return void |
|
234 | - */ |
|
235 | - public function update_options_form() { |
|
236 | - $form_options = get_option( 'lsx_ti_tours_api_options' ); |
|
237 | - if ( false === $form_options ) { |
|
238 | - $form_options = array( 'sample' ); |
|
239 | - } |
|
240 | - ?> |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Displays the options for the form. |
|
232 | + * |
|
233 | + * @return void |
|
234 | + */ |
|
235 | + public function update_options_form() { |
|
236 | + $form_options = get_option( 'lsx_ti_tours_api_options' ); |
|
237 | + if ( false === $form_options ) { |
|
238 | + $form_options = array( 'sample' ); |
|
239 | + } |
|
240 | + ?> |
|
241 | 241 | <form method="get" class="tour-refresh-form"> |
242 | 242 | <input type="hidden" name="page" value="<?php echo esc_attr( $this->plugin_slug ); ?>" /> |
243 | 243 | <input type="hidden" name="tab" value="tour" /> |
@@ -247,31 +247,31 @@ discard block |
||
247 | 247 | <select name="type"> |
248 | 248 | <option |
249 | 249 | <?php |
250 | - if ( in_array( 'personal', $form_options ) ) { |
|
251 | - echo esc_attr( 'selected="selected"' ); } |
|
252 | - ?> |
|
250 | + if ( in_array( 'personal', $form_options ) ) { |
|
251 | + echo esc_attr( 'selected="selected"' ); } |
|
252 | + ?> |
|
253 | 253 | value="personal"><?php esc_html_e( 'Personal', 'lsx-wetu-importer' ); ?></option> |
254 | 254 | <option |
255 | 255 | <?php |
256 | - if ( in_array( 'sample', $form_options ) ) { |
|
257 | - echo esc_attr( 'selected="selected"' ); } |
|
258 | - ?> |
|
256 | + if ( in_array( 'sample', $form_options ) ) { |
|
257 | + echo esc_attr( 'selected="selected"' ); } |
|
258 | + ?> |
|
259 | 259 | value="sample"><?php esc_html_e( 'Sample', 'lsx-wetu-importer' ); ?></option> |
260 | 260 | </select> |
261 | 261 | <input class="button submit" type="submit" value="<?php esc_attr_e( 'Refresh', 'lsx-wetu-importer' ); ?>" /> |
262 | 262 | </form> |
263 | 263 | <?php |
264 | - } |
|
264 | + } |
|
265 | 265 | |
266 | - /** |
|
267 | - * Grab all the current tour posts via the lsx_wetu_id field. |
|
268 | - */ |
|
269 | - public function find_current_tours() { |
|
270 | - global $wpdb; |
|
271 | - $return = array(); |
|
266 | + /** |
|
267 | + * Grab all the current tour posts via the lsx_wetu_id field. |
|
268 | + */ |
|
269 | + public function find_current_tours() { |
|
270 | + global $wpdb; |
|
271 | + $return = array(); |
|
272 | 272 | |
273 | - $current_tours = $wpdb->get_results( |
|
274 | - " |
|
273 | + $current_tours = $wpdb->get_results( |
|
274 | + " |
|
275 | 275 | SELECT key1.post_id,key1.meta_value,key2.post_title |
276 | 276 | FROM {$wpdb->postmeta} key1 |
277 | 277 | |
@@ -283,138 +283,138 @@ discard block |
||
283 | 283 | |
284 | 284 | LIMIT 0,500 |
285 | 285 | " |
286 | - ); |
|
287 | - |
|
288 | - if ( null !== $current_tours && ! empty( $current_tours ) ) { |
|
289 | - foreach ( $current_tours as $tour ) { |
|
290 | - $return[ $tour->meta_value ] = $tour; |
|
291 | - } |
|
292 | - } |
|
293 | - |
|
294 | - return $return; |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Run through the accommodation grabbed from the DB. |
|
299 | - */ |
|
300 | - public function process_ajax_search() { |
|
301 | - $return = false; |
|
302 | - check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
303 | - |
|
304 | - if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug ) { |
|
305 | - $tours = get_transient( 'lsx_ti_tours' ); |
|
306 | - |
|
307 | - if ( false !== $tours ) { |
|
308 | - $searched_items = false; |
|
309 | - if ( isset( $_POST['keyword'] ) ) { |
|
310 | - $keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) ); |
|
311 | - } else { |
|
312 | - $keyphrases = array( 0 ); |
|
313 | - } |
|
314 | - |
|
315 | - if ( ! is_array( $keyphrases ) ) { |
|
316 | - $keyphrases = array( $keyphrases ); |
|
317 | - } |
|
318 | - foreach ( $keyphrases as &$keyword ) { |
|
319 | - $keyword = ltrim( rtrim( $keyword ) ); |
|
320 | - } |
|
321 | - |
|
322 | - $post_status = false; |
|
323 | - if ( in_array( 'publish', $keyphrases ) ) { |
|
324 | - $post_status = 'publish'; |
|
325 | - } |
|
326 | - if ( in_array( 'pending', $keyphrases ) ) { |
|
327 | - $post_status = 'pending'; |
|
328 | - } |
|
329 | - if ( in_array( 'draft', $keyphrases ) ) { |
|
330 | - $post_status = 'draft'; |
|
331 | - } |
|
332 | - if ( in_array( 'import', $keyphrases ) ) { |
|
333 | - $post_status = 'import'; |
|
334 | - } |
|
335 | - |
|
336 | - if ( ! empty( $tours ) ) { |
|
337 | - $current_tours = $this->find_current_tours(); |
|
338 | - |
|
339 | - foreach ( $tours as $row_key => $row ) { |
|
340 | - if ( isset( $row['is_disabled'] ) && true === $row['is_disabled'] ) { |
|
341 | - continue; |
|
342 | - } |
|
343 | - |
|
344 | - // If this is a current tour, add its ID to the row. |
|
345 | - $row['post_id'] = 0; |
|
346 | - $row['post_title'] = $row['name']; |
|
347 | - |
|
348 | - if ( false !== $current_tours && array_key_exists( $row['identifier'], $current_tours ) ) { |
|
349 | - $row['post_id'] = $current_tours[ $row['identifier'] ]->post_id; |
|
350 | - $row['post_title'] = $current_tours[ $row['identifier'] ]->post_title; |
|
351 | - } |
|
352 | - |
|
353 | - // If we are searching for. |
|
354 | - if ( false !== $post_status ) { |
|
355 | - if ( 'import' === $post_status ) { |
|
356 | - |
|
357 | - if ( 0 !== $row['post_id'] ) { |
|
358 | - continue; |
|
359 | - } else { |
|
360 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key ); |
|
361 | - } |
|
362 | - } else { |
|
363 | - if ( 0 === $row['post_id'] ) { |
|
364 | - continue; |
|
365 | - } else { |
|
366 | - $current_status = get_post_status( $row['post_id'] ); |
|
367 | - |
|
368 | - if ( $current_status !== $post_status ) { |
|
369 | - continue; |
|
370 | - } |
|
371 | - } |
|
372 | - |
|
373 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key ); |
|
374 | - } |
|
375 | - } else { |
|
376 | - // Search through each keyword. |
|
377 | - foreach ( $keyphrases as $keyphrase ) { |
|
378 | - |
|
379 | - // Make sure the keyphrase is turned into an array. |
|
380 | - $keywords = explode( ' ', $keyphrase ); |
|
381 | - if ( ! is_array( $keywords ) ) { |
|
382 | - $keywords = array( $keywords ); |
|
383 | - } |
|
384 | - |
|
385 | - if ( $this->multineedle_stripos( ltrim( rtrim( $row['name'] ) ), $keywords ) !== false ) { |
|
386 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key ); |
|
387 | - } elseif ( $this->multineedle_stripos( ltrim( rtrim( $row['reference_number'] ) ), $keywords ) !== false ) { |
|
388 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key ); |
|
389 | - } elseif ( $this->multineedle_stripos( ltrim( rtrim( $row['identifier_key'] ) ), $keywords ) !== false ) { |
|
390 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key ); |
|
391 | - } |
|
392 | - } |
|
393 | - } |
|
394 | - } |
|
395 | - } |
|
396 | - |
|
397 | - if ( false !== $searched_items ) { |
|
398 | - $return = implode( $searched_items ); |
|
399 | - } |
|
400 | - } |
|
401 | - print_r( $return ); |
|
402 | - die(); |
|
403 | - } |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * Formats the row for output on the screen. |
|
408 | - */ |
|
409 | - public function format_row( $row = false, $row_key = '' ) { |
|
410 | - if ( false !== $row ) { |
|
411 | - $status = 'import'; |
|
412 | - |
|
413 | - if ( 0 !== $row['post_id'] ) { |
|
414 | - $status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>'; |
|
415 | - } |
|
416 | - |
|
417 | - $row_html = ' |
|
286 | + ); |
|
287 | + |
|
288 | + if ( null !== $current_tours && ! empty( $current_tours ) ) { |
|
289 | + foreach ( $current_tours as $tour ) { |
|
290 | + $return[ $tour->meta_value ] = $tour; |
|
291 | + } |
|
292 | + } |
|
293 | + |
|
294 | + return $return; |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Run through the accommodation grabbed from the DB. |
|
299 | + */ |
|
300 | + public function process_ajax_search() { |
|
301 | + $return = false; |
|
302 | + check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
303 | + |
|
304 | + if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug ) { |
|
305 | + $tours = get_transient( 'lsx_ti_tours' ); |
|
306 | + |
|
307 | + if ( false !== $tours ) { |
|
308 | + $searched_items = false; |
|
309 | + if ( isset( $_POST['keyword'] ) ) { |
|
310 | + $keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) ); |
|
311 | + } else { |
|
312 | + $keyphrases = array( 0 ); |
|
313 | + } |
|
314 | + |
|
315 | + if ( ! is_array( $keyphrases ) ) { |
|
316 | + $keyphrases = array( $keyphrases ); |
|
317 | + } |
|
318 | + foreach ( $keyphrases as &$keyword ) { |
|
319 | + $keyword = ltrim( rtrim( $keyword ) ); |
|
320 | + } |
|
321 | + |
|
322 | + $post_status = false; |
|
323 | + if ( in_array( 'publish', $keyphrases ) ) { |
|
324 | + $post_status = 'publish'; |
|
325 | + } |
|
326 | + if ( in_array( 'pending', $keyphrases ) ) { |
|
327 | + $post_status = 'pending'; |
|
328 | + } |
|
329 | + if ( in_array( 'draft', $keyphrases ) ) { |
|
330 | + $post_status = 'draft'; |
|
331 | + } |
|
332 | + if ( in_array( 'import', $keyphrases ) ) { |
|
333 | + $post_status = 'import'; |
|
334 | + } |
|
335 | + |
|
336 | + if ( ! empty( $tours ) ) { |
|
337 | + $current_tours = $this->find_current_tours(); |
|
338 | + |
|
339 | + foreach ( $tours as $row_key => $row ) { |
|
340 | + if ( isset( $row['is_disabled'] ) && true === $row['is_disabled'] ) { |
|
341 | + continue; |
|
342 | + } |
|
343 | + |
|
344 | + // If this is a current tour, add its ID to the row. |
|
345 | + $row['post_id'] = 0; |
|
346 | + $row['post_title'] = $row['name']; |
|
347 | + |
|
348 | + if ( false !== $current_tours && array_key_exists( $row['identifier'], $current_tours ) ) { |
|
349 | + $row['post_id'] = $current_tours[ $row['identifier'] ]->post_id; |
|
350 | + $row['post_title'] = $current_tours[ $row['identifier'] ]->post_title; |
|
351 | + } |
|
352 | + |
|
353 | + // If we are searching for. |
|
354 | + if ( false !== $post_status ) { |
|
355 | + if ( 'import' === $post_status ) { |
|
356 | + |
|
357 | + if ( 0 !== $row['post_id'] ) { |
|
358 | + continue; |
|
359 | + } else { |
|
360 | + $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key ); |
|
361 | + } |
|
362 | + } else { |
|
363 | + if ( 0 === $row['post_id'] ) { |
|
364 | + continue; |
|
365 | + } else { |
|
366 | + $current_status = get_post_status( $row['post_id'] ); |
|
367 | + |
|
368 | + if ( $current_status !== $post_status ) { |
|
369 | + continue; |
|
370 | + } |
|
371 | + } |
|
372 | + |
|
373 | + $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key ); |
|
374 | + } |
|
375 | + } else { |
|
376 | + // Search through each keyword. |
|
377 | + foreach ( $keyphrases as $keyphrase ) { |
|
378 | + |
|
379 | + // Make sure the keyphrase is turned into an array. |
|
380 | + $keywords = explode( ' ', $keyphrase ); |
|
381 | + if ( ! is_array( $keywords ) ) { |
|
382 | + $keywords = array( $keywords ); |
|
383 | + } |
|
384 | + |
|
385 | + if ( $this->multineedle_stripos( ltrim( rtrim( $row['name'] ) ), $keywords ) !== false ) { |
|
386 | + $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key ); |
|
387 | + } elseif ( $this->multineedle_stripos( ltrim( rtrim( $row['reference_number'] ) ), $keywords ) !== false ) { |
|
388 | + $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key ); |
|
389 | + } elseif ( $this->multineedle_stripos( ltrim( rtrim( $row['identifier_key'] ) ), $keywords ) !== false ) { |
|
390 | + $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key ); |
|
391 | + } |
|
392 | + } |
|
393 | + } |
|
394 | + } |
|
395 | + } |
|
396 | + |
|
397 | + if ( false !== $searched_items ) { |
|
398 | + $return = implode( $searched_items ); |
|
399 | + } |
|
400 | + } |
|
401 | + print_r( $return ); |
|
402 | + die(); |
|
403 | + } |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * Formats the row for output on the screen. |
|
408 | + */ |
|
409 | + public function format_row( $row = false, $row_key = '' ) { |
|
410 | + if ( false !== $row ) { |
|
411 | + $status = 'import'; |
|
412 | + |
|
413 | + if ( 0 !== $row['post_id'] ) { |
|
414 | + $status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>'; |
|
415 | + } |
|
416 | + |
|
417 | + $row_html = ' |
|
418 | 418 | <tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '"> |
419 | 419 | <td class="check-column"> |
420 | 420 | <label for="cb-select-' . $row['identifier'] . '" class="screen-reader-text">' . $row['post_title'] . '</label> |
@@ -436,992 +436,992 @@ discard block |
||
436 | 436 | ' . $row['identifier'] . ' |
437 | 437 | </td> |
438 | 438 | </tr>'; |
439 | - return $row_html; |
|
440 | - } |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * Connect to wetu |
|
445 | - */ |
|
446 | - public function process_ajax_import( $force = false ) { |
|
447 | - $return = false; |
|
448 | - check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
449 | - if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug && isset( $_POST['wetu_id'] ) ) { |
|
450 | - |
|
451 | - $wetu_id = sanitize_text_field( $_POST['wetu_id'] ); |
|
452 | - if ( isset( $_POST['post_id'] ) ) { |
|
453 | - $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
454 | - } else { |
|
455 | - $post_id = 0; |
|
456 | - } |
|
457 | - |
|
458 | - delete_option( 'lsx_wetu_importer_tour_settings' ); |
|
459 | - |
|
460 | - if ( isset( $_POST['team_members'] ) ) { |
|
461 | - $team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) ); |
|
462 | - } else { |
|
463 | - $team_members = false; |
|
464 | - } |
|
465 | - |
|
466 | - if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) { |
|
467 | - $content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) ); |
|
468 | - add_option( 'lsx_wetu_importer_tour_settings', $content ); |
|
469 | - } else { |
|
470 | - $content = false; |
|
471 | - } |
|
472 | - $jdata = wp_remote_get( 'https://wetu.com/API/Itinerary/V8/Get?id=' . $wetu_id ); |
|
473 | - |
|
474 | - if ( ! is_wp_error( $jdata ) && ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) { |
|
475 | - $jdata = json_decode( $jdata['body'], true ); |
|
476 | - $return = $this->import_row( $jdata, $wetu_id, $post_id, $team_members, $content ); |
|
477 | - $this->format_completed_row( $return ); |
|
478 | - $this->save_queue(); |
|
479 | - $this->cleanup_posts(); |
|
480 | - $this->attach_destination_images( $content ); |
|
481 | - $this->clean_attached_destinations( $return ); |
|
482 | - } else { |
|
483 | - $this->format_error( esc_html__( 'There was a problem importing your tour, please try again.', 'lsx-wetu-importer' ) ); |
|
484 | - } |
|
485 | - } |
|
486 | - } |
|
487 | - |
|
488 | - /** |
|
489 | - * Amends the tours destinations instead of replace. |
|
490 | - * |
|
491 | - * @param $id string |
|
492 | - * @return void |
|
493 | - */ |
|
494 | - public function clean_attached_destinations( $id ) { |
|
495 | - $current_connections = get_post_meta( $id, 'destination_to_tour', false ); |
|
496 | - delete_post_meta( $id, 'destination_to_tour' ); |
|
497 | - $current_connections = array_unique( $current_connections ); |
|
498 | - |
|
499 | - foreach ( $current_connections as $connection ) { |
|
500 | - add_post_meta( $id, 'destination_to_tour', $connection, false ); |
|
501 | - } |
|
502 | - } |
|
503 | - |
|
504 | - /** |
|
505 | - * Connect to wetu |
|
506 | - * |
|
507 | - * @param $data array |
|
508 | - * @param $wetu_id string |
|
509 | - */ |
|
510 | - public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $old1 = false, $old2 = false ) { |
|
511 | - $post_name = ''; |
|
512 | - $data_post_content = ''; |
|
513 | - $data_post_excerpt = ''; |
|
514 | - |
|
515 | - $current_post = get_post( $id ); |
|
516 | - |
|
517 | - $post = array( |
|
518 | - 'post_type' => 'tour', |
|
519 | - ); |
|
520 | - |
|
521 | - $content_used_general_description = false; |
|
522 | - |
|
523 | - if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) { |
|
524 | - $data_post_content = $current_post->post_content; |
|
525 | - if ( isset( $data['summary'] ) && ! empty( $data['summary'] ) ) { |
|
526 | - $data_post_content = $data['summary']; |
|
527 | - } |
|
528 | - $post['post_content'] = $data_post_content; |
|
529 | - } |
|
530 | - |
|
531 | - // Create or update the post. |
|
532 | - if ( false !== $id && '0' !== $id ) { |
|
533 | - $post['ID'] = $id; |
|
534 | - $post['post_status'] = 'publish'; |
|
535 | - if ( isset( $this->options ) && 'on' !== $this->options['disable_accommodation_title'] ) { |
|
536 | - $post['post_title'] = $data['name']; |
|
537 | - } |
|
538 | - $id = wp_update_post( $post ); |
|
539 | - } else { |
|
540 | - // Set the name. |
|
541 | - if ( isset( $data['name'] ) ) { |
|
542 | - $post_name = wp_unique_post_slug( sanitize_title( $data['name'] ), $id, 'draft', 'tour', 0 ); |
|
543 | - } |
|
544 | - |
|
545 | - if ( ! isset( $post['post_content'] ) ) { |
|
546 | - $post['post_content'] = ' '; |
|
547 | - } |
|
548 | - |
|
549 | - $post['post_name'] = $post_name; |
|
550 | - $post['post_title'] = $data['name']; |
|
551 | - $post['post_status'] = 'publish'; |
|
552 | - $id = wp_insert_post( $post ); |
|
553 | - |
|
554 | - // Save the WETU ID and the Last date it was modified. |
|
555 | - if ( false !== $id ) { |
|
556 | - add_post_meta( $id, 'lsx_wetu_id', $wetu_id ); |
|
557 | - add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data['last_modified'] ) ); |
|
558 | - } |
|
559 | - } |
|
560 | - |
|
561 | - // Set reference number. |
|
562 | - $this->set_reference_number( $data, $id ); |
|
563 | - |
|
564 | - // Set the team member if it is there. |
|
565 | - if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) { |
|
566 | - $this->set_team_member( $id, $team_members ); |
|
567 | - } |
|
568 | - |
|
569 | - // Set the price. |
|
570 | - if ( false !== $importable_content && in_array( 'price', $importable_content ) ) { |
|
571 | - $this->set_price( $data, $id ); |
|
572 | - } |
|
573 | - |
|
574 | - // Set the Duration. |
|
575 | - if ( false !== $importable_content && in_array( 'duration', $importable_content ) ) { |
|
576 | - $this->set_duration( $data, $id ); |
|
577 | - } |
|
578 | - |
|
579 | - // Set the Group Size. |
|
580 | - if ( false !== $importable_content && in_array( 'group_size', $importable_content ) ) { |
|
581 | - $this->set_group_size( $data, $id ); |
|
582 | - } |
|
583 | - |
|
584 | - // Set the Group Size. |
|
585 | - if ( false !== $importable_content && in_array( 'tags', $importable_content ) ) { |
|
586 | - $this->set_travel_styles( $id, $data ); |
|
587 | - } |
|
588 | - |
|
589 | - // Set the Start and End Point Destinations. |
|
590 | - if ( false !== $importable_content && in_array( 'start_end_point', $importable_content ) ) { |
|
591 | - $this->set_start_end_point( $data, $id ); |
|
592 | - } |
|
593 | - |
|
594 | - if ( false !== $importable_content && in_array( 'itineraries', $importable_content ) && isset( $data['legs'] ) && ! empty( $data['legs'] ) ) { |
|
595 | - $this->process_itineraries( $data, $id, $importable_content ); |
|
596 | - } |
|
597 | - |
|
598 | - if ( in_array( 'map', $importable_content ) && isset( $data['routes'] ) && ! empty( $data['routes'] ) ) { |
|
599 | - $this->set_map_data( $data, $id ); |
|
600 | - } |
|
601 | - |
|
602 | - return $id; |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * A loop which runs through each leg on the tour. |
|
607 | - */ |
|
608 | - public function process_itineraries( $data, $id, $importable_content ) { |
|
609 | - $day_counter = 1; |
|
610 | - $leg_counter = 0; |
|
611 | - |
|
612 | - delete_post_meta( $id, 'itinerary' ); |
|
613 | - |
|
614 | - if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) { |
|
615 | - delete_post_meta( $id, 'accommodation_to_tour' ); |
|
616 | - } |
|
617 | - |
|
618 | - foreach ( $data['legs'] as $leg ) { |
|
619 | - |
|
620 | - // Itinerary Accommodation. |
|
621 | - $current_accommodation = false; |
|
622 | - $current_destination = false; |
|
623 | - if ( 'Mobile' !== $leg['type'] ) { |
|
624 | - if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) { |
|
625 | - $current_accommodation = $this->set_accommodation( $leg, $id ); |
|
626 | - } |
|
627 | - if ( false !== $importable_content && in_array( 'destination', $importable_content ) ) { |
|
628 | - $current_destination = $this->set_destination( $leg, $id, $leg_counter ); |
|
629 | - } |
|
630 | - } |
|
631 | - |
|
632 | - // If the Nights are the same mount of days in the array, then it isnt "By Destination". |
|
633 | - if ( ( 1 <= (int) $leg['nights'] && isset( $leg['periods'] ) ) || 0 === $leg['itinerary_leg_id'] ) { |
|
634 | - |
|
635 | - foreach ( $leg['periods'] as $day_key => $day ) { |
|
636 | - $current_day = array(); |
|
637 | - |
|
638 | - // If this is a moble tented solution. |
|
639 | - $next_day_count = $day_counter + (int) $day['days']; |
|
640 | - |
|
641 | - if ( ( isset( $leg['stops'] ) && 'Mobile' !== $leg['type'] ) || ( 1 < (int) $day['days'] ) ) { |
|
642 | - $day_count_label = ' - ' . ( $next_day_count - 1 ); |
|
643 | - } else { |
|
644 | - $day_count_label = ''; |
|
645 | - } |
|
646 | - $current_day['title'] = esc_attr( 'Day ', 'lsx-wetu-importer' ) . $day_counter . $day_count_label; |
|
647 | - |
|
648 | - // Description. |
|
649 | - if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $day['notes'] ) ) { |
|
650 | - $current_day['description'] = $day['notes']; |
|
651 | - } else { |
|
652 | - $current_day['description'] = ''; |
|
653 | - } |
|
654 | - |
|
655 | - // Itinerary Gallery. |
|
656 | - if ( false !== $importable_content && in_array( 'itinerary_gallery', $importable_content ) && isset( $day['images'] ) ) { |
|
657 | - $current_day['featured_image'] = ''; |
|
658 | - } else { |
|
659 | - $current_day['featured_image'] = ''; |
|
660 | - } |
|
661 | - |
|
662 | - // If its a mobile safari, we need to get the destination and accommodation data from the stops. |
|
663 | - if ( 'Mobile' === $leg['type'] ) { |
|
664 | - $current_destination = $this->get_mobile_destination( $day, $leg, $id ); |
|
665 | - $current_accommodation = $this->get_mobile_accommodation( $day, $leg, $id ); |
|
666 | - } |
|
667 | - |
|
668 | - // Accommodation. |
|
669 | - if ( false !== $current_accommodation ) { |
|
670 | - $current_day['accommodation_to_tour'] = array( $current_accommodation ); |
|
671 | - } else { |
|
672 | - $current_day['accommodation_to_tour'] = array(); |
|
673 | - } |
|
674 | - |
|
675 | - // Destination. |
|
676 | - if ( false !== $current_destination ) { |
|
677 | - $current_day['destination_to_tour'] = array( $current_destination ); |
|
678 | - } else { |
|
679 | - $current_day['destination_to_tour'] = array(); |
|
680 | - } |
|
681 | - |
|
682 | - // Included. |
|
683 | - if ( false !== $importable_content && in_array( 'itinerary_included', $importable_content ) && isset( $day['included'] ) && '' !== $day['included'] ) { |
|
684 | - $current_day['included'] = $day['included']; |
|
685 | - } else { |
|
686 | - $current_day['included'] = ''; |
|
687 | - } |
|
688 | - |
|
689 | - // Excluded. |
|
690 | - if ( false !== $importable_content && in_array( 'itinerary_excluded', $importable_content ) && isset( $day['excluded'] ) && '' !== $day['excluded'] ) { |
|
691 | - $current_day['excluded'] = $day['excluded']; |
|
692 | - } else { |
|
693 | - $current_day['excluded'] = ''; |
|
694 | - } |
|
695 | - |
|
696 | - // Excluded. |
|
697 | - if ( false !== $importable_content && in_array( 'room_basis', $importable_content ) && isset( $day['room_basis'] ) && '' !== $day['room_basis'] ) { |
|
698 | - $current_day['room_basis'] = $day['room_basis']; |
|
699 | - } else { |
|
700 | - $current_day['room_basis'] = ''; |
|
701 | - } |
|
702 | - |
|
703 | - // Excluded. |
|
704 | - if ( false !== $importable_content && in_array( 'drinks_basis', $importable_content ) && isset( $day['drinks_basis'] ) && '' !== $day['drinks_basis'] ) { |
|
705 | - $current_day['drinks_basis'] = $day['drinks_basis']; |
|
706 | - } else { |
|
707 | - $current_day['drinks_basis'] = ''; |
|
708 | - } |
|
709 | - |
|
710 | - $this->set_itinerary_day( $current_day, $id ); |
|
711 | - $day_counter = $next_day_count; |
|
712 | - } |
|
713 | - } else { |
|
714 | - // This is for the by destination. |
|
715 | - |
|
716 | - $current_day = array(); |
|
717 | - $next_day_count = $day_counter + (int) $leg['nights']; |
|
718 | - $day_count_label = $next_day_count - 1; |
|
719 | - |
|
720 | - $current_day['title'] = esc_attr( 'Day ', 'lsx-wetu-importer' ) . $day_counter; |
|
721 | - |
|
722 | - if ( 0 !== (int) $leg['nights'] ) { |
|
723 | - $current_day['title'] .= ' - ' . $day_count_label; |
|
724 | - } |
|
725 | - |
|
726 | - // Description. |
|
727 | - if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $leg['notes'] ) ) { |
|
728 | - $current_day['description'] = $leg['notes']; |
|
729 | - } else { |
|
730 | - $current_day['description'] = ''; |
|
731 | - } |
|
732 | - |
|
733 | - // Itinerary Gallery. |
|
734 | - if ( false !== $importable_content && in_array( 'itinerary_gallery', $importable_content ) && isset( $leg['images'] ) ) { |
|
735 | - $current_day['featured_image'] = ''; |
|
736 | - } else { |
|
737 | - $current_day['featured_image'] = ''; |
|
738 | - } |
|
739 | - |
|
740 | - // Accommodation. |
|
741 | - if ( false !== $current_accommodation ) { |
|
742 | - $current_day['accommodation_to_tour'] = array( $current_accommodation ); |
|
743 | - } else { |
|
744 | - $current_day['accommodation_to_tour'] = array(); |
|
745 | - } |
|
746 | - |
|
747 | - // Destination. |
|
748 | - if ( false !== $current_destination ) { |
|
749 | - $current_day['destination_to_tour'] = array( $current_destination ); |
|
750 | - } else { |
|
751 | - $current_day['destination_to_tour'] = array(); |
|
752 | - } |
|
753 | - |
|
754 | - // Included. |
|
755 | - if ( false !== $importable_content && in_array( 'itinerary_included', $importable_content ) && isset( $leg['included'] ) && '' !== $leg['included'] ) { |
|
756 | - $current_day['included'] = $leg['included']; |
|
757 | - } else { |
|
758 | - $current_day['included'] = ''; |
|
759 | - } |
|
760 | - |
|
761 | - // Excluded. |
|
762 | - if ( false !== $importable_content && in_array( 'itinerary_excluded', $importable_content ) && isset( $leg['excluded'] ) && '' !== $leg['excluded'] ) { |
|
763 | - $current_day['excluded'] = $leg['excluded']; |
|
764 | - } else { |
|
765 | - $current_day['excluded'] = ''; |
|
766 | - } |
|
767 | - |
|
768 | - // Excluded. |
|
769 | - if ( false !== $importable_content && in_array( 'room_basis', $importable_content ) && isset( $leg['room_basis'] ) && '' !== $leg['room_basis'] ) { |
|
770 | - $current_day['room_basis'] = $leg['room_basis']; |
|
771 | - } else { |
|
772 | - $current_day['room_basis'] = ''; |
|
773 | - } |
|
774 | - |
|
775 | - // Excluded. |
|
776 | - if ( false !== $importable_content && in_array( 'drinks_basis', $importable_content ) && isset( $leg['drinks_basis'] ) && '' !== $leg['drinks_basis'] ) { |
|
777 | - $current_day['drinks_basis'] = $leg['drinks_basis']; |
|
778 | - } else { |
|
779 | - $current_day['drinks_basis'] = ''; |
|
780 | - } |
|
781 | - |
|
782 | - $this->set_itinerary_day( $current_day, $id ); |
|
783 | - $day_counter = $next_day_count; |
|
784 | - } |
|
785 | - $leg_counter++; |
|
786 | - } |
|
787 | - } |
|
788 | - |
|
789 | - /** |
|
790 | - * Sets the departs from and ends in points on the tours. |
|
791 | - * |
|
792 | - * @param array $data |
|
793 | - * @param string $id |
|
794 | - * @return void |
|
795 | - */ |
|
796 | - public function set_start_end_point( $data, $id ) { |
|
797 | - delete_post_meta( $id, 'departs_from' ); |
|
798 | - delete_post_meta( $id, 'ends_in' ); |
|
799 | - $departs_from = false; |
|
800 | - $ends_in = false; |
|
801 | - |
|
802 | - $args = array( |
|
803 | - 'points' => $data['legs'], |
|
804 | - 'start_index' => 0, |
|
805 | - 'end_index' => count( $data['legs'] ) - 2, |
|
806 | - ); |
|
807 | - $args = apply_filters( 'lsx_wetu_start_end_args', $args, $data ); |
|
808 | - |
|
809 | - if ( ! empty( $args['points'] ) && is_array( $args['points'] ) ) { |
|
810 | - $leg_counter = 0; |
|
811 | - |
|
812 | - foreach ( $args['points'] as $point ) { |
|
813 | - // If we are in the first leg, and the destination was attached then save it as the departure field. |
|
814 | - if ( $leg_counter === $args['start_index'] ) { |
|
815 | - $departs_from_destination = $this->set_country( $point['destination_content_entity_id'], $id ); |
|
816 | - if ( false !== $departs_from_destination ) { |
|
817 | - $departs_from = $departs_from_destination; |
|
818 | - } |
|
819 | - } |
|
820 | - // If its the last leg then save it as the ends in. |
|
821 | - if ( $leg_counter === $args['end_index'] ) { |
|
822 | - $ends_in = $point['destination_content_entity_id']; |
|
823 | - } |
|
824 | - $leg_counter++; |
|
825 | - } |
|
826 | - |
|
827 | - $departs_from = apply_filters( 'lsx_wetu_departs_from_id', $departs_from, $data, $this ); |
|
828 | - if ( false !== $departs_from ) { |
|
829 | - add_post_meta( $id, 'departs_from', $departs_from, true ); |
|
830 | - } |
|
831 | - |
|
832 | - if ( false !== $ends_in ) { |
|
833 | - $ends_in = apply_filters( 'lsx_wetu_ends_in_id', $ends_in, $data, $this ); |
|
834 | - $ends_in_destination = $this->set_country( $ends_in, $id ); |
|
835 | - if ( false !== $ends_in_destination ) { |
|
836 | - add_post_meta( $id, 'ends_in', $ends_in_destination, true ); |
|
837 | - } |
|
838 | - } |
|
839 | - } |
|
840 | - } |
|
841 | - |
|
842 | - /** |
|
843 | - * Gets the destination for the mobile camp. |
|
844 | - * |
|
845 | - * @param $day |
|
846 | - * @param $leg |
|
847 | - * @return void |
|
848 | - */ |
|
849 | - public function get_mobile_destination( $day, $leg, $id ) { |
|
850 | - $current_destination = false; |
|
851 | - $current_day = (int) $day['period_start_day']; |
|
852 | - if ( isset( $leg['stops'] ) ) { |
|
853 | - foreach ( $leg['stops'] as $stop ) { |
|
854 | - $arrival_day = (int) $stop['arrival_day']; |
|
855 | - $departure_day = (int) $stop['departure_day']; |
|
856 | - if ( $arrival_day <= $current_day && $current_day < $departure_day ) { |
|
857 | - $current_destination = $this->set_destination( $stop, $id, 0 ); |
|
858 | - } |
|
859 | - } |
|
860 | - } |
|
861 | - return $current_destination; |
|
862 | - } |
|
863 | - |
|
864 | - /** |
|
865 | - * Gets the accommodation for the mobile camp. |
|
866 | - * |
|
867 | - * @param $day |
|
868 | - * @param $leg |
|
869 | - * @return void |
|
870 | - */ |
|
871 | - public function get_mobile_accommodation( $day, $leg, $id ) { |
|
872 | - $current_accommodation = false; |
|
873 | - $current_day = (int) $day['period_start_day']; |
|
874 | - if ( isset( $leg['stops'] ) ) { |
|
875 | - foreach ( $leg['stops'] as $stop ) { |
|
876 | - $arrival_day = (int) $stop['arrival_day']; |
|
877 | - $departure_day = (int) $stop['departure_day']; |
|
878 | - if ( $arrival_day <= $current_day && $current_day < $departure_day ) { |
|
879 | - $current_accommodation = $this->set_accommodation( $stop, $id, 0 ); |
|
880 | - } |
|
881 | - } |
|
882 | - } |
|
883 | - return $current_accommodation; |
|
884 | - } |
|
885 | - |
|
886 | - /** |
|
887 | - * Run through your routes and save the points as a KML file. |
|
888 | - */ |
|
889 | - public function set_map_data( $data, $id, $zoom = 9 ) { |
|
890 | - if ( ! empty( $data['routes'] ) ) { |
|
891 | - delete_post_meta( $id, 'wetu_map_points' ); |
|
892 | - |
|
893 | - $points = array(); |
|
894 | - |
|
895 | - foreach ( $data['routes'] as $route ) { |
|
896 | - |
|
897 | - if ( isset( $route['points'] ) && '' !== $route['points'] ) { |
|
898 | - |
|
899 | - $temp_points = explode( ';', $route['points'] ); |
|
900 | - $point_counter = count( $temp_points ); |
|
901 | - |
|
902 | - for ( $x = 0; $x <= $point_counter; $x++ ) { |
|
903 | - $y = $x + 1; |
|
904 | - $points[] = $temp_points[ $x ] . ',' . $temp_points[ $y ]; |
|
905 | - $x++; |
|
906 | - } |
|
907 | - } |
|
908 | - } |
|
909 | - |
|
910 | - if ( ! empty( $points ) ) { |
|
911 | - $this->save_custom_field( implode( ' ', $points ), 'wetu_map_points', $id, false, true ); |
|
912 | - } |
|
913 | - } |
|
914 | - |
|
915 | - } |
|
916 | - |
|
917 | - // CLASS SPECIFIC FUNCTIONS. |
|
918 | - |
|
919 | - /** |
|
920 | - * Set the Itinerary Day. |
|
921 | - */ |
|
922 | - public function set_itinerary_day( $day, $id ) { |
|
923 | - $this->save_custom_field( $day, 'itinerary', $id, false, false ); |
|
924 | - } |
|
925 | - |
|
926 | - /** |
|
927 | - * Set the ref number |
|
928 | - */ |
|
929 | - public function set_reference_number( $data, $id ) { |
|
930 | - if ( isset( $data['reference_number'] ) && '' !== $data['reference_number'] ) { |
|
931 | - $this->save_custom_field( $data['reference_number'], 'lsx_wetu_ref', $id ); |
|
932 | - } |
|
933 | - } |
|
934 | - |
|
935 | - /** |
|
936 | - * Set the price. |
|
937 | - */ |
|
938 | - public function set_price( $data, $id ) { |
|
939 | - // Price. |
|
940 | - if ( isset( $data['price'] ) && '' !== $data['price'] ) { |
|
941 | - $price = $data['price']; |
|
942 | - if ( false === apply_filters( 'lsx_wetu_importer_disable_tour_price_filter', false ) ) { |
|
943 | - $price = preg_replace( '/[^0-9,.]/', '', $price ); |
|
944 | - } |
|
945 | - $meta_key = apply_filters( 'lsx_wetu_importer_price_meta_key', 'price' ); |
|
946 | - $this->save_custom_field( $price, $meta_key, $id ); |
|
947 | - } |
|
948 | - |
|
949 | - // Price includes. |
|
950 | - if ( isset( $data['price_includes'] ) && '' !== $data['price_includes'] ) { |
|
951 | - $meta_key = apply_filters( 'lsx_wetu_importer_included_meta_key', 'included' ); |
|
952 | - $this->save_custom_field( $data['price_includes'], $meta_key, $id ); |
|
953 | - } |
|
954 | - |
|
955 | - // Price Excludes. |
|
956 | - if ( isset( $data['price_excludes'] ) && '' !== $data['price_excludes'] ) { |
|
957 | - $meta_key = apply_filters( 'lsx_wetu_importer_not_included_meta_key', 'not_included' ); |
|
958 | - $this->save_custom_field( $data['price_excludes'], $meta_key, $id ); |
|
959 | - } |
|
960 | - } |
|
961 | - |
|
962 | - /** |
|
963 | - * Set the duration. |
|
964 | - */ |
|
965 | - public function set_duration( $data, $id ) { |
|
966 | - if ( isset( $data['days'] ) && ! empty( $data['days'] ) ) { |
|
967 | - $price = $data['days']; |
|
968 | - $price = preg_replace( '/[^0-9,.]/', '', $price ); |
|
969 | - $this->save_custom_field( $price, 'duration', $id ); |
|
970 | - } |
|
971 | - } |
|
972 | - |
|
973 | - /** |
|
974 | - * Set the group size |
|
975 | - */ |
|
976 | - public function set_group_size( $data, $id ) { |
|
977 | - if ( isset( $data['group_size'] ) && ! empty( $data['group_size'] ) ) { |
|
978 | - $group_size = $data['group_size']; |
|
979 | - $this->save_custom_field( $group_size, 'group_size', $id ); |
|
980 | - } |
|
981 | - } |
|
982 | - |
|
983 | - /** |
|
984 | - * Takes the WETU tags and sets the Travel Styles. |
|
985 | - * |
|
986 | - * @param string $id |
|
987 | - * @param array $travel_styles |
|
988 | - * @return void |
|
989 | - */ |
|
990 | - public function set_travel_styles( $id, $data ) { |
|
991 | - $tags = apply_filters( 'lsx_wetu_importer_tour_travel_styles', $data['tags'] ); |
|
992 | - if ( isset( $data['tags'] ) && ! empty( $tags ) ) { |
|
993 | - foreach ( $tags as $tag ) { |
|
994 | - $this->set_term( $id, $tag, 'travel-style' ); |
|
995 | - } |
|
996 | - } |
|
997 | - } |
|
998 | - |
|
999 | - /** |
|
1000 | - * Connects the Accommodation if its available |
|
1001 | - */ |
|
1002 | - public function set_accommodation( $day, $id ) { |
|
1003 | - $ac_id = false; |
|
1004 | - $this->current_accommodation = $this->find_current_accommodation(); |
|
1005 | - |
|
1006 | - if ( isset( $day['content_entity_id'] ) && ! empty( $day['content_entity_id'] ) ) { |
|
1007 | - if ( false !== $this->current_accommodation && ! empty( $this->current_accommodation ) && array_key_exists( $day['content_entity_id'], $this->current_accommodation ) ) { |
|
1008 | - $ac_id = $this->current_accommodation[ $day['content_entity_id'] ]; |
|
1009 | - } else { |
|
1010 | - $ac_id = wp_insert_post( |
|
1011 | - array( |
|
1012 | - 'post_type' => 'accommodation', |
|
1013 | - 'post_status' => 'draft', |
|
1014 | - 'post_title' => $day['content_entity_id'], |
|
1015 | - ) |
|
1016 | - ); |
|
1017 | - |
|
1018 | - $this->save_custom_field( $day['content_entity_id'], 'lsx_wetu_id', $ac_id ); |
|
1019 | - } |
|
1020 | - |
|
1021 | - if ( '' !== $ac_id && false !== $ac_id ) { |
|
1022 | - $this->save_custom_field( $ac_id, 'accommodation_to_tour', $id, false, false ); |
|
1023 | - $this->save_custom_field( $id, 'tour_to_accommodation', $ac_id, false, false ); |
|
1024 | - $this->queue_item( $ac_id ); |
|
1025 | - } |
|
1026 | - } |
|
1027 | - return $ac_id; |
|
1028 | - } |
|
1029 | - |
|
1030 | - /** |
|
1031 | - * Grab all the current accommodation posts via the lsx_wetu_id field. |
|
1032 | - * |
|
1033 | - * @param $post_type string |
|
1034 | - * @return boolean / array |
|
1035 | - */ |
|
1036 | - public function find_current_accommodation( $post_type = 'accommodation' ) { |
|
1037 | - global $wpdb; |
|
1038 | - $accommodation = parent::find_current_accommodation( $post_type ); |
|
1039 | - $return = false; |
|
1040 | - |
|
1041 | - if ( ! empty( $accommodation ) ) { |
|
1042 | - foreach ( $accommodation as $key => $acc ) { |
|
1043 | - $return[ $acc->meta_value ] = $acc->post_id; |
|
1044 | - } |
|
1045 | - } |
|
1046 | - |
|
1047 | - return $return; |
|
1048 | - } |
|
1049 | - |
|
1050 | - /** |
|
1051 | - * Grab all the current accommodation posts via the lsx_wetu_id field. |
|
1052 | - * |
|
1053 | - * @return boolean / array |
|
1054 | - */ |
|
1055 | - public function find_current_destinations() { |
|
1056 | - return $this->find_current_accommodation( 'destination' ); |
|
1057 | - } |
|
1058 | - |
|
1059 | - /** |
|
1060 | - * Connects the destinations post type |
|
1061 | - * |
|
1062 | - * @param $day array |
|
1063 | - * @param $id string |
|
1064 | - * @return boolean / string |
|
1065 | - */ |
|
1066 | - public function set_destination( $day, $id, $leg_counter ) { |
|
1067 | - $dest_id = false; |
|
1068 | - $country_id = false; |
|
1069 | - |
|
1070 | - $this->current_destinations = $this->find_current_destinations(); |
|
1071 | - |
|
1072 | - if ( isset( $day['destination_content_entity_id'] ) && ! empty( $day['destination_content_entity_id'] ) ) { |
|
1073 | - if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $day['destination_content_entity_id'], $this->current_destinations ) ) { |
|
1074 | - $dest_id = $this->current_destinations[ $day['destination_content_entity_id'] ]; |
|
1075 | - |
|
1076 | - // TODO Check for attachments here. |
|
1077 | - $this->destination_images[ $id ][] = array( $dest_id, $day['destination_content_entity_id'] ); |
|
1078 | - |
|
1079 | - // Check if there is a country asigned. |
|
1080 | - $potential_id = wp_get_post_parent_id( $dest_id ); |
|
1081 | - $country_wetu_id = get_post_meta( $potential_id, 'lsx_wetu_id', true ); |
|
1082 | - |
|
1083 | - if ( false !== $country_wetu_id ) { |
|
1084 | - $country_id = $this->set_country( $country_wetu_id, $id ); |
|
1085 | - // $this->destination_images[ $id ][] = array( $id, $country_wetu_id ); |
|
1086 | - } |
|
1087 | - } else { |
|
1088 | - $destination_json = wp_remote_get( 'https://wetu.com/API/Pins/' . $this->api_key . '/Get?ids=' . $day['destination_content_entity_id'] ); |
|
1089 | - |
|
1090 | - if ( ! is_wp_error( $destination_json ) && ! empty( $destination_json ) && isset( $destination_json['response'] ) && isset( $destination_json['response']['code'] ) && 200 === $destination_json['response']['code'] ) { |
|
1091 | - |
|
1092 | - $destination_data = json_decode( $destination_json['body'], true ); |
|
1093 | - |
|
1094 | - if ( ! empty( $destination_data ) && ! isset( $destination_data['error'] ) ) { |
|
1095 | - $destination_title = $day['destination_content_entity_id']; |
|
1096 | - |
|
1097 | - if ( isset( $destination_data[0]['name'] ) ) { |
|
1098 | - $destination_title = $destination_data[0]['name']; |
|
1099 | - } |
|
1100 | - |
|
1101 | - if ( isset( $destination_data[0]['map_object_id'] ) && isset( $destination_data[0]['position']['country_content_entity_id'] ) |
|
1102 | - && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id'] ) { |
|
1103 | - |
|
1104 | - $country_id = $this->set_country( $destination_data[0]['position']['country_content_entity_id'], $id ); |
|
1105 | - // Save the destination so we can grab the tour featured image and banner from them. |
|
1106 | - } |
|
1107 | - |
|
1108 | - $dest_post = array( |
|
1109 | - 'post_type' => 'destination', |
|
1110 | - 'post_status' => 'draft', |
|
1111 | - 'post_title' => $destination_title, |
|
1112 | - ); |
|
1113 | - |
|
1114 | - if ( false !== $country_id ) { |
|
1115 | - $dest_post['post_parent'] = $country_id; |
|
1116 | - } |
|
1117 | - $dest_id = wp_insert_post( $dest_post ); |
|
1118 | - |
|
1119 | - // Make sure we register the. |
|
1120 | - $this->current_destinations[ $day['destination_content_entity_id'] ] = $dest_id; |
|
1121 | - |
|
1122 | - // If there are images attached then use the destination. |
|
1123 | - if ( isset( $destination_data[0]['content']['images'] ) && ! empty( $destination_data[0]['content']['images'] ) ) { |
|
1124 | - $this->destination_images[ $id ][] = array( $dest_id, $day['destination_content_entity_id'] ); |
|
1125 | - } |
|
1126 | - |
|
1127 | - $this->save_custom_field( $day['destination_content_entity_id'], 'lsx_wetu_id', $dest_id ); |
|
1128 | - } |
|
1129 | - } |
|
1130 | - } |
|
1131 | - |
|
1132 | - if ( '' !== $dest_id && false !== $dest_id ) { |
|
1133 | - $this->save_custom_field( $dest_id, 'destination_to_tour', $id, false, false ); |
|
1134 | - $this->save_custom_field( $id, 'tour_to_destination', $dest_id, false, false ); |
|
1135 | - |
|
1136 | - // Save the item to display in the queue |
|
1137 | - $this->queue_item( $dest_id ); |
|
1138 | - |
|
1139 | - // Save the item to clean up the amount of connections. |
|
1140 | - $this->cleanup_posts[ $dest_id ] = 'tour_to_destination'; |
|
1141 | - |
|
1142 | - // Add this relation info so we can make sure certain items are set as countries. |
|
1143 | - if ( 0 !== $country_id && false !== $country_id ) { |
|
1144 | - $this->relation_meta[ $dest_id ] = $country_id; |
|
1145 | - $this->relation_meta[ $country_id ] = 0; |
|
1146 | - } else { |
|
1147 | - $this->relation_meta[ $dest_id ] = 0; |
|
1148 | - } |
|
1149 | - } |
|
1150 | - } |
|
1151 | - return $dest_id; |
|
1152 | - } |
|
1153 | - |
|
1154 | - /** |
|
1155 | - * Connects the destinations post type |
|
1156 | - * |
|
1157 | - * @param $dest_id string |
|
1158 | - * @param $country_id array |
|
1159 | - * @param $id string |
|
1160 | - * |
|
1161 | - * @return string |
|
1162 | - */ |
|
1163 | - public function set_country( $country_wetu_id, $id ) { |
|
1164 | - $country_id = false; |
|
1165 | - $this->current_destinations = $this->find_current_destinations(); |
|
1166 | - |
|
1167 | - if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $country_wetu_id, $this->current_destinations ) ) { |
|
1168 | - $country_id = $this->current_destinations[ $country_wetu_id ]; |
|
1169 | - $this->destination_images[ $id ][] = array( $country_id, $country_wetu_id ); |
|
1170 | - } else { |
|
1171 | - $country_json = wp_remote_get( 'https://wetu.com/API/Pins/' . $this->api_key . '/Get?ids=' . $country_wetu_id ); |
|
1172 | - |
|
1173 | - if ( ! is_wp_error( $country_json ) && ! empty( $country_json ) && isset( $country_json['response'] ) && isset( $country_json['response']['code'] ) && 200 === $country_json['response']['code'] ) { |
|
1174 | - $country_data = json_decode( $country_json['body'], true ); |
|
1175 | - |
|
1176 | - // Format the title of the destination if its available, otherwise default to the WETU ID. |
|
1177 | - $country_title = $country_wetu_id; |
|
1178 | - |
|
1179 | - if ( isset( $country_data[0]['name'] ) ) { |
|
1180 | - $country_title = $country_data[0]['name']; |
|
1181 | - } |
|
1182 | - |
|
1183 | - $country_id = wp_insert_post( |
|
1184 | - array( |
|
1185 | - 'post_type' => 'destination', |
|
1186 | - 'post_status' => 'draft', |
|
1187 | - 'post_title' => $country_title, |
|
1188 | - ) |
|
1189 | - ); |
|
1190 | - |
|
1191 | - // add the country to the current destination stack |
|
1192 | - $this->current_destinations[ $country_wetu_id ] = $country_id; |
|
1193 | - |
|
1194 | - // Check if there are images and save fore use later. |
|
1195 | - if ( isset( $country_data[0]['content']['images'] ) && ! empty( $country_data[0]['content']['images'] ) ) { |
|
1196 | - $this->destination_images[ $id ][] = array( $country_id, $country_wetu_id ); |
|
1197 | - } |
|
1198 | - |
|
1199 | - // Save the wetu field |
|
1200 | - $this->save_custom_field( $country_wetu_id, 'lsx_wetu_id', $country_id ); |
|
1201 | - } |
|
1202 | - } |
|
1203 | - |
|
1204 | - if ( '' !== $country_id && false !== $country_id ) { |
|
1205 | - $this->save_custom_field( $country_id, 'destination_to_tour', $id, false, false ); |
|
1206 | - $this->save_custom_field( $id, 'tour_to_destination', $country_id, false, false ); |
|
1207 | - $this->queue_item( $country_id ); |
|
1208 | - $this->cleanup_posts[ $country_id ] = 'tour_to_destination'; |
|
1209 | - |
|
1210 | - return $country_id; |
|
1211 | - } |
|
1212 | - } |
|
1213 | - |
|
1214 | - /** |
|
1215 | - * Connects the destinations post type |
|
1216 | - * |
|
1217 | - * @param $dest_id string |
|
1218 | - * @param $country_id array |
|
1219 | - * @param $id string |
|
1220 | - * |
|
1221 | - * @return string |
|
1222 | - */ |
|
1223 | - public function attach_destination_images( $importable_content = array() ) { |
|
1224 | - if ( false !== $this->destination_images ) { |
|
1225 | - $this->shuffle_assoc( $this->destination_images ); |
|
1226 | - foreach ( $this->destination_images as $tour => $destinations ) { |
|
1227 | - shuffle( $destinations ); |
|
1228 | - $image_set = false; |
|
1229 | - $forced = false; |
|
1230 | - |
|
1231 | - foreach ( $destinations as $destination ) { |
|
1232 | - if ( false === $image_set && false === $forced ) { |
|
1233 | - $url = 'https://wetu.com/API/Pins/' . $this->api_key; |
|
1234 | - |
|
1235 | - $url_qs = ''; |
|
1236 | - $jdata = wp_remote_get( $url . '/Get?' . $url_qs . '&ids=' . $destination[1] ); |
|
1237 | - |
|
1238 | - if ( ! is_wp_error( $jdata ) && ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) { |
|
1239 | - $adata = json_decode( $jdata['body'], true ); |
|
1240 | - |
|
1241 | - if ( ! empty( $adata ) && ! empty( $adata[0]['content']['images'] ) ) { |
|
1242 | - $this->find_attachments( $destination[0] ); |
|
1243 | - |
|
1244 | - // Set the featured image. |
|
1245 | - if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) { |
|
1246 | - $image_set = $this->set_featured_image( $adata, $tour ); |
|
1247 | - if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) { |
|
1248 | - $image_set = $this->set_banner_image( $adata, $tour ); |
|
1249 | - $forced = true; |
|
1250 | - } |
|
1251 | - continue; |
|
1252 | - } |
|
1253 | - if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) { |
|
1254 | - $image_set = $this->set_banner_image( $adata, $tour ); |
|
1255 | - } |
|
1256 | - } |
|
1257 | - } |
|
1258 | - } else { |
|
1259 | - continue; |
|
1260 | - } |
|
1261 | - } |
|
1262 | - } |
|
1263 | - } |
|
1264 | - } |
|
1265 | - |
|
1266 | - /** |
|
1267 | - * Creates the main gallery data |
|
1268 | - */ |
|
1269 | - public function set_featured_image( $data, $id ) { |
|
1270 | - $image_set = false; |
|
1271 | - $counter = 0; |
|
1272 | - |
|
1273 | - if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
1274 | - $images_array = $data[0]['content']['images']; |
|
1275 | - |
|
1276 | - if ( 'on' === $this->options['enable_tour_featured_random'] ) { |
|
1277 | - shuffle( $images_array ); |
|
1278 | - } |
|
1279 | - |
|
1280 | - foreach ( $images_array as $v ) { |
|
1281 | - |
|
1282 | - if ( true === $image_set ) { |
|
1283 | - $counter++; |
|
1284 | - continue; |
|
1285 | - } |
|
1286 | - |
|
1287 | - if ( ! $this->check_if_image_is_used( $v ) ) { |
|
1288 | - $temp_featured_image = $this->attach_image( $v, $id ); |
|
1289 | - |
|
1290 | - if ( false !== $temp_featured_image ) { |
|
1291 | - $this->featured_image = $temp_featured_image; |
|
1292 | - delete_post_meta( $id, '_thumbnail_id' ); |
|
1293 | - add_post_meta( $id, '_thumbnail_id', $this->featured_image, true ); |
|
1294 | - $image_set = true; |
|
1295 | - } |
|
1296 | - } |
|
1297 | - |
|
1298 | - $counter++; |
|
1299 | - } |
|
1300 | - } |
|
1301 | - return $image_set; |
|
1302 | - } |
|
1303 | - |
|
1304 | - /** |
|
1305 | - * Sets a banner image |
|
1306 | - */ |
|
1307 | - public function set_banner_image( $data, $id, $content = array( 'none' ) ) { |
|
1308 | - $image_set = false; |
|
1309 | - $counter = 0; |
|
1310 | - |
|
1311 | - if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
1312 | - |
|
1313 | - foreach ( $data[0]['content']['images'] as $v ) { |
|
1314 | - /* |
|
439 | + return $row_html; |
|
440 | + } |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * Connect to wetu |
|
445 | + */ |
|
446 | + public function process_ajax_import( $force = false ) { |
|
447 | + $return = false; |
|
448 | + check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
449 | + if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug && isset( $_POST['wetu_id'] ) ) { |
|
450 | + |
|
451 | + $wetu_id = sanitize_text_field( $_POST['wetu_id'] ); |
|
452 | + if ( isset( $_POST['post_id'] ) ) { |
|
453 | + $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
454 | + } else { |
|
455 | + $post_id = 0; |
|
456 | + } |
|
457 | + |
|
458 | + delete_option( 'lsx_wetu_importer_tour_settings' ); |
|
459 | + |
|
460 | + if ( isset( $_POST['team_members'] ) ) { |
|
461 | + $team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) ); |
|
462 | + } else { |
|
463 | + $team_members = false; |
|
464 | + } |
|
465 | + |
|
466 | + if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) { |
|
467 | + $content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) ); |
|
468 | + add_option( 'lsx_wetu_importer_tour_settings', $content ); |
|
469 | + } else { |
|
470 | + $content = false; |
|
471 | + } |
|
472 | + $jdata = wp_remote_get( 'https://wetu.com/API/Itinerary/V8/Get?id=' . $wetu_id ); |
|
473 | + |
|
474 | + if ( ! is_wp_error( $jdata ) && ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) { |
|
475 | + $jdata = json_decode( $jdata['body'], true ); |
|
476 | + $return = $this->import_row( $jdata, $wetu_id, $post_id, $team_members, $content ); |
|
477 | + $this->format_completed_row( $return ); |
|
478 | + $this->save_queue(); |
|
479 | + $this->cleanup_posts(); |
|
480 | + $this->attach_destination_images( $content ); |
|
481 | + $this->clean_attached_destinations( $return ); |
|
482 | + } else { |
|
483 | + $this->format_error( esc_html__( 'There was a problem importing your tour, please try again.', 'lsx-wetu-importer' ) ); |
|
484 | + } |
|
485 | + } |
|
486 | + } |
|
487 | + |
|
488 | + /** |
|
489 | + * Amends the tours destinations instead of replace. |
|
490 | + * |
|
491 | + * @param $id string |
|
492 | + * @return void |
|
493 | + */ |
|
494 | + public function clean_attached_destinations( $id ) { |
|
495 | + $current_connections = get_post_meta( $id, 'destination_to_tour', false ); |
|
496 | + delete_post_meta( $id, 'destination_to_tour' ); |
|
497 | + $current_connections = array_unique( $current_connections ); |
|
498 | + |
|
499 | + foreach ( $current_connections as $connection ) { |
|
500 | + add_post_meta( $id, 'destination_to_tour', $connection, false ); |
|
501 | + } |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * Connect to wetu |
|
506 | + * |
|
507 | + * @param $data array |
|
508 | + * @param $wetu_id string |
|
509 | + */ |
|
510 | + public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $old1 = false, $old2 = false ) { |
|
511 | + $post_name = ''; |
|
512 | + $data_post_content = ''; |
|
513 | + $data_post_excerpt = ''; |
|
514 | + |
|
515 | + $current_post = get_post( $id ); |
|
516 | + |
|
517 | + $post = array( |
|
518 | + 'post_type' => 'tour', |
|
519 | + ); |
|
520 | + |
|
521 | + $content_used_general_description = false; |
|
522 | + |
|
523 | + if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) { |
|
524 | + $data_post_content = $current_post->post_content; |
|
525 | + if ( isset( $data['summary'] ) && ! empty( $data['summary'] ) ) { |
|
526 | + $data_post_content = $data['summary']; |
|
527 | + } |
|
528 | + $post['post_content'] = $data_post_content; |
|
529 | + } |
|
530 | + |
|
531 | + // Create or update the post. |
|
532 | + if ( false !== $id && '0' !== $id ) { |
|
533 | + $post['ID'] = $id; |
|
534 | + $post['post_status'] = 'publish'; |
|
535 | + if ( isset( $this->options ) && 'on' !== $this->options['disable_accommodation_title'] ) { |
|
536 | + $post['post_title'] = $data['name']; |
|
537 | + } |
|
538 | + $id = wp_update_post( $post ); |
|
539 | + } else { |
|
540 | + // Set the name. |
|
541 | + if ( isset( $data['name'] ) ) { |
|
542 | + $post_name = wp_unique_post_slug( sanitize_title( $data['name'] ), $id, 'draft', 'tour', 0 ); |
|
543 | + } |
|
544 | + |
|
545 | + if ( ! isset( $post['post_content'] ) ) { |
|
546 | + $post['post_content'] = ' '; |
|
547 | + } |
|
548 | + |
|
549 | + $post['post_name'] = $post_name; |
|
550 | + $post['post_title'] = $data['name']; |
|
551 | + $post['post_status'] = 'publish'; |
|
552 | + $id = wp_insert_post( $post ); |
|
553 | + |
|
554 | + // Save the WETU ID and the Last date it was modified. |
|
555 | + if ( false !== $id ) { |
|
556 | + add_post_meta( $id, 'lsx_wetu_id', $wetu_id ); |
|
557 | + add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data['last_modified'] ) ); |
|
558 | + } |
|
559 | + } |
|
560 | + |
|
561 | + // Set reference number. |
|
562 | + $this->set_reference_number( $data, $id ); |
|
563 | + |
|
564 | + // Set the team member if it is there. |
|
565 | + if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) { |
|
566 | + $this->set_team_member( $id, $team_members ); |
|
567 | + } |
|
568 | + |
|
569 | + // Set the price. |
|
570 | + if ( false !== $importable_content && in_array( 'price', $importable_content ) ) { |
|
571 | + $this->set_price( $data, $id ); |
|
572 | + } |
|
573 | + |
|
574 | + // Set the Duration. |
|
575 | + if ( false !== $importable_content && in_array( 'duration', $importable_content ) ) { |
|
576 | + $this->set_duration( $data, $id ); |
|
577 | + } |
|
578 | + |
|
579 | + // Set the Group Size. |
|
580 | + if ( false !== $importable_content && in_array( 'group_size', $importable_content ) ) { |
|
581 | + $this->set_group_size( $data, $id ); |
|
582 | + } |
|
583 | + |
|
584 | + // Set the Group Size. |
|
585 | + if ( false !== $importable_content && in_array( 'tags', $importable_content ) ) { |
|
586 | + $this->set_travel_styles( $id, $data ); |
|
587 | + } |
|
588 | + |
|
589 | + // Set the Start and End Point Destinations. |
|
590 | + if ( false !== $importable_content && in_array( 'start_end_point', $importable_content ) ) { |
|
591 | + $this->set_start_end_point( $data, $id ); |
|
592 | + } |
|
593 | + |
|
594 | + if ( false !== $importable_content && in_array( 'itineraries', $importable_content ) && isset( $data['legs'] ) && ! empty( $data['legs'] ) ) { |
|
595 | + $this->process_itineraries( $data, $id, $importable_content ); |
|
596 | + } |
|
597 | + |
|
598 | + if ( in_array( 'map', $importable_content ) && isset( $data['routes'] ) && ! empty( $data['routes'] ) ) { |
|
599 | + $this->set_map_data( $data, $id ); |
|
600 | + } |
|
601 | + |
|
602 | + return $id; |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * A loop which runs through each leg on the tour. |
|
607 | + */ |
|
608 | + public function process_itineraries( $data, $id, $importable_content ) { |
|
609 | + $day_counter = 1; |
|
610 | + $leg_counter = 0; |
|
611 | + |
|
612 | + delete_post_meta( $id, 'itinerary' ); |
|
613 | + |
|
614 | + if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) { |
|
615 | + delete_post_meta( $id, 'accommodation_to_tour' ); |
|
616 | + } |
|
617 | + |
|
618 | + foreach ( $data['legs'] as $leg ) { |
|
619 | + |
|
620 | + // Itinerary Accommodation. |
|
621 | + $current_accommodation = false; |
|
622 | + $current_destination = false; |
|
623 | + if ( 'Mobile' !== $leg['type'] ) { |
|
624 | + if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) { |
|
625 | + $current_accommodation = $this->set_accommodation( $leg, $id ); |
|
626 | + } |
|
627 | + if ( false !== $importable_content && in_array( 'destination', $importable_content ) ) { |
|
628 | + $current_destination = $this->set_destination( $leg, $id, $leg_counter ); |
|
629 | + } |
|
630 | + } |
|
631 | + |
|
632 | + // If the Nights are the same mount of days in the array, then it isnt "By Destination". |
|
633 | + if ( ( 1 <= (int) $leg['nights'] && isset( $leg['periods'] ) ) || 0 === $leg['itinerary_leg_id'] ) { |
|
634 | + |
|
635 | + foreach ( $leg['periods'] as $day_key => $day ) { |
|
636 | + $current_day = array(); |
|
637 | + |
|
638 | + // If this is a moble tented solution. |
|
639 | + $next_day_count = $day_counter + (int) $day['days']; |
|
640 | + |
|
641 | + if ( ( isset( $leg['stops'] ) && 'Mobile' !== $leg['type'] ) || ( 1 < (int) $day['days'] ) ) { |
|
642 | + $day_count_label = ' - ' . ( $next_day_count - 1 ); |
|
643 | + } else { |
|
644 | + $day_count_label = ''; |
|
645 | + } |
|
646 | + $current_day['title'] = esc_attr( 'Day ', 'lsx-wetu-importer' ) . $day_counter . $day_count_label; |
|
647 | + |
|
648 | + // Description. |
|
649 | + if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $day['notes'] ) ) { |
|
650 | + $current_day['description'] = $day['notes']; |
|
651 | + } else { |
|
652 | + $current_day['description'] = ''; |
|
653 | + } |
|
654 | + |
|
655 | + // Itinerary Gallery. |
|
656 | + if ( false !== $importable_content && in_array( 'itinerary_gallery', $importable_content ) && isset( $day['images'] ) ) { |
|
657 | + $current_day['featured_image'] = ''; |
|
658 | + } else { |
|
659 | + $current_day['featured_image'] = ''; |
|
660 | + } |
|
661 | + |
|
662 | + // If its a mobile safari, we need to get the destination and accommodation data from the stops. |
|
663 | + if ( 'Mobile' === $leg['type'] ) { |
|
664 | + $current_destination = $this->get_mobile_destination( $day, $leg, $id ); |
|
665 | + $current_accommodation = $this->get_mobile_accommodation( $day, $leg, $id ); |
|
666 | + } |
|
667 | + |
|
668 | + // Accommodation. |
|
669 | + if ( false !== $current_accommodation ) { |
|
670 | + $current_day['accommodation_to_tour'] = array( $current_accommodation ); |
|
671 | + } else { |
|
672 | + $current_day['accommodation_to_tour'] = array(); |
|
673 | + } |
|
674 | + |
|
675 | + // Destination. |
|
676 | + if ( false !== $current_destination ) { |
|
677 | + $current_day['destination_to_tour'] = array( $current_destination ); |
|
678 | + } else { |
|
679 | + $current_day['destination_to_tour'] = array(); |
|
680 | + } |
|
681 | + |
|
682 | + // Included. |
|
683 | + if ( false !== $importable_content && in_array( 'itinerary_included', $importable_content ) && isset( $day['included'] ) && '' !== $day['included'] ) { |
|
684 | + $current_day['included'] = $day['included']; |
|
685 | + } else { |
|
686 | + $current_day['included'] = ''; |
|
687 | + } |
|
688 | + |
|
689 | + // Excluded. |
|
690 | + if ( false !== $importable_content && in_array( 'itinerary_excluded', $importable_content ) && isset( $day['excluded'] ) && '' !== $day['excluded'] ) { |
|
691 | + $current_day['excluded'] = $day['excluded']; |
|
692 | + } else { |
|
693 | + $current_day['excluded'] = ''; |
|
694 | + } |
|
695 | + |
|
696 | + // Excluded. |
|
697 | + if ( false !== $importable_content && in_array( 'room_basis', $importable_content ) && isset( $day['room_basis'] ) && '' !== $day['room_basis'] ) { |
|
698 | + $current_day['room_basis'] = $day['room_basis']; |
|
699 | + } else { |
|
700 | + $current_day['room_basis'] = ''; |
|
701 | + } |
|
702 | + |
|
703 | + // Excluded. |
|
704 | + if ( false !== $importable_content && in_array( 'drinks_basis', $importable_content ) && isset( $day['drinks_basis'] ) && '' !== $day['drinks_basis'] ) { |
|
705 | + $current_day['drinks_basis'] = $day['drinks_basis']; |
|
706 | + } else { |
|
707 | + $current_day['drinks_basis'] = ''; |
|
708 | + } |
|
709 | + |
|
710 | + $this->set_itinerary_day( $current_day, $id ); |
|
711 | + $day_counter = $next_day_count; |
|
712 | + } |
|
713 | + } else { |
|
714 | + // This is for the by destination. |
|
715 | + |
|
716 | + $current_day = array(); |
|
717 | + $next_day_count = $day_counter + (int) $leg['nights']; |
|
718 | + $day_count_label = $next_day_count - 1; |
|
719 | + |
|
720 | + $current_day['title'] = esc_attr( 'Day ', 'lsx-wetu-importer' ) . $day_counter; |
|
721 | + |
|
722 | + if ( 0 !== (int) $leg['nights'] ) { |
|
723 | + $current_day['title'] .= ' - ' . $day_count_label; |
|
724 | + } |
|
725 | + |
|
726 | + // Description. |
|
727 | + if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $leg['notes'] ) ) { |
|
728 | + $current_day['description'] = $leg['notes']; |
|
729 | + } else { |
|
730 | + $current_day['description'] = ''; |
|
731 | + } |
|
732 | + |
|
733 | + // Itinerary Gallery. |
|
734 | + if ( false !== $importable_content && in_array( 'itinerary_gallery', $importable_content ) && isset( $leg['images'] ) ) { |
|
735 | + $current_day['featured_image'] = ''; |
|
736 | + } else { |
|
737 | + $current_day['featured_image'] = ''; |
|
738 | + } |
|
739 | + |
|
740 | + // Accommodation. |
|
741 | + if ( false !== $current_accommodation ) { |
|
742 | + $current_day['accommodation_to_tour'] = array( $current_accommodation ); |
|
743 | + } else { |
|
744 | + $current_day['accommodation_to_tour'] = array(); |
|
745 | + } |
|
746 | + |
|
747 | + // Destination. |
|
748 | + if ( false !== $current_destination ) { |
|
749 | + $current_day['destination_to_tour'] = array( $current_destination ); |
|
750 | + } else { |
|
751 | + $current_day['destination_to_tour'] = array(); |
|
752 | + } |
|
753 | + |
|
754 | + // Included. |
|
755 | + if ( false !== $importable_content && in_array( 'itinerary_included', $importable_content ) && isset( $leg['included'] ) && '' !== $leg['included'] ) { |
|
756 | + $current_day['included'] = $leg['included']; |
|
757 | + } else { |
|
758 | + $current_day['included'] = ''; |
|
759 | + } |
|
760 | + |
|
761 | + // Excluded. |
|
762 | + if ( false !== $importable_content && in_array( 'itinerary_excluded', $importable_content ) && isset( $leg['excluded'] ) && '' !== $leg['excluded'] ) { |
|
763 | + $current_day['excluded'] = $leg['excluded']; |
|
764 | + } else { |
|
765 | + $current_day['excluded'] = ''; |
|
766 | + } |
|
767 | + |
|
768 | + // Excluded. |
|
769 | + if ( false !== $importable_content && in_array( 'room_basis', $importable_content ) && isset( $leg['room_basis'] ) && '' !== $leg['room_basis'] ) { |
|
770 | + $current_day['room_basis'] = $leg['room_basis']; |
|
771 | + } else { |
|
772 | + $current_day['room_basis'] = ''; |
|
773 | + } |
|
774 | + |
|
775 | + // Excluded. |
|
776 | + if ( false !== $importable_content && in_array( 'drinks_basis', $importable_content ) && isset( $leg['drinks_basis'] ) && '' !== $leg['drinks_basis'] ) { |
|
777 | + $current_day['drinks_basis'] = $leg['drinks_basis']; |
|
778 | + } else { |
|
779 | + $current_day['drinks_basis'] = ''; |
|
780 | + } |
|
781 | + |
|
782 | + $this->set_itinerary_day( $current_day, $id ); |
|
783 | + $day_counter = $next_day_count; |
|
784 | + } |
|
785 | + $leg_counter++; |
|
786 | + } |
|
787 | + } |
|
788 | + |
|
789 | + /** |
|
790 | + * Sets the departs from and ends in points on the tours. |
|
791 | + * |
|
792 | + * @param array $data |
|
793 | + * @param string $id |
|
794 | + * @return void |
|
795 | + */ |
|
796 | + public function set_start_end_point( $data, $id ) { |
|
797 | + delete_post_meta( $id, 'departs_from' ); |
|
798 | + delete_post_meta( $id, 'ends_in' ); |
|
799 | + $departs_from = false; |
|
800 | + $ends_in = false; |
|
801 | + |
|
802 | + $args = array( |
|
803 | + 'points' => $data['legs'], |
|
804 | + 'start_index' => 0, |
|
805 | + 'end_index' => count( $data['legs'] ) - 2, |
|
806 | + ); |
|
807 | + $args = apply_filters( 'lsx_wetu_start_end_args', $args, $data ); |
|
808 | + |
|
809 | + if ( ! empty( $args['points'] ) && is_array( $args['points'] ) ) { |
|
810 | + $leg_counter = 0; |
|
811 | + |
|
812 | + foreach ( $args['points'] as $point ) { |
|
813 | + // If we are in the first leg, and the destination was attached then save it as the departure field. |
|
814 | + if ( $leg_counter === $args['start_index'] ) { |
|
815 | + $departs_from_destination = $this->set_country( $point['destination_content_entity_id'], $id ); |
|
816 | + if ( false !== $departs_from_destination ) { |
|
817 | + $departs_from = $departs_from_destination; |
|
818 | + } |
|
819 | + } |
|
820 | + // If its the last leg then save it as the ends in. |
|
821 | + if ( $leg_counter === $args['end_index'] ) { |
|
822 | + $ends_in = $point['destination_content_entity_id']; |
|
823 | + } |
|
824 | + $leg_counter++; |
|
825 | + } |
|
826 | + |
|
827 | + $departs_from = apply_filters( 'lsx_wetu_departs_from_id', $departs_from, $data, $this ); |
|
828 | + if ( false !== $departs_from ) { |
|
829 | + add_post_meta( $id, 'departs_from', $departs_from, true ); |
|
830 | + } |
|
831 | + |
|
832 | + if ( false !== $ends_in ) { |
|
833 | + $ends_in = apply_filters( 'lsx_wetu_ends_in_id', $ends_in, $data, $this ); |
|
834 | + $ends_in_destination = $this->set_country( $ends_in, $id ); |
|
835 | + if ( false !== $ends_in_destination ) { |
|
836 | + add_post_meta( $id, 'ends_in', $ends_in_destination, true ); |
|
837 | + } |
|
838 | + } |
|
839 | + } |
|
840 | + } |
|
841 | + |
|
842 | + /** |
|
843 | + * Gets the destination for the mobile camp. |
|
844 | + * |
|
845 | + * @param $day |
|
846 | + * @param $leg |
|
847 | + * @return void |
|
848 | + */ |
|
849 | + public function get_mobile_destination( $day, $leg, $id ) { |
|
850 | + $current_destination = false; |
|
851 | + $current_day = (int) $day['period_start_day']; |
|
852 | + if ( isset( $leg['stops'] ) ) { |
|
853 | + foreach ( $leg['stops'] as $stop ) { |
|
854 | + $arrival_day = (int) $stop['arrival_day']; |
|
855 | + $departure_day = (int) $stop['departure_day']; |
|
856 | + if ( $arrival_day <= $current_day && $current_day < $departure_day ) { |
|
857 | + $current_destination = $this->set_destination( $stop, $id, 0 ); |
|
858 | + } |
|
859 | + } |
|
860 | + } |
|
861 | + return $current_destination; |
|
862 | + } |
|
863 | + |
|
864 | + /** |
|
865 | + * Gets the accommodation for the mobile camp. |
|
866 | + * |
|
867 | + * @param $day |
|
868 | + * @param $leg |
|
869 | + * @return void |
|
870 | + */ |
|
871 | + public function get_mobile_accommodation( $day, $leg, $id ) { |
|
872 | + $current_accommodation = false; |
|
873 | + $current_day = (int) $day['period_start_day']; |
|
874 | + if ( isset( $leg['stops'] ) ) { |
|
875 | + foreach ( $leg['stops'] as $stop ) { |
|
876 | + $arrival_day = (int) $stop['arrival_day']; |
|
877 | + $departure_day = (int) $stop['departure_day']; |
|
878 | + if ( $arrival_day <= $current_day && $current_day < $departure_day ) { |
|
879 | + $current_accommodation = $this->set_accommodation( $stop, $id, 0 ); |
|
880 | + } |
|
881 | + } |
|
882 | + } |
|
883 | + return $current_accommodation; |
|
884 | + } |
|
885 | + |
|
886 | + /** |
|
887 | + * Run through your routes and save the points as a KML file. |
|
888 | + */ |
|
889 | + public function set_map_data( $data, $id, $zoom = 9 ) { |
|
890 | + if ( ! empty( $data['routes'] ) ) { |
|
891 | + delete_post_meta( $id, 'wetu_map_points' ); |
|
892 | + |
|
893 | + $points = array(); |
|
894 | + |
|
895 | + foreach ( $data['routes'] as $route ) { |
|
896 | + |
|
897 | + if ( isset( $route['points'] ) && '' !== $route['points'] ) { |
|
898 | + |
|
899 | + $temp_points = explode( ';', $route['points'] ); |
|
900 | + $point_counter = count( $temp_points ); |
|
901 | + |
|
902 | + for ( $x = 0; $x <= $point_counter; $x++ ) { |
|
903 | + $y = $x + 1; |
|
904 | + $points[] = $temp_points[ $x ] . ',' . $temp_points[ $y ]; |
|
905 | + $x++; |
|
906 | + } |
|
907 | + } |
|
908 | + } |
|
909 | + |
|
910 | + if ( ! empty( $points ) ) { |
|
911 | + $this->save_custom_field( implode( ' ', $points ), 'wetu_map_points', $id, false, true ); |
|
912 | + } |
|
913 | + } |
|
914 | + |
|
915 | + } |
|
916 | + |
|
917 | + // CLASS SPECIFIC FUNCTIONS. |
|
918 | + |
|
919 | + /** |
|
920 | + * Set the Itinerary Day. |
|
921 | + */ |
|
922 | + public function set_itinerary_day( $day, $id ) { |
|
923 | + $this->save_custom_field( $day, 'itinerary', $id, false, false ); |
|
924 | + } |
|
925 | + |
|
926 | + /** |
|
927 | + * Set the ref number |
|
928 | + */ |
|
929 | + public function set_reference_number( $data, $id ) { |
|
930 | + if ( isset( $data['reference_number'] ) && '' !== $data['reference_number'] ) { |
|
931 | + $this->save_custom_field( $data['reference_number'], 'lsx_wetu_ref', $id ); |
|
932 | + } |
|
933 | + } |
|
934 | + |
|
935 | + /** |
|
936 | + * Set the price. |
|
937 | + */ |
|
938 | + public function set_price( $data, $id ) { |
|
939 | + // Price. |
|
940 | + if ( isset( $data['price'] ) && '' !== $data['price'] ) { |
|
941 | + $price = $data['price']; |
|
942 | + if ( false === apply_filters( 'lsx_wetu_importer_disable_tour_price_filter', false ) ) { |
|
943 | + $price = preg_replace( '/[^0-9,.]/', '', $price ); |
|
944 | + } |
|
945 | + $meta_key = apply_filters( 'lsx_wetu_importer_price_meta_key', 'price' ); |
|
946 | + $this->save_custom_field( $price, $meta_key, $id ); |
|
947 | + } |
|
948 | + |
|
949 | + // Price includes. |
|
950 | + if ( isset( $data['price_includes'] ) && '' !== $data['price_includes'] ) { |
|
951 | + $meta_key = apply_filters( 'lsx_wetu_importer_included_meta_key', 'included' ); |
|
952 | + $this->save_custom_field( $data['price_includes'], $meta_key, $id ); |
|
953 | + } |
|
954 | + |
|
955 | + // Price Excludes. |
|
956 | + if ( isset( $data['price_excludes'] ) && '' !== $data['price_excludes'] ) { |
|
957 | + $meta_key = apply_filters( 'lsx_wetu_importer_not_included_meta_key', 'not_included' ); |
|
958 | + $this->save_custom_field( $data['price_excludes'], $meta_key, $id ); |
|
959 | + } |
|
960 | + } |
|
961 | + |
|
962 | + /** |
|
963 | + * Set the duration. |
|
964 | + */ |
|
965 | + public function set_duration( $data, $id ) { |
|
966 | + if ( isset( $data['days'] ) && ! empty( $data['days'] ) ) { |
|
967 | + $price = $data['days']; |
|
968 | + $price = preg_replace( '/[^0-9,.]/', '', $price ); |
|
969 | + $this->save_custom_field( $price, 'duration', $id ); |
|
970 | + } |
|
971 | + } |
|
972 | + |
|
973 | + /** |
|
974 | + * Set the group size |
|
975 | + */ |
|
976 | + public function set_group_size( $data, $id ) { |
|
977 | + if ( isset( $data['group_size'] ) && ! empty( $data['group_size'] ) ) { |
|
978 | + $group_size = $data['group_size']; |
|
979 | + $this->save_custom_field( $group_size, 'group_size', $id ); |
|
980 | + } |
|
981 | + } |
|
982 | + |
|
983 | + /** |
|
984 | + * Takes the WETU tags and sets the Travel Styles. |
|
985 | + * |
|
986 | + * @param string $id |
|
987 | + * @param array $travel_styles |
|
988 | + * @return void |
|
989 | + */ |
|
990 | + public function set_travel_styles( $id, $data ) { |
|
991 | + $tags = apply_filters( 'lsx_wetu_importer_tour_travel_styles', $data['tags'] ); |
|
992 | + if ( isset( $data['tags'] ) && ! empty( $tags ) ) { |
|
993 | + foreach ( $tags as $tag ) { |
|
994 | + $this->set_term( $id, $tag, 'travel-style' ); |
|
995 | + } |
|
996 | + } |
|
997 | + } |
|
998 | + |
|
999 | + /** |
|
1000 | + * Connects the Accommodation if its available |
|
1001 | + */ |
|
1002 | + public function set_accommodation( $day, $id ) { |
|
1003 | + $ac_id = false; |
|
1004 | + $this->current_accommodation = $this->find_current_accommodation(); |
|
1005 | + |
|
1006 | + if ( isset( $day['content_entity_id'] ) && ! empty( $day['content_entity_id'] ) ) { |
|
1007 | + if ( false !== $this->current_accommodation && ! empty( $this->current_accommodation ) && array_key_exists( $day['content_entity_id'], $this->current_accommodation ) ) { |
|
1008 | + $ac_id = $this->current_accommodation[ $day['content_entity_id'] ]; |
|
1009 | + } else { |
|
1010 | + $ac_id = wp_insert_post( |
|
1011 | + array( |
|
1012 | + 'post_type' => 'accommodation', |
|
1013 | + 'post_status' => 'draft', |
|
1014 | + 'post_title' => $day['content_entity_id'], |
|
1015 | + ) |
|
1016 | + ); |
|
1017 | + |
|
1018 | + $this->save_custom_field( $day['content_entity_id'], 'lsx_wetu_id', $ac_id ); |
|
1019 | + } |
|
1020 | + |
|
1021 | + if ( '' !== $ac_id && false !== $ac_id ) { |
|
1022 | + $this->save_custom_field( $ac_id, 'accommodation_to_tour', $id, false, false ); |
|
1023 | + $this->save_custom_field( $id, 'tour_to_accommodation', $ac_id, false, false ); |
|
1024 | + $this->queue_item( $ac_id ); |
|
1025 | + } |
|
1026 | + } |
|
1027 | + return $ac_id; |
|
1028 | + } |
|
1029 | + |
|
1030 | + /** |
|
1031 | + * Grab all the current accommodation posts via the lsx_wetu_id field. |
|
1032 | + * |
|
1033 | + * @param $post_type string |
|
1034 | + * @return boolean / array |
|
1035 | + */ |
|
1036 | + public function find_current_accommodation( $post_type = 'accommodation' ) { |
|
1037 | + global $wpdb; |
|
1038 | + $accommodation = parent::find_current_accommodation( $post_type ); |
|
1039 | + $return = false; |
|
1040 | + |
|
1041 | + if ( ! empty( $accommodation ) ) { |
|
1042 | + foreach ( $accommodation as $key => $acc ) { |
|
1043 | + $return[ $acc->meta_value ] = $acc->post_id; |
|
1044 | + } |
|
1045 | + } |
|
1046 | + |
|
1047 | + return $return; |
|
1048 | + } |
|
1049 | + |
|
1050 | + /** |
|
1051 | + * Grab all the current accommodation posts via the lsx_wetu_id field. |
|
1052 | + * |
|
1053 | + * @return boolean / array |
|
1054 | + */ |
|
1055 | + public function find_current_destinations() { |
|
1056 | + return $this->find_current_accommodation( 'destination' ); |
|
1057 | + } |
|
1058 | + |
|
1059 | + /** |
|
1060 | + * Connects the destinations post type |
|
1061 | + * |
|
1062 | + * @param $day array |
|
1063 | + * @param $id string |
|
1064 | + * @return boolean / string |
|
1065 | + */ |
|
1066 | + public function set_destination( $day, $id, $leg_counter ) { |
|
1067 | + $dest_id = false; |
|
1068 | + $country_id = false; |
|
1069 | + |
|
1070 | + $this->current_destinations = $this->find_current_destinations(); |
|
1071 | + |
|
1072 | + if ( isset( $day['destination_content_entity_id'] ) && ! empty( $day['destination_content_entity_id'] ) ) { |
|
1073 | + if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $day['destination_content_entity_id'], $this->current_destinations ) ) { |
|
1074 | + $dest_id = $this->current_destinations[ $day['destination_content_entity_id'] ]; |
|
1075 | + |
|
1076 | + // TODO Check for attachments here. |
|
1077 | + $this->destination_images[ $id ][] = array( $dest_id, $day['destination_content_entity_id'] ); |
|
1078 | + |
|
1079 | + // Check if there is a country asigned. |
|
1080 | + $potential_id = wp_get_post_parent_id( $dest_id ); |
|
1081 | + $country_wetu_id = get_post_meta( $potential_id, 'lsx_wetu_id', true ); |
|
1082 | + |
|
1083 | + if ( false !== $country_wetu_id ) { |
|
1084 | + $country_id = $this->set_country( $country_wetu_id, $id ); |
|
1085 | + // $this->destination_images[ $id ][] = array( $id, $country_wetu_id ); |
|
1086 | + } |
|
1087 | + } else { |
|
1088 | + $destination_json = wp_remote_get( 'https://wetu.com/API/Pins/' . $this->api_key . '/Get?ids=' . $day['destination_content_entity_id'] ); |
|
1089 | + |
|
1090 | + if ( ! is_wp_error( $destination_json ) && ! empty( $destination_json ) && isset( $destination_json['response'] ) && isset( $destination_json['response']['code'] ) && 200 === $destination_json['response']['code'] ) { |
|
1091 | + |
|
1092 | + $destination_data = json_decode( $destination_json['body'], true ); |
|
1093 | + |
|
1094 | + if ( ! empty( $destination_data ) && ! isset( $destination_data['error'] ) ) { |
|
1095 | + $destination_title = $day['destination_content_entity_id']; |
|
1096 | + |
|
1097 | + if ( isset( $destination_data[0]['name'] ) ) { |
|
1098 | + $destination_title = $destination_data[0]['name']; |
|
1099 | + } |
|
1100 | + |
|
1101 | + if ( isset( $destination_data[0]['map_object_id'] ) && isset( $destination_data[0]['position']['country_content_entity_id'] ) |
|
1102 | + && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id'] ) { |
|
1103 | + |
|
1104 | + $country_id = $this->set_country( $destination_data[0]['position']['country_content_entity_id'], $id ); |
|
1105 | + // Save the destination so we can grab the tour featured image and banner from them. |
|
1106 | + } |
|
1107 | + |
|
1108 | + $dest_post = array( |
|
1109 | + 'post_type' => 'destination', |
|
1110 | + 'post_status' => 'draft', |
|
1111 | + 'post_title' => $destination_title, |
|
1112 | + ); |
|
1113 | + |
|
1114 | + if ( false !== $country_id ) { |
|
1115 | + $dest_post['post_parent'] = $country_id; |
|
1116 | + } |
|
1117 | + $dest_id = wp_insert_post( $dest_post ); |
|
1118 | + |
|
1119 | + // Make sure we register the. |
|
1120 | + $this->current_destinations[ $day['destination_content_entity_id'] ] = $dest_id; |
|
1121 | + |
|
1122 | + // If there are images attached then use the destination. |
|
1123 | + if ( isset( $destination_data[0]['content']['images'] ) && ! empty( $destination_data[0]['content']['images'] ) ) { |
|
1124 | + $this->destination_images[ $id ][] = array( $dest_id, $day['destination_content_entity_id'] ); |
|
1125 | + } |
|
1126 | + |
|
1127 | + $this->save_custom_field( $day['destination_content_entity_id'], 'lsx_wetu_id', $dest_id ); |
|
1128 | + } |
|
1129 | + } |
|
1130 | + } |
|
1131 | + |
|
1132 | + if ( '' !== $dest_id && false !== $dest_id ) { |
|
1133 | + $this->save_custom_field( $dest_id, 'destination_to_tour', $id, false, false ); |
|
1134 | + $this->save_custom_field( $id, 'tour_to_destination', $dest_id, false, false ); |
|
1135 | + |
|
1136 | + // Save the item to display in the queue |
|
1137 | + $this->queue_item( $dest_id ); |
|
1138 | + |
|
1139 | + // Save the item to clean up the amount of connections. |
|
1140 | + $this->cleanup_posts[ $dest_id ] = 'tour_to_destination'; |
|
1141 | + |
|
1142 | + // Add this relation info so we can make sure certain items are set as countries. |
|
1143 | + if ( 0 !== $country_id && false !== $country_id ) { |
|
1144 | + $this->relation_meta[ $dest_id ] = $country_id; |
|
1145 | + $this->relation_meta[ $country_id ] = 0; |
|
1146 | + } else { |
|
1147 | + $this->relation_meta[ $dest_id ] = 0; |
|
1148 | + } |
|
1149 | + } |
|
1150 | + } |
|
1151 | + return $dest_id; |
|
1152 | + } |
|
1153 | + |
|
1154 | + /** |
|
1155 | + * Connects the destinations post type |
|
1156 | + * |
|
1157 | + * @param $dest_id string |
|
1158 | + * @param $country_id array |
|
1159 | + * @param $id string |
|
1160 | + * |
|
1161 | + * @return string |
|
1162 | + */ |
|
1163 | + public function set_country( $country_wetu_id, $id ) { |
|
1164 | + $country_id = false; |
|
1165 | + $this->current_destinations = $this->find_current_destinations(); |
|
1166 | + |
|
1167 | + if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $country_wetu_id, $this->current_destinations ) ) { |
|
1168 | + $country_id = $this->current_destinations[ $country_wetu_id ]; |
|
1169 | + $this->destination_images[ $id ][] = array( $country_id, $country_wetu_id ); |
|
1170 | + } else { |
|
1171 | + $country_json = wp_remote_get( 'https://wetu.com/API/Pins/' . $this->api_key . '/Get?ids=' . $country_wetu_id ); |
|
1172 | + |
|
1173 | + if ( ! is_wp_error( $country_json ) && ! empty( $country_json ) && isset( $country_json['response'] ) && isset( $country_json['response']['code'] ) && 200 === $country_json['response']['code'] ) { |
|
1174 | + $country_data = json_decode( $country_json['body'], true ); |
|
1175 | + |
|
1176 | + // Format the title of the destination if its available, otherwise default to the WETU ID. |
|
1177 | + $country_title = $country_wetu_id; |
|
1178 | + |
|
1179 | + if ( isset( $country_data[0]['name'] ) ) { |
|
1180 | + $country_title = $country_data[0]['name']; |
|
1181 | + } |
|
1182 | + |
|
1183 | + $country_id = wp_insert_post( |
|
1184 | + array( |
|
1185 | + 'post_type' => 'destination', |
|
1186 | + 'post_status' => 'draft', |
|
1187 | + 'post_title' => $country_title, |
|
1188 | + ) |
|
1189 | + ); |
|
1190 | + |
|
1191 | + // add the country to the current destination stack |
|
1192 | + $this->current_destinations[ $country_wetu_id ] = $country_id; |
|
1193 | + |
|
1194 | + // Check if there are images and save fore use later. |
|
1195 | + if ( isset( $country_data[0]['content']['images'] ) && ! empty( $country_data[0]['content']['images'] ) ) { |
|
1196 | + $this->destination_images[ $id ][] = array( $country_id, $country_wetu_id ); |
|
1197 | + } |
|
1198 | + |
|
1199 | + // Save the wetu field |
|
1200 | + $this->save_custom_field( $country_wetu_id, 'lsx_wetu_id', $country_id ); |
|
1201 | + } |
|
1202 | + } |
|
1203 | + |
|
1204 | + if ( '' !== $country_id && false !== $country_id ) { |
|
1205 | + $this->save_custom_field( $country_id, 'destination_to_tour', $id, false, false ); |
|
1206 | + $this->save_custom_field( $id, 'tour_to_destination', $country_id, false, false ); |
|
1207 | + $this->queue_item( $country_id ); |
|
1208 | + $this->cleanup_posts[ $country_id ] = 'tour_to_destination'; |
|
1209 | + |
|
1210 | + return $country_id; |
|
1211 | + } |
|
1212 | + } |
|
1213 | + |
|
1214 | + /** |
|
1215 | + * Connects the destinations post type |
|
1216 | + * |
|
1217 | + * @param $dest_id string |
|
1218 | + * @param $country_id array |
|
1219 | + * @param $id string |
|
1220 | + * |
|
1221 | + * @return string |
|
1222 | + */ |
|
1223 | + public function attach_destination_images( $importable_content = array() ) { |
|
1224 | + if ( false !== $this->destination_images ) { |
|
1225 | + $this->shuffle_assoc( $this->destination_images ); |
|
1226 | + foreach ( $this->destination_images as $tour => $destinations ) { |
|
1227 | + shuffle( $destinations ); |
|
1228 | + $image_set = false; |
|
1229 | + $forced = false; |
|
1230 | + |
|
1231 | + foreach ( $destinations as $destination ) { |
|
1232 | + if ( false === $image_set && false === $forced ) { |
|
1233 | + $url = 'https://wetu.com/API/Pins/' . $this->api_key; |
|
1234 | + |
|
1235 | + $url_qs = ''; |
|
1236 | + $jdata = wp_remote_get( $url . '/Get?' . $url_qs . '&ids=' . $destination[1] ); |
|
1237 | + |
|
1238 | + if ( ! is_wp_error( $jdata ) && ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) { |
|
1239 | + $adata = json_decode( $jdata['body'], true ); |
|
1240 | + |
|
1241 | + if ( ! empty( $adata ) && ! empty( $adata[0]['content']['images'] ) ) { |
|
1242 | + $this->find_attachments( $destination[0] ); |
|
1243 | + |
|
1244 | + // Set the featured image. |
|
1245 | + if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) { |
|
1246 | + $image_set = $this->set_featured_image( $adata, $tour ); |
|
1247 | + if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) { |
|
1248 | + $image_set = $this->set_banner_image( $adata, $tour ); |
|
1249 | + $forced = true; |
|
1250 | + } |
|
1251 | + continue; |
|
1252 | + } |
|
1253 | + if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) { |
|
1254 | + $image_set = $this->set_banner_image( $adata, $tour ); |
|
1255 | + } |
|
1256 | + } |
|
1257 | + } |
|
1258 | + } else { |
|
1259 | + continue; |
|
1260 | + } |
|
1261 | + } |
|
1262 | + } |
|
1263 | + } |
|
1264 | + } |
|
1265 | + |
|
1266 | + /** |
|
1267 | + * Creates the main gallery data |
|
1268 | + */ |
|
1269 | + public function set_featured_image( $data, $id ) { |
|
1270 | + $image_set = false; |
|
1271 | + $counter = 0; |
|
1272 | + |
|
1273 | + if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
1274 | + $images_array = $data[0]['content']['images']; |
|
1275 | + |
|
1276 | + if ( 'on' === $this->options['enable_tour_featured_random'] ) { |
|
1277 | + shuffle( $images_array ); |
|
1278 | + } |
|
1279 | + |
|
1280 | + foreach ( $images_array as $v ) { |
|
1281 | + |
|
1282 | + if ( true === $image_set ) { |
|
1283 | + $counter++; |
|
1284 | + continue; |
|
1285 | + } |
|
1286 | + |
|
1287 | + if ( ! $this->check_if_image_is_used( $v ) ) { |
|
1288 | + $temp_featured_image = $this->attach_image( $v, $id ); |
|
1289 | + |
|
1290 | + if ( false !== $temp_featured_image ) { |
|
1291 | + $this->featured_image = $temp_featured_image; |
|
1292 | + delete_post_meta( $id, '_thumbnail_id' ); |
|
1293 | + add_post_meta( $id, '_thumbnail_id', $this->featured_image, true ); |
|
1294 | + $image_set = true; |
|
1295 | + } |
|
1296 | + } |
|
1297 | + |
|
1298 | + $counter++; |
|
1299 | + } |
|
1300 | + } |
|
1301 | + return $image_set; |
|
1302 | + } |
|
1303 | + |
|
1304 | + /** |
|
1305 | + * Sets a banner image |
|
1306 | + */ |
|
1307 | + public function set_banner_image( $data, $id, $content = array( 'none' ) ) { |
|
1308 | + $image_set = false; |
|
1309 | + $counter = 0; |
|
1310 | + |
|
1311 | + if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
1312 | + |
|
1313 | + foreach ( $data[0]['content']['images'] as $v ) { |
|
1314 | + /* |
|
1315 | 1315 | print_r('<pre>'); |
1316 | 1316 | print_r( $v ); |
1317 | 1317 | print_r('</pre>');*/ |
1318 | 1318 | |
1319 | - if ( true === $image_set || 0 === $counter ) { |
|
1320 | - $counter++; |
|
1321 | - continue; |
|
1322 | - } |
|
1323 | - |
|
1324 | - if ( ! $this->check_if_image_is_used( $v ) ) { |
|
1325 | - $temp_banner = $this->attach_image( |
|
1326 | - $v, |
|
1327 | - $id, |
|
1328 | - array( |
|
1329 | - 'width' => '1920', |
|
1330 | - 'height' => '600', |
|
1331 | - 'cropping' => 'c', |
|
1332 | - ) |
|
1333 | - ); |
|
1334 | - |
|
1335 | - if ( false !== $temp_banner ) { |
|
1336 | - $this->banner_image = $temp_banner; |
|
1337 | - |
|
1338 | - delete_post_meta( $id, 'image_group' ); |
|
1339 | - |
|
1340 | - $new_banner = array( |
|
1341 | - 'banner_image' => array( |
|
1342 | - 'cmb-field-0' => $this->banner_image, |
|
1343 | - ), |
|
1344 | - ); |
|
1345 | - add_post_meta( $id, 'image_group', $new_banner, true ); |
|
1346 | - $image_set = true; |
|
1347 | - } |
|
1348 | - } |
|
1349 | - $counter++; |
|
1350 | - } |
|
1351 | - } |
|
1352 | - |
|
1353 | - return $image_set; |
|
1354 | - } |
|
1355 | - |
|
1356 | - /** |
|
1357 | - * Grabs all of the current used featured images on the site. |
|
1358 | - */ |
|
1359 | - public function check_if_image_is_used( $v ) { |
|
1360 | - global $wpdb; |
|
1361 | - $return = false; |
|
1362 | - |
|
1363 | - $results = $wpdb->get_results( |
|
1364 | - $wpdb->prepare( |
|
1365 | - "SELECT post_id |
|
1319 | + if ( true === $image_set || 0 === $counter ) { |
|
1320 | + $counter++; |
|
1321 | + continue; |
|
1322 | + } |
|
1323 | + |
|
1324 | + if ( ! $this->check_if_image_is_used( $v ) ) { |
|
1325 | + $temp_banner = $this->attach_image( |
|
1326 | + $v, |
|
1327 | + $id, |
|
1328 | + array( |
|
1329 | + 'width' => '1920', |
|
1330 | + 'height' => '600', |
|
1331 | + 'cropping' => 'c', |
|
1332 | + ) |
|
1333 | + ); |
|
1334 | + |
|
1335 | + if ( false !== $temp_banner ) { |
|
1336 | + $this->banner_image = $temp_banner; |
|
1337 | + |
|
1338 | + delete_post_meta( $id, 'image_group' ); |
|
1339 | + |
|
1340 | + $new_banner = array( |
|
1341 | + 'banner_image' => array( |
|
1342 | + 'cmb-field-0' => $this->banner_image, |
|
1343 | + ), |
|
1344 | + ); |
|
1345 | + add_post_meta( $id, 'image_group', $new_banner, true ); |
|
1346 | + $image_set = true; |
|
1347 | + } |
|
1348 | + } |
|
1349 | + $counter++; |
|
1350 | + } |
|
1351 | + } |
|
1352 | + |
|
1353 | + return $image_set; |
|
1354 | + } |
|
1355 | + |
|
1356 | + /** |
|
1357 | + * Grabs all of the current used featured images on the site. |
|
1358 | + */ |
|
1359 | + public function check_if_image_is_used( $v ) { |
|
1360 | + global $wpdb; |
|
1361 | + $return = false; |
|
1362 | + |
|
1363 | + $results = $wpdb->get_results( |
|
1364 | + $wpdb->prepare( |
|
1365 | + "SELECT post_id |
|
1366 | 1366 | FROM {$wpdb->postmeta} |
1367 | 1367 | WHERE meta_value = '%s' |
1368 | 1368 | AND meta_key = 'lsx_wetu_id' |
1369 | 1369 | ", |
1370 | - array( $value ) |
|
1371 | - ) |
|
1372 | - ); |
|
1373 | - $attached_tours = array(); |
|
1374 | - if ( ! empty( $results ) ) { |
|
1375 | - foreach ( $results as $result ) { |
|
1376 | - if ( 'tour' === get_post_type( $result['post_id'] ) ) { |
|
1377 | - $attached_tours[] = $result['post_id']; |
|
1378 | - } |
|
1379 | - } |
|
1380 | - } |
|
1381 | - if ( ! empty( $attached_tours ) ) { |
|
1382 | - $return = true; |
|
1383 | - } |
|
1384 | - return $return; |
|
1385 | - } |
|
1386 | - |
|
1387 | - /** |
|
1388 | - * Que an item to be saved. |
|
1389 | - * |
|
1390 | - * @param $id int |
|
1391 | - */ |
|
1392 | - public function queue_item( $id ) { |
|
1393 | - if ( is_array( $this->import_queue ) && ! in_array( $id, $this->import_queue ) ) { |
|
1394 | - $this->import_queue[] = $id; |
|
1395 | - } else { |
|
1396 | - $this->import_queue[] = $id; |
|
1397 | - } |
|
1398 | - } |
|
1399 | - |
|
1400 | - /** |
|
1401 | - * Saves the queue to the option. |
|
1402 | - */ |
|
1403 | - public function save_queue() { |
|
1404 | - if ( ! empty( $this->import_queue ) ) { |
|
1405 | - if ( ! empty( $this->queued_imports ) ) { |
|
1406 | - $saved_imports = array_merge( $this->queued_imports, $this->import_queue ); |
|
1407 | - } else { |
|
1408 | - $saved_imports = $this->import_queue; |
|
1409 | - } |
|
1410 | - |
|
1411 | - delete_option( 'lsx_wetu_importer_que' ); |
|
1412 | - |
|
1413 | - if ( ! empty( $saved_imports ) ) { |
|
1414 | - $saved_imports = array_unique( $saved_imports ); |
|
1415 | - update_option( 'lsx_wetu_importer_que', $saved_imports ); |
|
1416 | - } |
|
1417 | - } |
|
1418 | - } |
|
1419 | - |
|
1420 | - /** |
|
1421 | - * The header of the item list |
|
1422 | - */ |
|
1423 | - public function table_header() { |
|
1424 | - ?> |
|
1370 | + array( $value ) |
|
1371 | + ) |
|
1372 | + ); |
|
1373 | + $attached_tours = array(); |
|
1374 | + if ( ! empty( $results ) ) { |
|
1375 | + foreach ( $results as $result ) { |
|
1376 | + if ( 'tour' === get_post_type( $result['post_id'] ) ) { |
|
1377 | + $attached_tours[] = $result['post_id']; |
|
1378 | + } |
|
1379 | + } |
|
1380 | + } |
|
1381 | + if ( ! empty( $attached_tours ) ) { |
|
1382 | + $return = true; |
|
1383 | + } |
|
1384 | + return $return; |
|
1385 | + } |
|
1386 | + |
|
1387 | + /** |
|
1388 | + * Que an item to be saved. |
|
1389 | + * |
|
1390 | + * @param $id int |
|
1391 | + */ |
|
1392 | + public function queue_item( $id ) { |
|
1393 | + if ( is_array( $this->import_queue ) && ! in_array( $id, $this->import_queue ) ) { |
|
1394 | + $this->import_queue[] = $id; |
|
1395 | + } else { |
|
1396 | + $this->import_queue[] = $id; |
|
1397 | + } |
|
1398 | + } |
|
1399 | + |
|
1400 | + /** |
|
1401 | + * Saves the queue to the option. |
|
1402 | + */ |
|
1403 | + public function save_queue() { |
|
1404 | + if ( ! empty( $this->import_queue ) ) { |
|
1405 | + if ( ! empty( $this->queued_imports ) ) { |
|
1406 | + $saved_imports = array_merge( $this->queued_imports, $this->import_queue ); |
|
1407 | + } else { |
|
1408 | + $saved_imports = $this->import_queue; |
|
1409 | + } |
|
1410 | + |
|
1411 | + delete_option( 'lsx_wetu_importer_que' ); |
|
1412 | + |
|
1413 | + if ( ! empty( $saved_imports ) ) { |
|
1414 | + $saved_imports = array_unique( $saved_imports ); |
|
1415 | + update_option( 'lsx_wetu_importer_que', $saved_imports ); |
|
1416 | + } |
|
1417 | + } |
|
1418 | + } |
|
1419 | + |
|
1420 | + /** |
|
1421 | + * The header of the item list |
|
1422 | + */ |
|
1423 | + public function table_header() { |
|
1424 | + ?> |
|
1425 | 1425 | <thead> |
1426 | 1426 | <tr> |
1427 | 1427 | <th class="manage-column column-cb check-column" id="cb" scope="col"> |
@@ -1436,13 +1436,13 @@ discard block |
||
1436 | 1436 | </tr> |
1437 | 1437 | </thead> |
1438 | 1438 | <?php |
1439 | - } |
|
1439 | + } |
|
1440 | 1440 | |
1441 | - /** |
|
1442 | - * The footer of the item list |
|
1443 | - */ |
|
1444 | - public function table_footer() { |
|
1445 | - ?> |
|
1441 | + /** |
|
1442 | + * The footer of the item list |
|
1443 | + */ |
|
1444 | + public function table_footer() { |
|
1445 | + ?> |
|
1446 | 1446 | <tfoot> |
1447 | 1447 | <tr> |
1448 | 1448 | <th class="manage-column column-cb check-column" id="cb" scope="col"> |
@@ -1457,5 +1457,5 @@ discard block |
||
1457 | 1457 | </tr> |
1458 | 1458 | </tfoot> |
1459 | 1459 | <?php |
1460 | - } |
|
1460 | + } |
|
1461 | 1461 | } |
@@ -16,288 +16,288 @@ |
||
16 | 16 | */ |
17 | 17 | class Cron { |
18 | 18 | |
19 | - /** |
|
20 | - * Holds class instance |
|
21 | - * |
|
22 | - * @since 1.0.0 |
|
23 | - * |
|
24 | - * @var object|Module_Template |
|
25 | - */ |
|
26 | - protected static $instance = null; |
|
27 | - |
|
28 | - /** |
|
29 | - * Initialize the plugin by setting localization, filters, and administration functions. |
|
30 | - * |
|
31 | - * @since 1.0.0 |
|
32 | - * |
|
33 | - * @access private |
|
34 | - */ |
|
35 | - public function __construct() { |
|
36 | - add_filter( 'cron_schedules', array( $this, 'register_schedule' ), 10, 1 ); |
|
37 | - add_action( 'lsx_wetu_importer_settings_before', array( $this, 'watch_for_trigger' ), 200 ); |
|
38 | - add_action( 'lsx_wetu_accommodation_images_cron', array( $this, 'process' ), 10, 1 ); |
|
39 | - add_action( 'lsx_wetu_accommodation_images_sync', array( $this, 'cron_callback' ), 10, 1 ); |
|
40 | - add_filter( 'cmb_meta_boxes', array( $this, 'metaboxes' ) ); |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Return an instance of this class. |
|
45 | - * |
|
46 | - * @since 1.0.0 |
|
47 | - * |
|
48 | - * @return object Cron() A single instance of this class. |
|
49 | - */ |
|
50 | - public static function get_instance() { |
|
51 | - // If the single instance hasn't been set, set it now. |
|
52 | - if ( null === self::$instance ) { |
|
53 | - self::$instance = new self(); |
|
54 | - } |
|
55 | - return self::$instance; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Define the metabox and field configurations. |
|
60 | - * |
|
61 | - * @param array $meta_boxes |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - public function metaboxes( array $meta_boxes ) { |
|
65 | - // Allowed post types. |
|
66 | - $allowed_post_types = array( 'accommodation' ); |
|
67 | - |
|
68 | - $fields = array(); |
|
69 | - |
|
70 | - $fields[] = array( |
|
71 | - 'id' => 'wetu_skip_banner', |
|
72 | - 'name' => esc_html__( 'Skip Banner Image', 'lsx-banners' ), |
|
73 | - 'type' => 'checkbox', |
|
74 | - ); |
|
75 | - |
|
76 | - $fields[] = array( |
|
77 | - 'id' => 'wetu_skip_featured', |
|
78 | - 'name' => esc_html__( 'Skip Featured Image', 'lsx-banners' ), |
|
79 | - 'type' => 'checkbox', |
|
80 | - ); |
|
81 | - |
|
82 | - $meta_boxes[] = array( |
|
83 | - 'title' => esc_html__( 'WETU Settings', 'lsx-banners' ), |
|
84 | - 'pages' => $allowed_post_types, |
|
85 | - 'fields' => $fields, |
|
86 | - 'context' => 'side', |
|
87 | - 'priority' => 'low', |
|
88 | - ); |
|
89 | - |
|
90 | - return $meta_boxes; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Registers a 5 min schedule for us to use. |
|
95 | - * |
|
96 | - * @param array $schedules |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - public function register_schedule( $schedules ) { |
|
100 | - $schedules['wetu-5-minutes'] = array( |
|
101 | - 'interval' => 5 * MINUTE_IN_SECONDS, |
|
102 | - 'display' => __( 'Every 5 minutes', 'lsx-wetu-importer' ), |
|
103 | - ); |
|
104 | - return $schedules; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Watches for changes in the button triggers. |
|
109 | - * |
|
110 | - * @return void |
|
111 | - */ |
|
112 | - public function watch_for_trigger() { |
|
113 | - |
|
114 | - if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) { |
|
115 | - $options = lsx_wetu_get_options(); |
|
116 | - |
|
117 | - // Check what state the option is in. |
|
118 | - $accommodation_cron = 'deactivate'; |
|
119 | - if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { |
|
120 | - $accommodation_cron = 'activate'; |
|
121 | - } |
|
122 | - |
|
123 | - // Check what state the cron is in. |
|
124 | - $scheduled = false; |
|
125 | - if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) { |
|
126 | - $scheduled = true; |
|
127 | - } |
|
128 | - |
|
129 | - // If activate and its not running. |
|
130 | - if ( false === $scheduled && 'activate' === $accommodation_cron ) { |
|
131 | - $schedule = 'weekly'; |
|
132 | - $this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule ); |
|
133 | - } elseif ( true === $scheduled && 'deactivate' === $accommodation_cron ) { |
|
134 | - $this->deactivate(); |
|
135 | - } |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Remove our cron from the shedule. |
|
141 | - * |
|
142 | - * @return void |
|
143 | - */ |
|
144 | - public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) { |
|
145 | - wp_clear_scheduled_hook( $task, array( $task ) ); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * This function will schedule the cron event. |
|
150 | - * |
|
151 | - * @param string $task |
|
152 | - * @param string $schedule |
|
153 | - * @param string $time |
|
154 | - * @return void |
|
155 | - */ |
|
156 | - public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'weekly', $time = 'Sunday 10pm' ) { |
|
157 | - $args = array( $task ); |
|
158 | - if ( '' === $time ) { |
|
159 | - $time = time(); |
|
160 | - } |
|
161 | - |
|
162 | - if ( isset( $_GET['accommodation_images_cron_featured'] ) && '' !== $_GET['accommodation_images_cron_featured'] ) { |
|
163 | - $args[] = 'featured_image'; |
|
164 | - } |
|
165 | - wp_schedule_event( $time, $schedule, $task, $args ); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * This is the function that will be triggered by the cron event. |
|
170 | - * |
|
171 | - * @return void |
|
172 | - */ |
|
173 | - public function process( $task = '' ) { |
|
174 | - switch ( $task ) { |
|
175 | - case 'lsx_wetu_accommodation_images_cron': |
|
176 | - $this->register_accommodation_images_sync(); |
|
177 | - break; |
|
178 | - |
|
179 | - default: |
|
180 | - break; |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * This is the function that will be triggered by the cron event. |
|
186 | - * |
|
187 | - * @return void |
|
188 | - */ |
|
189 | - public function register_accommodation_images_sync() { |
|
190 | - $time = strtotime( '+5 min' ); |
|
191 | - if ( ! wp_next_scheduled( 'lsx_wetu_accommodation_images_sync' ) ) { |
|
192 | - $this->load_items_to_sync( 'accommodation_images' ); |
|
193 | - $this->schedule( 'lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time ); |
|
194 | - } |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * This is the function that will be triggered by the cron event. |
|
199 | - * |
|
200 | - * @return void |
|
201 | - */ |
|
202 | - public function cron_callback( $task = '', $featured_image = '' ) { |
|
203 | - $has_accommodation = get_option( $task ); |
|
204 | - if ( false !== $has_accommodation && ! empty( $has_accommodation ) ) { |
|
205 | - $next_time = array_slice( $has_accommodation, 3 ); |
|
206 | - $this_time = array_slice( $has_accommodation, 0, 2 ); |
|
207 | - |
|
208 | - $api_key = $this->get_api_key(); |
|
209 | - $url = 'https://wetu.com/API/Pins/' . $api_key . '/Get?all=include&ids='; |
|
210 | - |
|
211 | - // Run through the current items. |
|
212 | - foreach ( $this_time as $accommodation ) { |
|
213 | - $wetu_id = get_post_meta( $accommodation, 'lsx_wetu_id', true ); |
|
214 | - $last_date = get_post_meta( $accommodation, 'lsx_wetu_modified_date', true ); |
|
215 | - |
|
216 | - // Grabbing the image sync. |
|
217 | - $featured_image = get_post_meta( $accommodation, 'wetu_skip_featured', true ); |
|
218 | - $banner_image = get_post_meta( $accommodation, 'wetu_skip_banner', true ); |
|
219 | - |
|
220 | - $accommodation_info = wp_remote_get( $url . $wetu_id ); |
|
221 | - if ( ! empty( $accommodation_info ) && isset( $accommodation_info['response'] ) && isset( $accommodation_info['response']['code'] ) && 200 === $accommodation_info['response']['code'] ) { |
|
222 | - $adata = json_decode( $accommodation_info['body'], true ); |
|
223 | - |
|
224 | - if ( isset( $adata[0] ) && isset( $adata[0]['last_modified'] ) && '' !== $adata[0]['last_modified'] ) { |
|
225 | - $modified_time = strtotime( $adata[0]['last_modified'] ); |
|
226 | - if ( $modified_time > $last_date ) { |
|
227 | - $accommodation_importer = new \LSX_WETU_Importer_Accommodation(); |
|
228 | - |
|
229 | - if ( false === $banner_image || '' === $banner_image ) { |
|
230 | - $accommodation_importer->set_banner_image( $adata, $accommodation ); |
|
231 | - } |
|
232 | - |
|
233 | - if ( false === $featured_image || '' === $featured_image ) { |
|
234 | - $accommodation_importer->set_featured_image( $adata, $accommodation ); |
|
235 | - } |
|
236 | - |
|
237 | - $accommodation_importer->create_main_gallery( $adata, $accommodation ); |
|
238 | - update_post_meta( $accommodation, 'lsx_wetu_modified_date', $modified_time, $last_date ); |
|
239 | - } |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - // Save the values for next time. |
|
245 | - if ( ! empty( $next_time ) ) { |
|
246 | - update_option( $task, $next_time ); |
|
247 | - } else { |
|
248 | - delete_option( $task ); |
|
249 | - $this->deactivate( $task ); |
|
250 | - } |
|
251 | - } else { |
|
252 | - $this->deactivate( $task ); |
|
253 | - update_option( 'lsx_wetu_nexttime', $task ); |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * This will grab the accommodation ids and load them up into an option field. |
|
259 | - * |
|
260 | - * @param string $task |
|
261 | - * @return void |
|
262 | - */ |
|
263 | - public function load_items_to_sync( $task = 'accommodation_images' ) { |
|
264 | - $args = array( |
|
265 | - 'post_status' => 'publish', |
|
266 | - 'posts_per_page' => -1, |
|
267 | - 'nopagin' => true, |
|
268 | - 'fields' => 'ids', |
|
269 | - ); |
|
270 | - switch ( $task ) { |
|
271 | - case 'accommodation_images': |
|
272 | - $args['post_type'] = 'accommodation'; |
|
273 | - break; |
|
274 | - |
|
275 | - default: |
|
276 | - break; |
|
277 | - } |
|
278 | - $items = new \WP_Query( $args ); |
|
279 | - if ( $items->have_posts() ) { |
|
280 | - update_option( 'lsx_wetu_' . $task . '_sync', $items->posts ); |
|
281 | - } |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * Gets the API key stored in the options table. |
|
286 | - * |
|
287 | - * @return string |
|
288 | - */ |
|
289 | - public function get_api_key() { |
|
290 | - $api_key = false; |
|
291 | - $options = lsx_wetu_get_options(); |
|
292 | - |
|
293 | - if ( ! defined( 'WETU_API_KEY' ) ) { |
|
294 | - if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) { |
|
295 | - $api_key = $options['api_key']; |
|
296 | - } |
|
297 | - } else { |
|
298 | - $api_key = WETU_API_KEY; |
|
299 | - } |
|
300 | - return $api_key; |
|
301 | - } |
|
19 | + /** |
|
20 | + * Holds class instance |
|
21 | + * |
|
22 | + * @since 1.0.0 |
|
23 | + * |
|
24 | + * @var object|Module_Template |
|
25 | + */ |
|
26 | + protected static $instance = null; |
|
27 | + |
|
28 | + /** |
|
29 | + * Initialize the plugin by setting localization, filters, and administration functions. |
|
30 | + * |
|
31 | + * @since 1.0.0 |
|
32 | + * |
|
33 | + * @access private |
|
34 | + */ |
|
35 | + public function __construct() { |
|
36 | + add_filter( 'cron_schedules', array( $this, 'register_schedule' ), 10, 1 ); |
|
37 | + add_action( 'lsx_wetu_importer_settings_before', array( $this, 'watch_for_trigger' ), 200 ); |
|
38 | + add_action( 'lsx_wetu_accommodation_images_cron', array( $this, 'process' ), 10, 1 ); |
|
39 | + add_action( 'lsx_wetu_accommodation_images_sync', array( $this, 'cron_callback' ), 10, 1 ); |
|
40 | + add_filter( 'cmb_meta_boxes', array( $this, 'metaboxes' ) ); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Return an instance of this class. |
|
45 | + * |
|
46 | + * @since 1.0.0 |
|
47 | + * |
|
48 | + * @return object Cron() A single instance of this class. |
|
49 | + */ |
|
50 | + public static function get_instance() { |
|
51 | + // If the single instance hasn't been set, set it now. |
|
52 | + if ( null === self::$instance ) { |
|
53 | + self::$instance = new self(); |
|
54 | + } |
|
55 | + return self::$instance; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Define the metabox and field configurations. |
|
60 | + * |
|
61 | + * @param array $meta_boxes |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + public function metaboxes( array $meta_boxes ) { |
|
65 | + // Allowed post types. |
|
66 | + $allowed_post_types = array( 'accommodation' ); |
|
67 | + |
|
68 | + $fields = array(); |
|
69 | + |
|
70 | + $fields[] = array( |
|
71 | + 'id' => 'wetu_skip_banner', |
|
72 | + 'name' => esc_html__( 'Skip Banner Image', 'lsx-banners' ), |
|
73 | + 'type' => 'checkbox', |
|
74 | + ); |
|
75 | + |
|
76 | + $fields[] = array( |
|
77 | + 'id' => 'wetu_skip_featured', |
|
78 | + 'name' => esc_html__( 'Skip Featured Image', 'lsx-banners' ), |
|
79 | + 'type' => 'checkbox', |
|
80 | + ); |
|
81 | + |
|
82 | + $meta_boxes[] = array( |
|
83 | + 'title' => esc_html__( 'WETU Settings', 'lsx-banners' ), |
|
84 | + 'pages' => $allowed_post_types, |
|
85 | + 'fields' => $fields, |
|
86 | + 'context' => 'side', |
|
87 | + 'priority' => 'low', |
|
88 | + ); |
|
89 | + |
|
90 | + return $meta_boxes; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Registers a 5 min schedule for us to use. |
|
95 | + * |
|
96 | + * @param array $schedules |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + public function register_schedule( $schedules ) { |
|
100 | + $schedules['wetu-5-minutes'] = array( |
|
101 | + 'interval' => 5 * MINUTE_IN_SECONDS, |
|
102 | + 'display' => __( 'Every 5 minutes', 'lsx-wetu-importer' ), |
|
103 | + ); |
|
104 | + return $schedules; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Watches for changes in the button triggers. |
|
109 | + * |
|
110 | + * @return void |
|
111 | + */ |
|
112 | + public function watch_for_trigger() { |
|
113 | + |
|
114 | + if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) { |
|
115 | + $options = lsx_wetu_get_options(); |
|
116 | + |
|
117 | + // Check what state the option is in. |
|
118 | + $accommodation_cron = 'deactivate'; |
|
119 | + if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { |
|
120 | + $accommodation_cron = 'activate'; |
|
121 | + } |
|
122 | + |
|
123 | + // Check what state the cron is in. |
|
124 | + $scheduled = false; |
|
125 | + if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) { |
|
126 | + $scheduled = true; |
|
127 | + } |
|
128 | + |
|
129 | + // If activate and its not running. |
|
130 | + if ( false === $scheduled && 'activate' === $accommodation_cron ) { |
|
131 | + $schedule = 'weekly'; |
|
132 | + $this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule ); |
|
133 | + } elseif ( true === $scheduled && 'deactivate' === $accommodation_cron ) { |
|
134 | + $this->deactivate(); |
|
135 | + } |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Remove our cron from the shedule. |
|
141 | + * |
|
142 | + * @return void |
|
143 | + */ |
|
144 | + public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) { |
|
145 | + wp_clear_scheduled_hook( $task, array( $task ) ); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * This function will schedule the cron event. |
|
150 | + * |
|
151 | + * @param string $task |
|
152 | + * @param string $schedule |
|
153 | + * @param string $time |
|
154 | + * @return void |
|
155 | + */ |
|
156 | + public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'weekly', $time = 'Sunday 10pm' ) { |
|
157 | + $args = array( $task ); |
|
158 | + if ( '' === $time ) { |
|
159 | + $time = time(); |
|
160 | + } |
|
161 | + |
|
162 | + if ( isset( $_GET['accommodation_images_cron_featured'] ) && '' !== $_GET['accommodation_images_cron_featured'] ) { |
|
163 | + $args[] = 'featured_image'; |
|
164 | + } |
|
165 | + wp_schedule_event( $time, $schedule, $task, $args ); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * This is the function that will be triggered by the cron event. |
|
170 | + * |
|
171 | + * @return void |
|
172 | + */ |
|
173 | + public function process( $task = '' ) { |
|
174 | + switch ( $task ) { |
|
175 | + case 'lsx_wetu_accommodation_images_cron': |
|
176 | + $this->register_accommodation_images_sync(); |
|
177 | + break; |
|
178 | + |
|
179 | + default: |
|
180 | + break; |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * This is the function that will be triggered by the cron event. |
|
186 | + * |
|
187 | + * @return void |
|
188 | + */ |
|
189 | + public function register_accommodation_images_sync() { |
|
190 | + $time = strtotime( '+5 min' ); |
|
191 | + if ( ! wp_next_scheduled( 'lsx_wetu_accommodation_images_sync' ) ) { |
|
192 | + $this->load_items_to_sync( 'accommodation_images' ); |
|
193 | + $this->schedule( 'lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time ); |
|
194 | + } |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * This is the function that will be triggered by the cron event. |
|
199 | + * |
|
200 | + * @return void |
|
201 | + */ |
|
202 | + public function cron_callback( $task = '', $featured_image = '' ) { |
|
203 | + $has_accommodation = get_option( $task ); |
|
204 | + if ( false !== $has_accommodation && ! empty( $has_accommodation ) ) { |
|
205 | + $next_time = array_slice( $has_accommodation, 3 ); |
|
206 | + $this_time = array_slice( $has_accommodation, 0, 2 ); |
|
207 | + |
|
208 | + $api_key = $this->get_api_key(); |
|
209 | + $url = 'https://wetu.com/API/Pins/' . $api_key . '/Get?all=include&ids='; |
|
210 | + |
|
211 | + // Run through the current items. |
|
212 | + foreach ( $this_time as $accommodation ) { |
|
213 | + $wetu_id = get_post_meta( $accommodation, 'lsx_wetu_id', true ); |
|
214 | + $last_date = get_post_meta( $accommodation, 'lsx_wetu_modified_date', true ); |
|
215 | + |
|
216 | + // Grabbing the image sync. |
|
217 | + $featured_image = get_post_meta( $accommodation, 'wetu_skip_featured', true ); |
|
218 | + $banner_image = get_post_meta( $accommodation, 'wetu_skip_banner', true ); |
|
219 | + |
|
220 | + $accommodation_info = wp_remote_get( $url . $wetu_id ); |
|
221 | + if ( ! empty( $accommodation_info ) && isset( $accommodation_info['response'] ) && isset( $accommodation_info['response']['code'] ) && 200 === $accommodation_info['response']['code'] ) { |
|
222 | + $adata = json_decode( $accommodation_info['body'], true ); |
|
223 | + |
|
224 | + if ( isset( $adata[0] ) && isset( $adata[0]['last_modified'] ) && '' !== $adata[0]['last_modified'] ) { |
|
225 | + $modified_time = strtotime( $adata[0]['last_modified'] ); |
|
226 | + if ( $modified_time > $last_date ) { |
|
227 | + $accommodation_importer = new \LSX_WETU_Importer_Accommodation(); |
|
228 | + |
|
229 | + if ( false === $banner_image || '' === $banner_image ) { |
|
230 | + $accommodation_importer->set_banner_image( $adata, $accommodation ); |
|
231 | + } |
|
232 | + |
|
233 | + if ( false === $featured_image || '' === $featured_image ) { |
|
234 | + $accommodation_importer->set_featured_image( $adata, $accommodation ); |
|
235 | + } |
|
236 | + |
|
237 | + $accommodation_importer->create_main_gallery( $adata, $accommodation ); |
|
238 | + update_post_meta( $accommodation, 'lsx_wetu_modified_date', $modified_time, $last_date ); |
|
239 | + } |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + // Save the values for next time. |
|
245 | + if ( ! empty( $next_time ) ) { |
|
246 | + update_option( $task, $next_time ); |
|
247 | + } else { |
|
248 | + delete_option( $task ); |
|
249 | + $this->deactivate( $task ); |
|
250 | + } |
|
251 | + } else { |
|
252 | + $this->deactivate( $task ); |
|
253 | + update_option( 'lsx_wetu_nexttime', $task ); |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * This will grab the accommodation ids and load them up into an option field. |
|
259 | + * |
|
260 | + * @param string $task |
|
261 | + * @return void |
|
262 | + */ |
|
263 | + public function load_items_to_sync( $task = 'accommodation_images' ) { |
|
264 | + $args = array( |
|
265 | + 'post_status' => 'publish', |
|
266 | + 'posts_per_page' => -1, |
|
267 | + 'nopagin' => true, |
|
268 | + 'fields' => 'ids', |
|
269 | + ); |
|
270 | + switch ( $task ) { |
|
271 | + case 'accommodation_images': |
|
272 | + $args['post_type'] = 'accommodation'; |
|
273 | + break; |
|
274 | + |
|
275 | + default: |
|
276 | + break; |
|
277 | + } |
|
278 | + $items = new \WP_Query( $args ); |
|
279 | + if ( $items->have_posts() ) { |
|
280 | + update_option( 'lsx_wetu_' . $task . '_sync', $items->posts ); |
|
281 | + } |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * Gets the API key stored in the options table. |
|
286 | + * |
|
287 | + * @return string |
|
288 | + */ |
|
289 | + public function get_api_key() { |
|
290 | + $api_key = false; |
|
291 | + $options = lsx_wetu_get_options(); |
|
292 | + |
|
293 | + if ( ! defined( 'WETU_API_KEY' ) ) { |
|
294 | + if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) { |
|
295 | + $api_key = $options['api_key']; |
|
296 | + } |
|
297 | + } else { |
|
298 | + $api_key = WETU_API_KEY; |
|
299 | + } |
|
300 | + return $api_key; |
|
301 | + } |
|
302 | 302 | } |
303 | 303 | Cron::get_instance(); |
@@ -9,32 +9,32 @@ discard block |
||
9 | 9 | |
10 | 10 | class LSX_WETU_Importer_Banner_Integration extends LSX_WETU_Importer { |
11 | 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 = 'banners'; |
|
20 | - |
|
21 | - /** |
|
22 | - * Initialize the plugin by setting localization, filters, and administration functions. |
|
23 | - * |
|
24 | - * @since 1.0.0 |
|
25 | - * |
|
26 | - * @access private |
|
27 | - */ |
|
28 | - public function __construct() { |
|
29 | - add_action( 'wp_ajax_lsx_import_sync_banners', array( $this, 'sync_new_banner' ) ); |
|
30 | - add_action( 'wp_ajax_nopriv_lsx_import_sync_banners', array( $this, 'sync_new_banner' ) ); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * Display the importer administration screen |
|
35 | - */ |
|
36 | - public function display_page() { |
|
37 | - ?> |
|
12 | + /** |
|
13 | + * The url to list items from WETU |
|
14 | + * |
|
15 | + * @since 0.0.1 |
|
16 | + * |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + public $tab_slug = 'banners'; |
|
20 | + |
|
21 | + /** |
|
22 | + * Initialize the plugin by setting localization, filters, and administration functions. |
|
23 | + * |
|
24 | + * @since 1.0.0 |
|
25 | + * |
|
26 | + * @access private |
|
27 | + */ |
|
28 | + public function __construct() { |
|
29 | + add_action( 'wp_ajax_lsx_import_sync_banners', array( $this, 'sync_new_banner' ) ); |
|
30 | + add_action( 'wp_ajax_nopriv_lsx_import_sync_banners', array( $this, 'sync_new_banner' ) ); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * Display the importer administration screen |
|
35 | + */ |
|
36 | + public function display_page() { |
|
37 | + ?> |
|
38 | 38 | <div class="wrap"> |
39 | 39 | <h2><?php esc_html_e( 'Download new banners straight from WETU', 'lsx-wetu-importer' ); ?></h2> |
40 | 40 | |
@@ -58,67 +58,67 @@ discard block |
||
58 | 58 | </thead> |
59 | 59 | |
60 | 60 | <?php |
61 | - $accommodation_args = array( |
|
62 | - 'post_type' => 'accommodation', |
|
63 | - 'post_status' => array( 'publish', 'pending', 'draft', 'future', 'private' ), |
|
64 | - 'nopagin' => 'true', |
|
65 | - 'posts_per_page' => '1000', |
|
66 | - 'meta_query' => array( |
|
67 | - 'relation' => 'AND', |
|
68 | - array( |
|
69 | - 'key' => 'lsx_wetu_id', |
|
70 | - 'compare' => 'EXISTS', |
|
71 | - ), |
|
72 | - array( |
|
73 | - 'key' => 'image_group', |
|
74 | - 'compare' => 'EXISTS', |
|
75 | - ), |
|
76 | - array( |
|
77 | - 'key' => 'image_group', |
|
78 | - 'value' => 'a:1:{s:12:"banner_image";a:0:{}}', |
|
79 | - 'compare' => '!=', |
|
80 | - ), |
|
81 | - ), |
|
82 | - ); |
|
83 | - $accommodation = new WP_Query( $accommodation_args ); |
|
84 | - ?> |
|
61 | + $accommodation_args = array( |
|
62 | + 'post_type' => 'accommodation', |
|
63 | + 'post_status' => array( 'publish', 'pending', 'draft', 'future', 'private' ), |
|
64 | + 'nopagin' => 'true', |
|
65 | + 'posts_per_page' => '1000', |
|
66 | + 'meta_query' => array( |
|
67 | + 'relation' => 'AND', |
|
68 | + array( |
|
69 | + 'key' => 'lsx_wetu_id', |
|
70 | + 'compare' => 'EXISTS', |
|
71 | + ), |
|
72 | + array( |
|
73 | + 'key' => 'image_group', |
|
74 | + 'compare' => 'EXISTS', |
|
75 | + ), |
|
76 | + array( |
|
77 | + 'key' => 'image_group', |
|
78 | + 'value' => 'a:1:{s:12:"banner_image";a:0:{}}', |
|
79 | + 'compare' => '!=', |
|
80 | + ), |
|
81 | + ), |
|
82 | + ); |
|
83 | + $accommodation = new WP_Query( $accommodation_args ); |
|
84 | + ?> |
|
85 | 85 | |
86 | 86 | <tbody id="the-list"> |
87 | 87 | <?php |
88 | - if ( $accommodation->have_posts() ) { |
|
89 | - while ( $accommodation->have_posts() ) { |
|
90 | - $accommodation->the_post(); |
|
91 | - ?> |
|
88 | + if ( $accommodation->have_posts() ) { |
|
89 | + while ( $accommodation->have_posts() ) { |
|
90 | + $accommodation->the_post(); |
|
91 | + ?> |
|
92 | 92 | <tr class="post-<?php the_ID(); ?> type-tour status-none" id="post-<?php the_ID(); ?>"> |
93 | 93 | <?php |
94 | - $banner_size_appropriate = false; |
|
95 | - $min_width = '1920'; |
|
96 | - $min_height = '500'; |
|
94 | + $banner_size_appropriate = false; |
|
95 | + $min_width = '1920'; |
|
96 | + $min_height = '500'; |
|
97 | 97 | |
98 | - $img_group = get_post_meta( get_the_ID(), 'image_group', true ); |
|
98 | + $img_group = get_post_meta( get_the_ID(), 'image_group', true ); |
|
99 | 99 | |
100 | - $thumbnails_html = false; |
|
100 | + $thumbnails_html = false; |
|
101 | 101 | |
102 | - if ( false !== $img_group ) { |
|
103 | - foreach ( $img_group['banner_image'] as $banner_image ) { |
|
104 | - $large = wp_get_attachment_image_src( $banner_image, 'full' ); |
|
105 | - $real_width = $large[1]; |
|
106 | - $real_height = $large[2]; |
|
102 | + if ( false !== $img_group ) { |
|
103 | + foreach ( $img_group['banner_image'] as $banner_image ) { |
|
104 | + $large = wp_get_attachment_image_src( $banner_image, 'full' ); |
|
105 | + $real_width = $large[1]; |
|
106 | + $real_height = $large[2]; |
|
107 | 107 | |
108 | - $status = 'optimized'; |
|
109 | - if ( $real_width < intval( $real_width ) ) { |
|
110 | - $status = 'width not enough.'; |
|
111 | - } |
|
108 | + $status = 'optimized'; |
|
109 | + if ( $real_width < intval( $real_width ) ) { |
|
110 | + $status = 'width not enough.'; |
|
111 | + } |
|
112 | 112 | |
113 | - $thumbnail = wp_get_attachment_image_src( $banner_image, 'thumbnail' ); |
|
114 | - $thumbnails_html[] = ' |
|
113 | + $thumbnail = wp_get_attachment_image_src( $banner_image, 'thumbnail' ); |
|
114 | + $thumbnails_html[] = ' |
|
115 | 115 | <div style="display:block;float:left;"> |
116 | 116 | <img src="' . $thumbnail[0] . '" /> |
117 | 117 | <p style="text-align:center;">' . $real_width . 'px by ' . $real_height . 'px</p> |
118 | 118 | </div>'; |
119 | - } |
|
120 | - } |
|
121 | - ?> |
|
119 | + } |
|
120 | + } |
|
121 | + ?> |
|
122 | 122 | <th class="check-column" scope="row"> |
123 | 123 | <label for="cb-select-<?php the_ID(); ?>" class="screen-reader-text"></label> |
124 | 124 | <input type="checkbox" data-identifier="<?php the_ID(); ?>" value="<?php the_ID(); ?>" name="post[]" id="cb-select-<?php the_ID(); ?>"> |
@@ -126,26 +126,26 @@ discard block |
||
126 | 126 | |
127 | 127 | <td class="post-title page-title column-title"> |
128 | 128 | <?php |
129 | - echo '<a href="' . esc_url( admin_url( '/post.php?post=' . get_the_ID() . '&action=edit' ) ) . '" target="_blank">'; |
|
130 | - the_title(); |
|
131 | - echo '</a>'; |
|
132 | - ?> |
|
129 | + echo '<a href="' . esc_url( admin_url( '/post.php?post=' . get_the_ID() . '&action=edit' ) ) . '" target="_blank">'; |
|
130 | + the_title(); |
|
131 | + echo '</a>'; |
|
132 | + ?> |
|
133 | 133 | </td> |
134 | 134 | |
135 | 135 | <td colspan="2" class="thumbnails column-thumbnails"> |
136 | 136 | <?php |
137 | - if ( false !== $thumbnails_html ) { |
|
138 | - echo wp_kses_post( implode( '', $thumbnails_html ) ); |
|
139 | - } else { |
|
140 | - echo '<p>There was an error retrieving your images.</p>'; |
|
141 | - } |
|
142 | - ?> |
|
137 | + if ( false !== $thumbnails_html ) { |
|
138 | + echo wp_kses_post( implode( '', $thumbnails_html ) ); |
|
139 | + } else { |
|
140 | + echo '<p>There was an error retrieving your images.</p>'; |
|
141 | + } |
|
142 | + ?> |
|
143 | 143 | </td> |
144 | 144 | </tr> |
145 | 145 | <?php |
146 | - } |
|
147 | - } |
|
148 | - ?> |
|
146 | + } |
|
147 | + } |
|
148 | + ?> |
|
149 | 149 | </tbody> |
150 | 150 | |
151 | 151 | <tfoot> |
@@ -166,125 +166,125 @@ discard block |
||
166 | 166 | </form> |
167 | 167 | </div> |
168 | 168 | <?php |
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Creates the main gallery data |
|
173 | - */ |
|
174 | - public function sync_new_banner() { |
|
175 | - check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
176 | - if ( isset( $_POST['action'] ) && 'lsx_import_sync_banners' === $_POST['action'] && isset( $_POST['post_id'] ) ) { |
|
177 | - |
|
178 | - $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
179 | - $banners = get_post_meta( $post_id, 'image_group', true ); |
|
180 | - $this->wetu_id = get_post_meta( $post_id, 'lsx_wetu_id', true ); |
|
181 | - |
|
182 | - $new_banner_array = false; |
|
183 | - $array_index = 0; |
|
184 | - |
|
185 | - foreach ( $banners['banner_image'] as $banner_image ) { |
|
186 | - $image_id = $this->attach_external_image2( $this->format_wetu_url( $banner_image ), array(), $post_id ); |
|
187 | - if ( null !== $image_id && '' !== $image_id ) { |
|
188 | - $new_banner_array['banner_image'][ 'cmb-field-' . $array_index ] = $image_id; |
|
189 | - $array_index++; |
|
190 | - } |
|
191 | - } |
|
192 | - |
|
193 | - if ( false !== $new_banner_array ) { |
|
194 | - delete_post_meta( $post_id, 'image_group' ); |
|
195 | - add_post_meta( $post_id, 'image_group', $new_banner_array, true ); |
|
196 | - echo true; |
|
197 | - } else { |
|
198 | - echo false; |
|
199 | - } |
|
200 | - } else { |
|
201 | - echo false; |
|
202 | - } |
|
203 | - |
|
204 | - die(); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * formats the url |
|
209 | - */ |
|
210 | - public function format_wetu_url( $post_id ) { |
|
211 | - return 'https://wetu.com/ImageHandler/c1920x800/' . $this->wetu_id . '/' . $this->format_filename( $post_id ); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * formats the filename |
|
216 | - */ |
|
217 | - public function format_filename( $post_id ) { |
|
218 | - $base = str_replace( '_', ' ', get_the_title( $post_id ) ); |
|
219 | - $base = rawurlencode( $base ); |
|
220 | - $type = get_post_mime_type( $post_id ); |
|
221 | - |
|
222 | - switch ( $type ) { |
|
223 | - case 'image/jpeg': |
|
224 | - return $base . '.jpg'; |
|
225 | - break; |
|
226 | - case 'image/png': |
|
227 | - return $base . '.png'; |
|
228 | - break; |
|
229 | - case 'image/gif': |
|
230 | - return $base . '.gif'; |
|
231 | - break; |
|
232 | - default: |
|
233 | - return false; |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - public function attach_external_image2( $url = null, $post_data = array(), $post_id = '' ) { |
|
238 | - if ( ! $url ) { |
|
239 | - return new WP_Error( 'missing', 'Need a valid URL' ); } |
|
240 | - $att_id = false; |
|
241 | - |
|
242 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
243 | - require_once ABSPATH . 'wp-admin/includes/media.php'; |
|
244 | - require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
245 | - |
|
246 | - $tmp = tempnam( '/tmp', 'FOO' ); |
|
247 | - $image = wp_remote_get( $url ); |
|
248 | - |
|
249 | - if ( ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) { |
|
250 | - file_put_contents( $tmp, $image['body'] ); |
|
251 | - chmod( $tmp, '777' ); |
|
252 | - |
|
253 | - preg_match( '/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches ); |
|
254 | - $url_filename = basename( $matches[0] ); |
|
255 | - $url_filename = str_replace( '%20', '_', $url_filename ); |
|
256 | - // extract filename from url for title. |
|
257 | - $url_type = wp_check_filetype( $url_filename ); |
|
258 | - |
|
259 | - // assemble file data (should be built like $_FILES since wp_handle_sideload() will be using). |
|
260 | - $file_array['tmp_name'] = $tmp; |
|
261 | - |
|
262 | - if ( ! empty( $filename ) && ' ' != $filename ) { |
|
263 | - $file_array['name'] = $filename . '.' . $url_type['ext']; |
|
264 | - } else { |
|
265 | - $file_array['name'] = $url_filename; |
|
266 | - } |
|
267 | - |
|
268 | - // set additional wp_posts columns. |
|
269 | - if ( empty( $post_data['post_title'] ) ) { |
|
270 | - $url_filename = str_replace( '%20', ' ', $url_filename ); |
|
271 | - $post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] ); |
|
272 | - } |
|
273 | - |
|
274 | - // make sure gets tied to parent. |
|
275 | - if ( empty( $post_data['post_parent'] ) ) { |
|
276 | - $post_data['post_parent'] = $post_id; |
|
277 | - } |
|
278 | - |
|
279 | - // do the validation and storage stuff. |
|
280 | - $att_id = media_handle_sideload( $file_array, $post_id, null, $post_data ); |
|
281 | - |
|
282 | - // If error storing permanently, unlink. |
|
283 | - if ( is_wp_error( $att_id ) ) { |
|
284 | - unlink( $file_array['tmp_name'] ); |
|
285 | - return false; |
|
286 | - } |
|
287 | - } |
|
288 | - return $att_id; |
|
289 | - } |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Creates the main gallery data |
|
173 | + */ |
|
174 | + public function sync_new_banner() { |
|
175 | + check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
176 | + if ( isset( $_POST['action'] ) && 'lsx_import_sync_banners' === $_POST['action'] && isset( $_POST['post_id'] ) ) { |
|
177 | + |
|
178 | + $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
179 | + $banners = get_post_meta( $post_id, 'image_group', true ); |
|
180 | + $this->wetu_id = get_post_meta( $post_id, 'lsx_wetu_id', true ); |
|
181 | + |
|
182 | + $new_banner_array = false; |
|
183 | + $array_index = 0; |
|
184 | + |
|
185 | + foreach ( $banners['banner_image'] as $banner_image ) { |
|
186 | + $image_id = $this->attach_external_image2( $this->format_wetu_url( $banner_image ), array(), $post_id ); |
|
187 | + if ( null !== $image_id && '' !== $image_id ) { |
|
188 | + $new_banner_array['banner_image'][ 'cmb-field-' . $array_index ] = $image_id; |
|
189 | + $array_index++; |
|
190 | + } |
|
191 | + } |
|
192 | + |
|
193 | + if ( false !== $new_banner_array ) { |
|
194 | + delete_post_meta( $post_id, 'image_group' ); |
|
195 | + add_post_meta( $post_id, 'image_group', $new_banner_array, true ); |
|
196 | + echo true; |
|
197 | + } else { |
|
198 | + echo false; |
|
199 | + } |
|
200 | + } else { |
|
201 | + echo false; |
|
202 | + } |
|
203 | + |
|
204 | + die(); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * formats the url |
|
209 | + */ |
|
210 | + public function format_wetu_url( $post_id ) { |
|
211 | + return 'https://wetu.com/ImageHandler/c1920x800/' . $this->wetu_id . '/' . $this->format_filename( $post_id ); |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * formats the filename |
|
216 | + */ |
|
217 | + public function format_filename( $post_id ) { |
|
218 | + $base = str_replace( '_', ' ', get_the_title( $post_id ) ); |
|
219 | + $base = rawurlencode( $base ); |
|
220 | + $type = get_post_mime_type( $post_id ); |
|
221 | + |
|
222 | + switch ( $type ) { |
|
223 | + case 'image/jpeg': |
|
224 | + return $base . '.jpg'; |
|
225 | + break; |
|
226 | + case 'image/png': |
|
227 | + return $base . '.png'; |
|
228 | + break; |
|
229 | + case 'image/gif': |
|
230 | + return $base . '.gif'; |
|
231 | + break; |
|
232 | + default: |
|
233 | + return false; |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + public function attach_external_image2( $url = null, $post_data = array(), $post_id = '' ) { |
|
238 | + if ( ! $url ) { |
|
239 | + return new WP_Error( 'missing', 'Need a valid URL' ); } |
|
240 | + $att_id = false; |
|
241 | + |
|
242 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
243 | + require_once ABSPATH . 'wp-admin/includes/media.php'; |
|
244 | + require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
245 | + |
|
246 | + $tmp = tempnam( '/tmp', 'FOO' ); |
|
247 | + $image = wp_remote_get( $url ); |
|
248 | + |
|
249 | + if ( ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) { |
|
250 | + file_put_contents( $tmp, $image['body'] ); |
|
251 | + chmod( $tmp, '777' ); |
|
252 | + |
|
253 | + preg_match( '/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches ); |
|
254 | + $url_filename = basename( $matches[0] ); |
|
255 | + $url_filename = str_replace( '%20', '_', $url_filename ); |
|
256 | + // extract filename from url for title. |
|
257 | + $url_type = wp_check_filetype( $url_filename ); |
|
258 | + |
|
259 | + // assemble file data (should be built like $_FILES since wp_handle_sideload() will be using). |
|
260 | + $file_array['tmp_name'] = $tmp; |
|
261 | + |
|
262 | + if ( ! empty( $filename ) && ' ' != $filename ) { |
|
263 | + $file_array['name'] = $filename . '.' . $url_type['ext']; |
|
264 | + } else { |
|
265 | + $file_array['name'] = $url_filename; |
|
266 | + } |
|
267 | + |
|
268 | + // set additional wp_posts columns. |
|
269 | + if ( empty( $post_data['post_title'] ) ) { |
|
270 | + $url_filename = str_replace( '%20', ' ', $url_filename ); |
|
271 | + $post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] ); |
|
272 | + } |
|
273 | + |
|
274 | + // make sure gets tied to parent. |
|
275 | + if ( empty( $post_data['post_parent'] ) ) { |
|
276 | + $post_data['post_parent'] = $post_id; |
|
277 | + } |
|
278 | + |
|
279 | + // do the validation and storage stuff. |
|
280 | + $att_id = media_handle_sideload( $file_array, $post_id, null, $post_data ); |
|
281 | + |
|
282 | + // If error storing permanently, unlink. |
|
283 | + if ( is_wp_error( $att_id ) ) { |
|
284 | + unlink( $file_array['tmp_name'] ); |
|
285 | + return false; |
|
286 | + } |
|
287 | + } |
|
288 | + return $att_id; |
|
289 | + } |
|
290 | 290 | } |
@@ -9,87 +9,87 @@ discard block |
||
9 | 9 | |
10 | 10 | class LSX_WETU_Importer_Destination extends LSX_WETU_Importer { |
11 | 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 | - public function set_variables() { |
|
72 | - parent::set_variables(); |
|
73 | - $this->url = 'https://wetu.com/API/Pins/' . $this->api_key; |
|
74 | - $this->url_qs = 'all=include'; |
|
75 | - $temp_options = get_option( '_lsx-to_settings', false ); |
|
76 | - |
|
77 | - if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) { |
|
78 | - $this->options = $temp_options[ $this->plugin_slug ]; |
|
79 | - } |
|
80 | - |
|
81 | - $destination_options = get_option( 'lsx_wetu_importer_destination_settings', false ); |
|
82 | - |
|
83 | - if ( false !== $destination_options ) { |
|
84 | - $this->destination_options = $destination_options; |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Display the importer administration screen |
|
90 | - */ |
|
91 | - public function display_page() { |
|
92 | - ?> |
|
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 | + public function set_variables() { |
|
72 | + parent::set_variables(); |
|
73 | + $this->url = 'https://wetu.com/API/Pins/' . $this->api_key; |
|
74 | + $this->url_qs = 'all=include'; |
|
75 | + $temp_options = get_option( '_lsx-to_settings', false ); |
|
76 | + |
|
77 | + if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) { |
|
78 | + $this->options = $temp_options[ $this->plugin_slug ]; |
|
79 | + } |
|
80 | + |
|
81 | + $destination_options = get_option( 'lsx_wetu_importer_destination_settings', false ); |
|
82 | + |
|
83 | + if ( false !== $destination_options ) { |
|
84 | + $this->destination_options = $destination_options; |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Display the importer administration screen |
|
90 | + */ |
|
91 | + public function display_page() { |
|
92 | + ?> |
|
93 | 93 | <div class="wrap"> |
94 | 94 | <div class="tablenav top"> |
95 | 95 | <div class="actions"> |
@@ -190,13 +190,13 @@ discard block |
||
190 | 190 | value="banner_image"/> <?php esc_html_e( 'Set Banner Image', 'lsx-wetu-importer' ); ?> |
191 | 191 | </li> |
192 | 192 | <?php |
193 | - /* |
|
193 | + /* |
|
194 | 194 | <li> |
195 | 195 | <input class="content" |
196 | 196 | type="checkbox" name="content[]" |
197 | 197 | value="unique_banner_image"/> <?php esc_html_e( 'Use the WETU banner field', 'lsx-wetu-importer' ); ?> |
198 | 198 | </li>*/ |
199 | - ?> |
|
199 | + ?> |
|
200 | 200 | |
201 | 201 | <li> |
202 | 202 | <input class="content" checked="checked" |
@@ -282,17 +282,17 @@ discard block |
||
282 | 282 | </div> |
283 | 283 | </div> |
284 | 284 | <?php |
285 | - } |
|
285 | + } |
|
286 | 286 | |
287 | - /** |
|
288 | - * Grab all the current destination posts via the lsx_wetu_id field. |
|
289 | - */ |
|
290 | - public function find_current_destination( $post_type = 'destination' ) { |
|
291 | - global $wpdb; |
|
292 | - $return = array(); |
|
287 | + /** |
|
288 | + * Grab all the current destination posts via the lsx_wetu_id field. |
|
289 | + */ |
|
290 | + public function find_current_destination( $post_type = 'destination' ) { |
|
291 | + global $wpdb; |
|
292 | + $return = array(); |
|
293 | 293 | |
294 | - // @codingStandardsIgnoreStart |
|
295 | - $current_destination = $wpdb->get_results(" |
|
294 | + // @codingStandardsIgnoreStart |
|
295 | + $current_destination = $wpdb->get_results(" |
|
296 | 296 | SELECT key1.post_id,key1.meta_value,key2.post_title as name,key2.post_date as last_modified |
297 | 297 | FROM {$wpdb->postmeta} key1 |
298 | 298 | |
@@ -304,151 +304,151 @@ discard block |
||
304 | 304 | |
305 | 305 | LIMIT 0,1000 |
306 | 306 | "); |
307 | - // @codingStandardsIgnoreEnd |
|
308 | - |
|
309 | - if ( null !== $current_destination && ! empty( $current_destination ) ) { |
|
310 | - foreach ( $current_destination as $accom ) { |
|
311 | - $return[ $accom->meta_value ] = $accom; |
|
312 | - } |
|
313 | - } |
|
314 | - |
|
315 | - return $return; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Run through the accommodation grabbed from the DB. |
|
320 | - */ |
|
321 | - public function process_ajax_search() { |
|
322 | - $return = false; |
|
323 | - check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
324 | - if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && 'destination' === $_POST['type'] ) { |
|
325 | - |
|
326 | - $searched_items = false; |
|
327 | - if ( isset( $_POST['keyword'] ) ) { |
|
328 | - $keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) ); |
|
329 | - } else { |
|
330 | - $keyphrases = array( 0 ); |
|
331 | - } |
|
332 | - |
|
333 | - if ( ! is_array( $keyphrases ) ) { |
|
334 | - $keyphrases = array( $keyphrases ); |
|
335 | - } |
|
336 | - foreach ( $keyphrases as &$keyword ) { |
|
337 | - $keyword = ltrim( rtrim( $keyword ) ); |
|
338 | - } |
|
339 | - |
|
340 | - $post_status = false; |
|
341 | - |
|
342 | - if ( in_array( 'publish', $keyphrases ) ) { |
|
343 | - $post_status = 'publish'; |
|
344 | - } |
|
345 | - if ( in_array( 'pending', $keyphrases ) ) { |
|
346 | - $post_status = 'pending'; |
|
347 | - } |
|
348 | - if ( in_array( 'draft', $keyphrases ) ) { |
|
349 | - $post_status = 'draft'; |
|
350 | - } |
|
351 | - if ( in_array( 'import', $keyphrases ) ) { |
|
352 | - $post_status = 'import'; |
|
353 | - } |
|
354 | - |
|
355 | - // If there is a post status use it. |
|
356 | - if ( false !== $post_status ) { |
|
357 | - |
|
358 | - $accommodation = array(); |
|
359 | - $current_accommodation = $this->find_current_accommodation( 'destination' ); |
|
360 | - if ( ! empty( $current_accommodation ) ) { |
|
361 | - foreach ( $current_accommodation as $cs_key => $ccs_id ) { |
|
362 | - $accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id ); |
|
363 | - } |
|
364 | - } |
|
365 | - |
|
366 | - // Run through each accommodation and use it. |
|
367 | - if ( ! empty( $accommodation ) ) { |
|
368 | - foreach ( $accommodation as $row_key => $row ) { |
|
369 | - $row['post_title'] = $row['name']; |
|
370 | - if ( 'import' === $post_status ) { |
|
371 | - if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) { |
|
372 | - $current_status = get_post_status( $row['post_id'] ); |
|
373 | - if ( 'draft' === $current_status ) { |
|
374 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key ); |
|
375 | - } |
|
376 | - } else { |
|
377 | - continue; |
|
378 | - } |
|
379 | - } else { |
|
380 | - if ( 0 === $row['post_id'] ) { |
|
381 | - continue; |
|
382 | - } else { |
|
383 | - $current_status = get_post_status( $row['post_id'] ); |
|
384 | - |
|
385 | - if ( $current_status !== $post_status ) { |
|
386 | - continue; |
|
387 | - } |
|
388 | - } |
|
389 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key ); |
|
390 | - } |
|
391 | - } |
|
392 | - } |
|
393 | - } else { |
|
394 | - |
|
395 | - $key_string_search = implode( '+', $keyphrases ); |
|
396 | - $search_data = wp_remote_get( $this->url . '/Search/' . $key_string_search . '/?all=include' ); |
|
397 | - |
|
398 | - if ( ! is_wp_error( $search_data ) || ! empty( $search_data ) && isset( $search_data['response'] ) && isset( $search_data['response']['code'] ) && 200 === $search_data['response']['code'] ) { |
|
399 | - $search_data = json_decode( $search_data['body'], true ); |
|
400 | - foreach ( $search_data as $sdata_key => $sdata ) { |
|
401 | - |
|
402 | - if ( isset( $sdata['type'] ) && 'Destination' !== trim( $sdata['type'] ) && 'Area' !== trim( $sdata['type'] ) ) { |
|
403 | - continue; |
|
404 | - } |
|
405 | - |
|
406 | - $temp_id = $this->get_post_id_by_key_value( $sdata['id'] ); |
|
407 | - if ( false === $temp_id ) { |
|
408 | - $sdata['post_id'] = 0; |
|
409 | - $sdata['post_title'] = $sdata['name']; |
|
410 | - } else { |
|
411 | - $sdata['post_id'] = $temp_id; |
|
412 | - $sdata['post_title'] = get_the_title( $temp_id ); |
|
413 | - } |
|
414 | - $searched_items[ sanitize_title( $sdata['name'] ) . '-' . $sdata['id'] ] = $this->format_row( $sdata, $sdata_key ); |
|
415 | - } |
|
416 | - } |
|
417 | - } |
|
418 | - |
|
419 | - if ( false !== $searched_items ) { |
|
420 | - $return = implode( $searched_items ); |
|
421 | - } |
|
422 | - print_r( $return ); |
|
423 | - } else { |
|
424 | - echo esc_attr( 'None found' ); |
|
425 | - } |
|
426 | - die(); |
|
427 | - } |
|
428 | - |
|
429 | - public function prepare_row_attributes( $cs_key, $ccs_id ) { |
|
430 | - $row_item = array( |
|
431 | - 'id' => $cs_key, |
|
432 | - 'type' => 'Destination', |
|
433 | - 'name' => get_the_title( $ccs_id ), |
|
434 | - 'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ), |
|
435 | - 'post_id' => $ccs_id, |
|
436 | - ); |
|
437 | - return $row_item; |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * Formats the row for output on the screen. |
|
442 | - */ |
|
443 | - public function format_row( $row = false, $row_key = '' ) { |
|
444 | - if ( false !== $row ) { |
|
445 | - |
|
446 | - $status = 'import'; |
|
447 | - if ( 0 !== $row['post_id'] ) { |
|
448 | - $status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>'; |
|
449 | - } |
|
450 | - |
|
451 | - $row_html = ' |
|
307 | + // @codingStandardsIgnoreEnd |
|
308 | + |
|
309 | + if ( null !== $current_destination && ! empty( $current_destination ) ) { |
|
310 | + foreach ( $current_destination as $accom ) { |
|
311 | + $return[ $accom->meta_value ] = $accom; |
|
312 | + } |
|
313 | + } |
|
314 | + |
|
315 | + return $return; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Run through the accommodation grabbed from the DB. |
|
320 | + */ |
|
321 | + public function process_ajax_search() { |
|
322 | + $return = false; |
|
323 | + check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
324 | + if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && 'destination' === $_POST['type'] ) { |
|
325 | + |
|
326 | + $searched_items = false; |
|
327 | + if ( isset( $_POST['keyword'] ) ) { |
|
328 | + $keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) ); |
|
329 | + } else { |
|
330 | + $keyphrases = array( 0 ); |
|
331 | + } |
|
332 | + |
|
333 | + if ( ! is_array( $keyphrases ) ) { |
|
334 | + $keyphrases = array( $keyphrases ); |
|
335 | + } |
|
336 | + foreach ( $keyphrases as &$keyword ) { |
|
337 | + $keyword = ltrim( rtrim( $keyword ) ); |
|
338 | + } |
|
339 | + |
|
340 | + $post_status = false; |
|
341 | + |
|
342 | + if ( in_array( 'publish', $keyphrases ) ) { |
|
343 | + $post_status = 'publish'; |
|
344 | + } |
|
345 | + if ( in_array( 'pending', $keyphrases ) ) { |
|
346 | + $post_status = 'pending'; |
|
347 | + } |
|
348 | + if ( in_array( 'draft', $keyphrases ) ) { |
|
349 | + $post_status = 'draft'; |
|
350 | + } |
|
351 | + if ( in_array( 'import', $keyphrases ) ) { |
|
352 | + $post_status = 'import'; |
|
353 | + } |
|
354 | + |
|
355 | + // If there is a post status use it. |
|
356 | + if ( false !== $post_status ) { |
|
357 | + |
|
358 | + $accommodation = array(); |
|
359 | + $current_accommodation = $this->find_current_accommodation( 'destination' ); |
|
360 | + if ( ! empty( $current_accommodation ) ) { |
|
361 | + foreach ( $current_accommodation as $cs_key => $ccs_id ) { |
|
362 | + $accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id ); |
|
363 | + } |
|
364 | + } |
|
365 | + |
|
366 | + // Run through each accommodation and use it. |
|
367 | + if ( ! empty( $accommodation ) ) { |
|
368 | + foreach ( $accommodation as $row_key => $row ) { |
|
369 | + $row['post_title'] = $row['name']; |
|
370 | + if ( 'import' === $post_status ) { |
|
371 | + if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) { |
|
372 | + $current_status = get_post_status( $row['post_id'] ); |
|
373 | + if ( 'draft' === $current_status ) { |
|
374 | + $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key ); |
|
375 | + } |
|
376 | + } else { |
|
377 | + continue; |
|
378 | + } |
|
379 | + } else { |
|
380 | + if ( 0 === $row['post_id'] ) { |
|
381 | + continue; |
|
382 | + } else { |
|
383 | + $current_status = get_post_status( $row['post_id'] ); |
|
384 | + |
|
385 | + if ( $current_status !== $post_status ) { |
|
386 | + continue; |
|
387 | + } |
|
388 | + } |
|
389 | + $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key ); |
|
390 | + } |
|
391 | + } |
|
392 | + } |
|
393 | + } else { |
|
394 | + |
|
395 | + $key_string_search = implode( '+', $keyphrases ); |
|
396 | + $search_data = wp_remote_get( $this->url . '/Search/' . $key_string_search . '/?all=include' ); |
|
397 | + |
|
398 | + if ( ! is_wp_error( $search_data ) || ! empty( $search_data ) && isset( $search_data['response'] ) && isset( $search_data['response']['code'] ) && 200 === $search_data['response']['code'] ) { |
|
399 | + $search_data = json_decode( $search_data['body'], true ); |
|
400 | + foreach ( $search_data as $sdata_key => $sdata ) { |
|
401 | + |
|
402 | + if ( isset( $sdata['type'] ) && 'Destination' !== trim( $sdata['type'] ) && 'Area' !== trim( $sdata['type'] ) ) { |
|
403 | + continue; |
|
404 | + } |
|
405 | + |
|
406 | + $temp_id = $this->get_post_id_by_key_value( $sdata['id'] ); |
|
407 | + if ( false === $temp_id ) { |
|
408 | + $sdata['post_id'] = 0; |
|
409 | + $sdata['post_title'] = $sdata['name']; |
|
410 | + } else { |
|
411 | + $sdata['post_id'] = $temp_id; |
|
412 | + $sdata['post_title'] = get_the_title( $temp_id ); |
|
413 | + } |
|
414 | + $searched_items[ sanitize_title( $sdata['name'] ) . '-' . $sdata['id'] ] = $this->format_row( $sdata, $sdata_key ); |
|
415 | + } |
|
416 | + } |
|
417 | + } |
|
418 | + |
|
419 | + if ( false !== $searched_items ) { |
|
420 | + $return = implode( $searched_items ); |
|
421 | + } |
|
422 | + print_r( $return ); |
|
423 | + } else { |
|
424 | + echo esc_attr( 'None found' ); |
|
425 | + } |
|
426 | + die(); |
|
427 | + } |
|
428 | + |
|
429 | + public function prepare_row_attributes( $cs_key, $ccs_id ) { |
|
430 | + $row_item = array( |
|
431 | + 'id' => $cs_key, |
|
432 | + 'type' => 'Destination', |
|
433 | + 'name' => get_the_title( $ccs_id ), |
|
434 | + 'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ), |
|
435 | + 'post_id' => $ccs_id, |
|
436 | + ); |
|
437 | + return $row_item; |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * Formats the row for output on the screen. |
|
442 | + */ |
|
443 | + public function format_row( $row = false, $row_key = '' ) { |
|
444 | + if ( false !== $row ) { |
|
445 | + |
|
446 | + $status = 'import'; |
|
447 | + if ( 0 !== $row['post_id'] ) { |
|
448 | + $status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>'; |
|
449 | + } |
|
450 | + |
|
451 | + $row_html = ' |
|
452 | 452 | <tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '"> |
453 | 453 | <th class="check-column" scope="row"> |
454 | 454 | <label for="cb-select-' . $row['id'] . '" class="screen-reader-text">' . $row['name'] . '</label> |
@@ -467,273 +467,273 @@ discard block |
||
467 | 467 | ' . $row['id'] . ' |
468 | 468 | </td> |
469 | 469 | </tr>'; |
470 | - return $row_html; |
|
471 | - } |
|
472 | - } |
|
473 | - |
|
474 | - /** |
|
475 | - * Connect to wetu |
|
476 | - */ |
|
477 | - public function process_ajax_import() { |
|
478 | - $return = false; |
|
479 | - |
|
480 | - check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
481 | - if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && 'destination' === $_POST['type'] && isset( $_POST['wetu_id'] ) ) { |
|
482 | - |
|
483 | - $wetu_id = sanitize_text_field( $_POST['wetu_id'] ); |
|
484 | - |
|
485 | - if ( isset( $_POST['post_id'] ) ) { |
|
486 | - $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
487 | - $this->current_post = get_post( $post_id ); |
|
488 | - } else { |
|
489 | - $post_id = 0; |
|
490 | - } |
|
491 | - |
|
492 | - if ( isset( $_POST['team_members'] ) ) { |
|
493 | - $team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) ); |
|
494 | - } else { |
|
495 | - $team_members = false; |
|
496 | - } |
|
497 | - |
|
498 | - $safari_brands = false; |
|
499 | - |
|
500 | - delete_option( 'lsx_wetu_importer_destination_settings' ); |
|
501 | - |
|
502 | - if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) { |
|
503 | - $content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) ); |
|
504 | - add_option( 'lsx_wetu_importer_destination_settings', $content ); |
|
505 | - } else { |
|
506 | - $content = false; |
|
507 | - } |
|
508 | - |
|
509 | - $jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
510 | - |
|
511 | - if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) { |
|
512 | - $adata = json_decode( $jdata['body'], true ); |
|
513 | - $return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands ); |
|
514 | - $this->remove_from_queue( $return ); |
|
515 | - $this->format_completed_row( $return ); |
|
516 | - } else { |
|
517 | - $this->format_error( esc_html__( 'There was a problem importing your destination, please try refreshing the page.', 'lsx-wetu-importer' ) ); |
|
518 | - } |
|
519 | - } |
|
520 | - die(); |
|
521 | - } |
|
522 | - |
|
523 | - /** |
|
524 | - * Saves the queue to the option. |
|
525 | - */ |
|
526 | - public function remove_from_queue( $id ) { |
|
527 | - if ( ! empty( $this->queued_imports ) ) { |
|
528 | - $key = array_search( $id, $this->queued_imports ); |
|
529 | - if ( false !== $key ) { |
|
530 | - unset( $this->queued_imports[ $key ] ); |
|
531 | - |
|
532 | - delete_option( 'lsx_wetu_importer_que' ); |
|
533 | - update_option( 'lsx_wetu_importer_que', $this->queued_imports ); |
|
534 | - } |
|
535 | - } |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Connect to wetu |
|
540 | - */ |
|
541 | - public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false ) { |
|
542 | - if ( 'Destination' === trim( $data[0]['type'] ) || 'Area' === trim( $data[0]['type'] ) ) { |
|
543 | - $post_name = ''; |
|
544 | - $data_post_content = ''; |
|
545 | - $data_post_excerpt = ''; |
|
546 | - |
|
547 | - $post = array( |
|
548 | - 'post_type' => 'destination', |
|
549 | - ); |
|
550 | - |
|
551 | - if ( ! empty( $importable_content ) && in_array( 'country', $importable_content ) ) { |
|
552 | - $parent = $this->check_for_parent( $data ); |
|
553 | - if ( false !== $parent ) { |
|
554 | - $post['post_parent'] = $parent; |
|
555 | - } |
|
556 | - } |
|
557 | - |
|
558 | - // Set the post_content. |
|
559 | - if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) { |
|
560 | - if ( isset( $data[0]['content']['general_description'] ) ) { |
|
561 | - |
|
562 | - if ( in_array( 'strip_tags', $importable_content ) ) { |
|
563 | - $post['post_content'] = wp_strip_all_tags( $data[0]['content']['general_description'] ); |
|
564 | - } else { |
|
565 | - $post['post_content'] = $data[0]['content']['general_description']; |
|
566 | - } |
|
567 | - } |
|
568 | - } |
|
569 | - |
|
570 | - if ( false !== $id && '0' !== $id ) { |
|
571 | - $post['ID'] = $id; |
|
572 | - if ( isset( $this->options ) && 'on' !== $this->options['disable_destination_title'] && isset( $data[0]['name'] ) ) { |
|
573 | - $post['post_title'] = $data[0]['name']; |
|
574 | - $post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 ); |
|
575 | - } |
|
576 | - $post['post_status'] = 'publish'; |
|
577 | - |
|
578 | - $id = wp_update_post( $post ); |
|
579 | - $prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true ); |
|
580 | - update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date ); |
|
581 | - } else { |
|
582 | - // Set the name. |
|
583 | - if ( isset( $data[0]['name'] ) ) { |
|
584 | - $post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 ); |
|
585 | - } |
|
586 | - |
|
587 | - $post['post_name'] = $post_name; |
|
588 | - $post['post_title'] = $data[0]['name']; |
|
589 | - $post['post_status'] = 'publish'; |
|
590 | - $id = wp_insert_post( $post ); |
|
591 | - |
|
592 | - // Save the WETU ID and the Last date it was modified. |
|
593 | - if ( false !== $id ) { |
|
594 | - add_post_meta( $id, 'lsx_wetu_id', $wetu_id ); |
|
595 | - add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) ); |
|
596 | - } |
|
597 | - } |
|
598 | - |
|
599 | - $this->find_attachments( $id ); |
|
600 | - |
|
601 | - // Set the team member if it is there. |
|
602 | - if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) { |
|
603 | - $this->set_team_member( $id, $team_members ); |
|
604 | - } |
|
605 | - |
|
606 | - $this->set_map_data( $data, $id, 9 ); |
|
607 | - |
|
608 | - // Set the Room Data. |
|
609 | - if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) { |
|
610 | - $this->set_video_data( $data, $id ); |
|
611 | - } |
|
612 | - |
|
613 | - // Set the Electricity. |
|
614 | - if ( false !== $importable_content && in_array( 'electricity', $importable_content ) ) { |
|
615 | - $this->set_travel_info( $data, $id, 'electricity', $importable_content ); |
|
616 | - } |
|
617 | - // Set the cuisine. |
|
618 | - if ( false !== $importable_content && in_array( 'cuisine', $importable_content ) ) { |
|
619 | - $this->set_travel_info( $data, $id, 'cuisine', $importable_content ); |
|
620 | - } |
|
621 | - // Set the banking. |
|
622 | - if ( false !== $importable_content && in_array( 'banking', $importable_content ) ) { |
|
623 | - $this->set_travel_info( $data, $id, 'banking', $importable_content ); |
|
624 | - } |
|
625 | - // Set the transport. |
|
626 | - if ( false !== $importable_content && in_array( 'transport', $importable_content ) ) { |
|
627 | - $this->set_travel_info( $data, $id, 'transport', $importable_content ); |
|
628 | - } |
|
629 | - // Set the dress. |
|
630 | - if ( false !== $importable_content && in_array( 'dress', $importable_content ) ) { |
|
631 | - $this->set_travel_info( $data, $id, 'dress', $importable_content ); |
|
632 | - } |
|
633 | - // Set the climate. |
|
634 | - if ( false !== $importable_content && in_array( 'climate', $importable_content ) ) { |
|
635 | - $this->set_travel_info( $data, $id, 'climate', $importable_content ); |
|
636 | - } |
|
637 | - // Set the Health. |
|
638 | - if ( false !== $importable_content && in_array( 'health', $importable_content ) ) { |
|
639 | - $this->set_travel_info( $data, $id, 'health', $importable_content ); |
|
640 | - } |
|
641 | - // Set the Safety. |
|
642 | - if ( false !== $importable_content && in_array( 'safety', $importable_content ) ) { |
|
643 | - $this->set_travel_info( $data, $id, 'safety', $importable_content ); |
|
644 | - } |
|
645 | - // Set the Visa. |
|
646 | - if ( false !== $importable_content && in_array( 'visa', $importable_content ) ) { |
|
647 | - $this->set_travel_info( $data, $id, 'visa', $importable_content ); |
|
648 | - } |
|
649 | - // Set the General. |
|
650 | - if ( false !== $importable_content && in_array( 'additional_info', $importable_content ) ) { |
|
651 | - $this->set_travel_info( $data, $id, 'additional_info', $importable_content ); |
|
652 | - } |
|
653 | - |
|
654 | - // Setup some default for use in the import. |
|
655 | - if ( false !== $importable_content && ( in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content ) ) ) { |
|
656 | - $this->find_attachments( $id ); |
|
657 | - |
|
658 | - // Set the featured image. |
|
659 | - if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) { |
|
660 | - $this->set_featured_image( $data, $id ); |
|
661 | - } |
|
662 | - if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) { |
|
663 | - $this->set_banner_image( $data, $id, $importable_content ); |
|
664 | - } |
|
665 | - // Import the main gallery. |
|
666 | - if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) { |
|
667 | - $this->create_main_gallery( $data, $id ); |
|
668 | - } |
|
669 | - } |
|
670 | - |
|
671 | - // Set the continent. |
|
672 | - if ( false !== $importable_content && in_array( 'continent', $importable_content ) ) { |
|
673 | - $this->set_continent( $data, $id ); |
|
674 | - } |
|
675 | - } |
|
676 | - |
|
677 | - return $id; |
|
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * Saves the room data |
|
682 | - */ |
|
683 | - public function set_travel_info( $data, $id, $meta_key, $importable = array( 'none' ) ) { |
|
684 | - if ( ! empty( $data[0]['travel_information'] ) && isset( $data[0]['travel_information'][ $meta_key ] ) ) { |
|
685 | - $content = $data[0]['travel_information'][ $meta_key ]; |
|
686 | - |
|
687 | - if ( in_array( 'strip_tags', $importable ) ) { |
|
688 | - $content = strip_tags( $content ); |
|
689 | - } |
|
690 | - |
|
691 | - $this->save_custom_field( $content, $meta_key, $id ); |
|
692 | - } |
|
693 | - } |
|
694 | - |
|
695 | - /** |
|
696 | - * Set the Travel Style |
|
697 | - */ |
|
698 | - public function set_continent( $data, $id ) { |
|
699 | - |
|
700 | - if ( isset( $data[0]['position']['country'] ) && $data[0]['map_object_id'] === $data[0]['position']['country_content_entity_id'] ) { |
|
701 | - // Get the continent code. |
|
702 | - $country_code = to_country_data( $data[0]['position']['country'], false ); |
|
703 | - $continent_code = to_continent_code( $country_code ); |
|
704 | - $continent_label = to_continent_label( $continent_code ); |
|
705 | - |
|
706 | - if ( ! empty( tour_operator()->options['display']['enable_search_region_filter'] ) ) { |
|
707 | - $continent_label = to_continent_region_label( $country_code ); |
|
708 | - } |
|
709 | - |
|
710 | - if ( '' !== $continent_label ) { |
|
711 | - $term = term_exists( trim( $continent_label ), 'continent' ); |
|
712 | - if ( ! $term ) { |
|
713 | - $term = wp_insert_term( trim( $continent_label ), 'continent' ); |
|
714 | - |
|
715 | - if ( is_wp_error( $term ) ) { |
|
716 | - echo wp_kses_post( $term->get_error_message() ); |
|
717 | - } |
|
718 | - } else { |
|
719 | - wp_set_object_terms( $id, sanitize_title( $continent_label ), 'continent', true ); |
|
720 | - } |
|
721 | - } |
|
722 | - } |
|
723 | - } |
|
724 | - |
|
725 | - /** |
|
726 | - * Save the list of Accommodation into an option |
|
727 | - */ |
|
728 | - public function check_for_parent( $data = array() ) { |
|
729 | - global $wpdb; |
|
730 | - |
|
731 | - if ( $data[0]['position']['country_content_entity_id'] !== $data[0]['position']['destination_content_entity_id'] ) { |
|
732 | - $result = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'lsx_wetu_id' AND meta_value = '%s'", array( $data[0]['position']['country_content_entity_id'] ) ) ); |
|
733 | - if ( ! empty( $result ) && '' !== $result && false !== $result ) { |
|
734 | - return $result; |
|
735 | - } |
|
736 | - } |
|
737 | - return false; |
|
738 | - } |
|
470 | + return $row_html; |
|
471 | + } |
|
472 | + } |
|
473 | + |
|
474 | + /** |
|
475 | + * Connect to wetu |
|
476 | + */ |
|
477 | + public function process_ajax_import() { |
|
478 | + $return = false; |
|
479 | + |
|
480 | + check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
481 | + if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && 'destination' === $_POST['type'] && isset( $_POST['wetu_id'] ) ) { |
|
482 | + |
|
483 | + $wetu_id = sanitize_text_field( $_POST['wetu_id'] ); |
|
484 | + |
|
485 | + if ( isset( $_POST['post_id'] ) ) { |
|
486 | + $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
487 | + $this->current_post = get_post( $post_id ); |
|
488 | + } else { |
|
489 | + $post_id = 0; |
|
490 | + } |
|
491 | + |
|
492 | + if ( isset( $_POST['team_members'] ) ) { |
|
493 | + $team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) ); |
|
494 | + } else { |
|
495 | + $team_members = false; |
|
496 | + } |
|
497 | + |
|
498 | + $safari_brands = false; |
|
499 | + |
|
500 | + delete_option( 'lsx_wetu_importer_destination_settings' ); |
|
501 | + |
|
502 | + if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) { |
|
503 | + $content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) ); |
|
504 | + add_option( 'lsx_wetu_importer_destination_settings', $content ); |
|
505 | + } else { |
|
506 | + $content = false; |
|
507 | + } |
|
508 | + |
|
509 | + $jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
510 | + |
|
511 | + if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) { |
|
512 | + $adata = json_decode( $jdata['body'], true ); |
|
513 | + $return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands ); |
|
514 | + $this->remove_from_queue( $return ); |
|
515 | + $this->format_completed_row( $return ); |
|
516 | + } else { |
|
517 | + $this->format_error( esc_html__( 'There was a problem importing your destination, please try refreshing the page.', 'lsx-wetu-importer' ) ); |
|
518 | + } |
|
519 | + } |
|
520 | + die(); |
|
521 | + } |
|
522 | + |
|
523 | + /** |
|
524 | + * Saves the queue to the option. |
|
525 | + */ |
|
526 | + public function remove_from_queue( $id ) { |
|
527 | + if ( ! empty( $this->queued_imports ) ) { |
|
528 | + $key = array_search( $id, $this->queued_imports ); |
|
529 | + if ( false !== $key ) { |
|
530 | + unset( $this->queued_imports[ $key ] ); |
|
531 | + |
|
532 | + delete_option( 'lsx_wetu_importer_que' ); |
|
533 | + update_option( 'lsx_wetu_importer_que', $this->queued_imports ); |
|
534 | + } |
|
535 | + } |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Connect to wetu |
|
540 | + */ |
|
541 | + public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false ) { |
|
542 | + if ( 'Destination' === trim( $data[0]['type'] ) || 'Area' === trim( $data[0]['type'] ) ) { |
|
543 | + $post_name = ''; |
|
544 | + $data_post_content = ''; |
|
545 | + $data_post_excerpt = ''; |
|
546 | + |
|
547 | + $post = array( |
|
548 | + 'post_type' => 'destination', |
|
549 | + ); |
|
550 | + |
|
551 | + if ( ! empty( $importable_content ) && in_array( 'country', $importable_content ) ) { |
|
552 | + $parent = $this->check_for_parent( $data ); |
|
553 | + if ( false !== $parent ) { |
|
554 | + $post['post_parent'] = $parent; |
|
555 | + } |
|
556 | + } |
|
557 | + |
|
558 | + // Set the post_content. |
|
559 | + if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) { |
|
560 | + if ( isset( $data[0]['content']['general_description'] ) ) { |
|
561 | + |
|
562 | + if ( in_array( 'strip_tags', $importable_content ) ) { |
|
563 | + $post['post_content'] = wp_strip_all_tags( $data[0]['content']['general_description'] ); |
|
564 | + } else { |
|
565 | + $post['post_content'] = $data[0]['content']['general_description']; |
|
566 | + } |
|
567 | + } |
|
568 | + } |
|
569 | + |
|
570 | + if ( false !== $id && '0' !== $id ) { |
|
571 | + $post['ID'] = $id; |
|
572 | + if ( isset( $this->options ) && 'on' !== $this->options['disable_destination_title'] && isset( $data[0]['name'] ) ) { |
|
573 | + $post['post_title'] = $data[0]['name']; |
|
574 | + $post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 ); |
|
575 | + } |
|
576 | + $post['post_status'] = 'publish'; |
|
577 | + |
|
578 | + $id = wp_update_post( $post ); |
|
579 | + $prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true ); |
|
580 | + update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date ); |
|
581 | + } else { |
|
582 | + // Set the name. |
|
583 | + if ( isset( $data[0]['name'] ) ) { |
|
584 | + $post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 ); |
|
585 | + } |
|
586 | + |
|
587 | + $post['post_name'] = $post_name; |
|
588 | + $post['post_title'] = $data[0]['name']; |
|
589 | + $post['post_status'] = 'publish'; |
|
590 | + $id = wp_insert_post( $post ); |
|
591 | + |
|
592 | + // Save the WETU ID and the Last date it was modified. |
|
593 | + if ( false !== $id ) { |
|
594 | + add_post_meta( $id, 'lsx_wetu_id', $wetu_id ); |
|
595 | + add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) ); |
|
596 | + } |
|
597 | + } |
|
598 | + |
|
599 | + $this->find_attachments( $id ); |
|
600 | + |
|
601 | + // Set the team member if it is there. |
|
602 | + if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) { |
|
603 | + $this->set_team_member( $id, $team_members ); |
|
604 | + } |
|
605 | + |
|
606 | + $this->set_map_data( $data, $id, 9 ); |
|
607 | + |
|
608 | + // Set the Room Data. |
|
609 | + if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) { |
|
610 | + $this->set_video_data( $data, $id ); |
|
611 | + } |
|
612 | + |
|
613 | + // Set the Electricity. |
|
614 | + if ( false !== $importable_content && in_array( 'electricity', $importable_content ) ) { |
|
615 | + $this->set_travel_info( $data, $id, 'electricity', $importable_content ); |
|
616 | + } |
|
617 | + // Set the cuisine. |
|
618 | + if ( false !== $importable_content && in_array( 'cuisine', $importable_content ) ) { |
|
619 | + $this->set_travel_info( $data, $id, 'cuisine', $importable_content ); |
|
620 | + } |
|
621 | + // Set the banking. |
|
622 | + if ( false !== $importable_content && in_array( 'banking', $importable_content ) ) { |
|
623 | + $this->set_travel_info( $data, $id, 'banking', $importable_content ); |
|
624 | + } |
|
625 | + // Set the transport. |
|
626 | + if ( false !== $importable_content && in_array( 'transport', $importable_content ) ) { |
|
627 | + $this->set_travel_info( $data, $id, 'transport', $importable_content ); |
|
628 | + } |
|
629 | + // Set the dress. |
|
630 | + if ( false !== $importable_content && in_array( 'dress', $importable_content ) ) { |
|
631 | + $this->set_travel_info( $data, $id, 'dress', $importable_content ); |
|
632 | + } |
|
633 | + // Set the climate. |
|
634 | + if ( false !== $importable_content && in_array( 'climate', $importable_content ) ) { |
|
635 | + $this->set_travel_info( $data, $id, 'climate', $importable_content ); |
|
636 | + } |
|
637 | + // Set the Health. |
|
638 | + if ( false !== $importable_content && in_array( 'health', $importable_content ) ) { |
|
639 | + $this->set_travel_info( $data, $id, 'health', $importable_content ); |
|
640 | + } |
|
641 | + // Set the Safety. |
|
642 | + if ( false !== $importable_content && in_array( 'safety', $importable_content ) ) { |
|
643 | + $this->set_travel_info( $data, $id, 'safety', $importable_content ); |
|
644 | + } |
|
645 | + // Set the Visa. |
|
646 | + if ( false !== $importable_content && in_array( 'visa', $importable_content ) ) { |
|
647 | + $this->set_travel_info( $data, $id, 'visa', $importable_content ); |
|
648 | + } |
|
649 | + // Set the General. |
|
650 | + if ( false !== $importable_content && in_array( 'additional_info', $importable_content ) ) { |
|
651 | + $this->set_travel_info( $data, $id, 'additional_info', $importable_content ); |
|
652 | + } |
|
653 | + |
|
654 | + // Setup some default for use in the import. |
|
655 | + if ( false !== $importable_content && ( in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content ) ) ) { |
|
656 | + $this->find_attachments( $id ); |
|
657 | + |
|
658 | + // Set the featured image. |
|
659 | + if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) { |
|
660 | + $this->set_featured_image( $data, $id ); |
|
661 | + } |
|
662 | + if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) { |
|
663 | + $this->set_banner_image( $data, $id, $importable_content ); |
|
664 | + } |
|
665 | + // Import the main gallery. |
|
666 | + if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) { |
|
667 | + $this->create_main_gallery( $data, $id ); |
|
668 | + } |
|
669 | + } |
|
670 | + |
|
671 | + // Set the continent. |
|
672 | + if ( false !== $importable_content && in_array( 'continent', $importable_content ) ) { |
|
673 | + $this->set_continent( $data, $id ); |
|
674 | + } |
|
675 | + } |
|
676 | + |
|
677 | + return $id; |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * Saves the room data |
|
682 | + */ |
|
683 | + public function set_travel_info( $data, $id, $meta_key, $importable = array( 'none' ) ) { |
|
684 | + if ( ! empty( $data[0]['travel_information'] ) && isset( $data[0]['travel_information'][ $meta_key ] ) ) { |
|
685 | + $content = $data[0]['travel_information'][ $meta_key ]; |
|
686 | + |
|
687 | + if ( in_array( 'strip_tags', $importable ) ) { |
|
688 | + $content = strip_tags( $content ); |
|
689 | + } |
|
690 | + |
|
691 | + $this->save_custom_field( $content, $meta_key, $id ); |
|
692 | + } |
|
693 | + } |
|
694 | + |
|
695 | + /** |
|
696 | + * Set the Travel Style |
|
697 | + */ |
|
698 | + public function set_continent( $data, $id ) { |
|
699 | + |
|
700 | + if ( isset( $data[0]['position']['country'] ) && $data[0]['map_object_id'] === $data[0]['position']['country_content_entity_id'] ) { |
|
701 | + // Get the continent code. |
|
702 | + $country_code = to_country_data( $data[0]['position']['country'], false ); |
|
703 | + $continent_code = to_continent_code( $country_code ); |
|
704 | + $continent_label = to_continent_label( $continent_code ); |
|
705 | + |
|
706 | + if ( ! empty( tour_operator()->options['display']['enable_search_region_filter'] ) ) { |
|
707 | + $continent_label = to_continent_region_label( $country_code ); |
|
708 | + } |
|
709 | + |
|
710 | + if ( '' !== $continent_label ) { |
|
711 | + $term = term_exists( trim( $continent_label ), 'continent' ); |
|
712 | + if ( ! $term ) { |
|
713 | + $term = wp_insert_term( trim( $continent_label ), 'continent' ); |
|
714 | + |
|
715 | + if ( is_wp_error( $term ) ) { |
|
716 | + echo wp_kses_post( $term->get_error_message() ); |
|
717 | + } |
|
718 | + } else { |
|
719 | + wp_set_object_terms( $id, sanitize_title( $continent_label ), 'continent', true ); |
|
720 | + } |
|
721 | + } |
|
722 | + } |
|
723 | + } |
|
724 | + |
|
725 | + /** |
|
726 | + * Save the list of Accommodation into an option |
|
727 | + */ |
|
728 | + public function check_for_parent( $data = array() ) { |
|
729 | + global $wpdb; |
|
730 | + |
|
731 | + if ( $data[0]['position']['country_content_entity_id'] !== $data[0]['position']['destination_content_entity_id'] ) { |
|
732 | + $result = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'lsx_wetu_id' AND meta_value = '%s'", array( $data[0]['position']['country_content_entity_id'] ) ) ); |
|
733 | + if ( ! empty( $result ) && '' !== $result && false !== $result ) { |
|
734 | + return $result; |
|
735 | + } |
|
736 | + } |
|
737 | + return false; |
|
738 | + } |
|
739 | 739 | } |
@@ -14,85 +14,85 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class LSX_WETU_Importer_Settings { |
16 | 16 | |
17 | - /** |
|
18 | - * Holds instance of the class |
|
19 | - * |
|
20 | - * @var object |
|
21 | - */ |
|
22 | - private static $instance; |
|
17 | + /** |
|
18 | + * Holds instance of the class |
|
19 | + * |
|
20 | + * @var object |
|
21 | + */ |
|
22 | + private static $instance; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Holds the default settings. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - public $defaults = array(); |
|
24 | + /** |
|
25 | + * Holds the default settings. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + public $defaults = array(); |
|
30 | 30 | |
31 | - /** |
|
32 | - * Holds the settings fields available. |
|
33 | - * |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - public $fields = array(); |
|
31 | + /** |
|
32 | + * Holds the settings fields available. |
|
33 | + * |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + public $fields = array(); |
|
37 | 37 | |
38 | - /** |
|
39 | - * Initialize the plugin by setting localization, filters, and administration functions. |
|
40 | - * |
|
41 | - * @since 1.0.0 |
|
42 | - * |
|
43 | - * @access private |
|
44 | - */ |
|
45 | - public function __construct() { |
|
46 | - $this->defaults = array( |
|
47 | - 'api_key' => '', |
|
48 | - 'disable_tour_title' => '', |
|
49 | - 'disable_tour_descriptions' => '', |
|
50 | - 'disable_tour_tags' => 'on', |
|
51 | - 'enable_tour_featured_random' => '', |
|
52 | - 'disable_accommodation_title' => '', |
|
53 | - 'disable_accommodation_descriptions' => '', |
|
54 | - 'disable_accommodation_filtering' => '', |
|
55 | - 'disable_accommodation_excerpts' => '', |
|
56 | - 'disable_destination_title' => '', |
|
57 | - 'disable_destination_descriptions' => '', |
|
58 | - 'image_replacing' => 'on', |
|
59 | - 'image_limit' => '15', |
|
60 | - 'image_scaling' => 'on', |
|
61 | - 'width' => '800', |
|
62 | - 'height' => '600', |
|
63 | - 'scaling' => 'h', |
|
64 | - 'enable_tour_ref_column' => '', |
|
65 | - 'cron_schedule' => 'daily', |
|
66 | - 'accommodation_images_cron' => '', |
|
67 | - 'accommodation_images_cron_featured' => '', |
|
68 | - ); |
|
69 | - $this->fields = array_keys( $this->defaults ); |
|
70 | - add_action( 'admin_init', array( $this, 'save_options' ) ); |
|
71 | - } |
|
38 | + /** |
|
39 | + * Initialize the plugin by setting localization, filters, and administration functions. |
|
40 | + * |
|
41 | + * @since 1.0.0 |
|
42 | + * |
|
43 | + * @access private |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | + $this->defaults = array( |
|
47 | + 'api_key' => '', |
|
48 | + 'disable_tour_title' => '', |
|
49 | + 'disable_tour_descriptions' => '', |
|
50 | + 'disable_tour_tags' => 'on', |
|
51 | + 'enable_tour_featured_random' => '', |
|
52 | + 'disable_accommodation_title' => '', |
|
53 | + 'disable_accommodation_descriptions' => '', |
|
54 | + 'disable_accommodation_filtering' => '', |
|
55 | + 'disable_accommodation_excerpts' => '', |
|
56 | + 'disable_destination_title' => '', |
|
57 | + 'disable_destination_descriptions' => '', |
|
58 | + 'image_replacing' => 'on', |
|
59 | + 'image_limit' => '15', |
|
60 | + 'image_scaling' => 'on', |
|
61 | + 'width' => '800', |
|
62 | + 'height' => '600', |
|
63 | + 'scaling' => 'h', |
|
64 | + 'enable_tour_ref_column' => '', |
|
65 | + 'cron_schedule' => 'daily', |
|
66 | + 'accommodation_images_cron' => '', |
|
67 | + 'accommodation_images_cron_featured' => '', |
|
68 | + ); |
|
69 | + $this->fields = array_keys( $this->defaults ); |
|
70 | + add_action( 'admin_init', array( $this, 'save_options' ) ); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Return an instance of this class. |
|
75 | - * |
|
76 | - * @return object |
|
77 | - */ |
|
78 | - public static function get_instance() { |
|
79 | - // If the single instance hasn't been set, set it now. |
|
80 | - if ( ! isset( self::$instance ) ) { |
|
81 | - self::$instance = new self(); |
|
82 | - } |
|
83 | - return self::$instance; |
|
84 | - } |
|
73 | + /** |
|
74 | + * Return an instance of this class. |
|
75 | + * |
|
76 | + * @return object |
|
77 | + */ |
|
78 | + public static function get_instance() { |
|
79 | + // If the single instance hasn't been set, set it now. |
|
80 | + if ( ! isset( self::$instance ) ) { |
|
81 | + self::$instance = new self(); |
|
82 | + } |
|
83 | + return self::$instance; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Display the importer welcome screen |
|
88 | - */ |
|
89 | - public function display_page() { |
|
90 | - $options = lsx_wetu_get_options(); |
|
91 | - foreach ( $options as $key => $value ) { |
|
92 | - $value = trim( $value ); |
|
93 | - } |
|
94 | - $options = wp_parse_args( $options, $this->defaults ); |
|
95 | - ?> |
|
86 | + /** |
|
87 | + * Display the importer welcome screen |
|
88 | + */ |
|
89 | + public function display_page() { |
|
90 | + $options = lsx_wetu_get_options(); |
|
91 | + foreach ( $options as $key => $value ) { |
|
92 | + $value = trim( $value ); |
|
93 | + } |
|
94 | + $options = wp_parse_args( $options, $this->defaults ); |
|
95 | + ?> |
|
96 | 96 | <div class="wrap"> |
97 | 97 | <form method="post" class=""> |
98 | 98 | <?php wp_nonce_field( 'lsx_wetu_importer_save', 'lsx_wetu_importer_save_options' ); ?> |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | <td> |
108 | 108 | <input data-toggle="tooltip" data-placement="top" title="The API key can be found on your My Account page of your WETU account." type="text" value=" |
109 | 109 | <?php |
110 | - if ( isset( $options['api_key'] ) ) { |
|
111 | - echo esc_attr( $options['api_key'] ); |
|
112 | - } |
|
113 | - ?> |
|
110 | + if ( isset( $options['api_key'] ) ) { |
|
111 | + echo esc_attr( $options['api_key'] ); |
|
112 | + } |
|
113 | + ?> |
|
114 | 114 | " name="api_key" /> |
115 | 115 | </td> |
116 | 116 | </tr> |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | <td> |
128 | 128 | <input type="checkbox" |
129 | 129 | <?php |
130 | - if ( isset( $options['disable_tour_title'] ) && '' !== $options['disable_tour_title'] ) { |
|
131 | - echo esc_attr( 'checked="checked"' ); |
|
132 | - } |
|
133 | - ?> |
|
130 | + if ( isset( $options['disable_tour_title'] ) && '' !== $options['disable_tour_title'] ) { |
|
131 | + echo esc_attr( 'checked="checked"' ); |
|
132 | + } |
|
133 | + ?> |
|
134 | 134 | name="disable_tour_title" /> |
135 | 135 | |
136 | 136 | <small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | <td> |
144 | 144 | <input type="checkbox" |
145 | 145 | <?php |
146 | - if ( isset( $options['disable_tour_descriptions'] ) && '' !== $options['disable_tour_descriptions'] ) { |
|
147 | - echo esc_attr( 'checked="checked"' ); |
|
148 | - } |
|
149 | - ?> |
|
146 | + if ( isset( $options['disable_tour_descriptions'] ) && '' !== $options['disable_tour_descriptions'] ) { |
|
147 | + echo esc_attr( 'checked="checked"' ); |
|
148 | + } |
|
149 | + ?> |
|
150 | 150 | name="disable_tour_descriptions" /> |
151 | 151 | |
152 | 152 | <small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | <td> |
160 | 160 | <input type="checkbox" |
161 | 161 | <?php |
162 | - if ( isset( $options['disable_tour_tags'] ) && '' !== $options['disable_tour_tags'] ) { |
|
163 | - echo esc_attr( 'checked="checked"' ); |
|
164 | - } |
|
165 | - ?> |
|
162 | + if ( isset( $options['disable_tour_tags'] ) && '' !== $options['disable_tour_tags'] ) { |
|
163 | + echo esc_attr( 'checked="checked"' ); |
|
164 | + } |
|
165 | + ?> |
|
166 | 166 | name="disable_tour_tags" /> |
167 | 167 | |
168 | 168 | <small><?php esc_html_e( 'Disable this is you dont want the option available on the import screen.', 'lsx-wetu-importer' ); ?></small> |
@@ -176,10 +176,10 @@ discard block |
||
176 | 176 | <td> |
177 | 177 | <input type="checkbox" |
178 | 178 | <?php |
179 | - if ( isset( $options['enable_tour_ref_column'] ) && '' !== $options['enable_tour_ref_column'] ) { |
|
180 | - echo esc_attr( 'checked="checked"' ); |
|
181 | - } |
|
182 | - ?> |
|
179 | + if ( isset( $options['enable_tour_ref_column'] ) && '' !== $options['enable_tour_ref_column'] ) { |
|
180 | + echo esc_attr( 'checked="checked"' ); |
|
181 | + } |
|
182 | + ?> |
|
183 | 183 | name="enable_tour_ref_column" /> |
184 | 184 | <small><?php esc_html_e( 'Enables the use of the WETU Reference Column for better tours management.', 'lsx-wetu-importer' ); ?></small> |
185 | 185 | </td> |
@@ -192,10 +192,10 @@ discard block |
||
192 | 192 | <td> |
193 | 193 | <input type="checkbox" |
194 | 194 | <?php |
195 | - if ( isset( $options['enable_tour_featured_random'] ) && '' !== $options['enable_tour_featured_random'] ) { |
|
196 | - echo esc_attr( 'checked="checked"' ); |
|
197 | - } |
|
198 | - ?> |
|
195 | + if ( isset( $options['enable_tour_featured_random'] ) && '' !== $options['enable_tour_featured_random'] ) { |
|
196 | + echo esc_attr( 'checked="checked"' ); |
|
197 | + } |
|
198 | + ?> |
|
199 | 199 | name="enable_tour_featured_random" /> |
200 | 200 | <small><?php esc_html_e( 'This will randomize the featured image from the destination gallery.', 'lsx-wetu-importer' ); ?></small> |
201 | 201 | </td> |
@@ -214,10 +214,10 @@ discard block |
||
214 | 214 | <td> |
215 | 215 | <input type="checkbox" |
216 | 216 | <?php |
217 | - if ( isset( $options['disable_accommodation_title'] ) && '' !== $options['disable_accommodation_title'] ) { |
|
218 | - echo esc_attr( 'checked="checked"' ); |
|
219 | - } |
|
220 | - ?> |
|
217 | + if ( isset( $options['disable_accommodation_title'] ) && '' !== $options['disable_accommodation_title'] ) { |
|
218 | + echo esc_attr( 'checked="checked"' ); |
|
219 | + } |
|
220 | + ?> |
|
221 | 221 | name="disable_accommodation_title" /> |
222 | 222 | |
223 | 223 | <small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
@@ -230,10 +230,10 @@ discard block |
||
230 | 230 | <td> |
231 | 231 | <input type="checkbox" |
232 | 232 | <?php |
233 | - if ( isset( $options['disable_accommodation_descriptions'] ) && '' !== $options['disable_accommodation_descriptions'] ) { |
|
234 | - echo esc_attr( 'checked="checked"' ); |
|
235 | - } |
|
236 | - ?> |
|
233 | + if ( isset( $options['disable_accommodation_descriptions'] ) && '' !== $options['disable_accommodation_descriptions'] ) { |
|
234 | + echo esc_attr( 'checked="checked"' ); |
|
235 | + } |
|
236 | + ?> |
|
237 | 237 | name="disable_accommodation_descriptions" /> |
238 | 238 | <small><?php esc_html_e( 'If you are going to edit the accommodation descriptions imported then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
239 | 239 | </td> |
@@ -245,10 +245,10 @@ discard block |
||
245 | 245 | <td> |
246 | 246 | <input type="checkbox" |
247 | 247 | <?php |
248 | - if ( isset( $options['disable_accommodation_filtering'] ) && '' !== $options['disable_accommodation_filtering'] ) { |
|
249 | - echo esc_attr( 'checked="checked"' ); |
|
250 | - } |
|
251 | - ?> |
|
248 | + if ( isset( $options['disable_accommodation_filtering'] ) && '' !== $options['disable_accommodation_filtering'] ) { |
|
249 | + echo esc_attr( 'checked="checked"' ); |
|
250 | + } |
|
251 | + ?> |
|
252 | 252 | name="disable_accommodation_filtering" /> |
253 | 253 | <small><?php esc_html_e( 'This will stop the HTML from being stripped out of the description.', 'lsx-wetu-importer' ); ?></small> |
254 | 254 | </td> |
@@ -261,10 +261,10 @@ discard block |
||
261 | 261 | <td> |
262 | 262 | <input type="checkbox" |
263 | 263 | <?php |
264 | - if ( isset( $options['disable_accommodation_excerpts'] ) && '' !== $options['disable_accommodation_excerpts'] ) { |
|
265 | - echo esc_attr( 'checked="checked"' ); |
|
266 | - } |
|
267 | - ?> |
|
264 | + if ( isset( $options['disable_accommodation_excerpts'] ) && '' !== $options['disable_accommodation_excerpts'] ) { |
|
265 | + echo esc_attr( 'checked="checked"' ); |
|
266 | + } |
|
267 | + ?> |
|
268 | 268 | name="disable_accommodation_excerpts" /> |
269 | 269 | <small><?php esc_html_e( 'If you are going to edit the accommodation excerpts then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
270 | 270 | </td> |
@@ -283,10 +283,10 @@ discard block |
||
283 | 283 | <td> |
284 | 284 | <input type="checkbox" |
285 | 285 | <?php |
286 | - if ( isset( $options['disable_destination_title'] ) && '' !== $options['disable_destination_title'] ) { |
|
287 | - echo esc_attr( 'checked="checked"' ); |
|
288 | - } |
|
289 | - ?> |
|
286 | + if ( isset( $options['disable_destination_title'] ) && '' !== $options['disable_destination_title'] ) { |
|
287 | + echo esc_attr( 'checked="checked"' ); |
|
288 | + } |
|
289 | + ?> |
|
290 | 290 | name="disable_destination_title" /> |
291 | 291 | |
292 | 292 | <small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
@@ -299,10 +299,10 @@ discard block |
||
299 | 299 | <td> |
300 | 300 | <input type="checkbox" |
301 | 301 | <?php |
302 | - if ( isset( $options['disable_destination_descriptions'] ) && '' !== $options['disable_destination_descriptions'] ) { |
|
303 | - echo esc_attr( 'checked="checked"' ); |
|
304 | - } |
|
305 | - ?> |
|
302 | + if ( isset( $options['disable_destination_descriptions'] ) && '' !== $options['disable_destination_descriptions'] ) { |
|
303 | + echo esc_attr( 'checked="checked"' ); |
|
304 | + } |
|
305 | + ?> |
|
306 | 306 | name="disable_destination_descriptions" /> |
307 | 307 | <small><?php esc_html_e( 'If you are going to edit the destination descriptions on this site then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
308 | 308 | </td> |
@@ -321,10 +321,10 @@ discard block |
||
321 | 321 | <td> |
322 | 322 | <input type="checkbox" |
323 | 323 | <?php |
324 | - if ( isset( $options['image_replacing'] ) && '' !== $options['image_replacing'] ) { |
|
325 | - echo esc_attr( 'checked="checked"' ); |
|
326 | - } |
|
327 | - ?> |
|
324 | + if ( isset( $options['image_replacing'] ) && '' !== $options['image_replacing'] ) { |
|
325 | + echo esc_attr( 'checked="checked"' ); |
|
326 | + } |
|
327 | + ?> |
|
328 | 328 | name="image_replacing" /> |
329 | 329 | <p><?php esc_html_e( 'Do you want your images to be replaced on each import.', 'lsx-wetu-importer' ); ?></p> |
330 | 330 | </td> |
@@ -336,10 +336,10 @@ discard block |
||
336 | 336 | <td> |
337 | 337 | <input placeholder="" type="text" value=" |
338 | 338 | <?php |
339 | - if ( isset( $options['image_limit'] ) && '' !== $options['image_limit'] ) { |
|
340 | - echo esc_attr( $options['image_limit'] ); |
|
341 | - } |
|
342 | - ?> |
|
339 | + if ( isset( $options['image_limit'] ) && '' !== $options['image_limit'] ) { |
|
340 | + echo esc_attr( $options['image_limit'] ); |
|
341 | + } |
|
342 | + ?> |
|
343 | 343 | " |
344 | 344 | name="image_limit" /> |
345 | 345 | </td> |
@@ -352,10 +352,10 @@ discard block |
||
352 | 352 | <td> |
353 | 353 | <input type="checkbox" |
354 | 354 | <?php |
355 | - if ( isset( $options['image_scaling'] ) && '' !== $options['image_scaling'] ) { |
|
356 | - echo esc_attr( 'checked="checked"' ); |
|
357 | - } |
|
358 | - ?> |
|
355 | + if ( isset( $options['image_scaling'] ) && '' !== $options['image_scaling'] ) { |
|
356 | + echo esc_attr( 'checked="checked"' ); |
|
357 | + } |
|
358 | + ?> |
|
359 | 359 | name="image_scaling" /> |
360 | 360 | </td> |
361 | 361 | </tr> |
@@ -366,10 +366,10 @@ discard block |
||
366 | 366 | <td> |
367 | 367 | <input placeholder="800" type="text" value=" |
368 | 368 | <?php |
369 | - if ( isset( $options['width'] ) && '' !== $options['width'] ) { |
|
370 | - echo esc_attr( $options['width'] ); |
|
371 | - } |
|
372 | - ?> |
|
369 | + if ( isset( $options['width'] ) && '' !== $options['width'] ) { |
|
370 | + echo esc_attr( $options['width'] ); |
|
371 | + } |
|
372 | + ?> |
|
373 | 373 | " |
374 | 374 | name="width" /> |
375 | 375 | </td> |
@@ -381,10 +381,10 @@ discard block |
||
381 | 381 | <td> |
382 | 382 | <input placeholder="600" type="text" value=" |
383 | 383 | <?php |
384 | - if ( isset( $options['height'] ) && '' !== $options['height'] ) { |
|
385 | - echo esc_attr( $options['height'] ); |
|
386 | - } |
|
387 | - ?> |
|
384 | + if ( isset( $options['height'] ) && '' !== $options['height'] ) { |
|
385 | + echo esc_attr( $options['height'] ); |
|
386 | + } |
|
387 | + ?> |
|
388 | 388 | " |
389 | 389 | name="height" /> |
390 | 390 | </td> |
@@ -397,52 +397,52 @@ discard block |
||
397 | 397 | <td> |
398 | 398 | <input type="radio" |
399 | 399 | <?php |
400 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'raw' === $options['scaling'] ) { |
|
401 | - echo esc_attr( 'checked="checked"' ); |
|
402 | - } |
|
403 | - ?> |
|
400 | + if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'raw' === $options['scaling'] ) { |
|
401 | + echo esc_attr( 'checked="checked"' ); |
|
402 | + } |
|
403 | + ?> |
|
404 | 404 | name="scaling" value="raw" /> <?php esc_html_e( 'Get the Full size image, no cropping takes place.', 'lsx-wetu-importer' ); ?><br /> |
405 | 405 | <input type="radio" |
406 | 406 | <?php |
407 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'c' === $options['scaling'] ) { |
|
408 | - echo esc_attr( 'checked="checked"' ); |
|
409 | - } |
|
410 | - ?> |
|
407 | + if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'c' === $options['scaling'] ) { |
|
408 | + echo esc_attr( 'checked="checked"' ); |
|
409 | + } |
|
410 | + ?> |
|
411 | 411 | name="scaling" value="c" /> <?php esc_html_e( 'Crop image to fit fully into the frame, Crop is taken from middle, preserving as much of the image as possible.', 'lsx-wetu-importer' ); ?><br /> |
412 | 412 | <input type="radio" |
413 | 413 | <?php |
414 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'h' === $options['scaling'] ) { |
|
415 | - echo esc_attr( 'checked="checked"' ); |
|
416 | - } |
|
417 | - ?> |
|
414 | + if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'h' === $options['scaling'] ) { |
|
415 | + echo esc_attr( 'checked="checked"' ); |
|
416 | + } |
|
417 | + ?> |
|
418 | 418 | name="scaling" value="h" /> <?php esc_html_e( 'Crop image to fit fully into the frame, but resize to height first, then crop on width if needed', 'lsx-wetu-importer' ); ?><br /> |
419 | 419 | <input type="radio" |
420 | 420 | <?php |
421 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'w' === $options['scaling'] ) { |
|
422 | - echo esc_attr( 'checked="checked"' ); |
|
423 | - } |
|
424 | - ?> |
|
421 | + if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'w' === $options['scaling'] ) { |
|
422 | + echo esc_attr( 'checked="checked"' ); |
|
423 | + } |
|
424 | + ?> |
|
425 | 425 | name="scaling" value="w" /> <?php esc_html_e( 'Crop image to fit fully into the frame, but resize to width first, then crop on height if needed', 'lsx-wetu-importer' ); ?><br /> |
426 | 426 | <input type="radio" |
427 | 427 | <?php |
428 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'nf' === $options['scaling'] ) { |
|
429 | - echo esc_attr( 'checked="checked"' ); |
|
430 | - } |
|
431 | - ?> |
|
428 | + if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'nf' === $options['scaling'] ) { |
|
429 | + echo esc_attr( 'checked="checked"' ); |
|
430 | + } |
|
431 | + ?> |
|
432 | 432 | name="scaling" value="nf" /> <?php esc_html_e( 'Resize the image to fit within the frame. but pad the image with white to ensure the resolution matches the frame', 'lsx-wetu-importer' ); ?><br /> |
433 | 433 | <input type="radio" |
434 | 434 | <?php |
435 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'n' === $options['scaling'] ) { |
|
436 | - echo esc_attr( 'checked="checked"' ); |
|
437 | - } |
|
438 | - ?> |
|
435 | + if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'n' === $options['scaling'] ) { |
|
436 | + echo esc_attr( 'checked="checked"' ); |
|
437 | + } |
|
438 | + ?> |
|
439 | 439 | name="scaling" value="n" /> <?php esc_html_e( 'Resize the image to fit within the frame. but do not upscale the image.', 'lsx-wetu-importer' ); ?><br /> |
440 | 440 | <input type="radio" |
441 | 441 | <?php |
442 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'W' === $options['scaling'] ) { |
|
443 | - echo esc_attr( 'checked="checked"' ); |
|
444 | - } |
|
445 | - ?> |
|
442 | + if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'W' === $options['scaling'] ) { |
|
443 | + echo esc_attr( 'checked="checked"' ); |
|
444 | + } |
|
445 | + ?> |
|
446 | 446 | name="scaling" value="W" /> <?php esc_html_e( 'Resize the image to fit within the frame. Image will not exceed specified dimensions', 'lsx-wetu-importer' ); ?> |
447 | 447 | </td> |
448 | 448 | </tr> |
@@ -460,28 +460,28 @@ discard block |
||
460 | 460 | <td> |
461 | 461 | <select name="cron_schedule" id="cron_schedule" class="widefat layout"> |
462 | 462 | <?php |
463 | - if ( isset( $options['cron_schedule'] ) && '' !== $options['cron_schedule'] ) { |
|
464 | - $schedule = $options['cron_schedule']; |
|
465 | - } else { |
|
466 | - $schedule = 'daily'; |
|
467 | - } |
|
468 | - $timeslots = array( |
|
469 | - 'daily' => __( 'Daily', 'lsx-wetu-importer' ), |
|
470 | - 'weekly-mon' => __( 'Weekly (Monday)', 'lsx-wetu-importer' ), |
|
471 | - 'weekly-tue' => __( 'Weekly (Tuesday)', 'lsx-wetu-importer' ), |
|
472 | - 'weekly-wed' => __( 'Weekly (Wednesday)', 'lsx-wetu-importer' ), |
|
473 | - 'weekly-thu' => __( 'Weekly (Thursday)', 'lsx-wetu-importer' ), |
|
474 | - 'weekly-fri' => __( 'Weekly (Friday)', 'lsx-wetu-importer' ), |
|
475 | - 'weekly-sat' => __( 'Weekly (Saturday)', 'lsx-wetu-importer' ), |
|
476 | - 'weekly-sun' => __( 'Weekly (Sunday)', 'lsx-wetu-importer' ), |
|
477 | - ); |
|
478 | - foreach ( $timeslots as $key => $name ) { |
|
479 | - $selected = ( $schedule == $key ) ? ' selected="selected"' : ''; |
|
480 | - ?> |
|
463 | + if ( isset( $options['cron_schedule'] ) && '' !== $options['cron_schedule'] ) { |
|
464 | + $schedule = $options['cron_schedule']; |
|
465 | + } else { |
|
466 | + $schedule = 'daily'; |
|
467 | + } |
|
468 | + $timeslots = array( |
|
469 | + 'daily' => __( 'Daily', 'lsx-wetu-importer' ), |
|
470 | + 'weekly-mon' => __( 'Weekly (Monday)', 'lsx-wetu-importer' ), |
|
471 | + 'weekly-tue' => __( 'Weekly (Tuesday)', 'lsx-wetu-importer' ), |
|
472 | + 'weekly-wed' => __( 'Weekly (Wednesday)', 'lsx-wetu-importer' ), |
|
473 | + 'weekly-thu' => __( 'Weekly (Thursday)', 'lsx-wetu-importer' ), |
|
474 | + 'weekly-fri' => __( 'Weekly (Friday)', 'lsx-wetu-importer' ), |
|
475 | + 'weekly-sat' => __( 'Weekly (Saturday)', 'lsx-wetu-importer' ), |
|
476 | + 'weekly-sun' => __( 'Weekly (Sunday)', 'lsx-wetu-importer' ), |
|
477 | + ); |
|
478 | + foreach ( $timeslots as $key => $name ) { |
|
479 | + $selected = ( $schedule == $key ) ? ' selected="selected"' : ''; |
|
480 | + ?> |
|
481 | 481 | <option value="<?php echo wp_kses_post( $key ); ?>" id="<?php echo wp_kses_post( $key ); ?>" <?php echo wp_kses_post( $selected ); ?>><?php echo wp_kses_post( $name ); ?></option> |
482 | 482 | <?php |
483 | - } |
|
484 | - ?> |
|
483 | + } |
|
484 | + ?> |
|
485 | 485 | </select> |
486 | 486 | </td> |
487 | 487 | </tr> |
@@ -492,10 +492,10 @@ discard block |
||
492 | 492 | <td> |
493 | 493 | <input type="checkbox" |
494 | 494 | <?php |
495 | - if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { |
|
496 | - echo esc_attr( 'checked="checked"' ); |
|
497 | - } |
|
498 | - ?> |
|
495 | + if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { |
|
496 | + echo esc_attr( 'checked="checked"' ); |
|
497 | + } |
|
498 | + ?> |
|
499 | 499 | name="accommodation_images_cron" /> |
500 | 500 | <p><?php esc_html_e( 'Update the accommodation images accodring to the schedule above.', 'lsx-wetu-importer' ); ?></p> |
501 | 501 | </td> |
@@ -507,10 +507,10 @@ discard block |
||
507 | 507 | <td> |
508 | 508 | <input type="checkbox" |
509 | 509 | <?php |
510 | - if ( isset( $options['accommodation_images_cron_featured'] ) && '' !== $options['accommodation_images_cron_featured'] ) { |
|
511 | - echo esc_attr( 'checked="checked"' ); |
|
512 | - } |
|
513 | - ?> |
|
510 | + if ( isset( $options['accommodation_images_cron_featured'] ) && '' !== $options['accommodation_images_cron_featured'] ) { |
|
511 | + echo esc_attr( 'checked="checked"' ); |
|
512 | + } |
|
513 | + ?> |
|
514 | 514 | name="accommodation_images_cron_featured" /> |
515 | 515 | <p><?php esc_html_e( 'Set the featured image when the gallery is created.', 'lsx-wetu-importer' ); ?></p> |
516 | 516 | </td> |
@@ -522,25 +522,25 @@ discard block |
||
522 | 522 | </form> |
523 | 523 | </div> |
524 | 524 | <?php |
525 | - } |
|
525 | + } |
|
526 | 526 | |
527 | - /** |
|
528 | - * Save the options fields |
|
529 | - * |
|
530 | - * @return void |
|
531 | - */ |
|
532 | - public function save_options() { |
|
533 | - if ( ! isset( $_POST['lsx_wetu_importer_save_options'] ) || ! wp_verify_nonce( $_POST['lsx_wetu_importer_save_options'], 'lsx_wetu_importer_save' ) ) { |
|
534 | - return; |
|
535 | - } |
|
536 | - $data_to_save = array(); |
|
537 | - foreach ( $this->defaults as $key => $field ) { |
|
538 | - if ( isset( $_POST[ $key ] ) ) { |
|
539 | - $data_to_save[ $key ] = sanitize_text_field( $_POST[ $key ] ); |
|
540 | - } else { |
|
541 | - $data_to_save[ $key ] = ''; |
|
542 | - } |
|
543 | - } |
|
544 | - update_option( 'lsx_wetu_importer_settings', $data_to_save ); |
|
545 | - } |
|
527 | + /** |
|
528 | + * Save the options fields |
|
529 | + * |
|
530 | + * @return void |
|
531 | + */ |
|
532 | + public function save_options() { |
|
533 | + if ( ! isset( $_POST['lsx_wetu_importer_save_options'] ) || ! wp_verify_nonce( $_POST['lsx_wetu_importer_save_options'], 'lsx_wetu_importer_save' ) ) { |
|
534 | + return; |
|
535 | + } |
|
536 | + $data_to_save = array(); |
|
537 | + foreach ( $this->defaults as $key => $field ) { |
|
538 | + if ( isset( $_POST[ $key ] ) ) { |
|
539 | + $data_to_save[ $key ] = sanitize_text_field( $_POST[ $key ] ); |
|
540 | + } else { |
|
541 | + $data_to_save[ $key ] = ''; |
|
542 | + } |
|
543 | + } |
|
544 | + update_option( 'lsx_wetu_importer_settings', $data_to_save ); |
|
545 | + } |
|
546 | 546 | } |