diff options
| author | Greg Roach <fisharebest@gmail.com> | 2014-09-12 22:05:03 +0100 |
|---|---|---|
| committer | Greg Roach <fisharebest@gmail.com> | 2014-09-12 22:05:03 +0100 |
| commit | ce75549277d91441ac24704d67c699e9857ef60a (patch) | |
| tree | 6cdf052cf1622ad956cceaf33d11830997d576b4 /includes | |
| parent | 034e822620d4ab7ab21f8b3387410adb9f7f28c6 (diff) | |
| download | webtrees-ce75549277d91441ac24704d67c699e9857ef60a.tar.gz webtrees-ce75549277d91441ac24704d67c699e9857ef60a.tar.bz2 webtrees-ce75549277d91441ac24704d67c699e9857ef60a.zip | |
Use the (faster) native mb_string functions where available, and fallbacks where not.
Diffstat (limited to 'includes')
| -rw-r--r-- | includes/functions/functions_export.php | 25 | ||||
| -rw-r--r-- | includes/functions/functions_rtl.php | 34 | ||||
| -rw-r--r-- | includes/session.php | 9 |
3 files changed, 37 insertions, 31 deletions
diff --git a/includes/functions/functions_export.php b/includes/functions/functions_export.php index 29fd732ae8..5cab08305f 100644 --- a/includes/functions/functions_export.php +++ b/includes/functions/functions_export.php @@ -38,10 +38,9 @@ function reformat_record_export($rec) { // Split long lines // The total length of a GEDCOM line, including level number, cross-reference number, // tag, value, delimiters, and terminator, must not exceed 255 (wide) characters. - // Use quick strlen() check before using slower WT_I18N::strlen() check - if (strlen($line)>WT_GEDCOM_LINE_LENGTH && WT_I18N::strlen($line)>WT_GEDCOM_LINE_LENGTH) { + if (mb_strlen($line) > WT_GEDCOM_LINE_LENGTH) { list($level, $tag)=explode(' ', $line, 3); - if ($tag!='CONT' && $tag!='CONC') { + if ($tag != 'CONT' && $tag != 'CONC') { $level++; } do { @@ -49,31 +48,31 @@ function reformat_record_export($rec) { $pos=WT_GEDCOM_LINE_LENGTH; if ($WORD_WRAPPED_NOTES) { // Split on a space, and remove it (for compatibility with some desktop apps) - while ($pos && WT_I18N::substr($line, $pos-1, 1)!=' ') { + while ($pos && mb_substr($line, $pos-1, 1)!=' ') { --$pos; } - if ($pos==strpos($line, ' ', 3)+1) { + if ($pos == strpos($line, ' ', 3) + 1) { // No spaces in the data! Can’t split it :-( break; } else { - $newrec.=WT_I18N::substr($line, 0, $pos-1).WT_EOL; - $line=$level.' CONC '.WT_I18N::substr($line, $pos); + $newrec .= mb_substr($line, 0, $pos - 1).WT_EOL; + $line=$level.' CONC ' . mb_substr($line, $pos); } } else { // Split on a non-space (standard gedcom behaviour) - while ($pos && WT_I18N::substr($line, $pos-1, 1)==' ') { + while ($pos && mb_substr($line, $pos-1, 1) == ' ') { --$pos; } - if ($pos==strpos($line, ' ', 3)) { + if ($pos == strpos($line, ' ', 3)) { // No non-spaces in the data! Can’t split it :-( break; } - $newrec.=WT_I18N::substr($line, 0, $pos).WT_EOL; - $line=$level.' CONC '.WT_I18N::substr($line, $pos); + $newrec .= mb_substr($line, 0, $pos) . WT_EOL; + $line = $level . ' CONC ' . mb_substr($line, $pos); } - } while (WT_I18N::strlen($line)>WT_GEDCOM_LINE_LENGTH); + } while (mb_strlen($line) > WT_GEDCOM_LINE_LENGTH); } - $newrec.=$line.WT_EOL; + $newrec .= $line . WT_EOL; } return $newrec; } diff --git a/includes/functions/functions_rtl.php b/includes/functions/functions_rtl.php index 0a7a249a96..019a0308b9 100644 --- a/includes/functions/functions_rtl.php +++ b/includes/functions/functions_rtl.php @@ -1038,29 +1038,29 @@ function finishCurrentSpan(&$result, $theEnd=false) { function utf8_wordwrap($string, $width=75, $sep="\n", $cut=false) { $out=''; while ($string) { - if (WT_I18N::strlen($string) <= $width){ //Do not wrap any text that is less than the output area. - $out.=$string; - $string=''; + if (mb_strlen($string) <= $width){ //Do not wrap any text that is less than the output area. + $out .= $string; + $string = ''; } else { - $sub1=WT_I18N::substr($string, 0, $width+1); - if (WT_I18N::substr($string,WT_I18N::strlen($sub1)-1,1)==' ') //include words that end by a space immediately after the area. - $sub=$sub1; + $sub1 = mb_substr($string, 0, $width+1); + if (mb_substr($string, mb_strlen($sub1)-1, 1) == ' ') //include words that end by a space immediately after the area. + $sub = $sub1; else - $sub=WT_I18N::substr($string, 0, $width); - $spacepos=strrpos($sub, ' '); - if ($spacepos==false) { + $sub = mb_substr($string, 0, $width); + $spacepos = strrpos($sub, ' '); + if ($spacepos == false) { // No space on line? if ($cut) { - $out.=$sub.$sep; - $string=WT_I18N::substr($string, WT_I18N::strlen($sub)); + $out .= $sub . $sep; + $string = mb_substr($string, mb_strlen($sub)); } else { - $spacepos=strpos($string, ' '); - if ($spacepos==false) { - $out.=$string; - $string=''; + $spacepos = strpos($string, ' '); + if ($spacepos == false) { + $out .= $string; + $string = ''; } else { - $out.=substr($string, 0, $spacepos).$sep; - $string=substr($string, $spacepos+1); + $out .= substr($string, 0, $spacepos).$sep; + $string = substr($string, $spacepos + 1); } } } else { diff --git a/includes/session.php b/includes/session.php index 0cf4fd2180..cf5242a6c9 100644 --- a/includes/session.php +++ b/includes/session.php @@ -185,6 +185,14 @@ if (!ini_get('date.timezone')) { date_default_timezone_set(@date_default_timezone_get()); } +// Use the patchwork/utf8 library to: +// set all PHP defaults to UTF-8 +// create shims for missing mb_string functions such as mb_strlen() +// check that requests are valid UTF-8 +\Patchwork\Utf8\Bootup::initAll(); // Enables the portablity layer and configures PHP for UTF-8 +\Patchwork\Utf8\Bootup::filterRequestUri(); // Redirects to an UTF-8 encoded URL if it's not already the case +\Patchwork\Utf8\Bootup::filterRequestInputs(); // Normalizes HTTP inputs to UTF-8 NFC + // Split the request protocol://host:port/path/to/script.php?var=value into parts // WT_SERVER_NAME = protocol://host:port // WT_SCRIPT_PATH = /path/to/ (begins and ends with /) @@ -227,7 +235,6 @@ if (!isset($_SERVER['HTTP_USER_AGENT'])) { // Common functions require WT_ROOT.'includes/functions/functions.php'; require WT_ROOT.'includes/functions/functions_db.php'; -// TODO: Not all pages require all of these. Only load them in scripts that need them? require WT_ROOT.'includes/functions/functions_print.php'; require WT_ROOT.'includes/functions/functions_mediadb.php'; require WT_ROOT.'includes/functions/functions_date.php'; |
