Commit eb681ca6 authored by nkoth's avatar nkoth

[NEW] Obscure email when using email as username if possible (coverage will...

[NEW] Obscure email when using email as username if possible (coverage will not be complete) and Show user's real name instead of login in autocomplete selector (only messages and trackers feature so far)
parent 6ca26281
......@@ -910,6 +910,9 @@ $.fn.tiki = function(func, type, options) {
case "username":
data = "tiki-ajax_services.php?listonly=users";
break;
case "userrealname":
data = "tiki-ajax_services.php?listonly=userrealnames";
break;
case "tag":
data = "tiki-ajax_services.php?listonly=tags&separator=+";
break;
......
......@@ -22,6 +22,7 @@ function sendForumEmailNotification($event, $object, $forum_info, $title, $data,
// Per-forum From address overrides global default.
if( $forum_info['outbound_from'] )
{
$author = $userlib->clean_user($author);
$my_sender = '"' . "$author" . '" <' . $forum_info['outbound_from'] . '>';
} else {
$my_sender = $prefs['sender_email'];
......
......@@ -12,6 +12,14 @@ function prefs_login_list() {
'description' => tra('Instead of creating new usernames, use the user\'s email address for authentication.'),
'type' => 'flag',
),
'login_is_email_obscure' => array(
'name' => tra('Obscure email when using email as username if possible (coverage will not be complete)'),
'description' => tra('This will attempt as much as possible to hide the email, showing the realname or the truncated email instead.'),
'type' => 'flag',
'dependencies' => array(
'login_is_email',
),
),
);
}
......@@ -142,7 +142,19 @@ function prefs_user_list() {
'type' => 'text',
'size' => '5',
'dependencies' => array('feature_jquery_autocomplete'),
)
),
'user_selector_realnames_tracker' => array(
'name' => tra('Show user\'s real name instead of login in autocomplete selector in trackers feature'),
'description' => tra('Use user\'s real name instead of login in autocomplete selector in trackers feature'),
'type' => 'flag',
'dependencies' => array('feature_jquery_autocomplete', 'user_show_realnames', 'feature_trackers'),
),
'user_selector_realnames_messu' => array(
'name' => tra('Show user\'s real name instead of login in autocomplete selector in messaging feature'),
'description' => tra('Use user\'s real name instead of login in autocomplete selector in messaging feature'),
'type' => 'flag',
'dependencies' => array('feature_jquery_autocomplete', 'user_show_realnames', 'feature_messages'),
),
);
}
......
......@@ -79,7 +79,7 @@ class reportsLib extends TikiLib
}
public function makeHtmlEmailBody($report_cache, $report_preferences, $tikiUrl) {
global $tikilib;
global $tikilib, $userlib;
$change_array = $this->makeChangeArray($report_cache);
$somethingHasHappened = false;
......@@ -112,6 +112,8 @@ class reportsLib extends TikiLib
}
$body .= $this->makeTime(strtotime($change['time'])).": ";
$change['data']['user'] = $userlib->clean_user($change['data']['user']);
if ($change['event']=='image_gallery_changed' && empty($change['data']['action'])) {
$body .= $change['data']['user']." ".tra("changed the picture gallery")." <a href=\"$tikiUrl/tiki-browse_gallery.php?galleryId=".$change['data']['galleryId']."&offset=0&sort_mode=created_desc\">".$change['data']['galleryName']."</a>.";
} elseif ($change['event']=='image_gallery_changed' && $change['data']['action']=="upload image") {
......
......@@ -725,6 +725,8 @@ function get_default_prefs() {
// user
'user_selector_threshold' => 50,
'user_selector_realnames_tracker' => 'n',
'user_selector_realnames_messu' => 'n',
'feature_userlevels' => 'n',
'userlevels' => function_exists('tra') ? array('1'=>tra('Simple'),'2'=>tra('Advanced')) : array('1'=>'Simple','2'=>'Advanced'),
'userbreadCrumb' => 4,
......@@ -775,6 +777,7 @@ function get_default_prefs() {
'change_language' => 'y',
'change_theme' => 'n',
'login_is_email' => 'n',
'login_is_email_obscure' => 'n',
'validateUsers' => 'y',
'validateEmail' => 'n',
'forgotPass' => 'y',
......
......@@ -68,10 +68,8 @@ function smarty_modifier_userlink($other_user,$class='link',$idletime='not_set',
if ( $fullname != '' ) {
$ou = $fullname;
} elseif ( $prefs['user_show_realnames'] == 'y' ) {
$user_details = $userlib->get_user_details($other_user);
$ou = $user_details['info']['realName'];
unset($user_details);
} else {
$ou = $userlib->clean_user($other_user);
}
if ( empty($ou) || $ou == '' ) {
$ou = $other_user;
......
......@@ -14,13 +14,8 @@ if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
function smarty_modifier_username($user, $login_fallback = true, $check_user_show_realnames = true, $html_encoding = true) {
global $userlib, $prefs;
if ( $prefs['user_show_realnames'] == 'y' || ! $check_user_show_realnames ) {
$details = $userlib->get_user_details($user);
$return = $details['info']['realName'];
unset($details);
if ( $return == '' ) $return = $login_fallback ? $user : tra('Anonymous');
} else $return = $user;
$return = $userlib->clean_user($user, $check_user_show_realnames, $login_fallback);
if ($html_encoding) $return = htmlspecialchars($return);
return $return;
}
......@@ -1311,6 +1311,12 @@ class TrackerLib extends TikiLib
}
}
}
if ($prefs['user_selector_realnames_tracker'] == 'y' && $ins_fields['data'][$i]['type'] == 'u') {
if (!$userlib->user_exists($ins_fields['data'][$i]['value'])) {
$finalusers = $userlib->find_best_user(array($ins_fields['data'][$i]['value']), '' , 'login');
$ins_fields['data'][$i]['value'] = $finalusers[0];
}
}
if ($ins_fields['data'][$i]['type'] == 'G' && isset($ins_fields['data'][$i]['options_array'][0]) && $ins_fields['data'][$i]['options_array'][0] == 'y') {
// Set geo attributes if google map field is set as item
global $attributelib;
......
......@@ -1217,6 +1217,49 @@ class UsersLib extends TikiLib
return $status;
}
function get_users_light($offset = 0, $maxRecords = -1, $sort_mode = 'login_asc', $find = '', $group = '') {
// This is a lighter version of get_users_names designed for ajax checking of userrealnames
global $prefs;
$mid = '';
$bindvars = array();
if(!empty($group)) {
if (!is_array($group)) {
$group = array($group);
}
$mid = ', `users_usergroups` uug where uu.`userId`=uug.`userId` and uug.`groupName` in ('.implode(',',array_fill(0, count($group),'?')).')';
$bindvars = $group;
}
if ($find) {
$findesc = '%' . $find . '%';
if (empty($mid)) {
$mid .= " where uu.`login` like ?";
} else {
$mid .= " and uu.`login` like ?";
}
$bindvars[] = array($findesc);
}
$query = "select uu.`login` from `users_users` uu $mid order by ".$this->convertSortMode($sort_mode);
$result = $this->fetchAll($query,$bindvars,$maxRecords,$offset);
$ret = array();
foreach ($result as $res) {
$ret[$res['login']] = $this->clean_user($res["login"]);
}
if (!empty($finddesc) && $prefs['user_show_realnames'] == 'y') {
$query = "select `user` from `tiki_user_preferences` where `prefName` = 'realName' and `value` like ?";
$result = $this->fetchAll($query,array($findesc),$maxRecords,$offset);
foreach ($result as $res) {
if (!isset($ret[$res['user']])) {
$ret[$res['user']] = $this->clean_user($res['user']);
}
}
}
asort($ret);
return($ret);
}
function get_users_names($offset = 0, $maxRecords = -1, $sort_mode = 'login_asc', $find = '') {
// This function gets an array of user login names.
......@@ -3341,6 +3384,43 @@ class UsersLib extends TikiLib
return $this->getOne($query, array());
}
}
function find_best_user($usrs, $group = '', $key = 'login') {
$finalusers = array();
foreach ($usrs as $u) {
$u = trim($u);
if ($u == 'admin') {
$finalusers[] = $u;
} elseif ($key == 'userId' && preg_match('/\(([0-9]+)\)$/', $u, $matches)) {
$finalusers[] = $this->get_user_login($matches[1]);
} elseif ($key == 'login' && preg_match('/\((.+)\)$/', $u, $matches)) {
$finalusers[] = $matches[1];
} else {
$possibleusers = $this->get_users_light(0, -1, 'login_asc', '', $group);
$unames = array_keys($possibleusers, $u);
if (count($unames) == 1 && $unames[0]) {
$finalusers[] = $unames[0];
}
}
}
return $finalusers;
}
function clean_user($u, $force_check_realnames = false, $login_fallback = true) {
global $tikilib, $prefs;
if ( $prefs['user_show_realnames'] == 'y' || $force_check_realnames) {
$realname = $tikilib->get_user_preference($u, 'realName', '');
}
if (!empty($realname)) {
$u = trim($realname); // need to trim to prevent mustMatch failure
} elseif ($prefs['login_is_email_obscure'] == 'y' && $atsign = strpos($u, '@')) {
$u = substr($u, 0, $atsign);
if (!$login_fallback) {
$u = tra('Anonymous');
}
}
return $u;
}
}
......
......@@ -64,6 +64,12 @@ if (isset($_REQUEST['send'])) {
$arr_to = preg_split('/\s*(?<!\\\);\s*/', $_REQUEST['to']);
$arr_cc = preg_split('/\s*(?<!\\\);\s*/', $_REQUEST['cc']);
$arr_bcc = preg_split('/\s*(?<!\\\);\s*/', $_REQUEST['bcc']);
if ($prefs['user_selector_realnames_messu'] == 'y') {
$groups = '';
$arr_to = $userlib->find_best_user($arr_to, $groups, 'login');
$arr_cc = $userlib->find_best_user($arr_cc, $groups);
$arr_bcc = $userlib->find_best_user($arr_bcc, $groups);
}
// Remove invalid users from the to, cc and bcc fields
$users = array();
foreach($arr_to as $a_user) {
......
......@@ -24,7 +24,11 @@
{/if}
{if (!$sent) or ((strstr($message, "{tr}ERROR{/tr}")) or (strstr($message, "{tr}Invalid{/tr}")))}
{if $prefs.user_selector_realnames_messu == 'y'}
{jq}$(".username").tiki("autocomplete", "userrealname", {multiple: true, multipleSeparator: ";"});{/jq}
{else}
{jq}$(".username").tiki("autocomplete", "username", {multiple: true, multipleSeparator: ";"});{/jq}
{/if}
<form action="messu-compose.php" method="post">
<table class="formcolor" >
<tr>
......
......@@ -103,6 +103,7 @@
<fieldset>
<legend>{tr}Username{/tr}</legend>
{preference name=login_is_email mode=invert}
{preference name=login_is_email_obscure}
<div class="adminoptionboxchild" id="login_is_email_childcontainer">
{preference name=min_username_length}
{preference name=max_username_length}
......
......@@ -15,6 +15,7 @@
{preference name=messu_mailbox_size}
{preference name=messu_archive_size}
{preference name=messu_sent_size}
{preference name=user_selector_realnames_messu}
</fieldset>
<div class="heading input_submit_container" style="text-align: center">
......
......@@ -3,6 +3,7 @@
<fieldset class="admin">
<form action="tiki-admin.php?page=trackers" method="post">
{preference name=user_selector_threshold}
{preference name=user_selector_realnames_tracker}
<div class="heading input_submit_container" style="text-align: right">
<input type="submit" name="trkset" value="{tr}Change preferences{/tr}" />
</div>
......
......@@ -291,9 +291,16 @@ title="{tr}Delete{/tr}">{icon _id='cross' alt="{tr}Delete{/tr}"}</a>&nbsp;&nbsp;
{if $prefs.javascript_enabled eq 'y' and $prefs.feature_jquery_autocomplete eq 'y' and $users|@count > $prefs.user_selector_threshold and $cur_field.isMandatory ne 'y'}
{* this is jquery entry field for performance enhancement - since it allows blank entry it can't be used for mandatory user selection. *}
<input id="user_selector_{$cur_field.id}" type="text" size="20" name="ins_{$cur_field.id}" value="{if $cur_field.options_array[0] eq '2'}{$user}{else}{$cur_field.value}{/if}" />
{if $prefs.user_selector_realnames_tracker == 'y'}
{jq}
$("#user_selector_{{$cur_field.id}}").tiki("autocomplete", "userrealname", {mustMatch: true});
{/jq}
{else}
{jq}
$("#user_selector_{{$cur_field.id}}").tiki("autocomplete", "username", {mustMatch: true});
{/jq}
{/if}
{else}
......
......@@ -34,9 +34,15 @@
{if $prefs.javascript_enabled eq 'y' and $prefs.feature_jquery_autocomplete eq 'y' and $field_value.list|@count > $prefs.user_selector_threshold and $field_value.isMandatory ne 'y'}
{* since autocomplete allows blank entry it can't be used for mandatory selection. *}
<input id="user_selector_{$field_value.fieldId}" type="text" size="20" name="{$field_value.ins_id}" value="{if $field_value.options_array[0] eq '2'}{$user}{else}{$field_value.value}{/if}" />
{if $prefs.user_selector_realnames_tracker == 'y'}
{jq}
$("#user_selector_{{$field_value.fieldId}}").tiki("autocomplete", "userrealname", {mustMatch: true});
{/jq}
{else}
{jq}
$("#user_selector_{{$field_value.fieldId}}").tiki("autocomplete", "username", {mustMatch: true});
{/jq}
{/if}
{else}
<select name="{$field_value.ins_id}" {if $field_value.http_request}onchange="selectValues('trackerIdList={$field_value.http_request[0]}&amp;fieldlist={$field_value.http_request[3]}&amp;filterfield={$field_value.http_request[1]}&amp;status={$field_value.http_request[4]}&amp;mandatory={$field_value.http_request[6]}&amp;filtervalue='+escape(this.value),'{$listfields.$fid.http_request[5]}')"{/if}>
{if $field_value.isMandatory ne 'y'}
......
......@@ -48,6 +48,38 @@ if ($access->is_serializable_request() && isset($_REQUEST['listonly'])) {
}
}
$access->output_serialized($usrs);
} elseif ($_REQUEST['listonly'] == 'userrealnames') {
$groups = '';
$listusers = $userlib->get_users_light(0, -1, 'login_asc', '', $groups);
$done = array();
$finalusers = array();
foreach($listusers as $usrId => $usr) {
if (isset($_REQUEST['q'])) {
$longusr = $usr . ' (' . $usrId . ')';
if (array_key_exists($usr, $done)) {
// disambiguate duplicates
if (stripos($longusr, $_REQUEST['q']) !== false) {
$oldkey = array_search($usr, $finalusers);
if ($oldkey !== false) {
$finalusers[$oldkey] = $done[$usr];
}
}
if (stripos($longusr, $_REQUEST['q']) !== false) {
$finalusers[] = $longusr;
}
} else {
if (stripos($longusr, $_REQUEST['q']) !== false) {
$finalusers[] = $usr;
}
}
$done[$usr] = $longusr;
}
}
// TODO also - proper perms checking
// tricker for users? Check the group they're in, then tiki_p_group_view_members
$access->output_serialized($finalusers);
} elseif( $_REQUEST['listonly'] == 'tags' ) {
global $freetaglib; require_once 'lib/freetag/freetaglib.php';
......
......@@ -66,7 +66,7 @@ if ($user) {
$sent = $messulib->post_message($userwatch, $user, $_REQUEST['to'], '', $_REQUEST['subject'], $_REQUEST['body'], $_REQUEST['priority'], '',
isset($_REQUEST['replytome']) ? 'y' : '', isset($_REQUEST['bccme']) ? 'y' : '');
if ($sent) {
$message = tra('Message sent to') . ':' . $userwatch . '<br />';
$message = tra('Message sent to') . ':' . $userlib->clean_user($userwatch) . '<br />';
} else {
$message = tra('An error occurred, please check your mail settings and try again');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment