LSX_WETU_Importer_Tours::import_row()   F
last analyzed

Complexity

Conditions 32
Paths 7680

Size

Total Lines 93
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
cc 32
eloc 48
nc 7680
nop 7
dl 0
loc 93
rs 0
c 7
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
2
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
3
 * @package   LSX_WETU_Importer_Tours
4
 * @author    LightSpeed
5
 * @license   GPL-3+
6
 * @link
7
 * @copyright 2017 LightSpeed
8
 **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the class comment
Loading history...
9
10
class LSX_WETU_Importer_Tours 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 = '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() {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
92
		$this->set_variables();
93
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
101
			$this->url    = 'https://wetu.com/API/Itinerary/' . $this->api_key;
0 ignored issues
show
Bug introduced by
Are you sure $this->api_key of type true 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

101
			$this->url    = 'https://wetu.com/API/Itinerary/' . /** @scrutinizer ignore-type */ $this->api_key;
Loading history...
102
			$this->url_qs = '';
103
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
104
		$tour_options = get_option( 'lsx_wetu_importer_tour_settings', false );
105
		if ( false !== $tour_options ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
106
			$this->tour_options = $tour_options;
107
		}
108
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
109
110
	/**
111
	 * Display the importer administration screen
112
	 */
113
	public function display_page() {
114
		?>
115
		<div class="wrap">
116
117
			<div class="tablenav top">
118
				<div class="alignleft actions">
119
					<?php $this->search_form(); ?>
120
				</div>
121
122
				<div class="alignleft actions">
123
					<?php $this->update_options_form(); ?>
124
				</div>
125
				<br clear="both" />
126
			</div>
127
128
			<form method="get" action="" id="posts-filter">
129
				<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr( $this->tab_slug ); ?>" />
130
131
				<table class="wp-list-table widefat fixed posts">
132
					<?php $this->table_header(); ?>
133
134
					<tbody id="the-list">
135
						<tr class="post-0 type-tour status-none" id="post-0">
136
							<td class="date column-date column-ref" colspan="5">
137
								<strong>
138
									<?php esc_html_e( 'Search for tours using the search form above', 'lsx-wetu-importer' ); ?>
139
								</strong>
140
							</td>
141
						</tr>
142
					</tbody>
143
144
					<?php $this->table_footer(); ?>
145
146
				</table>
147
148
				<p><input class="button button-primary add" type="button" value="<?php esc_html_e( 'Add to List', 'lsx-wetu-importer' ); ?>" />
149
					<input class="button button-primary clear" type="button" value="<?php esc_html_e( 'Clear', 'lsx-wetu-importer' ); ?>" />
150
				</p>
151
			</form>
152
153
			<div style="display:none;" class="import-list-wrapper">
154
				<br />
155
				<form method="get" action="" id="import-list">
156
157
					<div class="row">
158
						<div class="settings-all" style="width:30%;display:block;float:left;">
159
							<h3><?php esc_html_e( 'What content to Sync from WETU' ); ?></h3>
160
							<ul>
161
								<?php if ( isset( $this->options ) && isset( $this->options['disable_tour_descriptions'] ) && 'on' !== $this->options['disable_tour_descriptions'] ) { ?>
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
162
									<li><input class="content" checked="checked" type="checkbox" name="content[]" value="description" /> <?php esc_html_e( 'Description', 'lsx-wetu-importer' ); ?></li>
163
								<?php } ?>
164
165
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="price" /> <?php esc_html_e( 'Price', 'lsx-wetu-importer' ); ?></li>
166
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="duration" /> <?php esc_html_e( 'Duration', 'lsx-wetu-importer' ); ?></li>
167
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="group_size" /> <?php esc_html_e( 'Group Size', 'lsx-wetu-importer' ); ?></li>
168
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="category" /> <?php esc_html_e( 'Category', 'lsx-wetu-importer' ); ?></li>
169
								<?php if ( isset( $this->options ) && isset( $this->options['disable_tour_tags'] ) && 'on' !== $this->options['disable_tour_tags'] ) { ?>
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
170
									<li><input class="content" checked="checked" type="checkbox" name="content[]" value="tags" /> <?php esc_html_e( 'Tags', 'lsx-wetu-importer' ); ?></li>
171
								<?php } ?>
172
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="itineraries" /> <?php esc_html_e( 'Itinerary Days', 'lsx-wetu-importer' ); ?></li>
173
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="start_end_point" /> <?php esc_html_e( 'Departs from / Ends in', 'lsx-wetu-importer' ); ?></li>
174
							</ul>
175
						</div>
176
						<div class="settings-all" style="width:30%;display:block;float:left;">
177
							<h3><?php esc_html_e( 'Itinerary Info' ); ?></h3>
178
							<ul>
179
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="itinerary_description" /> <?php esc_html_e( 'Description', 'lsx-wetu-importer' ); ?></li>
180
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="itinerary_included" /> <?php esc_html_e( 'Included', 'lsx-wetu-importer' ); ?></li>
181
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="itinerary_excluded" /> <?php esc_html_e( 'Excluded', 'lsx-wetu-importer' ); ?></li>
182
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="room_basis" /> <?php esc_html_e( 'Room Basis', 'lsx-wetu-importer' ); ?></li>
183
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="drinks_basis" /> <?php esc_html_e( 'Drink Bases', 'lsx-wetu-importer' ); ?></li>
184
							</ul>
185
186
							<h4><?php esc_html_e( 'Additional Content' ); ?></h4>
187
							<ul>
188
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="accommodation" /> <?php esc_html_e( 'Sync Accommodation', 'lsx-wetu-importer' ); ?></li>
189
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="destination" /> <?php esc_html_e( 'Sync Destinations', 'lsx-wetu-importer' ); ?></li>
190
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="featured_image" /> <?php esc_html_e( 'Featured Image', 'lsx-wetu-importer' ); ?></li>
191
								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="banner_image" /> <?php esc_html_e( 'Banner Image', 'lsx-wetu-importer' ); ?></li>
192
							</ul>
193
						</div>
194
						<?php if ( class_exists( 'LSX_TO_Team' ) ) { ?>
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
195
							<div style="width:30%;display:block;float:left;">
196
								<h3><?php esc_html_e( 'Assign a Team Member' ); ?></h3>
197
								<?php $this->team_member_checkboxes( $this->tour_options ); ?>
198
							</div>
199
						<?php } ?>
200
201
						<br clear="both" />
202
					</div>
203
204
					<h3><?php esc_html_e( 'Your List' ); ?></h3>
205
					<p><input class="button button-primary" type="submit" value="<?php esc_html_e( 'Sync', 'lsx-wetu-importer' ); ?>" /></p>
206
					<table class="wp-list-table widefat fixed posts">
207
						<?php $this->table_header(); ?>
208
209
						<tbody>
210
211
						</tbody>
212
213
						<?php $this->table_footer(); ?>
214
215
					</table>
216
217
					<p><input class="button button-primary" type="submit" value="<?php esc_html_e( 'Sync', 'lsx-wetu-importer' ); ?>" /></p>
218
				</form>
219
			</div>
220
221
			<div style="display:none;" class="completed-list-wrapper">
222
				<h3><?php esc_html_e( 'Completed', 'lsx-wetu-importer' ); ?> - <small><?php esc_html_e( 'Import your', 'lsx-wetu-importer' ); ?> <a href="<?php echo esc_attr( admin_url( 'admin.php' ) ); ?>?page=<?php echo esc_attr( $this->plugin_slug ); ?>&tab=accommodation"><?php esc_html_e( 'accommodation' ); ?></a> <?php esc_html_e( 'next', 'lsx-wetu-importer' ); ?></small></h3>
223
				<ul>
224
				</ul>
225
			</div>
226
		</div>
227
		<?php
228
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
238
			$form_options = array( 'sample' );
239
		}
