Completed
Push — master ( 02b793...7006ed )
by Warwick
10:41 queued 02:31
created

WETU_Importer_Tours::set_variables()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 0
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package   WETU_Importer_Tours
4
 * @author    LightSpeed
5
 * @license   GPL-3+
6
 * @link
7
 * @copyright 2017 LightSpeed
8
 **/
9
10
class WETU_Importer_Tours extends WETU_Importer {
11
12
	/**
13
	 * The url to list items from WETU
14
	 *
15
	 * @since 0.0.1
16
	 *
17
	 * @var      string
18
	 */
19
	public $tab_slug = '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( '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','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','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','wetu-importer' ); ?>" />
152
					<input class="button button-primary clear" type="button" value="<?php esc_html_e( 'Clear','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','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','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','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','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','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','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','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','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','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','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','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','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','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','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','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','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','wetu-importer' ); ?>" /></p>
219
				</form>
220
			</div>
221
222
			<div style="display:none;" class="completed-list-wrapper">
223
				<h3><?php esc_html_e( 'Completed', 'wetu-importer' ); ?> - <small><?php esc_html_e( 'Import your', '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','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','wetu-importer' ); ?></option>
250
				<option <?php if ( in_array( 'sample', $form_options ) ) { echo esc_attr( 'selected="selected"' ); } ?>value="bad"><?php esc_html_e( 'Sample','wetu-importer' ); ?></option>
251
				<option <?php if ( in_array( 'personal', $form_options ) ) { echo esc_attr( 'selected="selected"' ); } ?>value="ok"><?php esc_html_e( 'Personal','wetu-importer' ); ?></option>
252
			</select>
253
			<input class="button submit" type="submit" value="<?php esc_attr_e( 'Refresh', '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
								//Add in the year and ref
390
							}
391
						}
392
					}
393
				}
394
395
				if ( false !== $searched_items ) {
396
					ksort( $searched_items );
397
					$return = implode( $searched_items );
398
				}
399
			}
400
			print_r( $return );
401
			die();
402
		}
403
	}
404
405
	/**
406
	 * Formats the row for output on the screen.
407
	 */
408
	public function format_row( $row = false ) {
409
		if ( false !== $row ) {
410
			$status = 'import';
411
412
			if ( 0 !== $row['post_id'] ) {
413
				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
414
			}
415
416
			$row_html = '
417
			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
418
				<th class="check-column" scope="row">
419
					<label for="cb-select-' . $row['identifier'] . '" class="screen-reader-text">' . $row['name'] . '</label>
420
					<input type="checkbox" data-identifier="' . $row['identifier'] . '" value="' . $row['post_id'] . '" name="post[]" id="cb-select-' . $row['identifier'] . '">
421
				</th>			
422
				<td class="post-title page-title column-title">
423
					<strong>' . $row['name'] . '</strong> - ' . $status . '
424
				</td>
425
				<td class="date column-date">
426
					' . $row['reference_number'] . '
427
				</td>				
428
				<td class="date column-date">
429
					<abbr title="' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '">' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '</abbr><br>Last Modified
430
				</td>
431
				<td class="ssid column-ssid">
432
					' . $row['identifier'] . '
433
				</td>
434
			</tr>';
435
			return $row_html;
436
		}
437
	}
438
439
	/**
440
	 * Connect to wetu
441
	 */
442
	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...
443
		$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...
444
445
		// @codingStandardsIgnoreLine
446
		if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_import_items' && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug && isset( $_POST['wetu_id'] ) ) {
447
448
			// @codingStandardsIgnoreLine
449
			$wetu_id = $_POST['wetu_id'];
450
451
			// @codingStandardsIgnoreLine
452
			if ( isset( $_POST['post_id'] ) ) {
453
				// @codingStandardsIgnoreLine
454
				$post_id = $_POST['post_id'];
455
			} else {
456
				$post_id = 0;
457
			}
458
459
			delete_option( 'wetu_importer_tour_settings' );
460
461
			// @codingStandardsIgnoreLine
462 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...
463
				// @codingStandardsIgnoreLine
464
				$content = $_POST['content'];
465
				add_option( 'wetu_importer_tour_settings',$content );
466
			} else {
467
				$content = false;
468
			}
469
			$jdata = wp_remote_get( 'https://wetu.com/API/Itinerary/V8/Get?id=' . $wetu_id );		
470
471 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...
472
				$jdata = json_decode( $jdata['body'], true );
473
				$return = $this->import_row( $jdata, $wetu_id, $post_id, $content );
474
				$this->format_completed_row( $return );
475
				$this->save_queue();
476
				$this->cleanup_posts();
477
				$this->attach_destination_images( $content );
478
				$this->clean_attached_destinations( $return );
479
			} else {
480
				$this->format_error( esc_html__( 'There was a problem importing your tour, please contact support.', 'wetu-importer' ) );
481
			}
482
		}
483
	}
484
485
	/**
486
	 * Amends the tours destinations instead of replace.
487
	 *
488
	 * @param $id string
489
	 * @return void
490
	 */
491
	public function clean_attached_destinations( $id ) {
492
		$current_connections = get_post_meta( $id, 'destination_to_tour', false );
493
		delete_post_meta( $id,'destination_to_tour' );
494
		$current_connections = array_unique( $current_connections );
495
496
		foreach ( $current_connections as $connection ) {
497
			add_post_meta( $id, 'destination_to_tour',$connection, false );
498
		}
499
	}
500
501
	/**
502
	 * Connect to wetu
503
	 *
504
	 * @param $data array
505
	 * @param $wetu_id string
506
	 */
507
	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...
508
		$post_name = '';
509
		$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...
510
		$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...
511
512
		$current_post = get_post( $id );
513
514
		$post = array(
515
			'post_type' => 'tour',
516
		);
517
518
		$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...
519
520
		if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) {
521
			$data_post_content = $current_post->post_content;
522
			if ( isset( $data['summary'] ) && ! empty( $data['summary'] ) ) {
523
				$data_post_content = $data['summary'];
524
			}
525
			$post['post_content'] = $data_post_content;
526
		}
527
528
		// Create or update the post.
529
		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...
530
			$post['ID'] = $id;
531
			$post['post_status'] = 'publish';
532
			$id = wp_update_post( $post );
533
			$prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true );
534
			update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data['last_modified'] ), $prev_date );
535
536
		} else {
537
			// Set the name.
538
			if ( isset( $data['name'] ) ) {
539
				$post_name = wp_unique_post_slug( sanitize_title( $data['name'] ), $id, 'draft', 'tour', 0 );
540
			}
541
542
			if ( ! isset( $post['post_content'] ) ) {
543
				$post['post_content'] = ' ';
544
			}
545
546
			$post['post_name']   = $post_name;
547
			$post['post_title']  = $data['name'];
548
			$post['post_status'] = 'publish';
549
			$id = wp_insert_post( $post );
550
551
			// Save the WETU ID and the Last date it was modified.
552
			if ( false !== $id ) {
553
				add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
554
				add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data['last_modified'] ) );
555
			}
556
		}
557
558
		// Set the price.
559
		if ( false !== $importable_content && in_array( 'price', $importable_content ) ) {
560
			$this->set_price( $data, $id );
561
		}
562
563
		// Set the Duration.
564
		if ( false !== $importable_content && in_array( 'duration', $importable_content ) ) {
565
			$this->set_duration( $data, $id );
566
		}
567
568
		// Set the Group Size.
569
		if ( false !== $importable_content && in_array( 'group_size', $importable_content ) ) {
570
			$this->set_group_size( $data, $id );
571
		}
572
573
		// Set the Group Size.
574
		if ( false !== $importable_content && in_array( 'tags', $importable_content ) ) {
575
			$this->set_travel_styles( $id, $data );
576
		}
577
578
		if ( false !== $importable_content && in_array( 'itineraries', $importable_content ) && isset( $data['legs'] ) && ! empty( $data['legs'] ) ) {
579
			$this->process_itineraries( $data, $id, $importable_content );
580
		}
581
582
		if ( in_array( 'map', $importable_content ) && isset( $data['routes'] ) && ! empty( $data['routes'] ) ) {
583
			$this->set_map_data( $data, $id );
584
		}
585
586
		return $id;
587
	}
588
589
	/**
590
	 * A loop which runs through each leg on the tour.
591
	 */
592
	public function process_itineraries( $data, $id, $importable_content ) {
593
		$day_counter = 1;
594
		$leg_counter = 0;
595
596
		delete_post_meta( $id, 'itinerary' );
597
598
		if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) {
599
			delete_post_meta( $id, 'accommodation_to_tour' );
600
		}
