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

Days Old Plug In works okay?

Quote Reply
Days Old Plug In works okay?
There was a mention back in Feb about this not working properly. I'm getting the same problem where it generates the code new_227.gif or various other numbers that dont exist. I couldn't find any mention of a cure. I *think* it is treating validated changed links as new and counting back to the Added Date for that link, hence the high days old number. Thanks

Quote Reply
Re: Days Old Plug In works okay? In reply to
try the following
1- set your days old value to 14.
2- Run repair table

and that should fix it...

Regards
Abd

http://www.idleb.com
Quote Reply
Re: Days Old Plug In works okay? In reply to
Thanks - that seems to have fixed it

Quote Reply
Re: Days Old Plug In works okay? In reply to
Only temporarily ... it is an ongoing problem. I keeps re-occurring on my system every few days ... particulary when I do a 'Build Changed' build.

Regards,

Clint.

--------------------------
http://www.AffiliatesDirectory.com - Affiliate Programs Directory
Quote Reply
Re: Days Old Plug In works okay? In reply to
The "fix" is to "repair tables" every time you run a partial build. What happens, it seems, is "un changed" records are not having the "new" status updated properly.

If you are running a dynamic site, you also need to do the repair tables thing on a daily basis to update the stats.

PUGDOG® Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Forum:http://LinkSQL.com/forum
Quote Reply
Re: Days Old Plug In works okay? In reply to
Yes I notice this has come back again. So I have to 'repair tables' every time? Phew.. I already have to do two builds every time I update because some search engines point at .shtml page extensions on my site instead of .html Oh well.. Links is still brilliant. Will this Days Old problem be fixed in a future release? Thanks

Quote Reply
Re: Days Old Plug In works okay? In reply to
I wrote the Days old plugin, but dont have any intentions on updating it. It is not a plugin problem, but a problem that Links doesnt change the new status to "no" sometimes.

Robert Blackstone
Webmaster of Scato Search
http://www.scato.com
Quote Reply
Re: Days Old Plug In works okay? In reply to
Funny this thread bubbled up again.

I was just playing with the Days_Old.pm file to see if I could get it to be run from inside the templates, rather than as a display hook.

I'm getting very odd results, which leads me to believe there might be a nesting problem, or other limitation in 'depth', in the template parser.

Doesn't look like GT::Date is being called properly when GT::Plugins::link is called from the template. I tried the simple things like re-initializing the Links::date_init but that didn't work.

Just odd this thread popped up :)

Also, you can do something like:
Code:
if (($link->{'isNew'} eq 'Yes') or ($link->{'isNew'} == 1)){
$link->{'Days_Old'} = GT::Date::date_diff ( GT::Date::date_get(), $link->{'Add_Date1'});
}
else {
$link->{'Days_Old'} = '';
}
to catch where the field is 'Yes' or '1'. Might not be an issue for most people, but it catches both positive values which is important if you call it before the 'isNew' flag is changed over.


PUGDOG® Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Plugins:http://LinkSQL.com/plugin
Quote Reply
Re: Days Old Plug In works okay? In reply to
Ok,

I seem to have gotten it working. The problem is more the date format than anything else. You need to make sure that the date is returned from GT::Date::date_get() in the format the other dates are being returned in.

That means, you might need to specify:

GT::Date::date_set_format('%ddd% %mmm% %dd% %yyyy%');

or some other format, depending on where you are calling the date. Remember, Add_Date is stored as "yyyy-mm-dd" internally, but it's output as "Thu Jul 12 2001" in the templates.

So, the routine becomes:

Code:
sub link {
# -------------------------------------------------------------------
my $link = shift;
Links::init_date(); ## you can either 'use GT::Date' or do it this way, this is probably better
GT::Date::date_set_format('%ddd% %mmm% %dd% %yyyy%'); ## this is the key to making it work
if (($link->{'isNew'} eq 'Yes') or ($link->{'isNew'} == 1)){
$link->{'Days_Old'} = GT::Date::date_diff ( GT::Date::date_get(), $link->{'Add_Date'});
}
else {
$link->{'Days_Old'} = '';
}
return $link;
}
I've actually just added this to the top of the link.html as a call to:

<%Plugins::Days_Old::link%>

and disabled all the hooks.

You can do something similar for the categories if you wish.

As for broken images, I sort of have a fix for that too.

If you only have 14 different graphics, (or whatever number), create a graphic that is only 1x1 pixels, or is transparent, etc. Give it a name in your series, like new_99.gif.

Change the first test in the above routine to be:

Code:
if (($link->{'isNew'} eq 'Yes') or ($link->{'isNew'} == 1)){
$link->{'Days_Old'} = GT::Date::date_diff ( GT::Date::date_get(), $link->{'Add_Date'});
($link->{'Days_Old'} <= 14) or ($link->{'Days_Old'} = 99);
}
If the link is older than your largest graphic file (14 days) it will call the new_99.gif file, which will be invisible to the user, but will prevent a broken image.

If you wanted to be slick, you could make it a call to $CFG->{'build_new_cutoff'}, but that would mean adding $CFG to the use Links line at the top of the file, and would impose some additional overhead for something so trivial.

PUGDOG® Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Plugins:http://LinkSQL.com/plugin
Quote Reply
Re: Days Old Plug In works okay? In reply to
BTW... to really "fix" this problem, and save cycles the next time, you could alter the code above to be:

Code:
if (($link->{'isNew'} eq 'Yes') or ($link->{'isNew'} == 1)){
$link->{'Days_Old'} = GT::Date::date_diff ( GT::Date::date_get(), $link->{'Add_Date'});
if ($link->{'Days_Old'} > $CFG->{'build_new_cutoff'}) {
my $LINK_DB = $DB->table('Links');
$LINK_DB->update (
{
isNew => 'No'
},
{
ID => $link->{'ID'}
}
);
($link->{'isNew'} eq 'Yes') && ($link->{'isNew'} = 'No');
($link->{'isNew'} eq '1') && ($link->{'isNew'} = '0');
}
#delete $link->{'Days_Old'}; ## undef isn't enough for consistency in some cases
$link->{'Days_Old'} = ''; ## undef, or set to null
}
Should be self explanatory, but if the Days_Old is greater than the cutoff date,
the database record is updated (so this won't happen again) and the current value
of isNew is also altered, changed to 0 or 'No' depending.

I haven't tested this, but it should work. It's pretty straight forward.

You also need to change the top of the file to

use Links qw/$IN $CFG $DB/;

The $TPL is no longer used, and should be deleted.



PUGDOG® Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Plugins:http://LinkSQL.com/plugin
Quote Reply
Re: Days Old Plug In works okay? In reply to
Hi

is there any chance of all this being incorporated into an updated plug in? I don't feel too comfortable playing around with the code.

Many Thanks

Quote Reply
Re: Days Old Plug In works okay? In reply to
I didn't write the original Days_Old plugin, so I can't really update it.

I have incorporated this into the MultiUp.pm file, and once installed, any template has access to it by calling <%Plugins::MultiUp::link_Days_Old%> at the top of the link.html file, or inside any loop including other files. AE_link_Days_Old does the same thing for the Attach_Elements table.

I haven't written/rewritten the subcat_Days_Old routines.


PUGDOG® Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Plugins:http://LinkSQL.com/plugin
Quote Reply
Re: Days Old Plug In works okay? In reply to
FWIW... it looks like the file ../admin/Links/Utils.pm as been set up as a place for functions that can be used in the templates.

If you copy the following code to that file, making sure to leave the last line of the file, 1;, you can call this at the top of your links.html template, and disable the site_html_link hook in the Days_Old plug in options screen.

The advantage of this routine is that it will reset older links back to 'isNew'='No'.

Code:
sub link_Days_Old {
# -------------------------------------------------------------------
# You call this tag by placing <%Links::Utils::link_Days_Old%> at the
# top of your link.html or detailed.html template, or wherever you
# have "Link" data, and want to use the <%Days_Old%> tag.
#
my $link = shift;
Links::init_date(); ## you can either 'use GT::Date' or do it this way, this is probably better
GT::Date::date_set_format('%ddd% %mmm% %dd% %yyyy%'); ## this is the key to making it work

if (($link->{'isNew'} eq 'Yes') or ($link->{'isNew'} == 1)){
$link->{'Days_Old'} = GT::Date::date_diff ( GT::Date::date_get(), $link->{'Add_Date'});
if ($link->{'Days_Old'} > $CFG->{'build_new_cutoff'}) {
my $LINK_DB = $DB->table('Links');
$LINK_DB->update (
{
isNew => 'No'
},
{
ID => $link->{'ID'}
}
);
($link->{'isNew'} eq 'Yes') && ($link->{'isNew'} = 'No');
($link->{'isNew'} eq '1') && ($link->{'isNew'} = '0');
$link->{'Days_Old'} = ''; ## might need to delete $link->{'Days_Old'} in some cases.
}
} else {
$link->{'Days_Old'} = ''; ## might need to delete $link->{'Days_Old'} in some cases.
}
return $link;
}
Again, I haven't tested this, but it should work.

Alex/GT - feel free to add this to the 2.1 release Utils.pm if you want. I'm not sure of the performance issues, but this was made an option 1.1x due to performance (users had to uncomment some lines), so this method of a called function shouldn't be too bad, right? And it still lets users decide if they want to use it.

Maybe: <%if isNew%><%Links::Utils::link_Days_Old%><%endif%>

If it's at the top of the link.html, it will also reset 'isNew', removing the flags from the link display. This might be a problem in display listings, since links that are really not new, won't have the graphic, .... but I see it as a "benefit". Additionally, on the next build or display if dynamic, this link won't be included at all, since it's been properly reset to 'isNew'=>'No' in the database record.

The only other issue I see, is the date format. Is there a way to determine the date format, and change it only if it doesn't match the format of the Add_Date field?


PUGDOG® Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Plugins:http://LinkSQL.com/plugin
Quote Reply
Re: [pugdog] Days Old Plug In works okay? In reply to
Ok,

In order to make this work with Links 2.1 (and maybe 2.05) you need to make the following change -- it's a change in the way the template parser works. It probably has impacted _all_ old plugins.

Change the first line of the subroutine from:

my $link = shift;

to

my $link = GT::Template->tags;

The parser no longer passes the tags as the first reference, you need to explicitly request them.




PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Days Old Plug In works okay? In reply to
Code:


sub link_Days_Old {
# -------------------------------------------------------------------
# You call this tag by placing <%Links::Utils::link_Days_Old%> at the
# top of your link.html or detailed.html template, or wherever you
# have "Link" data, and want to use the <%Days_Old%> tag.
#
my ($cutoff, $reset) = shift;
$reset ||= 0;
($reset = 1) && ($cutoff >= $CFG->{'build_new_cutoff'}); ## override reset 0 if cutoff >= cutoff date.
$cutoff ||= $CFG->{'build_new_cutoff'}; ## set cutoff if not set in either of the two places above
my $link = GT::Template->tags; ## load the template tags -- change in Links 2.1 parser
Links::init_date(); ## you can either 'use GT::Date' or do it this way, this is probably better
GT::Date::date_set_format('%ddd% %mmm% %dd% %yyyy%'); ## this is the key to making it work

if (($link->{'isNew'} eq 'Yes') or ($link->{'isNew'} == 1)){
$link->{'Stage_one'} = "I got here";
$link->{'Days_Old'} = GT::Date::date_diff ( GT::Date::date_get(), $link->{'Add_Date'});
if ($link->{'Days_Old'} > $cutoff) {
if ($reset) {
my $LINK_DB = $DB->table('Links');
$LINK_DB->update (
{
isNew => 'No'
},
{
ID => $link->{'ID'}
}
);
}
($link->{'isNew'} eq 'Yes') && ($link->{'isNew'} = 'No');
($link->{'isNew'} eq '1') && ($link->{'isNew'} = '0');
$link->{'Days_Old'} = ''; ## might need to delete $link->{'Days_Old'} in some cases.
}
} else {
$link->{'Days_Old'} = ''; ## might need to delete $link->{'Days_Old'} in some cases.
}
return $link;
}


You can then call it with:

<%Links::User::link_Days_Old (4,1)%>

And that will find all links newer than 4 days and reset the "isNew" flag for all the other links it finds. This features is sort of buggy, or really hard to under stand, so unless you know what you are doing, leave the second parameter off, or set it to 0 such as:

<%Links::Utils::link_Days_Old (4,0)%> or just <%Links::Utils::link_Days_Old (4)%>

If you leave off all parameters and the (), it defaults to the build_new_cutoff value set in the admin, just as before.

The behavior of setting the links that it finds to "isNew"=No will still happen if the parameter you pass is >= the $CFG->{'build_new_cutoff'} value, but otherwise, it won't update the records with the shortened date.

This tweak is of limited value for most people, but it shouldn't affect the way the plugin was working before, it just adds the extra parameter, and changes some internal logic.

It allows you to use the Days_Old flag in other places where you might only want a link to be flagged as "new" if it's 1 or 2 days old.






PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.