Aleksander Machniak
2012-11-26 789e5988aaebb78d368b137b98169ec1e616159c
Clarify rcube::get_user_name() usage, add rcube::get_user_email()
6 files modified
37 ■■■■ changed files
plugins/password/password.php 2 ●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube.php 16 ●●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_ldap.php 2 ●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_user.php 7 ●●●● patch | view | raw | blame | history
program/steps/settings/edit_identity.inc 5 ●●●●● patch | view | raw | blame | history
program/steps/settings/save_identity.inc 5 ●●●●● patch | view | raw | blame | history
plugins/password/password.php
@@ -164,7 +164,7 @@
                // Log password change
                if ($rcmail->config->get('password_log')) {
                    write_log('password', sprintf('Password changed for user %s (ID: %d) from %s',
                        $rcmail->user->get_username(), $rcmail->user->ID, rcmail_remote_ip()));
                        $rcmail->get_user_name(), $rcmail->user->ID, rcmail_remote_ip()));
                }
            }
            else {
program/lib/Roundcube/rcube.php
@@ -1203,8 +1203,22 @@
        if (is_object($this->user)) {
            return $this->user->get_username();
        }
        else if (isset($_SESSION['username'])) {
            return $_SESSION['username'];
        }
    }
        return null;
    /**
     * Getter for logged user email (derived from user name not identity).
     *
     * @return string User email address
     */
    public function get_user_email()
    {
        if (is_object($this->user)) {
            return $this->user->get_username('mail');
        }
    }
}
program/lib/Roundcube/rcube_ldap.php
@@ -273,7 +273,7 @@
            }
            // Get the pieces needed for variable replacement.
            if ($fu = $rcube->get_user_name())
            if ($fu = $rcube->get_user_email())
                list($u, $d) = explode('@', $fu);
            else
                $d = $this->mail_domain;
program/lib/Roundcube/rcube_user.php
@@ -86,12 +86,17 @@
    /**
     * Build a user name string (as e-mail address)
     *
     * @param  string $part Username part (empty or 'local' or 'domain')
     * @param  string $part Username part (empty or 'local' or 'domain', 'mail')
     * @return string Full user name or its part
     */
    function get_username($part = null)
    {
        if ($this->data['username']) {
            // return real name
            if (!$part) {
                return $this->data['username'];
            }
            list($local, $domain) = explode('@', $this->data['username']);
            // at least we should always have the local part
program/steps/settings/edit_identity.inc
@@ -42,8 +42,9 @@
    rcmail_overwrite_action('identities');
    return;
  }
  else if (IDENTITIES_LEVEL == 1)
    $IDENTITY_RECORD['email'] = $RCMAIL->user->get_username();
  else if (IDENTITIES_LEVEL == 1) {
    $IDENTITY_RECORD['email'] = $RCMAIL->get_user_email();
  }
}
program/steps/settings/save_identity.inc
@@ -107,8 +107,9 @@
// insert a new identity record
else if (IDENTITIES_LEVEL < 2)
{
  if (IDENTITIES_LEVEL == 1)
    $save_data['email'] = $RCMAIL->user->get_username();
  if (IDENTITIES_LEVEL == 1) {
    $save_data['email'] = $RCMAIL->get_user_email();
  }
  $plugin = $RCMAIL->plugins->exec_hook('identity_create', array('record' => $save_data));
  $save_data = $plugin['record'];