PluginProbe
Import Social Events / 1.1.1
Import Social Events v1.1.1
1.9.1 1.9.0 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 All 61 releases
import-facebook-events / includes / class-import-facebook-events-common.php

class-import-facebook-events-common.php in Import Social Events 1.1.1, at includes/class-import-facebook-events-common.php

829 lines 22.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Common functions class for Import Facebook Events.
4 *
5 * @link http://xylusthemes.com/
6 * @since 1.0.0
7 *
8 * @package Import_Facebook_Events
9 * @subpackage Import_Facebook_Events/includes
10 */
11 // Exit if accessed directly
12 if ( ! defined( 'ABSPATH' ) ) exit;
13
14 class Import_Facebook_Events_Common {
15
16 /**
17 * Initialize the class and set its properties.
18 *
19 * @since 1.0.0
20 */
21 public function __construct() {
22 add_action( 'wp_ajax_ife_render_terms_by_plugin', array( $this, 'ife_render_terms_by_plugin' ) );
23 add_action( 'ife_render_pro_notice', array( $this, 'render_pro_notice') );
24 }
25
26 /**
27 * Format events arguments as per TEC
28 *
29 * @since 1.0.0
30 * @param array $eventbrite_event Eventbrite event.
31 * @return array
32 */
33 public function render_import_into_and_taxonomy() {
34
35 $active_plugins = $this->get_active_supported_event_plugins();
36 ?>
37 <tr class="event_plugis_wrapper">
38 <th scope="row">
39 <?php esc_attr_e( 'Import into','import-facebook-events' ); ?> :
40 </th>
41 <td>
42 <select name="event_plugin" class="fb_event_plugin">
43 <?php
44 if( !empty( $active_plugins ) ){
45 foreach ($active_plugins as $slug => $name ) {
46 ?>
47 <option value="<?php echo $slug;?>"><?php echo $name; ?></option>
48 <?php
49 }
50 }
51 ?>
52 </select>
53 </td>
54 </tr>
55
56 <tr class="event_cats_wrapper">
57 <th scope="row">
58 <?php esc_attr_e( 'Event Categories for Event Import','import-facebook-events' ); ?> :
59 </th>
60 <td>
61 <div class="event_taxo_terms_wraper">
62
63 </div>
64 <span class="ife_small">
65 <?php esc_attr_e( 'These categories are assign to imported event.', 'import-facebook-events' ); ?>
66 </span>
67 </td>
68 </tr>
69 <?php
70
71 }
72
73 /**
74 * Render Taxonomy Terms based on event import into Selection.
75 *
76 * @since 1.0
77 * @return void
78 */
79 function ife_render_terms_by_plugin() {
80 global $ife_events;
81 $event_plugin = esc_attr( $_REQUEST['event_plugin'] );
82 $event_taxonomy = '';
83 switch ( $event_plugin ) {
84 case 'ife':
85 $event_taxonomy = $ife_events->ife->get_taxonomy();
86 break;
87
88 case 'tec':
89 $event_taxonomy = $ife_events->tec->get_taxonomy();
90 break;
91
92 case 'em':
93 $event_taxonomy = $ife_events->em->get_taxonomy();
94 break;
95
96 case 'eventon':
97 $event_taxonomy = $ife_events->eventon->get_taxonomy();
98 break;
99
100 case 'event_organizer':
101 $event_taxonomy = $ife_events->event_organizer->get_taxonomy();
102 break;
103
104 case 'aioec':
105 $event_taxonomy = $ife_events->aioec->get_taxonomy();
106 break;
107
108 case 'my_calendar':
109 $event_taxonomy = $ife_events->my_calendar->get_taxonomy();
110 break;
111
112 default:
113 break;
114 }
115
116 $terms = array();
117 if ( $event_taxonomy != '' ) {
118 if( taxonomy_exists( $event_taxonomy ) ){
119 $terms = get_terms( $event_taxonomy, array( 'hide_empty' => false ) );
120 }
121 }
122 if( ! empty( $terms ) ){ ?>
123 <select name="event_cats[]" multiple="multiple">
124 <?php foreach ($terms as $term ) { ?>
125 <option value="<?php echo $term->term_id; ?>">
126 <?php echo $term->name; ?>
127 </option>
128 <?php } ?>
129 </select>
130 <?php
131 }
132 wp_die();
133 }
134
135 /**
136 * Get Active supported active plugins.
137 *
138 * @since 1.0.0
139 * @return array
140 */
141 public function get_active_supported_event_plugins() {
142
143 $supported_plugins = array();
144 if ( ! function_exists( 'is_plugin_active' ) ) {
145 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
146 }
147 // check The Events Calendar active or not if active add it into array.
148 if( class_exists( 'Tribe__Events__Main' ) ){
149 $supported_plugins['tec'] = __( 'The Events Calendar', 'import-facebook-events' );
150 }
151
152 // check Events Manager.
153 if( defined( 'EM_VERSION' ) ){
154 $supported_plugins['em'] = __( 'Events Manager', 'import-facebook-events' );
155 }
156
157 // Check event_organizer.
158 if( defined( 'EVENT_ORGANISER_VER' ) && defined( 'EVENT_ORGANISER_DIR' ) ){
159 $supported_plugins['event_organizer'] = __( 'Event Organiser', 'import-facebook-events' );
160 }
161
162 // check EventON.
163 if( class_exists( 'EventON' ) ){
164 $supported_plugins['eventon'] = __( 'EventON', 'import-facebook-events' );
165 }
166
167 // check All in one Event Calendar
168 if( class_exists( 'Ai1ec_Event' ) ){
169 $supported_plugins['aioec'] = __( 'All in one Event Calendar', 'import-facebook-events' );
170 }
171
172 // check My Calendar
173 if ( is_plugin_active( 'my-calendar/my-calendar.php' ) ) {
174 $supported_plugins['my_calendar'] = __( 'My Calendar', 'import-facebook-events' );
175 }
176 $supported_plugins['ife'] = __( 'Facebook Events', 'import-facebook-events' );
177 return $supported_plugins;
178 }
179
180 /**
181 * Setup Featured image to events
182 *
183 * @since 1.0.0
184 * @param int $event_id event id.
185 * @param int $image_url Image URL
186 * @return void
187 */
188 public function setup_featured_image_to_event( $event_id, $image_url = '' ) {
189 if ( $image_url == '' ) {
190 return;
191 }
192 $event = get_post( $event_id );
193 if( Empty ( $event ) ){
194 return;
195 }
196 $import_origin = get_post_meta( $event_id, 'ife_event_origin', true );
197 $image_name = '';
198 if( $import_origin != '' ){
199 $image_name .= $import_origin."_";
200 }
201 // Add Featured Image to Post
202 $image_name .= $event->ID . '_' . $event->post_name . '_image.png';
203 $upload_dir = wp_upload_dir(); // Set upload folder
204
205 // Check for event file already Exists or not.
206 $params = array(
207 'numberposts' => 1,
208 'post_type' => 'attachment',
209 'meta_query' => array(
210 array(
211 'key' => '_wp_attached_file',
212 'value' => trim( $upload_dir['subdir'] . '/' . $image_name, '/' )
213 )
214 )
215 );
216
217 $existing_file = get_posts( $params );
218 if ( file_exists( $upload_dir['path'] . '/' . $image_name ) && isset( $existing_file[0]->ID ) ) {
219
220 $attach_id = $existing_file[0]->ID;
221
222 }else{
223
224 $image_data = file_get_contents( $image_url ); // Get image data
225 $unique_file_name = wp_unique_filename( $upload_dir['path'], $image_name ); // Generate unique name
226 $filename = basename( $unique_file_name ); // Create image file name
227
228 // Check folder permission and define file location
229 if( wp_mkdir_p( $upload_dir['path'] ) ) {
230 $file = $upload_dir['path'] . '/' . $filename;
231 } else {
232 $file = $upload_dir['basedir'] . '/' . $filename;
233 }
234
235 // Create the image file on the server
236 file_put_contents( $file, $image_data );
237
238 // Check image file type
239 $wp_filetype = wp_check_filetype( $filename, null );
240
241 // Set attachment data
242 $attachment = array(
243 'post_mime_type' => $wp_filetype['type'],
244 'post_title' => sanitize_file_name( $filename ),
245 'post_content' => '',
246 'post_status' => 'inherit'
247 );
248
249 // Create the attachment
250 $attach_id = wp_insert_attachment( $attachment, $file, $event_id );
251
252 // Include image.php
253 require_once(ABSPATH . 'wp-admin/includes/image.php');
254
255 // Define attachment metadata
256 $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
257
258 // Assign metadata to attachment
259 wp_update_attachment_metadata( $attach_id, $attach_data );
260
261 }
262
263 // And finally assign featured image to post
264 set_post_thumbnail( $event_id, $attach_id );
265 }
266
267 /**
268 * Format events arguments as per TEC
269 *
270 * @since 1.0.0
271 * @param array $eventbrite_event Eventbrite event.
272 * @return array
273 */
274 public function display_import_success_message( $import_data = array(),$import_args = array(), $schedule_post = '' ) {
275 global $ife_success_msg, $ife_errors;
276 if( empty( $import_data ) || !empty( $ife_errors ) ){
277 return;
278 }
279
280 $import_status = $import_ids = array();
281 foreach ($import_data as $key => $value) {
282 if( $value['status'] == 'created'){
283 $import_status['created'][] = $value;
284 }elseif( $value['status'] == 'updated'){
285 $import_status['updated'][] = $value;
286 }elseif( $value['status'] == 'skipped'){
287 $import_status['skipped'][] = $value;
288 }else{
289
290 }
291 if( isset( $value['id'] ) ){
292 $import_ids[] = $value['id'];
293 }
294 }
295 $created = $updated = $skipped = 0;
296 $created = isset( $import_status['created'] ) ? count( $import_status['created'] ) : 0;
297 $updated = isset( $import_status['updated'] ) ? count( $import_status['updated'] ) : 0;
298 $skipped = isset( $import_status['skipped'] ) ? count( $import_status['skipped'] ) : 0;
299
300 $success_message = esc_html__( 'Event(s) are imported successfully.', 'import-facebook-events' )."<br>";
301 if( $created > 0 ){
302 $success_message .= "<strong>".sprintf( __( '%d Created', 'import-facebook-events' ), $created )."</strong><br>";
303 }
304 if( $updated > 0 ){
305 $success_message .= "<strong>".sprintf( __( '%d Updated', 'import-facebook-events' ), $updated )."</strong><br>";
306 }
307 if( $skipped > 0 ){
308 $success_message .= "<strong>".sprintf( __( '%d Skipped (Already exists)', 'import-facebook-events' ), $skipped ) ."</strong><br>";
309 }
310 $ife_success_msg[] = $success_message;
311
312 if( $schedule_post != '' && $schedule_post > 0 ){
313 $temp_title = get_the_title( $schedule_post );
314 }else{
315 $temp_title = 'Manual Import';
316 }
317
318 if( $created > 0 || $updated > 0 || $skipped >0 ){
319 $insert_args = array(
320 'post_type' => 'ife_import_history',
321 'post_status' => 'publish',
322 'post_title' => $temp_title . " - ".ucfirst( $import_args["import_origin"]),
323 );
324
325 $insert = wp_insert_post( $insert_args, true );
326 if ( !is_wp_error( $insert ) ) {
327 update_post_meta( $insert, 'import_origin', $import_args["import_origin"] );
328 update_post_meta( $insert, 'created', $created );
329 update_post_meta( $insert, 'updated', $updated );
330 update_post_meta( $insert, 'skipped', $skipped );
331 update_post_meta( $insert, 'import_data', $import_args );
332 if( $schedule_post != '' && $schedule_post > 0 ){
333 update_post_meta( $insert, 'schedule_import_id', $schedule_post );
334 }
335 }
336 }
337 }
338
339 /**
340 * Get Import events into selected destination.
341 *
342 * @since 1.0.0
343 * @return array
344 */
345 public function import_events_into( $centralize_array, $event_args ){
346 global $ife_events;
347 $import_result = array();
348 $import_origin = isset( $event_args['import_origin'] ) ? $event_args['import_origin'] : '';
349 $event_import_into = isset( $event_args['import_into'] ) ? $event_args['import_into'] : '';
350
351 if ( $event_import_into == '' ) {
352 if ( $import_origin == 'facebook_tec' ) {
353 $event_import_into = 'tec';
354 } elseif ( $import_origin == 'facebook_em' ) {
355 $event_import_into = 'em';
356 } else {
357 $event_import_into = 'tec';
358 }
359 }
360
361 switch ( $event_import_into ) {
362 case 'ife':
363 $import_result = $ife_events->ife->import_event( $centralize_array, $event_args );
364 break;
365
366 case 'tec':
367 $import_result = $ife_events->tec->import_event( $centralize_array, $event_args );
368 break;
369
370 case 'em':
371 $import_result = $ife_events->em->import_event( $centralize_array, $event_args );
372 break;
373
374 case 'eventon':
375 $import_result = $ife_events->eventon->import_event( $centralize_array, $event_args );
376 break;
377
378 case 'event_organizer':
379 $import_result = $ife_events->event_organizer->import_event( $centralize_array, $event_args );
380 break;
381
382 case 'aioec':
383 $import_result = $ife_events->aioec->import_event( $centralize_array, $event_args );
384 break;
385
386 case 'my_calendar':
387 $import_result = $ife_events->my_calendar->import_event( $centralize_array, $event_args );
388 break;
389
390 default:
391 break;
392 }
393 return $import_result;
394 }
395
396 /**
397 * Render import Frequency
398 *
399 * @since 1.0.0
400 * @return void
401 */
402 function render_import_frequency(){
403 ?>
404 <select name="import_frequency" class="import_frequency" disabled="disabled" >
405 <option value='hourly'>
406 <?php esc_html_e( 'Once Hourly','import-facebook-events' ); ?>
407 </option>
408 <option value='twicedaily'>
409 <?php esc_html_e( 'Twice Daily','import-facebook-events' ); ?>
410 </option>
411 <option value="daily" selected="selected">
412 <?php esc_html_e( 'Once Daily','import-facebook-events' ); ?>
413 </option>
414 <option value="weekly" >
415 <?php esc_html_e( 'Once Weekly','import-facebook-events' ); ?>
416 </option>
417 <option value="monthly">
418 <?php esc_html_e( 'Once a Month','import-facebook-events' ); ?>
419 </option>
420 </select>
421 <?php
422 }
423
424 /**
425 * Render import type, one time or scheduled
426 *
427 * @since 1.0.0
428 * @return void
429 */
430 function render_import_type(){
431 ?>
432 <select name="import_type" id="import_type" disabled="disabled">
433 <option value="onetime" disabled="disabled" ><?php esc_attr_e( 'One-time Import','import-facebook-events' ); ?></option>
434 <option value="scheduled" disabled="disabled" selected="selected" ><?php esc_attr_e( 'Scheduled Import','import-facebook-events' ); ?></option>
435 </select>
436 <span class="hide_frequency">
437 <?php $this->render_import_frequency(); ?>
438 </span>
439 <?php
440 do_action( 'ife_render_pro_notice' );
441 }
442
443 /**
444 * Clean URL.
445 *
446 * @since 1.0.0
447 */
448 function clean_url( $url ) {
449
450 $url = str_replace( '&amp;#038;', '&', $url );
451 $url = str_replace( '&#038;', '&', $url );
452 return $url;
453
454 }
455
456 /**
457 * Get UTC offset
458 *
459 * @since 1.0.0
460 */
461 function get_utc_offset( $datetime ) {
462 try {
463 $datetime = new DateTime( $datetime );
464 } catch ( Exception $e ) {
465 return '';
466 }
467
468 $timezone = $datetime->getTimezone();
469 $offset = $timezone->getOffset( $datetime ) / 60 / 60;
470
471 if ( $offset >= 0 ) {
472 $offset = '+' . $offset;
473 }
474
475 return 'UTC' . $offset;
476 }
477
478 /**
479 * Render dropdown for Imported event status.
480 *
481 * @since 1.0
482 * @return void
483 */
484 function render_eventstatus_input() {
485 ?>
486 <tr class="event_status_wrapper">
487 <th scope="row">
488 <?php esc_attr_e( 'Status','import-facebook-events' ); ?> :
489 </th>
490 <td>
491 <select name="event_status" >
492 <option value="publish">
493 <?php esc_html_e( 'Published','import-facebook-events' ); ?>
494 </option>
495 <option value="pending">
496 <?php esc_html_e( 'Pending','import-facebook-events' ); ?>
497 </option>
498 <option value="draft">
499 <?php esc_html_e( 'Draft','import-facebook-events' ); ?>
500 </option>
501 </select>
502 </td>
503 </tr>
504 <?php
505 }
506
507 /**
508 * remove query string from URL.
509 *
510 * @since 1.0.0
511 */
512 function convert_datetime_to_db_datetime( $datetime ) {
513 try {
514 $datetime = new DateTime( $datetime );
515 return $datetime->format( 'Y-m-d H:i:s' );
516 }
517 catch ( Exception $e ) {
518 return $datetime;
519 }
520 }
521
522 /**
523 * Check for Existing Event
524 *
525 * @since 1.0.0
526 * @param int $event_id event id.
527 * @return /boolean
528 */
529 public function get_event_by_event_id( $post_type, $event_id ) {
530 $event_args = array(
531 'post_type' => $post_type,
532 'post_status' => array( 'pending', 'draft', 'publish' ),
533 'posts_per_page' => -1,
534 'suppress_filters' => true,
535 'meta_key' => 'ife_facebook_event_id',
536 'meta_value' => $event_id,
537 );
538 if( $post_type == 'tribe_events' && class_exists( 'Tribe__Events__Query' ) ){
539 remove_action( 'pre_get_posts', array( 'Tribe__Events__Query', 'pre_get_posts' ), 50 );
540 }
541 $events = new WP_Query( $event_args );
542 if( $post_type == 'tribe_events' && class_exists( 'Tribe__Events__Query' ) ){
543 add_action( 'pre_get_posts', array( 'Tribe__Events__Query', 'pre_get_posts' ), 50 );
544 }
545 if ( $events->have_posts() ) {
546 while ( $events->have_posts() ) {
547 $events->the_post();
548 return get_the_ID();
549 }
550 }
551 wp_reset_postdata();
552 return false;
553 }
554
555 /**
556 * Display upgrade to pro notice in form.
557 *
558 * @since 1.0.0
559 */
560 public function render_pro_notice(){
561 ?>
562 <span class="ife_small">
563 <?php printf( '<span style="color: red">%s</span> <a href="' . IFE_PLUGIN_BUY_NOW_URL. '" target="_blank" >%s</a>', __( 'Available in Pro version.', 'import-facebook-events' ), __( 'Upgrade to PRO', 'import-facebook-events' ) ); ?>
564 </span>
565 <?php
566 }
567
568 /**
569 * Get Active supported active plugins.
570 *
571 * @since 1.0.0
572 * @return array
573 */
574 public function ife_get_country_code( $country ) {
575 if ( $country == '' ) {
576 return '';
577 }
578
579 $countries = array(
580 'AF' => 'AFGHANISTAN',
581 'AL' => 'ALBANIA',
582 'DZ' => 'ALGERIA',
583 'AS' => 'AMERICAN SAMOA',
584 'AD' => 'ANDORRA',
585 'AO' => 'ANGOLA',
586 'AI' => 'ANGUILLA',
587 'AQ' => 'ANTARCTICA',
588 'AG' => 'ANTIGUA AND BARBUDA',
589 'AR' => 'ARGENTINA',
590 'AM' => 'ARMENIA',
591 'AW' => 'ARUBA',
592 'AU' => 'AUSTRALIA',
593 'AT' => 'AUSTRIA',
594 'AZ' => 'AZERBAIJAN',
595 'BS' => 'BAHAMAS',
596 'BH' => 'BAHRAIN',
597 'BD' => 'BANGLADESH',
598 'BB' => 'BARBADOS',
599 'BY' => 'BELARUS',
600 'BE' => 'BELGIUM',
601 'BZ' => 'BELIZE',
602 'BJ' => 'BENIN',
603 'BM' => 'BERMUDA',
604 'BT' => 'BHUTAN',
605 'BO' => 'BOLIVIA',
606 'BA' => 'BOSNIA AND HERZEGOVINA',
607 'BW' => 'BOTSWANA',
608 'BV' => 'BOUVET ISLAND',
609 'BR' => 'BRAZIL',
610 'IO' => 'BRITISH INDIAN OCEAN TERRITORY',
611 'BN' => 'BRUNEI DARUSSALAM',
612 'BG' => 'BULGARIA',
613 'BF' => 'BURKINA FASO',
614 'BI' => 'BURUNDI',
615 'KH' => 'CAMBODIA',
616 'CM' => 'CAMEROON',
617 'CA' => 'CANADA',
618 'CV' => 'CAPE VERDE',
619 'KY' => 'CAYMAN ISLANDS',
620 'CF' => 'CENTRAL AFRICAN REPUBLIC',
621 'TD' => 'CHAD',
622 'CL' => 'CHILE',
623 'CN' => 'CHINA',
624 'CX' => 'CHRISTMAS ISLAND',
625 'CC' => 'COCOS (KEELING) ISLANDS',
626 'CO' => 'COLOMBIA',
627 'KM' => 'COMOROS',
628 'CG' => 'CONGO',
629 'CD' => 'CONGO, THE DEMOCRATIC REPUBLIC OF THE',
630 'CK' => 'COOK ISLANDS',
631 'CR' => 'COSTA RICA',
632 'CI' => 'COTE D IVOIRE',
633 'HR' => 'CROATIA',
634 'CU' => 'CUBA',
635 'CY' => 'CYPRUS',
636 'CZ' => 'CZECH REPUBLIC',
637 'DK' => 'DENMARK',
638 'DJ' => 'DJIBOUTI',
639 'DM' => 'DOMINICA',
640 'DO' => 'DOMINICAN REPUBLIC',
641 'TP' => 'EAST TIMOR',
642 'EC' => 'ECUADOR',
643 'EG' => 'EGYPT',
644 'SV' => 'EL SALVADOR',
645 'GQ' => 'EQUATORIAL GUINEA',
646 'ER' => 'ERITREA',
647 'EE' => 'ESTONIA',
648 'ET' => 'ETHIOPIA',
649 'FK' => 'FALKLAND ISLANDS (MALVINAS)',
650 'FO' => 'FAROE ISLANDS',
651 'FJ' => 'FIJI',
652 'FI' => 'FINLAND',
653 'FR' => 'FRANCE',
654 'GF' => 'FRENCH GUIANA',
655 'PF' => 'FRENCH POLYNESIA',
656 'TF' => 'FRENCH SOUTHERN TERRITORIES',
657 'GA' => 'GABON',
658 'GM' => 'GAMBIA',
659 'GE' => 'GEORGIA',
660 'DE' => 'GERMANY',
661 'GH' => 'GHANA',
662 'GI' => 'GIBRALTAR',
663 'GR' => 'GREECE',
664 'GL' => 'GREENLAND',
665 'GD' => 'GRENADA',
666 'GP' => 'GUADELOUPE',
667 'GU' => 'GUAM',
668 'GT' => 'GUATEMALA',
669 'GN' => 'GUINEA',
670 'GW' => 'GUINEA-BISSAU',
671 'GY' => 'GUYANA',
672 'HT' => 'HAITI',
673 'HM' => 'HEARD ISLAND AND MCDONALD ISLANDS',
674 'VA' => 'HOLY SEE (VATICAN CITY STATE)',
675 'HN' => 'HONDURAS',
676 'HK' => 'HONG KONG',
677 'HU' => 'HUNGARY',
678 'IS' => 'ICELAND',
679 'IN' => 'INDIA',
680 'ID' => 'INDONESIA',
681 'IR' => 'IRAN, ISLAMIC REPUBLIC OF',
682 'IQ' => 'IRAQ',
683 'IE' => 'IRELAND',
684 'IL' => 'ISRAEL',
685 'IT' => 'ITALY',
686 'JM' => 'JAMAICA',
687 'JP' => 'JAPAN',
688 'JO' => 'JORDAN',
689 'KZ' => 'KAZAKSTAN',
690 'KE' => 'KENYA',
691 'KI' => 'KIRIBATI',
692 'KP' => 'KOREA DEMOCRATIC PEOPLES REPUBLIC OF',
693 'KR' => 'KOREA REPUBLIC OF',
694 'KW' => 'KUWAIT',
695 'KG' => 'KYRGYZSTAN',
696 'LA' => 'LAO PEOPLES DEMOCRATIC REPUBLIC',
697 'LV' => 'LATVIA',
698 'LB' => 'LEBANON',
699 'LS' => 'LESOTHO',
700 'LR' => 'LIBERIA',
701 'LY' => 'LIBYAN ARAB JAMAHIRIYA',
702 'LI' => 'LIECHTENSTEIN',
703 'LT' => 'LITHUANIA',
704 'LU' => 'LUXEMBOURG',
705 'MO' => 'MACAU',
706 'MK' => 'MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF',
707 'MG' => 'MADAGASCAR',
708 'MW' => 'MALAWI',
709 'MY' => 'MALAYSIA',
710 'MV' => 'MALDIVES',
711 'ML' => 'MALI',
712 'MT' => 'MALTA',
713 'MH' => 'MARSHALL ISLANDS',
714 'MQ' => 'MARTINIQUE',
715 'MR' => 'MAURITANIA',
716 'MU' => 'MAURITIUS',
717 'YT' => 'MAYOTTE',
718 'MX' => 'MEXICO',
719 'FM' => 'MICRONESIA, FEDERATED STATES OF',
720 'MD' => 'MOLDOVA, REPUBLIC OF',
721 'MC' => 'MONACO',
722 'MN' => 'MONGOLIA',
723 'MS' => 'MONTSERRAT',
724 'MA' => 'MOROCCO',
725 'MZ' => 'MOZAMBIQUE',
726 'MM' => 'MYANMAR',
727 'NA' => 'NAMIBIA',
728 'NR' => 'NAURU',
729 'NP' => 'NEPAL',
730 'NL' => 'NETHERLANDS',
731 'AN' => 'NETHERLANDS ANTILLES',
732 'NC' => 'NEW CALEDONIA',
733 'NZ' => 'NEW ZEALAND',
734 'NI' => 'NICARAGUA',
735 'NE' => 'NIGER',
736 'NG' => 'NIGERIA',
737 'NU' => 'NIUE',
738 'NF' => 'NORFOLK ISLAND',
739 'MP' => 'NORTHERN MARIANA ISLANDS',
740 'NO' => 'NORWAY',
741 'OM' => 'OMAN',
742 'PK' => 'PAKISTAN',
743 'PW' => 'PALAU',
744 'PS' => 'PALESTINIAN TERRITORY, OCCUPIED',
745 'PA' => 'PANAMA',
746 'PG' => 'PAPUA NEW GUINEA',
747 'PY' => 'PARAGUAY',
748 'PE' => 'PERU',
749 'PH' => 'PHILIPPINES',
750 'PN' => 'PITCAIRN',
751 'PL' => 'POLAND',
752 'PT' => 'PORTUGAL',
753 'PR' => 'PUERTO RICO',
754 'QA' => 'QATAR',
755 'RE' => 'REUNION',
756 'RO' => 'ROMANIA',
757 'RU' => 'RUSSIAN FEDERATION',
758 'RW' => 'RWANDA',
759 'SH' => 'SAINT HELENA',
760 'KN' => 'SAINT KITTS AND NEVIS',
761 'LC' => 'SAINT LUCIA',
762 'PM' => 'SAINT PIERRE AND MIQUELON',
763 'VC' => 'SAINT VINCENT AND THE GRENADINES',
764 'WS' => 'SAMOA',
765 'SM' => 'SAN MARINO',
766 'ST' => 'SAO TOME AND PRINCIPE',
767 'SA' => 'SAUDI ARABIA',
768 'SN' => 'SENEGAL',
769 'SC' => 'SEYCHELLES',
770 'SL' => 'SIERRA LEONE',
771 'SG' => 'SINGAPORE',
772 'SK' => 'SLOVAKIA',
773 'SI' => 'SLOVENIA',
774 'SB' => 'SOLOMON ISLANDS',
775 'SO' => 'SOMALIA',
776 'ZA' => 'SOUTH AFRICA',
777 'GS' => 'SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS',
778 'ES' => 'SPAIN',
779 'LK' => 'SRI LANKA',
780 'SD' => 'SUDAN',
781 'SR' => 'SURINAME',
782 'SJ' => 'SVALBARD AND JAN MAYEN',
783 'SZ' => 'SWAZILAND',
784 'SE' => 'SWEDEN',
785 'CH' => 'SWITZERLAND',
786 'SY' => 'SYRIAN ARAB REPUBLIC',
787 'TW' => 'TAIWAN, PROVINCE OF CHINA',
788 'TJ' => 'TAJIKISTAN',
789 'TZ' => 'TANZANIA, UNITED REPUBLIC OF',
790 'TH' => 'THAILAND',
791 'TG' => 'TOGO',
792 'TK' => 'TOKELAU',
793 'TO' => 'TONGA',
794 'TT' => 'TRINIDAD AND TOBAGO',
795 'TN' => 'TUNISIA',
796 'TR' => 'TURKEY',
797 'TM' => 'TURKMENISTAN',
798 'TC' => 'TURKS AND CAICOS ISLANDS',
799 'TV' => 'TUVALU',
800 'UG' => 'UGANDA',
801 'UA' => 'UKRAINE',
802 'AE' => 'UNITED ARAB EMIRATES',
803 'GB' => 'UNITED KINGDOM',
804 'US' => 'UNITED STATES',
805 'UM' => 'UNITED STATES MINOR OUTLYING ISLANDS',
806 'UY' => 'URUGUAY',
807 'UZ' => 'UZBEKISTAN',
808 'VU' => 'VANUATU',
809 'VE' => 'VENEZUELA',
810 'VN' => 'VIET NAM',
811 'VG' => 'VIRGIN ISLANDS, BRITISH',
812 'VI' => 'VIRGIN ISLANDS, U.S.',
813 'WF' => 'WALLIS AND FUTUNA',
814 'EH' => 'WESTERN SAHARA',
815 'YE' => 'YEMEN',
816 'YU' => 'YUGOSLAVIA',
817 'ZM' => 'ZAMBIA',
818 'ZW' => 'ZIMBABWE',
819 );
820
821 foreach ( $countries as $code => $name ) {
822 if ( strtoupper( $country ) == $name ) {
823 return $code;
824 }
825 }
826 return $country;
827 }
828 }
829