Passed
Push — master ( 037742...36c501 )
by Warwick
02:17
created

LSX_WETU_Importer_Tours   F

Complexity

Total Complexity 260

Size/Duplication

Total Lines 1319
Duplicated Lines 12.66 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 167
loc 1319
rs 0.8
c 0
b 0
f 0
wmc 260
lcom 1
cbo 1

30 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A set_variables() 0 11 3
B display_page() 0 117 4
A update_options_form() 0 21 5
A find_current_tours() 25 25 4
F process_ajax_search() 6 112 30
A format_row() 0 30 3
C process_ajax_import() 18 42 14
A clean_attached_destinations() 0 9 2
F import_row() 0 81 25
F process_itineraries() 50 162 53
B set_map_data() 0 27 7
A set_itinerary_day() 0 3 1
B set_price() 4 17 7
A set_duration() 5 7 3
A set_group_size() 0 6 3
A set_travel_styles() 0 7 3
B set_accommodation() 0 25 8
A find_current_accommodation() 0 13 3
A find_current_destinations() 0 3 1
D set_destination() 3 86 24
C set_country() 3 51 12
C attach_destination_images() 7 44 15
B set_featured_image() 0 31 7
B set_banner_image() 14 43 8
B check_if_image_is_used() 0 54 5
A queue_item() 0 7 3
A save_queue() 0 16 4
A table_header() 16 16 1
A table_footer() 16 16 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like LSX_WETU_Importer_Tours often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use LSX_WETU_Importer_Tours, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * @package   LSX_WETU_Importer_Tours
4
 * @author    LightSpeed
5
 * @license   GPL-3+
6
 * @link
7
 * @copyright 2017 LightSpeed
8
 **/
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() {
92
		$this->set_variables();
93
	}
94
95
	/**
96
	 * Sets the variables used throughout the plugin.
97
	 */
98
	public function set_variables() {
99
		parent::set_variables();
100
		if ( false !== $this->api_key ) {
101
			$this->url    = 'https://wetu.com/API/Itinerary/' . $this->api_key;
102
			$this->url_qs = '';
103
		}
104
		$tour_options = get_option( 'lsx_wetu_importer_tour_settings',false );
105
		if ( false !== $tour_options ) {
106
			$this->tour_options = $tour_options;
107
		}
108
	}
109
110
	/**
111
	 * Display the importer administration screen
112
	 */
