1 | <?php |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
2 | /** |
||
0 ignored issues
–
show
|
|||
3 | * @package LSX_WETU_Importer_Connect_Accommodation |
||
4 | * @author LightSpeed |
||
5 | * @license GPL-2.0+ |
||
6 | * @link |
||
7 | * @copyright 2016 LightSpeed |
||
8 | **/ |
||
0 ignored issues
–
show
|
|||
9 | |||
10 | class LSX_WETU_Importer_Connect_Accommodation extends LSX_WETU_Importer_Admin { |
||
0 ignored issues
–
show
The type
LSX_WETU_Importer_Admin was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
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() { |
||
0 ignored issues
–
show
|
|||
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 ] ) ) { |
||
0 ignored issues
–
show
|
|||
41 | $this->options = $temp_options[ $this->plugin_slug ]; |
||
0 ignored issues
–
show
|
|||
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 | } |
||
0 ignored issues
–
show
|
|||
50 | |||
51 | /** |
||
52 | * Display the importer administration screen |
||
53 | */ |
||
54 | public function display_page() { |
||
55 | global $post; |
||
56 | ?> |
||
57 | <div class="wrap"> |
||
58 | <h3><span class="dashicons dashicons-admin-multisite"></span> <?php esc_html_e( 'Connect your Accommodation', 'lsx-wetu-importer' ); ?></h3> |
||
59 | |||
60 | <form method="get" action="" id="connect-accommodation-filter"> |
||
61 | <input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr( $this->tab_slug ); ?>" /> |
||
62 | |||
63 | <p><?php esc_html_e( 'Below is a list of your accommodation that does not contain a WETU ID, but its Title matches a name in the WETU DB. Connecting it will all you to pull through information from WETU.', 'lsx-wetu-importer' ); ?></p> |
||
64 | |||
65 | <div class="ajax-loader-small" style="display:none;width:100%;text-align:center;"> |
||
66 | <img style="width:32px;" src="<?php echo esc_url( LSX_WETU_IMPORTER_URL . 'assets/images/ajaxloader.gif' ); ?>" /> |
||
67 | </div> |
||
68 | |||
69 | <?php |
||
70 | $loose_accommodation = $this->find_current_accommodation(); |
||
71 | ?> |
||
72 | <p><input class="button button-primary connect" type="button" value="<?php esc_html_e( 'Connect', 'lsx-wetu-importer' ); ?>" /></p> |
||
73 | <table class="wp-list-table widefat fixed posts"> |
||
74 | <?php $this->table_header(); ?> |
||
75 | |||
76 | <tbody> |
||
77 | <?php |
||
78 | if ( false !== $loose_accommodation ) { |
||
0 ignored issues
–
show
|
|||
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 ) { |
||
0 ignored issues
–
show
|
|||
91 | while ( $loose_accommodation_query->have_posts() ) { |
||
0 ignored issues
–
show
|
|||
92 | $loose_accommodation_query->the_post(); |
||
93 | |||
94 | foreach ( $accommodation as $row_key => $row ) { |
||
0 ignored issues
–
show
|
|||
95 | if ( stripos( ltrim( rtrim( $row->name ) ), $post->post_title ) !== false ) { |
||
0 ignored issues
–
show
|
|||
96 | $identifier = $row->id; |
||
97 | } else { |
||
98 | continue; |
||
99 | } |
||
100 | } |
||
101 | ?> |
||
102 | <tr class="post-<?php the_ID(); ?> type-accommodation status-none" id="post-<?php the_ID(); ?>"> |
||
103 | <th class="check-column" scope="row"> |
||
104 | <label for="cb-select-<?php the_ID(); ?>" class="screen-reader-text"><?php the_title(); ?></label> |
||
105 | <input type="checkbox" data-identifier="<?php echo esc_attr( $identifier ); ?>" value="<?php the_ID(); ?>" name="post[]" id="cb-select-<?php the_ID(); ?>"> |
||
106 | </th> |
||
107 | <td class="post-title page-title column-title"> |
||
108 | <strong><?php the_title(); ?></strong> - <a href="<?php echo esc_url( admin_url( '/post.php?post=' . $post->ID . '&action=edit' ) ); ?>" target="_blank"><?php echo esc_html( $post->post_status ); ?></a> |
||
109 | </td> |
||
110 | <td class="excerpt column-excerpt"> |
||
111 | <?php |
||
112 | echo wp_kses_post( strip_tags( get_the_excerpt() ) ); |
||
0 ignored issues
–
show
|
|||
113 | ?> |
||
114 | </td> |
||
115 | </tr> |
||
116 | <?php |
||
117 | } |
||
118 | } |
||
119 | } |
||
120 | ?> |
||
121 | </tbody> |
||
122 | |||
123 | <?php $this->table_footer(); ?> |
||
124 | |||
125 | </table> |
||
126 | |||
127 | <p><input class="button button-primary connect" type="button" value="<?php esc_html_e( 'Connect', 'lsx-wetu-importer' ); ?>" /></p> |
||
128 | |||
129 | </form> |
||
130 | |||
131 | <div style="display:none;" class="completed-list-wrapper"> |
||
132 | <h3><?php esc_html_e( 'Completed' ); ?></h3> |
||
133 | <ul> |
||
134 | </ul> |
||
135 | </div> |
||
136 | </div> |
||
137 | <?php |
||
138 | } |
||
0 ignored issues
–
show
|
|||
139 | |||
140 | /** |
||
141 | * The header of the item list |
||
142 | */ |
||
143 | public function table_header() { |
||
144 | ?> |
||
145 | <thead> |
||
146 | <tr> |
||
147 | <th style="" class="manage-column column-cb check-column" id="cb" scope="col"> |
||
148 | <label for="cb-select-all-1" class="screen-reader-text">Select All</label> |
||
149 | <input type="checkbox" id="cb-select-all-1"> |
||
150 | </th> |
||
151 | <th style="width:40%;" class="manage-column column-title " id="title" style="width:49%;" scope="col">Title</th> |
||
152 | <th style="width:40%;" class="manage-column column-date" id="date" style="width:49%;" scope="col">Excerpt</th> |
||
153 | </tr> |
||
154 | </thead> |
||
155 | <?php |
||
156 | } |
||
0 ignored issues
–
show
|
|||
157 | |||
158 | /** |
||
159 | * The footer of the item list |
||
160 | */ |
||
161 | public function table_footer() { |
||
162 | ?> |
||
163 | <tfoot> |
||
164 | <tr> |
||
165 | <th style="" class="manage-column column-cb check-column" id="cb" scope="col"> |
||
166 | <label for="cb-select-all-1" class="screen-reader-text">Select All</label> |
||
167 | <input type="checkbox" id="cb-select-all-1"> |
||
168 | </th> |
||
169 | <th style="width:40%;" class="manage-column column-title " id="title" style="width:49%;" scope="col">Title</th> |
||
170 | <th style="width:40%;" class="manage-column column-date" id="date" style="width:49%;" scope="col">Excerpt</th> |
||
171 | </tr> |
||
172 | </tfoot> |
||
173 | <?php |
||
174 | } |
||
0 ignored issues
–
show
|
|||
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; |
||
182 | |||
183 | $all_accommodation = $wpdb->get_results( |
||
0 ignored issues
–
show
|
|||
184 | " |
||
185 | SELECT ID |
||
186 | FROM {$wpdb->posts} |
||
187 | WHERE post_type = 'accommodation' |
||
188 | LIMIT 0,500 |
||
189 | ", |
||
190 | ARRAY_A |
||
191 | ); |
||
192 | |||
193 | $current_accommodation = $wpdb->get_results( |
||
0 ignored issues
–
show
|
|||
194 | " |
||
195 | SELECT key1.post_id |
||
196 | FROM {$wpdb->postmeta} key1 |
||
197 | |||
198 | INNER JOIN {$wpdb->posts} key2 |
||
199 | ON key1.post_id = key2.ID |
||
200 | |||
201 | WHERE key1.meta_key = 'lsx_wetu_id' |
||
202 | AND key2.post_type = 'accommodation' |
||
203 | |||
204 | LIMIT 0,500 |
||
205 | ", |
||
206 | ARRAY_A |
||
207 | ); |
||
208 | |||
209 | if ( null !== $all_accommodation && ! empty( $all_accommodation ) ) { |
||
0 ignored issues
–
show
|
|||
210 | // remove the extra accommodation |
||
0 ignored issues
–
show
|
|||
211 | if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) { |
||
0 ignored issues
–
show
|
|||
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 ) ) { |
||
0 ignored issues
–
show
|
|||
214 | $all_accommodation = $this->format_array( $current_accommodation, 'post_id' ); |
||
215 | } |
||
216 | |||
217 | $return = $all_accommodation; |
||
218 | } |
||
219 | |||
220 | return $return; |
||
221 | } |
||
0 ignored issues
–
show
|
|||
222 | |||
223 | /** |
||
0 ignored issues
–
show
|
|||
224 | * format the array |
||
0 ignored issues
–
show
|
|||
225 | */ |
||
226 | public function format_array( $array, $key ) { |
||
227 | $new_array = array(); |
||
228 | |||
229 | foreach ( $array as $value ) { |
||
0 ignored issues
–
show
|
|||
230 | $new_array[] = $value[ $key ]; |
||
231 | } |
||
232 | |||
233 | return $new_array; |
||
234 | } |
||
0 ignored issues
–
show
|
|||
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'] ) ) { |
||
0 ignored issues
–
show
|
|||
243 | $post_id = false; |
||
244 | $matching_id = false; |
||
245 | $post_id = sanitize_text_field( $_POST['post_id'] ); |
||
0 ignored issues
–
show
|
|||
246 | $matching_id = sanitize_text_field( $_POST['wetu_id'] ); |
||
0 ignored issues
–
show
|
|||
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 ); |
||
0 ignored issues
–
show
|
|||
253 | die(); |
||
0 ignored issues
–
show
|
|||
254 | } |
||
0 ignored issues
–
show
|
|||
255 | |||
256 | } |
||
257 | |||
258 | $lsx_wetu_importer_connect_accommodation = new LSX_WETU_Importer_Connect_Accommodation(); |
||
259 |