Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Displaying the age of a link

(Page 1 of 2)
> >
Quote Reply
Displaying the age of a link
Is there any way to display the age of a link, perhaps through a global?

So if a link was added 10 mins ago, 1 hour ago, 4 days ago, 2 weeks ago, 8 months ago, 1 year ago etc. it would say so?

Thanks!
Quote Reply
Re: [anthonyweston] Displaying the age of a link In reply to
MMmm not sure about the number of minutes etc, but doing a "day" one shouldn't be too hard.

work_out_days_diff
Code:
sub {
return GT::Date::date_diff($_[0],GT::Date::date_get());
}

Call with:

Code:
<%work_out_days_diff($Add_Date)%>

That should give you the number of days since it was added. Totally untested ;)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [anthonyweston] Displaying the age of a link In reply to
Hi,

Andy is right. It's not so simple. There is no field at moment to compare the time against Frown

This can be achieved with a plugin though. I've done this for one of my sites, will see if I can find some time to pack it in to separate plugin.

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [Andy] Displaying the age of a link In reply to
Thanks.

I guess minutes and hours is not too important. But something that says either "Today" or "6 days ago" or "3 months ago", "1 year ago" perhaps?

The global you gave me returns just -15630 for every link regardless of the add date.

If you have time to look at this in more detail I can pay for your time. Hit me up.

Thanks!

Anthony
Quote Reply
Re: [anthonyweston] Displaying the age of a link In reply to
Mmm, try the other way around.

Code:
sub {
return GT::Date::date_diff(GT::Date::date_get(), $_[0]);
}

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [anthonyweston] Displaying the age of a link In reply to
Ah ok, I seem to remember that the Add_Date gets converted before being passed back. Try doing a GT::Template::dump to see if you can find another tag (maybe Add_Date_orig, or similar). If that still doesn't work shoot me and email and I'll take a look for you later today (in the middle of another job atm)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [eupos] Displaying the age of a link In reply to
I think its more due to the fact Add_Date gets converted from yyyy-mm-dd format into the date_user_format value (in my case, %ddd% %mmm% %dd% %yyyy%, which would obviously cause date_diff() to not work as expected Smile)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [eupos] Displaying the age of a link In reply to
Yes trying it the other way round just produces 15630 instead of -15630.

Thanks Andy I'll shoot you an email in a moment.
Quote Reply
Re: [Andy] Displaying the age of a link In reply to
Right :)

Now it returns the proper day difference.

Code:
sub {
my $added = GT::Date::date_get($_[0]);
return GT::Date::date_diff(GT::Date::date_get(), $added);
}

It should be called with:
Code:
<%work_out_days_diff($Add_Date_time)%>

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [anthonyweston] Displaying the age of a link In reply to
Okay, before I catch the tube here is little something Smile
It should give you the desired result.

I called this global link_age to reflect it's purpose.

Code:
sub {
my $added = GT::Date::date_get($_[0]);
my $old = GT::Date::date_diff(GT::Date::date_get(), $added);

my $output;

if ($old == 0 ) {
$output = "Today";
}
elsif ( int ($old / 7) > 0 && int ($old / 7) < 4 ) {
my $weeks = int ($old / 7);
$output = $weeks == 1 ? "Week ago" : $weeks . " weeks ago";
}
elsif ( $old < 30 ) {
$output = $old == 1 ? "Yesterday" : $old . " days ago";
}
elsif ( $old < 365 ) {
my $months = int ($old / 30 );
$output = $months == 1 ? "Month ago" : $months . " months ago";
}
else {
my $years = int ($old / 365 );
$output = $years == 1 ? "Year ago" : $years . " years ago";
}

return $output;
}

Call it the same way as before <%link_age($Add_Date_time)%>, and it'll produce the age of the link: Today, Week ago, 3 weeks ago, Month ago ... etc.

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins

Last edited by:

eupos: Oct 18, 2012, 9:58 AM
Quote Reply
Re: [eupos] Displaying the age of a link In reply to
Thanks very much, is working Smile

There is one minor problem. Some links have 0 weeks ago. Is that something that can be fixed easily?

I'm guessing those are the links that don't fit into any of the calculations below for one reason or another with their date?

Anthony
Quote Reply
Re: [anthonyweston] Displaying the age of a link In reply to
Please try the modified version above. It should work this way - totally untested though.
I'm doing this from my phone which is not the best place to code :)

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Displaying the age of a link In reply to
Brilliant, thanks.

