Making WordPress.org


Ignore:
Timestamp:
04/20/2020 10:28:17 PM (6 years ago)
Author:
iandunn
Message:

Events: Replace individual countries with continents for clarity.

This is essentially the same data as before, but much more self-documenting.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/events/1.0/index.php

    r9748 r9749  
    958958                'asia'   => array(
    959959                        'promo_start'        => strtotime( '2019-12-20 00:00:00' ),
    960                         'regional_countries' => array(
    961                                 'cn', 'hk', 'jp', 'kp', 'kr', 'mn', 'mo', 'tw', 'af', 'bd',
    962                                 'bt', 'in', 'ir', 'lk', 'mv', 'np', 'pk', 'bn', 'id', 'kh',
    963                                 'la', 'mm', 'my', 'ph', 'sg', 'th', 'tl', 'vn', 'au', 'nf',
    964                                 'nz', 'fj', 'nc', 'pg', 'sb', 'vu', 'fm', 'gu', 'ki', 'mh',
    965                                 'mp', 'nr', 'pw', 'as', 'ck', 'nu', 'pf', 'pn', 'tk', 'to',
    966                                 'tv', 'wf', 'ws', 'tm', 'tj', 'kg', 'kz', 'uz', 'ae', 'am',
    967                                 'az', 'bh', 'cy', 'ge', 'il', 'iq', 'jo', 'kw', 'lb', 'om',
    968                                 'ps', 'qa', 'sa', 'sy', 'tr', 'ye'
     960
     961                        'regional_countries' => array_merge(
     962                                get_iso_3166_2_country_codes( 'asia' ),
     963                                get_iso_3166_2_country_codes( 'oceania' ),
     964
     965                                // Russia is often considered to be part of Asia geographically, and part of Europe politically.
     966                                array( 'RU' )
    969967                        ),
    970968                        'event'              => array(
     
    987985                'europe' => array(
    988986                        'promo_start'        => strtotime( '2020-04-04 00:00:00' ),
    989                         'regional_countries' => array(
    990                                 // todo
     987                        'regional_countries' => array_merge(
     988                                get_iso_3166_2_country_codes( 'africa' ),
     989                                get_iso_3166_2_country_codes( 'europe' )
    991990                        ),
    992991                        'event'              => array(
     
    10091008                'us'     => array(
    10101009                        'promo_start'        => strtotime( '2020-08-27 00:00:00' ),
    1011                         'regional_countries' => array(
    1012                                 'us', 'ca', 'bz', 'cr', 'sv', 'gt', 'hn', 'mx', 'ni', 'pa',
    1013                                 'ar', 'bo', 'br', 'cl', 'co', 'ec', 'gf', 'gy', 'py', 'pe',
    1014                                 'sr', 'uy', 've', 'ag', 'aw', 'bs', 'bb', 'ky', 'cu', 'dm',
    1015                                 'do', 'gd', 'ht', 'jm', 'kn', 'lc', 'vc', 'tt',
     1010
     1011                        'regional_countries' => array_merge(
     1012                                get_iso_3166_2_country_codes( 'south america' ),
     1013                                get_iso_3166_2_country_codes( 'north america' )
    10161014                        ),
    10171015                        'event'              => array(
     
    10331031                ),
    10341032        );
     1033}
     1034
     1035/**
     1036 * Get a list of ISO-3166-2 countries by continent.
     1037 *
     1038 * Data was sourced from https://dev.maxmind.com/geoip/legacy/codes/country_continent/ on 2020-04-17.
     1039 *
     1040 * @param string $continent
     1041 *
     1042 * @return array
     1043 */
     1044function get_iso_3166_2_country_codes( $continent = '' ) {
     1045        $codes = array(
     1046                'antarctica' => array( 'AQ', 'BV', 'GS', 'HM', 'TF' ),
     1047
     1048                'africa' => array(
     1049                        'AO', 'BF', 'BI', 'BJ', 'BW', 'CD', 'CF', 'CG', 'CI', 'CM', 'CV', 'DJ', 'DZ', 'EG', 'EH', 'ER', 'ET',
     1050                        'GA', 'GH', 'GM', 'GN', 'GQ', 'GW', 'KE', 'KM', 'LR', 'LS', 'LY', 'MA', 'MG', 'ML', 'MR', 'MU', 'MW',
     1051                        'MZ', 'NA', 'NE', 'NG', 'RE', 'RW', 'SC', 'SD', 'SH', 'SL', 'SN', 'SO', 'ST', 'SZ', 'TD', 'TG', 'TN',
     1052                        'TZ', 'UG', 'YT', 'ZA', 'ZM', 'ZW',
     1053                ),
     1054
     1055                'asia' => array(
     1056                        // Includes the Middle East, Armenia, Azerbaijan, Cyprus, Georgia.
     1057                        'AE', 'AF', 'AM', 'AP', 'AZ', 'BD', 'BH', 'BN', 'BT', 'CC', 'CN', 'CX', 'CY', 'GE', 'HK', 'ID', 'IL',
     1058                        'IN', 'IO', 'IQ', 'IR', 'JO', 'JP', 'KG', 'KH', 'KP', 'KR', 'KW', 'KZ', 'LA', 'LB', 'LK', 'MM', 'MN',
     1059                        'MO', 'MV', 'MY', 'NP', 'OM', 'PH', 'PK', 'PS', 'QA', 'SA', 'SG', 'SY', 'TH', 'TJ', 'TL', 'TM', 'TW',
     1060                        'UZ', 'VN', 'YE',
     1061                ),
     1062
     1063                'europe' => array(
     1064                        // Includes Russia, Turkey.
     1065                        'AD', 'AL', 'AT', 'AX', 'BA', 'BE', 'BG', 'BY', 'CH', 'CZ', 'DE', 'DK', 'EE', 'ES', 'EU', 'FI', 'FO',
     1066                        'FR', 'FX', 'GB', 'GG', 'GI', 'GR', 'HR', 'HU', 'IE', 'IM', 'IS', 'IT', 'JE', 'LI', 'LT', 'LU', 'LV',
     1067                        'MC', 'MD', 'ME', 'MK', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'RS', 'RU', 'SE', 'SI', 'SJ', 'SK', 'SM',
     1068                        'TR', 'UA', 'VA',
     1069                ),
     1070
     1071                'north america' => array(
     1072                        'AG', 'AI', 'AN', 'AW', 'BB', 'BL', 'BM', 'BS', 'BZ', 'CA', 'CR', 'CU', 'DM', 'DO', 'GD', 'GL', 'GP',
     1073                        'GT', 'HN', 'HT', 'JM', 'KN', 'KY', 'LC', 'MF', 'MQ', 'MS', 'MX', 'NI', 'PA', 'PM', 'PR', 'SV', 'TC',
     1074                        'TT', 'US', 'VC', 'VG', 'VI',
     1075                ),
     1076
     1077                'oceania' => array(
     1078                        'AS', 'AU', 'CK', 'FJ', 'FM', 'GU', 'KI', 'MH', 'MP', 'NC', 'NF', 'NR', 'NU', 'NZ', 'PF', 'PG', 'PN',
     1079                        'PW', 'SB', 'TK', 'TO', 'TV', 'UM', 'VU', 'WF', 'WS',
     1080                ),
     1081
     1082                'south america' => array(
     1083                        'AR', 'BO', 'BR', 'CL', 'CO', 'EC', 'FK', 'GF', 'GY', 'PE', 'PY', 'SR', 'UY', 'VE',
     1084                ),
     1085        );
     1086
     1087        if ( $continent ) {
     1088                return $codes[ $continent ];
     1089        } else {
     1090                return $codes;
     1091        }
    10351092}
    10361093
     
    10701127                } elseif ( is_within_date_range( $current_time, strtotime( '+ 2 weeks', $start ), strtotime( '+ 4 weeks', $start ) ) ) {
    10711128                        // Phase 2: Show within regional countries for next two weeks.
    1072                         if ( ! empty( $location['country'] ) && in_array( strtolower( $location['country'] ), $data['regional_countries'], true ) ) {
     1129                        if ( ! empty( $location['country'] ) && in_array( strtoupper( $location['country'] ), $data['regional_countries'], true ) ) {
    10731130                                $regional_wordcamps[] = $data['event'];
    10741131                        }
    10751132                } elseif ( is_within_date_range( $current_time, strtotime( '+ 4 weeks', $start ), strtotime( '+ 6 weeks', $start ) ) ) {
    10761133                        // Phase 3: Show only within the event country for the last two weeks.
    1077                         if ( ! empty( $location['country'] ) && strtolower( $data['event']['location']['country'] ) === strtolower( $location['country'] ) ) {
     1134                        if ( ! empty( $location['country'] ) && strtoupper( $data['event']['location']['country'] ) === strtoupper( $location['country'] ) ) {
    10781135                                $regional_wordcamps[] = $data['event'];
    10791136                        }
Note: See TracChangeset for help on using the changeset viewer.