@@ -73,15 +73,15 @@ discard block |
||
73 | 73 | public function __construct() { |
74 | 74 | $this->set_variables(); |
75 | 75 | |
76 | - add_action( 'lsx_tour_importer_admin_tab_'.$this->tab_slug, array($this,'display_page') ); |
|
77 | - add_action('wp_ajax_lsx_tour_importer',array($this,'process_ajax_search')); |
|
78 | - add_action('wp_ajax_nopriv_lsx_tour_importer',array($this,'process_ajax_search')); |
|
76 | + add_action('lsx_tour_importer_admin_tab_'.$this->tab_slug, array($this, 'display_page')); |
|
77 | + add_action('wp_ajax_lsx_tour_importer', array($this, 'process_ajax_search')); |
|
78 | + add_action('wp_ajax_nopriv_lsx_tour_importer', array($this, 'process_ajax_search')); |
|
79 | 79 | |
80 | - add_action('wp_ajax_lsx_import_items',array($this,'process_ajax_import')); |
|
81 | - add_action('wp_ajax_nopriv_lsx_import_items',array($this,'process_ajax_import')); |
|
80 | + add_action('wp_ajax_lsx_import_items', array($this, 'process_ajax_import')); |
|
81 | + add_action('wp_ajax_nopriv_lsx_import_items', array($this, 'process_ajax_import')); |
|
82 | 82 | |
83 | - $temp_options = get_option('_lsx-to_settings',false); |
|
84 | - if(false !== $temp_options && isset($temp_options[$this->plugin_slug]) && !empty($temp_options[$this->plugin_slug])){ |
|
83 | + $temp_options = get_option('_lsx-to_settings', false); |
|
84 | + if (false !== $temp_options && isset($temp_options[$this->plugin_slug]) && !empty($temp_options[$this->plugin_slug])) { |
|
85 | 85 | $this->options = $temp_options[$this->plugin_slug]; |
86 | 86 | } |
87 | 87 | } |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | { |
94 | 94 | parent::set_variables(); |
95 | 95 | |
96 | - if ( false !== $this->api_username && false !== $this->api_password ) { |
|
96 | + if (false !== $this->api_username && false !== $this->api_password) { |
|
97 | 97 | $this->url = 'https://wetu.com/API/Itinerary/'; |
98 | - $this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password; |
|
99 | - } elseif ( false !== $this->api_key ) { |
|
100 | - $this->url = 'https://wetu.com/API/Itinerary/' . $this->api_key; |
|
98 | + $this->url_qs = 'username='.$this->api_username.'&password='.$this->api_password; |
|
99 | + } elseif (false !== $this->api_key) { |
|
100 | + $this->url = 'https://wetu.com/API/Itinerary/'.$this->api_key; |
|
101 | 101 | $this->url_qs = ''; |
102 | 102 | } |
103 | 103 | } |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | <form method="get" action="" id="posts-filter"> |
118 | 118 | <input type="hidden" name="post_type" class="post_type" value="<?php echo $this->tab_slug; ?>" /> |
119 | 119 | |
120 | - <p><input class="button button-primary add" type="button" value="<?php _e('Add to List','wetu-importer'); ?>" /> |
|
121 | - <input class="button button-primary clear" type="button" value="<?php _e('Clear','wetu-importer'); ?>" /> |
|
120 | + <p><input class="button button-primary add" type="button" value="<?php _e('Add to List', 'wetu-importer'); ?>" /> |
|
121 | + <input class="button button-primary clear" type="button" value="<?php _e('Clear', 'wetu-importer'); ?>" /> |
|
122 | 122 | </p> |
123 | 123 | |
124 | 124 | <table class="wp-list-table widefat fixed posts"> |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | <tbody id="the-list"> |
128 | 128 | <tr class="post-0 type-tour status-none" id="post-0"> |
129 | 129 | <th class="check-column" scope="row"> |
130 | - <label for="cb-select-0" class="screen-reader-text"><?php _e('Enter a title to search for and press enter','wetu-importer'); ?></label> |
|
130 | + <label for="cb-select-0" class="screen-reader-text"><?php _e('Enter a title to search for and press enter', 'wetu-importer'); ?></label> |
|
131 | 131 | </th> |
132 | 132 | <td class="post-title page-title column-title"> |
133 | 133 | <strong> |
134 | - <?php _e('Enter a title to search for','wetu-importer'); ?> |
|
134 | + <?php _e('Enter a title to search for', 'wetu-importer'); ?> |
|
135 | 135 | </strong> |
136 | 136 | </td> |
137 | 137 | <td class="date column-date"> |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | |
146 | 146 | </table> |
147 | 147 | |
148 | - <p><input class="button button-primary add" type="button" value="<?php _e('Add to List','wetu-importer'); ?>" /> |
|
149 | - <input class="button button-primary clear" type="button" value="<?php _e('Clear','wetu-importer'); ?>" /> |
|
148 | + <p><input class="button button-primary add" type="button" value="<?php _e('Add to List', 'wetu-importer'); ?>" /> |
|
149 | + <input class="button button-primary clear" type="button" value="<?php _e('Clear', 'wetu-importer'); ?>" /> |
|
150 | 150 | </p> |
151 | 151 | </form> |
152 | 152 | |
@@ -158,35 +158,35 @@ discard block |
||
158 | 158 | <div style="width:30%;display:block;float:left;"> |
159 | 159 | <h3><?php _e('What content to Sync from WETU'); ?></h3> |
160 | 160 | <ul> |
161 | - <li><input class="content" type="checkbox" name="content[]" value="description" /> <?php _e('Description','wetu-importer'); ?></li> |
|
162 | - <li><input class="content" type="checkbox" name="content[]" value="excerpt" /> <?php _e('Excerpt','wetu-importer'); ?></li> |
|
161 | + <li><input class="content" type="checkbox" name="content[]" value="description" /> <?php _e('Description', 'wetu-importer'); ?></li> |
|
162 | + <li><input class="content" type="checkbox" name="content[]" value="excerpt" /> <?php _e('Excerpt', 'wetu-importer'); ?></li> |
|
163 | 163 | |
164 | - <li><input class="content" type="checkbox" name="content[]" value="price" /> <?php _e('Price','wetu-importer'); ?></li> |
|
165 | - <li><input class="content" type="checkbox" name="content[]" value="duration" /> <?php _e('Duration','wetu-importer'); ?></li> |
|
164 | + <li><input class="content" type="checkbox" name="content[]" value="price" /> <?php _e('Price', 'wetu-importer'); ?></li> |
|
165 | + <li><input class="content" type="checkbox" name="content[]" value="duration" /> <?php _e('Duration', 'wetu-importer'); ?></li> |
|
166 | 166 | |
167 | - <li><input class="content" type="checkbox" name="content[]" value="category" /> <?php _e('Category','wetu-importer'); ?></li> |
|
167 | + <li><input class="content" type="checkbox" name="content[]" value="category" /> <?php _e('Category', 'wetu-importer'); ?></li> |
|
168 | 168 | |
169 | - <li><input class="content" type="checkbox" name="content[]" value="itineraries" /> <?php _e('Itinerary Days','wetu-importer'); ?></li> |
|
169 | + <li><input class="content" type="checkbox" name="content[]" value="itineraries" /> <?php _e('Itinerary Days', 'wetu-importer'); ?></li> |
|
170 | 170 | |
171 | - <?php if(class_exists('TO_Maps')){ ?> |
|
172 | - <li><input class="content" type="checkbox" name="content[]" value="map" /> <?php _e('Map Coordinates (generates a KML file)','wetu-importer'); ?></li> |
|
171 | + <?php if (class_exists('TO_Maps')) { ?> |
|
172 | + <li><input class="content" type="checkbox" name="content[]" value="map" /> <?php _e('Map Coordinates (generates a KML file)', 'wetu-importer'); ?></li> |
|
173 | 173 | <?php } ?> |
174 | 174 | </ul> |
175 | 175 | </div> |
176 | 176 | <div style="width:30%;display:block;float:left;"> |
177 | 177 | <h3><?php _e('Itinerary Info'); ?></h3> |
178 | 178 | <ul> |
179 | - <li><input class="content" type="checkbox" name="content[]" value="itinerary_description" /> <?php _e('Description','wetu-importer'); ?></li> |
|
180 | - <li><input class="content" type="checkbox" name="content[]" value="itinerary_gallery" /> <?php _e('Gallery','wetu-importer'); ?></li> |
|
179 | + <li><input class="content" type="checkbox" name="content[]" value="itinerary_description" /> <?php _e('Description', 'wetu-importer'); ?></li> |
|
180 | + <li><input class="content" type="checkbox" name="content[]" value="itinerary_gallery" /> <?php _e('Gallery', 'wetu-importer'); ?></li> |
|
181 | 181 | </ul> |
182 | 182 | |
183 | 183 | <h4><?php _e('Additional Content'); ?></h4> |
184 | 184 | <ul> |
185 | - <li><input class="content" type="checkbox" name="content[]" value="accommodation" /> <?php _e('Sync Accommodation','wetu-importer'); ?></li> |
|
186 | - <li><input class="content" type="checkbox" name="content[]" value="destination" /> <?php _e('Sync Destinations','wetu-importer'); ?></li> |
|
185 | + <li><input class="content" type="checkbox" name="content[]" value="accommodation" /> <?php _e('Sync Accommodation', 'wetu-importer'); ?></li> |
|
186 | + <li><input class="content" type="checkbox" name="content[]" value="destination" /> <?php _e('Sync Destinations', 'wetu-importer'); ?></li> |
|
187 | 187 | </ul> |
188 | 188 | </div> |
189 | - <?php if(class_exists('TO_Team')){ ?> |
|
189 | + <?php if (class_exists('TO_Team')) { ?> |
|
190 | 190 | <div style="width:30%;display:block;float:left;"> |
191 | 191 | <h3><?php _e('Assign a Team Member'); ?></h3> |
192 | 192 | <?php $this->team_member_checkboxes(); ?> |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | |
210 | 210 | </table> |
211 | 211 | |
212 | - <p><input class="button button-primary" type="submit" value="<?php _e('Sync','wetu-importer'); ?>" /></p> |
|
212 | + <p><input class="button button-primary" type="submit" value="<?php _e('Sync', 'wetu-importer'); ?>" /></p> |
|
213 | 213 | </form> |
214 | 214 | </div> |
215 | 215 | |
@@ -227,17 +227,17 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public function update_options_form() { |
229 | 229 | $tours = get_transient('lsx_ti_tours'); |
230 | - echo '<div class="wetu-status"><h3>'.__('Wetu Status','wetu-importer').' - '; |
|
231 | - if('' === $tours || false === $tours || isset($_GET['refresh_tours'])){ |
|
230 | + echo '<div class="wetu-status"><h3>'.__('Wetu Status', 'wetu-importer').' - '; |
|
231 | + if ('' === $tours || false === $tours || isset($_GET['refresh_tours'])) { |
|
232 | 232 | $result = $this->update_options(); |
233 | 233 | |
234 | - if(true === $result){ |
|
235 | - echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>'; |
|
236 | - }else{ |
|
234 | + if (true === $result) { |
|
235 | + echo '<span style="color:green;">'.esc_attr('Connected', 'wetu-importer').'</span>'; |
|
236 | + }else { |
|
237 | 237 | echo '<span style="color:red;">'.wp_kses_post($result).'</span>'; |
238 | 238 | } |
239 | - }else{ |
|
240 | - echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>'; |
|
239 | + }else { |
|
240 | + echo '<span style="color:green;">'.esc_attr('Connected', 'wetu-importer').'</span>'; |
|
241 | 241 | } |
242 | 242 | echo '</h3></div>'; |
243 | 243 | } |
@@ -246,13 +246,13 @@ discard block |
||
246 | 246 | * Save the list of Tours into an option |
247 | 247 | */ |
248 | 248 | public function update_options() { |
249 | - $data = file_get_contents( $this->url . '/V7/List?' . $this->url_qs . '&own=true&type=All' ); |
|
249 | + $data = file_get_contents($this->url.'/V7/List?'.$this->url_qs.'&own=true&type=All'); |
|
250 | 250 | $tours = json_decode($data, true); |
251 | 251 | |
252 | - if(isset($tours['error'])){ |
|
252 | + if (isset($tours['error'])) { |
|
253 | 253 | return $tours['error']; |
254 | 254 | }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) { |
255 | - set_transient('lsx_ti_tours',$tours['itineraries'],60*60*2); |
|
255 | + set_transient('lsx_ti_tours', $tours['itineraries'], 60 * 60 * 2); |
|
256 | 256 | return true; |
257 | 257 | } |
258 | 258 | } |
@@ -276,8 +276,8 @@ discard block |
||
276 | 276 | |
277 | 277 | LIMIT 0,500 |
278 | 278 | "); |
279 | - if(null !== $current_tours && !empty($current_tours)){ |
|
280 | - foreach($current_tours as $tour){ |
|
279 | + if (null !== $current_tours && !empty($current_tours)) { |
|
280 | + foreach ($current_tours as $tour) { |
|
281 | 281 | $return[$tour->meta_value] = $tour; |
282 | 282 | } |
283 | 283 | } |
@@ -290,36 +290,36 @@ discard block |
||
290 | 290 | public function process_ajax_search() { |
291 | 291 | $return = false; |
292 | 292 | |
293 | - if(isset($_POST['action']) && $_POST['action'] === 'lsx_tour_importer' && isset($_POST['type']) && $_POST['type'] === $this->tab_slug){ |
|
293 | + if (isset($_POST['action']) && $_POST['action'] === 'lsx_tour_importer' && isset($_POST['type']) && $_POST['type'] === $this->tab_slug) { |
|
294 | 294 | $tours = get_transient('lsx_ti_tours'); |
295 | - if ( false !== $tours) { |
|
295 | + if (false !== $tours) { |
|
296 | 296 | |
297 | 297 | $searched_items = false; |
298 | 298 | |
299 | - if(isset($_POST['keyword'] )) { |
|
299 | + if (isset($_POST['keyword'])) { |
|
300 | 300 | $keyphrases = $_POST['keyword']; |
301 | - }else{ |
|
301 | + }else { |
|
302 | 302 | $keyphrases = array(0); |
303 | 303 | } |
304 | 304 | |
305 | - if(!is_array($keyphrases)){ |
|
305 | + if (!is_array($keyphrases)) { |
|
306 | 306 | $keyphrases = array($keyphrases); |
307 | 307 | } |
308 | - foreach($keyphrases as &$keyword){ |
|
308 | + foreach ($keyphrases as &$keyword) { |
|
309 | 309 | $keyword = ltrim(rtrim($keyword)); |
310 | 310 | } |
311 | 311 | |
312 | 312 | $post_status = false; |
313 | - if(in_array('publish',$keyphrases)){ |
|
313 | + if (in_array('publish', $keyphrases)) { |
|
314 | 314 | $post_status = 'publish'; |
315 | 315 | } |
316 | - if(in_array('pending',$keyphrases)){ |
|
316 | + if (in_array('pending', $keyphrases)) { |
|
317 | 317 | $post_status = 'pending'; |
318 | 318 | } |
319 | - if(in_array('draft',$keyphrases)){ |
|
319 | + if (in_array('draft', $keyphrases)) { |
|
320 | 320 | $post_status = 'draft'; |
321 | 321 | } |
322 | - if(in_array('import',$keyphrases)){ |
|
322 | + if (in_array('import', $keyphrases)) { |
|
323 | 323 | $post_status = 'import'; |
324 | 324 | } |
325 | 325 | |
@@ -327,41 +327,41 @@ discard block |
||
327 | 327 | if (!empty($tours)) { |
328 | 328 | $current_tours = $this->find_current_tours(); |
329 | 329 | |
330 | - foreach($tours as $row_key => $row){ |
|
330 | + foreach ($tours as $row_key => $row) { |
|
331 | 331 | |
332 | - if(isset($row['is_disabled']) && true === $row['is_disabled']){ |
|
332 | + if (isset($row['is_disabled']) && true === $row['is_disabled']) { |
|
333 | 333 | continue; |
334 | 334 | } |
335 | 335 | |
336 | - if('Sample' === $row['type']){ |
|
336 | + if ('Sample' === $row['type']) { |
|
337 | 337 | continue; |
338 | 338 | } |
339 | 339 | |
340 | 340 | //If this is a current tour, add its ID to the row. |
341 | 341 | $row['post_id'] = 0; |
342 | - if(false !== $current_tours && array_key_exists($row['identifier'], $current_tours)){ |
|
342 | + if (false !== $current_tours && array_key_exists($row['identifier'], $current_tours)) { |
|
343 | 343 | $row['post_id'] = $current_tours[$row['identifier']]->post_id; |
344 | 344 | } |
345 | 345 | |
346 | 346 | //If we are searching for |
347 | - if(false !== $post_status){ |
|
347 | + if (false !== $post_status) { |
|
348 | 348 | |
349 | - if('import' === $post_status){ |
|
349 | + if ('import' === $post_status) { |
|
350 | 350 | |
351 | - if(0 !== $row['post_id']){ |
|
351 | + if (0 !== $row['post_id']) { |
|
352 | 352 | continue; |
353 | - }else{ |
|
353 | + }else { |
|
354 | 354 | $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
355 | 355 | } |
356 | 356 | |
357 | 357 | |
358 | - }else{ |
|
358 | + }else { |
|
359 | 359 | |
360 | - if(0 === $row['post_id']){ |
|
360 | + if (0 === $row['post_id']) { |
|
361 | 361 | continue; |
362 | - }else{ |
|
362 | + }else { |
|
363 | 363 | $current_status = get_post_status($row['post_id']); |
364 | - if($current_status !== $post_status){ |
|
364 | + if ($current_status !== $post_status) { |
|
365 | 365 | continue; |
366 | 366 | } |
367 | 367 | |
@@ -370,17 +370,17 @@ discard block |
||
370 | 370 | |
371 | 371 | } |
372 | 372 | |
373 | - }else{ |
|
373 | + }else { |
|
374 | 374 | //Search through each keyword. |
375 | - foreach($keyphrases as $keyphrase){ |
|
375 | + foreach ($keyphrases as $keyphrase) { |
|
376 | 376 | |
377 | 377 | //Make sure the keyphrase is turned into an array |
378 | - $keywords = explode(" ",$keyphrase); |
|
379 | - if(!is_array($keywords)){ |
|
378 | + $keywords = explode(" ", $keyphrase); |
|
379 | + if (!is_array($keywords)) { |
|
380 | 380 | $keywords = array($keywords); |
381 | 381 | } |
382 | 382 | |
383 | - if($this->multineedle_stripos(ltrim(rtrim($row['name'])), $keywords) !== false){ |
|
383 | + if ($this->multineedle_stripos(ltrim(rtrim($row['name'])), $keywords) !== false) { |
|
384 | 384 | $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
385 | 385 | } |
386 | 386 | } |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | } |
389 | 389 | } |
390 | 390 | |
391 | - if(false !== $searched_items){ |
|
391 | + if (false !== $searched_items) { |
|
392 | 392 | ksort($searched_items); |
393 | 393 | $return = implode($searched_items); |
394 | 394 | } |
@@ -401,11 +401,11 @@ discard block |
||
401 | 401 | /** |
402 | 402 | * Formats the row for output on the screen. |
403 | 403 | */ |
404 | - public function format_row($row = false){ |
|
405 | - if(false !== $row){ |
|
404 | + public function format_row($row = false) { |
|
405 | + if (false !== $row) { |
|
406 | 406 | |
407 | 407 | $status = 'import'; |
408 | - if(0 !== $row['post_id']){ |
|
408 | + if (0 !== $row['post_id']) { |
|
409 | 409 | $status = '<a href="'.admin_url('/post.php?post='.$row['post_id'].'&action=edit').'" target="_blank">'.get_post_status($row['post_id']).'</a>'; |
410 | 410 | } |
411 | 411 | |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | <strong>'.$row['name'].'</strong> - '.$status.' |
420 | 420 | </td> |
421 | 421 | <td class="date column-date"> |
422 | - <abbr title="'.date('Y/m/d',strtotime($row['last_modified'])).'">'.date('Y/m/d',strtotime($row['last_modified'])).'</abbr><br>Last Modified |
|
422 | + <abbr title="'.date('Y/m/d', strtotime($row['last_modified'])).'">'.date('Y/m/d', strtotime($row['last_modified'])).'</abbr><br>Last Modified |
|
423 | 423 | </td> |
424 | 424 | <td class="ssid column-ssid"> |
425 | 425 | '.$row['identifier'].' |
@@ -434,29 +434,29 @@ discard block |
||
434 | 434 | */ |
435 | 435 | public function process_ajax_import($force = false) { |
436 | 436 | $return = false; |
437 | - if(isset($_POST['action']) && $_POST['action'] === 'lsx_import_items' && isset($_POST['type']) && $_POST['type'] === $this->tab_slug && isset($_POST['wetu_id'])){ |
|
437 | + if (isset($_POST['action']) && $_POST['action'] === 'lsx_import_items' && isset($_POST['type']) && $_POST['type'] === $this->tab_slug && isset($_POST['wetu_id'])) { |
|
438 | 438 | |
439 | 439 | $wetu_id = $_POST['wetu_id']; |
440 | - if(isset($_POST['post_id'])){ |
|
440 | + if (isset($_POST['post_id'])) { |
|
441 | 441 | $post_id = $_POST['post_id']; |
442 | - }else{ |
|
442 | + }else { |
|
443 | 443 | $post_id = 0; |
444 | 444 | } |
445 | 445 | |
446 | - if(isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])){ |
|
446 | + if (isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])) { |
|
447 | 447 | $content = $_POST['content']; |
448 | - }else{ |
|
448 | + }else { |
|
449 | 449 | $content = false; |
450 | 450 | } |
451 | 451 | |
452 | - $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id); |
|
452 | + $jdata = file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id); |
|
453 | 453 | |
454 | - if($jdata) |
|
454 | + if ($jdata) |
|
455 | 455 | { |
456 | - $jdata=json_decode($jdata,true); |
|
457 | - if(!empty($jdata)) |
|
456 | + $jdata = json_decode($jdata, true); |
|
457 | + if (!empty($jdata)) |
|
458 | 458 | { |
459 | - $return = $this->import_row($jdata,$wetu_id,$post_id,$content); |
|
459 | + $return = $this->import_row($jdata, $wetu_id, $post_id, $content); |
|
460 | 460 | $this->format_completed_row($return); |
461 | 461 | } |
462 | 462 | } |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | * @param $data array |
472 | 472 | * @param $wetu_id string |
473 | 473 | */ |
474 | - public function import_row($data,$wetu_id,$id=0,$importable_content=false,$old1=false,$old2=false) { |
|
474 | + public function import_row($data, $wetu_id, $id = 0, $importable_content = false, $old1 = false, $old2 = false) { |
|
475 | 475 | $post_name = $data_post_content = $data_post_excerpt = ''; |
476 | 476 | $post = array( |
477 | 477 | 'post_type' => 'tour', |
@@ -479,12 +479,12 @@ discard block |
||
479 | 479 | |
480 | 480 | //Set the post_content |
481 | 481 | $content_used_general_description = false; |
482 | - if(false !== $importable_content && in_array('description',$importable_content)){ |
|
482 | + if (false !== $importable_content && in_array('description', $importable_content)) { |
|
483 | 483 | $data_post_content = ''; |
484 | 484 | |
485 | - if(isset($data['description'])){ |
|
485 | + if (isset($data['description'])) { |
|
486 | 486 | $data_post_content = $data['description']; |
487 | - }elseif(isset($data['summary'])){ |
|
487 | + }elseif (isset($data['summary'])) { |
|
488 | 488 | $data_post_content = $data['summary']; |
489 | 489 | $content_used_general_description = true; |
490 | 490 | } |
@@ -492,24 +492,24 @@ discard block |
||
492 | 492 | } |
493 | 493 | |
494 | 494 | //set the post_excerpt |
495 | - if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
496 | - if(isset($data['summary']) && false === $content_used_general_description){ |
|
495 | + if (false !== $importable_content && in_array('excerpt', $importable_content)) { |
|
496 | + if (isset($data['summary']) && false === $content_used_general_description) { |
|
497 | 497 | $post['post_excerpt'] = $data['summary']; |
498 | 498 | } |
499 | 499 | } |
500 | 500 | |
501 | 501 | //Create or update the post |
502 | - if(false !== $id && '0' !== $id){ |
|
502 | + if (false !== $id && '0' !== $id) { |
|
503 | 503 | $post['ID'] = $id; |
504 | 504 | $post['post_status'] = 'pending'; |
505 | 505 | $id = wp_update_post($post); |
506 | - $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
507 | - update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date); |
|
508 | - }else{ |
|
506 | + $prev_date = get_post_meta($id, 'lsx_wetu_modified_date', true); |
|
507 | + update_post_meta($id, 'lsx_wetu_modified_date', strtotime($data['last_modified']), $prev_date); |
|
508 | + }else { |
|
509 | 509 | |
510 | 510 | //Set the name |
511 | - if(isset($data['name'])){ |
|
512 | - $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0); |
|
511 | + if (isset($data['name'])) { |
|
512 | + $post_name = wp_unique_post_slug(sanitize_title($data['name']), $id, 'draft', 'tour', 0); |
|
513 | 513 | } |
514 | 514 | $post['post_name'] = $post_name; |
515 | 515 | $post['post_title'] = $data['name']; |
@@ -517,51 +517,51 @@ discard block |
||
517 | 517 | $id = wp_insert_post($post); |
518 | 518 | |
519 | 519 | //Save the WETU ID and the Last date it was modified. |
520 | - if(false !== $id){ |
|
521 | - add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
522 | - add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified'])); |
|
520 | + if (false !== $id) { |
|
521 | + add_post_meta($id, 'lsx_wetu_id', $wetu_id); |
|
522 | + add_post_meta($id, 'lsx_wetu_modified_date', strtotime($data['last_modified'])); |
|
523 | 523 | } |
524 | 524 | } |
525 | 525 | |
526 | 526 | |
527 | 527 | //Set the price |
528 | - if(false !== $importable_content && in_array('price',$importable_content)){ |
|
529 | - $this->set_price($data,$id); |
|
528 | + if (false !== $importable_content && in_array('price', $importable_content)) { |
|
529 | + $this->set_price($data, $id); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | //Set the Duration |
533 | - if(false !== $importable_content && in_array('duration',$importable_content)){ |
|
534 | - $this->set_duration($data,$id); |
|
533 | + if (false !== $importable_content && in_array('duration', $importable_content)) { |
|
534 | + $this->set_duration($data, $id); |
|
535 | 535 | } |
536 | 536 | |
537 | - if(in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){ |
|
538 | - $this->process_itineraries($data,$id,$importable_content); |
|
537 | + if (in_array('itineraries', $importable_content) && isset($data['legs']) && !empty($data['legs'])) { |
|
538 | + $this->process_itineraries($data, $id, $importable_content); |
|
539 | 539 | } |
540 | 540 | |
541 | - if(in_array('map',$importable_content) && isset($data['routes']) && !empty($data['routes'])){ |
|
542 | - $this->process_map_points($data,$id); |
|
541 | + if (in_array('map', $importable_content) && isset($data['routes']) && !empty($data['routes'])) { |
|
542 | + $this->process_map_points($data, $id); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | //TODO Test These |
546 | 546 | //Setup some default for use in the import |
547 | - if(false !== $importable_content && (in_array('itinerary_gallery',$importable_content) || in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){ |
|
547 | + if (false !== $importable_content && (in_array('itinerary_gallery', $importable_content) || in_array('gallery', $importable_content) || in_array('banner_image', $importable_content) || in_array('featured_image', $importable_content))) { |
|
548 | 548 | $this->find_attachments($id); |
549 | 549 | } |
550 | 550 | //Set the featured image |
551 | 551 | //TODO Test These |
552 | - if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
553 | - $this->set_featured_image($data,$id); |
|
552 | + if (false !== $importable_content && in_array('featured_image', $importable_content)) { |
|
553 | + $this->set_featured_image($data, $id); |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | //TODO Test These |
557 | - if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
558 | - $this->set_banner_image($data,$id); |
|
557 | + if (false !== $importable_content && in_array('banner_image', $importable_content)) { |
|
558 | + $this->set_banner_image($data, $id); |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | //TODO Test These |
562 | 562 | //Import the main gallery |
563 | - if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
564 | - $this->create_main_gallery($data,$id); |
|
563 | + if (false !== $importable_content && in_array('gallery', $importable_content)) { |
|
564 | + $this->create_main_gallery($data, $id); |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | return $id; |
@@ -570,135 +570,135 @@ discard block |
||
570 | 570 | /** |
571 | 571 | * A loop which runs through each leg on the tour. |
572 | 572 | */ |
573 | - public function process_itineraries($data,$id,$importable_content) { |
|
573 | + public function process_itineraries($data, $id, $importable_content) { |
|
574 | 574 | $day_counter = 1; |
575 | 575 | $leg_counter = 0; |
576 | 576 | |
577 | - delete_post_meta($id,'itinerary'); |
|
577 | + delete_post_meta($id, 'itinerary'); |
|
578 | 578 | |
579 | - if(false !== $importable_content && in_array('accommodation',$importable_content)){ |
|
580 | - delete_post_meta($id,'accommodation_to_tour'); |
|
579 | + if (false !== $importable_content && in_array('accommodation', $importable_content)) { |
|
580 | + delete_post_meta($id, 'accommodation_to_tour'); |
|
581 | 581 | } |
582 | - if(false !== $importable_content && in_array('destination',$importable_content)){ |
|
583 | - delete_post_meta($id,'destination_to_tour'); |
|
584 | - delete_post_meta($id,'departs_from'); |
|
585 | - delete_post_meta($id,'ends_in'); |
|
582 | + if (false !== $importable_content && in_array('destination', $importable_content)) { |
|
583 | + delete_post_meta($id, 'destination_to_tour'); |
|
584 | + delete_post_meta($id, 'departs_from'); |
|
585 | + delete_post_meta($id, 'ends_in'); |
|
586 | 586 | } |
587 | 587 | |
588 | 588 | $departs_from = false; |
589 | 589 | $ends_in = false; |
590 | 590 | |
591 | - foreach($data['legs'] as $leg){ |
|
591 | + foreach ($data['legs'] as $leg) { |
|
592 | 592 | |
593 | - if(isset($leg['days']) && !empty($leg['days'])){ |
|
593 | + if (isset($leg['days']) && !empty($leg['days'])) { |
|
594 | 594 | |
595 | 595 | //Itinerary Accommodation |
596 | 596 | $current_accommodation = false; |
597 | - if(false !== $importable_content && in_array('accommodation',$importable_content)){ |
|
598 | - $current_accommodation = $this->set_accommodation($leg,$id); |
|
597 | + if (false !== $importable_content && in_array('accommodation', $importable_content)) { |
|
598 | + $current_accommodation = $this->set_accommodation($leg, $id); |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | //Itinerary Destination |
602 | 602 | $current_destination = false; |
603 | - if(false !== $importable_content && in_array('destination',$importable_content)){ |
|
604 | - $current_destination = $this->set_destination($leg,$id); |
|
603 | + if (false !== $importable_content && in_array('destination', $importable_content)) { |
|
604 | + $current_destination = $this->set_destination($leg, $id); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | //If the Nights are the same mount of days in the array, then it isnt "By Destination" |
608 | - if($leg['nights'] === count($leg['days']) || 0 === $leg['itinerary_leg_id']){ |
|
608 | + if ($leg['nights'] === count($leg['days']) || 0 === $leg['itinerary_leg_id']) { |
|
609 | 609 | |
610 | - foreach($leg['days'] as $day){ |
|
610 | + foreach ($leg['days'] as $day) { |
|
611 | 611 | |
612 | 612 | $current_day = array(); |
613 | 613 | |
614 | - $current_day['title'] = esc_attr('Day ','wetu-importer').$day_counter; |
|
614 | + $current_day['title'] = esc_attr('Day ', 'wetu-importer').$day_counter; |
|
615 | 615 | |
616 | 616 | //Description |
617 | - if(false !== $importable_content && in_array('itinerary_description',$importable_content) && isset($day['notes']) && '' !== $day['notes']){ |
|
617 | + if (false !== $importable_content && in_array('itinerary_description', $importable_content) && isset($day['notes']) && '' !== $day['notes']) { |
|
618 | 618 | $current_day['description'] = strip_tags($day['notes']); |
619 | - }else{ |
|
619 | + }else { |
|
620 | 620 | $current_day['description'] = ''; |
621 | 621 | } |
622 | 622 | |
623 | 623 | //Itinerary Gallery |
624 | - if(false !== $importable_content && in_array('itinerary_gallery',$importable_content) && isset($day['images'])){ |
|
624 | + if (false !== $importable_content && in_array('itinerary_gallery', $importable_content) && isset($day['images'])) { |
|
625 | 625 | $current_day['featured_image'] = ''; |
626 | - }else{ |
|
626 | + }else { |
|
627 | 627 | $current_day['featured_image'] = ''; |
628 | 628 | } |
629 | 629 | |
630 | 630 | //Accommodation |
631 | - if(false !== $current_accommodation){ |
|
631 | + if (false !== $current_accommodation) { |
|
632 | 632 | $current_day['accommodation_to_tour'] = array($current_accommodation); |
633 | - }else{ |
|
633 | + }else { |
|
634 | 634 | $current_day['accommodation_to_tour'] = array(); |
635 | 635 | } |
636 | 636 | |
637 | 637 | //Destination |
638 | - if(false !== $current_destination){ |
|
638 | + if (false !== $current_destination) { |
|
639 | 639 | $current_day['destination_to_tour'] = array($current_destination); |
640 | - }else{ |
|
640 | + }else { |
|
641 | 641 | $current_day['destination_to_tour'] = array(); |
642 | 642 | } |
643 | 643 | |
644 | - $this->set_itinerary_day($current_day,$id); |
|
644 | + $this->set_itinerary_day($current_day, $id); |
|
645 | 645 | $day_counter++; |
646 | 646 | } |
647 | 647 | |
648 | - }else{ |
|
649 | - $day_counter = $day_counter + (int)$leg['nights']; |
|
648 | + }else { |
|
649 | + $day_counter = $day_counter + (int) $leg['nights']; |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | } |
653 | 653 | |
654 | 654 | //If we are in the first leg, and the destination was attached then save it as the departure field. |
655 | - if( 0 === $leg_counter && false !== $current_destination){ |
|
655 | + if (0 === $leg_counter && false !== $current_destination) { |
|
656 | 656 | $departs_from = $current_destination; |
657 | 657 | } |
658 | 658 | |
659 | 659 | //If its the last leg then save it as the ends in. |
660 | - if( $leg_counter === (count($data['legs'])-2) && false !== $current_destination){ |
|
660 | + if ($leg_counter === (count($data['legs']) - 2) && false !== $current_destination) { |
|
661 | 661 | $ends_in = $current_destination; |
662 | 662 | } |
663 | 663 | $leg_counter++; |
664 | 664 | } |
665 | 665 | |
666 | - if(false !== $departs_from){ |
|
667 | - add_post_meta($id,'departs_from',$departs_from,true); |
|
666 | + if (false !== $departs_from) { |
|
667 | + add_post_meta($id, 'departs_from', $departs_from, true); |
|
668 | 668 | } |
669 | - if(false !== $ends_in){ |
|
670 | - add_post_meta($id,'ends_in',$ends_in,true); |
|
669 | + if (false !== $ends_in) { |
|
670 | + add_post_meta($id, 'ends_in', $ends_in, true); |
|
671 | 671 | } |
672 | 672 | } |
673 | 673 | |
674 | 674 | /** |
675 | 675 | * Run through your routes and save the points as a KML file. |
676 | 676 | */ |
677 | - public function process_map_points($data,$id) { |
|
677 | + public function process_map_points($data, $id) { |
|
678 | 678 | |
679 | - if(!empty($data['routes'])){ |
|
679 | + if (!empty($data['routes'])) { |
|
680 | 680 | |
681 | - delete_post_meta($id,'wetu_map_points'); |
|
681 | + delete_post_meta($id, 'wetu_map_points'); |
|
682 | 682 | |
683 | 683 | $points = array(); |
684 | 684 | |
685 | - foreach($data['routes'] as $route){ |
|
685 | + foreach ($data['routes'] as $route) { |
|
686 | 686 | |
687 | 687 | |
688 | - if(isset($route['points']) && '' !== $route['points']){ |
|
688 | + if (isset($route['points']) && '' !== $route['points']) { |
|
689 | 689 | |
690 | - $temp_points = explode(';',$route['points']); |
|
690 | + $temp_points = explode(';', $route['points']); |
|
691 | 691 | $point_counter = count($temp_points); |
692 | 692 | |
693 | 693 | for ($x = 0; $x <= $point_counter; $x++) { |
694 | - $y = $x+1; |
|
694 | + $y = $x + 1; |
|
695 | 695 | $points[] = $temp_points[$x].','.$temp_points[$y]; |
696 | 696 | $x++; |
697 | 697 | } |
698 | 698 | } |
699 | 699 | } |
700 | - if(!empty($points)){ |
|
701 | - $this->save_custom_field(implode(' ',$points),'wetu_map_points',$id,false,true); |
|
700 | + if (!empty($points)) { |
|
701 | + $this->save_custom_field(implode(' ', $points), 'wetu_map_points', $id, false, true); |
|
702 | 702 | } |
703 | 703 | } |
704 | 704 | |
@@ -707,28 +707,28 @@ discard block |
||
707 | 707 | /** |
708 | 708 | * Set the Itinerary Day |
709 | 709 | */ |
710 | - public function set_itinerary_day($day,$id) { |
|
711 | - $this->save_custom_field($day,'itinerary',$id,false,false); |
|
710 | + public function set_itinerary_day($day, $id) { |
|
711 | + $this->save_custom_field($day, 'itinerary', $id, false, false); |
|
712 | 712 | } |
713 | 713 | |
714 | 714 | /** |
715 | 715 | * Set the price |
716 | 716 | */ |
717 | - public function set_price($data,$id) { |
|
718 | - if(isset($data['price']) && ''!== $data['price']){ |
|
717 | + public function set_price($data, $id) { |
|
718 | + if (isset($data['price']) && '' !== $data['price']) { |
|
719 | 719 | $price = preg_replace("/[^0-9,.]/", "", $data['price']); |
720 | - $this->save_custom_field($price,'price',$id); |
|
720 | + $this->save_custom_field($price, 'price', $id); |
|
721 | 721 | } |
722 | 722 | } |
723 | 723 | |
724 | 724 | /** |
725 | 725 | * Set the duration |
726 | 726 | */ |
727 | - public function set_duration($data,$id) { |
|
728 | - if(isset($data['days']) && !empty($data['days'])){ |
|
727 | + public function set_duration($data, $id) { |
|
728 | + if (isset($data['days']) && !empty($data['days'])) { |
|
729 | 729 | $price = $data['days']; |
730 | 730 | $price = preg_replace("/[^0-9,.]/", "", $price); |
731 | - $this->save_custom_field($price,'duration',$id); |
|
731 | + $this->save_custom_field($price, 'duration', $id); |
|
732 | 732 | } |
733 | 733 | } |
734 | 734 | |
@@ -736,27 +736,27 @@ discard block |
||
736 | 736 | /** |
737 | 737 | * Connects the Accommodation if its available |
738 | 738 | */ |
739 | - public function set_accommodation($day,$id) { |
|
739 | + public function set_accommodation($day, $id) { |
|
740 | 740 | |
741 | 741 | $ac_id = false; |
742 | 742 | $this->current_accommodation = $this->find_current_accommodation(); |
743 | 743 | |
744 | - if(isset($day['content_entity_id']) && !empty($day['content_entity_id'])){ |
|
744 | + if (isset($day['content_entity_id']) && !empty($day['content_entity_id'])) { |
|
745 | 745 | |
746 | - if(false !== $this->current_accommodation && !empty($this->current_accommodation) && array_key_exists($day['content_entity_id'],$this->current_accommodation)){ |
|
746 | + if (false !== $this->current_accommodation && !empty($this->current_accommodation) && array_key_exists($day['content_entity_id'], $this->current_accommodation)) { |
|
747 | 747 | $ac_id = $this->current_accommodation[$day['content_entity_id']]; |
748 | - }else{ |
|
748 | + }else { |
|
749 | 749 | $ac_id = wp_insert_post(array( |
750 | 750 | 'post_type' => 'accommodation', |
751 | 751 | 'post_status' => 'draft', |
752 | 752 | 'post_title' => $day['content_entity_id'] |
753 | 753 | )); |
754 | - $this->save_custom_field($day['content_entity_id'],'lsx_wetu_id',$ac_id); |
|
754 | + $this->save_custom_field($day['content_entity_id'], 'lsx_wetu_id', $ac_id); |
|
755 | 755 | } |
756 | 756 | |
757 | - if('' !== $ac_id && false !== $ac_id){ |
|
758 | - $this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false); |
|
759 | - $this->save_custom_field($id,'tour_to_accommodation',$ac_id,false,false); |
|
757 | + if ('' !== $ac_id && false !== $ac_id) { |
|
758 | + $this->save_custom_field($ac_id, 'accommodation_to_tour', $id, false, false); |
|
759 | + $this->save_custom_field($id, 'tour_to_accommodation', $ac_id, false, false); |
|
760 | 760 | } |
761 | 761 | } |
762 | 762 | return $ac_id; |
@@ -768,13 +768,13 @@ discard block |
||
768 | 768 | * @param $post_type string |
769 | 769 | * @return boolean / array |
770 | 770 | */ |
771 | - public function find_current_accommodation($post_type='accommodation') { |
|
771 | + public function find_current_accommodation($post_type = 'accommodation') { |
|
772 | 772 | global $wpdb; |
773 | 773 | $accommodation = parent::find_current_accommodation($post_type); |
774 | 774 | |
775 | 775 | $return = false; |
776 | - if(!empty($accommodation)){ |
|
777 | - foreach($accommodation as $key => $acc){ |
|
776 | + if (!empty($accommodation)) { |
|
777 | + foreach ($accommodation as $key => $acc) { |
|
778 | 778 | $return[$acc->meta_value] = $acc->post_id; |
779 | 779 | } |
780 | 780 | } |
@@ -796,25 +796,25 @@ discard block |
||
796 | 796 | * @param $id string |
797 | 797 | * @return boolean / string |
798 | 798 | */ |
799 | - public function set_destination($day,$id) { |
|
799 | + public function set_destination($day, $id) { |
|
800 | 800 | $dest_id = false; |
801 | 801 | $country_id = false; |
802 | 802 | $this->current_destinations = $this->find_current_destinations(); |
803 | 803 | |
804 | - if(isset($day['destination_content_entity_id']) && !empty($day['destination_content_entity_id'])){ |
|
804 | + if (isset($day['destination_content_entity_id']) && !empty($day['destination_content_entity_id'])) { |
|
805 | 805 | |
806 | - if(false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($day['destination_content_entity_id'],$this->current_destinations)){ |
|
806 | + if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($day['destination_content_entity_id'], $this->current_destinations)) { |
|
807 | 807 | $dest_id = $this->current_destinations[$day['destination_content_entity_id']]; |
808 | 808 | |
809 | 809 | $potential_id = wp_get_post_parent_id($dest_id); |
810 | - $country_wetu_id = get_post_meta($potential_id,'lsx_wetu_id',true); |
|
811 | - if(false !== $country_wetu_id){ |
|
810 | + $country_wetu_id = get_post_meta($potential_id, 'lsx_wetu_id', true); |
|
811 | + if (false !== $country_wetu_id) { |
|
812 | 812 | $this->set_country($country_wetu_id, $id); |
813 | 813 | } |
814 | 814 | |
815 | 815 | }else { |
816 | 816 | |
817 | - $destination_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $day['destination_content_entity_id']); |
|
817 | + $destination_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=".$day['destination_content_entity_id']); |
|
818 | 818 | |
819 | 819 | if ($destination_json) { |
820 | 820 | $destination_data = json_decode($destination_json, true); |
@@ -823,12 +823,12 @@ discard block |
||
823 | 823 | |
824 | 824 | $destination_title = $day['destination_content_entity_id']; |
825 | 825 | |
826 | - if(isset($destination_data[0]['name'])){ |
|
826 | + if (isset($destination_data[0]['name'])) { |
|
827 | 827 | $destination_title = $destination_data[0]['name']; |
828 | 828 | } |
829 | 829 | |
830 | - if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id']) |
|
831 | - && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){ |
|
830 | + if (isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id']) |
|
831 | + && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']) { |
|
832 | 832 | |
833 | 833 | $country_id = $this->set_country($destination_data[0]['position']['country_content_entity_id'], $id); |
834 | 834 | } |
@@ -839,7 +839,7 @@ discard block |
||
839 | 839 | 'post_title' => $destination_title |
840 | 840 | ); |
841 | 841 | |
842 | - if(false !== $country_id){ |
|
842 | + if (false !== $country_id) { |
|
843 | 843 | $dest_post['post_parent'] = $country_id; |
844 | 844 | } |
845 | 845 | $dest_id = wp_insert_post($dest_post); |
@@ -872,9 +872,9 @@ discard block |
||
872 | 872 | |
873 | 873 | if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) { |
874 | 874 | $country_id = $this->current_destinations[$country_wetu_id]; |
875 | - } else { |
|
875 | + }else { |
|
876 | 876 | |
877 | - $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id); |
|
877 | + $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=".$country_wetu_id); |
|
878 | 878 | |
879 | 879 | if ($country_json) { |
880 | 880 | $country_data = json_decode($country_json, true); |