From f22635779b10fe3735a11bc1af5c88653e580534 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 7 Oct 2009 15:36:14 +0200 Subject: New dformat() function for fuzzy date support Ignore-this: 7193cd788fee2c05a9068bf6edd5dc17 It is now possible to use the %f placeholder in $conf['dformat'] to add a fuzzy age string. Template developers and plugin authors should replace their strftime + $conf['dformat'] calls with calls to the new dformat() function. Example: %Y/%m/%d %H:%M (%f) produces dates like this: 2009/09/16 10:36 (3 weeks ago) darcs-hash:20091007133614-6e07b-677108d1b43928ef8fd886813e43514507b5e073.gz --- inc/common.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 82d5f69ee..a15cb5c62 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1082,7 +1082,7 @@ function notify($id,$who,$rev='',$summary='',$minor=false,$replace=array()){ } $ip = clientIP(); - $text = str_replace('@DATE@',strftime($conf['dformat']),$text); + $text = str_replace('@DATE@',dformat(),$text); $text = str_replace('@BROWSER@',$_SERVER['HTTP_USER_AGENT'],$text); $text = str_replace('@IPADDRESS@',$ip,$text); $text = str_replace('@HOSTNAME@',gethostsbyaddrs($ip),$text); @@ -1223,6 +1223,26 @@ function datetime_h($dt){ } +/** + * Wraps around strftime but provides support for fuzzy dates + * + * The format default to $conf['dformat']. It is passed to + * strftime - %f can be used to get the value from datetime_h() + * + * @see datetime_h + * @author Andreas Gohr + */ +function dformat($dt=null,$format=''){ + global $conf; + + if(is_null($dt)) $dt = time(); + $dt = (int) $dt; + if(!$format) $format = $conf['dformat']; + + $format = str_replace('%f',datetime_h($dt),$format); + return strftime($format,$dt); +} + /** * return an obfuscated email address in line with $conf['mailguard'] setting * -- cgit v1.2.3