From c2158bebcc570b4f1a573122a546310268434e9e Mon Sep 17 00:00:00 2001 From: filip Date: Fri, 1 May 2015 12:56:14 +0200 Subject: added fallback for invalid date format localisation --- lib/news.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/news.php b/lib/news.php index 906f12f55..90effbb22 100644 --- a/lib/news.php +++ b/lib/news.php @@ -36,7 +36,14 @@ function news_date($dt, $locale = 'en') $eng_months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); $localised_months = array(_r('Jan'), _r('Feb'), _r('Mar'), _r('Apr'), _r('May'), _r('Jun'), _r('Jul'), _r('Aug'), _r('Sep'), _r('Oct'), _r('Nov'), _r('Dec')); - return str_replace($eng_months, $localised_months, date(_r('M d Y'), strtotime($dt))); + $date_format = _r('M d Y'); + if ((strpbrk($date_format, 'dj') == false) // check valid day formats + || (strpbrk($date_format, 'M') == false) // check valid month formats (all are 'FmMn' but we replace them in 3 letter form) + || (strpbrk($date_format, 'oYy') == false)) // check valid year formats + { + $date_format = 'M d Y'; // fallback for invalid date format localisation + } + return str_replace($eng_months, $localised_months, date($date_format, strtotime($dt))); } /** -- cgit v1.2.1