1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package WETU_Importer_Accommodation |
4
|
|
|
* @author LightSpeed |
5
|
|
|
* @license GPL-2.0+ |
6
|
|
|
* @link |
7
|
|
|
* @copyright 2016 LightSpeed |
8
|
|
|
**/ |
9
|
|
|
|
10
|
|
|
class WETU_Importer_Accommodation extends WETU_Importer_Admin { |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* The url to list items from WETU |
14
|
|
|
* |
15
|
|
|
* @since 0.0.1 |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
public $tab_slug = 'accommodation'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The url to list items from WETU |
23
|
|
|
* |
24
|
|
|
* @since 0.0.1 |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
public $url = false; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Options |
32
|
|
|
* |
33
|
|
|
* @since 0.0.1 |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
public $options = false; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Initialize the plugin by setting localization, filters, and administration functions. |
41
|
|
|
* |
42
|
|
|
* @since 1.0.0 |
43
|
|
|
* |
44
|
|
|
* @access private |
45
|
|
|
*/ |
46
|
|
View Code Duplication |
public function __construct() { |
|
|
|
|
47
|
|
|
$this->set_variables(); |
48
|
|
|
|
49
|
|
|
add_action( 'lsx_tour_importer_admin_tab_'.$this->tab_slug, array($this,'display_page') ); |
50
|
|
|
add_action('wp_ajax_lsx_tour_importer',array($this,'process_ajax_search')); |
51
|
|
|
add_action('wp_ajax_nopriv_lsx_tour_importer',array($this,'process_ajax_search')); |
52
|
|
|
|
53
|
|
|
add_action('wp_ajax_lsx_import_items',array($this,'process_ajax_import')); |
54
|
|
|
add_action('wp_ajax_nopriv_lsx_import_items',array($this,'process_ajax_import')); |
55
|
|
|
|
56
|
|
|
$temp_options = get_option('_lsx-to_settings',false); |
57
|
|
|
if(false !== $temp_options && isset($temp_options[$this->plugin_slug]) && !empty($temp_options[$this->plugin_slug])){ |
58
|
|
|
$this->options = $temp_options[$this->plugin_slug]; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Sets the variables used throughout the plugin. |
64
|
|
|
*/ |
65
|
|
|
public function set_variables() |
66
|
|
|
{ |
67
|
|
|
parent::set_variables(); |
68
|
|
|
|
69
|
|
|
if(false !== $this->api_key){ |
70
|
|
|
$this->url = 'https://wetu.com/API/Pins/'.$this->api_key; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* search_form |
76
|
|
|
*/ |
77
|
|
|
public function get_scaling_url($args=array()) { |
78
|
|
|
|
79
|
|
|
$defaults = array( |
80
|
|
|
'width' => '640', |
81
|
|
|
'height' => '480', |
82
|
|
|
'cropping' => 'c' |
83
|
|
|
); |
84
|
|
|
if(false !== $this->options){ |
85
|
|
|
if(isset($this->options['width']) && '' !== $this->options['width']){ |
86
|
|
|
$defaults['width'] = $this->options['width']; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
View Code Duplication |
if(isset($this->options['height']) && '' !== $this->options['height']){ |
|
|
|
|
90
|
|
|
$defaults['height'] = $this->options['height']; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
View Code Duplication |
if(isset($this->options['cropping']) && '' !== $this->options['cropping']){ |
|
|
|
|
94
|
|
|
$defaults['cropping'] = $this->options['cropping']; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
$args = wp_parse_args($args,$defaults); |
98
|
|
|
|
99
|
|
|
$cropping = $args['cropping']; |
100
|
|
|
$width = $args['width']; |
101
|
|
|
$height = $args['height']; |
102
|
|
|
|
103
|
|
|
return 'https://wetu.com/ImageHandler/'.$cropping.$width.'x'.$height.'/'; |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Display the importer administration screen |
109
|
|
|
*/ |
110
|
|
|
public function display_page() { |
111
|
|
|
?> |
112
|
|
|
<div class="wrap"> |
113
|
|
|
<?php screen_icon(); ?> |
114
|
|
|
|
115
|
|
|
<?php $this->update_options_form(); ?> |
116
|
|
|
|
117
|
|
|
<?php $this->search_form(); ?> |
118
|
|
|
|
119
|
|
|
<form method="get" action="" id="posts-filter"> |
120
|
|
|
<input type="hidden" name="post_type" class="post_type" value="<?php echo $this->tab_slug; ?>" /> |
121
|
|
|
|
122
|
|
|
<p><input class="button button-primary add" type="button" value="<?php _e('Add to List','wetu-importer'); ?>" /> |
123
|
|
|
<input class="button button-primary clear" type="button" value="<?php _e('Clear','wetu-importer'); ?>" /> |
124
|
|
|
</p> |
125
|
|
|
|
126
|
|
|
<table class="wp-list-table widefat fixed posts"> |
127
|
|
|
<?php $this->table_header(); ?> |
|
|
|
|
128
|
|
|
|
129
|
|
|
<tbody id="the-list"> |
130
|
|
|
<tr class="post-0 type-tour status-none" id="post-0"> |
131
|
|
|
<th class="check-column" scope="row"> |
132
|
|
|
<label for="cb-select-0" class="screen-reader-text"><?php _e('Enter a title to search for and press enter','wetu-importer'); ?></label> |
133
|
|
|
</th> |
134
|
|
|
<td class="post-title page-title column-title"> |
135
|
|
|
<strong> |
136
|
|
|
<?php _e('Enter a title to search for','wetu-importer'); ?> |
137
|
|
|
</strong> |
138
|
|
|
</td> |
139
|
|
|
<td class="date column-date"> |
140
|
|
|
</td> |
141
|
|
|
<td class="ssid column-ssid"> |
142
|
|
|
</td> |
143
|
|
|
</tr> |
144
|
|
|
</tbody> |
145
|
|
|
|
146
|
|
|
<?php $this->table_footer(); ?> |
|
|
|
|
147
|
|
|
|
148
|
|
|
</table> |
149
|
|
|
|
150
|
|
|
<p><input class="button button-primary add" type="button" value="<?php _e('Add to List','wetu-importer'); ?>" /> |
151
|
|
|
<input class="button button-primary clear" type="button" value="<?php _e('Clear','wetu-importer'); ?>" /> |
152
|
|
|
</p> |
153
|
|
|
</form> |
154
|
|
|
|
155
|
|
|
<div style="display:none;" class="import-list-wrapper"> |
156
|
|
|
<br /> |
157
|
|
|
<form method="get" action="" id="import-list"> |
158
|
|
|
|
159
|
|
|
<div class="row"> |
160
|
|
|
<div style="width:30%;display:block;float:left;"> |
161
|
|
|
<h3><?php _e('What content to Sync from WETU'); ?></h3> |
162
|
|
|
<ul> |
163
|
|
|
<li><input class="content" type="checkbox" name="content[]" value="description" /> <?php _e('Description','wetu-importer'); ?></li> |
164
|
|
|
<li><input class="content" type="checkbox" name="content[]" value="excerpt" /> <?php _e('Excerpt','wetu-importer'); ?></li> |
165
|
|
|
<li><input class="content" type="checkbox" name="content[]" value="gallery" /> <?php _e('Main Gallery','wetu-importer'); ?></li> |
166
|
|
|
<li><input class="content" type="checkbox" name="content[]" value="category" /> <?php _e('Category','wetu-importer'); ?></li> |
167
|
|
|
<?php if(class_exists('TO_Maps')){ ?> |
168
|
|
|
<li><input class="content" type="checkbox" name="content[]" value="location" /> <?php _e('Location','wetu-importer'); ?></li> |
169
|
|
|
<?php } ?> |
170
|
|
|
<li><input class="content" type="checkbox" name="content[]" value="destination" /> <?php _e('Connect Destinations','wetu-importer'); ?></li> |
171
|
|
|
<li><input class="content" type="checkbox" name="content[]" value="checkin" /> <?php _e('Check In / Check Out','wetu-importer'); ?></li> |
172
|
|
|
<li><input class="content" type="checkbox" name="content[]" value="facilities" /> <?php _e('Facilities','wetu-importer'); ?></li> |
173
|
|
|
<li><input class="content" type="checkbox" name="content[]" value="friendly" /> <?php _e('Friendly','wetu-importer'); ?></li> |
174
|
|
|
<li><input class="content" type="checkbox" name="content[]" value="rating" /> <?php _e('Rating','wetu-importer'); ?></li> |
175
|
|
|
<li><input class="content" type="checkbox" name="content[]" value="rooms" /> <?php _e('Rooms','wetu-importer'); ?></li> |
176
|
|
|
<li><input class="content" type="checkbox" name="content[]" value="special_interests" /> <?php _e('Special Interests','wetu-importer'); ?></li> |
177
|
|
|
<li><input class="content" type="checkbox" name="content[]" value="spoken_languages" /> <?php _e('Spoken Languages','wetu-importer'); ?></li> |
178
|
|
|
|
179
|
|
|
<?php if(class_exists('TO_Videos')){ ?> |
180
|
|
|
<li><input class="content" type="checkbox" name="content[]" value="videos" /> <?php _e('Videos','wetu-importer'); ?></li> |
181
|
|
|
<?php } ?> |
182
|
|
|
</ul> |
183
|
|
|
<h4><?php _e('Additional Content'); ?></h4> |
184
|
|
|
<ul> |
185
|
|
|
<li><input class="content" type="checkbox" name="content[]" value="featured_image" /> <?php _e('Set Featured Image','wetu-importer'); ?></li> |
186
|
|
|
<?php if(class_exists('LSX_Banners')){ ?> |
187
|
|
|
<li><input class="content" type="checkbox" name="content[]" value="banner_image" /> <?php _e('Set Banner Image','wetu-importer'); ?></li> |
188
|
|
|
<?php } ?> |
189
|
|
|
</ul> |
190
|
|
|
</div> |
191
|
|
|
<div style="width:30%;display:block;float:left;"> |
192
|
|
|
<h3><?php _e('Assign a Team Member'); ?></h3> |
193
|
|
|
<?php $this->team_member_checkboxes(); ?> |
194
|
|
|
</div> |
195
|
|
|
|
196
|
|
|
<div style="width:30%;display:block;float:left;"> |
197
|
|
|
<h3><?php _e('Assign a Safari Brand'); ?></h3> |
198
|
|
|
<?php echo $this->taxonomy_checkboxes('accommodation-brand'); ?> |
|
|
|
|
199
|
|
|
</div> |
200
|
|
|
|
201
|
|
|
<br clear="both" /> |
202
|
|
|
</div> |
203
|
|
|
|
204
|
|
|
|
205
|
|
|
<h3><?php _e('Your List'); ?></h3> |
206
|
|
|
<table class="wp-list-table widefat fixed posts"> |
207
|
|
|
<?php $this->table_header(); ?> |
|
|
|
|
208
|
|
|
|
209
|
|
|
<tbody> |
210
|
|
|
|
211
|
|
|
</tbody> |
212
|
|
|
|
213
|
|
|
<?php $this->table_footer(); ?> |
|
|
|
|
214
|
|
|
|
215
|
|
|
</table> |
216
|
|
|
|
217
|
|
|
<p><input class="button button-primary" type="submit" value="<?php _e('Sync','wetu-importer'); ?>" /></p> |
218
|
|
|
</form> |
219
|
|
|
</div> |
220
|
|
|
|
221
|
|
|
<div style="display:none;" class="completed-list-wrapper"> |
222
|
|
|
<h3><?php _e('Completed'); ?></h3> |
223
|
|
|
<ul> |
224
|
|
|
</ul> |
225
|
|
|
</div> |
226
|
|
|
</div> |
227
|
|
|
<?php |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* search_form |
232
|
|
|
*/ |
233
|
|
View Code Duplication |
public function search_form() { |
|
|
|
|
234
|
|
|
?> |
235
|
|
|
<form class="ajax-form" id="<?php echo $this->plugin_slug; ?>-search-form" method="get" action="tools.php" data-type="<?php echo $this->tab_slug; ?>"> |
236
|
|
|
<input type="hidden" name="page" value="<?php echo $this->tab_slug; ?>" /> |
237
|
|
|
|
238
|
|
|
<h3><span class="dashicons dashicons-search"></span> <?php _e('Search','wetu-importer'); ?></h3> |
239
|
|
|
<div class="normal-search"> |
240
|
|
|
<input pattern=".{3,}" placeholder="3 characters minimum" class="keyword" name="keyword" value=""> <input class="button button-primary submit" type="submit" value="<?php _e('Search','wetu-importer'); ?>" /> |
241
|
|
|
</div> |
242
|
|
|
<div class="advanced-search hidden" style="display:none;"> |
243
|
|
|
<p><?php _e('Enter several keywords, each on a new line.','wetu-importer'); ?></p> |
244
|
|
|
<textarea rows="10" cols="40" name="bulk-keywords"></textarea> |
245
|
|
|
<input class="button button-primary submit" type="submit" value="<?php _e('Search','wetu-importer'); ?>" /> |
246
|
|
|
</div> |
247
|
|
|
|
248
|
|
|
<p> |
249
|
|
|
<a class="advanced-search-toggle" href="#"><?php _e('Bulk Search','wetu-importer'); ?></a> | |
250
|
|
|
<a class="published search-toggle" href="#publish"><?php esc_attr_e('Published','wetu-importer'); ?></a> | |
251
|
|
|
<a class="pending search-toggle" href="#pending"><?php esc_attr_e('Pending','wetu-importer'); ?></a> | |
252
|
|
|
<a class="draft search-toggle" href="#draft"><?php esc_attr_e('Draft','wetu-importer'); ?></a> | |
253
|
|
|
<a class="import search-toggle" href="#import"><?php esc_attr_e('WETU','wetu-importer'); ?></a> |
254
|
|
|
</p> |
255
|
|
|
|
256
|
|
|
<div class="ajax-loader" style="display:none;width:100%;text-align:center;"> |
257
|
|
|
<img style="width:64px;" src="<?php echo WETU_IMPORTER_URL.'assets/images/ajaxloader.gif';?>" /> |
258
|
|
|
</div> |
259
|
|
|
|
260
|
|
|
<div class="ajax-loader-small" style="display:none;width:100%;text-align:center;"> |
261
|
|
|
<img style="width:32px;" src="<?php echo WETU_IMPORTER_URL.'assets/images/ajaxloader.gif';?>" /> |
262
|
|
|
</div> |
263
|
|
|
</form> |
264
|
|
|
<?php |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* search_form |
269
|
|
|
*/ |
270
|
|
|
public function update_options_form() { |
271
|
|
|
echo '<div style="display:none;" class="wetu-status"><h3>'.__('Wetu Status','wetu-importer').'</h3>'; |
272
|
|
|
$accommodation = get_transient('lsx_ti_accommodation'); |
273
|
|
|
if('' === $accommodation || false === $accommodation || isset($_GET['refresh_accommodation'])){ |
274
|
|
|
$this->update_options(); |
275
|
|
|
} |
276
|
|
|
echo '</div>'; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Save the list of Accommodation into an option |
282
|
|
|
*/ |
283
|
|
|
public function update_options() { |
284
|
|
|
$data= file_get_contents($this->url.'/List'); |
285
|
|
|
$accommodation = json_decode($data, true); |
286
|
|
|
|
287
|
|
View Code Duplication |
if(isset($accommodation['error'])){ |
|
|
|
|
288
|
|
|
return $accommodation['error']; |
289
|
|
|
}elseif (isset($accommodation) && !empty($accommodation)) { |
290
|
|
|
set_transient('lsx_ti_accommodation',$accommodation,60*60*2); |
291
|
|
|
return true; |
292
|
|
|
} |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* Grab all the current accommodation posts via the lsx_wetu_id field. |
297
|
|
|
*/ |
298
|
|
View Code Duplication |
public function find_current_accommodation($post_type='accommodation') { |
|
|
|
|
299
|
|
|
global $wpdb; |
300
|
|
|
$return = array(); |
301
|
|
|
|
302
|
|
|
$current_accommodation = $wpdb->get_results(" |
303
|
|
|
SELECT key1.post_id,key1.meta_value |
304
|
|
|
FROM {$wpdb->postmeta} key1 |
305
|
|
|
|
306
|
|
|
INNER JOIN {$wpdb->posts} key2 |
307
|
|
|
ON key1.post_id = key2.ID |
308
|
|
|
|
309
|
|
|
WHERE key1.meta_key = 'lsx_wetu_id' |
310
|
|
|
AND key2.post_type = '{$post_type}' |
311
|
|
|
|
312
|
|
|
LIMIT 0,500 |
313
|
|
|
"); |
314
|
|
|
if(null !== $current_accommodation && !empty($current_accommodation)){ |
315
|
|
|
foreach($current_accommodation as $accom){ |
316
|
|
|
$return[$accom->meta_value] = $accom; |
317
|
|
|
} |
318
|
|
|
} |
319
|
|
|
return $return; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* Run through the accommodation grabbed from the DB. |
324
|
|
|
*/ |
325
|
|
|
public function process_ajax_search() { |
326
|
|
|
$return = false; |
327
|
|
|
if(isset($_POST['action']) && $_POST['action'] === 'lsx_tour_importer' && isset($_POST['type']) && $_POST['type'] === 'accommodation'){ |
328
|
|
|
$accommodation = get_transient('lsx_ti_accommodation'); |
329
|
|
|
|
330
|
|
|
if ( false !== $accommodation ) { |
331
|
|
|
$searched_items = false; |
332
|
|
|
|
333
|
|
View Code Duplication |
if(isset($_POST['keyword'] )) { |
|
|
|
|
334
|
|
|
$keyphrases = $_POST['keyword']; |
335
|
|
|
}else{ |
336
|
|
|
$keyphrases = array(0); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
if(!is_array($keyphrases)){ |
340
|
|
|
$keyphrases = array($keyphrases); |
341
|
|
|
} |
342
|
|
|
foreach($keyphrases as &$keyword){ |
343
|
|
|
$keyword = ltrim(rtrim($keyword)); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
|
347
|
|
|
$post_status = false; |
348
|
|
|
if(in_array('publish',$keyphrases)){ |
349
|
|
|
$post_status = 'publish'; |
350
|
|
|
} |
351
|
|
|
if(in_array('pending',$keyphrases)){ |
352
|
|
|
$post_status = 'pending'; |
353
|
|
|
} |
354
|
|
|
if(in_array('draft',$keyphrases)){ |
355
|
|
|
$post_status = 'draft'; |
356
|
|
|
} |
357
|
|
|
if(in_array('import',$keyphrases)){ |
358
|
|
|
$post_status = 'import'; |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
if (!empty($accommodation)) { |
362
|
|
|
|
363
|
|
|
$current_accommodation = $this->find_current_accommodation(); |
364
|
|
|
|
365
|
|
|
foreach($accommodation as $row_key => $row){ |
366
|
|
|
|
367
|
|
|
//If this is a current tour, add its ID to the row. |
368
|
|
|
$row['post_id'] = 0; |
369
|
|
|
if(false !== $current_accommodation && array_key_exists($row['id'], $current_accommodation)){ |
370
|
|
|
$row['post_id'] = $current_accommodation[$row['id']]->post_id; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
//If we are searching for |
374
|
|
View Code Duplication |
if(false !== $post_status){ |
|
|
|
|
375
|
|
|
|
376
|
|
|
if('import' === $post_status){ |
377
|
|
|
|
378
|
|
|
if(0 !== $row['post_id']){ |
379
|
|
|
continue; |
380
|
|
|
}else{ |
381
|
|
|
$searched_items[sanitize_title($row['name']).'-'.$row['id']] = $this->format_row($row); |
|
|
|
|
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
|
385
|
|
|
}else{ |
386
|
|
|
|
387
|
|
|
if(0 === $row['post_id']){ |
388
|
|
|
continue; |
389
|
|
|
}else{ |
390
|
|
|
$current_status = get_post_status($row['post_id']); |
391
|
|
|
if($current_status !== $post_status){ |
392
|
|
|
continue; |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
} |
396
|
|
|
$searched_items[sanitize_title($row['name']).'-'.$row['id']] = $this->format_row($row); |
|
|
|
|
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
}else{ |
400
|
|
|
//Search through each keyword. |
401
|
|
|
foreach($keyphrases as $keyphrase){ |
402
|
|
|
|
403
|
|
|
//Make sure the keyphrase is turned into an array |
404
|
|
|
$keywords = explode(" ",$keyphrase); |
405
|
|
|
if(!is_array($keywords)){ |
406
|
|
|
$keywords = array($keywords); |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
if($this->multineedle_stripos(ltrim(rtrim($row['name'])), $keywords) !== false){ |
410
|
|
|
$searched_items[sanitize_title($row['name']).'-'.$row['id']] = $this->format_row($row); |
|
|
|
|
411
|
|
|
} |
412
|
|
|
} |
413
|
|
|
} |
414
|
|
|
} |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
|
418
|
|
|
if(false !== $searched_items){ |
419
|
|
|
ksort($searched_items); |
420
|
|
|
$return = implode($searched_items); |
421
|
|
|
} |
422
|
|
|
} |
423
|
|
|
print_r($return); |
424
|
|
|
die(); |
425
|
|
|
} |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
/** |
429
|
|
|
* Does a multine search |
430
|
|
|
*/ |
431
|
|
|
public function multineedle_stripos($haystack, $needles, $offset=0) { |
432
|
|
|
$found = false; |
433
|
|
|
$needle_count = count($needles); |
434
|
|
|
foreach($needles as $needle) { |
435
|
|
|
if(false !== stripos($haystack, $needle, $offset)){ |
436
|
|
|
$found[] = true; |
437
|
|
|
} |
438
|
|
|
} |
439
|
|
|
if(false !== $found && $needle_count === count($found)){ |
440
|
|
|
return true; |
441
|
|
|
}else{ |
442
|
|
|
return false; |
443
|
|
|
} |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* Formats the row for output on the screen. |
448
|
|
|
*/ |
449
|
|
View Code Duplication |
public function format_row($row = false){ |
|
|
|
|
450
|
|
|
if(false !== $row){ |
451
|
|
|
|
452
|
|
|
$status = 'import'; |
453
|
|
|
if(0 !== $row['post_id']){ |
454
|
|
|
$status = '<a href="'.admin_url('/post.php?post='.$row['post_id'].'&action=edit').'" target="_blank">'.get_post_status($row['post_id']).'</a>'; |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
$row_html = ' |
458
|
|
|
<tr class="post-'.$row['post_id'].' type-tour" id="post-'.$row['post_id'].'"> |
459
|
|
|
<th class="check-column" scope="row"> |
460
|
|
|
<label for="cb-select-'.$row['id'].'" class="screen-reader-text">'.$row['name'].'</label> |
461
|
|
|
<input type="checkbox" data-identifier="'.$row['id'].'" value="'.$row['post_id'].'" name="post[]" id="cb-select-'.$row['id'].'"> |
462
|
|
|
</th> |
463
|
|
|
<td class="post-title page-title column-title"> |
464
|
|
|
<strong>'.$row['name'].'</strong> - '.$status.' |
465
|
|
|
</td> |
466
|
|
|
<td class="date column-date"> |
467
|
|
|
<abbr title="'.date('Y/m/d',strtotime($row['last_modified'])).'">'.date('Y/m/d',strtotime($row['last_modified'])).'</abbr><br>Last Modified |
468
|
|
|
</td> |
469
|
|
|
<td class="ssid column-ssid"> |
470
|
|
|
'.$row['id'].' |
471
|
|
|
</td> |
472
|
|
|
</tr>'; |
473
|
|
|
return $row_html; |
474
|
|
|
} |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* Connect to wetu |
479
|
|
|
*/ |
480
|
|
|
public function process_ajax_import() { |
481
|
|
|
$return = false; |
|
|
|
|
482
|
|
|
if(isset($_POST['action']) && $_POST['action'] === 'lsx_import_items' && isset($_POST['type']) && $_POST['type'] === 'accommodation' && isset($_POST['wetu_id'])){ |
483
|
|
|
|
484
|
|
|
$wetu_id = $_POST['wetu_id']; |
485
|
|
|
if(isset($_POST['post_id'])){ |
486
|
|
|
$post_id = $_POST['post_id']; |
487
|
|
|
}else{ |
488
|
|
|
$post_id = 0; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
if(isset($_POST['team_members'])){ |
492
|
|
|
$team_members = $_POST['team_members']; |
493
|
|
|
}else{ |
494
|
|
|
$team_members = false; |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
if(isset($_POST['safari_brands'])){ |
498
|
|
|
$safari_brands = $_POST['safari_brands']; |
499
|
|
|
}else{ |
500
|
|
|
$safari_brands = false; |
501
|
|
|
} |
502
|
|
|
|
503
|
|
View Code Duplication |
if(isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])){ |
|
|
|
|
504
|
|
|
$content = $_POST['content']; |
505
|
|
|
}else{ |
506
|
|
|
$content = false; |
507
|
|
|
} |
508
|
|
|
|
509
|
|
|
$jdata=file_get_contents($this->url."/Get?ids=".$wetu_id); |
510
|
|
View Code Duplication |
if($jdata) |
|
|
|
|
511
|
|
|
{ |
512
|
|
|
$adata=json_decode($jdata,true); |
513
|
|
|
if(!empty($adata)) |
514
|
|
|
{ |
515
|
|
|
$return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
516
|
|
|
$this->format_completed_row($return); |
517
|
|
|
} |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
die(); |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
} |
524
|
|
|
/** |
525
|
|
|
* Formats the row for the completed list. |
526
|
|
|
*/ |
527
|
|
|
public function format_completed_row($response){ |
528
|
|
|
echo '<li class="post-'.$response.'"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="'.get_permalink($response).'">'.get_the_title($response).'</a></li>'; |
529
|
|
|
} |
530
|
|
|
/** |
531
|
|
|
* Connect to wetu |
532
|
|
|
*/ |
533
|
|
|
public function import_row($data,$wetu_id,$id=0,$team_members=false,$importable_content=false,$safari_brands=false) { |
534
|
|
|
|
535
|
|
|
if(trim($data[0]['type'])=='Accommodation') |
536
|
|
|
{ |
537
|
|
|
$post_name = $data_post_content = $data_post_excerpt = ''; |
538
|
|
|
$post = array( |
539
|
|
|
'post_type' => 'accommodation', |
540
|
|
|
); |
541
|
|
|
|
542
|
|
|
$content_used_general_description = false; |
543
|
|
|
|
544
|
|
|
//Set the post_content |
545
|
|
View Code Duplication |
if(false !== $importable_content && in_array('description',$importable_content)){ |
|
|
|
|
546
|
|
|
if(isset($data[0]['content']['extended_description'])) |
547
|
|
|
{ |
548
|
|
|
$data_post_content = $data[0]['content']['extended_description']; |
549
|
|
|
}elseif(isset($data[0]['content']['general_description'])){ |
550
|
|
|
$data_post_content = $data[0]['content']['general_description']; |
551
|
|
|
$content_used_general_description = true; |
552
|
|
|
}elseif(isset($data[0]['content']['teaser_description'])){ |
553
|
|
|
$data_post_content = $data[0]['content']['teaser_description']; |
554
|
|
|
} |
555
|
|
|
$post['post_content'] = wp_strip_all_tags($data_post_content); |
556
|
|
|
} |
557
|
|
|
|
558
|
|
|
//set the post_excerpt |
559
|
|
|
if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
560
|
|
|
if(isset($data[0]['content']['teaser_description'])){ |
561
|
|
|
$data_post_excerpt = $data[0]['content']['teaser_description']; |
562
|
|
|
}elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){ |
563
|
|
|
$data_post_excerpt = $data[0]['content']['general_description']; |
564
|
|
|
} |
565
|
|
|
$post['post_excerpt'] = $data_post_excerpt; |
566
|
|
|
} |
567
|
|
|
|
568
|
|
View Code Duplication |
if(false !== $id && '0' !== $id){ |
|
|
|
|
569
|
|
|
$post['ID'] = $id; |
570
|
|
|
if(isset($data[0]['name'])){ |
571
|
|
|
$post['post_title'] = $data[0]['name']; |
572
|
|
|
$post['post_status'] = 'pending'; |
573
|
|
|
$post['post_name'] = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
574
|
|
|
} |
575
|
|
|
$id = wp_update_post($post); |
576
|
|
|
$prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
577
|
|
|
update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
578
|
|
|
}else{ |
579
|
|
|
|
580
|
|
|
//Set the name |
581
|
|
|
if(isset($data[0]['name'])){ |
582
|
|
|
$post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
583
|
|
|
} |
584
|
|
|
$post['post_name'] = $post_name; |
585
|
|
|
$post['post_title'] = $data[0]['name']; |
586
|
|
|
$post['post_status'] = 'pending'; |
587
|
|
|
$id = wp_insert_post($post); |
588
|
|
|
|
589
|
|
|
//Save the WETU ID and the Last date it was modified. |
590
|
|
|
if(false !== $id){ |
591
|
|
|
add_post_meta($id,'lsx_wetu_id',$wetu_id); |
592
|
|
|
add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
593
|
|
|
} |
594
|
|
|
} |
595
|
|
|
//Setup some default for use in the import |
596
|
|
View Code Duplication |
if(false !== $importable_content && (in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){ |
|
|
|
|
597
|
|
|
$this->find_attachments($id); |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
//Set the team member if it is there |
601
|
|
View Code Duplication |
if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
|
|
|
602
|
|
|
$this->set_team_member($id,$team_members); |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
//Set the safari brand |
606
|
|
|
if(false !== $safari_brands && '' !== $safari_brands){ |
607
|
|
|
$this->set_safari_brands($id,$safari_brands); |
608
|
|
|
|
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
if(false !== $importable_content && in_array('location',$importable_content)){ |
612
|
|
|
$this->set_map_data($data,$id); |
613
|
|
|
$this->set_location_taxonomy($data,$id); |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
if(post_type_exists('destination') && false !== $importable_content && in_array('destination',$importable_content)){ |
617
|
|
|
$this->connect_destinations($data,$id); |
618
|
|
|
} |
619
|
|
|
|
620
|
|
|
if(false !== $importable_content && in_array('category',$importable_content)){ |
621
|
|
|
$this->set_taxonomy_style($data,$id); |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
//Set the Room Data |
625
|
|
|
if(false !== $importable_content && in_array('rooms',$importable_content)){ |
626
|
|
|
$this->set_room_data($data,$id); |
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
//Set the rating |
630
|
|
|
if(false !== $importable_content && in_array('rating',$importable_content)){ |
631
|
|
|
$this->set_rating($data,$id); |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
//Set the checkin checkout data |
635
|
|
|
if(false !== $importable_content && in_array('checkin',$importable_content)){ |
636
|
|
|
$this->set_checkin_checkout($data,$id); |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
//Set the Spoken Languages |
640
|
|
|
if(false !== $importable_content && in_array('spoken_languages',$importable_content)){ |
641
|
|
|
$this->set_spoken_languages($data,$id); |
642
|
|
|
} |
643
|
|
|
|
644
|
|
|
//Set the friendly options |
645
|
|
|
if(false !== $importable_content && in_array('friendly',$importable_content)){ |
646
|
|
|
$this->set_friendly($data,$id); |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
//Set the special_interests |
650
|
|
|
if(false !== $importable_content && in_array('special_interests',$importable_content)){ |
651
|
|
|
$this->set_special_interests($data,$id); |
652
|
|
|
} |
653
|
|
|
|
654
|
|
|
//Import the videos |
655
|
|
|
if(false !== $importable_content && in_array('videos',$importable_content)){ |
656
|
|
|
$this->set_video_data($data,$id); |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
//Import the facilities |
660
|
|
|
if(false !== $importable_content && in_array('facilities',$importable_content)){ |
661
|
|
|
$this->set_facilities($data,$id); |
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
//Set the featured image |
665
|
|
|
if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
666
|
|
|
$this->set_featured_image($data,$id); |
667
|
|
|
} |
668
|
|
|
if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
669
|
|
|
$this->set_banner_image($data,$id); |
670
|
|
|
} |
671
|
|
|
//Import the main gallery |
672
|
|
|
if(false !== $importable_content && in_array('gallery',$importable_content)){ |
673
|
|
|
$this->create_main_gallery($data,$id); |
674
|
|
|
} |
675
|
|
|
} |
676
|
|
|
return $id; |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
/** |
680
|
|
|
* Set the team memberon each item. |
681
|
|
|
*/ |
682
|
|
View Code Duplication |
public function set_team_member($id,$team_members) { |
|
|
|
|
683
|
|
|
|
684
|
|
|
delete_post_meta($id, 'team_to_'.$this->tab_slug); |
685
|
|
|
foreach($team_members as $team){ |
686
|
|
|
add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
687
|
|
|
} |
688
|
|
|
} |
689
|
|
|
|
690
|
|
|
/** |
691
|
|
|
* Set the safari brand |
692
|
|
|
*/ |
693
|
|
|
public function set_safari_brands($id,$safari_brands) { |
694
|
|
|
foreach($safari_brands as $safari_brand){ |
695
|
|
|
wp_set_object_terms( $id, intval($safari_brand), 'accommodation-brand',true); |
696
|
|
|
} |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
/** |
700
|
|
|
* Saves the longitude and lattitude, as well as sets the map marker. |
701
|
|
|
*/ |
702
|
|
View Code Duplication |
public function set_map_data($data,$id) { |
|
|
|
|
703
|
|
|
$longitude = $latitude = $address = false; |
704
|
|
|
$zoom = '15'; |
705
|
|
|
|
706
|
|
|
if(isset($data[0]['position'])){ |
707
|
|
|
|
708
|
|
|
if(isset($data[0]['position']['driving_latitude'])){ |
709
|
|
|
$latitude = $data[0]['position']['driving_latitude']; |
710
|
|
|
}elseif(isset($data[0]['position']['latitude'])){ |
711
|
|
|
$latitude = $data[0]['position']['latitude']; |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
if(isset($data[0]['position']['driving_longitude'])){ |
715
|
|
|
$longitude = $data[0]['position']['driving_longitude']; |
716
|
|
|
}elseif(isset($data[0]['position']['longitude'])){ |
717
|
|
|
$longitude = $data[0]['position']['longitude']; |
718
|
|
|
} |
719
|
|
|
|
720
|
|
|
} |
721
|
|
|
if(isset($data[0]['content']) && isset($data[0]['content']['contact_information'])){ |
722
|
|
|
if(isset($data[0]['content']['contact_information']['address'])){ |
723
|
|
|
$address = strip_tags($data[0]['content']['contact_information']['address']); |
724
|
|
|
|
725
|
|
|
$address = explode("\n",$address); |
726
|
|
|
foreach($address as $bitkey => $bit){ |
727
|
|
|
$bit = ltrim(rtrim($bit)); |
728
|
|
|
if(false === $bit || '' === $bit || null === $bit or empty($bit)){ |
729
|
|
|
unset($address[$bitkey]); |
730
|
|
|
} |
731
|
|
|
} |
732
|
|
|
$address = implode(', ',$address); |
733
|
|
|
$address = str_replace(', , ', ', ', $address); |
734
|
|
|
} |
735
|
|
|
} |
736
|
|
|
|
737
|
|
|
|
738
|
|
|
if(false !== $longitude){ |
739
|
|
|
$location_data = array( |
740
|
|
|
'address' => $address, |
741
|
|
|
'lat' => $latitude, |
742
|
|
|
'long' => $longitude, |
743
|
|
|
'zoom' => $zoom, |
744
|
|
|
'elevation' => '', |
745
|
|
|
); |
746
|
|
|
if(false !== $id && '0' !== $id){ |
747
|
|
|
$prev = get_post_meta($id,'location',true); |
748
|
|
|
update_post_meta($id,'location',$location_data,$prev); |
749
|
|
|
}else{ |
750
|
|
|
add_post_meta($id,'location',$location_data,true); |
751
|
|
|
} |
752
|
|
|
} |
753
|
|
|
} |
754
|
|
|
/** |
755
|
|
|
* Saves the longitude and lattitude, as well as sets the map marker. |
756
|
|
|
*/ |
757
|
|
|
public function set_location_taxonomy($data,$id) { |
758
|
|
|
$taxonomy = 'location'; |
|
|
|
|
759
|
|
|
$terms = false; |
|
|
|
|
760
|
|
|
if(isset($data[0]['position'])){ |
761
|
|
|
$country_id = 0; |
762
|
|
View Code Duplication |
if(isset($data[0]['position']['country'])){ |
|
|
|
|
763
|
|
|
|
764
|
|
|
if(!$term = term_exists(trim($data[0]['position']['country']), 'location')) |
765
|
|
|
{ |
766
|
|
|
$term = wp_insert_term(trim($data[0]['position']['country']), 'location'); |
767
|
|
|
if ( is_wp_error($term) ){ |
768
|
|
|
echo $term->get_error_message(); |
769
|
|
|
} |
770
|
|
|
else { |
771
|
|
|
wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
772
|
|
|
} |
773
|
|
|
} |
774
|
|
|
else |
775
|
|
|
{ |
776
|
|
|
wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
777
|
|
|
} |
778
|
|
|
$country_id = intval($term['term_id']); |
779
|
|
|
} |
780
|
|
|
|
781
|
|
View Code Duplication |
if(isset($data[0]['position']['destination'])){ |
|
|
|
|
782
|
|
|
|
783
|
|
|
$tax_args = array('parent'=>$country_id); |
784
|
|
|
if(!$term = term_exists(trim($data[0]['position']['destination']), 'location')) |
785
|
|
|
{ |
786
|
|
|
$term = wp_insert_term(trim($data[0]['position']['destination']), 'location', $tax_args); |
787
|
|
|
if ( is_wp_error($term) ){echo $term->get_error_message();} |
788
|
|
|
else { wp_set_object_terms( $id, intval($term['term_id']), 'location',true); } |
789
|
|
|
} |
790
|
|
|
else |
791
|
|
|
{ |
792
|
|
|
wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
793
|
|
|
} |
794
|
|
|
} |
795
|
|
|
} |
796
|
|
|
} |
797
|
|
|
|
798
|
|
|
/** |
799
|
|
|
* Connects the destinations post type |
800
|
|
|
*/ |
801
|
|
|
public function connect_destinations($data,$id) { |
802
|
|
|
if(isset($data[0]['position'])){ |
803
|
|
|
$destinations = false; |
804
|
|
|
if(isset($data[0]['position']['country'])){ |
805
|
|
|
$destinations['country'] = $data[0]['position']['country']; |
806
|
|
|
} |
807
|
|
|
if(isset($data[0]['position']['destination'])){ |
808
|
|
|
$destinations['destination'] = $data[0]['position']['destination']; |
809
|
|
|
} |
810
|
|
|
|
811
|
|
|
if(false !== $destinations){ |
812
|
|
|
$prev_values = get_post_meta($id,'destination_to_accommodation',false); |
813
|
|
|
if(false === $prev_values || !is_array($prev_values)){ |
814
|
|
|
$prev_values = array(); |
815
|
|
|
} |
816
|
|
|
foreach($destinations as $key => $value){ |
|
|
|
|
817
|
|
|
$destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination'); |
818
|
|
|
if (null !== $destination) { |
819
|
|
|
if(!in_array($destination->ID,$prev_values)){ |
820
|
|
|
add_post_meta($id,'destination_to_accommodation',$destination->ID,false); |
821
|
|
|
add_post_meta($destination->ID,'accommodation_to_destination',$id,false); |
822
|
|
|
} |
823
|
|
|
} |
824
|
|
|
} |
825
|
|
|
} |
826
|
|
|
} |
827
|
|
|
} |
828
|
|
|
|
829
|
|
|
/** |
830
|
|
|
* Set the Travel Style |
831
|
|
|
*/ |
832
|
|
|
public function set_taxonomy_style($data,$id) { |
833
|
|
|
$terms = false; |
|
|
|
|
834
|
|
|
if(isset($data[0]['category'])){ |
835
|
|
|
if(!$term = term_exists(trim($data[0]['category']), 'accommodation-type')) |
836
|
|
|
{ |
837
|
|
|
$term = wp_insert_term(trim($data[0]['category']), 'accommodation-type'); |
838
|
|
|
if ( is_wp_error($term) ){echo $term->get_error_message();} |
839
|
|
|
else { wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); } |
840
|
|
|
} |
841
|
|
|
else |
842
|
|
|
{ |
843
|
|
|
wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); |
844
|
|
|
} |
845
|
|
|
} |
846
|
|
|
} |
847
|
|
|
|
848
|
|
|
/** |
849
|
|
|
* Saves the room data |
850
|
|
|
*/ |
851
|
|
|
public function set_room_data($data,$id) { |
852
|
|
|
if(!empty($data[0]['rooms']) && is_array($data[0]['rooms'])){ |
853
|
|
|
$rooms = false; |
854
|
|
|
|
855
|
|
|
foreach($data[0]['rooms'] as $room){ |
856
|
|
|
|
857
|
|
|
$temp_room = array(); |
858
|
|
|
if(isset($room['name'])){ |
859
|
|
|
$temp_room['title'] = $room['name']; |
860
|
|
|
} |
861
|
|
|
if(isset($room['description'])){ |
862
|
|
|
$temp_room['description'] = strip_tags($room['description']); |
863
|
|
|
} |
864
|
|
|
$temp_room['price'] = 0; |
865
|
|
|
$temp_room['type'] = 'room'; |
866
|
|
|
|
867
|
|
|
if(!empty($room['images']) && is_array($room['images'])){ |
868
|
|
|
$attachments_args = array( |
869
|
|
|
'post_parent' => $id, |
870
|
|
|
'post_status' => 'inherit', |
871
|
|
|
'post_type' => 'attachment', |
872
|
|
|
'order' => 'ASC', |
873
|
|
|
); |
874
|
|
|
$attachments = new WP_Query($attachments_args); |
875
|
|
|
$found_attachments = array(); |
876
|
|
|
|
877
|
|
|
if($attachments->have_posts()){ |
878
|
|
|
foreach($attachments->posts as $attachment){ |
879
|
|
|
$found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
880
|
|
|
} |
881
|
|
|
} |
882
|
|
|
|
883
|
|
|
$temp_room['gallery'] = array(); |
884
|
|
|
foreach($room['images'] as $image_data){ |
885
|
|
|
$temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments); |
|
|
|
|
886
|
|
|
} |
887
|
|
|
} |
888
|
|
|
$rooms[] = $temp_room; |
889
|
|
|
} |
890
|
|
|
|
891
|
|
|
if(false !== $id && '0' !== $id){ |
892
|
|
|
delete_post_meta($id, 'units'); |
893
|
|
|
} |
894
|
|
|
foreach($rooms as $room){ |
|
|
|
|
895
|
|
|
add_post_meta($id,'units',$room,false); |
896
|
|
|
} |
897
|
|
|
|
898
|
|
|
if(isset($data[0]['features']) && isset($data[0]['features']['rooms'])){ |
899
|
|
|
$room_count = $data[0]['features']['rooms']; |
900
|
|
|
}else{ |
901
|
|
|
$room_count = count($data[0]['rooms']); |
902
|
|
|
} |
903
|
|
|
|
904
|
|
|
if(false !== $id && '0' !== $id){ |
905
|
|
|
$prev_rooms = get_post_meta($id,'number_of_rooms',true); |
906
|
|
|
update_post_meta($id,'number_of_rooms',$room_count,$prev_rooms); |
907
|
|
|
}else{ |
908
|
|
|
add_post_meta($id,'number_of_rooms',$room_count,true); |
909
|
|
|
} |
910
|
|
|
} |
911
|
|
|
} |
912
|
|
|
|
913
|
|
|
/** |
914
|
|
|
* Set the ratings |
915
|
|
|
*/ |
916
|
|
|
public function set_rating($data,$id) { |
917
|
|
|
|
918
|
|
|
if(!empty($data[0]['features']) && isset($data[0]['features']['star_authority'])){ |
919
|
|
|
$rating_type = $data[0]['features']['star_authority']; |
920
|
|
|
}else{ |
921
|
|
|
$rating_type = 'Unspecified2'; |
922
|
|
|
} |
923
|
|
|
$this->save_custom_field($rating_type,'rating_type',$id); |
924
|
|
|
|
925
|
|
|
if(!empty($data[0]['features']) && isset($data[0]['features']['stars'])){ |
926
|
|
|
$this->save_custom_field($data[0]['features']['stars'],'rating',$id,true); |
927
|
|
|
} |
928
|
|
|
} |
929
|
|
|
|
930
|
|
|
/** |
931
|
|
|
* Set the spoken_languages |
932
|
|
|
*/ |
933
|
|
View Code Duplication |
public function set_spoken_languages($data,$id) { |
|
|
|
|
934
|
|
|
if(!empty($data[0]['features']) && isset($data[0]['features']['spoken_languages']) && !empty($data[0]['features']['spoken_languages'])){ |
935
|
|
|
$languages = false; |
936
|
|
|
foreach($data[0]['features']['spoken_languages'] as $spoken_language){ |
937
|
|
|
$languages[] = sanitize_title($spoken_language); |
938
|
|
|
} |
939
|
|
|
if(false !== $languages){ |
940
|
|
|
$this->save_custom_field($languages,'spoken_languages',$id); |
941
|
|
|
} |
942
|
|
|
} |
943
|
|
|
} |
944
|
|
|
|
945
|
|
|
/** |
946
|
|
|
* Set the friendly |
947
|
|
|
*/ |
948
|
|
View Code Duplication |
public function set_friendly($data,$id) { |
|
|
|
|
949
|
|
|
if(!empty($data[0]['features']) && isset($data[0]['features']['suggested_visitor_types']) && !empty($data[0]['features']['suggested_visitor_types'])){ |
950
|
|
|
$friendly_options = false; |
951
|
|
|
foreach($data[0]['features']['suggested_visitor_types'] as $visitor_type){ |
952
|
|
|
$friendly_options[] = sanitize_title($visitor_type); |
953
|
|
|
} |
954
|
|
|
if(false !== $friendly_options){ |
955
|
|
|
$this->save_custom_field($friendly_options,'suggested_visitor_types',$id); |
956
|
|
|
} |
957
|
|
|
} |
958
|
|
|
} |
959
|
|
|
|
960
|
|
|
/** |
961
|
|
|
* Set the special interests |
962
|
|
|
*/ |
963
|
|
View Code Duplication |
public function set_special_interests($data,$id) { |
|
|
|
|
964
|
|
|
if(!empty($data[0]['features']) && isset($data[0]['features']['special_interests']) && !empty($data[0]['features']['special_interests'])){ |
965
|
|
|
$interests = false; |
966
|
|
|
foreach($data[0]['features']['special_interests'] as $special_interest){ |
967
|
|
|
$interests[] = sanitize_title($special_interest); |
968
|
|
|
} |
969
|
|
|
if(false !== $interests){ |
970
|
|
|
$this->save_custom_field($interests,'special_interests',$id); |
971
|
|
|
} |
972
|
|
|
} |
973
|
|
|
} |
974
|
|
|
|
975
|
|
|
/** |
976
|
|
|
* Set the Check in and Check out Date |
977
|
|
|
*/ |
978
|
|
|
public function set_checkin_checkout($data,$id) { |
979
|
|
|
|
980
|
|
View Code Duplication |
if(!empty($data[0]['features']) && isset($data[0]['features']['check_in_time'])){ |
|
|
|
|
981
|
|
|
$time = str_replace('h',':',$data[0]['features']['check_in_time']); |
982
|
|
|
$time = date('h:ia',strtotime($time)); |
983
|
|
|
$this->save_custom_field($time,'checkin_time',$id); |
|
|
|
|
984
|
|
|
} |
985
|
|
View Code Duplication |
if(!empty($data[0]['features']) && isset($data[0]['features']['check_out_time'])){ |
|
|
|
|
986
|
|
|
$time = str_replace('h',':',$data[0]['features']['check_out_time']); |
987
|
|
|
$time = date('h:ia',strtotime($time)); |
988
|
|
|
$this->save_custom_field($time,'checkout_time',$id); |
|
|
|
|
989
|
|
|
} |
990
|
|
|
} |
991
|
|
|
|
992
|
|
|
/** |
993
|
|
|
* Set the Video date |
994
|
|
|
*/ |
995
|
|
|
public function set_video_data($data,$id) { |
996
|
|
|
if(!empty($data[0]['content']['youtube_videos']) && is_array($data[0]['content']['youtube_videos'])){ |
997
|
|
|
$videos = false; |
998
|
|
|
|
999
|
|
|
foreach($data[0]['content']['youtube_videos'] as $video){ |
1000
|
|
|
$temp_video = ''; |
1001
|
|
|
if(isset($video['label'])){ |
1002
|
|
|
$temp_video['title'] = $video['label']; |
1003
|
|
|
} |
1004
|
|
|
if(isset($video['description'])){ |
1005
|
|
|
$temp_video['description'] = strip_tags($video['description']); |
1006
|
|
|
} |
1007
|
|
|
if(isset($video['url'])){ |
1008
|
|
|
$temp_video['url'] = $video['url']; |
1009
|
|
|
} |
1010
|
|
|
$temp_video['thumbnail'] = ''; |
1011
|
|
|
$videos[] = $temp_video; |
1012
|
|
|
} |
1013
|
|
|
|
1014
|
|
|
if(false !== $id && '0' !== $id){ |
1015
|
|
|
delete_post_meta($id, 'videos'); |
1016
|
|
|
} |
1017
|
|
|
foreach($videos as $video){ |
|
|
|
|
1018
|
|
|
add_post_meta($id,'videos',$video,false); |
1019
|
|
|
} |
1020
|
|
|
} |
1021
|
|
|
} |
1022
|
|
|
|
1023
|
|
|
/** |
1024
|
|
|
* Set the Facilities |
1025
|
|
|
*/ |
1026
|
|
|
public function set_facilities($data,$id) { |
1027
|
|
|
|
1028
|
|
|
$parent_facilities = array( |
1029
|
|
|
'available_services' => 'Available Services', |
1030
|
|
|
'property_facilities' => 'Property Facilities', |
1031
|
|
|
'room_facilities' => 'Room Facilities', |
1032
|
|
|
'activities_on_site' => 'Activities on Site' |
1033
|
|
|
); |
1034
|
|
|
foreach($parent_facilities as $key => $label){ |
1035
|
|
|
$terms = false; |
|
|
|
|
1036
|
|
|
if(isset($data[0]['features']) && isset($data[0]['features'][$key])){ |
1037
|
|
|
$parent_id = $this->set_term($id,$label,'facility'); |
|
|
|
|
1038
|
|
|
} |
1039
|
|
|
foreach($data[0]['features'][$key] as $child_facility){ |
1040
|
|
|
$this->set_term($id,$child_facility,'facility',$parent_id); |
|
|
|
|
1041
|
|
|
} |
1042
|
|
|
} |
1043
|
|
|
} |
1044
|
|
|
|
1045
|
|
|
function set_term($id=false,$name=false,$taxonomy=false,$parent=false){ |
|
|
|
|
1046
|
|
|
if(!$term = term_exists($name, $taxonomy)) |
1047
|
|
|
{ |
1048
|
|
|
if(false !== $parent){ $parent = array('parent'=>$parent); } |
1049
|
|
|
$term = wp_insert_term(trim($name), $taxonomy,$parent); |
1050
|
|
|
if ( is_wp_error($term) ){echo $term->get_error_message();} |
1051
|
|
|
else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); } |
1052
|
|
|
} |
1053
|
|
|
else |
1054
|
|
|
{ |
1055
|
|
|
wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
1056
|
|
|
} |
1057
|
|
|
return $term['term_id']; |
1058
|
|
|
} |
1059
|
|
|
|
1060
|
|
|
/** |
1061
|
|
|
* Creates the main gallery data |
1062
|
|
|
*/ |
1063
|
|
|
public function set_featured_image($data,$id) { |
1064
|
|
|
if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
1065
|
|
|
$this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id); |
1066
|
|
|
|
1067
|
|
|
if(false !== $this->featured_image){ |
1068
|
|
|
delete_post_meta($id,'_thumbnail_id'); |
1069
|
|
|
add_post_meta($id,'_thumbnail_id',$this->featured_image,true); |
1070
|
|
|
|
1071
|
|
View Code Duplication |
if(!empty($this->gallery_meta) && !in_array($this->featured_image,$this->gallery_meta)){ |
|
|
|
|
1072
|
|
|
add_post_meta($id,'gallery',$this->featured_image,false); |
1073
|
|
|
$this->gallery_meta[] = $this->featured_image; |
1074
|
|
|
} |
1075
|
|
|
} |
1076
|
|
|
} |
1077
|
|
|
} |
1078
|
|
|
|
1079
|
|
|
/** |
1080
|
|
|
* Sets a banner image |
1081
|
|
|
*/ |
1082
|
|
|
public function set_banner_image($data,$id) { |
1083
|
|
|
if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
1084
|
|
|
$this->banner_image = $this->attach_image($data[0]['content']['images'][1],$id,array('width'=>'1920','height'=>'800','cropping'=>'c')); |
|
|
|
|
1085
|
|
|
|
1086
|
|
|
if(false !== $this->banner_image){ |
1087
|
|
|
delete_post_meta($id,'image_group'); |
1088
|
|
|
$new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image)); |
1089
|
|
|
add_post_meta($id,'image_group',$new_banner,true); |
1090
|
|
|
|
1091
|
|
View Code Duplication |
if(!empty($this->gallery_meta) && !in_array($this->banner_image,$this->gallery_meta)){ |
|
|
|
|
1092
|
|
|
add_post_meta($id,'gallery',$this->banner_image,false); |
1093
|
|
|
$this->gallery_meta[] = $this->banner_image; |
1094
|
|
|
} |
1095
|
|
|
} |
1096
|
|
|
} |
1097
|
|
|
} |
1098
|
|
|
|
1099
|
|
|
/** |
1100
|
|
|
* Creates the main gallery data |
1101
|
|
|
*/ |
1102
|
|
|
public function create_main_gallery($data,$id) { |
1103
|
|
|
|
1104
|
|
|
if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
1105
|
|
|
|
1106
|
|
|
$counter = 0; |
1107
|
|
|
foreach($data[0]['content']['images'] as $image_data){ |
1108
|
|
|
if($counter === 0 && false !== $this->featured_image){continue;} |
1109
|
|
|
if($counter === 1 && false !== $this->banner_image){continue;} |
1110
|
|
|
|
1111
|
|
|
$this->gallery_meta[] = $temp_id = $this->attach_image($image_data,$id); |
|
|
|
|
1112
|
|
|
$counter++; |
1113
|
|
|
} |
1114
|
|
|
|
1115
|
|
|
if(!empty($this->gallery_meta)){ |
1116
|
|
|
delete_post_meta($id,'gallery'); |
1117
|
|
|
foreach($this->gallery_meta as $gallery_id){ |
1118
|
|
|
if(false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)){ |
1119
|
|
|
add_post_meta($id,'gallery',$gallery_id,false); |
1120
|
|
|
} |
1121
|
|
|
} |
1122
|
|
|
} |
1123
|
|
|
} |
1124
|
|
|
} |
1125
|
|
|
|
1126
|
|
|
/** |
1127
|
|
|
* Attaches 1 image |
1128
|
|
|
*/ |
1129
|
|
|
public function attach_image($v=false,$parent_id,$image_sizes=false){ |
1130
|
|
|
if(false !== $v){ |
1131
|
|
|
$temp_fragment = explode('/',$v['url_fragment']); |
1132
|
|
|
$url_filename = $temp_fragment[count($temp_fragment)-1]; |
1133
|
|
|
$url_filename = str_replace(array('.jpg','.png','.jpeg'),'',$url_filename); |
1134
|
|
|
|
1135
|
|
|
if(in_array($url_filename,$this->found_attachments)){ |
1136
|
|
|
return array_search($url_filename,$this->found_attachments); |
1137
|
|
|
} |
1138
|
|
|
|
1139
|
|
|
$postdata=array(); |
1140
|
|
|
if(empty($v['label'])) |
1141
|
|
|
{ |
1142
|
|
|
$v['label']=''; |
1143
|
|
|
} |
1144
|
|
View Code Duplication |
if(!empty($v['description'])) |
|
|
|
|
1145
|
|
|
{ |
1146
|
|
|
$desc=wp_strip_all_tags($v['description']); |
1147
|
|
|
$posdata=array('post_excerpt'=>$desc); |
|
|
|
|
1148
|
|
|
} |
1149
|
|
View Code Duplication |
if(!empty($v['section'])) |
|
|
|
|
1150
|
|
|
{ |
1151
|
|
|
$desc=wp_strip_all_tags($v['section']); |
1152
|
|
|
$posdata=array('post_excerpt'=>$desc); |
|
|
|
|
1153
|
|
|
} |
1154
|
|
|
|
1155
|
|
|
$attachID=NULL; |
|
|
|
|
1156
|
|
|
//Resizor - add option to setting if required |
1157
|
|
|
$fragment = str_replace(' ','%20',$v['url_fragment']); |
1158
|
|
|
$url = $this->get_scaling_url($image_sizes).$fragment; |
|
|
|
|
1159
|
|
|
$attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata); |
1160
|
|
|
|
1161
|
|
|
//echo($attachID.' add image'); |
|
|
|
|
1162
|
|
|
if($attachID!=NULL) |
1163
|
|
|
{ |
1164
|
|
|
return $attachID; |
1165
|
|
|
} |
1166
|
|
|
} |
1167
|
|
|
return false; |
1168
|
|
|
} |
1169
|
|
|
public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
1170
|
|
|
|
1171
|
|
|
if ( !$url || !$post_id ) { return new WP_Error('missing', "Need a valid URL and post ID..."); } |
1172
|
|
|
|
1173
|
|
|
require_once(ABSPATH . 'wp-admin/includes/file.php'); |
1174
|
|
|
require_once(ABSPATH . 'wp-admin/includes/media.php'); |
1175
|
|
|
require_once(ABSPATH . 'wp-admin/includes/image.php'); |
1176
|
|
|
// Download file to temp location, returns full server path to temp file |
1177
|
|
|
//$tmp = download_url( $url ); |
|
|
|
|
1178
|
|
|
|
1179
|
|
|
//var_dump($tmp); |
1180
|
|
|
$tmp = tempnam("/tmp", "FOO"); |
1181
|
|
|
|
1182
|
|
|
$image = file_get_contents($url); |
1183
|
|
|
file_put_contents($tmp, $image); |
1184
|
|
|
chmod($tmp,'777'); |
1185
|
|
|
|
1186
|
|
|
preg_match('/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches); // fix file filename for query strings |
1187
|
|
|
$url_filename = basename($matches[0]); |
1188
|
|
|
$url_filename=str_replace('%20','_',$url_filename); |
1189
|
|
|
// extract filename from url for title |
1190
|
|
|
$url_type = wp_check_filetype($url_filename); // determine file type (ext and mime/type) |
1191
|
|
|
|
1192
|
|
|
// override filename if given, reconstruct server path |
1193
|
|
|
if ( !empty( $filename ) && " " != $filename ) |
1194
|
|
|
{ |
1195
|
|
|
$filename = sanitize_file_name($filename); |
1196
|
|
|
$tmppath = pathinfo( $tmp ); |
1197
|
|
|
|
1198
|
|
|
$extension = ''; |
1199
|
|
|
if(isset($tmppath['extension'])){ |
1200
|
|
|
$extension = $tmppath['extension']; |
1201
|
|
|
} |
1202
|
|
|
|
1203
|
|
|
$new = $tmppath['dirname'] . "/". $filename . "." . $extension; |
1204
|
|
|
rename($tmp, $new); // renames temp file on server |
1205
|
|
|
$tmp = $new; // push new filename (in path) to be used in file array later |
1206
|
|
|
} |
1207
|
|
|
|
1208
|
|
|
// assemble file data (should be built like $_FILES since wp_handle_sideload() will be using) |
1209
|
|
|
$file_array['tmp_name'] = $tmp; // full server path to temp file |
|
|
|
|
1210
|
|
|
|
1211
|
|
View Code Duplication |
if ( !empty( $filename) && " " != $filename ) |
|
|
|
|
1212
|
|
|
{ |
1213
|
|
|
$file_array['name'] = $filename . "." . $url_type['ext']; // user given filename for title, add original URL extension |
1214
|
|
|
} |
1215
|
|
|
else |
1216
|
|
|
{ |
1217
|
|
|
$file_array['name'] = $url_filename; // just use original URL filename |
1218
|
|
|
} |
1219
|
|
|
|
1220
|
|
|
// set additional wp_posts columns |
1221
|
|
View Code Duplication |
if ( empty( $post_data['post_title'] ) ) |
|
|
|
|
1222
|
|
|
{ |
1223
|
|
|
|
1224
|
|
|
$url_filename=str_replace('%20',' ',$url_filename); |
1225
|
|
|
|
1226
|
|
|
$post_data['post_title'] = basename($url_filename, "." . $url_type['ext']); // just use the original filename (no extension) |
1227
|
|
|
} |
1228
|
|
|
|
1229
|
|
|
// make sure gets tied to parent |
1230
|
|
|
if ( empty( $post_data['post_parent'] ) ) |
1231
|
|
|
{ |
1232
|
|
|
$post_data['post_parent'] = $post_id; |
1233
|
|
|
} |
1234
|
|
|
|
1235
|
|
|
// required libraries for media_handle_sideload |
1236
|
|
|
|
1237
|
|
|
// do the validation and storage stuff |
1238
|
|
|
$att_id = media_handle_sideload( $file_array, $post_id, null, $post_data ); // $post_data can override the items saved to wp_posts table, like post_mime_type, guid, post_parent, post_title, post_content, post_status |
1239
|
|
|
|
1240
|
|
|
// If error storing permanently, unlink |
1241
|
|
|
if ( is_wp_error($att_id) ) |
1242
|
|
|
{ |
1243
|
|
|
unlink($file_array['tmp_name']); // clean up |
1244
|
|
|
return false; // output wp_error |
1245
|
|
|
//return $att_id; // output wp_error |
1246
|
|
|
} |
1247
|
|
|
|
1248
|
|
|
return $att_id; |
1249
|
|
|
} |
1250
|
|
|
} |
1251
|
|
|
$wetu_importer_accommodation = new WETU_Importer_Accommodation(); |
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.