601
		if ( false !== $importable_content && in_array( 'destination', $importable_content ) ) {
602
			delete_post_meta( $id, 'departs_from' );
603
			delete_post_meta( $id, 'ends_in' );
604
		}
605
606
		$departs_from = false;
607
		$ends_in = false;
608
609
		foreach ( $data['legs'] as $leg ) {
610
			// Itinerary Accommodation.
611
			$current_accommodation = false;
612
			if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) {
613
				$current_accommodation = $this->set_accommodation( $leg, $id );
614
			}
615
616
			// Itinerary Destination.
617
			$current_destination = false;
618
			if ( false !== $importable_content && in_array( 'destination', $importable_content ) ) {
619
				$current_destination = $this->set_destination( $leg, $id, $leg_counter );
620
			}
621
622
			// If the Nights are the same mount of days in the array,  then it isnt "By Destination".
623
			if ( ( (1 <= (int) $leg['nights'] && isset( $leg['periods'] ) ) ) || 0 === $leg['itinerary_leg_id'] ) {
624
				foreach ( $leg['periods'] as $day ) {
625
					$current_day = array();
626
					$current_day['title'] = esc_attr( 'Day ', 'wetu-importer' ) . $day_counter;
627
628
					//print_r('<pre>');print_r($day['notes']);print_r('</pre>');
629
630
					// Description.
631
					if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $day['notes'] ) ) {
632
						$current_day['description'] = $day['notes'];
633
					} else {
634
						$current_day['description'] = '';
635
					}
636
637
					// Itinerary Gallery.
638 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...
639
						$current_day['featured_image'] = '';
640
					} else {
641
						$current_day['featured_image'] = '';
642
					}
643
644
					// Accommodation.
645 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...
646
						$current_day['accommodation_to_tour'] = array( $current_accommodation );
647
					} else {
648
						$current_day['accommodation_to_tour'] = array();
649
					}
650
651
					// Destination.
652 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...
653
						$current_day['destination_to_tour'] = array( $current_destination );
654
					} else {
655
						$current_day['destination_to_tour'] = array();
656
					}
657
658
					// Included.
659 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...
660
						$current_day['included'] = $day['included'];
661
					} else {
662
						$current_day['included'] = '';
663
					}
664
665
					// Excluded.
666 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...
667
						$current_day['excluded'] = $day['excluded'];
668
					} else {
669
						$current_day['excluded'] = '';
670
					}
671
672
					$this->set_itinerary_day( $current_day,$id );
673
					$day_counter++;
674
				}
675
			} else {
676
				// This is for the by destination.
677
678
				$current_day = array();
679
				$next_day_count = $day_counter + (int) $leg['nights'];
680
				$day_count_label = $next_day_count - 1;
681
682
				$current_day['title'] = esc_attr( 'Day ', 'wetu-importer' ) . $day_counter;
683
684
				if ( 0 !== (int) $leg['nights'] ) {
685
					$current_day['title'] .= ' - ' . $day_count_label;
686
				}
687
688
				// Description.
689
				if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $leg['notes'] ) ) {
690
					$current_day['description'] = $leg['notes'];
691
				} else {
692
					$current_day['description'] = '';
693
				}
694
695
				// Itinerary Gallery.
696 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...
697
					$current_day['featured_image'] = '';
698
				} else {
699
					$current_day['featured_image'] = '';
700
				}
701
702
				// Accommodation.
703 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...
704
					$current_day['accommodation_to_tour'] = array( $current_accommodation );
705
				} else {
706
					$current_day['accommodation_to_tour'] = array();
707
				}
708
709
				// Destination.
710 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...
711
					$current_day['destination_to_tour'] = array( $current_destination );
712
				} else {
713
					$current_day['destination_to_tour'] = array();
714
				}
715
716
				//Included
717 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...
718
					$current_day['included'] = $leg['included'];
719
				} else {
720
					$current_day['included'] = '';
721
				}
722
723
				//Excluded
724 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...
725
					$current_day['excluded'] = $leg['excluded'];
726
				} else {
727
					$current_day['excluded'] = '';
728
				}
729
730
				$this->set_itinerary_day( $current_day,$id );
731
				$day_counter = $next_day_count;
732
			}
733
734
			//If we are in the first leg,  and the destination was attached then save it as the departure field.
735
			if ( 0 === $leg_counter && false !== $current_destination ) {
736
				$departs_from = $current_destination;
737
			}
