X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvcard.inc.php;h=0fc553ef539e7648a8b8f055f93bea0e2ffc9c38;hb=5d42c993d85a2f1fa3595eb1591a921c0f89d8cd;hp=c2b3db17bb01f498ae2b3d81b27ff691b557777a;hpb=662ec806255b74da16b3af7a8d17db99ca7756f9;p=platal.git diff --git a/include/vcard.inc.php b/include/vcard.inc.php index c2b3db1..0fc553e 100644 --- a/include/vcard.inc.php +++ b/include/vcard.inc.php @@ -1,6 +1,6 @@ photos = $photos; - if (is_array($users)) { - foreach ($users as $user) { - $this->add_user($user, $freetext); - } - } else { - $this->add_user($users, $freetext); - } + PlVCard::$folding = false; + $this->freetext = $freetext; + $this->photos = $photos; } - function escape($text) + public function addUser($user) { - return preg_replace('/[,;]/', '\\\\$0', $text); + $forlife = get_user_forlife($user, '_silent_user_callback'); + if ($forlife) { + $this->user_list[] = get_user_forlife($user); + $this->count++; + } } - 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 $this->text_encode(';;' - . $this->escape($adr) . ';' - . $this->escape($city) . ';' - . $this->escape($region) . ';' - . $this->escape($postcode) . ';' - . $this->escape($country), false); + public function addUsers(array $users) { + foreach ($users as $user) { + $this->addUser($user); + } } - function text_encode($text, $escape = true) + protected function fetch() { - if (is_array($text)) { - return implode(',', array_map(array($this, 'text_encode'), $text)); - } - if ($escape) { - $text = $this->escape($text); - } - return preg_replace("/(\r\n|\n|\r)/", '\n', $text); + return new PlArrayIterator($this->user_list); } - function add_user($x, $freetext) + protected function buildEntry($entry) { global $globals; - - $login = get_user_forlife($x); + $login = $entry['value']; $user = get_user_details($login); + if (empty($user['nom_usage'])) { + $entry = new PlVCardEntry($user['prenom'], $user['nom'], null, null, @$user['nickname']); + } else { + $entry = new PlVCardEntry($user['prenom'], array($user['nom'], $user['nom_usage']), null, null, @$user['nickname']); + } + + // Free text + $freetext = '(' . $user['promo'] . ')'; + if ($this->freetext) { + $freetext .= "\n" . $this->freetext; + } if (strlen(trim($user['freetext']))) { - $user['freetext'] = html_entity_decode($user['freetext']); + $freetext .= "\n" . MiniWiki::WikiToText($user['freetext']); } - if (!is_null($freetext)) { - if (strlen(trim($user['freetext']))) { - $user['freetext'] = $freetext . "\n" . $user['freetext']; - } else { - $user['freetext'] = $freetext; + $entry->set('NOTE', $freetext); + + // Mobile + if (!empty($user['mobile'])) { + $entry->addTel(null, $user['mobile'], false, true, true, false, true, true); + } + + // Emails + $entry->addMail(null, $user['bestalias'] . '@' . $globals->mail->domain, true); + $entry->addMail(null, $user['bestalias'] . '@' . $globals->mail->domain2); + if ($user['bestalias'] != $user['forlife']) { + $entry->addMail(null, $user['forlife'] . '@' . $globals->mail->domain); + $entry->addMail(null, $user['forlife'] . '@' . $globals->mail->domain2); + } + + // Homes + foreach ($user['adr'] as $adr) { + $street = array($adr['adr1']); + if (!empty($adr['adr2'])) { + $street[] = $adr['adr2']; + } + if (!empty($adr['adr3'])) { + $street[] = $adr['adr3']; + } + $group = $entry->addHome($street, null, null, $adr['postcode'], $adr['city'], $adr['region'], @$adr['country'], + $adr['active'], $adr['courier'], $adr['courier']); + if (!empty($adr['tels'])) { + foreach ($adr['tels'] as $tel) { + $fax = $tel['tel_type'] == 'Fax'; + $entry->addTel($group, $tel['tel'], $fax, !$fax, !$fax, false, false, !$fax && $adr['active'] && empty($user['mobile'])); + } + } + } + + // Pro + foreach ($user['adr_pro'] as $pro) { + $street = array($adr['adr1']); + if (!empty($pro['adr2'])) { + $street[] = $pro['adr2']; + } + if (!empty($pro['adr3'])) { + $street[] = $pro['adr3']; + } + $group = $entry->addWork($pro['entreprise'], null, $pro['poste'], $pro['fonction'], + $street, null, null, $pro['postcode'], $pro['city'], $pro['region'], @$pro['country']); + if (!empty($pro['tel'])) { + $entry->addTel($group, $pro['tel']); + } + if (!empty($pro['fax'])) { + $entry->addTel($group, $pro['fax'], true); + } + if (!empty($pro['email'])) { + $entry->addMail($group, $pro['email']); } } - // alias virtual + // Melix $res = XDB::query( "SELECT alias FROM virtual @@ -96,14 +139,25 @@ class VCard INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' ) WHERE ( redirect={?} OR redirect={?} ) AND alias LIKE '%@{$globals->mail->alias_dom}'", - S::v('uid'), + $user['user_id'], $user['forlife'].'@'.$globals->mail->domain, $user['forlife'].'@'.$globals->mail->domain2); + if ($res->numRows()) { + $entry->addMail(null, $res->fetchOneCell()); + } + + // Custom fields + if (count($user['gpxs_name'])) { + $entry->set('X-GROUPS', join(', ', $user['gpxs_name'])); + } + if (count($user['binets'])) { + $entry->set('X-BINETS', join(', ', $user['binets'])); + } + if (!empty($user['section'])) { + $entry->set('X-SECTION', $user['section']); + } - $user['virtualalias'] = $res->fetchOneCell(); - $user['gpxs_vcardjoin'] = join(',', array_map(array($this, 'text_encode'), $user['gpxs_name'])); - $user['binets_vcardjoin'] = join(',', array_map(array($this, 'text_encode'), $user['binets'])); - // get photo + // Photo if ($this->photos) { $res = XDB::query( "SELECT attach, attachmime @@ -111,25 +165,13 @@ class VCard INNER JOIN aliases AS a ON (a.id = p.uid AND a.type = 'a_vie') WHERE a.alias = {?}", $login); if ($res->numRows()) { - $user['photo'] = $res->fetchOneAssoc(); + list($data, $type) = $res->fetchOneRow(); + $entry->setPhoto($data, strtoupper($type)); } } - $this->users[] = $user; - } - - function do_page(&$page) - { - $page->changeTpl('core/vcard.tpl', NO_SKIN); - $page->register_modifier('vcard_enc', array($this, 'text_encode')); - $page->register_function('format_adr', array($this, 'format_adr')); - $page->assign_by_ref('users', $this->users); - - header("Pragma: "); - header("Cache-Control: "); - header("Content-type: text/x-vcard; charset=iso-8859-15"); - header("Content-Transfer-Encoding: 8bit"); + return $entry; } } -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>