Issues (2187)

classes/class-lsx-wetu-importer-accommodation.php (338 issues)

1
<?php
0 ignored issues
show
This file is missing a doc comment.
Loading history...
2
/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
3
 * @package   LSX_WETU_Importer_Accommodation
4
 * @author    LightSpeed
5
 * @license   GPL-2.0+
6
 * @link
7
 * @copyright 2016 LightSpeed
8
 **/
0 ignored issues
show
There must be no blank lines after the class comment
Loading history...
9
10
class LSX_WETU_Importer_Accommodation extends LSX_WETU_Importer {
11
12
	/**
13
	 * The url to list items from WETU
14
	 *
15
	 * @since 0.0.1
16
	 *
17
	 * @var      string
18
	 */
19
	public $tab_slug = '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() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
65
		$this->set_variables();
66
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
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 ] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
92
			$this->accommodation_options = $accommodation_options;
93
		}
94
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
95
96
	/**
97
	 * Display the importer administration screen
98
	 */
99
	public function display_page() {
100
		?>
101
		<div class="wrap">
102
103
			<div class="tablenav top">
104
				<div class="actions">
105
					<?php $this->search_form(); ?>
106
				</div>
107
			</div>
108
109
			<form method="get" action="" id="posts-filter">
110
				<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr( $this->tab_slug ); ?>" />
111
112
				<table class="wp-list-table widefat fixed posts">
113
					<?php $this->table_header(); ?>
114
115
					<tbody id="the-list">
116
						<tr class="post-0 type-tour status-none" id="post-0">
117
							<th class="check-column" scope="row">
118
								<label for="cb-select-0" class="screen-reader-text"><?php esc_html_e( 'Enter a title to search for and press enter', 'lsx-wetu-importer' ); ?></label>
119
							</th>
120
							<td class="post-title page-title column-title">
121
								<strong>
122
									<?php esc_html_e( 'Enter a title to search for', 'lsx-wetu-importer' ); ?>
123
								</strong>
124
							</td>
125
							<td class="date column-date">
126
							</td>
127
							<td class="ssid column-ssid">
128
							</td>
129
						</tr>
130
					</tbody>
131
132
					<?php $this->table_footer(); ?>
133
134
				</table>
135
136
				<p><input class="button button-primary add" type="button" value="<?php esc_attr_e( 'Add to List', 'lsx-wetu-importer' ); ?>" />
137
					<input class="button button-primary clear" type="button" value="<?php esc_attr_e( 'Clear', 'lsx-wetu-importer' ); ?>" />
138
				</p>
139
			</form>
140
141
			<div style="display:none;" class="import-list-wrapper">
142
				<br />
143
				<form method="get" action="" id="import-list">
144
145
					<div class="row">
146
						<div class="settings-all" style="width:30%;display:block;float:left;">
147
							<h3><?php esc_html_e( 'What content to Sync from WETU' ); ?></h3>
148
							<ul>
149
								<?php if ( isset( $this->options['disable_accommodation_descriptions'] ) && 'on' !== $this->options['disable_accommodation_descriptions'] ) { ?>
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
150
									<li><input class="content" checked="checked" type="checkbox" name="content[]" value="description" /> <?php esc_html_e( 'Description', 'lsx-wetu-importer' ); ?></li>
151
								<?php } ?>
152
								<?php if ( isset( $this->options['disable_accommodation_excerpts'] ) && 'on' !== $this->options['disable_accommodation_excerpts'] ) { ?>
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
153
									<li><input class="content" checked="checked" type="checkbox" name="content[]" value="excerpt" /> <?php esc_html_e( 'Excerpt', 'lsx-wetu-importer' ); ?></li>
154
								<?php } ?>
155
156
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="gallery" /> <?php esc_html_e( 'Main Gallery', 'lsx-wetu-importer' ); ?></li>
157
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="category" /> <?php esc_html_e( 'Category', 'lsx-wetu-importer' ); ?></li>
158
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="location" /> <?php esc_html_e( 'Location', 'lsx-wetu-importer' ); ?></li>
159
160
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="destination" /> <?php esc_html_e( 'Connect Destinations', 'lsx-wetu-importer' ); ?></li>
161
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="rating" /> <?php esc_html_e( 'Rating', 'lsx-wetu-importer' ); ?></li>
162
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="rooms" /> <?php esc_html_e( 'Rooms', 'lsx-wetu-importer' ); ?></li>
163
164
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="checkin" /> <?php esc_html_e( 'Check In / Check Out', 'lsx-wetu-importer' ); ?></li>
165
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="facilities" /> <?php esc_html_e( 'Facilities', 'lsx-wetu-importer' ); ?></li>
166
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="friendly" /> <?php esc_html_e( 'Friendly', 'lsx-wetu-importer' ); ?></li>
167
168
169
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="special_interests" /> <?php esc_html_e( 'Special Interests', 'lsx-wetu-importer' ); ?></li>
170
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="spoken_languages" /> <?php esc_html_e( 'Spoken Languages', 'lsx-wetu-importer' ); ?></li>
171
172
								<?php if ( class_exists( 'LSX_TO_Videos' ) ) { ?>
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
173
									<li><input class="content" checked="checked" type="checkbox" name="content[]" value="videos" /> <?php esc_html_e( 'Videos', 'lsx-wetu-importer' ); ?></li>
174
								<?php } ?>
175
							</ul>
176
							<h4><?php esc_html_e( 'Additional Content' ); ?></h4>
177
							<ul>
178
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="featured_image" /> <?php esc_html_e( 'Set Featured Image', 'lsx-wetu-importer' ); ?></li>
179
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="banner_image" /> <?php esc_html_e( 'Set Banner Image', 'lsx-wetu-importer' ); ?></li>
180
							</ul>
181
						</div>
182
						<div style="width:30%;display:block;float:left;">
183
							<h3><?php esc_html_e( 'Assign a Team Member' ); ?></h3>
184
							<?php $this->team_member_checkboxes( $this->accommodation_options ); ?>
185
						</div>
186
187
						<div style="width:30%;display:block;float:left;">
188
							<h3><?php esc_html_e( 'Assign a Safari Brand' ); ?></h3>
189
							<?php
190
								echo wp_kses_post( $this->taxonomy_checkboxes( 'accommodation-brand', $this->accommodation_options ) );
191
							?>
192
						</div>
193
194
						<br clear="both" />
195
					</div>
196
197
					<h3><?php esc_html_e( 'Your List' ); ?></h3>
198
					<p><input class="button button-primary" type="submit" value="<?php esc_attr_e( 'Sync', 'lsx-wetu-importer' ); ?>" /></p>
199
					<table class="wp-list-table widefat fixed posts">
200
						<?php $this->table_header(); ?>
201
202
						<tbody>
203
204
						</tbody>
205
206
						<?php $this->table_footer(); ?>
207
208
					</table>
209
210
					<p><input class="button button-primary" type="submit" value="<?php esc_attr_e( 'Sync', 'lsx-wetu-importer' ); ?>" /></p>
211
				</form>
212
			</div>
213
214
			<div style="display:none;" class="completed-list-wrapper">
215
				<h3><?php esc_html_e( 'Completed' ); ?> - <small><?php esc_html_e( 'Import your', 'lsx-wetu-importer' ); ?> <a href="<?php echo esc_url( admin_url( 'admin.php' ) ); ?>?page=<?php echo esc_attr( $this->plugin_slug ); ?>&tab=destination"><?php esc_html_e( 'destinations' ); ?></a> <?php esc_html_e( 'next', 'lsx-wetu-importer' ); ?></small></h3>
216
				<ul>
217
				</ul>
218
			</div>
219
		</div>
220
		<?php
221
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
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'] ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Blank line found at start of control structure
Loading history...
230
231
			$searched_items = false;
232
			if ( isset( $_POST['keyword'] ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
233
				$keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) );
234
			} else {
235
				$keyphrases = array( 0 );
236
			}
