Fix profile/{alias} (that is required for backward compatibility).
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 11 Oct 2010 13:10:47 +0000 (15:10 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 11 Oct 2010 13:10:47 +0000 (15:10 +0200)
BTW, this also fix the links for profile/{alias}@polytechnique.org

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/user.php
modules/profile.php

index 4d4a28a..854c848 100644 (file)
@@ -327,11 +327,11 @@ class User extends PlUser
 
     /** Return the main profile attached with this account if any.
      */
-    public function profile($forceFetch = false)
+    public function profile($forceFetch = false, $fields = 0x0000, $visibility = null)
     {
         if (!$this->_profile_fetched || $forceFetch) {
             $this->_profile_fetched = true;
-            $this->_profile = Profile::get($this);
+            $this->_profile = Profile::get($this, $fields, $visibility);
         }
         return $this->_profile;
     }
index b737ac6..e3239d2 100644 (file)
@@ -232,17 +232,6 @@ class ProfileModule extends PLModule
         if (is_null($id)) {
             return PL_NOT_FOUND;
         }
-        $pid = (!is_numeric($id) || S::admin()) ? Profile::getPID($id) : null;
-        if (is_null($pid)) {
-            if (S::logged()) {
-                $page->trigError($id . " inconnu dans l'annuaire.");
-            }
-            return PL_NOT_FOUND;
-        }
-
-        // Now that we know this is an existing profile, we can switch to the
-        // appropriate template.
-        $page->changeTpl('profile/profile.tpl', SIMPLE);
 
         // Determines the access level at which the profile will be displayed.
         if (!S::logged() || !S::user()->checkPerms('directory_ax') || Env::v('view') == 'public') {
@@ -258,10 +247,30 @@ class ProfileModule extends PLModule
             $page->assign('with_pending_pic', true);
         }
 
-        // Fetches profile's and profile's owner information and redirects to
-        // marketing if the owner has not subscribed and the requirer has logged in.
-        $profile = Profile::get($pid, Profile::FETCH_ALL, $view);
-        $owner = $profile->owner();
+        $pid = (!is_numeric($id) || S::admin()) ? Profile::getPID($id) : null;
+        if (is_null($pid)) {
+            $owner = User::getSilent($id);
+            if ($owner) {
+                $profile = $owner->profile(true, Profile::FETCH_ALL, $view);
+                if ($profile) {
+                    $pid = $profile->id();
+                }
+            }
+        } else {
+            // Fetches profile's and profile's owner information and redirects to
+            // marketing if the owner has not subscribed and the requirer has logged in.
+            $profile = Profile::get($pid, Profile::FETCH_ALL, $view);
+            $owner = $profile->owner();
+        }
+        if (is_null($pid)) {
+            if (S::logged()) {
+                $page->kill($id . " inconnu dans l'annuaire.");
+            }
+            return PL_NOT_FOUND;
+        }
+        // Now that we know this is an existing profile, we can switch to the
+        // appropriate template.
+        $page->changeTpl('profile/profile.tpl', SIMPLE);
 
         // Profile view are logged.
         if (S::logged()) {