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

Days_Old and <%loop links_loop%>

Quote Reply
Days_Old and <%loop links_loop%>
Heya,

I've been using the Days_Old plugin for a while building my links with the <%links%> tag.

For a variety of reasons I'd like to change how links are generated to using the <%loop links_loop%> tag.

The Days_Old plugin seems to go poof at this - probably not a hook into that. Has anyone found a work-around or fix for this?

Safe swoops
Sangiro
Quote Reply
Re: [sangiro] Days_Old and <%loop links_loop%> In reply to
Search for my update to it.

I install a Days_Old.pm (or something like that) in the Plugins area. You call it via a template tag. It doesn't go "pooof" anywhere :)

I know I posted it a few times over the years. First version was added to the User.pm (or something like that) but after plugins, was moved to that library tree.

You just copy the file to your Plugins area. No "install" necessary.

It also does some checking and updating of the "new" flags. (but won't reset category stats, you need to do that via the "repair tables")

I originally wrote it because of the way the date was being calculated, and needed to return a date-image that was not older than 14 days. (unless you "build" your site, date/new flags are not recalculated).


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 and <%loop links_loop%> In reply to
BTW... you call the routine in the Links.html template, so it's refreshed for each link.


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 and <%loop links_loop%> In reply to
pugdog,

Thanks for the reply. I'm assuming you're referring to this code. Is that right?

Not sure how this is to be used... Are you saying, save this as it's own .pm file and then call that pm file with a template tag, without installing it?

Do I use the tag you suggested in that post and will this find the appropriate PM in the plugins folder? Sorry for all the questions - just don't want to spin my wheels on this. Smile

Safe swoops
Sangiro
Quote Reply
Re: [sangiro] Days_Old and <%loop links_loop%> In reply to
Hi,
yes, sort of.

That was the original incarnation.

THe new one is in a module you just copy to the Plugins folder.

I tried to find the "generic" one yesterday, but couldn't. You can try this, and if it works, fine. It has some quirks that are specific to a 14 day "old" system, and a purely dynamic site, with no "builds."

You would call it with:

<%Plugins::Days_Old::___%> where __ is the name of the routine.

One version has both category_new and Link_new routines. You'd call the category new in the subcat.html

I'm working on a cleaned up version to be released with our tools collection.


PUGDOG� Enterprises, Inc.

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

Last edited by:

pugdog: Oct 16, 2004, 8:05 AM
Quote Reply
Re: [pugdog] Days_Old and <%loop links_loop%> In reply to
Pugdog,

Thanks for passing on this pm. It's not returning any result though, nor is it returning an error.

I have <%Plugins::Days_Old::link_Days_Old%> at the top of links.html and uses the tag <%Days_Old%>.

It returns nothing. When looking at a template dump of tags dump Days_Old is an empty field. My site is running in Dynamic mode.. Do you have any suggestions?

Safe swoops
Sangiro
Quote Reply
Re: [sangiro] Days_Old and <%loop links_loop%> In reply to
Try this, just replace the routine in the Days_Old.pm.
It's leaner, and one purpose.

Code:

sub link_Days_Old {
# -------------------------------------------------------------------
# Version 2.1.2 Oct 17, 2004
# -------------------------------------------------------------------
# You call this tag by placing <%Plugins::Days_Old::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.
# The function makes sure the "isNew" value is a 1/0 so you can use "<%if isNew%>" correctly.
# The function returns an integer in the <%Days_Old%> tag. "0" means the link is not new, and you can deal with it.
# eg: <%if Days_Old%><img src=<%build_images_url%>/new_<%Days_Old%>.gif><%endif%>
#
# The function also updates the database, so subsequent calls to the link behave properly.
# You still need to "Repair Tables" or "Build" to get the category and subcat counts correct.
#
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
my $LINK_DB = $DB->table('Links');
my $link = GT::Template->tags; ## load the template tags -- change in Links 2.1 parser
$link->{'Days_Old'} = GT::Date::date_diff ( GT::Date::date_get(), $link->{'Add_Date'});
if ($link->{'Days_Old'} > $CFG->{'build_new_cutoff'}) { ## if the link is not supposed to be "new"
if ( ($link->{isNew} eq 'Yes') or ($link->{isNew} == 1) ) { ## flags are wrong
$LINK_DB->update ( ## reset the flags
{
isNew => 'No'
},
{
ID => $link->{'ID'}
}
);
}

$link->{'isNew'} = '0';
$link->{'Days_Old'} = '0'; ## might need to delete $link->{'Days_Old'} in some cases.
} else { ## the link is IS NEW, so check it.
if ( ($link->{isNew} eq 'No') or ($link->{isNew} == 0) ) { ## flags are wrong
$LINK_DB->update (
{
isNew => 'Yes'
},
{
ID => $link->{'ID'}
}
);
}
$link->{'isNew'} = '1';
$link->{'Days_Old'} = '1'; ## might need to delete $link->{'Days_Old'} in some cases.
}
## return the data
return ($link); #fixed typo
}


If this works, I'll update the .pm file above. (The file above works for me.... and that's what *really* counts <g>)


