@@ -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,694 +558,694 @@ 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 { |
|
631 | + } |
|
632 | + } else { |
|
633 | 633 | ?> |
634 | 634 | <li><input class="team" type="checkbox" value="0" /> <?php esc_html_e( 'None', 'lsx-wetu-importer' ); ?></li> |
635 | 635 | <?php |
636 | 636 | } |
637 | - ?> |
|
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( array( |
|
849 | - 'taxonomy' => $taxonomy, |
|
850 | - 'hide_empty' => false, |
|
851 | - ) ); |
|
852 | - |
|
853 | - if ( ! is_wp_error( $terms ) ) { |
|
854 | - foreach ( $terms as $term ) { |
|
855 | - $return .= '<li><input class="' . $taxonomy . '" ' . $this->checked( $selected, $term->term_id, false ) . ' type="checkbox" value="' . $term->term_id . '" /> ' . $term->name . '</li>'; |
|
856 | - } |
|
857 | - } else { |
|
858 | - $return .= '<li><input type="checkbox" value="" /> ' . __( 'None', 'lsx-wetu-importer' ) . '</li>'; |
|
859 | - } |
|
860 | - |
|
861 | - $return .= '</ul>'; |
|
862 | - } |
|
863 | - |
|
864 | - return $return; |
|
865 | - } |
|
866 | - |
|
867 | - // MAP FUNCTIONS |
|
868 | - |
|
869 | - /** |
|
870 | - * Saves the longitude and lattitude, as well as sets the map marker. |
|
871 | - */ |
|
872 | - public function set_map_data( $data, $id, $zoom = '10' ) { |
|
873 | - $longitude = false; |
|
874 | - $latitude = false; |
|
875 | - $address = false; |
|
876 | - |
|
877 | - if ( isset( $data[0]['position'] ) ) { |
|
878 | - if ( isset( $data[0]['position']['driving_latitude'] ) ) { |
|
879 | - $latitude = $data[0]['position']['driving_latitude']; |
|
880 | - } elseif ( isset( $data[0]['position']['latitude'] ) ) { |
|
881 | - $latitude = $data[0]['position']['latitude']; |
|
882 | - } |
|
883 | - |
|
884 | - if ( isset( $data[0]['position']['driving_longitude'] ) ) { |
|
885 | - $longitude = $data[0]['position']['driving_longitude']; |
|
886 | - } elseif ( isset( $data[0]['position']['longitude'] ) ) { |
|
887 | - $longitude = $data[0]['position']['longitude']; |
|
888 | - } |
|
889 | - } |
|
890 | - |
|
891 | - if ( isset( $data[0]['content'] ) && isset( $data[0]['content']['contact_information'] ) ) { |
|
892 | - if ( isset( $data[0]['content']['contact_information']['address'] ) ) { |
|
893 | - $address = strip_tags( $data[0]['content']['contact_information']['address'] ); |
|
894 | - $address = explode( "\n", $address ); |
|
895 | - |
|
896 | - foreach ( $address as $bitkey => $bit ) { |
|
897 | - $bit = ltrim( rtrim( $bit ) ); |
|
898 | - |
|
899 | - if ( false === $bit || '' === $bit || null === $bit || empty( $bit ) ) { |
|
900 | - unset( $address[ $bitkey ] ); |
|
901 | - } |
|
902 | - } |
|
903 | - |
|
904 | - $address = implode( ', ', $address ); |
|
905 | - $address = str_replace( ', , ', ', ', $address ); |
|
906 | - } |
|
907 | - } |
|
908 | - |
|
909 | - if ( false !== $longitude ) { |
|
910 | - $location_data = array( |
|
911 | - 'address' => (string) $address, |
|
912 | - 'lat' => (string) $latitude, |
|
913 | - 'long' => (string) $longitude, |
|
914 | - 'zoom' => (string) $zoom, |
|
915 | - 'elevation' => '', |
|
916 | - ); |
|
917 | - |
|
918 | - if ( false !== $id && '0' !== $id ) { |
|
919 | - $prev = get_post_meta( $id, 'location', true ); |
|
920 | - update_post_meta( $id, 'location', $location_data, $prev ); |
|
921 | - } else { |
|
922 | - add_post_meta( $id, 'location', $location_data, true ); |
|
923 | - } |
|
924 | - } |
|
925 | - } |
|
926 | - |
|
927 | - // IMAGE FUNCTIONS |
|
928 | - |
|
929 | - /** |
|
930 | - * Creates the main gallery data |
|
931 | - */ |
|
932 | - public function set_featured_image( $data, $id ) { |
|
933 | - if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
934 | - $this->featured_image = $this->attach_image( $data[0]['content']['images'][0], $id, array( |
|
935 | - 'width' => '800', |
|
936 | - 'height' => '600', |
|
937 | - 'cropping' => 'h', |
|
938 | - ) ); |
|
939 | - |
|
940 | - if ( false !== $this->featured_image ) { |
|
941 | - delete_post_meta( $id, '_thumbnail_id' ); |
|
942 | - add_post_meta( $id, '_thumbnail_id', $this->featured_image, true ); |
|
943 | - } |
|
944 | - } |
|
945 | - } |
|
946 | - |
|
947 | - /** |
|
948 | - * Sets a banner image |
|
949 | - */ |
|
950 | - public function set_banner_image( $data, $id, $content = array( 'none' ) ) { |
|
951 | - if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
952 | - if ( in_array( 'unique_banner_image', $content ) && isset( $data[0]['destination_image'] ) && is_array( $data[0]['destination_image'] ) ) { |
|
953 | - $temp_banner = $this->attach_image( $data[0]['destination_image'], $id, array( |
|
954 | - 'width' => '1920', |
|
955 | - 'height' => '600', |
|
956 | - 'cropping' => 'c', |
|
957 | - )); |
|
958 | - } else { |
|
959 | - $temp_banner = $this->attach_image( $data[0]['content']['images'][1], $id, array( |
|
960 | - 'width' => '1920', |
|
961 | - 'height' => '600', |
|
962 | - 'cropping' => 'c', |
|
963 | - )); |
|
964 | - } |
|
965 | - |
|
966 | - if ( false !== $temp_banner ) { |
|
967 | - $this->banner_image = $temp_banner; |
|
968 | - |
|
969 | - delete_post_meta( $id, 'image_group' ); |
|
970 | - |
|
971 | - $new_banner = array( |
|
972 | - 'banner_image' => array( |
|
973 | - 'cmb-field-0' => $this->banner_image, |
|
974 | - ), |
|
975 | - ); |
|
976 | - |
|
977 | - add_post_meta( $id, 'image_group', $new_banner, true ); |
|
978 | - } |
|
979 | - } |
|
980 | - } |
|
981 | - |
|
982 | - /** |
|
983 | - * Creates the main gallery data |
|
984 | - */ |
|
985 | - public function create_main_gallery( $data, $id ) { |
|
986 | - if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
987 | - if ( isset( $this->options['image_replacing'] ) && 'on' === $this->options['image_replacing'] ) { |
|
988 | - $current_gallery = get_post_meta( $id, 'gallery', false ); |
|
989 | - |
|
990 | - if ( false !== $current_gallery && ! empty( $current_gallery ) ) { |
|
991 | - foreach ( $current_gallery as $g ) { |
|
992 | - delete_post_meta( $id, 'gallery', $g ); |
|
993 | - |
|
994 | - if ( 'attachment' === get_post_type( $g ) ) { |
|
995 | - wp_delete_attachment( $g, true ); |
|
996 | - } |
|
997 | - } |
|
998 | - } |
|
999 | - } |
|
1000 | - |
|
1001 | - $counter = 0; |
|
1002 | - |
|
1003 | - foreach ( $data[0]['content']['images'] as $image_data ) { |
|
1004 | - if ( ( 0 === $counter && false !== $this->featured_image ) || ( 1 === $counter && false !== $this->banner_image ) ) { |
|
1005 | - $counter++; |
|
1006 | - |
|
1007 | - if ( false !== $this->image_limit && false !== $this->image_limit ) { |
|
1008 | - $this->image_limit++; |
|
1009 | - } |
|
1010 | - |
|
1011 | - continue; |
|
1012 | - } |
|
1013 | - |
|
1014 | - if ( false !== $this->image_limit && $counter >= $this->image_limit ) { |
|
1015 | - continue; |
|
1016 | - } |
|
1017 | - |
|
1018 | - $this->gallery_meta[] = $this->attach_image( $image_data, $id ); |
|
1019 | - $counter++; |
|
1020 | - } |
|
1021 | - |
|
1022 | - if ( ! empty( $this->gallery_meta ) ) { |
|
1023 | - delete_post_meta( $id, 'gallery' ); |
|
1024 | - $this->gallery_meta = array_unique( $this->gallery_meta ); |
|
1025 | - |
|
1026 | - foreach ( $this->gallery_meta as $gallery_id ) { |
|
1027 | - if ( false !== $gallery_id && '' !== $gallery_id && ! is_array( $gallery_id ) ) { |
|
1028 | - add_post_meta( $id, 'gallery', $gallery_id, false ); |
|
1029 | - } |
|
1030 | - } |
|
1031 | - } |
|
1032 | - } |
|
1033 | - } |
|
1034 | - |
|
1035 | - /** |
|
1036 | - * search_form |
|
1037 | - */ |
|
1038 | - public function get_scaling_url( $args = array() ) { |
|
1039 | - $defaults = array( |
|
1040 | - 'width' => '1024', |
|
1041 | - 'height' => '768', |
|
1042 | - //'cropping' => 'w', |
|
1043 | - 'cropping' => 'h', |
|
1044 | - ); |
|
1045 | - |
|
1046 | - if ( false !== $this->options ) { |
|
1047 | - if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) { |
|
1048 | - $defaults['width'] = $this->options['width']; |
|
1049 | - } |
|
1050 | - |
|
1051 | - if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) { |
|
1052 | - $defaults['height'] = $this->options['height']; |
|
1053 | - } |
|
1054 | - |
|
1055 | - if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) { |
|
1056 | - $defaults['cropping'] = $this->options['cropping']; |
|
1057 | - } |
|
1058 | - } |
|
1059 | - |
|
1060 | - $args = wp_parse_args( $args, $defaults ); |
|
1061 | - $cropping = $args['cropping']; |
|
1062 | - $width = $args['width']; |
|
1063 | - $height = $args['height']; |
|
1064 | - |
|
1065 | - return 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/'; |
|
1066 | - } |
|
1067 | - |
|
1068 | - /** |
|
1069 | - * Attaches 1 image |
|
1070 | - */ |
|
1071 | - public function attach_image( $v = false, $parent_id, $image_sizes = false, $banner = false ) { |
|
1072 | - if ( false !== $v ) { |
|
1073 | - $temp_fragment = explode( '/', $v['url_fragment'] ); |
|
1074 | - $url_filename = $temp_fragment[ count( $temp_fragment ) - 1 ]; |
|
1075 | - $url_filename = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $url_filename ); |
|
1076 | - $url_filename = trim( $url_filename ); |
|
1077 | - $title = $url_filename; |
|
1078 | - $url_filename = str_replace( ' ', '_', $url_filename ); |
|
1079 | - |
|
1080 | - if ( ! isset( $this->options['image_replacing'] ) && in_array( $url_filename, $this->found_attachments ) ) { |
|
1081 | - return array_search( $url_filename, $this->found_attachments ); |
|
1082 | - } |
|
1083 | - |
|
1084 | - $postdata = array(); |
|
1085 | - |
|
1086 | - if ( empty( $v['label'] ) ) { |
|
1087 | - $v['label'] = ''; |
|
1088 | - } |
|
1089 | - |
|
1090 | - if ( ! empty( $v['description'] ) ) { |
|
1091 | - $desc = wp_strip_all_tags( $v['description'] ); |
|
1092 | - $posdata = array( |
|
1093 | - 'post_excerpt' => $desc, |
|
1094 | - ); |
|
1095 | - } |
|
1096 | - |
|
1097 | - if ( ! empty( $v['section'] ) ) { |
|
1098 | - $desc = wp_strip_all_tags( $v['section'] ); |
|
1099 | - $posdata = array( |
|
1100 | - 'post_excerpt' => $desc, |
|
1101 | - ); |
|
1102 | - } |
|
1103 | - |
|
1104 | - $attach_id = null; |
|
1105 | - // Resizor - add option to setting if required. |
|
1106 | - $fragment = str_replace( ' ', '%20', $v['url_fragment'] ); |
|
1107 | - $url = $this->get_scaling_url( $image_sizes ) . $fragment; |
|
1108 | - $attach_id = $this->attach_external_image2( $url, $parent_id, '', $v['label'], $postdata ); |
|
1109 | - if ( ! empty( $attach_id ) ) { |
|
1110 | - $this->found_attachments[ $attach_id ] = $url_filename; |
|
1111 | - add_post_meta( $attach_id, 'lsx_wetu_id', $v['url_fragment'], true ); |
|
1112 | - return $attach_id; |
|
1113 | - } |
|
1114 | - } |
|
1115 | - return false; |
|
1116 | - } |
|
1117 | - |
|
1118 | - public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
|
1119 | - if ( ! $url || ! $post_id ) { |
|
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( array( |
|
849 | + 'taxonomy' => $taxonomy, |
|
850 | + 'hide_empty' => false, |
|
851 | + ) ); |
|
852 | + |
|
853 | + if ( ! is_wp_error( $terms ) ) { |
|
854 | + foreach ( $terms as $term ) { |
|
855 | + $return .= '<li><input class="' . $taxonomy . '" ' . $this->checked( $selected, $term->term_id, false ) . ' type="checkbox" value="' . $term->term_id . '" /> ' . $term->name . '</li>'; |
|
856 | + } |
|
857 | + } else { |
|
858 | + $return .= '<li><input type="checkbox" value="" /> ' . __( 'None', 'lsx-wetu-importer' ) . '</li>'; |
|
859 | + } |
|
860 | + |
|
861 | + $return .= '</ul>'; |
|
862 | + } |
|
863 | + |
|
864 | + return $return; |
|
865 | + } |
|
866 | + |
|
867 | + // MAP FUNCTIONS |
|
868 | + |
|
869 | + /** |
|
870 | + * Saves the longitude and lattitude, as well as sets the map marker. |
|
871 | + */ |
|
872 | + public function set_map_data( $data, $id, $zoom = '10' ) { |
|
873 | + $longitude = false; |
|
874 | + $latitude = false; |
|
875 | + $address = false; |
|
876 | + |
|
877 | + if ( isset( $data[0]['position'] ) ) { |
|
878 | + if ( isset( $data[0]['position']['driving_latitude'] ) ) { |
|
879 | + $latitude = $data[0]['position']['driving_latitude']; |
|
880 | + } elseif ( isset( $data[0]['position']['latitude'] ) ) { |
|
881 | + $latitude = $data[0]['position']['latitude']; |
|
882 | + } |
|
883 | + |
|
884 | + if ( isset( $data[0]['position']['driving_longitude'] ) ) { |
|
885 | + $longitude = $data[0]['position']['driving_longitude']; |
|
886 | + } elseif ( isset( $data[0]['position']['longitude'] ) ) { |
|
887 | + $longitude = $data[0]['position']['longitude']; |
|
888 | + } |
|
889 | + } |
|
890 | + |
|
891 | + if ( isset( $data[0]['content'] ) && isset( $data[0]['content']['contact_information'] ) ) { |
|
892 | + if ( isset( $data[0]['content']['contact_information']['address'] ) ) { |
|
893 | + $address = strip_tags( $data[0]['content']['contact_information']['address'] ); |
|
894 | + $address = explode( "\n", $address ); |
|
895 | + |
|
896 | + foreach ( $address as $bitkey => $bit ) { |
|
897 | + $bit = ltrim( rtrim( $bit ) ); |
|
898 | + |
|
899 | + if ( false === $bit || '' === $bit || null === $bit || empty( $bit ) ) { |
|
900 | + unset( $address[ $bitkey ] ); |
|
901 | + } |
|
902 | + } |
|
903 | + |
|
904 | + $address = implode( ', ', $address ); |
|
905 | + $address = str_replace( ', , ', ', ', $address ); |
|
906 | + } |
|
907 | + } |
|
908 | + |
|
909 | + if ( false !== $longitude ) { |
|
910 | + $location_data = array( |
|
911 | + 'address' => (string) $address, |
|
912 | + 'lat' => (string) $latitude, |
|
913 | + 'long' => (string) $longitude, |
|
914 | + 'zoom' => (string) $zoom, |
|
915 | + 'elevation' => '', |
|
916 | + ); |
|
917 | + |
|
918 | + if ( false !== $id && '0' !== $id ) { |
|
919 | + $prev = get_post_meta( $id, 'location', true ); |
|
920 | + update_post_meta( $id, 'location', $location_data, $prev ); |
|
921 | + } else { |
|
922 | + add_post_meta( $id, 'location', $location_data, true ); |
|
923 | + } |
|
924 | + } |
|
925 | + } |
|
926 | + |
|
927 | + // IMAGE FUNCTIONS |
|
928 | + |
|
929 | + /** |
|
930 | + * Creates the main gallery data |
|
931 | + */ |
|
932 | + public function set_featured_image( $data, $id ) { |
|
933 | + if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
934 | + $this->featured_image = $this->attach_image( $data[0]['content']['images'][0], $id, array( |
|
935 | + 'width' => '800', |
|
936 | + 'height' => '600', |
|
937 | + 'cropping' => 'h', |
|
938 | + ) ); |
|
939 | + |
|
940 | + if ( false !== $this->featured_image ) { |
|
941 | + delete_post_meta( $id, '_thumbnail_id' ); |
|
942 | + add_post_meta( $id, '_thumbnail_id', $this->featured_image, true ); |
|
943 | + } |
|
944 | + } |
|
945 | + } |
|
946 | + |
|
947 | + /** |
|
948 | + * Sets a banner image |
|
949 | + */ |
|
950 | + public function set_banner_image( $data, $id, $content = array( 'none' ) ) { |
|
951 | + if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
952 | + if ( in_array( 'unique_banner_image', $content ) && isset( $data[0]['destination_image'] ) && is_array( $data[0]['destination_image'] ) ) { |
|
953 | + $temp_banner = $this->attach_image( $data[0]['destination_image'], $id, array( |
|
954 | + 'width' => '1920', |
|
955 | + 'height' => '600', |
|
956 | + 'cropping' => 'c', |
|
957 | + )); |
|
958 | + } else { |
|
959 | + $temp_banner = $this->attach_image( $data[0]['content']['images'][1], $id, array( |
|
960 | + 'width' => '1920', |
|
961 | + 'height' => '600', |
|
962 | + 'cropping' => 'c', |
|
963 | + )); |
|
964 | + } |
|
965 | + |
|
966 | + if ( false !== $temp_banner ) { |
|
967 | + $this->banner_image = $temp_banner; |
|
968 | + |
|
969 | + delete_post_meta( $id, 'image_group' ); |
|
970 | + |
|
971 | + $new_banner = array( |
|
972 | + 'banner_image' => array( |
|
973 | + 'cmb-field-0' => $this->banner_image, |
|
974 | + ), |
|
975 | + ); |
|
976 | + |
|
977 | + add_post_meta( $id, 'image_group', $new_banner, true ); |
|
978 | + } |
|
979 | + } |
|
980 | + } |
|
981 | + |
|
982 | + /** |
|
983 | + * Creates the main gallery data |
|
984 | + */ |
|
985 | + public function create_main_gallery( $data, $id ) { |
|
986 | + if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
987 | + if ( isset( $this->options['image_replacing'] ) && 'on' === $this->options['image_replacing'] ) { |
|
988 | + $current_gallery = get_post_meta( $id, 'gallery', false ); |
|
989 | + |
|
990 | + if ( false !== $current_gallery && ! empty( $current_gallery ) ) { |
|
991 | + foreach ( $current_gallery as $g ) { |
|
992 | + delete_post_meta( $id, 'gallery', $g ); |
|
993 | + |
|
994 | + if ( 'attachment' === get_post_type( $g ) ) { |
|
995 | + wp_delete_attachment( $g, true ); |
|
996 | + } |
|
997 | + } |
|
998 | + } |
|
999 | + } |
|
1000 | + |
|
1001 | + $counter = 0; |
|
1002 | + |
|
1003 | + foreach ( $data[0]['content']['images'] as $image_data ) { |
|
1004 | + if ( ( 0 === $counter && false !== $this->featured_image ) || ( 1 === $counter && false !== $this->banner_image ) ) { |
|
1005 | + $counter++; |
|
1006 | + |
|
1007 | + if ( false !== $this->image_limit && false !== $this->image_limit ) { |
|
1008 | + $this->image_limit++; |
|
1009 | + } |
|
1010 | + |
|
1011 | + continue; |
|
1012 | + } |
|
1013 | + |
|
1014 | + if ( false !== $this->image_limit && $counter >= $this->image_limit ) { |
|
1015 | + continue; |
|
1016 | + } |
|
1017 | + |
|
1018 | + $this->gallery_meta[] = $this->attach_image( $image_data, $id ); |
|
1019 | + $counter++; |
|
1020 | + } |
|
1021 | + |
|
1022 | + if ( ! empty( $this->gallery_meta ) ) { |
|
1023 | + delete_post_meta( $id, 'gallery' ); |
|
1024 | + $this->gallery_meta = array_unique( $this->gallery_meta ); |
|
1025 | + |
|
1026 | + foreach ( $this->gallery_meta as $gallery_id ) { |
|
1027 | + if ( false !== $gallery_id && '' !== $gallery_id && ! is_array( $gallery_id ) ) { |
|
1028 | + add_post_meta( $id, 'gallery', $gallery_id, false ); |
|
1029 | + } |
|
1030 | + } |
|
1031 | + } |
|
1032 | + } |
|
1033 | + } |
|
1034 | + |
|
1035 | + /** |
|
1036 | + * search_form |
|
1037 | + */ |
|
1038 | + public function get_scaling_url( $args = array() ) { |
|
1039 | + $defaults = array( |
|
1040 | + 'width' => '1024', |
|
1041 | + 'height' => '768', |
|
1042 | + //'cropping' => 'w', |
|
1043 | + 'cropping' => 'h', |
|
1044 | + ); |
|
1045 | + |
|
1046 | + if ( false !== $this->options ) { |
|
1047 | + if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) { |
|
1048 | + $defaults['width'] = $this->options['width']; |
|
1049 | + } |
|
1050 | + |
|
1051 | + if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) { |
|
1052 | + $defaults['height'] = $this->options['height']; |
|
1053 | + } |
|
1054 | + |
|
1055 | + if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) { |
|
1056 | + $defaults['cropping'] = $this->options['cropping']; |
|
1057 | + } |
|
1058 | + } |
|
1059 | + |
|
1060 | + $args = wp_parse_args( $args, $defaults ); |
|
1061 | + $cropping = $args['cropping']; |
|
1062 | + $width = $args['width']; |
|
1063 | + $height = $args['height']; |
|
1064 | + |
|
1065 | + return 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/'; |
|
1066 | + } |
|
1067 | + |
|
1068 | + /** |
|
1069 | + * Attaches 1 image |
|
1070 | + */ |
|
1071 | + public function attach_image( $v = false, $parent_id, $image_sizes = false, $banner = false ) { |
|
1072 | + if ( false !== $v ) { |
|
1073 | + $temp_fragment = explode( '/', $v['url_fragment'] ); |
|
1074 | + $url_filename = $temp_fragment[ count( $temp_fragment ) - 1 ]; |
|
1075 | + $url_filename = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $url_filename ); |
|
1076 | + $url_filename = trim( $url_filename ); |
|
1077 | + $title = $url_filename; |
|
1078 | + $url_filename = str_replace( ' ', '_', $url_filename ); |
|
1079 | + |
|
1080 | + if ( ! isset( $this->options['image_replacing'] ) && in_array( $url_filename, $this->found_attachments ) ) { |
|
1081 | + return array_search( $url_filename, $this->found_attachments ); |
|
1082 | + } |
|
1083 | + |
|
1084 | + $postdata = array(); |
|
1085 | + |
|
1086 | + if ( empty( $v['label'] ) ) { |
|
1087 | + $v['label'] = ''; |
|
1088 | + } |
|
1089 | + |
|
1090 | + if ( ! empty( $v['description'] ) ) { |
|
1091 | + $desc = wp_strip_all_tags( $v['description'] ); |
|
1092 | + $posdata = array( |
|
1093 | + 'post_excerpt' => $desc, |
|
1094 | + ); |
|
1095 | + } |
|
1096 | + |
|
1097 | + if ( ! empty( $v['section'] ) ) { |
|
1098 | + $desc = wp_strip_all_tags( $v['section'] ); |
|
1099 | + $posdata = array( |
|
1100 | + 'post_excerpt' => $desc, |
|
1101 | + ); |
|
1102 | + } |
|
1103 | + |
|
1104 | + $attach_id = null; |
|
1105 | + // Resizor - add option to setting if required. |
|
1106 | + $fragment = str_replace( ' ', '%20', $v['url_fragment'] ); |
|
1107 | + $url = $this->get_scaling_url( $image_sizes ) . $fragment; |
|
1108 | + $attach_id = $this->attach_external_image2( $url, $parent_id, '', $v['label'], $postdata ); |
|
1109 | + if ( ! empty( $attach_id ) ) { |
|
1110 | + $this->found_attachments[ $attach_id ] = $url_filename; |
|
1111 | + add_post_meta( $attach_id, 'lsx_wetu_id', $v['url_fragment'], true ); |
|
1112 | + return $attach_id; |
|
1113 | + } |
|
1114 | + } |
|
1115 | + return false; |
|
1116 | + } |
|
1117 | + |
|
1118 | + public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
|
1119 | + if ( ! $url || ! $post_id ) { |
|
1120 | 1120 | return new WP_Error( 'missing', 'Need a valid URL and post ID...' ); } |
1121 | - $att_id = false; |
|
1122 | - |
|
1123 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
1124 | - require_once( ABSPATH . 'wp-admin/includes/media.php' ); |
|
1125 | - require_once( ABSPATH . 'wp-admin/includes/image.php' ); |
|
1126 | - // Download file to temp location, returns full server path to temp file. |
|
1127 | - |
|
1128 | - $tmp = tempnam( '/tmp', 'FOO' ); |
|
1129 | - $image = wp_remote_get( $url ); |
|
1130 | - if ( ! is_wp_error( $image ) && ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) { |
|
1131 | - file_put_contents( $tmp, $image['body'] ); |
|
1132 | - chmod( $tmp, '777' ); |
|
1133 | - |
|
1134 | - 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 |
|
1135 | - $url_filename = basename( $matches[0] ); |
|
1136 | - $url_filename = str_replace( '%20', '_', $url_filename ); |
|
1137 | - // extract filename from url for title |
|
1138 | - $url_type = wp_check_filetype( $url_filename ); // determine file type (ext and mime/type) |
|
1139 | - |
|
1140 | - // override filename if given, reconstruct server path. |
|
1141 | - if ( ! empty( $filename ) && ' ' != $filename ) { |
|
1142 | - $filename = sanitize_file_name( $filename ); |
|
1143 | - $tmppath = pathinfo( $tmp ); |
|
1144 | - |
|
1145 | - $extension = ''; |
|
1146 | - if ( isset( $tmppath['extension'] ) ) { |
|
1147 | - $extension = $tmppath['extension']; |
|
1148 | - } |
|
1149 | - |
|
1150 | - $new = $tmppath['dirname'] . '/' . $filename . '.' . $extension; |
|
1151 | - rename( $tmp, $new ); // renames temp file on server |
|
1152 | - $tmp = $new; // push new filename (in path) to be used in file array later |
|
1153 | - } |
|
1154 | - |
|
1155 | - // assemble file data (should be built like $_FILES since wp_handle_sideload() will be using). |
|
1156 | - $file_array['tmp_name'] = $tmp; // full server path to temp file |
|
1157 | - |
|
1158 | - if ( ! empty( $filename ) && ' ' != $filename ) { |
|
1159 | - $file_array['name'] = $filename . '.' . $url_type['ext']; // user given filename for title, add original URL extension |
|
1160 | - } else { |
|
1161 | - $file_array['name'] = $url_filename; // just use original URL filename |
|
1162 | - } |
|
1163 | - |
|
1164 | - // set additional wp_posts columns. |
|
1165 | - if ( empty( $post_data['post_title'] ) ) { |
|
1166 | - |
|
1167 | - $url_filename = str_replace( '%20', ' ', $url_filename ); |
|
1168 | - |
|
1169 | - $post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] ); // just use the original filename (no extension) |
|
1170 | - } |
|
1171 | - |
|
1172 | - // make sure gets tied to parent. |
|
1173 | - if ( empty( $post_data['post_parent'] ) ) { |
|
1174 | - $post_data['post_parent'] = $post_id; |
|
1175 | - } |
|
1176 | - |
|
1177 | - // do the validation and storage stuff. |
|
1178 | - $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 |
|
1179 | - |
|
1180 | - // If error storing permanently, unlink. |
|
1181 | - if ( is_wp_error( $att_id ) ) { |
|
1182 | - unlink( $file_array['tmp_name'] ); |
|
1183 | - return false; |
|
1184 | - } |
|
1185 | - } |
|
1186 | - return $att_id; |
|
1187 | - } |
|
1188 | - |
|
1189 | - // AJAX FUNCTIONS |
|
1190 | - /** |
|
1191 | - * Run through the accommodation grabbed from the DB. |
|
1192 | - */ |
|
1193 | - public function process_ajax_search() { |
|
1194 | - $this->current_importer->process_ajax_search(); |
|
1195 | - die(); |
|
1196 | - } |
|
1197 | - |
|
1198 | - /** |
|
1199 | - * Connect to wetu |
|
1200 | - */ |
|
1201 | - public function process_ajax_import() { |
|
1202 | - $this->current_importer->process_ajax_import(); |
|
1203 | - die(); |
|
1204 | - } |
|
1205 | - |
|
1206 | - /** |
|
1207 | - * Formats the row for the completed list. |
|
1208 | - */ |
|
1209 | - public function format_completed_row( $response ) { |
|
1210 | - 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>' ); |
|
1211 | - } |
|
1212 | - |
|
1213 | - /** |
|
1214 | - * Formats the error. |
|
1215 | - */ |
|
1216 | - public function format_error( $response ) { |
|
1217 | - echo wp_kses_post( '<li class="post-error"><span class="dashicons dashicons-no"></span>' . $response . '</li>' ); |
|
1218 | - } |
|
1219 | - |
|
1220 | - /** |
|
1221 | - * Does a multine search |
|
1222 | - */ |
|
1223 | - public function multineedle_stripos( $haystack, $needles, $offset = 0 ) { |
|
1224 | - $found = false; |
|
1225 | - $needle_count = count( $needles ); |
|
1226 | - |
|
1227 | - foreach ( $needles as $needle ) { |
|
1228 | - if ( false !== stripos( $haystack, $needle, $offset ) ) { |
|
1229 | - $found[] = true; |
|
1230 | - } |
|
1231 | - } |
|
1232 | - |
|
1233 | - if ( false !== $found && count( $found ) === $needle_count ) { |
|
1234 | - return true; |
|
1235 | - } else { |
|
1236 | - return false; |
|
1237 | - } |
|
1238 | - } |
|
1239 | - |
|
1240 | - /** |
|
1241 | - * Grab all the current accommodation posts via the lsx_wetu_id field. |
|
1242 | - */ |
|
1243 | - public function find_current_accommodation( $post_type = 'accommodation' ) { |
|
1244 | - global $wpdb; |
|
1245 | - $return = array(); |
|
1246 | - |
|
1247 | - // @codingStandardsIgnoreStart |
|
1248 | - $current_accommodation = $wpdb->get_results(" |
|
1121 | + $att_id = false; |
|
1122 | + |
|
1123 | + require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
1124 | + require_once( ABSPATH . 'wp-admin/includes/media.php' ); |
|
1125 | + require_once( ABSPATH . 'wp-admin/includes/image.php' ); |
|
1126 | + // Download file to temp location, returns full server path to temp file. |
|
1127 | + |
|
1128 | + $tmp = tempnam( '/tmp', 'FOO' ); |
|
1129 | + $image = wp_remote_get( $url ); |
|
1130 | + if ( ! is_wp_error( $image ) && ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) { |
|
1131 | + file_put_contents( $tmp, $image['body'] ); |
|
1132 | + chmod( $tmp, '777' ); |
|
1133 | + |
|
1134 | + 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 |
|
1135 | + $url_filename = basename( $matches[0] ); |
|
1136 | + $url_filename = str_replace( '%20', '_', $url_filename ); |
|
1137 | + // extract filename from url for title |
|
1138 | + $url_type = wp_check_filetype( $url_filename ); // determine file type (ext and mime/type) |
|
1139 | + |
|
1140 | + // override filename if given, reconstruct server path. |
|
1141 | + if ( ! empty( $filename ) && ' ' != $filename ) { |
|
1142 | + $filename = sanitize_file_name( $filename ); |
|
1143 | + $tmppath = pathinfo( $tmp ); |
|
1144 | + |
|
1145 | + $extension = ''; |
|
1146 | + if ( isset( $tmppath['extension'] ) ) { |
|
1147 | + $extension = $tmppath['extension']; |
|
1148 | + } |
|
1149 | + |
|
1150 | + $new = $tmppath['dirname'] . '/' . $filename . '.' . $extension; |
|
1151 | + rename( $tmp, $new ); // renames temp file on server |
|
1152 | + $tmp = $new; // push new filename (in path) to be used in file array later |
|
1153 | + } |
|
1154 | + |
|
1155 | + // assemble file data (should be built like $_FILES since wp_handle_sideload() will be using). |
|
1156 | + $file_array['tmp_name'] = $tmp; // full server path to temp file |
|
1157 | + |
|
1158 | + if ( ! empty( $filename ) && ' ' != $filename ) { |
|
1159 | + $file_array['name'] = $filename . '.' . $url_type['ext']; // user given filename for title, add original URL extension |
|
1160 | + } else { |
|
1161 | + $file_array['name'] = $url_filename; // just use original URL filename |
|
1162 | + } |
|
1163 | + |
|
1164 | + // set additional wp_posts columns. |
|
1165 | + if ( empty( $post_data['post_title'] ) ) { |
|
1166 | + |
|
1167 | + $url_filename = str_replace( '%20', ' ', $url_filename ); |
|
1168 | + |
|
1169 | + $post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] ); // just use the original filename (no extension) |
|
1170 | + } |
|
1171 | + |
|
1172 | + // make sure gets tied to parent. |
|
1173 | + if ( empty( $post_data['post_parent'] ) ) { |
|
1174 | + $post_data['post_parent'] = $post_id; |
|
1175 | + } |
|
1176 | + |
|
1177 | + // do the validation and storage stuff. |
|
1178 | + $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 |
|
1179 | + |
|
1180 | + // If error storing permanently, unlink. |
|
1181 | + if ( is_wp_error( $att_id ) ) { |
|
1182 | + unlink( $file_array['tmp_name'] ); |
|
1183 | + return false; |
|
1184 | + } |
|
1185 | + } |
|
1186 | + return $att_id; |
|
1187 | + } |
|
1188 | + |
|
1189 | + // AJAX FUNCTIONS |
|
1190 | + /** |
|
1191 | + * Run through the accommodation grabbed from the DB. |
|
1192 | + */ |
|
1193 | + public function process_ajax_search() { |
|
1194 | + $this->current_importer->process_ajax_search(); |
|
1195 | + die(); |
|
1196 | + } |
|
1197 | + |
|
1198 | + /** |
|
1199 | + * Connect to wetu |
|
1200 | + */ |
|
1201 | + public function process_ajax_import() { |
|
1202 | + $this->current_importer->process_ajax_import(); |
|
1203 | + die(); |
|
1204 | + } |
|
1205 | + |
|
1206 | + /** |
|
1207 | + * Formats the row for the completed list. |
|
1208 | + */ |
|
1209 | + public function format_completed_row( $response ) { |
|
1210 | + 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>' ); |
|
1211 | + } |
|
1212 | + |
|
1213 | + /** |
|
1214 | + * Formats the error. |
|
1215 | + */ |
|
1216 | + public function format_error( $response ) { |
|
1217 | + echo wp_kses_post( '<li class="post-error"><span class="dashicons dashicons-no"></span>' . $response . '</li>' ); |
|
1218 | + } |
|
1219 | + |
|
1220 | + /** |
|
1221 | + * Does a multine search |
|
1222 | + */ |
|
1223 | + public function multineedle_stripos( $haystack, $needles, $offset = 0 ) { |
|
1224 | + $found = false; |
|
1225 | + $needle_count = count( $needles ); |
|
1226 | + |
|
1227 | + foreach ( $needles as $needle ) { |
|
1228 | + if ( false !== stripos( $haystack, $needle, $offset ) ) { |
|
1229 | + $found[] = true; |
|
1230 | + } |
|
1231 | + } |
|
1232 | + |
|
1233 | + if ( false !== $found && count( $found ) === $needle_count ) { |
|
1234 | + return true; |
|
1235 | + } else { |
|
1236 | + return false; |
|
1237 | + } |
|
1238 | + } |
|
1239 | + |
|
1240 | + /** |
|
1241 | + * Grab all the current accommodation posts via the lsx_wetu_id field. |
|
1242 | + */ |
|
1243 | + public function find_current_accommodation( $post_type = 'accommodation' ) { |
|
1244 | + global $wpdb; |
|
1245 | + $return = array(); |
|
1246 | + |
|
1247 | + // @codingStandardsIgnoreStart |
|
1248 | + $current_accommodation = $wpdb->get_results(" |
|
1249 | 1249 | SELECT key1.post_id,key1.meta_value |
1250 | 1250 | FROM {$wpdb->postmeta} key1 |
1251 | 1251 | |
@@ -1257,128 +1257,128 @@ discard block |
||
1257 | 1257 | |
1258 | 1258 | LIMIT 0,5000 |
1259 | 1259 | "); |
1260 | - // @codingStandardsIgnoreEnd |
|
1261 | - |
|
1262 | - if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) { |
|
1263 | - foreach ( $current_accommodation as $accom ) { |
|
1264 | - $return[ $accom->meta_value ] = $accom; |
|
1265 | - } |
|
1266 | - } |
|
1267 | - |
|
1268 | - return $return; |
|
1269 | - } |
|
1270 | - |
|
1271 | - /** |
|
1272 | - * Set the Video date |
|
1273 | - */ |
|
1274 | - public function set_video_data( $data, $id ) { |
|
1275 | - if ( ! empty( $data[0]['content']['youtube_videos'] ) && is_array( $data[0]['content']['youtube_videos'] ) ) { |
|
1276 | - $videos = false; |
|
1277 | - |
|
1278 | - foreach ( $data[0]['content']['youtube_videos'] as $video ) { |
|
1279 | - $temp_video = array(); |
|
1280 | - |
|
1281 | - if ( isset( $video['label'] ) ) { |
|
1282 | - $temp_video['title'] = $video['label']; |
|
1283 | - } |
|
1284 | - if ( isset( $video['description'] ) ) { |
|
1285 | - $temp_video['description'] = strip_tags( $video['description'] ); |
|
1286 | - } |
|
1287 | - if ( isset( $video['url'] ) ) { |
|
1288 | - $temp_video['url'] = $video['url']; |
|
1289 | - } |
|
1290 | - |
|
1291 | - $temp_video['thumbnail'] = ''; |
|
1292 | - $videos[] = $temp_video; |
|
1293 | - } |
|
1294 | - |
|
1295 | - if ( false !== $id && '0' !== $id ) { |
|
1296 | - delete_post_meta( $id, 'videos' ); |
|
1297 | - } |
|
1298 | - |
|
1299 | - foreach ( $videos as $video ) { |
|
1300 | - add_post_meta( $id, 'videos', $video, false ); |
|
1301 | - } |
|
1302 | - } |
|
1303 | - } |
|
1304 | - |
|
1305 | - public function shuffle_assoc( &$array ) { |
|
1306 | - $new = array(); |
|
1307 | - $keys = array_keys( $array ); |
|
1308 | - |
|
1309 | - shuffle( $keys ); |
|
1310 | - |
|
1311 | - foreach ( $keys as $key ) { |
|
1312 | - $new[ $key ] = $array[ $key ]; |
|
1313 | - } |
|
1314 | - |
|
1315 | - $array = $new; |
|
1316 | - |
|
1317 | - return true; |
|
1318 | - } |
|
1319 | - |
|
1320 | - /** |
|
1321 | - * Save the list of Tours into an option |
|
1322 | - */ |
|
1323 | - public function update_options() { |
|
1324 | - $own = ''; |
|
1325 | - $options = array(); |
|
1326 | - delete_option( 'lsx_ti_tours_api_options' ); |
|
1327 | - |
|
1328 | - if ( isset( $_GET['own'] ) ) { |
|
1329 | - $this->current_importer->url_qs .= '&own=true'; |
|
1330 | - $options[] = 'own'; |
|
1331 | - } |
|
1332 | - |
|
1333 | - if ( isset( $_GET['type'] ) && 'allitineraries' !== $_GET['type'] ) { |
|
1334 | - $this->current_importer->url_qs .= '&type=' . $_GET['type']; |
|
1335 | - $options[] = $_GET['type']; |
|
1336 | - } else { |
|
1337 | - $options[] = 'sample'; |
|
1338 | - $this->current_importer->url_qs .= '&type=sample'; |
|
1339 | - } |
|
1340 | - |
|
1341 | - $url = str_replace( 'Pins', 'Itinerary', $this->current_importer->url . '/V8/List?' . $this->current_importer->url_qs ); |
|
1342 | - $url .= '&results=2000'; |
|
1343 | - add_option( 'lsx_ti_tours_api_options', $options ); |
|
1344 | - $data = wp_remote_get( $url ); |
|
1345 | - $tours = json_decode( wp_remote_retrieve_body( $data ), true ); |
|
1346 | - |
|
1347 | - if ( isset( $tours['error'] ) ) { |
|
1348 | - return $tours['error']; |
|
1349 | - } elseif ( isset( $tours['itineraries'] ) && ! empty( $tours['itineraries'] ) ) { |
|
1350 | - set_transient( 'lsx_ti_tours', $tours['itineraries'], 60 * 60 * 4 ); |
|
1351 | - return true; |
|
1352 | - } |
|
1353 | - } |
|
1354 | - |
|
1355 | - /** |
|
1356 | - * Gets the post_id from the key |
|
1357 | - * |
|
1358 | - * @param boolean $wetu_id |
|
1359 | - * @return string |
|
1360 | - */ |
|
1361 | - public function get_post_id_by_key_value( $wetu_id = false ) { |
|
1362 | - global $wpdb; |
|
1363 | - $id = false; |
|
1364 | - if ( false !== $wetu_id && '' !== $wetu_id ) { |
|
1365 | - $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 ) ) ); |
|
1366 | - if ( false !== $result && ! empty( $result ) ) { |
|
1367 | - $id = $result; |
|
1368 | - } |
|
1369 | - } |
|
1370 | - return $id; |
|
1371 | - } |
|
1372 | - /** |
|
1373 | - * Set the team memberon each item. |
|
1374 | - */ |
|
1375 | - public function set_team_member( $id, $team_members ) { |
|
1376 | - delete_post_meta( $id, 'team_to_' . $this->tab_slug ); |
|
1377 | - |
|
1378 | - foreach ( $team_members as $team ) { |
|
1379 | - add_post_meta( $id, 'team_to_' . $this->tab_slug, $team ); |
|
1380 | - } |
|
1381 | - } |
|
1260 | + // @codingStandardsIgnoreEnd |
|
1261 | + |
|
1262 | + if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) { |
|
1263 | + foreach ( $current_accommodation as $accom ) { |
|
1264 | + $return[ $accom->meta_value ] = $accom; |
|
1265 | + } |
|
1266 | + } |
|
1267 | + |
|
1268 | + return $return; |
|
1269 | + } |
|
1270 | + |
|
1271 | + /** |
|
1272 | + * Set the Video date |
|
1273 | + */ |
|
1274 | + public function set_video_data( $data, $id ) { |
|
1275 | + if ( ! empty( $data[0]['content']['youtube_videos'] ) && is_array( $data[0]['content']['youtube_videos'] ) ) { |
|
1276 | + $videos = false; |
|
1277 | + |
|
1278 | + foreach ( $data[0]['content']['youtube_videos'] as $video ) { |
|
1279 | + $temp_video = array(); |
|
1280 | + |
|
1281 | + if ( isset( $video['label'] ) ) { |
|
1282 | + $temp_video['title'] = $video['label']; |
|
1283 | + } |
|
1284 | + if ( isset( $video['description'] ) ) { |
|
1285 | + $temp_video['description'] = strip_tags( $video['description'] ); |
|
1286 | + } |
|
1287 | + if ( isset( $video['url'] ) ) { |
|
1288 | + $temp_video['url'] = $video['url']; |
|
1289 | + } |
|
1290 | + |
|
1291 | + $temp_video['thumbnail'] = ''; |
|
1292 | + $videos[] = $temp_video; |
|
1293 | + } |
|
1294 | + |
|
1295 | + if ( false !== $id && '0' !== $id ) { |
|
1296 | + delete_post_meta( $id, 'videos' ); |
|
1297 | + } |
|
1298 | + |
|
1299 | + foreach ( $videos as $video ) { |
|
1300 | + add_post_meta( $id, 'videos', $video, false ); |
|
1301 | + } |
|
1302 | + } |
|
1303 | + } |
|
1304 | + |
|
1305 | + public function shuffle_assoc( &$array ) { |
|
1306 | + $new = array(); |
|
1307 | + $keys = array_keys( $array ); |
|
1308 | + |
|
1309 | + shuffle( $keys ); |
|
1310 | + |
|
1311 | + foreach ( $keys as $key ) { |
|
1312 | + $new[ $key ] = $array[ $key ]; |
|
1313 | + } |
|
1314 | + |
|
1315 | + $array = $new; |
|
1316 | + |
|
1317 | + return true; |
|
1318 | + } |
|
1319 | + |
|
1320 | + /** |
|
1321 | + * Save the list of Tours into an option |
|
1322 | + */ |
|
1323 | + public function update_options() { |
|
1324 | + $own = ''; |
|
1325 | + $options = array(); |
|
1326 | + delete_option( 'lsx_ti_tours_api_options' ); |
|
1327 | + |
|
1328 | + if ( isset( $_GET['own'] ) ) { |
|
1329 | + $this->current_importer->url_qs .= '&own=true'; |
|
1330 | + $options[] = 'own'; |
|
1331 | + } |
|
1332 | + |
|
1333 | + if ( isset( $_GET['type'] ) && 'allitineraries' !== $_GET['type'] ) { |
|
1334 | + $this->current_importer->url_qs .= '&type=' . $_GET['type']; |
|
1335 | + $options[] = $_GET['type']; |
|
1336 | + } else { |
|
1337 | + $options[] = 'sample'; |
|
1338 | + $this->current_importer->url_qs .= '&type=sample'; |
|
1339 | + } |
|
1340 | + |
|
1341 | + $url = str_replace( 'Pins', 'Itinerary', $this->current_importer->url . '/V8/List?' . $this->current_importer->url_qs ); |
|
1342 | + $url .= '&results=2000'; |
|
1343 | + add_option( 'lsx_ti_tours_api_options', $options ); |
|
1344 | + $data = wp_remote_get( $url ); |
|
1345 | + $tours = json_decode( wp_remote_retrieve_body( $data ), true ); |
|
1346 | + |
|
1347 | + if ( isset( $tours['error'] ) ) { |
|
1348 | + return $tours['error']; |
|
1349 | + } elseif ( isset( $tours['itineraries'] ) && ! empty( $tours['itineraries'] ) ) { |
|
1350 | + set_transient( 'lsx_ti_tours', $tours['itineraries'], 60 * 60 * 4 ); |
|
1351 | + return true; |
|
1352 | + } |
|
1353 | + } |
|
1354 | + |
|
1355 | + /** |
|
1356 | + * Gets the post_id from the key |
|
1357 | + * |
|
1358 | + * @param boolean $wetu_id |
|
1359 | + * @return string |
|
1360 | + */ |
|
1361 | + public function get_post_id_by_key_value( $wetu_id = false ) { |
|
1362 | + global $wpdb; |
|
1363 | + $id = false; |
|
1364 | + if ( false !== $wetu_id && '' !== $wetu_id ) { |
|
1365 | + $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 ) ) ); |
|
1366 | + if ( false !== $result && ! empty( $result ) ) { |
|
1367 | + $id = $result; |
|
1368 | + } |
|
1369 | + } |
|
1370 | + return $id; |
|
1371 | + } |
|
1372 | + /** |
|
1373 | + * Set the team memberon each item. |
|
1374 | + */ |
|
1375 | + public function set_team_member( $id, $team_members ) { |
|
1376 | + delete_post_meta( $id, 'team_to_' . $this->tab_slug ); |
|
1377 | + |
|
1378 | + foreach ( $team_members as $team ) { |
|
1379 | + add_post_meta( $id, 'team_to_' . $this->tab_slug, $team ); |
|
1380 | + } |
|
1381 | + } |
|
1382 | 1382 | } |
1383 | 1383 | |
1384 | 1384 | $lsx_wetu_importer = new LSX_WETU_Importer(); |
@@ -197,40 +197,40 @@ discard block |
||
197 | 197 | * @access private |
198 | 198 | */ |
199 | 199 | public function __construct() { |
200 | - add_action( 'admin_init', array( $this, 'compatible_version_check' ) ); |
|
201 | - require_once LSX_WETU_IMPORTER_PATH . 'includes/helpers.php'; |
|
200 | + add_action('admin_init', array($this, 'compatible_version_check')); |
|
201 | + require_once LSX_WETU_IMPORTER_PATH.'includes/helpers.php'; |
|
202 | 202 | |
203 | 203 | // Don't run anything else in the plugin, if we're on an incompatible PHP version. |
204 | - if ( ! self::compatible_version() ) { |
|
204 | + if (!self::compatible_version()) { |
|
205 | 205 | return; |
206 | 206 | } |
207 | 207 | |
208 | 208 | $this->set_variables(); |
209 | 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 ); |
|
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 | 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'; |
|
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 | 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'; |
|
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 | 223 | $this->post_columns = LSX_WETU_Importer_Post_Columns::get_instance(); |
224 | 224 | } |
225 | 225 | |
226 | - add_action( 'init', array( $this, 'load_class' ) ); |
|
226 | + add_action('init', array($this, 'load_class')); |
|
227 | 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' ) ); |
|
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 | 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' ) ); |
|
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 | 234 | } |
235 | 235 | } |
236 | 236 | |
@@ -240,21 +240,21 @@ discard block |
||
240 | 240 | * @since 1.0.0 |
241 | 241 | */ |
242 | 242 | public function load_plugin_textdomain() { |
243 | - load_plugin_textdomain( 'lsx-wetu-importer', false, basename( LSX_WETU_IMPORTER_PATH ) . '/languages' ); |
|
243 | + load_plugin_textdomain('lsx-wetu-importer', false, basename(LSX_WETU_IMPORTER_PATH).'/languages'); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
247 | 247 | * Sets the variables used throughout the plugin. |
248 | 248 | */ |
249 | 249 | public function set_variables() { |
250 | - $this->post_types = array( 'accommodation', 'destination', 'tour' ); |
|
250 | + $this->post_types = array('accommodation', 'destination', 'tour'); |
|
251 | 251 | $options = lsx_wetu_get_options(); |
252 | 252 | |
253 | 253 | // Set the options. |
254 | 254 | $this->options = $options; |
255 | 255 | |
256 | - $temp_options = get_option( '_lsx-to_settings', false ); |
|
257 | - if ( false !== $temp_options ) { |
|
256 | + $temp_options = get_option('_lsx-to_settings', false); |
|
257 | + if (false !== $temp_options) { |
|
258 | 258 | $this->accommodation_settings = $temp_options['accommodation']; |
259 | 259 | $this->tour_settings = $temp_options['tour']; |
260 | 260 | $this->destination_settings = $temp_options['destination']; |
@@ -262,51 +262,51 @@ discard block |
||
262 | 262 | |
263 | 263 | $this->api_key = false; |
264 | 264 | |
265 | - if ( ! defined( 'WETU_API_KEY' ) ) { |
|
266 | - if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) { |
|
265 | + if (!defined('WETU_API_KEY')) { |
|
266 | + if (isset($options['api_key']) && '' !== $options['api_key']) { |
|
267 | 267 | $this->api_key = $options['api_key']; |
268 | 268 | } |
269 | - } else { |
|
269 | + }else { |
|
270 | 270 | $this->api_key = WETU_API_KEY; |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Set the tab slug. |
274 | 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 { |
|
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 | 279 | // @codingStandardsIgnoreLine |
280 | - $this->tab_slug = sanitize_text_field( $_POST['type'] ); |
|
280 | + $this->tab_slug = sanitize_text_field($_POST['type']); |
|
281 | 281 | } |
282 | 282 | } |
283 | 283 | |
284 | 284 | // If any tours were queued. |
285 | - $this->queued_imports = get_option( 'lsx_wetu_importer_que', array() ); |
|
285 | + $this->queued_imports = get_option('lsx_wetu_importer_que', array()); |
|
286 | 286 | |
287 | 287 | // Set the scaling options. |
288 | - if ( isset( $this->options ) && isset( $this->options['image_scaling'] ) ) { |
|
288 | + if (isset($this->options) && isset($this->options['image_scaling'])) { |
|
289 | 289 | $this->scale_images = true; |
290 | 290 | |
291 | 291 | $width = '1024'; |
292 | - if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) { |
|
292 | + if (isset($this->options['width']) && '' !== $this->options['width']) { |
|
293 | 293 | $width = $this->options['width']; |
294 | 294 | } |
295 | 295 | |
296 | 296 | $height = '768'; |
297 | - if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) { |
|
297 | + if (isset($this->options['height']) && '' !== $this->options['height']) { |
|
298 | 298 | $height = $this->options['height']; |
299 | 299 | } |
300 | 300 | |
301 | 301 | $cropping = 'w'; |
302 | - if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) { |
|
302 | + if (isset($this->options['cropping']) && '' !== $this->options['cropping']) { |
|
303 | 303 | $cropping = $this->options['cropping']; |
304 | 304 | } |
305 | 305 | |
306 | - $this->image_scaling_url = 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/'; |
|
306 | + $this->image_scaling_url = 'https://wetu.com/ImageHandler/'.$cropping.$width.'x'.$height.'/'; |
|
307 | 307 | } |
308 | 308 | |
309 | - if ( isset( $this->options ) && isset( $this->options['image_limit'] ) && '' !== $this->options['image_limit'] ) { |
|
309 | + if (isset($this->options) && isset($this->options['image_limit']) && '' !== $this->options['image_limit']) { |
|
310 | 310 | $this->image_limit = $this->options['image_limit']; |
311 | 311 | } |
312 | 312 | } |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | * @since 1.0.0 |
329 | 329 | */ |
330 | 330 | public static function compatible_version() { |
331 | - if ( version_compare( PHP_VERSION, '5.6', '<' ) ) { |
|
331 | + if (version_compare(PHP_VERSION, '5.6', '<')) { |
|
332 | 332 | return false; |
333 | 333 | } |
334 | 334 | |
@@ -342,13 +342,13 @@ discard block |
||
342 | 342 | * @since 1.0.0 |
343 | 343 | */ |
344 | 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' ) ); |
|
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 | 349 | |
350 | - if ( isset( $_GET['activate'] ) ) { |
|
351 | - unset( $_GET['activate'] ); |
|
350 | + if (isset($_GET['activate'])) { |
|
351 | + unset($_GET['activate']); |
|
352 | 352 | } |
353 | 353 | } |
354 | 354 | } |
@@ -361,8 +361,8 @@ discard block |
||
361 | 361 | */ |
362 | 362 | public function compatible_version_notice() { |
363 | 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 ) ); |
|
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 | 366 | } |
367 | 367 | |
368 | 368 | /** |
@@ -372,9 +372,9 @@ discard block |
||
372 | 372 | * @since 1.0.0 |
373 | 373 | */ |
374 | 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' ) ); |
|
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 | 378 | } |
379 | 379 | } |
380 | 380 | |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | * Load the importer class you want to use |
385 | 385 | */ |
386 | 386 | public function load_class() { |
387 | - switch ( $this->tab_slug ) { |
|
387 | + switch ($this->tab_slug) { |
|
388 | 388 | case 'accommodation': |
389 | 389 | $this->current_importer = new LSX_WETU_Importer_Accommodation(); |
390 | 390 | break; |
@@ -411,36 +411,36 @@ discard block |
||
411 | 411 | * Registers the admin page which will house the importer form. |
412 | 412 | */ |
413 | 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' ) ); |
|
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 | 415 | } |
416 | 416 | |
417 | 417 | /** |
418 | 418 | * Enqueue the JS needed to contact wetu and return your result. |
419 | 419 | */ |
420 | 420 | public function admin_scripts() { |
421 | - if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) { |
|
421 | + if (defined('WP_DEBUG') && true === WP_DEBUG) { |
|
422 | 422 | $min = ''; |
423 | - } else { |
|
423 | + }else { |
|
424 | 424 | $min = '.min'; |
425 | 425 | } |
426 | 426 | |
427 | 427 | $min = ''; |
428 | 428 | |
429 | - if ( is_admin() && isset( $_GET['page'] ) && $this->plugin_slug === $_GET['page'] ) { |
|
429 | + if (is_admin() && isset($_GET['page']) && $this->plugin_slug === $_GET['page']) { |
|
430 | 430 | |
431 | 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 ); |
|
432 | + wp_enqueue_style('lsx-wetu-importer-style', LSX_WETU_IMPORTER_URL.'assets/css/lsx-wetu-importer.css', LSX_WETU_IMPORTER_VER, true); |
|
433 | 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 ); |
|
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 | 437 | |
438 | 438 | wp_localize_script( |
439 | 439 | 'lsx-wetu-importers-script', |
440 | 440 | 'lsx_tour_importer_params', |
441 | 441 | array( |
442 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
443 | - 'ajax_nonce' => wp_create_nonce( 'lsx_wetu_ajax_action' ), |
|
442 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
443 | + 'ajax_nonce' => wp_create_nonce('lsx_wetu_ajax_action'), |
|
444 | 444 | ) |
445 | 445 | ); |
446 | 446 | } |
@@ -454,8 +454,8 @@ discard block |
||
454 | 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 ) { |
|
457 | + $this->navigation($this->tab_slug); |
|
458 | + if ('default' !== $this->tab_slug && 'settings' !== $this->tab_slug) { |
|
459 | 459 | $this->wetu_status(); |
460 | 460 | $this->post_status_navigation(); |
461 | 461 | } |
@@ -473,18 +473,18 @@ discard block |
||
473 | 473 | public function post_status_navigation() { |
474 | 474 | ?> |
475 | 475 | <ul class="subsubsub"> |
476 | - <li class="searchform"><a class="current" href="#search"><?php esc_attr_e( 'Search', 'lsx-wetu-importer' ); ?></a> | </li> |
|
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> |
|
478 | - <li class="pending"><a href="#pending"><?php esc_attr_e( 'Pending', 'lsx-wetu-importer' ); ?> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_post_count( $this->tab_slug, 'pending ' ) ); ?>)</span></a>| </li> |
|
479 | - <li class="draft"><a href="#draft"><?php esc_attr_e( 'Draft', 'lsx-wetu-importer' ); ?></a> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_post_count( $this->tab_slug, 'draft ' ) ); ?>)</span></li> |
|
480 | - |
|
481 | - <?php if ( 'tour' === $this->tab_slug ) { ?> |
|
482 | - <li class="import"> | <a class="import search-toggle" href="#import"><?php esc_attr_e( 'WETU', 'lsx-wetu-importer' ); ?> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_tour_count() ); ?>)</span></a></li> |
|
483 | - <?php } else if ( ! empty( $this->queued_imports ) ) { ?> |
|
484 | - <li class="import"> | <a class="import search-toggle" href="#import"><?php esc_attr_e( 'WETU Queue', 'lsx-wetu-importer' ); ?> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_queue_count( $this->tab_slug ) ); ?>)</span></a></li> |
|
476 | + <li class="searchform"><a class="current" href="#search"><?php esc_attr_e('Search', 'lsx-wetu-importer'); ?></a> | </li> |
|
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> |
|
478 | + <li class="pending"><a href="#pending"><?php esc_attr_e('Pending', 'lsx-wetu-importer'); ?> <span class="count"> (<?php echo esc_attr(lsx_wetu_get_post_count($this->tab_slug, 'pending ')); ?>)</span></a>| </li> |
|
479 | + <li class="draft"><a href="#draft"><?php esc_attr_e('Draft', 'lsx-wetu-importer'); ?></a> <span class="count"> (<?php echo esc_attr(lsx_wetu_get_post_count($this->tab_slug, 'draft ')); ?>)</span></li> |
|
480 | + |
|
481 | + <?php if ('tour' === $this->tab_slug) { ?> |
|
482 | + <li class="import"> | <a class="import search-toggle" href="#import"><?php esc_attr_e('WETU', 'lsx-wetu-importer'); ?> <span class="count"> (<?php echo esc_attr(lsx_wetu_get_tour_count()); ?>)</span></a></li> |
|
483 | + <?php }else if (!empty($this->queued_imports)) { ?> |
|
484 | + <li class="import"> | <a class="import search-toggle" href="#import"><?php esc_attr_e('WETU Queue', 'lsx-wetu-importer'); ?> <span class="count"> (<?php echo esc_attr(lsx_wetu_get_queue_count($this->tab_slug)); ?>)</span></a></li> |
|
485 | 485 | <?php } ?> |
486 | 486 | </ul> |
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> |
|
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 | |
@@ -493,29 +493,29 @@ discard block |
||
493 | 493 | */ |
494 | 494 | public function search_form() { |
495 | 495 | ?> |
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 | - <input type="hidden" name="page" value="<?php echo esc_attr( $this->tab_slug ); ?>" /> |
|
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 | + <input type="hidden" name="page" value="<?php echo esc_attr($this->tab_slug); ?>" /> |
|
498 | 498 | |
499 | - <?php do_action( 'lsx_wetu_importer_search_form', $this ); ?> |
|
499 | + <?php do_action('lsx_wetu_importer_search_form', $this); ?> |
|
500 | 500 | |
501 | 501 | <div class="normal-search"> |
502 | - <input pattern=".{3,}" placeholder="3 characters minimum" class="keyword" name="keyword" value=""> <input class="button button-primary submit" type="submit" value="<?php esc_html_e( 'Search', 'lsx-wetu-importer' ); ?>" /> |
|
502 | + <input pattern=".{3,}" placeholder="3 characters minimum" class="keyword" name="keyword" value=""> <input class="button button-primary submit" type="submit" value="<?php esc_html_e('Search', 'lsx-wetu-importer'); ?>" /> |
|
503 | 503 | </div> |
504 | 504 | |
505 | 505 | <div class="advanced-search hidden" style="display:none;"> |
506 | 506 | <textarea rows="10" cols="40" name="bulk-keywords"></textarea> |
507 | - <input class="button button-primary submit" type="submit" value="<?php esc_attr_e( 'Search', 'lsx-wetu-importer' ); ?>" /> |
|
507 | + <input class="button button-primary submit" type="submit" value="<?php esc_attr_e('Search', 'lsx-wetu-importer'); ?>" /> |
|
508 | 508 | </div> |
509 | 509 | |
510 | 510 | <div class="ajax-loader" style="display:none;width:100%;text-align:center;"> |
511 | - <img style="width:64px;" src="<?php echo esc_url( LSX_WETU_IMPORTER_URL . 'assets/images/ajaxloader.gif' ); ?>" /> |
|
511 | + <img style="width:64px;" src="<?php echo esc_url(LSX_WETU_IMPORTER_URL.'assets/images/ajaxloader.gif'); ?>" /> |
|
512 | 512 | </div> |
513 | 513 | |
514 | 514 | <div class="ajax-loader-small" style="display:none;width:100%;text-align:center;"> |
515 | - <img style="width:32px;" src="<?php echo esc_url( LSX_WETU_IMPORTER_URL . 'assets/images/ajaxloader.gif' ); ?>" /> |
|
515 | + <img style="width:32px;" src="<?php echo esc_url(LSX_WETU_IMPORTER_URL.'assets/images/ajaxloader.gif'); ?>" /> |
|
516 | 516 | </div> |
517 | 517 | |
518 | - <a class="button advanced-search-toggle" href="#"><?php esc_html_e( 'Bulk Search', 'lsx-wetu-importer' ); ?></a> |
|
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 | } |
@@ -528,13 +528,13 @@ discard block |
||
528 | 528 | <thead> |
529 | 529 | <tr> |
530 | 530 | <th style="" class="manage-column column-cb check-column no-sort" id="cb" scope="col"> |
531 | - <label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e( 'Select All', 'lsx-wetu-importer' ); ?></label> |
|
531 | + <label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e('Select All', 'lsx-wetu-importer'); ?></label> |
|
532 | 532 | <input type="checkbox" id="cb-select-all-1"> |
533 | 533 | </th> |
534 | - <th style="" class="manage-column column-order " id="order"><?php esc_attr_e( 'Order', 'lsx-wetu-importer' ); ?></th> |
|
535 | - <th style="" class="manage-column column-title " id="title" style="width:50%;" scope="col"><?php esc_attr_e( 'Title', 'lsx-wetu-importer' ); ?></th> |
|
536 | - <th style="" class="manage-column column-date" id="date" scope="col"><?php esc_attr_e( 'Date', 'lsx-wetu-importer' ); ?></th> |
|
537 | - <th style="" class="manage-column column-ssid" id="ssid" scope="col"><?php esc_attr_e( 'WETU ID', 'lsx-wetu-importer' ); ?></th> |
|
534 | + <th style="" class="manage-column column-order " id="order"><?php esc_attr_e('Order', 'lsx-wetu-importer'); ?></th> |
|
535 | + <th style="" class="manage-column column-title " id="title" style="width:50%;" scope="col"><?php esc_attr_e('Title', 'lsx-wetu-importer'); ?></th> |
|
536 | + <th style="" class="manage-column column-date" id="date" scope="col"><?php esc_attr_e('Date', 'lsx-wetu-importer'); ?></th> |
|
537 | + <th style="" class="manage-column column-ssid" id="ssid" scope="col"><?php esc_attr_e('WETU ID', 'lsx-wetu-importer'); ?></th> |
|
538 | 538 | </tr> |
539 | 539 | </thead> |
540 | 540 | <?php |
@@ -548,13 +548,13 @@ discard block |
||
548 | 548 | <tfoot> |
549 | 549 | <tr> |
550 | 550 | <th style="" class="manage-column column-cb check-column" id="cb" scope="col"> |
551 | - <label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e( 'Select All', 'lsx-wetu-importer' ); ?></label> |
|
551 | + <label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e('Select All', 'lsx-wetu-importer'); ?></label> |
|
552 | 552 | <input type="checkbox" id="cb-select-all-1"> |
553 | 553 | </th> |
554 | - <th style="" class="manage-column column-order "><?php esc_attr_e( 'Order', 'lsx-wetu-importer' ); ?></th> |
|
555 | - <th style="" class="manage-column column-title" scope="col"><?php esc_attr_e( 'Title', 'lsx-wetu-importer' ); ?></th> |
|
556 | - <th style="" class="manage-column column-date" scope="col"><?php esc_attr_e( 'Date', 'lsx-wetu-importer' ); ?></th> |
|
557 | - <th style="" class="manage-column column-ssid" scope="col"><?php esc_attr_e( 'WETU ID', 'lsx-wetu-importer' ); ?></th> |
|
554 | + <th style="" class="manage-column column-order "><?php esc_attr_e('Order', 'lsx-wetu-importer'); ?></th> |
|
555 | + <th style="" class="manage-column column-title" scope="col"><?php esc_attr_e('Title', 'lsx-wetu-importer'); ?></th> |
|
556 | + <th style="" class="manage-column column-date" scope="col"><?php esc_attr_e('Date', 'lsx-wetu-importer'); ?></th> |
|
557 | + <th style="" class="manage-column column-ssid" scope="col"><?php esc_attr_e('WETU ID', 'lsx-wetu-importer'); ?></th> |
|
558 | 558 | </tr> |
559 | 559 | </tfoot> |
560 | 560 | <?php |
@@ -565,42 +565,42 @@ discard block |
||
565 | 565 | * |
566 | 566 | * @param $tab string |
567 | 567 | */ |
568 | - public function navigation( $tab = '' ) { |
|
568 | + public function navigation($tab = '') { |
|
569 | 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' ), |
|
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 | 573 | ); |
574 | 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>' ); |
|
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 | 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>' ); |
|
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 | 581 | } |
582 | 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>' ); |
|
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 | 585 | } |
586 | 586 | |
587 | 587 | /** |
588 | 588 | * Wetu Status Bar. |
589 | 589 | */ |
590 | 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' ) . ' - '; |
|
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 | 593 | |
594 | - if ( '' === $tours || false === $tours || isset( $_GET['refresh_tours'] ) ) { |
|
594 | + if ('' === $tours || false === $tours || isset($_GET['refresh_tours'])) { |
|
595 | 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>'; |
|
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 | 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>'; |
|
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 | 604 | } |
605 | 605 | echo '</h3>'; |
606 | 606 | echo '</div>'; |
@@ -609,8 +609,8 @@ discard block |
||
609 | 609 | /** |
610 | 610 | * Set_taxonomy with some terms |
611 | 611 | */ |
612 | - public function team_member_checkboxes( $selected = array() ) { |
|
613 | - if ( post_type_exists( 'team' ) ) { |
|
612 | + public function team_member_checkboxes($selected = array()) { |
|
613 | + if (post_type_exists('team')) { |
|
614 | 614 | ?> |
615 | 615 | <ul> |
616 | 616 | <?php |
@@ -621,17 +621,17 @@ discard block |
||
621 | 621 | 'fields' => 'ids', |
622 | 622 | ); |
623 | 623 | |
624 | - $team_members = new WP_Query( $team_args ); |
|
624 | + $team_members = new WP_Query($team_args); |
|
625 | 625 | |
626 | - if ( $team_members->have_posts() ) { |
|
627 | - foreach ( $team_members->posts as $member ) { |
|
626 | + if ($team_members->have_posts()) { |
|
627 | + foreach ($team_members->posts as $member) { |
|
628 | 628 | ?> |
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> |
|
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 | 631 | } |
632 | - } else { |
|
632 | + }else { |
|
633 | 633 | ?> |
634 | - <li><input class="team" type="checkbox" value="0" /> <?php esc_html_e( 'None', 'lsx-wetu-importer' ); ?></li> |
|
634 | + <li><input class="team" type="checkbox" value="0" /> <?php esc_html_e('None', 'lsx-wetu-importer'); ?></li> |
|
635 | 635 | <?php |
636 | 636 | } |
637 | 637 | ?> |
@@ -650,13 +650,13 @@ discard block |
||
650 | 650 | * @param $needle string |
651 | 651 | * @param $echo bool |
652 | 652 | */ |
653 | - public function checked( $haystack = false, $needle = '', $echo = true ) { |
|
654 | - $return = $this->itemd( $haystack, $needle, 'checked', false ); |
|
653 | + public function checked($haystack = false, $needle = '', $echo = true) { |
|
654 | + $return = $this->itemd($haystack, $needle, 'checked', false); |
|
655 | 655 | |
656 | - if ( '' !== $return ) { |
|
657 | - if ( true === $echo ) { |
|
658 | - echo wp_kses_post( $return ); |
|
659 | - } else { |
|
656 | + if ('' !== $return) { |
|
657 | + if (true === $echo) { |
|
658 | + echo wp_kses_post($return); |
|
659 | + }else { |
|
660 | 660 | return $return; |
661 | 661 | } |
662 | 662 | } |
@@ -669,13 +669,13 @@ discard block |
||
669 | 669 | * @param $needle string |
670 | 670 | * @param $echo bool |
671 | 671 | */ |
672 | - public function selected( $haystack = false, $needle = '', $echo = true ) { |
|
673 | - $return = $this->itemd( $haystack, $needle, 'selected' ); |
|
672 | + public function selected($haystack = false, $needle = '', $echo = true) { |
|
673 | + $return = $this->itemd($haystack, $needle, 'selected'); |
|
674 | 674 | |
675 | - if ( '' !== $return ) { |
|
676 | - if ( true === $echo ) { |
|
677 | - echo wp_kses_post( $return ); |
|
678 | - } else { |
|
675 | + if ('' !== $return) { |
|
676 | + if (true === $echo) { |
|
677 | + echo wp_kses_post($return); |
|
678 | + }else { |
|
679 | 679 | return $return; |
680 | 680 | } |
681 | 681 | } |
@@ -690,17 +690,17 @@ discard block |
||
690 | 690 | * @param $wrap bool |
691 | 691 | * @return $html string |
692 | 692 | */ |
693 | - public function itemd( $haystack = false, $needle = '', $type = '', $wrap = true ) { |
|
693 | + public function itemd($haystack = false, $needle = '', $type = '', $wrap = true) { |
|
694 | 694 | $html = ''; |
695 | 695 | |
696 | - if ( '' !== $type ) { |
|
697 | - if ( ! is_array( $haystack ) ) { |
|
698 | - $haystack = array( $haystack ); |
|
696 | + if ('' !== $type) { |
|
697 | + if (!is_array($haystack)) { |
|
698 | + $haystack = array($haystack); |
|
699 | 699 | } |
700 | - if ( in_array( $needle, $haystack ) ) { |
|
701 | - if ( true === $wrap || 'true' === $wrap ) { |
|
702 | - $html = $type . '="' . $type . '"'; |
|
703 | - } else { |
|
700 | + if (in_array($needle, $haystack)) { |
|
701 | + if (true === $wrap || 'true' === $wrap) { |
|
702 | + $html = $type.'="'.$type.'"'; |
|
703 | + }else { |
|
704 | 704 | $html = $type; |
705 | 705 | } |
706 | 706 | } |
@@ -712,9 +712,9 @@ discard block |
||
712 | 712 | /** |
713 | 713 | * Grabs any attachments for the current item |
714 | 714 | */ |
715 | - public function find_attachments( $id = false ) { |
|
716 | - if ( false !== $id ) { |
|
717 | - if ( empty( $this->found_attachments ) ) { |
|
715 | + public function find_attachments($id = false) { |
|
716 | + if (false !== $id) { |
|
717 | + if (empty($this->found_attachments)) { |
|
718 | 718 | $attachments_args = array( |
719 | 719 | 'post_parent' => $id, |
720 | 720 | 'post_status' => 'inherit', |
@@ -724,11 +724,11 @@ discard block |
||
724 | 724 | 'posts_per_page' => '-1', |
725 | 725 | ); |
726 | 726 | |
727 | - $attachments = new WP_Query( $attachments_args ); |
|
727 | + $attachments = new WP_Query($attachments_args); |
|
728 | 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 ); |
|
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 | 732 | } |
733 | 733 | } |
734 | 734 | } |
@@ -740,19 +740,19 @@ discard block |
||
740 | 740 | /** |
741 | 741 | * Saves the room data |
742 | 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 ); |
|
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 | 747 | $value--; |
748 | 748 | } |
749 | 749 | |
750 | - $prev = get_post_meta( $id, $meta_key, true ); |
|
750 | + $prev = get_post_meta($id, $meta_key, true); |
|
751 | 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 ); |
|
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 | 756 | } |
757 | 757 | } |
758 | 758 | } |
@@ -761,15 +761,15 @@ discard block |
||
761 | 761 | * Grabs the custom fields, and resaves an array of unique items. |
762 | 762 | */ |
763 | 763 | public function cleanup_posts() { |
764 | - if ( ! empty( $this->cleanup_posts ) ) { |
|
764 | + if (!empty($this->cleanup_posts)) { |
|
765 | 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 ); |
|
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 | 770 | |
771 | - foreach ( $new_items as $new_item ) { |
|
772 | - add_post_meta( $id, $key, $new_item, false ); |
|
771 | + foreach ($new_items as $new_item) { |
|
772 | + add_post_meta($id, $key, $new_item, false); |
|
773 | 773 | } |
774 | 774 | } |
775 | 775 | } |
@@ -780,26 +780,26 @@ discard block |
||
780 | 780 | /** |
781 | 781 | * Set_taxonomy with some terms |
782 | 782 | */ |
783 | - public function set_taxonomy( $taxonomy, $terms, $id ) { |
|
783 | + public function set_taxonomy($taxonomy, $terms, $id) { |
|
784 | 784 | $result = array(); |
785 | 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 ); |
|
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 | 797 | } |
798 | - } else { |
|
799 | - wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
798 | + }else { |
|
799 | + wp_set_object_terms($id, intval($term['term_id']), $taxonomy, true); |
|
800 | 800 | } |
801 | - } else { |
|
802 | - $result[] = trim( $k ); |
|
801 | + }else { |
|
802 | + $result[] = trim($k); |
|
803 | 803 | } |
804 | 804 | } |
805 | 805 | } |
@@ -815,23 +815,23 @@ discard block |
||
815 | 815 | * @param boolean $parent |
816 | 816 | * @return void |
817 | 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 ) { |
|
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 | 822 | $parent = array( |
823 | 823 | 'parent' => $parent, |
824 | 824 | ); |
825 | 825 | } |
826 | - $term = wp_insert_term( trim( $name ), $taxonomy, $parent ); |
|
826 | + $term = wp_insert_term(trim($name), $taxonomy, $parent); |
|
827 | 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 ); |
|
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 | 832 | } |
833 | - } else { |
|
834 | - wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true ); |
|
833 | + }else { |
|
834 | + wp_set_object_terms($id, intval($term['term_id']), $taxonomy, true); |
|
835 | 835 | } |
836 | 836 | |
837 | 837 | return $term['term_id']; |
@@ -840,22 +840,22 @@ discard block |
||
840 | 840 | /** |
841 | 841 | * set_taxonomy with some terms |
842 | 842 | */ |
843 | - public function taxonomy_checkboxes( $taxonomy = false, $selected = array() ) { |
|
843 | + public function taxonomy_checkboxes($taxonomy = false, $selected = array()) { |
|
844 | 844 | $return = ''; |
845 | 845 | |
846 | - if ( false !== $taxonomy ) { |
|
846 | + if (false !== $taxonomy) { |
|
847 | 847 | $return .= '<ul>'; |
848 | - $terms = get_terms( array( |
|
848 | + $terms = get_terms(array( |
|
849 | 849 | 'taxonomy' => $taxonomy, |
850 | 850 | 'hide_empty' => false, |
851 | - ) ); |
|
851 | + )); |
|
852 | 852 | |
853 | - if ( ! is_wp_error( $terms ) ) { |
|
854 | - foreach ( $terms as $term ) { |
|
855 | - $return .= '<li><input class="' . $taxonomy . '" ' . $this->checked( $selected, $term->term_id, false ) . ' type="checkbox" value="' . $term->term_id . '" /> ' . $term->name . '</li>'; |
|
853 | + if (!is_wp_error($terms)) { |
|
854 | + foreach ($terms as $term) { |
|
855 | + $return .= '<li><input class="'.$taxonomy.'" '.$this->checked($selected, $term->term_id, false).' type="checkbox" value="'.$term->term_id.'" /> '.$term->name.'</li>'; |
|
856 | 856 | } |
857 | - } else { |
|
858 | - $return .= '<li><input type="checkbox" value="" /> ' . __( 'None', 'lsx-wetu-importer' ) . '</li>'; |
|
857 | + }else { |
|
858 | + $return .= '<li><input type="checkbox" value="" /> '.__('None', 'lsx-wetu-importer').'</li>'; |
|
859 | 859 | } |
860 | 860 | |
861 | 861 | $return .= '</ul>'; |
@@ -869,44 +869,44 @@ discard block |
||
869 | 869 | /** |
870 | 870 | * Saves the longitude and lattitude, as well as sets the map marker. |
871 | 871 | */ |
872 | - public function set_map_data( $data, $id, $zoom = '10' ) { |
|
872 | + public function set_map_data($data, $id, $zoom = '10') { |
|
873 | 873 | $longitude = false; |
874 | 874 | $latitude = false; |
875 | 875 | $address = false; |
876 | 876 | |
877 | - if ( isset( $data[0]['position'] ) ) { |
|
878 | - if ( isset( $data[0]['position']['driving_latitude'] ) ) { |
|
877 | + if (isset($data[0]['position'])) { |
|
878 | + if (isset($data[0]['position']['driving_latitude'])) { |
|
879 | 879 | $latitude = $data[0]['position']['driving_latitude']; |
880 | - } elseif ( isset( $data[0]['position']['latitude'] ) ) { |
|
880 | + } elseif (isset($data[0]['position']['latitude'])) { |
|
881 | 881 | $latitude = $data[0]['position']['latitude']; |
882 | 882 | } |
883 | 883 | |
884 | - if ( isset( $data[0]['position']['driving_longitude'] ) ) { |
|
884 | + if (isset($data[0]['position']['driving_longitude'])) { |
|
885 | 885 | $longitude = $data[0]['position']['driving_longitude']; |
886 | - } elseif ( isset( $data[0]['position']['longitude'] ) ) { |
|
886 | + } elseif (isset($data[0]['position']['longitude'])) { |
|
887 | 887 | $longitude = $data[0]['position']['longitude']; |
888 | 888 | } |
889 | 889 | } |
890 | 890 | |
891 | - if ( isset( $data[0]['content'] ) && isset( $data[0]['content']['contact_information'] ) ) { |
|
892 | - if ( isset( $data[0]['content']['contact_information']['address'] ) ) { |
|
893 | - $address = strip_tags( $data[0]['content']['contact_information']['address'] ); |
|
894 | - $address = explode( "\n", $address ); |
|
891 | + if (isset($data[0]['content']) && isset($data[0]['content']['contact_information'])) { |
|
892 | + if (isset($data[0]['content']['contact_information']['address'])) { |
|
893 | + $address = strip_tags($data[0]['content']['contact_information']['address']); |
|
894 | + $address = explode("\n", $address); |
|
895 | 895 | |
896 | - foreach ( $address as $bitkey => $bit ) { |
|
897 | - $bit = ltrim( rtrim( $bit ) ); |
|
896 | + foreach ($address as $bitkey => $bit) { |
|
897 | + $bit = ltrim(rtrim($bit)); |
|
898 | 898 | |
899 | - if ( false === $bit || '' === $bit || null === $bit || empty( $bit ) ) { |
|
900 | - unset( $address[ $bitkey ] ); |
|
899 | + if (false === $bit || '' === $bit || null === $bit || empty($bit)) { |
|
900 | + unset($address[$bitkey]); |
|
901 | 901 | } |
902 | 902 | } |
903 | 903 | |
904 | - $address = implode( ', ', $address ); |
|
905 | - $address = str_replace( ', , ', ', ', $address ); |
|
904 | + $address = implode(', ', $address); |
|
905 | + $address = str_replace(', , ', ', ', $address); |
|
906 | 906 | } |
907 | 907 | } |
908 | 908 | |
909 | - if ( false !== $longitude ) { |
|
909 | + if (false !== $longitude) { |
|
910 | 910 | $location_data = array( |
911 | 911 | 'address' => (string) $address, |
912 | 912 | 'lat' => (string) $latitude, |
@@ -915,11 +915,11 @@ discard block |
||
915 | 915 | 'elevation' => '', |
916 | 916 | ); |
917 | 917 | |
918 | - if ( false !== $id && '0' !== $id ) { |
|
919 | - $prev = get_post_meta( $id, 'location', true ); |
|
920 | - update_post_meta( $id, 'location', $location_data, $prev ); |
|
921 | - } else { |
|
922 | - add_post_meta( $id, 'location', $location_data, true ); |
|
918 | + if (false !== $id && '0' !== $id) { |
|
919 | + $prev = get_post_meta($id, 'location', true); |
|
920 | + update_post_meta($id, 'location', $location_data, $prev); |
|
921 | + }else { |
|
922 | + add_post_meta($id, 'location', $location_data, true); |
|
923 | 923 | } |
924 | 924 | } |
925 | 925 | } |
@@ -929,17 +929,17 @@ discard block |
||
929 | 929 | /** |
930 | 930 | * Creates the main gallery data |
931 | 931 | */ |
932 | - public function set_featured_image( $data, $id ) { |
|
933 | - if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
934 | - $this->featured_image = $this->attach_image( $data[0]['content']['images'][0], $id, array( |
|
932 | + public function set_featured_image($data, $id) { |
|
933 | + if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) { |
|
934 | + $this->featured_image = $this->attach_image($data[0]['content']['images'][0], $id, array( |
|
935 | 935 | 'width' => '800', |
936 | 936 | 'height' => '600', |
937 | 937 | 'cropping' => 'h', |
938 | - ) ); |
|
938 | + )); |
|
939 | 939 | |
940 | - if ( false !== $this->featured_image ) { |
|
941 | - delete_post_meta( $id, '_thumbnail_id' ); |
|
942 | - add_post_meta( $id, '_thumbnail_id', $this->featured_image, true ); |
|
940 | + if (false !== $this->featured_image) { |
|
941 | + delete_post_meta($id, '_thumbnail_id'); |
|
942 | + add_post_meta($id, '_thumbnail_id', $this->featured_image, true); |
|
943 | 943 | } |
944 | 944 | } |
945 | 945 | } |
@@ -947,26 +947,26 @@ discard block |
||
947 | 947 | /** |
948 | 948 | * Sets a banner image |
949 | 949 | */ |
950 | - public function set_banner_image( $data, $id, $content = array( 'none' ) ) { |
|
951 | - if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
952 | - if ( in_array( 'unique_banner_image', $content ) && isset( $data[0]['destination_image'] ) && is_array( $data[0]['destination_image'] ) ) { |
|
953 | - $temp_banner = $this->attach_image( $data[0]['destination_image'], $id, array( |
|
950 | + public function set_banner_image($data, $id, $content = array('none')) { |
|
951 | + if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) { |
|
952 | + if (in_array('unique_banner_image', $content) && isset($data[0]['destination_image']) && is_array($data[0]['destination_image'])) { |
|
953 | + $temp_banner = $this->attach_image($data[0]['destination_image'], $id, array( |
|
954 | 954 | 'width' => '1920', |
955 | 955 | 'height' => '600', |
956 | 956 | 'cropping' => 'c', |
957 | 957 | )); |
958 | - } else { |
|
959 | - $temp_banner = $this->attach_image( $data[0]['content']['images'][1], $id, array( |
|
958 | + }else { |
|
959 | + $temp_banner = $this->attach_image($data[0]['content']['images'][1], $id, array( |
|
960 | 960 | 'width' => '1920', |
961 | 961 | 'height' => '600', |
962 | 962 | 'cropping' => 'c', |
963 | 963 | )); |
964 | 964 | } |
965 | 965 | |
966 | - if ( false !== $temp_banner ) { |
|
966 | + if (false !== $temp_banner) { |
|
967 | 967 | $this->banner_image = $temp_banner; |
968 | 968 | |
969 | - delete_post_meta( $id, 'image_group' ); |
|
969 | + delete_post_meta($id, 'image_group'); |
|
970 | 970 | |
971 | 971 | $new_banner = array( |
972 | 972 | 'banner_image' => array( |
@@ -974,7 +974,7 @@ discard block |
||
974 | 974 | ), |
975 | 975 | ); |
976 | 976 | |
977 | - add_post_meta( $id, 'image_group', $new_banner, true ); |
|
977 | + add_post_meta($id, 'image_group', $new_banner, true); |
|
978 | 978 | } |
979 | 979 | } |
980 | 980 | } |
@@ -982,17 +982,17 @@ discard block |
||
982 | 982 | /** |
983 | 983 | * Creates the main gallery data |
984 | 984 | */ |
985 | - public function create_main_gallery( $data, $id ) { |
|
986 | - if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
|
987 | - if ( isset( $this->options['image_replacing'] ) && 'on' === $this->options['image_replacing'] ) { |
|
988 | - $current_gallery = get_post_meta( $id, 'gallery', false ); |
|
985 | + public function create_main_gallery($data, $id) { |
|
986 | + if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) { |
|
987 | + if (isset($this->options['image_replacing']) && 'on' === $this->options['image_replacing']) { |
|
988 | + $current_gallery = get_post_meta($id, 'gallery', false); |
|
989 | 989 | |
990 | - if ( false !== $current_gallery && ! empty( $current_gallery ) ) { |
|
991 | - foreach ( $current_gallery as $g ) { |
|
992 | - delete_post_meta( $id, 'gallery', $g ); |
|
990 | + if (false !== $current_gallery && !empty($current_gallery)) { |
|
991 | + foreach ($current_gallery as $g) { |
|
992 | + delete_post_meta($id, 'gallery', $g); |
|
993 | 993 | |
994 | - if ( 'attachment' === get_post_type( $g ) ) { |
|
995 | - wp_delete_attachment( $g, true ); |
|
994 | + if ('attachment' === get_post_type($g)) { |
|
995 | + wp_delete_attachment($g, true); |
|
996 | 996 | } |
997 | 997 | } |
998 | 998 | } |
@@ -1000,32 +1000,32 @@ discard block |
||
1000 | 1000 | |
1001 | 1001 | $counter = 0; |
1002 | 1002 | |
1003 | - foreach ( $data[0]['content']['images'] as $image_data ) { |
|
1004 | - if ( ( 0 === $counter && false !== $this->featured_image ) || ( 1 === $counter && false !== $this->banner_image ) ) { |
|
1003 | + foreach ($data[0]['content']['images'] as $image_data) { |
|
1004 | + if ((0 === $counter && false !== $this->featured_image) || (1 === $counter && false !== $this->banner_image)) { |
|
1005 | 1005 | $counter++; |
1006 | 1006 | |
1007 | - if ( false !== $this->image_limit && false !== $this->image_limit ) { |
|
1007 | + if (false !== $this->image_limit && false !== $this->image_limit) { |
|
1008 | 1008 | $this->image_limit++; |
1009 | 1009 | } |
1010 | 1010 | |
1011 | 1011 | continue; |
1012 | 1012 | } |
1013 | 1013 | |
1014 | - if ( false !== $this->image_limit && $counter >= $this->image_limit ) { |
|
1014 | + if (false !== $this->image_limit && $counter >= $this->image_limit) { |
|
1015 | 1015 | continue; |
1016 | 1016 | } |
1017 | 1017 | |
1018 | - $this->gallery_meta[] = $this->attach_image( $image_data, $id ); |
|
1018 | + $this->gallery_meta[] = $this->attach_image($image_data, $id); |
|
1019 | 1019 | $counter++; |
1020 | 1020 | } |
1021 | 1021 | |
1022 | - if ( ! empty( $this->gallery_meta ) ) { |
|
1023 | - delete_post_meta( $id, 'gallery' ); |
|
1024 | - $this->gallery_meta = array_unique( $this->gallery_meta ); |
|
1022 | + if (!empty($this->gallery_meta)) { |
|
1023 | + delete_post_meta($id, 'gallery'); |
|
1024 | + $this->gallery_meta = array_unique($this->gallery_meta); |
|
1025 | 1025 | |
1026 | - foreach ( $this->gallery_meta as $gallery_id ) { |
|
1027 | - if ( false !== $gallery_id && '' !== $gallery_id && ! is_array( $gallery_id ) ) { |
|
1028 | - add_post_meta( $id, 'gallery', $gallery_id, false ); |
|
1026 | + foreach ($this->gallery_meta as $gallery_id) { |
|
1027 | + if (false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)) { |
|
1028 | + add_post_meta($id, 'gallery', $gallery_id, false); |
|
1029 | 1029 | } |
1030 | 1030 | } |
1031 | 1031 | } |
@@ -1035,7 +1035,7 @@ discard block |
||
1035 | 1035 | /** |
1036 | 1036 | * search_form |
1037 | 1037 | */ |
1038 | - public function get_scaling_url( $args = array() ) { |
|
1038 | + public function get_scaling_url($args = array()) { |
|
1039 | 1039 | $defaults = array( |
1040 | 1040 | 'width' => '1024', |
1041 | 1041 | 'height' => '768', |
@@ -1043,59 +1043,59 @@ discard block |
||
1043 | 1043 | 'cropping' => 'h', |
1044 | 1044 | ); |
1045 | 1045 | |
1046 | - if ( false !== $this->options ) { |
|
1047 | - if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) { |
|
1046 | + if (false !== $this->options) { |
|
1047 | + if (isset($this->options['width']) && '' !== $this->options['width']) { |
|
1048 | 1048 | $defaults['width'] = $this->options['width']; |
1049 | 1049 | } |
1050 | 1050 | |
1051 | - if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) { |
|
1051 | + if (isset($this->options['height']) && '' !== $this->options['height']) { |
|
1052 | 1052 | $defaults['height'] = $this->options['height']; |
1053 | 1053 | } |
1054 | 1054 | |
1055 | - if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) { |
|
1055 | + if (isset($this->options['cropping']) && '' !== $this->options['cropping']) { |
|
1056 | 1056 | $defaults['cropping'] = $this->options['cropping']; |
1057 | 1057 | } |
1058 | 1058 | } |
1059 | 1059 | |
1060 | - $args = wp_parse_args( $args, $defaults ); |
|
1060 | + $args = wp_parse_args($args, $defaults); |
|
1061 | 1061 | $cropping = $args['cropping']; |
1062 | 1062 | $width = $args['width']; |
1063 | 1063 | $height = $args['height']; |
1064 | 1064 | |
1065 | - return 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/'; |
|
1065 | + return 'https://wetu.com/ImageHandler/'.$cropping.$width.'x'.$height.'/'; |
|
1066 | 1066 | } |
1067 | 1067 | |
1068 | 1068 | /** |
1069 | 1069 | * Attaches 1 image |
1070 | 1070 | */ |
1071 | - public function attach_image( $v = false, $parent_id, $image_sizes = false, $banner = false ) { |
|
1072 | - if ( false !== $v ) { |
|
1073 | - $temp_fragment = explode( '/', $v['url_fragment'] ); |
|
1074 | - $url_filename = $temp_fragment[ count( $temp_fragment ) - 1 ]; |
|
1075 | - $url_filename = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $url_filename ); |
|
1076 | - $url_filename = trim( $url_filename ); |
|
1071 | + public function attach_image($v = false, $parent_id, $image_sizes = false, $banner = false) { |
|
1072 | + if (false !== $v) { |
|
1073 | + $temp_fragment = explode('/', $v['url_fragment']); |
|
1074 | + $url_filename = $temp_fragment[count($temp_fragment) - 1]; |
|
1075 | + $url_filename = str_replace(array('.jpg', '.png', '.jpeg'), '', $url_filename); |
|
1076 | + $url_filename = trim($url_filename); |
|
1077 | 1077 | $title = $url_filename; |
1078 | - $url_filename = str_replace( ' ', '_', $url_filename ); |
|
1078 | + $url_filename = str_replace(' ', '_', $url_filename); |
|
1079 | 1079 | |
1080 | - if ( ! isset( $this->options['image_replacing'] ) && in_array( $url_filename, $this->found_attachments ) ) { |
|
1081 | - return array_search( $url_filename, $this->found_attachments ); |
|
1080 | + if (!isset($this->options['image_replacing']) && in_array($url_filename, $this->found_attachments)) { |
|
1081 | + return array_search($url_filename, $this->found_attachments); |
|
1082 | 1082 | } |
1083 | 1083 | |
1084 | 1084 | $postdata = array(); |
1085 | 1085 | |
1086 | - if ( empty( $v['label'] ) ) { |
|
1086 | + if (empty($v['label'])) { |
|
1087 | 1087 | $v['label'] = ''; |
1088 | 1088 | } |
1089 | 1089 | |
1090 | - if ( ! empty( $v['description'] ) ) { |
|
1091 | - $desc = wp_strip_all_tags( $v['description'] ); |
|
1090 | + if (!empty($v['description'])) { |
|
1091 | + $desc = wp_strip_all_tags($v['description']); |
|
1092 | 1092 | $posdata = array( |
1093 | 1093 | 'post_excerpt' => $desc, |
1094 | 1094 | ); |
1095 | 1095 | } |
1096 | 1096 | |
1097 | - if ( ! empty( $v['section'] ) ) { |
|
1098 | - $desc = wp_strip_all_tags( $v['section'] ); |
|
1097 | + if (!empty($v['section'])) { |
|
1098 | + $desc = wp_strip_all_tags($v['section']); |
|
1099 | 1099 | $posdata = array( |
1100 | 1100 | 'post_excerpt' => $desc, |
1101 | 1101 | ); |
@@ -1103,83 +1103,83 @@ discard block |
||
1103 | 1103 | |
1104 | 1104 | $attach_id = null; |
1105 | 1105 | // Resizor - add option to setting if required. |
1106 | - $fragment = str_replace( ' ', '%20', $v['url_fragment'] ); |
|
1107 | - $url = $this->get_scaling_url( $image_sizes ) . $fragment; |
|
1108 | - $attach_id = $this->attach_external_image2( $url, $parent_id, '', $v['label'], $postdata ); |
|
1109 | - if ( ! empty( $attach_id ) ) { |
|
1110 | - $this->found_attachments[ $attach_id ] = $url_filename; |
|
1111 | - add_post_meta( $attach_id, 'lsx_wetu_id', $v['url_fragment'], true ); |
|
1106 | + $fragment = str_replace(' ', '%20', $v['url_fragment']); |
|
1107 | + $url = $this->get_scaling_url($image_sizes).$fragment; |
|
1108 | + $attach_id = $this->attach_external_image2($url, $parent_id, '', $v['label'], $postdata); |
|
1109 | + if (!empty($attach_id)) { |
|
1110 | + $this->found_attachments[$attach_id] = $url_filename; |
|
1111 | + add_post_meta($attach_id, 'lsx_wetu_id', $v['url_fragment'], true); |
|
1112 | 1112 | return $attach_id; |
1113 | 1113 | } |
1114 | 1114 | } |
1115 | 1115 | return false; |
1116 | 1116 | } |
1117 | 1117 | |
1118 | - public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
|
1119 | - if ( ! $url || ! $post_id ) { |
|
1120 | -return new WP_Error( 'missing', 'Need a valid URL and post ID...' ); } |
|
1118 | + public function attach_external_image2($url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array()) { |
|
1119 | + if (!$url || !$post_id) { |
|
1120 | +return new WP_Error('missing', 'Need a valid URL and post ID...'); } |
|
1121 | 1121 | $att_id = false; |
1122 | 1122 | |
1123 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
1124 | - require_once( ABSPATH . 'wp-admin/includes/media.php' ); |
|
1125 | - require_once( ABSPATH . 'wp-admin/includes/image.php' ); |
|
1123 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
1124 | + require_once(ABSPATH.'wp-admin/includes/media.php'); |
|
1125 | + require_once(ABSPATH.'wp-admin/includes/image.php'); |
|
1126 | 1126 | // Download file to temp location, returns full server path to temp file. |
1127 | 1127 | |
1128 | - $tmp = tempnam( '/tmp', 'FOO' ); |
|
1129 | - $image = wp_remote_get( $url ); |
|
1130 | - if ( ! is_wp_error( $image ) && ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) { |
|
1131 | - file_put_contents( $tmp, $image['body'] ); |
|
1132 | - chmod( $tmp, '777' ); |
|
1128 | + $tmp = tempnam('/tmp', 'FOO'); |
|
1129 | + $image = wp_remote_get($url); |
|
1130 | + if (!is_wp_error($image) && !empty($image) && isset($image['response']) && isset($image['response']['code']) && 200 === $image['response']['code']) { |
|
1131 | + file_put_contents($tmp, $image['body']); |
|
1132 | + chmod($tmp, '777'); |
|
1133 | 1133 | |
1134 | - 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 |
|
1135 | - $url_filename = basename( $matches[0] ); |
|
1136 | - $url_filename = str_replace( '%20', '_', $url_filename ); |
|
1134 | + 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 |
|
1135 | + $url_filename = basename($matches[0]); |
|
1136 | + $url_filename = str_replace('%20', '_', $url_filename); |
|
1137 | 1137 | // extract filename from url for title |
1138 | - $url_type = wp_check_filetype( $url_filename ); // determine file type (ext and mime/type) |
|
1138 | + $url_type = wp_check_filetype($url_filename); // determine file type (ext and mime/type) |
|
1139 | 1139 | |
1140 | 1140 | // override filename if given, reconstruct server path. |
1141 | - if ( ! empty( $filename ) && ' ' != $filename ) { |
|
1142 | - $filename = sanitize_file_name( $filename ); |
|
1143 | - $tmppath = pathinfo( $tmp ); |
|
1141 | + if (!empty($filename) && ' ' != $filename) { |
|
1142 | + $filename = sanitize_file_name($filename); |
|
1143 | + $tmppath = pathinfo($tmp); |
|
1144 | 1144 | |
1145 | 1145 | $extension = ''; |
1146 | - if ( isset( $tmppath['extension'] ) ) { |
|
1146 | + if (isset($tmppath['extension'])) { |
|
1147 | 1147 | $extension = $tmppath['extension']; |
1148 | 1148 | } |
1149 | 1149 | |
1150 | - $new = $tmppath['dirname'] . '/' . $filename . '.' . $extension; |
|
1151 | - rename( $tmp, $new ); // renames temp file on server |
|
1152 | - $tmp = $new; // push new filename (in path) to be used in file array later |
|
1150 | + $new = $tmppath['dirname'].'/'.$filename.'.'.$extension; |
|
1151 | + rename($tmp, $new); // renames temp file on server |
|
1152 | + $tmp = $new; // push new filename (in path) to be used in file array later |
|
1153 | 1153 | } |
1154 | 1154 | |
1155 | 1155 | // assemble file data (should be built like $_FILES since wp_handle_sideload() will be using). |
1156 | - $file_array['tmp_name'] = $tmp; // full server path to temp file |
|
1156 | + $file_array['tmp_name'] = $tmp; // full server path to temp file |
|
1157 | 1157 | |
1158 | - if ( ! empty( $filename ) && ' ' != $filename ) { |
|
1159 | - $file_array['name'] = $filename . '.' . $url_type['ext']; // user given filename for title, add original URL extension |
|
1160 | - } else { |
|
1161 | - $file_array['name'] = $url_filename; // just use original URL filename |
|
1158 | + if (!empty($filename) && ' ' != $filename) { |
|
1159 | + $file_array['name'] = $filename.'.'.$url_type['ext']; // user given filename for title, add original URL extension |
|
1160 | + }else { |
|
1161 | + $file_array['name'] = $url_filename; // just use original URL filename |
|
1162 | 1162 | } |
1163 | 1163 | |
1164 | 1164 | // set additional wp_posts columns. |
1165 | - if ( empty( $post_data['post_title'] ) ) { |
|
1165 | + if (empty($post_data['post_title'])) { |
|
1166 | 1166 | |
1167 | - $url_filename = str_replace( '%20', ' ', $url_filename ); |
|
1167 | + $url_filename = str_replace('%20', ' ', $url_filename); |
|
1168 | 1168 | |
1169 | - $post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] ); // just use the original filename (no extension) |
|
1169 | + $post_data['post_title'] = basename($url_filename, '.'.$url_type['ext']); // just use the original filename (no extension) |
|
1170 | 1170 | } |
1171 | 1171 | |
1172 | 1172 | // make sure gets tied to parent. |
1173 | - if ( empty( $post_data['post_parent'] ) ) { |
|
1173 | + if (empty($post_data['post_parent'])) { |
|
1174 | 1174 | $post_data['post_parent'] = $post_id; |
1175 | 1175 | } |
1176 | 1176 | |
1177 | 1177 | // do the validation and storage stuff. |
1178 | - $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 |
|
1178 | + $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 |
|
1179 | 1179 | |
1180 | 1180 | // If error storing permanently, unlink. |
1181 | - if ( is_wp_error( $att_id ) ) { |
|
1182 | - unlink( $file_array['tmp_name'] ); |
|
1181 | + if (is_wp_error($att_id)) { |
|
1182 | + unlink($file_array['tmp_name']); |
|
1183 | 1183 | return false; |
1184 | 1184 | } |
1185 | 1185 | } |
@@ -1206,33 +1206,33 @@ discard block |
||
1206 | 1206 | /** |
1207 | 1207 | * Formats the row for the completed list. |
1208 | 1208 | */ |
1209 | - public function format_completed_row( $response ) { |
|
1210 | - 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>' ); |
|
1209 | + public function format_completed_row($response) { |
|
1210 | + 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>'); |
|
1211 | 1211 | } |
1212 | 1212 | |
1213 | 1213 | /** |
1214 | 1214 | * Formats the error. |
1215 | 1215 | */ |
1216 | - public function format_error( $response ) { |
|
1217 | - echo wp_kses_post( '<li class="post-error"><span class="dashicons dashicons-no"></span>' . $response . '</li>' ); |
|
1216 | + public function format_error($response) { |
|
1217 | + echo wp_kses_post('<li class="post-error"><span class="dashicons dashicons-no"></span>'.$response.'</li>'); |
|
1218 | 1218 | } |
1219 | 1219 | |
1220 | 1220 | /** |
1221 | 1221 | * Does a multine search |
1222 | 1222 | */ |
1223 | - public function multineedle_stripos( $haystack, $needles, $offset = 0 ) { |
|
1223 | + public function multineedle_stripos($haystack, $needles, $offset = 0) { |
|
1224 | 1224 | $found = false; |
1225 | - $needle_count = count( $needles ); |
|
1225 | + $needle_count = count($needles); |
|
1226 | 1226 | |
1227 | - foreach ( $needles as $needle ) { |
|
1228 | - if ( false !== stripos( $haystack, $needle, $offset ) ) { |
|
1227 | + foreach ($needles as $needle) { |
|
1228 | + if (false !== stripos($haystack, $needle, $offset)) { |
|
1229 | 1229 | $found[] = true; |
1230 | 1230 | } |
1231 | 1231 | } |
1232 | 1232 | |
1233 | - if ( false !== $found && count( $found ) === $needle_count ) { |
|
1233 | + if (false !== $found && count($found) === $needle_count) { |
|
1234 | 1234 | return true; |
1235 | - } else { |
|
1235 | + }else { |
|
1236 | 1236 | return false; |
1237 | 1237 | } |
1238 | 1238 | } |
@@ -1240,7 +1240,7 @@ discard block |
||
1240 | 1240 | /** |
1241 | 1241 | * Grab all the current accommodation posts via the lsx_wetu_id field. |
1242 | 1242 | */ |
1243 | - public function find_current_accommodation( $post_type = 'accommodation' ) { |
|
1243 | + public function find_current_accommodation($post_type = 'accommodation') { |
|
1244 | 1244 | global $wpdb; |
1245 | 1245 | $return = array(); |
1246 | 1246 | |
@@ -1259,9 +1259,9 @@ discard block |
||
1259 | 1259 | "); |
1260 | 1260 | // @codingStandardsIgnoreEnd |
1261 | 1261 | |
1262 | - if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) { |
|
1263 | - foreach ( $current_accommodation as $accom ) { |
|
1264 | - $return[ $accom->meta_value ] = $accom; |
|
1262 | + if (null !== $current_accommodation && !empty($current_accommodation)) { |
|
1263 | + foreach ($current_accommodation as $accom) { |
|
1264 | + $return[$accom->meta_value] = $accom; |
|
1265 | 1265 | } |
1266 | 1266 | } |
1267 | 1267 | |
@@ -1271,20 +1271,20 @@ discard block |
||
1271 | 1271 | /** |
1272 | 1272 | * Set the Video date |
1273 | 1273 | */ |
1274 | - public function set_video_data( $data, $id ) { |
|
1275 | - if ( ! empty( $data[0]['content']['youtube_videos'] ) && is_array( $data[0]['content']['youtube_videos'] ) ) { |
|
1274 | + public function set_video_data($data, $id) { |
|
1275 | + if (!empty($data[0]['content']['youtube_videos']) && is_array($data[0]['content']['youtube_videos'])) { |
|
1276 | 1276 | $videos = false; |
1277 | 1277 | |
1278 | - foreach ( $data[0]['content']['youtube_videos'] as $video ) { |
|
1278 | + foreach ($data[0]['content']['youtube_videos'] as $video) { |
|
1279 | 1279 | $temp_video = array(); |
1280 | 1280 | |
1281 | - if ( isset( $video['label'] ) ) { |
|
1281 | + if (isset($video['label'])) { |
|
1282 | 1282 | $temp_video['title'] = $video['label']; |
1283 | 1283 | } |
1284 | - if ( isset( $video['description'] ) ) { |
|
1285 | - $temp_video['description'] = strip_tags( $video['description'] ); |
|
1284 | + if (isset($video['description'])) { |
|
1285 | + $temp_video['description'] = strip_tags($video['description']); |
|
1286 | 1286 | } |
1287 | - if ( isset( $video['url'] ) ) { |
|
1287 | + if (isset($video['url'])) { |
|
1288 | 1288 | $temp_video['url'] = $video['url']; |
1289 | 1289 | } |
1290 | 1290 | |
@@ -1292,24 +1292,24 @@ discard block |
||
1292 | 1292 | $videos[] = $temp_video; |
1293 | 1293 | } |
1294 | 1294 | |
1295 | - if ( false !== $id && '0' !== $id ) { |
|
1296 | - delete_post_meta( $id, 'videos' ); |
|
1295 | + if (false !== $id && '0' !== $id) { |
|
1296 | + delete_post_meta($id, 'videos'); |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | - foreach ( $videos as $video ) { |
|
1300 | - add_post_meta( $id, 'videos', $video, false ); |
|
1299 | + foreach ($videos as $video) { |
|
1300 | + add_post_meta($id, 'videos', $video, false); |
|
1301 | 1301 | } |
1302 | 1302 | } |
1303 | 1303 | } |
1304 | 1304 | |
1305 | - public function shuffle_assoc( &$array ) { |
|
1305 | + public function shuffle_assoc(&$array) { |
|
1306 | 1306 | $new = array(); |
1307 | - $keys = array_keys( $array ); |
|
1307 | + $keys = array_keys($array); |
|
1308 | 1308 | |
1309 | - shuffle( $keys ); |
|
1309 | + shuffle($keys); |
|
1310 | 1310 | |
1311 | - foreach ( $keys as $key ) { |
|
1312 | - $new[ $key ] = $array[ $key ]; |
|
1311 | + foreach ($keys as $key) { |
|
1312 | + $new[$key] = $array[$key]; |
|
1313 | 1313 | } |
1314 | 1314 | |
1315 | 1315 | $array = $new; |
@@ -1323,31 +1323,31 @@ discard block |
||
1323 | 1323 | public function update_options() { |
1324 | 1324 | $own = ''; |
1325 | 1325 | $options = array(); |
1326 | - delete_option( 'lsx_ti_tours_api_options' ); |
|
1326 | + delete_option('lsx_ti_tours_api_options'); |
|
1327 | 1327 | |
1328 | - if ( isset( $_GET['own'] ) ) { |
|
1328 | + if (isset($_GET['own'])) { |
|
1329 | 1329 | $this->current_importer->url_qs .= '&own=true'; |
1330 | 1330 | $options[] = 'own'; |
1331 | 1331 | } |
1332 | 1332 | |
1333 | - if ( isset( $_GET['type'] ) && 'allitineraries' !== $_GET['type'] ) { |
|
1334 | - $this->current_importer->url_qs .= '&type=' . $_GET['type']; |
|
1333 | + if (isset($_GET['type']) && 'allitineraries' !== $_GET['type']) { |
|
1334 | + $this->current_importer->url_qs .= '&type='.$_GET['type']; |
|
1335 | 1335 | $options[] = $_GET['type']; |
1336 | - } else { |
|
1336 | + }else { |
|
1337 | 1337 | $options[] = 'sample'; |
1338 | 1338 | $this->current_importer->url_qs .= '&type=sample'; |
1339 | 1339 | } |
1340 | 1340 | |
1341 | - $url = str_replace( 'Pins', 'Itinerary', $this->current_importer->url . '/V8/List?' . $this->current_importer->url_qs ); |
|
1341 | + $url = str_replace('Pins', 'Itinerary', $this->current_importer->url.'/V8/List?'.$this->current_importer->url_qs); |
|
1342 | 1342 | $url .= '&results=2000'; |
1343 | - add_option( 'lsx_ti_tours_api_options', $options ); |
|
1344 | - $data = wp_remote_get( $url ); |
|
1345 | - $tours = json_decode( wp_remote_retrieve_body( $data ), true ); |
|
1343 | + add_option('lsx_ti_tours_api_options', $options); |
|
1344 | + $data = wp_remote_get($url); |
|
1345 | + $tours = json_decode(wp_remote_retrieve_body($data), true); |
|
1346 | 1346 | |
1347 | - if ( isset( $tours['error'] ) ) { |
|
1347 | + if (isset($tours['error'])) { |
|
1348 | 1348 | return $tours['error']; |
1349 | - } elseif ( isset( $tours['itineraries'] ) && ! empty( $tours['itineraries'] ) ) { |
|
1350 | - set_transient( 'lsx_ti_tours', $tours['itineraries'], 60 * 60 * 4 ); |
|
1349 | + } elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) { |
|
1350 | + set_transient('lsx_ti_tours', $tours['itineraries'], 60 * 60 * 4); |
|
1351 | 1351 | return true; |
1352 | 1352 | } |
1353 | 1353 | } |
@@ -1358,12 +1358,12 @@ discard block |
||
1358 | 1358 | * @param boolean $wetu_id |
1359 | 1359 | * @return string |
1360 | 1360 | */ |
1361 | - public function get_post_id_by_key_value( $wetu_id = false ) { |
|
1361 | + public function get_post_id_by_key_value($wetu_id = false) { |
|
1362 | 1362 | global $wpdb; |
1363 | 1363 | $id = false; |
1364 | - if ( false !== $wetu_id && '' !== $wetu_id ) { |
|
1365 | - $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 ) ) ); |
|
1366 | - if ( false !== $result && ! empty( $result ) ) { |
|
1364 | + if (false !== $wetu_id && '' !== $wetu_id) { |
|
1365 | + $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))); |
|
1366 | + if (false !== $result && !empty($result)) { |
|
1367 | 1367 | $id = $result; |
1368 | 1368 | } |
1369 | 1369 | } |
@@ -1372,11 +1372,11 @@ discard block |
||
1372 | 1372 | /** |
1373 | 1373 | * Set the team memberon each item. |
1374 | 1374 | */ |
1375 | - public function set_team_member( $id, $team_members ) { |
|
1376 | - delete_post_meta( $id, 'team_to_' . $this->tab_slug ); |
|
1375 | + public function set_team_member($id, $team_members) { |
|
1376 | + delete_post_meta($id, 'team_to_'.$this->tab_slug); |
|
1377 | 1377 | |
1378 | - foreach ( $team_members as $team ) { |
|
1379 | - add_post_meta( $id, 'team_to_' . $this->tab_slug, $team ); |
|
1378 | + foreach ($team_members as $team) { |
|
1379 | + add_post_meta($id, 'team_to_'.$this->tab_slug, $team); |
|
1380 | 1380 | } |
1381 | 1381 | } |
1382 | 1382 | } |
@@ -14,84 +14,84 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class LSX_WETU_Importer_Settings { |
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 | - * Holds the default settings. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - public $defaults = array(); |
|
24 | + /** |
|
25 | + * Holds the default settings. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + public $defaults = array(); |
|
30 | 30 | |
31 | - /** |
|
32 | - * Holds the settings fields available. |
|
33 | - * |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - public $fields = array(); |
|
31 | + /** |
|
32 | + * Holds the settings fields available. |
|
33 | + * |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + public $fields = array(); |
|
37 | 37 | |
38 | - /** |
|
39 | - * Initialize the plugin by setting localization, filters, and administration functions. |
|
40 | - * |
|
41 | - * @since 1.0.0 |
|
42 | - * |
|
43 | - * @access private |
|
44 | - */ |
|
45 | - public function __construct() { |
|
46 | - $this->defaults = array( |
|
47 | - 'api_key' => '', |
|
48 | - 'disable_tour_title' => '', |
|
49 | - 'disable_tour_descriptions' => '', |
|
50 | - 'disable_tour_tags' => 'on', |
|
51 | - 'enable_tour_featured_random' => '', |
|
52 | - 'disable_accommodation_title' => '', |
|
53 | - 'disable_accommodation_descriptions' => '', |
|
54 | - 'disable_accommodation_filtering' => '', |
|
55 | - 'disable_accommodation_excerpts' => '', |
|
56 | - 'disable_destination_title' => '', |
|
57 | - 'disable_destination_descriptions' => '', |
|
58 | - 'image_replacing' => 'on', |
|
59 | - 'image_limit' => '15', |
|
60 | - 'image_scaling' => 'on', |
|
61 | - 'width' => '800', |
|
62 | - 'height' => '600', |
|
63 | - 'scaling' => 'h', |
|
64 | - 'enable_tour_ref_column' => '', |
|
65 | - 'cron_schedule' => 'daily', |
|
66 | - 'accommodation_images_cron' => '', |
|
67 | - ); |
|
68 | - $this->fields = array_keys( $this->defaults ); |
|
69 | - add_action( 'admin_init', array( $this, 'save_options' ) ); |
|
70 | - } |
|
38 | + /** |
|
39 | + * Initialize the plugin by setting localization, filters, and administration functions. |
|
40 | + * |
|
41 | + * @since 1.0.0 |
|
42 | + * |
|
43 | + * @access private |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | + $this->defaults = array( |
|
47 | + 'api_key' => '', |
|
48 | + 'disable_tour_title' => '', |
|
49 | + 'disable_tour_descriptions' => '', |
|
50 | + 'disable_tour_tags' => 'on', |
|
51 | + 'enable_tour_featured_random' => '', |
|
52 | + 'disable_accommodation_title' => '', |
|
53 | + 'disable_accommodation_descriptions' => '', |
|
54 | + 'disable_accommodation_filtering' => '', |
|
55 | + 'disable_accommodation_excerpts' => '', |
|
56 | + 'disable_destination_title' => '', |
|
57 | + 'disable_destination_descriptions' => '', |
|
58 | + 'image_replacing' => 'on', |
|
59 | + 'image_limit' => '15', |
|
60 | + 'image_scaling' => 'on', |
|
61 | + 'width' => '800', |
|
62 | + 'height' => '600', |
|
63 | + 'scaling' => 'h', |
|
64 | + 'enable_tour_ref_column' => '', |
|
65 | + 'cron_schedule' => 'daily', |
|
66 | + 'accommodation_images_cron' => '', |
|
67 | + ); |
|
68 | + $this->fields = array_keys( $this->defaults ); |
|
69 | + add_action( 'admin_init', array( $this, 'save_options' ) ); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Return an instance of this class. |
|
74 | - * |
|
75 | - * @return object |
|
76 | - */ |
|
77 | - public static function get_instance() { |
|
78 | - // If the single instance hasn't been set, set it now. |
|
79 | - if ( ! isset( self::$instance ) ) { |
|
80 | - self::$instance = new self(); |
|
81 | - } |
|
82 | - return self::$instance; |
|
83 | - } |
|
72 | + /** |
|
73 | + * Return an instance of this class. |
|
74 | + * |
|
75 | + * @return object |
|
76 | + */ |
|
77 | + public static function get_instance() { |
|
78 | + // If the single instance hasn't been set, set it now. |
|
79 | + if ( ! isset( self::$instance ) ) { |
|
80 | + self::$instance = new self(); |
|
81 | + } |
|
82 | + return self::$instance; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Display the importer welcome screen |
|
87 | - */ |
|
88 | - public function display_page() { |
|
89 | - $options = lsx_wetu_get_options(); |
|
90 | - foreach ( $options as $key => $value ) { |
|
91 | - $value = trim( $value ); |
|
92 | - } |
|
93 | - $options = wp_parse_args( $options, $this->defaults ); |
|
94 | - ?> |
|
85 | + /** |
|
86 | + * Display the importer welcome screen |
|
87 | + */ |
|
88 | + public function display_page() { |
|
89 | + $options = lsx_wetu_get_options(); |
|
90 | + foreach ( $options as $key => $value ) { |
|
91 | + $value = trim( $value ); |
|
92 | + } |
|
93 | + $options = wp_parse_args( $options, $this->defaults ); |
|
94 | + ?> |
|
95 | 95 | <div class="wrap"> |
96 | 96 | <form method="post" class=""> |
97 | 97 | <?php wp_nonce_field( 'lsx_wetu_importer_save', 'lsx_wetu_importer_save_options' ); ?> |
@@ -106,10 +106,10 @@ discard block |
||
106 | 106 | <td> |
107 | 107 | <input data-toggle="tooltip" data-placement="top" title="The API key can be found on your My Account page of your WETU account." type="text" value=" |
108 | 108 | <?php |
109 | - if ( isset( $options['api_key'] ) ) { |
|
110 | - echo esc_attr( $options['api_key'] ); |
|
111 | - } |
|
112 | - ?> |
|
109 | + if ( isset( $options['api_key'] ) ) { |
|
110 | + echo esc_attr( $options['api_key'] ); |
|
111 | + } |
|
112 | + ?> |
|
113 | 113 | " name="api_key" /> |
114 | 114 | </td> |
115 | 115 | </tr> |
@@ -126,10 +126,10 @@ discard block |
||
126 | 126 | <td> |
127 | 127 | <input type="checkbox" |
128 | 128 | <?php |
129 | - if ( isset( $options['disable_tour_title'] ) && '' !== $options['disable_tour_title'] ) { |
|
130 | - echo esc_attr( 'checked="checked"' ); |
|
131 | - } |
|
132 | - ?> |
|
129 | + if ( isset( $options['disable_tour_title'] ) && '' !== $options['disable_tour_title'] ) { |
|
130 | + echo esc_attr( 'checked="checked"' ); |
|
131 | + } |
|
132 | + ?> |
|
133 | 133 | name="disable_tour_title" /> |
134 | 134 | |
135 | 135 | <small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
@@ -142,10 +142,10 @@ discard block |
||
142 | 142 | <td> |
143 | 143 | <input type="checkbox" |
144 | 144 | <?php |
145 | - if ( isset( $options['disable_tour_descriptions'] ) && '' !== $options['disable_tour_descriptions'] ) { |
|
146 | - echo esc_attr( 'checked="checked"' ); |
|
147 | - } |
|
148 | - ?> |
|
145 | + if ( isset( $options['disable_tour_descriptions'] ) && '' !== $options['disable_tour_descriptions'] ) { |
|
146 | + echo esc_attr( 'checked="checked"' ); |
|
147 | + } |
|
148 | + ?> |
|
149 | 149 | name="disable_tour_descriptions" /> |
150 | 150 | |
151 | 151 | <small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | <td> |
159 | 159 | <input type="checkbox" |
160 | 160 | <?php |
161 | - if ( isset( $options['disable_tour_tags'] ) && '' !== $options['disable_tour_tags'] ) { |
|
162 | - echo esc_attr( 'checked="checked"' ); |
|
163 | - } |
|
164 | - ?> |
|
161 | + if ( isset( $options['disable_tour_tags'] ) && '' !== $options['disable_tour_tags'] ) { |
|
162 | + echo esc_attr( 'checked="checked"' ); |
|
163 | + } |
|
164 | + ?> |
|
165 | 165 | name="disable_tour_tags" /> |
166 | 166 | |
167 | 167 | <small><?php esc_html_e( 'Disable this is you dont want the option available on the import screen.', 'lsx-wetu-importer' ); ?></small> |
@@ -175,10 +175,10 @@ discard block |
||
175 | 175 | <td> |
176 | 176 | <input type="checkbox" |
177 | 177 | <?php |
178 | - if ( isset( $options['enable_tour_ref_column'] ) && '' !== $options['enable_tour_ref_column'] ) { |
|
179 | - echo esc_attr( 'checked="checked"' ); |
|
180 | - } |
|
181 | - ?> |
|
178 | + if ( isset( $options['enable_tour_ref_column'] ) && '' !== $options['enable_tour_ref_column'] ) { |
|
179 | + echo esc_attr( 'checked="checked"' ); |
|
180 | + } |
|
181 | + ?> |
|
182 | 182 | name="enable_tour_ref_column" /> |
183 | 183 | <small><?php esc_html_e( 'Enables the use of the WETU Reference Column for better tours management.', 'lsx-wetu-importer' ); ?></small> |
184 | 184 | </td> |
@@ -191,10 +191,10 @@ discard block |
||
191 | 191 | <td> |
192 | 192 | <input type="checkbox" |
193 | 193 | <?php |
194 | - if ( isset( $options['enable_tour_featured_random'] ) && '' !== $options['enable_tour_featured_random'] ) { |
|
195 | - echo esc_attr( 'checked="checked"' ); |
|
196 | - } |
|
197 | - ?> |
|
194 | + if ( isset( $options['enable_tour_featured_random'] ) && '' !== $options['enable_tour_featured_random'] ) { |
|
195 | + echo esc_attr( 'checked="checked"' ); |
|
196 | + } |
|
197 | + ?> |
|
198 | 198 | name="enable_tour_featured_random" /> |
199 | 199 | <small><?php esc_html_e( 'This will randomize the featured image from the destination gallery.', 'lsx-wetu-importer' ); ?></small> |
200 | 200 | </td> |
@@ -213,10 +213,10 @@ discard block |
||
213 | 213 | <td> |
214 | 214 | <input type="checkbox" |
215 | 215 | <?php |
216 | - if ( isset( $options['disable_accommodation_title'] ) && '' !== $options['disable_accommodation_title'] ) { |
|
217 | - echo esc_attr( 'checked="checked"' ); |
|
218 | - } |
|
219 | - ?> |
|
216 | + if ( isset( $options['disable_accommodation_title'] ) && '' !== $options['disable_accommodation_title'] ) { |
|
217 | + echo esc_attr( 'checked="checked"' ); |
|
218 | + } |
|
219 | + ?> |
|
220 | 220 | name="disable_accommodation_title" /> |
221 | 221 | |
222 | 222 | <small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
@@ -229,10 +229,10 @@ discard block |
||
229 | 229 | <td> |
230 | 230 | <input type="checkbox" |
231 | 231 | <?php |
232 | - if ( isset( $options['disable_accommodation_descriptions'] ) && '' !== $options['disable_accommodation_descriptions'] ) { |
|
233 | - echo esc_attr( 'checked="checked"' ); |
|
234 | - } |
|
235 | - ?> |
|
232 | + if ( isset( $options['disable_accommodation_descriptions'] ) && '' !== $options['disable_accommodation_descriptions'] ) { |
|
233 | + echo esc_attr( 'checked="checked"' ); |
|
234 | + } |
|
235 | + ?> |
|
236 | 236 | name="disable_accommodation_descriptions" /> |
237 | 237 | <small><?php esc_html_e( 'If you are going to edit the accommodation descriptions imported then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
238 | 238 | </td> |
@@ -244,10 +244,10 @@ discard block |
||
244 | 244 | <td> |
245 | 245 | <input type="checkbox" |
246 | 246 | <?php |
247 | - if ( isset( $options['disable_accommodation_filtering'] ) && '' !== $options['disable_accommodation_filtering'] ) { |
|
248 | - echo esc_attr( 'checked="checked"' ); |
|
249 | - } |
|
250 | - ?> |
|
247 | + if ( isset( $options['disable_accommodation_filtering'] ) && '' !== $options['disable_accommodation_filtering'] ) { |
|
248 | + echo esc_attr( 'checked="checked"' ); |
|
249 | + } |
|
250 | + ?> |
|
251 | 251 | name="disable_accommodation_filtering" /> |
252 | 252 | <small><?php esc_html_e( 'This will stop the HTML from being stripped out of the description.', 'lsx-wetu-importer' ); ?></small> |
253 | 253 | </td> |
@@ -260,10 +260,10 @@ discard block |
||
260 | 260 | <td> |
261 | 261 | <input type="checkbox" |
262 | 262 | <?php |
263 | - if ( isset( $options['disable_accommodation_excerpts'] ) && '' !== $options['disable_accommodation_excerpts'] ) { |
|
264 | - echo esc_attr( 'checked="checked"' ); |
|
265 | - } |
|
266 | - ?> |
|
263 | + if ( isset( $options['disable_accommodation_excerpts'] ) && '' !== $options['disable_accommodation_excerpts'] ) { |
|
264 | + echo esc_attr( 'checked="checked"' ); |
|
265 | + } |
|
266 | + ?> |
|
267 | 267 | name="disable_accommodation_excerpts" /> |
268 | 268 | <small><?php esc_html_e( 'If you are going to edit the accommodation excerpts then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
269 | 269 | </td> |
@@ -282,10 +282,10 @@ discard block |
||
282 | 282 | <td> |
283 | 283 | <input type="checkbox" |
284 | 284 | <?php |
285 | - if ( isset( $options['disable_destination_title'] ) && '' !== $options['disable_destination_title'] ) { |
|
286 | - echo esc_attr( 'checked="checked"' ); |
|
287 | - } |
|
288 | - ?> |
|
285 | + if ( isset( $options['disable_destination_title'] ) && '' !== $options['disable_destination_title'] ) { |
|
286 | + echo esc_attr( 'checked="checked"' ); |
|
287 | + } |
|
288 | + ?> |
|
289 | 289 | name="disable_destination_title" /> |
290 | 290 | |
291 | 291 | <small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
@@ -298,10 +298,10 @@ discard block |
||
298 | 298 | <td> |
299 | 299 | <input type="checkbox" |
300 | 300 | <?php |
301 | - if ( isset( $options['disable_destination_descriptions'] ) && '' !== $options['disable_destination_descriptions'] ) { |
|
302 | - echo esc_attr( 'checked="checked"' ); |
|
303 | - } |
|
304 | - ?> |
|
301 | + if ( isset( $options['disable_destination_descriptions'] ) && '' !== $options['disable_destination_descriptions'] ) { |
|
302 | + echo esc_attr( 'checked="checked"' ); |
|
303 | + } |
|
304 | + ?> |
|
305 | 305 | name="disable_destination_descriptions" /> |
306 | 306 | <small><?php esc_html_e( 'If you are going to edit the destination descriptions on this site then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
307 | 307 | </td> |
@@ -320,10 +320,10 @@ discard block |
||
320 | 320 | <td> |
321 | 321 | <input type="checkbox" |
322 | 322 | <?php |
323 | - if ( isset( $options['image_replacing'] ) && '' !== $options['image_replacing'] ) { |
|
324 | - echo esc_attr( 'checked="checked"' ); |
|
325 | - } |
|
326 | - ?> |
|
323 | + if ( isset( $options['image_replacing'] ) && '' !== $options['image_replacing'] ) { |
|
324 | + echo esc_attr( 'checked="checked"' ); |
|
325 | + } |
|
326 | + ?> |
|
327 | 327 | name="image_replacing" /> |
328 | 328 | <p><?php esc_html_e( 'Do you want your images to be replaced on each import.', 'lsx-wetu-importer' ); ?></p> |
329 | 329 | </td> |
@@ -335,10 +335,10 @@ discard block |
||
335 | 335 | <td> |
336 | 336 | <input placeholder="" type="text" value=" |
337 | 337 | <?php |
338 | - if ( isset( $options['image_limit'] ) && '' !== $options['image_limit'] ) { |
|
339 | - echo esc_attr( $options['image_limit'] ); |
|
340 | - } |
|
341 | - ?> |
|
338 | + if ( isset( $options['image_limit'] ) && '' !== $options['image_limit'] ) { |
|
339 | + echo esc_attr( $options['image_limit'] ); |
|
340 | + } |
|
341 | + ?> |
|
342 | 342 | " |
343 | 343 | name="image_limit" /> |
344 | 344 | </td> |
@@ -351,10 +351,10 @@ discard block |
||
351 | 351 | <td> |
352 | 352 | <input type="checkbox" |
353 | 353 | <?php |
354 | - if ( isset( $options['image_scaling'] ) && '' !== $options['image_scaling'] ) { |
|
355 | - echo esc_attr( 'checked="checked"' ); |
|
356 | - } |
|
357 | - ?> |
|
354 | + if ( isset( $options['image_scaling'] ) && '' !== $options['image_scaling'] ) { |
|
355 | + echo esc_attr( 'checked="checked"' ); |
|
356 | + } |
|
357 | + ?> |
|
358 | 358 | name="image_scaling" /> |
359 | 359 | </td> |
360 | 360 | </tr> |
@@ -365,10 +365,10 @@ discard block |
||
365 | 365 | <td> |
366 | 366 | <input placeholder="800" type="text" value=" |
367 | 367 | <?php |
368 | - if ( isset( $options['width'] ) && '' !== $options['width'] ) { |
|
369 | - echo esc_attr( $options['width'] ); |
|
370 | - } |
|
371 | - ?> |
|
368 | + if ( isset( $options['width'] ) && '' !== $options['width'] ) { |
|
369 | + echo esc_attr( $options['width'] ); |
|
370 | + } |
|
371 | + ?> |
|
372 | 372 | " |
373 | 373 | name="width" /> |
374 | 374 | </td> |
@@ -380,10 +380,10 @@ discard block |
||
380 | 380 | <td> |
381 | 381 | <input placeholder="600" type="text" value=" |
382 | 382 | <?php |
383 | - if ( isset( $options['height'] ) && '' !== $options['height'] ) { |
|
384 | - echo esc_attr( $options['height'] ); |
|
385 | - } |
|
386 | - ?> |
|
383 | + if ( isset( $options['height'] ) && '' !== $options['height'] ) { |
|
384 | + echo esc_attr( $options['height'] ); |
|
385 | + } |
|
386 | + ?> |
|
387 | 387 | " |
388 | 388 | name="height" /> |
389 | 389 | </td> |
@@ -396,52 +396,52 @@ discard block |
||
396 | 396 | <td> |
397 | 397 | <input type="radio" |
398 | 398 | <?php |
399 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'raw' === $options['scaling'] ) { |
|
400 | - echo esc_attr( 'checked="checked"' ); |
|
401 | - } |
|
402 | - ?> |
|
399 | + if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'raw' === $options['scaling'] ) { |
|
400 | + echo esc_attr( 'checked="checked"' ); |
|
401 | + } |
|
402 | + ?> |
|
403 | 403 | name="scaling" value="raw" /> <?php esc_html_e( 'Get the Full size image, no cropping takes place.', 'lsx-wetu-importer' ); ?><br /> |
404 | 404 | <input type="radio" |
405 | 405 | <?php |
406 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'c' === $options['scaling'] ) { |
|
407 | - echo esc_attr( 'checked="checked"' ); |
|
408 | - } |
|
409 | - ?> |
|
406 | + if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'c' === $options['scaling'] ) { |
|
407 | + echo esc_attr( 'checked="checked"' ); |
|
408 | + } |
|
409 | + ?> |
|
410 | 410 | name="scaling" value="c" /> <?php esc_html_e( 'Crop image to fit fully into the frame, Crop is taken from middle, preserving as much of the image as possible.', 'lsx-wetu-importer' ); ?><br /> |
411 | 411 | <input type="radio" |
412 | 412 | <?php |
413 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'h' === $options['scaling'] ) { |
|
414 | - echo esc_attr( 'checked="checked"' ); |
|
415 | - } |
|
416 | - ?> |
|
413 | + if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'h' === $options['scaling'] ) { |
|
414 | + echo esc_attr( 'checked="checked"' ); |
|
415 | + } |
|
416 | + ?> |
|
417 | 417 | name="scaling" value="h" /> <?php esc_html_e( 'Crop image to fit fully into the frame, but resize to height first, then crop on width if needed', 'lsx-wetu-importer' ); ?><br /> |
418 | 418 | <input type="radio" |
419 | 419 | <?php |
420 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'w' === $options['scaling'] ) { |
|
421 | - echo esc_attr( 'checked="checked"' ); |
|
422 | - } |
|
423 | - ?> |
|
420 | + if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'w' === $options['scaling'] ) { |
|
421 | + echo esc_attr( 'checked="checked"' ); |
|
422 | + } |
|
423 | + ?> |
|
424 | 424 | name="scaling" value="w" /> <?php esc_html_e( 'Crop image to fit fully into the frame, but resize to width first, then crop on height if needed', 'lsx-wetu-importer' ); ?><br /> |
425 | 425 | <input type="radio" |
426 | 426 | <?php |
427 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'nf' === $options['scaling'] ) { |
|
428 | - echo esc_attr( 'checked="checked"' ); |
|
429 | - } |
|
430 | - ?> |
|
427 | + if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'nf' === $options['scaling'] ) { |
|
428 | + echo esc_attr( 'checked="checked"' ); |
|
429 | + } |
|
430 | + ?> |
|
431 | 431 | name="scaling" value="nf" /> <?php esc_html_e( 'Resize the image to fit within the frame. but pad the image with white to ensure the resolution matches the frame', 'lsx-wetu-importer' ); ?><br /> |
432 | 432 | <input type="radio" |
433 | 433 | <?php |
434 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'n' === $options['scaling'] ) { |
|
435 | - echo esc_attr( 'checked="checked"' ); |
|
436 | - } |
|
437 | - ?> |
|
434 | + if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'n' === $options['scaling'] ) { |
|
435 | + echo esc_attr( 'checked="checked"' ); |
|
436 | + } |
|
437 | + ?> |
|
438 | 438 | name="scaling" value="n" /> <?php esc_html_e( 'Resize the image to fit within the frame. but do not upscale the image.', 'lsx-wetu-importer' ); ?><br /> |
439 | 439 | <input type="radio" |
440 | 440 | <?php |
441 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'W' === $options['scaling'] ) { |
|
442 | - echo esc_attr( 'checked="checked"' ); |
|
443 | - } |
|
444 | - ?> |
|
441 | + if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'W' === $options['scaling'] ) { |
|
442 | + echo esc_attr( 'checked="checked"' ); |
|
443 | + } |
|
444 | + ?> |
|
445 | 445 | name="scaling" value="W" /> <?php esc_html_e( 'Resize the image to fit within the frame. Image will not exceed specified dimensions', 'lsx-wetu-importer' ); ?> |
446 | 446 | </td> |
447 | 447 | </tr> |
@@ -459,28 +459,28 @@ discard block |
||
459 | 459 | <td> |
460 | 460 | <select name="cron_schedule" id="cron_schedule" class="widefat layout"> |
461 | 461 | <?php |
462 | - if ( isset( $options['cron_schedule'] ) && '' !== $options['cron_schedule'] ) { |
|
463 | - $schedule = $options['cron_schedule']; |
|
464 | - } else { |
|
465 | - $schedule = 'daily'; |
|
466 | - } |
|
467 | - $timeslots = array( |
|
468 | - 'daily' => __( 'Daily', 'lsx-wetu-importer' ), |
|
469 | - 'weekly-mon' => __( 'Weekly (Monday)', 'lsx-wetu-importer' ), |
|
470 | - 'weekly-tue' => __( 'Weekly (Tuesday)', 'lsx-wetu-importer' ), |
|
471 | - 'weekly-wed' => __( 'Weekly (Wednesday)', 'lsx-wetu-importer' ), |
|
472 | - 'weekly-thu' => __( 'Weekly (Thursday)', 'lsx-wetu-importer' ), |
|
473 | - 'weekly-fri' => __( 'Weekly (Friday)', 'lsx-wetu-importer' ), |
|
474 | - 'weekly-sat' => __( 'Weekly (Saturday)', 'lsx-wetu-importer' ), |
|
475 | - 'weekly-sun' => __( 'Weekly (Sunday)', 'lsx-wetu-importer' ), |
|
476 | - ); |
|
477 | - foreach ( $timeslots as $key => $name ) { |
|
478 | - $selected = ( $schedule == $key ) ? ' selected="selected"' : ''; |
|
479 | - ?> |
|
462 | + if ( isset( $options['cron_schedule'] ) && '' !== $options['cron_schedule'] ) { |
|
463 | + $schedule = $options['cron_schedule']; |
|
464 | + } else { |
|
465 | + $schedule = 'daily'; |
|
466 | + } |
|
467 | + $timeslots = array( |
|
468 | + 'daily' => __( 'Daily', 'lsx-wetu-importer' ), |
|
469 | + 'weekly-mon' => __( 'Weekly (Monday)', 'lsx-wetu-importer' ), |
|
470 | + 'weekly-tue' => __( 'Weekly (Tuesday)', 'lsx-wetu-importer' ), |
|
471 | + 'weekly-wed' => __( 'Weekly (Wednesday)', 'lsx-wetu-importer' ), |
|
472 | + 'weekly-thu' => __( 'Weekly (Thursday)', 'lsx-wetu-importer' ), |
|
473 | + 'weekly-fri' => __( 'Weekly (Friday)', 'lsx-wetu-importer' ), |
|
474 | + 'weekly-sat' => __( 'Weekly (Saturday)', 'lsx-wetu-importer' ), |
|
475 | + 'weekly-sun' => __( 'Weekly (Sunday)', 'lsx-wetu-importer' ), |
|
476 | + ); |
|
477 | + foreach ( $timeslots as $key => $name ) { |
|
478 | + $selected = ( $schedule == $key ) ? ' selected="selected"' : ''; |
|
479 | + ?> |
|
480 | 480 | <option value="<?php echo wp_kses_post( $key ); ?>" id="<?php echo wp_kses_post( $key ); ?>" <?php echo wp_kses_post( $selected ); ?>><?php echo wp_kses_post( $name ); ?></option> |
481 | 481 | <?php |
482 | - } |
|
483 | - ?> |
|
482 | + } |
|
483 | + ?> |
|
484 | 484 | </select> |
485 | 485 | </td> |
486 | 486 | </tr> |
@@ -491,10 +491,10 @@ discard block |
||
491 | 491 | <td> |
492 | 492 | <input type="checkbox" |
493 | 493 | <?php |
494 | - if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { |
|
495 | - echo esc_attr( 'checked="checked"' ); |
|
496 | - } |
|
497 | - ?> |
|
494 | + if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { |
|
495 | + echo esc_attr( 'checked="checked"' ); |
|
496 | + } |
|
497 | + ?> |
|
498 | 498 | name="accommodation_images_cron" /> |
499 | 499 | <p><?php esc_html_e( 'Update the accommodation images accodring to the schedule above.', 'lsx-wetu-importer' ); ?></p> |
500 | 500 | </td> |
@@ -506,25 +506,25 @@ discard block |
||
506 | 506 | </form> |
507 | 507 | </div> |
508 | 508 | <?php |
509 | - } |
|
509 | + } |
|
510 | 510 | |
511 | - /** |
|
512 | - * Save the options fields |
|
513 | - * |
|
514 | - * @return void |
|
515 | - */ |
|
516 | - public function save_options() { |
|
517 | - if ( ! isset( $_POST['lsx_wetu_importer_save_options'] ) || ! wp_verify_nonce( $_POST['lsx_wetu_importer_save_options'], 'lsx_wetu_importer_save' ) ) { |
|
518 | - return; |
|
519 | - } |
|
520 | - $data_to_save = array(); |
|
521 | - foreach ( $this->defaults as $key => $field ) { |
|
522 | - if ( isset( $_POST[ $key ] ) ) { |
|
523 | - $data_to_save[ $key ] = sanitize_text_field( $_POST[ $key ] ); |
|
524 | - } else { |
|
525 | - $data_to_save[ $key ] = ''; |
|
526 | - } |
|
527 | - } |
|
528 | - update_option( 'lsx_wetu_importer_settings', $data_to_save ); |
|
529 | - } |
|
511 | + /** |
|
512 | + * Save the options fields |
|
513 | + * |
|
514 | + * @return void |
|
515 | + */ |
|
516 | + public function save_options() { |
|
517 | + if ( ! isset( $_POST['lsx_wetu_importer_save_options'] ) || ! wp_verify_nonce( $_POST['lsx_wetu_importer_save_options'], 'lsx_wetu_importer_save' ) ) { |
|
518 | + return; |
|
519 | + } |
|
520 | + $data_to_save = array(); |
|
521 | + foreach ( $this->defaults as $key => $field ) { |
|
522 | + if ( isset( $_POST[ $key ] ) ) { |
|
523 | + $data_to_save[ $key ] = sanitize_text_field( $_POST[ $key ] ); |
|
524 | + } else { |
|
525 | + $data_to_save[ $key ] = ''; |
|
526 | + } |
|
527 | + } |
|
528 | + update_option( 'lsx_wetu_importer_settings', $data_to_save ); |
|
529 | + } |
|
530 | 530 | } |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | 'cron_schedule' => 'daily', |
66 | 66 | 'accommodation_images_cron' => '', |
67 | 67 | ); |
68 | - $this->fields = array_keys( $this->defaults ); |
|
69 | - add_action( 'admin_init', array( $this, 'save_options' ) ); |
|
68 | + $this->fields = array_keys($this->defaults); |
|
69 | + add_action('admin_init', array($this, 'save_options')); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public static function get_instance() { |
78 | 78 | // If the single instance hasn't been set, set it now. |
79 | - if ( ! isset( self::$instance ) ) { |
|
79 | + if (!isset(self::$instance)) { |
|
80 | 80 | self::$instance = new self(); |
81 | 81 | } |
82 | 82 | return self::$instance; |
@@ -87,27 +87,27 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function display_page() { |
89 | 89 | $options = lsx_wetu_get_options(); |
90 | - foreach ( $options as $key => $value ) { |
|
91 | - $value = trim( $value ); |
|
90 | + foreach ($options as $key => $value) { |
|
91 | + $value = trim($value); |
|
92 | 92 | } |
93 | - $options = wp_parse_args( $options, $this->defaults ); |
|
93 | + $options = wp_parse_args($options, $this->defaults); |
|
94 | 94 | ?> |
95 | 95 | <div class="wrap"> |
96 | 96 | <form method="post" class=""> |
97 | - <?php wp_nonce_field( 'lsx_wetu_importer_save', 'lsx_wetu_importer_save_options' ); ?> |
|
98 | - <?php do_action( 'lsx_wetu_importer_settings_before' ); ?> |
|
99 | - <h1><?php esc_html_e( 'General', 'lsx-wetu-importer' ); ?></h1> |
|
97 | + <?php wp_nonce_field('lsx_wetu_importer_save', 'lsx_wetu_importer_save_options'); ?> |
|
98 | + <?php do_action('lsx_wetu_importer_settings_before'); ?> |
|
99 | + <h1><?php esc_html_e('General', 'lsx-wetu-importer'); ?></h1> |
|
100 | 100 | <table class="form-table"> |
101 | 101 | <tbody> |
102 | 102 | <tr class="form-field"> |
103 | 103 | <th scope="row"> |
104 | - <label for="wetu_api_key"><span title="The API key can be found on your My Account page of your WETU account." id="doc-tooltip" class="dashicons dashicons-editor-help tooltip"></span> <?php esc_html_e( 'API Key', 'lsx-wetu-importer' ); ?></label> |
|
104 | + <label for="wetu_api_key"><span title="The API key can be found on your My Account page of your WETU account." id="doc-tooltip" class="dashicons dashicons-editor-help tooltip"></span> <?php esc_html_e('API Key', 'lsx-wetu-importer'); ?></label> |
|
105 | 105 | </th> |
106 | 106 | <td> |
107 | 107 | <input data-toggle="tooltip" data-placement="top" title="The API key can be found on your My Account page of your WETU account." type="text" value=" |
108 | 108 | <?php |
109 | - if ( isset( $options['api_key'] ) ) { |
|
110 | - echo esc_attr( $options['api_key'] ); |
|
109 | + if (isset($options['api_key'])) { |
|
110 | + echo esc_attr($options['api_key']); |
|
111 | 111 | } |
112 | 112 | ?> |
113 | 113 | " name="api_key" /> |
@@ -116,227 +116,227 @@ discard block |
||
116 | 116 | </tbody> |
117 | 117 | </table> |
118 | 118 | |
119 | - <h1><?php esc_html_e( 'Tours', 'lsx-wetu-importer' ); ?></h1> |
|
119 | + <h1><?php esc_html_e('Tours', 'lsx-wetu-importer'); ?></h1> |
|
120 | 120 | <table class="form-table"> |
121 | 121 | <tbody> |
122 | 122 | <tr class="form-field -wrap"> |
123 | 123 | <th scope="row"> |
124 | - <label for="disable_tour_title"><?php esc_html_e( 'Enable Custom Titles', 'lsx-wetu-importer' ); ?></label> |
|
124 | + <label for="disable_tour_title"><?php esc_html_e('Enable Custom Titles', 'lsx-wetu-importer'); ?></label> |
|
125 | 125 | </th> |
126 | 126 | <td> |
127 | 127 | <input type="checkbox" |
128 | 128 | <?php |
129 | - if ( isset( $options['disable_tour_title'] ) && '' !== $options['disable_tour_title'] ) { |
|
130 | - echo esc_attr( 'checked="checked"' ); |
|
129 | + if (isset($options['disable_tour_title']) && '' !== $options['disable_tour_title']) { |
|
130 | + echo esc_attr('checked="checked"'); |
|
131 | 131 | } |
132 | 132 | ?> |
133 | 133 | name="disable_tour_title" /> |
134 | 134 | |
135 | - <small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
|
135 | + <small><?php esc_html_e('If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer'); ?></small> |
|
136 | 136 | </td> |
137 | 137 | </tr> |
138 | 138 | <tr class="form-field -wrap"> |
139 | 139 | <th scope="row"> |
140 | - <label for="disable_tour_descriptions"><?php esc_html_e( 'Disable Descriptions', 'lsx-wetu-importer' ); ?></label> |
|
140 | + <label for="disable_tour_descriptions"><?php esc_html_e('Disable Descriptions', 'lsx-wetu-importer'); ?></label> |
|
141 | 141 | </th> |
142 | 142 | <td> |
143 | 143 | <input type="checkbox" |
144 | 144 | <?php |
145 | - if ( isset( $options['disable_tour_descriptions'] ) && '' !== $options['disable_tour_descriptions'] ) { |
|
146 | - echo esc_attr( 'checked="checked"' ); |
|
145 | + if (isset($options['disable_tour_descriptions']) && '' !== $options['disable_tour_descriptions']) { |
|
146 | + echo esc_attr('checked="checked"'); |
|
147 | 147 | } |
148 | 148 | ?> |
149 | 149 | name="disable_tour_descriptions" /> |
150 | 150 | |
151 | - <small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
|
151 | + <small><?php esc_html_e('If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer'); ?></small> |
|
152 | 152 | </td> |
153 | 153 | </tr> |
154 | 154 | <tr class="form-field -wrap"> |
155 | 155 | <th scope="row"> |
156 | - <label for="disable_tour_tags"><?php esc_html_e( 'Disable Tags / Travel Styles', 'lsx-wetu-importer' ); ?></label> |
|
156 | + <label for="disable_tour_tags"><?php esc_html_e('Disable Tags / Travel Styles', 'lsx-wetu-importer'); ?></label> |
|
157 | 157 | </th> |
158 | 158 | <td> |
159 | 159 | <input type="checkbox" |
160 | 160 | <?php |
161 | - if ( isset( $options['disable_tour_tags'] ) && '' !== $options['disable_tour_tags'] ) { |
|
162 | - echo esc_attr( 'checked="checked"' ); |
|
161 | + if (isset($options['disable_tour_tags']) && '' !== $options['disable_tour_tags']) { |
|
162 | + echo esc_attr('checked="checked"'); |
|
163 | 163 | } |
164 | 164 | ?> |
165 | 165 | name="disable_tour_tags" /> |
166 | 166 | |
167 | - <small><?php esc_html_e( 'Disable this is you dont want the option available on the import screen.', 'lsx-wetu-importer' ); ?></small> |
|
167 | + <small><?php esc_html_e('Disable this is you dont want the option available on the import screen.', 'lsx-wetu-importer'); ?></small> |
|
168 | 168 | </td> |
169 | 169 | </tr> |
170 | 170 | |
171 | 171 | <tr class="form-field -wrap"> |
172 | 172 | <th scope="row"> |
173 | - <label for="enable_tour_ref_column"><?php esc_html_e( 'Enable Reference Column', 'lsx-wetu-importer' ); ?></label> |
|
173 | + <label for="enable_tour_ref_column"><?php esc_html_e('Enable Reference Column', 'lsx-wetu-importer'); ?></label> |
|
174 | 174 | </th> |
175 | 175 | <td> |
176 | 176 | <input type="checkbox" |
177 | 177 | <?php |
178 | - if ( isset( $options['enable_tour_ref_column'] ) && '' !== $options['enable_tour_ref_column'] ) { |
|
179 | - echo esc_attr( 'checked="checked"' ); |
|
178 | + if (isset($options['enable_tour_ref_column']) && '' !== $options['enable_tour_ref_column']) { |
|
179 | + echo esc_attr('checked="checked"'); |
|
180 | 180 | } |
181 | 181 | ?> |
182 | 182 | name="enable_tour_ref_column" /> |
183 | - <small><?php esc_html_e( 'Enables the use of the WETU Reference Column for better tours management.', 'lsx-wetu-importer' ); ?></small> |
|
183 | + <small><?php esc_html_e('Enables the use of the WETU Reference Column for better tours management.', 'lsx-wetu-importer'); ?></small> |
|
184 | 184 | </td> |
185 | 185 | </tr> |
186 | 186 | |
187 | 187 | <tr class="form-field -wrap"> |
188 | 188 | <th scope="row"> |
189 | - <label for="enable_tour_featured_random"><?php esc_html_e( 'Randomize Featured Image', 'lsx-wetu-importer' ); ?></label> |
|
189 | + <label for="enable_tour_featured_random"><?php esc_html_e('Randomize Featured Image', 'lsx-wetu-importer'); ?></label> |
|
190 | 190 | </th> |
191 | 191 | <td> |
192 | 192 | <input type="checkbox" |
193 | 193 | <?php |
194 | - if ( isset( $options['enable_tour_featured_random'] ) && '' !== $options['enable_tour_featured_random'] ) { |
|
195 | - echo esc_attr( 'checked="checked"' ); |
|
194 | + if (isset($options['enable_tour_featured_random']) && '' !== $options['enable_tour_featured_random']) { |
|
195 | + echo esc_attr('checked="checked"'); |
|
196 | 196 | } |
197 | 197 | ?> |
198 | 198 | name="enable_tour_featured_random" /> |
199 | - <small><?php esc_html_e( 'This will randomize the featured image from the destination gallery.', 'lsx-wetu-importer' ); ?></small> |
|
199 | + <small><?php esc_html_e('This will randomize the featured image from the destination gallery.', 'lsx-wetu-importer'); ?></small> |
|
200 | 200 | </td> |
201 | 201 | </tr> |
202 | 202 | </tbody> |
203 | 203 | </table> |
204 | 204 | |
205 | - <h1><?php esc_html_e( 'Accommodation', 'lsx-wetu-importer' ); ?></h1> |
|
205 | + <h1><?php esc_html_e('Accommodation', 'lsx-wetu-importer'); ?></h1> |
|
206 | 206 | |
207 | 207 | <table class="form-table"> |
208 | 208 | <tbody> |
209 | 209 | <tr class="form-field -wrap"> |
210 | 210 | <th scope="row"> |
211 | - <label for="disable_accommodation_title"><?php esc_html_e( 'Enable Custom Titles', 'lsx-wetu-importer' ); ?></label> |
|
211 | + <label for="disable_accommodation_title"><?php esc_html_e('Enable Custom Titles', 'lsx-wetu-importer'); ?></label> |
|
212 | 212 | </th> |
213 | 213 | <td> |
214 | 214 | <input type="checkbox" |
215 | 215 | <?php |
216 | - if ( isset( $options['disable_accommodation_title'] ) && '' !== $options['disable_accommodation_title'] ) { |
|
217 | - echo esc_attr( 'checked="checked"' ); |
|
216 | + if (isset($options['disable_accommodation_title']) && '' !== $options['disable_accommodation_title']) { |
|
217 | + echo esc_attr('checked="checked"'); |
|
218 | 218 | } |
219 | 219 | ?> |
220 | 220 | name="disable_accommodation_title" /> |
221 | 221 | |
222 | - <small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
|
222 | + <small><?php esc_html_e('If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer'); ?></small> |
|
223 | 223 | </td> |
224 | 224 | </tr> |
225 | 225 | <tr class="form-field -wrap"> |
226 | 226 | <th scope="row"> |
227 | - <label for="disable_accommodation_descriptions"><?php esc_html_e( 'Disable Descriptions', 'lsx-wetu-importer' ); ?></label> |
|
227 | + <label for="disable_accommodation_descriptions"><?php esc_html_e('Disable Descriptions', 'lsx-wetu-importer'); ?></label> |
|
228 | 228 | </th> |
229 | 229 | <td> |
230 | 230 | <input type="checkbox" |
231 | 231 | <?php |
232 | - if ( isset( $options['disable_accommodation_descriptions'] ) && '' !== $options['disable_accommodation_descriptions'] ) { |
|
233 | - echo esc_attr( 'checked="checked"' ); |
|
232 | + if (isset($options['disable_accommodation_descriptions']) && '' !== $options['disable_accommodation_descriptions']) { |
|
233 | + echo esc_attr('checked="checked"'); |
|
234 | 234 | } |
235 | 235 | ?> |
236 | 236 | name="disable_accommodation_descriptions" /> |
237 | - <small><?php esc_html_e( 'If you are going to edit the accommodation descriptions imported then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
|
237 | + <small><?php esc_html_e('If you are going to edit the accommodation descriptions imported then enable this setting.', 'lsx-wetu-importer'); ?></small> |
|
238 | 238 | </td> |
239 | 239 | </tr> |
240 | 240 | <tr class="form-field -wrap"> |
241 | 241 | <th scope="row"> |
242 | - <label for="disable_accommodation_filtering"><?php esc_html_e( 'Disable Description Filtering', 'lsx-wetu-importer' ); ?></label> |
|
242 | + <label for="disable_accommodation_filtering"><?php esc_html_e('Disable Description Filtering', 'lsx-wetu-importer'); ?></label> |
|
243 | 243 | </th> |
244 | 244 | <td> |
245 | 245 | <input type="checkbox" |
246 | 246 | <?php |
247 | - if ( isset( $options['disable_accommodation_filtering'] ) && '' !== $options['disable_accommodation_filtering'] ) { |
|
248 | - echo esc_attr( 'checked="checked"' ); |
|
247 | + if (isset($options['disable_accommodation_filtering']) && '' !== $options['disable_accommodation_filtering']) { |
|
248 | + echo esc_attr('checked="checked"'); |
|
249 | 249 | } |
250 | 250 | ?> |
251 | 251 | name="disable_accommodation_filtering" /> |
252 | - <small><?php esc_html_e( 'This will stop the HTML from being stripped out of the description.', 'lsx-wetu-importer' ); ?></small> |
|
252 | + <small><?php esc_html_e('This will stop the HTML from being stripped out of the description.', 'lsx-wetu-importer'); ?></small> |
|
253 | 253 | </td> |
254 | 254 | </tr> |
255 | 255 | |
256 | 256 | <tr class="form-field -wrap"> |
257 | 257 | <th scope="row"> |
258 | - <label for="disable_accommodation_excerpts"><?php esc_html_e( 'Disable Excerpts', 'lsx-wetu-importer' ); ?></label> |
|
258 | + <label for="disable_accommodation_excerpts"><?php esc_html_e('Disable Excerpts', 'lsx-wetu-importer'); ?></label> |
|
259 | 259 | </th> |
260 | 260 | <td> |
261 | 261 | <input type="checkbox" |
262 | 262 | <?php |
263 | - if ( isset( $options['disable_accommodation_excerpts'] ) && '' !== $options['disable_accommodation_excerpts'] ) { |
|
264 | - echo esc_attr( 'checked="checked"' ); |
|
263 | + if (isset($options['disable_accommodation_excerpts']) && '' !== $options['disable_accommodation_excerpts']) { |
|
264 | + echo esc_attr('checked="checked"'); |
|
265 | 265 | } |
266 | 266 | ?> |
267 | 267 | name="disable_accommodation_excerpts" /> |
268 | - <small><?php esc_html_e( 'If you are going to edit the accommodation excerpts then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
|
268 | + <small><?php esc_html_e('If you are going to edit the accommodation excerpts then enable this setting.', 'lsx-wetu-importer'); ?></small> |
|
269 | 269 | </td> |
270 | 270 | </tr> |
271 | 271 | </tbody> |
272 | 272 | </table> |
273 | 273 | |
274 | - <h1><?php esc_html_e( 'Destinations', 'lsx-wetu-importer' ); ?></h1> |
|
274 | + <h1><?php esc_html_e('Destinations', 'lsx-wetu-importer'); ?></h1> |
|
275 | 275 | |
276 | 276 | <table class="form-table"> |
277 | 277 | <tbody> |
278 | 278 | <tr class="form-field -wrap"> |
279 | 279 | <th scope="row"> |
280 | - <label for="disable_destination_title"><?php esc_html_e( 'Enable Custom Titles', 'lsx-wetu-importer' ); ?></label> |
|
280 | + <label for="disable_destination_title"><?php esc_html_e('Enable Custom Titles', 'lsx-wetu-importer'); ?></label> |
|
281 | 281 | </th> |
282 | 282 | <td> |
283 | 283 | <input type="checkbox" |
284 | 284 | <?php |
285 | - if ( isset( $options['disable_destination_title'] ) && '' !== $options['disable_destination_title'] ) { |
|
286 | - echo esc_attr( 'checked="checked"' ); |
|
285 | + if (isset($options['disable_destination_title']) && '' !== $options['disable_destination_title']) { |
|
286 | + echo esc_attr('checked="checked"'); |
|
287 | 287 | } |
288 | 288 | ?> |
289 | 289 | name="disable_destination_title" /> |
290 | 290 | |
291 | - <small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
|
291 | + <small><?php esc_html_e('If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer'); ?></small> |
|
292 | 292 | </td> |
293 | 293 | </tr> |
294 | 294 | <tr class="form-field -wrap"> |
295 | 295 | <th scope="row"> |
296 | - <label for="disable_destination_descriptions"><?php esc_html_e( 'Disable Descriptions', 'lsx-wetu-importer' ); ?></label> |
|
296 | + <label for="disable_destination_descriptions"><?php esc_html_e('Disable Descriptions', 'lsx-wetu-importer'); ?></label> |
|
297 | 297 | </th> |
298 | 298 | <td> |
299 | 299 | <input type="checkbox" |
300 | 300 | <?php |
301 | - if ( isset( $options['disable_destination_descriptions'] ) && '' !== $options['disable_destination_descriptions'] ) { |
|
302 | - echo esc_attr( 'checked="checked"' ); |
|
301 | + if (isset($options['disable_destination_descriptions']) && '' !== $options['disable_destination_descriptions']) { |
|
302 | + echo esc_attr('checked="checked"'); |
|
303 | 303 | } |
304 | 304 | ?> |
305 | 305 | name="disable_destination_descriptions" /> |
306 | - <small><?php esc_html_e( 'If you are going to edit the destination descriptions on this site then enable this setting.', 'lsx-wetu-importer' ); ?></small> |
|
306 | + <small><?php esc_html_e('If you are going to edit the destination descriptions on this site then enable this setting.', 'lsx-wetu-importer'); ?></small> |
|
307 | 307 | </td> |
308 | 308 | </tr> |
309 | 309 | </tbody> |
310 | 310 | </table> |
311 | 311 | |
312 | - <h1><?php esc_html_e( 'Images', 'lsx-wetu-importer' ); ?></h1> |
|
312 | + <h1><?php esc_html_e('Images', 'lsx-wetu-importer'); ?></h1> |
|
313 | 313 | |
314 | 314 | <table class="form-table"> |
315 | 315 | <tbody> |
316 | 316 | <tr class="form-field -wrap"> |
317 | 317 | <th scope="row"> |
318 | - <label for="image_replacing"><?php esc_html_e( 'Replace Images', 'lsx-wetu-importer' ); ?></label> |
|
318 | + <label for="image_replacing"><?php esc_html_e('Replace Images', 'lsx-wetu-importer'); ?></label> |
|
319 | 319 | </th> |
320 | 320 | <td> |
321 | 321 | <input type="checkbox" |
322 | 322 | <?php |
323 | - if ( isset( $options['image_replacing'] ) && '' !== $options['image_replacing'] ) { |
|
324 | - echo esc_attr( 'checked="checked"' ); |
|
323 | + if (isset($options['image_replacing']) && '' !== $options['image_replacing']) { |
|
324 | + echo esc_attr('checked="checked"'); |
|
325 | 325 | } |
326 | 326 | ?> |
327 | 327 | name="image_replacing" /> |
328 | - <p><?php esc_html_e( 'Do you want your images to be replaced on each import.', 'lsx-wetu-importer' ); ?></p> |
|
328 | + <p><?php esc_html_e('Do you want your images to be replaced on each import.', 'lsx-wetu-importer'); ?></p> |
|
329 | 329 | </td> |
330 | 330 | </tr> |
331 | 331 | <tr class="form-field -wrap"> |
332 | 332 | <th scope="row"> |
333 | - <label for="image_limit"> <?php esc_html_e( 'Limit the amount of images imported to the gallery', 'lsx-wetu-importer' ); ?></label> |
|
333 | + <label for="image_limit"> <?php esc_html_e('Limit the amount of images imported to the gallery', 'lsx-wetu-importer'); ?></label> |
|
334 | 334 | </th> |
335 | 335 | <td> |
336 | 336 | <input placeholder="" type="text" value=" |
337 | 337 | <?php |
338 | - if ( isset( $options['image_limit'] ) && '' !== $options['image_limit'] ) { |
|
339 | - echo esc_attr( $options['image_limit'] ); |
|
338 | + if (isset($options['image_limit']) && '' !== $options['image_limit']) { |
|
339 | + echo esc_attr($options['image_limit']); |
|
340 | 340 | } |
341 | 341 | ?> |
342 | 342 | " |
@@ -346,13 +346,13 @@ discard block |
||
346 | 346 | |
347 | 347 | <tr class="form-field -wrap"> |
348 | 348 | <th scope="row"> |
349 | - <label for="image_scaling"><?php esc_html_e( 'Enable Image Scaling', 'lsx-wetu-importer' ); ?></label> |
|
349 | + <label for="image_scaling"><?php esc_html_e('Enable Image Scaling', 'lsx-wetu-importer'); ?></label> |
|
350 | 350 | </th> |
351 | 351 | <td> |
352 | 352 | <input type="checkbox" |
353 | 353 | <?php |
354 | - if ( isset( $options['image_scaling'] ) && '' !== $options['image_scaling'] ) { |
|
355 | - echo esc_attr( 'checked="checked"' ); |
|
354 | + if (isset($options['image_scaling']) && '' !== $options['image_scaling']) { |
|
355 | + echo esc_attr('checked="checked"'); |
|
356 | 356 | } |
357 | 357 | ?> |
358 | 358 | name="image_scaling" /> |
@@ -360,13 +360,13 @@ discard block |
||
360 | 360 | </tr> |
361 | 361 | <tr class="form-field -wrap"> |
362 | 362 | <th scope="row"> |
363 | - <label for="width"> <?php esc_html_e( 'Width (px)', 'lsx-wetu-importer' ); ?></label> |
|
363 | + <label for="width"> <?php esc_html_e('Width (px)', 'lsx-wetu-importer'); ?></label> |
|
364 | 364 | </th> |
365 | 365 | <td> |
366 | 366 | <input placeholder="800" type="text" value=" |
367 | 367 | <?php |
368 | - if ( isset( $options['width'] ) && '' !== $options['width'] ) { |
|
369 | - echo esc_attr( $options['width'] ); |
|
368 | + if (isset($options['width']) && '' !== $options['width']) { |
|
369 | + echo esc_attr($options['width']); |
|
370 | 370 | } |
371 | 371 | ?> |
372 | 372 | " |
@@ -375,13 +375,13 @@ discard block |
||
375 | 375 | </tr> |
376 | 376 | <tr class="form-field -wrap"> |
377 | 377 | <th scope="row"> |
378 | - <label for="height"> <?php esc_html_e( 'Height (px)', 'lsx-wetu-importer' ); ?></label> |
|
378 | + <label for="height"> <?php esc_html_e('Height (px)', 'lsx-wetu-importer'); ?></label> |
|
379 | 379 | </th> |
380 | 380 | <td> |
381 | 381 | <input placeholder="600" type="text" value=" |
382 | 382 | <?php |
383 | - if ( isset( $options['height'] ) && '' !== $options['height'] ) { |
|
384 | - echo esc_attr( $options['height'] ); |
|
383 | + if (isset($options['height']) && '' !== $options['height']) { |
|
384 | + echo esc_attr($options['height']); |
|
385 | 385 | } |
386 | 386 | ?> |
387 | 387 | " |
@@ -391,93 +391,93 @@ discard block |
||
391 | 391 | |
392 | 392 | <tr class="form-field -wrap image-settings"> |
393 | 393 | <th scope="row"> |
394 | - <label for="scaling"> <?php esc_html_e( 'Scaling', 'lsx-wetu-importer' ); ?></label> |
|
394 | + <label for="scaling"> <?php esc_html_e('Scaling', 'lsx-wetu-importer'); ?></label> |
|
395 | 395 | </th> |
396 | 396 | <td> |
397 | 397 | <input type="radio" |
398 | 398 | <?php |
399 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'raw' === $options['scaling'] ) { |
|
400 | - echo esc_attr( 'checked="checked"' ); |
|
399 | + if (isset($options['scaling']) && '' !== $options['scaling'] && 'raw' === $options['scaling']) { |
|
400 | + echo esc_attr('checked="checked"'); |
|
401 | 401 | } |
402 | 402 | ?> |
403 | - name="scaling" value="raw" /> <?php esc_html_e( 'Get the Full size image, no cropping takes place.', 'lsx-wetu-importer' ); ?><br /> |
|
403 | + name="scaling" value="raw" /> <?php esc_html_e('Get the Full size image, no cropping takes place.', 'lsx-wetu-importer'); ?><br /> |
|
404 | 404 | <input type="radio" |
405 | 405 | <?php |
406 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'c' === $options['scaling'] ) { |
|
407 | - echo esc_attr( 'checked="checked"' ); |
|
406 | + if (isset($options['scaling']) && '' !== $options['scaling'] && 'c' === $options['scaling']) { |
|
407 | + echo esc_attr('checked="checked"'); |
|
408 | 408 | } |
409 | 409 | ?> |
410 | - name="scaling" value="c" /> <?php esc_html_e( 'Crop image to fit fully into the frame, Crop is taken from middle, preserving as much of the image as possible.', 'lsx-wetu-importer' ); ?><br /> |
|
410 | + name="scaling" value="c" /> <?php esc_html_e('Crop image to fit fully into the frame, Crop is taken from middle, preserving as much of the image as possible.', 'lsx-wetu-importer'); ?><br /> |
|
411 | 411 | <input type="radio" |
412 | 412 | <?php |
413 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'h' === $options['scaling'] ) { |
|
414 | - echo esc_attr( 'checked="checked"' ); |
|
413 | + if (isset($options['scaling']) && '' !== $options['scaling'] && 'h' === $options['scaling']) { |
|
414 | + echo esc_attr('checked="checked"'); |
|
415 | 415 | } |
416 | 416 | ?> |
417 | - name="scaling" value="h" /> <?php esc_html_e( 'Crop image to fit fully into the frame, but resize to height first, then crop on width if needed', 'lsx-wetu-importer' ); ?><br /> |
|
417 | + name="scaling" value="h" /> <?php esc_html_e('Crop image to fit fully into the frame, but resize to height first, then crop on width if needed', 'lsx-wetu-importer'); ?><br /> |
|
418 | 418 | <input type="radio" |
419 | 419 | <?php |
420 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'w' === $options['scaling'] ) { |
|
421 | - echo esc_attr( 'checked="checked"' ); |
|
420 | + if (isset($options['scaling']) && '' !== $options['scaling'] && 'w' === $options['scaling']) { |
|
421 | + echo esc_attr('checked="checked"'); |
|
422 | 422 | } |
423 | 423 | ?> |
424 | - name="scaling" value="w" /> <?php esc_html_e( 'Crop image to fit fully into the frame, but resize to width first, then crop on height if needed', 'lsx-wetu-importer' ); ?><br /> |
|
424 | + name="scaling" value="w" /> <?php esc_html_e('Crop image to fit fully into the frame, but resize to width first, then crop on height if needed', 'lsx-wetu-importer'); ?><br /> |
|
425 | 425 | <input type="radio" |
426 | 426 | <?php |
427 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'nf' === $options['scaling'] ) { |
|
428 | - echo esc_attr( 'checked="checked"' ); |
|
427 | + if (isset($options['scaling']) && '' !== $options['scaling'] && 'nf' === $options['scaling']) { |
|
428 | + echo esc_attr('checked="checked"'); |
|
429 | 429 | } |
430 | 430 | ?> |
431 | - name="scaling" value="nf" /> <?php esc_html_e( 'Resize the image to fit within the frame. but pad the image with white to ensure the resolution matches the frame', 'lsx-wetu-importer' ); ?><br /> |
|
431 | + name="scaling" value="nf" /> <?php esc_html_e('Resize the image to fit within the frame. but pad the image with white to ensure the resolution matches the frame', 'lsx-wetu-importer'); ?><br /> |
|
432 | 432 | <input type="radio" |
433 | 433 | <?php |
434 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'n' === $options['scaling'] ) { |
|
435 | - echo esc_attr( 'checked="checked"' ); |
|
434 | + if (isset($options['scaling']) && '' !== $options['scaling'] && 'n' === $options['scaling']) { |
|
435 | + echo esc_attr('checked="checked"'); |
|
436 | 436 | } |
437 | 437 | ?> |
438 | - name="scaling" value="n" /> <?php esc_html_e( 'Resize the image to fit within the frame. but do not upscale the image.', 'lsx-wetu-importer' ); ?><br /> |
|
438 | + name="scaling" value="n" /> <?php esc_html_e('Resize the image to fit within the frame. but do not upscale the image.', 'lsx-wetu-importer'); ?><br /> |
|
439 | 439 | <input type="radio" |
440 | 440 | <?php |
441 | - if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'W' === $options['scaling'] ) { |
|
442 | - echo esc_attr( 'checked="checked"' ); |
|
441 | + if (isset($options['scaling']) && '' !== $options['scaling'] && 'W' === $options['scaling']) { |
|
442 | + echo esc_attr('checked="checked"'); |
|
443 | 443 | } |
444 | 444 | ?> |
445 | - name="scaling" value="W" /> <?php esc_html_e( 'Resize the image to fit within the frame. Image will not exceed specified dimensions', 'lsx-wetu-importer' ); ?> |
|
445 | + name="scaling" value="W" /> <?php esc_html_e('Resize the image to fit within the frame. Image will not exceed specified dimensions', 'lsx-wetu-importer'); ?> |
|
446 | 446 | </td> |
447 | 447 | </tr> |
448 | 448 | </tbody> |
449 | 449 | </table> |
450 | 450 | |
451 | - <h1><?php esc_html_e( 'Sync', 'lsx-wetu-importer' ); ?></h1> |
|
451 | + <h1><?php esc_html_e('Sync', 'lsx-wetu-importer'); ?></h1> |
|
452 | 452 | |
453 | 453 | <table class="form-table"> |
454 | 454 | <tbody> |
455 | 455 | <tr class="form-field -wrap"> |
456 | 456 | <th scope="row"> |
457 | - <label for="cron_schedule"><?php esc_html_e( 'Schedule', 'lsx-wetu-importer' ); ?></label> |
|
457 | + <label for="cron_schedule"><?php esc_html_e('Schedule', 'lsx-wetu-importer'); ?></label> |
|
458 | 458 | </th> |
459 | 459 | <td> |
460 | 460 | <select name="cron_schedule" id="cron_schedule" class="widefat layout"> |
461 | 461 | <?php |
462 | - if ( isset( $options['cron_schedule'] ) && '' !== $options['cron_schedule'] ) { |
|
462 | + if (isset($options['cron_schedule']) && '' !== $options['cron_schedule']) { |
|
463 | 463 | $schedule = $options['cron_schedule']; |
464 | - } else { |
|
464 | + }else { |
|
465 | 465 | $schedule = 'daily'; |
466 | 466 | } |
467 | 467 | $timeslots = array( |
468 | - 'daily' => __( 'Daily', 'lsx-wetu-importer' ), |
|
469 | - 'weekly-mon' => __( 'Weekly (Monday)', 'lsx-wetu-importer' ), |
|
470 | - 'weekly-tue' => __( 'Weekly (Tuesday)', 'lsx-wetu-importer' ), |
|
471 | - 'weekly-wed' => __( 'Weekly (Wednesday)', 'lsx-wetu-importer' ), |
|
472 | - 'weekly-thu' => __( 'Weekly (Thursday)', 'lsx-wetu-importer' ), |
|
473 | - 'weekly-fri' => __( 'Weekly (Friday)', 'lsx-wetu-importer' ), |
|
474 | - 'weekly-sat' => __( 'Weekly (Saturday)', 'lsx-wetu-importer' ), |
|
475 | - 'weekly-sun' => __( 'Weekly (Sunday)', 'lsx-wetu-importer' ), |
|
468 | + 'daily' => __('Daily', 'lsx-wetu-importer'), |
|
469 | + 'weekly-mon' => __('Weekly (Monday)', 'lsx-wetu-importer'), |
|
470 | + 'weekly-tue' => __('Weekly (Tuesday)', 'lsx-wetu-importer'), |
|
471 | + 'weekly-wed' => __('Weekly (Wednesday)', 'lsx-wetu-importer'), |
|
472 | + 'weekly-thu' => __('Weekly (Thursday)', 'lsx-wetu-importer'), |
|
473 | + 'weekly-fri' => __('Weekly (Friday)', 'lsx-wetu-importer'), |
|
474 | + 'weekly-sat' => __('Weekly (Saturday)', 'lsx-wetu-importer'), |
|
475 | + 'weekly-sun' => __('Weekly (Sunday)', 'lsx-wetu-importer'), |
|
476 | 476 | ); |
477 | - foreach ( $timeslots as $key => $name ) { |
|
478 | - $selected = ( $schedule == $key ) ? ' selected="selected"' : ''; |
|
477 | + foreach ($timeslots as $key => $name) { |
|
478 | + $selected = ($schedule == $key) ? ' selected="selected"' : ''; |
|
479 | 479 | ?> |
480 | - <option value="<?php echo wp_kses_post( $key ); ?>" id="<?php echo wp_kses_post( $key ); ?>" <?php echo wp_kses_post( $selected ); ?>><?php echo wp_kses_post( $name ); ?></option> |
|
480 | + <option value="<?php echo wp_kses_post($key); ?>" id="<?php echo wp_kses_post($key); ?>" <?php echo wp_kses_post($selected); ?>><?php echo wp_kses_post($name); ?></option> |
|
481 | 481 | <?php |
482 | 482 | } |
483 | 483 | ?> |
@@ -486,23 +486,23 @@ discard block |
||
486 | 486 | </tr> |
487 | 487 | <tr class="form-field -wrap"> |
488 | 488 | <th scope="row"> |
489 | - <label for="accommodation_images_cron"><?php esc_html_e( 'Accommodation Images', 'lsx-wetu-importer' ); ?></label> |
|
489 | + <label for="accommodation_images_cron"><?php esc_html_e('Accommodation Images', 'lsx-wetu-importer'); ?></label> |
|
490 | 490 | </th> |
491 | 491 | <td> |
492 | 492 | <input type="checkbox" |
493 | 493 | <?php |
494 | - if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { |
|
495 | - echo esc_attr( 'checked="checked"' ); |
|
494 | + if (isset($options['accommodation_images_cron']) && '' !== $options['accommodation_images_cron']) { |
|
495 | + echo esc_attr('checked="checked"'); |
|
496 | 496 | } |
497 | 497 | ?> |
498 | 498 | name="accommodation_images_cron" /> |
499 | - <p><?php esc_html_e( 'Update the accommodation images accodring to the schedule above.', 'lsx-wetu-importer' ); ?></p> |
|
499 | + <p><?php esc_html_e('Update the accommodation images accodring to the schedule above.', 'lsx-wetu-importer'); ?></p> |
|
500 | 500 | </td> |
501 | 501 | </tr> |
502 | 502 | </tbody> |
503 | 503 | </table> |
504 | 504 | |
505 | - <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_html_e( 'Save Changes', 'lsx-wetu-importer' ); ?>"></p> |
|
505 | + <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_html_e('Save Changes', 'lsx-wetu-importer'); ?>"></p> |
|
506 | 506 | </form> |
507 | 507 | </div> |
508 | 508 | <?php |
@@ -514,17 +514,17 @@ discard block |
||
514 | 514 | * @return void |
515 | 515 | */ |
516 | 516 | public function save_options() { |
517 | - if ( ! isset( $_POST['lsx_wetu_importer_save_options'] ) || ! wp_verify_nonce( $_POST['lsx_wetu_importer_save_options'], 'lsx_wetu_importer_save' ) ) { |
|
517 | + if (!isset($_POST['lsx_wetu_importer_save_options']) || !wp_verify_nonce($_POST['lsx_wetu_importer_save_options'], 'lsx_wetu_importer_save')) { |
|
518 | 518 | return; |
519 | 519 | } |
520 | 520 | $data_to_save = array(); |
521 | - foreach ( $this->defaults as $key => $field ) { |
|
522 | - if ( isset( $_POST[ $key ] ) ) { |
|
523 | - $data_to_save[ $key ] = sanitize_text_field( $_POST[ $key ] ); |
|
524 | - } else { |
|
525 | - $data_to_save[ $key ] = ''; |
|
521 | + foreach ($this->defaults as $key => $field) { |
|
522 | + if (isset($_POST[$key])) { |
|
523 | + $data_to_save[$key] = sanitize_text_field($_POST[$key]); |
|
524 | + }else { |
|
525 | + $data_to_save[$key] = ''; |
|
526 | 526 | } |
527 | 527 | } |
528 | - update_option( 'lsx_wetu_importer_settings', $data_to_save ); |
|
528 | + update_option('lsx_wetu_importer_settings', $data_to_save); |
|
529 | 529 | } |
530 | 530 | } |
@@ -16,234 +16,234 @@ |
||
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 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Return an instance of this class. |
|
44 | - * |
|
45 | - * @since 1.0.0 |
|
46 | - * |
|
47 | - * @return object Cron() A single instance of this class. |
|
48 | - */ |
|
49 | - public static function get_instance() { |
|
50 | - // If the single instance hasn't been set, set it now. |
|
51 | - if ( null === self::$instance ) { |
|
52 | - self::$instance = new self(); |
|
53 | - } |
|
54 | - return self::$instance; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Registers a 5 min schedule for us to use. |
|
59 | - * |
|
60 | - * @param array $schedules |
|
61 | - * @return array |
|
62 | - */ |
|
63 | - public function register_schedule( $schedules ) { |
|
64 | - $schedules['wetu-5-minutes'] = array( |
|
65 | - 'interval' => 5 * MINUTE_IN_SECONDS, |
|
66 | - 'display' => __( 'Every 5 minutes', 'lsx-wetu-importer' ), |
|
67 | - ); |
|
68 | - return $schedules; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Watches for changes in the button triggers. |
|
73 | - * |
|
74 | - * @return void |
|
75 | - */ |
|
76 | - public function watch_for_trigger() { |
|
77 | - |
|
78 | - if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) { |
|
79 | - $options = lsx_wetu_get_options(); |
|
80 | - |
|
81 | - // Check what state the option is in. |
|
82 | - $accommodation_cron = 'deactivate'; |
|
83 | - if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { |
|
84 | - $accommodation_cron = 'activate'; |
|
85 | - } |
|
86 | - |
|
87 | - // Check what state the cron is in. |
|
88 | - $schedule = false; |
|
89 | - if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) { |
|
90 | - $schedule = true; |
|
91 | - } |
|
92 | - |
|
93 | - // If activate and its not running. |
|
94 | - if ( false === $schedule && 'activate' === $accommodation_cron ) { |
|
95 | - $schedule = 'daily'; |
|
96 | - $this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule ); |
|
97 | - } elseif ( true === $schedule && 'deactivate' === $accommodation_cron ) { |
|
98 | - $this->deactivate(); |
|
99 | - } |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Remove our cron from the shedule. |
|
105 | - * |
|
106 | - * @return void |
|
107 | - */ |
|
108 | - public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) { |
|
109 | - wp_clear_scheduled_hook( $task, array( $task ) ); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * This function will schedule the cron event. |
|
114 | - * |
|
115 | - * @param string $task |
|
116 | - * @param string $schedule |
|
117 | - * @param string $time |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'daily', $time = '' ) { |
|
121 | - if ( '' === $time ) { |
|
122 | - $time = time(); |
|
123 | - } |
|
124 | - wp_schedule_event( $time, $schedule, $task, array( $task ) ); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * This is the function that will be triggered by the cron event. |
|
129 | - * |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - public function process( $task = '' ) { |
|
133 | - switch ( $task ) { |
|
134 | - case 'lsx_wetu_accommodation_images_cron': |
|
135 | - $this->register_accommodation_images_sync(); |
|
136 | - break; |
|
137 | - |
|
138 | - default: |
|
139 | - break; |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * This is the function that will be triggered by the cron event. |
|
145 | - * |
|
146 | - * @return void |
|
147 | - */ |
|
148 | - public function register_accommodation_images_sync() { |
|
149 | - $time = strtotime( '+1 min' ); |
|
150 | - if ( ! wp_next_scheduled( 'lsx_wetu_accommodation_images_sync' ) ) { |
|
151 | - $this->load_items_to_sync( 'accommodation_images' ); |
|
152 | - $this->schedule( 'lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time ); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * This is the function that will be triggered by the cron event. |
|
158 | - * |
|
159 | - * @return void |
|
160 | - */ |
|
161 | - public function cron_callback( $task = '' ) { |
|
162 | - $has_accommodation = get_option( $task ); |
|
163 | - if ( false !== $has_accommodation && ! empty( $has_accommodation ) ) { |
|
164 | - $next_time = array_slice( $has_accommodation, 5 ); |
|
165 | - $this_time = array_slice( $has_accommodation, 0, 4 ); |
|
166 | - |
|
167 | - $api_key = $this->get_api_key(); |
|
168 | - $url = 'https://wetu.com/API/Pins/' . $api_key . '/Get?all=include&ids='; |
|
169 | - |
|
170 | - // Run through the current items. |
|
171 | - foreach ( $this_time as $accommodation ) { |
|
172 | - $wetu_id = get_post_meta( $accommodation, 'lsx_wetu_id', true ); |
|
173 | - $last_date = get_post_meta( $accommodation, 'lsx_wetu_modified_date', true ); |
|
174 | - |
|
175 | - $accommodation_info = wp_remote_get( $url . $wetu_id ); |
|
176 | - if ( ! empty( $accommodation_info ) && isset( $accommodation_info['response'] ) && isset( $accommodation_info['response']['code'] ) && 200 === $accommodation_info['response']['code'] ) { |
|
177 | - $adata = json_decode( $accommodation_info['body'], true ); |
|
178 | - |
|
179 | - if ( isset( $adata[0] ) && isset( $adata[0]['last_modified'] ) && '' !== $adata[0]['last_modified'] ) { |
|
180 | - $modified_time = strtotime( $adata[0]['last_modified'] ); |
|
181 | - if ( $modified_time > $last_date ) { |
|
182 | - $accommodation_importer = new \LSX_WETU_Importer_Accommodation(); |
|
183 | - $accommodation_importer->create_main_gallery( $adata, $accommodation ); |
|
184 | - update_post_meta( $accommodation, 'lsx_wetu_modified_date', $modified_time, $last_date ); |
|
185 | - } |
|
186 | - } |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - // Save the values for next time. |
|
191 | - if ( ! empty( $next_time ) ) { |
|
192 | - update_option( $task, $next_time ); |
|
193 | - } else { |
|
194 | - delete_option( $task ); |
|
195 | - $this->deactivate( $task ); |
|
196 | - } |
|
197 | - } else { |
|
198 | - $this->deactivate( $task ); |
|
199 | - update_option( 'lsx_wetu_nexttime', $task ); |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * This will grab the accommodation ids and load them up into an option field. |
|
205 | - * |
|
206 | - * @param string $task |
|
207 | - * @return void |
|
208 | - */ |
|
209 | - public function load_items_to_sync( $task = 'accommodation_images' ) { |
|
210 | - $args = array( |
|
211 | - 'post_status' => 'publish', |
|
212 | - 'posts_per_page' => -1, |
|
213 | - 'nopagin' => true, |
|
214 | - 'fields' => 'ids', |
|
215 | - ); |
|
216 | - switch ( $task ) { |
|
217 | - case 'accommodation_images': |
|
218 | - $args['post_type'] = 'accommodation'; |
|
219 | - break; |
|
220 | - |
|
221 | - default: |
|
222 | - break; |
|
223 | - } |
|
224 | - $items = new \WP_Query( $args ); |
|
225 | - if ( $items->have_posts() ) { |
|
226 | - update_option( 'lsx_wetu_' . $task . '_sync', $items->posts ); |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Gets the API key stored in the options table. |
|
232 | - * |
|
233 | - * @return string |
|
234 | - */ |
|
235 | - public function get_api_key() { |
|
236 | - $api_key = false; |
|
237 | - $options = lsx_wetu_get_options(); |
|
238 | - |
|
239 | - if ( ! defined( 'WETU_API_KEY' ) ) { |
|
240 | - if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) { |
|
241 | - $api_key = $options['api_key']; |
|
242 | - } |
|
243 | - } else { |
|
244 | - $api_key = WETU_API_KEY; |
|
245 | - } |
|
246 | - return $api_key; |
|
247 | - } |
|
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 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Return an instance of this class. |
|
44 | + * |
|
45 | + * @since 1.0.0 |
|
46 | + * |
|
47 | + * @return object Cron() A single instance of this class. |
|
48 | + */ |
|
49 | + public static function get_instance() { |
|
50 | + // If the single instance hasn't been set, set it now. |
|
51 | + if ( null === self::$instance ) { |
|
52 | + self::$instance = new self(); |
|
53 | + } |
|
54 | + return self::$instance; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Registers a 5 min schedule for us to use. |
|
59 | + * |
|
60 | + * @param array $schedules |
|
61 | + * @return array |
|
62 | + */ |
|
63 | + public function register_schedule( $schedules ) { |
|
64 | + $schedules['wetu-5-minutes'] = array( |
|
65 | + 'interval' => 5 * MINUTE_IN_SECONDS, |
|
66 | + 'display' => __( 'Every 5 minutes', 'lsx-wetu-importer' ), |
|
67 | + ); |
|
68 | + return $schedules; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Watches for changes in the button triggers. |
|
73 | + * |
|
74 | + * @return void |
|
75 | + */ |
|
76 | + public function watch_for_trigger() { |
|
77 | + |
|
78 | + if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) { |
|
79 | + $options = lsx_wetu_get_options(); |
|
80 | + |
|
81 | + // Check what state the option is in. |
|
82 | + $accommodation_cron = 'deactivate'; |
|
83 | + if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { |
|
84 | + $accommodation_cron = 'activate'; |
|
85 | + } |
|
86 | + |
|
87 | + // Check what state the cron is in. |
|
88 | + $schedule = false; |
|
89 | + if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) { |
|
90 | + $schedule = true; |
|
91 | + } |
|
92 | + |
|
93 | + // If activate and its not running. |
|
94 | + if ( false === $schedule && 'activate' === $accommodation_cron ) { |
|
95 | + $schedule = 'daily'; |
|
96 | + $this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule ); |
|
97 | + } elseif ( true === $schedule && 'deactivate' === $accommodation_cron ) { |
|
98 | + $this->deactivate(); |
|
99 | + } |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Remove our cron from the shedule. |
|
105 | + * |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) { |
|
109 | + wp_clear_scheduled_hook( $task, array( $task ) ); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * This function will schedule the cron event. |
|
114 | + * |
|
115 | + * @param string $task |
|
116 | + * @param string $schedule |
|
117 | + * @param string $time |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'daily', $time = '' ) { |
|
121 | + if ( '' === $time ) { |
|
122 | + $time = time(); |
|
123 | + } |
|
124 | + wp_schedule_event( $time, $schedule, $task, array( $task ) ); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * This is the function that will be triggered by the cron event. |
|
129 | + * |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + public function process( $task = '' ) { |
|
133 | + switch ( $task ) { |
|
134 | + case 'lsx_wetu_accommodation_images_cron': |
|
135 | + $this->register_accommodation_images_sync(); |
|
136 | + break; |
|
137 | + |
|
138 | + default: |
|
139 | + break; |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * This is the function that will be triggered by the cron event. |
|
145 | + * |
|
146 | + * @return void |
|
147 | + */ |
|
148 | + public function register_accommodation_images_sync() { |
|
149 | + $time = strtotime( '+1 min' ); |
|
150 | + if ( ! wp_next_scheduled( 'lsx_wetu_accommodation_images_sync' ) ) { |
|
151 | + $this->load_items_to_sync( 'accommodation_images' ); |
|
152 | + $this->schedule( 'lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time ); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * This is the function that will be triggered by the cron event. |
|
158 | + * |
|
159 | + * @return void |
|
160 | + */ |
|
161 | + public function cron_callback( $task = '' ) { |
|
162 | + $has_accommodation = get_option( $task ); |
|
163 | + if ( false !== $has_accommodation && ! empty( $has_accommodation ) ) { |
|
164 | + $next_time = array_slice( $has_accommodation, 5 ); |
|
165 | + $this_time = array_slice( $has_accommodation, 0, 4 ); |
|
166 | + |
|
167 | + $api_key = $this->get_api_key(); |
|
168 | + $url = 'https://wetu.com/API/Pins/' . $api_key . '/Get?all=include&ids='; |
|
169 | + |
|
170 | + // Run through the current items. |
|
171 | + foreach ( $this_time as $accommodation ) { |
|
172 | + $wetu_id = get_post_meta( $accommodation, 'lsx_wetu_id', true ); |
|
173 | + $last_date = get_post_meta( $accommodation, 'lsx_wetu_modified_date', true ); |
|
174 | + |
|
175 | + $accommodation_info = wp_remote_get( $url . $wetu_id ); |
|
176 | + if ( ! empty( $accommodation_info ) && isset( $accommodation_info['response'] ) && isset( $accommodation_info['response']['code'] ) && 200 === $accommodation_info['response']['code'] ) { |
|
177 | + $adata = json_decode( $accommodation_info['body'], true ); |
|
178 | + |
|
179 | + if ( isset( $adata[0] ) && isset( $adata[0]['last_modified'] ) && '' !== $adata[0]['last_modified'] ) { |
|
180 | + $modified_time = strtotime( $adata[0]['last_modified'] ); |
|
181 | + if ( $modified_time > $last_date ) { |
|
182 | + $accommodation_importer = new \LSX_WETU_Importer_Accommodation(); |
|
183 | + $accommodation_importer->create_main_gallery( $adata, $accommodation ); |
|
184 | + update_post_meta( $accommodation, 'lsx_wetu_modified_date', $modified_time, $last_date ); |
|
185 | + } |
|
186 | + } |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + // Save the values for next time. |
|
191 | + if ( ! empty( $next_time ) ) { |
|
192 | + update_option( $task, $next_time ); |
|
193 | + } else { |
|
194 | + delete_option( $task ); |
|
195 | + $this->deactivate( $task ); |
|
196 | + } |
|
197 | + } else { |
|
198 | + $this->deactivate( $task ); |
|
199 | + update_option( 'lsx_wetu_nexttime', $task ); |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * This will grab the accommodation ids and load them up into an option field. |
|
205 | + * |
|
206 | + * @param string $task |
|
207 | + * @return void |
|
208 | + */ |
|
209 | + public function load_items_to_sync( $task = 'accommodation_images' ) { |
|
210 | + $args = array( |
|
211 | + 'post_status' => 'publish', |
|
212 | + 'posts_per_page' => -1, |
|
213 | + 'nopagin' => true, |
|
214 | + 'fields' => 'ids', |
|
215 | + ); |
|
216 | + switch ( $task ) { |
|
217 | + case 'accommodation_images': |
|
218 | + $args['post_type'] = 'accommodation'; |
|
219 | + break; |
|
220 | + |
|
221 | + default: |
|
222 | + break; |
|
223 | + } |
|
224 | + $items = new \WP_Query( $args ); |
|
225 | + if ( $items->have_posts() ) { |
|
226 | + update_option( 'lsx_wetu_' . $task . '_sync', $items->posts ); |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Gets the API key stored in the options table. |
|
232 | + * |
|
233 | + * @return string |
|
234 | + */ |
|
235 | + public function get_api_key() { |
|
236 | + $api_key = false; |
|
237 | + $options = lsx_wetu_get_options(); |
|
238 | + |
|
239 | + if ( ! defined( 'WETU_API_KEY' ) ) { |
|
240 | + if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) { |
|
241 | + $api_key = $options['api_key']; |
|
242 | + } |
|
243 | + } else { |
|
244 | + $api_key = WETU_API_KEY; |
|
245 | + } |
|
246 | + return $api_key; |
|
247 | + } |
|
248 | 248 | } |
249 | 249 | Cron::get_instance(); |
@@ -33,10 +33,10 @@ discard block |
||
33 | 33 | * @access private |
34 | 34 | */ |
35 | 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 ); |
|
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 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public static function get_instance() { |
50 | 50 | // If the single instance hasn't been set, set it now. |
51 | - if ( null === self::$instance ) { |
|
51 | + if (null === self::$instance) { |
|
52 | 52 | self::$instance = new self(); |
53 | 53 | } |
54 | 54 | return self::$instance; |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | * @param array $schedules |
61 | 61 | * @return array |
62 | 62 | */ |
63 | - public function register_schedule( $schedules ) { |
|
63 | + public function register_schedule($schedules) { |
|
64 | 64 | $schedules['wetu-5-minutes'] = array( |
65 | 65 | 'interval' => 5 * MINUTE_IN_SECONDS, |
66 | - 'display' => __( 'Every 5 minutes', 'lsx-wetu-importer' ), |
|
66 | + 'display' => __('Every 5 minutes', 'lsx-wetu-importer'), |
|
67 | 67 | ); |
68 | 68 | return $schedules; |
69 | 69 | } |
@@ -75,26 +75,26 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function watch_for_trigger() { |
77 | 77 | |
78 | - if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) { |
|
78 | + if (isset($_GET['page']) && 'lsx-wetu-importer' === $_GET['page'] && isset($_GET['tab']) && 'settings' === $_GET['tab']) { |
|
79 | 79 | $options = lsx_wetu_get_options(); |
80 | 80 | |
81 | 81 | // Check what state the option is in. |
82 | 82 | $accommodation_cron = 'deactivate'; |
83 | - if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { |
|
83 | + if (isset($options['accommodation_images_cron']) && '' !== $options['accommodation_images_cron']) { |
|
84 | 84 | $accommodation_cron = 'activate'; |
85 | 85 | } |
86 | 86 | |
87 | 87 | // Check what state the cron is in. |
88 | 88 | $schedule = false; |
89 | - if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) { |
|
89 | + if (wp_next_scheduled('lsx_wetu_accommodation_images_cron')) { |
|
90 | 90 | $schedule = true; |
91 | 91 | } |
92 | 92 | |
93 | 93 | // If activate and its not running. |
94 | - if ( false === $schedule && 'activate' === $accommodation_cron ) { |
|
94 | + if (false === $schedule && 'activate' === $accommodation_cron) { |
|
95 | 95 | $schedule = 'daily'; |
96 | - $this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule ); |
|
97 | - } elseif ( true === $schedule && 'deactivate' === $accommodation_cron ) { |
|
96 | + $this->schedule('lsx_wetu_accommodation_images_cron', $schedule); |
|
97 | + } elseif (true === $schedule && 'deactivate' === $accommodation_cron) { |
|
98 | 98 | $this->deactivate(); |
99 | 99 | } |
100 | 100 | } |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @return void |
107 | 107 | */ |
108 | - public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) { |
|
109 | - wp_clear_scheduled_hook( $task, array( $task ) ); |
|
108 | + public function deactivate($task = 'lsx_wetu_accommodation_images_cron') { |
|
109 | + wp_clear_scheduled_hook($task, array($task)); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | * @param string $time |
118 | 118 | * @return void |
119 | 119 | */ |
120 | - public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'daily', $time = '' ) { |
|
121 | - if ( '' === $time ) { |
|
120 | + public function schedule($task = 'lsx_wetu_accommodation_images_cron', $schedule = 'daily', $time = '') { |
|
121 | + if ('' === $time) { |
|
122 | 122 | $time = time(); |
123 | 123 | } |
124 | - wp_schedule_event( $time, $schedule, $task, array( $task ) ); |
|
124 | + wp_schedule_event($time, $schedule, $task, array($task)); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @return void |
131 | 131 | */ |
132 | - public function process( $task = '' ) { |
|
133 | - switch ( $task ) { |
|
132 | + public function process($task = '') { |
|
133 | + switch ($task) { |
|
134 | 134 | case 'lsx_wetu_accommodation_images_cron': |
135 | 135 | $this->register_accommodation_images_sync(); |
136 | 136 | break; |
@@ -146,10 +146,10 @@ discard block |
||
146 | 146 | * @return void |
147 | 147 | */ |
148 | 148 | public function register_accommodation_images_sync() { |
149 | - $time = strtotime( '+1 min' ); |
|
150 | - if ( ! wp_next_scheduled( 'lsx_wetu_accommodation_images_sync' ) ) { |
|
151 | - $this->load_items_to_sync( 'accommodation_images' ); |
|
152 | - $this->schedule( 'lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time ); |
|
149 | + $time = strtotime('+1 min'); |
|
150 | + if (!wp_next_scheduled('lsx_wetu_accommodation_images_sync')) { |
|
151 | + $this->load_items_to_sync('accommodation_images'); |
|
152 | + $this->schedule('lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time); |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
@@ -158,45 +158,45 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @return void |
160 | 160 | */ |
161 | - public function cron_callback( $task = '' ) { |
|
162 | - $has_accommodation = get_option( $task ); |
|
163 | - if ( false !== $has_accommodation && ! empty( $has_accommodation ) ) { |
|
164 | - $next_time = array_slice( $has_accommodation, 5 ); |
|
165 | - $this_time = array_slice( $has_accommodation, 0, 4 ); |
|
161 | + public function cron_callback($task = '') { |
|
162 | + $has_accommodation = get_option($task); |
|
163 | + if (false !== $has_accommodation && !empty($has_accommodation)) { |
|
164 | + $next_time = array_slice($has_accommodation, 5); |
|
165 | + $this_time = array_slice($has_accommodation, 0, 4); |
|
166 | 166 | |
167 | 167 | $api_key = $this->get_api_key(); |
168 | - $url = 'https://wetu.com/API/Pins/' . $api_key . '/Get?all=include&ids='; |
|
168 | + $url = 'https://wetu.com/API/Pins/'.$api_key.'/Get?all=include&ids='; |
|
169 | 169 | |
170 | 170 | // Run through the current items. |
171 | - foreach ( $this_time as $accommodation ) { |
|
172 | - $wetu_id = get_post_meta( $accommodation, 'lsx_wetu_id', true ); |
|
173 | - $last_date = get_post_meta( $accommodation, 'lsx_wetu_modified_date', true ); |
|
171 | + foreach ($this_time as $accommodation) { |
|
172 | + $wetu_id = get_post_meta($accommodation, 'lsx_wetu_id', true); |
|
173 | + $last_date = get_post_meta($accommodation, 'lsx_wetu_modified_date', true); |
|
174 | 174 | |
175 | - $accommodation_info = wp_remote_get( $url . $wetu_id ); |
|
176 | - if ( ! empty( $accommodation_info ) && isset( $accommodation_info['response'] ) && isset( $accommodation_info['response']['code'] ) && 200 === $accommodation_info['response']['code'] ) { |
|
177 | - $adata = json_decode( $accommodation_info['body'], true ); |
|
175 | + $accommodation_info = wp_remote_get($url.$wetu_id); |
|
176 | + if (!empty($accommodation_info) && isset($accommodation_info['response']) && isset($accommodation_info['response']['code']) && 200 === $accommodation_info['response']['code']) { |
|
177 | + $adata = json_decode($accommodation_info['body'], true); |
|
178 | 178 | |
179 | - if ( isset( $adata[0] ) && isset( $adata[0]['last_modified'] ) && '' !== $adata[0]['last_modified'] ) { |
|
180 | - $modified_time = strtotime( $adata[0]['last_modified'] ); |
|
181 | - if ( $modified_time > $last_date ) { |
|
179 | + if (isset($adata[0]) && isset($adata[0]['last_modified']) && '' !== $adata[0]['last_modified']) { |
|
180 | + $modified_time = strtotime($adata[0]['last_modified']); |
|
181 | + if ($modified_time > $last_date) { |
|
182 | 182 | $accommodation_importer = new \LSX_WETU_Importer_Accommodation(); |
183 | - $accommodation_importer->create_main_gallery( $adata, $accommodation ); |
|
184 | - update_post_meta( $accommodation, 'lsx_wetu_modified_date', $modified_time, $last_date ); |
|
183 | + $accommodation_importer->create_main_gallery($adata, $accommodation); |
|
184 | + update_post_meta($accommodation, 'lsx_wetu_modified_date', $modified_time, $last_date); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | 190 | // Save the values for next time. |
191 | - if ( ! empty( $next_time ) ) { |
|
192 | - update_option( $task, $next_time ); |
|
193 | - } else { |
|
194 | - delete_option( $task ); |
|
195 | - $this->deactivate( $task ); |
|
191 | + if (!empty($next_time)) { |
|
192 | + update_option($task, $next_time); |
|
193 | + }else { |
|
194 | + delete_option($task); |
|
195 | + $this->deactivate($task); |
|
196 | 196 | } |
197 | - } else { |
|
198 | - $this->deactivate( $task ); |
|
199 | - update_option( 'lsx_wetu_nexttime', $task ); |
|
197 | + }else { |
|
198 | + $this->deactivate($task); |
|
199 | + update_option('lsx_wetu_nexttime', $task); |
|
200 | 200 | } |
201 | 201 | } |
202 | 202 | |
@@ -206,14 +206,14 @@ discard block |
||
206 | 206 | * @param string $task |
207 | 207 | * @return void |
208 | 208 | */ |
209 | - public function load_items_to_sync( $task = 'accommodation_images' ) { |
|
209 | + public function load_items_to_sync($task = 'accommodation_images') { |
|
210 | 210 | $args = array( |
211 | 211 | 'post_status' => 'publish', |
212 | 212 | 'posts_per_page' => -1, |
213 | 213 | 'nopagin' => true, |
214 | 214 | 'fields' => 'ids', |
215 | 215 | ); |
216 | - switch ( $task ) { |
|
216 | + switch ($task) { |
|
217 | 217 | case 'accommodation_images': |
218 | 218 | $args['post_type'] = 'accommodation'; |
219 | 219 | break; |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | default: |
222 | 222 | break; |
223 | 223 | } |
224 | - $items = new \WP_Query( $args ); |
|
225 | - if ( $items->have_posts() ) { |
|
226 | - update_option( 'lsx_wetu_' . $task . '_sync', $items->posts ); |
|
224 | + $items = new \WP_Query($args); |
|
225 | + if ($items->have_posts()) { |
|
226 | + update_option('lsx_wetu_'.$task.'_sync', $items->posts); |
|
227 | 227 | } |
228 | 228 | } |
229 | 229 | |
@@ -236,11 +236,11 @@ discard block |
||
236 | 236 | $api_key = false; |
237 | 237 | $options = lsx_wetu_get_options(); |
238 | 238 | |
239 | - if ( ! defined( 'WETU_API_KEY' ) ) { |
|
240 | - if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) { |
|
239 | + if (!defined('WETU_API_KEY')) { |
|
240 | + if (isset($options['api_key']) && '' !== $options['api_key']) { |
|
241 | 241 | $api_key = $options['api_key']; |
242 | 242 | } |
243 | - } else { |
|
243 | + }else { |
|
244 | 244 | $api_key = WETU_API_KEY; |
245 | 245 | } |
246 | 246 | return $api_key; |