+class VCard
+{
+ static private $windows = false;
+ private $iterator = null;
+
+ public function __construct($users, $photos = true, $freetext = null)
+ {
+ $this->iterator = new VCardIterator($photos, $freetext);
+ VCard::$windows = (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false);
+ if (is_array($users)) {
+ foreach ($users as $user) {
+ $this->iterator->add_user($user);
+ }
+ } else {
+ $this->iterator->add_user($users);
+ }
+ }
+
+ public static function escape($text)
+ {
+ if (VCard::$windows) {
+ return str_replace(';', '\\\\;', $text);
+ } else {
+ return str_replace(array(';', ','), array('\\\\;', '\\\\,'), $text);
+ }
+ }
+
+ public static function format_adr($params, &$smarty)
+ {
+ // $adr1, $adr2, $adr3, $postcode, $city, $region, $country
+ extract($params['adr']);
+ $adr = trim($adr1);
+ $adr = trim("$adr\n$adr2");
+ $adr = trim("$adr\n$adr3");
+ return VCard::text_encode(';;'
+ . (VCard::$windows ? VCard::escape($adr) : $adr) . ';'
+ . (VCard::$windows ? VCard::escape($city) : $city) . ';'
+ . (VCard::$windows ? VCard::escape($region) : $region) . ';'
+ . (VCard::$windows ? VCard::escape($postcode) : $postcode) . ';'
+ . (VCard::$windows ? VCard::escape($country) : $country), false);
+ }
+
+ public static function text_encode($text, $escape = true)
+ {
+ if (is_array($text)) {
+ return implode(',', array_map(array('VCard', 'text_encode'), $text));
+ }
+ if ($escape) {
+ $text = VCard::escape($text);
+ }
+ if (VCard::$windows) {
+ $text = utf8_decode($text);
+ }
+ return str_replace(array("\r\n", "\n", "\r"), '\n', $text);
+ }
+
+ public function do_page(&$page)