Completed
Push — master ( 99c772...e11db9 )
by Warwick
15:03
created

WETU_Importer_Accommodation::__construct()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 20
Code Lines 13

Duplication

Lines 20
Ratio 100 %

Importance

Changes 0
Metric Value
dl 20
loc 20
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 13
nc 4
nop 0
1
<?php
2
/**
3
 * @package   WETU_Importer_Accommodation
4
 * @author    LightSpeed
5
 * @license   GPL-2.0+
6
 * @link      
7
 * @copyright 2016 LightSpeed
8
 **/
9
10
class WETU_Importer_Accommodation extends WETU_Importer_Admin {
11
12
	/**
13
	 * The url to list items from WETU
14
	 *
15
	 * @since 0.0.1
16
	 *
17
	 * @var      string
18
	 */
19
	public $tab_slug = 'accommodation';
20
21
	/**
22
	 * The url to list items from WETU
23
	 *
24
	 * @since 0.0.1
25
	 *
26
	 * @var      string
27
	 */
28
	public $url = false;
29
30
	/**
31
	 * The query string url to list items from WETU
32
	 *
33
	 * @since 0.0.1
34
	 *
35
	 * @var      string
36
	 */
37
	public $url_qs = false;
38
39
	/**
40
	 * Options
41
	 *
42
	 * @since 0.0.1
43
	 *
44
	 * @var      string
45
	 */
46
	public $options = false;
47
48
	/**
49
	 * The fields you wish to import
50
	 *
51
	 * @since 0.0.1
52
	 *
53
	 * @var      string
54
	 */
55
	public $accommodation_options = false;
56
57
	/**
58
	 * Initialize the plugin by setting localization, filters, and administration functions.
59
	 *
60
	 * @since 1.0.0
61
	 *
62
	 * @access private
63
	 */
64 View Code Duplication
	public function __construct() {
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...
65
		$this->set_variables();
66
67
		add_action( 'lsx_tour_importer_admin_tab_'.$this->tab_slug, array($this,'display_page') );
68
		add_action('wp_ajax_lsx_tour_importer',array($this,'process_ajax_search'));	
69
		add_action('wp_ajax_nopriv_lsx_tour_importer',array($this,'process_ajax_search'));		
70
71
		add_action('wp_ajax_lsx_import_items',array($this,'process_ajax_import'));	
72
		add_action('wp_ajax_nopriv_lsx_import_items',array($this,'process_ajax_import'));
73
74
		$temp_options = get_option('_lsx-to_settings',false);
75
		if(false !== $temp_options && isset($temp_options[$this->plugin_slug]) && !empty($temp_options[$this->plugin_slug])){
76
			$this->options = $temp_options[$this->plugin_slug];
77
		}
78
79
		$accommodation_options = get_option('wetu_importer_accommodation_settings',false);
80
		if(false !== $accommodation_options){
81
			$this->accommodation_options = $accommodation_options;
82
		}
83
	}
84
85
	/**
86
	 * Sets the variables used throughout the plugin.
87
	 */
88
	public function set_variables()
89
	{
90
		parent::set_variables();
91
92
		// ** This request only works with API KEY **
93
		//if ( false !== $this->api_username && false !== $this->api_password ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
94
		//	$this->url    = 'https://wetu.com/API/Pins/';
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
95
		//	$this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password;
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
96
		//} elseif ( false !== $this->api_key ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
97
			$this->url    = 'https://wetu.com/API/Pins/' . $this->api_key;
98
			$this->url_qs = '';
99
		//}
100
	}
101
102
	/**
103
	 * search_form
104
	 */
105
	public function get_scaling_url($args=array()) {
106
107
		$defaults = array(
108
			'width' => '640',
109
			'height' => '480',
110
			'cropping' => 'c'
111
		);
112
		if(false !== $this->options){
113
			if(isset($this->options['width']) && '' !== $this->options['width']){
114
				$defaults['width'] = $this->options['width'];
115
			}
116
117 View Code Duplication
			if(isset($this->options['height']) && '' !== $this->options['height']){
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...
118
				$defaults['height'] = $this->options['height'];
119
			}
120
121 View Code Duplication
			if(isset($this->options['cropping']) && '' !== $this->options['cropping']){
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...
122
				$defaults['cropping'] = $this->options['cropping'];
123
			}	
124
		}	
125
		$args = wp_parse_args($args,$defaults);
126
127
		$cropping = $args['cropping'];
128
		$width = $args['width'];
129
		$height = $args['height'];
130
131
		return 'https://wetu.com/ImageHandler/'.$cropping.$width.'x'.$height.'/';
132
133
	}
134
135
	/**
136
	 * Display the importer administration screen
137
	 */
138
	public function display_page() {
139
        ?>
140
        <div class="wrap">
141
            <?php screen_icon(); ?>
142
143
            <?php $this->update_options_form(); ?>
144
145
            <?php $this->search_form(); ?>
146
147
			<form method="get" action="" id="posts-filter">
148
				<input type="hidden" name="post_type" class="post_type" value="<?php echo $this->tab_slug; ?>" />
149
				
150
				<p><input class="button button-primary add" type="button" value="<?php _e('Add to List','wetu-importer'); ?>" />
151
					<input class="button button-primary clear" type="button" value="<?php _e('Clear','wetu-importer'); ?>" />
152
				</p>				
153
154
				<table class="wp-list-table widefat fixed posts">
155
					<?php $this->table_header(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method WETU_Importer_Accommodation::table_header() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
156
				
157
					<tbody id="the-list">
158
						<tr class="post-0 type-tour status-none" id="post-0">
159
							<th class="check-column" scope="row">
160
								<label for="cb-select-0" class="screen-reader-text"><?php _e('Enter a title to search for and press enter','wetu-importer'); ?></label>
161
							</th>
162
							<td class="post-title page-title column-title">
163
								<strong>
164
									<?php _e('Enter a title to search for','wetu-importer'); ?>
165
								</strong>
166
							</td>
167
							<td class="date column-date">							
168
							</td>
169
							<td class="ssid column-ssid">
170
							</td>
171
						</tr>									
172
					</tbody>
173
174
					<?php $this->table_footer(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method WETU_Importer_Accommodation::table_footer() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
175
176
				</table>
177
178
				<p><input class="button button-primary add" type="button" value="<?php _e('Add to List','wetu-importer'); ?>" />
179
					<input class="button button-primary clear" type="button" value="<?php _e('Clear','wetu-importer'); ?>" />
180
				</p>
181
			</form> 
182
183
			<div style="display:none;" class="import-list-wrapper">
184
				<br />        
185
				<form method="get" action="" id="import-list">
186
187
					<div class="row">
188
						<div style="width:30%;display:block;float:left;">
189
							<h3><?php _e('What content to Sync from WETU'); ?></h3>
190
							<ul>
191
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'description'); ?>" type="checkbox" name="content[]" value="description" /> <?php _e('Description','wetu-importer'); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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" checked="<?php $this->checked($this->accommodation_options,'excerpt'); ?>" type="checkbox" name="content[]" value="excerpt" /> <?php _e('Excerpt','wetu-importer'); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'gallery'); ?>" type="checkbox" name="content[]" value="gallery" /> <?php _e('Main Gallery','wetu-importer'); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
194
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'category'); ?>" type="checkbox" name="content[]" value="category" /> <?php _e('Category','wetu-importer'); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
195 View Code Duplication
		                        <?php if(class_exists('TO_Maps')){ ?>
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...
196
								    <li><input class="content" checked="<?php $this->checked($this->accommodation_options,'location'); ?>" type="checkbox" name="content[]" value="location" /> <?php _e('Location','wetu-importer'); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
197
		                        <?php } ?>
198
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'destination'); ?>" type="checkbox" name="content[]" value="destination" /> <?php _e('Connect Destinations','wetu-importer'); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
199
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'checkin'); ?>" type="checkbox" name="content[]" value="checkin" /> <?php _e('Check In / Check Out','wetu-importer'); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
200
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'facilities'); ?>" type="checkbox" name="content[]" value="facilities" /> <?php _e('Facilities','wetu-importer'); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
201
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'friendly'); ?>" type="checkbox" name="content[]" value="friendly" /> <?php _e('Friendly','wetu-importer'); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
202
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'rating'); ?>" type="checkbox" name="content[]" value="rating" /> <?php _e('Rating','wetu-importer'); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
203
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'rooms'); ?>" type="checkbox" name="content[]" value="rooms" /> <?php _e('Rooms','wetu-importer'); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
204
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'special_interests'); ?>" type="checkbox" name="content[]" value="special_interests" /> <?php _e('Special Interests','wetu-importer'); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
205
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'spoken_languages'); ?>" type="checkbox" name="content[]" value="spoken_languages" /> <?php _e('Spoken Languages','wetu-importer'); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
206
207 View Code Duplication
		                        <?php if(class_exists('TO_Videos')){ ?>
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...
208
								    <li><input class="content" checked="<?php $this->checked($this->accommodation_options,'videos'); ?>" type="checkbox" name="content[]" value="videos" /> <?php _e('Videos','wetu-importer'); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
209
		                        <?php } ?>
210
							</ul>
211
							<h4><?php _e('Additional Content'); ?></h4>
212
							<ul>
213
								<li><input class="content" checked="<?php $this->checked($this->accommodation_options,'featured_image'); ?>" type="checkbox" name="content[]" value="featured_image" /> <?php _e('Set Featured Image','wetu-importer'); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
214
		                        <?php if(class_exists('LSX_Banners')){ ?>
215
								    <li><input class="content" checked="<?php $this->checked($this->accommodation_options,'banner_image'); ?>" type="checkbox" name="content[]" value="banner_image" /> <?php _e('Set Banner Image','wetu-importer'); ?></li>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
216
		                        <?php } ?>
217
							</ul>
218
						</div>
219
						<div style="width:30%;display:block;float:left;">
220
							<h3><?php _e('Assign a Team Member'); ?></h3> 
221
							<?php $this->team_member_checkboxes($this->accommodation_options); ?>
0 ignored issues
show
Documentation introduced by
$this->accommodation_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...
222
						</div>
223
224
						<div style="width:30%;display:block;float:left;">
225
							<h3><?php _e('Assign a Safari Brand'); ?></h3> 
226
							<?php echo $this->taxonomy_checkboxes('accommodation-brand',$this->accommodation_options); ?>
0 ignored issues
show
Documentation introduced by
'accommodation-brand' 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
$this->accommodation_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...
227
						</div>	
228
229
						<br clear="both" />			
230
					</div>
231
232
233
					<h3><?php _e('Your List'); ?></h3>
234
                    <p><input class="button button-primary" type="submit" value="<?php _e('Sync','wetu-importer'); ?>" /></p>
235
					<table class="wp-list-table widefat fixed posts">
