From: Pascal Corpet Date: Sun, 6 Jun 2010 18:18:16 +0000 (+0200) Subject: Allow name modifications without validation when only changing case or accents. Close... X-Git-Tag: xorg/1.0.0~168 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=ac40839f3df01fbb1544818b0f42138a91a7fa2d;p=platal.git Allow name modifications without validation when only changing case or accents. Closes #1082 --- diff --git a/include/name.func.inc.php b/include/name.func.inc.php index 7b761da..b728d19 100644 --- a/include/name.func.inc.php +++ b/include/name.func.inc.php @@ -220,6 +220,25 @@ function build_sn_pub($pid) return $sn_old; } +/** Transform a name to its canonical value so it can be compared + * to another form (different case, with accents or with - instead + * of blanks). + * @see compare_basename to compare + */ +function name_to_basename($value) { + $value = mb_strtoupper(replace_accent($value)); + return preg_replace('/[^A-Z]/', ' ', $value); +} + +/** Compares two strings and check if they are two forms of the + * same name (different case, with accents or with - instead of + * blanks). + * @see name_to_basename to retreive the compared string + */ +function compare_basename($a, $b) { + return name_to_basename($a) == name_to_basename($b); +} + function set_alias_names(&$sn_new, $sn_old, $pid, $uid, $update_new = false, $new_alias = null) { $has_new = false; @@ -232,7 +251,7 @@ function set_alias_names(&$sn_new, $sn_old, $pid, $uid, $update_new = false, $ne $sn['particle'], $sn['name'], $typeid, $sn_old[$typeid]['id'], $pid); unset($sn_old[$typeid]); } elseif ($update_new - || (isset($sn_old[$typeid]) && $sn_old[$typeid]['fullname'] == $sn['fullname'])) { + || (isset($sn_old[$typeid]) && compare_basename($sn_old[$typeid]['fullname'], $sn['fullname']))) { XDB::execute("INSERT INTO profile_name (particle, name, typeid, pid) VALUES ({?}, {?}, {?}, {?})", $sn['particle'], $sn['name'], $typeid, $pid); diff --git a/modules/profile/general.inc.php b/modules/profile/general.inc.php index 6967a38..470d7ec 100644 --- a/modules/profile/general.inc.php +++ b/modules/profile/general.inc.php @@ -19,6 +19,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ +require_once 'name.func.inc.php'; + class ProfileSettingSearchNames implements ProfileSetting { private $private_name_end; @@ -38,8 +40,7 @@ class ProfileSettingSearchNames implements ProfileSetting private function prepareField($value) { - $value = mb_strtoupper(replace_accent($value)); - return preg_replace('/[^A-Z]/', ' ', $value); + return name_to_basename($value); } private function prepare(ProfilePage &$page, $field, $value, $init, &$success)