PUGDOG� Enterprises, Inc.

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

Last edited by:

pugdog: Oct 20, 2004, 3:10 AM
Quote Reply
Re: [pugdog] Days_Old and <%loop links_loop%> In reply to
Hi Pugdog,

If you put this line in
GT::Date::date_set_format('%ddd% %mmm% %dd% %yyyy%');
then it changes the date format forever on sites using mod_perl. This becomes a problem when adding or modifying links.

Personally I would use
date_get (time, '%ddd% %mmm% %dd% %yyyy%');
but if you want to use date_set_format you really need to set the format back at the end of the sub using
GT::Date::date_set_format($CFG->{'date_db_format'});

Laura.
Quote Reply
Re: [afinlr] Days_Old and <%loop links_loop%> In reply to
Laura,

I do use mod_perl on my server... Would you set it back after the return statement?

Pugdog,

I tried the code above. If I leave the hooks on in the plugin it returns the error below. When I disable both the hooks in Days_Old the result is the same as before... No, error but no rasult on the <%Days_Old%> tag either.

Quote:
With Hooks

A fatal error has occured:

GT::Plugins (20442): Error running plugin PRE hook: Plugins::Days_Old::subcategory. Reason: syntax error at /cgi-bin/classifieds/admin/Plugins/Days_Old.pm line 93, near "$link;"
Compilation failed in require at GT::Plugins::_load_hook line 268.
at /cgi-bin/gear/admin/Links/SiteHTML.pm line 28.

Please enable debugging in setup for more details.

OK
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@dropzone.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Safe swoops
Sangiro

Last edited by:

sangiro: Oct 17, 2004, 12:27 PM
Quote Reply
Re: [sangiro] Days_Old and <%loop links_loop%> In reply to
I would set it back just before the return statement.

This looks like it might be causing the problem
return ($link;
Quote Reply
Re: [afinlr] Days_Old and <%loop links_loop%> In reply to
Quote:
return ($link;

Yup - good catch. That prevents it from crashing, but it's still not returning anything. The dump doesn't even show a tag called Days_Old available. Frown

Safe swoops
Sangiro
Quote Reply
Re: [sangiro] Days_Old and <%loop links_loop%> In reply to
Hi,

My routine does *NOT* use any hooks.... it's called from within the link.html template, or detailed.html template.

You pass the link data to the function, and it modifies it, and passes it right back. That's all.

Without the expanded functionality, it could almost be a global, not a function. The reason for the .pm file was expanded functionality for my sites, and historic. But it might be able to be simplified even further into a global.... which might address some mod_perl issues.

You can UNINSTALL the Days_Old plugin, and just leave the Days_Old.pm as modified above in your Plugins directory.

IT does not have to be "installed". Just copied to Plugins directory.

I'll have to figure out the mod_perl thing.... but it's not doing anything "bad" except as Laura pointed out, under mod_perl for that process it will change the date, either of the two fixes she presented will fix it. Avoiding the "set date" format, might be better. mod_perl is a different beast, and it's almost impossible to develop under it. Non of my development systems use it, but all the plugins and scripts use standard GT calls, so, in theory, they should work in the mod_perl environment (ie: the use of .pm files, not .cgi scripts, etc).

I'll look at it again. But I dont' have a mod_perl server to test under at the moment.


PUGDOG� Enterprises, Inc.

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