@@ -14,57 +14,57 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class LSX_WETU_Importer_Welcome { |
16 | 16 | |
17 | - /** |
|
18 | - * Holds instance of the class |
|
19 | - * |
|
20 | - * @var object |
|
21 | - */ |
|
22 | - private static $instance; |
|
17 | + /** |
|
18 | + * Holds instance of the class |
|
19 | + * |
|
20 | + * @var object |
|
21 | + */ |
|
22 | + private static $instance; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Initialize the plugin by setting localization, filters, and administration functions. |
|
26 | - * |
|
27 | - * @since 1.0.0 |
|
28 | - * |
|
29 | - * @access private |
|
30 | - */ |
|
31 | - public function __construct() { |
|
32 | - } |
|
24 | + /** |
|
25 | + * Initialize the plugin by setting localization, filters, and administration functions. |
|
26 | + * |
|
27 | + * @since 1.0.0 |
|
28 | + * |
|
29 | + * @access private |
|
30 | + */ |
|
31 | + public function __construct() { |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Return an instance of this class. |
|
36 | - * |
|
37 | - * @return object |
|
38 | - */ |
|
39 | - public static function get_instance() { |
|
40 | - // If the single instance hasn't been set, set it now. |
|
41 | - if ( ! isset( self::$instance ) ) { |
|
42 | - self::$instance = new self(); |
|
43 | - } |
|
44 | - return self::$instance; |
|
45 | - } |
|
34 | + /** |
|
35 | + * Return an instance of this class. |
|
36 | + * |
|
37 | + * @return object |
|
38 | + */ |
|
39 | + public static function get_instance() { |
|
40 | + // If the single instance hasn't been set, set it now. |
|
41 | + if ( ! isset( self::$instance ) ) { |
|
42 | + self::$instance = new self(); |
|
43 | + } |
|
44 | + return self::$instance; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Display the importer welcome screen |
|
49 | - */ |
|
50 | - public function display_page() { |
|
51 | - ?> |
|
47 | + /** |
|
48 | + * Display the importer welcome screen |
|
49 | + */ |
|
50 | + public function display_page() { |
|
51 | + ?> |
|
52 | 52 | <div class="row section"> |
53 | 53 | <h1><?php esc_html_e( 'Welcome to the LSX Importer for Wetu', 'lsx-wetu-importer' ); ?></h1> |
54 | 54 | <p><?php esc_html_e( 'If this is the first time running the import, please follow the steps below.', 'lsx-wetu-importer' ); ?></p> |
55 | 55 | </div> |
56 | 56 | <?php |
57 | - $this->importer_steps(); |
|
58 | - $this->welcome_blocks(); |
|
59 | - } |
|
57 | + $this->importer_steps(); |
|
58 | + $this->welcome_blocks(); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Undocumented function |
|
63 | - * |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - public function importer_steps() { |
|
67 | - ?> |
|
61 | + /** |
|
62 | + * Undocumented function |
|
63 | + * |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + public function importer_steps() { |
|
67 | + ?> |
|
68 | 68 | <div class="row section postbox"> |
69 | 69 | <div class="welcome-block-header"> |
70 | 70 | <p class="heading"><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=tour' ); ?>"><?php esc_html_e( 'Import your tours', 'lsx-wetu-importer' ); ?></a></p> |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | <div class="spacer"></div> |
86 | 86 | </div> |
87 | 87 | <?php |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Outputs the welcome blocks on the welcome screen |
|
92 | - * |
|
93 | - * @return void |
|
94 | - */ |
|
95 | - public function welcome_blocks() { |
|
96 | - ?> |
|
90 | + /** |
|
91 | + * Outputs the welcome blocks on the welcome screen |
|
92 | + * |
|
93 | + * @return void |
|
94 | + */ |
|
95 | + public function welcome_blocks() { |
|
96 | + ?> |
|
97 | 97 | <div class="row section"> |
98 | 98 | <div class="welcome-block postbox"> |
99 | 99 | <?php $this->tour_block(); ?> |
@@ -109,15 +109,15 @@ discard block |
||
109 | 109 | </div> |
110 | 110 | </div> |
111 | 111 | <?php |
112 | - } |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Outputs the Tour Block. |
|
116 | - * |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - public function tour_block() { |
|
120 | - ?> |
|
114 | + /** |
|
115 | + * Outputs the Tour Block. |
|
116 | + * |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + public function tour_block() { |
|
120 | + ?> |
|
121 | 121 | <h2 class="title"><?php esc_html_e( 'Importing tours', 'lsx-wetu-importer' ); ?></h2> |
122 | 122 | <p class="excerpt"><?php esc_html_e( 'Search for tours, select the ones you want to import and choose the data you want to sync on import. All connected accommodadtions will be imported as drafts to be pubished after completing the tour import.', 'lsx-wetu-importer' ); ?></p> |
123 | 123 | <p><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=tour' ); ?>" class="button button-primary"><?php esc_html_e( 'Import Tours', 'lsx-wetu-importer' ); ?></a></p> |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | </ul> |
130 | 130 | </p> |
131 | 131 | <?php |
132 | - } |
|
133 | - /** |
|
134 | - * Outputs the Accommodation Block. |
|
135 | - * |
|
136 | - * @return void |
|
137 | - */ |
|
138 | - public function accommodation_block() { |
|
139 | - ?> |
|
132 | + } |
|
133 | + /** |
|
134 | + * Outputs the Accommodation Block. |
|
135 | + * |
|
136 | + * @return void |
|
137 | + */ |
|
138 | + public function accommodation_block() { |
|
139 | + ?> |
|
140 | 140 | <h2 class="title"><?php esc_html_e( 'Import and publish accommodation', 'lsx-wetu-importer' ); ?></h2> |
141 | 141 | <p class="excerpt"><?php esc_html_e( 'All accommodations connnected to your tours have been imported as drafts. Review the imported accommodations, sync selected data and publish.', 'lsx-wetu-importer' ); ?></p> |
142 | 142 | <p><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=accommodation' ); ?>" class="button button-primary"><?php esc_html_e( 'Sync accommodation', 'lsx-wetu-importer' ); ?></a></p> |
@@ -150,14 +150,14 @@ discard block |
||
150 | 150 | </ul> |
151 | 151 | </p> |
152 | 152 | <?php |
153 | - } |
|
154 | - /** |
|
155 | - * Outputs the Destination Block. |
|
156 | - * |
|
157 | - * @return void |
|
158 | - */ |
|
159 | - public function destination_block() { |
|
160 | - ?> |
|
153 | + } |
|
154 | + /** |
|
155 | + * Outputs the Destination Block. |
|
156 | + * |
|
157 | + * @return void |
|
158 | + */ |
|
159 | + public function destination_block() { |
|
160 | + ?> |
|
161 | 161 | <h2 class="title"><?php esc_html_e( 'Import and publish destinations', 'lsx-wetu-importer' ); ?></h2> |
162 | 162 | <p class="excerpt"><?php esc_html_e( 'All destinations and regions connnected to your tours & accommodations have been imported as drafts. Review the imported accommodations, sync selected data and publish.', 'lsx-wetu-importer' ); ?></p> |
163 | 163 | <p><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=destination' ); ?>" class="button button-primary"><?php esc_html_e( 'Sync destinations', 'lsx-wetu-importer' ); ?></a></p> |
@@ -170,16 +170,16 @@ discard block |
||
170 | 170 | </ul> |
171 | 171 | </p> |
172 | 172 | <?php |
173 | - } |
|
174 | - /** |
|
175 | - * Outputs the last welcome block |
|
176 | - * |
|
177 | - * @return void |
|
178 | - */ |
|
179 | - public function end_block() { |
|
180 | - ?> |
|
173 | + } |
|
174 | + /** |
|
175 | + * Outputs the last welcome block |
|
176 | + * |
|
177 | + * @return void |
|
178 | + */ |
|
179 | + public function end_block() { |
|
180 | + ?> |
|
181 | 181 | <h2 class="title"><?php esc_html_e( 'Done! Check out your imported content', 'lsx-wetu-importer' ); ?></h2> |
182 | 182 | <p><?php esc_html_e( 'If you’ve updated your content on Wetu then you can return to these steps at any stage to import and re-sync any updates', 'lsx-wetu-importer' ); ?></p> |
183 | 183 | <?php |
184 | - } |
|
184 | + } |
|
185 | 185 | } |
@@ -15,18 +15,18 @@ discard block |
||
15 | 15 | * @return array |
16 | 16 | */ |
17 | 17 | function lsx_wetu_get_options() { |
18 | - $options = get_option( 'lsx_wetu_importer_settings', array() ); |
|
19 | - if ( empty( $options ) ) { |
|
20 | - // Check for any previous options. |
|
21 | - $temp_options = get_option( '_lsx-to_settings', false ); |
|
22 | - if ( false !== $temp_options && isset( $temp_options['lsx-wetu-importer'] ) && ! empty( $temp_options['lsx-wetu-importer'] ) ) { |
|
23 | - $options = $temp_options['lsx-wetu-importer']; |
|
24 | - } |
|
25 | - if ( false !== $temp_options && isset( $temp_options['api']['wetu_api_key'] ) && '' !== $temp_options['api']['wetu_api_key'] ) { |
|
26 | - $options['api_key'] = $temp_options['api']['wetu_api_key']; |
|
27 | - } |
|
28 | - } |
|
29 | - return $options; |
|
18 | + $options = get_option( 'lsx_wetu_importer_settings', array() ); |
|
19 | + if ( empty( $options ) ) { |
|
20 | + // Check for any previous options. |
|
21 | + $temp_options = get_option( '_lsx-to_settings', false ); |
|
22 | + if ( false !== $temp_options && isset( $temp_options['lsx-wetu-importer'] ) && ! empty( $temp_options['lsx-wetu-importer'] ) ) { |
|
23 | + $options = $temp_options['lsx-wetu-importer']; |
|
24 | + } |
|
25 | + if ( false !== $temp_options && isset( $temp_options['api']['wetu_api_key'] ) && '' !== $temp_options['api']['wetu_api_key'] ) { |
|
26 | + $options['api_key'] = $temp_options['api']['wetu_api_key']; |
|
27 | + } |
|
28 | + } |
|
29 | + return $options; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -37,38 +37,38 @@ discard block |
||
37 | 37 | * @return void |
38 | 38 | */ |
39 | 39 | function lsx_wetu_get_post_count( $post_type = '', $post_status = '' ) { |
40 | - global $wpdb; |
|
41 | - $count = '0'; |
|
42 | - if ( '' !== $post_type && '' !== $post_status ) { |
|
43 | - $result = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`ID`) FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array( trim( $post_status ), $post_type ) ) ); |
|
44 | - if ( false !== $result && '' !== $result ) { |
|
45 | - if ( 'tour' === $post_type ) { |
|
46 | - $wetu_tours = get_transient( 'lsx_ti_tours' ); |
|
47 | - if ( false !== $wetu_tours ) { |
|
48 | - $results = $wpdb->get_results( $wpdb->prepare( "SELECT `ID` FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array( trim( $post_status ), $post_type ) ) ); |
|
49 | - $result_count = 0; |
|
50 | - $tour_wetu_ids = array(); |
|
51 | - foreach ( $wetu_tours as $wetu_tour ) { |
|
52 | - $tour_wetu_ids[] = $wetu_tour['identifier']; |
|
53 | - } |
|
40 | + global $wpdb; |
|
41 | + $count = '0'; |
|
42 | + if ( '' !== $post_type && '' !== $post_status ) { |
|
43 | + $result = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`ID`) FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array( trim( $post_status ), $post_type ) ) ); |
|
44 | + if ( false !== $result && '' !== $result ) { |
|
45 | + if ( 'tour' === $post_type ) { |
|
46 | + $wetu_tours = get_transient( 'lsx_ti_tours' ); |
|
47 | + if ( false !== $wetu_tours ) { |
|
48 | + $results = $wpdb->get_results( $wpdb->prepare( "SELECT `ID` FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array( trim( $post_status ), $post_type ) ) ); |
|
49 | + $result_count = 0; |
|
50 | + $tour_wetu_ids = array(); |
|
51 | + foreach ( $wetu_tours as $wetu_tour ) { |
|
52 | + $tour_wetu_ids[] = $wetu_tour['identifier']; |
|
53 | + } |
|
54 | 54 | |
55 | - if ( ! empty( $results ) ) { |
|
56 | - foreach ( $results as $tour ) { |
|
57 | - $current_wetu_id = get_post_meta( $tour->ID, 'lsx_wetu_id', true ); |
|
58 | - if ( in_array( $current_wetu_id, $tour_wetu_ids ) ) { |
|
59 | - $result_count++; |
|
60 | - } |
|
61 | - } |
|
62 | - } |
|
63 | - $result = $result_count; |
|
64 | - } else { |
|
65 | - $result = 0; |
|
66 | - } |
|
67 | - } |
|
68 | - $count = $result; |
|
69 | - } |
|
70 | - } |
|
71 | - return $count; |
|
55 | + if ( ! empty( $results ) ) { |
|
56 | + foreach ( $results as $tour ) { |
|
57 | + $current_wetu_id = get_post_meta( $tour->ID, 'lsx_wetu_id', true ); |
|
58 | + if ( in_array( $current_wetu_id, $tour_wetu_ids ) ) { |
|
59 | + $result_count++; |
|
60 | + } |
|
61 | + } |
|
62 | + } |
|
63 | + $result = $result_count; |
|
64 | + } else { |
|
65 | + $result = 0; |
|
66 | + } |
|
67 | + } |
|
68 | + $count = $result; |
|
69 | + } |
|
70 | + } |
|
71 | + return $count; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | * @return void |
79 | 79 | */ |
80 | 80 | function lsx_wetu_get_queue_count( $post_type = '' ) { |
81 | - $count = '0'; |
|
82 | - $queued_imports = get_option( 'lsx_wetu_importer_que', array() ); |
|
83 | - if ( isset( $queued_imports[ $post_type ] ) ) { |
|
84 | - $count = count( $queued_imports[ $post_type ] ); |
|
85 | - } |
|
86 | - return $count; |
|
81 | + $count = '0'; |
|
82 | + $queued_imports = get_option( 'lsx_wetu_importer_que', array() ); |
|
83 | + if ( isset( $queued_imports[ $post_type ] ) ) { |
|
84 | + $count = count( $queued_imports[ $post_type ] ); |
|
85 | + } |
|
86 | + return $count; |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | * @return void |
94 | 94 | */ |
95 | 95 | function lsx_wetu_get_tour_count( $post_type = '' ) { |
96 | - $count = '0'; |
|
97 | - $wetu_tours = get_transient( 'lsx_ti_tours', array() ); |
|
98 | - if ( ! empty( $wetu_tours ) ) { |
|
99 | - $count = count( $wetu_tours ); |
|
100 | - } |
|
101 | - return $count; |
|
96 | + $count = '0'; |
|
97 | + $wetu_tours = get_transient( 'lsx_ti_tours', array() ); |
|
98 | + if ( ! empty( $wetu_tours ) ) { |
|
99 | + $count = count( $wetu_tours ); |
|
100 | + } |
|
101 | + return $count; |
|
102 | 102 | } |
@@ -9,95 +9,95 @@ discard block |
||
9 | 9 | |
10 | 10 | class LSX_WETU_Importer_Accommodation extends LSX_WETU_Importer { |
11 | 11 | |
12 | - /** |
|
13 | - * The url to list items from WETU |
|
14 | - * |
|
15 | - * @since 0.0.1 |
|
16 | - * |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - public $tab_slug = 'accommodation'; |
|
20 | - |
|
21 | - /** |
|
22 | - * The url to list items from WETU |
|
23 | - * |
|
24 | - * @since 0.0.1 |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $url = false; |
|
29 | - |
|
30 | - /** |
|
31 | - * The query string url to list items from WETU |
|
32 | - * |
|
33 | - * @since 0.0.1 |
|
34 | - * |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - public $url_qs = false; |
|
38 | - |
|
39 | - /** |
|
40 | - * Options |
|
41 | - * |
|
42 | - * @since 0.0.1 |
|
43 | - * |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - public $options = false; |
|
47 | - |
|
48 | - /** |
|
49 | - * The fields you wish to import |
|
50 | - * |
|
51 | - * @since 0.0.1 |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - public $accommodation_options = false; |
|
56 | - |
|
57 | - /** |
|
58 | - * Initialize the plugin by setting localization, filters, and administration functions. |
|
59 | - * |
|
60 | - * @since 1.0.0 |
|
61 | - * |
|
62 | - * @access private |
|
63 | - */ |
|
64 | - public function __construct() { |
|
65 | - $this->set_variables(); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Sets the variables used throughout the plugin. |
|
70 | - */ |
|
71 | - public function set_variables() { |
|
72 | - parent::set_variables(); |
|
73 | - |
|
74 | - // ** This request only works with API KEY ** |
|
75 | - // if ( false !== $this->api_username && false !== $this->api_password ) { |
|
76 | - // $this->url = 'https://wetu.com/API/Pins/'; |
|
77 | - // $this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password; |
|
78 | - // } elseif ( false !== $this->api_key ) { |
|
79 | - $this->url = 'https://wetu.com/API/Pins/' . $this->api_key; |
|
80 | - $this->url_qs = 'all=include'; |
|
81 | - // } |
|
82 | - |
|
83 | - $temp_options = get_option( '_lsx-to_settings', false ); |
|
84 | - |
|
85 | - if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) { |
|
86 | - $this->options = $temp_options[ $this->plugin_slug ]; |
|
87 | - } |
|
88 | - |
|
89 | - $accommodation_options = get_option( 'lsx_wetu_importer_accommodation_settings', false ); |
|
90 | - |
|
91 | - if ( false !== $accommodation_options ) { |
|
92 | - $this->accommodation_options = $accommodation_options; |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Display the importer administration screen |
|
98 | - */ |
|
99 | - public function display_page() { |
|
100 | - ?> |
|
12 | + /** |
|
13 | + * The url to list items from WETU |
|
14 | + * |
|
15 | + * @since 0.0.1 |
|
16 | + * |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + public $tab_slug = 'accommodation'; |
|
20 | + |
|
21 | + /** |
|
22 | + * The url to list items from WETU |
|
23 | + * |
|
24 | + * @since 0.0.1 |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $url = false; |
|
29 | + |
|
30 | + /** |
|
31 | + * The query string url to list items from WETU |
|
32 | + * |
|
33 | + * @since 0.0.1 |
|
34 | + * |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + public $url_qs = false; |
|
38 | + |
|
39 | + /** |
|
40 | + * Options |
|
41 | + * |
|
42 | + * @since 0.0.1 |
|
43 | + * |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + public $options = false; |
|
47 | + |
|
48 | + /** |
|
49 | + * The fields you wish to import |
|
50 | + * |
|
51 | + * @since 0.0.1 |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + public $accommodation_options = false; |
|
56 | + |
|
57 | + /** |
|
58 | + * Initialize the plugin by setting localization, filters, and administration functions. |
|
59 | + * |
|
60 | + * @since 1.0.0 |
|
61 | + * |
|
62 | + * @access private |
|
63 | + */ |
|
64 | + public function __construct() { |
|
65 | + $this->set_variables(); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Sets the variables used throughout the plugin. |
|
70 | + */ |
|
71 | + public function set_variables() { |
|
72 | + parent::set_variables(); |
|
73 | + |
|
74 | + // ** This request only works with API KEY ** |
|
75 | + // if ( false !== $this->api_username && false !== $this->api_password ) { |
|
76 | + // $this->url = 'https://wetu.com/API/Pins/'; |
|
77 | + // $this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password; |
|
78 | + // } elseif ( false !== $this->api_key ) { |
|
79 | + $this->url = 'https://wetu.com/API/Pins/' . $this->api_key; |
|
80 | + $this->url_qs = 'all=include'; |
|
81 | + // } |
|
82 | + |
|
83 | + $temp_options = get_option( '_lsx-to_settings', false ); |
|
84 | + |
|
85 | + if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) { |
|
86 | + $this->options = $temp_options[ $this->plugin_slug ]; |
|
87 | + } |
|
88 | + |
|
89 | + $accommodation_options = get_option( 'lsx_wetu_importer_accommodation_settings', false ); |
|
90 | + |
|
91 | + if ( false !== $accommodation_options ) { |
|
92 | + $this->accommodation_options = $accommodation_options; |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Display the importer administration screen |
|
98 | + */ |
|
99 | + public function display_page() { |
|
100 | + ?> |
|
101 | 101 | <div class="wrap"> |
102 | 102 | |
103 | 103 | <div class="tablenav top"> |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | <div style="width:30%;display:block;float:left;"> |
188 | 188 | <h3><?php esc_html_e( 'Assign a Safari Brand' ); ?></h3> |
189 | 189 | <?php |
190 | - echo wp_kses_post( $this->taxonomy_checkboxes( 'accommodation-brand', $this->accommodation_options ) ); |
|
191 | - ?> |
|
190 | + echo wp_kses_post( $this->taxonomy_checkboxes( 'accommodation-brand', $this->accommodation_options ) ); |
|
191 | + ?> |
|
192 | 192 | </div> |
193 | 193 | |
194 | 194 | <br clear="both" /> |
@@ -218,142 +218,142 @@ discard block |
||
218 | 218 | </div> |
219 | 219 | </div> |
220 | 220 | <?php |
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Run through the accommodation grabbed from the DB. |
|
225 | - */ |
|
226 | - public function process_ajax_search() { |
|
227 | - $return = false; |
|
228 | - check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
229 | - if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && 'accommodation' === $_POST['type'] ) { |
|
230 | - |
|
231 | - $searched_items = false; |
|
232 | - if ( isset( $_POST['keyword'] ) ) { |
|
233 | - $keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) ); |
|
234 | - } else { |
|
235 | - $keyphrases = array( 0 ); |
|
236 | - } |
|
237 | - |
|
238 | - if ( ! is_array( $keyphrases ) ) { |
|
239 | - $keyphrases = array( $keyphrases ); |
|
240 | - } |
|
241 | - foreach ( $keyphrases as &$keyword ) { |
|
242 | - $keyword = ltrim( rtrim( $keyword ) ); |
|
243 | - } |
|
244 | - |
|
245 | - $post_status = false; |
|
246 | - |
|
247 | - if ( in_array( 'publish', $keyphrases ) ) { |
|
248 | - $post_status = 'publish'; |
|
249 | - } |
|
250 | - if ( in_array( 'pending', $keyphrases ) ) { |
|
251 | - $post_status = 'pending'; |
|
252 | - } |
|
253 | - if ( in_array( 'draft', $keyphrases ) ) { |
|
254 | - $post_status = 'draft'; |
|
255 | - } |
|
256 | - if ( in_array( 'import', $keyphrases ) ) { |
|
257 | - $post_status = 'import'; |
|
258 | - } |
|
259 | - |
|
260 | - // If there is a post status use it. |
|
261 | - if ( false !== $post_status ) { |
|
262 | - |
|
263 | - $accommodation = array(); |
|
264 | - $current_accommodation = $this->find_current_accommodation(); |
|
265 | - if ( ! empty( $current_accommodation ) ) { |
|
266 | - foreach ( $current_accommodation as $cs_key => $ccs_id ) { |
|
267 | - $accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id ); |
|
268 | - } |
|
269 | - } |
|
270 | - |
|
271 | - // Run through each accommodation and use it. |
|
272 | - if ( ! empty( $accommodation ) ) { |
|
273 | - foreach ( $accommodation as $row_key => $row ) { |
|
274 | - $row['post_title'] = $row['name']; |
|
275 | - if ( 'import' === $post_status ) { |
|
276 | - if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) { |
|
277 | - $current_status = get_post_status( $row['post_id'] ); |
|
278 | - if ( 'draft' === $current_status ) { |
|
279 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row ); |
|
280 | - } |
|
281 | - } else { |
|
282 | - continue; |
|
283 | - } |
|
284 | - } else { |
|
285 | - if ( 0 === $row['post_id'] ) { |
|
286 | - continue; |
|
287 | - } else { |
|
288 | - $current_status = get_post_status( $row['post_id'] ); |
|
289 | - if ( $current_status !== $post_status ) { |
|
290 | - continue; |
|
291 | - } |
|
292 | - } |
|
293 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key ); |
|
294 | - } |
|
295 | - } |
|
296 | - } |
|
297 | - } else { |
|
298 | - $key_string_search = implode( '+', $keyphrases ); |
|
299 | - $search_data = wp_remote_get( $this->url . '/Search/' . $key_string_search ); |
|
300 | - if ( ! empty( $search_data ) && isset( $search_data['response'] ) && isset( $search_data['response']['code'] ) && 200 === $search_data['response']['code'] ) { |
|
301 | - |
|
302 | - $search_data = json_decode( $search_data['body'], true ); |
|
303 | - foreach ( $search_data as $sdata_key => $sdata ) { |
|
304 | - |
|
305 | - if ( 'Destination' === trim( $sdata['type'] ) || 'Activity' === trim( $sdata['type'] ) || 'Restaurant' === trim( $sdata['type'] ) || 'None' === trim( $sdata['type'] ) || 'Site / Attraction' === trim( $sdata['type'] ) || '' === trim( $sdata['type'] ) ) { |
|
306 | - continue; |
|
307 | - } |
|
308 | - |
|
309 | - $temp_id = $this->get_post_id_by_key_value( $sdata['id'] ); |
|
310 | - if ( false === $temp_id ) { |
|
311 | - $sdata['post_id'] = 0; |
|
312 | - $sdata['post_title'] = $sdata['name']; |
|
313 | - } else { |
|
314 | - $sdata['post_id'] = $temp_id; |
|
315 | - $sdata['post_title'] = get_the_title( $temp_id ); |
|
316 | - } |
|
317 | - $searched_items[ sanitize_title( $sdata['name'] ) . '-' . $sdata['id'] ] = $this->format_row( $sdata, $sdata_key ); |
|
318 | - } |
|
319 | - } |
|
320 | - } |
|
321 | - |
|
322 | - if ( false !== $searched_items ) { |
|
323 | - $return = implode( $searched_items ); |
|
324 | - } |
|
325 | - print_r( $return ); |
|
326 | - } |
|
327 | - |
|
328 | - die(); |
|
329 | - } |
|
330 | - |
|
331 | - public function prepare_row_attributes( $cs_key, $ccs_id ) { |
|
332 | - $row_item = array( |
|
333 | - 'id' => $cs_key, |
|
334 | - 'type' => 'Accommodation', |
|
335 | - 'name' => get_the_title( $ccs_id ), |
|
336 | - 'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ), |
|
337 | - 'post_id' => $ccs_id, |
|
338 | - ); |
|
339 | - return $row_item; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Formats the row for output on the screen. |
|
344 | - * |
|
345 | - * @param boolean $row the current row to format. |
|
346 | - * @return void |
|
347 | - */ |
|
348 | - public function format_row( $row = false, $row_key = '' ) { |
|
349 | - if ( false !== $row ) { |
|
350 | - |
|
351 | - $status = 'import'; |
|
352 | - if ( 0 !== $row['post_id'] ) { |
|
353 | - $status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>'; |
|
354 | - } |
|
355 | - |
|
356 | - $row_html = ' |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Run through the accommodation grabbed from the DB. |
|
225 | + */ |
|
226 | + public function process_ajax_search() { |
|
227 | + $return = false; |
|
228 | + check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
229 | + if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && 'accommodation' === $_POST['type'] ) { |
|
230 | + |
|
231 | + $searched_items = false; |
|
232 | + if ( isset( $_POST['keyword'] ) ) { |
|
233 | + $keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) ); |
|
234 | + } else { |
|
235 | + $keyphrases = array( 0 ); |
|
236 | + } |
|
237 | + |
|
238 | + if ( ! is_array( $keyphrases ) ) { |
|
239 | + $keyphrases = array( $keyphrases ); |
|
240 | + } |
|
241 | + foreach ( $keyphrases as &$keyword ) { |
|
242 | + $keyword = ltrim( rtrim( $keyword ) ); |
|
243 | + } |
|
244 | + |
|
245 | + $post_status = false; |
|
246 | + |
|
247 | + if ( in_array( 'publish', $keyphrases ) ) { |
|
248 | + $post_status = 'publish'; |
|
249 | + } |
|
250 | + if ( in_array( 'pending', $keyphrases ) ) { |
|
251 | + $post_status = 'pending'; |
|
252 | + } |
|
253 | + if ( in_array( 'draft', $keyphrases ) ) { |
|
254 | + $post_status = 'draft'; |
|
255 | + } |
|
256 | + if ( in_array( 'import', $keyphrases ) ) { |
|
257 | + $post_status = 'import'; |
|
258 | + } |
|
259 | + |
|
260 | + // If there is a post status use it. |
|
261 | + if ( false !== $post_status ) { |
|
262 | + |
|
263 | + $accommodation = array(); |
|
264 | + $current_accommodation = $this->find_current_accommodation(); |
|
265 | + if ( ! empty( $current_accommodation ) ) { |
|
266 | + foreach ( $current_accommodation as $cs_key => $ccs_id ) { |
|
267 | + $accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id ); |
|
268 | + } |
|
269 | + } |
|
270 | + |
|
271 | + // Run through each accommodation and use it. |
|
272 | + if ( ! empty( $accommodation ) ) { |
|
273 | + foreach ( $accommodation as $row_key => $row ) { |
|
274 | + $row['post_title'] = $row['name']; |
|
275 | + if ( 'import' === $post_status ) { |
|
276 | + if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) { |
|
277 | + $current_status = get_post_status( $row['post_id'] ); |
|
278 | + if ( 'draft' === $current_status ) { |
|
279 | + $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row ); |
|
280 | + } |
|
281 | + } else { |
|
282 | + continue; |
|
283 | + } |
|
284 | + } else { |
|
285 | + if ( 0 === $row['post_id'] ) { |
|
286 | + continue; |
|
287 | + } else { |
|
288 | + $current_status = get_post_status( $row['post_id'] ); |
|
289 | + if ( $current_status !== $post_status ) { |
|
290 | + continue; |
|
291 | + } |
|
292 | + } |
|
293 | + $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key ); |
|
294 | + } |
|
295 | + } |
|
296 | + } |
|
297 | + } else { |
|
298 | + $key_string_search = implode( '+', $keyphrases ); |
|
299 | + $search_data = wp_remote_get( $this->url . '/Search/' . $key_string_search ); |
|
300 | + if ( ! empty( $search_data ) && isset( $search_data['response'] ) && isset( $search_data['response']['code'] ) && 200 === $search_data['response']['code'] ) { |
|
301 | + |
|
302 | + $search_data = json_decode( $search_data['body'], true ); |
|
303 | + foreach ( $search_data as $sdata_key => $sdata ) { |
|
304 | + |
|
305 | + if ( 'Destination' === trim( $sdata['type'] ) || 'Activity' === trim( $sdata['type'] ) || 'Restaurant' === trim( $sdata['type'] ) || 'None' === trim( $sdata['type'] ) || 'Site / Attraction' === trim( $sdata['type'] ) || '' === trim( $sdata['type'] ) ) { |
|
306 | + continue; |
|
307 | + } |
|
308 | + |
|
309 | + $temp_id = $this->get_post_id_by_key_value( $sdata['id'] ); |
|
310 | + if ( false === $temp_id ) { |
|
311 | + $sdata['post_id'] = 0; |
|
312 | + $sdata['post_title'] = $sdata['name']; |
|
313 | + } else { |
|
314 | + $sdata['post_id'] = $temp_id; |
|
315 | + $sdata['post_title'] = get_the_title( $temp_id ); |
|
316 | + } |
|
317 | + $searched_items[ sanitize_title( $sdata['name'] ) . '-' . $sdata['id'] ] = $this->format_row( $sdata, $sdata_key ); |
|
318 | + } |
|
319 | + } |
|
320 | + } |
|
321 | + |
|
322 | + if ( false !== $searched_items ) { |
|
323 | + $return = implode( $searched_items ); |
|
324 | + } |
|
325 | + print_r( $return ); |
|
326 | + } |
|
327 | + |
|
328 | + die(); |
|
329 | + } |
|
330 | + |
|
331 | + public function prepare_row_attributes( $cs_key, $ccs_id ) { |
|
332 | + $row_item = array( |
|
333 | + 'id' => $cs_key, |
|
334 | + 'type' => 'Accommodation', |
|
335 | + 'name' => get_the_title( $ccs_id ), |
|
336 | + 'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ), |
|
337 | + 'post_id' => $ccs_id, |
|
338 | + ); |
|
339 | + return $row_item; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Formats the row for output on the screen. |
|
344 | + * |
|
345 | + * @param boolean $row the current row to format. |
|
346 | + * @return void |
|
347 | + */ |
|
348 | + public function format_row( $row = false, $row_key = '' ) { |
|
349 | + if ( false !== $row ) { |
|
350 | + |
|
351 | + $status = 'import'; |
|
352 | + if ( 0 !== $row['post_id'] ) { |
|
353 | + $status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>'; |
|
354 | + } |
|
355 | + |
|
356 | + $row_html = ' |
|
357 | 357 | <tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '"> |
358 | 358 | <th class="check-column" scope="row"> |
359 | 359 | <label for="cb-select-' . $row['id'] . '" class="screen-reader-text">' . $row['name'] . '</label> |
@@ -372,457 +372,457 @@ discard block |
||
372 | 372 | ' . $row['id'] . ' |
373 | 373 | </td> |
374 | 374 | </tr>'; |
375 | - return $row_html; |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * Saves the queue to the option. |
|
381 | - */ |
|
382 | - public function remove_from_queue( $id ) { |
|
383 | - if ( ! empty( $this->queued_imports ) ) { |
|
384 | - $key = array_search( $id, $this->queued_imports ); |
|
385 | - if ( false !== $key ) { |
|
386 | - unset( $this->queued_imports[ $key ] ); |
|
387 | - |
|
388 | - delete_option( 'lsx_wetu_importer_que' ); |
|
389 | - update_option( 'lsx_wetu_importer_que', $this->queued_imports ); |
|
390 | - } |
|
391 | - } |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Connect to wetu |
|
396 | - */ |
|
397 | - public function process_ajax_import() { |
|
398 | - $return = false; |
|
399 | - check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
400 | - |
|
401 | - if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && 'accommodation' === $_POST['type'] && isset( $_POST['wetu_id'] ) ) { |
|
402 | - |
|
403 | - $wetu_id = sanitize_text_field( $_POST['wetu_id'] ); |
|
404 | - if ( isset( $_POST['post_id'] ) ) { |
|
405 | - $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
406 | - } else { |
|
407 | - $post_id = 0; |
|
408 | - } |
|
409 | - |
|
410 | - if ( isset( $_POST['team_members'] ) ) { |
|
411 | - $team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) ); |
|
412 | - } else { |
|
413 | - $team_members = false; |
|
414 | - } |
|
415 | - |
|
416 | - if ( isset( $_POST['safari_brands'] ) ) { |
|
417 | - $safari_brands = array_map( 'sanitize_text_field', wp_unslash( $_POST['safari_brands'] ) ); |
|
418 | - } else { |
|
419 | - $safari_brands = false; |
|
420 | - } |
|
421 | - delete_option( 'lsx_wetu_importer_accommodation_settings' ); |
|
422 | - |
|
423 | - if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) { |
|
424 | - $content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) ); |
|
425 | - add_option( 'lsx_wetu_importer_accommodation_settings', $content ); |
|
426 | - } else { |
|
427 | - $content = false; |
|
428 | - } |
|
429 | - |
|
430 | - $jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
431 | - |
|
432 | - if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) { |
|
433 | - $adata = json_decode( $jdata['body'], true ); |
|
434 | - $return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands ); |
|
435 | - $this->format_completed_row( $return ); |
|
436 | - $this->remove_from_queue( $return ); |
|
437 | - $this->cleanup_posts(); |
|
438 | - } else { |
|
439 | - $this->format_error( esc_html__( 'There was a problem importing your accommodation, please try refreshing the page.', 'lsx-wetu-importer' ) ); |
|
440 | - } |
|
441 | - } |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * Connect to wetu |
|
446 | - */ |
|
447 | - public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false ) { |
|
448 | - $post_name = ''; |
|
449 | - $data_post_content = ''; |
|
450 | - $data_post_excerpt = ''; |
|
451 | - |
|
452 | - $post = array( |
|
453 | - 'post_type' => 'accommodation', |
|
454 | - ); |
|
455 | - $content_used_general_description = false; |
|
456 | - |
|
457 | - // Set the post_content. |
|
458 | - if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) { |
|
459 | - if ( isset( $data[0]['content']['extended_description'] ) ) { |
|
460 | - $data_post_content = $data[0]['content']['extended_description']; |
|
461 | - } elseif ( isset( $data[0]['content']['general_description'] ) ) { |
|
462 | - $data_post_content = $data[0]['content']['general_description']; |
|
463 | - $content_used_general_description = true; |
|
464 | - } elseif ( isset( $data[0]['content']['teaser_description'] ) ) { |
|
465 | - $data_post_content = $data[0]['content']['teaser_description']; |
|
466 | - } |
|
467 | - |
|
468 | - if ( isset( $this->options['disable_accommodation_filtering'] ) && 'on' === $this->options['disable_accommodation_filtering'] ) { |
|
469 | - $post['post_content'] = $data_post_content; |
|
470 | - } else { |
|
471 | - $post['post_content'] = wp_strip_all_tags( $data_post_content ); |
|
472 | - } |
|
473 | - } |
|
474 | - |
|
475 | - // set the post_excerpt. |
|
476 | - if ( ! empty( $importable_content ) && in_array( 'excerpt', $importable_content ) ) { |
|
477 | - if ( isset( $data[0]['content']['teaser_description'] ) ) { |
|
478 | - $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
479 | - } elseif ( isset( $data[0]['content']['general_description'] ) && false === $content_used_general_description ) { |
|
480 | - $data_post_excerpt = $data[0]['content']['general_description']; |
|
481 | - } |
|
482 | - |
|
483 | - $post['post_excerpt'] = $data_post_excerpt; |
|
484 | - } |
|
485 | - |
|
486 | - if ( false !== $id && '0' !== $id ) { |
|
487 | - $post['ID'] = $id; |
|
488 | - |
|
489 | - if ( isset( $this->options ) && 'on' !== $this->options['disable_accommodation_title'] && isset( $data[0]['name'] ) ) { |
|
490 | - $post['post_title'] = $data[0]['name']; |
|
491 | - $post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'accommodation', 0 ); |
|
492 | - } |
|
493 | - |
|
494 | - $post['post_status'] = 'publish'; |
|
495 | - |
|
496 | - $id = wp_update_post( $post ); |
|
497 | - $prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true ); |
|
498 | - update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date ); |
|
499 | - } else { |
|
500 | - // Set the name. |
|
501 | - if ( isset( $data[0]['name'] ) ) { |
|
502 | - $post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'accommodation', 0 ); |
|
503 | - } |
|
504 | - |
|
505 | - $post['post_name'] = $post_name; |
|
506 | - $post['post_title'] = $data[0]['name']; |
|
507 | - $post['post_status'] = 'publish'; |
|
508 | - $id = wp_insert_post( $post ); |
|
509 | - |
|
510 | - // Save the WETU ID and the Last date it was modified. |
|
511 | - if ( false !== $id ) { |
|
512 | - add_post_meta( $id, 'lsx_wetu_id', $wetu_id ); |
|
513 | - add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) ); |
|
514 | - } |
|
515 | - } |
|
516 | - |
|
517 | - // Setup some default for use in the import. |
|
518 | - if ( false !== $importable_content && ( in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content ) ) ) { |
|
519 | - $this->find_attachments( $id ); |
|
520 | - } |
|
521 | - |
|
522 | - // Set the team member if it is there. |
|
523 | - if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) { |
|
524 | - $this->set_team_member( $id, $team_members ); |
|
525 | - } |
|
526 | - |
|
527 | - // Set the safari brand. |
|
528 | - if ( false !== $safari_brands && '' !== $safari_brands ) { |
|
529 | - $this->set_safari_brands( $id, $safari_brands ); |
|
530 | - } |
|
531 | - |
|
532 | - $this->set_map_data( $data, $id, 9 ); |
|
533 | - |
|
534 | - if ( post_type_exists( 'destination' ) && false !== $importable_content && in_array( 'destination', $importable_content ) ) { |
|
535 | - $this->connect_destinations( $data, $id ); |
|
536 | - } |
|
537 | - |
|
538 | - if ( false !== $importable_content && in_array( 'category', $importable_content ) ) { |
|
539 | - $this->set_taxonomy_style( $data, $id ); |
|
540 | - } |
|
541 | - |
|
542 | - // Set the Room Data. |
|
543 | - if ( false !== $importable_content && in_array( 'rooms', $importable_content ) ) { |
|
544 | - $this->set_room_data( $data, $id ); |
|
545 | - } |
|
546 | - |
|
547 | - // Set the rating. |
|
548 | - if ( false !== $importable_content && in_array( 'rating', $importable_content ) ) { |
|
549 | - $this->set_rating( $data, $id ); |
|
550 | - } |
|
551 | - |
|
552 | - // Set the checkin checkout data. |
|
553 | - if ( false !== $importable_content && in_array( 'checkin', $importable_content ) ) { |
|
554 | - $this->set_checkin_checkout( $data, $id ); |
|
555 | - } |
|
556 | - |
|
557 | - // Set the Spoken Languages. |
|
558 | - if ( false !== $importable_content && in_array( 'spoken_languages', $importable_content ) ) { |
|
559 | - $this->set_spoken_languages( $data, $id ); |
|
560 | - } |
|
561 | - |
|
562 | - // Set the friendly options. |
|
563 | - if ( false !== $importable_content && in_array( 'friendly', $importable_content ) ) { |
|
564 | - $this->set_friendly( $data, $id ); |
|
565 | - } |
|
566 | - |
|
567 | - // Set the special_interests. |
|
568 | - if ( false !== $importable_content && in_array( 'special_interests', $importable_content ) ) { |
|
569 | - $this->set_special_interests( $data, $id ); |
|
570 | - } |
|
571 | - |
|
572 | - // Import the videos. |
|
573 | - if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) { |
|
574 | - $this->set_video_data( $data, $id ); |
|
575 | - } |
|
576 | - |
|
577 | - // Import the facilities. |
|
578 | - if ( false !== $importable_content && in_array( 'facilities', $importable_content ) ) { |
|
579 | - $this->set_facilities( $data, $id ); |
|
580 | - } |
|
581 | - |
|
582 | - // Set the featured image. |
|
583 | - if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) { |
|
584 | - $this->set_featured_image( $data, $id ); |
|
585 | - } |
|
586 | - |
|
587 | - if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) { |
|
588 | - $this->set_banner_image( $data, $id ); |
|
589 | - } |
|
590 | - |
|
591 | - // Import the main gallery. |
|
592 | - if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) { |
|
593 | - $this->create_main_gallery( $data, $id ); |
|
594 | - } |
|
595 | - |
|
596 | - return $id; |
|
597 | - } |
|
598 | - |
|
599 | - /** |
|
600 | - * Set the safari brand |
|
601 | - */ |
|
602 | - public function set_safari_brands( $id, $safari_brands ) { |
|
603 | - foreach ( $safari_brands as $safari_brand ) { |
|
604 | - wp_set_object_terms( $id, intval( $safari_brand ), 'accommodation-brand', true ); |
|
605 | - } |
|
606 | - } |
|
607 | - |
|
608 | - /** |
|
609 | - * Connects the destinations post type |
|
610 | - */ |
|
611 | - public function connect_destinations( $data, $id ) { |
|
612 | - if ( isset( $data[0]['position'] ) ) { |
|
613 | - $destinations = false; |
|
614 | - |
|
615 | - if ( isset( $data[0]['position']['country'] ) ) { |
|
616 | - $destinations['country'] = $data[0]['position']['country']; |
|
617 | - } |
|
618 | - |
|
619 | - if ( isset( $data[0]['position']['destination'] ) ) { |
|
620 | - $destinations['destination'] = $data[0]['position']['destination']; |
|
621 | - } |
|
622 | - |
|
623 | - if ( false !== $destinations ) { |
|
624 | - $prev_values = get_post_meta( $id, 'destination_to_accommodation', false ); |
|
625 | - |
|
626 | - if ( false === $prev_values || ! is_array( $prev_values ) ) { |
|
627 | - $prev_values = array(); |
|
628 | - } |
|
629 | - |
|
630 | - delete_post_meta( $id, 'destination_to_accommodation', $prev_values ); |
|
631 | - $destinations = array_unique( $destinations ); |
|
632 | - |
|
633 | - foreach ( $destinations as $key => $value ) { |
|
634 | - $destination = get_page_by_title( ltrim( rtrim( $value ) ), 'OBJECT', 'destination' ); |
|
635 | - if ( null !== $destination ) { |
|
636 | - if ( ! in_array( $destination->ID, $prev_values ) ) { |
|
637 | - add_post_meta( $id, 'destination_to_accommodation', $destination->ID, false ); |
|
638 | - add_post_meta( $destination->ID, 'accommodation_to_destination', $id, false ); |
|
639 | - $this->cleanup_posts[ $destination->ID ] = 'accommodation_to_destination'; |
|
640 | - } |
|
641 | - } |
|
642 | - } |
|
643 | - } |
|
644 | - } |
|
645 | - } |
|
646 | - |
|
647 | - /** |
|
648 | - * Set the Travel Style |
|
649 | - */ |
|
650 | - public function set_taxonomy_style( $data, $id ) { |
|
651 | - $terms = false; |
|
652 | - |
|
653 | - if ( isset( $data[0]['category'] ) ) { |
|
654 | - $term = term_exists( trim( $data[0]['category'] ), 'accommodation-type' ); |
|
655 | - if ( ! $term ) { |
|
656 | - $term = wp_insert_term( trim( $data[0]['category'] ), 'accommodation-type' ); |
|
657 | - |
|
658 | - if ( is_wp_error( $term ) ) { |
|
659 | - echo wp_kses_post( $term->get_error_message() ); |
|
660 | - } |
|
661 | - } else { |
|
662 | - wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type', true ); |
|
663 | - } |
|
664 | - } else { |
|
665 | - wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type', true ); |
|
666 | - } |
|
667 | - } |
|
668 | - |
|
669 | - /** |
|
670 | - * Saves the room data |
|
671 | - */ |
|
672 | - public function set_room_data( $data, $id ) { |
|
673 | - if ( ! empty( $data[0]['rooms'] ) && is_array( $data[0]['rooms'] ) ) { |
|
674 | - $rooms = false; |
|
675 | - |
|
676 | - foreach ( $data[0]['rooms'] as $room ) { |
|
677 | - $temp_room = array(); |
|
678 | - |
|
679 | - if ( isset( $room['name'] ) ) { |
|
680 | - $temp_room['title'] = $room['name']; |
|
681 | - } |
|
682 | - |
|
683 | - if ( isset( $room['description'] ) ) { |
|
684 | - $temp_room['description'] = strip_tags( $room['description'] ); |
|
685 | - } |
|
686 | - |
|
687 | - $temp_room['price'] = 0; |
|
688 | - $temp_room['type'] = 'room'; |
|
689 | - |
|
690 | - if ( ! empty( $room['images'] ) && is_array( $room['images'] ) ) { |
|
691 | - $temp_room['gallery'] = array(); |
|
692 | - $temp_room['gallery'][] = $this->attach_image( $room['images'][0], $id ); |
|
693 | - } |
|
694 | - $rooms[] = $temp_room; |
|
695 | - } |
|
696 | - |
|
697 | - if ( false !== $id && '0' !== $id ) { |
|
698 | - delete_post_meta( $id, 'units' ); |
|
699 | - } |
|
700 | - |
|
701 | - foreach ( $rooms as $room ) { |
|
702 | - add_post_meta( $id, 'units', $room, false ); |
|
703 | - } |
|
704 | - |
|
705 | - if ( isset( $data[0]['features'] ) && isset( $data[0]['features']['rooms'] ) ) { |
|
706 | - $room_count = $data[0]['features']['rooms']; |
|
707 | - } else { |
|
708 | - $room_count = count( $data[0]['rooms'] ); |
|
709 | - } |
|
710 | - |
|
711 | - if ( false !== $id && '0' !== $id ) { |
|
712 | - $prev_rooms = get_post_meta( $id, 'number_of_rooms', true ); |
|
713 | - update_post_meta( $id, 'number_of_rooms', $room_count, $prev_rooms ); |
|
714 | - } else { |
|
715 | - add_post_meta( $id, 'number_of_rooms', $room_count, true ); |
|
716 | - } |
|
717 | - } |
|
718 | - } |
|
719 | - |
|
720 | - /** |
|
721 | - * Set the ratings |
|
722 | - */ |
|
723 | - public function set_rating( $data, $id ) { |
|
724 | - if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['star_authority'] ) ) { |
|
725 | - $rating_type = $data[0]['features']['star_authority']; |
|
726 | - } else { |
|
727 | - $rating_type = 'Unspecified2'; |
|
728 | - } |
|
729 | - |
|
730 | - $this->save_custom_field( $rating_type, 'rating_type', $id ); |
|
731 | - |
|
732 | - if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['stars'] ) ) { |
|
733 | - $this->save_custom_field( $data[0]['features']['stars'], 'rating', $id, true ); |
|
734 | - } |
|
735 | - } |
|
736 | - |
|
737 | - /** |
|
738 | - * Set the spoken_languages |
|
739 | - */ |
|
740 | - public function set_spoken_languages( $data, $id ) { |
|
741 | - if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['spoken_languages'] ) && ! empty( $data[0]['features']['spoken_languages'] ) ) { |
|
742 | - $languages = false; |
|
743 | - |
|
744 | - foreach ( $data[0]['features']['spoken_languages'] as $spoken_language ) { |
|
745 | - $languages[] = sanitize_title( $spoken_language ); |
|
746 | - } |
|
747 | - |
|
748 | - if ( false !== $languages ) { |
|
749 | - $this->save_custom_field( $languages, 'spoken_languages', $id ); |
|
750 | - } |
|
751 | - } |
|
752 | - } |
|
753 | - |
|
754 | - /** |
|
755 | - * Set the friendly |
|
756 | - */ |
|
757 | - public function set_friendly( $data, $id ) { |
|
758 | - if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['suggested_visitor_types'] ) && ! empty( $data[0]['features']['suggested_visitor_types'] ) ) { |
|
759 | - $friendly_options = false; |
|
760 | - |
|
761 | - foreach ( $data[0]['features']['suggested_visitor_types'] as $visitor_type ) { |
|
762 | - $friendly_options[] = sanitize_title( $visitor_type ); |
|
763 | - } |
|
764 | - |
|
765 | - if ( false !== $friendly_options ) { |
|
766 | - $this->save_custom_field( $friendly_options, 'suggested_visitor_types', $id ); |
|
767 | - } |
|
768 | - } |
|
769 | - } |
|
770 | - |
|
771 | - /** |
|
772 | - * Set the special interests |
|
773 | - */ |
|
774 | - public function set_special_interests( $data, $id ) { |
|
775 | - if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['special_interests'] ) && ! empty( $data[0]['features']['special_interests'] ) ) { |
|
776 | - $interests = false; |
|
777 | - |
|
778 | - foreach ( $data[0]['features']['special_interests'] as $special_interest ) { |
|
779 | - $interests[] = sanitize_title( $special_interest ); |
|
780 | - } |
|
781 | - |
|
782 | - if ( false !== $interests ) { |
|
783 | - $this->save_custom_field( $interests, 'special_interests', $id ); |
|
784 | - } |
|
785 | - } |
|
786 | - } |
|
787 | - |
|
788 | - /** |
|
789 | - * Set the Check in and Check out Date |
|
790 | - */ |
|
791 | - public function set_checkin_checkout( $data, $id ) { |
|
792 | - if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_in_time'] ) ) { |
|
793 | - $time = str_replace( 'h', ':', $data[0]['features']['check_in_time'] ); |
|
794 | - $time = date( 'h:ia', strtotime( $time ) ); |
|
795 | - $this->save_custom_field( $time, 'checkin_time', $id ); |
|
796 | - } |
|
797 | - |
|
798 | - if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_out_time'] ) ) { |
|
799 | - $time = str_replace( 'h', ':', $data[0]['features']['check_out_time'] ); |
|
800 | - $time = date( 'h:ia', strtotime( $time ) ); |
|
801 | - $this->save_custom_field( $time, 'checkout_time', $id ); |
|
802 | - } |
|
803 | - } |
|
804 | - |
|
805 | - /** |
|
806 | - * Set the Facilities |
|
807 | - */ |
|
808 | - public function set_facilities( $data, $id ) { |
|
809 | - $parent_facilities = array( |
|
810 | - 'available_services' => 'Available Services', |
|
811 | - 'property_facilities' => 'Property Facilities', |
|
812 | - 'room_facilities' => 'Room Facilities', |
|
813 | - 'activities_on_site' => 'Activities on Site', |
|
814 | - ); |
|
815 | - |
|
816 | - foreach ( $parent_facilities as $key => $label ) { |
|
817 | - $terms = false; |
|
818 | - |
|
819 | - if ( isset( $data[0]['features'] ) && isset( $data[0]['features'][ $key ] ) ) { |
|
820 | - $parent_id = $this->set_term( $id, $label, 'facility' ); |
|
821 | - } |
|
822 | - |
|
823 | - foreach ( $data[0]['features'][ $key ] as $child_facility ) { |
|
824 | - $this->set_term( $id, $child_facility, 'facility', $parent_id ); |
|
825 | - } |
|
826 | - } |
|
827 | - } |
|
375 | + return $row_html; |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Saves the queue to the option. |
|
381 | + */ |
|
382 | + public function remove_from_queue( $id ) { |
|
383 | + if ( ! empty( $this->queued_imports ) ) { |
|
384 | + $key = array_search( $id, $this->queued_imports ); |
|
385 | + if ( false !== $key ) { |
|
386 | + unset( $this->queued_imports[ $key ] ); |
|
387 | + |
|
388 | + delete_option( 'lsx_wetu_importer_que' ); |
|
389 | + update_option( 'lsx_wetu_importer_que', $this->queued_imports ); |
|
390 | + } |
|
391 | + } |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * Connect to wetu |
|
396 | + */ |
|
397 | + public function process_ajax_import() { |
|
398 | + $return = false; |
|
399 | + check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
400 | + |
|
401 | + if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && 'accommodation' === $_POST['type'] && isset( $_POST['wetu_id'] ) ) { |
|
402 | + |
|
403 | + $wetu_id = sanitize_text_field( $_POST['wetu_id'] ); |
|
404 | + if ( isset( $_POST['post_id'] ) ) { |
|
405 | + $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
406 | + } else { |
|
407 | + $post_id = 0; |
|
408 | + } |
|
409 | + |
|
410 | + if ( isset( $_POST['team_members'] ) ) { |
|
411 | + $team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) ); |
|
412 | + } else { |
|
413 | + $team_members = false; |
|
414 | + } |
|
415 | + |
|
416 | + if ( isset( $_POST['safari_brands'] ) ) { |
|
417 | + $safari_brands = array_map( 'sanitize_text_field', wp_unslash( $_POST['safari_brands'] ) ); |
|
418 | + } else { |
|
419 | + $safari_brands = false; |
|
420 | + } |
|
421 | + delete_option( 'lsx_wetu_importer_accommodation_settings' ); |
|
422 | + |
|
423 | + if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) { |
|
424 | + $content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) ); |
|
425 | + add_option( 'lsx_wetu_importer_accommodation_settings', $content ); |
|
426 | + } else { |
|
427 | + $content = false; |
|
428 | + } |
|
429 | + |
|
430 | + $jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
431 | + |
|
432 | + if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) { |
|
433 | + $adata = json_decode( $jdata['body'], true ); |
|
434 | + $return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands ); |
|
435 | + $this->format_completed_row( $return ); |
|
436 | + $this->remove_from_queue( $return ); |
|
437 | + $this->cleanup_posts(); |
|
438 | + } else { |
|
439 | + $this->format_error( esc_html__( 'There was a problem importing your accommodation, please try refreshing the page.', 'lsx-wetu-importer' ) ); |
|
440 | + } |
|
441 | + } |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * Connect to wetu |
|
446 | + */ |
|
447 | + public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false ) { |
|
448 | + $post_name = ''; |
|
449 | + $data_post_content = ''; |
|
450 | + $data_post_excerpt = ''; |
|
451 | + |
|
452 | + $post = array( |
|
453 | + 'post_type' => 'accommodation', |
|
454 | + ); |
|
455 | + $content_used_general_description = false; |
|
456 | + |
|
457 | + // Set the post_content. |
|
458 | + if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) { |
|
459 | + if ( isset( $data[0]['content']['extended_description'] ) ) { |
|
460 | + $data_post_content = $data[0]['content']['extended_description']; |
|
461 | + } elseif ( isset( $data[0]['content']['general_description'] ) ) { |
|
462 | + $data_post_content = $data[0]['content']['general_description']; |
|
463 | + $content_used_general_description = true; |
|
464 | + } elseif ( isset( $data[0]['content']['teaser_description'] ) ) { |
|
465 | + $data_post_content = $data[0]['content']['teaser_description']; |
|
466 | + } |
|
467 | + |
|
468 | + if ( isset( $this->options['disable_accommodation_filtering'] ) && 'on' === $this->options['disable_accommodation_filtering'] ) { |
|
469 | + $post['post_content'] = $data_post_content; |
|
470 | + } else { |
|
471 | + $post['post_content'] = wp_strip_all_tags( $data_post_content ); |
|
472 | + } |
|
473 | + } |
|
474 | + |
|
475 | + // set the post_excerpt. |
|
476 | + if ( ! empty( $importable_content ) && in_array( 'excerpt', $importable_content ) ) { |
|
477 | + if ( isset( $data[0]['content']['teaser_description'] ) ) { |
|
478 | + $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
479 | + } elseif ( isset( $data[0]['content']['general_description'] ) && false === $content_used_general_description ) { |
|
480 | + $data_post_excerpt = $data[0]['content']['general_description']; |
|
481 | + } |
|
482 | + |
|
483 | + $post['post_excerpt'] = $data_post_excerpt; |
|
484 | + } |
|
485 | + |
|
486 | + if ( false !== $id && '0' !== $id ) { |
|
487 | + $post['ID'] = $id; |
|
488 | + |
|
489 | + if ( isset( $this->options ) && 'on' !== $this->options['disable_accommodation_title'] && isset( $data[0]['name'] ) ) { |
|
490 | + $post['post_title'] = $data[0]['name']; |
|
491 | + $post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'accommodation', 0 ); |
|
492 | + } |
|
493 | + |
|
494 | + $post['post_status'] = 'publish'; |
|
495 | + |
|
496 | + $id = wp_update_post( $post ); |
|
497 | + $prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true ); |
|
498 | + update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date ); |
|
499 | + } else { |
|
500 | + // Set the name. |
|
501 | + if ( isset( $data[0]['name'] ) ) { |
|
502 | + $post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'accommodation', 0 ); |
|
503 | + } |
|
504 | + |
|
505 | + $post['post_name'] = $post_name; |
|
506 | + $post['post_title'] = $data[0]['name']; |
|
507 | + $post['post_status'] = 'publish'; |
|
508 | + $id = wp_insert_post( $post ); |
|
509 | + |
|
510 | + // Save the WETU ID and the Last date it was modified. |
|
511 | + if ( false !== $id ) { |
|
512 | + add_post_meta( $id, 'lsx_wetu_id', $wetu_id ); |
|
513 | + add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) ); |
|
514 | + } |
|
515 | + } |
|
516 | + |
|
517 | + // Setup some default for use in the import. |
|
518 | + if ( false !== $importable_content && ( in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content ) ) ) { |
|
519 | + $this->find_attachments( $id ); |
|
520 | + } |
|
521 | + |
|
522 | + // Set the team member if it is there. |
|
523 | + if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) { |
|
524 | + $this->set_team_member( $id, $team_members ); |
|
525 | + } |
|
526 | + |
|
527 | + // Set the safari brand. |
|
528 | + if ( false !== $safari_brands && '' !== $safari_brands ) { |
|
529 | + $this->set_safari_brands( $id, $safari_brands ); |
|
530 | + } |
|
531 | + |
|
532 | + $this->set_map_data( $data, $id, 9 ); |
|
533 | + |
|
534 | + if ( post_type_exists( 'destination' ) && false !== $importable_content && in_array( 'destination', $importable_content ) ) { |
|
535 | + $this->connect_destinations( $data, $id ); |
|
536 | + } |
|
537 | + |
|
538 | + if ( false !== $importable_content && in_array( 'category', $importable_content ) ) { |
|
539 | + $this->set_taxonomy_style( $data, $id ); |
|
540 | + } |
|
541 | + |
|
542 | + // Set the Room Data. |
|
543 | + if ( false !== $importable_content && in_array( 'rooms', $importable_content ) ) { |
|
544 | + $this->set_room_data( $data, $id ); |
|
545 | + } |
|
546 | + |
|
547 | + // Set the rating. |
|
548 | + if ( false !== $importable_content && in_array( 'rating', $importable_content ) ) { |
|
549 | + $this->set_rating( $data, $id ); |
|
550 | + } |
|
551 | + |
|
552 | + // Set the checkin checkout data. |
|
553 | + if ( false !== $importable_content && in_array( 'checkin', $importable_content ) ) { |
|
554 | + $this->set_checkin_checkout( $data, $id ); |
|
555 | + } |
|
556 | + |
|
557 | + // Set the Spoken Languages. |
|
558 | + if ( false !== $importable_content && in_array( 'spoken_languages', $importable_content ) ) { |
|
559 | + $this->set_spoken_languages( $data, $id ); |
|
560 | + } |
|
561 | + |
|
562 | + // Set the friendly options. |
|
563 | + if ( false !== $importable_content && in_array( 'friendly', $importable_content ) ) { |
|
564 | + $this->set_friendly( $data, $id ); |
|
565 | + } |
|
566 | + |
|
567 | + // Set the special_interests. |
|
568 | + if ( false !== $importable_content && in_array( 'special_interests', $importable_content ) ) { |
|
569 | + $this->set_special_interests( $data, $id ); |
|
570 | + } |
|
571 | + |
|
572 | + // Import the videos. |
|
573 | + if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) { |
|
574 | + $this->set_video_data( $data, $id ); |
|
575 | + } |
|
576 | + |
|
577 | + // Import the facilities. |
|
578 | + if ( false !== $importable_content && in_array( 'facilities', $importable_content ) ) { |
|
579 | + $this->set_facilities( $data, $id ); |
|
580 | + } |
|
581 | + |
|
582 | + // Set the featured image. |
|
583 | + if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) { |
|
584 | + $this->set_featured_image( $data, $id ); |
|
585 | + } |
|
586 | + |
|
587 | + if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) { |
|
588 | + $this->set_banner_image( $data, $id ); |
|
589 | + } |
|
590 | + |
|
591 | + // Import the main gallery. |
|
592 | + if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) { |
|
593 | + $this->create_main_gallery( $data, $id ); |
|
594 | + } |
|
595 | + |
|
596 | + return $id; |
|
597 | + } |
|
598 | + |
|
599 | + /** |
|
600 | + * Set the safari brand |
|
601 | + */ |
|
602 | + public function set_safari_brands( $id, $safari_brands ) { |
|
603 | + foreach ( $safari_brands as $safari_brand ) { |
|
604 | + wp_set_object_terms( $id, intval( $safari_brand ), 'accommodation-brand', true ); |
|
605 | + } |
|
606 | + } |
|
607 | + |
|
608 | + /** |
|
609 | + * Connects the destinations post type |
|
610 | + */ |
|
611 | + public function connect_destinations( $data, $id ) { |
|
612 | + if ( isset( $data[0]['position'] ) ) { |
|
613 | + $destinations = false; |
|
614 | + |
|
615 | + if ( isset( $data[0]['position']['country'] ) ) { |
|
616 | + $destinations['country'] = $data[0]['position']['country']; |
|
617 | + } |
|
618 | + |
|
619 | + if ( isset( $data[0]['position']['destination'] ) ) { |
|
620 | + $destinations['destination'] = $data[0]['position']['destination']; |
|
621 | + } |
|
622 | + |
|
623 | + if ( false !== $destinations ) { |
|
624 | + $prev_values = get_post_meta( $id, 'destination_to_accommodation', false ); |
|
625 | + |
|
626 | + if ( false === $prev_values || ! is_array( $prev_values ) ) { |
|
627 | + $prev_values = array(); |
|
628 | + } |
|
629 | + |
|
630 | + delete_post_meta( $id, 'destination_to_accommodation', $prev_values ); |
|
631 | + $destinations = array_unique( $destinations ); |
|
632 | + |
|
633 | + foreach ( $destinations as $key => $value ) { |
|
634 | + $destination = get_page_by_title( ltrim( rtrim( $value ) ), 'OBJECT', 'destination' ); |
|
635 | + if ( null !== $destination ) { |
|
636 | + if ( ! in_array( $destination->ID, $prev_values ) ) { |
|
637 | + add_post_meta( $id, 'destination_to_accommodation', $destination->ID, false ); |
|
638 | + add_post_meta( $destination->ID, 'accommodation_to_destination', $id, false ); |
|
639 | + $this->cleanup_posts[ $destination->ID ] = 'accommodation_to_destination'; |
|
640 | + } |
|
641 | + } |
|
642 | + } |
|
643 | + } |
|
644 | + } |
|
645 | + } |
|
646 | + |
|
647 | + /** |
|
648 | + * Set the Travel Style |
|
649 | + */ |
|
650 | + public function set_taxonomy_style( $data, $id ) { |
|
651 | + $terms = false; |
|
652 | + |
|
653 | + if ( isset( $data[0]['category'] ) ) { |
|
654 | + $term = term_exists( trim( $data[0]['category'] ), 'accommodation-type' ); |
|
655 | + if ( ! $term ) { |
|
656 | + $term = wp_insert_term( trim( $data[0]['category'] ), 'accommodation-type' ); |
|
657 | + |
|
658 | + if ( is_wp_error( $term ) ) { |
|
659 | + echo wp_kses_post( $term->get_error_message() ); |
|
660 | + } |
|
661 | + } else { |
|
662 | + wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type', true ); |
|
663 | + } |
|
664 | + } else { |
|
665 | + wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type', true ); |
|
666 | + } |
|
667 | + } |
|
668 | + |
|
669 | + /** |
|
670 | + * Saves the room data |
|
671 | + */ |
|
672 | + public function set_room_data( $data, $id ) { |
|
673 | + if ( ! empty( $data[0]['rooms'] ) && is_array( $data[0]['rooms'] ) ) { |
|
674 | + $rooms = false; |
|
675 | + |
|
676 | + foreach ( $data[0]['rooms'] as $room ) { |
|
677 | + $temp_room = array(); |
|
678 | + |
|
679 | + if ( isset( $room['name'] ) ) { |
|
680 | + $temp_room['title'] = $room['name']; |
|
681 | + } |
|
682 | + |
|
683 | + if ( isset( $room['description'] ) ) { |
|
684 | + $temp_room['description'] = strip_tags( $room['description'] ); |
|
685 | + } |
|
686 | + |
|
687 | + $temp_room['price'] = 0; |
|
688 | + $temp_room['type'] = 'room'; |
|
689 | + |
|
690 | + if ( ! empty( $room['images'] ) && is_array( $room['images'] ) ) { |
|
691 | + $temp_room['gallery'] = array(); |
|
692 | + $temp_room['gallery'][] = $this->attach_image( $room['images'][0], $id ); |
|
693 | + } |
|
694 | + $rooms[] = $temp_room; |
|
695 | + } |
|
696 | + |
|
697 | + if ( false !== $id && '0' !== $id ) { |
|
698 | + delete_post_meta( $id, 'units' ); |
|
699 | + } |
|
700 | + |
|
701 | + foreach ( $rooms as $room ) { |
|
702 | + add_post_meta( $id, 'units', $room, false ); |
|
703 | + } |
|
704 | + |
|
705 | + if ( isset( $data[0]['features'] ) && isset( $data[0]['features']['rooms'] ) ) { |
|
706 | + $room_count = $data[0]['features']['rooms']; |
|
707 | + } else { |
|
708 | + $room_count = count( $data[0]['rooms'] ); |
|
709 | + } |
|
710 | + |
|
711 | + if ( false !== $id && '0' !== $id ) { |
|
712 | + $prev_rooms = get_post_meta( $id, 'number_of_rooms', true ); |
|
713 | + update_post_meta( $id, 'number_of_rooms', $room_count, $prev_rooms ); |
|
714 | + } else { |
|
715 | + add_post_meta( $id, 'number_of_rooms', $room_count, true ); |
|
716 | + } |
|
717 | + } |
|
718 | + } |
|
719 | + |
|
720 | + /** |
|
721 | + * Set the ratings |
|
722 | + */ |
|
723 | + public function set_rating( $data, $id ) { |
|
724 | + if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['star_authority'] ) ) { |
|
725 | + $rating_type = $data[0]['features']['star_authority']; |
|
726 | + } else { |
|
727 | + $rating_type = 'Unspecified2'; |
|
728 | + } |
|
729 | + |
|
730 | + $this->save_custom_field( $rating_type, 'rating_type', $id ); |
|
731 | + |
|
732 | + if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['stars'] ) ) { |
|
733 | + $this->save_custom_field( $data[0]['features']['stars'], 'rating', $id, true ); |
|
734 | + } |
|
735 | + } |
|
736 | + |
|
737 | + /** |
|
738 | + * Set the spoken_languages |
|
739 | + */ |
|
740 | + public function set_spoken_languages( $data, $id ) { |
|
741 | + if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['spoken_languages'] ) && ! empty( $data[0]['features']['spoken_languages'] ) ) { |
|
742 | + $languages = false; |
|
743 | + |
|
744 | + foreach ( $data[0]['features']['spoken_languages'] as $spoken_language ) { |
|
745 | + $languages[] = sanitize_title( $spoken_language ); |
|
746 | + } |
|
747 | + |
|
748 | + if ( false !== $languages ) { |
|
749 | + $this->save_custom_field( $languages, 'spoken_languages', $id ); |
|
750 | + } |
|
751 | + } |
|
752 | + } |
|
753 | + |
|
754 | + /** |
|
755 | + * Set the friendly |
|
756 | + */ |
|
757 | + public function set_friendly( $data, $id ) { |
|
758 | + if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['suggested_visitor_types'] ) && ! empty( $data[0]['features']['suggested_visitor_types'] ) ) { |
|
759 | + $friendly_options = false; |
|
760 | + |
|
761 | + foreach ( $data[0]['features']['suggested_visitor_types'] as $visitor_type ) { |
|
762 | + $friendly_options[] = sanitize_title( $visitor_type ); |
|
763 | + } |
|
764 | + |
|
765 | + if ( false !== $friendly_options ) { |
|
766 | + $this->save_custom_field( $friendly_options, 'suggested_visitor_types', $id ); |
|
767 | + } |
|
768 | + } |
|
769 | + } |
|
770 | + |
|
771 | + /** |
|
772 | + * Set the special interests |
|
773 | + */ |
|
774 | + public function set_special_interests( $data, $id ) { |
|
775 | + if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['special_interests'] ) && ! empty( $data[0]['features']['special_interests'] ) ) { |
|
776 | + $interests = false; |
|
777 | + |
|
778 | + foreach ( $data[0]['features']['special_interests'] as $special_interest ) { |
|
779 | + $interests[] = sanitize_title( $special_interest ); |
|
780 | + } |
|
781 | + |
|
782 | + if ( false !== $interests ) { |
|
783 | + $this->save_custom_field( $interests, 'special_interests', $id ); |
|
784 | + } |
|
785 | + } |
|
786 | + } |
|
787 | + |
|
788 | + /** |
|
789 | + * Set the Check in and Check out Date |
|
790 | + */ |
|
791 | + public function set_checkin_checkout( $data, $id ) { |
|
792 | + if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_in_time'] ) ) { |
|
793 | + $time = str_replace( 'h', ':', $data[0]['features']['check_in_time'] ); |
|
794 | + $time = date( 'h:ia', strtotime( $time ) ); |
|
795 | + $this->save_custom_field( $time, 'checkin_time', $id ); |
|
796 | + } |
|
797 | + |
|
798 | + if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_out_time'] ) ) { |
|
799 | + $time = str_replace( 'h', ':', $data[0]['features']['check_out_time'] ); |
|
800 | + $time = date( 'h:ia', strtotime( $time ) ); |
|
801 | + $this->save_custom_field( $time, 'checkout_time', $id ); |
|
802 | + } |
|
803 | + } |
|
804 | + |
|
805 | + /** |
|
806 | + * Set the Facilities |
|
807 | + */ |
|
808 | + public function set_facilities( $data, $id ) { |
|
809 | + $parent_facilities = array( |
|
810 | + 'available_services' => 'Available Services', |
|
811 | + 'property_facilities' => 'Property Facilities', |
|
812 | + 'room_facilities' => 'Room Facilities', |
|
813 | + 'activities_on_site' => 'Activities on Site', |
|
814 | + ); |
|
815 | + |
|
816 | + foreach ( $parent_facilities as $key => $label ) { |
|
817 | + $terms = false; |
|
818 | + |
|
819 | + if ( isset( $data[0]['features'] ) && isset( $data[0]['features'][ $key ] ) ) { |
|
820 | + $parent_id = $this->set_term( $id, $label, 'facility' ); |
|
821 | + } |
|
822 | + |
|
823 | + foreach ( $data[0]['features'][ $key ] as $child_facility ) { |
|
824 | + $this->set_term( $id, $child_facility, 'facility', $parent_id ); |
|
825 | + } |
|
826 | + } |
|
827 | + } |
|
828 | 828 | } |
@@ -9,51 +9,51 @@ discard block |
||
9 | 9 | |
10 | 10 | class LSX_WETU_Importer_Connect_Accommodation extends LSX_WETU_Importer_Admin { |
11 | 11 | |
12 | - /** |
|
13 | - * The url to list items from WETU |
|
14 | - * |
|
15 | - * @since 0.0.1 |
|
16 | - * |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - public $tab_slug = 'connect_accommodation'; |
|
20 | - |
|
21 | - /** |
|
22 | - * The url to list items from WETU |
|
23 | - * |
|
24 | - * @since 0.0.1 |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $url = false; |
|
29 | - |
|
30 | - /** |
|
31 | - * Initialize the plugin by setting localization, filters, and administration functions. |
|
32 | - * |
|
33 | - * @since 1.0.0 |
|
34 | - * |
|
35 | - * @access private |
|
36 | - */ |
|
37 | - public function __construct() { |
|
38 | - $temp_options = get_option( '_lsx-to_settings', false ); |
|
39 | - |
|
40 | - if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) { |
|
41 | - $this->options = $temp_options[ $this->plugin_slug ]; |
|
42 | - } |
|
43 | - |
|
44 | - $this->url = 'http://wetu.com/API/Pins/' . $this->options['api_key'] . '/List'; |
|
45 | - |
|
46 | - add_action( 'lsx_tour_importer_admin_tab_' . $this->tab_slug, array( $this, 'display_page' ) ); |
|
47 | - add_action( 'wp_ajax_lsx_import_connect_accommodation', array( $this, 'process_connection' ) ); |
|
48 | - add_action( 'wp_ajax_nopriv_lsx_import_connect_accommodation', array( $this, 'process_connection' ) ); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Display the importer administration screen |
|
53 | - */ |
|
54 | - public function display_page() { |
|
55 | - global $post; |
|
56 | - ?> |
|
12 | + /** |
|
13 | + * The url to list items from WETU |
|
14 | + * |
|
15 | + * @since 0.0.1 |
|
16 | + * |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + public $tab_slug = 'connect_accommodation'; |
|
20 | + |
|
21 | + /** |
|
22 | + * The url to list items from WETU |
|
23 | + * |
|
24 | + * @since 0.0.1 |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $url = false; |
|
29 | + |
|
30 | + /** |
|
31 | + * Initialize the plugin by setting localization, filters, and administration functions. |
|
32 | + * |
|
33 | + * @since 1.0.0 |
|
34 | + * |
|
35 | + * @access private |
|
36 | + */ |
|
37 | + public function __construct() { |
|
38 | + $temp_options = get_option( '_lsx-to_settings', false ); |
|
39 | + |
|
40 | + if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) { |
|
41 | + $this->options = $temp_options[ $this->plugin_slug ]; |
|
42 | + } |
|
43 | + |
|
44 | + $this->url = 'http://wetu.com/API/Pins/' . $this->options['api_key'] . '/List'; |
|
45 | + |
|
46 | + add_action( 'lsx_tour_importer_admin_tab_' . $this->tab_slug, array( $this, 'display_page' ) ); |
|
47 | + add_action( 'wp_ajax_lsx_import_connect_accommodation', array( $this, 'process_connection' ) ); |
|
48 | + add_action( 'wp_ajax_nopriv_lsx_import_connect_accommodation', array( $this, 'process_connection' ) ); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Display the importer administration screen |
|
53 | + */ |
|
54 | + public function display_page() { |
|
55 | + global $post; |
|
56 | + ?> |
|
57 | 57 | <div class="wrap"> |
58 | 58 | <h3><span class="dashicons dashicons-admin-multisite"></span> <?php esc_html_e( 'Connect your Accommodation', 'lsx-wetu-importer' ); ?></h3> |
59 | 59 | |
@@ -67,38 +67,38 @@ discard block |
||
67 | 67 | </div> |
68 | 68 | |
69 | 69 | <?php |
70 | - $loose_accommodation = $this->find_current_accommodation(); |
|
71 | - ?> |
|
70 | + $loose_accommodation = $this->find_current_accommodation(); |
|
71 | + ?> |
|
72 | 72 | <p><input class="button button-primary connect" type="button" value="<?php esc_html_e( 'Connect', 'lsx-wetu-importer' ); ?>" /></p> |
73 | 73 | <table class="wp-list-table widefat fixed posts"> |
74 | 74 | <?php $this->table_header(); ?> |
75 | 75 | |
76 | 76 | <tbody> |
77 | 77 | <?php |
78 | - if ( false !== $loose_accommodation ) { |
|
79 | - |
|
80 | - $loose_args = array( |
|
81 | - 'post_type' => 'accommodation', |
|
82 | - 'post_status' => array( 'publish', 'pending' ), |
|
83 | - 'nopagin' => true, |
|
84 | - 'post__in' => $loose_accommodation, |
|
85 | - ); |
|
86 | - $loose_accommodation_query = new WP_Query( $loose_args ); |
|
87 | - $accommodation = get_transient( 'lsx_ti_accommodation' ); |
|
88 | - $identifier = ''; |
|
89 | - |
|
90 | - if ( $loose_accommodation_query->have_posts() && false !== $accommodation ) { |
|
91 | - while ( $loose_accommodation_query->have_posts() ) { |
|
92 | - $loose_accommodation_query->the_post(); |
|
93 | - |
|
94 | - foreach ( $accommodation as $row_key => $row ) { |
|
95 | - if ( stripos( ltrim( rtrim( $row->name ) ), $post->post_title ) !== false ) { |
|
96 | - $identifier = $row->id; |
|
97 | - } else { |
|
98 | - continue; |
|
99 | - } |
|
100 | - } |
|
101 | - ?> |
|
78 | + if ( false !== $loose_accommodation ) { |
|
79 | + |
|
80 | + $loose_args = array( |
|
81 | + 'post_type' => 'accommodation', |
|
82 | + 'post_status' => array( 'publish', 'pending' ), |
|
83 | + 'nopagin' => true, |
|
84 | + 'post__in' => $loose_accommodation, |
|
85 | + ); |
|
86 | + $loose_accommodation_query = new WP_Query( $loose_args ); |
|
87 | + $accommodation = get_transient( 'lsx_ti_accommodation' ); |
|
88 | + $identifier = ''; |
|
89 | + |
|
90 | + if ( $loose_accommodation_query->have_posts() && false !== $accommodation ) { |
|
91 | + while ( $loose_accommodation_query->have_posts() ) { |
|
92 | + $loose_accommodation_query->the_post(); |
|
93 | + |
|
94 | + foreach ( $accommodation as $row_key => $row ) { |
|
95 | + if ( stripos( ltrim( rtrim( $row->name ) ), $post->post_title ) !== false ) { |
|
96 | + $identifier = $row->id; |
|
97 | + } else { |
|
98 | + continue; |
|
99 | + } |
|
100 | + } |
|
101 | + ?> |
|
102 | 102 | <tr class="post-<?php the_ID(); ?> type-accommodation status-none" id="post-<?php the_ID(); ?>"> |
103 | 103 | <th class="check-column" scope="row"> |
104 | 104 | <label for="cb-select-<?php the_ID(); ?>" class="screen-reader-text"><?php the_title(); ?></label> |
@@ -109,15 +109,15 @@ discard block |
||
109 | 109 | </td> |
110 | 110 | <td class="excerpt column-excerpt"> |
111 | 111 | <?php |
112 | - echo wp_kses_post( strip_tags( get_the_excerpt() ) ); |
|
113 | - ?> |
|
112 | + echo wp_kses_post( strip_tags( get_the_excerpt() ) ); |
|
113 | + ?> |
|
114 | 114 | </td> |
115 | 115 | </tr> |
116 | 116 | <?php |
117 | - } |
|
118 | - } |
|
119 | - } |
|
120 | - ?> |
|
117 | + } |
|
118 | + } |
|
119 | + } |
|
120 | + ?> |
|
121 | 121 | </tbody> |
122 | 122 | |
123 | 123 | <?php $this->table_footer(); ?> |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | </div> |
136 | 136 | </div> |
137 | 137 | <?php |
138 | - } |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * The header of the item list |
|
142 | - */ |
|
143 | - public function table_header() { |
|
144 | - ?> |
|
140 | + /** |
|
141 | + * The header of the item list |
|
142 | + */ |
|
143 | + public function table_header() { |
|
144 | + ?> |
|
145 | 145 | <thead> |
146 | 146 | <tr> |
147 | 147 | <th style="" class="manage-column column-cb check-column" id="cb" scope="col"> |
@@ -153,13 +153,13 @@ discard block |
||
153 | 153 | </tr> |
154 | 154 | </thead> |
155 | 155 | <?php |
156 | - } |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * The footer of the item list |
|
160 | - */ |
|
161 | - public function table_footer() { |
|
162 | - ?> |
|
158 | + /** |
|
159 | + * The footer of the item list |
|
160 | + */ |
|
161 | + public function table_footer() { |
|
162 | + ?> |
|
163 | 163 | <tfoot> |
164 | 164 | <tr> |
165 | 165 | <th style="" class="manage-column column-cb check-column" id="cb" scope="col"> |
@@ -171,27 +171,27 @@ discard block |
||
171 | 171 | </tr> |
172 | 172 | </tfoot> |
173 | 173 | <?php |
174 | - } |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * Grab all the current accommodation posts via the lsx_wetu_id field. |
|
178 | - */ |
|
179 | - public function find_current_accommodation() { |
|
180 | - global $wpdb; |
|
181 | - $return = false; |
|
176 | + /** |
|
177 | + * Grab all the current accommodation posts via the lsx_wetu_id field. |
|
178 | + */ |
|
179 | + public function find_current_accommodation() { |
|
180 | + global $wpdb; |
|
181 | + $return = false; |
|
182 | 182 | |
183 | - $all_accommodation = $wpdb->get_results( |
|
184 | - " |
|
183 | + $all_accommodation = $wpdb->get_results( |
|
184 | + " |
|
185 | 185 | SELECT ID |
186 | 186 | FROM {$wpdb->posts} |
187 | 187 | WHERE post_type = 'accommodation' |
188 | 188 | LIMIT 0,500 |
189 | 189 | ", |
190 | - ARRAY_A |
|
191 | - ); |
|
190 | + ARRAY_A |
|
191 | + ); |
|
192 | 192 | |
193 | - $current_accommodation = $wpdb->get_results( |
|
194 | - " |
|
193 | + $current_accommodation = $wpdb->get_results( |
|
194 | + " |
|
195 | 195 | SELECT key1.post_id |
196 | 196 | FROM {$wpdb->postmeta} key1 |
197 | 197 | |
@@ -203,55 +203,55 @@ discard block |
||
203 | 203 | |
204 | 204 | LIMIT 0,500 |
205 | 205 | ", |
206 | - ARRAY_A |
|
207 | - ); |
|
208 | - |
|
209 | - if ( null !== $all_accommodation && ! empty( $all_accommodation ) ) { |
|
210 | - // remove the extra accommodation |
|
211 | - if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) { |
|
212 | - $all_accommodation = array_diff( $this->format_array( $all_accommodation, 'ID' ), $this->format_array( $current_accommodation, 'post_id' ) ); |
|
213 | - } elseif ( null !== $current_accommodation && empty( $current_accommodation ) ) { |
|
214 | - $all_accommodation = $this->format_array( $current_accommodation, 'post_id' ); |
|
215 | - } |
|
216 | - |
|
217 | - $return = $all_accommodation; |
|
218 | - } |
|
219 | - |
|
220 | - return $return; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * format the array |
|
225 | - */ |
|
226 | - public function format_array( $array, $key ) { |
|
227 | - $new_array = array(); |
|
228 | - |
|
229 | - foreach ( $array as $value ) { |
|
230 | - $new_array[] = $value[ $key ]; |
|
231 | - } |
|
232 | - |
|
233 | - return $new_array; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Run through the accommodation an connect them. |
|
238 | - */ |
|
239 | - public function process_connection() { |
|
240 | - $return = false; |
|
241 | - check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
242 | - if ( isset( $_POST['action'] ) && 'lsx_import_connect_accommodation' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug && isset( $_POST['post_id'] ) && isset( $_POST['wetu_id'] ) ) { |
|
243 | - $post_id = false; |
|
244 | - $matching_id = false; |
|
245 | - $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
246 | - $matching_id = sanitize_text_field( $_POST['wetu_id'] ); |
|
247 | - |
|
248 | - add_post_meta( $post_id, 'lsx_wetu_id', $matching_id ); |
|
249 | - $return = '<li class="post-' . $post_id . '"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="' . get_permalink( $post_id ) . '">' . get_the_title( $post_id ) . '</a></li>'; |
|
250 | - } |
|
251 | - |
|
252 | - print_r( $return ); |
|
253 | - die(); |
|
254 | - } |
|
206 | + ARRAY_A |
|
207 | + ); |
|
208 | + |
|
209 | + if ( null !== $all_accommodation && ! empty( $all_accommodation ) ) { |
|
210 | + // remove the extra accommodation |
|
211 | + if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) { |
|
212 | + $all_accommodation = array_diff( $this->format_array( $all_accommodation, 'ID' ), $this->format_array( $current_accommodation, 'post_id' ) ); |
|
213 | + } elseif ( null !== $current_accommodation && empty( $current_accommodation ) ) { |
|
214 | + $all_accommodation = $this->format_array( $current_accommodation, 'post_id' ); |
|
215 | + } |
|
216 | + |
|
217 | + $return = $all_accommodation; |
|
218 | + } |
|
219 | + |
|
220 | + return $return; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * format the array |
|
225 | + */ |
|
226 | + public function format_array( $array, $key ) { |
|
227 | + $new_array = array(); |
|
228 | + |
|
229 | + foreach ( $array as $value ) { |
|
230 | + $new_array[] = $value[ $key ]; |
|
231 | + } |
|
232 | + |
|
233 | + return $new_array; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Run through the accommodation an connect them. |
|
238 | + */ |
|
239 | + public function process_connection() { |
|
240 | + $return = false; |
|
241 | + check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
242 | + if ( isset( $_POST['action'] ) && 'lsx_import_connect_accommodation' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug && isset( $_POST['post_id'] ) && isset( $_POST['wetu_id'] ) ) { |
|
243 | + $post_id = false; |
|
244 | + $matching_id = false; |
|
245 | + $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
246 | + $matching_id = sanitize_text_field( $_POST['wetu_id'] ); |
|
247 | + |
|
248 | + add_post_meta( $post_id, 'lsx_wetu_id', $matching_id ); |
|
249 | + $return = '<li class="post-' . $post_id . '"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="' . get_permalink( $post_id ) . '">' . get_the_title( $post_id ) . '</a></li>'; |
|
250 | + } |
|
251 | + |
|
252 | + print_r( $return ); |
|
253 | + die(); |
|
254 | + } |
|
255 | 255 | |
256 | 256 | } |
257 | 257 |
@@ -14,109 +14,109 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class LSX_WETU_Importer_Post_Columns { |
16 | 16 | |
17 | - /** |
|
18 | - * Holds instance of the class |
|
19 | - * |
|
20 | - * @var object |
|
21 | - */ |
|
22 | - private static $instance; |
|
17 | + /** |
|
18 | + * Holds instance of the class |
|
19 | + * |
|
20 | + * @var object |
|
21 | + */ |
|
22 | + private static $instance; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Initialize the plugin by setting localization, filters, and administration functions. |
|
26 | - * |
|
27 | - * @since 1.0.0 |
|
28 | - * |
|
29 | - * @access private |
|
30 | - */ |
|
31 | - public function __construct() { |
|
32 | - add_filter( 'manage_tour_posts_columns', array( $this, 'register_tour_columns' ) ); |
|
33 | - add_action( 'manage_tour_posts_custom_column', array( $this, 'output_tour_ref_column' ), 10, 2 ); |
|
24 | + /** |
|
25 | + * Initialize the plugin by setting localization, filters, and administration functions. |
|
26 | + * |
|
27 | + * @since 1.0.0 |
|
28 | + * |
|
29 | + * @access private |
|
30 | + */ |
|
31 | + public function __construct() { |
|
32 | + add_filter( 'manage_tour_posts_columns', array( $this, 'register_tour_columns' ) ); |
|
33 | + add_action( 'manage_tour_posts_custom_column', array( $this, 'output_tour_ref_column' ), 10, 2 ); |
|
34 | 34 | |
35 | - // Sortables Columns, sorting needs to be fixed |
|
36 | - // add_filter( 'manage_edit-tour_sortable_columns', array( $this, 'register_sortable_columns' ) ); |
|
37 | - // add_action( 'pre_get_posts', array( $this, 'columns_posts_orderby' ) ); |
|
38 | - } |
|
35 | + // Sortables Columns, sorting needs to be fixed |
|
36 | + // add_filter( 'manage_edit-tour_sortable_columns', array( $this, 'register_sortable_columns' ) ); |
|
37 | + // add_action( 'pre_get_posts', array( $this, 'columns_posts_orderby' ) ); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Return an instance of this class. |
|
42 | - * |
|
43 | - * @return object |
|
44 | - */ |
|
45 | - public static function get_instance() { |
|
46 | - // If the single instance hasn't been set, set it now. |
|
47 | - if ( ! isset( self::$instance ) ) { |
|
48 | - self::$instance = new self(); |
|
49 | - } |
|
50 | - return self::$instance; |
|
51 | - } |
|
40 | + /** |
|
41 | + * Return an instance of this class. |
|
42 | + * |
|
43 | + * @return object |
|
44 | + */ |
|
45 | + public static function get_instance() { |
|
46 | + // If the single instance hasn't been set, set it now. |
|
47 | + if ( ! isset( self::$instance ) ) { |
|
48 | + self::$instance = new self(); |
|
49 | + } |
|
50 | + return self::$instance; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Display the importer welcome screen |
|
55 | - */ |
|
56 | - public function display_page() { |
|
53 | + /** |
|
54 | + * Display the importer welcome screen |
|
55 | + */ |
|
56 | + public function display_page() { |
|
57 | 57 | |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Registers the tour ref column |
|
62 | - * |
|
63 | - * @param array $columns |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public function register_tour_columns( $columns ) { |
|
67 | - $new_columns = array( |
|
68 | - 'cb' => $columns['cb'], |
|
69 | - 'title' => $columns['title'], |
|
70 | - 'wetu_ref' => __( 'Ref', 'lsx-wetu-importer' ), |
|
71 | - ); |
|
72 | - unset( $columns['cb'] ); |
|
73 | - unset( $columns['title'] ); |
|
74 | - foreach ( $columns as $column_key => $column_label ) { |
|
75 | - $new_columns[ $column_key ] = $column_label; |
|
76 | - } |
|
77 | - $columns = $new_columns; |
|
78 | - return $columns; |
|
79 | - } |
|
60 | + /** |
|
61 | + * Registers the tour ref column |
|
62 | + * |
|
63 | + * @param array $columns |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public function register_tour_columns( $columns ) { |
|
67 | + $new_columns = array( |
|
68 | + 'cb' => $columns['cb'], |
|
69 | + 'title' => $columns['title'], |
|
70 | + 'wetu_ref' => __( 'Ref', 'lsx-wetu-importer' ), |
|
71 | + ); |
|
72 | + unset( $columns['cb'] ); |
|
73 | + unset( $columns['title'] ); |
|
74 | + foreach ( $columns as $column_key => $column_label ) { |
|
75 | + $new_columns[ $column_key ] = $column_label; |
|
76 | + } |
|
77 | + $columns = $new_columns; |
|
78 | + return $columns; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Outputs the tour reference column |
|
83 | - * |
|
84 | - * @param string $column |
|
85 | - * @param string $post_id |
|
86 | - * @return void |
|
87 | - */ |
|
88 | - public function output_tour_ref_column( $column, $post_id ) { |
|
89 | - if ( 'wetu_ref' === $column ) { |
|
90 | - echo esc_attr( get_post_meta( $post_id, 'lsx_wetu_ref', true ) ); |
|
91 | - } |
|
92 | - } |
|
81 | + /** |
|
82 | + * Outputs the tour reference column |
|
83 | + * |
|
84 | + * @param string $column |
|
85 | + * @param string $post_id |
|
86 | + * @return void |
|
87 | + */ |
|
88 | + public function output_tour_ref_column( $column, $post_id ) { |
|
89 | + if ( 'wetu_ref' === $column ) { |
|
90 | + echo esc_attr( get_post_meta( $post_id, 'lsx_wetu_ref', true ) ); |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Register the columns that will be sortable |
|
96 | - * |
|
97 | - * @param array $columns |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - public function register_sortable_columns( $columns = array() ) { |
|
101 | - $columns['wetu_ref'] = 'price_per_month'; |
|
102 | - return $columns; |
|
103 | - } |
|
94 | + /** |
|
95 | + * Register the columns that will be sortable |
|
96 | + * |
|
97 | + * @param array $columns |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + public function register_sortable_columns( $columns = array() ) { |
|
101 | + $columns['wetu_ref'] = 'price_per_month'; |
|
102 | + return $columns; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Sort the columns |
|
107 | - * |
|
108 | - * @param object $query WP_Query() |
|
109 | - * @return void |
|
110 | - */ |
|
111 | - public function columns_posts_orderby( $query ) { |
|
112 | - if ( ! is_admin() || ! $query->is_main_query() ) { |
|
113 | - return; |
|
114 | - } |
|
115 | - if ( 'wetu_ref' === $query->get( 'orderby' ) ) { |
|
116 | - $query->set( 'orderby', 'meta_value' ); |
|
117 | - $query->set( 'meta_key', 'lsx_wetu_reference' ); |
|
118 | - } |
|
119 | - /* |
|
105 | + /** |
|
106 | + * Sort the columns |
|
107 | + * |
|
108 | + * @param object $query WP_Query() |
|
109 | + * @return void |
|
110 | + */ |
|
111 | + public function columns_posts_orderby( $query ) { |
|
112 | + if ( ! is_admin() || ! $query->is_main_query() ) { |
|
113 | + return; |
|
114 | + } |
|
115 | + if ( 'wetu_ref' === $query->get( 'orderby' ) ) { |
|
116 | + $query->set( 'orderby', 'meta_value' ); |
|
117 | + $query->set( 'meta_key', 'lsx_wetu_reference' ); |
|
118 | + } |
|
119 | + /* |
|
120 | 120 | if ( $query->is_search() && 'tour' === $query->get( 'post_type' ) ) { |
121 | 121 | $meta_query = array( |
122 | 122 | 'relation' => 'OR', |
@@ -128,5 +128,5 @@ discard block |
||
128 | 128 | ); |
129 | 129 | $query->set( 'meta_query', $meta_query ); |
130 | 130 | }*/ |
131 | - } |
|
131 | + } |
|
132 | 132 | } |
@@ -13,465 +13,465 @@ discard block |
||
13 | 13 | */ |
14 | 14 | class LSX_WETU_Importer { |
15 | 15 | |
16 | - /** |
|
17 | - * Holds class instance |
|
18 | - * |
|
19 | - * @since 1.0.0 |
|
20 | - * |
|
21 | - * @var object|Module_Template |
|
22 | - */ |
|
23 | - protected static $instance = null; |
|
24 | - |
|
25 | - /** |
|
26 | - * The slug for this plugin |
|
27 | - * |
|
28 | - * @since 0.0.1 |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - public $plugin_slug = 'lsx-wetu-importer'; |
|
33 | - |
|
34 | - /** |
|
35 | - * The url to list items from WETU |
|
36 | - * |
|
37 | - * @since 0.0.1 |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - public $tab_slug = 'default'; |
|
42 | - |
|
43 | - /** |
|
44 | - * The options for the plugin |
|
45 | - * |
|
46 | - * @since 0.0.1 |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - public $options = false; |
|
51 | - |
|
52 | - /** |
|
53 | - * The url to import images from WETU |
|
54 | - * |
|
55 | - * @since 0.0.1 |
|
56 | - * |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - public $import_scaling_url = false; |
|
60 | - |
|
61 | - /** |
|
62 | - * scale the images on import or not |
|
63 | - * |
|
64 | - * @since 0.0.1 |
|
65 | - * |
|
66 | - * @var boolean |
|
67 | - */ |
|
68 | - public $scale_images = false; |
|
69 | - |
|
70 | - /** |
|
71 | - * The WETU API Key |
|
72 | - */ |
|
73 | - public $api_key = false; |
|
74 | - |
|
75 | - /** |
|
76 | - * The post types this works with. |
|
77 | - */ |
|
78 | - public $post_types = array(); |
|
79 | - |
|
80 | - /** |
|
81 | - * The previously attached images |
|
82 | - * |
|
83 | - * @var array() |
|
84 | - */ |
|
85 | - public $found_attachments = array(); |
|
86 | - |
|
87 | - /** |
|
88 | - * The gallery ids for the found attachements |
|
89 | - * |
|
90 | - * @var array() |
|
91 | - */ |
|
92 | - public $gallery_meta = array(); |
|
93 | - |
|
94 | - /** |
|
95 | - * The post ids to clean up (make sure the connected items are only singular) |
|
96 | - * |
|
97 | - * @var array() |
|
98 | - */ |
|
99 | - public $cleanup_posts = array(); |
|
100 | - |
|
101 | - /** |
|
102 | - * A post => parent relationship array. |
|
103 | - * |
|
104 | - * @var array() |
|
105 | - */ |
|
106 | - public $relation_meta = array(); |
|
107 | - |
|
108 | - /** |
|
109 | - * Image Limit |
|
110 | - * |
|
111 | - * @var int |
|
112 | - */ |
|
113 | - public $image_limit = false; |
|
114 | - |
|
115 | - /** |
|
116 | - * the featured image id |
|
117 | - * |
|
118 | - * @var int |
|
119 | - */ |
|
120 | - public $featured_image = false; |
|
121 | - |
|
122 | - /** |
|
123 | - * the banner image |
|
124 | - * |
|
125 | - * @var int |
|
126 | - */ |
|
127 | - public $banner_image = false; |
|
128 | - |
|
129 | - /** |
|
130 | - * Holds the current import to display |
|
131 | - * |
|
132 | - * @var int |
|
133 | - */ |
|
134 | - public $current_importer = false; |
|
135 | - |
|
136 | - /** |
|
137 | - * if you ran a tour import then you will have accommodation and destination queued to sync as well. |
|
138 | - * |
|
139 | - * @var int |
|
140 | - */ |
|
141 | - public $queued_imports = array(); |
|
142 | - |
|
143 | - /** |
|
144 | - * An Array to hold the items to queue |
|
145 | - * |
|
146 | - * @var int |
|
147 | - */ |
|
148 | - public $import_queue = array(); |
|
149 | - |
|
150 | - /** |
|
151 | - * Holds the current post that is being imported. Use to check the content and excerpt. |
|
152 | - * |
|
153 | - * @var int |
|
154 | - */ |
|
155 | - public $current_post = false; |
|
156 | - |
|
157 | - /** |
|
158 | - * Holds the accommodation settings |
|
159 | - * |
|
160 | - * @var int |
|
161 | - */ |
|
162 | - public $accommodation_settings = false; |
|
163 | - |
|
164 | - /** |
|
165 | - * Holds the tour settings |
|
166 | - * |
|
167 | - * @var int |
|
168 | - */ |
|
169 | - public $tour_settings = false; |
|
170 | - |
|
171 | - /** |
|
172 | - * Holds the destination settings |
|
173 | - * |
|
174 | - * @var int |
|
175 | - */ |
|
176 | - public $destination_settings = false; |
|
177 | - |
|
178 | - /** |
|
179 | - * Hold the flag to let you know if the debug is enabled or not. |
|
180 | - * |
|
181 | - * @var int |
|
182 | - */ |
|
183 | - public $debug_enabled = false; |
|
184 | - |
|
185 | - /** |
|
186 | - * Hold the post columns object |
|
187 | - * |
|
188 | - * @var object LSX_WETU_Importer_Post_Columns() |
|
189 | - */ |
|
190 | - public $post_columns = false; |
|
191 | - |
|
192 | - /** |
|
193 | - * Initialize the plugin by setting localization, filters, and administration functions. |
|
194 | - * |
|
195 | - * @since 1.0.0 |
|
196 | - * |
|
197 | - * @access private |
|
198 | - */ |
|
199 | - public function __construct() { |
|
200 | - add_action( 'admin_init', array( $this, 'compatible_version_check' ) ); |
|
201 | - require_once LSX_WETU_IMPORTER_PATH . 'includes/helpers.php'; |
|
202 | - |
|
203 | - // Don't run anything else in the plugin, if we're on an incompatible PHP version. |
|
204 | - if ( ! self::compatible_version() ) { |
|
205 | - return; |
|
206 | - } |
|
207 | - |
|
208 | - $this->set_variables(); |
|
209 | - |
|
210 | - add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); |
|
211 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 11 ); |
|
212 | - add_action( 'admin_menu', array( $this, 'register_importer_page' ), 20 ); |
|
213 | - |
|
214 | - require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-welcome.php'; |
|
215 | - require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-accommodation.php'; |
|
216 | - require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-destination.php'; |
|
217 | - require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-tours.php'; |
|
218 | - require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-settings.php'; |
|
219 | - require_once LSX_WETU_IMPORTER_PATH . 'classes/class-cron.php'; |
|
220 | - |
|
221 | - if ( isset( $this->options ) && isset( $this->options['enable_tour_ref_column'] ) && '' !== $this->options['enable_tour_ref_column'] ) { |
|
222 | - require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-post-columns.php'; |
|
223 | - $this->post_columns = LSX_WETU_Importer_Post_Columns::get_instance(); |
|
224 | - } |
|
225 | - |
|
226 | - add_action( 'init', array( $this, 'load_class' ) ); |
|
227 | - |
|
228 | - if ( 'default' !== $this->tab_slug ) { |
|
229 | - add_action( 'wp_ajax_lsx_tour_importer', array( $this, 'process_ajax_search' ) ); |
|
230 | - add_action( 'wp_ajax_nopriv_lsx_tour_importer', array( $this, 'process_ajax_search' ) ); |
|
231 | - |
|
232 | - add_action( 'wp_ajax_lsx_import_items', array( $this, 'process_ajax_import' ) ); |
|
233 | - add_action( 'wp_ajax_nopriv_lsx_import_items', array( $this, 'process_ajax_import' ) ); |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Load the plugin text domain for translation. |
|
239 | - * |
|
240 | - * @since 1.0.0 |
|
241 | - */ |
|
242 | - public function load_plugin_textdomain() { |
|
243 | - load_plugin_textdomain( 'lsx-wetu-importer', false, basename( LSX_WETU_IMPORTER_PATH ) . '/languages' ); |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Sets the variables used throughout the plugin. |
|
248 | - */ |
|
249 | - public function set_variables() { |
|
250 | - $this->post_types = array( 'accommodation', 'destination', 'tour' ); |
|
251 | - $options = lsx_wetu_get_options(); |
|
252 | - |
|
253 | - // Set the options. |
|
254 | - $this->options = $options; |
|
255 | - |
|
256 | - $temp_options = get_option( '_lsx-to_settings', false ); |
|
257 | - if ( false !== $temp_options ) { |
|
258 | - $this->accommodation_settings = $temp_options['accommodation']; |
|
259 | - $this->tour_settings = $temp_options['tour']; |
|
260 | - $this->destination_settings = $temp_options['destination']; |
|
261 | - } |
|
262 | - |
|
263 | - $this->api_key = false; |
|
264 | - |
|
265 | - if ( ! defined( 'WETU_API_KEY' ) ) { |
|
266 | - if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) { |
|
267 | - $this->api_key = $options['api_key']; |
|
268 | - } |
|
269 | - } else { |
|
270 | - $this->api_key = WETU_API_KEY; |
|
271 | - } |
|
272 | - |
|
273 | - // Set the tab slug. |
|
274 | - // @codingStandardsIgnoreLine |
|
275 | - if ( isset( $_GET['tab'] ) || ( defined( 'DOING_AJAX' ) && isset( $_POST['type'] ) ) ) { |
|
276 | - if ( isset( $_GET['tab'] ) ) { |
|
277 | - $this->tab_slug = sanitize_text_field( $_GET['tab'] ); |
|
278 | - } else { |
|
279 | - // @codingStandardsIgnoreLine |
|
280 | - $this->tab_slug = sanitize_text_field( $_POST['type'] ); |
|
281 | - } |
|
282 | - } |
|
283 | - |
|
284 | - // If any tours were queued. |
|
285 | - $this->queued_imports = get_option( 'lsx_wetu_importer_que', array() ); |
|
286 | - |
|
287 | - // Set the scaling options. |
|
288 | - if ( isset( $this->options ) && isset( $this->options['image_scaling'] ) ) { |
|
289 | - $this->scale_images = true; |
|
290 | - |
|
291 | - $width = '1024'; |
|
292 | - if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) { |
|
293 | - $width = $this->options['width']; |
|
294 | - } |
|
295 | - |
|
296 | - $height = '768'; |
|
297 | - if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) { |
|
298 | - $height = $this->options['height']; |
|
299 | - } |
|
300 | - |
|
301 | - $cropping = 'w'; |
|
302 | - if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) { |
|
303 | - $cropping = $this->options['cropping']; |
|
304 | - } |
|
305 | - |
|
306 | - $this->image_scaling_url = 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/'; |
|
307 | - } |
|
308 | - |
|
309 | - if ( isset( $this->options ) && isset( $this->options['image_limit'] ) && '' !== $this->options['image_limit'] ) { |
|
310 | - $this->image_limit = $this->options['image_limit']; |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - // COMPATABILITY FUNCTIONS. |
|
315 | - |
|
316 | - /** |
|
317 | - * On plugin activation |
|
318 | - * |
|
319 | - * @since 1.0.0 |
|
320 | - */ |
|
321 | - public static function register_activation_hook() { |
|
322 | - self::compatible_version_check_on_activation(); |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Check if the PHP version is compatible. |
|
327 | - * |
|
328 | - * @since 1.0.0 |
|
329 | - */ |
|
330 | - public static function compatible_version() { |
|
331 | - if ( version_compare( PHP_VERSION, '5.6', '<' ) ) { |
|
332 | - return false; |
|
333 | - } |
|
334 | - |
|
335 | - return true; |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * The backup sanity check, in case the plugin is activated in a weird way, |
|
340 | - * or the versions change after activation. |
|
341 | - * |
|
342 | - * @since 1.0.0 |
|
343 | - */ |
|
344 | - public function compatible_version_check() { |
|
345 | - if ( ! self::compatible_version() ) { |
|
346 | - if ( is_plugin_active( plugin_basename( LSX_WETU_IMPORTER_CORE ) ) ) { |
|
347 | - deactivate_plugins( plugin_basename( LSX_WETU_IMPORTER_CORE ) ); |
|
348 | - add_action( 'admin_notices', array( $this, 'compatible_version_notice' ) ); |
|
349 | - |
|
350 | - if ( isset( $_GET['activate'] ) ) { |
|
351 | - unset( $_GET['activate'] ); |
|
352 | - } |
|
353 | - } |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Display the notice related with the older version from PHP. |
|
359 | - * |
|
360 | - * @since 1.0.0 |
|
361 | - */ |
|
362 | - public function compatible_version_notice() { |
|
363 | - $class = 'notice notice-error'; |
|
364 | - $message = esc_html__( 'LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer' ); |
|
365 | - printf( '<div class="%1$s"><p>%2$s</p></div>', esc_html( $class ), esc_html( $message ) ); |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * The primary sanity check, automatically disable the plugin on activation if it doesn't |
|
370 | - * meet minimum requirements. |
|
371 | - * |
|
372 | - * @since 1.0.0 |
|
373 | - */ |
|
374 | - public static function compatible_version_check_on_activation() { |
|
375 | - if ( ! self::compatible_version() ) { |
|
376 | - deactivate_plugins( plugin_basename( LSX_WETU_IMPORTER_CORE ) ); |
|
377 | - wp_die( esc_html__( 'LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer' ) ); |
|
378 | - } |
|
379 | - } |
|
380 | - |
|
381 | - // DISPLAY FUNCTIONS. |
|
382 | - |
|
383 | - /** |
|
384 | - * Load the importer class you want to use |
|
385 | - */ |
|
386 | - public function load_class() { |
|
387 | - switch ( $this->tab_slug ) { |
|
388 | - case 'accommodation': |
|
389 | - $this->current_importer = new LSX_WETU_Importer_Accommodation(); |
|
390 | - break; |
|
391 | - |
|
392 | - case 'destination': |
|
393 | - $this->current_importer = new LSX_WETU_Importer_Destination(); |
|
394 | - break; |
|
395 | - |
|
396 | - case 'tour': |
|
397 | - $this->current_importer = new LSX_WETU_Importer_Tours(); |
|
398 | - break; |
|
399 | - |
|
400 | - case 'settings': |
|
401 | - $this->current_importer = LSX_WETU_Importer_Settings::get_instance(); |
|
402 | - break; |
|
403 | - |
|
404 | - default: |
|
405 | - $this->current_importer = LSX_WETU_Importer_Welcome::get_instance(); |
|
406 | - break; |
|
407 | - } |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Registers the admin page which will house the importer form. |
|
412 | - */ |
|
413 | - public function register_importer_page() { |
|
414 | - add_submenu_page( 'tour-operator', esc_html__( 'Importer', 'tour-operator' ), esc_html__( 'Importer', 'tour-operator' ), 'manage_options', 'lsx-wetu-importer', array( $this, 'display_page' ) ); |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * Enqueue the JS needed to contact wetu and return your result. |
|
419 | - */ |
|
420 | - public function admin_scripts() { |
|
421 | - if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) { |
|
422 | - $min = ''; |
|
423 | - } else { |
|
424 | - $min = '.min'; |
|
425 | - } |
|
426 | - |
|
427 | - $min = ''; |
|
428 | - |
|
429 | - if ( is_admin() && isset( $_GET['page'] ) && $this->plugin_slug === $_GET['page'] ) { |
|
430 | - |
|
431 | - // wp_enqueue_style( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/css/datatables' . $min . '.css', LSX_WETU_IMPORTER_VER, true ); |
|
432 | - wp_enqueue_style( 'lsx-wetu-importer-style', LSX_WETU_IMPORTER_URL . 'assets/css/lsx-wetu-importer.css', LSX_WETU_IMPORTER_VER, true ); |
|
433 | - |
|
434 | - if ( isset( $_GET['tab'] ) ) { |
|
435 | - wp_enqueue_script( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/js/datatables' . $min . '.js', array( 'jquery' ), LSX_WETU_IMPORTER_VER, true ); |
|
436 | - wp_enqueue_script( 'lsx-wetu-importers-script', LSX_WETU_IMPORTER_URL . 'assets/js/lsx-wetu-importer' . $min . '.js', array( 'jquery', 'datatables' ), LSX_WETU_IMPORTER_VER, true ); |
|
437 | - |
|
438 | - wp_localize_script( |
|
439 | - 'lsx-wetu-importers-script', |
|
440 | - 'lsx_tour_importer_params', |
|
441 | - array( |
|
442 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
443 | - 'ajax_nonce' => wp_create_nonce( 'lsx_wetu_ajax_action' ), |
|
444 | - ) |
|
445 | - ); |
|
446 | - } |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * Display the importer administration screen |
|
452 | - */ |
|
453 | - public function display_page() { |
|
454 | - ?> |
|
16 | + /** |
|
17 | + * Holds class instance |
|
18 | + * |
|
19 | + * @since 1.0.0 |
|
20 | + * |
|
21 | + * @var object|Module_Template |
|
22 | + */ |
|
23 | + protected static $instance = null; |
|
24 | + |
|
25 | + /** |
|
26 | + * The slug for this plugin |
|
27 | + * |
|
28 | + * @since 0.0.1 |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + public $plugin_slug = 'lsx-wetu-importer'; |
|
33 | + |
|
34 | + /** |
|
35 | + * The url to list items from WETU |
|
36 | + * |
|
37 | + * @since 0.0.1 |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + public $tab_slug = 'default'; |
|
42 | + |
|
43 | + /** |
|
44 | + * The options for the plugin |
|
45 | + * |
|
46 | + * @since 0.0.1 |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + public $options = false; |
|
51 | + |
|
52 | + /** |
|
53 | + * The url to import images from WETU |
|
54 | + * |
|
55 | + * @since 0.0.1 |
|
56 | + * |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + public $import_scaling_url = false; |
|
60 | + |
|
61 | + /** |
|
62 | + * scale the images on import or not |
|
63 | + * |
|
64 | + * @since 0.0.1 |
|
65 | + * |
|
66 | + * @var boolean |
|
67 | + */ |
|
68 | + public $scale_images = false; |
|
69 | + |
|
70 | + /** |
|
71 | + * The WETU API Key |
|
72 | + */ |
|
73 | + public $api_key = false; |
|
74 | + |
|
75 | + /** |
|
76 | + * The post types this works with. |
|
77 | + */ |
|
78 | + public $post_types = array(); |
|
79 | + |
|
80 | + /** |
|
81 | + * The previously attached images |
|
82 | + * |
|
83 | + * @var array() |
|
84 | + */ |
|
85 | + public $found_attachments = array(); |
|
86 | + |
|
87 | + /** |
|
88 | + * The gallery ids for the found attachements |
|
89 | + * |
|
90 | + * @var array() |
|
91 | + */ |
|
92 | + public $gallery_meta = array(); |
|
93 | + |
|
94 | + /** |
|
95 | + * The post ids to clean up (make sure the connected items are only singular) |
|
96 | + * |
|
97 | + * @var array() |
|
98 | + */ |
|
99 | + public $cleanup_posts = array(); |
|
100 | + |
|
101 | + /** |
|
102 | + * A post => parent relationship array. |
|
103 | + * |
|
104 | + * @var array() |
|
105 | + */ |
|
106 | + public $relation_meta = array(); |
|
107 | + |
|
108 | + /** |
|
109 | + * Image Limit |
|
110 | + * |
|
111 | + * @var int |
|
112 | + */ |
|
113 | + public $image_limit = false; |
|
114 | + |
|
115 | + /** |
|
116 | + * the featured image id |
|
117 | + * |
|
118 | + * @var int |
|
119 | + */ |
|
120 | + public $featured_image = false; |
|
121 | + |
|
122 | + /** |
|
123 | + * the banner image |
|
124 | + * |
|
125 | + * @var int |
|
126 | + */ |
|
127 | + public $banner_image = false; |
|
128 | + |
|
129 | + /** |
|
130 | + * Holds the current import to display |
|
131 | + * |
|
132 | + * @var int |
|
133 | + */ |
|
134 | + public $current_importer = false; |
|
135 | + |
|
136 | + /** |
|
137 | + * if you ran a tour import then you will have accommodation and destination queued to sync as well. |
|
138 | + * |
|
139 | + * @var int |
|
140 | + */ |
|
141 | + public $queued_imports = array(); |
|
142 | + |
|
143 | + /** |
|
144 | + * An Array to hold the items to queue |
|
145 | + * |
|
146 | + * @var int |
|
147 | + */ |
|
148 | + public $import_queue = array(); |
|
149 | + |
|
150 | + /** |
|
151 | + * Holds the current post that is being imported. Use to check the content and excerpt. |
|
152 | + * |
|
153 | + * @var int |
|
154 | + */ |
|
155 | + public $current_post = false; |
|
156 | + |
|
157 | + /** |
|
158 | + * Holds the accommodation settings |
|
159 | + * |
|
160 | + * @var int |
|
161 | + */ |
|
162 | + public $accommodation_settings = false; |
|
163 | + |
|
164 | + /** |
|
165 | + * Holds the tour settings |
|
166 | + * |
|
167 | + * @var int |
|
168 | + */ |
|
169 | + public $tour_settings = false; |
|
170 | + |
|
171 | + /** |
|
172 | + * Holds the destination settings |
|
173 | + * |
|
174 | + * @var int |
|
175 | + */ |
|
176 | + public $destination_settings = false; |
|
177 | + |
|
178 | + /** |
|
179 | + * Hold the flag to let you know if the debug is enabled or not. |
|
180 | + * |
|
181 | + * @var int |
|
182 | + */ |
|
183 | + public $debug_enabled = false; |
|
184 | + |
|
185 | + /** |
|
186 | + * Hold the post columns object |
|
187 | + * |
|
188 | + * @var object LSX_WETU_Importer_Post_Columns() |
|
189 | + */ |
|
190 | + public $post_columns = false; |
|
191 | + |
|
192 | + /** |
|
193 | + * Initialize the plugin by setting localization, filters, and administration functions. |
|
194 | + * |
|
195 | + * @since 1.0.0 |
|
196 | + * |
|
197 | + * @access private |
|
198 | + */ |
|
199 | + public function __construct() { |
|
200 | + add_action( 'admin_init', array( $this, 'compatible_version_check' ) ); |
|
201 | + require_once LSX_WETU_IMPORTER_PATH . 'includes/helpers.php'; |
|
202 | + |
|
203 | + // Don't run anything else in the plugin, if we're on an incompatible PHP version. |
|
204 | + if ( ! self::compatible_version() ) { |
|
205 | + return; |
|
206 | + } |
|
207 | + |
|
208 | + $this->set_variables(); |
|
209 | + |
|
210 | + add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); |
|
211 | + add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 11 ); |
|
212 | + add_action( 'admin_menu', array( $this, 'register_importer_page' ), 20 ); |
|
213 | + |
|
214 | + require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-welcome.php'; |
|
215 | + require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-accommodation.php'; |
|
216 | + require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-destination.php'; |
|
217 | + require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-tours.php'; |
|
218 | + require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-settings.php'; |
|
219 | + require_once LSX_WETU_IMPORTER_PATH . 'classes/class-cron.php'; |
|
220 | + |
|
221 | + if ( isset( $this->options ) && isset( $this->options['enable_tour_ref_column'] ) && '' !== $this->options['enable_tour_ref_column'] ) { |
|
222 | + require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-post-columns.php'; |
|
223 | + $this->post_columns = LSX_WETU_Importer_Post_Columns::get_instance(); |
|
224 | + } |
|
225 | + |
|
226 | + add_action( 'init', array( $this, 'load_class' ) ); |
|
227 | + |
|
228 | + if ( 'default' !== $this->tab_slug ) { |
|
229 | + add_action( 'wp_ajax_lsx_tour_importer', array( $this, 'process_ajax_search' ) ); |
|
230 | + add_action( 'wp_ajax_nopriv_lsx_tour_importer', array( $this, 'process_ajax_search' ) ); |
|
231 | + |
|
232 | + add_action( 'wp_ajax_lsx_import_items', array( $this, 'process_ajax_import' ) ); |
|
233 | + add_action( 'wp_ajax_nopriv_lsx_import_items', array( $this, 'process_ajax_import' ) ); |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Load the plugin text domain for translation. |
|
239 | + * |
|
240 | + * @since 1.0.0 |
|
241 | + */ |
|
242 | + public function load_plugin_textdomain() { |
|
243 | + load_plugin_textdomain( 'lsx-wetu-importer', false, basename( LSX_WETU_IMPORTER_PATH ) . '/languages' ); |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Sets the variables used throughout the plugin. |
|
248 | + */ |
|
249 | + public function set_variables() { |
|
250 | + $this->post_types = array( 'accommodation', 'destination', 'tour' ); |
|
251 | + $options = lsx_wetu_get_options(); |
|
252 | + |
|
253 | + // Set the options. |
|
254 | + $this->options = $options; |
|
255 | + |
|
256 | + $temp_options = get_option( '_lsx-to_settings', false ); |
|
257 | + if ( false !== $temp_options ) { |
|
258 | + $this->accommodation_settings = $temp_options['accommodation']; |
|
259 | + $this->tour_settings = $temp_options['tour']; |
|
260 | + $this->destination_settings = $temp_options['destination']; |
|
261 | + } |
|
262 | + |
|
263 | + $this->api_key = false; |
|
264 | + |
|
265 | + if ( ! defined( 'WETU_API_KEY' ) ) { |
|
266 | + if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) { |
|
267 | + $this->api_key = $options['api_key']; |
|
268 | + } |
|
269 | + } else { |
|
270 | + $this->api_key = WETU_API_KEY; |
|
271 | + } |
|
272 | + |
|
273 | + // Set the tab slug. |
|
274 | + // @codingStandardsIgnoreLine |
|
275 | + if ( isset( $_GET['tab'] ) || ( defined( 'DOING_AJAX' ) && isset( $_POST['type'] ) ) ) { |
|
276 | + if ( isset( $_GET['tab'] ) ) { |
|
277 | + $this->tab_slug = sanitize_text_field( $_GET['tab'] ); |
|
278 | + } else { |
|
279 | + // @codingStandardsIgnoreLine |
|
280 | + $this->tab_slug = sanitize_text_field( $_POST['type'] ); |
|
281 | + } |
|
282 | + } |
|
283 | + |
|
284 | + // If any tours were queued. |
|
285 | + $this->queued_imports = get_option( 'lsx_wetu_importer_que', array() ); |
|
286 | + |
|
287 | + // Set the scaling options. |
|
288 | + if ( isset( $this->options ) && isset( $this->options['image_scaling'] ) ) { |
|
289 | + $this->scale_images = true; |
|
290 | + |
|
291 | + $width = '1024'; |
|
292 | + if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) { |
|
293 | + $width = $this->options['width']; |
|
294 | + } |
|
295 | + |
|
296 | + $height = '768'; |
|
297 | + if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) { |
|
298 | + $height = $this->options['height']; |
|
299 | + } |
|
300 | + |
|
301 | + $cropping = 'w'; |
|
302 | + if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) { |
|
303 | + $cropping = $this->options['cropping']; |
|
304 | + } |
|
305 | + |
|
306 | + $this->image_scaling_url = 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/'; |
|
307 | + } |
|
308 | + |
|
309 | + if ( isset( $this->options ) && isset( $this->options['image_limit'] ) && '' !== $this->options['image_limit'] ) { |
|
310 | + $this->image_limit = $this->options['image_limit']; |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + // COMPATABILITY FUNCTIONS. |
|
315 | + |
|
316 | + /** |
|
317 | + * On plugin activation |
|
318 | + * |
|
319 | + * @since 1.0.0 |
|
320 | + */ |
|
321 | + public static function register_activation_hook() { |
|
322 | + self::compatible_version_check_on_activation(); |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Check if the PHP version is compatible. |
|
327 | + * |
|
328 | + * @since 1.0.0 |
|
329 | + */ |
|
330 | + public static function compatible_version() { |
|
331 | + if ( version_compare( PHP_VERSION, '5.6', '<' ) ) { |
|
332 | + return false; |
|
333 | + } |
|
334 | + |
|
335 | + return true; |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * The backup sanity check, in case the plugin is activated in a weird way, |
|
340 | + * or the versions change after activation. |
|
341 | + * |
|
342 | + * @since 1.0.0 |
|
343 | + */ |
|
344 | + public function compatible_version_check() { |
|
345 | + if ( ! self::compatible_version() ) { |
|
346 | + if ( is_plugin_active( plugin_basename( LSX_WETU_IMPORTER_CORE ) ) ) { |
|
347 | + deactivate_plugins( plugin_basename( LSX_WETU_IMPORTER_CORE ) ); |
|
348 | + add_action( 'admin_notices', array( $this, 'compatible_version_notice' ) ); |
|
349 | + |
|
350 | + if ( isset( $_GET['activate'] ) ) { |
|
351 | + unset( $_GET['activate'] ); |
|
352 | + } |
|
353 | + } |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Display the notice related with the older version from PHP. |
|
359 | + * |
|
360 | + * @since 1.0.0 |
|
361 | + */ |
|
362 | + public function compatible_version_notice() { |
|
363 | + $class = 'notice notice-error'; |
|
364 | + $message = esc_html__( 'LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer' ); |
|
365 | + printf( '<div class="%1$s"><p>%2$s</p></div>', esc_html( $class ), esc_html( $message ) ); |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * The primary sanity check, automatically disable the plugin on activation if it doesn't |
|
370 | + * meet minimum requirements. |
|
371 | + * |
|
372 | + * @since 1.0.0 |
|
373 | + */ |
|
374 | + public static function compatible_version_check_on_activation() { |
|
375 | + if ( ! self::compatible_version() ) { |
|
376 | + deactivate_plugins( plugin_basename( LSX_WETU_IMPORTER_CORE ) ); |
|
377 | + wp_die( esc_html__( 'LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer' ) ); |
|
378 | + } |
|
379 | + } |
|
380 | + |
|
381 | + // DISPLAY FUNCTIONS. |
|
382 | + |
|
383 | + /** |
|
384 | + * Load the importer class you want to use |
|
385 | + */ |
|
386 | + public function load_class() { |
|
387 | + switch ( $this->tab_slug ) { |
|
388 | + case 'accommodation': |
|
389 | + $this->current_importer = new LSX_WETU_Importer_Accommodation(); |
|
390 | + break; |
|
391 | + |
|
392 | + case 'destination': |
|
393 | + $this->current_importer = new LSX_WETU_Importer_Destination(); |
|
394 | + break; |
|
395 | + |
|
396 | + case 'tour': |
|
397 | + $this->current_importer = new LSX_WETU_Importer_Tours(); |
|
398 | + break; |
|
399 | + |
|
400 | + case 'settings': |
|
401 | + $this->current_importer = LSX_WETU_Importer_Settings::get_instance(); |
|
402 | + break; |
|
403 | + |
|
404 | + default: |
|
405 | + $this->current_importer = LSX_WETU_Importer_Welcome::get_instance(); |
|
406 | + break; |
|
407 | + } |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Registers the admin page which will house the importer form. |
|
412 | + */ |
|
413 | + public function register_importer_page() { |
|
414 | + add_submenu_page( 'tour-operator', esc_html__( 'Importer', 'tour-operator' ), esc_html__( 'Importer', 'tour-operator' ), 'manage_options', 'lsx-wetu-importer', array( $this, 'display_page' ) ); |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * Enqueue the JS needed to contact wetu and return your result. |
|
419 | + */ |
|
420 | + public function admin_scripts() { |
|
421 | + if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) { |
|
422 | + $min = ''; |
|
423 | + } else { |
|
424 | + $min = '.min'; |
|
425 | + } |
|
426 | + |
|
427 | + $min = ''; |
|
428 | + |
|
429 | + if ( is_admin() && isset( $_GET['page'] ) && $this->plugin_slug === $_GET['page'] ) { |
|
430 | + |
|
431 | + // wp_enqueue_style( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/css/datatables' . $min . '.css', LSX_WETU_IMPORTER_VER, true ); |
|
432 | + wp_enqueue_style( 'lsx-wetu-importer-style', LSX_WETU_IMPORTER_URL . 'assets/css/lsx-wetu-importer.css', LSX_WETU_IMPORTER_VER, true ); |
|
433 | + |
|
434 | + if ( isset( $_GET['tab'] ) ) { |
|
435 | + wp_enqueue_script( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/js/datatables' . $min . '.js', array( 'jquery' ), LSX_WETU_IMPORTER_VER, true ); |
|
436 | + wp_enqueue_script( 'lsx-wetu-importers-script', LSX_WETU_IMPORTER_URL . 'assets/js/lsx-wetu-importer' . $min . '.js', array( 'jquery', 'datatables' ), LSX_WETU_IMPORTER_VER, true ); |
|
437 | + |
|
438 | + wp_localize_script( |
|
439 | + 'lsx-wetu-importers-script', |
|
440 | + 'lsx_tour_importer_params', |
|
441 | + array( |
|
442 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
443 | + 'ajax_nonce' => wp_create_nonce( 'lsx_wetu_ajax_action' ), |
|
444 | + ) |
|
445 | + ); |
|
446 | + } |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * Display the importer administration screen |
|
452 | + */ |
|
453 | + public function display_page() { |
|
454 | + ?> |
|
455 | 455 | <div class="wrap"> |
456 | 456 | <?php |
457 | - $this->navigation( $this->tab_slug ); |
|
458 | - if ( 'default' !== $this->tab_slug && 'settings' !== $this->tab_slug ) { |
|
459 | - $this->wetu_status(); |
|
460 | - $this->post_status_navigation(); |
|
461 | - } |
|
462 | - $this->current_importer->display_page(); |
|
463 | - ?> |
|
457 | + $this->navigation( $this->tab_slug ); |
|
458 | + if ( 'default' !== $this->tab_slug && 'settings' !== $this->tab_slug ) { |
|
459 | + $this->wetu_status(); |
|
460 | + $this->post_status_navigation(); |
|
461 | + } |
|
462 | + $this->current_importer->display_page(); |
|
463 | + ?> |
|
464 | 464 | </div> |
465 | 465 | <?php |
466 | - } |
|
467 | - |
|
468 | - /** |
|
469 | - * Outputs the post status navigation |
|
470 | - * |
|
471 | - * @return void |
|
472 | - */ |
|
473 | - public function post_status_navigation() { |
|
474 | - ?> |
|
466 | + } |
|
467 | + |
|
468 | + /** |
|
469 | + * Outputs the post status navigation |
|
470 | + * |
|
471 | + * @return void |
|
472 | + */ |
|
473 | + public function post_status_navigation() { |
|
474 | + ?> |
|
475 | 475 | <ul class="subsubsub"> |
476 | 476 | <li class="searchform"><a class="current" href="#search"><?php esc_attr_e( 'Search', 'lsx-wetu-importer' ); ?></a> | </li> |
477 | 477 | <li class="publish"><a href="#publish"><?php esc_attr_e( 'Published', 'lsx-wetu-importer' ); ?> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_post_count( $this->tab_slug, 'publish ' ) ); ?>)</span></a> | </li> |
@@ -486,13 +486,13 @@ discard block |
||
486 | 486 | </ul> |
487 | 487 | <a class="documentation" target="_blank"href="https://tour-operator.lsdev.biz/documentation/extension/wetu-importer/"><?php esc_attr_e( 'Documentation', 'lsx-wetu-importer' ); ?></a> |
488 | 488 | <?php |
489 | - } |
|
489 | + } |
|
490 | 490 | |
491 | - /** |
|
492 | - * Search Form |
|
493 | - */ |
|
494 | - public function search_form() { |
|
495 | - ?> |
|
491 | + /** |
|
492 | + * Search Form |
|
493 | + */ |
|
494 | + public function search_form() { |
|
495 | + ?> |
|
496 | 496 | <form class="ajax-form" id="<?php echo esc_attr( $this->plugin_slug ); ?>-search-form" method="get" action="tools.php" data-type="<?php echo esc_attr( $this->tab_slug ); ?>"> |
497 | 497 | <input type="hidden" name="page" value="<?php echo esc_attr( $this->tab_slug ); ?>" /> |
498 | 498 | |
@@ -518,13 +518,13 @@ discard block |
||
518 | 518 | <a class="button advanced-search-toggle" href="#"><?php esc_html_e( 'Bulk Search', 'lsx-wetu-importer' ); ?></a> |
519 | 519 | </form> |
520 | 520 | <?php |
521 | - } |
|
521 | + } |
|
522 | 522 | |
523 | - /** |
|
524 | - * The header of the item list |
|
525 | - */ |
|
526 | - public function table_header() { |
|
527 | - ?> |
|
523 | + /** |
|
524 | + * The header of the item list |
|
525 | + */ |
|
526 | + public function table_header() { |
|
527 | + ?> |
|
528 | 528 | <thead> |
529 | 529 | <tr> |
530 | 530 | <th style="" class="manage-column column-cb check-column no-sort" id="cb" scope="col"> |
@@ -538,13 +538,13 @@ discard block |
||
538 | 538 | </tr> |
539 | 539 | </thead> |
540 | 540 | <?php |
541 | - } |
|
541 | + } |
|
542 | 542 | |
543 | - /** |
|
544 | - * The footer of the item list |
|
545 | - */ |
|
546 | - public function table_footer() { |
|
547 | - ?> |
|
543 | + /** |
|
544 | + * The footer of the item list |
|
545 | + */ |
|
546 | + public function table_footer() { |
|
547 | + ?> |
|
548 | 548 | <tfoot> |
549 | 549 | <tr> |
550 | 550 | <th style="" class="manage-column column-cb check-column" id="cb" scope="col"> |
@@ -558,724 +558,724 @@ discard block |
||
558 | 558 | </tr> |
559 | 559 | </tfoot> |
560 | 560 | <?php |
561 | - } |
|
562 | - |
|
563 | - /** |
|
564 | - * Displays the importers navigation. |
|
565 | - * |
|
566 | - * @param $tab string |
|
567 | - */ |
|
568 | - public function navigation( $tab = '' ) { |
|
569 | - $post_types = array( |
|
570 | - 'tour' => esc_attr( 'Tours', 'lsx-wetu-importer' ), |
|
571 | - 'accommodation' => esc_attr( 'Accommodation', 'lsx-wetu-importer' ), |
|
572 | - 'destination' => esc_attr( 'Destinations', 'lsx-wetu-importer' ), |
|
573 | - ); |
|
574 | - |
|
575 | - echo wp_kses_post( '<div class="wp-filter">' ); |
|
576 | - echo wp_kses_post( '<ul class="filter-links">' ); |
|
577 | - echo wp_kses_post( '<li><a class="' . $this->itemd( $tab, 'default', 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '">' . esc_attr__( 'Home', 'lsx-wetu-importer' ) . '</a></li>' ); |
|
578 | - |
|
579 | - foreach ( $post_types as $post_type => $label ) { |
|
580 | - echo wp_kses_post( ' | <li><a class="' . $this->itemd( $tab, $post_type, 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '&tab=' . $post_type . '">' . $label . '</a></li>' ); |
|
581 | - } |
|
582 | - |
|
583 | - echo wp_kses_post( ' | <li><a class="' . $this->itemd( $tab, 'settings', 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '&tab=settings">' . esc_attr__( 'Settings', 'lsx-wetu-importer' ) . '</a></li>' ); |
|
584 | - echo wp_kses_post( '</ul> </div>' ); |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Wetu Status Bar. |
|
589 | - */ |
|
590 | - public function wetu_status() { |
|
591 | - $tours = get_transient( 'lsx_ti_tours' ); |
|
592 | - echo '<div class="wetu-status tour-wetu-status"><h3>' . esc_html__( 'Wetu Status', 'lsx-wetu-importer' ) . ' - '; |
|
593 | - |
|
594 | - if ( '' === $tours || false === $tours || isset( $_GET['refresh_tours'] ) ) { |
|
595 | - $result = $this->update_options(); |
|
596 | - if ( true === $result ) { |
|
597 | - echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span>'; |
|
598 | - echo ' - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>'; |
|
599 | - } else { |
|
600 | - echo '<span style="color:red;">' . wp_kses_post( $result ) . '</span>'; |
|
601 | - } |
|
602 | - } else { |
|
603 | - echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span> - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>'; |
|
604 | - } |
|
605 | - echo '</h3>'; |
|
606 | - echo '</div>'; |
|
607 | - } |
|
608 | - |
|
609 | - /** |
|
610 | - * Set_taxonomy with some terms |
|
611 | - */ |
|
612 | - public function team_member_checkboxes( $selected = array() ) { |
|
613 | - if ( post_type_exists( 'team' ) ) { |
|
614 | - ?> |
|
561 | + } |
|
562 | + |
|
563 | + /** |
|
564 | + * Displays the importers navigation. |
|
565 | + * |
|
566 | + * @param $tab string |
|
567 | + */ |
|
568 | + public function navigation( $tab = '' ) { |
|
569 | + $post_types = array( |
|
570 | + 'tour' => esc_attr( 'Tours', 'lsx-wetu-importer' ), |
|
571 | + 'accommodation' => esc_attr( 'Accommodation', 'lsx-wetu-importer' ), |
|
572 | + 'destination' => esc_attr( 'Destinations', 'lsx-wetu-importer' ), |
|
573 | + ); |
|
574 | + |
|
575 | + echo wp_kses_post( '<div class="wp-filter">' ); |
|
576 | + echo wp_kses_post( '<ul class="filter-links">' ); |
|
577 | + echo wp_kses_post( '<li><a class="' . $this->itemd( $tab, 'default', 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '">' . esc_attr__( 'Home', 'lsx-wetu-importer' ) . '</a></li>' ); |
|
578 | + |
|
579 | + foreach ( $post_types as $post_type => $label ) { |
|
580 | + echo wp_kses_post( ' | <li><a class="' . $this->itemd( $tab, $post_type, 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '&tab=' . $post_type . '">' . $label . '</a></li>' ); |
|
581 | + } |
|
582 | + |
|
583 | + echo wp_kses_post( ' | <li><a class="' . $this->itemd( $tab, 'settings', 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '&tab=settings">' . esc_attr__( 'Settings', 'lsx-wetu-importer' ) . '</a></li>' ); |
|
584 | + echo wp_kses_post( '</ul> </div>' ); |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Wetu Status Bar. |
|
589 | + */ |
|
590 | + public function wetu_status() { |
|
591 | + $tours = get_transient( 'lsx_ti_tours' ); |
|
592 | + echo '<div class="wetu-status tour-wetu-status"><h3>' . esc_html__( 'Wetu Status', 'lsx-wetu-importer' ) . ' - '; |
|
593 | + |
|
594 | + if ( '' === $tours || false === $tours || isset( $_GET['refresh_tours'] ) ) { |
|
595 | + $result = $this->update_options(); |
|
596 | + if ( true === $result ) { |
|
597 | + echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span>'; |
|
598 | + echo ' - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>'; |
|
599 | + } else { |
|
600 | + echo '<span style="color:red;">' . wp_kses_post( $result ) . '</span>'; |
|
601 | + } |
|
602 | + } else { |
|
603 | + echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span> - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>'; |
|
604 | + } |
|
605 | + echo '</h3>'; |
|
606 | + echo '</div>'; |
|
607 | + } |
|
608 | + |
|
609 | + /** |
|
610 | + * Set_taxonomy with some terms |
|
611 | + */ |
|
612 | + public function team_member_checkboxes( $selected = array() ) { |
|
613 | + if ( post_type_exists( 'team' ) ) { |
|
614 | + ?> |
|
615 | 615 | <ul> |
616 | 616 | <?php |
617 | - $team_args = array( |
|
618 | - 'post_type' => 'team', |
|
619 | - 'post_status' => 'publish', |
|
620 | - 'nopagin' => true, |
|
621 | - 'fields' => 'ids', |
|
622 | - ); |
|
623 | - |
|
624 | - $team_members = new WP_Query( $team_args ); |
|
625 | - |
|
626 | - if ( $team_members->have_posts() ) { |
|
627 | - foreach ( $team_members->posts as $member ) { |
|
628 | - ?> |
|
617 | + $team_args = array( |
|
618 | + 'post_type' => 'team', |
|
619 | + 'post_status' => 'publish', |
|
620 | + 'nopagin' => true, |
|
621 | + 'fields' => 'ids', |
|
622 | + ); |
|
623 | + |
|
624 | + $team_members = new WP_Query( $team_args ); |
|
625 | + |
|
626 | + if ( $team_members->have_posts() ) { |
|
627 | + foreach ( $team_members->posts as $member ) { |
|
628 | + ?> |
|
629 | 629 | <li><input class="team" <?php $this->checked( $selected, $member ); ?> type="checkbox" value="<?php echo esc_attr( $member ); ?>" /> <?php echo wp_kses_post( get_the_title( $member ) ); ?></li> |
630 | 630 | <?php |
631 | - } |
|
632 | - } else { |
|
633 | - ?> |
|
631 | + } |
|
632 | + } else { |
|
633 | + ?> |
|
634 | 634 | <li><input class="team" type="checkbox" value="0" /> <?php esc_html_e( 'None', 'lsx-wetu-importer' ); ?></li> |
635 | 635 | <?php |
636 | - } |
|
637 | - ?> |
|
636 | + } |
|
637 | + ?> |
|
638 | 638 | </ul> |
639 | 639 | <?php |
640 | - } |
|
641 | - } |
|
642 | - |
|
643 | - |
|
644 | - // GENERAL FUNCTIONS. |
|
645 | - |
|
646 | - /** |
|
647 | - * Checks to see if an item is checked. |
|
648 | - * |
|
649 | - * @param $haystack array|string |
|
650 | - * @param $needle string |
|
651 | - * @param $echo bool |
|
652 | - */ |
|
653 | - public function checked( $haystack = false, $needle = '', $echo = true ) { |
|
654 | - $return = $this->itemd( $haystack, $needle, 'checked', false ); |
|
655 | - |
|
656 | - if ( '' !== $return ) { |
|
657 | - if ( true === $echo ) { |
|
658 | - echo wp_kses_post( $return ); |
|
659 | - } else { |
|
660 | - return $return; |
|
661 | - } |
|
662 | - } |
|
663 | - } |
|
664 | - |
|
665 | - /** |
|
666 | - * Checks to see if an item is checked. |
|
667 | - * |
|
668 | - * @param $haystack array|string |
|
669 | - * @param $needle string |
|
670 | - * @param $echo bool |
|
671 | - */ |
|
672 | - public function selected( $haystack = false, $needle = '', $echo = true ) { |
|
673 | - $return = $this->itemd( $haystack, $needle, 'selected' ); |
|
674 | - |
|
675 | - if ( '' !== $return ) { |
|
676 | - if ( true === $echo ) { |
|
677 | - echo wp_kses_post( $return ); |
|
678 | - } else { |
|
679 | - return $return; |
|
680 | - } |
|
681 | - } |
|
682 | - } |
|
683 | - |
|
684 | - /** |
|
685 | - * Checks to see if an item is selected. If $echo is false, it will return the $type if conditions are true. |
|
686 | - * |
|
687 | - * @param $haystack array|string |
|
688 | - * @param $needle string |
|
689 | - * @param $type string |
|
690 | - * @param $wrap bool |
|
691 | - * @return $html string |
|
692 | - */ |
|
693 | - public function itemd( $haystack = false, $needle = '', $type = '', $wrap = true ) { |
|
694 | - $html = ''; |
|
695 | - |
|
696 | - if ( '' !== $type ) { |
|
697 | - if ( ! is_array( $haystack ) ) { |
|
698 | - $haystack = array( $haystack ); |
|
699 | - } |
|
700 | - if ( in_array( $needle, $haystack ) ) { |
|
701 | - if ( true === $wrap || 'true' === $wrap ) { |
|
702 | - $html = $type . '="' . $type . '"'; |
|
703 | - } else { |
|
704 | - $html = $type; |
|
705 | - } |
|
706 | - } |
|
707 | - } |
|
708 | - |
|
709 | - return $html; |
|
710 | - } |
|
711 | - |
|
712 | - /** |
|
713 | - * Grabs any attachments for the current item |
|
714 | - */ |
|
715 | - public function find_attachments( $id = false ) { |
|
716 | - if ( false !== $id ) { |
|
717 | - if ( empty( $this->found_attachments ) ) { |
|
718 | - $attachments_args = array( |
|
719 | - 'post_parent' => $id, |
|
720 | - 'post_status' => 'inherit', |
|
721 | - 'post_type' => 'attachment', |
|
722 | - 'order' => 'ASC', |
|
723 | - 'nopagin' => 'true', |
|
724 | - 'posts_per_page' => '-1', |
|
725 | - ); |
|
726 | - |
|
727 | - $attachments = new WP_Query( $attachments_args ); |
|
728 | - |
|
729 | - if ( $attachments->have_posts() ) { |
|
730 | - foreach ( $attachments->posts as $attachment ) { |
|
731 | - $this->found_attachments[ $attachment->ID ] = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $attachment->post_title ); |
|
732 | - } |
|
733 | - } |
|
734 | - } |
|
735 | - } |
|
736 | - } |
|
737 | - |
|
738 | - // CUSTOM FIELD FUNCTIONS. |
|
739 | - |
|
740 | - /** |
|
741 | - * Saves the room data |
|
742 | - */ |
|
743 | - public function save_custom_field( $value = false, $meta_key, $id, $decrease = false, $unique = true ) { |
|
744 | - if ( false !== $value ) { |
|
745 | - if ( false !== $decrease ) { |
|
746 | - $value = intval( $value ); |
|
747 | - $value--; |
|
748 | - } |
|
749 | - |
|
750 | - $prev = get_post_meta( $id, $meta_key, true ); |
|
751 | - |
|
752 | - if ( false !== $id && '0' !== $id && false !== $prev && true === $unique ) { |
|
753 | - update_post_meta( $id, $meta_key, $value, $prev ); |
|
754 | - } else { |
|
755 | - add_post_meta( $id, $meta_key, $value, $unique ); |
|
756 | - } |
|
757 | - } |
|
758 | - } |
|
759 | - |
|
760 | - /** |
|
761 | - * Grabs the custom fields, and resaves an array of unique items. |
|
762 | - */ |
|
763 | - public function cleanup_posts() { |
|
764 | - if ( ! empty( $this->cleanup_posts ) ) { |
|
765 | - |
|
766 | - foreach ( $this->cleanup_posts as $id => $key ) { |
|
767 | - $prev_items = get_post_meta( $id, $key, false ); |
|
768 | - $new_items = array_unique( $prev_items ); |
|
769 | - delete_post_meta( $id, $key ); |
|
770 | - |
|
771 | - foreach ( $new_items as $new_item ) { |
|
772 | - add_post_meta( $id, $key, $new_item, false ); |
|
773 | - } |
|
774 | - } |
|
775 | - } |
|
776 | - } |
|
777 | - |
|
778 | - // TAXONOMY FUNCTIONS. |
|
779 | - |
|
780 | - /** |
|
781 | - * Set_taxonomy with some terms |
|
782 | - */ |
|
783 | - public function set_taxonomy( $taxonomy, $terms, $id ) { |
|
784 | - $result = array(); |
|
785 | - |
|
786 | - if ( ! empty( $data ) ) { |
|
787 | - foreach ( $data as $k ) { |
|
788 | - if ( $id ) { |
|
789 | - $term = term_exists( trim( $k ), $tax ); |
|
790 | - if ( ! $term ) { |
|
791 | - $term = wp_insert_term( trim( $k ), $tax ); |
|
792 | - |
|
793 | - if ( is_wp_error( $term ) ) { |
|
794 | - echo wp_kses_post( $term->get_error_message() ); |
|
795 | - } else { |
|
796 | - wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
797 | - } |
|
798 | - } else { |
|
799 | - wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
800 | - } |
|
801 | - } else { |
|
802 | - $result[] = trim( $k ); |
|
803 | - } |
|
804 | - } |
|
805 | - } |
|
806 | - return $result; |
|
807 | - } |
|
808 | - |
|
809 | - /** |
|
810 | - * Sets the terms of the current post |
|
811 | - * |
|
812 | - * @param boolean $id |
|
813 | - * @param boolean $name |
|
814 | - * @param boolean $taxonomy |
|
815 | - * @param boolean $parent |
|
816 | - * @return void |
|
817 | - */ |
|
818 | - public function set_term( $id = false, $name = false, $taxonomy = false, $parent = false ) { |
|
819 | - $term = term_exists( $name, $taxonomy ); |
|
820 | - if ( ! $term ) { |
|
821 | - if ( false !== $parent ) { |
|
822 | - $parent = array( |
|
823 | - 'parent' => $parent, |
|
824 | - ); |
|
825 | - } |
|
826 | - $term = wp_insert_term( trim( $name ), $taxonomy, $parent ); |
|
827 | - |
|
828 | - if ( is_wp_error( $term ) ) { |
|
829 | - echo wp_kses_post( $term->get_error_message() ); |
|
830 | - } else { |
|
831 | - wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
832 | - } |
|
833 | - } else { |
|
834 | - wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
835 | - } |
|
836 | - |
|
837 | - return $term['term_id']; |
|
838 | - } |
|
839 | - |
|
840 | - /** |
|
841 | - * set_taxonomy with some terms |
|
842 | - */ |
|
843 | - public function taxonomy_checkboxes( $taxonomy = false, $selected = array() ) { |
|
844 | - $return = ''; |
|
845 | - |
|
846 | - if ( false !== $taxonomy ) { |
|
847 | - $return .= '<ul>'; |
|
848 | - $terms = get_terms( |
|
849 | - array( |
|
850 | - 'taxonomy' => $taxonomy, |
|
851 | - 'hide_empty' => false, |
|
852 | - ) |
|
853 | - ); |
|
854 | - |
|
855 | - if ( ! is_wp_error( $terms ) ) { |
|
856 | - foreach ( $terms as $term ) { |
|
857 | - $return .= '<li><input class="' . $taxonomy . '" ' . $this->checked( $selected, $term->term_id, false ) . ' type="checkbox" value="' . $term->term_id . '" /> ' . $term->name . '</li>'; |
|
858 | - } |
|
859 | - } else { |
|
860 | - $return .= '<li><input type="checkbox" value="" /> ' . __( 'None', 'lsx-wetu-importer' ) . '</li>'; |
|
861 | - } |
|
862 | - |
|
863 | - $return .= '</ul>'; |
|
864 | - } |
|
865 | - |
|
866 | - return $return; |
|
867 | - } |
|
868 | - |
|
869 | - // MAP FUNCTIONS |
|
870 | - |
|
871 | - /** |
|
872 | - * Saves the longitude and lattitude, as well as sets the map marker. |
|
873 | - */ |
|
874 | - public function set_map_data( $data, $id, $zoom = '10' ) { |
|
875 | - $longitude = false; |
|
876 | - $latitude = false; |
|
877 | - $address = false; |
|
878 | - |
|
879 | - if ( isset( $data[0]['position'] ) ) { |
|
880 | - if ( isset( $data[0]['position']['driving_latitude'] ) ) { |
|
881 | - $latitude = $data[0]['position']['driving_latitude']; |
|
882 | - } elseif ( isset( $data[0]['position']['latitude'] ) ) { |
|
883 | - $latitude = $data[0]['position']['latitude']; |
|
884 | - } |
|
885 | - |
|
886 | - if ( isset( $data[0]['position']['driving_longitude'] ) ) { |
|
887 | - $longitude = $data[0]['position']['driving_longitude']; |
|
888 | - } elseif ( isset( $data[0]['position']['longitude'] ) ) { |
|
889 | - $longitude = $data[0]['position']['longitude']; |
|
890 | - } |
|
891 | - } |
|
892 | - |
|
893 | - if ( isset( $data[0]['content'] ) && isset( $data[0]['content']['contact_information'] ) ) { |
|
894 | - if ( isset( $data[0]['content']['contact_information']['address'] ) ) { |
|
895 | - $address = strip_tags( $data[0]['content']['contact_information']['address'] ); |
|
896 | - $address = explode( "\n", $address ); |
|
897 | - |
|
898 | - foreach ( $address as $bitkey => $bit ) { |
|
899 | - $bit = ltrim( rtrim( $bit ) ); |
|
900 | - |
|
901 | - if ( false === $bit || '' === $bit || null === $bit || empty( $bit ) ) { |
|
902 | - unset( $address[ $bitkey ] ); |
|
903 | - } |
|
904 | - } |
|
905 | - |
|
906 | - $address = implode( ', ', $address ); |
|
907 | - $address = str_replace( ', , ', ', ', $address ); |
|
908 | - } |
|
909 | - } |
|
910 | - |
|
911 | - if ( false !== $longitude ) { |
|
912 | - $location_data = array( |
|
913 | - 'address' => (string) $address, |
|
914 | - 'lat' => (string) $latitude, |
|
915 | - 'long' => (string) $longitude, |
|
916 | - 'zoom' => (string) $zoom, |
|
917 | - 'elevation' => '', |
|
918 | - ); |
|
919 | - |
|
920 | - if ( false !== $id && '0' !== $id ) { |
|
921 | - $prev = get_post_meta( $id, 'location', true ); |
|
922 | - update_post_meta( $id, 'location', $location_data, $prev ); |
|
923 | - } else { |
|
924 | - add_post_meta( $id, 'location', $location_data, true ); |
|
925 | - } |
|
926 | - } |
|
927 | - } |
|
928 | - |
|
929 | - // IMAGE FUNCTIONS |
|
930 | - |
|
931 | - /** |
|
932 | - * Creates the main gallery data |
|
933 | - */ |
|
934 | - public function set_featured_image( $data, $id ) { |
|
935 | - if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
936 | - $this->featured_image = $this->attach_image( |
|
937 | - $data[0]['content']['images'][0], |
|
938 | - $id, |
|
939 | - array( |
|
940 | - 'width' => '800', |
|
941 | - 'height' => '600', |
|
942 | - 'cropping' => 'h', |
|
943 | - ) |
|
944 | - ); |
|
945 | - |
|
946 | - if ( false !== $this->featured_image ) { |
|
947 | - delete_post_meta( $id, '_thumbnail_id' ); |
|
948 | - add_post_meta( $id, '_thumbnail_id', $this->featured_image, true ); |
|
949 | - } |
|
950 | - } |
|
951 | - } |
|
952 | - |
|
953 | - /** |
|
954 | - * Sets a banner image |
|
955 | - */ |
|
956 | - public function set_banner_image( $data, $id, $content = array( 'none' ) ) { |
|
957 | - if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
958 | - if ( in_array( 'unique_banner_image', $content ) && isset( $data[0]['destination_image'] ) && is_array( $data[0]['destination_image'] ) ) { |
|
959 | - $temp_banner = $this->attach_image( |
|
960 | - $data[0]['destination_image'], |
|
961 | - $id, |
|
962 | - array( |
|
963 | - 'width' => '1920', |
|
964 | - 'height' => '600', |
|
965 | - 'cropping' => 'c', |
|
966 | - ) |
|
967 | - ); |
|
968 | - } else { |
|
969 | - $temp_banner = $this->attach_image( |
|
970 | - $data[0]['content']['images'][1], |
|
971 | - $id, |
|
972 | - array( |
|
973 | - 'width' => '1920', |
|
974 | - 'height' => '600', |
|
975 | - 'cropping' => 'c', |
|
976 | - ) |
|
977 | - ); |
|
978 | - } |
|
979 | - |
|
980 | - if ( false !== $temp_banner ) { |
|
981 | - $this->banner_image = $temp_banner; |
|
982 | - |
|
983 | - delete_post_meta( $id, 'image_group' ); |
|
984 | - |
|
985 | - $new_banner = array( |
|
986 | - 'banner_image' => array( |
|
987 | - 'cmb-field-0' => $this->banner_image, |
|
988 | - ), |
|
989 | - ); |
|
990 | - |
|
991 | - add_post_meta( $id, 'image_group', $new_banner, true ); |
|
992 | - } |
|
993 | - } |
|
994 | - } |
|
995 | - |
|
996 | - /** |
|
997 | - * Checks if the current image is being used as a thumbnail somewhere else. |
|
998 | - */ |
|
999 | - public function is_image_being_used( $image_id = '', $post_id = '' ) { |
|
1000 | - global $wpdb; |
|
1001 | - $being_used = false; |
|
1002 | - if ( '' !== $image_id ) { |
|
1003 | - $sql = "SELECT * FROM `{$wpdb->postmeta}` WHERE `post_id` != {$post_id} AND `meta_key` LIKE '_thumbnail_id' AND `meta_value` LIKE '{$image_id}'"; |
|
1004 | - $results = $wpdb->query( $sql ); |
|
1005 | - if ( false !== $results && ! empty( $results ) ) { |
|
1006 | - $being_used = true; |
|
1007 | - } |
|
1008 | - } |
|
1009 | - return $being_used; |
|
1010 | - } |
|
1011 | - |
|
1012 | - /** |
|
1013 | - * Creates the main gallery data |
|
1014 | - */ |
|
1015 | - public function create_main_gallery( $data, $id ) { |
|
1016 | - if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
1017 | - if ( isset( $this->options['image_replacing'] ) && 'on' === $this->options['image_replacing'] ) { |
|
1018 | - $current_gallery = get_post_meta( $id, 'gallery', false ); |
|
1019 | - |
|
1020 | - if ( false !== $current_gallery && ! empty( $current_gallery ) ) { |
|
1021 | - foreach ( $current_gallery as $g ) { |
|
1022 | - delete_post_meta( $id, 'gallery', $g ); |
|
1023 | - |
|
1024 | - if ( 'attachment' === get_post_type( $g ) && false === $this->is_image_being_used( $g, $id ) ) { |
|
1025 | - wp_delete_attachment( $g, true ); |
|
1026 | - } |
|
1027 | - } |
|
1028 | - } |
|
1029 | - } |
|
1030 | - |
|
1031 | - $counter = 0; |
|
1032 | - |
|
1033 | - foreach ( $data[0]['content']['images'] as $image_data ) { |
|
1034 | - if ( ( 0 === $counter && false !== $this->featured_image ) || ( 1 === $counter && false !== $this->banner_image ) ) { |
|
1035 | - $counter++; |
|
1036 | - |
|
1037 | - if ( false !== $this->image_limit && false !== $this->image_limit ) { |
|
1038 | - $this->image_limit++; |
|
1039 | - } |
|
1040 | - |
|
1041 | - continue; |
|
1042 | - } |
|
1043 | - |
|
1044 | - if ( false !== $this->image_limit && $counter >= $this->image_limit ) { |
|
1045 | - continue; |
|
1046 | - } |
|
1047 | - |
|
1048 | - $this->gallery_meta[] = $this->attach_image( $image_data, $id ); |
|
1049 | - $counter++; |
|
1050 | - } |
|
1051 | - |
|
1052 | - if ( ! empty( $this->gallery_meta ) ) { |
|
1053 | - delete_post_meta( $id, 'gallery' ); |
|
1054 | - $this->gallery_meta = array_unique( $this->gallery_meta ); |
|
1055 | - |
|
1056 | - foreach ( $this->gallery_meta as $gallery_id ) { |
|
1057 | - if ( false !== $gallery_id && '' !== $gallery_id && ! is_array( $gallery_id ) ) { |
|
1058 | - add_post_meta( $id, 'gallery', $gallery_id, false ); |
|
1059 | - } |
|
1060 | - } |
|
1061 | - } |
|
1062 | - } |
|
1063 | - } |
|
1064 | - |
|
1065 | - /** |
|
1066 | - * search_form |
|
1067 | - */ |
|
1068 | - public function get_scaling_url( $args = array() ) { |
|
1069 | - $defaults = array( |
|
1070 | - 'width' => '1024', |
|
1071 | - 'height' => '768', |
|
1072 | - // 'cropping' => 'w', |
|
1073 | - 'cropping' => 'h', |
|
1074 | - ); |
|
1075 | - |
|
1076 | - if ( false !== $this->options ) { |
|
1077 | - if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) { |
|
1078 | - $defaults['width'] = $this->options['width']; |
|
1079 | - } |
|
1080 | - |
|
1081 | - if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) { |
|
1082 | - $defaults['height'] = $this->options['height']; |
|
1083 | - } |
|
1084 | - |
|
1085 | - if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) { |
|
1086 | - $defaults['cropping'] = $this->options['cropping']; |
|
1087 | - } |
|
1088 | - } |
|
1089 | - |
|
1090 | - $args = wp_parse_args( $args, $defaults ); |
|
1091 | - $cropping = $args['cropping']; |
|
1092 | - $width = $args['width']; |
|
1093 | - $height = $args['height']; |
|
1094 | - |
|
1095 | - return 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/'; |
|
1096 | - } |
|
1097 | - |
|
1098 | - /** |
|
1099 | - * Attaches 1 image |
|
1100 | - */ |
|
1101 | - public function attach_image( $v = false, $parent_id, $image_sizes = false, $banner = false ) { |
|
1102 | - if ( false !== $v ) { |
|
1103 | - $temp_fragment = explode( '/', $v['url_fragment'] ); |
|
1104 | - $url_filename = $temp_fragment[ count( $temp_fragment ) - 1 ]; |
|
1105 | - $url_filename = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $url_filename ); |
|
1106 | - $url_filename = trim( $url_filename ); |
|
1107 | - $title = $url_filename; |
|
1108 | - $url_filename = str_replace( ' ', '_', $url_filename ); |
|
1109 | - |
|
1110 | - if ( ! isset( $this->options['image_replacing'] ) && in_array( $url_filename, $this->found_attachments ) ) { |
|
1111 | - return array_search( $url_filename, $this->found_attachments ); |
|
1112 | - } |
|
1113 | - |
|
1114 | - $postdata = array(); |
|
1115 | - |
|
1116 | - if ( empty( $v['label'] ) ) { |
|
1117 | - $v['label'] = ''; |
|
1118 | - } |
|
1119 | - |
|
1120 | - if ( ! empty( $v['description'] ) ) { |
|
1121 | - $desc = wp_strip_all_tags( $v['description'] ); |
|
1122 | - $posdata = array( |
|
1123 | - 'post_excerpt' => $desc, |
|
1124 | - ); |
|
1125 | - } |
|
1126 | - |
|
1127 | - if ( ! empty( $v['section'] ) ) { |
|
1128 | - $desc = wp_strip_all_tags( $v['section'] ); |
|
1129 | - $posdata = array( |
|
1130 | - 'post_excerpt' => $desc, |
|
1131 | - ); |
|
1132 | - } |
|
1133 | - |
|
1134 | - $attach_id = null; |
|
1135 | - // Resizor - add option to setting if required. |
|
1136 | - $fragment = str_replace( ' ', '%20', $v['url_fragment'] ); |
|
1137 | - $url = $this->get_scaling_url( $image_sizes ) . $fragment; |
|
1138 | - $attach_id = $this->attach_external_image2( $url, $parent_id, '', $v['label'], $postdata ); |
|
1139 | - if ( ! empty( $attach_id ) ) { |
|
1140 | - $this->found_attachments[ $attach_id ] = $url_filename; |
|
1141 | - add_post_meta( $attach_id, 'lsx_wetu_id', $v['url_fragment'], true ); |
|
1142 | - return $attach_id; |
|
1143 | - } |
|
1144 | - } |
|
1145 | - return false; |
|
1146 | - } |
|
1147 | - |
|
1148 | - public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
|
1149 | - if ( ! $url || ! $post_id ) { |
|
1150 | - return new WP_Error( 'missing', 'Need a valid URL and post ID...' ); } |
|
1151 | - $att_id = false; |
|
1152 | - |
|
1153 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
1154 | - require_once ABSPATH . 'wp-admin/includes/media.php'; |
|
1155 | - require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
1156 | - // Download file to temp location, returns full server path to temp file. |
|
1157 | - |
|
1158 | - $tmp = tempnam( '/tmp', 'FOO' ); |
|
1159 | - $image = wp_remote_get( $url ); |
|
1160 | - if ( ! is_wp_error( $image ) && ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) { |
|
1161 | - file_put_contents( $tmp, $image['body'] ); |
|
1162 | - chmod( $tmp, '777' ); |
|
1163 | - |
|
1164 | - 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 |
|
1165 | - $url_filename = basename( $matches[0] ); |
|
1166 | - $url_filename = str_replace( '%20', '_', $url_filename ); |
|
1167 | - // extract filename from url for title |
|
1168 | - $url_type = wp_check_filetype( $url_filename ); // determine file type (ext and mime/type) |
|
1169 | - |
|
1170 | - // override filename if given, reconstruct server path. |
|
1171 | - if ( ! empty( $filename ) && ' ' != $filename ) { |
|
1172 | - $filename = sanitize_file_name( $filename ); |
|
1173 | - $tmppath = pathinfo( $tmp ); |
|
1174 | - |
|
1175 | - $extension = ''; |
|
1176 | - if ( isset( $tmppath['extension'] ) ) { |
|
1177 | - $extension = $tmppath['extension']; |
|
1178 | - } |
|
1179 | - |
|
1180 | - $new = $tmppath['dirname'] . '/' . $filename . '.' . $extension; |
|
1181 | - rename( $tmp, $new ); // renames temp file on server |
|
1182 | - $tmp = $new; // push new filename (in path) to be used in file array later |
|
1183 | - } |
|
1184 | - |
|
1185 | - // assemble file data (should be built like $_FILES since wp_handle_sideload() will be using). |
|
1186 | - $file_array['tmp_name'] = $tmp; // full server path to temp file |
|
1187 | - |
|
1188 | - if ( ! empty( $filename ) && ' ' != $filename ) { |
|
1189 | - $file_array['name'] = $filename . '.' . $url_type['ext']; // user given filename for title, add original URL extension |
|
1190 | - } else { |
|
1191 | - $file_array['name'] = $url_filename; // just use original URL filename |
|
1192 | - } |
|
1193 | - |
|
1194 | - // set additional wp_posts columns. |
|
1195 | - if ( empty( $post_data['post_title'] ) ) { |
|
1196 | - |
|
1197 | - $url_filename = str_replace( '%20', ' ', $url_filename ); |
|
1198 | - |
|
1199 | - $post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] ); // just use the original filename (no extension) |
|
1200 | - } |
|
1201 | - |
|
1202 | - // make sure gets tied to parent. |
|
1203 | - if ( empty( $post_data['post_parent'] ) ) { |
|
1204 | - $post_data['post_parent'] = $post_id; |
|
1205 | - } |
|
1206 | - |
|
1207 | - // do the validation and storage stuff. |
|
1208 | - $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 |
|
1209 | - |
|
1210 | - // If error storing permanently, unlink. |
|
1211 | - if ( is_wp_error( $att_id ) ) { |
|
1212 | - unlink( $file_array['tmp_name'] ); |
|
1213 | - return false; |
|
1214 | - } |
|
1215 | - } |
|
1216 | - return $att_id; |
|
1217 | - } |
|
1218 | - |
|
1219 | - // AJAX FUNCTIONS |
|
1220 | - /** |
|
1221 | - * Run through the accommodation grabbed from the DB. |
|
1222 | - */ |
|
1223 | - public function process_ajax_search() { |
|
1224 | - $this->current_importer->process_ajax_search(); |
|
1225 | - die(); |
|
1226 | - } |
|
1227 | - |
|
1228 | - /** |
|
1229 | - * Connect to wetu |
|
1230 | - */ |
|
1231 | - public function process_ajax_import() { |
|
1232 | - $this->current_importer->process_ajax_import(); |
|
1233 | - die(); |
|
1234 | - } |
|
1235 | - |
|
1236 | - /** |
|
1237 | - * Formats the row for the completed list. |
|
1238 | - */ |
|
1239 | - public function format_completed_row( $response ) { |
|
1240 | - echo wp_kses_post( '<li class="post-' . $response . '"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="' . get_permalink( $response ) . '">' . get_the_title( $response ) . '</a></li>' ); |
|
1241 | - } |
|
1242 | - |
|
1243 | - /** |
|
1244 | - * Formats the error. |
|
1245 | - */ |
|
1246 | - public function format_error( $response ) { |
|
1247 | - echo wp_kses_post( '<li class="post-error"><span class="dashicons dashicons-no"></span>' . $response . '</li>' ); |
|
1248 | - } |
|
1249 | - |
|
1250 | - /** |
|
1251 | - * Does a multine search |
|
1252 | - */ |
|
1253 | - public function multineedle_stripos( $haystack, $needles, $offset = 0 ) { |
|
1254 | - $found = false; |
|
1255 | - $needle_count = count( $needles ); |
|
1256 | - |
|
1257 | - foreach ( $needles as $needle ) { |
|
1258 | - if ( false !== stripos( $haystack, $needle, $offset ) ) { |
|
1259 | - $found[] = true; |
|
1260 | - } |
|
1261 | - } |
|
1262 | - |
|
1263 | - if ( false !== $found && count( $found ) === $needle_count ) { |
|
1264 | - return true; |
|
1265 | - } else { |
|
1266 | - return false; |
|
1267 | - } |
|
1268 | - } |
|
1269 | - |
|
1270 | - /** |
|
1271 | - * Grab all the current accommodation posts via the lsx_wetu_id field. |
|
1272 | - */ |
|
1273 | - public function find_current_accommodation( $post_type = 'accommodation' ) { |
|
1274 | - global $wpdb; |
|
1275 | - $return = array(); |
|
1276 | - |
|
1277 | - // @codingStandardsIgnoreStart |
|
1278 | - $current_accommodation = $wpdb->get_results(" |
|
640 | + } |
|
641 | + } |
|
642 | + |
|
643 | + |
|
644 | + // GENERAL FUNCTIONS. |
|
645 | + |
|
646 | + /** |
|
647 | + * Checks to see if an item is checked. |
|
648 | + * |
|
649 | + * @param $haystack array|string |
|
650 | + * @param $needle string |
|
651 | + * @param $echo bool |
|
652 | + */ |
|
653 | + public function checked( $haystack = false, $needle = '', $echo = true ) { |
|
654 | + $return = $this->itemd( $haystack, $needle, 'checked', false ); |
|
655 | + |
|
656 | + if ( '' !== $return ) { |
|
657 | + if ( true === $echo ) { |
|
658 | + echo wp_kses_post( $return ); |
|
659 | + } else { |
|
660 | + return $return; |
|
661 | + } |
|
662 | + } |
|
663 | + } |
|
664 | + |
|
665 | + /** |
|
666 | + * Checks to see if an item is checked. |
|
667 | + * |
|
668 | + * @param $haystack array|string |
|
669 | + * @param $needle string |
|
670 | + * @param $echo bool |
|
671 | + */ |
|
672 | + public function selected( $haystack = false, $needle = '', $echo = true ) { |
|
673 | + $return = $this->itemd( $haystack, $needle, 'selected' ); |
|
674 | + |
|
675 | + if ( '' !== $return ) { |
|
676 | + if ( true === $echo ) { |
|
677 | + echo wp_kses_post( $return ); |
|
678 | + } else { |
|
679 | + return $return; |
|
680 | + } |
|
681 | + } |
|
682 | + } |
|
683 | + |
|
684 | + /** |
|
685 | + * Checks to see if an item is selected. If $echo is false, it will return the $type if conditions are true. |
|
686 | + * |
|
687 | + * @param $haystack array|string |
|
688 | + * @param $needle string |
|
689 | + * @param $type string |
|
690 | + * @param $wrap bool |
|
691 | + * @return $html string |
|
692 | + */ |
|
693 | + public function itemd( $haystack = false, $needle = '', $type = '', $wrap = true ) { |
|
694 | + $html = ''; |
|
695 | + |
|
696 | + if ( '' !== $type ) { |
|
697 | + if ( ! is_array( $haystack ) ) { |
|
698 | + $haystack = array( $haystack ); |
|
699 | + } |
|
700 | + if ( in_array( $needle, $haystack ) ) { |
|
701 | + if ( true === $wrap || 'true' === $wrap ) { |
|
702 | + $html = $type . '="' . $type . '"'; |
|
703 | + } else { |
|
704 | + $html = $type; |
|
705 | + } |
|
706 | + } |
|
707 | + } |
|
708 | + |
|
709 | + return $html; |
|
710 | + } |
|
711 | + |
|
712 | + /** |
|
713 | + * Grabs any attachments for the current item |
|
714 | + */ |
|
715 | + public function find_attachments( $id = false ) { |
|
716 | + if ( false !== $id ) { |
|
717 | + if ( empty( $this->found_attachments ) ) { |
|
718 | + $attachments_args = array( |
|
719 | + 'post_parent' => $id, |
|
720 | + 'post_status' => 'inherit', |
|
721 | + 'post_type' => 'attachment', |
|
722 | + 'order' => 'ASC', |
|
723 | + 'nopagin' => 'true', |
|
724 | + 'posts_per_page' => '-1', |
|
725 | + ); |
|
726 | + |
|
727 | + $attachments = new WP_Query( $attachments_args ); |
|
728 | + |
|
729 | + if ( $attachments->have_posts() ) { |
|
730 | + foreach ( $attachments->posts as $attachment ) { |
|
731 | + $this->found_attachments[ $attachment->ID ] = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $attachment->post_title ); |
|
732 | + } |
|
733 | + } |
|
734 | + } |
|
735 | + } |
|
736 | + } |
|
737 | + |
|
738 | + // CUSTOM FIELD FUNCTIONS. |
|
739 | + |
|
740 | + /** |
|
741 | + * Saves the room data |
|
742 | + */ |
|
743 | + public function save_custom_field( $value = false, $meta_key, $id, $decrease = false, $unique = true ) { |
|
744 | + if ( false !== $value ) { |
|
745 | + if ( false !== $decrease ) { |
|
746 | + $value = intval( $value ); |
|
747 | + $value--; |
|
748 | + } |
|
749 | + |
|
750 | + $prev = get_post_meta( $id, $meta_key, true ); |
|
751 | + |
|
752 | + if ( false !== $id && '0' !== $id && false !== $prev && true === $unique ) { |
|
753 | + update_post_meta( $id, $meta_key, $value, $prev ); |
|
754 | + } else { |
|
755 | + add_post_meta( $id, $meta_key, $value, $unique ); |
|
756 | + } |
|
757 | + } |
|
758 | + } |
|
759 | + |
|
760 | + /** |
|
761 | + * Grabs the custom fields, and resaves an array of unique items. |
|
762 | + */ |
|
763 | + public function cleanup_posts() { |
|
764 | + if ( ! empty( $this->cleanup_posts ) ) { |
|
765 | + |
|
766 | + foreach ( $this->cleanup_posts as $id => $key ) { |
|
767 | + $prev_items = get_post_meta( $id, $key, false ); |
|
768 | + $new_items = array_unique( $prev_items ); |
|
769 | + delete_post_meta( $id, $key ); |
|
770 | + |
|
771 | + foreach ( $new_items as $new_item ) { |
|
772 | + add_post_meta( $id, $key, $new_item, false ); |
|
773 | + } |
|
774 | + } |
|
775 | + } |
|
776 | + } |
|
777 | + |
|
778 | + // TAXONOMY FUNCTIONS. |
|
779 | + |
|
780 | + /** |
|
781 | + * Set_taxonomy with some terms |
|
782 | + */ |
|
783 | + public function set_taxonomy( $taxonomy, $terms, $id ) { |
|
784 | + $result = array(); |
|
785 | + |
|
786 | + if ( ! empty( $data ) ) { |
|
787 | + foreach ( $data as $k ) { |
|
788 | + if ( $id ) { |
|
789 | + $term = term_exists( trim( $k ), $tax ); |
|
790 | + if ( ! $term ) { |
|
791 | + $term = wp_insert_term( trim( $k ), $tax ); |
|
792 | + |
|
793 | + if ( is_wp_error( $term ) ) { |
|
794 | + echo wp_kses_post( $term->get_error_message() ); |
|
795 | + } else { |
|
796 | + wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
797 | + } |
|
798 | + } else { |
|
799 | + wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
800 | + } |
|
801 | + } else { |
|
802 | + $result[] = trim( $k ); |
|
803 | + } |
|
804 | + } |
|
805 | + } |
|
806 | + return $result; |
|
807 | + } |
|
808 | + |
|
809 | + /** |
|
810 | + * Sets the terms of the current post |
|
811 | + * |
|
812 | + * @param boolean $id |
|
813 | + * @param boolean $name |
|
814 | + * @param boolean $taxonomy |
|
815 | + * @param boolean $parent |
|
816 | + * @return void |
|
817 | + */ |
|
818 | + public function set_term( $id = false, $name = false, $taxonomy = false, $parent = false ) { |
|
819 | + $term = term_exists( $name, $taxonomy ); |
|
820 | + if ( ! $term ) { |
|
821 | + if ( false !== $parent ) { |
|
822 | + $parent = array( |
|
823 | + 'parent' => $parent, |
|
824 | + ); |
|
825 | + } |
|
826 | + $term = wp_insert_term( trim( $name ), $taxonomy, $parent ); |
|
827 | + |
|
828 | + if ( is_wp_error( $term ) ) { |
|
829 | + echo wp_kses_post( $term->get_error_message() ); |
|
830 | + } else { |
|
831 | + wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
832 | + } |
|
833 | + } else { |
|
834 | + wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
835 | + } |
|
836 | + |
|
837 | + return $term['term_id']; |
|
838 | + } |
|
839 | + |
|
840 | + /** |
|
841 | + * set_taxonomy with some terms |
|
842 | + */ |
|
843 | + public function taxonomy_checkboxes( $taxonomy = false, $selected = array() ) { |
|
844 | + $return = ''; |
|
845 | + |
|
846 | + if ( false !== $taxonomy ) { |
|
847 | + $return .= '<ul>'; |
|
848 | + $terms = get_terms( |
|
849 | + array( |
|
850 | + 'taxonomy' => $taxonomy, |
|
851 | + 'hide_empty' => false, |
|
852 | + ) |
|
853 | + ); |
|
854 | + |
|
855 | + if ( ! is_wp_error( $terms ) ) { |
|
856 | + foreach ( $terms as $term ) { |
|
857 | + $return .= '<li><input class="' . $taxonomy . '" ' . $this->checked( $selected, $term->term_id, false ) . ' type="checkbox" value="' . $term->term_id . '" /> ' . $term->name . '</li>'; |
|
858 | + } |
|
859 | + } else { |
|
860 | + $return .= '<li><input type="checkbox" value="" /> ' . __( 'None', 'lsx-wetu-importer' ) . '</li>'; |
|
861 | + } |
|
862 | + |
|
863 | + $return .= '</ul>'; |
|
864 | + } |
|
865 | + |
|
866 | + return $return; |
|
867 | + } |
|
868 | + |
|
869 | + // MAP FUNCTIONS |
|
870 | + |
|
871 | + /** |
|
872 | + * Saves the longitude and lattitude, as well as sets the map marker. |
|
873 | + */ |
|
874 | + public function set_map_data( $data, $id, $zoom = '10' ) { |
|
875 | + $longitude = false; |
|
876 | + $latitude = false; |
|
877 | + $address = false; |
|
878 | + |
|
879 | + if ( isset( $data[0]['position'] ) ) { |
|
880 | + if ( isset( $data[0]['position']['driving_latitude'] ) ) { |
|
881 | + $latitude = $data[0]['position']['driving_latitude']; |
|
882 | + } elseif ( isset( $data[0]['position']['latitude'] ) ) { |
|
883 | + $latitude = $data[0]['position']['latitude']; |
|
884 | + } |
|
885 | + |
|
886 | + if ( isset( $data[0]['position']['driving_longitude'] ) ) { |
|
887 | + $longitude = $data[0]['position']['driving_longitude']; |
|
888 | + } elseif ( isset( $data[0]['position']['longitude'] ) ) { |
|
889 | + $longitude = $data[0]['position']['longitude']; |
|
890 | + } |
|
891 | + } |
|
892 | + |
|
893 | + if ( isset( $data[0]['content'] ) && isset( $data[0]['content']['contact_information'] ) ) { |
|
894 | + if ( isset( $data[0]['content']['contact_information']['address'] ) ) { |
|
895 | + $address = strip_tags( $data[0]['content']['contact_information']['address'] ); |
|
896 | + $address = explode( "\n", $address ); |
|
897 | + |
|
898 | + foreach ( $address as $bitkey => $bit ) { |
|
899 | + $bit = ltrim( rtrim( $bit ) ); |
|
900 | + |
|
901 | + if ( false === $bit || '' === $bit || null === $bit || empty( $bit ) ) { |
|
902 | + unset( $address[ $bitkey ] ); |
|
903 | + } |
|
904 | + } |
|
905 | + |
|
906 | + $address = implode( ', ', $address ); |
|
907 | + $address = str_replace( ', , ', ', ', $address ); |
|
908 | + } |
|
909 | + } |
|
910 | + |
|
911 | + if ( false !== $longitude ) { |
|
912 | + $location_data = array( |
|
913 | + 'address' => (string) $address, |
|
914 | + 'lat' => (string) $latitude, |
|
915 | + 'long' => (string) $longitude, |
|
916 | + 'zoom' => (string) $zoom, |
|
917 | + 'elevation' => '', |
|
918 | + ); |
|
919 | + |
|
920 | + if ( false !== $id && '0' !== $id ) { |
|
921 | + $prev = get_post_meta( $id, 'location', true ); |
|
922 | + update_post_meta( $id, 'location', $location_data, $prev ); |
|
923 | + } else { |
|
924 | + add_post_meta( $id, 'location', $location_data, true ); |
|
925 | + } |
|
926 | + } |
|
927 | + } |
|
928 | + |
|
929 | + // IMAGE FUNCTIONS |
|
930 | + |
|
931 | + /** |
|
932 | + * Creates the main gallery data |
|
933 | + */ |
|
934 | + public function set_featured_image( $data, $id ) { |
|
935 | + if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
936 | + $this->featured_image = $this->attach_image( |
|
937 | + $data[0]['content']['images'][0], |
|
938 | + $id, |
|
939 | + array( |
|
940 | + 'width' => '800', |
|
941 | + 'height' => '600', |
|
942 | + 'cropping' => 'h', |
|
943 | + ) |
|
944 | + ); |
|
945 | + |
|
946 | + if ( false !== $this->featured_image ) { |
|
947 | + delete_post_meta( $id, '_thumbnail_id' ); |
|
948 | + add_post_meta( $id, '_thumbnail_id', $this->featured_image, true ); |
|
949 | + } |
|
950 | + } |
|
951 | + } |
|
952 | + |
|
953 | + /** |
|
954 | + * Sets a banner image |
|
955 | + */ |
|
956 | + public function set_banner_image( $data, $id, $content = array( 'none' ) ) { |
|
957 | + if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
958 | + if ( in_array( 'unique_banner_image', $content ) && isset( $data[0]['destination_image'] ) && is_array( $data[0]['destination_image'] ) ) { |
|
959 | + $temp_banner = $this->attach_image( |
|
960 | + $data[0]['destination_image'], |
|
961 | + $id, |
|
962 | + array( |
|
963 | + 'width' => '1920', |
|
964 | + 'height' => '600', |
|
965 | + 'cropping' => 'c', |
|
966 | + ) |
|
967 | + ); |
|
968 | + } else { |
|
969 | + $temp_banner = $this->attach_image( |
|
970 | + $data[0]['content']['images'][1], |
|
971 | + $id, |
|
972 | + array( |
|
973 | + 'width' => '1920', |
|
974 | + 'height' => '600', |
|
975 | + 'cropping' => 'c', |
|
976 | + ) |
|
977 | + ); |
|
978 | + } |
|
979 | + |
|
980 | + if ( false !== $temp_banner ) { |
|
981 | + $this->banner_image = $temp_banner; |
|
982 | + |
|
983 | + delete_post_meta( $id, 'image_group' ); |
|
984 | + |
|
985 | + $new_banner = array( |
|
986 | + 'banner_image' => array( |
|
987 | + 'cmb-field-0' => $this->banner_image, |
|
988 | + ), |
|
989 | + ); |
|
990 | + |
|
991 | + add_post_meta( $id, 'image_group', $new_banner, true ); |
|
992 | + } |
|
993 | + } |
|
994 | + } |
|
995 | + |
|
996 | + /** |
|
997 | + * Checks if the current image is being used as a thumbnail somewhere else. |
|
998 | + */ |
|
999 | + public function is_image_being_used( $image_id = '', $post_id = '' ) { |
|
1000 | + global $wpdb; |
|
1001 | + $being_used = false; |
|
1002 | + if ( '' !== $image_id ) { |
|
1003 | + $sql = "SELECT * FROM `{$wpdb->postmeta}` WHERE `post_id` != {$post_id} AND `meta_key` LIKE '_thumbnail_id' AND `meta_value` LIKE '{$image_id}'"; |
|
1004 | + $results = $wpdb->query( $sql ); |
|
1005 | + if ( false !== $results && ! empty( $results ) ) { |
|
1006 | + $being_used = true; |
|
1007 | + } |
|
1008 | + } |
|
1009 | + return $being_used; |
|
1010 | + } |
|
1011 | + |
|
1012 | + /** |
|
1013 | + * Creates the main gallery data |
|
1014 | + */ |
|
1015 | + public function create_main_gallery( $data, $id ) { |
|
1016 | + if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
1017 | + if ( isset( $this->options['image_replacing'] ) && 'on' === $this->options['image_replacing'] ) { |
|
1018 | + $current_gallery = get_post_meta( $id, 'gallery', false ); |
|
1019 | + |
|
1020 | + if ( false !== $current_gallery && ! empty( $current_gallery ) ) { |
|
1021 | + foreach ( $current_gallery as $g ) { |
|
1022 | + delete_post_meta( $id, 'gallery', $g ); |
|
1023 | + |
|
1024 | + if ( 'attachment' === get_post_type( $g ) && false === $this->is_image_being_used( $g, $id ) ) { |
|
1025 | + wp_delete_attachment( $g, true ); |
|
1026 | + } |
|
1027 | + } |
|
1028 | + } |
|
1029 | + } |
|
1030 | + |
|
1031 | + $counter = 0; |
|
1032 | + |
|
1033 | + foreach ( $data[0]['content']['images'] as $image_data ) { |
|
1034 | + if ( ( 0 === $counter && false !== $this->featured_image ) || ( 1 === $counter && false !== $this->banner_image ) ) { |
|
1035 | + $counter++; |
|
1036 | + |
|
1037 | + if ( false !== $this->image_limit && false !== $this->image_limit ) { |
|
1038 | + $this->image_limit++; |
|
1039 | + } |
|
1040 | + |
|
1041 | + continue; |
|
1042 | + } |
|
1043 | + |
|
1044 | + if ( false !== $this->image_limit && $counter >= $this->image_limit ) { |
|
1045 | + continue; |
|
1046 | + } |
|
1047 | + |
|
1048 | + $this->gallery_meta[] = $this->attach_image( $image_data, $id ); |
|
1049 | + $counter++; |
|
1050 | + } |
|
1051 | + |
|
1052 | + if ( ! empty( $this->gallery_meta ) ) { |
|
1053 | + delete_post_meta( $id, 'gallery' ); |
|
1054 | + $this->gallery_meta = array_unique( $this->gallery_meta ); |
|
1055 | + |
|
1056 | + foreach ( $this->gallery_meta as $gallery_id ) { |
|
1057 | + if ( false !== $gallery_id && '' !== $gallery_id && ! is_array( $gallery_id ) ) { |
|
1058 | + add_post_meta( $id, 'gallery', $gallery_id, false ); |
|
1059 | + } |
|
1060 | + } |
|
1061 | + } |
|
1062 | + } |
|
1063 | + } |
|
1064 | + |
|
1065 | + /** |
|
1066 | + * search_form |
|
1067 | + */ |
|
1068 | + public function get_scaling_url( $args = array() ) { |
|
1069 | + $defaults = array( |
|
1070 | + 'width' => '1024', |
|
1071 | + 'height' => '768', |
|
1072 | + // 'cropping' => 'w', |
|
1073 | + 'cropping' => 'h', |
|
1074 | + ); |
|
1075 | + |
|
1076 | + if ( false !== $this->options ) { |
|
1077 | + if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) { |
|
1078 | + $defaults['width'] = $this->options['width']; |
|
1079 | + } |
|
1080 | + |
|
1081 | + if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) { |
|
1082 | + $defaults['height'] = $this->options['height']; |
|
1083 | + } |
|
1084 | + |
|
1085 | + if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) { |
|
1086 | + $defaults['cropping'] = $this->options['cropping']; |
|
1087 | + } |
|
1088 | + } |
|
1089 | + |
|
1090 | + $args = wp_parse_args( $args, $defaults ); |
|
1091 | + $cropping = $args['cropping']; |
|
1092 | + $width = $args['width']; |
|
1093 | + $height = $args['height']; |
|
1094 | + |
|
1095 | + return 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/'; |
|
1096 | + } |
|
1097 | + |
|
1098 | + /** |
|
1099 | + * Attaches 1 image |
|
1100 | + */ |
|
1101 | + public function attach_image( $v = false, $parent_id, $image_sizes = false, $banner = false ) { |
|
1102 | + if ( false !== $v ) { |
|
1103 | + $temp_fragment = explode( '/', $v['url_fragment'] ); |
|
1104 | + $url_filename = $temp_fragment[ count( $temp_fragment ) - 1 ]; |
|
1105 | + $url_filename = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $url_filename ); |
|
1106 | + $url_filename = trim( $url_filename ); |
|
1107 | + $title = $url_filename; |
|
1108 | + $url_filename = str_replace( ' ', '_', $url_filename ); |
|
1109 | + |
|
1110 | + if ( ! isset( $this->options['image_replacing'] ) && in_array( $url_filename, $this->found_attachments ) ) { |
|
1111 | + return array_search( $url_filename, $this->found_attachments ); |
|
1112 | + } |
|
1113 | + |
|
1114 | + $postdata = array(); |
|
1115 | + |
|
1116 | + if ( empty( $v['label'] ) ) { |
|
1117 | + $v['label'] = ''; |
|
1118 | + } |
|
1119 | + |
|
1120 | + if ( ! empty( $v['description'] ) ) { |
|
1121 | + $desc = wp_strip_all_tags( $v['description'] ); |
|
1122 | + $posdata = array( |
|
1123 | + 'post_excerpt' => $desc, |
|
1124 | + ); |
|
1125 | + } |
|
1126 | + |
|
1127 | + if ( ! empty( $v['section'] ) ) { |
|
1128 | + $desc = wp_strip_all_tags( $v['section'] ); |
|
1129 | + $posdata = array( |
|
1130 | + 'post_excerpt' => $desc, |
|
1131 | + ); |
|
1132 | + } |
|
1133 | + |
|
1134 | + $attach_id = null; |
|
1135 | + // Resizor - add option to setting if required. |
|
1136 | + $fragment = str_replace( ' ', '%20', $v['url_fragment'] ); |
|
1137 | + $url = $this->get_scaling_url( $image_sizes ) . $fragment; |
|
1138 | + $attach_id = $this->attach_external_image2( $url, $parent_id, '', $v['label'], $postdata ); |
|
1139 | + if ( ! empty( $attach_id ) ) { |
|
1140 | + $this->found_attachments[ $attach_id ] = $url_filename; |
|
1141 | + add_post_meta( $attach_id, 'lsx_wetu_id', $v['url_fragment'], true ); |
|
1142 | + return $attach_id; |
|
1143 | + } |
|
1144 | + } |
|
1145 | + return false; |
|
1146 | + } |
|
1147 | + |
|
1148 | + public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
|
1149 | + if ( ! $url || ! $post_id ) { |
|
1150 | + return new WP_Error( 'missing', 'Need a valid URL and post ID...' ); } |
|
1151 | + $att_id = false; |
|
1152 | + |
|
1153 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
1154 | + require_once ABSPATH . 'wp-admin/includes/media.php'; |
|
1155 | + require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
1156 | + // Download file to temp location, returns full server path to temp file. |
|
1157 | + |
|
1158 | + $tmp = tempnam( '/tmp', 'FOO' ); |
|
1159 | + $image = wp_remote_get( $url ); |
|
1160 | + if ( ! is_wp_error( $image ) && ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) { |
|
1161 | + file_put_contents( $tmp, $image['body'] ); |
|
1162 | + chmod( $tmp, '777' ); |
|
1163 | + |
|
1164 | + 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 |
|
1165 | + $url_filename = basename( $matches[0] ); |
|
1166 | + $url_filename = str_replace( '%20', '_', $url_filename ); |
|
1167 | + // extract filename from url for title |
|
1168 | + $url_type = wp_check_filetype( $url_filename ); // determine file type (ext and mime/type) |
|
1169 | + |
|
1170 | + // override filename if given, reconstruct server path. |
|
1171 | + if ( ! empty( $filename ) && ' ' != $filename ) { |
|
1172 | + $filename = sanitize_file_name( $filename ); |
|
1173 | + $tmppath = pathinfo( $tmp ); |
|
1174 | + |
|
1175 | + $extension = ''; |
|
1176 | + if ( isset( $tmppath['extension'] ) ) { |
|
1177 | + $extension = $tmppath['extension']; |
|
1178 | + } |
|
1179 | + |
|
1180 | + $new = $tmppath['dirname'] . '/' . $filename . '.' . $extension; |
|
1181 | + rename( $tmp, $new ); // renames temp file on server |
|
1182 | + $tmp = $new; // push new filename (in path) to be used in file array later |
|
1183 | + } |
|
1184 | + |
|
1185 | + // assemble file data (should be built like $_FILES since wp_handle_sideload() will be using). |
|
1186 | + $file_array['tmp_name'] = $tmp; // full server path to temp file |
|
1187 | + |
|
1188 | + if ( ! empty( $filename ) && ' ' != $filename ) { |
|
1189 | + $file_array['name'] = $filename . '.' . $url_type['ext']; // user given filename for title, add original URL extension |
|
1190 | + } else { |
|
1191 | + $file_array['name'] = $url_filename; // just use original URL filename |
|
1192 | + } |
|
1193 | + |
|
1194 | + // set additional wp_posts columns. |
|
1195 | + if ( empty( $post_data['post_title'] ) ) { |
|
1196 | + |
|
1197 | + $url_filename = str_replace( '%20', ' ', $url_filename ); |
|
1198 | + |
|
1199 | + $post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] ); // just use the original filename (no extension) |
|
1200 | + } |
|
1201 | + |
|
1202 | + // make sure gets tied to parent. |
|
1203 | + if ( empty( $post_data['post_parent'] ) ) { |
|
1204 | + $post_data['post_parent'] = $post_id; |
|
1205 | + } |
|
1206 | + |
|
1207 | + // do the validation and storage stuff. |
|
1208 | + $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 |
|
1209 | + |
|
1210 | + // If error storing permanently, unlink. |
|
1211 | + if ( is_wp_error( $att_id ) ) { |
|
1212 | + unlink( $file_array['tmp_name'] ); |
|
1213 | + return false; |
|
1214 | + } |
|
1215 | + } |
|
1216 | + return $att_id; |
|
1217 | + } |
|
1218 | + |
|
1219 | + // AJAX FUNCTIONS |
|
1220 | + /** |
|
1221 | + * Run through the accommodation grabbed from the DB. |
|
1222 | + */ |
|
1223 | + public function process_ajax_search() { |
|
1224 | + $this->current_importer->process_ajax_search(); |
|
1225 | + die(); |
|
1226 | + } |
|
1227 | + |
|
1228 | + /** |
|
1229 | + * Connect to wetu |
|
1230 | + */ |
|
1231 | + public function process_ajax_import() { |
|
1232 | + $this->current_importer->process_ajax_import(); |
|
1233 | + die(); |
|
1234 | + } |
|
1235 | + |
|
1236 | + /** |
|
1237 | + * Formats the row for the completed list. |
|
1238 | + */ |
|
1239 | + public function format_completed_row( $response ) { |
|
1240 | + echo wp_kses_post( '<li class="post-' . $response . '"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="' . get_permalink( $response ) . '">' . get_the_title( $response ) . '</a></li>' ); |
|
1241 | + } |
|
1242 | + |
|
1243 | + /** |
|
1244 | + * Formats the error. |
|
1245 | + */ |
|
1246 | + public function format_error( $response ) { |
|
1247 | + echo wp_kses_post( '<li class="post-error"><span class="dashicons dashicons-no"></span>' . $response . '</li>' ); |
|
1248 | + } |
|
1249 | + |
|
1250 | + /** |
|
1251 | + * Does a multine search |
|
1252 | + */ |
|
1253 | + public function multineedle_stripos( $haystack, $needles, $offset = 0 ) { |
|
1254 | + $found = false; |
|
1255 | + $needle_count = count( $needles ); |
|
1256 | + |
|
1257 | + foreach ( $needles as $needle ) { |
|
1258 | + if ( false !== stripos( $haystack, $needle, $offset ) ) { |
|
1259 | + $found[] = true; |
|
1260 | + } |
|
1261 | + } |
|
1262 | + |
|
1263 | + if ( false !== $found && count( $found ) === $needle_count ) { |
|
1264 | + return true; |
|
1265 | + } else { |
|
1266 | + return false; |
|
1267 | + } |
|
1268 | + } |
|
1269 | + |
|
1270 | + /** |
|
1271 | + * Grab all the current accommodation posts via the lsx_wetu_id field. |
|
1272 | + */ |
|
1273 | + public function find_current_accommodation( $post_type = 'accommodation' ) { |
|
1274 | + global $wpdb; |
|
1275 | + $return = array(); |
|
1276 | + |
|
1277 | + // @codingStandardsIgnoreStart |
|
1278 | + $current_accommodation = $wpdb->get_results(" |
|
1279 | 1279 | SELECT key1.post_id,key1.meta_value |
1280 | 1280 | FROM {$wpdb->postmeta} key1 |
1281 | 1281 | |
@@ -1287,128 +1287,128 @@ discard block |
||
1287 | 1287 | |
1288 | 1288 | LIMIT 0,5000 |
1289 | 1289 | "); |
1290 | - // @codingStandardsIgnoreEnd |
|
1291 | - |
|
1292 | - if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) { |
|
1293 | - foreach ( $current_accommodation as $accom ) { |
|
1294 | - $return[ $accom->meta_value ] = $accom; |
|
1295 | - } |
|
1296 | - } |
|
1297 | - |
|
1298 | - return $return; |
|
1299 | - } |
|
1300 | - |
|
1301 | - /** |
|
1302 | - * Set the Video date |
|
1303 | - */ |
|
1304 | - public function set_video_data( $data, $id ) { |
|
1305 | - if ( ! empty( $data[0]['content']['youtube_videos'] ) && is_array( $data[0]['content']['youtube_videos'] ) ) { |
|
1306 | - $videos = false; |
|
1307 | - |
|
1308 | - foreach ( $data[0]['content']['youtube_videos'] as $video ) { |
|
1309 | - $temp_video = array(); |
|
1310 | - |
|
1311 | - if ( isset( $video['label'] ) ) { |
|
1312 | - $temp_video['title'] = $video['label']; |
|
1313 | - } |
|
1314 | - if ( isset( $video['description'] ) ) { |
|
1315 | - $temp_video['description'] = strip_tags( $video['description'] ); |
|
1316 | - } |
|
1317 | - if ( isset( $video['url'] ) ) { |
|
1318 | - $temp_video['url'] = $video['url']; |
|
1319 | - } |
|
1320 | - |
|
1321 | - $temp_video['thumbnail'] = ''; |
|
1322 | - $videos[] = $temp_video; |
|
1323 | - } |
|
1324 | - |
|
1325 | - if ( false !== $id && '0' !== $id ) { |
|
1326 | - delete_post_meta( $id, 'videos' ); |
|
1327 | - } |
|
1328 | - |
|
1329 | - foreach ( $videos as $video ) { |
|
1330 | - add_post_meta( $id, 'videos', $video, false ); |
|
1331 | - } |
|
1332 | - } |
|
1333 | - } |
|
1334 | - |
|
1335 | - public function shuffle_assoc( &$array ) { |
|
1336 | - $new = array(); |
|
1337 | - $keys = array_keys( $array ); |
|
1338 | - |
|
1339 | - shuffle( $keys ); |
|
1340 | - |
|
1341 | - foreach ( $keys as $key ) { |
|
1342 | - $new[ $key ] = $array[ $key ]; |
|
1343 | - } |
|
1344 | - |
|
1345 | - $array = $new; |
|
1346 | - |
|
1347 | - return true; |
|
1348 | - } |
|
1349 | - |
|
1350 | - /** |
|
1351 | - * Save the list of Tours into an option |
|
1352 | - */ |
|
1353 | - public function update_options() { |
|
1354 | - $own = ''; |
|
1355 | - $options = array(); |
|
1356 | - delete_option( 'lsx_ti_tours_api_options' ); |
|
1357 | - |
|
1358 | - if ( isset( $_GET['own'] ) ) { |
|
1359 | - $this->current_importer->url_qs .= '&own=true'; |
|
1360 | - $options[] = 'own'; |
|
1361 | - } |
|
1362 | - |
|
1363 | - if ( isset( $_GET['type'] ) && 'allitineraries' !== $_GET['type'] ) { |
|
1364 | - $this->current_importer->url_qs .= '&type=' . $_GET['type']; |
|
1365 | - $options[] = $_GET['type']; |
|
1366 | - } else { |
|
1367 | - $options[] = 'sample'; |
|
1368 | - $this->current_importer->url_qs .= '&type=sample'; |
|
1369 | - } |
|
1370 | - |
|
1371 | - $url = str_replace( 'Pins', 'Itinerary', $this->current_importer->url . '/V8/List?' . $this->current_importer->url_qs ); |
|
1372 | - $url .= '&results=2000'; |
|
1373 | - add_option( 'lsx_ti_tours_api_options', $options ); |
|
1374 | - $data = wp_remote_get( $url ); |
|
1375 | - $tours = json_decode( wp_remote_retrieve_body( $data ), true ); |
|
1376 | - |
|
1377 | - if ( isset( $tours['error'] ) ) { |
|
1378 | - return $tours['error']; |
|
1379 | - } elseif ( isset( $tours['itineraries'] ) && ! empty( $tours['itineraries'] ) ) { |
|
1380 | - set_transient( 'lsx_ti_tours', $tours['itineraries'], 60 * 60 * 4 ); |
|
1381 | - return true; |
|
1382 | - } |
|
1383 | - } |
|
1384 | - |
|
1385 | - /** |
|
1386 | - * Gets the post_id from the key |
|
1387 | - * |
|
1388 | - * @param boolean $wetu_id |
|
1389 | - * @return string |
|
1390 | - */ |
|
1391 | - public function get_post_id_by_key_value( $wetu_id = false ) { |
|
1392 | - global $wpdb; |
|
1393 | - $id = false; |
|
1394 | - if ( false !== $wetu_id && '' !== $wetu_id ) { |
|
1395 | - $result = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM `$wpdb->postmeta` WHERE `meta_key` = 'lsx_wetu_id' AND `meta_value` = '%s'", array( $wetu_id ) ) ); |
|
1396 | - if ( false !== $result && ! empty( $result ) ) { |
|
1397 | - $id = $result; |
|
1398 | - } |
|
1399 | - } |
|
1400 | - return $id; |
|
1401 | - } |
|
1402 | - /** |
|
1403 | - * Set the team memberon each item. |
|
1404 | - */ |
|
1405 | - public function set_team_member( $id, $team_members ) { |
|
1406 | - delete_post_meta( $id, 'team_to_' . $this->tab_slug ); |
|
1407 | - |
|
1408 | - foreach ( $team_members as $team ) { |
|
1409 | - add_post_meta( $id, 'team_to_' . $this->tab_slug, $team ); |
|
1410 | - } |
|
1411 | - } |
|
1290 | + // @codingStandardsIgnoreEnd |
|
1291 | + |
|
1292 | + if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) { |
|
1293 | + foreach ( $current_accommodation as $accom ) { |
|
1294 | + $return[ $accom->meta_value ] = $accom; |
|
1295 | + } |
|
1296 | + } |
|
1297 | + |
|
1298 | + return $return; |
|
1299 | + } |
|
1300 | + |
|
1301 | + /** |
|
1302 | + * Set the Video date |
|
1303 | + */ |
|
1304 | + public function set_video_data( $data, $id ) { |
|
1305 | + if ( ! empty( $data[0]['content']['youtube_videos'] ) && is_array( $data[0]['content']['youtube_videos'] ) ) { |
|
1306 | + $videos = false; |
|
1307 | + |
|
1308 | + foreach ( $data[0]['content']['youtube_videos'] as $video ) { |
|
1309 | + $temp_video = array(); |
|
1310 | + |
|
1311 | + if ( isset( $video['label'] ) ) { |
|
1312 | + $temp_video['title'] = $video['label']; |
|
1313 | + } |
|
1314 | + if ( isset( $video['description'] ) ) { |
|
1315 | + $temp_video['description'] = strip_tags( $video['description'] ); |
|
1316 | + } |
|
1317 | + if ( isset( $video['url'] ) ) { |
|
1318 | + $temp_video['url'] = $video['url']; |
|
1319 | + } |
|
1320 | + |
|
1321 | + $temp_video['thumbnail'] = ''; |
|
1322 | + $videos[] = $temp_video; |
|
1323 | + } |
|
1324 | + |
|
1325 | + if ( false !== $id && '0' !== $id ) { |
|
1326 | + delete_post_meta( $id, 'videos' ); |
|
1327 | + } |
|
1328 | + |
|
1329 | + foreach ( $videos as $video ) { |
|
1330 | + add_post_meta( $id, 'videos', $video, false ); |
|
1331 | + } |
|
1332 | + } |
|
1333 | + } |
|
1334 | + |
|
1335 | + public function shuffle_assoc( &$array ) { |
|
1336 | + $new = array(); |
|
1337 | + $keys = array_keys( $array ); |
|
1338 | + |
|
1339 | + shuffle( $keys ); |
|
1340 | + |
|
1341 | + foreach ( $keys as $key ) { |
|
1342 | + $new[ $key ] = $array[ $key ]; |
|
1343 | + } |
|
1344 | + |
|
1345 | + $array = $new; |
|
1346 | + |
|
1347 | + return true; |
|
1348 | + } |
|
1349 | + |
|
1350 | + /** |
|
1351 | + * Save the list of Tours into an option |
|
1352 | + */ |
|
1353 | + public function update_options() { |
|
1354 | + $own = ''; |
|
1355 | + $options = array(); |
|
1356 | + delete_option( 'lsx_ti_tours_api_options' ); |
|
1357 | + |
|
1358 | + if ( isset( $_GET['own'] ) ) { |
|
1359 | + $this->current_importer->url_qs .= '&own=true'; |
|
1360 | + $options[] = 'own'; |
|
1361 | + } |
|
1362 | + |
|
1363 | + if ( isset( $_GET['type'] ) && 'allitineraries' !== $_GET['type'] ) { |
|
1364 | + $this->current_importer->url_qs .= '&type=' . $_GET['type']; |
|
1365 | + $options[] = $_GET['type']; |
|
1366 | + } else { |
|
1367 | + $options[] = 'sample'; |
|
1368 | + $this->current_importer->url_qs .= '&type=sample'; |
|
1369 | + } |
|
1370 | + |
|
1371 | + $url = str_replace( 'Pins', 'Itinerary', $this->current_importer->url . '/V8/List?' . $this->current_importer->url_qs ); |
|
1372 | + $url .= '&results=2000'; |
|
1373 | + add_option( 'lsx_ti_tours_api_options', $options ); |
|
1374 | + $data = wp_remote_get( $url ); |
|
1375 | + $tours = json_decode( wp_remote_retrieve_body( $data ), true ); |
|
1376 | + |
|
1377 | + if ( isset( $tours['error'] ) ) { |
|
1378 | + return $tours['error']; |
|
1379 | + } elseif ( isset( $tours['itineraries'] ) && ! empty( $tours['itineraries'] ) ) { |
|
1380 | + set_transient( 'lsx_ti_tours', $tours['itineraries'], 60 * 60 * 4 ); |
|
1381 | + return true; |
|
1382 | + } |
|
1383 | + } |
|
1384 | + |
|
1385 | + /** |
|
1386 | + * Gets the post_id from the key |
|
1387 | + * |
|
1388 | + * @param boolean $wetu_id |
|
1389 | + * @return string |
|
1390 | + */ |
|
1391 | + public function get_post_id_by_key_value( $wetu_id = false ) { |
|
1392 | + global $wpdb; |
|
1393 | + $id = false; |
|
1394 | + if ( false !== $wetu_id && '' !== $wetu_id ) { |
|
1395 | + $result = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM `$wpdb->postmeta` WHERE `meta_key` = 'lsx_wetu_id' AND `meta_value` = '%s'", array( $wetu_id ) ) ); |
|
1396 | + if ( false !== $result && ! empty( $result ) ) { |
|
1397 | + $id = $result; |
|
1398 | + } |
|
1399 | + } |
|
1400 | + return $id; |
|
1401 | + } |
|
1402 | + /** |
|
1403 | + * Set the team memberon each item. |
|
1404 | + */ |
|
1405 | + public function set_team_member( $id, $team_members ) { |
|
1406 | + delete_post_meta( $id, 'team_to_' . $this->tab_slug ); |
|
1407 | + |
|
1408 | + foreach ( $team_members as $team ) { |
|
1409 | + add_post_meta( $id, 'team_to_' . $this->tab_slug, $team ); |
|
1410 | + } |
|
1411 | + } |
|
1412 | 1412 | } |
1413 | 1413 | |
1414 | 1414 | $lsx_wetu_importer = new LSX_WETU_Importer(); |
@@ -16,288 +16,288 @@ |
||
16 | 16 | */ |
17 | 17 | class Cron { |
18 | 18 | |
19 | - /** |
|
20 | - * Holds class instance |
|
21 | - * |
|
22 | - * @since 1.0.0 |
|
23 | - * |
|
24 | - * @var object|Module_Template |
|
25 | - */ |
|
26 | - protected static $instance = null; |
|
27 | - |
|
28 | - /** |
|
29 | - * Initialize the plugin by setting localization, filters, and administration functions. |
|
30 | - * |
|
31 | - * @since 1.0.0 |
|
32 | - * |
|
33 | - * @access private |
|
34 | - */ |
|
35 | - public function __construct() { |
|
36 | - add_filter( 'cron_schedules', array( $this, 'register_schedule' ), 10, 1 ); |
|
37 | - add_action( 'lsx_wetu_importer_settings_before', array( $this, 'watch_for_trigger' ), 200 ); |
|
38 | - add_action( 'lsx_wetu_accommodation_images_cron', array( $this, 'process' ), 10, 1 ); |
|
39 | - add_action( 'lsx_wetu_accommodation_images_sync', array( $this, 'cron_callback' ), 10, 1 ); |
|
40 | - add_filter( 'cmb_meta_boxes', array( $this, 'metaboxes' ) ); |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Return an instance of this class. |
|
45 | - * |
|
46 | - * @since 1.0.0 |
|
47 | - * |
|
48 | - * @return object Cron() A single instance of this class. |
|
49 | - */ |
|
50 | - public static function get_instance() { |
|
51 | - // If the single instance hasn't been set, set it now. |
|
52 | - if ( null === self::$instance ) { |
|
53 | - self::$instance = new self(); |
|
54 | - } |
|
55 | - return self::$instance; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Define the metabox and field configurations. |
|
60 | - * |
|
61 | - * @param array $meta_boxes |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - public function metaboxes( array $meta_boxes ) { |
|
65 | - // Allowed post types. |
|
66 | - $allowed_post_types = array( 'accommodation' ); |
|
67 | - |
|
68 | - $fields = array(); |
|
69 | - |
|
70 | - $fields[] = array( |
|
71 | - 'id' => 'wetu_skip_banner', |
|
72 | - 'name' => esc_html__( 'Skip Banner Image', 'lsx-banners' ), |
|
73 | - 'type' => 'checkbox', |
|
74 | - ); |
|
75 | - |
|
76 | - $fields[] = array( |
|
77 | - 'id' => 'wetu_skip_featured', |
|
78 | - 'name' => esc_html__( 'Skip Featured Image', 'lsx-banners' ), |
|
79 | - 'type' => 'checkbox', |
|
80 | - ); |
|
81 | - |
|
82 | - $meta_boxes[] = array( |
|
83 | - 'title' => esc_html__( 'WETU Settings', 'lsx-banners' ), |
|
84 | - 'pages' => $allowed_post_types, |
|
85 | - 'fields' => $fields, |
|
86 | - 'context' => 'side', |
|
87 | - 'priority' => 'low', |
|
88 | - ); |
|
89 | - |
|
90 | - return $meta_boxes; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Registers a 5 min schedule for us to use. |
|
95 | - * |
|
96 | - * @param array $schedules |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - public function register_schedule( $schedules ) { |
|
100 | - $schedules['wetu-5-minutes'] = array( |
|
101 | - 'interval' => 5 * MINUTE_IN_SECONDS, |
|
102 | - 'display' => __( 'Every 5 minutes', 'lsx-wetu-importer' ), |
|
103 | - ); |
|
104 | - return $schedules; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Watches for changes in the button triggers. |
|
109 | - * |
|
110 | - * @return void |
|
111 | - */ |
|
112 | - public function watch_for_trigger() { |
|
113 | - |
|
114 | - if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) { |
|
115 | - $options = lsx_wetu_get_options(); |
|
116 | - |
|
117 | - // Check what state the option is in. |
|
118 | - $accommodation_cron = 'deactivate'; |
|
119 | - if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { |
|
120 | - $accommodation_cron = 'activate'; |
|
121 | - } |
|
122 | - |
|
123 | - // Check what state the cron is in. |
|
124 | - $scheduled = false; |
|
125 | - if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) { |
|
126 | - $scheduled = true; |
|
127 | - } |
|
128 | - |
|
129 | - // If activate and its not running. |
|
130 | - if ( false === $scheduled && 'activate' === $accommodation_cron ) { |
|
131 | - $schedule = 'weekly'; |
|
132 | - $this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule ); |
|
133 | - } elseif ( true === $scheduled && 'deactivate' === $accommodation_cron ) { |
|
134 | - $this->deactivate(); |
|
135 | - } |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Remove our cron from the shedule. |
|
141 | - * |
|
142 | - * @return void |
|
143 | - */ |
|
144 | - public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) { |
|
145 | - wp_clear_scheduled_hook( $task, array( $task ) ); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * This function will schedule the cron event. |
|
150 | - * |
|
151 | - * @param string $task |
|
152 | - * @param string $schedule |
|
153 | - * @param string $time |
|
154 | - * @return void |
|
155 | - */ |
|
156 | - public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'weekly', $time = 'Sunday 10pm' ) { |
|
157 | - $args = array( $task ); |
|
158 | - if ( '' === $time ) { |
|
159 | - $time = time(); |
|
160 | - } |
|
161 | - |
|
162 | - if ( isset( $_GET['accommodation_images_cron_featured'] ) && '' !== $_GET['accommodation_images_cron_featured'] ) { |
|
163 | - $args[] = 'featured_image'; |
|
164 | - } |
|
165 | - wp_schedule_event( $time, $schedule, $task, $args ); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * This is the function that will be triggered by the cron event. |
|
170 | - * |
|
171 | - * @return void |
|
172 | - */ |
|
173 | - public function process( $task = '' ) { |
|
174 | - switch ( $task ) { |
|
175 | - case 'lsx_wetu_accommodation_images_cron': |
|
176 | - $this->register_accommodation_images_sync(); |
|
177 | - break; |
|
178 | - |
|
179 | - default: |
|
180 | - break; |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * This is the function that will be triggered by the cron event. |
|
186 | - * |
|
187 | - * @return void |
|
188 | - */ |
|
189 | - public function register_accommodation_images_sync() { |
|
190 | - $time = strtotime( '+5 min' ); |
|
191 | - if ( ! wp_next_scheduled( 'lsx_wetu_accommodation_images_sync' ) ) { |
|
192 | - $this->load_items_to_sync( 'accommodation_images' ); |
|
193 | - $this->schedule( 'lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time ); |
|
194 | - } |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * This is the function that will be triggered by the cron event. |
|
199 | - * |
|
200 | - * @return void |
|
201 | - */ |
|
202 | - public function cron_callback( $task = '', $featured_image = '' ) { |
|
203 | - $has_accommodation = get_option( $task ); |
|
204 | - if ( false !== $has_accommodation && ! empty( $has_accommodation ) ) { |
|
205 | - $next_time = array_slice( $has_accommodation, 3 ); |
|
206 | - $this_time = array_slice( $has_accommodation, 0, 2 ); |
|
207 | - |
|
208 | - $api_key = $this->get_api_key(); |
|
209 | - $url = 'https://wetu.com/API/Pins/' . $api_key . '/Get?all=include&ids='; |
|
210 | - |
|
211 | - // Run through the current items. |
|
212 | - foreach ( $this_time as $accommodation ) { |
|
213 | - $wetu_id = get_post_meta( $accommodation, 'lsx_wetu_id', true ); |
|
214 | - $last_date = get_post_meta( $accommodation, 'lsx_wetu_modified_date', true ); |
|
215 | - |
|
216 | - // Grabbing the image sync. |
|
217 | - $featured_image = get_post_meta( $accommodation, 'wetu_skip_featured', true ); |
|
218 | - $banner_image = get_post_meta( $accommodation, 'wetu_skip_banner', true ); |
|
219 | - |
|
220 | - $accommodation_info = wp_remote_get( $url . $wetu_id ); |
|
221 | - if ( ! empty( $accommodation_info ) && isset( $accommodation_info['response'] ) && isset( $accommodation_info['response']['code'] ) && 200 === $accommodation_info['response']['code'] ) { |
|
222 | - $adata = json_decode( $accommodation_info['body'], true ); |
|
223 | - |
|
224 | - if ( isset( $adata[0] ) && isset( $adata[0]['last_modified'] ) && '' !== $adata[0]['last_modified'] ) { |
|
225 | - $modified_time = strtotime( $adata[0]['last_modified'] ); |
|
226 | - if ( $modified_time > $last_date ) { |
|
227 | - $accommodation_importer = new \LSX_WETU_Importer_Accommodation(); |
|
228 | - |
|
229 | - if ( false === $banner_image || '' === $banner_image ) { |
|
230 | - $accommodation_importer->set_banner_image( $adata, $accommodation ); |
|
231 | - } |
|
232 | - |
|
233 | - if ( false === $featured_image || '' === $featured_image ) { |
|
234 | - $accommodation_importer->set_featured_image( $adata, $accommodation ); |
|
235 | - } |
|
236 | - |
|
237 | - $accommodation_importer->create_main_gallery( $adata, $accommodation ); |
|
238 | - update_post_meta( $accommodation, 'lsx_wetu_modified_date', $modified_time, $last_date ); |
|
239 | - } |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - // Save the values for next time. |
|
245 | - if ( ! empty( $next_time ) ) { |
|
246 | - update_option( $task, $next_time ); |
|
247 | - } else { |
|
248 | - delete_option( $task ); |
|
249 | - $this->deactivate( $task ); |
|
250 | - } |
|
251 | - } else { |
|
252 | - $this->deactivate( $task ); |
|
253 | - update_option( 'lsx_wetu_nexttime', $task ); |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * This will grab the accommodation ids and load them up into an option field. |
|
259 | - * |
|
260 | - * @param string $task |
|
261 | - * @return void |
|
262 | - */ |
|
263 | - public function load_items_to_sync( $task = 'accommodation_images' ) { |
|
264 | - $args = array( |
|
265 | - 'post_status' => 'publish', |
|
266 | - 'posts_per_page' => -1, |
|
267 | - 'nopagin' => true, |
|
268 | - 'fields' => 'ids', |
|
269 | - ); |
|
270 | - switch ( $task ) { |
|
271 | - case 'accommodation_images': |
|
272 | - $args['post_type'] = 'accommodation'; |
|
273 | - break; |
|
274 | - |
|
275 | - default: |
|
276 | - break; |
|
277 | - } |
|
278 | - $items = new \WP_Query( $args ); |
|
279 | - if ( $items->have_posts() ) { |
|
280 | - update_option( 'lsx_wetu_' . $task . '_sync', $items->posts ); |
|
281 | - } |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * Gets the API key stored in the options table. |
|
286 | - * |
|
287 | - * @return string |
|
288 | - */ |
|
289 | - public function get_api_key() { |
|
290 | - $api_key = false; |
|
291 | - $options = lsx_wetu_get_options(); |
|
292 | - |
|
293 | - if ( ! defined( 'WETU_API_KEY' ) ) { |
|
294 | - if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) { |
|
295 | - $api_key = $options['api_key']; |
|
296 | - } |
|
297 | - } else { |
|
298 | - $api_key = WETU_API_KEY; |
|
299 | - } |
|
300 | - return $api_key; |
|
301 | - } |
|
19 | + /** |
|
20 | + * Holds class instance |
|
21 | + * |
|
22 | + * @since 1.0.0 |
|
23 | + * |
|
24 | + * @var object|Module_Template |
|
25 | + */ |
|
26 | + protected static $instance = null; |
|
27 | + |
|
28 | + /** |
|
29 | + * Initialize the plugin by setting localization, filters, and administration functions. |
|
30 | + * |
|
31 | + * @since 1.0.0 |
|
32 | + * |
|
33 | + * @access private |
|
34 | + */ |
|
35 | + public function __construct() { |
|
36 | + add_filter( 'cron_schedules', array( $this, 'register_schedule' ), 10, 1 ); |
|
37 | + add_action( 'lsx_wetu_importer_settings_before', array( $this, 'watch_for_trigger' ), 200 ); |
|
38 | + add_action( 'lsx_wetu_accommodation_images_cron', array( $this, 'process' ), 10, 1 ); |
|
39 | + add_action( 'lsx_wetu_accommodation_images_sync', array( $this, 'cron_callback' ), 10, 1 ); |
|
40 | + add_filter( 'cmb_meta_boxes', array( $this, 'metaboxes' ) ); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Return an instance of this class. |
|
45 | + * |
|
46 | + * @since 1.0.0 |
|
47 | + * |
|
48 | + * @return object Cron() A single instance of this class. |
|
49 | + */ |
|
50 | + public static function get_instance() { |
|
51 | + // If the single instance hasn't been set, set it now. |
|
52 | + if ( null === self::$instance ) { |
|
53 | + self::$instance = new self(); |
|
54 | + } |
|
55 | + return self::$instance; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Define the metabox and field configurations. |
|
60 | + * |
|
61 | + * @param array $meta_boxes |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + public function metaboxes( array $meta_boxes ) { |
|
65 | + // Allowed post types. |
|
66 | + $allowed_post_types = array( 'accommodation' ); |
|
67 | + |
|
68 | + $fields = array(); |
|
69 | + |
|
70 | + $fields[] = array( |
|
71 | + 'id' => 'wetu_skip_banner', |
|
72 | + 'name' => esc_html__( 'Skip Banner Image', 'lsx-banners' ), |
|
73 | + 'type' => 'checkbox', |
|
74 | + ); |
|
75 | + |
|
76 | + $fields[] = array( |
|
77 | + 'id' => 'wetu_skip_featured', |
|
78 | + 'name' => esc_html__( 'Skip Featured Image', 'lsx-banners' ), |
|
79 | + 'type' => 'checkbox', |
|
80 | + ); |
|
81 | + |
|
82 | + $meta_boxes[] = array( |
|
83 | + 'title' => esc_html__( 'WETU Settings', 'lsx-banners' ), |
|
84 | + 'pages' => $allowed_post_types, |
|
85 | + 'fields' => $fields, |
|
86 | + 'context' => 'side', |
|
87 | + 'priority' => 'low', |
|
88 | + ); |
|
89 | + |
|
90 | + return $meta_boxes; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Registers a 5 min schedule for us to use. |
|
95 | + * |
|
96 | + * @param array $schedules |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + public function register_schedule( $schedules ) { |
|
100 | + $schedules['wetu-5-minutes'] = array( |
|
101 | + 'interval' => 5 * MINUTE_IN_SECONDS, |
|
102 | + 'display' => __( 'Every 5 minutes', 'lsx-wetu-importer' ), |
|
103 | + ); |
|
104 | + return $schedules; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Watches for changes in the button triggers. |
|
109 | + * |
|
110 | + * @return void |
|
111 | + */ |
|
112 | + public function watch_for_trigger() { |
|
113 | + |
|
114 | + if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) { |
|
115 | + $options = lsx_wetu_get_options(); |
|
116 | + |
|
117 | + // Check what state the option is in. |
|
118 | + $accommodation_cron = 'deactivate'; |
|
119 | + if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { |
|
120 | + $accommodation_cron = 'activate'; |
|
121 | + } |
|
122 | + |
|
123 | + // Check what state the cron is in. |
|
124 | + $scheduled = false; |
|
125 | + if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) { |
|
126 | + $scheduled = true; |
|
127 | + } |
|
128 | + |
|
129 | + // If activate and its not running. |
|
130 | + if ( false === $scheduled && 'activate' === $accommodation_cron ) { |
|
131 | + $schedule = 'weekly'; |
|
132 | + $this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule ); |
|
133 | + } elseif ( true === $scheduled && 'deactivate' === $accommodation_cron ) { |
|
134 | + $this->deactivate(); |
|
135 | + } |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Remove our cron from the shedule. |
|
141 | + * |
|
142 | + * @return void |
|
143 | + */ |
|
144 | + public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) { |
|
145 | + wp_clear_scheduled_hook( $task, array( $task ) ); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * This function will schedule the cron event. |
|
150 | + * |
|
151 | + * @param string $task |
|
152 | + * @param string $schedule |
|
153 | + * @param string $time |
|
154 | + * @return void |
|
155 | + */ |
|
156 | + public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'weekly', $time = 'Sunday 10pm' ) { |
|
157 | + $args = array( $task ); |
|
158 | + if ( '' === $time ) { |
|
159 | + $time = time(); |
|
160 | + } |
|
161 | + |
|
162 | + if ( isset( $_GET['accommodation_images_cron_featured'] ) && '' !== $_GET['accommodation_images_cron_featured'] ) { |
|
163 | + $args[] = 'featured_image'; |
|
164 | + } |
|
165 | + wp_schedule_event( $time, $schedule, $task, $args ); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * This is the function that will be triggered by the cron event. |
|
170 | + * |
|
171 | + * @return void |
|
172 | + */ |
|
173 | + public function process( $task = '' ) { |
|
174 | + switch ( $task ) { |
|
175 | + case 'lsx_wetu_accommodation_images_cron': |
|
176 | + $this->register_accommodation_images_sync(); |
|
177 | + break; |
|
178 | + |
|
179 | + default: |
|
180 | + break; |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * This is the function that will be triggered by the cron event. |
|
186 | + * |
|
187 | + * @return void |
|
188 | + */ |
|
189 | + public function register_accommodation_images_sync() { |
|
190 | + $time = strtotime( '+5 min' ); |
|
191 | + if ( ! wp_next_scheduled( 'lsx_wetu_accommodation_images_sync' ) ) { |
|
192 | + $this->load_items_to_sync( 'accommodation_images' ); |
|
193 | + $this->schedule( 'lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time ); |
|
194 | + } |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * This is the function that will be triggered by the cron event. |
|
199 | + * |
|
200 | + * @return void |
|
201 | + */ |
|
202 | + public function cron_callback( $task = '', $featured_image = '' ) { |
|
203 | + $has_accommodation = get_option( $task ); |
|
204 | + if ( false !== $has_accommodation && ! empty( $has_accommodation ) ) { |
|
205 | + $next_time = array_slice( $has_accommodation, 3 ); |
|
206 | + $this_time = array_slice( $has_accommodation, 0, 2 ); |
|
207 | + |
|
208 | + $api_key = $this->get_api_key(); |
|
209 | + $url = 'https://wetu.com/API/Pins/' . $api_key . '/Get?all=include&ids='; |
|
210 | + |
|
211 | + // Run through the current items. |
|
212 | + foreach ( $this_time as $accommodation ) { |
|
213 | + $wetu_id = get_post_meta( $accommodation, 'lsx_wetu_id', true ); |
|
214 | + $last_date = get_post_meta( $accommodation, 'lsx_wetu_modified_date', true ); |
|
215 | + |
|
216 | + // Grabbing the image sync. |
|
217 | + $featured_image = get_post_meta( $accommodation, 'wetu_skip_featured', true ); |
|
218 | + $banner_image = get_post_meta( $accommodation, 'wetu_skip_banner', true ); |
|
219 | + |
|
220 | + $accommodation_info = wp_remote_get( $url . $wetu_id ); |
|
221 | + if ( ! empty( $accommodation_info ) && isset( $accommodation_info['response'] ) && isset( $accommodation_info['response']['code'] ) && 200 === $accommodation_info['response']['code'] ) { |
|
222 | + $adata = json_decode( $accommodation_info['body'], true ); |
|
223 | + |
|
224 | + if ( isset( $adata[0] ) && isset( $adata[0]['last_modified'] ) && '' !== $adata[0]['last_modified'] ) { |
|
225 | + $modified_time = strtotime( $adata[0]['last_modified'] ); |
|
226 | + if ( $modified_time > $last_date ) { |
|
227 | + $accommodation_importer = new \LSX_WETU_Importer_Accommodation(); |
|
228 | + |
|
229 | + if ( false === $banner_image || '' === $banner_image ) { |
|
230 | + $accommodation_importer->set_banner_image( $adata, $accommodation ); |
|
231 | + } |
|
232 | + |
|
233 | + if ( false === $featured_image || '' === $featured_image ) { |
|
234 | + $accommodation_importer->set_featured_image( $adata, $accommodation ); |
|
235 | + } |
|
236 | + |
|
237 | + $accommodation_importer->create_main_gallery( $adata, $accommodation ); |
|
238 | + update_post_meta( $accommodation, 'lsx_wetu_modified_date', $modified_time, $last_date ); |
|
239 | + } |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + // Save the values for next time. |
|
245 | + if ( ! empty( $next_time ) ) { |
|
246 | + update_option( $task, $next_time ); |
|
247 | + } else { |
|
248 | + delete_option( $task ); |
|
249 | + $this->deactivate( $task ); |
|
250 | + } |
|
251 | + } else { |
|
252 | + $this->deactivate( $task ); |
|
253 | + update_option( 'lsx_wetu_nexttime', $task ); |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * This will grab the accommodation ids and load them up into an option field. |
|
259 | + * |
|
260 | + * @param string $task |
|
261 | + * @return void |
|
262 | + */ |
|
263 | + public function load_items_to_sync( $task = 'accommodation_images' ) { |
|
264 | + $args = array( |
|
265 | + 'post_status' => 'publish', |
|
266 | + 'posts_per_page' => -1, |
|
267 | + 'nopagin' => true, |
|
268 | + 'fields' => 'ids', |
|
269 | + ); |
|
270 | + switch ( $task ) { |
|
271 | + case 'accommodation_images': |
|
272 | + $args['post_type'] = 'accommodation'; |
|
273 | + break; |
|
274 | + |
|
275 | + default: |
|
276 | + break; |
|
277 | + } |
|
278 | + $items = new \WP_Query( $args ); |
|
279 | + if ( $items->have_posts() ) { |
|
280 | + update_option( 'lsx_wetu_' . $task . '_sync', $items->posts ); |
|
281 | + } |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * Gets the API key stored in the options table. |
|
286 | + * |
|
287 | + * @return string |
|
288 | + */ |
|
289 | + public function get_api_key() { |
|
290 | + $api_key = false; |
|
291 | + $options = lsx_wetu_get_options(); |
|
292 | + |
|
293 | + if ( ! defined( 'WETU_API_KEY' ) ) { |
|
294 | + if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) { |
|
295 | + $api_key = $options['api_key']; |
|
296 | + } |
|
297 | + } else { |
|
298 | + $api_key = WETU_API_KEY; |
|
299 | + } |
|
300 | + return $api_key; |
|
301 | + } |
|
302 | 302 | } |
303 | 303 | Cron::get_instance(); |
@@ -9,32 +9,32 @@ discard block |
||
9 | 9 | |
10 | 10 | class LSX_WETU_Importer_Banner_Integration extends LSX_WETU_Importer { |
11 | 11 | |
12 | - /** |
|
13 | - * The url to list items from WETU |
|
14 | - * |
|
15 | - * @since 0.0.1 |
|
16 | - * |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - public $tab_slug = 'banners'; |
|
20 | - |
|
21 | - /** |
|
22 | - * Initialize the plugin by setting localization, filters, and administration functions. |
|
23 | - * |
|
24 | - * @since 1.0.0 |
|
25 | - * |
|
26 | - * @access private |
|
27 | - */ |
|
28 | - public function __construct() { |
|
29 | - add_action( 'wp_ajax_lsx_import_sync_banners', array( $this, 'sync_new_banner' ) ); |
|
30 | - add_action( 'wp_ajax_nopriv_lsx_import_sync_banners', array( $this, 'sync_new_banner' ) ); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * Display the importer administration screen |
|
35 | - */ |
|
36 | - public function display_page() { |
|
37 | - ?> |
|
12 | + /** |
|
13 | + * The url to list items from WETU |
|
14 | + * |
|
15 | + * @since 0.0.1 |
|
16 | + * |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + public $tab_slug = 'banners'; |
|
20 | + |
|
21 | + /** |
|
22 | + * Initialize the plugin by setting localization, filters, and administration functions. |
|
23 | + * |
|
24 | + * @since 1.0.0 |
|
25 | + * |
|
26 | + * @access private |
|
27 | + */ |
|
28 | + public function __construct() { |
|
29 | + add_action( 'wp_ajax_lsx_import_sync_banners', array( $this, 'sync_new_banner' ) ); |
|
30 | + add_action( 'wp_ajax_nopriv_lsx_import_sync_banners', array( $this, 'sync_new_banner' ) ); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * Display the importer administration screen |
|
35 | + */ |
|
36 | + public function display_page() { |
|
37 | + ?> |
|
38 | 38 | <div class="wrap"> |
39 | 39 | <h2><?php esc_html_e( 'Download new banners straight from WETU', 'lsx-wetu-importer' ); ?></h2> |
40 | 40 | |
@@ -58,67 +58,67 @@ discard block |
||
58 | 58 | </thead> |
59 | 59 | |
60 | 60 | <?php |
61 | - $accommodation_args = array( |
|
62 | - 'post_type' => 'accommodation', |
|
63 | - 'post_status' => array( 'publish', 'pending', 'draft', 'future', 'private' ), |
|
64 | - 'nopagin' => 'true', |
|
65 | - 'posts_per_page' => '1000', |
|
66 | - 'meta_query' => array( |
|
67 | - 'relation' => 'AND', |
|
68 | - array( |
|
69 | - 'key' => 'lsx_wetu_id', |
|
70 | - 'compare' => 'EXISTS', |
|
71 | - ), |
|
72 | - array( |
|
73 | - 'key' => 'image_group', |
|
74 | - 'compare' => 'EXISTS', |
|
75 | - ), |
|
76 | - array( |
|
77 | - 'key' => 'image_group', |
|
78 | - 'value' => 'a:1:{s:12:"banner_image";a:0:{}}', |
|
79 | - 'compare' => '!=', |
|
80 | - ), |
|
81 | - ), |
|
82 | - ); |
|
83 | - $accommodation = new WP_Query( $accommodation_args ); |
|
84 | - ?> |
|
61 | + $accommodation_args = array( |
|
62 | + 'post_type' => 'accommodation', |
|
63 | + 'post_status' => array( 'publish', 'pending', 'draft', 'future', 'private' ), |
|
64 | + 'nopagin' => 'true', |
|
65 | + 'posts_per_page' => '1000', |
|
66 | + 'meta_query' => array( |
|
67 | + 'relation' => 'AND', |
|
68 | + array( |
|
69 | + 'key' => 'lsx_wetu_id', |
|
70 | + 'compare' => 'EXISTS', |
|
71 | + ), |
|
72 | + array( |
|
73 | + 'key' => 'image_group', |
|
74 | + 'compare' => 'EXISTS', |
|
75 | + ), |
|
76 | + array( |
|
77 | + 'key' => 'image_group', |
|
78 | + 'value' => 'a:1:{s:12:"banner_image";a:0:{}}', |
|
79 | + 'compare' => '!=', |
|
80 | + ), |
|
81 | + ), |
|
82 | + ); |
|
83 | + $accommodation = new WP_Query( $accommodation_args ); |
|
84 | + ?> |
|
85 | 85 | |
86 | 86 | <tbody id="the-list"> |
87 | 87 | <?php |
88 | - if ( $accommodation->have_posts() ) { |
|
89 | - while ( $accommodation->have_posts() ) { |
|
90 | - $accommodation->the_post(); |
|
91 | - ?> |
|
88 | + if ( $accommodation->have_posts() ) { |
|
89 | + while ( $accommodation->have_posts() ) { |
|
90 | + $accommodation->the_post(); |
|
91 | + ?> |
|
92 | 92 | <tr class="post-<?php the_ID(); ?> type-tour status-none" id="post-<?php the_ID(); ?>"> |
93 | 93 | <?php |
94 | - $banner_size_appropriate = false; |
|
95 | - $min_width = '1920'; |
|
96 | - $min_height = '500'; |
|
94 | + $banner_size_appropriate = false; |
|
95 | + $min_width = '1920'; |
|
96 | + $min_height = '500'; |
|
97 | 97 | |
98 | - $img_group = get_post_meta( get_the_ID(), 'image_group', true ); |
|
98 | + $img_group = get_post_meta( get_the_ID(), 'image_group', true ); |
|
99 | 99 | |
100 | - $thumbnails_html = false; |
|
100 | + $thumbnails_html = false; |
|
101 | 101 | |
102 | - if ( false !== $img_group ) { |
|
103 | - foreach ( $img_group['banner_image'] as $banner_image ) { |
|
104 | - $large = wp_get_attachment_image_src( $banner_image, 'full' ); |
|
105 | - $real_width = $large[1]; |
|
106 | - $real_height = $large[2]; |
|
102 | + if ( false !== $img_group ) { |
|
103 | + foreach ( $img_group['banner_image'] as $banner_image ) { |
|
104 | + $large = wp_get_attachment_image_src( $banner_image, 'full' ); |
|
105 | + $real_width = $large[1]; |
|
106 | + $real_height = $large[2]; |
|
107 | 107 | |
108 | - $status = 'optimized'; |
|
109 | - if ( $real_width < intval( $real_width ) ) { |
|
110 | - $status = 'width not enough.'; |
|
111 | - } |
|
108 | + $status = 'optimized'; |
|
109 | + if ( $real_width < intval( $real_width ) ) { |
|
110 | + $status = 'width not enough.'; |
|
111 | + } |
|
112 | 112 | |
113 | - $thumbnail = wp_get_attachment_image_src( $banner_image, 'thumbnail' ); |
|
114 | - $thumbnails_html[] = ' |
|
113 | + $thumbnail = wp_get_attachment_image_src( $banner_image, 'thumbnail' ); |
|
114 | + $thumbnails_html[] = ' |
|
115 | 115 | <div style="display:block;float:left;"> |
116 | 116 | <img src="' . $thumbnail[0] . '" /> |
117 | 117 | <p style="text-align:center;">' . $real_width . 'px by ' . $real_height . 'px</p> |
118 | 118 | </div>'; |
119 | - } |
|
120 | - } |
|
121 | - ?> |
|
119 | + } |
|
120 | + } |
|
121 | + ?> |
|
122 | 122 | <th class="check-column" scope="row"> |
123 | 123 | <label for="cb-select-<?php the_ID(); ?>" class="screen-reader-text"></label> |
124 | 124 | <input type="checkbox" data-identifier="<?php the_ID(); ?>" value="<?php the_ID(); ?>" name="post[]" id="cb-select-<?php the_ID(); ?>"> |
@@ -126,26 +126,26 @@ discard block |
||
126 | 126 | |
127 | 127 | <td class="post-title page-title column-title"> |
128 | 128 | <?php |
129 | - echo '<a href="' . esc_url( admin_url( '/post.php?post=' . get_the_ID() . '&action=edit' ) ) . '" target="_blank">'; |
|
130 | - the_title(); |
|
131 | - echo '</a>'; |
|
132 | - ?> |
|
129 | + echo '<a href="' . esc_url( admin_url( '/post.php?post=' . get_the_ID() . '&action=edit' ) ) . '" target="_blank">'; |
|
130 | + the_title(); |
|
131 | + echo '</a>'; |
|
132 | + ?> |
|
133 | 133 | </td> |
134 | 134 | |
135 | 135 | <td colspan="2" class="thumbnails column-thumbnails"> |
136 | 136 | <?php |
137 | - if ( false !== $thumbnails_html ) { |
|
138 | - echo wp_kses_post( implode( '', $thumbnails_html ) ); |
|
139 | - } else { |
|
140 | - echo '<p>There was an error retrieving your images.</p>'; |
|
141 | - } |
|
142 | - ?> |
|
137 | + if ( false !== $thumbnails_html ) { |
|
138 | + echo wp_kses_post( implode( '', $thumbnails_html ) ); |
|
139 | + } else { |
|
140 | + echo '<p>There was an error retrieving your images.</p>'; |
|
141 | + } |
|
142 | + ?> |
|
143 | 143 | </td> |
144 | 144 | </tr> |
145 | 145 | <?php |
146 | - } |
|
147 | - } |
|
148 | - ?> |
|
146 | + } |
|
147 | + } |
|
148 | + ?> |
|
149 | 149 | </tbody> |
150 | 150 | |
151 | 151 | <tfoot> |
@@ -166,125 +166,125 @@ discard block |
||
166 | 166 | </form> |
167 | 167 | </div> |
168 | 168 | <?php |
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Creates the main gallery data |
|
173 | - */ |
|
174 | - public function sync_new_banner() { |
|
175 | - check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
176 | - if ( isset( $_POST['action'] ) && 'lsx_import_sync_banners' === $_POST['action'] && isset( $_POST['post_id'] ) ) { |
|
177 | - |
|
178 | - $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
179 | - $banners = get_post_meta( $post_id, 'image_group', true ); |
|
180 | - $this->wetu_id = get_post_meta( $post_id, 'lsx_wetu_id', true ); |
|
181 | - |
|
182 | - $new_banner_array = false; |
|
183 | - $array_index = 0; |
|
184 | - |
|
185 | - foreach ( $banners['banner_image'] as $banner_image ) { |
|
186 | - $image_id = $this->attach_external_image2( $this->format_wetu_url( $banner_image ), array(), $post_id ); |
|
187 | - if ( null !== $image_id && '' !== $image_id ) { |
|
188 | - $new_banner_array['banner_image'][ 'cmb-field-' . $array_index ] = $image_id; |
|
189 | - $array_index++; |
|
190 | - } |
|
191 | - } |
|
192 | - |
|
193 | - if ( false !== $new_banner_array ) { |
|
194 | - delete_post_meta( $post_id, 'image_group' ); |
|
195 | - add_post_meta( $post_id, 'image_group', $new_banner_array, true ); |
|
196 | - echo true; |
|
197 | - } else { |
|
198 | - echo false; |
|
199 | - } |
|
200 | - } else { |
|
201 | - echo false; |
|
202 | - } |
|
203 | - |
|
204 | - die(); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * formats the url |
|
209 | - */ |
|
210 | - public function format_wetu_url( $post_id ) { |
|
211 | - return 'https://wetu.com/ImageHandler/c1920x800/' . $this->wetu_id . '/' . $this->format_filename( $post_id ); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * formats the filename |
|
216 | - */ |
|
217 | - public function format_filename( $post_id ) { |
|
218 | - $base = str_replace( '_', ' ', get_the_title( $post_id ) ); |
|
219 | - $base = rawurlencode( $base ); |
|
220 | - $type = get_post_mime_type( $post_id ); |
|
221 | - |
|
222 | - switch ( $type ) { |
|
223 | - case 'image/jpeg': |
|
224 | - return $base . '.jpg'; |
|
225 | - break; |
|
226 | - case 'image/png': |
|
227 | - return $base . '.png'; |
|
228 | - break; |
|
229 | - case 'image/gif': |
|
230 | - return $base . '.gif'; |
|
231 | - break; |
|
232 | - default: |
|
233 | - return false; |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - public function attach_external_image2( $url = null, $post_data = array(), $post_id = '' ) { |
|
238 | - if ( ! $url ) { |
|
239 | - return new WP_Error( 'missing', 'Need a valid URL' ); } |
|
240 | - $att_id = false; |
|
241 | - |
|
242 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
243 | - require_once ABSPATH . 'wp-admin/includes/media.php'; |
|
244 | - require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
245 | - |
|
246 | - $tmp = tempnam( '/tmp', 'FOO' ); |
|
247 | - $image = wp_remote_get( $url ); |
|
248 | - |
|
249 | - if ( ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) { |
|
250 | - file_put_contents( $tmp, $image['body'] ); |
|
251 | - chmod( $tmp, '777' ); |
|
252 | - |
|
253 | - preg_match( '/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches ); |
|
254 | - $url_filename = basename( $matches[0] ); |
|
255 | - $url_filename = str_replace( '%20', '_', $url_filename ); |
|
256 | - // extract filename from url for title. |
|
257 | - $url_type = wp_check_filetype( $url_filename ); |
|
258 | - |
|
259 | - // assemble file data (should be built like $_FILES since wp_handle_sideload() will be using). |
|
260 | - $file_array['tmp_name'] = $tmp; |
|
261 | - |
|
262 | - if ( ! empty( $filename ) && ' ' != $filename ) { |
|
263 | - $file_array['name'] = $filename . '.' . $url_type['ext']; |
|
264 | - } else { |
|
265 | - $file_array['name'] = $url_filename; |
|
266 | - } |
|
267 | - |
|
268 | - // set additional wp_posts columns. |
|
269 | - if ( empty( $post_data['post_title'] ) ) { |
|
270 | - $url_filename = str_replace( '%20', ' ', $url_filename ); |
|
271 | - $post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] ); |
|
272 | - } |
|
273 | - |
|
274 | - // make sure gets tied to parent. |
|
275 | - if ( empty( $post_data['post_parent'] ) ) { |
|
276 | - $post_data['post_parent'] = $post_id; |
|
277 | - } |
|
278 | - |
|
279 | - // do the validation and storage stuff. |
|
280 | - $att_id = media_handle_sideload( $file_array, $post_id, null, $post_data ); |
|
281 | - |
|
282 | - // If error storing permanently, unlink. |
|
283 | - if ( is_wp_error( $att_id ) ) { |
|
284 | - unlink( $file_array['tmp_name'] ); |
|
285 | - return false; |
|
286 | - } |
|
287 | - } |
|
288 | - return $att_id; |
|
289 | - } |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Creates the main gallery data |
|
173 | + */ |
|
174 | + public function sync_new_banner() { |
|
175 | + check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
176 | + if ( isset( $_POST['action'] ) && 'lsx_import_sync_banners' === $_POST['action'] && isset( $_POST['post_id'] ) ) { |
|
177 | + |
|
178 | + $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
179 | + $banners = get_post_meta( $post_id, 'image_group', true ); |
|
180 | + $this->wetu_id = get_post_meta( $post_id, 'lsx_wetu_id', true ); |
|
181 | + |
|
182 | + $new_banner_array = false; |
|
183 | + $array_index = 0; |
|
184 | + |
|
185 | + foreach ( $banners['banner_image'] as $banner_image ) { |
|
186 | + $image_id = $this->attach_external_image2( $this->format_wetu_url( $banner_image ), array(), $post_id ); |
|
187 | + if ( null !== $image_id && '' !== $image_id ) { |
|
188 | + $new_banner_array['banner_image'][ 'cmb-field-' . $array_index ] = $image_id; |
|
189 | + $array_index++; |
|
190 | + } |
|
191 | + } |
|
192 | + |
|
193 | + if ( false !== $new_banner_array ) { |
|
194 | + delete_post_meta( $post_id, 'image_group' ); |
|
195 | + add_post_meta( $post_id, 'image_group', $new_banner_array, true ); |
|
196 | + echo true; |
|
197 | + } else { |
|
198 | + echo false; |
|
199 | + } |
|
200 | + } else { |
|
201 | + echo false; |
|
202 | + } |
|
203 | + |
|
204 | + die(); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * formats the url |
|
209 | + */ |
|
210 | + public function format_wetu_url( $post_id ) { |
|
211 | + return 'https://wetu.com/ImageHandler/c1920x800/' . $this->wetu_id . '/' . $this->format_filename( $post_id ); |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * formats the filename |
|
216 | + */ |
|
217 | + public function format_filename( $post_id ) { |
|
218 | + $base = str_replace( '_', ' ', get_the_title( $post_id ) ); |
|
219 | + $base = rawurlencode( $base ); |
|
220 | + $type = get_post_mime_type( $post_id ); |
|
221 | + |
|
222 | + switch ( $type ) { |
|
223 | + case 'image/jpeg': |
|
224 | + return $base . '.jpg'; |
|
225 | + break; |
|
226 | + case 'image/png': |
|
227 | + return $base . '.png'; |
|
228 | + break; |
|
229 | + case 'image/gif': |
|
230 | + return $base . '.gif'; |
|
231 | + break; |
|
232 | + default: |
|
233 | + return false; |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + public function attach_external_image2( $url = null, $post_data = array(), $post_id = '' ) { |
|
238 | + if ( ! $url ) { |
|
239 | + return new WP_Error( 'missing', 'Need a valid URL' ); } |
|
240 | + $att_id = false; |
|
241 | + |
|
242 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
243 | + require_once ABSPATH . 'wp-admin/includes/media.php'; |
|
244 | + require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
245 | + |
|
246 | + $tmp = tempnam( '/tmp', 'FOO' ); |
|
247 | + $image = wp_remote_get( $url ); |
|
248 | + |
|
249 | + if ( ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) { |
|
250 | + file_put_contents( $tmp, $image['body'] ); |
|
251 | + chmod( $tmp, '777' ); |
|
252 | + |
|
253 | + preg_match( '/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches ); |
|
254 | + $url_filename = basename( $matches[0] ); |
|
255 | + $url_filename = str_replace( '%20', '_', $url_filename ); |
|
256 | + // extract filename from url for title. |
|
257 | + $url_type = wp_check_filetype( $url_filename ); |
|
258 | + |
|
259 | + // assemble file data (should be built like $_FILES since wp_handle_sideload() will be using). |
|
260 | + $file_array['tmp_name'] = $tmp; |
|
261 | + |
|
262 | + if ( ! empty( $filename ) && ' ' != $filename ) { |
|
263 | + $file_array['name'] = $filename . '.' . $url_type['ext']; |
|
264 | + } else { |
|
265 | + $file_array['name'] = $url_filename; |
|
266 | + } |
|
267 | + |
|
268 | + // set additional wp_posts columns. |
|
269 | + if ( empty( $post_data['post_title'] ) ) { |
|
270 | + $url_filename = str_replace( '%20', ' ', $url_filename ); |
|
271 | + $post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] ); |
|
272 | + } |
|
273 | + |
|
274 | + // make sure gets tied to parent. |
|
275 | + if ( empty( $post_data['post_parent'] ) ) { |
|
276 | + $post_data['post_parent'] = $post_id; |
|
277 | + } |
|
278 | + |
|
279 | + // do the validation and storage stuff. |
|
280 | + $att_id = media_handle_sideload( $file_array, $post_id, null, $post_data ); |
|
281 | + |
|
282 | + // If error storing permanently, unlink. |
|
283 | + if ( is_wp_error( $att_id ) ) { |
|
284 | + unlink( $file_array['tmp_name'] ); |
|
285 | + return false; |
|
286 | + } |
|
287 | + } |
|
288 | + return $att_id; |
|
289 | + } |
|
290 | 290 | } |
@@ -9,87 +9,87 @@ discard block |
||
9 | 9 | |
10 | 10 | class LSX_WETU_Importer_Destination extends LSX_WETU_Importer { |
11 | 11 | |
12 | - /** |
|
13 | - * The url to list items from WETU |
|
14 | - * |
|
15 | - * @since 0.0.1 |
|
16 | - * |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - public $tab_slug = 'destination'; |
|
20 | - |
|
21 | - /** |
|
22 | - * The url to list items from WETU |
|
23 | - * |
|
24 | - * @since 0.0.1 |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $url = false; |
|
29 | - |
|
30 | - /** |
|
31 | - * The query string url to list items from WETU |
|
32 | - * |
|
33 | - * @since 0.0.1 |
|
34 | - * |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - public $url_qs = false; |
|
38 | - |
|
39 | - /** |
|
40 | - * Options |
|
41 | - * |
|
42 | - * @since 0.0.1 |
|
43 | - * |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - public $options = false; |
|
47 | - |
|
48 | - /** |
|
49 | - * The fields you wish to import |
|
50 | - * |
|
51 | - * @since 0.0.1 |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - public $destination_options = false; |
|
56 | - |
|
57 | - /** |
|
58 | - * Initialize the plugin by setting localization, filters, and administration functions. |
|
59 | - * |
|
60 | - * @since 1.0.0 |
|
61 | - * |
|
62 | - * @access private |
|
63 | - */ |
|
64 | - public function __construct() { |
|
65 | - $this->set_variables(); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Sets the variables used throughout the plugin. |
|
70 | - */ |
|
71 | - public function set_variables() { |
|
72 | - parent::set_variables(); |
|
73 | - $this->url = 'https://wetu.com/API/Pins/' . $this->api_key; |
|
74 | - $this->url_qs = 'all=include'; |
|
75 | - $temp_options = get_option( '_lsx-to_settings', false ); |
|
76 | - |
|
77 | - if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) { |
|
78 | - $this->options = $temp_options[ $this->plugin_slug ]; |
|
79 | - } |
|
80 | - |
|
81 | - $destination_options = get_option( 'lsx_wetu_importer_destination_settings', false ); |
|
82 | - |
|
83 | - if ( false !== $destination_options ) { |
|
84 | - $this->destination_options = $destination_options; |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Display the importer administration screen |
|
90 | - */ |
|
91 | - public function display_page() { |
|
92 | - ?> |
|
12 | + /** |
|
13 | + * The url to list items from WETU |
|
14 | + * |
|
15 | + * @since 0.0.1 |
|
16 | + * |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + public $tab_slug = 'destination'; |
|
20 | + |
|
21 | + /** |
|
22 | + * The url to list items from WETU |
|
23 | + * |
|
24 | + * @since 0.0.1 |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $url = false; |
|
29 | + |
|
30 | + /** |
|
31 | + * The query string url to list items from WETU |
|
32 | + * |
|
33 | + * @since 0.0.1 |
|
34 | + * |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + public $url_qs = false; |
|
38 | + |
|
39 | + /** |
|
40 | + * Options |
|
41 | + * |
|
42 | + * @since 0.0.1 |
|
43 | + * |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + public $options = false; |
|
47 | + |
|
48 | + /** |
|
49 | + * The fields you wish to import |
|
50 | + * |
|
51 | + * @since 0.0.1 |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + public $destination_options = false; |
|
56 | + |
|
57 | + /** |
|
58 | + * Initialize the plugin by setting localization, filters, and administration functions. |
|
59 | + * |
|
60 | + * @since 1.0.0 |
|
61 | + * |
|
62 | + * @access private |
|
63 | + */ |
|
64 | + public function __construct() { |
|
65 | + $this->set_variables(); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Sets the variables used throughout the plugin. |
|
70 | + */ |
|
71 | + public function set_variables() { |
|
72 | + parent::set_variables(); |
|
73 | + $this->url = 'https://wetu.com/API/Pins/' . $this->api_key; |
|
74 | + $this->url_qs = 'all=include'; |
|
75 | + $temp_options = get_option( '_lsx-to_settings', false ); |
|
76 | + |
|
77 | + if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) { |
|
78 | + $this->options = $temp_options[ $this->plugin_slug ]; |
|
79 | + } |
|
80 | + |
|
81 | + $destination_options = get_option( 'lsx_wetu_importer_destination_settings', false ); |
|
82 | + |
|
83 | + if ( false !== $destination_options ) { |
|
84 | + $this->destination_options = $destination_options; |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Display the importer administration screen |
|
90 | + */ |
|
91 | + public function display_page() { |
|
92 | + ?> |
|
93 | 93 | <div class="wrap"> |
94 | 94 | <div class="tablenav top"> |
95 | 95 | <div class="actions"> |
@@ -190,13 +190,13 @@ discard block |
||
190 | 190 | value="banner_image"/> <?php esc_html_e( 'Set Banner Image', 'lsx-wetu-importer' ); ?> |
191 | 191 | </li> |
192 | 192 | <?php |
193 | - /* |
|
193 | + /* |
|
194 | 194 | <li> |
195 | 195 | <input class="content" |
196 | 196 | type="checkbox" name="content[]" |
197 | 197 | value="unique_banner_image"/> <?php esc_html_e( 'Use the WETU banner field', 'lsx-wetu-importer' ); ?> |
198 | 198 | </li>*/ |
199 | - ?> |
|
199 | + ?> |
|
200 | 200 | |
201 | 201 | <li> |
202 | 202 | <input class="content" checked="checked" |
@@ -282,17 +282,17 @@ discard block |
||
282 | 282 | </div> |
283 | 283 | </div> |
284 | 284 | <?php |
285 | - } |
|
285 | + } |
|
286 | 286 | |
287 | - /** |
|
288 | - * Grab all the current destination posts via the lsx_wetu_id field. |
|
289 | - */ |
|
290 | - public function find_current_destination( $post_type = 'destination' ) { |
|
291 | - global $wpdb; |
|
292 | - $return = array(); |
|
287 | + /** |
|
288 | + * Grab all the current destination posts via the lsx_wetu_id field. |
|
289 | + */ |
|
290 | + public function find_current_destination( $post_type = 'destination' ) { |
|
291 | + global $wpdb; |
|
292 | + $return = array(); |
|
293 | 293 | |
294 | - // @codingStandardsIgnoreStart |
|
295 | - $current_destination = $wpdb->get_results(" |
|
294 | + // @codingStandardsIgnoreStart |
|
295 | + $current_destination = $wpdb->get_results(" |
|
296 | 296 | SELECT key1.post_id,key1.meta_value,key2.post_title as name,key2.post_date as last_modified |
297 | 297 | FROM {$wpdb->postmeta} key1 |
298 | 298 | |
@@ -304,151 +304,151 @@ discard block |
||
304 | 304 | |
305 | 305 | LIMIT 0,1000 |
306 | 306 | "); |
307 | - // @codingStandardsIgnoreEnd |
|
308 | - |
|
309 | - if ( null !== $current_destination && ! empty( $current_destination ) ) { |
|
310 | - foreach ( $current_destination as $accom ) { |
|
311 | - $return[ $accom->meta_value ] = $accom; |
|
312 | - } |
|
313 | - } |
|
314 | - |
|
315 | - return $return; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Run through the accommodation grabbed from the DB. |
|
320 | - */ |
|
321 | - public function process_ajax_search() { |
|
322 | - $return = false; |
|
323 | - check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
324 | - if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && 'destination' === $_POST['type'] ) { |
|
325 | - |
|
326 | - $searched_items = false; |
|
327 | - if ( isset( $_POST['keyword'] ) ) { |
|
328 | - $keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) ); |
|
329 | - } else { |
|
330 | - $keyphrases = array( 0 ); |
|
331 | - } |
|
332 | - |
|
333 | - if ( ! is_array( $keyphrases ) ) { |
|
334 | - $keyphrases = array( $keyphrases ); |
|
335 | - } |
|
336 | - foreach ( $keyphrases as &$keyword ) { |
|
337 | - $keyword = ltrim( rtrim( $keyword ) ); |
|
338 | - } |
|
339 | - |
|
340 | - $post_status = false; |
|
341 | - |
|
342 | - if ( in_array( 'publish', $keyphrases ) ) { |
|
343 | - $post_status = 'publish'; |
|
344 | - } |
|
345 | - if ( in_array( 'pending', $keyphrases ) ) { |
|
346 | - $post_status = 'pending'; |
|
347 | - } |
|
348 | - if ( in_array( 'draft', $keyphrases ) ) { |
|
349 | - $post_status = 'draft'; |
|
350 | - } |
|
351 | - if ( in_array( 'import', $keyphrases ) ) { |
|
352 | - $post_status = 'import'; |
|
353 | - } |
|
354 | - |
|
355 | - // If there is a post status use it. |
|
356 | - if ( false !== $post_status ) { |
|
357 | - |
|
358 | - $accommodation = array(); |
|
359 | - $current_accommodation = $this->find_current_accommodation( 'destination' ); |
|
360 | - if ( ! empty( $current_accommodation ) ) { |
|
361 | - foreach ( $current_accommodation as $cs_key => $ccs_id ) { |
|
362 | - $accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id ); |
|
363 | - } |
|
364 | - } |
|
365 | - |
|
366 | - // Run through each accommodation and use it. |
|
367 | - if ( ! empty( $accommodation ) ) { |
|
368 | - foreach ( $accommodation as $row_key => $row ) { |
|
369 | - $row['post_title'] = $row['name']; |
|
370 | - if ( 'import' === $post_status ) { |
|
371 | - if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) { |
|
372 | - $current_status = get_post_status( $row['post_id'] ); |
|
373 | - if ( 'draft' === $current_status ) { |
|
374 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key ); |
|
375 | - } |
|
376 | - } else { |
|
377 | - continue; |
|
378 | - } |
|
379 | - } else { |
|
380 | - if ( 0 === $row['post_id'] ) { |
|
381 | - continue; |
|
382 | - } else { |
|
383 | - $current_status = get_post_status( $row['post_id'] ); |
|
384 | - |
|
385 | - if ( $current_status !== $post_status ) { |
|
386 | - continue; |
|
387 | - } |
|
388 | - } |
|
389 | - $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key ); |
|
390 | - } |
|
391 | - } |
|
392 | - } |
|
393 | - } else { |
|
394 | - |
|
395 | - $key_string_search = implode( '+', $keyphrases ); |
|
396 | - $search_data = wp_remote_get( $this->url . '/Search/' . $key_string_search . '/?all=include' ); |
|
397 | - |
|
398 | - if ( ! is_wp_error( $search_data ) || ! empty( $search_data ) && isset( $search_data['response'] ) && isset( $search_data['response']['code'] ) && 200 === $search_data['response']['code'] ) { |
|
399 | - $search_data = json_decode( $search_data['body'], true ); |
|
400 | - foreach ( $search_data as $sdata_key => $sdata ) { |
|
401 | - |
|
402 | - if ( isset( $sdata['type'] ) && 'Destination' !== trim( $sdata['type'] ) && 'Area' !== trim( $sdata['type'] ) ) { |
|
403 | - continue; |
|
404 | - } |
|
405 | - |
|
406 | - $temp_id = $this->get_post_id_by_key_value( $sdata['id'] ); |
|
407 | - if ( false === $temp_id ) { |
|
408 | - $sdata['post_id'] = 0; |
|
409 | - $sdata['post_title'] = $sdata['name']; |
|
410 | - } else { |
|
411 | - $sdata['post_id'] = $temp_id; |
|
412 | - $sdata['post_title'] = get_the_title( $temp_id ); |
|
413 | - } |
|
414 | - $searched_items[ sanitize_title( $sdata['name'] ) . '-' . $sdata['id'] ] = $this->format_row( $sdata, $sdata_key ); |
|
415 | - } |
|
416 | - } |
|
417 | - } |
|
418 | - |
|
419 | - if ( false !== $searched_items ) { |
|
420 | - $return = implode( $searched_items ); |
|
421 | - } |
|
422 | - print_r( $return ); |
|
423 | - } else { |
|
424 | - echo esc_attr( 'None found' ); |
|
425 | - } |
|
426 | - die(); |
|
427 | - } |
|
428 | - |
|
429 | - public function prepare_row_attributes( $cs_key, $ccs_id ) { |
|
430 | - $row_item = array( |
|
431 | - 'id' => $cs_key, |
|
432 | - 'type' => 'Destination', |
|
433 | - 'name' => get_the_title( $ccs_id ), |
|
434 | - 'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ), |
|
435 | - 'post_id' => $ccs_id, |
|
436 | - ); |
|
437 | - return $row_item; |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * Formats the row for output on the screen. |
|
442 | - */ |
|
443 | - public function format_row( $row = false, $row_key = '' ) { |
|
444 | - if ( false !== $row ) { |
|
445 | - |
|
446 | - $status = 'import'; |
|
447 | - if ( 0 !== $row['post_id'] ) { |
|
448 | - $status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>'; |
|
449 | - } |
|
450 | - |
|
451 | - $row_html = ' |
|
307 | + // @codingStandardsIgnoreEnd |
|
308 | + |
|
309 | + if ( null !== $current_destination && ! empty( $current_destination ) ) { |
|
310 | + foreach ( $current_destination as $accom ) { |
|
311 | + $return[ $accom->meta_value ] = $accom; |
|
312 | + } |
|
313 | + } |
|
314 | + |
|
315 | + return $return; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Run through the accommodation grabbed from the DB. |
|
320 | + */ |
|
321 | + public function process_ajax_search() { |
|
322 | + $return = false; |
|
323 | + check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
324 | + if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && 'destination' === $_POST['type'] ) { |
|
325 | + |
|
326 | + $searched_items = false; |
|
327 | + if ( isset( $_POST['keyword'] ) ) { |
|
328 | + $keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) ); |
|
329 | + } else { |
|
330 | + $keyphrases = array( 0 ); |
|
331 | + } |
|
332 | + |
|
333 | + if ( ! is_array( $keyphrases ) ) { |
|
334 | + $keyphrases = array( $keyphrases ); |
|
335 | + } |
|
336 | + foreach ( $keyphrases as &$keyword ) { |
|
337 | + $keyword = ltrim( rtrim( $keyword ) ); |
|
338 | + } |
|
339 | + |
|
340 | + $post_status = false; |
|
341 | + |
|
342 | + if ( in_array( 'publish', $keyphrases ) ) { |
|
343 | + $post_status = 'publish'; |
|
344 | + } |
|
345 | + if ( in_array( 'pending', $keyphrases ) ) { |
|
346 | + $post_status = 'pending'; |
|
347 | + } |
|
348 | + if ( in_array( 'draft', $keyphrases ) ) { |
|
349 | + $post_status = 'draft'; |
|
350 | + } |
|
351 | + if ( in_array( 'import', $keyphrases ) ) { |
|
352 | + $post_status = 'import'; |
|
353 | + } |
|
354 | + |
|
355 | + // If there is a post status use it. |
|
356 | + if ( false !== $post_status ) { |
|
357 | + |
|
358 | + $accommodation = array(); |
|
359 | + $current_accommodation = $this->find_current_accommodation( 'destination' ); |
|
360 | + if ( ! empty( $current_accommodation ) ) { |
|
361 | + foreach ( $current_accommodation as $cs_key => $ccs_id ) { |
|
362 | + $accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id ); |
|
363 | + } |
|
364 | + } |
|
365 | + |
|
366 | + // Run through each accommodation and use it. |
|
367 | + if ( ! empty( $accommodation ) ) { |
|
368 | + foreach ( $accommodation as $row_key => $row ) { |
|
369 | + $row['post_title'] = $row['name']; |
|
370 | + if ( 'import' === $post_status ) { |
|
371 | + if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) { |
|
372 | + $current_status = get_post_status( $row['post_id'] ); |
|
373 | + if ( 'draft' === $current_status ) { |
|
374 | + $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key ); |
|
375 | + } |
|
376 | + } else { |
|
377 | + continue; |
|
378 | + } |
|
379 | + } else { |
|
380 | + if ( 0 === $row['post_id'] ) { |
|
381 | + continue; |
|
382 | + } else { |
|
383 | + $current_status = get_post_status( $row['post_id'] ); |
|
384 | + |
|
385 | + if ( $current_status !== $post_status ) { |
|
386 | + continue; |
|
387 | + } |
|
388 | + } |
|
389 | + $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key ); |
|
390 | + } |
|
391 | + } |
|
392 | + } |
|
393 | + } else { |
|
394 | + |
|
395 | + $key_string_search = implode( '+', $keyphrases ); |
|
396 | + $search_data = wp_remote_get( $this->url . '/Search/' . $key_string_search . '/?all=include' ); |
|
397 | + |
|
398 | + if ( ! is_wp_error( $search_data ) || ! empty( $search_data ) && isset( $search_data['response'] ) && isset( $search_data['response']['code'] ) && 200 === $search_data['response']['code'] ) { |
|
399 | + $search_data = json_decode( $search_data['body'], true ); |
|
400 | + foreach ( $search_data as $sdata_key => $sdata ) { |
|
401 | + |
|
402 | + if ( isset( $sdata['type'] ) && 'Destination' !== trim( $sdata['type'] ) && 'Area' !== trim( $sdata['type'] ) ) { |
|
403 | + continue; |
|
404 | + } |
|
405 | + |
|
406 | + $temp_id = $this->get_post_id_by_key_value( $sdata['id'] ); |
|
407 | + if ( false === $temp_id ) { |
|
408 | + $sdata['post_id'] = 0; |
|
409 | + $sdata['post_title'] = $sdata['name']; |
|
410 | + } else { |
|
411 | + $sdata['post_id'] = $temp_id; |
|
412 | + $sdata['post_title'] = get_the_title( $temp_id ); |
|
413 | + } |
|
414 | + $searched_items[ sanitize_title( $sdata['name'] ) . '-' . $sdata['id'] ] = $this->format_row( $sdata, $sdata_key ); |
|
415 | + } |
|
416 | + } |
|
417 | + } |
|
418 | + |
|
419 | + if ( false !== $searched_items ) { |
|
420 | + $return = implode( $searched_items ); |
|
421 | + } |
|
422 | + print_r( $return ); |
|
423 | + } else { |
|
424 | + echo esc_attr( 'None found' ); |
|
425 | + } |
|
426 | + die(); |
|
427 | + } |
|
428 | + |
|
429 | + public function prepare_row_attributes( $cs_key, $ccs_id ) { |
|
430 | + $row_item = array( |
|
431 | + 'id' => $cs_key, |
|
432 | + 'type' => 'Destination', |
|
433 | + 'name' => get_the_title( $ccs_id ), |
|
434 | + 'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ), |
|
435 | + 'post_id' => $ccs_id, |
|
436 | + ); |
|
437 | + return $row_item; |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * Formats the row for output on the screen. |
|
442 | + */ |
|
443 | + public function format_row( $row = false, $row_key = '' ) { |
|
444 | + if ( false !== $row ) { |
|
445 | + |
|
446 | + $status = 'import'; |
|
447 | + if ( 0 !== $row['post_id'] ) { |
|
448 | + $status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>'; |
|
449 | + } |
|
450 | + |
|
451 | + $row_html = ' |
|
452 | 452 | <tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '"> |
453 | 453 | <th class="check-column" scope="row"> |
454 | 454 | <label for="cb-select-' . $row['id'] . '" class="screen-reader-text">' . $row['name'] . '</label> |
@@ -467,273 +467,273 @@ discard block |
||
467 | 467 | ' . $row['id'] . ' |
468 | 468 | </td> |
469 | 469 | </tr>'; |
470 | - return $row_html; |
|
471 | - } |
|
472 | - } |
|
473 | - |
|
474 | - /** |
|
475 | - * Connect to wetu |
|
476 | - */ |
|
477 | - public function process_ajax_import() { |
|
478 | - $return = false; |
|
479 | - |
|
480 | - check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
481 | - if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && 'destination' === $_POST['type'] && isset( $_POST['wetu_id'] ) ) { |
|
482 | - |
|
483 | - $wetu_id = sanitize_text_field( $_POST['wetu_id'] ); |
|
484 | - |
|
485 | - if ( isset( $_POST['post_id'] ) ) { |
|
486 | - $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
487 | - $this->current_post = get_post( $post_id ); |
|
488 | - } else { |
|
489 | - $post_id = 0; |
|
490 | - } |
|
491 | - |
|
492 | - if ( isset( $_POST['team_members'] ) ) { |
|
493 | - $team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) ); |
|
494 | - } else { |
|
495 | - $team_members = false; |
|
496 | - } |
|
497 | - |
|
498 | - $safari_brands = false; |
|
499 | - |
|
500 | - delete_option( 'lsx_wetu_importer_destination_settings' ); |
|
501 | - |
|
502 | - if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) { |
|
503 | - $content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) ); |
|
504 | - add_option( 'lsx_wetu_importer_destination_settings', $content ); |
|
505 | - } else { |
|
506 | - $content = false; |
|
507 | - } |
|
508 | - |
|
509 | - $jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
510 | - |
|
511 | - if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) { |
|
512 | - $adata = json_decode( $jdata['body'], true ); |
|
513 | - $return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands ); |
|
514 | - $this->remove_from_queue( $return ); |
|
515 | - $this->format_completed_row( $return ); |
|
516 | - } else { |
|
517 | - $this->format_error( esc_html__( 'There was a problem importing your destination, please try refreshing the page.', 'lsx-wetu-importer' ) ); |
|
518 | - } |
|
519 | - } |
|
520 | - die(); |
|
521 | - } |
|
522 | - |
|
523 | - /** |
|
524 | - * Saves the queue to the option. |
|
525 | - */ |
|
526 | - public function remove_from_queue( $id ) { |
|
527 | - if ( ! empty( $this->queued_imports ) ) { |
|
528 | - $key = array_search( $id, $this->queued_imports ); |
|
529 | - if ( false !== $key ) { |
|
530 | - unset( $this->queued_imports[ $key ] ); |
|
531 | - |
|
532 | - delete_option( 'lsx_wetu_importer_que' ); |
|
533 | - update_option( 'lsx_wetu_importer_que', $this->queued_imports ); |
|
534 | - } |
|
535 | - } |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Connect to wetu |
|
540 | - */ |
|
541 | - public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false ) { |
|
542 | - if ( 'Destination' === trim( $data[0]['type'] ) || 'Area' === trim( $data[0]['type'] ) ) { |
|
543 | - $post_name = ''; |
|
544 | - $data_post_content = ''; |
|
545 | - $data_post_excerpt = ''; |
|
546 | - |
|
547 | - $post = array( |
|
548 | - 'post_type' => 'destination', |
|
549 | - ); |
|
550 | - |
|
551 | - if ( ! empty( $importable_content ) && in_array( 'country', $importable_content ) ) { |
|
552 | - $parent = $this->check_for_parent( $data ); |
|
553 | - if ( false !== $parent ) { |
|
554 | - $post['post_parent'] = $parent; |
|
555 | - } |
|
556 | - } |
|
557 | - |
|
558 | - // Set the post_content. |
|
559 | - if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) { |
|
560 | - if ( isset( $data[0]['content']['general_description'] ) ) { |
|
561 | - |
|
562 | - if ( in_array( 'strip_tags', $importable_content ) ) { |
|
563 | - $post['post_content'] = wp_strip_all_tags( $data[0]['content']['general_description'] ); |
|
564 | - } else { |
|
565 | - $post['post_content'] = $data[0]['content']['general_description']; |
|
566 | - } |
|
567 | - } |
|
568 | - } |
|
569 | - |
|
570 | - if ( false !== $id && '0' !== $id ) { |
|
571 | - $post['ID'] = $id; |
|
572 | - if ( isset( $this->options ) && 'on' !== $this->options['disable_destination_title'] && isset( $data[0]['name'] ) ) { |
|
573 | - $post['post_title'] = $data[0]['name']; |
|
574 | - $post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 ); |
|
575 | - } |
|
576 | - $post['post_status'] = 'publish'; |
|
577 | - |
|
578 | - $id = wp_update_post( $post ); |
|
579 | - $prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true ); |
|
580 | - update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date ); |
|
581 | - } else { |
|
582 | - // Set the name. |
|
583 | - if ( isset( $data[0]['name'] ) ) { |
|
584 | - $post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 ); |
|
585 | - } |
|
586 | - |
|
587 | - $post['post_name'] = $post_name; |
|
588 | - $post['post_title'] = $data[0]['name']; |
|
589 | - $post['post_status'] = 'publish'; |
|
590 | - $id = wp_insert_post( $post ); |
|
591 | - |
|
592 | - // Save the WETU ID and the Last date it was modified. |
|
593 | - if ( false !== $id ) { |
|
594 | - add_post_meta( $id, 'lsx_wetu_id', $wetu_id ); |
|
595 | - add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) ); |
|
596 | - } |
|
597 | - } |
|
598 | - |
|
599 | - $this->find_attachments( $id ); |
|
600 | - |
|
601 | - // Set the team member if it is there. |
|
602 | - if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) { |
|
603 | - $this->set_team_member( $id, $team_members ); |
|
604 | - } |
|
605 | - |
|
606 | - $this->set_map_data( $data, $id, 9 ); |
|
607 | - |
|
608 | - // Set the Room Data. |
|
609 | - if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) { |
|
610 | - $this->set_video_data( $data, $id ); |
|
611 | - } |
|
612 | - |
|
613 | - // Set the Electricity. |
|
614 | - if ( false !== $importable_content && in_array( 'electricity', $importable_content ) ) { |
|
615 | - $this->set_travel_info( $data, $id, 'electricity', $importable_content ); |
|
616 | - } |
|
617 | - // Set the cuisine. |
|
618 | - if ( false !== $importable_content && in_array( 'cuisine', $importable_content ) ) { |
|
619 | - $this->set_travel_info( $data, $id, 'cuisine', $importable_content ); |
|
620 | - } |
|
621 | - // Set the banking. |
|
622 | - if ( false !== $importable_content && in_array( 'banking', $importable_content ) ) { |
|
623 | - $this->set_travel_info( $data, $id, 'banking', $importable_content ); |
|
624 | - } |
|
625 | - // Set the transport. |
|
626 | - if ( false !== $importable_content && in_array( 'transport', $importable_content ) ) { |
|
627 | - $this->set_travel_info( $data, $id, 'transport', $importable_content ); |
|
628 | - } |
|
629 | - // Set the dress. |
|
630 | - if ( false !== $importable_content && in_array( 'dress', $importable_content ) ) { |
|
631 | - $this->set_travel_info( $data, $id, 'dress', $importable_content ); |
|
632 | - } |
|
633 | - // Set the climate. |
|
634 | - if ( false !== $importable_content && in_array( 'climate', $importable_content ) ) { |
|
635 | - $this->set_travel_info( $data, $id, 'climate', $importable_content ); |
|
636 | - } |
|
637 | - // Set the Health. |
|
638 | - if ( false !== $importable_content && in_array( 'health', $importable_content ) ) { |
|
639 | - $this->set_travel_info( $data, $id, 'health', $importable_content ); |
|
640 | - } |
|
641 | - // Set the Safety. |
|
642 | - if ( false !== $importable_content && in_array( 'safety', $importable_content ) ) { |
|
643 | - $this->set_travel_info( $data, $id, 'safety', $importable_content ); |
|
644 | - } |
|
645 | - // Set the Visa. |
|
646 | - if ( false !== $importable_content && in_array( 'visa', $importable_content ) ) { |
|
647 | - $this->set_travel_info( $data, $id, 'visa', $importable_content ); |
|
648 | - } |
|
649 | - // Set the General. |
|
650 | - if ( false !== $importable_content && in_array( 'additional_info', $importable_content ) ) { |
|
651 | - $this->set_travel_info( $data, $id, 'additional_info', $importable_content ); |
|
652 | - } |
|
653 | - |
|
654 | - // Setup some default for use in the import. |
|
655 | - if ( false !== $importable_content && ( in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content ) ) ) { |
|
656 | - $this->find_attachments( $id ); |
|
657 | - |
|
658 | - // Set the featured image. |
|
659 | - if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) { |
|
660 | - $this->set_featured_image( $data, $id ); |
|
661 | - } |
|
662 | - if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) { |
|
663 | - $this->set_banner_image( $data, $id, $importable_content ); |
|
664 | - } |
|
665 | - // Import the main gallery. |
|
666 | - if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) { |
|
667 | - $this->create_main_gallery( $data, $id ); |
|
668 | - } |
|
669 | - } |
|
670 | - |
|
671 | - // Set the continent. |
|
672 | - if ( false !== $importable_content && in_array( 'continent', $importable_content ) ) { |
|
673 | - $this->set_continent( $data, $id ); |
|
674 | - } |
|
675 | - } |
|
676 | - |
|
677 | - return $id; |
|
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * Saves the room data |
|
682 | - */ |
|
683 | - public function set_travel_info( $data, $id, $meta_key, $importable = array( 'none' ) ) { |
|
684 | - if ( ! empty( $data[0]['travel_information'] ) && isset( $data[0]['travel_information'][ $meta_key ] ) ) { |
|
685 | - $content = $data[0]['travel_information'][ $meta_key ]; |
|
686 | - |
|
687 | - if ( in_array( 'strip_tags', $importable ) ) { |
|
688 | - $content = strip_tags( $content ); |
|
689 | - } |
|
690 | - |
|
691 | - $this->save_custom_field( $content, $meta_key, $id ); |
|
692 | - } |
|
693 | - } |
|
694 | - |
|
695 | - /** |
|
696 | - * Set the Travel Style |
|
697 | - */ |
|
698 | - public function set_continent( $data, $id ) { |
|
699 | - |
|
700 | - if ( isset( $data[0]['position']['country'] ) && $data[0]['map_object_id'] === $data[0]['position']['country_content_entity_id'] ) { |
|
701 | - // Get the continent code. |
|
702 | - $country_code = to_country_data( $data[0]['position']['country'], false ); |
|
703 | - $continent_code = to_continent_code( $country_code ); |
|
704 | - $continent_label = to_continent_label( $continent_code ); |
|
705 | - |
|
706 | - if ( ! empty( tour_operator()->options['display']['enable_search_region_filter'] ) ) { |
|
707 | - $continent_label = to_continent_region_label( $country_code ); |
|
708 | - } |
|
709 | - |
|
710 | - if ( '' !== $continent_label ) { |
|
711 | - $term = term_exists( trim( $continent_label ), 'continent' ); |
|
712 | - if ( ! $term ) { |
|
713 | - $term = wp_insert_term( trim( $continent_label ), 'continent' ); |
|
714 | - |
|
715 | - if ( is_wp_error( $term ) ) { |
|
716 | - echo wp_kses_post( $term->get_error_message() ); |
|
717 | - } |
|
718 | - } else { |
|
719 | - wp_set_object_terms( $id, sanitize_title( $continent_label ), 'continent', true ); |
|
720 | - } |
|
721 | - } |
|
722 | - } |
|
723 | - } |
|
724 | - |
|
725 | - /** |
|
726 | - * Save the list of Accommodation into an option |
|
727 | - */ |
|
728 | - public function check_for_parent( $data = array() ) { |
|
729 | - global $wpdb; |
|
730 | - |
|
731 | - if ( $data[0]['position']['country_content_entity_id'] !== $data[0]['position']['destination_content_entity_id'] ) { |
|
732 | - $result = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'lsx_wetu_id' AND meta_value = '%s'", array( $data[0]['position']['country_content_entity_id'] ) ) ); |
|
733 | - if ( ! empty( $result ) && '' !== $result && false !== $result ) { |
|
734 | - return $result; |
|
735 | - } |
|
736 | - } |
|
737 | - return false; |
|
738 | - } |
|
470 | + return $row_html; |
|
471 | + } |
|
472 | + } |
|
473 | + |
|
474 | + /** |
|
475 | + * Connect to wetu |
|
476 | + */ |
|
477 | + public function process_ajax_import() { |
|
478 | + $return = false; |
|
479 | + |
|
480 | + check_ajax_referer( 'lsx_wetu_ajax_action', 'security' ); |
|
481 | + if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && 'destination' === $_POST['type'] && isset( $_POST['wetu_id'] ) ) { |
|
482 | + |
|
483 | + $wetu_id = sanitize_text_field( $_POST['wetu_id'] ); |
|
484 | + |
|
485 | + if ( isset( $_POST['post_id'] ) ) { |
|
486 | + $post_id = sanitize_text_field( $_POST['post_id'] ); |
|
487 | + $this->current_post = get_post( $post_id ); |
|
488 | + } else { |
|
489 | + $post_id = 0; |
|
490 | + } |
|
491 | + |
|
492 | + if ( isset( $_POST['team_members'] ) ) { |
|
493 | + $team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) ); |
|
494 | + } else { |
|
495 | + $team_members = false; |
|
496 | + } |
|
497 | + |
|
498 | + $safari_brands = false; |
|
499 | + |
|
500 | + delete_option( 'lsx_wetu_importer_destination_settings' ); |
|
501 | + |
|
502 | + if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) { |
|
503 | + $content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) ); |
|
504 | + add_option( 'lsx_wetu_importer_destination_settings', $content ); |
|
505 | + } else { |
|
506 | + $content = false; |
|
507 | + } |
|
508 | + |
|
509 | + $jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
510 | + |
|
511 | + if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) { |
|
512 | + $adata = json_decode( $jdata['body'], true ); |
|
513 | + $return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands ); |
|
514 | + $this->remove_from_queue( $return ); |
|
515 | + $this->format_completed_row( $return ); |
|
516 | + } else { |
|
517 | + $this->format_error( esc_html__( 'There was a problem importing your destination, please try refreshing the page.', 'lsx-wetu-importer' ) ); |
|
518 | + } |
|
519 | + } |
|
520 | + die(); |
|
521 | + } |
|
522 | + |
|
523 | + /** |
|
524 | + * Saves the queue to the option. |
|
525 | + */ |
|
526 | + public function remove_from_queue( $id ) { |
|
527 | + if ( ! empty( $this->queued_imports ) ) { |
|
528 | + $key = array_search( $id, $this->queued_imports ); |
|
529 | + if ( false !== $key ) { |
|
530 | + unset( $this->queued_imports[ $key ] ); |
|
531 | + |
|
532 | + delete_option( 'lsx_wetu_importer_que' ); |
|
533 | + update_option( 'lsx_wetu_importer_que', $this->queued_imports ); |
|
534 | + } |
|
535 | + } |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Connect to wetu |
|
540 | + */ |
|
541 | + public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false ) { |
|
542 | + if ( 'Destination' === trim( $data[0]['type'] ) || 'Area' === trim( $data[0]['type'] ) ) { |
|
543 | + $post_name = ''; |
|
544 | + $data_post_content = ''; |
|
545 | + $data_post_excerpt = ''; |
|
546 | + |
|
547 | + $post = array( |
|
548 | + 'post_type' => 'destination', |
|
549 | + ); |
|
550 | + |
|
551 | + if ( ! empty( $importable_content ) && in_array( 'country', $importable_content ) ) { |
|
552 | + $parent = $this->check_for_parent( $data ); |
|
553 | + if ( false !== $parent ) { |
|
554 | + $post['post_parent'] = $parent; |
|
555 | + } |
|
556 | + } |
|
557 | + |
|
558 | + // Set the post_content. |
|
559 | + if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) { |
|
560 | + if ( isset( $data[0]['content']['general_description'] ) ) { |
|
561 | + |
|
562 | + if ( in_array( 'strip_tags', $importable_content ) ) { |
|
563 | + $post['post_content'] = wp_strip_all_tags( $data[0]['content']['general_description'] ); |
|
564 | + } else { |
|
565 | + $post['post_content'] = $data[0]['content']['general_description']; |
|
566 | + } |
|
567 | + } |
|
568 | + } |
|
569 | + |
|
570 | + if ( false !== $id && '0' !== $id ) { |
|
571 | + $post['ID'] = $id; |
|
572 | + if ( isset( $this->options ) && 'on' !== $this->options['disable_destination_title'] && isset( $data[0]['name'] ) ) { |
|
573 | + $post['post_title'] = $data[0]['name']; |
|
574 | + $post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 ); |
|
575 | + } |
|
576 | + $post['post_status'] = 'publish'; |
|
577 | + |
|
578 | + $id = wp_update_post( $post ); |
|
579 | + $prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true ); |
|
580 | + update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date ); |
|
581 | + } else { |
|
582 | + // Set the name. |
|
583 | + if ( isset( $data[0]['name'] ) ) { |
|
584 | + $post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 ); |
|
585 | + } |
|
586 | + |
|
587 | + $post['post_name'] = $post_name; |
|
588 | + $post['post_title'] = $data[0]['name']; |
|
589 | + $post['post_status'] = 'publish'; |
|
590 | + $id = wp_insert_post( $post ); |
|
591 | + |
|
592 | + // Save the WETU ID and the Last date it was modified. |
|
593 | + if ( false !== $id ) { |
|
594 | + add_post_meta( $id, 'lsx_wetu_id', $wetu_id ); |
|
595 | + add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) ); |
|
596 | + } |
|
597 | + } |
|
598 | + |
|
599 | + $this->find_attachments( $id ); |
|
600 | + |
|
601 | + // Set the team member if it is there. |
|
602 | + if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) { |
|
603 | + $this->set_team_member( $id, $team_members ); |
|
604 | + } |
|
605 | + |
|
606 | + $this->set_map_data( $data, $id, 9 ); |
|
607 | + |
|
608 | + // Set the Room Data. |
|
609 | + if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) { |
|
610 | + $this->set_video_data( $data, $id ); |
|
611 | + } |
|
612 | + |
|
613 | + // Set the Electricity. |
|
614 | + if ( false !== $importable_content && in_array( 'electricity', $importable_content ) ) { |
|
615 | + $this->set_travel_info( $data, $id, 'electricity', $importable_content ); |
|
616 | + } |
|
617 | + // Set the cuisine. |
|
618 | + if ( false !== $importable_content && in_array( 'cuisine', $importable_content ) ) { |
|
619 | + $this->set_travel_info( $data, $id, 'cuisine', $importable_content ); |
|
620 | + } |
|
621 | + // Set the banking. |
|
622 | + if ( false !== $importable_content && in_array( 'banking', $importable_content ) ) { |
|
623 | + $this->set_travel_info( $data, $id, 'banking', $importable_content ); |
|
624 | + } |
|
625 | + // Set the transport. |
|
626 | + if ( false !== $importable_content && in_array( 'transport', $importable_content ) ) { |
|
627 | + $this->set_travel_info( $data, $id, 'transport', $importable_content ); |
|
628 | + } |
|
629 | + // Set the dress. |
|
630 | + if ( false !== $importable_content && in_array( 'dress', $importable_content ) ) { |
|
631 | + $this->set_travel_info( $data, $id, 'dress', $importable_content ); |
|
632 | + } |
|
633 | + // Set the climate. |
|
634 | + if ( false !== $importable_content && in_array( 'climate', $importable_content ) ) { |
|
635 | + $this->set_travel_info( $data, $id, 'climate', $importable_content ); |
|
636 | + } |
|
637 | + // Set the Health. |
|
638 | + if ( false !== $importable_content && in_array( 'health', $importable_content ) ) { |
|
639 | + $this->set_travel_info( $data, $id, 'health', $importable_content ); |
|
640 | + } |
|
641 | + // Set the Safety. |
|
642 | + if ( false !== $importable_content && in_array( 'safety', $importable_content ) ) { |
|
643 | + $this->set_travel_info( $data, $id, 'safety', $importable_content ); |
|
644 | + } |
|
645 | + // Set the Visa. |
|
646 | + if ( false !== $importable_content && in_array( 'visa', $importable_content ) ) { |
|
647 | + $this->set_travel_info( $data, $id, 'visa', $importable_content ); |
|
648 | + } |
|
649 | + // Set the General. |
|
650 | + if ( false !== $importable_content && in_array( 'additional_info', $importable_content ) ) { |
|
651 | + $this->set_travel_info( $data, $id, 'additional_info', $importable_content ); |
|
652 | + } |
|
653 | + |
|
654 | + // Setup some default for use in the import. |
|
655 | + if ( false !== $importable_content && ( in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content ) ) ) { |
|
656 | + $this->find_attachments( $id ); |
|
657 | + |
|
658 | + // Set the featured image. |
|
659 | + if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) { |
|
660 | + $this->set_featured_image( $data, $id ); |
|
661 | + } |
|
662 | + if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) { |
|
663 | + $this->set_banner_image( $data, $id, $importable_content ); |
|
664 | + } |
|
665 | + // Import the main gallery. |
|
666 | + if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) { |
|
667 | + $this->create_main_gallery( $data, $id ); |
|
668 | + } |
|
669 | + } |
|
670 | + |
|
671 | + // Set the continent. |
|
672 | + if ( false !== $importable_content && in_array( 'continent', $importable_content ) ) { |
|
673 | + $this->set_continent( $data, $id ); |
|
674 | + } |
|
675 | + } |
|
676 | + |
|
677 | + return $id; |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * Saves the room data |
|
682 | + */ |
|
683 | + public function set_travel_info( $data, $id, $meta_key, $importable = array( 'none' ) ) { |
|
684 | + if ( ! empty( $data[0]['travel_information'] ) && isset( $data[0]['travel_information'][ $meta_key ] ) ) { |
|
685 | + $content = $data[0]['travel_information'][ $meta_key ]; |
|
686 | + |
|
687 | + if ( in_array( 'strip_tags', $importable ) ) { |
|
688 | + $content = strip_tags( $content ); |
|
689 | + } |
|
690 | + |
|
691 | + $this->save_custom_field( $content, $meta_key, $id ); |
|
692 | + } |
|
693 | + } |
|
694 | + |
|
695 | + /** |
|
696 | + * Set the Travel Style |
|
697 | + */ |
|
698 | + public function set_continent( $data, $id ) { |
|
699 | + |
|
700 | + if ( isset( $data[0]['position']['country'] ) && $data[0]['map_object_id'] === $data[0]['position']['country_content_entity_id'] ) { |
|
701 | + // Get the continent code. |
|
702 | + $country_code = to_country_data( $data[0]['position']['country'], false ); |
|
703 | + $continent_code = to_continent_code( $country_code ); |
|
704 | + $continent_label = to_continent_label( $continent_code ); |
|
705 | + |
|
706 | + if ( ! empty( tour_operator()->options['display']['enable_search_region_filter'] ) ) { |
|
707 | + $continent_label = to_continent_region_label( $country_code ); |
|
708 | + } |
|
709 | + |
|
710 | + if ( '' !== $continent_label ) { |
|
711 | + $term = term_exists( trim( $continent_label ), 'continent' ); |
|
712 | + if ( ! $term ) { |
|
713 | + $term = wp_insert_term( trim( $continent_label ), 'continent' ); |
|
714 | + |
|
715 | + if ( is_wp_error( $term ) ) { |
|
716 | + echo wp_kses_post( $term->get_error_message() ); |
|
717 | + } |
|
718 | + } else { |
|
719 | + wp_set_object_terms( $id, sanitize_title( $continent_label ), 'continent', true ); |
|
720 | + } |
|
721 | + } |
|
722 | + } |
|
723 | + } |
|
724 | + |
|
725 | + /** |
|
726 | + * Save the list of Accommodation into an option |
|
727 | + */ |
|
728 | + public function check_for_parent( $data = array() ) { |
|
729 | + global $wpdb; |
|
730 | + |
|
731 | + if ( $data[0]['position']['country_content_entity_id'] !== $data[0]['position']['destination_content_entity_id'] ) { |
|
732 | + $result = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'lsx_wetu_id' AND meta_value = '%s'", array( $data[0]['position']['country_content_entity_id'] ) ) ); |
|
733 | + if ( ! empty( $result ) && '' !== $result && false !== $result ) { |
|
734 | + return $result; |
|
735 | + } |
|
736 | + } |
|
737 | + return false; |
|
738 | + } |
|
739 | 739 | } |