change _booking_ucname function to handle names like McClure
This commit is contained in:
@@ -31,13 +31,41 @@ function _booking_remove_emoji($text) {
|
|||||||
* Taken from http://php.net/manual/en/function.ucwords.php
|
* Taken from http://php.net/manual/en/function.ucwords.php
|
||||||
*/
|
*/
|
||||||
function _booking_ucname($string) {
|
function _booking_ucname($string) {
|
||||||
$string = ucwords(strtolower($string));
|
$all_uppercase = '';
|
||||||
|
$all_lowercase = 'De La|De Las|Der|Van De|Van Der|Vit De|Von|Or|And';
|
||||||
|
$prefixes = 'Mc';
|
||||||
|
$suffixes = "'S";
|
||||||
|
|
||||||
|
// captialize all first letters
|
||||||
|
$string = preg_replace('/\\b(\\w)/e', 'strtoupper("$1")', strtolower(trim($string)));
|
||||||
|
|
||||||
|
if ($all_uppercase) {
|
||||||
|
// capitalize acronymns and initialisms e.g. PHP
|
||||||
|
$string = preg_replace("/\\b($all_uppercase)\\b/e", 'strtoupper("$1")', $string);
|
||||||
|
}
|
||||||
|
if ($all_lowercase) {
|
||||||
|
// decapitalize short words e.g. and
|
||||||
|
// all occurences will be changed to lowercase
|
||||||
|
$string = preg_replace("/\\b($all_lowercase)\\b/e", 'strtolower("$1")', $string);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($prefixes) {
|
||||||
|
// capitalize letter after certain name prefixes e.g 'Mc'
|
||||||
|
$string = preg_replace("/\\b($prefixes)(\\w)/e", '"$1".strtoupper("$2")', $string);
|
||||||
|
}
|
||||||
|
if ($suffixes) {
|
||||||
|
// decapitalize certain word suffixes e.g. 's
|
||||||
|
$string = preg_replace("/(\\w)($suffixes)\\b/e", '"$1".strtolower("$2")', $string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
$string = ucwords(strtolower($string));
|
||||||
foreach (array('-', '\'') as $delimiter) {
|
foreach (array('-', '\'') as $delimiter) {
|
||||||
if (strpos($string, $delimiter) !== false) {
|
if (strpos($string, $delimiter) !== false) {
|
||||||
$string = implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
|
$string = implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,7 +7,9 @@ function booking_node_presave($node) {
|
|||||||
if($node->type == 'booking') {
|
if($node->type == 'booking') {
|
||||||
$title = t('!event registration: !name', array(
|
$title = t('!event registration: !name', array(
|
||||||
'!event' => $event->booking_eventname,
|
'!event' => $event->booking_eventname,
|
||||||
'!name' => _booking_ucname($node->booking_firstname . ' ' . $node->booking_lastname),
|
// no longer needed since applied at node creation
|
||||||
|
//'!name' => _booking_ucname($node->booking_firstname . ' ' . $node->booking_lastname),
|
||||||
|
'!name' => $node->booking_firstname . ' ' . $node->booking_lastname,
|
||||||
));
|
));
|
||||||
|
|
||||||
//strip any emojis from user input if that feature is enabled
|
//strip any emojis from user input if that feature is enabled
|
||||||
|
Reference in New Issue
Block a user