236
						<?php $this->table_header(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method WETU_Importer_Accommodation::table_header() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
237
238
						<tbody>
239
240
						</tbody>
241
242
						<?php $this->table_footer(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method WETU_Importer_Accommodation::table_footer() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
243
244
					</table>
245
246
					<p><input class="button button-primary" type="submit" value="<?php _e('Sync','wetu-importer'); ?>" /></p>
247
				</form>
248
			</div>
249
250
			<div style="display:none;" class="completed-list-wrapper">
251
				<h3><?php _e('Completed'); ?> - <small><?php _e('Import your','wetu-importer'); ?> <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=destination"><?php _e('destinations'); ?></a> <?php _e('next','wetu-importer'); ?></small></h3>
252
				<ul>
253
				</ul>
254
			</div>
255
        </div>
256
        <?php
257
	}
258
259
	/**
260
	 * search_form
261
	 */
262 View Code Duplication
	public function search_form() {
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...
263
	?>
264
        <form class="ajax-form" id="<?php echo $this->plugin_slug; ?>-search-form" method="get" action="tools.php" data-type="<?php echo $this->tab_slug; ?>">
265
        	<input type="hidden" name="page" value="<?php echo $this->tab_slug; ?>" />
266
267
        	<h3><span class="dashicons dashicons-search"></span> <?php _e('Search','wetu-importer'); ?></h3>
268
        	<div class="normal-search">
269
        		<input pattern=".{3,}" placeholder="3 characters minimum" class="keyword" name="keyword" value=""> <input class="button button-primary submit" type="submit" value="<?php _e('Search','wetu-importer'); ?>" />
270
        	</div>
271
        	<div class="advanced-search hidden" style="display:none;">
272
        		<p><?php _e('Enter several keywords, each on a new line.','wetu-importer'); ?></p>
273
        		<textarea rows="10" cols="40" name="bulk-keywords"></textarea>
274
        		<input class="button button-primary submit" type="submit" value="<?php _e('Search','wetu-importer'); ?>" />
275
        	</div>    
276
277
        	<p>
278
                <a class="advanced-search-toggle" href="#"><?php _e('Bulk Search','wetu-importer'); ?></a> |
279
                <a class="published search-toggle" href="#publish"><?php esc_attr_e('Published','wetu-importer'); ?></a> |
280
                <a class="pending search-toggle"  href="#pending"><?php esc_attr_e('Pending','wetu-importer'); ?></a> |
281
                <a class="draft search-toggle"  href="#draft"><?php esc_attr_e('Draft','wetu-importer'); ?></a> |
282
                <a class="import search-toggle"  href="#import"><?php esc_attr_e('WETU','wetu-importer'); ?></a>
283
            </p>
284
285
            <div class="ajax-loader" style="display:none;width:100%;text-align:center;">
286
            	<img style="width:64px;" src="<?php echo WETU_IMPORTER_URL.'assets/images/ajaxloader.gif';?>" />
287
            </div>
288
289
            <div class="ajax-loader-small" style="display:none;width:100%;text-align:center;">
290
            	<img style="width:32px;" src="<?php echo WETU_IMPORTER_URL.'assets/images/ajaxloader.gif';?>" />
291
            </div>            
292
        </form>	
293
	<?php 
294
	}	
295
296
	/**
297
	 * search_form
298
	 */
299
	public function update_options_form() {
300
		echo '<div style="display:none;" class="wetu-status"><h3>'.__('Wetu Status','wetu-importer').'</h3>';
301
		$accommodation = get_transient('lsx_ti_accommodation');
302
		if('' === $accommodation || false === $accommodation || isset($_GET['refresh_accommodation'])){
303
			$this->update_options();
304
		}
305
		echo '</div>';
306
	}
307
308
309
	/**
310
	 * Save the list of Accommodation into an option
311
	 */
312
	public function update_options() {
313
		$data = file_get_contents( $this->url . '/List?' . $this->url_qs );
314
		$accommodation = json_decode($data, true);
315
316 View Code Duplication
		if(isset($accommodation['error'])){
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...
317
		    return $accommodation['error'];
318
        }elseif (isset($accommodation) && !empty($accommodation)) {
319
			set_transient('lsx_ti_accommodation',$accommodation,60*60*2);
320
			return true;
321
		}
322
	}
323
324
	/**
325
	 * Grab all the current accommodation posts via the lsx_wetu_id field.
326
	 */
327 View Code Duplication
	public function find_current_accommodation($post_type='accommodation') {
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...
328
		global $wpdb;
329
		$return = array();
330
331
		$current_accommodation = $wpdb->get_results("
332
					SELECT key1.post_id,key1.meta_value
333
					FROM {$wpdb->postmeta} key1
334
335
					INNER JOIN  {$wpdb->posts} key2 
336
    				ON key1.post_id = key2.ID
337
					
338
					WHERE key1.meta_key = 'lsx_wetu_id'
339
					AND key2.post_type = '{$post_type}'
340
341
					LIMIT 0,500
342
		");
343
		if(null !== $current_accommodation && !empty($current_accommodation)){
344
			foreach($current_accommodation as $accom){
345
				$return[$accom->meta_value] = $accom;
346
			}
347
		}
348
		return $return;
349
	}	
350
351
	/**
352
	 * Run through the accommodation grabbed from the DB.
353
	 */
354
	public function process_ajax_search() {
355
		$return = false;
356
		if(isset($_POST['action']) && $_POST['action'] === 'lsx_tour_importer' && isset($_POST['type']) && $_POST['type'] === 'accommodation'){
357
			$accommodation = get_transient('lsx_ti_accommodation');
358
359
			if ( false !== $accommodation ) {
360
				$searched_items = false;
361
362 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...
363
					$keyphrases = $_POST['keyword'];
364
				}else{
365
					$keyphrases = array(0);
366
                }
367
368
				if(!is_array($keyphrases)){
369
					$keyphrases = array($keyphrases);
370
				}
371
				foreach($keyphrases as &$keyword){
372
					$keyword = ltrim(rtrim($keyword));
373
				}
374
375
376
				$post_status = false;
377
				if(in_array('publish',$keyphrases)){
378
					$post_status = 'publish';
379
				}
380
				if(in_array('pending',$keyphrases)){
381
					$post_status = 'pending';
382
				}
383
				if(in_array('draft',$keyphrases)){
384
					$post_status = 'draft';
385
				}
386
				if(in_array('import',$keyphrases)){
387
					$post_status = 'import';
388
				}
389
390
				if (!empty($accommodation)) {
391
392
					$current_accommodation = $this->find_current_accommodation();
393
394
					foreach($accommodation as $row_key => $row){
395
396
						//If this is a current tour, add its ID to the row.
397
						$row['post_id'] = 0;
398
						if(false !== $current_accommodation && array_key_exists($row['id'], $current_accommodation)){
399
							$row['post_id'] = $current_accommodation[$row['id']]->post_id;
400
						}
401
402
						//If we are searching for
403 View Code Duplication
						if(false !== $post_status){
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...
404
405
							if('import' === $post_status){
406
407
								if(0 !== $row['post_id']){
408
									continue;
409
								}else{
410
									$searched_items[sanitize_title($row['name']).'-'.$row['id']] = $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...
411
								}
412
413
414
							}else{
415
416
								if(0 === $row['post_id']){
417
									continue;
418
								}else{
419
									$current_status = get_post_status($row['post_id']);
420
									if($current_status !== $post_status){
421
										continue;
422
									}
423
424
								}
425
								$searched_items[sanitize_title($row['name']).'-'.$row['id']] = $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...
426
							}
427
428
						}else{
429
							//Search through each keyword.
430
							foreach($keyphrases as $keyphrase){
431
432
								//Make sure the keyphrase is turned into an array
433
								$keywords = explode(" ",$keyphrase);
434
								if(!is_array($keywords)){
435
									$keywords = array($keywords);
436
								}
437
438
								if($this->multineedle_stripos(ltrim(rtrim($row['name'])), $keywords) !== false){
439
									$searched_items[sanitize_title($row['name']).'-'.$row['id']] = $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...
440
								}
441
							}
442
						}
443
					}		
444
				}
445
446
447
				if(false !== $searched_items){
448
					ksort($searched_items);
449
					$return = implode($searched_items);
450
				}
451
			}
452
			print_r($return);
453
			die();
454
		}
455
	}
456
457
	/**
458
	 * Does a multine search
459
	 */	
460
	public function multineedle_stripos($haystack, $needles, $offset=0) {
461
		$found = false;
462
		$needle_count = count($needles);
463
	    foreach($needles as $needle) {
464
	    	if(false !== stripos($haystack, $needle, $offset)){
465
	        	$found[] = true;
466
	    	}
467
	    }
468
	    if(false !== $found && $needle_count === count($found)){ 
469
	    	return true;
470
		}else{
471
			return false;
472
		}
473
	}
474
475
	/**
476
	 * Formats the row for output on the screen.
477
	 */	
478 View Code Duplication
	public function format_row($row = false){
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...
479
		if(false !== $row){
480
481
			$status = 'import';
482
			if(0 !== $row['post_id']){
483
				$status = '<a href="'.admin_url('/post.php?post='.$row['post_id'].'&action=edit').'" target="_blank">'.get_post_status($row['post_id']).'</a>';
484
			}
485
486
			$row_html = '
487
			<tr class="post-'.$row['post_id'].' type-tour" id="post-'.$row['post_id'].'">
488
				<th class="check-column" scope="row">
489
					<label for="cb-select-'.$row['id'].'" class="screen-reader-text">'.$row['name'].'</label>
490
					<input type="checkbox" data-identifier="'.$row['id'].'" value="'.$row['post_id'].'" name="post[]" id="cb-select-'.$row['id'].'">
491
				</th>
492
				<td class="post-title page-title column-title">
493
					<strong>'.$row['name'].'</strong> - '.$status.'
494
				</td>
495
				<td class="date column-date">
496
					<abbr title="'.date('Y/m/d',strtotime($row['last_modified'])).'">'.date('Y/m/d',strtotime($row['last_modified'])).'</abbr><br>Last Modified
497
				</td>
498
				<td class="ssid column-ssid">
499
					'.$row['id'].'
500
				</td>
501
			</tr>';		
502
			return $row_html;
503
		}
504
	}
505
506
	/**
507
	 * Connect to wetu
508
	 */
509
	public function process_ajax_import() {
510
		$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...
511
		if(isset($_POST['action']) && $_POST['action'] === 'lsx_import_items' && isset($_POST['type']) && $_POST['type'] === 'accommodation' && isset($_POST['wetu_id'])){
512
			
513
			$wetu_id = $_POST['wetu_id'];
514
			if(isset($_POST['post_id'])){
515
				$post_id = $_POST['post_id'];	
516
			}else{
517
				$post_id = 0;
518
			}
519
520
			if(isset($_POST['team_members'])){
521
				$team_members = $_POST['team_members'];	
522
			}else{
523
				$team_members = false;
524
			}
525
526
			if(isset($_POST['safari_brands'])){
527
				$safari_brands = $_POST['safari_brands'];	
528
			}else{
529
				$safari_brands = false;
530
			}			
531
532
			if(isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])){
533
				$content = $_POST['content'];
534
				add_option('wetu_importer_accommodation_settings',$content);
535
			}else{
536
				delete_option('wetu_importer_accommodation_settings');
537
				$content = false;
538
			}
539
540
            $jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
541 View Code Duplication
            if($jdata)
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...
542
            {
543
                $adata=json_decode($jdata,true);
544
                if(!empty($adata))
545
                {
546
                	$return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands);
547
                	$this->format_completed_row($return);
548
                }
549
            }
