summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLester Caine <lester@lsces.co.uk>2026-06-06 22:17:49 +0100
committerLester Caine <lester@lsces.co.uk>2026-06-06 22:17:49 +0100
commit169833bfaf4d3d325273c9f993c63b31a909677f (patch)
treea405a55a08449c73e9113d51292fad473a833add
parent0ea8300d978a66500568c3655552c3c176e1bd52 (diff)
downloadthemes-169833bfaf4d3d325273c9f993c63b31a909677f.tar.gz
themes-169833bfaf4d3d325273c9f993c63b31a909677f.tar.bz2
themes-169833bfaf4d3d325273c9f993c63b31a909677f.zip
themes: handle unparseable date strings in bit_date_format modifier
PHP 8.3+ throws DateMalformedStringException instead of a warning when DateTime::__construct() receives an invalid string (e.g. '---' from corrupted EXIF metadata). The existing empty() guard doesn't catch non-empty garbage values. Wrap the DateTime construction in try/catch and add a strtotime() pre-check on the fallback path so both code paths return '' for invalid input. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
-rwxr-xr-xsmartyplugins/modifier.bit_date_format.php13
1 files changed, 10 insertions, 3 deletions
diff --git a/smartyplugins/modifier.bit_date_format.php b/smartyplugins/modifier.bit_date_format.php
index d939678..4a115c3 100755
--- a/smartyplugins/modifier.bit_date_format.php
+++ b/smartyplugins/modifier.bit_date_format.php
@@ -39,15 +39,22 @@ function smarty_modifier_bit_date_format( $pString, $format = "%b %e, %Y", $pTra
if( $gBitUser->getPreference( 'site_display_utc' ) == 'Fixed' && class_exists( 'DateTime' ) ) {
date_default_timezone_set( $gBitUser->getPreference( 'site_display_timezone', 'UTC' ) );
- $dateTimeUser = is_numeric( $pString )
- ? new \DateTime( '@'.(int)$pString )
- : new \DateTime( $pString );
+ try {
+ $dateTimeUser = is_numeric( $pString )
+ ? new \DateTime( '@'.(int)$pString )
+ : new \DateTime( $pString );
+ } catch ( \DateMalformedStringException | \Exception $e ) {
+ return '';
+ }
$disptime = strtotime($dateTimeUser->format(DATE_W3C));
return $gBitSystem->mServerTimestamp->strftime( $format, $disptime );
}
$format = $gBitSystem->get_display_offset()
? preg_replace( "/ ?%Z/",'', $format )
: $format = preg_replace( "/%Z/", "UTC", $format );
+ if( !is_numeric( $pString ) && strtotime( $pString ) === false ) {
+ return '';
+ }
$disptime = $gBitSystem->mServerTimestamp->getDisplayDateFromUTC( $pString );
return $gBitSystem->mServerTimestamp->strftime( $format, $disptime, TRUE );