738
739
			//If its the last leg then save it as the ends in.
740
			// @codingStandardsIgnoreLine
741
			if ( $leg_counter === (count( $data['legs'] ) -2) && false !== $current_destination ) {
742
				$ends_in = $current_destination;
743
			}
744
745
			$leg_counter++;
746
		}
747
748
		if ( false !== $departs_from ) {
749
			add_post_meta( $id, 'departs_from', $departs_from, true );
750
		}
751
		if ( false !== $ends_in ) {
752
			add_post_meta( $id, 'ends_in', $ends_in, true );
753
		}
754
	}
755
756
	/**
757
	 * Run through your routes and save the points as a KML file.
758
	 */
759
	public function set_map_data( $data, $id, $zoom = 9 ) {
760
		if ( ! empty( $data['routes'] ) ) {
761
			delete_post_meta( $id,'wetu_map_points' );
762
763
			$points = array();
764
765
			foreach ( $data['routes'] as $route ) {
766
767
				if ( isset( $route['points'] ) && '' !== $route['points'] ) {
768
769
					$temp_points = explode( ';',$route['points'] );
770
					$point_counter = count( $temp_points );
771
772
					for ( $x = 0; $x <= $point_counter; $x++ ) {
773
						$y = $x + 1;
774
						$points[] = $temp_points[ $x ] . ',' . $temp_points[ $y ];
775
						$x++;
776
					}
777
				}
778
			}
779
780
			if ( ! empty( $points ) ) {
781
				$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...
782
			}
783
		}
784
785
	}
786
787
	// CLASS SPECIFIC FUNCTIONS.
788
789
	/**
790
	 * Set the Itinerary Day
791
	 */
792
	public function set_itinerary_day( $day, $id ) {
793
		$this->save_custom_field( $day,'itinerary',$id,false,false );
794
	}
795
796
	/**
797
	 * Set the price
798
	 */
799
	public function set_price( $data, $id ) {
800
		//Price
801 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...
802
			$price = preg_replace( '/[^0-9,.]/', '', $data['price'] );
803
			$this->save_custom_field( $price,'price',$id );
804
		}
805
806
		//Price includes
807
		if ( isset( $data['price_includes'] ) && '' !== $data['price_includes'] ) {
808
			$this->save_custom_field( $data['price_includes'],'included',$id );
809
		}
810
811
		//Price Excludes
812
		if ( isset( $data['price_excludes'] ) && '' !== $data['price_excludes'] ) {
813
			$this->save_custom_field( $data['price_excludes'],'not_included',$id );
814
		}
815
	}
816
817
	/**
818
	 * Set the duration
819
	 */
820
	public function set_duration( $data, $id ) {
821 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...
822
			$price = $data['days'];
823
			$price = preg_replace( '/[^0-9,.]/', '', $price );
824
			$this->save_custom_field( $price,'duration',$id );
825
		}
826
	}
827
828
	/**
829
	 * Set the group size
830
	 */
831
	public function set_group_size( $data, $id ) {
832
		if ( isset( $data['group_size'] ) && ! empty( $data['group_size'] ) ) {
833
			$group_size = $data['group_size'];
834
			$this->save_custom_field( $group_size,'group_size',$id );
835
		}
836
	}
837
838
	/**
839
	 * Takes the WETU tags and sets the Travel Styles.
840
	 *
841
	 * @param string $id
842
	 * @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...
843
	 * @return void
844
	 */
845
	public function set_travel_styles( $id, $data ) {
846
		if ( isset( $data['tags'] ) ) {
847
			foreach ( $data['tags'] as $tag ) {
848
				$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...
849
			}
850
		}
851
	}
852
853
	/**
854
	 * Connects the Accommodation if its available
855
	 */
856
	public function set_accommodation( $day, $id ) {
857
		$ac_id = false;
858
		$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...
859
860
		if ( isset( $day['content_entity_id'] ) && ! empty( $day['content_entity_id'] ) ) {
861
			if ( false !== $this->current_accommodation && ! empty( $this->current_accommodation ) && array_key_exists( $day['content_entity_id'],$this->current_accommodation ) ) {
862
				$ac_id = $this->current_accommodation[ $day['content_entity_id'] ];
863
			} else {
864
				$ac_id = wp_insert_post(array(
865
					'post_type' => 'accommodation',
866
					'post_status' => 'draft',
867
					'post_title' => $day['content_entity_id'],
868
				));
869
870
				$this->save_custom_field( $day['content_entity_id'],'lsx_wetu_id',$ac_id );
871
			}
872
873
			if ( '' !== $ac_id && false !== $ac_id ) {
874
				$this->save_custom_field( $ac_id,'accommodation_to_tour',$id,false,false );
875
				$this->save_custom_field( $id,'tour_to_accommodation',$ac_id,false,false );
876
				$this->queue_item( $ac_id );
877
			}
878
		}
879
		return $ac_id;
880
	}