550
551
			die();
552
		}
553
554
	}	
555
	/**
556
	 * Formats the row for the completed list.
557
	 */
558
	public function format_completed_row($response){
559
		echo '<li class="post-'.$response.'"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="'.get_permalink($response).'">'.get_the_title($response).'</a></li>';
560
	}
561
	/**
562
	 * Connect to wetu
563
	 */
564
	public function import_row($data,$wetu_id,$id=0,$team_members=false,$importable_content=false,$safari_brands=false) {
565
566
        if(trim($data[0]['type'])=='Accommodation')
567
        {
568
	        $post_name = $data_post_content = $data_post_excerpt = '';
569
	        $post = array(
570
	          'post_type'		=> 'accommodation',
571
	        );
572
573
	        $content_used_general_description = false;
574
575
	        //Set the post_content
576 View Code Duplication
	        if(false !== $importable_content && in_array('description',$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...
577
		        if(isset($data[0]['content']['extended_description']))
578
		        {
579
		            $data_post_content = $data[0]['content']['extended_description'];
580
		        }elseif(isset($data[0]['content']['general_description'])){
581
		            $data_post_content = $data[0]['content']['general_description'];
582
		            $content_used_general_description = true;
583
		        }elseif(isset($data[0]['content']['teaser_description'])){
584
		        	$data_post_content = $data[0]['content']['teaser_description'];
585
		        }
586
	        	$post['post_content'] = wp_strip_all_tags($data_post_content);
587
	        }
588
589
	        //set the post_excerpt
590
	        if(false !== $importable_content && in_array('excerpt',$importable_content)){
591
		        if(isset($data[0]['content']['teaser_description'])){
592
		        	$data_post_excerpt = $data[0]['content']['teaser_description'];
593
		        }elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){
594
		            $data_post_excerpt = $data[0]['content']['general_description'];
595
		        }	   
596
		        $post['post_excerpt'] = $data_post_excerpt;     	
597
	        }
598
599 View Code Duplication
	        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...
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...
600
	        	$post['ID'] = $id;
601
				if(isset($data[0]['name'])){
602
					$post['post_title'] = $data[0]['name'];
603
	        		$post['post_status'] = 'publish';
604
					$post['post_name'] = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0);
605
				}
606
	        	$id = wp_update_post($post);
607
	        	$prev_date = get_post_meta($id,'lsx_wetu_modified_date',true);
608
	        	update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date);
609
	        }else{
610
611
		        //Set the name
612
		        if(isset($data[0]['name'])){
613
		            $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0);
614
		        }
615
	        	$post['post_name'] = $post_name;
616
	        	$post['post_title'] = $data[0]['name'];
617
	        	$post['post_status'] = 'publish';
618
	        	$id = wp_insert_post($post);
619
620
	        	//Save the WETU ID and the Last date it was modified.
621
	        	if(false !== $id){
622
	        		add_post_meta($id,'lsx_wetu_id',$wetu_id);
623
	        		add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']));
624
	        	}
625
	        }
626
	        //Setup some default for use in the import