I've also changed 30 to 28 as I was getting 28 days ago on some links, where this would be better off as "Month ago".

Thanks for all your help!
Quote Reply
Re: [anthonyweston] Displaying the age of a link In reply to
You are welcome, glad that it worked :)

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Displaying the age of a link In reply to
Im using this also now, in german:

Code:
sub {
my $added = GT::Date::date_get($_[0]);
my $old = GT::Date::date_diff(GT::Date::date_get(), $added);

my $output;

if ($old == 0 ) {
$output = "heute";
}
elsif ( int ($old / 7) > 0 && int ($old / 7) < 4 ) {
my $weeks = int ($old / 7);
$output = $weeks == 1 ? "Woche" : $weeks . " Wochen";
}
elsif ( $old < 30 ) {
$output = $old == 1 ? " gestern" : $old . " Tagen";
}
elsif ( $old < 365 ) {
my $months = int ($old / 30 );
$output = $months == 1 ? "Monat" : $months . " Monaten";
}
else {
my $years = int ($old / 365 );
$output = $years == 1 ? "Jahr" : $years . " Jahren";
}

return $output;
}

call it with:

Code:
Eingetragen seit <%link_age($Add_Date_time)%>
___________________________________________
http://www.westalgarve.de
http://www.portugalforum.org
http://www.portugal-links.de
Quote Reply
Re: [kailew] Displaying the age of a link In reply to
hmmm ... this doesn't work on
- search
- new
- cool

and those pages. Any solution?

It returns only a zero and then the link is "since today" in the directory ...

Kai
___________________________________________
http://www.westalgarve.de
http://www.portugalforum.org
http://www.portugal-links.de
Quote Reply
Re: [kailew] Displaying the age of a link In reply to
Hello Kai,

Just checked on my dev install and on a client website. And the global does the job perfect.
Both tests are on stock and heavily modified GLinks installs.

How do you build the pages (static/dynamic)?

Any example url where it doesn't work?

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Displaying the age of a link In reply to
Boris,

you're so fast ... Smile

Look here: http://www.portugal-links.de/New/2012-12-10.html
and here: http://www.portugal-links.de/cgi-bin/search.cgi?query=odeceixe&submit=los

always the same value: "Eingetragen seit: heute" which means "today" because of the "0".

Here it works great: http://www.portugal-links.de/Algarve/Allgemeines/index.html

I'm using static pages with detailed_url

Kai
___________________________________________
http://www.westalgarve.de
http://www.portugalforum.org
http://www.portugal-links.de
Quote Reply
Re: [kailew] Displaying the age of a link In reply to
Mmm can't see any differences regarding that code in glinks 3.2.0 which is your case :\

Can you send me admin access? Can find any problems with that code on 3 installs.

I'm afraid can't reproduce the issue locally.

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [kailew] Displaying the age of a link In reply to
Right,

Nailed it :)

Seems you are using the outdated pre 3.x templates, although they are still supported, the way they are built is different and the tag <%Add_Date_time%> is not available there and that's why the global always shows "today" in your case.

It's better for you to migrate your templates to luna css template set in order to avoid such issues in the future.

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Displaying the age of a link In reply to
Hi Boris,

I can't update, because it took very long to modify these templates. Is there another way?

Kai
___________________________________________
http://www.westalgarve.de
http://www.portugalforum.org
http://www.portugal-links.de
Quote Reply
Re: [kailew] Displaying the age of a link In reply to
Hi,

You can still update and use your current template set Angelic Just be sure to backup the templates (if they are not in the "luna" folder, then thats fine as they won't get updated).

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Displaying the age of a link In reply to
Hi Andy,

sorry, but I don't understand what you mean ...

My lsql version is the latest one in german. I've modified the templates very much ... what should I do exactly?

Kai
___________________________________________
http://www.westalgarve.de
http://www.portugalforum.org
http://www.portugal-links.de
Quote Reply
Re: [kailew] Displaying the age of a link In reply to
Hi,

Ah ok, I'm not 100% sure if they have an upgrade for the German version (I could be wrong).

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Displaying the age of a link In reply to
I think not ... that was the problem with the module for page rank ...

Kai
___________________________________________
http://www.westalgarve.de
http://www.portugalforum.org
http://www.portugal-links.de
> >