881
882
	/**
883
	 * Grab all the current accommodation posts via the lsx_wetu_id field.
884
	 *
885
	 * @param $post_type string
886
	 * @return boolean / array
887
	 */
888
	public function find_current_accommodation( $post_type = 'accommodation' ) {
889
		global $wpdb;
890
		$accommodation = parent::find_current_accommodation( $post_type );
891
		$return = false;
892
893
		if ( ! empty( $accommodation ) ) {
894
			foreach ( $accommodation as $key => $acc ) {
895
				$return[ $acc->meta_value ] = $acc->post_id;
896
			}
897
		}
898
899
		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 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...
900
	}
901
902
	/**
903
	 * Grab all the current accommodation posts via the lsx_wetu_id field.
904
	 * @return boolean / array
905
	 */
906
	public function find_current_destinations() {
907
		return $this->find_current_accommodation( 'destination' );
908
	}
909
910
	/**
911
	 * Connects the destinations post type
912
	 *
913
	 * @param $day array
914
	 * @param $id string
915
	 * @return boolean / string
916
	 */
917
	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...
918
		$dest_id    = false;
919
		$country_id = false;
920
		
921
		$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...
922
923
		if ( isset( $day['destination_content_entity_id'] ) && ! empty( $day['destination_content_entity_id'] ) ) {
924
			if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $day['destination_content_entity_id'], $this->current_destinations ) ) {
925
				$dest_id = $this->current_destinations[ $day['destination_content_entity_id'] ];
926
927
				//TODO Check for attachments here.
928
				$this->destination_images[ $id ][] = array( $dest_id, $day['destination_content_entity_id'] );
929
930
				//Check if there is a country asigned.
931
				$potential_id = wp_get_post_parent_id( $dest_id );
932
				$country_wetu_id = get_post_meta( $potential_id, 'lsx_wetu_id', true );
933
934
				if ( false !== $country_wetu_id ) {
935
					$country_id = $this->set_country( $country_wetu_id, $id );
936
				}
937
			} else {
938
				$destination_json = wp_remote_get( 'https://wetu.com/API/Pins/' . $this->api_key . '/Get?ids=' . $day['destination_content_entity_id'] );
939
940
				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...
941
942
					$destination_data = json_decode( $destination_json['body'], true );
943
944
					if ( ! empty( $destination_data ) && ! isset( $destination_data['error'] ) ) {
945
						$destination_title = $day['destination_content_entity_id'];
946
947
						if ( isset( $destination_data[0]['name'] ) ) {
948
							$destination_title = $destination_data[0]['name'];
949
						}
950
951
						if ( isset( $destination_data[0]['map_object_id'] ) && isset( $destination_data[0]['position']['country_content_entity_id'] )
952
							&& $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id'] ) {
953
954
							$country_id = $this->set_country( $destination_data[0]['position']['country_content_entity_id'], $id );
955
							// Save the destination so we can grab the tour featured image and banner from them.
956
						}
957
958
						$dest_post = array(
959
							'post_type' => 'destination',
960
							'post_status' => 'draft',
961
							'post_title' => $destination_title,
962
						);
963
964
						if ( false !== $country_id ) {
965
							$dest_post['post_parent'] = $country_id;
966
						}
967
						$dest_id = wp_insert_post( $dest_post );
968
969
						// Make sure we register the.
970
						$this->current_destinations[ $day['destination_content_entity_id'] ] = $dest_id;
971
972
						// If there are images attached then use the destination.
973 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...
974
							$this->destination_images[ $id ][] = array( $dest_id, $day['destination_content_entity_id'] );
975
						}
976
977
						$this->save_custom_field( $day['destination_content_entity_id'], 'lsx_wetu_id', $dest_id );
978
					}
979
				}
980
			}
