Passed
Push — master ( 4ddb5b...a3fb73 )
by Warwick
03:31
created

WETU_Importer_Destination::set_variables()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 22
Code Lines 10

Duplication

Lines 22
Ratio 100 %

Importance

Changes 0
Metric Value
dl 22
loc 22
rs 8.6737
c 0
b 0
f 0
cc 5
eloc 10
nc 4
nop 0
1
<?php
2
/**
3
 * @package   WETU_Importer_Destination
4
 * @author    LightSpeed
5
 * @license   GPL-2.0+
6
 * @link      
7
 * @copyright 2016 LightSpeed
8
 **/
9
10
class WETU_Importer_Destination extends WETU_Importer
11
{
12
13
	/**
14
	 * The url to list items from WETU
15
	 *
16
	 * @since 0.0.1
17
	 *
18
	 * @var      string
19
	 */
20
	public $tab_slug = 'destination';
21
22
	/**
23
	 * The url to list items from WETU
24
	 *
25
	 * @since 0.0.1
26
	 *
27
	 * @var      string
28
	 */
29
	public $url = false;
30
31
	/**
32
	 * The query string url to list items from WETU
33
	 *
34
	 * @since 0.0.1
35
	 *
36
	 * @var      string
37
	 */
38
	public $url_qs = false;
39
40
	/**
41
	 * Options
42
	 *
43
	 * @since 0.0.1
44
	 *
45
	 * @var      string
46
	 */
47
	public $options = false;
48
49
	/**
50
	 * The fields you wish to import
51
	 *
52
	 * @since 0.0.1
53
	 *
54
	 * @var      string
55
	 */
56
	public $destination_options = false;
57
58
	/**
59
	 * Initialize the plugin by setting localization, filters, and administration functions.
60
	 *
61
	 * @since 1.0.0
62
	 *
63
	 * @access private
64
	 */
65
	public function __construct()
66
	{
67
		$this->set_variables();
68
	}
69
70
	/**
71
	 * Sets the variables used throughout the plugin.
72
	 */
73 View Code Duplication
	public function set_variables()
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...
74
	{
75
		parent::set_variables();
76
		// ** This request only works with API KEY **
77
		//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...
78
		//	$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...
79
		//	$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...
80
		//} 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...
81
		$this->url = 'https://wetu.com/API/Pins/' . $this->api_key;
82
		$this->url_qs = '';
83
		//}
84
85
		$temp_options = get_option('_lsx-to_settings', false);
86
		if (false !== $temp_options && isset($temp_options[$this->plugin_slug]) && !empty($temp_options[$this->plugin_slug])) {
87
			$this->options = $temp_options[$this->plugin_slug];
88
		}
89
90
		$destination_options = get_option('wetu_importer_destination_settings', false);
91
		if (false !== $destination_options) {
92
			$this->destination_options = $destination_options;
93
		}
94
	}
95
96
	/**
97
	 * Display the importer administration screen
98
	 */
99
	public function display_page()
100
	{
101
		?>
102
        <div class="wrap">
103
			<?php $this->navigation('destination'); ?>
104
105
			<?php $this->search_form(); ?>
106
107
            <form method="get" action="" id="posts-filter">
108
                <input type="hidden" name="post_type" class="post_type" value="<?php echo $this->tab_slug; ?>"/>
109
110
                <p><input class="button button-primary add" type="button"
111
                          value="<?php _e('Add to List', 'wetu-importer'); ?>"/>
112
                    <input class="button button-primary clear" type="button"
113
                           value="<?php _e('Clear', 'wetu-importer'); ?>"/>
114
                </p>
115
116
                <table class="wp-list-table widefat fixed posts">
117
					<?php $this->table_header(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method WETU_Importer_Destination::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...
118
119
                    <tbody id="the-list">
120
                    <tr class="post-0 type-tour status-none" id="post-0">
121
                        <th class="check-column" scope="row">
122
                            <label for="cb-select-0"
123
                                   class="screen-reader-text"><?php _e('Enter a title to search for and press enter', 'wetu-importer'); ?></label>
124
                        </th>
125
                        <td class="post-title page-title column-title">
126
                            <strong>
127
								<?php _e('Enter a title to search for', 'wetu-importer'); ?>
128
                            </strong>
129
                        </td>
130
                        <td class="date column-date">
131
                        </td>
132
                        <td class="ssid column-ssid">
133
                        </td>
134
                    </tr>
135
                    </tbody>
136
137
					<?php $this->table_footer(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method WETU_Importer_Destination::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...
138
139
                </table>
140
141
                <p><input class="button button-primary add" type="button"
142
                          value="<?php _e('Add to List', 'wetu-importer'); ?>"/>
143
                    <input class="button button-primary clear" type="button"
144
                           value="<?php _e('Clear', 'wetu-importer'); ?>"/>
145
                </p>
146
            </form>
147
148
            <div style="display:none;" class="import-list-wrapper">
149
                <br/>
150
                <form method="get" action="" id="import-list">
151
152
                    <div class="row">
153
                        <div class="settings-all" style="width:30%;display:block;float:left;">
154
                            <h3><?php _e('What content to Sync from WETU'); ?></h3>
155
                            <ul>
156
                                <li>
157
                                    <input class="content select-all" <?php $this->checked($this->destination_options, 'all'); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_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...
158
                                           type="checkbox" name="content[]"
159
                                           value="all"/> <?php _e('Select All', 'wetu-importer'); ?></li>
160
                                <li>
161
                                    <input class="content" <?php $this->checked($this->destination_options, 'description'); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_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...
162
                                           type="checkbox" name="content[]"
163
                                           value="description"/> <?php _e('Description', 'wetu-importer'); ?></li>
164
                                <li>
165
                                    <input class="content" <?php $this->checked($this->destination_options, 'excerpt'); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_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...
166
                                           type="checkbox" name="content[]"
167
                                           value="excerpt"/> <?php _e('Excerpt', 'wetu-importer'); ?></li>
168
                                <li>
169
                                    <input class="content" <?php $this->checked($this->destination_options, 'gallery'); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_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...
170
                                           type="checkbox" name="content[]"
171
                                           value="gallery"/> <?php _e('Main Gallery', 'wetu-importer'); ?></li>
172 View Code Duplication
								<?php if (class_exists('LSX_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...
173
                                    <li>
174
                                        <input class="content" <?php $this->checked($this->destination_options, 'location'); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
175
                                               type="checkbox" name="content[]"
176
                                               value="location"/> <?php _e('Location', 'wetu-importer'); ?></li>
177
								<?php } ?>
178
179 View Code Duplication
								<?php if (class_exists('LSX_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...
180
                                    <li>
181
                                        <input class="content" <?php $this->checked($this->destination_options, 'videos'); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_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...
182
                                               type="checkbox" name="content[]"
183
                                               value="videos"/> <?php _e('Videos', 'wetu-importer'); ?></li>
184
								<?php } ?>
185
186
                            </ul>
187
                            <h4><?php _e('Additional Content'); ?></h4>
188
                            <ul>
189
                                <li>
190
                                    <input class="content" <?php $this->checked($this->destination_options, 'featured_image'); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
191
                                           type="checkbox" name="content[]"
192
                                           value="featured_image"/> <?php _e('Set Featured Image', 'wetu-importer'); ?>
193
                                </li>
194 View Code Duplication
								<?php if (class_exists('LSX_Banners')) { ?>
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...
195
                                    <li>
196
                                        <input class="content" <?php $this->checked($this->destination_options, 'banner_image'); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_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
                                               type="checkbox" name="content[]"
198
                                               value="banner_image"/> <?php _e('Set Banner Image', 'wetu-importer'); ?>
199
                                    </li>
200
								<?php } ?>
201
                            </ul>
202
                        </div>
203
                        <div class="settings-all" style="width:30%;display:block;float:left;">
204
                            <h3><?php _e('Travel Information'); ?></h3>
205
                            <ul>
206
                                <li>
207
                                    <input class="content" <?php $this->checked($this->destination_options, 'electricity'); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_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...
208
                                           type="checkbox" name="content[]"
209
                                           value="electricity"/> <?php _e('Electricity', 'wetu-importer'); ?></li>
210
                                <li>
211
                                    <input class="content" <?php $this->checked($this->destination_options, 'banking'); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_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...
212
                                           type="checkbox" name="content[]"
213
                                           value="banking"/> <?php _e('Banking', 'wetu-importer'); ?></li>
214
                                <li>
215
                                    <input class="content" <?php $this->checked($this->destination_options, 'cuisine'); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_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
                                           type="checkbox" name="content[]"
217
                                           value="cuisine"/> <?php _e('Cuisine', 'wetu-importer'); ?></li>
218
                                <li>
219
                                    <input class="content" <?php $this->checked($this->destination_options, 'climate'); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_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...
220
                                           type="checkbox" name="content[]"
221
                                           value="climate"/> <?php _e('Climate', 'wetu-importer'); ?></li>
222
                                <li>
223
                                    <input class="content" <?php $this->checked($this->destination_options, 'transport'); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_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...
224
                                           type="checkbox" name="content[]"
225
                                           value="transport"/> <?php _e('Transport', 'wetu-importer'); ?></li>
226
                                <li><input class="content" <?php $this->checked($this->destination_options, 'dress'); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_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...
227
                                           type="checkbox" name="content[]"
228
                                           value="dress"/> <?php _e('Dress', 'wetu-importer'); ?></li>
229
                            </ul>
230
                        </div>
231
232
						<?php if (class_exists('LSX_TO_Team')) { ?>
233
                            <div style="width:30%;display:block;float:left;">
234
                                <h3><?php _e('Assign a Team Member'); ?></h3>
235
								<?php $this->team_member_checkboxes($this->destination_options); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_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...
236
                            </div>
237
						<?php } ?>
238
239
                        <br clear="both"/>
240
                    </div>
241
242
243
                    <h3><?php _e('Your List'); ?></h3>
244
                    <p><input class="button button-primary" type="submit"
245
                              value="<?php _e('Sync', 'wetu-importer'); ?>"/></p>
246
                    <table class="wp-list-table widefat fixed posts">
247
						<?php $this->table_header(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method WETU_Importer_Destination::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...
248
249
                        <tbody>
250
251
                        </tbody>
252
253
						<?php $this->table_footer(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method WETU_Importer_Destination::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...
254
255
                    </table>
256
257
                    <p><input class="button button-primary" type="submit"
258
                              value="<?php _e('Sync', 'wetu-importer'); ?>"/></p>
259
                </form>
260
            </div>
261
262
            <div style="display:none;" class="completed-list-wrapper">
263
                <h3><?php _e('Completed'); ?></h3>
264
                <ul>
265
                </ul>
266
            </div>
267
        </div>
268
		<?php
269
	}
270
271
	/**
272
	 * search_form
273
	 */
274 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...
275
	{
276
		?>
277
        <form class="ajax-form" id="<?php echo $this->plugin_slug; ?>-search-form" method="get" action="tools.php"
278
              data-type="<?php echo $this->tab_slug; ?>">
279
            <input type="hidden" name="page" value="<?php echo $this->tab_slug; ?>"/>
280
281
            <h3><span class="dashicons dashicons-search"></span> <?php _e('Search', 'wetu-importer'); ?></h3>
282
            <div class="normal-search">
283
                <input pattern=".{3,}" placeholder="3 characters minimum" class="keyword" name="keyword" value="">
284
                <input class="button button-primary submit" type="submit"
285
                       value="<?php _e('Search', 'wetu-importer'); ?>"/>
286
            </div>
287
288
289
            <div class="advanced-search hidden" style="display:none;">
290
                <p><?php _e('Enter several keywords, each on a new line.', 'wetu-importer'); ?></p>
291
                <textarea rows="10" cols="40" name="bulk-keywords"></textarea>
292
                <input class="button button-primary submit" type="submit"
293
                       value="<?php _e('Search', 'wetu-importer'); ?>"/>
294
            </div>
295
296
            <p>
297
                <a class="advanced-search-toggle" href="#"><?php _e('Bulk Search', 'wetu-importer'); ?></a> |
298
                <a class="published search-toggle"
299
                   href="#publish"><?php esc_attr_e('Published', 'wetu-importer'); ?></a> |
300
                <a class="pending search-toggle" href="#pending"><?php esc_attr_e('Pending', 'wetu-importer'); ?></a> |
301
                <a class="draft search-toggle" href="#draft"><?php esc_attr_e('Draft', 'wetu-importer'); ?></a>
302
            </p>
303
304
            <div class="ajax-loader" style="display:none;width:100%;text-align:center;">
305
                <img style="width:64px;" src="<?php echo WETU_IMPORTER_URL . 'assets/images/ajaxloader.gif'; ?>"/>
306
            </div>
307
308
            <div class="ajax-loader-small" style="display:none;width:100%;text-align:center;">
309
                <img style="width:32px;" src="<?php echo WETU_IMPORTER_URL . 'assets/images/ajaxloader.gif'; ?>"/>
310
            </div>
311
        </form>
312
		<?php
313
	}
314
315
	/**
316
	 * Grab all the current destination posts via the lsx_wetu_id field.
317
	 */
318 View Code Duplication
	public function find_current_destination($post_type = 'destination')
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...
319
	{
320
		global $wpdb;
321
		$return = array();
322
323
		$current_destination = $wpdb->get_results("
324
					SELECT key1.post_id,key1.meta_value,key2.post_title as name,key2.post_date as last_modified
325
					FROM {$wpdb->postmeta} key1
326
327
					INNER JOIN  {$wpdb->posts} key2 
328
    				ON key1.post_id = key2.ID
329
					
330
					WHERE key1.meta_key = 'lsx_wetu_id'
331
					AND key2.post_type = '{$post_type}'
332
333
					LIMIT 0,500
334
		");
335
		if (null !== $current_destination && !empty($current_destination)) {
336
			foreach ($current_destination as $accom) {
337
				$return[$accom->meta_value] = $accom;
338
			}
339
		}
340
		return $return;
341
	}
342
343
	/**
344
	 * Run through the destination grabbed from the DB.
345
	 */
346
	public function process_ajax_search()
347
	{
348
		$return = false;
349
		if (isset($_POST['action']) && $_POST['action'] === 'lsx_tour_importer' && isset($_POST['type']) && $_POST['type'] === 'destination') {
350
351
			if (isset($_POST['keyword'])) {
352
				$searched_items = false;
353
354 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...
355
					$keyphrases = $_POST['keyword'];
356
				} else {
357
					$keyphrases = array(0);
358
				}
359
360
				if (!is_array($keyphrases)) {
361
					$keyphrases = array($keyphrases);
362
				}
363
				foreach ($keyphrases as &$keyword) {
364
					$keyword = ltrim(rtrim($keyword));
365
				}
366
367
				$post_status = false;
368
				if (in_array('publish', $keyphrases)) {
369
					$post_status = 'publish';
370
				}
371
				if (in_array('pending', $keyphrases)) {
372
					$post_status = 'pending';
373
				}
374
				if (in_array('draft', $keyphrases)) {
375
					$post_status = 'draft';
376
				}
377
378
				$destination = $this->find_current_destination();
379
380
				if (!empty($destination)) {
381
382
					foreach ($destination as $row) {
383
384
						//If we are searching for
385
						if (false !== $post_status) {
386
387
							$current_status = get_post_status($row->post_id);
388
							if ($current_status !== $post_status) {
389
								continue;
390
							}
391
							$searched_items[sanitize_title($row->name) . '-' . $row->meta_value] = $this->format_row($row);
392
393
394
						} else {
395
							//Search through each keyword.
396
							foreach ($keyphrases as $keyphrase) {
397
398
								//Make sure the keyphrase is turned into an array
399
								$keywords = explode(" ", $keyphrase);
400
								if (!is_array($keywords)) {
401
									$keywords = array($keywords);
402
								}
403
404
								if ($this->multineedle_stripos(ltrim(rtrim($row->name)), $keywords) !== false) {
405
									$searched_items[sanitize_title($row->name) . '-' . $row->meta_value] = $this->format_row($row);
406
								}
407
							}
408
						}
409
					}
410
				}
411
412
				if (false !== $searched_items) {
413
					ksort($searched_items);
414
					$return = implode($searched_items);
415
				}
416
			}
417
			print_r($return);
418
			die();
419
		}
420
	}
421
422
	/**
423
	 * Formats the row for output on the screen.
424
	 */
425
	public function format_row($row = false)
426
	{
427
		if (false !== $row) {
428
429
			$status = 'import';
430
			if (0 !== $row->post_id) {
431
				$status = '<a href="' . admin_url('/post.php?post=' . $row->post_id . '&action=edit') . '" target="_blank">' . get_post_status($row->post_id) . '</a>';
432
			}
433
434
			$row_html = '
435
			<tr class="post-' . $row->post_id . ' type-tour" id="post-' . $row->post_id . '">
436
				<th class="check-column" scope="row">
437
					<label for="cb-select-' . $row->meta_value . '" class="screen-reader-text">' . $row->name . '</label>
438
					<input type="checkbox" data-identifier="' . $row->meta_value . '" value="' . $row->post_id . '" name="post[]" id="cb-select-' . $row->meta_value . '">
439
				</th>
440
				<td class="post-title page-title column-title">
441
					<strong>' . $row->name . '</strong> - ' . $status . '
442
				</td>
443
				<td class="date column-date">
444
					<abbr title="' . date('Y/m/d', strtotime($row->last_modified)) . '">' . date('Y/m/d', strtotime($row->last_modified)) . '</abbr><br>Last Modified
445
				</td>
446
				<td class="ssid column-ssid">
447
					' . $row->meta_value . '
448
				</td>
449
			</tr>';
450
			return $row_html;
451
		}
452
	}
453
454
	/**
455
	 * Connect to wetu
456
	 */
457
	public function process_ajax_import()
458
	{
459
		$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...
460
		if (isset($_POST['action']) && $_POST['action'] === 'lsx_import_items' && isset($_POST['type']) && $_POST['type'] === 'destination' && isset($_POST['wetu_id'])) {
461
462
			$wetu_id = $_POST['wetu_id'];
463
			if (isset($_POST['post_id'])) {
464
				$post_id = $_POST['post_id'];
465
			} else {
466
				$post_id = 0;
467
			}
468
469
			if (isset($_POST['team_members'])) {
470
				$team_members = $_POST['team_members'];
471
			} else {
472
				$team_members = false;
473
			}
474
475
			$safari_brands = false;
476
477
			delete_option('wetu_importer_destination_settings');
478 View Code Duplication
			if (isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
479
				$content = $_POST['content'];
480
				add_option('wetu_importer_destination_settings', $content);
481
			} else {
482
				$content = false;
483
			}
484
485
			$jdata = file_get_contents($this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id);
486
			if ($jdata) {
487
				$adata = json_decode($jdata, true);
488
				if (!empty($adata)) {
489
					$return = $this->import_row($adata, $wetu_id, $post_id, $team_members, $content, $safari_brands);
490
					$this->format_completed_row($return);
491
				}
492
			}
493
		}
494
	}
495
496
	/**
497
	 * Connect to wetu
498
	 */
499
	public function import_row($data, $wetu_id, $id = 0, $team_members = false, $importable_content = false, $safari_brands = false)
0 ignored issues
show
Unused Code introduced by
The parameter $safari_brands is not used and could be removed.

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

Loading history...
500
	{
501
502
		if (trim($data[0]['type']) == 'Destination') {
503
			$post_name = $data_post_content = $data_post_excerpt = '';
504
			$post = array(
505
				'post_type' => 'destination',
506
			);
507
508
			$content_used_general_description = false;
509
510
			//Set the post_content
511 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...
512
				if (isset($data[0]['content']['extended_description'])) {
513
					$data_post_content = $data[0]['content']['extended_description'];
514
				} elseif (isset($data[0]['content']['general_description'])) {
515
					$data_post_content = $data[0]['content']['general_description'];
516
					$content_used_general_description = true;
517
				} elseif (isset($data[0]['content']['teaser_description'])) {
518
					$data_post_content = $data[0]['content']['teaser_description'];
519
				}
520
				$post['post_content'] = wp_strip_all_tags($data_post_content);
521
			}
522
523
			//set the post_excerpt
524 View Code Duplication
			if (false !== $importable_content && in_array('excerpt', $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...
525
				if (isset($data[0]['content']['teaser_description'])) {
526
					$data_post_excerpt = $data[0]['content']['teaser_description'];
527
				} elseif (isset($data[0]['content']['extended_description'])) {
528
					$data_post_excerpt = $data[0]['content']['extended_description'];
529
				} elseif (isset($data[0]['content']['general_description']) && false === $content_used_general_description) {
530
					$data_post_excerpt = $data[0]['content']['general_description'];
531
				}
532
				$post['post_excerpt'] = $data_post_excerpt;
533
			}
534
535 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...
536
				$post['ID'] = $id;
537
				if (isset($data[0]['name'])) {
538
					$post['post_title'] = $data[0]['name'];
539
					$post['post_status'] = 'publish';
540
					$post['post_name'] = wp_unique_post_slug(sanitize_title($data[0]['name']), $id, 'draft', 'destination', 0);
541
				}
542
				$id = wp_update_post($post);
543
				$prev_date = get_post_meta($id, 'lsx_wetu_modified_date', true);
544
				update_post_meta($id, 'lsx_wetu_modified_date', strtotime($data[0]['last_modified']), $prev_date);
545
			} else {
546
547
				//Set the name
548
				if (isset($data[0]['name'])) {
549
					$post_name = wp_unique_post_slug(sanitize_title($data[0]['name']), $id, 'draft', 'destination', 0);
550
				}
551
				$post['post_name'] = $post_name;
552
				$post['post_title'] = $data[0]['name'];
553
				$post['post_status'] = 'publish';
554
				$id = wp_insert_post($post);
555
556
				//Save the WETU ID and the Last date it was modified.
557
				if (false !== $id) {
558
					add_post_meta($id, 'lsx_wetu_id', $wetu_id);
559
					add_post_meta($id, 'lsx_wetu_modified_date', strtotime($data[0]['last_modified']));
560
				}
561
			}
562
563
			//Set the team member if it is there
564 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...
565
				$this->set_team_member($id, $team_members);
566
			}
567
568
			if (class_exists('LSX_TO_Maps')) {
569
				$this->set_map_data($data, $id, 4);
570
			}
571
572
			//Set the Room Data
573
			if (false !== $importable_content && in_array('videos', $importable_content)) {
574
				$this->set_video_data($data, $id);
0 ignored issues
show
Bug introduced by
The method set_video_data() does not seem to exist on object<WETU_Importer_Destination>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
575
			}
576
577
			//Set the Electricity
578
			if (false !== $importable_content && in_array('electricity', $importable_content)) {
579
				$this->set_travel_info($data, $id, 'electricity');
580
			}
581
			//Set the cuisine
582
			if (false !== $importable_content && in_array('cuisine', $importable_content)) {
583
				$this->set_travel_info($data, $id, 'cuisine');
584
			}
585
			//Set the banking
586
			if (false !== $importable_content && in_array('banking', $importable_content)) {
587
				$this->set_travel_info($data, $id, 'banking');
588
			}
589
			//Set the transport
590
			if (false !== $importable_content && in_array('transport', $importable_content)) {
591
				$this->set_travel_info($data, $id, 'transport');
592
			}
593
			//Set the dress
594
			if (false !== $importable_content && in_array('dress', $importable_content)) {
595
				$this->set_travel_info($data, $id, 'dress');
596
			}
597
			//Set the climate
598
			if (false !== $importable_content && in_array('climate', $importable_content)) {
599
				$this->set_travel_info($data, $id, 'climate');
600
			}
601
602
			//Setup some default for use in the import
603
			if (false !== $importable_content && (in_array('gallery', $importable_content) || in_array('banner_image', $importable_content) || in_array('featured_image', $importable_content))) {
604
				$this->find_attachments($id);
605
606
				//Set the featured image
607
				if (false !== $importable_content && in_array('featured_image', $importable_content)) {
608
					$this->set_featured_image($data, $id);
609
				}
610
				if (false !== $importable_content && in_array('banner_image', $importable_content)) {
611
					$this->set_banner_image($data, $id);
612
				}
613
				//Import the main gallery
614
				if (false !== $importable_content && in_array('gallery', $importable_content)) {
615
					$this->create_main_gallery($data, $id);
616
				}
617
			}
618
619
		}
620
		return $id;
621
	}
622
623
	/**
624
	 * Set the team memberon each item.
625
	 */
626 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...
627
	{
628
629
		delete_post_meta($id, 'team_to_' . $this->tab_slug);
630
		foreach ($team_members as $team) {
631
			add_post_meta($id, 'team_to_' . $this->tab_slug, $team);
632
		}
633
	}
634
635
	/**
636
	 * Saves the room data
637
	 */
638
	public function set_travel_info($data, $id, $meta_key)
639
	{
640
641
		if (!empty($data[0]['travel_information']) && isset($data[0]['travel_information'][$meta_key])) {
642
			$content = $data[0]['travel_information'][$meta_key];
643
			$this->save_custom_field($content, $meta_key, $id);
644
		}
645
	}
646
647
}