Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-04-05 17:35:18

edduddiee
Plugin Author
Registered: 2006-02-13
Posts: 2
Website

A Proper Time Since Function

I am not sure if this is the right place to post this but it seemed to fit with title.

I have just documented on my site how you can make a proper timesince function that works with times longer than days (including weeks and months and years).

It works by replacing the built in time-since function with a new one. While I am sure you could use a plugin with the same effect I dont know how the plugin system works. The post can be found here:

http://e26.co.uk/code/textpattern-time-since

Regards, Eddie

update: I have turned this in to a plugin for ease of use. Check it out

Last edited by edduddiee (2006-06-27 16:17:20)

Offline

#2 2006-04-05 21:45:47

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 704

Re: A Proper Time Since Function

I might have considered Feature Ideas. The mod would be easier than a plugin, I think, but it will have to be done over at each upgrade of TXP.
I wouldn’t hesitate to submit a patch.

Offline

#3 2006-04-06 00:42:28

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: A Proper Time Since Function

A plugin would be easier…

Offline

#4 2006-04-06 03:13:53

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 704

Re: A Proper Time Since Function

Mary – I’m curious?

The normal flow would be posted > safe_strftime > since. Putting three modified functions in a plugin xxx_safe_strftime xxx_since and then placing xxx_posted in the article form wouldn’t be that difficult, but I am guessing there is a better way.

Offline

#5 2006-04-06 05:10:08

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: A Proper Time Since Function

From the standpoint of the user, a plugin is easier in that you’re not modifying the core files. Once you start doing that it can become a real burden when it comes to upgrade time. There’s also increasing the likelihood of incorrect copies (and then trying to help them debug them…), since typically users aren’t familiar with PHP.

You can easily make a plugin which provides one new tag, that will work for comments, articles and search results forms.

function ext_better_since($atts)
{
	global $thisarticle, $thiscomment;

	if ($thiscomment)
	{
		return better_since($thisarticle['posted'] + tz_offset());
	}

	elseif ($thisarticle)
	{
		return better_since($thiscomment['time'] + tz_offset());
	}
}

function better_since($stamp)
{
	// the contents of your new function
}

The flow is posted > safe_strftime or posted > since, not all three. If you’re using “since” – the purpose of making this modification – you don’t need the other functions.

If you really wanted to make a tag that can turn this “since” on and off later, like you can for posted and comment_time, you’d only need new copies of those two functions (safe_strftime doesn’t need to be copied), which is still better than modifying the core files. :)

Offline

#6 2006-04-06 05:46:14

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 704

Re: A Proper Time Since Function

Thank You!

Offline

Board footer

Powered by FluxBB