mustbme
05-01-2006, 03:16 PM
UPDATE: Don't do it! It's pretty, but his modification breaks the p2_news plugin.
This hack may break other plugins, or SD itself.
Do not add this modification to SD, instead, request something similar be added in a future release of SD!
See initial post "I'm not suggesting anyone modify their installation."
ORIGINAL POST:
I'm not a programmer, so I may have taken the wrong approach here, and I'm not suggesting anyone modify their installation, this just happened to work nicely on a test site. Hopefully I didn't reinvent the wheel... Tested *only* with news and latest news plugins - I'm sure it will adversely affect something else, somewhere, but it would be cool to see something like this included down the road... (hint)
Code as attachment below.
Add to table sd_mainsettings:
settingid: [leave blank (auto inc)]
varname: datehack
groupname: Date and Time Options
input: yesno
title: Date Hack (Human Readable)
description: Appends (today, yesterday, n days ago) to DisplayDate. [ OR Similar Text ]
value: 1
settingid: [leave blank (auto inc)]
varname: datehacklimit
groupname: Date and Time Options
input: text
title: Date Hack Limit
description: Limit number of Days (ex: 365) to display datehack. Empty or 0 defaults to forever. [ OR Similar Text ]
value: 365
Add to globalfunctions.php, immediately before DisplayDate()
function humanreadable($date = NULL) {
global $mainsettings;
$days = (mktime() - $date) / 86400;
if($days < 1) {
$result = 'Today';
} elseif($days < 2) {
$result = 'Yesterday';
} else {
$result = ceil($days) .' Days Ago';
}
if (($days < ($mainsettings['datehacklimit'] + 1)) || (!$mainsettings['datehacklimit'])){
return ' (' . $result . ')';
} else
return '';
}
Modify DisplayDate()
Change bottom line in function from:
return $gmepoch ? strtr(@gmdate($dateformat, $gmepoch + (3600 * $timezoneoffset + $dst)),
To:
if ($mainsettings['datehack']) {
return $gmepoch ? strtr(@gmdate($dateformat, $gmepoch + (3600 * $timezoneoffset + $dst)), $sdlanguage) . ' ' . humanreadable($gmepoch + (3600 * $timezoneoffset + $dst)) : '';
} else {
return $gmepoch ? strtr(@gmdate($dateformat, $gmepoch + (3600 * $timezoneoffset + $dst)), $sdlanguage) : '';
}
Results:
<div align="center">http://www.mustbme.com/images/datehack1.jpg</div>
<div align="center">http://www.mustbme.com/images/datehack2.jpg</div>
<div align="center">http://www.mustbme.com/images/datehack3.jpg</div>
[attachmentid=340]
This hack may break other plugins, or SD itself.
Do not add this modification to SD, instead, request something similar be added in a future release of SD!
See initial post "I'm not suggesting anyone modify their installation."
ORIGINAL POST:
I'm not a programmer, so I may have taken the wrong approach here, and I'm not suggesting anyone modify their installation, this just happened to work nicely on a test site. Hopefully I didn't reinvent the wheel... Tested *only* with news and latest news plugins - I'm sure it will adversely affect something else, somewhere, but it would be cool to see something like this included down the road... (hint)
Code as attachment below.
Add to table sd_mainsettings:
settingid: [leave blank (auto inc)]
varname: datehack
groupname: Date and Time Options
input: yesno
title: Date Hack (Human Readable)
description: Appends (today, yesterday, n days ago) to DisplayDate. [ OR Similar Text ]
value: 1
settingid: [leave blank (auto inc)]
varname: datehacklimit
groupname: Date and Time Options
input: text
title: Date Hack Limit
description: Limit number of Days (ex: 365) to display datehack. Empty or 0 defaults to forever. [ OR Similar Text ]
value: 365
Add to globalfunctions.php, immediately before DisplayDate()
function humanreadable($date = NULL) {
global $mainsettings;
$days = (mktime() - $date) / 86400;
if($days < 1) {
$result = 'Today';
} elseif($days < 2) {
$result = 'Yesterday';
} else {
$result = ceil($days) .' Days Ago';
}
if (($days < ($mainsettings['datehacklimit'] + 1)) || (!$mainsettings['datehacklimit'])){
return ' (' . $result . ')';
} else
return '';
}
Modify DisplayDate()
Change bottom line in function from:
return $gmepoch ? strtr(@gmdate($dateformat, $gmepoch + (3600 * $timezoneoffset + $dst)),
To:
if ($mainsettings['datehack']) {
return $gmepoch ? strtr(@gmdate($dateformat, $gmepoch + (3600 * $timezoneoffset + $dst)), $sdlanguage) . ' ' . humanreadable($gmepoch + (3600 * $timezoneoffset + $dst)) : '';
} else {
return $gmepoch ? strtr(@gmdate($dateformat, $gmepoch + (3600 * $timezoneoffset + $dst)), $sdlanguage) : '';
}
Results:
<div align="center">http://www.mustbme.com/images/datehack1.jpg</div>
<div align="center">http://www.mustbme.com/images/datehack2.jpg</div>
<div align="center">http://www.mustbme.com/images/datehack3.jpg</div>
[attachmentid=340]