627 View Code Duplication
	        if(false !== $importable_content && (in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){
0 ignored issues
show
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...
628
				$this->find_attachments($id);
629
			}
630
631
	        //Set the team member if it is there
632 View Code Duplication
	        if(post_type_exists('team') && false !== $team_members && '' !== $team_members){
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...
633
	        	$this->set_team_member($id,$team_members);
634
	    	}
635
636
	        //Set the safari brand
637
	        if(false !== $safari_brands && '' !== $safari_brands){
638
	        	$this->set_safari_brands($id,$safari_brands);
639
640
	    	}	    	
641
642
	        if(class_exists('LSX_TO_Maps')){
643
	        	$this->set_map_data($data,$id);
644
	        	$this->set_location_taxonomy($data,$id);
645
	        }
646
647
	        if(post_type_exists('destination') && false !== $importable_content && in_array('destination',$importable_content)){
648
	        	$this->connect_destinations($data,$id);
649
	        }
650
651
	        if(false !== $importable_content && in_array('category',$importable_content)){
652
	        	$this->set_taxonomy_style($data,$id);
653
	        }
654
655
	        //Set the Room Data
656
	        if(false !== $importable_content && in_array('rooms',$importable_content)){
657
	        	$this->set_room_data($data,$id);
658
	    	}
659
660
	    	//Set the rating
661
	    	if(false !== $importable_content && in_array('rating',$importable_content)){
662
	       		$this->set_rating($data,$id);
663
	    	}
664
665
	    	//Set the checkin checkout data
666
	    	if(false !== $importable_content && in_array('checkin',$importable_content)){
667
	        	$this->set_checkin_checkout($data,$id);
668
	        }
669
670
	    	//Set the Spoken Languages
671
	    	if(false !== $importable_content && in_array('spoken_languages',$importable_content)){
672
	       		$this->set_spoken_languages($data,$id);
673
	    	}
674
675
	    	//Set the friendly options
676
	    	if(false !== $importable_content && in_array('friendly',$importable_content)){
677
	       		$this->set_friendly($data,$id);
678
	    	}
679
680
	    	//Set the special_interests
681
	    	if(false !== $importable_content && in_array('special_interests',$importable_content)){
682
	       		$this->set_special_interests($data,$id);
683
	    	}	    		    		        
684
685
	        //Import the videos
686
	        if(false !== $importable_content && in_array('videos',$importable_content)){
687
	        	$this->set_video_data($data,$id);
688
	        }
689
690
	        //Import the facilities
691
	        if(false !== $importable_content && in_array('facilities',$importable_content)){
692
	        	$this->set_facilities($data,$id);
693
	        }	        
694
695
	        //Set the featured image
696
	        if(false !== $importable_content && in_array('featured_image',$importable_content)){
697
	        	$this->set_featured_image($data,$id);
698
	        }
699
	        if(false !== $importable_content && in_array('banner_image',$importable_content)){
700
	        	$this->set_banner_image($data,$id);
701
	        }	        
702
	        //Import the main gallery
703
	        if(false !== $importable_content && in_array('gallery',$importable_content)){	    	
704
	    		$this->create_main_gallery($data,$id);
705
	        }	        	        	        
706
        }
707
        return $id;
708
	}
709
710
	/**
711
	 * Set the team memberon each item.
712
	 */
713 View Code Duplication
	public function set_team_member($id,$team_members) {
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...
714
715
		delete_post_meta($id, 'team_to_'.$this->tab_slug);
716
		foreach($team_members as $team){
717
        	add_post_meta($id,'team_to_'.$this->tab_slug,$team);			
718
		}
719
	}
720
721
	/**
722
	 * Set the safari brand
723
	 */
724
	public function set_safari_brands($id,$safari_brands) {
725
		foreach($safari_brands as $safari_brand){
726
        	wp_set_object_terms( $id, intval($safari_brand), 'accommodation-brand',true);			
727
		}
728
	}	
729
	
730
	/**
731
	 * Saves the longitude and lattitude, as well as sets the map marker.
732
	 */
733 View Code Duplication
	public function set_map_data($data,$id) {
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...
734
		$longitude = $latitude = $address = false;
735
		$zoom = '15';	
736
737
		if(isset($data[0]['position'])){
738
739
			if(isset($data[0]['position']['driving_latitude'])){
740
				$latitude = $data[0]['position']['driving_latitude'];
741
			}elseif(isset($data[0]['position']['latitude'])){
742
				$latitude = $data[0]['position']['latitude'];
743
			}
744
745
			if(isset($data[0]['position']['driving_longitude'])){
746
				$longitude = $data[0]['position']['driving_longitude'];
747
			}elseif(isset($data[0]['position']['longitude'])){
748
				$longitude = $data[0]['position']['longitude'];
749
			}		
750
751
		}
752
		if(isset($data[0]['content']) && isset($data[0]['content']['contact_information'])){
753
			if(isset($data[0]['content']['contact_information']['address'])){
754
				$address = strip_tags($data[0]['content']['contact_information']['address']);
755
756
				$address = explode("\n",$address);
757
				foreach($address as $bitkey => $bit){
758
					$bit = ltrim(rtrim($bit));
759
					if(false === $bit || '' === $bit || null === $bit or empty($bit)){
760
						unset($address[$bitkey]);
761
					}
762
				}
763
				$address = implode(', ',$address);
764
				$address = str_replace(', , ', ', ', $address);
765
			}	
766
		}
767
768
769
		if(false !== $longitude){
770
			$location_data = array(
771
				'address'	=>	$address,
772
				'lat'		=>	$latitude,
773
				'long'		=>	$longitude,
774
				'zoom'		=>	$zoom,
775
				'elevation'	=>	'',
776
			);
777
			if(false !== $id && '0' !== $id){
778
	        	$prev = get_post_meta($id,'location',true);
779
	        	update_post_meta($id,'location',$location_data,$prev);
780
	        }else{
781
	        	add_post_meta($id,'location',$location_data,true);
782
	        }
783
		}
784
	}
785
	/**
786
	 * Saves the longitude and lattitude, as well as sets the map marker.
787
	 */