237
238
			if ( ! is_array( $keyphrases ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
239
				$keyphrases = array( $keyphrases );
240
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
241
			foreach ( $keyphrases as &$keyword ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
242
				$keyword = ltrim( rtrim( $keyword ) );
243
			}
244
245
			$post_status = false;
246
247
			if ( in_array( 'publish', $keyphrases ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
248
				$post_status = 'publish';
249
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
250
			if ( in_array( 'pending', $keyphrases ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
251
				$post_status = 'pending';
252
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
253
			if ( in_array( 'draft', $keyphrases ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
254
				$post_status = 'draft';
255
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
256
			if ( in_array( 'import', $keyphrases ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
257
				$post_status = 'import';
258
			}
259
260
			// If there is a post status use it.
261
			if ( false !== $post_status ) {
0 ignored issues
show
Blank line found at start of control structure
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
262
263
				$accommodation         = array();
264
				$current_accommodation = $this->find_current_accommodation();
265
				if ( ! empty( $current_accommodation ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
266
					foreach ( $current_accommodation as $cs_key => $ccs_id ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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 ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
273
					foreach ( $accommodation as $row_key => $row ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
274
						$row['post_title'] = $row['name'];
275
						if ( 'import' === $post_status ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
276
							if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
277
								$current_status = get_post_status( $row['post_id'] );
278
								if ( 'draft' === $current_status ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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'] ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
286
								continue;
287
							} else {
288
								$current_status = get_post_status( $row['post_id'] );
289
								if ( $current_status !== $post_status ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
290
									continue;
291
								}
292
							}
0 ignored issues
show
No blank line found after control structure
Loading history...
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'] ) {
0 ignored issues
show
Blank line found at start of control structure
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
301
302
					$search_data = json_decode( $search_data['body'], true );
303
					foreach ( $search_data as $sdata_key => $sdata ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Blank line found at start of control structure
Loading history...
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'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
306
							continue;
307
						}
308
309
						$temp_id = $this->get_post_id_by_key_value( $sdata['id'] );
310
						if ( false === $temp_id ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
						}
0 ignored issues
show
No blank line found after control structure
Loading history...
317
						$searched_items[ sanitize_title( $sdata['name'] ) . '-' . $sdata['id'] ] = $this->format_row( $sdata, $sdata_key );
318
					}
319
				}
320
			}
321
322
			if ( false !== $searched_items ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
323
				$return = implode( $searched_items );
324
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
325
			print_r( $return );
0 ignored issues
show
print_r() found. Debug code should not normally be used in production.
Loading history...
326
		}
327
328
		die();
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
329
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
330
331
	public function prepare_row_attributes( $cs_key, $ccs_id ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function prepare_row_attributes()
Loading history...
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' ) ),
0 ignored issues
show
date() is affected by runtime timezone changes which can cause date/time to be incorrectly displayed. Use gmdate() instead.
Loading history...
337
			'post_id'       => $ccs_id,
338
		);
339
		return $row_item;
340
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
341
342
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$row_key" missing
Loading history...
343
	 * Formats the row for output on the screen.
344
	 *
345
	 * @param boolean $row the current row to format.
346
	 * @return void
0 ignored issues
show
Function return type is void, but function contains return statement
Loading history...
347
	 */
348
	public function format_row( $row = false, $row_key = '' ) {
349
		if ( false !== $row ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Blank line found at start of control structure
Loading history...
350
351
			$status = 'import';
352
			if ( 0 !== $row['post_id'] ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
353
				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
0 ignored issues
show
Are you sure get_post_status($row['post_id']) of type false|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

353
				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . /** @scrutinizer ignore-type */ get_post_status( $row['post_id'] ) . '</a>';
Loading history...
354
			}
355
356
			$row_html = '
357
			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
358
				<th class="check-column" scope="row">
359
					<label for="cb-select-' . $row['id'] . '" class="screen-reader-text">' . $row['name'] . '</label>
360
					<input type="checkbox" data-identifier="' . $row['id'] . '" value="' . $row['post_id'] . '" name="post[]" id="cb-select-' . $row['id'] . '">
361
				</th>
362
				<td class="column-order">
363
					' . ( $row_key + 1 ) . '
364
				</td>
365
				<td class="post-title page-title column-title">
366
					<strong>' . $row['post_title'] . '</strong> - ' . $status . '
367
				</td>
368
				<td class="date column-date">
369
					<abbr title="' . date( 'Y/m/d', strtotime( $row['last_modified'] ) ) . '">' . date( 'Y/m/d', strtotime( $row['last_modified'] ) ) . '</abbr><br>Last Modified
0 ignored issues
show
date() is affected by runtime timezone changes which can cause date/time to be incorrectly displayed. Use gmdate() instead.
Loading history...
370
				</td>
371
				<td class="ssid column-ssid">
372
					' . $row['id'] . '
373
				</td>
374
			</tr>';
375
			return $row_html;
376
		}
377
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
378
379
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
380
	 * Saves the queue to the option.
381
	 */
382
	public function remove_from_queue( $id ) {
383
		if ( ! empty( $this->queued_imports ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
384
			$key = array_search( $id, $this->queued_imports );
0 ignored issues
show
$this->queued_imports of type integer is incompatible with the type array expected by parameter $haystack of array_search(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

384
			$key = array_search( $id, /** @scrutinizer ignore-type */ $this->queued_imports );
Loading history...
Not using strict comparison for array_search; supply true for third argument.
Loading history...
385
			if ( false !== $key ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
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'] ) ) {
0 ignored issues
show
Blank line found at start of control structure
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
402
403
			$wetu_id = sanitize_text_field( $_POST['wetu_id'] );
0 ignored issues
show
$_POST data not unslashed before sanitization. Use wp_unslash() or similar
Loading history...
404
			if ( isset( $_POST['post_id'] ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
405
				$post_id = sanitize_text_field( $_POST['post_id'] );
0 ignored issues
show
$_POST data not unslashed before sanitization. Use wp_unslash() or similar
Loading history...
406
			} else {
407
				$post_id = 0;
408
			}
409
410
			if ( isset( $_POST['team_members'] ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
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'] ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
417
				$safari_brands = array_map( 'sanitize_text_field', wp_unslash( $_POST['safari_brands'] ) );
418
			} else {
419
				$safari_brands = false;
420
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
421
			delete_option( 'lsx_wetu_importer_accommodation_settings' );
422
423
			if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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'] ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
443
444
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$data" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$wetu_id" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$safari_brands" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$importable_content" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$team_members" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
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 ) ) {
0 ignored issues
show
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
459
			if ( isset( $data[0]['content']['extended_description'] ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
460
				$data_post_content = $data[0]['content']['extended_description'];
461
			} elseif ( isset( $data[0]['content']['general_description'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
462
				$data_post_content                = $data[0]['content']['general_description'];
463
				$content_used_general_description = true;
464
			} elseif ( isset( $data[0]['content']['teaser_description'] ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
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'] ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
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 ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
477
			if ( isset( $data[0]['content']['teaser_description'] ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
478
				$data_post_excerpt = $data[0]['content']['teaser_description'];
479
			} elseif ( isset( $data[0]['content']['general_description'] ) && false === $content_used_general_description ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
487
			$post['ID'] = $id;
488
489
			if ( isset( $this->options ) && 'on' !== $this->options['disable_accommodation_title'] && isset( $data[0]['name'] ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
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 );
0 ignored issues
show
It seems like $id can also be of type WP_Error; however, parameter $post_id of get_post_meta() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

497
			$prev_date = get_post_meta( /** @scrutinizer ignore-type */ $id, 'lsx_wetu_modified_date', true );
Loading history...
498
			update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date );
0 ignored issues
show
It seems like $id can also be of type WP_Error; however, parameter $post_id of update_post_meta() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

498
			update_post_meta( /** @scrutinizer ignore-type */ $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date );
Loading history...
499
		} else {
500
			// Set the name.
501
			if ( isset( $data[0]['name'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
The condition false !== $id is always true.
Loading history...
512
				add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
0 ignored issues
show
It seems like $id can also be of type WP_Error; however, parameter $post_id of add_post_meta() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

512
				add_post_meta( /** @scrutinizer ignore-type */ $id, 'lsx_wetu_id', $wetu_id );
Loading history...
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 ) ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
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 ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
524
			$this->set_team_member( $id, $team_members );
525
		}
526
527
		// Set the safari brand.
528
		if ( false !== $safari_brands && '' !== $safari_brands ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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 ) ) {
0 ignored issues
show
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
535
			$this->connect_destinations( $data, $id );
536
		}
537
538
		if ( false !== $importable_content && in_array( 'category', $importable_content ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
539
			$this->set_taxonomy_style( $data, $id );
540
		}
541
542
		// Set the Room Data.
543
		if ( false !== $importable_content && in_array( 'rooms', $importable_content ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
544
			$this->set_room_data( $data, $id );
545
		}
546
547
		// Set the rating.
548
		if ( false !== $importable_content && in_array( 'rating', $importable_content ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
549
			$this->set_rating( $data, $id );
550
		}
551
552
		// Set the checkin checkout data.
553
		if ( false !== $importable_content && in_array( 'checkin', $importable_content ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
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 ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
559
			$this->set_spoken_languages( $data, $id );
560
		}
561
562
		// Set the friendly options.
563
		if ( false !== $importable_content && in_array( 'friendly', $importable_content ) ) {
0 ignored issues
show
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
564
			$this->set_friendly( $data, $id );
565
		}
566
567
		// Set the special_interests.
568
		if ( false !== $importable_content && in_array( 'special_interests', $importable_content ) ) {
0 ignored issues
show
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
569
			$this->set_special_interests( $data, $id );
570
		}
571
572
		// Import the videos.
573
		if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
574
			$this->set_video_data( $data, $id );
575
		}
576
577
		// Import the facilities.
578
		if ( false !== $importable_content && in_array( 'facilities', $importable_content ) ) {
0 ignored issues
show
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
579
			$this->set_facilities( $data, $id );
580
		}
581
582
		// Set the featured image.
583
		if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
584
			$this->set_featured_image( $data, $id );
585
		}
586
587
		if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
0 ignored issues
show
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
588
			$this->set_banner_image( $data, $id );
589
		}
590
591
		// Import the main gallery.
592
		if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
593
			$this->create_main_gallery( $data, $id );
594
		}
595
596
		return $id;
597
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
598
599
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$safari_brands" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
600
	 * Set the safari brand
601
	 */
602
	public function set_safari_brands( $id, $safari_brands ) {
603
		foreach ( $safari_brands as $safari_brand ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
604
			wp_set_object_terms( $id, intval( $safari_brand ), 'accommodation-brand', true );
605
		}
606
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
607
608
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$data" missing
Loading history...
609
	 * Connects the destinations post type
610
	 */
611
	public function connect_destinations( $data, $id ) {
612
		if ( isset( $data[0]['position'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
613
			$destinations = false;
614
615
			if ( isset( $data[0]['position']['country'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
616
				$destinations['country'] = $data[0]['position']['country'];
617
			}
618
619
			if ( isset( $data[0]['position']['destination'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
620
				$destinations['destination'] = $data[0]['position']['destination'];
621
			}
622
623
			if ( false !== $destinations ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
The condition false !== $destinations is always false.
Loading history...
624
				$prev_values = get_post_meta( $id, 'destination_to_accommodation', false );
625
626
				if ( false === $prev_values || ! is_array( $prev_values ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
634
					$destination = get_page_by_title( ltrim( rtrim( $value ) ), 'OBJECT', 'destination' );
635
					if ( null !== $destination ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
636
						if ( ! in_array( $destination->ID, $prev_values ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
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
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
646
647
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$data" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
648
	 * Set the Travel Style
649
	 */
650
	public function set_taxonomy_style( $data, $id ) {
651
		$terms = false;
652
653
		if ( isset( $data[0]['category'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
654
			$term = term_exists( trim( $data[0]['category'] ), 'accommodation-type' );
655
			if ( ! $term ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
656
				$term = wp_insert_term( trim( $data[0]['category'] ), 'accommodation-type' );
657
658
				if ( is_wp_error( $term ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
668
669
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$data" missing
Loading history...
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'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
674
			$rooms = false;
675
676
			foreach ( $data[0]['rooms'] as $room ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
677
				$temp_room = array();
678
679
				if ( isset( $room['name'] ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
680
					$temp_room['title'] = $room['name'];
681
				}
682
683
				if ( isset( $room['description'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
684
					$temp_room['description'] = strip_tags( $room['description'] );
0 ignored issues
show
strip_tags() is discouraged. Use the more comprehensive wp_strip_all_tags() instead.
Loading history...
685
				}
686
687
				$temp_room['price'] = 0;
688
				$temp_room['type']  = 'room';
689
690
				if ( ! empty( $room['images'] ) && is_array( $room['images'] ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
691
					$temp_room['gallery']   = array();
692
					$temp_room['gallery'][] = $this->attach_image( $room['images'][0], $id );
693
				}
0 ignored issues
show
No blank line found after control structure
Loading history...
694
				$rooms[] = $temp_room;
695
			}
696
697
			if ( false !== $id && '0' !== $id ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
698
				delete_post_meta( $id, 'units' );
699
			}
700
701
			foreach ( $rooms as $room ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
702
				add_post_meta( $id, 'units', $room, false );
703
			}
704
705
			if ( isset( $data[0]['features'] ) && isset( $data[0]['features']['rooms'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
706
				$room_count = $data[0]['features']['rooms'];
707
			} else {
708
				$room_count = count( $data[0]['rooms'] );
709
			}
710
711
			if ( false !== $id && '0' !== $id ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
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
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
719
720
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$data" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
721
	 * Set the ratings
722
	 */
723
	public function set_rating( $data, $id ) {
724
		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['star_authority'] ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
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'] ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
733
			$this->save_custom_field( $data[0]['features']['stars'], 'rating', $id, true );
734
		}
735
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
736
737
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$data" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
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'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
742
			$languages = false;
743
744
			foreach ( $data[0]['features']['spoken_languages'] as $spoken_language ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
745
				$languages[] = sanitize_title( $spoken_language );
746
			}
747
748
			if ( false !== $languages ) {
0 ignored issues
show
The condition false !== $languages is always false.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
749
				$this->save_custom_field( $languages, 'spoken_languages', $id );
750
			}
751
		}
752
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
753
754
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$data" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
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'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
759
			$friendly_options = false;
760
761
			foreach ( $data[0]['features']['suggested_visitor_types'] as $visitor_type ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
762
				$friendly_options[] = sanitize_title( $visitor_type );
763
			}
764
765
			if ( false !== $friendly_options ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
The condition false !== $friendly_options is always false.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
766
				$this->save_custom_field( $friendly_options, 'suggested_visitor_types', $id );
767
			}
768
		}
769
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
770
771
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$data" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
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'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
776
			$interests = false;
777
778
			foreach ( $data[0]['features']['special_interests'] as $special_interest ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
779
				$interests[] = sanitize_title( $special_interest );
780
			}
781
782
			if ( false !== $interests ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
The condition false !== $interests is always false.
Loading history...
783
				$this->save_custom_field( $interests, 'special_interests', $id );
784
			}
785
		}
786
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
787
788
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$data" missing
Loading history...
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'] ) ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
793
			$time = str_replace( 'h', ':', $data[0]['features']['check_in_time'] );
794
			$time = date( 'h:ia', strtotime( $time ) );
0 ignored issues
show
date() is affected by runtime timezone changes which can cause date/time to be incorrectly displayed. Use gmdate() instead.
Loading history...
795
			$this->save_custom_field( $time, 'checkin_time', $id );
796
		}
797
798
		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_out_time'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
799
			$time = str_replace( 'h', ':', $data[0]['features']['check_out_time'] );
800
			$time = date( 'h:ia', strtotime( $time ) );
0 ignored issues
show
date() is affected by runtime timezone changes which can cause date/time to be incorrectly displayed. Use gmdate() instead.
Loading history...
801
			$this->save_custom_field( $time, 'checkout_time', $id );
802
		}
803
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
804
805
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$data" missing
Loading history...
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 ) {
0 ignored issues
show
Expected 0 spaces before closing bracket; 1 found
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
817
			$terms = false;
818
819
			if ( isset( $data[0]['features'] ) && isset( $data[0]['features'][ $key ] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
820
				$parent_id = $this->set_term( $id, $label, 'facility' );
0 ignored issues
show
$label of type string is incompatible with the type boolean expected by parameter $name of LSX_WETU_Importer::set_term(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

820
				$parent_id = $this->set_term( $id, /** @scrutinizer ignore-type */ $label, 'facility' );
Loading history...
'facility' of type string is incompatible with the type boolean expected by parameter $taxonomy of LSX_WETU_Importer::set_term(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

820
				$parent_id = $this->set_term( $id, $label, /** @scrutinizer ignore-type */ 'facility' );
Loading history...
821
			}
822
823
			foreach ( $data[0]['features'][ $key ] as $child_facility ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
824
				$this->set_term( $id, $child_facility, 'facility', $parent_id );
0 ignored issues
show
$parent_id of type void is incompatible with the type boolean expected by parameter $parent of LSX_WETU_Importer::set_term(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

824
				$this->set_term( $id, $child_facility, 'facility', /** @scrutinizer ignore-type */ $parent_id );
Loading history...
825
			}
826
		}
827
	}
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
828
}
829