113
	public function display_page() {
114
		?>
115
		<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
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
							<th class="check-column" scope="row">
137
								<label for="cb-select-0" class="screen-reader-text"><?php esc_html_e( 'Enter a title to search for and press enter','lsx-wetu-importer' ); ?></label>
138
							</th>
139
							<td class="date column-date column-ref" colspan="4">
140
								<strong>
141
									<?php esc_html_e( 'Search for tours using the search form above','lsx-wetu-importer' ); ?>
142
								</strong>
143
							</td>
144
						</tr>
145
					</tbody>
146
147
					<?php $this->table_footer(); ?>
148
149
				</table>
150
151
				<p><input class="button button-primary add" type="button" value="<?php esc_html_e( 'Add to List','lsx-wetu-importer' ); ?>" />
152
					<input class="button button-primary clear" type="button" value="<?php esc_html_e( 'Clear','lsx-wetu-importer' ); ?>" />
153
				</p>
154
			</form>
155
156
			<div style="display:none;" class="import-list-wrapper">
157
				<br />
158
				<form method="get" action="" id="import-list">
159
160
					<div class="row">
161
						<div class="settings-all" style="width:30%;display:block;float:left;">
162
							<h3><?php esc_html_e( 'What content to Sync from WETU' ); ?></h3>
163
							<ul>
164
								<li><input class="content select-all" <?php $this->checked( $this->tour_options,'all' ); ?> type="checkbox"name="content[]"  value="all" /> <?php esc_html_e( 'Select All','lsx-wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->tour_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
165
166
								<?php if ( isset( $this->options ) && ! isset( $this->options['disable_tour_descriptions'] ) ) { ?>
167
									<li><input class="content" <?php $this->checked( $this->tour_options,'description' ); ?> type="checkbox" name="content[]" value="description" /> <?php esc_html_e( 'Description','lsx-wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->tour_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
168
								<?php } ?>
169
170
								<li><input class="content" <?php $this->checked( $this->tour_options,'price' ); ?> type="checkbox" name="content[]" value="price" /> <?php esc_html_e( 'Price','lsx-wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->tour_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
171
								<li><input class="content" <?php $this->checked( $this->tour_options,'duration' ); ?> type="checkbox" name="content[]" value="duration" /> <?php esc_html_e( 'Duration','lsx-wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->tour_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
172
								<li><input class="content" <?php $this->checked( $this->tour_options,'group_size' ); ?> type="checkbox" name="content[]" value="group_size" /> <?php esc_html_e( 'Group Size','lsx-wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->tour_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
173
								<li><input class="content" <?php $this->checked( $this->tour_options,'category' ); ?> type="checkbox" name="content[]" value="category" /> <?php esc_html_e( 'Category','lsx-wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->tour_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
174
								<li><input class="content" <?php $this->checked( $this->tour_options,'tags' ); ?> type="checkbox" name="content[]" value="tags" /> <?php esc_html_e( 'Tags','lsx-wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->tour_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
175
176
								<li><input class="content" <?php $this->checked( $this->tour_options,'itineraries' ); ?> type="checkbox" name="content[]" value="itineraries" /> <?php esc_html_e( 'Itinerary Days','lsx-wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->tour_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
177
							</ul>
178
						</div>
179
						<div class="settings-all" style="width:30%;display:block;float:left;">
180
							<h3><?php esc_html_e( 'Itinerary Info' ); ?></h3>
181
							<ul>
182
								<li><input class="content" <?php $this->checked( $this->tour_options,'itinerary_description' ); ?> type="checkbox" name="content[]" value="itinerary_description" /> <?php esc_html_e( 'Description','lsx-wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->tour_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
183
								<li><input class="content" <?php $this->checked( $this->tour_options,'itinerary_included' ); ?> type="checkbox" name="content[]" value="itinerary_included" /> <?php esc_html_e( 'Included','lsx-wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->tour_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
184
								<li><input class="content" <?php $this->checked( $this->tour_options,'itinerary_excluded' ); ?> type="checkbox" name="content[]" value="itinerary_excluded" /> <?php esc_html_e( 'Excluded','lsx-wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->tour_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
185
							</ul>
186
187
							<h4><?php esc_html_e( 'Additional Content' ); ?></h4>
188
							<ul>
189
								<li><input class="content" <?php $this->checked( $this->tour_options,'accommodation' ); ?> type="checkbox" name="content[]" value="accommodation" /> <?php esc_html_e( 'Sync Accommodation','lsx-wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->tour_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
190
								<li><input class="content" <?php $this->checked( $this->tour_options,'destination' ); ?> type="checkbox" name="content[]" value="destination" /> <?php esc_html_e( 'Sync Destinations','lsx-wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->tour_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
191
								<li><input class="content" <?php $this->checked( $this->tour_options,'featured_image' ); ?> type="checkbox" name="content[]" value="featured_image" /> <?php esc_html_e( 'Featured Image','lsx-wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->tour_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
192
								<li><input class="content" <?php $this->checked( $this->tour_options,'banner_image' ); ?> type="checkbox" name="content[]" value="banner_image" /> <?php esc_html_e( 'Banner Image','lsx-wetu-importer' ); ?></li>
0 ignored issues
show
Documentation introduced by
$this->tour_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
193
							</ul>
194
						</div>
195
						<?php if ( class_exists( 'LSX_TO_Team' ) ) { ?>
196
							<div style="width:30%;display:block;float:left;">
197
								<h3><?php esc_html_e( 'Assign a Team Member' ); ?></h3>
198
								<?php $this->team_member_checkboxes( $this->tour_options ); ?>
0 ignored issues
show
Documentation introduced by
$this->tour_options is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
199
							</div>
200
						<?php } ?>
201
202
						<br clear="both" />
203
					</div>
204
205
					<h3><?php esc_html_e( 'Your List' ); ?></h3>
206
					<p><input class="button button-primary" type="submit" value="<?php esc_html_e( 'Sync','lsx-wetu-importer' ); ?>" /></p>
207
					<table class="wp-list-table widefat fixed posts">
208
						<?php $this->table_header(); ?>
209
210
						<tbody>
211
212
						</tbody>
213
214
						<?php $this->table_footer(); ?>
215
216
					</table>
217
218
					<p><input class="button button-primary" type="submit" value="<?php esc_html_e( 'Sync','lsx-wetu-importer' ); ?>" /></p>
219
				</form>
220
			</div>
221
222
			<div style="display:none;" class="completed-list-wrapper">
223
				<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>
224
				<ul>
225
				</ul>
226
			</div>
227
		</div>
228
		<?php
229
	}
230
231
	/**
232
	 * Displays the options for the form.
233
	 *
234
	 * @return void
235
	 */
236
	public function update_options_form() {
237
		$form_options = get_option( 'lsx_ti_tours_api_options' );
238
		if ( false === $form_options ) {
239
			$form_options = array( 'sample' );
240
		}
241
		?>
242
		<form method="get" class="tour-refresh-form">
243
			<input type="hidden" name="page" value="<?php echo esc_attr( $this->plugin_slug ); ?>" />
244
			<input type="hidden" name="tab" value="tour" />
245
			<input type="hidden" name="refresh_tours" value="true" />
246
			<input class="content" type="hidden" name="own" value="true" />
247
248
			<select name="type" id="wpseo-readability-filter">
249
				<option <?php if ( in_array( 'allitineraries', $form_options ) ) { echo esc_attr( 'selected="selected"' ); } ?> value="allitineraries"><?php esc_html_e( 'All Itineraries','lsx-wetu-importer' ); ?></option>
250
				<option <?php if ( in_array( 'sample', $form_options ) ) { echo esc_attr( 'selected="selected"' ); } ?>value="bad"><?php esc_html_e( 'Sample','lsx-wetu-importer' ); ?></option>
251
				<option <?php if ( in_array( 'personal', $form_options ) ) { echo esc_attr( 'selected="selected"' ); } ?>value="ok"><?php esc_html_e( 'Personal','lsx-wetu-importer' ); ?></option>
252
			</select>
253
			<input class="button submit" type="submit" value="<?php esc_attr_e( 'Refresh', 'lsx-wetu-importer' ); ?>" />
254
		</form>
255
		<?php
256
	}
257
258
	/**
259
	 * Grab all the current tour posts via the lsx_wetu_id field.
260
	 */
261 View Code Duplication
	public function find_current_tours() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
262
		global $wpdb;
263
		$return = array();
264
265
		$current_tours = $wpdb->get_results("
266
			SELECT key1.post_id,key1.meta_value
267
			FROM {$wpdb->postmeta} key1
268
269
			INNER JOIN  {$wpdb->posts} key2
270
			ON key1.post_id = key2.ID
271
272
			WHERE key1.meta_key = 'lsx_wetu_id'
273
			AND key2.post_type = 'tour'
274
275
			LIMIT 0,500
276
		");
277
278
		if ( null !== $current_tours && ! empty( $current_tours ) ) {
279
			foreach ( $current_tours as $tour ) {
280
				$return[ $tour->meta_value ] = $tour;
281
			}
282
		}
283
284
		return $return;
285
	}
286
287
	/**
288
	 * Run through the accommodation grabbed from the DB.
289
	 */
290
	public function process_ajax_search() {
291
		$return = false;
292
293
		// @codingStandardsIgnoreLine
294
		if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_tour_importer' && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug ) {
295
			$tours = get_transient( 'lsx_ti_tours' );
296
297
			if ( false !== $tours ) {
298
299
				$searched_items = false;
300
301
				// @codingStandardsIgnoreLine
302 View Code Duplication
				if ( isset( $_POST['keyword'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
303
					// @codingStandardsIgnoreLine
304
					$keyphrases = $_POST['keyword'];
305
				} else {
306
					$keyphrases = array( 0 );
307
				}
308
309
				if ( ! is_array( $keyphrases ) ) {
310
					$keyphrases = array( $keyphrases );
311
				}
312
				foreach ( $keyphrases as &$keyword ) {
313
					$keyword = ltrim( rtrim( $keyword ) );
314
				}
315
316
				$post_status = false;
317
				if ( in_array( 'publish',$keyphrases ) ) {
318
					$post_status = 'publish';
319
				}
320
				if ( in_array( 'pending',$keyphrases ) ) {
321
					$post_status = 'pending';
322
				}
323
				if ( in_array( 'draft',$keyphrases ) ) {
324
					$post_status = 'draft';
325
				}
326
				if ( in_array( 'import',$keyphrases ) ) {
327
					$post_status = 'import';
328
				}
329
330
				if ( ! empty( $tours ) ) {
331
					$current_tours = $this->find_current_tours();
332
333
					foreach ( $tours as $row_key => $row ) {
334
						if ( isset( $row['is_disabled'] ) && true === $row['is_disabled'] ) {
335
							continue;
336
						}
337
338
						/*if('Sample' === $row['type']){
339
							continue;
340
						}*/
341
342
						//If this is a current tour, add its ID to the row.
343
						$row['post_id'] = 0;
344
345
						if ( false !== $current_tours && array_key_exists( $row['identifier'], $current_tours ) ) {
346
							$row['post_id'] = $current_tours[ $row['identifier'] ]->post_id;
347
						}
348
349
						//If we are searching for
350
						if ( false !== $post_status ) {
351
							if ( 'import' === $post_status ) {
352
353
								if ( 0 !== $row['post_id'] ) {
354
									continue;
355
								} else {
356
									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row );
0 ignored issues
show
Documentation introduced by
$row is of type array<string,?,{"post_id":"?"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
357
								}
358
							} else {
359
								if ( 0 === $row['post_id'] ) {
360
									continue;
361
								} else {
362
									$current_status = get_post_status( $row['post_id'] );
363
364
									if ( $current_status !== $post_status ) {
365
										continue;
366
									}
367
								}
368
369
								$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row );
0 ignored issues
show
Documentation introduced by
$row is of type array<string,?,{"post_id":"?"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
370
							}
371
						} else {
372
							// Search through each keyword.
373
							foreach ( $keyphrases as $keyphrase ) {
374
375
								// Make sure the keyphrase is turned into an array.
376
								$keywords = explode( ' ',$keyphrase );
377
								if ( ! is_array( $keywords ) ) {
378
									$keywords = array( $keywords );
379
								}
380
381
								if ( $this->multineedle_stripos( ltrim( rtrim( $row['name'] ) ), $keywords ) !== false ) {
382
									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row );
0 ignored issues
show
Documentation introduced by
$row is of type array<string,?,{"post_id":"?"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
383
								} else if ( $this->multineedle_stripos( ltrim( rtrim( $row['reference_number'] ) ), $keywords ) !== false ) {
384
									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row );
0 ignored issues
show
Documentation introduced by
$row is of type array<string,?,{"post_id":"?"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
385
								} else if ( $this->multineedle_stripos( ltrim( rtrim( $row['identifier_key'] ) ), $keywords ) !== false ) {
386
									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row );
0 ignored issues
show
Documentation introduced by
$row is of type array<string,?,{"post_id":"?"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
387
								}
388
							}
389
						}
390
					}
391
				}
392
393
				if ( false !== $searched_items ) {
394
					ksort( $searched_items );
395
					$return = implode( $searched_items );
396
				}
397
			}
398
			print_r( $return );
399
			die();
400
		}
401
	}
402
403
	/**
404
	 * Formats the row for output on the screen.
405
	 */
406
	public function format_row( $row = false ) {
407
		if ( false !== $row ) {
408
			$status = 'import';
409
410
			if ( 0 !== $row['post_id'] ) {
411
				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
412
			}
413
414
			$row_html = '
415
			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
416
				<th class="check-column" scope="row">
417
					<label for="cb-select-' . $row['identifier'] . '" class="screen-reader-text">' . $row['name'] . '</label>
418
					<input type="checkbox" data-identifier="' . $row['identifier'] . '" value="' . $row['post_id'] . '" name="post[]" id="cb-select-' . $row['identifier'] . '">
419
				</th>			
420
				<td class="post-title page-title column-title">
421
					<strong>' . $row['name'] . '</strong> - ' . $status . '
422
				</td>
423
				<td class="date column-date">
424
					' . $row['reference_number'] . '
425
				</td>				
426
				<td class="date column-date">
427
					<abbr title="' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '">' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '</abbr><br>Last Modified
428
				</td>
429
				<td class="ssid column-ssid">
430
					' . $row['identifier'] . '
431
				</td>
432
			</tr>';
433
			return $row_html;
434
		}
435
	}
436
437
	/**
438
	 * Connect to wetu
439
	 */
440
	public function process_ajax_import( $force = false ) {
0 ignored issues
show
Unused Code introduced by
The parameter $force is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
441
		$return = false;
0 ignored issues
show
Unused Code introduced by
$return is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
442
443
		// @codingStandardsIgnoreLine
444
		if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_import_items' && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug && isset( $_POST['wetu_id'] ) ) {
445
446
			// @codingStandardsIgnoreLine
447
			$wetu_id = $_POST['wetu_id'];
448
449
			// @codingStandardsIgnoreLine
450
			if ( isset( $_POST['post_id'] ) ) {
451
				// @codingStandardsIgnoreLine
452
				$post_id = $_POST['post_id'];
453
			} else {
454
				$post_id = 0;
455
			}
456
457
			delete_option( 'lsx_wetu_importer_tour_settings' );
458
459
			// @codingStandardsIgnoreLine
460 View Code Duplication
			if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
461
				// @codingStandardsIgnoreLine
462
				$content = $_POST['content'];
463
				add_option( 'lsx_wetu_importer_tour_settings',$content );
464
			} else {
465
				$content = false;
466
			}
467
			$jdata = wp_remote_get( 'https://wetu.com/API/Itinerary/V8/Get?id=' . $wetu_id );
468
469 View Code Duplication
			if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
470
				$jdata = json_decode( $jdata['body'], true );
471
				$return = $this->import_row( $jdata, $wetu_id, $post_id, $content );
472
				$this->format_completed_row( $return );
473
				$this->save_queue();
474
				$this->cleanup_posts();
475
				$this->attach_destination_images( $content );
476
				$this->clean_attached_destinations( $return );
477
			} else {
478
				$this->format_error( esc_html__( 'There was a problem importing your tour, please contact support.', 'lsx-wetu-importer' ) );
479
			}
480
		}
481
	}
482
483
	/**
484
	 * Amends the tours destinations instead of replace.
485
	 *
486
	 * @param $id string
487
	 * @return void
488
	 */
489
	public function clean_attached_destinations( $id ) {
490
		$current_connections = get_post_meta( $id, 'destination_to_tour', false );
491
		delete_post_meta( $id,'destination_to_tour' );
492
		$current_connections = array_unique( $current_connections );
493
494
		foreach ( $current_connections as $connection ) {
495
			add_post_meta( $id, 'destination_to_tour',$connection, false );
496
		}
497
	}
498
499
	/**
500
	 * Connect to wetu
501
	 *
502
	 * @param $data array
503
	 * @param $wetu_id string
504
	 */
505
	public function import_row( $data, $wetu_id, $id = 0, $importable_content = array(), $old1 = false, $old2 = false ) {
0 ignored issues
show
Unused Code introduced by
The parameter $old1 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $old2 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
506
		$post_name = '';
507
		$data_post_content = '';
0 ignored issues
show
Unused Code introduced by
$data_post_content is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
508
		$data_post_excerpt = '';
0 ignored issues
show
Unused Code introduced by
$data_post_excerpt is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
509
510
		$current_post = get_post( $id );
511
512
		$post = array(
513
			'post_type' => 'tour',
514
		);
515
516
		$content_used_general_description = false;
0 ignored issues
show
Unused Code introduced by
$content_used_general_description is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
517
518
		if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) {
519
			$data_post_content = $current_post->post_content;
520
			if ( isset( $data['summary'] ) && ! empty( $data['summary'] ) ) {
521
				$data_post_content = $data['summary'];
522
			}
523
			$post['post_content'] = $data_post_content;
524
		}
525
526
		// Create or update the post.
527
		if ( false !== $id && '0' !== $id ) {
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison !== seems to always evaluate to true as the types of '0' (string) and $id (integer) can never be identical. Maybe you want to use a loose comparison != instead?
Loading history...
528
			$post['ID'] = $id;
529
			$post['post_status'] = 'publish';
530
			$id = wp_update_post( $post );
531
			$prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true );
532
			update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data['last_modified'] ), $prev_date );
533
534
		} else {
535
			// Set the name.
536
			if ( isset( $data['name'] ) ) {
537
				$post_name = wp_unique_post_slug( sanitize_title( $data['name'] ), $id, 'draft', 'tour', 0 );
538
			}
539
540
			if ( ! isset( $post['post_content'] ) ) {
541
				$post['post_content'] = ' ';
542
			}
543
544
			$post['post_name']   = $post_name;
545
			$post['post_title']  = $data['name'];
546
			$post['post_status'] = 'publish';
547
			$id = wp_insert_post( $post );
548
549
			// Save the WETU ID and the Last date it was modified.
550
			if ( false !== $id ) {
551
				add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
552
				add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data['last_modified'] ) );
553
			}
554
		}
555
556
		// Set the price.
557
		if ( false !== $importable_content && in_array( 'price', $importable_content ) ) {
558
			$this->set_price( $data, $id );
559
		}
560
561
		// Set the Duration.
562
		if ( false !== $importable_content && in_array( 'duration', $importable_content ) ) {
563
			$this->set_duration( $data, $id );
564
		}
565
566
		// Set the Group Size.
567
		if ( false !== $importable_content && in_array( 'group_size', $importable_content ) ) {
568
			$this->set_group_size( $data, $id );
569
		}
570
571
		// Set the Group Size.
572
		if ( false !== $importable_content && in_array( 'tags', $importable_content ) ) {
573
			$this->set_travel_styles( $id, $data );
574
		}
575
576
		if ( false !== $importable_content && in_array( 'itineraries', $importable_content ) && isset( $data['legs'] ) && ! empty( $data['legs'] ) ) {
577
			$this->process_itineraries( $data, $id, $importable_content );
578
		}
579
580
		if ( in_array( 'map', $importable_content ) && isset( $data['routes'] ) && ! empty( $data['routes'] ) ) {
581
			$this->set_map_data( $data, $id );
582
		}
583
584
		return $id;
585
	}
586
587
	/**
588
	 * A loop which runs through each leg on the tour.
589
	 */
590
	public function process_itineraries( $data, $id, $importable_content ) {
591
		$day_counter = 1;
592
		$leg_counter = 0;
593
594
		delete_post_meta( $id, 'itinerary' );
595
596
		if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) {
597
			delete_post_meta( $id, 'accommodation_to_tour' );
598
		}
599
		if ( false !== $importable_content && in_array( 'destination', $importable_content ) ) {
600
			delete_post_meta( $id, 'departs_from' );
601
			delete_post_meta( $id, 'ends_in' );
602
		}
603
604
		$departs_from = false;
605
		$ends_in = false;
606
607
		foreach ( $data['legs'] as $leg ) {
608
			// Itinerary Accommodation.
609
			$current_accommodation = false;
610
			if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) {
611
				$current_accommodation = $this->set_accommodation( $leg, $id );
612
			}
613
614
			// Itinerary Destination.
615
			$current_destination = false;
616
			if ( false !== $importable_content && in_array( 'destination', $importable_content ) ) {
617
				$current_destination = $this->set_destination( $leg, $id, $leg_counter );
618
			}
619
620
			// If the Nights are the same mount of days in the array,  then it isnt "By Destination".
621
			if ( ( (1 <= (int) $leg['nights'] && isset( $leg['periods'] ) ) ) || 0 === $leg['itinerary_leg_id'] ) {
622
				foreach ( $leg['periods'] as $day ) {
623
					$current_day = array();
624
					$current_day['title'] = esc_attr( 'Day ', 'lsx-wetu-importer' ) . $day_counter;
625
626
					//print_r('<pre>');print_r($day['notes']);print_r('</pre>');
627
628
					// Description.
629
					if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $day['notes'] ) ) {
630
						$current_day['description'] = $day['notes'];
631
					} else {
632
						$current_day['description'] = '';
633
					}
634
635
					// Itinerary Gallery.
636 View Code Duplication
					if ( false !== $importable_content && in_array( 'itinerary_gallery', $importable_content ) && isset( $day['images'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
637
						$current_day['featured_image'] = '';
638
					} else {
639
						$current_day['featured_image'] = '';
640
					}
641
642
					// Accommodation.
643 View Code Duplication
					if ( false !== $current_accommodation ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
644
						$current_day['accommodation_to_tour'] = array( $current_accommodation );
645
					} else {
646
						$current_day['accommodation_to_tour'] = array();
647
					}
648
649
					// Destination.
650 View Code Duplication
					if ( false !== $current_destination ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
651
						$current_day['destination_to_tour'] = array( $current_destination );
652
					} else {
653
						$current_day['destination_to_tour'] = array();
654
					}
655
656
					// Included.
657 View Code Duplication
					if ( false !== $importable_content && in_array( 'itinerary_included', $importable_content ) && isset( $day['included'] ) && '' !== $day['included'] ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
658
						$current_day['included'] = $day['included'];
659
					} else {
660
						$current_day['included'] = '';
661
					}
662
663
					// Excluded.
664 View Code Duplication
					if ( false !== $importable_content && in_array( 'itinerary_excluded', $importable_content ) && isset( $day['excluded'] ) && '' !== $day['excluded'] ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
665
						$current_day['excluded'] = $day['excluded'];
666
					} else {
667
						$current_day['excluded'] = '';
668
					}
669
670
					$this->set_itinerary_day( $current_day,$id );
671
					$day_counter++;
672
				}
673
			} else {
674
				// This is for the by destination.
675
676
				$current_day = array();
677
				$next_day_count = $day_counter + (int) $leg['nights'];
678
				$day_count_label = $next_day_count - 1;
679
680
				$current_day['title'] = esc_attr( 'Day ', 'lsx-wetu-importer' ) . $day_counter;
681
682
				if ( 0 !== (int) $leg['nights'] ) {
683
					$current_day['title'] .= ' - ' . $day_count_label;
684
				}
685
686
				// Description.
687
				if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $leg['notes'] ) ) {
688
					$current_day['description'] = $leg['notes'];
689
				} else {
690
					$current_day['description'] = '';
691
				}
692
693
				// Itinerary Gallery.
694 View Code Duplication
				if ( false !== $importable_content && in_array( 'itinerary_gallery', $importable_content ) && isset( $leg['images'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
695
					$current_day['featured_image'] = '';
696
				} else {
697
					$current_day['featured_image'] = '';
698
				}
699
700
				// Accommodation.
701 View Code Duplication
				if ( false !== $current_accommodation ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
702
					$current_day['accommodation_to_tour'] = array( $current_accommodation );
703
				} else {
704
					$current_day['accommodation_to_tour'] = array();
705
				}
706
707
				// Destination.
708 View Code Duplication
				if ( false !== $current_destination ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
709
					$current_day['destination_to_tour'] = array( $current_destination );
710
				} else {
711
					$current_day['destination_to_tour'] = array();
712
				}
713
714
				//Included
715 View Code Duplication
				if ( false !== $importable_content && in_array( 'itinerary_included', $importable_content ) && isset( $leg['included'] ) && '' !== $leg['included'] ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
716
					$current_day['included'] = $leg['included'];
717
				} else {
718
					$current_day['included'] = '';
719
				}
720
721
				//Excluded
722 View Code Duplication
				if ( false !== $importable_content && in_array( 'itinerary_excluded', $importable_content ) && isset( $leg['excluded'] ) && '' !== $leg['excluded'] ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
723
					$current_day['excluded'] = $leg['excluded'];
724
				} else {
725
					$current_day['excluded'] = '';
726
				}
727
728
				$this->set_itinerary_day( $current_day,$id );
729
				$day_counter = $next_day_count;
730
			}
731
732
			// If we are in the first leg,  and the destination was attached then save it as the departure field.
733
			if ( 0 === $leg_counter && false !== $current_destination ) {
734
				$departs_from = $current_destination;
735
			}
736
737
			// If its the last leg then save it as the ends in.
738
			if ( $leg_counter === (count( $data['legs'] ) -2) && false !== $current_destination ) {
739
				$ends_in = $current_destination;
740
			}
741
742
			$leg_counter++;
743
		}
744
745
		if ( false !== $departs_from ) {
746
			add_post_meta( $id, 'departs_from', $departs_from, true );
747
		}
748
		if ( false !== $ends_in ) {
749
			add_post_meta( $id, 'ends_in', $ends_in, true );
750
		}
751
	}
752
753
	/**
754
	 * Run through your routes and save the points as a KML file.
755
	 */
756
	public function set_map_data( $data, $id, $zoom = 9 ) {
757
		if ( ! empty( $data['routes'] ) ) {
758
			delete_post_meta( $id,'wetu_map_points' );
759
760
			$points = array();
761
762
			foreach ( $data['routes'] as $route ) {
763
764
				if ( isset( $route['points'] ) && '' !== $route['points'] ) {
765
766
					$temp_points = explode( ';',$route['points'] );
767
					$point_counter = count( $temp_points );
768
769
					for ( $x = 0; $x <= $point_counter; $x++ ) {
770
						$y = $x + 1;
771
						$points[] = $temp_points[ $x ] . ',' . $temp_points[ $y ];
772
						$x++;
773
					}
774
				}
775
			}
776
777
			if ( ! empty( $points ) ) {
778
				$this->save_custom_field( implode( ' ',$points ),'wetu_map_points',$id,false,true );
0 ignored issues
show
Documentation introduced by
implode(' ', $points) is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
779
			}
780
		}
781
782
	}
783
784
	// CLASS SPECIFIC FUNCTIONS.
785
786
	/**
787
	 * Set the Itinerary Day
788
	 */
789
	public function set_itinerary_day( $day, $id ) {
790
		$this->save_custom_field( $day,'itinerary',$id,false,false );
791
	}
792
793
	/**
794
	 * Set the price
795
	 */
796
	public function set_price( $data, $id ) {
797
		//Price
798 View Code Duplication
		if ( isset( $data['price'] ) && '' !== $data['price'] ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
799
			$price = preg_replace( '/[^0-9,.]/', '', $data['price'] );
800
			$this->save_custom_field( $price,'price',$id );
801
		}
802
803
		//Price includes
804
		if ( isset( $data['price_includes'] ) && '' !== $data['price_includes'] ) {
805
			$this->save_custom_field( $data['price_includes'],'included',$id );
806
		}
807
808
		//Price Excludes
809
		if ( isset( $data['price_excludes'] ) && '' !== $data['price_excludes'] ) {
810
			$this->save_custom_field( $data['price_excludes'],'not_included',$id );
811
		}
812
	}
813
814
	/**
815
	 * Set the duration
816
	 */
817
	public function set_duration( $data, $id ) {
818 View Code Duplication
		if ( isset( $data['days'] ) && ! empty( $data['days'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
819
			$price = $data['days'];
820
			$price = preg_replace( '/[^0-9,.]/', '', $price );
821
			$this->save_custom_field( $price,'duration',$id );
822
		}
823
	}
824
825
	/**
826
	 * Set the group size
827
	 */
828
	public function set_group_size( $data, $id ) {
829
		if ( isset( $data['group_size'] ) && ! empty( $data['group_size'] ) ) {
830
			$group_size = $data['group_size'];
831
			$this->save_custom_field( $group_size,'group_size',$id );
832
		}
833
	}
834
835
	/**
836
	 * Takes the WETU tags and sets the Travel Styles.
837
	 *
838
	 * @param string $id
839
	 * @param array $travel_styles
0 ignored issues
show
Bug introduced by
There is no parameter named $travel_styles. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
840
	 * @return void
841
	 */
842
	public function set_travel_styles( $id, $data ) {
843
		if ( isset( $data['tags'] ) ) {
844
			foreach ( $data['tags'] as $tag ) {
845
				$this->set_term( $id, $tag, 'travel-style' );
0 ignored issues
show
Documentation introduced by
$id is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'travel-style' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
846
			}
847
		}
848
	}
849
850
	/**
851
	 * Connects the Accommodation if its available
852
	 */
853
	public function set_accommodation( $day, $id ) {
854
		$ac_id = false;
855
		$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 boolean. 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...
856
857
		if ( isset( $day['content_entity_id'] ) && ! empty( $day['content_entity_id'] ) ) {
858
			if ( false !== $this->current_accommodation && ! empty( $this->current_accommodation ) && array_key_exists( $day['content_entity_id'],$this->current_accommodation ) ) {
859
				$ac_id = $this->current_accommodation[ $day['content_entity_id'] ];
860
			} else {
861
				$ac_id = wp_insert_post(array(
862
					'post_type' => 'accommodation',
863
					'post_status' => 'draft',
864
					'post_title' => $day['content_entity_id'],
865
				));
866
867
				$this->save_custom_field( $day['content_entity_id'],'lsx_wetu_id',$ac_id );
868
			}
869
870
			if ( '' !== $ac_id && false !== $ac_id ) {
871
				$this->save_custom_field( $ac_id,'accommodation_to_tour',$id,false,false );
872
				$this->save_custom_field( $id,'tour_to_accommodation',$ac_id,false,false );
873
				$this->queue_item( $ac_id );
874
			}
875
		}
876
		return $ac_id;
877
	}
878
879
	/**
880
	 * Grab all the current accommodation posts via the lsx_wetu_id field.
881
	 *
882
	 * @param $post_type string
883
	 * @return boolean / array
884
	 */
885
	public function find_current_accommodation( $post_type = 'accommodation' ) {
886
		global $wpdb;
887
		$accommodation = parent::find_current_accommodation( $post_type );
888
		$return = false;
889
890
		if ( ! empty( $accommodation ) ) {
891
			foreach ( $accommodation as $key => $acc ) {
892
				$return[ $acc->meta_value ] = $acc->post_id;
893
			}
894
		}
895
896
		return $return;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $return; (false) is incompatible with the return type of the parent method LSX_WETU_Importer::find_current_accommodation of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
897
	}
898
899
	/**
900
	 * Grab all the current accommodation posts via the lsx_wetu_id field.
901
	 * @return boolean / array
902
	 */
903
	public function find_current_destinations() {
904
		return $this->find_current_accommodation( 'destination' );
905
	}
906
907
	/**
908
	 * Connects the destinations post type
909
	 *
910
	 * @param $day array
911
	 * @param $id string
912
	 * @return boolean / string
913
	 */
914
	public function set_destination( $day, $id, $leg_counter ) {
0 ignored issues
show
Unused Code introduced by
The parameter $leg_counter is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
915
		$dest_id    = false;
916
		$country_id = false;
917
918
		$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 boolean. 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...
919
920
		if ( isset( $day['destination_content_entity_id'] ) && ! empty( $day['destination_content_entity_id'] ) ) {
921
			if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $day['destination_content_entity_id'], $this->current_destinations ) ) {
922
				$dest_id = $this->current_destinations[ $day['destination_content_entity_id'] ];
923
924
				//TODO Check for attachments here.
925
				$this->destination_images[ $id ][] = array( $dest_id, $day['destination_content_entity_id'] );
926
927
				//Check if there is a country asigned.
928
				$potential_id = wp_get_post_parent_id( $dest_id );
929
				$country_wetu_id = get_post_meta( $potential_id, 'lsx_wetu_id', true );
930
931
				if ( false !== $country_wetu_id ) {
932
					$country_id = $this->set_country( $country_wetu_id, $id );
933
				}
934
			} else {
935
				$destination_json = wp_remote_get( 'https://wetu.com/API/Pins/' . $this->api_key . '/Get?ids=' . $day['destination_content_entity_id'] );
936
937
				if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) {
0 ignored issues
show
Bug introduced by
The variable $jdata seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
938
939
					$destination_data = json_decode( $destination_json['body'], true );
940
941
					if ( ! empty( $destination_data ) && ! isset( $destination_data['error'] ) ) {
942
						$destination_title = $day['destination_content_entity_id'];
943
944
						if ( isset( $destination_data[0]['name'] ) ) {
945
							$destination_title = $destination_data[0]['name'];
946
						}
947
948
						if ( isset( $destination_data[0]['map_object_id'] ) && isset( $destination_data[0]['position']['country_content_entity_id'] )
949
							&& $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id'] ) {
950
951
							$country_id = $this->set_country( $destination_data[0]['position']['country_content_entity_id'], $id );
952
							// Save the destination so we can grab the tour featured image and banner from them.
953
						}
954
955
						$dest_post = array(
956
							'post_type' => 'destination',
957
							'post_status' => 'draft',
958
							'post_title' => $destination_title,
959
						);
960
961
						if ( false !== $country_id ) {
962
							$dest_post['post_parent'] = $country_id;
963
						}
964
						$dest_id = wp_insert_post( $dest_post );
965
966
						// Make sure we register the.
967
						$this->current_destinations[ $day['destination_content_entity_id'] ] = $dest_id;
968
969
						// If there are images attached then use the destination.
970 View Code Duplication
						if ( isset( $destination_data[0]['content']['images'] ) && ! empty( $destination_data[0]['content']['images'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
971
							$this->destination_images[ $id ][] = array( $dest_id, $day['destination_content_entity_id'] );
972
						}
973
974
						$this->save_custom_field( $day['destination_content_entity_id'], 'lsx_wetu_id', $dest_id );
975
					}
976
				}
977
			}
978
979
			if ( '' !== $dest_id && false !== $dest_id ) {
980
				$this->save_custom_field( $dest_id, 'destination_to_tour', $id, false, false );
981
				$this->save_custom_field( $id, 'tour_to_destination', $dest_id, false, false );
982
983
				//Save the item to display in the queue
984
				$this->queue_item( $dest_id );
985
986
				//Save the item to clean up the amount of connections.
987
				$this->cleanup_posts[ $dest_id ] = 'tour_to_destination';
988
989
				//Add this relation info so we can make sure certain items are set as countries.
990
				if ( 0 !== $country_id && false !== $country_id ) {
991
					$this->relation_meta[ $dest_id ] = $country_id;
992
					$this->relation_meta[ $country_id ] = 0;
993
				} else {
994
					$this->relation_meta[ $dest_id ] = 0;
995
				}
996
			}
997
		}
998
		return $dest_id;
999
	}
1000
1001
	/**
1002
	 * Connects the destinations post type
1003
	 *
1004
	 * @param $dest_id string
1005
	 * @param $country_id array
1006
	 * @param $id string
1007
	 *
1008
	 * @return string
1009
	 */
1010
	public function set_country( $country_wetu_id, $id ) {
1011
		$country_id = false;
1012
		$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 boolean. 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...
1013
1014
		if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $country_wetu_id, $this->current_destinations ) ) {
1015
			$country_id = $this->current_destinations[ $country_wetu_id ];
1016
			$this->destination_images[ $id ][] = array( $country_id, $country_wetu_id );
1017
		} else {
1018
			$country_json = file_get_contents( 'https://wetu.com/API/Pins/' . $this->api_key . '/Get?ids=' . $country_wetu_id );
1019
1020
			if ( $country_json ) {
1021
				$country_data = json_decode( $country_json, true );
1022
1023
				if ( ! empty( $country_data ) && ! isset( $country_data['error'] ) ) {
1024
1025
					//Format the title of the destination if its available,  otherwise default to the WETU ID.
1026
					$country_title = $country_wetu_id;
1027
1028
					if ( isset( $country_data[0]['name'] ) ) {
1029
						$country_title = $country_data[0]['name'];
1030
					}
1031
1032
					$country_id = wp_insert_post(array(
1033
						'post_type' => 'destination',
1034
						'post_status' => 'draft',
1035
						'post_title' => $country_title,
1036
					));
1037
1038
					//add the country to the current destination stack
1039
					$this->current_destinations[ $country_wetu_id ] = $country_id;
1040
1041
					// Check if there are images and save fore use later.
1042 View Code Duplication
					if ( isset( $country_data[0]['content']['images'] ) && ! empty( $country_data[0]['content']['images'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1043
						$this->destination_images[ $id ][] = array( $country_id,$country_wetu_id );
1044
					}
1045
1046
					//Save the wetu field
1047
					$this->save_custom_field( $country_wetu_id, 'lsx_wetu_id', $country_id );
1048
				}
1049
			}
1050
		}
1051
1052
		if ( '' !== $country_id && false !== $country_id ) {
1053
			$this->save_custom_field( $country_id, 'destination_to_tour', $id, false, false );
1054
			$this->save_custom_field( $id, 'tour_to_destination', $country_id, false, false );
1055
			$this->queue_item( $country_id );
1056
			$this->cleanup_posts[ $country_id ] = 'tour_to_destination';
1057
1058
			return $country_id;
1059
		}
1060
	}
1061
1062
	/**
1063
	 * Connects the destinations post type
1064
	 *
1065
	 * @param $dest_id string
1066
	 * @param $country_id array
1067
	 * @param $id string
1068
	 *
1069
	 * @return string
1070
	 */
1071
	public function attach_destination_images( $importable_content = array() ) {
1072
		if ( false !== $this->destination_images ) {
1073
			$this->shuffle_assoc( $this->destination_images );
1074
1075
			foreach ( $this->destination_images as $tour => $destinations ) {
1076
				//$this->shuffle_assoc( $destinations );
1077
1078
				$image_set = false;
1079
				$forced = false;
1080
1081
				foreach ( $destinations as $destination ) {
1082
					if ( false === $image_set && false === $forced ) {
1083
						$url = 'https://wetu.com/API/Pins/' . $this->api_key;
1084
						$url_qs = '';
1085
1086
						$jdata = file_get_contents( $url . '/Get?' . $url_qs . '&ids=' . $destination[1] );
1087
1088
						if ( $jdata ) {
1089
							$adata = json_decode( $jdata, true );
1090
1091
							if ( ! empty( $adata ) && ! empty( $adata[0]['content']['images'] ) ) {
1092
								$this->find_attachments( $destination[0] );
1093
1094
								//Set the featured image
1095
								if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
1096
									$image_set = $this->set_featured_image( $adata, $tour );
1097 View Code Duplication
									if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1098
										$image_set = $this->set_banner_image( $adata, $tour );
1099
										$forced = true;
1100
									}
1101
									continue;
1102
								}
1103 View Code Duplication
								if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1104
									$image_set = $this->set_banner_image( $adata, $tour );
1105
								}
1106
							}
1107
						}
1108
					} else {
1109
						continue;
1110
					}
1111
				}
1112
			}
1113
		}
1114
	}
1115
1116
	/**
1117
	 * Creates the main gallery data
1118
	 */
1119
	public function set_featured_image( $data, $id ) {
1120
		$image_set = false;
1121
		$counter = 0;
1122
1123
		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
1124
			foreach ( $data[0]['content']['images'] as $v ) {
1125
				/*print_r('<pre>');
1126
				print_r( $v );
1127
				print_r('</pre>');*/
1128
1129
				if ( true === $image_set ) {
1130
					$counter++;
1131
					continue;
1132
				}
1133
1134
				if ( ! $this->check_if_image_is_used( $v ) ) {
1135
					$temp_featured_image = $this->attach_image( $v , $id );
1136
1137
					if ( false !== $temp_featured_image ) {
1138
						$this->featured_image = $temp_featured_image;
1139
						delete_post_meta( $id, '_thumbnail_id' );
1140
						add_post_meta( $id, '_thumbnail_id', $this->featured_image, true );
1141
						$image_set = true;
1142
					}
1143
				}
1144
1145
				$counter++;
1146
			}
1147
		}
1148
		return $image_set;
1149
	}
1150
1151
	/**
1152
	 * Sets a banner image
1153
	 */
1154
	public function set_banner_image( $data, $id, $content = array( 'none' ) ) {
1155
		$image_set = false;
1156
		$counter = 0;
1157
1158
		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
1159
1160
			foreach ( $data[0]['content']['images'] as $v ) {
1161
				/*print_r('<pre>');
1162
				print_r( $v );
1163
				print_r('</pre>');*/
1164
1165
				if ( true === $image_set || 0 === $counter ) {
1166
					$counter++;
1167
					continue;
1168
				}
1169
1170
				if ( ! $this->check_if_image_is_used( $v ) ) {
1171
					$temp_banner = $this->attach_image( $v, $id, array(
0 ignored issues
show
Documentation introduced by
array('width' => '1920',...00', 'cropping' => 'c') is of type array<string,string,{"wi...","cropping":"string"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1172
						'width' => '1920',
1173
						'height' => '600',
1174
						'cropping' => 'c',
1175
					) );
1176
1177 View Code Duplication
					if ( false !== $temp_banner ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1178
						$this->banner_image = $temp_banner;
1179
1180
						delete_post_meta( $id,'image_group' );
1181
1182
						$new_banner = array(
1183
							'banner_image' => array(
1184
								'cmb-field-0' => $this->banner_image,
1185
							),
1186
						);
1187
						add_post_meta( $id,'image_group',$new_banner,true );
1188
						$image_set = true;
1189
					}
1190
				}
1191
				$counter++;
1192
			}
1193
		}
1194
1195
		return $image_set;
1196
	}
1197
1198
	/**
1199
	 * Grabs all of the current used featured images on the site.
1200
	 */
1201
	public function check_if_image_is_used( $v ) {
1202
		global $wpdb;
1203
1204
		$temp_fragment = explode( '/', $v['url_fragment'] );
1205
		$url_filename = $temp_fragment[ count( $temp_fragment ) -1 ];
1206
		$url_filename = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $url_filename );
1207
		$url_filename = trim( $url_filename );
1208
		$url_filename = str_replace( ' ', '_', $url_filename );
1209
1210
		if ( in_array( $url_filename, $this->found_attachments ) ) {
1211
			//check to see if there is a featured image set with this ID.
1212
			$found_id = array_search( $url_filename, $this->found_attachments );
1213
1214
			$querystring = "
1215
				SELECT      post_id
1216
				FROM        {$wpdb->postmeta}
1217
				WHERE       meta_value = '{$found_id}'
1218
				AND 		meta_key = '_thumbnail_id'
1219
			";
1220
			// @codingStandardsIgnoreLine
1221
			$results = $wpdb->get_results( $querystring );
1222
1223
			if ( ! empty( $results ) ) {
1224
				return true;
1225
			} else {
1226
				return false;
1227
			}
1228
		} else {
1229
			$querystring = "
1230
				SELECT      ID
1231
				FROM        {$wpdb->posts}
1232
				WHERE       post_name = '{$url_filename}'
1233
			";
1234
			// @codingStandardsIgnoreLine
1235
			$results = $wpdb->get_results( $querystring );
1236
			if ( ! empty( $results ) ) {
1237
				$querystring = "
1238
					SELECT      post_id
1239
					FROM        {$wpdb->postmeta}
1240
					WHERE       meta_value = '{$results[0]->ID}'
1241
					AND 		meta_key = '_thumbnail_id'
1242
				";
1243
				// @codingStandardsIgnoreLine
1244
				$results = $wpdb->get_results( $querystring );
1245
				if ( ! empty( $results ) ) {
1246
					return true;
1247
				} else {
1248
					return false;
1249
				}
1250
			} else {
1251
				return false;
1252
			}
1253
		}
1254
	}
