Whups::formatUser PHP Method

formatUser() public static method

Returns a user string from the user's name and email address.
public static formatUser ( string | array $user = null, boolean $showemail = true, boolean $showname = true, boolean $html = false )
$user string | array A user name or a hash as returned from {@link self::getUserAttributes()}.
$showemail boolean Whether to include the email address.
$showname boolean Whether to include the full name.
$html boolean Whether to "prettify" the result. If true, email addresses are obscured, the result is escaped for HTML output, and a group icon might be added.
    public static function formatUser($user = null, $showemail = true, $showname = true, $html = false)
    {
        if (!is_null($user) && empty($user)) {
            return '';
        }
        if (is_array($user)) {
            $details = $user;
        } else {
            $details = self::getUserAttributes($user);
        }
        if (!empty($details['name'])) {
            $name = $details['name'];
        } else {
            $name = $details['user'];
        }
        if (($showemail || empty($name) || !$showname) && !empty($details['email'])) {
            if ($html && $GLOBALS['conf']['prefs']['obfuscate_email'] && strpos($details['email'], '@') !== false) {
                $details['email'] = str_replace(array('@', '.'), array(' (at) ', ' (dot) '), $details['email']);
            }
            if (!empty($name) && $showname) {
                $addrOb = new Horde_Mail_Rfc822_Address($details['email']);
                $addrOb->personal = $name;
                $name = strval($addrOb);
            } else {
                $name = $details['email'];
            }
        }
        if ($html) {
            $name = htmlspecialchars($name);
            if ($details['type'] == 'group') {
                $name = Horde::img('group.png', !empty($details['name']) ? $details['name'] : $details['user']) . $name;
            }
        }
        return $name;
    }

Usage Example

Exemplo n.º 1
0
 public function __construct(&$vars)
 {
     global $whups_driver, $conf;
     parent::__construct($vars, _("Create Ticket - Step 4"));
     /* Preserve previously uploaded attachments. */
     $this->addHidden('', 'deferred_attachment', 'text', false);
     /* Groups. */
     $mygroups = $GLOBALS['injector']->getInstance('Horde_Group')->listAll($conf['prefs']['assign_all_groups'] ? null : $GLOBALS['registry']->getAuth());
     asort($mygroups);
     $users = $whups_driver->getQueueUsers($vars->get('queue'));
     $f_users = array();
     foreach ($users as $user) {
         $f_users['user:'******'group:' . $id] = $group;
         }
     }
     if (count($f_users)) {
         asort($f_users);
         $owners = $this->addVariable(_("Owners"), 'owners', 'multienum', false, false, null, array($f_users));
     }
     if (count($f_groups)) {
         asort($f_groups);
         $group_owners = $this->addVariable(_("Group Owners"), 'group_owners', 'multienum', false, false, null, array($f_groups));
     }
     if (!count($f_users) && !count($f_groups)) {
         $owner_params = array(_("There are no users to which this ticket can be assigned."));
         $this->addVariable(_("Owners"), 'owners', 'invalid', false, false, null, $owner_params);
     }
 }
All Usage Examples Of Whups::formatUser