981
982
			if ( '' !== $dest_id && false !== $dest_id ) {
983
				$this->save_custom_field( $dest_id, 'destination_to_tour', $id, false, false );
984
				$this->save_custom_field( $id, 'tour_to_destination', $dest_id, false, false );
985
986
				//Save the item to display in the queue
987
				$this->queue_item( $dest_id );
988
989
				//Save the item to clean up the amount of connections.
990
				$this->cleanup_posts[ $dest_id ] = 'tour_to_destination';
991
992
				//Add this relation info so we can make sure certain items are set as countries.
993
				if ( 0 !== $country_id && false !== $country_id ) {
994
					$this->relation_meta[ $dest_id ] = $country_id;
995
					$this->relation_meta[ $country_id ] = 0;
996
				} else {
997
					$this->relation_meta[ $dest_id ] = 0;
998
				}
999
			}
1000
		}
1001
		return $dest_id;
1002
	}
1003
1004
	/**
1005
	 * Connects the destinations post type
1006
	 *
1007
	 * @param $dest_id string
1008
	 * @param $country_id array
1009
	 * @param $id string
1010
	 *
1011
	 * @return string
1012
	 */
1013
	public function set_country( $country_wetu_id, $id ) {
1014
		$country_id = false;
1015
		$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...
1016
1017
		if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $country_wetu_id, $this->current_destinations ) ) {
1018
			$country_id = $this->current_destinations[ $country_wetu_id ];
1019
			$this->destination_images[ $id ][] = array( $country_id, $country_wetu_id );
1020
		} else {
1021
			$country_json = file_get_contents( 'https://wetu.com/API/Pins/' . $this->api_key . '/Get?ids=' . $country_wetu_id );
1022
1023
			if ( $country_json ) {
1024
				$country_data = json_decode( $country_json, true );
1025
1026
				if ( ! empty( $country_data ) && ! isset( $country_data['error'] ) ) {
1027
1028
					//Format the title of the destination if its available,  otherwise default to the WETU ID.
1029
					$country_title = $country_wetu_id;
1030
1031
					if ( isset( $country_data[0]['name'] ) ) {
1032
						$country_title = $country_data[0]['name'];
1033
					}
1034
1035
					$country_id = wp_insert_post(array(
1036
						'post_type' => 'destination',
1037
						'post_status' => 'draft',
1038
						'post_title' => $country_title,
1039
					));
1040
1041
					//add the country to the current destination stack
1042
					$this->current_destinations[ $country_wetu_id ] = $country_id;
1043
1044
					// Check if there are images and save fore use later.
1045 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...
1046
						$this->destination_images[ $id ][] = array( $country_id,$country_wetu_id );
1047
					}
1048
1049
					//Save the wetu field
1050
					$this->save_custom_field( $country_wetu_id, 'lsx_wetu_id', $country_id );
1051
				}
1052
			}
1053
		}
1054
1055
		if ( '' !== $country_id && false !== $country_id ) {
1056
			$this->save_custom_field( $country_id, 'destination_to_tour', $id, false, false );
1057
			$this->save_custom_field( $id, 'tour_to_destination', $country_id, false, false );
1058
			$this->queue_item( $country_id );
1059
			$this->cleanup_posts[ $country_id ] = 'tour_to_destination';
1060
1061
			return $country_id;
1062
		}
1063
	}
1064
1065
	/**
1066
	 * Connects the destinations post type
1067
	 *
1068
	 * @param $dest_id string
1069
	 * @param $country_id array
1070
	 * @param $id string
1071
	 *
1072
	 * @return string
1073
	 */
1074
	public function attach_destination_images( $importable_content = array() ) {
1075
		if ( false !== $this->destination_images ) {
1076
			$this->shuffle_assoc( $this->destination_images );
1077
1078
			foreach ( $this->destination_images as $tour => $destinations ) {
1079
				//$this->shuffle_assoc( $destinations );
1080
1081
				$image_set = false;
1082
				$forced = false;
1083
1084
				foreach ( $destinations as $destination ) {
1085
					if ( false === $image_set && false === $forced ) {
1086
						$url = 'https://wetu.com/API/Pins/' . $this->api_key;
1087
						$url_qs = '';
1088
1089
						$jdata = file_get_contents( $url . '/Get?' . $url_qs . '&ids=' . $destination[1] );
1090
1091
						if ( $jdata ) {
1092
							$adata = json_decode( $jdata, true );
1093
1094
							if ( ! empty( $adata ) && ! empty( $adata[0]['content']['images'] ) ) {
1095
								$this->find_attachments( $destination[0] );
1096
1097
								//Set the featured image
1098
								if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
1099
									$image_set = $this->set_featured_image( $adata, $tour );
1100 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...
1101
										$image_set = $this->set_banner_image( $adata, $tour );
1102
										$forced = true;
1103
									}
1104
									continue;
1105
								}
1106 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...
1107
									$image_set = $this->set_banner_image( $adata, $tour );
1108
								}
1109
							}
1110
						}
1111
					} else {
1112
						continue;
1113
					}
1114
				}