1255
1256
	/**
1257
	 * Que an item to be saved.
1258
	 *
1259
	 * @param   $id     int
1260
	 */
1261
	public function queue_item( $id ) {
1262
		if ( is_array( $this->import_queue ) && ! in_array( $id,$this->import_queue ) ) {
1263
			$this->import_queue[] = $id;
1264
		} else {
1265
			$this->import_queue[] = $id;
1266
		}
1267
	}
1268
1269
	/**
1270
	 * Saves the queue to the option.
1271
	 */
1272
	public function save_queue() {
1273
		if ( ! empty( $this->import_queue ) ) {
1274
			if ( ! empty( $this->queued_imports ) ) {
1275
				$saved_imports = array_merge( $this->queued_imports,$this->import_queue );
1276
			} else {
1277
				$saved_imports = $this->import_queue;
1278
			}
1279
1280
			delete_option( 'lsx_wetu_importer_que' );
1281
1282
			if ( ! empty( $saved_imports ) ) {
1283
				$saved_imports = array_unique( $saved_imports );
1284
				update_option( 'lsx_wetu_importer_que',$saved_imports );
1285
			}
1286
		}
1287
	}
1288
1289
	/**
1290
	 * The header of the item list
1291
	 */
1292 View Code Duplication
	public function table_header() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1293
		?>
