Firefox PHP

Time_ago module + hack

Posted by alfaguru 
All files from this thread

File Name File Size   Posted by Date  
time_ago.zip 1.3 KB open | download alfaguru 01/08/2007 Read message
Time_ago module + hack
January 08, 2007 08:10PM
Hi, I've written a little module which changes the display of timestamps to the form 'X units ago' ('5 seconds ago', '1 hour ago', etc.), which I think is generally a friendlier way to display them. It needs the following hack to work:

after
function phorum_date( $picture, $ts )
{
in format_functions.php
insert
	if(defined('PHORUM_MOD_TIME_AGO')) {
		return phorum_time_ago($ts);
	}
The attached module contains the rest of the code, which is pretty straightforward if not exactly elegant.
Attachments:
open | download - time_ago.zip (1.3 KB)
Re: Time_ago module + hack
January 08, 2007 08:13PM
There's already a mod that does this. Not sure if it's better than yours but it's a mod and this is a hack.

Maybe you should explore the possibilities to make this work withjout hacking core code?

---
-=[ Panu ]=-
Re: Time_ago module + hack
January 08, 2007 08:20PM
Do you mean the readable_dates module? It doesn't do the same thing as this.

The reason this is a hack and not a module is because I couldn't find a way to get at dates on a page in their original timestamp form rather than as formatted strings. The readable_dates module performs some contortions to force dates to be formatted in a way it can parse back. I didn't really want to do that as it creates so many possibilities for bugs when dealing with the unformatted timestamps is so much simpler.
Re: Time_ago module + hack
January 08, 2007 09:03PM
This type of displaying of relative dates is something that I have planned to integrate in readable_dates as well. But that will only be done for Phorum 5.2. Two reasons for only implementing it in 5.2 are:

* Phorum 5.2 already has some code built in for formatting relative dates (currently used for telling how long ago a user registered in the profile);

* I want to make some changes to the data structures so modules can access the unformatted datestamps. That will make this kind of module a lot easier and cleaner to write in 5.2.

So till 5.2, this module will be great for people who want relative date formatting. Thanks for writing the mod!


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Time_ago module + hack
January 08, 2007 10:23PM
Quote
alfaguru
Do you mean the readable_dates module? It doesn't do the same thing as this.

Sorry yes, I remebered it wrong.

Quote
alfaguru
The reason this is a hack and not a module is because I couldn't find a way to get at dates on a page in their original timestamp form rather than as formatted strings. The

Yeah, I checked and there's no hook after the messages are fetched from db. If there was a hook right after db fetch the date wouldn't be contaminated yet and would make for example date mods much easier.

---
-=[ Panu ]=-
Sorry, only registered users may post in this forum.

Click here to login