@@ -97,12 +97,12 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function set_variables() { |
99 | 99 | parent::set_variables(); |
100 | - if ( false !== $this->api_key ) { |
|
101 | - $this->url = 'https://wetu.com/API/Itinerary/' . $this->api_key; |
|
100 | + if (false !== $this->api_key) { |
|
101 | + $this->url = 'https://wetu.com/API/Itinerary/'.$this->api_key; |
|
102 | 102 | $this->url_qs = ''; |
103 | 103 | } |
104 | - $tour_options = get_option( 'lsx_wetu_importer_tour_settings',false ); |
|
105 | - if ( false !== $tour_options ) { |
|
104 | + $tour_options = get_option('lsx_wetu_importer_tour_settings', false); |
|
105 | + if (false !== $tour_options) { |
|
106 | 106 | $this->tour_options = $tour_options; |
107 | 107 | } |
108 | 108 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | </div> |
127 | 127 | |
128 | 128 | <form method="get" action="" id="posts-filter"> |
129 | - <input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr( $this->tab_slug ); ?>" /> |
|
129 | + <input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr($this->tab_slug); ?>" /> |
|
130 | 130 | |
131 | 131 | <table class="wp-list-table widefat fixed posts"> |
132 | 132 | <?php $this->table_header(); ?> |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | <tbody id="the-list"> |
135 | 135 | <tr class="post-0 type-tour status-none" id="post-0"> |
136 | 136 | <th class="check-column" scope="row"> |
137 | - <label for="cb-select-0" class="screen-reader-text"><?php esc_html_e( 'Enter a title to search for and press enter','lsx-wetu-importer' ); ?></label> |
|
137 | + <label for="cb-select-0" class="screen-reader-text"><?php esc_html_e('Enter a title to search for and press enter', 'lsx-wetu-importer'); ?></label> |
|
138 | 138 | </th> |
139 | 139 | <td class="date column-date column-ref" colspan="4"> |
140 | 140 | <strong> |
141 | - <?php esc_html_e( 'Search for tours using the search form above','lsx-wetu-importer' ); ?> |
|
141 | + <?php esc_html_e('Search for tours using the search form above', 'lsx-wetu-importer'); ?> |
|
142 | 142 | </strong> |
143 | 143 | </td> |
144 | 144 | </tr> |
@@ -148,8 +148,8 @@ discard block |
||
148 | 148 | |
149 | 149 | </table> |
150 | 150 | |
151 | - <p><input class="button button-primary add" type="button" value="<?php esc_html_e( 'Add to List','lsx-wetu-importer' ); ?>" /> |
|
152 | - <input class="button button-primary clear" type="button" value="<?php esc_html_e( 'Clear','lsx-wetu-importer' ); ?>" /> |
|
151 | + <p><input class="button button-primary add" type="button" value="<?php esc_html_e('Add to List', 'lsx-wetu-importer'); ?>" /> |
|
152 | + <input class="button button-primary clear" type="button" value="<?php esc_html_e('Clear', 'lsx-wetu-importer'); ?>" /> |
|
153 | 153 | </p> |
154 | 154 | </form> |
155 | 155 | |
@@ -159,51 +159,51 @@ discard block |
||
159 | 159 | |
160 | 160 | <div class="row"> |
161 | 161 | <div class="settings-all" style="width:30%;display:block;float:left;"> |
162 | - <h3><?php esc_html_e( 'What content to Sync from WETU' ); ?></h3> |
|
162 | + <h3><?php esc_html_e('What content to Sync from WETU'); ?></h3> |
|
163 | 163 | <ul> |
164 | - <li><input class="content select-all" <?php $this->checked( $this->tour_options,'all' ); ?> type="checkbox"name="content[]" value="all" /> <?php esc_html_e( 'Select All','lsx-wetu-importer' ); ?></li> |
|
164 | + <li><input class="content select-all" <?php $this->checked($this->tour_options, 'all'); ?> type="checkbox"name="content[]" value="all" /> <?php esc_html_e('Select All', 'lsx-wetu-importer'); ?></li> |
|
165 | 165 | |
166 | - <?php if ( isset( $this->options ) && ! isset( $this->options['disable_tour_descriptions'] ) ) { ?> |
|
167 | - <li><input class="content" <?php $this->checked( $this->tour_options,'description' ); ?> type="checkbox" name="content[]" value="description" /> <?php esc_html_e( 'Description','lsx-wetu-importer' ); ?></li> |
|
166 | + <?php if (isset($this->options) && !isset($this->options['disable_tour_descriptions'])) { ?> |
|
167 | + <li><input class="content" <?php $this->checked($this->tour_options, 'description'); ?> type="checkbox" name="content[]" value="description" /> <?php esc_html_e('Description', 'lsx-wetu-importer'); ?></li> |
|
168 | 168 | <?php } ?> |
169 | 169 | |
170 | - <li><input class="content" <?php $this->checked( $this->tour_options,'price' ); ?> type="checkbox" name="content[]" value="price" /> <?php esc_html_e( 'Price','lsx-wetu-importer' ); ?></li> |
|
171 | - <li><input class="content" <?php $this->checked( $this->tour_options,'duration' ); ?> type="checkbox" name="content[]" value="duration" /> <?php esc_html_e( 'Duration','lsx-wetu-importer' ); ?></li> |
|
172 | - <li><input class="content" <?php $this->checked( $this->tour_options,'group_size' ); ?> type="checkbox" name="content[]" value="group_size" /> <?php esc_html_e( 'Group Size','lsx-wetu-importer' ); ?></li> |
|
173 | - <li><input class="content" <?php $this->checked( $this->tour_options,'category' ); ?> type="checkbox" name="content[]" value="category" /> <?php esc_html_e( 'Category','lsx-wetu-importer' ); ?></li> |
|
174 | - <li><input class="content" <?php $this->checked( $this->tour_options,'tags' ); ?> type="checkbox" name="content[]" value="tags" /> <?php esc_html_e( 'Tags','lsx-wetu-importer' ); ?></li> |
|
170 | + <li><input class="content" <?php $this->checked($this->tour_options, 'price'); ?> type="checkbox" name="content[]" value="price" /> <?php esc_html_e('Price', 'lsx-wetu-importer'); ?></li> |
|
171 | + <li><input class="content" <?php $this->checked($this->tour_options, 'duration'); ?> type="checkbox" name="content[]" value="duration" /> <?php esc_html_e('Duration', 'lsx-wetu-importer'); ?></li> |
|
172 | + <li><input class="content" <?php $this->checked($this->tour_options, 'group_size'); ?> type="checkbox" name="content[]" value="group_size" /> <?php esc_html_e('Group Size', 'lsx-wetu-importer'); ?></li> |
|
173 | + <li><input class="content" <?php $this->checked($this->tour_options, 'category'); ?> type="checkbox" name="content[]" value="category" /> <?php esc_html_e('Category', 'lsx-wetu-importer'); ?></li> |
|
174 | + <li><input class="content" <?php $this->checked($this->tour_options, 'tags'); ?> type="checkbox" name="content[]" value="tags" /> <?php esc_html_e('Tags', 'lsx-wetu-importer'); ?></li> |
|
175 | 175 | |
176 | - <li><input class="content" <?php $this->checked( $this->tour_options,'itineraries' ); ?> type="checkbox" name="content[]" value="itineraries" /> <?php esc_html_e( 'Itinerary Days','lsx-wetu-importer' ); ?></li> |
|
176 | + <li><input class="content" <?php $this->checked($this->tour_options, 'itineraries'); ?> type="checkbox" name="content[]" value="itineraries" /> <?php esc_html_e('Itinerary Days', 'lsx-wetu-importer'); ?></li> |
|
177 | 177 | </ul> |
178 | 178 | </div> |
179 | 179 | <div class="settings-all" style="width:30%;display:block;float:left;"> |
180 | - <h3><?php esc_html_e( 'Itinerary Info' ); ?></h3> |
|
180 | + <h3><?php esc_html_e('Itinerary Info'); ?></h3> |
|
181 | 181 | <ul> |
182 | - <li><input class="content" <?php $this->checked( $this->tour_options,'itinerary_description' ); ?> type="checkbox" name="content[]" value="itinerary_description" /> <?php esc_html_e( 'Description','lsx-wetu-importer' ); ?></li> |
|
183 | - <li><input class="content" <?php $this->checked( $this->tour_options,'itinerary_included' ); ?> type="checkbox" name="content[]" value="itinerary_included" /> <?php esc_html_e( 'Included','lsx-wetu-importer' ); ?></li> |
|
184 | - <li><input class="content" <?php $this->checked( $this->tour_options,'itinerary_excluded' ); ?> type="checkbox" name="content[]" value="itinerary_excluded" /> <?php esc_html_e( 'Excluded','lsx-wetu-importer' ); ?></li> |
|
182 | + <li><input class="content" <?php $this->checked($this->tour_options, 'itinerary_description'); ?> type="checkbox" name="content[]" value="itinerary_description" /> <?php esc_html_e('Description', 'lsx-wetu-importer'); ?></li> |
|
183 | + <li><input class="content" <?php $this->checked($this->tour_options, 'itinerary_included'); ?> type="checkbox" name="content[]" value="itinerary_included" /> <?php esc_html_e('Included', 'lsx-wetu-importer'); ?></li> |
|
184 | + <li><input class="content" <?php $this->checked($this->tour_options, 'itinerary_excluded'); ?> type="checkbox" name="content[]" value="itinerary_excluded" /> <?php esc_html_e('Excluded', 'lsx-wetu-importer'); ?></li> |
|
185 | 185 | </ul> |
186 | 186 | |
187 | - <h4><?php esc_html_e( 'Additional Content' ); ?></h4> |
|
187 | + <h4><?php esc_html_e('Additional Content'); ?></h4> |
|
188 | 188 | <ul> |
189 | - <li><input class="content" <?php $this->checked( $this->tour_options,'accommodation' ); ?> type="checkbox" name="content[]" value="accommodation" /> <?php esc_html_e( 'Sync Accommodation','lsx-wetu-importer' ); ?></li> |
|
190 | - <li><input class="content" <?php $this->checked( $this->tour_options,'destination' ); ?> type="checkbox" name="content[]" value="destination" /> <?php esc_html_e( 'Sync Destinations','lsx-wetu-importer' ); ?></li> |
|
191 | - <li><input class="content" <?php $this->checked( $this->tour_options,'featured_image' ); ?> type="checkbox" name="content[]" value="featured_image" /> <?php esc_html_e( 'Featured Image','lsx-wetu-importer' ); ?></li> |
|
192 | - <li><input class="content" <?php $this->checked( $this->tour_options,'banner_image' ); ?> type="checkbox" name="content[]" value="banner_image" /> <?php esc_html_e( 'Banner Image','lsx-wetu-importer' ); ?></li> |
|
189 | + <li><input class="content" <?php $this->checked($this->tour_options, 'accommodation'); ?> type="checkbox" name="content[]" value="accommodation" /> <?php esc_html_e('Sync Accommodation', 'lsx-wetu-importer'); ?></li> |
|
190 | + <li><input class="content" <?php $this->checked($this->tour_options, 'destination'); ?> type="checkbox" name="content[]" value="destination" /> <?php esc_html_e('Sync Destinations', 'lsx-wetu-importer'); ?></li> |
|
191 | + <li><input class="content" <?php $this->checked($this->tour_options, 'featured_image'); ?> type="checkbox" name="content[]" value="featured_image" /> <?php esc_html_e('Featured Image', 'lsx-wetu-importer'); ?></li> |
|
192 | + <li><input class="content" <?php $this->checked($this->tour_options, 'banner_image'); ?> type="checkbox" name="content[]" value="banner_image" /> <?php esc_html_e('Banner Image', 'lsx-wetu-importer'); ?></li> |
|
193 | 193 | </ul> |
194 | 194 | </div> |
195 | - <?php if ( class_exists( 'LSX_TO_Team' ) ) { ?> |
|
195 | + <?php if (class_exists('LSX_TO_Team')) { ?> |
|
196 | 196 | <div style="width:30%;display:block;float:left;"> |
197 | - <h3><?php esc_html_e( 'Assign a Team Member' ); ?></h3> |
|
198 | - <?php $this->team_member_checkboxes( $this->tour_options ); ?> |
|
197 | + <h3><?php esc_html_e('Assign a Team Member'); ?></h3> |
|
198 | + <?php $this->team_member_checkboxes($this->tour_options); ?> |
|
199 | 199 | </div> |
200 | 200 | <?php } ?> |
201 | 201 | |
202 | 202 | <br clear="both" /> |
203 | 203 | </div> |
204 | 204 | |
205 | - <h3><?php esc_html_e( 'Your List' ); ?></h3> |
|
206 | - <p><input class="button button-primary" type="submit" value="<?php esc_html_e( 'Sync','lsx-wetu-importer' ); ?>" /></p> |
|
205 | + <h3><?php esc_html_e('Your List'); ?></h3> |
|
206 | + <p><input class="button button-primary" type="submit" value="<?php esc_html_e('Sync', 'lsx-wetu-importer'); ?>" /></p> |
|
207 | 207 | <table class="wp-list-table widefat fixed posts"> |
208 | 208 | <?php $this->table_header(); ?> |
209 | 209 | |
@@ -215,12 +215,12 @@ discard block |
||
215 | 215 | |
216 | 216 | </table> |
217 | 217 | |
218 | - <p><input class="button button-primary" type="submit" value="<?php esc_html_e( 'Sync','lsx-wetu-importer' ); ?>" /></p> |
|
218 | + <p><input class="button button-primary" type="submit" value="<?php esc_html_e('Sync', 'lsx-wetu-importer'); ?>" /></p> |
|
219 | 219 | </form> |
220 | 220 | </div> |
221 | 221 | |
222 | 222 | <div style="display:none;" class="completed-list-wrapper"> |
223 | - <h3><?php esc_html_e( 'Completed', 'lsx-wetu-importer' ); ?> - <small><?php esc_html_e( 'Import your', 'lsx-wetu-importer' ); ?> <a href="<?php echo esc_attr( admin_url( 'admin.php' ) ); ?>?page=<?php echo esc_attr( $this->plugin_slug ); ?>&tab=accommodation"><?php esc_html_e( 'accommodation' ); ?></a> <?php esc_html_e( 'next','lsx-wetu-importer' ); ?></small></h3> |
|
223 | + <h3><?php esc_html_e('Completed', 'lsx-wetu-importer'); ?> - <small><?php esc_html_e('Import your', 'lsx-wetu-importer'); ?> <a href="<?php echo esc_attr(admin_url('admin.php')); ?>?page=<?php echo esc_attr($this->plugin_slug); ?>&tab=accommodation"><?php esc_html_e('accommodation'); ?></a> <?php esc_html_e('next', 'lsx-wetu-importer'); ?></small></h3> |
|
224 | 224 | <ul> |
225 | 225 | </ul> |
226 | 226 | </div> |
@@ -234,23 +234,23 @@ discard block |
||
234 | 234 | * @return void |
235 | 235 | */ |
236 | 236 | public function update_options_form() { |
237 | - $form_options = get_option( 'lsx_ti_tours_api_options' ); |
|
238 | - if ( false === $form_options ) { |
|
239 | - $form_options = array( 'sample' ); |
|
237 | + $form_options = get_option('lsx_ti_tours_api_options'); |
|
238 | + if (false === $form_options) { |
|
239 | + $form_options = array('sample'); |
|
240 | 240 | } |
241 | 241 | ?> |
242 | 242 | <form method="get" class="tour-refresh-form"> |
243 | - <input type="hidden" name="page" value="<?php echo esc_attr( $this->plugin_slug ); ?>" /> |
|
243 | + <input type="hidden" name="page" value="<?php echo esc_attr($this->plugin_slug); ?>" /> |
|
244 | 244 | <input type="hidden" name="tab" value="tour" /> |
245 | 245 | <input type="hidden" name="refresh_tours" value="true" /> |
246 | 246 | <input class="content" type="hidden" name="own" value="true" /> |
247 | 247 | |
248 | 248 | <select name="type"> |
249 | - <option <?php if ( in_array( 'allitineraries', $form_options ) ) { echo esc_attr( 'selected="selected"' ); } ?> value="allitineraries"><?php esc_html_e( 'All Itineraries','lsx-wetu-importer' ); ?></option> |
|
250 | - <option <?php if ( in_array( 'sample', $form_options ) ) { echo esc_attr( 'selected="selected"' ); } ?>value="sample"><?php esc_html_e( 'Sample','lsx-wetu-importer' ); ?></option> |
|
251 | - <option <?php if ( in_array( 'personal', $form_options ) ) { echo esc_attr( 'selected="selected"' ); } ?>value="personal"><?php esc_html_e( 'Personal','lsx-wetu-importer' ); ?></option> |
|
249 | + <option <?php if (in_array('allitineraries', $form_options)) { echo esc_attr('selected="selected"'); } ?> value="allitineraries"><?php esc_html_e('All Itineraries', 'lsx-wetu-importer'); ?></option> |
|
250 | + <option <?php if (in_array('sample', $form_options)) { echo esc_attr('selected="selected"'); } ?>value="sample"><?php esc_html_e('Sample', 'lsx-wetu-importer'); ?></option> |
|
251 | + <option <?php if (in_array('personal', $form_options)) { echo esc_attr('selected="selected"'); } ?>value="personal"><?php esc_html_e('Personal', 'lsx-wetu-importer'); ?></option> |
|
252 | 252 | </select> |
253 | - <input class="button submit" type="submit" value="<?php esc_attr_e( 'Refresh', 'lsx-wetu-importer' ); ?>" /> |
|
253 | + <input class="button submit" type="submit" value="<?php esc_attr_e('Refresh', 'lsx-wetu-importer'); ?>" /> |
|
254 | 254 | </form> |
255 | 255 | <?php |
256 | 256 | } |
@@ -275,9 +275,9 @@ discard block |
||
275 | 275 | LIMIT 0,500 |
276 | 276 | "); |
277 | 277 | |
278 | - if ( null !== $current_tours && ! empty( $current_tours ) ) { |
|
279 | - foreach ( $current_tours as $tour ) { |
|
280 | - $return[ $tour->meta_value ] = $tour; |
|
278 | + if (null !== $current_tours && !empty($current_tours)) { |
|
279 | + foreach ($current_tours as $tour) { |
|
280 | + $return[$tour->meta_value] = $tour; |
|
281 | 281 | } |
282 | 282 | } |
283 | 283 | |
@@ -289,45 +289,45 @@ discard block |
||
289 | 289 | */ |
290 | 290 | public function process_ajax_search() { |
291 | 291 | $return = false; |
292 | - check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
292 | + check_ajax_referer('lsx_wetu_ajax_action', 'security'); |
|
293 | 293 | |
294 | - if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug ) { |
|
295 | - $tours = get_transient( 'lsx_ti_tours' ); |
|
294 | + if (isset($_POST['action']) && 'lsx_tour_importer' === $_POST['action'] && isset($_POST['type']) && $_POST['type'] === $this->tab_slug) { |
|
295 | + $tours = get_transient('lsx_ti_tours'); |
|
296 | 296 | |
297 | - if ( false !== $tours ) { |
|
297 | + if (false !== $tours) { |
|
298 | 298 | $searched_items = false; |
299 | - if ( isset( $_POST['keyword'] ) ) { |
|
300 | - $keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) ); |
|
301 | - } else { |
|
302 | - $keyphrases = array( 0 ); |
|
299 | + if (isset($_POST['keyword'])) { |
|
300 | + $keyphrases = array_map('sanitize_text_field', wp_unslash($_POST['keyword'])); |
|
301 | + }else { |
|
302 | + $keyphrases = array(0); |
|
303 | 303 | } |
304 | 304 | |
305 | - if ( ! is_array( $keyphrases ) ) { |
|
306 | - $keyphrases = array( $keyphrases ); |
|
305 | + if (!is_array($keyphrases)) { |
|
306 | + $keyphrases = array($keyphrases); |
|
307 | 307 | } |
308 | - foreach ( $keyphrases as &$keyword ) { |
|
309 | - $keyword = ltrim( rtrim( $keyword ) ); |
|
308 | + foreach ($keyphrases as &$keyword) { |
|
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 | |
326 | - if ( ! empty( $tours ) ) { |
|
326 | + if (!empty($tours)) { |
|
327 | 327 | $current_tours = $this->find_current_tours(); |
328 | 328 | |
329 | - foreach ( $tours as $row_key => $row ) { |
|
330 | - if ( isset( $row['is_disabled'] ) && true === $row['is_disabled'] ) { |
|
329 | + foreach ($tours as $row_key => $row) { |
|
330 | + if (isset($row['is_disabled']) && true === $row['is_disabled']) { |
|
331 | 331 | continue; |
332 | 332 | } |
333 | 333 | |
@@ -338,60 +338,60 @@ discard block |
||
338 | 338 | //If this is a current tour, add its ID to the row. |
339 | 339 | $row['post_id'] = 0; |
340 | 340 | |
341 | - if ( false !== $current_tours && array_key_exists( $row['identifier'], $current_tours ) ) { |
|
342 | - $row['post_id'] = $current_tours[ $row['identifier'] ]->post_id; |
|
341 | + if (false !== $current_tours && array_key_exists($row['identifier'], $current_tours)) { |
|
342 | + $row['post_id'] = $current_tours[$row['identifier']]->post_id; |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | //If we are searching for |
346 | - if ( false !== $post_status ) { |
|
347 | - if ( 'import' === $post_status ) { |
|
346 | + if (false !== $post_status) { |
|
347 | + if ('import' === $post_status) { |
|
348 | 348 | |
349 | - if ( 0 !== $row['post_id'] ) { |
|
349 | + if (0 !== $row['post_id']) { |
|
350 | 350 | continue; |
351 | - } else { |
|
352 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row ); |
|
351 | + }else { |
|
352 | + $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
|
353 | 353 | } |
354 | - } else { |
|
355 | - if ( 0 === $row['post_id'] ) { |
|
354 | + }else { |
|
355 | + if (0 === $row['post_id']) { |
|
356 | 356 | continue; |
357 | - } else { |
|
358 | - $current_status = get_post_status( $row['post_id'] ); |
|
357 | + }else { |
|
358 | + $current_status = get_post_status($row['post_id']); |
|
359 | 359 | |
360 | - if ( $current_status !== $post_status ) { |
|
360 | + if ($current_status !== $post_status) { |
|
361 | 361 | continue; |
362 | 362 | } |
363 | 363 | } |
364 | 364 | |
365 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row ); |
|
365 | + $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
|
366 | 366 | } |
367 | - } else { |
|
367 | + }else { |
|
368 | 368 | // Search through each keyword. |
369 | - foreach ( $keyphrases as $keyphrase ) { |
|
369 | + foreach ($keyphrases as $keyphrase) { |
|
370 | 370 | |
371 | 371 | // Make sure the keyphrase is turned into an array. |
372 | - $keywords = explode( ' ',$keyphrase ); |
|
373 | - if ( ! is_array( $keywords ) ) { |
|
374 | - $keywords = array( $keywords ); |
|
372 | + $keywords = explode(' ', $keyphrase); |
|
373 | + if (!is_array($keywords)) { |
|
374 | + $keywords = array($keywords); |
|
375 | 375 | } |
376 | 376 | |
377 | - if ( $this->multineedle_stripos( ltrim( rtrim( $row['name'] ) ), $keywords ) !== false ) { |
|
378 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row ); |
|
379 | - } else if ( $this->multineedle_stripos( ltrim( rtrim( $row['reference_number'] ) ), $keywords ) !== false ) { |
|
380 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row ); |
|
381 | - } else if ( $this->multineedle_stripos( ltrim( rtrim( $row['identifier_key'] ) ), $keywords ) !== false ) { |
|
382 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row ); |
|
377 | + if ($this->multineedle_stripos(ltrim(rtrim($row['name'])), $keywords) !== false) { |
|
378 | + $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
|
379 | + }else if ($this->multineedle_stripos(ltrim(rtrim($row['reference_number'])), $keywords) !== false) { |
|
380 | + $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
|
381 | + }else if ($this->multineedle_stripos(ltrim(rtrim($row['identifier_key'])), $keywords) !== false) { |
|
382 | + $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
|
383 | 383 | } |
384 | 384 | } |
385 | 385 | } |
386 | 386 | } |
387 | 387 | } |
388 | 388 | |
389 | - if ( false !== $searched_items ) { |
|
390 | - ksort( $searched_items ); |
|
391 | - $return = implode( $searched_items ); |
|
389 | + if (false !== $searched_items) { |
|
390 | + ksort($searched_items); |
|
391 | + $return = implode($searched_items); |
|
392 | 392 | } |
393 | 393 | } |
394 | - print_r( $return ); |
|
394 | + print_r($return); |
|
395 | 395 | die(); |
396 | 396 | } |
397 | 397 | } |
@@ -399,31 +399,31 @@ discard block |
||
399 | 399 | /** |
400 | 400 | * Formats the row for output on the screen. |
401 | 401 | */ |
402 | - public function format_row( $row = false ) { |
|
403 | - if ( false !== $row ) { |
|
402 | + public function format_row($row = false) { |
|
403 | + if (false !== $row) { |
|
404 | 404 | $status = 'import'; |
405 | 405 | |
406 | - if ( 0 !== $row['post_id'] ) { |
|
407 | - $status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>'; |
|
406 | + if (0 !== $row['post_id']) { |
|
407 | + $status = '<a href="'.admin_url('/post.php?post='.$row['post_id'].'&action=edit').'" target="_blank">'.get_post_status($row['post_id']).'</a>'; |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | $row_html = ' |
411 | - <tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '"> |
|
411 | + <tr class="post-' . $row['post_id'].' type-tour" id="post-'.$row['post_id'].'"> |
|
412 | 412 | <th class="check-column" scope="row"> |
413 | - <label for="cb-select-' . $row['identifier'] . '" class="screen-reader-text">' . $row['name'] . '</label> |
|
414 | - <input type="checkbox" data-identifier="' . $row['identifier'] . '" value="' . $row['post_id'] . '" name="post[]" id="cb-select-' . $row['identifier'] . '"> |
|
413 | + <label for="cb-select-' . $row['identifier'].'" class="screen-reader-text">'.$row['name'].'</label> |
|
414 | + <input type="checkbox" data-identifier="' . $row['identifier'].'" value="'.$row['post_id'].'" name="post[]" id="cb-select-'.$row['identifier'].'"> |
|
415 | 415 | </th> |
416 | 416 | <td class="post-title page-title column-title"> |
417 | - <strong>' . $row['name'] . '</strong> - ' . $status . ' |
|
417 | + <strong>' . $row['name'].'</strong> - '.$status.' |
|
418 | 418 | </td> |
419 | 419 | <td class="date column-date"> |
420 | - ' . $row['reference_number'] . ' |
|
420 | + ' . $row['reference_number'].' |
|
421 | 421 | </td> |
422 | 422 | <td class="date column-date"> |
423 | - <abbr title="' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '">' . date( 'Y/m/d',strtotime( $row['last_modified'] ) ) . '</abbr><br>Last Modified |
|
423 | + <abbr title="' . date('Y/m/d', strtotime($row['last_modified'])).'">'.date('Y/m/d', strtotime($row['last_modified'])).'</abbr><br>Last Modified |
|
424 | 424 | </td> |
425 | 425 | <td class="ssid column-ssid"> |
426 | - ' . $row['identifier'] . ' |
|
426 | + ' . $row['identifier'].' |
|
427 | 427 | </td> |
428 | 428 | </tr>'; |
429 | 429 | return $row_html; |
@@ -433,38 +433,38 @@ discard block |
||
433 | 433 | /** |
434 | 434 | * Connect to wetu |
435 | 435 | */ |
436 | - public function process_ajax_import( $force = false ) { |
|
436 | + public function process_ajax_import($force = false) { |
|
437 | 437 | $return = false; |
438 | - check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
439 | - if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug && isset( $_POST['wetu_id'] ) ) { |
|
438 | + check_ajax_referer('lsx_wetu_ajax_action', 'security'); |
|
439 | + if (isset($_POST['action']) && 'lsx_import_items' === $_POST['action'] && isset($_POST['type']) && $_POST['type'] === $this->tab_slug && isset($_POST['wetu_id'])) { |
|
440 | 440 | |
441 | - $wetu_id = sanitize_text_field( $_POST['wetu_id'] ); |
|
442 | - if ( isset( $_POST['post_id'] ) ) { |
|
443 | - $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
444 | - } else { |
|
441 | + $wetu_id = sanitize_text_field($_POST['wetu_id']); |
|
442 | + if (isset($_POST['post_id'])) { |
|
443 | + $post_id = sanitize_text_field($_POST['post_id']); |
|
444 | + }else { |
|
445 | 445 | $post_id = 0; |
446 | 446 | } |
447 | 447 | |
448 | - delete_option( 'lsx_wetu_importer_tour_settings' ); |
|
448 | + delete_option('lsx_wetu_importer_tour_settings'); |
|
449 | 449 | |
450 | - if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) { |
|
451 | - $content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) ); |
|
452 | - add_option( 'lsx_wetu_importer_tour_settings',$content ); |
|
453 | - } else { |
|
450 | + if (isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])) { |
|
451 | + $content = array_map('sanitize_text_field', wp_unslash($_POST['content'])); |
|
452 | + add_option('lsx_wetu_importer_tour_settings', $content); |
|
453 | + }else { |
|
454 | 454 | $content = false; |
455 | 455 | } |
456 | - $jdata = wp_remote_get( 'https://wetu.com/API/Itinerary/V8/Get?id=' . $wetu_id ); |
|
456 | + $jdata = wp_remote_get('https://wetu.com/API/Itinerary/V8/Get?id='.$wetu_id); |
|
457 | 457 | |
458 | - if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) { |
|
459 | - $jdata = json_decode( $jdata['body'], true ); |
|
460 | - $return = $this->import_row( $jdata, $wetu_id, $post_id, $content ); |
|
461 | - $this->format_completed_row( $return ); |
|
458 | + if (!empty($jdata) && isset($jdata['response']) && isset($jdata['response']['code']) && 200 === $jdata['response']['code']) { |
|
459 | + $jdata = json_decode($jdata['body'], true); |
|
460 | + $return = $this->import_row($jdata, $wetu_id, $post_id, $content); |
|
461 | + $this->format_completed_row($return); |
|
462 | 462 | $this->save_queue(); |
463 | 463 | $this->cleanup_posts(); |
464 | - $this->attach_destination_images( $content ); |
|
465 | - $this->clean_attached_destinations( $return ); |
|
466 | - } else { |
|
467 | - $this->format_error( esc_html__( 'There was a problem importing your tour, please contact support.', 'lsx-wetu-importer' ) ); |
|
464 | + $this->attach_destination_images($content); |
|
465 | + $this->clean_attached_destinations($return); |
|
466 | + }else { |
|
467 | + $this->format_error(esc_html__('There was a problem importing your tour, please contact support.', 'lsx-wetu-importer')); |
|
468 | 468 | } |
469 | 469 | } |
470 | 470 | } |
@@ -475,13 +475,13 @@ discard block |
||
475 | 475 | * @param $id string |
476 | 476 | * @return void |
477 | 477 | */ |
478 | - public function clean_attached_destinations( $id ) { |
|
479 | - $current_connections = get_post_meta( $id, 'destination_to_tour', false ); |
|
480 | - delete_post_meta( $id,'destination_to_tour' ); |
|
481 | - $current_connections = array_unique( $current_connections ); |
|
478 | + public function clean_attached_destinations($id) { |
|
479 | + $current_connections = get_post_meta($id, 'destination_to_tour', false); |
|
480 | + delete_post_meta($id, 'destination_to_tour'); |
|
481 | + $current_connections = array_unique($current_connections); |
|
482 | 482 | |
483 | - foreach ( $current_connections as $connection ) { |
|
484 | - add_post_meta( $id, 'destination_to_tour',$connection, false ); |
|
483 | + foreach ($current_connections as $connection) { |
|
484 | + add_post_meta($id, 'destination_to_tour', $connection, false); |
|
485 | 485 | } |
486 | 486 | } |
487 | 487 | |
@@ -491,12 +491,12 @@ discard block |
||
491 | 491 | * @param $data array |
492 | 492 | * @param $wetu_id string |
493 | 493 | */ |
494 | - public function import_row( $data, $wetu_id, $id = 0, $importable_content = array(), $old1 = false, $old2 = false ) { |
|
494 | + public function import_row($data, $wetu_id, $id = 0, $importable_content = array(), $old1 = false, $old2 = false) { |
|
495 | 495 | $post_name = ''; |
496 | 496 | $data_post_content = ''; |
497 | 497 | $data_post_excerpt = ''; |
498 | 498 | |
499 | - $current_post = get_post( $id ); |
|
499 | + $current_post = get_post($id); |
|
500 | 500 | |
501 | 501 | $post = array( |
502 | 502 | 'post_type' => 'tour', |
@@ -504,71 +504,71 @@ discard block |
||
504 | 504 | |
505 | 505 | $content_used_general_description = false; |
506 | 506 | |
507 | - if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) { |
|
507 | + if (!empty($importable_content) && in_array('description', $importable_content)) { |
|
508 | 508 | $data_post_content = $current_post->post_content; |
509 | - if ( isset( $data['summary'] ) && ! empty( $data['summary'] ) ) { |
|
509 | + if (isset($data['summary']) && !empty($data['summary'])) { |
|
510 | 510 | $data_post_content = $data['summary']; |
511 | 511 | } |
512 | 512 | $post['post_content'] = $data_post_content; |
513 | 513 | } |
514 | 514 | |
515 | 515 | // Create or update the post. |
516 | - if ( false !== $id && '0' !== $id ) { |
|
516 | + if (false !== $id && '0' !== $id) { |
|
517 | 517 | $post['ID'] = $id; |
518 | 518 | $post['post_status'] = 'publish'; |
519 | - $id = wp_update_post( $post ); |
|
520 | - if ( isset( $data['last_modified'] ) ) { |
|
521 | - $prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true ); |
|
522 | - update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data['last_modified'] ), $prev_date ); |
|
519 | + $id = wp_update_post($post); |
|
520 | + if (isset($data['last_modified'])) { |
|
521 | + $prev_date = get_post_meta($id, 'lsx_wetu_modified_date', true); |
|
522 | + update_post_meta($id, 'lsx_wetu_modified_date', strtotime($data['last_modified']), $prev_date); |
|
523 | 523 | } |
524 | - } else { |
|
524 | + }else { |
|
525 | 525 | // Set the name. |
526 | - if ( isset( $data['name'] ) ) { |
|
527 | - $post_name = wp_unique_post_slug( sanitize_title( $data['name'] ), $id, 'draft', 'tour', 0 ); |
|
526 | + if (isset($data['name'])) { |
|
527 | + $post_name = wp_unique_post_slug(sanitize_title($data['name']), $id, 'draft', 'tour', 0); |
|
528 | 528 | } |
529 | 529 | |
530 | - if ( ! isset( $post['post_content'] ) ) { |
|
530 | + if (!isset($post['post_content'])) { |
|
531 | 531 | $post['post_content'] = ' '; |
532 | 532 | } |
533 | 533 | |
534 | 534 | $post['post_name'] = $post_name; |
535 | 535 | $post['post_title'] = $data['name']; |
536 | 536 | $post['post_status'] = 'publish'; |
537 | - $id = wp_insert_post( $post ); |
|
537 | + $id = wp_insert_post($post); |
|
538 | 538 | |
539 | 539 | // Save the WETU ID and the Last date it was modified. |
540 | - if ( false !== $id ) { |
|
541 | - add_post_meta( $id, 'lsx_wetu_id', $wetu_id ); |
|
542 | - add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data['last_modified'] ) ); |
|
540 | + if (false !== $id) { |
|
541 | + add_post_meta($id, 'lsx_wetu_id', $wetu_id); |
|
542 | + add_post_meta($id, 'lsx_wetu_modified_date', strtotime($data['last_modified'])); |
|
543 | 543 | } |
544 | 544 | } |
545 | 545 | |
546 | 546 | // Set the price. |
547 | - if ( false !== $importable_content && in_array( 'price', $importable_content ) ) { |
|
548 | - $this->set_price( $data, $id ); |
|
547 | + if (false !== $importable_content && in_array('price', $importable_content)) { |
|
548 | + $this->set_price($data, $id); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | // Set the Duration. |
552 | - if ( false !== $importable_content && in_array( 'duration', $importable_content ) ) { |
|
553 | - $this->set_duration( $data, $id ); |
|
552 | + if (false !== $importable_content && in_array('duration', $importable_content)) { |
|
553 | + $this->set_duration($data, $id); |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | // Set the Group Size. |
557 | - if ( false !== $importable_content && in_array( 'group_size', $importable_content ) ) { |
|
558 | - $this->set_group_size( $data, $id ); |
|
557 | + if (false !== $importable_content && in_array('group_size', $importable_content)) { |
|
558 | + $this->set_group_size($data, $id); |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | // Set the Group Size. |
562 | - if ( false !== $importable_content && in_array( 'tags', $importable_content ) ) { |
|
563 | - $this->set_travel_styles( $id, $data ); |
|
562 | + if (false !== $importable_content && in_array('tags', $importable_content)) { |
|
563 | + $this->set_travel_styles($id, $data); |
|
564 | 564 | } |
565 | 565 | |
566 | - if ( false !== $importable_content && in_array( 'itineraries', $importable_content ) && isset( $data['legs'] ) && ! empty( $data['legs'] ) ) { |
|
567 | - $this->process_itineraries( $data, $id, $importable_content ); |
|
566 | + if (false !== $importable_content && in_array('itineraries', $importable_content) && isset($data['legs']) && !empty($data['legs'])) { |
|
567 | + $this->process_itineraries($data, $id, $importable_content); |
|
568 | 568 | } |
569 | 569 | |
570 | - if ( in_array( 'map', $importable_content ) && isset( $data['routes'] ) && ! empty( $data['routes'] ) ) { |
|
571 | - $this->set_map_data( $data, $id ); |
|
570 | + if (in_array('map', $importable_content) && isset($data['routes']) && !empty($data['routes'])) { |
|
571 | + $this->set_map_data($data, $id); |
|
572 | 572 | } |
573 | 573 | |
574 | 574 | return $id; |
@@ -577,195 +577,195 @@ discard block |
||
577 | 577 | /** |
578 | 578 | * A loop which runs through each leg on the tour. |
579 | 579 | */ |
580 | - public function process_itineraries( $data, $id, $importable_content ) { |
|
580 | + public function process_itineraries($data, $id, $importable_content) { |
|
581 | 581 | $day_counter = 1; |
582 | 582 | $leg_counter = 0; |
583 | 583 | |
584 | - delete_post_meta( $id, 'itinerary' ); |
|
584 | + delete_post_meta($id, 'itinerary'); |
|
585 | 585 | |
586 | - if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) { |
|
587 | - delete_post_meta( $id, 'accommodation_to_tour' ); |
|
586 | + if (false !== $importable_content && in_array('accommodation', $importable_content)) { |
|
587 | + delete_post_meta($id, 'accommodation_to_tour'); |
|
588 | 588 | } |
589 | - if ( false !== $importable_content && in_array( 'destination', $importable_content ) ) { |
|
590 | - delete_post_meta( $id, 'departs_from' ); |
|
591 | - delete_post_meta( $id, 'ends_in' ); |
|
589 | + if (false !== $importable_content && in_array('destination', $importable_content)) { |
|
590 | + delete_post_meta($id, 'departs_from'); |
|
591 | + delete_post_meta($id, 'ends_in'); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | $departs_from = false; |
595 | 595 | $ends_in = false; |
596 | 596 | |
597 | - foreach ( $data['legs'] as $leg ) { |
|
597 | + foreach ($data['legs'] as $leg) { |
|
598 | 598 | // Itinerary Accommodation. |
599 | 599 | $current_accommodation = false; |
600 | - if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) { |
|
601 | - $current_accommodation = $this->set_accommodation( $leg, $id ); |
|
600 | + if (false !== $importable_content && in_array('accommodation', $importable_content)) { |
|
601 | + $current_accommodation = $this->set_accommodation($leg, $id); |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | // Itinerary Destination. |
605 | 605 | $current_destination = false; |
606 | - if ( false !== $importable_content && in_array( 'destination', $importable_content ) ) { |
|
607 | - $current_destination = $this->set_destination( $leg, $id, $leg_counter ); |
|
606 | + if (false !== $importable_content && in_array('destination', $importable_content)) { |
|
607 | + $current_destination = $this->set_destination($leg, $id, $leg_counter); |
|
608 | 608 | } |
609 | 609 | |
610 | 610 | // If the Nights are the same mount of days in the array, then it isnt "By Destination". |
611 | - if ( ( ( 1 <= (int) $leg['nights'] && isset( $leg['periods'] ) ) ) || 0 === $leg['itinerary_leg_id'] ) { |
|
612 | - foreach ( $leg['periods'] as $day ) { |
|
611 | + if (((1 <= (int) $leg['nights'] && isset($leg['periods']))) || 0 === $leg['itinerary_leg_id']) { |
|
612 | + foreach ($leg['periods'] as $day) { |
|
613 | 613 | $current_day = array(); |
614 | - $current_day['title'] = esc_attr( 'Day ', 'lsx-wetu-importer' ) . $day_counter; |
|
614 | + $current_day['title'] = esc_attr('Day ', 'lsx-wetu-importer').$day_counter; |
|
615 | 615 | |
616 | 616 | //print_r('<pre>');print_r($day['notes']);print_r('</pre>'); |
617 | 617 | |
618 | 618 | // Description. |
619 | - if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $day['notes'] ) ) { |
|
619 | + if (false !== $importable_content && in_array('itinerary_description', $importable_content) && isset($day['notes'])) { |
|
620 | 620 | $current_day['description'] = $day['notes']; |
621 | - } else { |
|
621 | + }else { |
|
622 | 622 | $current_day['description'] = ''; |
623 | 623 | } |
624 | 624 | |
625 | 625 | // Itinerary Gallery. |
626 | - if ( false !== $importable_content && in_array( 'itinerary_gallery', $importable_content ) && isset( $day['images'] ) ) { |
|
626 | + if (false !== $importable_content && in_array('itinerary_gallery', $importable_content) && isset($day['images'])) { |
|
627 | 627 | $current_day['featured_image'] = ''; |
628 | - } else { |
|
628 | + }else { |
|
629 | 629 | $current_day['featured_image'] = ''; |
630 | 630 | } |
631 | 631 | |
632 | 632 | // Accommodation. |
633 | - if ( false !== $current_accommodation ) { |
|
634 | - $current_day['accommodation_to_tour'] = array( $current_accommodation ); |
|
635 | - } else { |
|
633 | + if (false !== $current_accommodation) { |
|
634 | + $current_day['accommodation_to_tour'] = array($current_accommodation); |
|
635 | + }else { |
|
636 | 636 | $current_day['accommodation_to_tour'] = array(); |
637 | 637 | } |
638 | 638 | |
639 | 639 | // Destination. |
640 | - if ( false !== $current_destination ) { |
|
641 | - $current_day['destination_to_tour'] = array( $current_destination ); |
|
642 | - } else { |
|
640 | + if (false !== $current_destination) { |
|
641 | + $current_day['destination_to_tour'] = array($current_destination); |
|
642 | + }else { |
|
643 | 643 | $current_day['destination_to_tour'] = array(); |
644 | 644 | } |
645 | 645 | |
646 | 646 | // Included. |
647 | - if ( false !== $importable_content && in_array( 'itinerary_included', $importable_content ) && isset( $day['included'] ) && '' !== $day['included'] ) { |
|
647 | + if (false !== $importable_content && in_array('itinerary_included', $importable_content) && isset($day['included']) && '' !== $day['included']) { |
|
648 | 648 | $current_day['included'] = $day['included']; |
649 | - } else { |
|
649 | + }else { |
|
650 | 650 | $current_day['included'] = ''; |
651 | 651 | } |
652 | 652 | |
653 | 653 | // Excluded. |
654 | - if ( false !== $importable_content && in_array( 'itinerary_excluded', $importable_content ) && isset( $day['excluded'] ) && '' !== $day['excluded'] ) { |
|
654 | + if (false !== $importable_content && in_array('itinerary_excluded', $importable_content) && isset($day['excluded']) && '' !== $day['excluded']) { |
|
655 | 655 | $current_day['excluded'] = $day['excluded']; |
656 | - } else { |
|
656 | + }else { |
|
657 | 657 | $current_day['excluded'] = ''; |
658 | 658 | } |
659 | 659 | |
660 | - $this->set_itinerary_day( $current_day,$id ); |
|
660 | + $this->set_itinerary_day($current_day, $id); |
|
661 | 661 | $day_counter++; |
662 | 662 | } |
663 | - } else { |
|
663 | + }else { |
|
664 | 664 | // This is for the by destination. |
665 | 665 | |
666 | 666 | $current_day = array(); |
667 | 667 | $next_day_count = $day_counter + (int) $leg['nights']; |
668 | 668 | $day_count_label = $next_day_count - 1; |
669 | 669 | |
670 | - $current_day['title'] = esc_attr( 'Day ', 'lsx-wetu-importer' ) . $day_counter; |
|
670 | + $current_day['title'] = esc_attr('Day ', 'lsx-wetu-importer').$day_counter; |
|
671 | 671 | |
672 | - if ( 0 !== (int) $leg['nights'] ) { |
|
673 | - $current_day['title'] .= ' - ' . $day_count_label; |
|
672 | + if (0 !== (int) $leg['nights']) { |
|
673 | + $current_day['title'] .= ' - '.$day_count_label; |
|
674 | 674 | } |
675 | 675 | |
676 | 676 | // Description. |
677 | - if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $leg['notes'] ) ) { |
|
677 | + if (false !== $importable_content && in_array('itinerary_description', $importable_content) && isset($leg['notes'])) { |
|
678 | 678 | $current_day['description'] = $leg['notes']; |
679 | - } else { |
|
679 | + }else { |
|
680 | 680 | $current_day['description'] = ''; |
681 | 681 | } |
682 | 682 | |
683 | 683 | // Itinerary Gallery. |
684 | - if ( false !== $importable_content && in_array( 'itinerary_gallery', $importable_content ) && isset( $leg['images'] ) ) { |
|
684 | + if (false !== $importable_content && in_array('itinerary_gallery', $importable_content) && isset($leg['images'])) { |
|
685 | 685 | $current_day['featured_image'] = ''; |
686 | - } else { |
|
686 | + }else { |
|
687 | 687 | $current_day['featured_image'] = ''; |
688 | 688 | } |
689 | 689 | |
690 | 690 | // Accommodation. |
691 | - if ( false !== $current_accommodation ) { |
|
692 | - $current_day['accommodation_to_tour'] = array( $current_accommodation ); |
|
693 | - } else { |
|
691 | + if (false !== $current_accommodation) { |
|
692 | + $current_day['accommodation_to_tour'] = array($current_accommodation); |
|
693 | + }else { |
|
694 | 694 | $current_day['accommodation_to_tour'] = array(); |
695 | 695 | } |
696 | 696 | |
697 | 697 | // Destination. |
698 | - if ( false !== $current_destination ) { |
|
699 | - $current_day['destination_to_tour'] = array( $current_destination ); |
|
700 | - } else { |
|
698 | + if (false !== $current_destination) { |
|
699 | + $current_day['destination_to_tour'] = array($current_destination); |
|
700 | + }else { |
|
701 | 701 | $current_day['destination_to_tour'] = array(); |
702 | 702 | } |
703 | 703 | |
704 | 704 | // Included. |
705 | - if ( false !== $importable_content && in_array( 'itinerary_included', $importable_content ) && isset( $leg['included'] ) && '' !== $leg['included'] ) { |
|
705 | + if (false !== $importable_content && in_array('itinerary_included', $importable_content) && isset($leg['included']) && '' !== $leg['included']) { |
|
706 | 706 | $current_day['included'] = $leg['included']; |
707 | - } else { |
|
707 | + }else { |
|
708 | 708 | $current_day['included'] = ''; |
709 | 709 | } |
710 | 710 | |
711 | 711 | // Excluded. |
712 | - if ( false !== $importable_content && in_array( 'itinerary_excluded', $importable_content ) && isset( $leg['excluded'] ) && '' !== $leg['excluded'] ) { |
|
712 | + if (false !== $importable_content && in_array('itinerary_excluded', $importable_content) && isset($leg['excluded']) && '' !== $leg['excluded']) { |
|
713 | 713 | $current_day['excluded'] = $leg['excluded']; |
714 | - } else { |
|
714 | + }else { |
|
715 | 715 | $current_day['excluded'] = ''; |
716 | 716 | } |
717 | 717 | |
718 | - $this->set_itinerary_day( $current_day,$id ); |
|
718 | + $this->set_itinerary_day($current_day, $id); |
|
719 | 719 | $day_counter = $next_day_count; |
720 | 720 | } |
721 | 721 | |
722 | 722 | // If we are in the first leg, and the destination was attached then save it as the departure field. |
723 | - if ( 0 === $leg_counter && false !== $current_destination ) { |
|
723 | + if (0 === $leg_counter && false !== $current_destination) { |
|
724 | 724 | $departs_from = $current_destination; |
725 | 725 | } |
726 | 726 | |
727 | 727 | // If its the last leg then save it as the ends in. |
728 | - if ( ( count( $data['legs'] ) - 2 ) === $leg_counter && false !== $current_destination ) { |
|
728 | + if ((count($data['legs']) - 2) === $leg_counter && false !== $current_destination) { |
|
729 | 729 | $ends_in = $current_destination; |
730 | 730 | } |
731 | 731 | |
732 | 732 | $leg_counter++; |
733 | 733 | } |
734 | 734 | |
735 | - if ( false !== $departs_from ) { |
|
736 | - add_post_meta( $id, 'departs_from', $departs_from, true ); |
|
735 | + if (false !== $departs_from) { |
|
736 | + add_post_meta($id, 'departs_from', $departs_from, true); |
|
737 | 737 | } |
738 | - if ( false !== $ends_in ) { |
|
739 | - add_post_meta( $id, 'ends_in', $ends_in, true ); |
|
738 | + if (false !== $ends_in) { |
|
739 | + add_post_meta($id, 'ends_in', $ends_in, true); |
|
740 | 740 | } |
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
744 | 744 | * Run through your routes and save the points as a KML file. |
745 | 745 | */ |
746 | - public function set_map_data( $data, $id, $zoom = 9 ) { |
|
747 | - if ( ! empty( $data['routes'] ) ) { |
|
748 | - delete_post_meta( $id,'wetu_map_points' ); |
|
746 | + public function set_map_data($data, $id, $zoom = 9) { |
|
747 | + if (!empty($data['routes'])) { |
|
748 | + delete_post_meta($id, 'wetu_map_points'); |
|
749 | 749 | |
750 | 750 | $points = array(); |
751 | 751 | |
752 | - foreach ( $data['routes'] as $route ) { |
|
752 | + foreach ($data['routes'] as $route) { |
|
753 | 753 | |
754 | - if ( isset( $route['points'] ) && '' !== $route['points'] ) { |
|
754 | + if (isset($route['points']) && '' !== $route['points']) { |
|
755 | 755 | |
756 | - $temp_points = explode( ';',$route['points'] ); |
|
757 | - $point_counter = count( $temp_points ); |
|
756 | + $temp_points = explode(';', $route['points']); |
|
757 | + $point_counter = count($temp_points); |
|
758 | 758 | |
759 | - for ( $x = 0; $x <= $point_counter; $x++ ) { |
|
759 | + for ($x = 0; $x <= $point_counter; $x++) { |
|
760 | 760 | $y = $x + 1; |
761 | - $points[] = $temp_points[ $x ] . ',' . $temp_points[ $y ]; |
|
761 | + $points[] = $temp_points[$x].','.$temp_points[$y]; |
|
762 | 762 | $x++; |
763 | 763 | } |
764 | 764 | } |
765 | 765 | } |
766 | 766 | |
767 | - if ( ! empty( $points ) ) { |
|
768 | - $this->save_custom_field( implode( ' ',$points ),'wetu_map_points',$id,false,true ); |
|
767 | + if (!empty($points)) { |
|
768 | + $this->save_custom_field(implode(' ', $points), 'wetu_map_points', $id, false, true); |
|
769 | 769 | } |
770 | 770 | } |
771 | 771 | |
@@ -776,52 +776,52 @@ discard block |
||
776 | 776 | /** |
777 | 777 | * Set the Itinerary Day. |
778 | 778 | */ |
779 | - public function set_itinerary_day( $day, $id ) { |
|
780 | - $this->save_custom_field( $day, 'itinerary', $id, false, false ); |
|
779 | + public function set_itinerary_day($day, $id) { |
|
780 | + $this->save_custom_field($day, 'itinerary', $id, false, false); |
|
781 | 781 | } |
782 | 782 | |
783 | 783 | /** |
784 | 784 | * Set the price. |
785 | 785 | */ |
786 | - public function set_price( $data, $id ) { |
|
786 | + public function set_price($data, $id) { |
|
787 | 787 | // Price. |
788 | - if ( isset( $data['price'] ) && '' !== $data['price'] ) { |
|
789 | - $price = preg_replace( '/[^0-9,.]/', '', $data['price'] ); |
|
790 | - $meta_key = apply_filters( 'lsx_wetu_importer_price_meta_key', 'price' ); |
|
791 | - $this->save_custom_field( $price, $meta_key, $id ); |
|
788 | + if (isset($data['price']) && '' !== $data['price']) { |
|
789 | + $price = preg_replace('/[^0-9,.]/', '', $data['price']); |
|
790 | + $meta_key = apply_filters('lsx_wetu_importer_price_meta_key', 'price'); |
|
791 | + $this->save_custom_field($price, $meta_key, $id); |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | // Price includes. |
795 | - if ( isset( $data['price_includes'] ) && '' !== $data['price_includes'] ) { |
|
796 | - $meta_key = apply_filters( 'lsx_wetu_importer_included_meta_key', 'included' ); |
|
797 | - $this->save_custom_field( $data['price_includes'], $meta_key, $id ); |
|
795 | + if (isset($data['price_includes']) && '' !== $data['price_includes']) { |
|
796 | + $meta_key = apply_filters('lsx_wetu_importer_included_meta_key', 'included'); |
|
797 | + $this->save_custom_field($data['price_includes'], $meta_key, $id); |
|
798 | 798 | } |
799 | 799 | |
800 | 800 | // Price Excludes. |
801 | - if ( isset( $data['price_excludes'] ) && '' !== $data['price_excludes'] ) { |
|
802 | - $meta_key = apply_filters( 'lsx_wetu_importer_not_included_meta_key', 'not_included' ); |
|
803 | - $this->save_custom_field( $data['price_excludes'], $meta_key, $id ); |
|
801 | + if (isset($data['price_excludes']) && '' !== $data['price_excludes']) { |
|
802 | + $meta_key = apply_filters('lsx_wetu_importer_not_included_meta_key', 'not_included'); |
|
803 | + $this->save_custom_field($data['price_excludes'], $meta_key, $id); |
|
804 | 804 | } |
805 | 805 | } |
806 | 806 | |
807 | 807 | /** |
808 | 808 | * Set the duration. |
809 | 809 | */ |
810 | - public function set_duration( $data, $id ) { |
|
811 | - if ( isset( $data['days'] ) && ! empty( $data['days'] ) ) { |
|
810 | + public function set_duration($data, $id) { |
|
811 | + if (isset($data['days']) && !empty($data['days'])) { |
|
812 | 812 | $price = $data['days']; |
813 | - $price = preg_replace( '/[^0-9,.]/', '', $price ); |
|
814 | - $this->save_custom_field( $price, 'duration', $id ); |
|
813 | + $price = preg_replace('/[^0-9,.]/', '', $price); |
|
814 | + $this->save_custom_field($price, 'duration', $id); |
|
815 | 815 | } |
816 | 816 | } |
817 | 817 | |
818 | 818 | /** |
819 | 819 | * Set the group size |
820 | 820 | */ |
821 | - public function set_group_size( $data, $id ) { |
|
822 | - if ( isset( $data['group_size'] ) && ! empty( $data['group_size'] ) ) { |
|
821 | + public function set_group_size($data, $id) { |
|
822 | + if (isset($data['group_size']) && !empty($data['group_size'])) { |
|
823 | 823 | $group_size = $data['group_size']; |
824 | - $this->save_custom_field( $group_size,'group_size',$id ); |
|
824 | + $this->save_custom_field($group_size, 'group_size', $id); |
|
825 | 825 | } |
826 | 826 | } |
827 | 827 | |
@@ -832,10 +832,10 @@ discard block |
||
832 | 832 | * @param array $travel_styles |
833 | 833 | * @return void |
834 | 834 | */ |
835 | - public function set_travel_styles( $id, $data ) { |
|
836 | - if ( isset( $data['tags'] ) ) { |
|
837 | - foreach ( $data['tags'] as $tag ) { |
|
838 | - $this->set_term( $id, $tag, 'travel-style' ); |
|
835 | + public function set_travel_styles($id, $data) { |
|
836 | + if (isset($data['tags'])) { |
|
837 | + foreach ($data['tags'] as $tag) { |
|
838 | + $this->set_term($id, $tag, 'travel-style'); |
|
839 | 839 | } |
840 | 840 | } |
841 | 841 | } |
@@ -843,27 +843,27 @@ discard block |
||
843 | 843 | /** |
844 | 844 | * Connects the Accommodation if its available |
845 | 845 | */ |
846 | - public function set_accommodation( $day, $id ) { |
|
846 | + public function set_accommodation($day, $id) { |
|
847 | 847 | $ac_id = false; |
848 | 848 | $this->current_accommodation = $this->find_current_accommodation(); |
849 | 849 | |
850 | - if ( isset( $day['content_entity_id'] ) && ! empty( $day['content_entity_id'] ) ) { |
|
851 | - if ( false !== $this->current_accommodation && ! empty( $this->current_accommodation ) && array_key_exists( $day['content_entity_id'],$this->current_accommodation ) ) { |
|
852 | - $ac_id = $this->current_accommodation[ $day['content_entity_id'] ]; |
|
853 | - } else { |
|
850 | + if (isset($day['content_entity_id']) && !empty($day['content_entity_id'])) { |
|
851 | + if (false !== $this->current_accommodation && !empty($this->current_accommodation) && array_key_exists($day['content_entity_id'], $this->current_accommodation)) { |
|
852 | + $ac_id = $this->current_accommodation[$day['content_entity_id']]; |
|
853 | + }else { |
|
854 | 854 | $ac_id = wp_insert_post(array( |
855 | 855 | 'post_type' => 'accommodation', |
856 | 856 | 'post_status' => 'draft', |
857 | 857 | 'post_title' => $day['content_entity_id'], |
858 | 858 | )); |
859 | 859 | |
860 | - $this->save_custom_field( $day['content_entity_id'],'lsx_wetu_id',$ac_id ); |
|
860 | + $this->save_custom_field($day['content_entity_id'], 'lsx_wetu_id', $ac_id); |
|
861 | 861 | } |
862 | 862 | |
863 | - if ( '' !== $ac_id && false !== $ac_id ) { |
|
864 | - $this->save_custom_field( $ac_id,'accommodation_to_tour',$id,false,false ); |
|
865 | - $this->save_custom_field( $id,'tour_to_accommodation',$ac_id,false,false ); |
|
866 | - $this->queue_item( $ac_id ); |
|
863 | + if ('' !== $ac_id && false !== $ac_id) { |
|
864 | + $this->save_custom_field($ac_id, 'accommodation_to_tour', $id, false, false); |
|
865 | + $this->save_custom_field($id, 'tour_to_accommodation', $ac_id, false, false); |
|
866 | + $this->queue_item($ac_id); |
|
867 | 867 | } |
868 | 868 | } |
869 | 869 | return $ac_id; |
@@ -875,14 +875,14 @@ discard block |
||
875 | 875 | * @param $post_type string |
876 | 876 | * @return boolean / array |
877 | 877 | */ |
878 | - public function find_current_accommodation( $post_type = 'accommodation' ) { |
|
878 | + public function find_current_accommodation($post_type = 'accommodation') { |
|
879 | 879 | global $wpdb; |
880 | - $accommodation = parent::find_current_accommodation( $post_type ); |
|
880 | + $accommodation = parent::find_current_accommodation($post_type); |
|
881 | 881 | $return = false; |
882 | 882 | |
883 | - if ( ! empty( $accommodation ) ) { |
|
884 | - foreach ( $accommodation as $key => $acc ) { |
|
885 | - $return[ $acc->meta_value ] = $acc->post_id; |
|
883 | + if (!empty($accommodation)) { |
|
884 | + foreach ($accommodation as $key => $acc) { |
|
885 | + $return[$acc->meta_value] = $acc->post_id; |
|
886 | 886 | } |
887 | 887 | } |
888 | 888 | |
@@ -894,7 +894,7 @@ discard block |
||
894 | 894 | * @return boolean / array |
895 | 895 | */ |
896 | 896 | public function find_current_destinations() { |
897 | - return $this->find_current_accommodation( 'destination' ); |
|
897 | + return $this->find_current_accommodation('destination'); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | /** |
@@ -904,44 +904,44 @@ discard block |
||
904 | 904 | * @param $id string |
905 | 905 | * @return boolean / string |
906 | 906 | */ |
907 | - public function set_destination( $day, $id, $leg_counter ) { |
|
907 | + public function set_destination($day, $id, $leg_counter) { |
|
908 | 908 | $dest_id = false; |
909 | 909 | $country_id = false; |
910 | 910 | |
911 | 911 | $this->current_destinations = $this->find_current_destinations(); |
912 | 912 | |
913 | - if ( isset( $day['destination_content_entity_id'] ) && ! empty( $day['destination_content_entity_id'] ) ) { |
|
914 | - if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $day['destination_content_entity_id'], $this->current_destinations ) ) { |
|
915 | - $dest_id = $this->current_destinations[ $day['destination_content_entity_id'] ]; |
|
913 | + if (isset($day['destination_content_entity_id']) && !empty($day['destination_content_entity_id'])) { |
|
914 | + if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($day['destination_content_entity_id'], $this->current_destinations)) { |
|
915 | + $dest_id = $this->current_destinations[$day['destination_content_entity_id']]; |
|
916 | 916 | |
917 | 917 | //TODO Check for attachments here. |
918 | - $this->destination_images[ $id ][] = array( $dest_id, $day['destination_content_entity_id'] ); |
|
918 | + $this->destination_images[$id][] = array($dest_id, $day['destination_content_entity_id']); |
|
919 | 919 | |
920 | 920 | //Check if there is a country asigned. |
921 | - $potential_id = wp_get_post_parent_id( $dest_id ); |
|
922 | - $country_wetu_id = get_post_meta( $potential_id, 'lsx_wetu_id', true ); |
|
921 | + $potential_id = wp_get_post_parent_id($dest_id); |
|
922 | + $country_wetu_id = get_post_meta($potential_id, 'lsx_wetu_id', true); |
|
923 | 923 | |
924 | - if ( false !== $country_wetu_id ) { |
|
925 | - $country_id = $this->set_country( $country_wetu_id, $id ); |
|
924 | + if (false !== $country_wetu_id) { |
|
925 | + $country_id = $this->set_country($country_wetu_id, $id); |
|
926 | 926 | } |
927 | - } else { |
|
928 | - $destination_json = wp_remote_get( 'https://wetu.com/API/Pins/' . $this->api_key . '/Get?ids=' . $day['destination_content_entity_id'] ); |
|
927 | + }else { |
|
928 | + $destination_json = wp_remote_get('https://wetu.com/API/Pins/'.$this->api_key.'/Get?ids='.$day['destination_content_entity_id']); |
|
929 | 929 | |
930 | - if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) { |
|
930 | + if (!empty($jdata) && isset($jdata['response']) && isset($jdata['response']['code']) && 200 === $jdata['response']['code']) { |
|
931 | 931 | |
932 | - $destination_data = json_decode( $destination_json['body'], true ); |
|
932 | + $destination_data = json_decode($destination_json['body'], true); |
|
933 | 933 | |
934 | - if ( ! empty( $destination_data ) && ! isset( $destination_data['error'] ) ) { |
|
934 | + if (!empty($destination_data) && !isset($destination_data['error'])) { |
|
935 | 935 | $destination_title = $day['destination_content_entity_id']; |
936 | 936 | |
937 | - if ( isset( $destination_data[0]['name'] ) ) { |
|
937 | + if (isset($destination_data[0]['name'])) { |
|
938 | 938 | $destination_title = $destination_data[0]['name']; |
939 | 939 | } |
940 | 940 | |
941 | - if ( isset( $destination_data[0]['map_object_id'] ) && isset( $destination_data[0]['position']['country_content_entity_id'] ) |
|
942 | - && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id'] ) { |
|
941 | + if (isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id']) |
|
942 | + && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']) { |
|
943 | 943 | |
944 | - $country_id = $this->set_country( $destination_data[0]['position']['country_content_entity_id'], $id ); |
|
944 | + $country_id = $this->set_country($destination_data[0]['position']['country_content_entity_id'], $id); |
|
945 | 945 | // Save the destination so we can grab the tour featured image and banner from them. |
946 | 946 | } |
947 | 947 | |
@@ -951,40 +951,40 @@ discard block |
||
951 | 951 | 'post_title' => $destination_title, |
952 | 952 | ); |
953 | 953 | |
954 | - if ( false !== $country_id ) { |
|
954 | + if (false !== $country_id) { |
|
955 | 955 | $dest_post['post_parent'] = $country_id; |
956 | 956 | } |
957 | - $dest_id = wp_insert_post( $dest_post ); |
|
957 | + $dest_id = wp_insert_post($dest_post); |
|
958 | 958 | |
959 | 959 | // Make sure we register the. |
960 | - $this->current_destinations[ $day['destination_content_entity_id'] ] = $dest_id; |
|
960 | + $this->current_destinations[$day['destination_content_entity_id']] = $dest_id; |
|
961 | 961 | |
962 | 962 | // If there are images attached then use the destination. |
963 | - if ( isset( $destination_data[0]['content']['images'] ) && ! empty( $destination_data[0]['content']['images'] ) ) { |
|
964 | - $this->destination_images[ $id ][] = array( $dest_id, $day['destination_content_entity_id'] ); |
|
963 | + if (isset($destination_data[0]['content']['images']) && !empty($destination_data[0]['content']['images'])) { |
|
964 | + $this->destination_images[$id][] = array($dest_id, $day['destination_content_entity_id']); |
|
965 | 965 | } |
966 | 966 | |
967 | - $this->save_custom_field( $day['destination_content_entity_id'], 'lsx_wetu_id', $dest_id ); |
|
967 | + $this->save_custom_field($day['destination_content_entity_id'], 'lsx_wetu_id', $dest_id); |
|
968 | 968 | } |
969 | 969 | } |
970 | 970 | } |
971 | 971 | |
972 | - if ( '' !== $dest_id && false !== $dest_id ) { |
|
973 | - $this->save_custom_field( $dest_id, 'destination_to_tour', $id, false, false ); |
|
974 | - $this->save_custom_field( $id, 'tour_to_destination', $dest_id, false, false ); |
|
972 | + if ('' !== $dest_id && false !== $dest_id) { |
|
973 | + $this->save_custom_field($dest_id, 'destination_to_tour', $id, false, false); |
|
974 | + $this->save_custom_field($id, 'tour_to_destination', $dest_id, false, false); |
|
975 | 975 | |
976 | 976 | //Save the item to display in the queue |
977 | - $this->queue_item( $dest_id ); |
|
977 | + $this->queue_item($dest_id); |
|
978 | 978 | |
979 | 979 | //Save the item to clean up the amount of connections. |
980 | - $this->cleanup_posts[ $dest_id ] = 'tour_to_destination'; |
|
980 | + $this->cleanup_posts[$dest_id] = 'tour_to_destination'; |
|
981 | 981 | |
982 | 982 | //Add this relation info so we can make sure certain items are set as countries. |
983 | - if ( 0 !== $country_id && false !== $country_id ) { |
|
984 | - $this->relation_meta[ $dest_id ] = $country_id; |
|
985 | - $this->relation_meta[ $country_id ] = 0; |
|
986 | - } else { |
|
987 | - $this->relation_meta[ $dest_id ] = 0; |
|
983 | + if (0 !== $country_id && false !== $country_id) { |
|
984 | + $this->relation_meta[$dest_id] = $country_id; |
|
985 | + $this->relation_meta[$country_id] = 0; |
|
986 | + }else { |
|
987 | + $this->relation_meta[$dest_id] = 0; |
|
988 | 988 | } |
989 | 989 | } |
990 | 990 | } |
@@ -1000,23 +1000,23 @@ discard block |
||
1000 | 1000 | * |
1001 | 1001 | * @return string |
1002 | 1002 | */ |
1003 | - public function set_country( $country_wetu_id, $id ) { |
|
1003 | + public function set_country($country_wetu_id, $id) { |
|
1004 | 1004 | $country_id = false; |
1005 | 1005 | $this->current_destinations = $this->find_current_destinations(); |
1006 | 1006 | |
1007 | - if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $country_wetu_id, $this->current_destinations ) ) { |
|
1008 | - $country_id = $this->current_destinations[ $country_wetu_id ]; |
|
1009 | - $this->destination_images[ $id ][] = array( $country_id, $country_wetu_id ); |
|
1010 | - } else { |
|
1011 | - $country_json = wp_remote_get( 'https://wetu.com/API/Pins/' . $this->api_key . '/Get?ids=' . $country_wetu_id ); |
|
1007 | + if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) { |
|
1008 | + $country_id = $this->current_destinations[$country_wetu_id]; |
|
1009 | + $this->destination_images[$id][] = array($country_id, $country_wetu_id); |
|
1010 | + }else { |
|
1011 | + $country_json = wp_remote_get('https://wetu.com/API/Pins/'.$this->api_key.'/Get?ids='.$country_wetu_id); |
|
1012 | 1012 | |
1013 | - if ( ! empty( $country_json ) && isset( $country_json['response'] ) && isset( $country_json['response']['code'] ) && 200 === $country_json['response']['code'] ) { |
|
1014 | - $country_data = json_decode( $country_json['body'], true ); |
|
1013 | + if (!empty($country_json) && isset($country_json['response']) && isset($country_json['response']['code']) && 200 === $country_json['response']['code']) { |
|
1014 | + $country_data = json_decode($country_json['body'], true); |
|
1015 | 1015 | |
1016 | 1016 | // Format the title of the destination if its available, otherwise default to the WETU ID. |
1017 | 1017 | $country_title = $country_wetu_id; |
1018 | 1018 | |
1019 | - if ( isset( $country_data[0]['name'] ) ) { |
|
1019 | + if (isset($country_data[0]['name'])) { |
|
1020 | 1020 | $country_title = $country_data[0]['name']; |
1021 | 1021 | } |
1022 | 1022 | |
@@ -1027,23 +1027,23 @@ discard block |
||
1027 | 1027 | )); |
1028 | 1028 | |
1029 | 1029 | //add the country to the current destination stack |
1030 | - $this->current_destinations[ $country_wetu_id ] = $country_id; |
|
1030 | + $this->current_destinations[$country_wetu_id] = $country_id; |
|
1031 | 1031 | |
1032 | 1032 | // Check if there are images and save fore use later. |
1033 | - if ( isset( $country_data[0]['content']['images'] ) && ! empty( $country_data[0]['content']['images'] ) ) { |
|
1034 | - $this->destination_images[ $id ][] = array( $country_id,$country_wetu_id ); |
|
1033 | + if (isset($country_data[0]['content']['images']) && !empty($country_data[0]['content']['images'])) { |
|
1034 | + $this->destination_images[$id][] = array($country_id, $country_wetu_id); |
|
1035 | 1035 | } |
1036 | 1036 | |
1037 | 1037 | //Save the wetu field |
1038 | - $this->save_custom_field( $country_wetu_id, 'lsx_wetu_id', $country_id ); |
|
1038 | + $this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id); |
|
1039 | 1039 | } |
1040 | 1040 | } |
1041 | 1041 | |
1042 | - if ( '' !== $country_id && false !== $country_id ) { |
|
1043 | - $this->save_custom_field( $country_id, 'destination_to_tour', $id, false, false ); |
|
1044 | - $this->save_custom_field( $id, 'tour_to_destination', $country_id, false, false ); |
|
1045 | - $this->queue_item( $country_id ); |
|
1046 | - $this->cleanup_posts[ $country_id ] = 'tour_to_destination'; |
|
1042 | + if ('' !== $country_id && false !== $country_id) { |
|
1043 | + $this->save_custom_field($country_id, 'destination_to_tour', $id, false, false); |
|
1044 | + $this->save_custom_field($id, 'tour_to_destination', $country_id, false, false); |
|
1045 | + $this->queue_item($country_id); |
|
1046 | + $this->cleanup_posts[$country_id] = 'tour_to_destination'; |
|
1047 | 1047 | |
1048 | 1048 | return $country_id; |
1049 | 1049 | } |
@@ -1058,44 +1058,44 @@ discard block |
||
1058 | 1058 | * |
1059 | 1059 | * @return string |
1060 | 1060 | */ |
1061 | - public function attach_destination_images( $importable_content = array() ) { |
|
1062 | - if ( false !== $this->destination_images ) { |
|
1063 | - $this->shuffle_assoc( $this->destination_images ); |
|
1061 | + public function attach_destination_images($importable_content = array()) { |
|
1062 | + if (false !== $this->destination_images) { |
|
1063 | + $this->shuffle_assoc($this->destination_images); |
|
1064 | 1064 | |
1065 | - foreach ( $this->destination_images as $tour => $destinations ) { |
|
1065 | + foreach ($this->destination_images as $tour => $destinations) { |
|
1066 | 1066 | //$this->shuffle_assoc( $destinations ); |
1067 | 1067 | |
1068 | 1068 | $image_set = false; |
1069 | 1069 | $forced = false; |
1070 | 1070 | |
1071 | - foreach ( $destinations as $destination ) { |
|
1072 | - if ( false === $image_set && false === $forced ) { |
|
1073 | - $url = 'https://wetu.com/API/Pins/' . $this->api_key; |
|
1071 | + foreach ($destinations as $destination) { |
|
1072 | + if (false === $image_set && false === $forced) { |
|
1073 | + $url = 'https://wetu.com/API/Pins/'.$this->api_key; |
|
1074 | 1074 | $url_qs = ''; |
1075 | 1075 | |
1076 | - $jdata = wp_remote_get( $url . '/Get?' . $url_qs . '&ids=' . $destination[1] ); |
|
1076 | + $jdata = wp_remote_get($url.'/Get?'.$url_qs.'&ids='.$destination[1]); |
|
1077 | 1077 | |
1078 | - if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) { |
|
1079 | - $adata = json_decode( $jdata['body'], true ); |
|
1078 | + if (!empty($jdata) && isset($jdata['response']) && isset($jdata['response']['code']) && 200 === $jdata['response']['code']) { |
|
1079 | + $adata = json_decode($jdata['body'], true); |
|
1080 | 1080 | |
1081 | - if ( ! empty( $adata ) && ! empty( $adata[0]['content']['images'] ) ) { |
|
1082 | - $this->find_attachments( $destination[0] ); |
|
1081 | + if (!empty($adata) && !empty($adata[0]['content']['images'])) { |
|
1082 | + $this->find_attachments($destination[0]); |
|
1083 | 1083 | |
1084 | 1084 | //Set the featured image |
1085 | - if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) { |
|
1086 | - $image_set = $this->set_featured_image( $adata, $tour ); |
|
1087 | - if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) { |
|
1088 | - $image_set = $this->set_banner_image( $adata, $tour ); |
|
1085 | + if (false !== $importable_content && in_array('featured_image', $importable_content)) { |
|
1086 | + $image_set = $this->set_featured_image($adata, $tour); |
|
1087 | + if (false !== $importable_content && in_array('banner_image', $importable_content)) { |
|
1088 | + $image_set = $this->set_banner_image($adata, $tour); |
|
1089 | 1089 | $forced = true; |
1090 | 1090 | } |
1091 | 1091 | continue; |
1092 | 1092 | } |
1093 | - if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) { |
|
1094 | - $image_set = $this->set_banner_image( $adata, $tour ); |
|
1093 | + if (false !== $importable_content && in_array('banner_image', $importable_content)) { |
|
1094 | + $image_set = $this->set_banner_image($adata, $tour); |
|
1095 | 1095 | } |
1096 | 1096 | } |
1097 | 1097 | } |
1098 | - } else { |
|
1098 | + }else { |
|
1099 | 1099 | continue; |
1100 | 1100 | } |
1101 | 1101 | } |
@@ -1106,28 +1106,28 @@ discard block |
||
1106 | 1106 | /** |
1107 | 1107 | * Creates the main gallery data |
1108 | 1108 | */ |
1109 | - public function set_featured_image( $data, $id ) { |
|
1109 | + public function set_featured_image($data, $id) { |
|
1110 | 1110 | $image_set = false; |
1111 | 1111 | $counter = 0; |
1112 | 1112 | |
1113 | - if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
1114 | - foreach ( $data[0]['content']['images'] as $v ) { |
|
1113 | + if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) { |
|
1114 | + foreach ($data[0]['content']['images'] as $v) { |
|
1115 | 1115 | /*print_r('<pre>'); |
1116 | 1116 | print_r( $v ); |
1117 | 1117 | print_r('</pre>');*/ |
1118 | 1118 | |
1119 | - if ( true === $image_set ) { |
|
1119 | + if (true === $image_set) { |
|
1120 | 1120 | $counter++; |
1121 | 1121 | continue; |
1122 | 1122 | } |
1123 | 1123 | |
1124 | - if ( ! $this->check_if_image_is_used( $v ) ) { |
|
1125 | - $temp_featured_image = $this->attach_image( $v , $id ); |
|
1124 | + if (!$this->check_if_image_is_used($v)) { |
|
1125 | + $temp_featured_image = $this->attach_image($v, $id); |
|
1126 | 1126 | |
1127 | - if ( false !== $temp_featured_image ) { |
|
1127 | + if (false !== $temp_featured_image) { |
|
1128 | 1128 | $this->featured_image = $temp_featured_image; |
1129 | - delete_post_meta( $id, '_thumbnail_id' ); |
|
1130 | - add_post_meta( $id, '_thumbnail_id', $this->featured_image, true ); |
|
1129 | + delete_post_meta($id, '_thumbnail_id'); |
|
1130 | + add_post_meta($id, '_thumbnail_id', $this->featured_image, true); |
|
1131 | 1131 | $image_set = true; |
1132 | 1132 | } |
1133 | 1133 | } |
@@ -1141,40 +1141,40 @@ discard block |
||
1141 | 1141 | /** |
1142 | 1142 | * Sets a banner image |
1143 | 1143 | */ |
1144 | - public function set_banner_image( $data, $id, $content = array( 'none' ) ) { |
|
1144 | + public function set_banner_image($data, $id, $content = array('none')) { |
|
1145 | 1145 | $image_set = false; |
1146 | 1146 | $counter = 0; |
1147 | 1147 | |
1148 | - if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
1148 | + if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) { |
|
1149 | 1149 | |
1150 | - foreach ( $data[0]['content']['images'] as $v ) { |
|
1150 | + foreach ($data[0]['content']['images'] as $v) { |
|
1151 | 1151 | /*print_r('<pre>'); |
1152 | 1152 | print_r( $v ); |
1153 | 1153 | print_r('</pre>');*/ |
1154 | 1154 | |
1155 | - if ( true === $image_set || 0 === $counter ) { |
|
1155 | + if (true === $image_set || 0 === $counter) { |
|
1156 | 1156 | $counter++; |
1157 | 1157 | continue; |
1158 | 1158 | } |
1159 | 1159 | |
1160 | - if ( ! $this->check_if_image_is_used( $v ) ) { |
|
1161 | - $temp_banner = $this->attach_image( $v, $id, array( |
|
1160 | + if (!$this->check_if_image_is_used($v)) { |
|
1161 | + $temp_banner = $this->attach_image($v, $id, array( |
|
1162 | 1162 | 'width' => '1920', |
1163 | 1163 | 'height' => '600', |
1164 | 1164 | 'cropping' => 'c', |
1165 | - ) ); |
|
1165 | + )); |
|
1166 | 1166 | |
1167 | - if ( false !== $temp_banner ) { |
|
1167 | + if (false !== $temp_banner) { |
|
1168 | 1168 | $this->banner_image = $temp_banner; |
1169 | 1169 | |
1170 | - delete_post_meta( $id,'image_group' ); |
|
1170 | + delete_post_meta($id, 'image_group'); |
|
1171 | 1171 | |
1172 | 1172 | $new_banner = array( |
1173 | 1173 | 'banner_image' => array( |
1174 | 1174 | 'cmb-field-0' => $this->banner_image, |
1175 | 1175 | ), |
1176 | 1176 | ); |
1177 | - add_post_meta( $id,'image_group',$new_banner,true ); |
|
1177 | + add_post_meta($id, 'image_group', $new_banner, true); |
|
1178 | 1178 | $image_set = true; |
1179 | 1179 | } |
1180 | 1180 | } |
@@ -1188,36 +1188,36 @@ discard block |
||
1188 | 1188 | /** |
1189 | 1189 | * Grabs all of the current used featured images on the site. |
1190 | 1190 | */ |
1191 | - public function check_if_image_is_used( $v ) { |
|
1191 | + public function check_if_image_is_used($v) { |
|
1192 | 1192 | global $wpdb; |
1193 | 1193 | |
1194 | - $temp_fragment = explode( '/', $v['url_fragment'] ); |
|
1195 | - $url_filename = $temp_fragment[ count( $temp_fragment ) - 1 ]; |
|
1196 | - $url_filename = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $url_filename ); |
|
1197 | - $url_filename = trim( $url_filename ); |
|
1198 | - $url_filename = str_replace( ' ', '_', $url_filename ); |
|
1194 | + $temp_fragment = explode('/', $v['url_fragment']); |
|
1195 | + $url_filename = $temp_fragment[count($temp_fragment) - 1]; |
|
1196 | + $url_filename = str_replace(array('.jpg', '.png', '.jpeg'), '', $url_filename); |
|
1197 | + $url_filename = trim($url_filename); |
|
1198 | + $url_filename = str_replace(' ', '_', $url_filename); |
|
1199 | 1199 | |
1200 | - if ( in_array( $url_filename, $this->found_attachments ) ) { |
|
1200 | + if (in_array($url_filename, $this->found_attachments)) { |
|
1201 | 1201 | // check to see if there is a featured image set with this ID. |
1202 | - $found_id = array_search( $url_filename, $this->found_attachments ); |
|
1202 | + $found_id = array_search($url_filename, $this->found_attachments); |
|
1203 | 1203 | |
1204 | - $results = $wpdb->get_results( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value = '%s' AND meta_key = '_thumbnail_id'", array( $found_id ) ) ); |
|
1205 | - if ( ! empty( $results ) ) { |
|
1204 | + $results = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value = '%s' AND meta_key = '_thumbnail_id'", array($found_id))); |
|
1205 | + if (!empty($results)) { |
|
1206 | 1206 | return true; |
1207 | - } else { |
|
1207 | + }else { |
|
1208 | 1208 | return false; |
1209 | 1209 | } |
1210 | - } else { |
|
1211 | - $results = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_name = '%s'", array( $url_filename ) ) ); |
|
1210 | + }else { |
|
1211 | + $results = $wpdb->get_results($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_name = '%s'", array($url_filename))); |
|
1212 | 1212 | |
1213 | - if ( ! empty( $results ) ) { |
|
1214 | - $results = $wpdb->get_results( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value = '%s' AND meta_key = '_thumbnail_id'", array( $results[0]->ID ) ) ); |
|
1215 | - if ( ! empty( $results ) ) { |
|
1213 | + if (!empty($results)) { |
|
1214 | + $results = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value = '%s' AND meta_key = '_thumbnail_id'", array($results[0]->ID))); |
|
1215 | + if (!empty($results)) { |
|
1216 | 1216 | return true; |
1217 | - } else { |
|
1217 | + }else { |
|
1218 | 1218 | return false; |
1219 | 1219 | } |
1220 | - } else { |
|
1220 | + }else { |
|
1221 | 1221 | return false; |
1222 | 1222 | } |
1223 | 1223 | } |
@@ -1228,10 +1228,10 @@ discard block |
||
1228 | 1228 | * |
1229 | 1229 | * @param $id int |
1230 | 1230 | */ |
1231 | - public function queue_item( $id ) { |
|
1232 | - if ( is_array( $this->import_queue ) && ! in_array( $id, $this->import_queue ) ) { |
|
1231 | + public function queue_item($id) { |
|
1232 | + if (is_array($this->import_queue) && !in_array($id, $this->import_queue)) { |
|
1233 | 1233 | $this->import_queue[] = $id; |
1234 | - } else { |
|
1234 | + }else { |
|
1235 | 1235 | $this->import_queue[] = $id; |
1236 | 1236 | } |
1237 | 1237 | } |
@@ -1240,18 +1240,18 @@ discard block |
||
1240 | 1240 | * Saves the queue to the option. |
1241 | 1241 | */ |
1242 | 1242 | public function save_queue() { |
1243 | - if ( ! empty( $this->import_queue ) ) { |
|
1244 | - if ( ! empty( $this->queued_imports ) ) { |
|
1245 | - $saved_imports = array_merge( $this->queued_imports, $this->import_queue ); |
|
1246 | - } else { |
|
1243 | + if (!empty($this->import_queue)) { |
|
1244 | + if (!empty($this->queued_imports)) { |
|
1245 | + $saved_imports = array_merge($this->queued_imports, $this->import_queue); |
|
1246 | + }else { |
|
1247 | 1247 | $saved_imports = $this->import_queue; |
1248 | 1248 | } |
1249 | 1249 | |
1250 | - delete_option( 'lsx_wetu_importer_que' ); |
|
1250 | + delete_option('lsx_wetu_importer_que'); |
|
1251 | 1251 | |
1252 | - if ( ! empty( $saved_imports ) ) { |
|
1253 | - $saved_imports = array_unique( $saved_imports ); |
|
1254 | - update_option( 'lsx_wetu_importer_que', $saved_imports ); |
|
1252 | + if (!empty($saved_imports)) { |
|
1253 | + $saved_imports = array_unique($saved_imports); |
|
1254 | + update_option('lsx_wetu_importer_que', $saved_imports); |
|
1255 | 1255 | } |
1256 | 1256 | } |
1257 | 1257 | } |
@@ -1264,13 +1264,13 @@ discard block |
||
1264 | 1264 | <thead> |
1265 | 1265 | <tr> |
1266 | 1266 | <th style="" class="manage-column column-cb check-column" id="cb" scope="col"> |
1267 | - <label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e( 'Select All', 'lsx-wetu-importer' ); ?></label> |
|
1267 | + <label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e('Select All', 'lsx-wetu-importer'); ?></label> |
|
1268 | 1268 | <input type="checkbox" id="cb-select-all-1"> |
1269 | 1269 | </th> |
1270 | - <th style="" class="manage-column column-title " id="title" style="width:50%;" scope="col"><?php esc_attr_e( 'Title', 'lsx-wetu-importer' ); ?></th> |
|
1271 | - <th style="" class="manage-column column-date" id="ref" style="width:10%;" scope="col"><?php esc_attr_e( 'Ref', 'lsx-wetu-importer' ); ?></th> |
|
1272 | - <th style="" class="manage-column column-date" id="date" scope="col"><?php esc_attr_e( 'Date', 'lsx-wetu-importer' ); ?></th> |
|
1273 | - <th style="" class="manage-column column-ssid" id="ssid" scope="col"><?php esc_attr_e( 'WETU ID', 'lsx-wetu-importer' ); ?></th> |
|
1270 | + <th style="" class="manage-column column-title " id="title" style="width:50%;" scope="col"><?php esc_attr_e('Title', 'lsx-wetu-importer'); ?></th> |
|
1271 | + <th style="" class="manage-column column-date" id="ref" style="width:10%;" scope="col"><?php esc_attr_e('Ref', 'lsx-wetu-importer'); ?></th> |
|
1272 | + <th style="" class="manage-column column-date" id="date" scope="col"><?php esc_attr_e('Date', 'lsx-wetu-importer'); ?></th> |
|
1273 | + <th style="" class="manage-column column-ssid" id="ssid" scope="col"><?php esc_attr_e('WETU ID', 'lsx-wetu-importer'); ?></th> |
|
1274 | 1274 | </tr> |
1275 | 1275 | </thead> |
1276 | 1276 | <?php |
@@ -1284,13 +1284,13 @@ discard block |
||
1284 | 1284 | <tfoot> |
1285 | 1285 | <tr> |
1286 | 1286 | <th style="" class="manage-column column-cb check-column" id="cb" scope="col"> |
1287 | - <label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e( 'Select All', 'lsx-wetu-importer' ); ?></label> |
|
1287 | + <label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e('Select All', 'lsx-wetu-importer'); ?></label> |
|
1288 | 1288 | <input type="checkbox" id="cb-select-all-1"> |
1289 | 1289 | </th> |
1290 | - <th style="" class="manage-column column-title" scope="col"><?php esc_attr_e( 'Title', 'lsx-wetu-importer' ); ?></th> |
|
1291 | - <th style="" class="manage-column column-date" id="ref" style="width:10%;" scope="col"><?php esc_attr_e( 'Ref', 'lsx-wetu-importer' ); ?></th> |
|
1292 | - <th style="" class="manage-column column-date" scope="col"><?php esc_attr_e( 'Date', 'lsx-wetu-importer' ); ?></th> |
|
1293 | - <th style="" class="manage-column column-ssid" scope="col"><?php esc_attr_e( 'WETU ID', 'lsx-wetu-importer' ); ?></th> |
|
1290 | + <th style="" class="manage-column column-title" scope="col"><?php esc_attr_e('Title', 'lsx-wetu-importer'); ?></th> |
|
1291 | + <th style="" class="manage-column column-date" id="ref" style="width:10%;" scope="col"><?php esc_attr_e('Ref', 'lsx-wetu-importer'); ?></th> |
|
1292 | + <th style="" class="manage-column column-date" scope="col"><?php esc_attr_e('Date', 'lsx-wetu-importer'); ?></th> |
|
1293 | + <th style="" class="manage-column column-ssid" scope="col"><?php esc_attr_e('WETU ID', 'lsx-wetu-importer'); ?></th> |
|
1294 | 1294 | </tr> |
1295 | 1295 | </tfoot> |
1296 | 1296 | <?php |