/** * Handle initials. * * Taken from OSBib * * @see formatNames() * * @author Mark Grimshaw * @version 1 * * @param $creator Associative array of creator name e.g. * <pre> * array(['surname'] => 'Grimshaw', ['firstname'] => Mark, ['initials'] => 'M N G', ['prefix'] => )) * </pre> * Initials must be space-delimited. * * @param $initialsStyle * @param $firstNameInitial * @return Formatted string of initials. */ function checkInitials(&$creator, $initialsStyle, $firstNameInitial) { /** * Format firstname */ if ($creator['firstname'] && !$firstNameInitial) { // Full name $firstName = stripslashes($creator['firstname']); } else { if ($creator['firstname']) { $fn = split(" ", stripslashes($creator['firstname'])); $firstTime = TRUE; foreach ($fn as $name) { if ($firstTime) { $firstNameInitialMake = UTF8::utf8_strtoupper(UTF8::utf8_substr(trim($name), 0, 1)); $firstTime = FALSE; } else { $initials[] = UTF8::utf8_strtoupper(UTF8::utf8_substr(trim($name), 0, 1)); } } if (isset($initials)) { if ($creator['initials']) { $creator['initials'] = join(" ", $initials) . ' ' . $creator['initials']; } else { $creator['initials'] = join(" ", $initials); } } } } /** * Initials are stored as space-delimited characters. * If no initials, return just the firstname or its initial in the correct format. */ if (!$creator['initials']) { if (isset($firstName)) { // full first name only return $firstName; } if (isset($firstNameInitialMake) && $initialsStyle > 1) { // First name initial with no '.' return $firstNameInitialMake; } if (isset($firstNameInitialMake)) { // First name initial with '.' return $firstNameInitialMake . '.'; } return ''; // nothing here } $initialsArray = explode(' ', $creator['initials']); /** * If firstname is initial only, prepend to array */ if (isset($firstNameInitialMake)) { array_unshift($initialsArray, $firstNameInitialMake); } if ($initialsStyle == 0) { // 'T. U. ' $initials = implode('. ', $initialsArray) . '.'; } else { if ($initialsStyle == 1) { // 'T.U.' $initials = implode('.', $initialsArray) . '.'; } else { if ($initialsStyle == 2) { // 'T U ' $initials = implode(' ', $initialsArray); } else { // 'TU ' $initials = implode('', $initialsArray); } } } /** * If we have a full first name, prepend it to $initials. */ if (isset($firstName)) { return $firstName . ' ' . $initials; } return $initials; }
/** * This is a unicode aware replacement for ucfirst() * * @author Andrea Rossato <*****@*****.**> * @see ucfirst() */ static function utf8_ucfirst($str) { $fc = UTF8::utf8_substr($str, 0, 1); return UTF8::utf8_strtoupper($fc) . UTF8::utf8_substr($str, 1, UTF8::utf8_strlen($str)); }