1115
			}
1116
		}
1117
	}
1118
1119
	/**
1120
	 * Creates the main gallery data
1121
	 */
1122
	public function set_featured_image( $data, $id ) {
1123
		$image_set = false;
1124
		$counter = 0;
1125
1126
		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
1127
			foreach ( $data[0]['content']['images'] as $v ) {
1128
				/*print_r('<pre>');
1129
				print_r( $v );
1130
				print_r('</pre>');*/
1131
1132
				if ( true === $image_set ) {
1133
					$counter++;
1134
					continue;
1135
				}
1136
1137
				if ( ! $this->check_if_image_is_used( $v ) ) {
1138
					$temp_featured_image = $this->attach_image( $v , $id );
1139
1140
					if ( false !== $temp_featured_image ) {
1141
						$this->featured_image = $temp_featured_image;
1142
						delete_post_meta( $id, '_thumbnail_id' );
1143
						add_post_meta( $id, '_thumbnail_id', $this->featured_image, true );
1144
						$image_set = true;
1145
					}
1146
				}
1147
1148
				$counter++;
1149
			}
1150
		}
1151
		return $image_set;
1152
	}
1153
1154
	/**
1155
	 * Sets a banner image
1156
	 */
1157
	public function set_banner_image( $data, $id, $content = array( 'none' ) ) {
1158
		$image_set = false;
1159
		$counter = 0;
1160
1161
		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
1162
1163
			foreach ( $data[0]['content']['images'] as $v ) {
1164
				/*print_r('<pre>');
1165
				print_r( $v );
1166
				print_r('</pre>');*/
1167
1168
				if ( true === $image_set || 0 === $counter ) {
1169
					$counter++;
1170
					continue;
1171
				}
1172
1173
				if ( ! $this->check_if_image_is_used( $v ) ) {
1174
					$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...
1175
						'width' => '1920',
1176
						'height' => '600',
1177
						'cropping' => 'c',
1178
					) );
1179
1180 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...
1181
						$this->banner_image = $temp_banner;
1182
1183
						delete_post_meta( $id,'image_group' );
1184
1185
						$new_banner = array(
1186
							'banner_image' => array(
1187
								'cmb-field-0' => $this->banner_image,
1188
							),
1189
						);
1190
						add_post_meta( $id,'image_group',$new_banner,true );
1191
						$image_set = true;
1192
					}
1193
				}
1194
				$counter++;
1195
			}
1196
		}
1197
1198
		return $image_set;
1199
	}
1200
1201
	/**
1202
	 * Grabs all of the current used featured images on the site.
1203
	 */
1204
	public function check_if_image_is_used( $v ) {
1205
		global $wpdb;
1206
1207
		$temp_fragment = explode( '/',$v['url_fragment'] );
1208
		$url_filename = $temp_fragment[ count( $temp_fragment ) -1 ];
1209
		$url_filename = str_replace( array( '.jpg', '.png', '.jpeg' ),'',$url_filename );
1210
		$url_filename = trim( $url_filename );
1211
		$url_filename = str_replace( ' ','_',$url_filename );
1212
1213
		if ( in_array( $url_filename,$this->found_attachments ) ) {
1214
			//check to see if there is a featured image set with this ID.
1215
			$found_id = array_search( $url_filename,$this->found_attachments );
1216
1217
			$querystring = "
1218
				SELECT      post_id
1219
				FROM        {$wpdb->postmeta}
1220
				WHERE       meta_value = '{$found_id}'
1221
				AND 		meta_key = '_thumbnail_id'
1222
			";
1223
			// @codingStandardsIgnoreLine
1224
			$results = $wpdb->get_results( $querystring );
1225
1226
			if ( ! empty( $results ) ) {
1227
				return true;
1228
			} else {
1229
				return false;
1230
			}
1231
		} else {
1232
			$querystring = "
1233
				SELECT      ID
1234
				FROM        {$wpdb->posts}
1235
				WHERE       post_name = '{$url_filename}'
1236
			";
1237
			// @codingStandardsIgnoreLine
1238
			$results = $wpdb->get_results( $querystring );
1239
			if ( ! empty( $results ) ) {
1240
				$querystring = "
1241
					SELECT      post_id
1242
					FROM        {$wpdb->postmeta}
1243
					WHERE       meta_value = '{$results[0]->ID}'
1244
					AND 		meta_key = '_thumbnail_id'
1245
				";
1246
				// @codingStandardsIgnoreLine
1247
				$results = $wpdb->get_results( $querystring );
1248
				if ( ! empty( $results ) ) {
1249
					return true;
1250
				} else {
1251
					return false;
1252
				}
1253
			} else {
1254
				return false;
1255
			}
1256
		}
1257
	}
