From f0fe473aadd945daa4c1d463d22800c601b0f4f1 Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Wed, 29 Mar 2006 13:39:13 +0000 Subject: [PATCH] Fix missing UTF-8 encoding of date locales on Windows setups --- docs/NEWS | 3 +++ include/functions.inc.php | 27 ++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/docs/NEWS b/docs/NEWS index e359b9b..63cefb4 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,9 @@ Version 1.0 () ------------------------------------------------------------------------ + * Fix missing UTF-8 encoding of date locales on Windows setups + (garvinhicking) + * Fix imagepng() function call for PHP 5.1.0 versions (Sebastian Mordziol) diff --git a/include/functions.inc.php b/include/functions.inc.php index 72dd02b..8f729e4 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -76,6 +76,12 @@ function serendipity_serverOffsetHour($timestamp = null, $negative = false) { */ function serendipity_strftime($format, $timestamp = null, $useOffset = true) { global $serendipity; + static $is_win_utf = null; + + if ($is_win_utf === null) { + // Windows does not have UTF-8 locales. + $is_win_utf = (LANG_CHARSET == 'UTF-8' && strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? true : false); + } switch($serendipity['calendar']) { default: @@ -85,7 +91,8 @@ function serendipity_strftime($format, $timestamp = null, $useOffset = true) { } elseif ($useOffset) { $timestamp = serendipity_serverOffsetHour($timestamp); } - return strftime($format, $timestamp); + $out = strftime($format, $timestamp); + break; case 'jalali-utf8': if ($timestamp == null) { @@ -95,10 +102,16 @@ function serendipity_strftime($format, $timestamp = null, $useOffset = true) { } require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php'; - return jalali_strftime_utf($format, $timestamp); + $out = jalali_strftime_utf($format, $timestamp); + break; + } + + if ($is_win_utf) { + $out = utf8_encode($out); } -} + return $out; +} /** * A wrapper function call for formatting Timestamps. * @@ -373,7 +386,7 @@ function serendipity_sendMail($to, $subject, $message, $fromMail, $headers = NUL if (is_null($fromMail) || empty($fromMail)) { $fromMail = $to; } - + if (is_null($headers)) { $headers = array(); } @@ -413,8 +426,8 @@ function serendipity_sendMail($to, $subject, $message, $fromMail, $headers = NUL $maildata['subject'] = str_replace(array("\n", "\r"), array('', ''), mb_encode_mimeheader($maildata['subject'], LANG_CHARSET)); $maildata['fromName'] = str_replace(array("\n", "\r"), array('', ''), mb_encode_mimeheader($maildata['fromName'], LANG_CHARSET)); } - - + + // Always add these headers if (!empty($maildata['blogMail'])) { $maildata['headers'][] = 'From: "'. $maildata['fromName'] .'" <'. $maildata['blogMail'] .'>'; @@ -426,7 +439,7 @@ function serendipity_sendMail($to, $subject, $message, $fromMail, $headers = NUL $maildata['headers'][] = 'MIME-Version: 1.0'; $maildata['headers'][] = 'Precedence: bulk'; $maildata['headers'][] = 'Content-Type: text/plain; charset=' . LANG_CHARSET; - + if (LANG_CHARSET == 'UTF-8') { if (function_exists('imap_8bit')) { $maildata['headers'][] = 'Content-Transfer-Encoding: quoted-printable'; -- 2.39.5