788
	public function set_location_taxonomy($data,$id) {
789
		$taxonomy = 'location';
0 ignored issues
show
Unused Code introduced by
$taxonomy 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...
790
		$terms = false;
0 ignored issues
show
Unused Code introduced by
$terms 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...
791
		if(isset($data[0]['position'])){
792
			$country_id = 0;
793 View Code Duplication
			if(isset($data[0]['position']['country'])){
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...
794
795
				if(!$term = term_exists(trim($data[0]['position']['country']), 'location'))
796
		        {
797
		            $term = wp_insert_term(trim($data[0]['position']['country']), 'location');
798
		            if ( is_wp_error($term) ){
799
		            	echo $term->get_error_message();
800
		            }
801
		            else {
802
		            	wp_set_object_terms( $id, intval($term['term_id']), 'location',true);
803
		            }
804
		        }
805
		        else
806
		        {
807
		            wp_set_object_terms( $id, intval($term['term_id']), 'location',true);
808
		        }
809
		        $country_id = intval($term['term_id']);
810
		    }
811
812 View Code Duplication
			if(isset($data[0]['position']['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...
813
814
				$tax_args = array('parent'=>$country_id);
815
				if(!$term = term_exists(trim($data[0]['position']['destination']), 'location'))
816
		        {
817
		            $term = wp_insert_term(trim($data[0]['position']['destination']), 'location', $tax_args);
818
		            if ( is_wp_error($term) ){echo $term->get_error_message();}
819
		            else { wp_set_object_terms( $id, intval($term['term_id']), 'location',true); }
820
		        }
821
		        else
822
		        {
823
		            wp_set_object_terms( $id, intval($term['term_id']), 'location',true);
824
		        }				
825
			}		
826
		}
827
	}
828
829
	/**
830
	 * Connects the destinations post type
831
	 */
832
	public function connect_destinations($data,$id) {
833
		if(isset($data[0]['position'])){
834
		    $destinations = false;
835
		    if(isset($data[0]['position']['country'])){
836
		    	$destinations['country'] = $data[0]['position']['country'];
837
		    }
838
		    if(isset($data[0]['position']['destination'])){
839
		    	$destinations['destination'] = $data[0]['position']['destination'];
840
		    }
841
		    
842
		    if(false !== $destinations){	
843
		    	$prev_values = get_post_meta($id,'destination_to_accommodation',false);
844
		    	if(false === $prev_values || !is_array($prev_values)){
845
		    		$prev_values = array();
846
		    	}
847
			    foreach($destinations as $key => $value){
0 ignored issues
show
Bug introduced by
The expression $destinations of type false is not traversable.
Loading history...
848
				    $destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination');
849
	                if (null !== $destination) {
850
	                	if(!in_array($destination->ID,$prev_values)){
851
	                   		add_post_meta($id,'destination_to_accommodation',$destination->ID,false);
852
	                   		add_post_meta($destination->ID,'accommodation_to_destination',$id,false);
853
	                	}
854
	                } 		    	
855
			    }	
856
			}
857
		}
858
	}	
859
860
	/**
861
	 * Set the Travel Style
862
	 */
863
	public function set_taxonomy_style($data,$id) {
864
		$terms = false;
0 ignored issues
show
Unused Code introduced by
$terms 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...
865
		if(isset($data[0]['category'])){
866
			if(!$term = term_exists(trim($data[0]['category']), 'accommodation-type'))
867
	        {
868
	            $term = wp_insert_term(trim($data[0]['category']), 'accommodation-type');
869
	            if ( is_wp_error($term) ){echo $term->get_error_message();}
870
	            else { wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); }
871
	        }
872
	        else
873
	        {
874
	            wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true);
875
	        }				
876
		}
877
	}		
878
879
	/**
880
	 * Saves the room data
881
	 */
882
	public function set_room_data($data,$id) {
883
		if(!empty($data[0]['rooms']) && is_array($data[0]['rooms'])){
884
			$rooms = false;
885
886
			foreach($data[0]['rooms'] as $room){
887
888
				$temp_room = array();
889
				if(isset($room['name'])){
890
					$temp_room['title'] = $room['name'];
891
				}
892
				if(isset($room['description'])){
893
					$temp_room['description'] = strip_tags($room['description']);
894
				}			
895
				$temp_room['price'] = 0;
896
				$temp_room['type'] = 'room';
897
898
				if(!empty($room['images']) && is_array($room['images'])){
899
			    	$attachments_args = array(
900
			    			'post_parent' => $id,
901
			    			'post_status' => 'inherit',
902
			    			'post_type' => 'attachment',
903
			    			'order' => 'ASC',
904
			    	);   	
905
			    	$attachments = new WP_Query($attachments_args);
906
			    	$found_attachments = array();
907
908
			    	if($attachments->have_posts()){
909
			    		foreach($attachments->posts as $attachment){
910
			    			$found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title);
911
			    		}
912
			    	}
913
914
					$temp_room['gallery'] = array();
915
					foreach($room['images'] as $image_data){
916
			    		$temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments);
0 ignored issues
show
Documentation introduced by
$found_attachments is of type array, 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...
917
			    	}
918
				}
919
				$rooms[] = $temp_room;
920
			}
921
922
			if(false !== $id && '0' !== $id){
923
				delete_post_meta($id, 'units');				
924
			}
925
			foreach($rooms as $room){
0 ignored issues
show
Bug introduced by
The expression $rooms of type false is not traversable.
Loading history...
926
		        add_post_meta($id,'units',$room,false);			
927
			}
928
929
			if(isset($data[0]['features']) && isset($data[0]['features']['rooms'])){
930
				$room_count = $data[0]['features']['rooms'];
931
			}else{
932
				$room_count = count($data[0]['rooms']);
933
			}
934
935
			if(false !== $id && '0' !== $id){
936
	        	$prev_rooms = get_post_meta($id,'number_of_rooms',true);
937
	        	update_post_meta($id,'number_of_rooms',$room_count,$prev_rooms);
938
	        }else{
939
	        	add_post_meta($id,'number_of_rooms',$room_count,true);
940
	        }
941
		}
942
	}
943
944
	/**
945
	 * Set the ratings
946
	 */
947
	public function set_rating($data,$id) {
948
949
		if(!empty($data[0]['features']) && isset($data[0]['features']['star_authority'])){
950
			$rating_type = $data[0]['features']['star_authority'];	
951
		}else{
952
			$rating_type = 'Unspecified2';
953
		}
954
		$this->save_custom_field($rating_type,'rating_type',$id);
955
956
		if(!empty($data[0]['features']) && isset($data[0]['features']['stars'])){
957
			$this->save_custom_field($data[0]['features']['stars'],'rating',$id,true);	
958
		}
959
	}
960
961
	/**
962
	 * Set the spoken_languages
963
	 */
964 View Code Duplication
	public function set_spoken_languages($data,$id) {
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...
965
		if(!empty($data[0]['features']) && isset($data[0]['features']['spoken_languages']) && !empty($data[0]['features']['spoken_languages'])){
966
			$languages = false;
967
			foreach($data[0]['features']['spoken_languages'] as $spoken_language){
968
				$languages[] = sanitize_title($spoken_language);
969
			}
970
			if(false !== $languages){
971
				$this->save_custom_field($languages,'spoken_languages',$id);
972
			}
973
		}
974
	}
975
976
	/**
977
	 * Set the friendly
978
	 */
979 View Code Duplication
	public function set_friendly($data,$id) {
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...
980
		if(!empty($data[0]['features']) && isset($data[0]['features']['suggested_visitor_types']) && !empty($data[0]['features']['suggested_visitor_types'])){
981
			$friendly_options = false;
982
			foreach($data[0]['features']['suggested_visitor_types'] as $visitor_type){
983
				$friendly_options[] = sanitize_title($visitor_type);
984
			}
985
			if(false !== $friendly_options){
986
				$this->save_custom_field($friendly_options,'suggested_visitor_types',$id);
987
			}
988
		}		
989
	}
