/[drupal]/contributions/modules/addresses/addresses.inc
ViewVC logotype

Contents of /contributions/modules/addresses/addresses.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.57 - (show annotations) (download) (as text)
Thu Jan 8 07:56:26 2009 UTC (10 months, 2 weeks ago) by brmassa
Branch: MAIN
CVS Tags: DRUPAL-6--1-05, DRUPAL-6--1-04, DRUPAL-6--1-03, HEAD
Changes since 1.56: +23 -1 lines
File MIME type: text/x-php
New features:
* All default fields are now themable functions

Improvements:
* Make token value substitution more generic, since new fields can be implemented, such as phone and fax fields.
1 <?php
2 // $Id: addresses.inc,v 1.56 2008/11/17 16:01:56 alexiswilke Exp $
3 /**
4 * @author Bruno Massa
5 * @file
6 * An implementation of a universal API for address manipulation.
7 */
8
9 /**
10 * List all countries on Planet! :)
11 *
12 * It uses the ISO notation.
13 * See http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
14 * or http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm
15 * for further info.
16 *
17 * @param $available
18 * String (optional). A list of countries that are allowed.
19 * @param $upper
20 * Boolean (optional). When TRUE, the country codes will
21 * be totally in Upper Case. Its the default ISO code,
22 * but the files and function are all named with lower
23 * case, so its better to return lower case by default
24 * @return
25 * Array. 'COUNTRY CODE' => 'COUNTRY NAME' pairs as layed out in
26 * ISO 3166-1 alpha-2
27 */
28 function _addresses_country_get($available = array(), $upper = FALSE) {
29 $countries = array(
30 'ad' => t('Andorra'),
31 'ae' => t('United Arab Emirates'),
32 'af' => t('Afghanistan'),
33 'ag' => t('Antigua and Barbuda'),
34 'ai' => t('Anguilla'),
35 'al' => t('Albania'),
36 'am' => t('Armenia'),
37 'an' => t('Netherlands Antilles'),
38 'ao' => t('Angola'),
39 'aq' => t('Antarctica'),
40 'ar' => t('Argentina'),
41 'as' => t('American Samoa'),
42 'at' => t('Austria'),
43 'au' => t('Australia'),
44 'aw' => t('Aruba'),
45 'ax' => t('Aland Islands'),
46 'az' => t('Azerbaijan'),
47 'ba' => t('Bosnia and Herzegovina'),
48 'bb' => t('Barbados'),
49 'bd' => t('Bangladesh'),
50 'be' => t('Belgium'),
51 'bf' => t('Burkina Faso'),
52 'bg' => t('Bulgaria'),
53 'bh' => t('Bahrain'),
54 'bi' => t('Burundi'),
55 'bj' => t('Benin'),
56 'bm' => t('Bermuda'),
57 'bn' => t('Brunei'),
58 'bo' => t('Bolivia'),
59 'br' => t('Brazil'),
60 'bs' => t('Bahamas'),
61 'bt' => t('Bhutan'),
62 'bv' => t('Bouvet Island'),
63 'bw' => t('Botswana'),
64 'by' => t('Belarus'),
65 'bz' => t('Belize'),
66 'ca' => t('Canada'),
67 'cc' => t('Cocos (Keeling) Islands'),
68 'cd' => t('Congo (Kinshasa)'),
69 'cf' => t('Central African Republic'),
70 'cg' => t('Congo (Brazzaville)'),
71 'ch' => t('Switzerland'),
72 'ci' => t('Ivory Coast'),
73 'ck' => t('Cook Islands'),
74 'cl' => t('Chile'),
75 'cm' => t('Cameroon'),
76 'cn' => t('China'),
77 'co' => t('Colombia'),
78 'cr' => t('Costa Rica'),
79 'cs' => t('Serbia And Montenegro'),
80 'cu' => t('Cuba'),
81 'cv' => t('Cape Verde'),
82 'cx' => t('Christmas Island'),
83 'cy' => t('Cyprus'),
84 'cz' => t('Czech Republic'),
85 'de' => t('Germany'),
86 'dj' => t('Djibouti'),
87 'dk' => t('Denmark'),
88 'dm' => t('Dominica'),
89 'do' => t('Dominican Republic'),
90 'dz' => t('Algeria'),
91 'ec' => t('Ecuador'),
92 'ee' => t('Estonia'),
93 'eg' => t('Egypt'),
94 'eh' => t('Western Sahara'),
95 'er' => t('Eritrea'),
96 'es' => t('Spain'),
97 'et' => t('Ethiopia'),
98 'fi' => t('Finland'),
99 'fj' => t('Fiji'),
100 'fk' => t('Falkland Islands'),
101 'fm' => t('Micronesia'),
102 'fo' => t('Faroe Islands'),
103 'fr' => t('France'),
104 'ga' => t('Gabon'),
105 'gd' => t('Grenada'),
106 'ge' => t('Georgia'),
107 'gf' => t('French Guiana'),
108 'gg' => t('Guernsey'),
109 'gh' => t('Ghana'),
110 'gi' => t('Gibraltar'),
111 'gl' => t('Greenland'),
112 'gm' => t('Gambia'),
113 'gn' => t('Guinea'),
114 'gp' => t('Guadeloupe'),
115 'gq' => t('Equatorial Guinea'),
116 'gr' => t('Greece'),
117 'gs' => t('South Georgia and the South Sandwich Islands'),
118 'gt' => t('Guatemala'),
119 'gu' => t('Guam'),
120 'gw' => t('Guinea-Bissau'),
121 'gy' => t('Guyana'),
122 'hk' => t('Hong Kong S.A.R., China'),
123 'hm' => t('Heard Island and McDonald Islands'),
124 'hn' => t('Honduras'),
125 'hr' => t('Croatia'),
126 'ht' => t('Haiti'),
127 'hu' => t('Hungary'),
128 'id' => t('Indonesia'),
129 'ie' => t('Ireland'),
130 'il' => t('Israel'),
131 'im' => t('Isle of Man'),
132 'in' => t('India'),
133 'io' => t('British Indian Ocean Territory'),
134 'iq' => t('Iraq'),
135 'ir' => t('Iran'),
136 'is' => t('Iceland'),
137 'it' => t('Italy'),
138 'je' => t('Jersey'),
139 'jm' => t('Jamaica'),
140 'jo' => t('Jordan'),
141 'jp' => t('Japan'),
142 'ke' => t('Kenya'),
143 'kg' => t('Kyrgyzstan'),
144 'kh' => t('Cambodia'),
145 'ki' => t('Kiribati'),
146 'km' => t('Comoros'),
147 'kn' => t('Saint Kitts and Nevis'),
148 'kp' => t('North Korea'),
149 'kr' => t('South Korea'),
150 'kw' => t('Kuwait'),
151 'ky' => t('Cayman Islands'),
152 'kz' => t('Kazakhstan'),
153 'la' => t('Laos'),
154 'lb' => t('Lebanon'),
155 'lc' => t('Saint Lucia'),
156 'li' => t('Liechtenstein'),
157 'lk' => t('Sri Lanka'),
158 'lr' => t('Liberia'),
159 'ls' => t('Lesotho'),
160 'lt' => t('Lithuania'),
161 'lu' => t('Luxembourg'),
162 'lv' => t('Latvia'),
163 'ly' => t('Libya'),
164 'ma' => t('Morocco'),
165 'mc' => t('Monaco'),
166 'md' => t('Moldova'),
167 'me' => t('Montenegro'),
168 'mg' => t('Madagascar'),
169 'mh' => t('Marshall Islands'),
170 'mk' => t('Macedonia'),
171 'ml' => t('Mali'),
172 'mm' => t('Myanmar'),
173 'mn' => t('Mongolia'),
174 'mo' => t('Macao S.A.R., China'),
175 'mp' => t('Northern Mariana Islands'),
176 'mq' => t('Martinique'),
177 'mr' => t('Mauritania'),
178 'ms' => t('Montserrat'),
179 'mt' => t('Malta'),
180 'mu' => t('Mauritius'),
181 'mv' => t('Maldives'),
182 'mw' => t('Malawi'),
183 'mx' => t('Mexico'),
184 'my' => t('Malaysia'),
185 'mz' => t('Mozambique'),
186 'na' => t('Namibia'),
187 'nc' => t('New Caledonia'),
188 'ne' => t('Niger'),
189 'nf' => t('Norfolk Island'),
190 'ng' => t('Nigeria'),
191 'ni' => t('Nicaragua'),
192 'nl' => t('Netherlands'),
193 'no' => t('Norway'),
194 'np' => t('Nepal'),
195 'nr' => t('Nauru'),
196 'nu' => t('Niue'),
197 'nz' => t('New Zealand'),
198 'om' => t('Oman'),
199 'pa' => t('Panama'),
200 'pe' => t('Peru'),
201 'pf' => t('French Polynesia'),
202 'pg' => t('Papua New Guinea'),
203 'ph' => t('Philippines'),
204 'pk' => t('Pakistan'),
205 'pl' => t('Poland'),
206 'pm' => t('Saint Pierre and Miquelon'),
207 'pn' => t('Pitcairn'),
208 'pr' => t('Puerto Rico'),
209 'ps' => t('Palestinian Territory'),
210 'pt' => t('Portugal'),
211 'pw' => t('Palau'),
212 'py' => t('Paraguay'),
213 'qa' => t('Qatar'),
214 're' => t('Reunion'),
215 'ro' => t('Romania'),
216 'rs' => t('Serbia'),
217 'ru' => t('Russia'),
218 'rw' => t('Rwanda'),
219 'sa' => t('Saudi Arabia'),
220 'sb' => t('Solomon Islands'),
221 'sc' => t('Seychelles'),
222 'sd' => t('Sudan'),
223 'se' => t('Sweden'),
224 'sg' => t('Singapore'),
225 'sh' => t('Saint Helena'),
226 'si' => t('Slovenia'),
227 'sj' => t('Svalbard and Jan Mayen'),
228 'sk' => t('Slovakia'),
229 'sl' => t('Sierra Leone'),
230 'sm' => t('San Marino'),
231 'sn' => t('Senegal'),
232 'so' => t('Somalia'),
233 'sr' => t('Suriname'),
234 'st' => t('Sao Tome and Principe'),
235 'sv' => t('El Salvador'),
236 'sy' => t('Syria'),
237 'sz' => t('Swaziland'),
238 'tc' => t('Turks and Caicos Islands'),
239 'td' => t('Chad'),
240 'tf' => t('French Southern Territories'),
241 'tg' => t('Togo'),
242 'th' => t('Thailand'),
243 'tj' => t('Tajikistan'),
244 'tk' => t('Tokelau'),
245 'tl' => t('East Timor'),
246 'tm' => t('Turkmenistan'),
247 'tn' => t('Tunisia'),
248 'to' => t('Tonga'),
249 'tr' => t('Turkey'),
250 'tt' => t('Trinidad and Tobago'),
251 'tv' => t('Tuvalu'),
252 'tw' => t('Taiwan'),
253 'tz' => t('Tanzania'),
254 'ua' => t('Ukraine'),
255 'ug' => t('Uganda'),
256 'uk' => t('United Kingdom'),
257 'um' => t('United States Minor Outlying Islands'),
258 'us' => t('United States'),
259 'uy' => t('Uruguay'),
260 'uz' => t('Uzbekistan'),
261 'va' => t('Vatican'),
262 'vc' => t('Saint Vincent and the Grenadines'),
263 've' => t('Venezuela'),
264 'vg' => t('British Virgin Islands'),
265 'vi' => t('U.S. Virgin Islands'),
266 'vn' => t('Vietnam'),
267 'vu' => t('Vanuatu'),
268 'wf' => t('Wallis and Futuna'),
269 'ws' => t('Samoa'),
270 'ye' => t('Yemen'),
271 'yt' => t('Mayotte'),
272 'za' => t('South Africa'),
273 'zm' => t('Zambia'),
274 'zw' => t('Zimbabwe'),
275 );
276
277 if (!empty($available)) {
278 foreach ($countries as $ccode => $country) {
279 if (empty($available[$ccode])) {
280 unset($countries[$ccode]);
281 }
282 }
283 }
284
285 // In fact, the ISO codes for countries are all Upper Case.
286 // So, if someone needs the list as the official records,
287 // it will convert.
288 if (!empty($upper)) {
289 $countries = array_change_key_case($countries, CASE_UPPER);
290 }
291
292 // Sort the list and return
293 natcasesort($countries);
294
295 return $countries;
296 }
297
298 /**
299 * 3-diget code of all countries on Planet! :)
300 *
301 * It uses the ISO notation.
302 * See http://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
303 * for further info.
304 *
305 * @return
306 * Array. 'COUNTRY 2-DIGIT CODE' => 'COUNTRY 3-DIGIT CODE' pairs
307 */
308 function _addresses_country_get_code3() {
309 $countries = array(
310 'af' => 'afg',
311 'ax' => 'ala',
312 'al' => 'alb',
313 'dz' => 'dza',
314 'as' => 'asm',
315 'ad' => 'and',
316 'ao' => 'ago',
317 'ai' => 'aia',
318 'aq' => 'ata',
319 'ag' => 'atg',
320 'ar' => 'arg',
321 'am' => 'arm',
322 'aw' => 'abw',
323 'au' => 'aus',
324 'at' => 'aut',
325 'az' => 'aze',
326 'bs' => 'bhs',
327 'bh' => 'bhr',
328 'bd' => 'bgd',
329 'bb' => 'brb',
330 'by' => 'blr',
331 'be' => 'bel',
332 'bz' => 'blz',
333 'bj' => 'ben',
334 'bm' => 'bmu',
335 'bt' => 'btn',
336 'bo' => 'bol',
337 'ba' => 'bih',
338 'bw' => 'bwa',
339 'bv' => 'bvt',
340 'br' => 'bra',
341 'io' => 'iot',
342 'bn' => 'brn',
343 'bg' => 'bgr',
344 'bf' => 'bfa',
345 'bi' => 'bdi',
346 'kh' => 'khm',
347 'cm' => 'cmr',
348 'ca' => 'can',
349 'cv' => 'cpv',
350 'ky' => 'cym',
351 'cf' => 'caf',
352 'td' => 'tcd',
353 'cl' => 'chl',
354 'cn' => 'chn',
355 'cx' => 'cxr',
356 'cc' => 'cck',
357 'co' => 'col',
358 'km' => 'com',
359 'cg' => 'cog',
360 'cd' => 'zar',
361 'ck' => 'cok',
362 'cr' => 'cri',
363 'ci' => 'civ',
364 'hr' => 'hrv',
365 'cu' => 'cub',
366 'cy' => 'cyp',
367 'cz' => 'cze',
368 'dk' => 'dnk',
369 'dj' => 'dji',
370 'dm' => 'dma',
371 'do' => 'dom',
372 'ec' => 'ecu',
373 'eg' => 'egy',
374 'sv' => 'slv',
375 'gq' => 'gnq',
376 'er' => 'eri',
377 'ee' => 'est',
378 'et' => 'eth',
379 'fk' => 'flk',
380 'fo' => 'fro',
381 'fj' => 'fji',
382 'fi' => 'fin',
383 'fr' => 'fra',
384 'gf' => 'guf',
385 'pf' => 'pyf',
386 'tf' => 'atf',
387 'ga' => 'gab',
388 'gm' => 'gmb',
389 'ge' => 'geo',
390 'de' => 'deu',
391 'gh' => 'gha',
392 'gi' => 'gib',
393 'gr' => 'grc',
394 'gl' => 'grl',
395 'gd' => 'grd',
396 'gp' => 'glp',
397 'gu' => 'gum',
398 'gt' => 'gtm',
399 'gg' => 'ggy',
400 'gn' => 'gin',
401 'gw' => 'gnb',
402 'gy' => 'guy',
403 'ht' => 'hti',
404 'hm' => 'hmd',
405 'va' => 'vat',
406 'hn' => 'hnd',
407 'hk' => 'hkg',
408 'hu' => 'hun',
409 'is' => 'isl',
410 'in' => 'ind',
411 'id' => 'idn',
412 'ir' => 'irn',
413 'iq' => 'irq',
414 'ie' => 'irl',
415 'im' => 'imn',
416 'il' => 'isr',
417 'it' => 'ita',
418 'jm' => 'jam',
419 'jp' => 'jpn',
420 'je' => 'jey',
421 'jo' => 'jor',
422 'kz' => 'kaz',
423 'ke' => 'ken',
424 'ki' => 'kir',
425 'kp' => 'prk',
426 'kr' => 'kor',
427 'kw' => 'kwt',
428 'kg' => 'kgz',
429 'la' => 'lao',
430 'lv' => 'lva',
431 'lb' => 'lbn',
432 'ls' => 'lso',
433 'lr' => 'lbr',
434 'ly' => 'lby',
435 'li' => 'lie',
436 'lt' => 'ltu',
437 'lu' => 'lux',
438 'mo' => 'mac',
439 'mk' => 'mkd',
440 'mg' => 'mdg',
441 'mw' => 'mwi',
442 'my' => 'mys',
443 'mv' => 'mdv',
444 'ml' => 'mli',
445 'mt' => 'mlt',
446 'mh' => 'mhl',
447 'mq' => 'mtq',
448 'mr' => 'mrt',
449 'mu' => 'mus',
450 'yt' => 'myt',
451 'mx' => 'mex',
452 'fm' => 'fsm',
453 'md' => 'mda',
454 'mc' => 'mco',
455 'mn' => 'mng',
456 'me' => 'mne',
457 'ms' => 'msr',
458 'ma' => 'mar',
459 'mz' => 'moz',
460 'mm' => 'mmr',
461 'na' => 'nam',
462 'nr' => 'nru',
463 'np' => 'npl',
464 'nl' => 'nld',
465 'an' => 'ant',
466 'nc' => 'ncl',
467 'nz' => 'nzl',
468 'ni' => 'nic',
469 'ne' => 'ner',
470 'ng' => 'nga',
471 'nu' => 'niu',
472 'nf' => 'nfk',
473 'mp' => 'mnp',
474 'no' => 'nor',
475 'om' => 'omn',
476 'pk' => 'pak',
477 'pw' => 'plw',
478 'ps' => 'pse',
479 'pa' => 'pan',
480 'pg' => 'png',
481 'py' => 'pry',
482 'pe' => 'per',
483 'ph' => 'phl',
484 'pn' => 'pcn',
485 'pl' => 'pol',
486 'pt' => 'prt',
487 'pr' => 'pri',
488 'qa' => 'qat',
489 're' => 'reu',
490 'ro' => 'rou',
491 'ru' => 'rus',
492 'rw' => 'rwa',
493 'bl' => 'blm',
494 'sh' => 'shn',
495 'kn' => 'kna',
496 'lc' => 'lca',
497 'mf' => 'maf',
498 'pm' => 'spm',
499 'vc' => 'vct',
500 'ws' => 'wsm',
501 'sm' => 'smr',
502 'st' => 'stp',
503 'sa' => 'sau',
504 'sn' => 'sen',
505 'rs' => 'srb',
506 'sc' => 'syc',
507 'sl' => 'sle',
508 'sg' => 'sgp',
509 'sk' => 'svk',
510 'si' => 'svn',
511 'sb' => 'slb',
512 'so' => 'som',
513 'za' => 'zaf',
514 'gs' => 'sgs',
515 'es' => 'esp',
516 'lk' => 'lka',
517 'sd' => 'sdn',
518 'sr' => 'sur',
519 'sj' => 'sjm',
520 'sz' => 'swz',
521 'se' => 'swe',
522 'ch' => 'che',
523 'sy' => 'syr',
524 'tw' => 'twn',
525 'tj' => 'tjk',
526 'tz' => 'tza',
527 'th' => 'tha',
528 'tl' => 'tls',
529 'tg' => 'tgo',
530 'tk' => 'tkl',
531 'to' => 'ton',
532 'tt' => 'tto',
533 'tn' => 'tun',
534 'tr' => 'tur',
535 'tm' => 'tkm',
536 'tc' => 'tca',
537 'tv' => 'tuv',
538 'ug' => 'uga',
539 'ua' => 'ukr',
540 'ae' => 'are',
541 'gb' => 'gbr',
542 'us' => 'usa',
543 'um' => 'umi',
544 'uy' => 'ury',
545 'uz' => 'uzb',
546 'vu' => 'vut',
547 've' => 'ven',
548 'vn' => 'vnm',
549 'vg' => 'vgb',
550 'vi' => 'vir',
551 'wf' => 'wlf',
552 'eh' => 'esh',
553 'ye' => 'yem',
554 'zm' => 'zmb',
555 'zw' => 'zwe'
556 );
557
558 return $countries;
559 }
560
561 /**
562 * Get available states.
563 *
564 * @param $country
565 * String (optional). The 2-digit country code
566 * @return
567 * Array. If $country is passed, then return an array
568 * of states for that country. If nothing is passed then return
569 * an array of countrys who have states, where each country contains
570 * an array of states.
571 */
572 function _addresses_province_get($country = NULL) {
573 static $provinces;
574
575 // Get a list of countries
576 $countries_all = _addresses_country_get();
577
578 // Test if its needed to update the province list
579 if (empty($country) and empty($provinces)) {
580 // Get the countries list
581 $countries = array_keys($countries_all);
582 $update = TRUE;
583 }
584 elseif (!empty($country) and $countries_all[$country] and empty($provinces[$country])) {
585 $countries[] = $country;
586 $update = TRUE;
587 }
588
589 if (!empty($update)) {
590 foreach ($countries as $country_code) {
591 // Load country specifice code .inc file if it exists.
592 // For example, if country_code for U.S. == 'us', load 'addresses.us.inc'
593 include_once drupal_get_path('module', 'addresses') .'/countries/'. $country_code .'.inc';
594
595 // If the country have a province list, load it
596 $function = 'addresses_province_list_'. $country_code;
597 if (function_exists($function)) {
598 $provinces[$country_code] = $function();
599 }
600 }
601 }
602
603 // Return the states of a single country, if any
604 if (!empty($country)) {
605 if (isset($provinces[$country])) {
606 return $provinces[$country];
607 }
608 else {
609 return array();
610 }
611 }
612 else {
613 return $provinces;
614 }
615 }
616
617 /**
618 * Generates HTML for the passed address.
619 *
620 * @ingroup themeable
621 * @param $afields
622 * Array. A single address with the following fields (generally, but it can have more):
623 * - 'street' => A string representing the street
624 * - 'additional' => A string for any additional portion of the street
625 * - 'city' => A string for the city name
626 * - 'province' => The standard postal abbreviation for the province
627 * - 'country' => The two-letter ISO code for the country of the address (REQUIRED)
628 * - 'postal_code' => The international postal code for the address
629 */
630 function theme_addresses($afields) {
631 // If all fields are hidden, return ''
632 if (empty($afields)) {
633 return '';
634 }
635
636 // Get the proper address format
637 if (!empty($afields['country'])
638 and !$format_address = variable_get('addresses_format_'. $afields['country'], '')) {
639
640 // Load country specifice code .inc file if it exists.
641 // For example, if country_code for U.S. == 'us', load 'addresses.us.inc'
642 include_once drupal_get_path('module', 'addresses') .'/countries/'. $afields['country'] .'.inc';
643
644 // If the country has an preset address format
645 $function = 'addresses_address_format_'. $afields['country'];
646 if (function_exists($function)) {
647 $format_address = $function();
648 variable_set('addresses_format_'. $afields['country'], $format_address);
649 }
650 }
651
652 // If still no proper address format, use the United States format
653 if (empty($format_address) and !$format_address = variable_get('addresses_format_default', '')) {
654 include_once drupal_get_path('module', 'addresses') .'/countries/us.inc';
655 $format_address = addresses_address_format_us();
656 variable_set('addresses_format_default', $format_address);
657 }
658
659 // Call token module to replace all tokens to their right value. Also,
660 // use 'adr' microformat
661 $format_address = '<dl class="adr">'.
662 token_replace($format_address, 'addresses_adr', $afields, '!', '') .'</dl> ';
663
664 // Besides being the Drupal Address info,
665 // its possible to be used by hCard and VCard (if a address name was provided)
666 $format_address = '<div class="vcard">'.
667 token_replace($format_address, 'addresses_general', $afields, '!', '') .'</div>';
668
669 // Replace the new lines for HTML line breaks AND remove
670 // all empty lines
671 $format_address = explode("\n", $format_address);
672 foreach (array_keys($format_address) as $line) {
673 $format_address[$line] = trim($format_address[$line]);
674 if (empty($format_address[$line])) {
675 unset($format_address[$line]);
676 }
677 }
678 $format_address = implode('<br/>', $format_address);
679
680 // Add the CCS
681 drupal_add_css(drupal_get_path('module', 'addresses') .'/addresses.css');
682
683 return $format_address;
684 }
685
686 /**
687 * Print the field Primary.
688 *
689 * @param $afields
690 * Array. All field values
691 * @ingroup themeable
692 */
693 function theme_addresses_field_primary($afields) {
694 return ' ('. t('default') .')';
695 }
696
697 /**
698 * Print the field Address name.
699 *
700 * @param $afields
701 * Array. All field values
702 * @ingroup themeable
703 */
704 function theme_addresses_field_aname($afields) {
705 return '<span class="fn org">'. theme('placeholder', $object['aname']) . $values['primary'] .'</span>';
706 }
707
708 /**
709 * Print the field City.
710 *
711 * @param $afields
712 * Array. All field values
713 * @ingroup themeable
714 */
715 function theme_addresses_field_city($afields) {
716 return '<dt>'. t('City') .': </dt><dd class="city locality">'. $afields['city'] .'</dd>';
717 }
718
719 /**
720 * Print the field Street.
721 *
722 * @param $afields
723 * Array. All field values
724 * @ingroup themeable
725 */
726 function theme_addresses_field_street($afields) {
727 return '<dt>'. t('Address') .': </dt><dd class="street-address">'. $afields['street'] .'</dd>';
728 }
729
730 /**
731 * Print the field Additional.
732 *
733 * @param $afields
734 * Array. All field values
735 * @ingroup themeable
736 */
737 function theme_addresses_field_additional($afields) {
738 return '<dt>'. t('Additional') .': </dt><dd class="extended-address">'. $afields['additional'] .'</dd>';
739 }
740
741 /**
742 * Print the field Country 3-digit code.
743 *
744 * @param $afields
745 * Array. All field values
746 * @ingroup themeable
747 */
748 function theme_addresses_field_country_name($afields) {
749 $countries = _addresses_country_get();
750 return '<dt>'. t('Country') .': </dt><dd class="country-name">'. $countries[$afields['country']] .'</dd>';
751 }
752
753 /**
754 * Print the field Country 2-digit code.
755 *
756 * @param $afields
757 * Array. All field values
758 * @ingroup themeable
759 */
760 function theme_addresses_field_country_code2($afields) {
761 $countries = _addresses_country_get();
762 return '<dt>'. t('Country') .': </dt><dd><abbr class="country-name" title="'.
763 $countries[$afields['country']] .'">'. drupal_strtoupper($afields['country']) .'</abbr></dd>';
764 }
765
766 /**
767 * Print the field Country name.
768 *
769 * @param $afields
770 * Array. All field values
771 * @ingroup themeable
772 */
773 function theme_addresses_field_country_code3($afields) {
774 $countries = _addresses_country_get();
775 $country_code3 = _addresses_country_get_code3();
776 return '<dt>'. t('Country') .': </dt><dd><abbr class="country-name" title="'.
777 $countries[$afields['country']] .'">'. drupal_strtoupper($country_code3[$afields['country']]) .'</abbr></dd>';
778 }
779
780 /**
781 * Print the field Postal Code.
782 *
783 * @param $afields
784 * Array. All field values
785 * @ingroup themeable
786 */
787 function theme_addresses_field_postal_code($afields) {
788 return '<dt>'. t('Postal Code') .': </dt><dd class="region">'. $afields['postal_code'] .'</dd>';
789 }
790
791 /**
792 * Print the field Province name.
793 *
794 * @param $afields
795 * Array. All field values
796 * @ingroup themeable
797 */
798 function theme_addresses_field_province_name($afields) {
799 $provinces = _addresses_province_get($afields['country']);
800 return '<dt>'. t('Province') .': </dt><dd class="region">'. $provinces[$afields['province']] .'</dd>';
801 }
802
803 /**
804 * Print the field Province code.
805 *
806 * @param $afields
807 * Array. All field values
808 * @ingroup themeable
809 */
810 function theme_addresses_field_province_code($afields) {
811 $provinces = _addresses_province_get($afields['country']);
812 return '<dt>'. t('Province') .': </dt><dd><abbr class="region" title="'.
813 $provinces[$afields['province']] .'">'. drupal_strtoupper($afields['province']) .'</abbr></dd>';
814 }
815
816 /**
817 * Create a single line address. Usefull for some labels.
818 *
819 * @param $afields
820 * Array. The address parts. see theme_address()
821 * @return
822 * String. The single line address
823 * @ingroup themeable
824 */
825 function theme_addresses_singleline($afields) {
826 // Check if its a valied address
827 if (empty($afields)) {
828 return '';
829 }
830
831 $output = '';
832
833 // Add the streets
834 if (!empty($afields['street'])) {
835 $output .= $afields['street'];
836 }
837
838 // Add the city
839 if (!empty($afields['city'])) {
840 if (!empty($afields['street'])) {
841 $output .= ', ';
842 }
843 $output .= $afields['city'];
844 }
845
846 // Add the state / province
847 if (!empty($afields['province'])) {
848 if (!empty($afields['street']) or !empty($afields['city'])) {
849 $output .= ', ';
850 }
851 $output .= $afields['province'];
852 }
853
854 // Add the Postal code
855 if (!empty($afields['postal_code'])) {
856 if (!empty($afields)) {
857 $output .= ' ';
858 }
859 $output .= $afields['postal_code'];
860 }
861
862 // Add the country
863 if (!empty($afields['country'])) {
864 $output .= ', '. $afields['country'];
865 }
866
867 return $output;
868 }

  ViewVC Help
Powered by ViewVC 1.1.2