|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package WETU_Importer_Tours |
|
4
|
|
|
* @author LightSpeed |
|
5
|
|
|
* @license GPL-3+ |
|
6
|
|
|
* @link |
|
7
|
|
|
* @copyright 2017 LightSpeed |
|
8
|
|
|
**/ |
|
9
|
|
|
|
|
10
|
|
|
class WETU_Importer_Tours extends WETU_Importer { |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* The url to list items from WETU |
|
14
|
|
|
* |
|
15
|
|
|
* @since 0.0.1 |
|
16
|
|
|
* |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
public $tab_slug = 'tour'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The url to list items from WETU |
|
23
|
|
|
* |
|
24
|
|
|
* @since 0.0.1 |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
public $url = false; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The query string url to list items from WETU |
|
32
|
|
|
* |
|
33
|
|
|
* @since 0.0.1 |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
public $url_qs = false; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Holds a list of any current accommodation |
|
41
|
|
|
* |
|
42
|
|
|
* @since 0.0.1 |
|
43
|
|
|
* |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
public $current_accommodation = false; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Holds a list of any current destinations |
|
50
|
|
|
* |
|
51
|
|
|
* @since 0.0.1 |
|
52
|
|
|
* |
|
53
|
|
|
* @var string |
|
54
|
|
|
*/ |
|
55
|
|
|
public $current_destinations = false; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Holds a list of the destination and the image it needs to grab. |
|
59
|
|
|
* |
|
60
|
|
|
* @since 0.0.1 |
|
61
|
|
|
* |
|
62
|
|
|
* @var string |
|
63
|
|
|
*/ |
|
64
|
|
|
public $destination_images = false; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Options |
|
68
|
|
|
* |
|
69
|
|
|
* @since 0.0.1 |
|
70
|
|
|
* |
|
71
|
|
|
* @var string |
|
72
|
|
|
*/ |
|
73
|
|
|
public $options = false; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* The fields you wish to import |
|
77
|
|
|
* |
|
78
|
|
|
* @since 0.0.1 |
|
79
|
|
|
* |
|
80
|
|
|
* @var string |
|
81
|
|
|
*/ |
|
82
|
|
|
public $tour_options = false; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Initialize the plugin by setting localization, filters, and administration functions. |
|
86
|
|
|
* |
|
87
|
|
|
* @since 1.0.0 |
|
88
|
|
|
* |
|
89
|
|
|
* @access private |
|
90
|
|
|
*/ |
|
91
|
|
|
public function __construct() { |
|
92
|
|
|
$this->set_variables(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Sets the variables used throughout the plugin. |
|
97
|
|
|
*/ |
|
98
|
|
|
public function set_variables() |
|
99
|
|
|
{ |
|
100
|
|
|
parent::set_variables(); |
|
101
|
|
|
|
|
102
|
|
|
if ( false !== $this->api_username && false !== $this->api_password ) { |
|
103
|
|
|
$this->url = 'https://wetu.com/API/Itinerary/'; |
|
104
|
|
|
$this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password; |
|
105
|
|
|
} elseif ( false !== $this->api_key ) { |
|
106
|
|
|
$this->url = 'https://wetu.com/API/Itinerary/' . $this->api_key; |
|
107
|
|
|
$this->url_qs = ''; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
$temp_options = get_option('_lsx-to_settings',false); |
|
111
|
|
|
if(false !== $temp_options && isset($temp_options[$this->plugin_slug]) && !empty($temp_options[$this->plugin_slug])){ |
|
112
|
|
|
$this->options = $temp_options[$this->plugin_slug]; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
$tour_options = get_option('wetu_importer_tour_settings',false); |
|
116
|
|
|
if(false !== $tour_options){ |
|
117
|
|
|
$this->tour_options = $tour_options; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Display the importer administration screen |
|
123
|
|
|
*/ |
|
124
|
|
|
public function display_page() { |
|
125
|
|
|
?> |
|
126
|
|
|
<div class="wrap"> |
|
127
|
|
|
<?php $this->navigation('tour'); ?> |
|
128
|
|
|
|
|
129
|
|
|
<?php $this->update_options_form(); ?> |
|
130
|
|
|
|
|
131
|
|
|
<?php $this->search_form(); ?> |
|
132
|
|
|
|
|
133
|
|
|
<form method="get" action="" id="posts-filter"> |
|
134
|
|
|
<input type="hidden" name="post_type" class="post_type" value="<?php echo $this->tab_slug; ?>" /> |
|
135
|
|
|
|
|
136
|
|
|
<p><input class="button button-primary add" type="button" value="<?php _e('Add to List','wetu-importer'); ?>" /> |
|
137
|
|
|
<input class="button button-primary clear" type="button" value="<?php _e('Clear','wetu-importer'); ?>" /> |
|
138
|
|
|
</p> |
|
139
|
|
|
|
|
140
|
|
|
<table class="wp-list-table widefat fixed posts"> |
|
141
|
|
|
<?php $this->table_header(); ?> |
|
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
<tbody id="the-list"> |
|
144
|
|
|
<tr class="post-0 type-tour status-none" id="post-0"> |
|
145
|
|
|
<th class="check-column" scope="row"> |
|
146
|
|
|
<label for="cb-select-0" class="screen-reader-text"><?php _e('Enter a title to search for and press enter','wetu-importer'); ?></label> |
|
147
|
|
|
</th> |
|
148
|
|
|
<td class="post-title page-title column-title"> |
|
149
|
|
|
<strong> |
|
150
|
|
|
<?php _e('Enter a title to search for','wetu-importer'); ?> |
|
151
|
|
|
</strong> |
|
152
|
|
|
</td> |
|
153
|
|
|
<td class="date column-date"> |
|
154
|
|
|
</td> |
|
155
|
|
|
<td class="ssid column-ssid"> |
|
156
|
|
|
</td> |
|
157
|
|
|
</tr> |
|
158
|
|
|
</tbody> |
|
159
|
|
|
|
|
160
|
|
|
<?php $this->table_footer(); ?> |
|
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
</table> |
|
163
|
|
|
|
|
164
|
|
|
<p><input class="button button-primary add" type="button" value="<?php _e('Add to List','wetu-importer'); ?>" /> |
|
165
|
|
|
<input class="button button-primary clear" type="button" value="<?php _e('Clear','wetu-importer'); ?>" /> |
|
166
|
|
|
</p> |
|
167
|
|
|
</form> |
|
168
|
|
|
|
|
169
|
|
|
<div style="display:none;" class="import-list-wrapper"> |
|
170
|
|
|
<br /> |
|
171
|
|
|
<form method="get" action="" id="import-list"> |
|
172
|
|
|
|
|
173
|
|
|
<div class="row"> |
|
174
|
|
|
<div class="settings-all" style="width:30%;display:block;float:left;"> |
|
175
|
|
|
<h3><?php _e('What content to Sync from WETU'); ?></h3> |
|
176
|
|
|
<ul> |
|
177
|
|
|
<li><input class="content select-all" <?php $this->checked($this->tour_options,'all'); ?> type="checkbox"name="content[]" value="all" /> <?php _e('Select All','wetu-importer'); ?></li> |
|
|
|
|
|
|
178
|
|
|
<li><input class="content" <?php $this->checked($this->tour_options,'description'); ?> type="checkbox" name="content[]" value="description" /> <?php _e('Description','wetu-importer'); ?></li> |
|
|
|
|
|
|
179
|
|
|
<li><input class="content" <?php $this->checked($this->tour_options,'excerpt'); ?> type="checkbox" name="content[]" value="excerpt" /> <?php _e('Excerpt','wetu-importer'); ?></li> |
|
|
|
|
|
|
180
|
|
|
|
|
181
|
|
|
<li><input class="content" <?php $this->checked($this->tour_options,'price'); ?> type="checkbox" name="content[]" value="price" /> <?php _e('Price','wetu-importer'); ?></li> |
|
|
|
|
|
|
182
|
|
|
<li><input class="content" <?php $this->checked($this->tour_options,'duration'); ?> type="checkbox" name="content[]" value="duration" /> <?php _e('Duration','wetu-importer'); ?></li> |
|
|
|
|
|
|
183
|
|
|
|
|
184
|
|
|
<li><input class="content" <?php $this->checked($this->tour_options,'category'); ?> type="checkbox" name="content[]" value="category" /> <?php _e('Category','wetu-importer'); ?></li> |
|
|
|
|
|
|
185
|
|
|
|
|
186
|
|
|
<li><input class="content" <?php $this->checked($this->tour_options,'itineraries'); ?> type="checkbox" name="content[]" value="itineraries" /> <?php _e('Itinerary Days','wetu-importer'); ?></li> |
|
|
|
|
|
|
187
|
|
|
|
|
188
|
|
|
<?php /*if(class_exists('LSX_TO_Maps')){ ?> |
|
|
|
|
|
|
189
|
|
|
<li><input class="content" <?php $this->checked($this->tour_options,'map'); ?> type="checkbox" name="content[]" value="map" /> <?php _e('Map Coordinates (generates a KML file)','wetu-importer'); ?></li> |
|
190
|
|
|
<?php }*/ ?> |
|
191
|
|
|
</ul> |
|
192
|
|
|
</div> |
|
193
|
|
|
<div class="settings-all" style="width:30%;display:block;float:left;"> |
|
194
|
|
|
<h3><?php _e('Itinerary Info'); ?></h3> |
|
195
|
|
|
<ul> |
|
196
|
|
|
<li><input class="content" <?php $this->checked($this->tour_options,'itinerary_description'); ?> type="checkbox" name="content[]" value="itinerary_description" /> <?php _e('Description','wetu-importer'); ?></li> |
|
|
|
|
|
|
197
|
|
|
<li><input class="content" <?php $this->checked($this->tour_options,'itinerary_included'); ?> type="checkbox" name="content[]" value="itinerary_included" /> <?php _e('Included','wetu-importer'); ?></li> |
|
|
|
|
|
|
198
|
|
|
<li><input class="content" <?php $this->checked($this->tour_options,'itinerary_excluded'); ?> type="checkbox" name="content[]" value="itinerary_excluded" /> <?php _e('Excluded','wetu-importer'); ?></li> |
|
|
|
|
|
|
199
|
|
|
</ul> |
|
200
|
|
|
|
|
201
|
|
|
<h4><?php _e('Additional Content'); ?></h4> |
|
202
|
|
|
<ul> |
|
203
|
|
|
<li><input class="content" <?php $this->checked($this->tour_options,'accommodation'); ?> type="checkbox" name="content[]" value="accommodation" /> <?php _e('Sync Accommodation','wetu-importer'); ?></li> |
|
|
|
|
|
|
204
|
|
|
<li><input class="content" <?php $this->checked($this->tour_options,'destination'); ?> type="checkbox" name="content[]" value="destination" /> <?php _e('Sync Destinations','wetu-importer'); ?></li> |
|
|
|
|
|
|
205
|
|
|
<li><input class="content" <?php $this->checked($this->tour_options,'featured_image'); ?> type="checkbox" name="content[]" value="featured_image" /> <?php _e('Featured Image','wetu-importer'); ?></li> |
|
|
|
|
|
|
206
|
|
|
<li><input class="content" <?php $this->checked($this->tour_options,'banner_image'); ?> type="checkbox" name="content[]" value="banner_image" /> <?php _e('Banner Image','wetu-importer'); ?></li> |
|
|
|
|
|
|
207
|
|
|
</ul> |
|
208
|
|
|
</div> |
|
209
|
|
|
<?php if(class_exists('LSX_TO_Team')){ ?> |
|
210
|
|
|
<div style="width:30%;display:block;float:left;"> |
|
211
|
|
|
<h3><?php _e('Assign a Team Member'); ?></h3> |
|
212
|
|
|
<?php $this->team_member_checkboxes($this->tour_options); ?> |
|
|
|
|
|
|
213
|
|
|
</div> |
|
214
|
|
|
<?php } ?> |
|
215
|
|
|
|
|
216
|
|
|
<br clear="both" /> |
|
217
|
|
|
</div> |
|
218
|
|
|
|
|
219
|
|
|
|
|
220
|
|
|
<h3><?php _e('Your List'); ?></h3> |
|
221
|
|
|
<p><input class="button button-primary" type="submit" value="<?php _e('Sync','wetu-importer'); ?>" /></p> |
|
222
|
|
|
<table class="wp-list-table widefat fixed posts"> |
|
223
|
|
|
<?php $this->table_header(); ?> |
|
|
|
|
|
|
224
|
|
|
|
|
225
|
|
|
<tbody> |
|
226
|
|
|
|
|
227
|
|
|
</tbody> |
|
228
|
|
|
|
|
229
|
|
|
<?php $this->table_footer(); ?> |
|
|
|
|
|
|
230
|
|
|
|
|
231
|
|
|
</table> |
|
232
|
|
|
|
|
233
|
|
|
<p><input class="button button-primary" type="submit" value="<?php _e('Sync','wetu-importer'); ?>" /></p> |
|
234
|
|
|
</form> |
|
235
|
|
|
</div> |
|
236
|
|
|
|
|
237
|
|
|
<div style="display:none;" class="completed-list-wrapper"> |
|
238
|
|
|
<h3><?php _e('Completed','wetu-importer'); ?> - <small><?php _e('Import your','wetu-importer'); ?> <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=accommodation"><?php _e('accommodation'); ?></a> <?php _e('next','wetu-importer'); ?></small></h3> |
|
239
|
|
|
<ul> |
|
240
|
|
|
</ul> |
|
241
|
|
|
</div> |
|
242
|
|
|
</div> |
|
243
|
|
|
<?php |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* search_form |
|
248
|
|
|
*/ |
|
249
|
|
|
public function update_options_form() { |
|
250
|
|
|
$tours = get_transient('lsx_ti_tours'); |
|
251
|
|
|
|
|
252
|
|
|
echo '<div class="wetu-status tour-wetu-status"><h3>'.__('Wetu Status','wetu-importer').' - '; |
|
253
|
|
|
if('' === $tours || false === $tours || isset($_GET['refresh_tours'])){ |
|
254
|
|
|
$result = $this->update_options(); |
|
255
|
|
|
|
|
256
|
|
|
if(true === $result){ |
|
257
|
|
|
echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>'; |
|
258
|
|
|
echo ' - <small><a href="#">'.esc_attr('Refresh','wetu-importer').'</a></small>'; |
|
259
|
|
|
}else{ |
|
260
|
|
|
echo '<span style="color:red;">'.wp_kses_post($result).'</span>'; |
|
261
|
|
|
} |
|
262
|
|
|
}else{ |
|
263
|
|
|
echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span> - <small><a href="#">'.esc_attr('Refresh','wetu-importer').'</a></small>'; |
|
264
|
|
|
} |
|
265
|
|
|
echo '</h3>'; |
|
266
|
|
|
|
|
267
|
|
|
$form_options = get_option('lsx_ti_tours_api_options'); |
|
268
|
|
|
if(false === $form_options){ |
|
269
|
|
|
$form_options = array(0); |
|
270
|
|
|
} |
|
271
|
|
|
?> |
|
272
|
|
|
<form method="get" class="tour-refresh-form" action="<?php echo admin_url('admin.php'); ?>"> |
|
273
|
|
|
|
|
274
|
|
|
<input type="hidden" name="page" value="<?php echo $this->plugin_slug; ?>" /> |
|
275
|
|
|
<input type="hidden" name="tab" value="tour" /> |
|
276
|
|
|
<input type="hidden" name="refresh_tours" value="true" /> |
|
277
|
|
|
|
|
278
|
|
|
<p class="tour-search-options"> |
|
279
|
|
|
<label for="own"><input class="content" <?php if(in_array('own',$form_options)){ echo 'checked'; } ?> type="checkbox" name="own" value="true" /> <?php esc_html_e('Own Tours','wetu-importer'); ?> </label> |
|
280
|
|
|
</p> |
|
281
|
|
|
|
|
282
|
|
|
<p class="tour-search-options"> |
|
283
|
|
|
<label for="type"><input class="content" <?php if(in_array('allitineraries',$form_options)){ echo 'checked'; } ?> type="radio" name="type[]" value="allitineraries" /> <?php _e('All','wetu-importer'); ?></label> |
|
284
|
|
|
<label for="type"><input class="content" <?php if(in_array('sample',$form_options)){ echo 'checked'; } ?>type="radio" name="type[]" value="sample" /> <?php _e('Sample','wetu-importer'); ?></label> |
|
285
|
|
|
<label for="type"><input class="content" <?php if(in_array('personal',$form_options)){ echo 'checked'; } ?>type="radio" name="type[]" value="personal" /> <?php _e('Personal','wetu-importer'); ?></label> |
|
286
|
|
|
</p> |
|
287
|
|
|
</form> |
|
288
|
|
|
|
|
289
|
|
|
<?php |
|
290
|
|
|
echo '</div>'; |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* Save the list of Tours into an option |
|
295
|
|
|
*/ |
|
296
|
|
|
public function update_options() { |
|
297
|
|
|
|
|
298
|
|
|
$own = ''; |
|
|
|
|
|
|
299
|
|
|
$options = array(); |
|
300
|
|
|
|
|
301
|
|
|
delete_option('lsx_ti_tours_api_options'); |
|
302
|
|
|
|
|
303
|
|
|
if(isset($_GET['own'])){ |
|
304
|
|
|
$this->url_qs .= '&own=true'; |
|
305
|
|
|
$options[] = 'own'; |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
if(isset($_GET['type'])){ |
|
309
|
|
|
$this->url_qs .= '&type='.implode('',$_GET['type']); |
|
310
|
|
|
$options[] = implode('',$_GET['type']); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
$this->url_qs .= '&results=2000'; |
|
314
|
|
|
|
|
315
|
|
|
add_option('lsx_ti_tours_api_options',$options); |
|
316
|
|
|
|
|
317
|
|
|
$data = file_get_contents( $this->url . '/V7/List?' . $this->url_qs ); |
|
318
|
|
|
|
|
319
|
|
|
$tours = json_decode($data, true); |
|
320
|
|
|
|
|
321
|
|
|
if(isset($tours['error'])){ |
|
322
|
|
|
return $tours['error']; |
|
323
|
|
View Code Duplication |
}elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) { |
|
|
|
|
|
|
324
|
|
|
set_transient('lsx_ti_tours',$tours['itineraries'],60*60*2); |
|
325
|
|
|
return true; |
|
326
|
|
|
} |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
/** |
|
330
|
|
|
* Grab all the current tour posts via the lsx_wetu_id field. |
|
331
|
|
|
*/ |
|
332
|
|
View Code Duplication |
public function find_current_tours() { |
|
|
|
|
|
|
333
|
|
|
global $wpdb; |
|
334
|
|
|
$return = array(); |
|
335
|
|
|
|
|
336
|
|
|
$current_tours = $wpdb->get_results(" |
|
337
|
|
|
SELECT key1.post_id,key1.meta_value |
|
338
|
|
|
FROM {$wpdb->postmeta} key1 |
|
339
|
|
|
|
|
340
|
|
|
INNER JOIN {$wpdb->posts} key2 |
|
341
|
|
|
ON key1.post_id = key2.ID |
|
342
|
|
|
|
|
343
|
|
|
WHERE key1.meta_key = 'lsx_wetu_id' |
|
344
|
|
|
AND key2.post_type = 'tour' |
|
345
|
|
|
|
|
346
|
|
|
LIMIT 0,500 |
|
347
|
|
|
"); |
|
348
|
|
|
if(null !== $current_tours && !empty($current_tours)){ |
|
349
|
|
|
foreach($current_tours as $tour){ |
|
350
|
|
|
$return[$tour->meta_value] = $tour; |
|
351
|
|
|
} |
|
352
|
|
|
} |
|
353
|
|
|
return $return; |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
/** |
|
357
|
|
|
* Run through the accommodation grabbed from the DB. |
|
358
|
|
|
*/ |
|
359
|
|
|
public function process_ajax_search() { |
|
360
|
|
|
$return = false; |
|
361
|
|
|
|
|
362
|
|
|
if(isset($_POST['action']) && $_POST['action'] === 'lsx_tour_importer' && isset($_POST['type']) && $_POST['type'] === $this->tab_slug){ |
|
363
|
|
|
|
|
364
|
|
|
|
|
365
|
|
|
$tours = get_transient('lsx_ti_tours'); |
|
366
|
|
|
if ( false !== $tours) { |
|
367
|
|
|
|
|
368
|
|
|
$searched_items = false; |
|
369
|
|
|
|
|
370
|
|
View Code Duplication |
if(isset($_POST['keyword'] )) { |
|
|
|
|
|
|
371
|
|
|
$keyphrases = $_POST['keyword']; |
|
372
|
|
|
}else{ |
|
373
|
|
|
$keyphrases = array(0); |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
if(!is_array($keyphrases)){ |
|
377
|
|
|
$keyphrases = array($keyphrases); |
|
378
|
|
|
} |
|
379
|
|
|
foreach($keyphrases as &$keyword){ |
|
380
|
|
|
$keyword = ltrim(rtrim($keyword)); |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
$post_status = false; |
|
384
|
|
|
if(in_array('publish',$keyphrases)){ |
|
385
|
|
|
$post_status = 'publish'; |
|
386
|
|
|
} |
|
387
|
|
|
if(in_array('pending',$keyphrases)){ |
|
388
|
|
|
$post_status = 'pending'; |
|
389
|
|
|
} |
|
390
|
|
|
if(in_array('draft',$keyphrases)){ |
|
391
|
|
|
$post_status = 'draft'; |
|
392
|
|
|
} |
|
393
|
|
|
if(in_array('import',$keyphrases)){ |
|
394
|
|
|
$post_status = 'import'; |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
|
|
398
|
|
|
if (!empty($tours)) { |
|
399
|
|
|
$current_tours = $this->find_current_tours(); |
|
400
|
|
|
|
|
401
|
|
|
foreach($tours as $row_key => $row){ |
|
402
|
|
|
|
|
403
|
|
|
if(isset($row['is_disabled']) && true === $row['is_disabled']){ |
|
404
|
|
|
continue; |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
/*if('Sample' === $row['type']){ |
|
|
|
|
|
|
408
|
|
|
continue; |
|
409
|
|
|
}*/ |
|
410
|
|
|
|
|
411
|
|
|
//If this is a current tour, add its ID to the row. |
|
412
|
|
|
$row['post_id'] = 0; |
|
413
|
|
|
if(false !== $current_tours && array_key_exists($row['identifier'], $current_tours)){ |
|
414
|
|
|
$row['post_id'] = $current_tours[$row['identifier']]->post_id; |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
//If we are searching for |
|
418
|
|
View Code Duplication |
if(false !== $post_status){ |
|
|
|
|
|
|
419
|
|
|
|
|
420
|
|
|
if('import' === $post_status){ |
|
421
|
|
|
|
|
422
|
|
|
if(0 !== $row['post_id']){ |
|
423
|
|
|
continue; |
|
424
|
|
|
}else{ |
|
425
|
|
|
$searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
|
|
|
|
|
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
|
|
429
|
|
|
}else{ |
|
430
|
|
|
|
|
431
|
|
|
if(0 === $row['post_id']){ |
|
432
|
|
|
continue; |
|
433
|
|
|
}else{ |
|
434
|
|
|
$current_status = get_post_status($row['post_id']); |
|
435
|
|
|
if($current_status !== $post_status){ |
|
436
|
|
|
continue; |
|
437
|
|
|
} |
|
438
|
|
|
|
|
439
|
|
|
} |
|
440
|
|
|
$searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
|
|
|
|
|
|
441
|
|
|
|
|
442
|
|
|
} |
|
443
|
|
|
|
|
444
|
|
|
}else{ |
|
445
|
|
|
//Search through each keyword. |
|
446
|
|
|
foreach($keyphrases as $keyphrase){ |
|
447
|
|
|
|
|
448
|
|
|
//Make sure the keyphrase is turned into an array |
|
449
|
|
|
$keywords = explode(" ",$keyphrase); |
|
450
|
|
|
if(!is_array($keywords)){ |
|
451
|
|
|
$keywords = array($keywords); |
|
452
|
|
|
} |
|
453
|
|
|
|
|
454
|
|
|
if($this->multineedle_stripos(ltrim(rtrim($row['name'])), $keywords) !== false){ |
|
455
|
|
|
$searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
|
|
|
|
|
|
456
|
|
|
} |
|
457
|
|
|
} |
|
458
|
|
|
} |
|
459
|
|
|
} |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
if(false !== $searched_items){ |
|
463
|
|
|
ksort($searched_items); |
|
464
|
|
|
$return = implode($searched_items); |
|
465
|
|
|
} |
|
466
|
|
|
} |
|
467
|
|
|
print_r($return); |
|
468
|
|
|
die(); |
|
469
|
|
|
} |
|
470
|
|
|
} |
|
471
|
|
|
|
|
472
|
|
|
/** |
|
473
|
|
|
* Formats the row for output on the screen. |
|
474
|
|
|
*/ |
|
475
|
|
View Code Duplication |
public function format_row($row = false){ |
|
|
|
|
|
|
476
|
|
|
if(false !== $row){ |
|
477
|
|
|
|
|
478
|
|
|
$status = 'import'; |
|
479
|
|
|
if(0 !== $row['post_id']){ |
|
480
|
|
|
$status = '<a href="'.admin_url('/post.php?post='.$row['post_id'].'&action=edit').'" target="_blank">'.get_post_status($row['post_id']).'</a>'; |
|
481
|
|
|
} |
|
482
|
|
|
|
|
483
|
|
|
$row_html = ' |
|
484
|
|
|
<tr class="post-'.$row['post_id'].' type-tour" id="post-'.$row['post_id'].'"> |
|
485
|
|
|
<th class="check-column" scope="row"> |
|
486
|
|
|
<label for="cb-select-'.$row['identifier'].'" class="screen-reader-text">'.$row['name'].'</label> |
|
487
|
|
|
<input type="checkbox" data-identifier="'.$row['identifier'].'" value="'.$row['post_id'].'" name="post[]" id="cb-select-'.$row['identifier'].'"> |
|
488
|
|
|
</th> |
|
489
|
|
|
<td class="post-title page-title column-title"> |
|
490
|
|
|
<strong>'.$row['name'].'</strong> - '.$status.' |
|
491
|
|
|
</td> |
|
492
|
|
|
<td class="date column-date"> |
|
493
|
|
|
<abbr title="'.date('Y/m/d',strtotime($row['last_modified'])).'">'.date('Y/m/d',strtotime($row['last_modified'])).'</abbr><br>Last Modified |
|
494
|
|
|
</td> |
|
495
|
|
|
<td class="ssid column-ssid"> |
|
496
|
|
|
'.$row['identifier'].' |
|
497
|
|
|
</td> |
|
498
|
|
|
</tr>'; |
|
499
|
|
|
return $row_html; |
|
500
|
|
|
} |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
/** |
|
504
|
|
|
* Connect to wetu |
|
505
|
|
|
*/ |
|
506
|
|
|
public function process_ajax_import($force = false) { |
|
|
|
|
|
|
507
|
|
|
$return = false; |
|
|
|
|
|
|
508
|
|
|
|
|
509
|
|
|
if(isset($_POST['action']) && $_POST['action'] === 'lsx_import_items' && isset($_POST['type']) && $_POST['type'] === $this->tab_slug && isset($_POST['wetu_id'])){ |
|
510
|
|
|
|
|
511
|
|
|
$wetu_id = $_POST['wetu_id']; |
|
512
|
|
|
if(isset($_POST['post_id'])){ |
|
513
|
|
|
$post_id = $_POST['post_id']; |
|
514
|
|
|
}else{ |
|
515
|
|
|
$post_id = 0; |
|
516
|
|
|
} |
|
517
|
|
|
|
|
518
|
|
|
delete_option('wetu_importer_tour_settings'); |
|
519
|
|
View Code Duplication |
if(isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])){ |
|
|
|
|
|
|
520
|
|
|
$content = $_POST['content']; |
|
521
|
|
|
add_option('wetu_importer_tour_settings',$content); |
|
522
|
|
|
}else{ |
|
523
|
|
|
$content = false; |
|
524
|
|
|
} |
|
525
|
|
|
|
|
526
|
|
|
$jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id); |
|
527
|
|
|
|
|
528
|
|
View Code Duplication |
if($jdata) |
|
|
|
|
|
|
529
|
|
|
{ |
|
530
|
|
|
$jdata=json_decode($jdata,true); |
|
531
|
|
|
if(!empty($jdata)) |
|
532
|
|
|
{ |
|
533
|
|
|
$return = $this->import_row($jdata,$wetu_id,$post_id,$content); |
|
534
|
|
|
$this->format_completed_row($return); |
|
535
|
|
|
$this->cleanup_posts(); |
|
536
|
|
|
$this->attach_destination_images($content); |
|
537
|
|
|
} |
|
538
|
|
|
} |
|
539
|
|
|
} |
|
540
|
|
|
} |
|
541
|
|
|
|
|
542
|
|
|
/** |
|
543
|
|
|
* Connect to wetu |
|
544
|
|
|
* |
|
545
|
|
|
* @param $data array |
|
546
|
|
|
* @param $wetu_id string |
|
547
|
|
|
*/ |
|
548
|
|
|
public function import_row($data,$wetu_id,$id=0,$importable_content=false,$old1=false,$old2=false) { |
|
|
|
|
|
|
549
|
|
|
$post_name = $data_post_content = $data_post_excerpt = ''; |
|
|
|
|
|
|
550
|
|
|
$post = array( |
|
551
|
|
|
'post_type' => 'tour', |
|
552
|
|
|
); |
|
553
|
|
|
|
|
554
|
|
|
//Set the post_content |
|
555
|
|
|
$content_used_general_description = false; |
|
|
|
|
|
|
556
|
|
|
if(false !== $importable_content && in_array('description',$importable_content)){ |
|
557
|
|
|
$data_post_content = ''; |
|
558
|
|
|
|
|
559
|
|
|
if(isset($data['description'])){ |
|
560
|
|
|
$data_post_content = $data['description']; |
|
561
|
|
|
}elseif(isset($data['summary'])){ |
|
562
|
|
|
$data_post_content = $data['summary']; |
|
563
|
|
|
} |
|
564
|
|
|
$post['post_content'] = $data_post_content; |
|
565
|
|
|
} |
|
566
|
|
|
|
|
567
|
|
|
//Create or update the post |
|
568
|
|
|
if(false !== $id && '0' !== $id){ |
|
|
|
|
|
|
569
|
|
|
$post['ID'] = $id; |
|
570
|
|
|
$post['post_status'] = 'publish'; |
|
571
|
|
|
$id = wp_update_post($post); |
|
572
|
|
|
$prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
573
|
|
|
update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date); |
|
574
|
|
|
}else{ |
|
575
|
|
|
|
|
576
|
|
|
//Set the name |
|
577
|
|
|
if(isset($data['name'])){ |
|
578
|
|
|
$post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0); |
|
579
|
|
|
} |
|
580
|
|
|
$post['post_name'] = $post_name; |
|
581
|
|
|
$post['post_title'] = $data['name']; |
|
582
|
|
|
$post['post_status'] = 'publish'; |
|
583
|
|
|
$id = wp_insert_post($post); |
|
584
|
|
|
|
|
585
|
|
|
//Save the WETU ID and the Last date it was modified. |
|
586
|
|
|
if(false !== $id){ |
|
587
|
|
|
add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
588
|
|
|
add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified'])); |
|
589
|
|
|
} |
|
590
|
|
|
} |
|
591
|
|
|
|
|
592
|
|
|
|
|
593
|
|
|
//Set the price |
|
594
|
|
|
if(false !== $importable_content && in_array('price',$importable_content)){ |
|
595
|
|
|
$this->set_price($data,$id); |
|
596
|
|
|
} |
|
597
|
|
|
|
|
598
|
|
|
//Set the Duration |
|
599
|
|
|
if(false !== $importable_content && in_array('duration',$importable_content)){ |
|
600
|
|
|
$this->set_duration($data,$id); |
|
601
|
|
|
} |
|
602
|
|
|
|
|
603
|
|
|
if(false !== $importable_content && in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){ |
|
604
|
|
|
$this->process_itineraries($data,$id,$importable_content); |
|
605
|
|
|
} |
|
606
|
|
|
|
|
607
|
|
|
if(in_array('map',$importable_content) && isset($data['routes']) && !empty($data['routes'])){ |
|
608
|
|
|
$this->set_map_data($data,$id); |
|
609
|
|
|
} |
|
610
|
|
|
|
|
611
|
|
|
return $id; |
|
612
|
|
|
} |
|
613
|
|
|
|
|
614
|
|
|
/** |
|
615
|
|
|
* A loop which runs through each leg on the tour. |
|
616
|
|
|
*/ |
|
617
|
|
|
public function process_itineraries($data,$id,$importable_content) { |
|
618
|
|
|
$day_counter = 1; |
|
619
|
|
|
$leg_counter = 0; |
|
620
|
|
|
|
|
621
|
|
|
delete_post_meta($id,'itinerary'); |
|
622
|
|
|
|
|
623
|
|
|
if(false !== $importable_content && in_array('accommodation',$importable_content)){ |
|
624
|
|
|
delete_post_meta($id,'accommodation_to_tour'); |
|
625
|
|
|
} |
|
626
|
|
|
if(false !== $importable_content && in_array('destination',$importable_content)){ |
|
627
|
|
|
delete_post_meta($id,'destination_to_tour'); |
|
628
|
|
|
delete_post_meta($id,'departs_from'); |
|
629
|
|
|
delete_post_meta($id,'ends_in'); |
|
630
|
|
|
} |
|
631
|
|
|
|
|
632
|
|
|
$departs_from = false; |
|
633
|
|
|
$ends_in = false; |
|
634
|
|
|
|
|
635
|
|
|
foreach($data['legs'] as $leg){ |
|
636
|
|
|
|
|
637
|
|
|
if(isset($leg['days']) && !empty($leg['days'])){ |
|
638
|
|
|
|
|
639
|
|
|
//Itinerary Accommodation |
|
640
|
|
|
$current_accommodation = false; |
|
641
|
|
|
if(false !== $importable_content && in_array('accommodation',$importable_content)){ |
|
642
|
|
|
$current_accommodation = $this->set_accommodation($leg,$id); |
|
643
|
|
|
} |
|
644
|
|
|
|
|
645
|
|
|
//Itinerary Destination |
|
646
|
|
|
$current_destination = false; |
|
647
|
|
|
if(false !== $importable_content && in_array('destination',$importable_content)){ |
|
648
|
|
|
$current_destination = $this->set_destination($leg,$id,$leg_counter); |
|
649
|
|
|
} |
|
650
|
|
|
|
|
651
|
|
|
//If the Nights are the same mount of days in the array, then it isnt "By Destination" |
|
652
|
|
|
if($leg['nights'] === count($leg['days']) || 0 === $leg['itinerary_leg_id']){ |
|
653
|
|
|
|
|
654
|
|
|
foreach($leg['days'] as $day){ |
|
655
|
|
|
|
|
656
|
|
|
$current_day = array(); |
|
657
|
|
|
|
|
658
|
|
|
$current_day['title'] = esc_attr('Day ','wetu-importer').$day_counter; |
|
659
|
|
|
|
|
660
|
|
|
//print_r('<pre>');print_r($day['notes']);print_r('</pre>'); |
|
|
|
|
|
|
661
|
|
|
|
|
662
|
|
|
//Description |
|
663
|
|
|
if(false !== $importable_content && in_array('itinerary_description',$importable_content) && isset($day['notes'])){ |
|
664
|
|
|
$current_day['description'] = $day['notes']; |
|
665
|
|
|
}else{ |
|
666
|
|
|
$current_day['description'] = ''; |
|
667
|
|
|
} |
|
668
|
|
|
|
|
669
|
|
|
//Itinerary Gallery |
|
670
|
|
|
if(false !== $importable_content && in_array('itinerary_gallery',$importable_content) && isset($day['images'])){ |
|
671
|
|
|
$current_day['featured_image'] = ''; |
|
672
|
|
|
}else{ |
|
673
|
|
|
$current_day['featured_image'] = ''; |
|
674
|
|
|
} |
|
675
|
|
|
|
|
676
|
|
|
//Accommodation |
|
677
|
|
|
if(false !== $current_accommodation){ |
|
678
|
|
|
$current_day['accommodation_to_tour'] = array($current_accommodation); |
|
679
|
|
|
}else{ |
|
680
|
|
|
$current_day['accommodation_to_tour'] = array(); |
|
681
|
|
|
} |
|
682
|
|
|
|
|
683
|
|
|
//Destination |
|
684
|
|
|
if(false !== $current_destination){ |
|
685
|
|
|
$current_day['destination_to_tour'] = array($current_destination); |
|
686
|
|
|
}else{ |
|
687
|
|
|
$current_day['destination_to_tour'] = array(); |
|
688
|
|
|
} |
|
689
|
|
|
|
|
690
|
|
|
//Included |
|
691
|
|
View Code Duplication |
if(false !== $importable_content && in_array('itinerary_included',$importable_content) && isset($day['included']) && '' !== $day['included']){ |
|
|
|
|
|
|
692
|
|
|
$current_day['included'] = $day['included']; |
|
693
|
|
|
}else{ |
|
694
|
|
|
$current_day['included'] = ''; |
|
695
|
|
|
} |
|
696
|
|
|
|
|
697
|
|
|
//Excluded |
|
698
|
|
View Code Duplication |
if(false !== $importable_content && in_array('itinerary_excluded',$importable_content) && isset($day['excluded']) && '' !== $day['excluded']){ |
|
|
|
|
|
|
699
|
|
|
$current_day['excluded'] = $day['excluded']; |
|
700
|
|
|
}else{ |
|
701
|
|
|
$current_day['excluded'] = ''; |
|
702
|
|
|
} |
|
703
|
|
|
|
|
704
|
|
|
$this->set_itinerary_day($current_day,$id); |
|
705
|
|
|
$day_counter++; |
|
706
|
|
|
} |
|
707
|
|
|
|
|
708
|
|
|
}else{ |
|
709
|
|
|
$day_counter = $day_counter + (int)$leg['nights']; |
|
710
|
|
|
} |
|
711
|
|
|
|
|
712
|
|
|
} |
|
713
|
|
|
|
|
714
|
|
|
//If we are in the first leg, and the destination was attached then save it as the departure field. |
|
715
|
|
|
if( 0 === $leg_counter && false !== $current_destination){ |
|
716
|
|
|
$departs_from = $current_destination; |
|
|
|
|
|
|
717
|
|
|
} |
|
718
|
|
|
|
|
719
|
|
|
//If its the last leg then save it as the ends in. |
|
720
|
|
|
if( $leg_counter === (count($data['legs'])-2) && false !== $current_destination){ |
|
721
|
|
|
$ends_in = $current_destination; |
|
722
|
|
|
} |
|
723
|
|
|
$leg_counter++; |
|
724
|
|
|
} |
|
725
|
|
|
|
|
726
|
|
|
if(false !== $departs_from){ |
|
727
|
|
|
add_post_meta($id,'departs_from',$departs_from,true); |
|
728
|
|
|
} |
|
729
|
|
|
if(false !== $ends_in){ |
|
730
|
|
|
add_post_meta($id,'ends_in',$ends_in,true); |
|
731
|
|
|
} |
|
732
|
|
|
} |
|
733
|
|
|
|
|
734
|
|
|
/** |
|
735
|
|
|
* Run through your routes and save the points as a KML file. |
|
736
|
|
|
*/ |
|
737
|
|
|
public function set_map_data($data,$id,$zoom=9) { |
|
738
|
|
|
|
|
739
|
|
|
if(!empty($data['routes'])){ |
|
740
|
|
|
|
|
741
|
|
|
delete_post_meta($id,'wetu_map_points'); |
|
742
|
|
|
|
|
743
|
|
|
$points = array(); |
|
744
|
|
|
|
|
745
|
|
|
foreach($data['routes'] as $route){ |
|
746
|
|
|
|
|
747
|
|
|
|
|
748
|
|
|
if(isset($route['points']) && '' !== $route['points']){ |
|
749
|
|
|
|
|
750
|
|
|
$temp_points = explode(';',$route['points']); |
|
751
|
|
|
$point_counter = count($temp_points); |
|
752
|
|
|
|
|
753
|
|
|
for ($x = 0; $x <= $point_counter; $x++) { |
|
754
|
|
|
$y = $x+1; |
|
755
|
|
|
$points[] = $temp_points[$x].','.$temp_points[$y]; |
|
756
|
|
|
$x++; |
|
757
|
|
|
} |
|
758
|
|
|
} |
|
759
|
|
|
} |
|
760
|
|
|
if(!empty($points)){ |
|
761
|
|
|
$this->save_custom_field(implode(' ',$points),'wetu_map_points',$id,false,true); |
|
|
|
|
|
|
762
|
|
|
} |
|
763
|
|
|
} |
|
764
|
|
|
|
|
765
|
|
|
} |
|
766
|
|
|
|
|
767
|
|
|
// CLASS SPECIFIC FUNCTIONS |
|
768
|
|
|
|
|
769
|
|
|
/** |
|
770
|
|
|
* Set the Itinerary Day |
|
771
|
|
|
*/ |
|
772
|
|
|
public function set_itinerary_day($day,$id) { |
|
773
|
|
|
$this->save_custom_field($day,'itinerary',$id,false,false); |
|
774
|
|
|
} |
|
775
|
|
|
|
|
776
|
|
|
/** |
|
777
|
|
|
* Set the price |
|
778
|
|
|
*/ |
|
779
|
|
|
public function set_price($data,$id) { |
|
780
|
|
|
//Price |
|
781
|
|
View Code Duplication |
if(isset($data['price']) && ''!== $data['price']){ |
|
|
|
|
|
|
782
|
|
|
$price = preg_replace("/[^0-9,.]/", "", $data['price']); |
|
783
|
|
|
$this->save_custom_field($price,'price',$id); |
|
784
|
|
|
} |
|
785
|
|
|
|
|
786
|
|
|
//Price includes |
|
787
|
|
|
if(isset($data['price_includes']) && ''!== $data['price_includes']){ |
|
788
|
|
|
$this->save_custom_field($data['price_includes'],'included',$id); |
|
789
|
|
|
} |
|
790
|
|
|
|
|
791
|
|
|
//Price Excludes |
|
792
|
|
|
if(isset($data['price_excludes']) && ''!== $data['price_excludes']){ |
|
793
|
|
|
$this->save_custom_field($data['price_excludes'],'not_included',$id); |
|
794
|
|
|
} |
|
795
|
|
|
|
|
796
|
|
|
} |
|
797
|
|
|
|
|
798
|
|
|
/** |
|
799
|
|
|
* Set the duration |
|
800
|
|
|
*/ |
|
801
|
|
|
public function set_duration($data,$id) { |
|
802
|
|
View Code Duplication |
if(isset($data['days']) && !empty($data['days'])){ |
|
|
|
|
|
|
803
|
|
|
$price = $data['days']; |
|
804
|
|
|
$price = preg_replace("/[^0-9,.]/", "", $price); |
|
805
|
|
|
$this->save_custom_field($price,'duration',$id); |
|
806
|
|
|
} |
|
807
|
|
|
} |
|
808
|
|
|
|
|
809
|
|
|
/** |
|
810
|
|
|
* Connects the Accommodation if its available |
|
811
|
|
|
*/ |
|
812
|
|
|
public function set_accommodation($day,$id) { |
|
813
|
|
|
|
|
814
|
|
|
$ac_id = false; |
|
815
|
|
|
$this->current_accommodation = $this->find_current_accommodation(); |
|
|
|
|
|
|
816
|
|
|
|
|
817
|
|
|
if(isset($day['content_entity_id']) && !empty($day['content_entity_id'])){ |
|
818
|
|
|
|
|
819
|
|
|
if(false !== $this->current_accommodation && !empty($this->current_accommodation) && array_key_exists($day['content_entity_id'],$this->current_accommodation)){ |
|
820
|
|
|
$ac_id = $this->current_accommodation[$day['content_entity_id']]; |
|
821
|
|
|
}else{ |
|
822
|
|
|
$ac_id = wp_insert_post(array( |
|
823
|
|
|
'post_type' => 'accommodation', |
|
824
|
|
|
'post_status' => 'draft', |
|
825
|
|
|
'post_title' => $day['content_entity_id'] |
|
826
|
|
|
)); |
|
827
|
|
|
$this->save_custom_field($day['content_entity_id'],'lsx_wetu_id',$ac_id); |
|
828
|
|
|
} |
|
829
|
|
|
|
|
830
|
|
|
if('' !== $ac_id && false !== $ac_id){ |
|
831
|
|
|
$this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false); |
|
832
|
|
|
$this->save_custom_field($id,'tour_to_accommodation',$ac_id,false,false); |
|
833
|
|
|
} |
|
834
|
|
|
} |
|
835
|
|
|
return $ac_id; |
|
836
|
|
|
} |
|
837
|
|
|
|
|
838
|
|
|
/** |
|
839
|
|
|
* Grab all the current accommodation posts via the lsx_wetu_id field. |
|
840
|
|
|
* |
|
841
|
|
|
* @param $post_type string |
|
842
|
|
|
* @return boolean / array |
|
843
|
|
|
*/ |
|
844
|
|
|
public function find_current_accommodation($post_type='accommodation') { |
|
845
|
|
|
global $wpdb; |
|
846
|
|
|
$accommodation = parent::find_current_accommodation($post_type); |
|
847
|
|
|
|
|
848
|
|
|
$return = false; |
|
849
|
|
|
if(!empty($accommodation)){ |
|
850
|
|
|
foreach($accommodation as $key => $acc){ |
|
851
|
|
|
$return[$acc->meta_value] = $acc->post_id; |
|
852
|
|
|
} |
|
853
|
|
|
} |
|
854
|
|
|
return $return; |
|
|
|
|
|
|
855
|
|
|
} |
|
856
|
|
|
|
|
857
|
|
|
/** |
|
858
|
|
|
* Grab all the current accommodation posts via the lsx_wetu_id field. |
|
859
|
|
|
* @return boolean / array |
|
860
|
|
|
*/ |
|
861
|
|
|
public function find_current_destinations() { |
|
862
|
|
|
return $this->find_current_accommodation('destination'); |
|
863
|
|
|
} |
|
864
|
|
|
|
|
865
|
|
|
/** |
|
866
|
|
|
* Connects the destinations post type |
|
867
|
|
|
* |
|
868
|
|
|
* @param $day array |
|
869
|
|
|
* @param $id string |
|
870
|
|
|
* @return boolean / string |
|
871
|
|
|
*/ |
|
872
|
|
|
public function set_destination($day,$id,$leg_counter) { |
|
873
|
|
|
$dest_id = false; |
|
874
|
|
|
$country_id = false; |
|
875
|
|
|
$this->current_destinations = $this->find_current_destinations(); |
|
|
|
|
|
|
876
|
|
|
|
|
877
|
|
|
if(isset($day['destination_content_entity_id']) && !empty($day['destination_content_entity_id'])){ |
|
878
|
|
|
|
|
879
|
|
|
if(false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($day['destination_content_entity_id'],$this->current_destinations)){ |
|
880
|
|
|
$dest_id = $this->current_destinations[$day['destination_content_entity_id']]; |
|
881
|
|
|
|
|
882
|
|
|
//Check if there is a country asigned. |
|
883
|
|
|
$potential_id = wp_get_post_parent_id($dest_id); |
|
884
|
|
|
$country_wetu_id = get_post_meta($potential_id,'lsx_wetu_id',true); |
|
885
|
|
|
if(false !== $country_wetu_id){ |
|
886
|
|
|
$country_id = $this->set_country($country_wetu_id, $id); |
|
887
|
|
|
} |
|
888
|
|
|
|
|
889
|
|
|
}else { |
|
890
|
|
|
|
|
891
|
|
|
$destination_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $day['destination_content_entity_id']); |
|
892
|
|
|
|
|
893
|
|
|
if ($destination_json) { |
|
894
|
|
|
$destination_data = json_decode($destination_json, true); |
|
895
|
|
|
|
|
896
|
|
|
if (!empty($destination_data) && !isset($destination_data['error'])) { |
|
897
|
|
|
|
|
898
|
|
|
$destination_title = $day['destination_content_entity_id']; |
|
899
|
|
|
|
|
900
|
|
|
if(isset($destination_data[0]['name'])){ |
|
901
|
|
|
$destination_title = $destination_data[0]['name']; |
|
902
|
|
|
} |
|
903
|
|
|
|
|
904
|
|
|
if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id']) |
|
905
|
|
|
&& $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){ |
|
906
|
|
|
|
|
907
|
|
|
$country_id = $this->set_country($destination_data[0]['position']['country_content_entity_id'], $id); |
|
908
|
|
|
} |
|
909
|
|
|
|
|
910
|
|
|
$dest_post = array( |
|
911
|
|
|
'post_type' => 'destination', |
|
912
|
|
|
'post_status' => 'draft', |
|
913
|
|
|
'post_title' => $destination_title |
|
914
|
|
|
); |
|
915
|
|
|
|
|
916
|
|
|
if(false !== $country_id){ |
|
917
|
|
|
$dest_post['post_parent'] = $country_id; |
|
918
|
|
|
} |
|
919
|
|
|
$dest_id = wp_insert_post($dest_post); |
|
920
|
|
|
|
|
921
|
|
|
//Make sure we register the |
|
922
|
|
|
$this->current_destinations[$day['destination_content_entity_id']] = $dest_id; |
|
923
|
|
|
|
|
924
|
|
|
$this->save_custom_field($day['destination_content_entity_id'], 'lsx_wetu_id', $dest_id); |
|
925
|
|
|
} |
|
926
|
|
|
} |
|
927
|
|
|
} |
|
928
|
|
|
|
|
929
|
|
|
if ('' !== $dest_id && false !== $dest_id) { |
|
930
|
|
|
$this->save_custom_field($dest_id, 'destination_to_tour', $id, false, false); |
|
931
|
|
|
$this->save_custom_field($id, 'tour_to_destination', $dest_id, false, false); |
|
932
|
|
|
$this->cleanup_posts[$dest_id] = 'tour_to_destination'; |
|
933
|
|
|
|
|
934
|
|
|
// Save the first destination so we can grab the tour featured image and banner |
|
935
|
|
|
if(0 === $leg_counter){ |
|
936
|
|
|
$this->destination_images[$id] = array($dest_id,$day['destination_content_entity_id']); |
|
937
|
|
|
} |
|
938
|
|
|
|
|
939
|
|
|
//Add this relation info so we can make sure certain items are set as countries. |
|
940
|
|
|
if(0 !== $country_id && false !== $country_id){ |
|
941
|
|
|
$this->relation_meta[$dest_id] = $country_id; |
|
942
|
|
|
$this->relation_meta[$country_id] = 0; |
|
943
|
|
|
}else{ |
|
944
|
|
|
$this->relation_meta[$dest_id] = 0; |
|
945
|
|
|
} |
|
946
|
|
|
} |
|
947
|
|
|
} |
|
948
|
|
|
return $dest_id; |
|
949
|
|
|
} |
|
950
|
|
|
|
|
951
|
|
|
/** |
|
952
|
|
|
* Connects the destinations post type |
|
953
|
|
|
* |
|
954
|
|
|
* @param $dest_id string |
|
955
|
|
|
* @param $country_id array |
|
956
|
|
|
* @param $id string |
|
957
|
|
|
* |
|
958
|
|
|
* @return string |
|
959
|
|
|
*/ |
|
960
|
|
|
public function set_country($country_wetu_id, $id) { |
|
961
|
|
|
$country_id = false; |
|
962
|
|
|
$this->current_destinations = $this->find_current_destinations(); |
|
|
|
|
|
|
963
|
|
|
|
|
964
|
|
|
if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) { |
|
965
|
|
|
$country_id = $this->current_destinations[$country_wetu_id]; |
|
966
|
|
|
} else { |
|
967
|
|
|
|
|
968
|
|
|
$country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id); |
|
969
|
|
|
|
|
970
|
|
|
if ($country_json) { |
|
971
|
|
|
$country_data = json_decode($country_json, true); |
|
972
|
|
|
|
|
973
|
|
|
if (!empty($country_data) && !isset($country_data['error'])) { |
|
974
|
|
|
|
|
975
|
|
|
//Format the title of the destination if its available, otherwise default to the WETU ID. |
|
976
|
|
|
$country_title = $country_wetu_id; |
|
977
|
|
|
if (isset($country_data[0]['name'])) { |
|
978
|
|
|
$country_title = $country_data[0]['name']; |
|
979
|
|
|
} |
|
980
|
|
|
|
|
981
|
|
|
$country_id = wp_insert_post(array( |
|
982
|
|
|
'post_type' => 'destination', |
|
983
|
|
|
'post_status' => 'draft', |
|
984
|
|
|
'post_title' => $country_title |
|
985
|
|
|
)); |
|
986
|
|
|
//add the country to the current destination stack |
|
987
|
|
|
$this->current_destinations[$country_wetu_id] = $country_id; |
|
988
|
|
|
|
|
989
|
|
|
//Save the wetu field |
|
990
|
|
|
$this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id); |
|
991
|
|
|
} |
|
992
|
|
|
} |
|
993
|
|
|
} |
|
994
|
|
|
|
|
995
|
|
|
if ('' !== $country_id && false !== $country_id) { |
|
996
|
|
|
$this->save_custom_field($country_id, 'destination_to_tour', $id, false, false); |
|
997
|
|
|
$this->save_custom_field($id, 'tour_to_destination', $country_id, false, false); |
|
998
|
|
|
$this->cleanup_posts[$country_id] = 'tour_to_destination'; |
|
999
|
|
|
|
|
1000
|
|
|
return $country_id; |
|
1001
|
|
|
} |
|
1002
|
|
|
} |
|
1003
|
|
|
|
|
1004
|
|
|
/** |
|
1005
|
|
|
* Connects the destinations post type |
|
1006
|
|
|
* |
|
1007
|
|
|
* @param $dest_id string |
|
1008
|
|
|
* @param $country_id array |
|
1009
|
|
|
* @param $id string |
|
1010
|
|
|
* |
|
1011
|
|
|
* @return string |
|
1012
|
|
|
*/ |
|
1013
|
|
|
public function attach_destination_images($importable_content=array()) { |
|
1014
|
|
|
if(false !== $this->destination_images){ |
|
1015
|
|
|
|
|
1016
|
|
|
foreach($this->destination_images as $tour => $destination){ |
|
|
|
|
|
|
1017
|
|
|
|
|
1018
|
|
|
$url = 'https://wetu.com/API/Pins/' . $this->api_key; |
|
1019
|
|
|
$url_qs = ''; |
|
1020
|
|
|
|
|
1021
|
|
|
$jdata = file_get_contents($url . '/Get?' . $url_qs . '&ids=' . $destination[1]); |
|
1022
|
|
|
if ($jdata) { |
|
1023
|
|
|
$adata = json_decode($jdata, true); |
|
1024
|
|
|
|
|
1025
|
|
|
if (!empty($adata)) { |
|
1026
|
|
|
$this->find_attachments($destination[0]); |
|
1027
|
|
|
|
|
1028
|
|
|
//Set the featured image |
|
1029
|
|
|
if (false !== $importable_content && in_array('featured_image', $importable_content)) { |
|
1030
|
|
|
$this->set_featured_image($adata, $tour); |
|
1031
|
|
|
} |
|
1032
|
|
|
if (false !== $importable_content && in_array('banner_image', $importable_content)) { |
|
1033
|
|
|
$this->set_banner_image($adata, $tour); |
|
1034
|
|
|
} |
|
1035
|
|
|
} |
|
1036
|
|
|
} |
|
1037
|
|
|
} |
|
1038
|
|
|
} |
|
1039
|
|
|
} |
|
1040
|
|
|
} |
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:
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: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: