From 54cabe90fc74fa713a711c50cd096801586de084 Mon Sep 17 00:00:00 2001 From: Vincent Zanotti Date: Sun, 24 Aug 2008 23:23:41 +0200 Subject: [PATCH] Upgrades the profile to the new User/hruid model. This is only a partial upgrade though, since the profile will benefit from the integration of all profile informations to the User object. Signed-off-by: Vincent Zanotti --- modules/profile.php | 131 +++++++++++++++++++---------------- templates/profile/admin_trombino.tpl | 10 +-- templates/profile/profile.tpl | 36 +++++----- 3 files changed, 95 insertions(+), 82 deletions(-) diff --git a/modules/profile.php b/modules/profile.php index 15ea9bc..d283e3d 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -135,9 +135,7 @@ class ProfileModule extends PLModule require_once('validations.inc.php'); - $trombi_x = '/home/web/trombino/photos'.S::v('promo') - .'/'.S::v('forlife').'.jpg'; - + $trombi_x = '/home/web/trombino/photos' . S::v('promo') . '/' . S::user()->login() . '.jpg'; if (Env::has('upload')) { S::assert_xsrf_token(); @@ -190,52 +188,67 @@ class ProfileModule extends PLModule function handler_profile(&$page, $x = null) { + // TODO/note for upcoming developers: + // We currently maintain both $user and $login; $user is the old way of + // obtaining information, and eventually everything will be loaded + // through $login. That is the reason why in the template $user is named + // $x, and $login $user (sorry for the confusion). + + // Determines which user to display the profile of, and retrieves basic + // information on this user. if (is_null($x)) { return PL_NOT_FOUND; } - global $globals; - require_once 'user.func.inc.php'; - - $page->changeTpl('profile/profile.tpl', SIMPLE); - - $view = 'private'; - if (!S::logged() || Env::v('view') == 'public') $view = 'public'; - if (S::logged() && Env::v('view') == 'ax') $view = 'ax'; - $login = S::logged() ? User::get($x) : User::getSilent($x); if (!$login) { return PL_NOT_FOUND; } + // Now that we know this is the profile of an existing user, we can + // switch to the appropriate template. + $page->changeTpl('profile/profile.tpl', SIMPLE); + require_once 'user.func.inc.php'; + + // Determines the access level at which the profile will be displayed. + if (!S::logged() || Env::v('view') == 'public') { + $view = 'public'; + } else if (S::logged() && Env::v('view') == 'ax') { + $view = 'ax'; + } else { + $view = 'private'; + } + + // Determines is the user is registered, and fetches the user infos in + // the appropriate way. $res = XDB::query("SELECT perms IN ('admin','user','disabled') FROM auth_user_md5 WHERE user_id = {?}", $login->id()); - if (!$res->fetchOneCell()) { - $user = get_not_registered_user($x, true); - if ($user->total() != 1) { - return PL_NOT_FOUND; - } - $user = $user->next(); + if ($res->fetchOneCell()) { + $new = Env::v('modif') == 'new'; + $user = get_user_details($login->login(), S::v('uid'), $view); + } else { + $new = false; + $user = array(); if (S::logged()) { - pl_redirect('marketing/public/' . $user['user_id']); + pl_redirect('marketing/public/' . $login->login()); } - $user['forlife'] = $x; - } else { - $new = Env::v('modif') == 'new'; - $user = get_user_details($login->login(), S::v('uid'), $view); } + // Profile view are logged. if (S::logged()) { S::logger()->log('view_profile', $login->login()); } - $title = $user['prenom'] . ' ' . ( empty($user['nom_usage']) ? $user['nom'] : $user['nom_usage'] ); - $page->setTitle($title); + // Sets the title of the html page. + $page->setTitle($login->fullName()); - // photo - - $photo = 'photo/'.$user['forlife'].($new ? '/req' : ''); + // Prepares the display of the user's mugshot. + $photo = 'photo/' . $login->login() . ($new ? '/req' : ''); + if (!isset($user['photo_pub']) || !has_user_right($user['photo_pub'], $view)) { + $photo = ""; + } + $page->assign('photo_url', $photo); if (!isset($user['y']) and !isset($user['x'])) { list($user['x'], $user['y']) = getimagesize("images/none.png"); @@ -255,29 +268,33 @@ class ProfileModule extends PLModule $user['x'] = 160; } - $page->assign('logged', has_user_right('private', $view)); - if (!has_user_right($user['photo_pub'], $view)) { - $photo = ""; - } - - $page->assign_by_ref('x', $user); - $page->assign('photo_url', $photo); - // alias virtual + // Determines and displays the virtual alias. + global $globals; $res = XDB::query( - "SELECT alias - FROM virtual - INNER JOIN virtual_redirect USING(vid) - INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' ) - WHERE ( redirect={?} OR redirect={?} ) - AND alias LIKE '%@{$globals->mail->alias_dom}'", - $user['user_id'], - $user['forlife'].'@'.$globals->mail->domain, - $user['forlife'].'@'.$globals->mail->domain2); + "SELECT alias + FROM virtual + INNER JOIN virtual_redirect USING (vid) + INNER JOIN auth_user_quick ON (user_id = {?} AND emails_alias_pub = 'public') + WHERE (redirect={?} OR redirect={?}) + AND alias LIKE '%@{$globals->mail->alias_dom}'", + $login->id(), + $login->forlifeEmail(), + // TODO(vzanotti): get ride of all @m4x.org addresses in the + // virtual redirect base, and remove this über-ugly hack. + $login->login() . '@' . $globals->mail->domain2); $page->assign('virtualalias', $res->fetchOneCell()); + + // Adds miscellaneous properties to the display. + // Adds the global user property array to the display. + $page->assign_by_ref('x', $user); + $page->assign_by_ref('user', $login); + $page->assign('logged', has_user_right('private', $view)); $page->assign('view', $view); $page->addJsLink('close_on_esc.js'); - header('Last-Modified: ' . date('r', strtotime($user['date']))); + if (isset($user['date'])) { + header('Last-Modified: ' . date('r', strtotime($user['date']))); + } } function handler_ax(&$page, $user = null) @@ -721,22 +738,20 @@ class ProfileModule extends PLModule $vcard->do_page($page); } - 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": header("Content-type: image/jpeg"); - readfile("/home/web/trombino/photos".$promo."/".$forlife.".jpg"); + readfile("/home/web/trombino/photos" . $user->promo() . "/" . $user->login() . ".jpg"); exit; break; @@ -749,17 +764,15 @@ class ProfileModule extends PLModule unlink($_FILES['userfile']['tmp_name']); XDB::execute( "REPLACE INTO photo SET uid={?}, attachmime = {?}, attach={?}, x={?}, y={?}", - $uid, $mimetype, $data, $x, $y); + $user->id(), $mimetype, $data, $x, $y); break; case "delete": S::assert_xsrf_token(); - XDB::execute('DELETE FROM photo WHERE uid = {?}', $uid); + XDB::execute('DELETE FROM photo WHERE uid = {?}', $user->id()); break; } - - $page->assign('forlife', $forlife); } function handler_admin_binets(&$page, $action = 'list', $id = null) { $page->setTitle('Administration - Binets'); diff --git a/templates/profile/admin_trombino.tpl b/templates/profile/admin_trombino.tpl index 15180f4..7af1a5d 100644 --- a/templates/profile/admin_trombino.tpl +++ b/templates/profile/admin_trombino.tpl @@ -26,21 +26,21 @@

-Photo actuelle de {$forlife} +Photo actuelle de {$user->login()}

-[ PHOTO ] +[ PHOTO ]

-Supprimer cette photo +Supprimer cette photo

-Voir sa photo de trombi récupérée à l'école (si disponible) +Voir sa photo de trombi récupérée à l'école (si disponible)

-
+ {xsrf_token_field}
diff --git a/templates/profile/profile.tpl b/templates/profile/profile.tpl index 0b35dd7..ad3816d 100644 --- a/templates/profile/profile.tpl +++ b/templates/profile/profile.tpl @@ -41,7 +41,7 @@ function chgMainWinLoc(strPage)
- {if $photo_url}Photo de {$x.forlife}{/if} + {if $photo_url}Photo de {$user->login()}{/if} {if $logged && ( $x.section|smarty:nodefaults || $x.binets_join|smarty:nodefaults || $x.gpxs_join|smarty:nodefaults)}

À l'X...

{if $x.section}
Section : {$x.section}
{/if} @@ -57,27 +57,27 @@ function chgMainWinLoc(strPage)
- {if $x.sexe}•{/if} - {$x.prenom} {if $x.nom_usage eq ""}{$x.nom}{else}{$x.nom_usage} ({$x.nom}){/if} + {if $user->isFemale()}•{/if} + {$user->fullName()}{if $x.nom_usage neq ""} ({$x.nom}){/if} {if $logged} {if $x.nickname} (alias {$x.nickname}){/if} {/if} {if $x.web} {icon name="world_go" title="Site Web"}{/if} {if $logged} -  {if !$x.dcd}{* +  {if !$x.dcd}{* *}{icon name=vcard title="Afficher la carte de visite"}{/if} {if !$x.is_contact} - + {icon name=add title="Ajouter à mes contacts"} {else} - + {icon name=cross title="Retirer de mes contacts"} {/if} {if hasPerm('admin')} - + {icon name=wrench title="administrer user"} {/if} - {if $x.forlife eq $smarty.session.forlife} + {if $user->login() eq $smarty.session.hruid} {icon name="user_edit" title="Modifier ma fiche"} {/if} {/if} @@ -93,20 +93,20 @@ function chgMainWinLoc(strPage) {if $logged} @@ -123,15 +123,15 @@ function chgMainWinLoc(strPage) {if $x.iso3166} {$x.nationalite}  {/if} - X {$x.promo} - {if ($x.promo_sortie-3 > $x.promo)} + X {$user->promo()} + {if $x.promo_sortie && ($x.promo_sortie-3 > $x.promo)} - X {math equation="a-b" a=$x.promo_sortie b=3} {/if} {if $x.applis_join}  - Formation : {$x.applis_join|smarty:nodefaults} {/if} {if $logged && $x.is_referent} - [Ma fiche référent] + [Ma fiche référent] {/if}
@@ -193,7 +193,7 @@ function chgMainWinLoc(strPage)
Cette fiche est publique et visible par tout internaute,
- vous pouvez aussi voir celle réservée aux X. + vous pouvez aussi voir celle réservée aux X.
{elseif $view eq 'ax'} -- 2.1.4