Merge remote branch 'origin/platal-1.0.0' into platal-1.0.1
[platal.git] / plugins / function.profile.php
index 8d34076..3a05b61 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2009 Polytechnique.org                              *
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
 
 function smarty_function_profile($params, &$smarty)
 {
-    $with_promo = isset($params['with_promo']) ? $params['with_promo'] : false;
-    $with_sex   = isset($params['with_sex']) ? $params['with_sex'] : true;
-    $with_link  = isset($params['with_link']) ? $params['with_link'] : true;
-    $user = $params['user'];
+    $params = new PlDict($params);
+    $with_promo = $params->b('promo', false) || $params->b('cat', false);
+    $with_sex   = $params->b('sex', true);
+    $with_link  = $params->b('link', true);
+    $with_dir   = $params->b('directory', true);
+    $with_groupperms = $params->b('groupperms', true);
+    $user = $params->v('user');
+    if (is_int($user) || ctype_digit($user)) {
+        $user = User::getWithUID($user);
+    }
 
-    $name = pl_entities($user->fullName());
+    if ($with_dir) {
+        $name = pl_entities($user->directoryName());
+    } else {
+        $name = pl_entities($user->fullName());
+    }
     if ($with_sex && $user->isFemale()) {
-      $name = '&bull;' . $name;
+        $name = '&bull;' . $name;
     }
     if ($with_promo) {
-      $promo = $user->promo();
-      if ($promo) {
-        $name .= ' (' . pl_entities($promo) . ')';
-      }
+        $promo = $user->category();
+        if ($promo) {
+            $name .= ' (' . pl_entities($promo) . ')';
+        }
     }
     if ($with_link) {
-      $profile = ($user instanceof Profile) ? $user : $user->profile();
-      if ($profile) {
-        $name = '<a href="profile/' . $profile->hrid() . '" class="popup2">' . $name . '</a>';
-      }
+        $profile = ($user instanceof Profile) ? $user : $user->profile();
+        if ($profile) {
+            $name = '<a href="profile/' . $profile->hrid() . '" class="popup2">' . $name . '</a>';
+        }
+    }
+    if ($user->lost) {
+        $name .= ' <a href="https://www.polytechnique.org/marketing/broken/' . $user->hruid . '"><img src="images/icons/error.gif" alt="Patte cassée" /></a>';
+    }
+    if ($with_groupperms && $user instanceof User && $user->group_perms == 'admin' && !empty($name)) {
+        $name = '<strong>' . $name . '</strong>';
     }
     return $name;
 }