240
		?>
241
		<form method="get" class="tour-refresh-form">
242
			<input type="hidden" name="page" value="<?php echo esc_attr( $this->plugin_slug ); ?>" />
243
			<input type="hidden" name="tab" value="tour" />
244
			<input type="hidden" name="refresh_tours" value="true" />
245
			<input class="content" type="hidden" name="own" value="true" />
246
247
			<select name="type">
248
				<option 
249
				<?php
250
				if ( in_array( 'personal', $form_options ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
251
					echo esc_attr( 'selected="selected"' ); }
252
				?>
253
value="personal"><?php esc_html_e( 'Personal', 'lsx-wetu-importer' ); ?></option>
254
				<option 
255
				<?php
256
				if ( in_array( 'sample', $form_options ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
257
					echo esc_attr( 'selected="selected"' ); }
258
				?>
259
value="sample"><?php esc_html_e( 'Sample', 'lsx-wetu-importer' ); ?></option>
260
			</select>
261
			<input class="button submit" type="submit" value="<?php esc_attr_e( 'Refresh', 'lsx-wetu-importer' ); ?>" />
262
		</form>
263
		<?php
264
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
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();
272
273
		$current_tours = $wpdb->get_results(
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete().
Loading history...
274
			"
275
			SELECT key1.post_id,key1.meta_value,key2.post_title
276
			FROM {$wpdb->postmeta} key1
277
278
			INNER JOIN  {$wpdb->posts} key2
279
			ON key1.post_id = key2.ID
280
281
			WHERE key1.meta_key = 'lsx_wetu_id'
282
			AND key2.post_type = 'tour'
283
284
			LIMIT 0,500
285
		"
286
		);
287
288
		if ( null !== $current_tours && ! empty( $current_tours ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
289
			foreach ( $current_tours as $tour ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
290
				$return[ $tour->meta_value ] = $tour;
0 ignored issues
show
introduced by
Detected usage of meta_value, possible slow query.
Loading history...
291
			}
292
		}
293
294
		return $return;
295
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
305
			$tours = get_transient( 'lsx_ti_tours' );
306
307
			if ( false !== $tours ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
308
				$searched_items = false;
309
				if ( isset( $_POST['keyword'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
310
					$keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) );
311
				} else {
312
					$keyphrases = array( 0 );
313
				}
314
315
				if ( ! is_array( $keyphrases ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
316
					$keyphrases = array( $keyphrases );
317
				}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
318
				foreach ( $keyphrases as &$keyword ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
319
					$keyword = ltrim( rtrim( $keyword ) );
320
				}
321
322
				$post_status = false;
323
				if ( in_array( 'publish', $keyphrases ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
324
					$post_status = 'publish';
325
				}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
326
				if ( in_array( 'pending', $keyphrases ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
327
					$post_status = 'pending';
328
				}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
329
				if ( in_array( 'draft', $keyphrases ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
330
					$post_status = 'draft';
331
				}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
332
				if ( in_array( 'import', $keyphrases ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
333
					$post_status = 'import';
334
				}
335
336
				if ( ! empty( $tours ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
337
					$current_tours = $this->find_current_tours();
338
339
					foreach ( $tours as $row_key => $row ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
340
						if ( isset( $row['is_disabled'] ) && true === $row['is_disabled'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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 ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
355
							if ( 'import' === $post_status ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
356
357
								if ( 0 !== $row['post_id'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
364
									continue;
365
								} else {
366
									$current_status = get_post_status( $row['post_id'] );
367
368
									if ( $current_status !== $post_status ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
378
379
								// Make sure the keyphrase is turned into an array.
380
								$keywords = explode( ' ', $keyphrase );
381
								if ( ! is_array( $keywords ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
382
									$keywords = array( $keywords );
383
								}
384
385
								if ( $this->multineedle_stripos( ltrim( rtrim( $row['name'] ) ), $keywords ) !== false ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
398
					$return = implode( $searched_items );
399
				}
400
			}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
401
			print_r( $return );
0 ignored issues
show
introduced by
print_r() found. Debug code should not normally be used in production.
Loading history...
402
			die();
0 ignored issues
show
Best Practice introduced by
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...
403
		}
404
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
405
406
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$row_key" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$row" missing
Loading history...
407
	 * Formats the row for output on the screen.
408
	 */
409
	public function format_row( $row = false, $row_key = '' ) {
410
		if ( false !== $row ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
411
			$status = 'import';
412
413
			if ( 0 !== $row['post_id'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
414
				$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
Bug introduced by
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

414
				$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...
415
			}
416
417
			$row_html = '
418
			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
419
				<td class="check-column">
420
					<label for="cb-select-' . $row['identifier'] . '" class="screen-reader-text">' . $row['post_title'] . '</label>
421
					<input type="checkbox" data-identifier="' . $row['identifier'] . '" value="' . $row['post_id'] . '" name="post[]" id="cb-select-' . $row['identifier'] . '">
422
				</td>
423
				<td class="column-order">
424
					' . ( $row_key + 1 ) . '
425
				</td>
426
				<td class="post-title page-title column-title">
427
					' . $row['post_title'] . ' - ' . $status . '
428
				</td>
429
				<td class="date column-date">
430
					' . $row['reference_number'] . '
431
				</td>
432
				<td class="date column-date">
433
					<abbr title="' . date( 'Y/m/d', strtotime( $row['last_modified'] ) ) . '">' . date( 'Y/m/d', strtotime( $row['last_modified'] ) ) . '</abbr><br>Last Modified
0 ignored issues
show
introduced by
date() is affected by runtime timezone changes which can cause date/time to be incorrectly displayed. Use gmdate() instead.
Loading history...
434
				</td>
435
				<td class="ssid column-ssid">
436
					' . $row['identifier'] . '
437
				</td>
438
			</tr>';
439
			return $row_html;
440
		}
441
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
442
443
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$force" missing
Loading history...
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'] ) ) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
450
451
			$wetu_id = sanitize_text_field( $_POST['wetu_id'] );
0 ignored issues
show
introduced by
$_POST data not unslashed before sanitization. Use wp_unslash() or similar
Loading history...
452
			if ( isset( $_POST['post_id'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
453
				$post_id = sanitize_text_field( $_POST['post_id'] );
0 ignored issues
show
introduced by
$_POST data not unslashed before sanitization. Use wp_unslash() or similar
Loading history...
454
			} else {
455
				$post_id = 0;
456
			}
457
458
			delete_option( 'lsx_wetu_importer_tour_settings' );
459
460
			if ( isset( $_POST['team_members'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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
			}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
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'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
487
488
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
489
	 * Amends the tours destinations instead of replace.
490
	 *
491
	 * @param $id string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
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 );
0 ignored issues
show
Bug introduced by
It seems like $current_connections can also be of type false and null; however, parameter $array of array_unique() does only seem to accept array, 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
		$current_connections = array_unique( /** @scrutinizer ignore-type */ $current_connections );
Loading history...
498
499
		foreach ( $current_connections as $connection ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
500
			add_post_meta( $id, 'destination_to_tour', $connection, false );
501
		}
502
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
503
504
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$old1" missing
Loading history...
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 "$id" 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 "$importable_content" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$old2" missing
Loading history...
505
	 * Connect to wetu
506
	 *
507
	 * @param $data array
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
508
	 * @param $wetu_id string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
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 ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
524
			$data_post_content = $current_post->post_content;
525
			if ( isset( $data['summary'] ) && ! empty( $data['summary'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
526
				$data_post_content = $data['summary'];
527
			}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
528
			$post['post_content'] = $data_post_content;
529
		}
530
531
		// Create or update the post.
532
		if ( false !== $id && '0' !== $id ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
533
			$post['ID']          = $id;
534
			$post['post_status'] = 'publish';
535
			if ( isset( $this->options ) && 'on' !== $this->options['disable_accommodation_title'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
536
				$post['post_title'] = $data['name'];
537
			}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
538
			$id = wp_update_post( $post );
539
		} else {
540
			// Set the name.
541
			if ( isset( $data['name'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
542
				$post_name = wp_unique_post_slug( sanitize_title( $data['name'] ), $id, 'draft', 'tour', 0 );
543
			}
544
545
			if ( ! isset( $post['post_content'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
introduced by
The condition false !== $id is always true.
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
556
				add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
0 ignored issues
show
Bug introduced by
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

556
				add_post_meta( /** @scrutinizer ignore-type */ $id, 'lsx_wetu_id', $wetu_id );
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
566
			$this->set_team_member( $id, $team_members );
567
		}
568
569
		// Set the price.
570
		if ( false !== $importable_content && in_array( 'price', $importable_content ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
571
			$this->set_price( $data, $id );
572
		}
573
574
		// Set the Duration.
575
		if ( false !== $importable_content && in_array( 'duration', $importable_content ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
576
			$this->set_duration( $data, $id );
577
		}
578
579
		// Set the Group Size.
580
		if ( false !== $importable_content && in_array( 'group_size', $importable_content ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
581
			$this->set_group_size( $data, $id );
582
		}
583
584
		// Set the Group Size.
585
		if ( false !== $importable_content && in_array( 'tags', $importable_content ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
586
			$this->set_travel_styles( $id, $data );
0 ignored issues
show
Bug introduced by
It seems like $id can also be of type WP_Error; however, parameter $id of LSX_WETU_Importer_Tours::set_travel_styles() does only seem to accept string, 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

586
			$this->set_travel_styles( /** @scrutinizer ignore-type */ $id, $data );
Loading history...
587
		}
588
589
		// Set the Start and End Point Destinations.
590
		if ( false !== $importable_content && in_array( 'start_end_point', $importable_content ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
591
			$this->set_start_end_point( $data, $id );
0 ignored issues
show
Bug introduced by
It seems like $id can also be of type WP_Error; however, parameter $id of LSX_WETU_Importer_Tours::set_start_end_point() does only seem to accept string, 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

591
			$this->set_start_end_point( $data, /** @scrutinizer ignore-type */ $id );
Loading history...
592
		}
593
594
		if ( false !== $importable_content && in_array( 'itineraries', $importable_content ) && isset( $data['legs'] ) && ! empty( $data['legs'] ) ) {
0 ignored issues
show
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
595
			$this->process_itineraries( $data, $id, $importable_content );
596
		}
597
598
		if ( in_array( 'map', $importable_content ) && isset( $data['routes'] ) && ! empty( $data['routes'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
599
			$this->set_map_data( $data, $id );
600
		}
601
602
		return $id;
603
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
604
605
	/**
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...
Coding Style Documentation introduced by
Doc comment for parameter "$importable_content" missing
Loading history...
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 ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
615
			delete_post_meta( $id, 'accommodation_to_tour' );
616
		}
617
618
		foreach ( $data['legs'] as $leg ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
619
620
			// Itinerary Accommodation.
621
			$current_accommodation = false;
622
			$current_destination   = false;
623
			if ( 'Mobile' !== $leg['type'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
624
				if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
625
					$current_accommodation = $this->set_accommodation( $leg, $id );
626
				}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
627
				if ( false !== $importable_content && in_array( 'destination', $importable_content ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
634
635
				foreach ( $leg['periods'] as $day_key => $day ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
642
						$day_count_label = ' - ' . ( $next_day_count - 1 );
643
					} else {
644
						$day_count_label = '';
645
					}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
646
					$current_day['title'] = esc_attr( 'Day ', 'lsx-wetu-importer' ) . $day_counter . $day_count_label;
0 ignored issues
show
introduced by
esc_attr() expects only one parameter. Did you mean to use esc_attr__() ? Found: esc_attr( 'Day ', 'lsx-wetu-importer' )
Loading history...
Unused Code introduced by
The call to esc_attr() has too many arguments starting with 'lsx-wetu-importer'. ( Ignorable by Annotation )

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

646
					$current_day['title'] = /** @scrutinizer ignore-call */ esc_attr( 'Day ', 'lsx-wetu-importer' ) . $day_counter . $day_count_label;

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
647
648
					// Description.
649
					if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $day['notes'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
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'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
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'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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'] ) {
0 ignored issues
show
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
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'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
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'] ) {
0 ignored issues
show
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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;
0 ignored issues
show
introduced by
esc_attr() expects only one parameter. Did you mean to use esc_attr__() ? Found: esc_attr( 'Day ', 'lsx-wetu-importer' )
Loading history...
721
722
				if ( 0 !== (int) $leg['nights'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
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'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
735
					$current_day['featured_image'] = '';
736
				} else {
737
					$current_day['featured_image'] = '';
738
				}
739
740
				// Accommodation.
741
				if ( false !== $current_accommodation ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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'] ) {
0 ignored issues
show
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
			}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
785
			$leg_counter++;
786
		}
787
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
788
789
	/**
790
	 * Sets the departs from and ends in points on the tours.
791
	 *
792
	 * @param array  $data
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
793
	 * @param string $id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
794
	 * @return void
795
	 */
796
	public function set_start_end_point( $data, $id ) {
797
		delete_post_meta( $id, 'departs_from' );
0 ignored issues
show
Bug introduced by
$id of type string is incompatible with the type integer expected by parameter $post_id of delete_post_meta(). ( Ignorable by Annotation )

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

797
		delete_post_meta( /** @scrutinizer ignore-type */ $id, 'departs_from' );
Loading history...
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'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
810
			$leg_counter = 0;
811
812
			foreach ( $args['points'] as $point ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
815
					$departs_from_destination = $this->set_country( $point['destination_content_entity_id'], $id );
816
					if ( false !== $departs_from_destination ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
817
						$departs_from = $departs_from_destination;
818
					}
819
				}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
820
				// If its the last leg then save it as the ends in.
821
				if ( $leg_counter === $args['end_index'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
822
					$ends_in = $point['destination_content_entity_id'];
823
				}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
824
				$leg_counter++;
825
			}
826
827
			$departs_from = apply_filters( 'lsx_wetu_departs_from_id', $departs_from, $data, $this );
828
			if ( false !== $departs_from ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
829
				add_post_meta( $id, 'departs_from', $departs_from, true );
0 ignored issues
show
Bug introduced by
$id of type string is incompatible with the type integer expected by parameter $post_id of add_post_meta(). ( Ignorable by Annotation )

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

829
				add_post_meta( /** @scrutinizer ignore-type */ $id, 'departs_from', $departs_from, true );
Loading history...
830
			}
831
832
			if ( false !== $ends_in ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
The condition false !== $ends_in_destination is always true.
Loading history...
836
					add_post_meta( $id, 'ends_in', $ends_in_destination, true );
837
				}
838
			}
839
		}
840
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
841
842
	/**
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 "$leg" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$day" missing
Loading history...
843
	 * Gets the destination for the mobile camp.
844
	 *
845
	 * @param $day
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
846
	 * @param $leg
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
847
	 * @return void
0 ignored issues
show
Coding Style introduced by
Function return type is void, but function contains return statement
Loading history...
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'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
853
			foreach ( $leg['stops'] as $stop ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
854
				$arrival_day   = (int) $stop['arrival_day'];
855
				$departure_day = (int) $stop['departure_day'];
856
				if ( $arrival_day <= $current_day && $current_day < $departure_day ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
857
					$current_destination = $this->set_destination( $stop, $id, 0 );
858
				}
859
			}
860
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
861
		return $current_destination;
862
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
863
864
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$leg" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$day" missing
Loading history...
865
	 * Gets the accommodation for the mobile camp.
866
	 *
867
	 * @param $day
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
868
	 * @param $leg
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
869
	 * @return void
0 ignored issues
show
Coding Style introduced by
Function return type is void, but function contains return statement
Loading history...
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'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
875
			foreach ( $leg['stops'] as $stop ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
876
				$arrival_day   = (int) $stop['arrival_day'];
877
				$departure_day = (int) $stop['departure_day'];
878
				if ( $arrival_day <= $current_day && $current_day < $departure_day ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
879
					$current_accommodation = $this->set_accommodation( $stop, $id, 0 );
0 ignored issues
show
Unused Code introduced by
The call to LSX_WETU_Importer_Tours::set_accommodation() has too many arguments starting with 0. ( Ignorable by Annotation )

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

879
					/** @scrutinizer ignore-call */ 
880
     $current_accommodation = $this->set_accommodation( $stop, $id, 0 );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
880
				}
881
			}
882
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
883
		return $current_accommodation;
884
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
885
886
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$zoom" missing
Loading history...
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...
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'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
891
			delete_post_meta( $id, 'wetu_map_points' );
892
893
			$points = array();
894
895
			foreach ( $data['routes'] as $route ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
896
897
				if ( isset( $route['points'] ) && '' !== $route['points'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
898
899
					$temp_points   = explode( ';', $route['points'] );
900
					$point_counter = count( $temp_points );
901
902
					for ( $x = 0; $x <= $point_counter; $x++ ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
903
						$y        = $x + 1;
904
						$points[] = $temp_points[ $x ] . ',' . $temp_points[ $y ];
905
						$x++;
906
					}
907
				}
908
			}
909
910
			if ( ! empty( $points ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
911
				$this->save_custom_field( implode( ' ', $points ), 'wetu_map_points', $id, false, true );
912
			}
913
		}
914
915
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
916
917
	// CLASS SPECIFIC FUNCTIONS.
918
919
	/**
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 "$day" missing
Loading history...
920
	 * Set the Itinerary Day.
921
	 */
922
	public function set_itinerary_day( $day, $id ) {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
923
		$this->save_custom_field( $day, 'itinerary', $id, false, false );
924
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
925
926
	/**
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...
927
	 * Set the ref number
928
	 */
929
	public function set_reference_number( $data, $id ) {
930
		if ( isset( $data['reference_number'] ) && '' !== $data['reference_number'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
931
			$this->save_custom_field( $data['reference_number'], 'lsx_wetu_ref', $id );
932
		}
933
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
934
935
	/**
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...
936
	 * Set the price.
937
	 */
938
	public function set_price( $data, $id ) {
939
		// Price.
940
		if ( isset( $data['price'] ) && '' !== $data['price'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
941
			$price = $data['price'];
942
			if ( false === apply_filters( 'lsx_wetu_importer_disable_tour_price_filter', false ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
943
				$price = preg_replace( '/[^0-9,.]/', '', $price );
944
			}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
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'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
961
962
	/**
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...
963
	 * Set the duration.
964
	 */
965
	public function set_duration( $data, $id ) {
966
		if ( isset( $data['days'] ) && ! empty( $data['days'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
967
			$price = $data['days'];
968
			$price = preg_replace( '/[^0-9,.]/', '', $price );
969
			$this->save_custom_field( $price, 'duration', $id );
970
		}
971
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
972
973
	/**
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...
974
	 * Set the group size
975
	 */
976
	public function set_group_size( $data, $id ) {
977
		if ( isset( $data['group_size'] ) && ! empty( $data['group_size'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
978
			$group_size = $data['group_size'];
979
			$this->save_custom_field( $group_size, 'group_size', $id );
980
		}
981
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
982
983
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$data" missing
Loading history...
984
	 * Takes the WETU tags and sets the Travel Styles.
985
	 *
986
	 * @param string $id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
987
	 * @param array  $travel_styles
0 ignored issues
show
Coding Style introduced by
Doc comment for parameter $travel_styles does not match actual variable name $data
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
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 ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
993
			foreach ( $tags as $tag ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
994
				$this->set_term( $id, $tag, 'travel-style' );
0 ignored issues
show
Bug introduced by
'travel-style' 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

994
				$this->set_term( $id, $tag, /** @scrutinizer ignore-type */ 'travel-style' );
Loading history...
Bug introduced by
$id of type string is incompatible with the type boolean expected by parameter $id 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

994
				$this->set_term( /** @scrutinizer ignore-type */ $id, $tag, 'travel-style' );
Loading history...
995
			}
996
		}
997
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
998
999
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$day" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
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();
0 ignored issues
show
Documentation Bug introduced by
The property $current_accommodation was declared of type string, but $this->find_current_accommodation() is of type false. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1005
1006
		if ( isset( $day['content_entity_id'] ) && ! empty( $day['content_entity_id'] ) && ! in_array( (int) $day['content_entity_id'], array( 25862 ) ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
1007
			if ( false !== $this->current_accommodation && ! empty( $this->current_accommodation ) && array_key_exists( $day['content_entity_id'], $this->current_accommodation ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
The condition false !== $this->current_accommodation is always false.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
introduced by
The condition false !== $ac_id is always true.
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
1027
		return $ac_id;
1028
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
1029
1030
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_type" missing
Loading history...
1031
	 * Grab all the current accommodation posts via the lsx_wetu_id field.
1032
	 *
1033
	 * @param $post_type string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
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 ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1042
			foreach ( $accommodation as $key => $acc ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1043
				$return[ $acc->meta_value ] = $acc->post_id;
0 ignored issues
show
introduced by
Detected usage of meta_value, possible slow query.
Loading history...
1044
			}
1045
		}
1046
1047
		return $return;
1048
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
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
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
1058
1059
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$day" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$leg_counter" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
1060
	 * Connects the destinations post type
1061
	 *
1062
	 * @param $day array
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
1063
	 * @param $id string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
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();
0 ignored issues
show
Documentation Bug introduced by
The property $current_destinations was declared of type string, but $this->find_current_destinations() is of type false. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1071
1072
		if ( isset( $day['destination_content_entity_id'] ) && ! empty( $day['destination_content_entity_id'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1073
			if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $day['destination_content_entity_id'], $this->current_destinations ) ) {
0 ignored issues
show
introduced by
The condition false !== $this->current_destinations is always false.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1084
					$country_id = $this->set_country( $country_wetu_id, $id );
1085
					// $this->destination_images[ $id ][] = array( $id, $country_wetu_id );
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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'] ) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1091
1092
					$destination_data = json_decode( $destination_json['body'], true );
1093
1094
					if ( ! empty( $destination_data ) && ! isset( $destination_data['error'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1095
						$destination_title = $day['destination_content_entity_id'];
1096
1097
						if ( isset( $destination_data[0]['name'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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'] )
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1102
							&& $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id'] ) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1115
							$dest_post['post_parent'] = $country_id;
1116
						}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
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'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
1151
		return $dest_id;
1152
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
1153
1154
	/**
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 "$country_wetu_id" missing
Loading history...
1155
	 * Connects the destinations post type
1156
	 *
1157
	 * @param $dest_id string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
1158
	 * @param $country_id array
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
1159
	 * @param $id string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
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();
0 ignored issues
show
Documentation Bug introduced by
The property $current_destinations was declared of type string, but $this->find_current_destinations() is of type false. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1166
1167
		if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $country_wetu_id, $this->current_destinations ) ) {
0 ignored issues
show
introduced by
The condition false !== $this->current_destinations is always false.
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
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'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1196
					$this->destination_images[ $id ][] = array( $country_id, $country_wetu_id );
1197
				}
1198
1199
				// Save the wetu field
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
1200
				$this->save_custom_field( $country_wetu_id, 'lsx_wetu_id', $country_id );
1201
			}
1202
		}
1203
1204
		if ( '' !== $country_id && false !== $country_id ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
1213
1214
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$importable_content" missing
Loading history...
1215
	 * Connects the destinations post type
1216
	 *
1217
	 * @param $dest_id string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
1218
	 * @param $country_id array
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
1219
	 * @param $id string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
1220
	 *
1221
	 * @return string
0 ignored issues
show
Coding Style introduced by
Function return type is not void, but function has no return statement
Loading history...
1222
	 */
1223
	public function attach_destination_images( $importable_content = array() ) {
1224
		if ( false !== $this->destination_images ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
The condition false !== $this->destination_images is always true.
Loading history...
1225
			$this->shuffle_assoc( $this->destination_images );
1226
			foreach ( $this->destination_images as $tour => $destinations ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1227
				shuffle( $destinations );
1228
				$image_set = false;
1229
				$forced    = false;
1230
1231
				foreach ( $destinations as $destination ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1232
					if ( false === $image_set && false === $forced ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1239
							$adata = json_decode( $jdata['body'], true );
1240
1241
							if ( ! empty( $adata ) && ! empty( $adata[0]['content']['images'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1242
								$this->find_attachments( $destination[0] );
1243
1244
								// Set the featured image.
1245
								if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
1246
									$image_set = $this->set_featured_image( $adata, $tour );
1247
									if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
0 ignored issues
show
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1248
										$image_set = $this->set_banner_image( $adata, $tour );
1249
										$forced    = true;
1250
									}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
1251
									continue;
1252
								}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
1253
								if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
1254
									$image_set = $this->set_banner_image( $adata, $tour );
1255
								}
1256
							}
1257
						}
1258
					} else {
1259
						continue;
1260
					}
1261
				}
1262
			}
1263
		}
1264
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
1265
1266
	/**
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...
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'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1274
			$images_array = $data[0]['content']['images'];
1275
1276
			if ( 'on' === $this->options['enable_tour_featured_random'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1277
				shuffle( $images_array );
1278
			}
1279
1280
			foreach ( $images_array as $v ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
1281
1282
				if ( true === $image_set ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1283
					$counter++;
1284
					continue;
1285
				}
1286
1287
				if ( ! $this->check_if_image_is_used( $v ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1288
					$temp_featured_image = $this->attach_image( $v, $id );
1289
1290
					if ( false !== $temp_featured_image ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
1301
		return $image_set;
1302
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
1303
1304
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$content" missing
Loading history...
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...
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'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
1312
1313
			foreach ( $data[0]['content']['images'] as $v ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1314
				/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1315
				print_r('<pre>');
0 ignored issues
show
Coding Style introduced by
Block comments must start with a capital letter
Loading history...
1316
				print_r( $v );
1317
				print_r('</pre>');*/
0 ignored issues
show
Coding Style introduced by
Comment closer must be on a new line
Loading history...
1318
1319
				if ( true === $image_set || 0 === $counter ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1320
					$counter++;
1321
					continue;
1322
				}
1323
1324
				if ( ! $this->check_if_image_is_used( $v ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
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
				}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
1349
				$counter++;
1350
			}
1351
		}
1352
1353
		return $image_set;
1354
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
1355
1356
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$v" missing
Loading history...
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(
0 ignored issues
show
introduced by
Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete().
Loading history...
introduced by
Usage of a direct database call is discouraged.
Loading history...
1364
			$wpdb->prepare(
1365
				"SELECT post_id
1366
				 FROM {$wpdb->postmeta}
1367
				 WHERE meta_value = '%s'
0 ignored issues
show
introduced by
Simple placeholders should not be quoted in the query string in $wpdb->prepare(). Found: '%s'.
Loading history...
1368
				 AND meta_key = 'lsx_wetu_id'
1369
				",
1370
				array( $value )
1371
			)
1372
		);
1373
		$attached_tours = array();
1374
		if ( ! empty( $results ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1375
			foreach ( $results as $result ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1376
				if ( 'tour' === get_post_type( $result['post_id'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1377
					$attached_tours[] = $result['post_id'];
1378
				}
1379
			}
1380
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
1381
		if ( ! empty( $attached_tours ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1382
			$return = true;
1383
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
1384
		return $return;
1385
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
1386
1387
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
1388
	 * Que an item to be saved.
1389
	 *
1390
	 * @param   $id     int
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
1391
	 */
1392
	public function queue_item( $id ) {
1393
		if ( is_array( $this->import_queue ) && ! in_array( $id, $this->import_queue ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
The condition is_array($this->import_queue) is always false.
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
1394
			$this->import_queue[] = $id;
1395
		} else {
1396
			$this->import_queue[] = $id;
1397
		}
1398
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
1399
1400
	/**
1401
	 * Saves the queue to the option.
1402
	 */
1403
	public function save_queue() {
1404
		if ( ! empty( $this->import_queue ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1405
			if ( ! empty( $this->queued_imports ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1406
				$saved_imports = array_merge( $this->queued_imports, $this->import_queue );
0 ignored issues
show
Bug introduced by
$this->queued_imports of type integer is incompatible with the type array expected by parameter $arrays of array_merge(). ( Ignorable by Annotation )

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

1406
				$saved_imports = array_merge( /** @scrutinizer ignore-type */ $this->queued_imports, $this->import_queue );
Loading history...
1407
			} else {
1408
				$saved_imports = $this->import_queue;
1409
			}
1410
1411
			delete_option( 'lsx_wetu_importer_que' );
1412
1413
			if ( ! empty( $saved_imports ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1414
				$saved_imports = array_unique( $saved_imports );
0 ignored issues
show
Bug introduced by
It seems like $saved_imports can also be of type integer; however, parameter $array of array_unique() does only seem to accept array, 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

1414
				$saved_imports = array_unique( /** @scrutinizer ignore-type */ $saved_imports );
Loading history...
1415
				update_option( 'lsx_wetu_importer_que', $saved_imports );
1416
			}
1417
		}
1418
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
1419
1420
	/**
1421
	 * The header of the item list
1422
	 */
1423
	public function table_header() {
1424
		?>
1425
		<thead>
1426
		<tr>
1427
			<th class="manage-column column-cb check-column" id="cb" scope="col">
1428
				<label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e( 'Select All', 'lsx-wetu-importer' ); ?></label>
1429
				<input type="checkbox" id="cb-select-all-1">
1430
			</th>
1431
			<th class="manage-column column-order " id="order" scope="col"><?php esc_attr_e( 'Order', 'lsx-wetu-importer' ); ?></th>
1432
			<th class="manage-column column-title " id="title" scope="col"><?php esc_attr_e( 'Title', 'lsx-wetu-importer' ); ?></th>
1433
			<th class="manage-column column-date" id="ref" scope="col"><?php esc_attr_e( 'Ref', 'lsx-wetu-importer' ); ?></th>
1434
			<th class="manage-column column-date" id="date" scope="col"><?php esc_attr_e( 'Date', 'lsx-wetu-importer' ); ?></th>
1435
			<th class="manage-column column-ssid" id="ssid" scope="col"><?php esc_attr_e( 'WETU ID', 'lsx-wetu-importer' ); ?></th>
1436
		</tr>
1437
		</thead>
1438
		<?php
1439
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
1440
1441
	/**
1442
	 * The footer of the item list
1443
	 */
1444
	public function table_footer() {
1445
		?>
1446
		<tfoot>
1447
		<tr>
1448
			<th class="manage-column column-cb check-column" id="cb" scope="col">
1449
				<label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e( 'Select All', 'lsx-wetu-importer' ); ?></label>
1450
				<input type="checkbox" id="cb-select-all-1">
1451
			</th>
1452
			<th class="manage-column column-order " id="order" scope="col"><?php esc_attr_e( 'Order', 'lsx-wetu-importer' ); ?></th>
1453
			<th class="manage-column column-title" scope="col"><?php esc_attr_e( 'Title', 'lsx-wetu-importer' ); ?></th>
1454
			<th class="manage-column column-date" id="ref" scope="col"><?php esc_attr_e( 'Ref', 'lsx-wetu-importer' ); ?></th>
1455
			<th class="manage-column column-date" scope="col"><?php esc_attr_e( 'Date', 'lsx-wetu-importer' ); ?></th>
1456
			<th class="manage-column column-ssid" scope="col"><?php esc_attr_e( 'WETU ID', 'lsx-wetu-importer' ); ?></th>
1457
		</tr>
1458
		</tfoot>
1459
		<?php
1460
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
1461
}
1462