From: Vincent Zanotti Date: Sun, 21 Sep 2008 20:09:09 +0000 (+0200) Subject: Merge commit 'origin/master' into hruid X-Git-Tag: xorg/0.10.0~86^2~15 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=805f3d1679a53bb04fff34619c171a1381068612;p=platal.git Merge commit 'origin/master' into hruid Conflicts: classes/xnetsession.php include/validations/medals.inc.php include/validations/nomusage.inc.php include/validations/photos.inc.php include/vcard.inc.php Signed-off-by: Vincent Zanotti --- 805f3d1679a53bb04fff34619c171a1381068612 diff --cc include/validations/medals.inc.php index 498ee49,599ba21..a2a5dc1 --- a/include/validations/medals.inc.php +++ b/include/validations/medals.inc.php @@@ -101,10 -101,10 +101,10 @@@ class MedalReq extends Validat public function commit () { require_once 'notifs.inc.php'; - register_watch_op($this->user->id(), WATCH_FICHE, 'medals'); - register_watch_op($this->uid, WATCH_FICHE, '', 'medals'); ++ register_watch_op($this->user->id(), WATCH_FICHE, '', 'medals'); return XDB::execute('REPLACE INTO profile_medals_sub VALUES ({?}, {?}, {?})', - $this->uid, $this->mid, $this->gid); + $this->user->id(), $this->mid, $this->gid); } // }}} diff --cc include/validations/nomusage.inc.php index 319b1cf,15f3e8e..0bc76cd --- a/include/validations/nomusage.inc.php +++ b/include/validations/nomusage.inc.php @@@ -114,9 -110,9 +114,9 @@@ class UsageReq extends Validat public function commit() { require_once 'notifs.inc.php'; - register_watch_op($this->user->id(), WATCH_FICHE, 'nom'); - register_watch_op($this->uid, WATCH_FICHE, '', 'nom'); ++ register_watch_op($this->user->id(), WATCH_FICHE, '', 'nom'); require_once('user.func.inc.php'); - $this->bestalias = set_new_usage($this->uid, $this->nom_usage, $this->alias); + set_new_usage($this->user->id(), $this->nom_usage, $this->alias); return true; } diff --cc include/validations/photos.inc.php index f65b06c,0f2d109..7194e04 --- a/include/validations/photos.inc.php +++ b/include/validations/photos.inc.php @@@ -140,8 -140,8 +140,8 @@@ class PhotoReq extends Validat require_once 'notifs.inc.php'; XDB::execute('REPLACE INTO photo (uid, attachmime, attach, x, y) VALUES ({?},{?},{?},{?},{?})', - $this->uid, $this->mimetype, $this->data, $this->x, $this->y); - register_watch_op($this->uid, WATCH_FICHE, '', 'photo'); + $this->user->id(), $this->mimetype, $this->data, $this->x, $this->y); - register_watch_op($this->user->id(), WATCH_FICHE, 'photo'); ++ register_watch_op($this->user->id(), WATCH_FICHE, '', 'photo'); return true; } diff --cc include/vcard.inc.php index 0671343,2be89de..d16dae6 --- a/include/vcard.inc.php +++ b/include/vcard.inc.php @@@ -34,47 -35,99 +35,99 @@@ class VCard extends PlVCar $this->photos = $photos; } - public function add_user($user) + public function addUser($user) { - $forlife = get_user_forlife($user, '_silent_user_callback'); - if ($forlife) { - $this->user_list[] = get_user_forlife($user); + $user = User::getSilent($user); + if ($user) { + $this->user_list[] = $user; $this->count++; } } - public function first() - { - return count($this->user_list) == $this->count - 1; - } - - public function last() - { - return count($this->user_list) == 0; + public function addUsers(array $users) { + foreach ($users as $user) { + $this->addUser($user); + } } - public function total() + protected function fetch() { - return $this->count; + return PlIteratorUtils::fromArray($this->user_list); } - public function next() + protected function buildEntry($entry) { - if (!$this->user_list) { - return null; - } global $globals; - $login = array_shift($this->user_list); + $login = $entry['value']; - $user = get_user_details($login); + $user = get_user_details($login->login()); - if (strlen(trim($user['freetext']))) { - $user['freetext'] = pl_entity_decode($user['freetext']); + 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) { - if (strlen(trim($user['freetext']))) { - $user['freetext'] = $this->freetext . "\n" . $user['freetext']; - } else { - $user['freetext'] = $this->freetext; + $freetext .= "\n" . $this->freetext; + } + if (strlen(trim($user['freetext']))) { + $freetext .= "\n" . MiniWiki::WikiToText($user['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']); } } @@@ -89,91 -142,35 +142,34 @@@ $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('VCard', 'text_encode'), $user['gpxs_name'])); - $user['binets_vcardjoin'] = join(', ', array_map(array('VCard', 'text_encode'), $user['binets'])); - // get photo + // Photo if ($this->photos) { $res = XDB::query( - "SELECT attach, attachmime - FROM photo AS p - INNER JOIN aliases AS a ON (a.id = p.uid AND a.type = 'a_vie') - WHERE a.alias = {?}", $login); + "SELECT attach, attachmime + FROM photo AS p + WHERE u.user_id = {?}", $login->id()); if ($res->numRows()) { - $user['photo'] = $res->fetchOneAssoc(); - } - } - return $user; - } - } - - 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); + list($data, $type) = $res->fetchOneRow(); + $entry->setPhoto($data, strtoupper($type)); } - } 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); + return $entry; } - - public 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->iterator); - - header("Pragma: "); - header("Cache-Control: "); - header("Content-type: text/x-vcard; charset=UTF-8"); - } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: diff --cc modules/profile.php index d283e3d,039f71a..07324f4 --- a/modules/profile.php +++ b/modules/profile.php @@@ -734,19 -718,22 +734,20 @@@ class ProfileModule extends PLModul $x = substr($x, 0, strlen($x) - 4); } - $vcard = new VCard($x); - $vcard->do_page($page); + $vcard = new VCard(); + $vcard->addUser($x); + $vcard->show(); } - function handler_admin_trombino(&$page, $uid = null, $action = null) { + function handler_admin_trombino(&$page, $login = null, $action = null) { $page->changeTpl('profile/admin_trombino.tpl'); $page->setTitle('Administration - Trombino'); - $page->assign('uid', $uid); - $q = XDB::query( - "SELECT a.alias,promo - FROM auth_user_md5 AS u - INNER JOIN aliases AS a ON ( u.user_id = a.id AND type='a_vie' ) - WHERE user_id = {?}", $uid); - list($forlife, $promo) = $q->fetchOneRow(); + if (!$login || !($user = User::get($login))) { + return PL_NOT_FOUND; + } else { + $page->assign_by_ref('user', $user); + } switch ($action) { case "original":