1294
		<thead>
1295
		<tr>
1296
			<th style="" class="manage-column column-cb check-column" id="cb" scope="col">
1297
				<label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e( 'Select All', 'lsx-wetu-importer' ); ?></label>
1298
				<input type="checkbox" id="cb-select-all-1">
1299
			</th>
1300
			<th style="" class="manage-column column-title " id="title" style="width:50%;" scope="col"><?php esc_attr_e( 'Title', 'lsx-wetu-importer' ); ?></th>
1301
			<th style="" class="manage-column column-date" id="ref" style="width:10%;" scope="col"><?php esc_attr_e( 'Ref', 'lsx-wetu-importer' ); ?></th>
1302
			<th style="" class="manage-column column-date" id="date" scope="col"><?php esc_attr_e( 'Date', 'lsx-wetu-importer' ); ?></th>
1303
			<th style="" class="manage-column column-ssid" id="ssid" scope="col"><?php esc_attr_e( 'WETU ID', 'lsx-wetu-importer' ); ?></th>
1304
		</tr>
1305
		</thead>
1306
		<?php
1307
	}
1308
1309
	/**
1310
	 * The footer of the item list
1311
	 */
1312 View Code Duplication
	public function table_footer() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1313
		?>
1314
		<tfoot>
1315
		<tr>
1316
			<th style="" class="manage-column column-cb check-column" id="cb" scope="col">
1317
				<label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e( 'Select All', 'lsx-wetu-importer' ); ?></label>
1318
				<input type="checkbox" id="cb-select-all-1">
1319
			</th>
1320
			<th style="" class="manage-column column-title" scope="col"><?php esc_attr_e( 'Title', 'lsx-wetu-importer' ); ?></th>
1321
			<th style="" class="manage-column column-date" id="ref" style="width:10%;" scope="col"><?php esc_attr_e( 'Ref', 'lsx-wetu-importer' ); ?></th>			
1322
			<th style="" class="manage-column column-date" scope="col"><?php esc_attr_e( 'Date', 'lsx-wetu-importer' ); ?></th>
1323
			<th style="" class="manage-column column-ssid" scope="col"><?php esc_attr_e( 'WETU ID', 'lsx-wetu-importer' ); ?></th>
1324
		</tr>
1325
		</tfoot>
1326
		<?php
1327
	}
1328
}
1329