990
991
	/**
992
	 * Set the special interests
993
	 */
994 View Code Duplication
	public function set_special_interests($data,$id) {
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...
995
		if(!empty($data[0]['features']) && isset($data[0]['features']['special_interests']) && !empty($data[0]['features']['special_interests'])){
996
			$interests = false;
997
			foreach($data[0]['features']['special_interests'] as $special_interest){
998
				$interests[] = sanitize_title($special_interest);
999
			}
1000
			if(false !== $interests){
1001
				$this->save_custom_field($interests,'special_interests',$id);
1002
			}
1003
		}		
1004
	}				
1005
1006
	/**
1007
	 * Set the Check in and Check out Date
1008
	 */
1009
	public function set_checkin_checkout($data,$id) {
1010
1011 View Code Duplication
		if(!empty($data[0]['features']) && isset($data[0]['features']['check_in_time'])){
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...
1012
			$time = str_replace('h',':',$data[0]['features']['check_in_time']);
1013
			$time = date('h:ia',strtotime($time));
1014
			$this->save_custom_field($time,'checkin_time',$id);
0 ignored issues
show
Documentation introduced by
$time 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...
1015
		}
1016 View Code Duplication
		if(!empty($data[0]['features']) && isset($data[0]['features']['check_out_time'])){
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...
1017
			$time = str_replace('h',':',$data[0]['features']['check_out_time']);
1018
			$time = date('h:ia',strtotime($time));
1019
			$this->save_custom_field($time,'checkout_time',$id);
0 ignored issues
show
Documentation introduced by
$time 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...
1020
		}
1021
	}	
1022
1023
	/**
1024
	 * Set the Video date
1025
	 */
1026
	public function set_video_data($data,$id) {
1027
		if(!empty($data[0]['content']['youtube_videos']) && is_array($data[0]['content']['youtube_videos'])){
1028
			$videos = false;
1029
1030
			foreach($data[0]['content']['youtube_videos'] as $video){
1031
				$temp_video = '';
1032
				if(isset($video['label'])){
1033
					$temp_video['title'] = $video['label'];
1034
				}
1035
				if(isset($video['description'])){
1036
					$temp_video['description'] = strip_tags($video['description']);
1037
				}	
1038
				if(isset($video['url'])){
1039
					$temp_video['url'] = $video['url'];
1040
				}						
1041
				$temp_video['thumbnail'] = '';
1042
				$videos[] = $temp_video;
1043
			}
1044
1045
			if(false !== $id && '0' !== $id){
1046
				delete_post_meta($id, 'videos');				
1047
			}
1048
			foreach($videos as $video){
0 ignored issues
show
Bug introduced by
The expression $videos of type false is not traversable.
Loading history...
1049
		        add_post_meta($id,'videos',$video,false);			
1050
			}
1051
		}
1052
	}	
1053
1054
	/**
1055
	 * Set the Facilities
1056
	 */
1057
	public function set_facilities($data,$id) {
1058
1059
		$parent_facilities = array(
1060
			'available_services' => 'Available Services',
1061
			'property_facilities' => 'Property Facilities',
1062
			'room_facilities' => 'Room Facilities',
1063
			'activities_on_site' => 'Activities on Site'
1064
		);
1065
		foreach($parent_facilities as $key => $label){
1066
			$terms = false;
0 ignored issues
show
Unused Code introduced by
$terms 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...
1067
			if(isset($data[0]['features']) && isset($data[0]['features'][$key])){
1068
				$parent_id = $this->set_term($id,$label,'facility');	
0 ignored issues
show
Documentation introduced by
$label 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
'facility' 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...
1069
			}
1070
			foreach($data[0]['features'][$key] as $child_facility){
1071
				$this->set_term($id,$child_facility,'facility',$parent_id);
0 ignored issues
show
Bug introduced by
The variable $parent_id does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Documentation introduced by
'facility' 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...
1072
			}
1073
		}
1074
	}
1075
1076
	function set_term($id=false,$name=false,$taxonomy=false,$parent=false){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1077
		if(!$term = term_exists($name, $taxonomy))
1078
        {
1079
        	if(false !== $parent){ $parent = array('parent'=>$parent); }
1080
            $term = wp_insert_term(trim($name), $taxonomy,$parent);
1081
            if ( is_wp_error($term) ){echo $term->get_error_message();}
1082
            else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); }
1083
        }
1084
        else
1085
        {
1086
            wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true);
1087
        }
1088
        return $term['term_id'];
1089
	}	
1090
1091
	/**
1092
	 * Creates the main gallery data
1093
	 */
1094
	public function set_featured_image($data,$id) {
1095
		if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){
1096
	    	$this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id);
1097
1098
	    	if(false !== $this->featured_image){
1099
	    		delete_post_meta($id,'_thumbnail_id');
1100
	    		add_post_meta($id,'_thumbnail_id',$this->featured_image,true);
1101
1102 View Code Duplication
	    		if(!empty($this->gallery_meta) && !in_array($this->featured_image,$this->gallery_meta)){
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...
1103
	    			add_post_meta($id,'gallery',$this->featured_image,false);
1104
	    			$this->gallery_meta[] = $this->featured_image;
1105
	    		}
1106
	    	}			
1107
		}	
1108
	}	
1109
1110
	/**
1111
	 * Sets a banner image
1112
	 */
1113
	public function set_banner_image($data,$id) {
1114
		if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){
1115
	    	$this->banner_image = $this->attach_image($data[0]['content']['images'][1],$id,array('width'=>'1920','height'=>'800','cropping'=>'c'));
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...
1116
1117
	    	if(false !== $this->banner_image){
1118
	    		delete_post_meta($id,'image_group');
1119
	    		$new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image));
1120
	    		add_post_meta($id,'image_group',$new_banner,true);
1121
1122 View Code Duplication
	    		if(!empty($this->gallery_meta) && !in_array($this->banner_image,$this->gallery_meta)){
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...
1123
	    			add_post_meta($id,'gallery',$this->banner_image,false);
1124
	    			$this->gallery_meta[] = $this->banner_image;
1125
	    		}
1126
	    	}			
1127
		}	
1128
	}		
1129
1130
	/**
1131
	 * Creates the main gallery data
1132
	 */
