@@ -156,31 +156,31 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function __construct() { |
158 | 158 | |
159 | - add_action( 'admin_init', array( $this, 'compatible_version_check' ) ); |
|
159 | + add_action('admin_init', array($this, 'compatible_version_check')); |
|
160 | 160 | |
161 | 161 | // Don't run anything else in the plugin, if we're on an incompatible PHP version |
162 | - if ( ! self::compatible_version() ) { |
|
162 | + if (!self::compatible_version()) { |
|
163 | 163 | return; |
164 | 164 | } |
165 | 165 | |
166 | 166 | $this->set_variables(); |
167 | 167 | |
168 | - add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); |
|
169 | - add_action( 'admin_enqueue_scripts', array($this,'admin_scripts') ,11 ); |
|
170 | - add_action( 'admin_menu', array( $this, 'register_importer_page' ),20 ); |
|
168 | + add_action('init', array($this, 'load_plugin_textdomain')); |
|
169 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts'), 11); |
|
170 | + add_action('admin_menu', array($this, 'register_importer_page'), 20); |
|
171 | 171 | |
172 | 172 | require_once(WETU_IMPORTER_PATH.'classes/class-accommodation.php'); |
173 | 173 | require_once(WETU_IMPORTER_PATH.'classes/class-destination.php'); |
174 | 174 | require_once(WETU_IMPORTER_PATH.'classes/class-tours.php'); |
175 | 175 | |
176 | - add_action( 'init', array( $this, 'load_class' ) ); |
|
176 | + add_action('init', array($this, 'load_class')); |
|
177 | 177 | |
178 | - if('default' !== $this->tab_slug){ |
|
179 | - add_action('wp_ajax_lsx_tour_importer',array($this,'process_ajax_search')); |
|
180 | - add_action('wp_ajax_nopriv_lsx_tour_importer',array($this,'process_ajax_search')); |
|
178 | + if ('default' !== $this->tab_slug) { |
|
179 | + add_action('wp_ajax_lsx_tour_importer', array($this, 'process_ajax_search')); |
|
180 | + add_action('wp_ajax_nopriv_lsx_tour_importer', array($this, 'process_ajax_search')); |
|
181 | 181 | |
182 | - add_action('wp_ajax_lsx_import_items',array($this,'process_ajax_import')); |
|
183 | - add_action('wp_ajax_nopriv_lsx_import_items',array($this,'process_ajax_import')); |
|
182 | + add_action('wp_ajax_lsx_import_items', array($this, 'process_ajax_import')); |
|
183 | + add_action('wp_ajax_nopriv_lsx_import_items', array($this, 'process_ajax_import')); |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | |
@@ -192,18 +192,18 @@ discard block |
||
192 | 192 | * @since 1.0.0 |
193 | 193 | */ |
194 | 194 | public function load_plugin_textdomain() { |
195 | - load_plugin_textdomain( 'wetu-importer', FALSE, basename( WETU_IMPORTER_PATH ) . '/languages'); |
|
195 | + load_plugin_textdomain('wetu-importer', FALSE, basename(WETU_IMPORTER_PATH).'/languages'); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
199 | 199 | * Sets the variables used throughout the plugin. |
200 | 200 | */ |
201 | 201 | public function set_variables() { |
202 | - $this->post_types = array('accommodation','destination','tour'); |
|
203 | - $temp_options = get_option('_lsx-to_settings',false); |
|
202 | + $this->post_types = array('accommodation', 'destination', 'tour'); |
|
203 | + $temp_options = get_option('_lsx-to_settings', false); |
|
204 | 204 | |
205 | 205 | //Set the options. |
206 | - if(false !== $temp_options && isset($temp_options[$this->plugin_slug])) { |
|
206 | + if (false !== $temp_options && isset($temp_options[$this->plugin_slug])) { |
|
207 | 207 | $this->options = $temp_options[$this->plugin_slug]; |
208 | 208 | |
209 | 209 | $this->api_key = false; |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | } |
222 | 222 | |
223 | 223 | //Set the tab slug |
224 | - if(isset($_GET['tab']) || isset($_POST['type'])) { |
|
224 | + if (isset($_GET['tab']) || isset($_POST['type'])) { |
|
225 | 225 | if (isset($_GET['tab'])) { |
226 | 226 | $this->tab_slug = $_GET['tab']; |
227 | - } else { |
|
227 | + }else { |
|
228 | 228 | $this->tab_slug = $_POST['type']; |
229 | 229 | } |
230 | 230 | |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | if (isset($this->options['cropping']) && '' !== $this->options['cropping']) { |
249 | 249 | $cropping = $this->options['cropping']; |
250 | 250 | } |
251 | - $this->image_scaling_url = 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/'; |
|
251 | + $this->image_scaling_url = 'https://wetu.com/ImageHandler/'.$cropping.$width.'x'.$height.'/'; |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * @since 1.0.0 |
272 | 272 | */ |
273 | 273 | public static function compatible_version() { |
274 | - if ( version_compare( PHP_VERSION, '5.6', '<' ) ) { |
|
274 | + if (version_compare(PHP_VERSION, '5.6', '<')) { |
|
275 | 275 | return false; |
276 | 276 | } |
277 | 277 | |
@@ -285,13 +285,13 @@ discard block |
||
285 | 285 | * @since 1.0.0 |
286 | 286 | */ |
287 | 287 | public function compatible_version_check() { |
288 | - if ( ! self::compatible_version() ) { |
|
289 | - if ( is_plugin_active( plugin_basename( WETU_IMPORTER_CORE ) ) ) { |
|
290 | - deactivate_plugins( plugin_basename( WETU_IMPORTER_CORE ) ); |
|
291 | - add_action( 'admin_notices', array( $this, 'compatible_version_notice' ) ); |
|
288 | + if (!self::compatible_version()) { |
|
289 | + if (is_plugin_active(plugin_basename(WETU_IMPORTER_CORE))) { |
|
290 | + deactivate_plugins(plugin_basename(WETU_IMPORTER_CORE)); |
|
291 | + add_action('admin_notices', array($this, 'compatible_version_notice')); |
|
292 | 292 | |
293 | - if ( isset( $_GET['activate'] ) ) { |
|
294 | - unset( $_GET['activate'] ); |
|
293 | + if (isset($_GET['activate'])) { |
|
294 | + unset($_GET['activate']); |
|
295 | 295 | } |
296 | 296 | } |
297 | 297 | } |
@@ -304,8 +304,8 @@ discard block |
||
304 | 304 | */ |
305 | 305 | public function compatible_version_notice() { |
306 | 306 | $class = 'notice notice-error'; |
307 | - $message = esc_html__( 'Wetu Importer Plugin requires PHP 5.6 or higher.', 'wetu-importer' ); |
|
308 | - printf( '<div class="%1$s"><p>%2$s</p></div>', esc_html( $class ), esc_html( $message ) ); |
|
307 | + $message = esc_html__('Wetu Importer Plugin requires PHP 5.6 or higher.', 'wetu-importer'); |
|
308 | + printf('<div class="%1$s"><p>%2$s</p></div>', esc_html($class), esc_html($message)); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | /** |
@@ -315,9 +315,9 @@ discard block |
||
315 | 315 | * @since 1.0.0 |
316 | 316 | */ |
317 | 317 | public static function compatible_version_check_on_activation() { |
318 | - if ( ! self::compatible_version() ) { |
|
319 | - deactivate_plugins( plugin_basename( WETU_IMPORTER_CORE ) ); |
|
320 | - wp_die( esc_html__( 'Wetu Importer Plugin requires PHP 5.6 or higher.', 'wetu-importer' ) ); |
|
318 | + if (!self::compatible_version()) { |
|
319 | + deactivate_plugins(plugin_basename(WETU_IMPORTER_CORE)); |
|
320 | + wp_die(esc_html__('Wetu Importer Plugin requires PHP 5.6 or higher.', 'wetu-importer')); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | |
@@ -326,9 +326,9 @@ discard block |
||
326 | 326 | /* |
327 | 327 | * Load the importer class you want to use |
328 | 328 | */ |
329 | - public function load_class(){ |
|
329 | + public function load_class() { |
|
330 | 330 | |
331 | - switch($this->tab_slug){ |
|
331 | + switch ($this->tab_slug) { |
|
332 | 332 | case 'accommodation': |
333 | 333 | $this->current_importer = new WETU_Importer_Accommodation(); |
334 | 334 | break; |
@@ -352,25 +352,25 @@ discard block |
||
352 | 352 | * Registers the admin page which will house the importer form. |
353 | 353 | */ |
354 | 354 | public function register_importer_page() { |
355 | - add_submenu_page( 'tour-operator',esc_html__( 'Importer', 'tour-operator' ), esc_html__( 'Importer', 'tour-operator' ), 'manage_options', 'wetu-importer', array( $this, 'display_page' ) ); |
|
355 | + add_submenu_page('tour-operator', esc_html__('Importer', 'tour-operator'), esc_html__('Importer', 'tour-operator'), 'manage_options', 'wetu-importer', array($this, 'display_page')); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
359 | 359 | * Enqueue the JS needed to contact wetu and return your result. |
360 | 360 | */ |
361 | 361 | public function admin_scripts() { |
362 | - if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) { |
|
362 | + if (defined('WP_DEBUG') && true === WP_DEBUG) { |
|
363 | 363 | $min = ''; |
364 | - } else { |
|
364 | + }else { |
|
365 | 365 | $min = '.min'; |
366 | 366 | } |
367 | 367 | $min = ''; |
368 | 368 | |
369 | - if(is_admin() && isset($_GET['page']) && $this->plugin_slug === $_GET['page']){ |
|
370 | - wp_enqueue_script( 'wetu-importers-script', WETU_IMPORTER_URL . 'assets/js/wetu-importer' . $min . '.js', array( 'jquery' ), WETU_IMPORTER_VER, true ); |
|
371 | - wp_localize_script( 'wetu-importers-script', 'lsx_tour_importer_params', array( |
|
369 | + if (is_admin() && isset($_GET['page']) && $this->plugin_slug === $_GET['page']) { |
|
370 | + wp_enqueue_script('wetu-importers-script', WETU_IMPORTER_URL.'assets/js/wetu-importer'.$min.'.js', array('jquery'), WETU_IMPORTER_VER, true); |
|
371 | + wp_localize_script('wetu-importers-script', 'lsx_tour_importer_params', array( |
|
372 | 372 | 'ajax_url' => admin_url('admin-ajax.php'), |
373 | - ) ); |
|
373 | + )); |
|
374 | 374 | } |
375 | 375 | } |
376 | 376 | |
@@ -382,14 +382,14 @@ discard block |
||
382 | 382 | <div class="wrap"> |
383 | 383 | <?php screen_icon(); ?> |
384 | 384 | |
385 | - <?php if(!is_object($this->current_importer)){ |
|
385 | + <?php if (!is_object($this->current_importer)) { |
|
386 | 386 | ?> |
387 | - <h2><?php _e('Welcome to the LSX Wetu Importer','wetu-importer'); ?></h2> |
|
387 | + <h2><?php _e('Welcome to the LSX Wetu Importer', 'wetu-importer'); ?></h2> |
|
388 | 388 | <p>If this is the first time you are running the import, then follow the steps below.</p> |
389 | 389 | <ul> |
390 | - <li>Step 1 - Import your <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=tour"><?php _e('Tours','wetu-importer'); ?></a></li> |
|
391 | - <li>Step 2 - The tour import will have created draft <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=accommodation"><?php _e('accommodation','wetu-importer'); ?></a> that will need to be imported.</li> |
|
392 | - <li>Step 3 - Lastly import the <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=destination"><?php _e('destinations','wetu-importer'); ?></a> draft posts created during the previous two steps.</li> |
|
390 | + <li>Step 1 - Import your <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=tour"><?php _e('Tours', 'wetu-importer'); ?></a></li> |
|
391 | + <li>Step 2 - The tour import will have created draft <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=accommodation"><?php _e('accommodation', 'wetu-importer'); ?></a> that will need to be imported.</li> |
|
392 | + <li>Step 3 - Lastly import the <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=destination"><?php _e('destinations', 'wetu-importer'); ?></a> draft posts created during the previous two steps.</li> |
|
393 | 393 | </ul> |
394 | 394 | |
395 | 395 | <?php /*<h3><?php _e('Additional Tools','wetu-importer'); ?></h3> |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | <?php } ?> |
401 | 401 | </ul> |
402 | 402 | <?php*/ |
403 | - }else{ |
|
403 | + }else { |
|
404 | 404 | $this->current_importer->display_page(); |
405 | 405 | }; ?> |
406 | 406 | </div> |
@@ -415,38 +415,38 @@ discard block |
||
415 | 415 | <form class="ajax-form" id="<?php echo $this->plugin_slug; ?>-search-form" method="get" action="tools.php" data-type="<?php echo $this->tab_slug; ?>"> |
416 | 416 | <input type="hidden" name="page" value="<?php echo $this->tab_slug; ?>" /> |
417 | 417 | |
418 | - <h3><span class="dashicons dashicons-search"></span> <?php _e('Search','wetu-importer'); ?></h3> |
|
418 | + <h3><span class="dashicons dashicons-search"></span> <?php _e('Search', 'wetu-importer'); ?></h3> |
|
419 | 419 | |
420 | - <?php do_action('wetu_importer_search_form',$this); ?> |
|
420 | + <?php do_action('wetu_importer_search_form', $this); ?> |
|
421 | 421 | |
422 | 422 | <div class="normal-search"> |
423 | - <input pattern=".{3,}" placeholder="3 characters minimum" class="keyword" name="keyword" value=""> <input class="button button-primary submit" type="submit" value="<?php _e('Search','wetu-importer'); ?>" /> |
|
423 | + <input pattern=".{3,}" placeholder="3 characters minimum" class="keyword" name="keyword" value=""> <input class="button button-primary submit" type="submit" value="<?php _e('Search', 'wetu-importer'); ?>" /> |
|
424 | 424 | </div> |
425 | 425 | <div class="advanced-search hidden" style="display:none;"> |
426 | - <p><?php _e('Enter several keywords, each on a new line.','wetu-importer'); ?></p> |
|
426 | + <p><?php _e('Enter several keywords, each on a new line.', 'wetu-importer'); ?></p> |
|
427 | 427 | <textarea rows="10" cols="40" name="bulk-keywords"></textarea> |
428 | - <input class="button button-primary submit" type="submit" value="<?php _e('Search','wetu-importer'); ?>" /> |
|
428 | + <input class="button button-primary submit" type="submit" value="<?php _e('Search', 'wetu-importer'); ?>" /> |
|
429 | 429 | </div> |
430 | 430 | |
431 | 431 | <p> |
432 | - <a class="advanced-search-toggle" href="#"><?php _e('Bulk Search','wetu-importer'); ?></a> | |
|
433 | - <a class="published search-toggle" href="#publish"><?php esc_attr_e('Published','wetu-importer'); ?></a> | |
|
434 | - <a class="pending search-toggle" href="#pending"><?php esc_attr_e('Pending','wetu-importer'); ?></a> | |
|
435 | - <a class="draft search-toggle" href="#draft"><?php esc_attr_e('Draft','wetu-importer'); ?></a> |
|
436 | - |
|
437 | - <?php if('tour'===$this->tab_slug){ ?> |
|
438 | - | <a class="import search-toggle" href="#import"><?php esc_attr_e('WETU','wetu-importer'); ?></a> |
|
439 | - <?php }else if(!empty($this->queued_imports)) { ?> |
|
440 | - | <a class="import search-toggle" href="#import"><?php esc_attr_e('WETU Queue','wetu-importer'); ?></a> |
|
432 | + <a class="advanced-search-toggle" href="#"><?php _e('Bulk Search', 'wetu-importer'); ?></a> | |
|
433 | + <a class="published search-toggle" href="#publish"><?php esc_attr_e('Published', 'wetu-importer'); ?></a> | |
|
434 | + <a class="pending search-toggle" href="#pending"><?php esc_attr_e('Pending', 'wetu-importer'); ?></a> | |
|
435 | + <a class="draft search-toggle" href="#draft"><?php esc_attr_e('Draft', 'wetu-importer'); ?></a> |
|
436 | + |
|
437 | + <?php if ('tour' === $this->tab_slug) { ?> |
|
438 | + | <a class="import search-toggle" href="#import"><?php esc_attr_e('WETU', 'wetu-importer'); ?></a> |
|
439 | + <?php }else if (!empty($this->queued_imports)) { ?> |
|
440 | + | <a class="import search-toggle" href="#import"><?php esc_attr_e('WETU Queue', 'wetu-importer'); ?></a> |
|
441 | 441 | <?php } ?> |
442 | 442 | </p> |
443 | 443 | |
444 | 444 | <div class="ajax-loader" style="display:none;width:100%;text-align:center;"> |
445 | - <img style="width:64px;" src="<?php echo WETU_IMPORTER_URL.'assets/images/ajaxloader.gif';?>" /> |
|
445 | + <img style="width:64px;" src="<?php echo WETU_IMPORTER_URL.'assets/images/ajaxloader.gif'; ?>" /> |
|
446 | 446 | </div> |
447 | 447 | |
448 | 448 | <div class="ajax-loader-small" style="display:none;width:100%;text-align:center;"> |
449 | - <img style="width:32px;" src="<?php echo WETU_IMPORTER_URL.'assets/images/ajaxloader.gif';?>" /> |
|
449 | + <img style="width:32px;" src="<?php echo WETU_IMPORTER_URL.'assets/images/ajaxloader.gif'; ?>" /> |
|
450 | 450 | </div> |
451 | 451 | </form> |
452 | 452 | <?php |
@@ -495,15 +495,15 @@ discard block |
||
495 | 495 | * |
496 | 496 | * @param $tab string |
497 | 497 | */ |
498 | - public function navigation($tab='') { |
|
498 | + public function navigation($tab = '') { |
|
499 | 499 | $post_types = array( |
500 | - 'tour' => esc_attr('Tours','wetu-importer'), |
|
501 | - 'accommodation' => esc_attr('Accommodation','wetu-importer'), |
|
502 | - 'destination' => esc_attr('Destinations','wetu-importer'), |
|
500 | + 'tour' => esc_attr('Tours', 'wetu-importer'), |
|
501 | + 'accommodation' => esc_attr('Accommodation', 'wetu-importer'), |
|
502 | + 'destination' => esc_attr('Destinations', 'wetu-importer'), |
|
503 | 503 | ); |
504 | - echo '<div class="wet-navigation"><div class="subsubsub"><a class="'.$this->itemd($tab,'','current',false).'" href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'">'.esc_attr('Home','wetu-importer').'</a>'; |
|
505 | - foreach($post_types as $post_type => $label){ |
|
506 | - echo ' | <a class="'.$this->itemd($tab,$post_type,'current',false).'" href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab='.$post_type.'">'.$label.'</a>'; |
|
504 | + echo '<div class="wet-navigation"><div class="subsubsub"><a class="'.$this->itemd($tab, '', 'current', false).'" href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'">'.esc_attr('Home', 'wetu-importer').'</a>'; |
|
505 | + foreach ($post_types as $post_type => $label) { |
|
506 | + echo ' | <a class="'.$this->itemd($tab, $post_type, 'current', false).'" href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab='.$post_type.'">'.$label.'</a>'; |
|
507 | 507 | } |
508 | 508 | echo '</div><br clear="both"/></div>'; |
509 | 509 | } |
@@ -511,23 +511,23 @@ discard block |
||
511 | 511 | /** |
512 | 512 | * set_taxonomy with some terms |
513 | 513 | */ |
514 | - public function team_member_checkboxes($selected=array()) { |
|
515 | - if(post_type_exists('team')) { ?> |
|
514 | + public function team_member_checkboxes($selected = array()) { |
|
515 | + if (post_type_exists('team')) { ?> |
|
516 | 516 | <ul> |
517 | 517 | <?php |
518 | - $team_args=array( |
|
518 | + $team_args = array( |
|
519 | 519 | 'post_type' => 'team', |
520 | 520 | 'post_status' => 'publish', |
521 | 521 | 'nopagin' => true, |
522 | 522 | 'fields' => 'ids' |
523 | 523 | ); |
524 | 524 | $team_members = new WP_Query($team_args); |
525 | - if($team_members->have_posts()){ |
|
526 | - foreach($team_members->posts as $member){ ?> |
|
527 | - <li><input class="team" <?php $this->checked($selected,$member); ?> type="checkbox" value="<?php echo $member; ?>" /> <?php echo get_the_title($member); ?></li> |
|
525 | + if ($team_members->have_posts()) { |
|
526 | + foreach ($team_members->posts as $member) { ?> |
|
527 | + <li><input class="team" <?php $this->checked($selected, $member); ?> type="checkbox" value="<?php echo $member; ?>" /> <?php echo get_the_title($member); ?></li> |
|
528 | 528 | <?php } |
529 | - }else{ ?> |
|
530 | - <li><input class="team" type="checkbox" value="0" /> <?php _e('None','wetu-importer'); ?></li> |
|
529 | + }else { ?> |
|
530 | + <li><input class="team" type="checkbox" value="0" /> <?php _e('None', 'wetu-importer'); ?></li> |
|
531 | 531 | <?php } |
532 | 532 | ?> |
533 | 533 | </ul> |
@@ -544,12 +544,12 @@ discard block |
||
544 | 544 | * @param $needle string |
545 | 545 | * @param $echo bool |
546 | 546 | */ |
547 | - public function checked($haystack=false,$needle='',$echo=true) { |
|
548 | - $return = $this->itemd($haystack,$needle,'checked'); |
|
549 | - if('' !== $return) { |
|
547 | + public function checked($haystack = false, $needle = '', $echo = true) { |
|
548 | + $return = $this->itemd($haystack, $needle, 'checked'); |
|
549 | + if ('' !== $return) { |
|
550 | 550 | if (true === $echo) { |
551 | 551 | echo $return; |
552 | - } else { |
|
552 | + }else { |
|
553 | 553 | return $return; |
554 | 554 | } |
555 | 555 | } |
@@ -562,12 +562,12 @@ discard block |
||
562 | 562 | * @param $needle string |
563 | 563 | * @param $echo bool |
564 | 564 | */ |
565 | - public function selected($haystack=false,$needle='',$echo=true) { |
|
566 | - $return = $this->itemd($haystack,$needle,'selected'); |
|
567 | - if('' !== $return) { |
|
565 | + public function selected($haystack = false, $needle = '', $echo = true) { |
|
566 | + $return = $this->itemd($haystack, $needle, 'selected'); |
|
567 | + if ('' !== $return) { |
|
568 | 568 | if (true === $echo) { |
569 | 569 | echo $return; |
570 | - } else { |
|
570 | + }else { |
|
571 | 571 | return $return; |
572 | 572 | } |
573 | 573 | } |
@@ -582,16 +582,16 @@ discard block |
||
582 | 582 | * @param $wrap bool |
583 | 583 | * @return $html string |
584 | 584 | */ |
585 | - public function itemd($haystack=false,$needle='',$type='',$wrap=true) { |
|
585 | + public function itemd($haystack = false, $needle = '', $type = '', $wrap = true) { |
|
586 | 586 | $html = ''; |
587 | - if('' !== $type) { |
|
587 | + if ('' !== $type) { |
|
588 | 588 | if (!is_array($haystack)) { |
589 | 589 | $haystack = array($haystack); |
590 | 590 | } |
591 | 591 | if (in_array($needle, $haystack)) { |
592 | - if(true === $wrap || 'true' === $wrap) { |
|
593 | - $html = $type . '="' . $type . '"'; |
|
594 | - }else{ |
|
592 | + if (true === $wrap || 'true' === $wrap) { |
|
593 | + $html = $type.'="'.$type.'"'; |
|
594 | + }else { |
|
595 | 595 | $html = $type; |
596 | 596 | } |
597 | 597 | } |
@@ -603,9 +603,9 @@ discard block |
||
603 | 603 | /** |
604 | 604 | * grabs any attachments for the current item |
605 | 605 | */ |
606 | - public function find_attachments($id=false) { |
|
607 | - if(false !== $id){ |
|
608 | - if(empty($this->found_attachments)){ |
|
606 | + public function find_attachments($id = false) { |
|
607 | + if (false !== $id) { |
|
608 | + if (empty($this->found_attachments)) { |
|
609 | 609 | |
610 | 610 | $attachments_args = array( |
611 | 611 | 'post_parent' => $id, |
@@ -617,9 +617,9 @@ discard block |
||
617 | 617 | ); |
618 | 618 | |
619 | 619 | $attachments = new WP_Query($attachments_args); |
620 | - if($attachments->have_posts()){ |
|
621 | - foreach($attachments->posts as $attachment){ |
|
622 | - $this->found_attachments[$attachment->ID] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
620 | + if ($attachments->have_posts()) { |
|
621 | + foreach ($attachments->posts as $attachment) { |
|
622 | + $this->found_attachments[$attachment->ID] = str_replace(array('.jpg', '.png', '.jpeg'), '', $attachment->post_title); |
|
623 | 623 | $this->gallery_meta[] = $attachment->ID; |
624 | 624 | } |
625 | 625 | } |
@@ -633,18 +633,18 @@ discard block |
||
633 | 633 | /** |
634 | 634 | * Saves the room data |
635 | 635 | */ |
636 | - public function save_custom_field($value=false,$meta_key,$id,$decrease=false,$unique=true) { |
|
637 | - if(false !== $value){ |
|
638 | - if(false !== $decrease){ |
|
636 | + public function save_custom_field($value = false, $meta_key, $id, $decrease = false, $unique = true) { |
|
637 | + if (false !== $value) { |
|
638 | + if (false !== $decrease) { |
|
639 | 639 | $value = intval($value); |
640 | 640 | $value--; |
641 | 641 | } |
642 | - $prev = get_post_meta($id,$meta_key,true); |
|
642 | + $prev = get_post_meta($id, $meta_key, true); |
|
643 | 643 | |
644 | - if(false !== $id && '0' !== $id && false !== $prev && true === $unique){ |
|
645 | - update_post_meta($id,$meta_key,$value,$prev); |
|
646 | - }else{ |
|
647 | - add_post_meta($id,$meta_key,$value,$unique); |
|
644 | + if (false !== $id && '0' !== $id && false !== $prev && true === $unique) { |
|
645 | + update_post_meta($id, $meta_key, $value, $prev); |
|
646 | + }else { |
|
647 | + add_post_meta($id, $meta_key, $value, $unique); |
|
648 | 648 | } |
649 | 649 | } |
650 | 650 | } |
@@ -653,12 +653,12 @@ discard block |
||
653 | 653 | * Grabs the custom fields, and resaves an array of unique items. |
654 | 654 | */ |
655 | 655 | public function cleanup_posts() { |
656 | - if(!empty($this->cleanup_posts)){ |
|
657 | - foreach($this->cleanup_posts as $id => $key) { |
|
656 | + if (!empty($this->cleanup_posts)) { |
|
657 | + foreach ($this->cleanup_posts as $id => $key) { |
|
658 | 658 | $prev_items = get_post_meta($id, $key, false); |
659 | 659 | $new_items = array_unique($prev_items); |
660 | 660 | delete_post_meta($id, $key); |
661 | - foreach($new_items as $new_item) { |
|
661 | + foreach ($new_items as $new_item) { |
|
662 | 662 | add_post_meta($id, $key, $new_item, false); |
663 | 663 | } |
664 | 664 | } |
@@ -670,51 +670,51 @@ discard block |
||
670 | 670 | /** |
671 | 671 | * set_taxonomy with some terms |
672 | 672 | */ |
673 | - public function set_taxonomy($taxonomy,$terms,$id) { |
|
674 | - $result=array(); |
|
675 | - if(!empty($data)) |
|
673 | + public function set_taxonomy($taxonomy, $terms, $id) { |
|
674 | + $result = array(); |
|
675 | + if (!empty($data)) |
|
676 | 676 | { |
677 | - foreach($data as $k) |
|
677 | + foreach ($data as $k) |
|
678 | 678 | { |
679 | - if($id) |
|
679 | + if ($id) |
|
680 | 680 | { |
681 | - if(!$term = term_exists(trim($k), $tax)) |
|
681 | + if (!$term = term_exists(trim($k), $tax)) |
|
682 | 682 | { |
683 | 683 | $term = wp_insert_term(trim($k), $tax); |
684 | - if ( is_wp_error($term) ) |
|
684 | + if (is_wp_error($term)) |
|
685 | 685 | { |
686 | 686 | echo $term->get_error_message(); |
687 | 687 | } |
688 | 688 | else |
689 | 689 | { |
690 | - wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
690 | + wp_set_object_terms($id, intval($term['term_id']), $taxonomy, true); |
|
691 | 691 | } |
692 | 692 | } |
693 | 693 | else |
694 | 694 | { |
695 | - wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
695 | + wp_set_object_terms($id, intval($term['term_id']), $taxonomy, true); |
|
696 | 696 | } |
697 | 697 | } |
698 | 698 | else |
699 | 699 | { |
700 | - $result[]=trim($k); |
|
700 | + $result[] = trim($k); |
|
701 | 701 | } |
702 | 702 | } |
703 | 703 | } |
704 | 704 | return $result; |
705 | 705 | } |
706 | 706 | |
707 | - public function set_term($id=false,$name=false,$taxonomy=false,$parent=false){ |
|
708 | - if(!$term = term_exists($name, $taxonomy)) |
|
707 | + public function set_term($id = false, $name = false, $taxonomy = false, $parent = false) { |
|
708 | + if (!$term = term_exists($name, $taxonomy)) |
|
709 | 709 | { |
710 | - if(false !== $parent){ $parent = array('parent'=>$parent); } |
|
711 | - $term = wp_insert_term(trim($name), $taxonomy,$parent); |
|
712 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
713 | - else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); } |
|
710 | + if (false !== $parent) { $parent = array('parent'=>$parent); } |
|
711 | + $term = wp_insert_term(trim($name), $taxonomy, $parent); |
|
712 | + if (is_wp_error($term)) {echo $term->get_error_message(); } |
|
713 | + else { wp_set_object_terms($id, intval($term['term_id']), $taxonomy, true); } |
|
714 | 714 | } |
715 | 715 | else |
716 | 716 | { |
717 | - wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
717 | + wp_set_object_terms($id, intval($term['term_id']), $taxonomy, true); |
|
718 | 718 | } |
719 | 719 | return $term['term_id']; |
720 | 720 | } |
@@ -722,18 +722,18 @@ discard block |
||
722 | 722 | /** |
723 | 723 | * set_taxonomy with some terms |
724 | 724 | */ |
725 | - public function taxonomy_checkboxes($taxonomy=false,$selected=array()) { |
|
725 | + public function taxonomy_checkboxes($taxonomy = false, $selected = array()) { |
|
726 | 726 | $return = ''; |
727 | - if(false !== $taxonomy){ |
|
727 | + if (false !== $taxonomy) { |
|
728 | 728 | $return .= '<ul>'; |
729 | - $terms = get_terms(array('taxonomy'=>$taxonomy,'hide_empty'=>false)); |
|
729 | + $terms = get_terms(array('taxonomy'=>$taxonomy, 'hide_empty'=>false)); |
|
730 | 730 | |
731 | - if(!is_wp_error($terms)){ |
|
732 | - foreach($terms as $term){ |
|
733 | - $return .= '<li><input class="'.$taxonomy.'" '.$this->checked($selected,$term->term_id,false).' type="checkbox" value="'.$term->term_id.'" /> '.$term->name.'</li>'; |
|
731 | + if (!is_wp_error($terms)) { |
|
732 | + foreach ($terms as $term) { |
|
733 | + $return .= '<li><input class="'.$taxonomy.'" '.$this->checked($selected, $term->term_id, false).' type="checkbox" value="'.$term->term_id.'" /> '.$term->name.'</li>'; |
|
734 | 734 | } |
735 | - }else{ |
|
736 | - $return .= '<li><input type="checkbox" value="" /> '.__('None','wetu-importer').'</li>'; |
|
735 | + }else { |
|
736 | + $return .= '<li><input type="checkbox" value="" /> '.__('None', 'wetu-importer').'</li>'; |
|
737 | 737 | } |
738 | 738 | $return .= '</ul>'; |
739 | 739 | } |
@@ -744,53 +744,53 @@ discard block |
||
744 | 744 | /** |
745 | 745 | * Saves the longitude and lattitude, as well as sets the map marker. |
746 | 746 | */ |
747 | - public function set_map_data($data,$id,$zoom = '10') { |
|
747 | + public function set_map_data($data, $id, $zoom = '10') { |
|
748 | 748 | $longitude = $latitude = $address = false; |
749 | 749 | |
750 | - if(isset($data[0]['position'])){ |
|
750 | + if (isset($data[0]['position'])) { |
|
751 | 751 | |
752 | - if(isset($data[0]['position']['driving_latitude'])){ |
|
752 | + if (isset($data[0]['position']['driving_latitude'])) { |
|
753 | 753 | $latitude = $data[0]['position']['driving_latitude']; |
754 | - }elseif(isset($data[0]['position']['latitude'])){ |
|
754 | + }elseif (isset($data[0]['position']['latitude'])) { |
|
755 | 755 | $latitude = $data[0]['position']['latitude']; |
756 | 756 | } |
757 | 757 | |
758 | - if(isset($data[0]['position']['driving_longitude'])){ |
|
758 | + if (isset($data[0]['position']['driving_longitude'])) { |
|
759 | 759 | $longitude = $data[0]['position']['driving_longitude']; |
760 | - }elseif(isset($data[0]['position']['longitude'])){ |
|
760 | + }elseif (isset($data[0]['position']['longitude'])) { |
|
761 | 761 | $longitude = $data[0]['position']['longitude']; |
762 | 762 | } |
763 | 763 | |
764 | 764 | } |
765 | - if(isset($data[0]['content']) && isset($data[0]['content']['contact_information'])){ |
|
766 | - if(isset($data[0]['content']['contact_information']['address'])){ |
|
765 | + if (isset($data[0]['content']) && isset($data[0]['content']['contact_information'])) { |
|
766 | + if (isset($data[0]['content']['contact_information']['address'])) { |
|
767 | 767 | $address = strip_tags($data[0]['content']['contact_information']['address']); |
768 | 768 | |
769 | - $address = explode("\n",$address); |
|
770 | - foreach($address as $bitkey => $bit){ |
|
769 | + $address = explode("\n", $address); |
|
770 | + foreach ($address as $bitkey => $bit) { |
|
771 | 771 | $bit = ltrim(rtrim($bit)); |
772 | - if(false === $bit || '' === $bit || null === $bit or empty($bit)){ |
|
772 | + if (false === $bit || '' === $bit || null === $bit or empty($bit)) { |
|
773 | 773 | unset($address[$bitkey]); |
774 | 774 | } |
775 | 775 | } |
776 | - $address = implode(', ',$address); |
|
776 | + $address = implode(', ', $address); |
|
777 | 777 | $address = str_replace(', , ', ', ', $address); |
778 | 778 | } |
779 | 779 | } |
780 | 780 | |
781 | - if(false !== $longitude){ |
|
781 | + if (false !== $longitude) { |
|
782 | 782 | $location_data = array( |
783 | - 'address' => (string)$address, |
|
784 | - 'lat' => (string)$latitude, |
|
785 | - 'long' => (string)$longitude, |
|
786 | - 'zoom' => (string)$zoom, |
|
783 | + 'address' => (string) $address, |
|
784 | + 'lat' => (string) $latitude, |
|
785 | + 'long' => (string) $longitude, |
|
786 | + 'zoom' => (string) $zoom, |
|
787 | 787 | 'elevation' => '', |
788 | 788 | ); |
789 | - if(false !== $id && '0' !== $id){ |
|
790 | - $prev = get_post_meta($id,'location',true); |
|
791 | - update_post_meta($id,'location',$location_data,$prev); |
|
792 | - }else{ |
|
793 | - add_post_meta($id,'location',$location_data,true); |
|
789 | + if (false !== $id && '0' !== $id) { |
|
790 | + $prev = get_post_meta($id, 'location', true); |
|
791 | + update_post_meta($id, 'location', $location_data, $prev); |
|
792 | + }else { |
|
793 | + add_post_meta($id, 'location', $location_data, true); |
|
794 | 794 | } |
795 | 795 | } |
796 | 796 | } |
@@ -800,22 +800,22 @@ discard block |
||
800 | 800 | /** |
801 | 801 | * Creates the main gallery data |
802 | 802 | */ |
803 | - public function set_featured_image($data,$id) { |
|
804 | - if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
|
805 | - if('tour' === $this->tab_slug){ |
|
803 | + public function set_featured_image($data, $id) { |
|
804 | + if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) { |
|
805 | + if ('tour' === $this->tab_slug) { |
|
806 | 806 | $key = array_rand($data[0]['content']['images']); |
807 | - $this->featured_image = $this->attach_image($data[0]['content']['images'][$key],$id); |
|
808 | - }else{ |
|
809 | - $this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id); |
|
807 | + $this->featured_image = $this->attach_image($data[0]['content']['images'][$key], $id); |
|
808 | + }else { |
|
809 | + $this->featured_image = $this->attach_image($data[0]['content']['images'][0], $id); |
|
810 | 810 | } |
811 | 811 | |
812 | 812 | |
813 | - if(false !== $this->featured_image){ |
|
814 | - delete_post_meta($id,'_thumbnail_id'); |
|
815 | - add_post_meta($id,'_thumbnail_id',$this->featured_image,true); |
|
813 | + if (false !== $this->featured_image) { |
|
814 | + delete_post_meta($id, '_thumbnail_id'); |
|
815 | + add_post_meta($id, '_thumbnail_id', $this->featured_image, true); |
|
816 | 816 | |
817 | - if(!empty($this->gallery_meta) && !in_array($this->featured_image,$this->gallery_meta)){ |
|
818 | - add_post_meta($id,'gallery',$this->featured_image,false); |
|
817 | + if (!empty($this->gallery_meta) && !in_array($this->featured_image, $this->gallery_meta)) { |
|
818 | + add_post_meta($id, 'gallery', $this->featured_image, false); |
|
819 | 819 | $this->gallery_meta[] = $this->featured_image; |
820 | 820 | } |
821 | 821 | } |
@@ -825,23 +825,23 @@ discard block |
||
825 | 825 | /** |
826 | 826 | * Sets a banner image |
827 | 827 | */ |
828 | - public function set_banner_image($data,$id) { |
|
829 | - if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
|
828 | + public function set_banner_image($data, $id) { |
|
829 | + if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) { |
|
830 | 830 | |
831 | - if('tour' === $this->tab_slug){ |
|
831 | + if ('tour' === $this->tab_slug) { |
|
832 | 832 | $key = array_rand($data[0]['content']['images']); |
833 | - $this->banner_image = $this->attach_image($data[0]['content']['images'][$key],$id,array('width'=>'1920','height'=>'600','cropping'=>'c')); |
|
834 | - }else{ |
|
835 | - $this->banner_image = $this->attach_image($data[0]['content']['images'][1],$id,array('width'=>'1920','height'=>'600','cropping'=>'c')); |
|
833 | + $this->banner_image = $this->attach_image($data[0]['content']['images'][$key], $id, array('width'=>'1920', 'height'=>'600', 'cropping'=>'c')); |
|
834 | + }else { |
|
835 | + $this->banner_image = $this->attach_image($data[0]['content']['images'][1], $id, array('width'=>'1920', 'height'=>'600', 'cropping'=>'c')); |
|
836 | 836 | } |
837 | 837 | |
838 | - if(false !== $this->banner_image){ |
|
839 | - delete_post_meta($id,'image_group'); |
|
838 | + if (false !== $this->banner_image) { |
|
839 | + delete_post_meta($id, 'image_group'); |
|
840 | 840 | $new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image)); |
841 | - add_post_meta($id,'image_group',$new_banner,true); |
|
841 | + add_post_meta($id, 'image_group', $new_banner, true); |
|
842 | 842 | |
843 | - if(!empty($this->gallery_meta) && !in_array($this->banner_image,$this->gallery_meta)){ |
|
844 | - add_post_meta($id,'gallery',$this->banner_image,false); |
|
843 | + if (!empty($this->gallery_meta) && !in_array($this->banner_image, $this->gallery_meta)) { |
|
844 | + add_post_meta($id, 'gallery', $this->banner_image, false); |
|
845 | 845 | $this->gallery_meta[] = $this->banner_image; |
846 | 846 | } |
847 | 847 | } |
@@ -851,24 +851,24 @@ discard block |
||
851 | 851 | /** |
852 | 852 | * Creates the main gallery data |
853 | 853 | */ |
854 | - public function create_main_gallery($data,$id) { |
|
854 | + public function create_main_gallery($data, $id) { |
|
855 | 855 | |
856 | - if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
|
856 | + if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) { |
|
857 | 857 | $counter = 0; |
858 | - foreach($data[0]['content']['images'] as $image_data){ |
|
859 | - if($counter === 0 && false !== $this->featured_image){$counter++;continue;} |
|
860 | - if($counter === 1 && false !== $this->banner_image){$counter++;continue;} |
|
858 | + foreach ($data[0]['content']['images'] as $image_data) { |
|
859 | + if ($counter === 0 && false !== $this->featured_image) {$counter++; continue; } |
|
860 | + if ($counter === 1 && false !== $this->banner_image) {$counter++; continue; } |
|
861 | 861 | |
862 | - $this->gallery_meta[] = $this->attach_image($image_data,$id); |
|
862 | + $this->gallery_meta[] = $this->attach_image($image_data, $id); |
|
863 | 863 | $counter++; |
864 | 864 | } |
865 | 865 | |
866 | - if(!empty($this->gallery_meta)){ |
|
867 | - delete_post_meta($id,'gallery'); |
|
866 | + if (!empty($this->gallery_meta)) { |
|
867 | + delete_post_meta($id, 'gallery'); |
|
868 | 868 | $this->gallery_meta = array_unique($this->gallery_meta); |
869 | - foreach($this->gallery_meta as $gallery_id){ |
|
870 | - if(false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)){ |
|
871 | - add_post_meta($id,'gallery',$gallery_id,false); |
|
869 | + foreach ($this->gallery_meta as $gallery_id) { |
|
870 | + if (false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)) { |
|
871 | + add_post_meta($id, 'gallery', $gallery_id, false); |
|
872 | 872 | } |
873 | 873 | } |
874 | 874 | } |
@@ -878,27 +878,27 @@ discard block |
||
878 | 878 | /** |
879 | 879 | * search_form |
880 | 880 | */ |
881 | - public function get_scaling_url($args=array()) { |
|
881 | + public function get_scaling_url($args = array()) { |
|
882 | 882 | |
883 | 883 | $defaults = array( |
884 | 884 | 'width' => '640', |
885 | 885 | 'height' => '480', |
886 | 886 | 'cropping' => 'c' |
887 | 887 | ); |
888 | - if(false !== $this->options){ |
|
889 | - if(isset($this->options['width']) && '' !== $this->options['width']){ |
|
888 | + if (false !== $this->options) { |
|
889 | + if (isset($this->options['width']) && '' !== $this->options['width']) { |
|
890 | 890 | $defaults['width'] = $this->options['width']; |
891 | 891 | } |
892 | 892 | |
893 | - if(isset($this->options['height']) && '' !== $this->options['height']){ |
|
893 | + if (isset($this->options['height']) && '' !== $this->options['height']) { |
|
894 | 894 | $defaults['height'] = $this->options['height']; |
895 | 895 | } |
896 | 896 | |
897 | - if(isset($this->options['cropping']) && '' !== $this->options['cropping']){ |
|
897 | + if (isset($this->options['cropping']) && '' !== $this->options['cropping']) { |
|
898 | 898 | $defaults['cropping'] = $this->options['cropping']; |
899 | 899 | } |
900 | 900 | } |
901 | - $args = wp_parse_args($args,$defaults); |
|
901 | + $args = wp_parse_args($args, $defaults); |
|
902 | 902 | |
903 | 903 | $cropping = $args['cropping']; |
904 | 904 | $width = $args['width']; |
@@ -911,40 +911,40 @@ discard block |
||
911 | 911 | /** |
912 | 912 | * Attaches 1 image |
913 | 913 | */ |
914 | - public function attach_image($v=false,$parent_id,$image_sizes=false){ |
|
915 | - if(false !== $v){ |
|
916 | - $temp_fragment = explode('/',$v['url_fragment']); |
|
917 | - $url_filename = $temp_fragment[count($temp_fragment)-1]; |
|
918 | - $url_filename = str_replace(array('.jpg','.png','.jpeg'),'',$url_filename); |
|
919 | - |
|
920 | - if(in_array($url_filename,$this->found_attachments)){ |
|
921 | - return array_search($url_filename,$this->found_attachments); |
|
914 | + public function attach_image($v = false, $parent_id, $image_sizes = false) { |
|
915 | + if (false !== $v) { |
|
916 | + $temp_fragment = explode('/', $v['url_fragment']); |
|
917 | + $url_filename = $temp_fragment[count($temp_fragment) - 1]; |
|
918 | + $url_filename = str_replace(array('.jpg', '.png', '.jpeg'), '', $url_filename); |
|
919 | + |
|
920 | + if (in_array($url_filename, $this->found_attachments)) { |
|
921 | + return array_search($url_filename, $this->found_attachments); |
|
922 | 922 | } |
923 | 923 | |
924 | - $postdata=array(); |
|
925 | - if(empty($v['label'])) |
|
924 | + $postdata = array(); |
|
925 | + if (empty($v['label'])) |
|
926 | 926 | { |
927 | - $v['label']=''; |
|
927 | + $v['label'] = ''; |
|
928 | 928 | } |
929 | - if(!empty($v['description'])) |
|
929 | + if (!empty($v['description'])) |
|
930 | 930 | { |
931 | - $desc=wp_strip_all_tags($v['description']); |
|
932 | - $posdata=array('post_excerpt'=>$desc); |
|
931 | + $desc = wp_strip_all_tags($v['description']); |
|
932 | + $posdata = array('post_excerpt'=>$desc); |
|
933 | 933 | } |
934 | - if(!empty($v['section'])) |
|
934 | + if (!empty($v['section'])) |
|
935 | 935 | { |
936 | - $desc=wp_strip_all_tags($v['section']); |
|
937 | - $posdata=array('post_excerpt'=>$desc); |
|
936 | + $desc = wp_strip_all_tags($v['section']); |
|
937 | + $posdata = array('post_excerpt'=>$desc); |
|
938 | 938 | } |
939 | 939 | |
940 | - $attachID=NULL; |
|
940 | + $attachID = NULL; |
|
941 | 941 | //Resizor - add option to setting if required |
942 | - $fragment = str_replace(' ','%20',$v['url_fragment']); |
|
942 | + $fragment = str_replace(' ', '%20', $v['url_fragment']); |
|
943 | 943 | $url = $this->get_scaling_url($image_sizes).$fragment; |
944 | - $attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata); |
|
944 | + $attachID = $this->attach_external_image2($url, $parent_id, '', $v['label'], $postdata); |
|
945 | 945 | |
946 | 946 | //echo($attachID.' add image'); |
947 | - if($attachID!=NULL) |
|
947 | + if ($attachID != NULL) |
|
948 | 948 | { |
949 | 949 | return $attachID; |
950 | 950 | } |
@@ -952,13 +952,13 @@ discard block |
||
952 | 952 | return false; |
953 | 953 | } |
954 | 954 | |
955 | - public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
|
955 | + public function attach_external_image2($url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array()) { |
|
956 | 956 | |
957 | - if ( !$url || !$post_id ) { return new WP_Error('missing', "Need a valid URL and post ID..."); } |
|
957 | + if (!$url || !$post_id) { return new WP_Error('missing', "Need a valid URL and post ID..."); } |
|
958 | 958 | |
959 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
960 | - require_once(ABSPATH . 'wp-admin/includes/media.php'); |
|
961 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
959 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
960 | + require_once(ABSPATH.'wp-admin/includes/media.php'); |
|
961 | + require_once(ABSPATH.'wp-admin/includes/image.php'); |
|
962 | 962 | // Download file to temp location, returns full server path to temp file |
963 | 963 | //$tmp = download_url( $url ); |
964 | 964 | |
@@ -967,53 +967,53 @@ discard block |
||
967 | 967 | |
968 | 968 | $image = file_get_contents($url); |
969 | 969 | file_put_contents($tmp, $image); |
970 | - chmod($tmp,'777'); |
|
970 | + chmod($tmp, '777'); |
|
971 | 971 | |
972 | - preg_match('/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches); // fix file filename for query strings |
|
972 | + preg_match('/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches); // fix file filename for query strings |
|
973 | 973 | $url_filename = basename($matches[0]); |
974 | - $url_filename=str_replace('%20','_',$url_filename); |
|
974 | + $url_filename = str_replace('%20', '_', $url_filename); |
|
975 | 975 | // extract filename from url for title |
976 | - $url_type = wp_check_filetype($url_filename); // determine file type (ext and mime/type) |
|
976 | + $url_type = wp_check_filetype($url_filename); // determine file type (ext and mime/type) |
|
977 | 977 | |
978 | 978 | // override filename if given, reconstruct server path |
979 | - if ( !empty( $filename ) && " " != $filename ) |
|
979 | + if (!empty($filename) && " " != $filename) |
|
980 | 980 | { |
981 | 981 | $filename = sanitize_file_name($filename); |
982 | - $tmppath = pathinfo( $tmp ); |
|
982 | + $tmppath = pathinfo($tmp); |
|
983 | 983 | |
984 | 984 | $extension = ''; |
985 | - if(isset($tmppath['extension'])){ |
|
985 | + if (isset($tmppath['extension'])) { |
|
986 | 986 | $extension = $tmppath['extension']; |
987 | 987 | } |
988 | 988 | |
989 | - $new = $tmppath['dirname'] . "/". $filename . "." . $extension; |
|
990 | - rename($tmp, $new); // renames temp file on server |
|
991 | - $tmp = $new; // push new filename (in path) to be used in file array later |
|
989 | + $new = $tmppath['dirname']."/".$filename.".".$extension; |
|
990 | + rename($tmp, $new); // renames temp file on server |
|
991 | + $tmp = $new; // push new filename (in path) to be used in file array later |
|
992 | 992 | } |
993 | 993 | |
994 | 994 | // assemble file data (should be built like $_FILES since wp_handle_sideload() will be using) |
995 | - $file_array['tmp_name'] = $tmp; // full server path to temp file |
|
995 | + $file_array['tmp_name'] = $tmp; // full server path to temp file |
|
996 | 996 | |
997 | - if ( !empty( $filename) && " " != $filename ) |
|
997 | + if (!empty($filename) && " " != $filename) |
|
998 | 998 | { |
999 | - $file_array['name'] = $filename . "." . $url_type['ext']; // user given filename for title, add original URL extension |
|
999 | + $file_array['name'] = $filename.".".$url_type['ext']; // user given filename for title, add original URL extension |
|
1000 | 1000 | } |
1001 | 1001 | else |
1002 | 1002 | { |
1003 | - $file_array['name'] = $url_filename; // just use original URL filename |
|
1003 | + $file_array['name'] = $url_filename; // just use original URL filename |
|
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | // set additional wp_posts columns |
1007 | - if ( empty( $post_data['post_title'] ) ) |
|
1007 | + if (empty($post_data['post_title'])) |
|
1008 | 1008 | { |
1009 | 1009 | |
1010 | - $url_filename=str_replace('%20',' ',$url_filename); |
|
1010 | + $url_filename = str_replace('%20', ' ', $url_filename); |
|
1011 | 1011 | |
1012 | - $post_data['post_title'] = basename($url_filename, "." . $url_type['ext']); // just use the original filename (no extension) |
|
1012 | + $post_data['post_title'] = basename($url_filename, ".".$url_type['ext']); // just use the original filename (no extension) |
|
1013 | 1013 | } |
1014 | 1014 | |
1015 | 1015 | // make sure gets tied to parent |
1016 | - if ( empty( $post_data['post_parent'] ) ) |
|
1016 | + if (empty($post_data['post_parent'])) |
|
1017 | 1017 | { |
1018 | 1018 | $post_data['post_parent'] = $post_id; |
1019 | 1019 | } |
@@ -1021,12 +1021,12 @@ discard block |
||
1021 | 1021 | // required libraries for media_handle_sideload |
1022 | 1022 | |
1023 | 1023 | // do the validation and storage stuff |
1024 | - $att_id = media_handle_sideload( $file_array, $post_id, null, $post_data ); // $post_data can override the items saved to wp_posts table, like post_mime_type, guid, post_parent, post_title, post_content, post_status |
|
1024 | + $att_id = media_handle_sideload($file_array, $post_id, null, $post_data); // $post_data can override the items saved to wp_posts table, like post_mime_type, guid, post_parent, post_title, post_content, post_status |
|
1025 | 1025 | |
1026 | 1026 | // If error storing permanently, unlink |
1027 | - if ( is_wp_error($att_id) ) |
|
1027 | + if (is_wp_error($att_id)) |
|
1028 | 1028 | { |
1029 | - unlink($file_array['tmp_name']); // clean up |
|
1029 | + unlink($file_array['tmp_name']); // clean up |
|
1030 | 1030 | return false; // output wp_error |
1031 | 1031 | //return $att_id; // output wp_error |
1032 | 1032 | } |
@@ -1055,24 +1055,24 @@ discard block |
||
1055 | 1055 | /** |
1056 | 1056 | * Formats the row for the completed list. |
1057 | 1057 | */ |
1058 | - public function format_completed_row($response){ |
|
1058 | + public function format_completed_row($response) { |
|
1059 | 1059 | echo '<li class="post-'.$response.'"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="'.get_permalink($response).'">'.get_the_title($response).'</a></li>'; |
1060 | 1060 | } |
1061 | 1061 | |
1062 | 1062 | /** |
1063 | 1063 | * Does a multine search |
1064 | 1064 | */ |
1065 | - public function multineedle_stripos($haystack, $needles, $offset=0) { |
|
1065 | + public function multineedle_stripos($haystack, $needles, $offset = 0) { |
|
1066 | 1066 | $found = false; |
1067 | 1067 | $needle_count = count($needles); |
1068 | - foreach($needles as $needle) { |
|
1069 | - if(false !== stripos($haystack, $needle, $offset)){ |
|
1068 | + foreach ($needles as $needle) { |
|
1069 | + if (false !== stripos($haystack, $needle, $offset)) { |
|
1070 | 1070 | $found[] = true; |
1071 | 1071 | } |
1072 | 1072 | } |
1073 | - if(false !== $found && $needle_count === count($found)){ |
|
1073 | + if (false !== $found && $needle_count === count($found)) { |
|
1074 | 1074 | return true; |
1075 | - }else{ |
|
1075 | + }else { |
|
1076 | 1076 | return false; |
1077 | 1077 | } |
1078 | 1078 | } |
@@ -1080,7 +1080,7 @@ discard block |
||
1080 | 1080 | /** |
1081 | 1081 | * Grab all the current accommodation posts via the lsx_wetu_id field. |
1082 | 1082 | */ |
1083 | - public function find_current_accommodation($post_type='accommodation') { |
|
1083 | + public function find_current_accommodation($post_type = 'accommodation') { |
|
1084 | 1084 | global $wpdb; |
1085 | 1085 | $return = array(); |
1086 | 1086 | |
@@ -1096,8 +1096,8 @@ discard block |
||
1096 | 1096 | |
1097 | 1097 | LIMIT 0,5000 |
1098 | 1098 | "); |
1099 | - if(null !== $current_accommodation && !empty($current_accommodation)){ |
|
1100 | - foreach($current_accommodation as $accom){ |
|
1099 | + if (null !== $current_accommodation && !empty($current_accommodation)) { |
|
1100 | + foreach ($current_accommodation as $accom) { |
|
1101 | 1101 | $return[$accom->meta_value] = $accom; |
1102 | 1102 | } |
1103 | 1103 | } |
@@ -1107,31 +1107,31 @@ discard block |
||
1107 | 1107 | /** |
1108 | 1108 | * Set the Video date |
1109 | 1109 | */ |
1110 | - public function set_video_data($data,$id) { |
|
1111 | - if(!empty($data[0]['content']['youtube_videos']) && is_array($data[0]['content']['youtube_videos'])){ |
|
1110 | + public function set_video_data($data, $id) { |
|
1111 | + if (!empty($data[0]['content']['youtube_videos']) && is_array($data[0]['content']['youtube_videos'])) { |
|
1112 | 1112 | $videos = false; |
1113 | 1113 | |
1114 | - foreach($data[0]['content']['youtube_videos'] as $video){ |
|
1114 | + foreach ($data[0]['content']['youtube_videos'] as $video) { |
|
1115 | 1115 | $temp_video = array(); |
1116 | 1116 | |
1117 | - if(isset($video['label'])){ |
|
1117 | + if (isset($video['label'])) { |
|
1118 | 1118 | $temp_video['title'] = $video['label']; |
1119 | 1119 | } |
1120 | - if(isset($video['description'])){ |
|
1120 | + if (isset($video['description'])) { |
|
1121 | 1121 | $temp_video['description'] = strip_tags($video['description']); |
1122 | 1122 | } |
1123 | - if(isset($video['url'])){ |
|
1123 | + if (isset($video['url'])) { |
|
1124 | 1124 | $temp_video['url'] = $video['url']; |
1125 | 1125 | } |
1126 | 1126 | $temp_video['thumbnail'] = ''; |
1127 | 1127 | $videos[] = $temp_video; |
1128 | 1128 | } |
1129 | 1129 | |
1130 | - if(false !== $id && '0' !== $id){ |
|
1130 | + if (false !== $id && '0' !== $id) { |
|
1131 | 1131 | delete_post_meta($id, 'videos'); |
1132 | 1132 | } |
1133 | - foreach($videos as $video){ |
|
1134 | - add_post_meta($id,'videos',$video,false); |
|
1133 | + foreach ($videos as $video) { |
|
1134 | + add_post_meta($id, 'videos', $video, false); |
|
1135 | 1135 | } |
1136 | 1136 | } |
1137 | 1137 | } |