1258
1259
	/**
1260
	 * Que an item to be saved.
1261
	 *
1262
	 * @param   $id     int
1263
	 */
1264
	public function queue_item( $id ) {
1265
		if ( is_array( $this->import_queue ) && ! in_array( $id,$this->import_queue ) ) {
1266
			$this->import_queue[] = $id;
1267
		} else {
1268
			$this->import_queue[] = $id;
1269
		}
1270
	}
1271
1272
	/**
1273
	 * Saves the queue to the option.
1274
	 */
1275
	public function save_queue() {
1276
		if ( ! empty( $this->import_queue ) ) {
1277
			if ( ! empty( $this->queued_imports ) ) {
1278
				$saved_imports = array_merge( $this->queued_imports,$this->import_queue );
1279
			} else {
1280
				$saved_imports = $this->import_queue;
1281
			}
1282
1283
			delete_option( 'wetu_importer_que' );
1284
1285
			if ( ! empty( $saved_imports ) ) {
1286
				$saved_imports = array_unique( $saved_imports );
1287
				update_option( 'wetu_importer_que',$saved_imports );
1288
			}
1289
		}
1290
	}
1291
1292
	/**
1293
	 * The header of the item list
1294
	 */
1295 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...
1296
		?>
1297
		<thead>
1298
		<tr>
1299
			<th style="" class="manage-column column-cb check-column" id="cb" scope="col">
1300
				<label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e( 'Select All', 'wetu-importer' ); ?></label>
1301
				<input type="checkbox" id="cb-select-all-1">
1302
			</th>
1303
			<th style="" class="manage-column column-title " id="title" style="width:50%;" scope="col"><?php esc_attr_e( 'Title', 'wetu-importer' ); ?></th>
1304
			<th style="" class="manage-column column-date" id="ref" style="width:10%;" scope="col"><?php esc_attr_e( 'Ref', 'wetu-importer' ); ?></th>
1305
			<th style="" class="manage-column column-date" id="date" scope="col"><?php esc_attr_e( 'Date', 'wetu-importer' ); ?></th>
1306
			<th style="" class="manage-column column-ssid" id="ssid" scope="col"><?php esc_attr_e( 'WETU ID', 'wetu-importer' ); ?></th>
1307
		</tr>
1308
		</thead>
1309
		<?php
1310
	}
1311
1312
	/**
1313
	 * The footer of the item list
1314
	 */
1315 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...
1316
		?>
1317
		<tfoot>
1318
		<tr>
1319
			<th style="" class="manage-column column-cb check-column" id="cb" scope="col">
1320
				<label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e( 'Select All', 'wetu-importer' ); ?></label>
1321
				<input type="checkbox" id="cb-select-all-1">
1322
			</th>
1323
			<th style="" class="manage-column column-title" scope="col"><?php esc_attr_e( 'Title', 'wetu-importer' ); ?></th>
1324
			<th style="" class="manage-column column-date" id="ref" style="width:10%;" scope="col"><?php esc_attr_e( 'Ref', 'wetu-importer' ); ?></th>			
1325
			<th style="" class="manage-column column-date" scope="col"><?php esc_attr_e( 'Date', 'wetu-importer' ); ?></th>
1326
			<th style="" class="manage-column column-ssid" scope="col"><?php esc_attr_e( 'WETU ID', 'wetu-importer' ); ?></th>
1327
		</tr>
1328
		</tfoot>
1329
		<?php
1330
	}	
1331
1332
}
1333