1133
	public function create_main_gallery($data,$id) {
1134
1135
		if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){
1136
1137
	    	$counter = 0;
1138
	    	foreach($data[0]['content']['images'] as $image_data){
1139
	    		if($counter === 0 && false !== $this->featured_image){continue;}
1140
	    		if($counter === 1 && false !== $this->banner_image){continue;}
1141
1142
	    		$this->gallery_meta[] = $temp_id = $this->attach_image($image_data,$id);
0 ignored issues
show
Unused Code introduced by
$temp_id 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...
1143
	    		$counter++;
1144
	    	}
1145
1146
	    	if(!empty($this->gallery_meta)){
1147
	    		delete_post_meta($id,'gallery');
1148
	    		foreach($this->gallery_meta as $gallery_id){
1149
	    			if(false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)){
1150
	    				add_post_meta($id,'gallery',$gallery_id,false);
1151
	    			}
1152
	    		}
1153
	    	}
1154
    	}
1155
	}	
1156
1157
	/**
1158
	 * Attaches 1 image
1159
	 */
1160
	public function attach_image($v=false,$parent_id,$image_sizes=false){
1161
		if(false !== $v){
1162
	   		$temp_fragment = explode('/',$v['url_fragment']);
1163
	    	$url_filename = $temp_fragment[count($temp_fragment)-1];
1164
	    	$url_filename = str_replace(array('.jpg','.png','.jpeg'),'',$url_filename);
1165
	
1166
	    	if(in_array($url_filename,$this->found_attachments)){
1167
	    		return array_search($url_filename,$this->found_attachments);
1168
	    	}
1169
	    	               
1170
	        $postdata=array();
1171
	        if(empty($v['label']))
1172
	        {
1173
	            $v['label']='';
1174
	        }
1175 View Code Duplication
	        if(!empty($v['description']))
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...
1176
	        {
1177
	            $desc=wp_strip_all_tags($v['description']);
1178
	            $posdata=array('post_excerpt'=>$desc);
0 ignored issues
show
Unused Code introduced by
$posdata 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...
1179
	        }
1180 View Code Duplication
	        if(!empty($v['section']))
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
	        {
1182
	            $desc=wp_strip_all_tags($v['section']);
1183
	            $posdata=array('post_excerpt'=>$desc);
0 ignored issues
show
Unused Code introduced by
$posdata 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...
1184
	        }
1185
1186
	        $attachID=NULL;  
0 ignored issues
show
Unused Code introduced by
$attachID 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...
1187
	        //Resizor - add option to setting if required
1188
	        $fragment = str_replace(' ','%20',$v['url_fragment']);
1189
	        $url = $this->get_scaling_url($image_sizes).$fragment;
0 ignored issues
show
Documentation introduced by
$image_sizes is of type boolean, 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...
1190
	        $attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata);
1191
1192
	        //echo($attachID.' add image');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
1193
	        if($attachID!=NULL)
1194
	        {
1195
	            return $attachID;
1196
	        }
1197
        }	
1198
        return 	false;
1199
	}
1200
	public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) {
1201
	
1202
		if ( !$url || !$post_id ) { return new WP_Error('missing', "Need a valid URL and post ID..."); }
1203
1204
		require_once(ABSPATH . 'wp-admin/includes/file.php');
1205
		require_once(ABSPATH . 'wp-admin/includes/media.php');
1206
		require_once(ABSPATH . 'wp-admin/includes/image.php');
1207
		// Download file to temp location, returns full server path to temp file
1208
		//$tmp = download_url( $url );
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
1209
1210
		//var_dump($tmp);
1211
		$tmp = tempnam("/tmp", "FOO");
1212
1213
		$image = file_get_contents($url);
1214
		file_put_contents($tmp, $image);
1215
		chmod($tmp,'777');
1216
1217
		preg_match('/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches);    // fix file filename for query strings
1218
		$url_filename = basename($matches[0]);
1219
		$url_filename=str_replace('%20','_',$url_filename);
1220
		// extract filename from url for title
1221
		$url_type = wp_check_filetype($url_filename);                                           // determine file type (ext and mime/type)
1222
		 
1223
		// override filename if given, reconstruct server path
1224
		if ( !empty( $filename ) && " " != $filename )
1225
		{
1226
			$filename = sanitize_file_name($filename);
1227
			$tmppath = pathinfo( $tmp );      
1228
1229
			$extension = '';  
1230
			if(isset($tmppath['extension'])){
1231
				$extension = $tmppath['extension'];
1232
			}   
1233
1234
			$new = $tmppath['dirname'] . "/". $filename . "." . $extension;
1235
			rename($tmp, $new);                                                                 // renames temp file on server
1236
			$tmp = $new;                                                                        // push new filename (in path) to be used in file array later
1237
		}
1238
1239
		// assemble file data (should be built like $_FILES since wp_handle_sideload() will be using)
1240
		$file_array['tmp_name'] = $tmp;                                                         // full server path to temp file
0 ignored issues
show
Coding Style Comprehensibility introduced by
$file_array was never initialized. Although not strictly required by PHP, it is generally a good practice to add $file_array = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1241
1242 View Code Duplication
		if ( !empty( $filename) && " " != $filename )
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...
1243
		{
1244
			$file_array['name'] = $filename . "." . $url_type['ext'];                           // user given filename for title, add original URL extension
1245
		}
1246
		else
1247
		{
1248
			$file_array['name'] = $url_filename;                                                // just use original URL filename
1249
		}
1250
1251
		// set additional wp_posts columns
1252 View Code Duplication
		if ( empty( $post_data['post_title'] ) )
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...
1253
		{
1254
1255
			$url_filename=str_replace('%20',' ',$url_filename);
1256
1257
			$post_data['post_title'] = basename($url_filename, "." . $url_type['ext']);         // just use the original filename (no extension)
1258
		}
1259
1260
		// make sure gets tied to parent
1261
		if ( empty( $post_data['post_parent'] ) )
1262
		{
1263
			$post_data['post_parent'] = $post_id;
1264
		}
1265
1266
		// required libraries for media_handle_sideload
1267
1268
		// do the validation and storage stuff
1269
		$att_id = media_handle_sideload( $file_array, $post_id, null, $post_data );             // $post_data can override the items saved to wp_posts table, like post_mime_type, guid, post_parent, post_title, post_content, post_status
1270
		 
1271
		// If error storing permanently, unlink
1272
		if ( is_wp_error($att_id) )
1273
		{
1274
			unlink($file_array['tmp_name']);   // clean up
1275
			return false; // output wp_error
1276
			//return $att_id; // output wp_error
1277
		}
1278
1279
		return $att_id;
1280
	}			
1281
}
1282
$wetu_importer_accommodation = new WETU_Importer_Accommodation();